@copilotkit/runtime 2.0.0-next.1 → 2.0.0-rc.1

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 (623) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +135 -1
  3. package/dist/_virtual/_rolldown/runtime.cjs +29 -0
  4. package/dist/_virtual/_rolldown/runtime.mjs +18 -0
  5. package/dist/agent/converters/aisdk.cjs +355 -0
  6. package/dist/agent/converters/aisdk.cjs.map +1 -0
  7. package/dist/agent/converters/aisdk.d.cts +22 -0
  8. package/dist/agent/converters/aisdk.d.cts.map +1 -0
  9. package/dist/agent/converters/aisdk.d.mts +22 -0
  10. package/dist/agent/converters/aisdk.d.mts.map +1 -0
  11. package/dist/agent/converters/aisdk.mjs +351 -0
  12. package/dist/agent/converters/aisdk.mjs.map +1 -0
  13. package/dist/agent/converters/index.d.mts +2 -0
  14. package/dist/agent/converters/tanstack.cjs +374 -0
  15. package/dist/agent/converters/tanstack.cjs.map +1 -0
  16. package/dist/agent/converters/tanstack.d.cts +83 -0
  17. package/dist/agent/converters/tanstack.d.cts.map +1 -0
  18. package/dist/agent/converters/tanstack.d.mts +83 -0
  19. package/dist/agent/converters/tanstack.d.mts.map +1 -0
  20. package/dist/agent/converters/tanstack.mjs +372 -0
  21. package/dist/agent/converters/tanstack.mjs.map +1 -0
  22. package/dist/agent/converters/usage.cjs +68 -0
  23. package/dist/agent/converters/usage.cjs.map +1 -0
  24. package/dist/agent/converters/usage.d.cts +19 -0
  25. package/dist/agent/converters/usage.d.cts.map +1 -0
  26. package/dist/agent/converters/usage.d.mts +19 -0
  27. package/dist/agent/converters/usage.d.mts.map +1 -0
  28. package/dist/agent/converters/usage.mjs +62 -0
  29. package/dist/agent/converters/usage.mjs.map +1 -0
  30. package/dist/agent/index.cjs +1328 -0
  31. package/dist/agent/index.cjs.map +1 -0
  32. package/dist/agent/index.d.cts +467 -0
  33. package/dist/agent/index.d.cts.map +1 -0
  34. package/dist/agent/index.d.mts +468 -0
  35. package/dist/agent/index.d.mts.map +1 -0
  36. package/dist/agent/index.mjs +1318 -0
  37. package/dist/agent/index.mjs.map +1 -0
  38. package/dist/agent/learned-skills.cjs +76 -0
  39. package/dist/agent/learned-skills.cjs.map +1 -0
  40. package/dist/agent/learned-skills.d.cts +15 -0
  41. package/dist/agent/learned-skills.d.cts.map +1 -0
  42. package/dist/agent/learned-skills.d.mts +15 -0
  43. package/dist/agent/learned-skills.d.mts.map +1 -0
  44. package/dist/agent/learned-skills.mjs +74 -0
  45. package/dist/agent/learned-skills.mjs.map +1 -0
  46. package/dist/agent/mcp-tool-names.cjs +82 -0
  47. package/dist/agent/mcp-tool-names.cjs.map +1 -0
  48. package/dist/agent/mcp-tool-names.mjs +80 -0
  49. package/dist/agent/mcp-tool-names.mjs.map +1 -0
  50. package/dist/agent/state-delta.cjs +321 -0
  51. package/dist/agent/state-delta.cjs.map +1 -0
  52. package/dist/agent/state-delta.mjs +320 -0
  53. package/dist/agent/state-delta.mjs.map +1 -0
  54. package/dist/agent/url-download.cjs +503 -0
  55. package/dist/agent/url-download.cjs.map +1 -0
  56. package/dist/agent/url-download.d.cts +79 -0
  57. package/dist/agent/url-download.d.cts.map +1 -0
  58. package/dist/agent/url-download.d.mts +79 -0
  59. package/dist/agent/url-download.d.mts.map +1 -0
  60. package/dist/agent/url-download.mjs +500 -0
  61. package/dist/agent/url-download.mjs.map +1 -0
  62. package/dist/index.cjs +75 -0
  63. package/dist/index.d.cts +24 -0
  64. package/dist/index.d.mts +24 -0
  65. package/dist/index.mjs +17 -5598
  66. package/dist/internal/learned-skills.cjs +21 -0
  67. package/dist/internal/learned-skills.d.cts +9 -0
  68. package/dist/internal/learned-skills.d.mts +9 -0
  69. package/dist/internal/learned-skills.mjs +9 -0
  70. package/dist/node.cjs +7 -0
  71. package/dist/node.d.cts +4 -0
  72. package/dist/node.d.mts +4 -0
  73. package/dist/node.mjs +4 -0
  74. package/dist/runtime/core/channel-activation-config.cjs +87 -0
  75. package/dist/runtime/core/channel-activation-config.cjs.map +1 -0
  76. package/dist/runtime/core/channel-activation-config.d.cts +39 -0
  77. package/dist/runtime/core/channel-activation-config.d.cts.map +1 -0
  78. package/dist/runtime/core/channel-activation-config.d.mts +39 -0
  79. package/dist/runtime/core/channel-activation-config.d.mts.map +1 -0
  80. package/dist/runtime/core/channel-activation-config.mjs +85 -0
  81. package/dist/runtime/core/channel-activation-config.mjs.map +1 -0
  82. package/dist/runtime/core/channel-manager.cjs +973 -0
  83. package/dist/runtime/core/channel-manager.cjs.map +1 -0
  84. package/dist/runtime/core/channel-manager.d.cts +166 -0
  85. package/dist/runtime/core/channel-manager.d.cts.map +1 -0
  86. package/dist/runtime/core/channel-manager.d.mts +167 -0
  87. package/dist/runtime/core/channel-manager.d.mts.map +1 -0
  88. package/dist/runtime/core/channel-manager.mjs +972 -0
  89. package/dist/runtime/core/channel-manager.mjs.map +1 -0
  90. package/dist/runtime/core/debug-event-bus.cjs +57 -0
  91. package/dist/runtime/core/debug-event-bus.cjs.map +1 -0
  92. package/dist/runtime/core/debug-event-bus.d.cts +18 -0
  93. package/dist/runtime/core/debug-event-bus.d.cts.map +1 -0
  94. package/dist/runtime/core/debug-event-bus.d.mts +18 -0
  95. package/dist/runtime/core/debug-event-bus.d.mts.map +1 -0
  96. package/dist/runtime/core/debug-event-bus.mjs +55 -0
  97. package/dist/runtime/core/debug-event-bus.mjs.map +1 -0
  98. package/dist/runtime/core/fetch-cors.cjs +71 -0
  99. package/dist/runtime/core/fetch-cors.cjs.map +1 -0
  100. package/dist/runtime/core/fetch-cors.d.cts +19 -0
  101. package/dist/runtime/core/fetch-cors.d.cts.map +1 -0
  102. package/dist/runtime/core/fetch-cors.d.mts +19 -0
  103. package/dist/runtime/core/fetch-cors.d.mts.map +1 -0
  104. package/dist/runtime/core/fetch-cors.mjs +69 -0
  105. package/dist/runtime/core/fetch-cors.mjs.map +1 -0
  106. package/dist/runtime/core/fetch-handler.cjs +539 -0
  107. package/dist/runtime/core/fetch-handler.cjs.map +1 -0
  108. package/dist/runtime/core/fetch-handler.d.cts +99 -0
  109. package/dist/runtime/core/fetch-handler.d.cts.map +1 -0
  110. package/dist/runtime/core/fetch-handler.d.mts +99 -0
  111. package/dist/runtime/core/fetch-handler.d.mts.map +1 -0
  112. package/dist/runtime/core/fetch-handler.mjs +538 -0
  113. package/dist/runtime/core/fetch-handler.mjs.map +1 -0
  114. package/dist/runtime/core/fetch-router.cjs +141 -0
  115. package/dist/runtime/core/fetch-router.cjs.map +1 -0
  116. package/dist/runtime/core/fetch-router.mjs +140 -0
  117. package/dist/runtime/core/fetch-router.mjs.map +1 -0
  118. package/dist/runtime/core/hooks.cjs +28 -0
  119. package/dist/runtime/core/hooks.cjs.map +1 -0
  120. package/dist/runtime/core/hooks.d.cts +121 -0
  121. package/dist/runtime/core/hooks.d.cts.map +1 -0
  122. package/dist/runtime/core/hooks.d.mts +121 -0
  123. package/dist/runtime/core/hooks.d.mts.map +1 -0
  124. package/dist/runtime/core/hooks.mjs +24 -0
  125. package/dist/runtime/core/hooks.mjs.map +1 -0
  126. package/dist/runtime/core/learning.cjs +61 -0
  127. package/dist/runtime/core/learning.cjs.map +1 -0
  128. package/dist/runtime/core/learning.d.cts +61 -0
  129. package/dist/runtime/core/learning.d.cts.map +1 -0
  130. package/dist/runtime/core/learning.d.mts +61 -0
  131. package/dist/runtime/core/learning.d.mts.map +1 -0
  132. package/dist/runtime/core/learning.mjs +56 -0
  133. package/dist/runtime/core/learning.mjs.map +1 -0
  134. package/dist/runtime/core/logger.cjs +21 -0
  135. package/dist/runtime/core/logger.cjs.map +1 -0
  136. package/dist/runtime/core/logger.d.cts +12 -0
  137. package/dist/runtime/core/logger.d.cts.map +1 -0
  138. package/dist/runtime/core/logger.d.mts +12 -0
  139. package/dist/runtime/core/logger.d.mts.map +1 -0
  140. package/dist/runtime/core/logger.mjs +18 -0
  141. package/dist/runtime/core/logger.mjs.map +1 -0
  142. package/dist/runtime/core/middleware-sse-parser.cjs +149 -0
  143. package/dist/runtime/core/middleware-sse-parser.cjs.map +1 -0
  144. package/dist/runtime/core/middleware-sse-parser.d.cts +21 -0
  145. package/dist/runtime/core/middleware-sse-parser.d.cts.map +1 -0
  146. package/dist/runtime/core/middleware-sse-parser.d.mts +21 -0
  147. package/dist/runtime/core/middleware-sse-parser.d.mts.map +1 -0
  148. package/dist/runtime/core/middleware-sse-parser.mjs +148 -0
  149. package/dist/runtime/core/middleware-sse-parser.mjs.map +1 -0
  150. package/dist/runtime/core/middleware.cjs +34 -0
  151. package/dist/runtime/core/middleware.cjs.map +1 -0
  152. package/dist/runtime/core/middleware.d.cts +31 -0
  153. package/dist/runtime/core/middleware.d.cts.map +1 -0
  154. package/dist/runtime/core/middleware.d.mts +31 -0
  155. package/dist/runtime/core/middleware.d.mts.map +1 -0
  156. package/dist/runtime/core/middleware.mjs +32 -0
  157. package/dist/runtime/core/middleware.mjs.map +1 -0
  158. package/dist/runtime/core/package-info.cjs +9 -0
  159. package/dist/runtime/core/package-info.cjs.map +1 -0
  160. package/dist/runtime/core/package-info.mjs +7 -0
  161. package/dist/runtime/core/package-info.mjs.map +1 -0
  162. package/dist/runtime/core/runtime-error-reporter.cjs +21 -0
  163. package/dist/runtime/core/runtime-error-reporter.cjs.map +1 -0
  164. package/dist/runtime/core/runtime-error-reporter.mjs +18 -0
  165. package/dist/runtime/core/runtime-error-reporter.mjs.map +1 -0
  166. package/dist/runtime/core/runtime.cjs +256 -0
  167. package/dist/runtime/core/runtime.cjs.map +1 -0
  168. package/dist/runtime/core/runtime.d.cts +481 -0
  169. package/dist/runtime/core/runtime.d.cts.map +1 -0
  170. package/dist/runtime/core/runtime.d.mts +481 -0
  171. package/dist/runtime/core/runtime.d.mts.map +1 -0
  172. package/dist/runtime/core/runtime.mjs +249 -0
  173. package/dist/runtime/core/runtime.mjs.map +1 -0
  174. package/dist/runtime/endpoints/auto-start-channels.cjs +46 -0
  175. package/dist/runtime/endpoints/auto-start-channels.cjs.map +1 -0
  176. package/dist/runtime/endpoints/auto-start-channels.mjs +45 -0
  177. package/dist/runtime/endpoints/auto-start-channels.mjs.map +1 -0
  178. package/dist/runtime/endpoints/node-fetch-handler.cjs +75 -0
  179. package/dist/runtime/endpoints/node-fetch-handler.cjs.map +1 -0
  180. package/dist/runtime/endpoints/node-fetch-handler.d.cts +11 -0
  181. package/dist/runtime/endpoints/node-fetch-handler.d.cts.map +1 -0
  182. package/dist/runtime/endpoints/node-fetch-handler.d.mts +11 -0
  183. package/dist/runtime/endpoints/node-fetch-handler.d.mts.map +1 -0
  184. package/dist/runtime/endpoints/node-fetch-handler.mjs +73 -0
  185. package/dist/runtime/endpoints/node-fetch-handler.mjs.map +1 -0
  186. package/dist/runtime/endpoints/node.cjs +16 -0
  187. package/dist/runtime/endpoints/node.cjs.map +1 -0
  188. package/dist/runtime/endpoints/node.d.cts +104 -0
  189. package/dist/runtime/endpoints/node.d.cts.map +1 -0
  190. package/dist/runtime/endpoints/node.d.mts +104 -0
  191. package/dist/runtime/endpoints/node.d.mts.map +1 -0
  192. package/dist/runtime/endpoints/node.mjs +16 -0
  193. package/dist/runtime/endpoints/node.mjs.map +1 -0
  194. package/dist/runtime/endpoints/single-route-helpers.cjs +130 -0
  195. package/dist/runtime/endpoints/single-route-helpers.cjs.map +1 -0
  196. package/dist/runtime/endpoints/single-route-helpers.mjs +125 -0
  197. package/dist/runtime/endpoints/single-route-helpers.mjs.map +1 -0
  198. package/dist/runtime/generative-ui/generative-ui-middleware.cjs +393 -0
  199. package/dist/runtime/generative-ui/generative-ui-middleware.cjs.map +1 -0
  200. package/dist/runtime/generative-ui/generative-ui-middleware.d.cts +20 -0
  201. package/dist/runtime/generative-ui/generative-ui-middleware.d.cts.map +1 -0
  202. package/dist/runtime/generative-ui/generative-ui-middleware.d.mts +20 -0
  203. package/dist/runtime/generative-ui/generative-ui-middleware.d.mts.map +1 -0
  204. package/dist/runtime/generative-ui/generative-ui-middleware.mjs +392 -0
  205. package/dist/runtime/generative-ui/generative-ui-middleware.mjs.map +1 -0
  206. package/dist/runtime/generative-ui/index.d.cts +2 -0
  207. package/dist/runtime/generative-ui/index.d.mts +2 -0
  208. package/dist/runtime/generative-ui/surface-writer.cjs +85 -0
  209. package/dist/runtime/generative-ui/surface-writer.cjs.map +1 -0
  210. package/dist/runtime/generative-ui/surface-writer.d.cts +32 -0
  211. package/dist/runtime/generative-ui/surface-writer.d.cts.map +1 -0
  212. package/dist/runtime/generative-ui/surface-writer.d.mts +32 -0
  213. package/dist/runtime/generative-ui/surface-writer.d.mts.map +1 -0
  214. package/dist/runtime/generative-ui/surface-writer.mjs +84 -0
  215. package/dist/runtime/generative-ui/surface-writer.mjs.map +1 -0
  216. package/dist/runtime/handlers/get-runtime-info.cjs +140 -0
  217. package/dist/runtime/handlers/get-runtime-info.cjs.map +1 -0
  218. package/dist/runtime/handlers/get-runtime-info.mjs +140 -0
  219. package/dist/runtime/handlers/get-runtime-info.mjs.map +1 -0
  220. package/dist/runtime/handlers/handle-connect.cjs +62 -0
  221. package/dist/runtime/handlers/handle-connect.cjs.map +1 -0
  222. package/dist/runtime/handlers/handle-connect.mjs +62 -0
  223. package/dist/runtime/handlers/handle-connect.mjs.map +1 -0
  224. package/dist/runtime/handlers/handle-debug-events.cjs +33 -0
  225. package/dist/runtime/handlers/handle-debug-events.cjs.map +1 -0
  226. package/dist/runtime/handlers/handle-debug-events.mjs +33 -0
  227. package/dist/runtime/handlers/handle-debug-events.mjs.map +1 -0
  228. package/dist/runtime/handlers/handle-inspector-learning.cjs +56 -0
  229. package/dist/runtime/handlers/handle-inspector-learning.cjs.map +1 -0
  230. package/dist/runtime/handlers/handle-inspector-learning.mjs +55 -0
  231. package/dist/runtime/handlers/handle-inspector-learning.mjs.map +1 -0
  232. package/dist/runtime/handlers/handle-inspector-metadata.cjs +36 -0
  233. package/dist/runtime/handlers/handle-inspector-metadata.cjs.map +1 -0
  234. package/dist/runtime/handlers/handle-inspector-metadata.mjs +35 -0
  235. package/dist/runtime/handlers/handle-inspector-metadata.mjs.map +1 -0
  236. package/dist/runtime/handlers/handle-run.cjs +111 -0
  237. package/dist/runtime/handlers/handle-run.cjs.map +1 -0
  238. package/dist/runtime/handlers/handle-run.mjs +110 -0
  239. package/dist/runtime/handlers/handle-run.mjs.map +1 -0
  240. package/dist/runtime/handlers/handle-stop.cjs +102 -0
  241. package/dist/runtime/handlers/handle-stop.cjs.map +1 -0
  242. package/dist/runtime/handlers/handle-stop.mjs +101 -0
  243. package/dist/runtime/handlers/handle-stop.mjs.map +1 -0
  244. package/dist/runtime/handlers/handle-suggest.cjs +83 -0
  245. package/dist/runtime/handlers/handle-suggest.cjs.map +1 -0
  246. package/dist/runtime/handlers/handle-suggest.mjs +82 -0
  247. package/dist/runtime/handlers/handle-suggest.mjs.map +1 -0
  248. package/dist/runtime/handlers/handle-trajectory-connect.cjs +40 -0
  249. package/dist/runtime/handlers/handle-trajectory-connect.cjs.map +1 -0
  250. package/dist/runtime/handlers/handle-trajectory-connect.mjs +39 -0
  251. package/dist/runtime/handlers/handle-trajectory-connect.mjs.map +1 -0
  252. package/dist/runtime/handlers/handle-transcribe.cjs +112 -0
  253. package/dist/runtime/handlers/handle-transcribe.cjs.map +1 -0
  254. package/dist/runtime/handlers/handle-transcribe.mjs +111 -0
  255. package/dist/runtime/handlers/handle-transcribe.mjs.map +1 -0
  256. package/dist/runtime/handlers/header-utils.cjs +185 -0
  257. package/dist/runtime/handlers/header-utils.cjs.map +1 -0
  258. package/dist/runtime/handlers/header-utils.d.cts +53 -0
  259. package/dist/runtime/handlers/header-utils.d.cts.map +1 -0
  260. package/dist/runtime/handlers/header-utils.d.mts +53 -0
  261. package/dist/runtime/handlers/header-utils.d.mts.map +1 -0
  262. package/dist/runtime/handlers/header-utils.mjs +183 -0
  263. package/dist/runtime/handlers/header-utils.mjs.map +1 -0
  264. package/dist/runtime/handlers/intelligence/annotate.cjs +83 -0
  265. package/dist/runtime/handlers/intelligence/annotate.cjs.map +1 -0
  266. package/dist/runtime/handlers/intelligence/annotate.mjs +82 -0
  267. package/dist/runtime/handlers/intelligence/annotate.mjs.map +1 -0
  268. package/dist/runtime/handlers/intelligence/connect.cjs +68 -0
  269. package/dist/runtime/handlers/intelligence/connect.cjs.map +1 -0
  270. package/dist/runtime/handlers/intelligence/connect.mjs +68 -0
  271. package/dist/runtime/handlers/intelligence/connect.mjs.map +1 -0
  272. package/dist/runtime/handlers/intelligence/memories.cjs +260 -0
  273. package/dist/runtime/handlers/intelligence/memories.cjs.map +1 -0
  274. package/dist/runtime/handlers/intelligence/memories.mjs +254 -0
  275. package/dist/runtime/handlers/intelligence/memories.mjs.map +1 -0
  276. package/dist/runtime/handlers/intelligence/run.cjs +283 -0
  277. package/dist/runtime/handlers/intelligence/run.cjs.map +1 -0
  278. package/dist/runtime/handlers/intelligence/run.mjs +282 -0
  279. package/dist/runtime/handlers/intelligence/run.mjs.map +1 -0
  280. package/dist/runtime/handlers/intelligence/thread-names.cjs +172 -0
  281. package/dist/runtime/handlers/intelligence/thread-names.cjs.map +1 -0
  282. package/dist/runtime/handlers/intelligence/thread-names.mjs +171 -0
  283. package/dist/runtime/handlers/intelligence/thread-names.mjs.map +1 -0
  284. package/dist/runtime/handlers/intelligence/threads.cjs +399 -0
  285. package/dist/runtime/handlers/intelligence/threads.cjs.map +1 -0
  286. package/dist/runtime/handlers/intelligence/threads.mjs +390 -0
  287. package/dist/runtime/handlers/intelligence/threads.mjs.map +1 -0
  288. package/dist/runtime/handlers/shared/agent-utils.cjs +267 -0
  289. package/dist/runtime/handlers/shared/agent-utils.cjs.map +1 -0
  290. package/dist/runtime/handlers/shared/agent-utils.mjs +262 -0
  291. package/dist/runtime/handlers/shared/agent-utils.mjs.map +1 -0
  292. package/dist/runtime/handlers/shared/cloud-telemetry.cjs +30 -0
  293. package/dist/runtime/handlers/shared/cloud-telemetry.cjs.map +1 -0
  294. package/dist/runtime/handlers/shared/cloud-telemetry.mjs +29 -0
  295. package/dist/runtime/handlers/shared/cloud-telemetry.mjs.map +1 -0
  296. package/dist/runtime/handlers/shared/describe-endpoint.cjs +25 -0
  297. package/dist/runtime/handlers/shared/describe-endpoint.cjs.map +1 -0
  298. package/dist/runtime/handlers/shared/describe-endpoint.mjs +24 -0
  299. package/dist/runtime/handlers/shared/describe-endpoint.mjs.map +1 -0
  300. package/dist/runtime/handlers/shared/intelligence-utils.cjs +24 -0
  301. package/dist/runtime/handlers/shared/intelligence-utils.cjs.map +1 -0
  302. package/dist/runtime/handlers/shared/intelligence-utils.mjs +23 -0
  303. package/dist/runtime/handlers/shared/intelligence-utils.mjs.map +1 -0
  304. package/dist/runtime/handlers/shared/json-response.cjs +14 -0
  305. package/dist/runtime/handlers/shared/json-response.cjs.map +1 -0
  306. package/dist/runtime/handlers/shared/json-response.mjs +12 -0
  307. package/dist/runtime/handlers/shared/json-response.mjs.map +1 -0
  308. package/dist/runtime/handlers/shared/mcp-apps-servers.cjs +22 -0
  309. package/dist/runtime/handlers/shared/mcp-apps-servers.cjs.map +1 -0
  310. package/dist/runtime/handlers/shared/mcp-apps-servers.mjs +22 -0
  311. package/dist/runtime/handlers/shared/mcp-apps-servers.mjs.map +1 -0
  312. package/dist/runtime/handlers/shared/memory-policy.cjs +78 -0
  313. package/dist/runtime/handlers/shared/memory-policy.cjs.map +1 -0
  314. package/dist/runtime/handlers/shared/memory-policy.mjs +77 -0
  315. package/dist/runtime/handlers/shared/memory-policy.mjs.map +1 -0
  316. package/dist/runtime/handlers/shared/platform-error.cjs +39 -0
  317. package/dist/runtime/handlers/shared/platform-error.cjs.map +1 -0
  318. package/dist/runtime/handlers/shared/platform-error.mjs +39 -0
  319. package/dist/runtime/handlers/shared/platform-error.mjs.map +1 -0
  320. package/dist/runtime/handlers/shared/resolve-intelligence-user.cjs +50 -0
  321. package/dist/runtime/handlers/shared/resolve-intelligence-user.cjs.map +1 -0
  322. package/dist/runtime/handlers/shared/resolve-intelligence-user.mjs +49 -0
  323. package/dist/runtime/handlers/shared/resolve-intelligence-user.mjs.map +1 -0
  324. package/dist/runtime/handlers/shared/sse-keep-alive.cjs +68 -0
  325. package/dist/runtime/handlers/shared/sse-keep-alive.cjs.map +1 -0
  326. package/dist/runtime/handlers/shared/sse-keep-alive.mjs +66 -0
  327. package/dist/runtime/handlers/shared/sse-keep-alive.mjs.map +1 -0
  328. package/dist/runtime/handlers/shared/sse-response.cjs +237 -0
  329. package/dist/runtime/handlers/shared/sse-response.cjs.map +1 -0
  330. package/dist/runtime/handlers/shared/sse-response.mjs +236 -0
  331. package/dist/runtime/handlers/shared/sse-response.mjs.map +1 -0
  332. package/dist/runtime/handlers/shared/thread-access.cjs +137 -0
  333. package/dist/runtime/handlers/shared/thread-access.cjs.map +1 -0
  334. package/dist/runtime/handlers/shared/thread-access.d.cts +28 -0
  335. package/dist/runtime/handlers/shared/thread-access.d.cts.map +1 -0
  336. package/dist/runtime/handlers/shared/thread-access.d.mts +28 -0
  337. package/dist/runtime/handlers/shared/thread-access.d.mts.map +1 -0
  338. package/dist/runtime/handlers/shared/thread-access.mjs +132 -0
  339. package/dist/runtime/handlers/shared/thread-access.mjs.map +1 -0
  340. package/dist/runtime/handlers/sse/connect.cjs +23 -0
  341. package/dist/runtime/handlers/sse/connect.cjs.map +1 -0
  342. package/dist/runtime/handlers/sse/connect.mjs +23 -0
  343. package/dist/runtime/handlers/sse/connect.mjs.map +1 -0
  344. package/dist/runtime/handlers/sse/run.cjs +44 -0
  345. package/dist/runtime/handlers/sse/run.cjs.map +1 -0
  346. package/dist/runtime/handlers/sse/run.mjs +44 -0
  347. package/dist/runtime/handlers/sse/run.mjs.map +1 -0
  348. package/dist/runtime/index.d.cts +29 -0
  349. package/dist/runtime/index.d.cts.map +1 -0
  350. package/dist/runtime/index.d.mts +29 -0
  351. package/dist/runtime/index.d.mts.map +1 -0
  352. package/dist/runtime/intelligence-platform/client.cjs +1338 -0
  353. package/dist/runtime/intelligence-platform/client.cjs.map +1 -0
  354. package/dist/runtime/intelligence-platform/client.d.cts +824 -0
  355. package/dist/runtime/intelligence-platform/client.d.cts.map +1 -0
  356. package/dist/runtime/intelligence-platform/client.d.mts +824 -0
  357. package/dist/runtime/intelligence-platform/client.d.mts.map +1 -0
  358. package/dist/runtime/intelligence-platform/client.mjs +1334 -0
  359. package/dist/runtime/intelligence-platform/client.mjs.map +1 -0
  360. package/dist/runtime/intelligence-platform/experimental.d.cts +26 -0
  361. package/dist/runtime/intelligence-platform/experimental.d.cts.map +1 -0
  362. package/dist/runtime/intelligence-platform/experimental.d.mts +26 -0
  363. package/dist/runtime/intelligence-platform/experimental.d.mts.map +1 -0
  364. package/dist/runtime/intelligence-platform/index.d.cts +3 -0
  365. package/dist/runtime/intelligence-platform/index.d.mts +3 -0
  366. package/dist/runtime/intelligence-platform/learned-skills.cjs +95 -0
  367. package/dist/runtime/intelligence-platform/learned-skills.cjs.map +1 -0
  368. package/dist/runtime/intelligence-platform/learned-skills.d.cts +43 -0
  369. package/dist/runtime/intelligence-platform/learned-skills.d.cts.map +1 -0
  370. package/dist/runtime/intelligence-platform/learned-skills.d.mts +43 -0
  371. package/dist/runtime/intelligence-platform/learned-skills.d.mts.map +1 -0
  372. package/dist/runtime/intelligence-platform/learned-skills.mjs +92 -0
  373. package/dist/runtime/intelligence-platform/learned-skills.mjs.map +1 -0
  374. package/dist/runtime/intelligence-platform/learning-management.cjs +203 -0
  375. package/dist/runtime/intelligence-platform/learning-management.cjs.map +1 -0
  376. package/dist/runtime/intelligence-platform/learning-management.d.cts +111 -0
  377. package/dist/runtime/intelligence-platform/learning-management.d.cts.map +1 -0
  378. package/dist/runtime/intelligence-platform/learning-management.d.mts +111 -0
  379. package/dist/runtime/intelligence-platform/learning-management.d.mts.map +1 -0
  380. package/dist/runtime/intelligence-platform/learning-management.mjs +193 -0
  381. package/dist/runtime/intelligence-platform/learning-management.mjs.map +1 -0
  382. package/dist/runtime/intelligence-platform/skill-registry/archive.cjs +131 -0
  383. package/dist/runtime/intelligence-platform/skill-registry/archive.cjs.map +1 -0
  384. package/dist/runtime/intelligence-platform/skill-registry/archive.d.cts +10 -0
  385. package/dist/runtime/intelligence-platform/skill-registry/archive.d.cts.map +1 -0
  386. package/dist/runtime/intelligence-platform/skill-registry/archive.d.mts +10 -0
  387. package/dist/runtime/intelligence-platform/skill-registry/archive.d.mts.map +1 -0
  388. package/dist/runtime/intelligence-platform/skill-registry/archive.mjs +127 -0
  389. package/dist/runtime/intelligence-platform/skill-registry/archive.mjs.map +1 -0
  390. package/dist/runtime/intelligence-platform/skill-registry/config.cjs +65 -0
  391. package/dist/runtime/intelligence-platform/skill-registry/config.cjs.map +1 -0
  392. package/dist/runtime/intelligence-platform/skill-registry/config.d.cts +47 -0
  393. package/dist/runtime/intelligence-platform/skill-registry/config.d.cts.map +1 -0
  394. package/dist/runtime/intelligence-platform/skill-registry/config.d.mts +47 -0
  395. package/dist/runtime/intelligence-platform/skill-registry/config.d.mts.map +1 -0
  396. package/dist/runtime/intelligence-platform/skill-registry/config.mjs +65 -0
  397. package/dist/runtime/intelligence-platform/skill-registry/config.mjs.map +1 -0
  398. package/dist/runtime/intelligence-platform/skill-registry/errors.cjs +10 -0
  399. package/dist/runtime/intelligence-platform/skill-registry/errors.cjs.map +1 -0
  400. package/dist/runtime/intelligence-platform/skill-registry/errors.d.cts +7 -0
  401. package/dist/runtime/intelligence-platform/skill-registry/errors.d.cts.map +1 -0
  402. package/dist/runtime/intelligence-platform/skill-registry/errors.d.mts +7 -0
  403. package/dist/runtime/intelligence-platform/skill-registry/errors.d.mts.map +1 -0
  404. package/dist/runtime/intelligence-platform/skill-registry/errors.mjs +10 -0
  405. package/dist/runtime/intelligence-platform/skill-registry/errors.mjs.map +1 -0
  406. package/dist/runtime/intelligence-platform/skill-registry/index.d.cts +7 -0
  407. package/dist/runtime/intelligence-platform/skill-registry/index.d.mts +7 -0
  408. package/dist/runtime/intelligence-platform/skill-registry/registry.cjs +247 -0
  409. package/dist/runtime/intelligence-platform/skill-registry/registry.cjs.map +1 -0
  410. package/dist/runtime/intelligence-platform/skill-registry/registry.d.cts +36 -0
  411. package/dist/runtime/intelligence-platform/skill-registry/registry.d.cts.map +1 -0
  412. package/dist/runtime/intelligence-platform/skill-registry/registry.d.mts +36 -0
  413. package/dist/runtime/intelligence-platform/skill-registry/registry.d.mts.map +1 -0
  414. package/dist/runtime/intelligence-platform/skill-registry/registry.mjs +246 -0
  415. package/dist/runtime/intelligence-platform/skill-registry/registry.mjs.map +1 -0
  416. package/dist/runtime/intelligence-platform/skill-registry/skill-content.cjs +41 -0
  417. package/dist/runtime/intelligence-platform/skill-registry/skill-content.cjs.map +1 -0
  418. package/dist/runtime/intelligence-platform/skill-registry/skill-content.d.cts +12 -0
  419. package/dist/runtime/intelligence-platform/skill-registry/skill-content.d.cts.map +1 -0
  420. package/dist/runtime/intelligence-platform/skill-registry/skill-content.d.mts +12 -0
  421. package/dist/runtime/intelligence-platform/skill-registry/skill-content.d.mts.map +1 -0
  422. package/dist/runtime/intelligence-platform/skill-registry/skill-content.mjs +38 -0
  423. package/dist/runtime/intelligence-platform/skill-registry/skill-content.mjs.map +1 -0
  424. package/dist/runtime/intelligence-platform/skill-registry/snapshot.cjs +92 -0
  425. package/dist/runtime/intelligence-platform/skill-registry/snapshot.cjs.map +1 -0
  426. package/dist/runtime/intelligence-platform/skill-registry/snapshot.d.cts +27 -0
  427. package/dist/runtime/intelligence-platform/skill-registry/snapshot.d.cts.map +1 -0
  428. package/dist/runtime/intelligence-platform/skill-registry/snapshot.d.mts +27 -0
  429. package/dist/runtime/intelligence-platform/skill-registry/snapshot.d.mts.map +1 -0
  430. package/dist/runtime/intelligence-platform/skill-registry/snapshot.mjs +91 -0
  431. package/dist/runtime/intelligence-platform/skill-registry/snapshot.mjs.map +1 -0
  432. package/dist/runtime/intelligence-platform/thread-lock-heartbeat.cjs +142 -0
  433. package/dist/runtime/intelligence-platform/thread-lock-heartbeat.cjs.map +1 -0
  434. package/dist/runtime/intelligence-platform/thread-lock-heartbeat.mjs +141 -0
  435. package/dist/runtime/intelligence-platform/thread-lock-heartbeat.mjs.map +1 -0
  436. package/dist/runtime/intelligence-platform/trajectories.cjs +95 -0
  437. package/dist/runtime/intelligence-platform/trajectories.cjs.map +1 -0
  438. package/dist/runtime/intelligence-platform/trajectories.d.cts +11 -0
  439. package/dist/runtime/intelligence-platform/trajectories.d.cts.map +1 -0
  440. package/dist/runtime/intelligence-platform/trajectories.d.mts +11 -0
  441. package/dist/runtime/intelligence-platform/trajectories.d.mts.map +1 -0
  442. package/dist/runtime/intelligence-platform/trajectories.mjs +91 -0
  443. package/dist/runtime/intelligence-platform/trajectories.mjs.map +1 -0
  444. package/dist/runtime/node.d.cts +2 -0
  445. package/dist/runtime/node.d.mts +2 -0
  446. package/dist/runtime/runner/agent-runner.cjs +82 -0
  447. package/dist/runtime/runner/agent-runner.cjs.map +1 -0
  448. package/dist/runtime/runner/agent-runner.d.cts +151 -0
  449. package/dist/runtime/runner/agent-runner.d.cts.map +1 -0
  450. package/dist/runtime/runner/agent-runner.d.mts +151 -0
  451. package/dist/runtime/runner/agent-runner.d.mts.map +1 -0
  452. package/dist/runtime/runner/agent-runner.mjs +73 -0
  453. package/dist/runtime/runner/agent-runner.mjs.map +1 -0
  454. package/dist/runtime/runner/in-memory.cjs +741 -0
  455. package/dist/runtime/runner/in-memory.cjs.map +1 -0
  456. package/dist/runtime/runner/in-memory.d.cts +427 -0
  457. package/dist/runtime/runner/in-memory.d.cts.map +1 -0
  458. package/dist/runtime/runner/in-memory.d.mts +427 -0
  459. package/dist/runtime/runner/in-memory.d.mts.map +1 -0
  460. package/dist/runtime/runner/in-memory.mjs +734 -0
  461. package/dist/runtime/runner/in-memory.mjs.map +1 -0
  462. package/dist/runtime/runner/index.d.cts +5 -0
  463. package/dist/runtime/runner/index.d.mts +5 -0
  464. package/dist/runtime/runner/index.mjs +6 -0
  465. package/dist/runtime/runner/intelligence.cjs +617 -0
  466. package/dist/runtime/runner/intelligence.cjs.map +1 -0
  467. package/dist/runtime/runner/intelligence.d.cts +104 -0
  468. package/dist/runtime/runner/intelligence.d.cts.map +1 -0
  469. package/dist/runtime/runner/intelligence.d.mts +104 -0
  470. package/dist/runtime/runner/intelligence.d.mts.map +1 -0
  471. package/dist/runtime/runner/intelligence.mjs +616 -0
  472. package/dist/runtime/runner/intelligence.mjs.map +1 -0
  473. package/dist/runtime/telemetry/disclosure.cjs +25 -0
  474. package/dist/runtime/telemetry/disclosure.cjs.map +1 -0
  475. package/dist/runtime/telemetry/disclosure.mjs +24 -0
  476. package/dist/runtime/telemetry/disclosure.mjs.map +1 -0
  477. package/dist/runtime/telemetry/events.d.cts +66 -0
  478. package/dist/runtime/telemetry/events.d.cts.map +1 -0
  479. package/dist/runtime/telemetry/events.d.mts +66 -0
  480. package/dist/runtime/telemetry/events.d.mts.map +1 -0
  481. package/dist/runtime/telemetry/instance-created.cjs +34 -0
  482. package/dist/runtime/telemetry/instance-created.cjs.map +1 -0
  483. package/dist/runtime/telemetry/instance-created.mjs +34 -0
  484. package/dist/runtime/telemetry/instance-created.mjs.map +1 -0
  485. package/dist/runtime/telemetry/telemetry-client.cjs +108 -0
  486. package/dist/runtime/telemetry/telemetry-client.cjs.map +1 -0
  487. package/dist/runtime/telemetry/telemetry-client.d.cts +10 -0
  488. package/dist/runtime/telemetry/telemetry-client.d.cts.map +1 -0
  489. package/dist/runtime/telemetry/telemetry-client.d.mts +10 -0
  490. package/dist/runtime/telemetry/telemetry-client.d.mts.map +1 -0
  491. package/dist/runtime/telemetry/telemetry-client.mjs +107 -0
  492. package/dist/runtime/telemetry/telemetry-client.mjs.map +1 -0
  493. package/dist/runtime/telemetry/telemetry-identity.cjs +12 -0
  494. package/dist/runtime/telemetry/telemetry-identity.cjs.map +1 -0
  495. package/dist/runtime/telemetry/telemetry-identity.mjs +11 -0
  496. package/dist/runtime/telemetry/telemetry-identity.mjs.map +1 -0
  497. package/dist/runtime/transcription-service/transcription-service.cjs +7 -0
  498. package/dist/runtime/transcription-service/transcription-service.cjs.map +1 -0
  499. package/dist/runtime/transcription-service/transcription-service.d.cts +14 -0
  500. package/dist/runtime/transcription-service/transcription-service.d.cts.map +1 -0
  501. package/dist/runtime/transcription-service/transcription-service.d.mts +14 -0
  502. package/dist/runtime/transcription-service/transcription-service.d.mts.map +1 -0
  503. package/dist/runtime/transcription-service/transcription-service.mjs +6 -0
  504. package/dist/runtime/transcription-service/transcription-service.mjs.map +1 -0
  505. package/package.json +104 -105
  506. package/.eslintrc.js +0 -7
  507. package/CHANGELOG.md +0 -2920
  508. package/__snapshots__/schema/schema.graphql +0 -371
  509. package/dist/index.d.ts +0 -1494
  510. package/dist/index.js +0 -5641
  511. package/dist/index.js.map +0 -1
  512. package/dist/index.mjs.map +0 -1
  513. package/dist/langgraph.d.ts +0 -284
  514. package/dist/langgraph.js +0 -211
  515. package/dist/langgraph.js.map +0 -1
  516. package/dist/langgraph.mjs +0 -206
  517. package/dist/langgraph.mjs.map +0 -1
  518. package/dist/v2/index.d.ts +0 -2
  519. package/dist/v2/index.js +0 -22
  520. package/dist/v2/index.js.map +0 -1
  521. package/dist/v2/index.mjs +0 -5
  522. package/dist/v2/index.mjs.map +0 -1
  523. package/jest.config.js +0 -10
  524. package/scripts/generate-gql-schema.ts +0 -13
  525. package/src/agents/langgraph/event-source.ts +0 -329
  526. package/src/agents/langgraph/events.ts +0 -377
  527. package/src/graphql/inputs/action.input.ts +0 -16
  528. package/src/graphql/inputs/agent-session.input.ts +0 -13
  529. package/src/graphql/inputs/agent-state.input.ts +0 -13
  530. package/src/graphql/inputs/cloud-guardrails.input.ts +0 -16
  531. package/src/graphql/inputs/cloud.input.ts +0 -8
  532. package/src/graphql/inputs/context-property.input.ts +0 -10
  533. package/src/graphql/inputs/copilot-context.input.ts +0 -10
  534. package/src/graphql/inputs/custom-property.input.ts +0 -15
  535. package/src/graphql/inputs/extensions.input.ts +0 -21
  536. package/src/graphql/inputs/forwarded-parameters.input.ts +0 -22
  537. package/src/graphql/inputs/frontend.input.ts +0 -14
  538. package/src/graphql/inputs/generate-copilot-response.input.ts +0 -59
  539. package/src/graphql/inputs/load-agent-state.input.ts +0 -10
  540. package/src/graphql/inputs/message.input.ts +0 -110
  541. package/src/graphql/inputs/meta-event.input.ts +0 -18
  542. package/src/graphql/message-conversion/agui-to-gql.test.ts +0 -1263
  543. package/src/graphql/message-conversion/agui-to-gql.ts +0 -333
  544. package/src/graphql/message-conversion/gql-to-agui.test.ts +0 -1580
  545. package/src/graphql/message-conversion/gql-to-agui.ts +0 -278
  546. package/src/graphql/message-conversion/index.ts +0 -2
  547. package/src/graphql/message-conversion/roundtrip-conversion.test.ts +0 -526
  548. package/src/graphql/resolvers/copilot.resolver.ts +0 -708
  549. package/src/graphql/resolvers/state.resolver.ts +0 -27
  550. package/src/graphql/types/agents-response.type.ts +0 -19
  551. package/src/graphql/types/base/index.ts +0 -10
  552. package/src/graphql/types/converted/index.ts +0 -176
  553. package/src/graphql/types/copilot-response.type.ts +0 -138
  554. package/src/graphql/types/enums.ts +0 -38
  555. package/src/graphql/types/extensions-response.type.ts +0 -23
  556. package/src/graphql/types/guardrails-result.type.ts +0 -20
  557. package/src/graphql/types/load-agent-state-response.type.ts +0 -17
  558. package/src/graphql/types/message-status.type.ts +0 -42
  559. package/src/graphql/types/meta-events.type.ts +0 -71
  560. package/src/graphql/types/response-status.type.ts +0 -66
  561. package/src/index.ts +0 -4
  562. package/src/langgraph.ts +0 -1
  563. package/src/lib/cloud/index.ts +0 -4
  564. package/src/lib/error-messages.ts +0 -200
  565. package/src/lib/index.ts +0 -52
  566. package/src/lib/integrations/index.ts +0 -6
  567. package/src/lib/integrations/nest/index.ts +0 -14
  568. package/src/lib/integrations/nextjs/app-router.ts +0 -38
  569. package/src/lib/integrations/nextjs/pages-router.ts +0 -39
  570. package/src/lib/integrations/node-express/index.ts +0 -14
  571. package/src/lib/integrations/node-http/index.ts +0 -143
  572. package/src/lib/integrations/node-http/request-handler.ts +0 -111
  573. package/src/lib/integrations/shared.ts +0 -161
  574. package/src/lib/logger.ts +0 -28
  575. package/src/lib/observability.ts +0 -160
  576. package/src/lib/runtime/__tests__/copilot-runtime-error.test.ts +0 -169
  577. package/src/lib/runtime/__tests__/mcp-tools-utils.test.ts +0 -464
  578. package/src/lib/runtime/agent-integrations/langgraph/agent.ts +0 -209
  579. package/src/lib/runtime/agent-integrations/langgraph/consts.ts +0 -34
  580. package/src/lib/runtime/agent-integrations/langgraph/index.ts +0 -2
  581. package/src/lib/runtime/copilot-runtime.ts +0 -710
  582. package/src/lib/runtime/mcp-tools-utils.ts +0 -254
  583. package/src/lib/runtime/retry-utils.ts +0 -96
  584. package/src/lib/runtime/telemetry-agent-runner.ts +0 -139
  585. package/src/lib/runtime/types.ts +0 -49
  586. package/src/lib/runtime/utils.ts +0 -87
  587. package/src/lib/streaming.ts +0 -202
  588. package/src/lib/telemetry-client.ts +0 -64
  589. package/src/service-adapters/anthropic/anthropic-adapter.ts +0 -452
  590. package/src/service-adapters/anthropic/utils.ts +0 -152
  591. package/src/service-adapters/bedrock/bedrock-adapter.ts +0 -73
  592. package/src/service-adapters/conversion.ts +0 -67
  593. package/src/service-adapters/empty/empty-adapter.ts +0 -38
  594. package/src/service-adapters/events.ts +0 -294
  595. package/src/service-adapters/experimental/ollama/ollama-adapter.ts +0 -84
  596. package/src/service-adapters/google/google-genai-adapter.test.ts +0 -104
  597. package/src/service-adapters/google/google-genai-adapter.ts +0 -88
  598. package/src/service-adapters/groq/groq-adapter.ts +0 -203
  599. package/src/service-adapters/index.ts +0 -18
  600. package/src/service-adapters/langchain/langchain-adapter.ts +0 -111
  601. package/src/service-adapters/langchain/langserve.ts +0 -88
  602. package/src/service-adapters/langchain/types.ts +0 -14
  603. package/src/service-adapters/langchain/utils.ts +0 -313
  604. package/src/service-adapters/openai/openai-adapter.ts +0 -283
  605. package/src/service-adapters/openai/openai-assistant-adapter.ts +0 -344
  606. package/src/service-adapters/openai/utils.ts +0 -199
  607. package/src/service-adapters/service-adapter.ts +0 -41
  608. package/src/service-adapters/shared/error-utils.ts +0 -61
  609. package/src/service-adapters/shared/index.ts +0 -1
  610. package/src/service-adapters/unify/unify-adapter.ts +0 -151
  611. package/src/utils/failed-response-status-reasons.ts +0 -70
  612. package/src/utils/index.ts +0 -1
  613. package/src/v2/index.ts +0 -3
  614. package/tests/global.d.ts +0 -13
  615. package/tests/service-adapters/anthropic/allowlist-approach.test.ts +0 -226
  616. package/tests/service-adapters/anthropic/anthropic-adapter.test.ts +0 -389
  617. package/tests/service-adapters/openai/allowlist-approach.test.ts +0 -238
  618. package/tests/service-adapters/openai/openai-adapter.test.ts +0 -301
  619. package/tests/setup.jest.ts +0 -21
  620. package/tests/tsconfig.json +0 -10
  621. package/tsconfig.json +0 -13
  622. package/tsup.config.ts +0 -20
  623. package/typedoc.json +0 -4
@@ -0,0 +1,260 @@
1
+ const require_runtime = require('../../../_virtual/_rolldown/runtime.cjs');
2
+ const require_json_response = require('../shared/json-response.cjs');
3
+ const require_resolve_intelligence_user = require('../shared/resolve-intelligence-user.cjs');
4
+ const require_runtime$1 = require('../../core/runtime.cjs');
5
+ const require_memory_policy = require('../shared/memory-policy.cjs');
6
+ const require_platform_error = require('../shared/platform-error.cjs');
7
+ let _copilotkit_shared = require("@copilotkit/shared");
8
+
9
+ //#region src/runtime/handlers/intelligence/memories.ts
10
+ async function resolveClientMemory(runtime, request) {
11
+ const user = await require_resolve_intelligence_user.resolveIntelligenceUser({
12
+ runtime,
13
+ request
14
+ });
15
+ if (require_json_response.isHandlerResponse(user)) return user;
16
+ const access = await require_memory_policy.resolveWebMemory(runtime, request, user, "client");
17
+ if (require_json_response.isHandlerResponse(access)) return access;
18
+ if (runtime.memory && !require_memory_policy.grantAllowsMemory(access.grant)) return require_json_response.errorResponse("Memory access denied", 403);
19
+ return access;
20
+ }
21
+ const MISSING_INTELLIGENCE_MESSAGE = "Missing CopilotKitIntelligence configuration. Memory operations require a CopilotKitIntelligence instance to be provided in CopilotRuntime options.";
22
+ /** Allowed `kind` vocabulary the platform's memory endpoints accept. */
23
+ const MEMORY_KINDS = new Set([
24
+ "topical",
25
+ "episodic",
26
+ "operational"
27
+ ]);
28
+ /** Allowed `scope` vocabulary the platform's memory endpoints accept. */
29
+ const MEMORY_SCOPES = new Set(["user", "project"]);
30
+ /**
31
+ * Maps a thrown error to a `Response`.
32
+ *
33
+ * The reasoning now lives with the implementation in
34
+ * `../shared/platform-error`, which the thread handlers share. This alias is
35
+ * kept so the many call sites below read the same as they always did.
36
+ */
37
+ const memoryErrorResponse = require_platform_error.platformErrorResponse;
38
+ async function parseJsonBody(request) {
39
+ try {
40
+ return await request.json();
41
+ } catch (error) {
42
+ _copilotkit_shared.logger.error({ err: error }, "Malformed JSON in memory request body");
43
+ return require_json_response.errorResponse("Invalid request body", 400);
44
+ }
45
+ }
46
+ /**
47
+ * Extracts and validates the create/supersede body fields the platform's
48
+ * memory endpoints require. Returns a `Response` (400) on invalid input.
49
+ */
50
+ function parseMemoryBody(body) {
51
+ const { content, kind, scope, sourceThreadIds } = body;
52
+ if (typeof content !== "string" || typeof kind !== "string") return require_json_response.errorResponse("Memory requires string `content` and `kind`", 400);
53
+ if (!MEMORY_KINDS.has(kind)) return require_json_response.errorResponse("Memory `kind` must be one of: topical, episodic, operational", 400);
54
+ if (scope !== void 0 && typeof scope !== "string") return require_json_response.errorResponse("Memory `scope` must be a string when provided", 400);
55
+ if (typeof scope === "string" && !MEMORY_SCOPES.has(scope)) return require_json_response.errorResponse("Memory `scope` must be one of: user, project", 400);
56
+ if (sourceThreadIds !== void 0 && (!Array.isArray(sourceThreadIds) || !sourceThreadIds.every((id) => typeof id === "string"))) return require_json_response.errorResponse("Memory `sourceThreadIds` must be an array of strings when provided", 400);
57
+ return {
58
+ content,
59
+ kind,
60
+ ...typeof scope === "string" ? { scope } : {},
61
+ ...Array.isArray(sourceThreadIds) ? { sourceThreadIds } : {}
62
+ };
63
+ }
64
+ /**
65
+ * Validates the recall body: `query` required non-empty string (trimmed);
66
+ * `limit` optional finite positive integer; `scope` optional and in the known
67
+ * scopes. Returns a 400 Response on invalid input. The returned `query` is the
68
+ * trimmed value so a whitespace-padded query is never forwarded to the platform.
69
+ */
70
+ function parseRecallBody(body) {
71
+ const { query, limit, scope } = body;
72
+ const trimmedQuery = typeof query === "string" ? query.trim() : query;
73
+ if (typeof trimmedQuery !== "string" || trimmedQuery.length === 0) return require_json_response.errorResponse("Recall requires a non-empty string `query`", 400);
74
+ if (limit !== void 0 && !(typeof limit === "number" && Number.isInteger(limit) && limit > 0)) return require_json_response.errorResponse("Recall `limit` must be a positive integer", 400);
75
+ if (scope !== void 0 && typeof scope !== "string") return require_json_response.errorResponse("Recall `scope` must be a string when provided", 400);
76
+ if (typeof scope === "string" && !MEMORY_SCOPES.has(scope)) return require_json_response.errorResponse("Recall `scope` must be one of: user, project", 400);
77
+ return {
78
+ query: trimmedQuery,
79
+ ...typeof limit === "number" ? { limit } : {},
80
+ ...typeof scope === "string" ? { scope } : {}
81
+ };
82
+ }
83
+ /**
84
+ * Lists the resolved user's long-term memories via CopilotKit Intelligence.
85
+ *
86
+ * Mirrors {@link handleListThreads}: requires a `CopilotKitIntelligence`
87
+ * runtime, resolves the user with `identifyUser` (never trusting a
88
+ * client-supplied id), and proxies to the platform's `GET /api/memories`
89
+ * with the project API key + resolved user. The `?includeInvalidated=true`
90
+ * query is forwarded so callers can opt into retired rows. The response is
91
+ * the platform's `{ memories }` envelope, which the client memory store
92
+ * consumes directly.
93
+ */
94
+ async function handleListMemories({ runtime, request }) {
95
+ if (require_runtime$1.isIntelligenceRuntime(runtime)) try {
96
+ const includeInvalidated = new URL(request.url).searchParams.get("includeInvalidated") === "true";
97
+ const access = await resolveClientMemory(runtime, request);
98
+ if (require_json_response.isHandlerResponse(access)) return access;
99
+ const data = await runtime.intelligence.listMemories({
100
+ userId: access.user.id,
101
+ ...runtime.memory ? { memoryGrant: access.grant } : {},
102
+ ...includeInvalidated ? { includeInvalidated: true } : {}
103
+ });
104
+ if (data == null || typeof data !== "object" || !Array.isArray(data.memories)) {
105
+ _copilotkit_shared.logger.error({ data }, "listMemories: platform returned a response without a `memories` array");
106
+ return require_json_response.errorResponse("Memory platform returned an invalid list response", 502);
107
+ }
108
+ return Response.json(data);
109
+ } catch (error) {
110
+ _copilotkit_shared.logger.error({ err: error }, "Error listing memories");
111
+ return memoryErrorResponse(error, "Failed to list memories");
112
+ }
113
+ return require_json_response.errorResponse(MISSING_INTELLIGENCE_MESSAGE, 422);
114
+ }
115
+ /**
116
+ * Semantically recalls the resolved user's memories via the platform (`POST
117
+ * /api/memories/recall`, hybrid RAG). Mirrors {@link handleListMemories}:
118
+ * requires a `CopilotKitIntelligence` runtime, resolves the user with
119
+ * `identifyUser` (never a client-supplied id), proxies with the project API
120
+ * key + resolved user. Body `{ query, limit?, scope? }`; response `{ memories }`,
121
+ * each optionally carrying `score`.
122
+ */
123
+ async function handleRecallMemories({ runtime, request }) {
124
+ if (!require_runtime$1.isIntelligenceRuntime(runtime)) return require_json_response.errorResponse(MISSING_INTELLIGENCE_MESSAGE, 422);
125
+ try {
126
+ const body = await parseJsonBody(request);
127
+ if (require_json_response.isHandlerResponse(body)) return body;
128
+ const fields = parseRecallBody(body);
129
+ if (require_json_response.isHandlerResponse(fields)) return fields;
130
+ const access = await resolveClientMemory(runtime, request);
131
+ if (require_json_response.isHandlerResponse(access)) return access;
132
+ const data = await runtime.intelligence.recallMemories({
133
+ userId: access.user.id,
134
+ ...runtime.memory ? { memoryGrant: access.grant } : {},
135
+ ...fields
136
+ });
137
+ if (data == null || typeof data !== "object" || !Array.isArray(data.memories)) {
138
+ _copilotkit_shared.logger.error({ data }, "recallMemories: platform returned a response without a `memories` array");
139
+ return require_json_response.errorResponse("Memory platform returned an invalid recall response", 502);
140
+ }
141
+ return Response.json(data);
142
+ } catch (error) {
143
+ _copilotkit_shared.logger.error({ err: error }, "Error recalling memories");
144
+ return memoryErrorResponse(error, "Failed to recall memories");
145
+ }
146
+ }
147
+ /**
148
+ * Mints memory-realtime join credentials (platform `POST
149
+ * /api/memories/subscribe`). Mirrors {@link handleSubscribeToThreads}: requires
150
+ * a `CopilotKitIntelligence` runtime and resolves the user with `identifyUser`
151
+ * (never a client-supplied id). Returns `{ joinToken, joinCode }` — memory needs
152
+ * the `joinCode` here (unlike threads, where it rides the thread-list response)
153
+ * because the client builds the `user_meta:memories:<joinCode>` channel topic
154
+ * from it.
155
+ *
156
+ * When the platform also resolves a project scope, the response additionally
157
+ * carries `projectJoinToken` / `projectJoinCode`, which the client uses to open
158
+ * a second `project_meta:memories:<projectJoinCode>` channel. These are
159
+ * optional: absent project scope → both fields are omitted (silent-degrade
160
+ * contract; the client opens only the user channel).
161
+ */
162
+ async function handleSubscribeToMemories({ runtime, request }) {
163
+ if (require_runtime$1.isIntelligenceRuntime(runtime)) try {
164
+ const access = await resolveClientMemory(runtime, request);
165
+ if (require_json_response.isHandlerResponse(access)) return access;
166
+ const credentials = await runtime.intelligence.ɵsubscribeToMemories({
167
+ userId: access.user.id,
168
+ ...runtime.memory ? { memoryGrant: access.grant } : {}
169
+ });
170
+ return Response.json({
171
+ ...credentials.joinToken !== void 0 ? { joinToken: credentials.joinToken } : {},
172
+ ...credentials.joinCode !== void 0 ? { joinCode: credentials.joinCode } : {},
173
+ ...credentials.projectJoinToken !== void 0 ? { projectJoinToken: credentials.projectJoinToken } : {},
174
+ ...credentials.projectJoinCode !== void 0 ? { projectJoinCode: credentials.projectJoinCode } : {}
175
+ });
176
+ } catch (error) {
177
+ _copilotkit_shared.logger.error({ err: error }, "Error subscribing to memories");
178
+ return memoryErrorResponse(error, "Failed to subscribe to memories");
179
+ }
180
+ return require_json_response.errorResponse(MISSING_INTELLIGENCE_MESSAGE, 422);
181
+ }
182
+ /**
183
+ * Creates a memory for the resolved user (platform `POST /api/memories`).
184
+ * Identity comes from `identifyUser`, never the request body. Returns 201
185
+ * with the stored memory (the client store applies it server-authoritatively).
186
+ */
187
+ async function handleCreateMemory({ runtime, request }) {
188
+ if (!require_runtime$1.isIntelligenceRuntime(runtime)) return require_json_response.errorResponse(MISSING_INTELLIGENCE_MESSAGE, 422);
189
+ try {
190
+ const body = await parseJsonBody(request);
191
+ if (require_json_response.isHandlerResponse(body)) return body;
192
+ const fields = parseMemoryBody(body);
193
+ if (require_json_response.isHandlerResponse(fields)) return fields;
194
+ const access = await resolveClientMemory(runtime, request);
195
+ if (require_json_response.isHandlerResponse(access)) return access;
196
+ const data = await runtime.intelligence.createMemory({
197
+ userId: access.user.id,
198
+ ...runtime.memory ? { memoryGrant: access.grant } : {},
199
+ ...fields
200
+ });
201
+ return Response.json(data, { status: 201 });
202
+ } catch (error) {
203
+ _copilotkit_shared.logger.error({ err: error }, "Error creating memory");
204
+ return memoryErrorResponse(error, "Failed to create memory");
205
+ }
206
+ }
207
+ /**
208
+ * Supersedes a memory (platform `PATCH /api/memories/:id`): retires `:id` and
209
+ * inserts the new content atomically; the response carries `retiredId`.
210
+ */
211
+ async function handleUpdateMemory({ runtime, request, memoryId }) {
212
+ if (!require_runtime$1.isIntelligenceRuntime(runtime)) return require_json_response.errorResponse(MISSING_INTELLIGENCE_MESSAGE, 422);
213
+ try {
214
+ const body = await parseJsonBody(request);
215
+ if (require_json_response.isHandlerResponse(body)) return body;
216
+ const fields = parseMemoryBody(body);
217
+ if (require_json_response.isHandlerResponse(fields)) return fields;
218
+ const access = await resolveClientMemory(runtime, request);
219
+ if (require_json_response.isHandlerResponse(access)) return access;
220
+ const data = await runtime.intelligence.updateMemory({
221
+ userId: access.user.id,
222
+ ...runtime.memory ? { memoryGrant: access.grant } : {},
223
+ id: memoryId,
224
+ ...fields
225
+ });
226
+ return Response.json(data);
227
+ } catch (error) {
228
+ _copilotkit_shared.logger.error({ err: error }, "Error updating memory");
229
+ return memoryErrorResponse(error, "Failed to update memory");
230
+ }
231
+ }
232
+ /**
233
+ * Retires (forgets) a memory (platform `DELETE /api/memories/:id`). Non-lossy
234
+ * on the platform side; returns 204.
235
+ */
236
+ async function handleRemoveMemory({ runtime, request, memoryId }) {
237
+ if (!require_runtime$1.isIntelligenceRuntime(runtime)) return require_json_response.errorResponse(MISSING_INTELLIGENCE_MESSAGE, 422);
238
+ try {
239
+ const access = await resolveClientMemory(runtime, request);
240
+ if (require_json_response.isHandlerResponse(access)) return access;
241
+ await runtime.intelligence.removeMemory({
242
+ userId: access.user.id,
243
+ id: memoryId,
244
+ ...runtime.memory ? { memoryGrant: access.grant } : {}
245
+ });
246
+ return new Response(null, { status: 204 });
247
+ } catch (error) {
248
+ _copilotkit_shared.logger.error({ err: error }, "Error removing memory");
249
+ return memoryErrorResponse(error, "Failed to remove memory");
250
+ }
251
+ }
252
+
253
+ //#endregion
254
+ exports.handleCreateMemory = handleCreateMemory;
255
+ exports.handleListMemories = handleListMemories;
256
+ exports.handleRecallMemories = handleRecallMemories;
257
+ exports.handleRemoveMemory = handleRemoveMemory;
258
+ exports.handleSubscribeToMemories = handleSubscribeToMemories;
259
+ exports.handleUpdateMemory = handleUpdateMemory;
260
+ //# sourceMappingURL=memories.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"memories.cjs","names":["resolveIntelligenceUser","isHandlerResponse","resolveWebMemory","grantAllowsMemory","errorResponse","platformErrorResponse","isIntelligenceRuntime"],"sources":["../../../../src/runtime/handlers/intelligence/memories.ts"],"sourcesContent":["import type {\n CopilotIntelligenceRuntimeLike,\n CopilotRuntimeLike,\n} from \"../../core/runtime\";\nimport { isIntelligenceRuntime } from \"../../core/runtime\";\nimport { logger } from \"@copilotkit/shared\";\nimport { errorResponse, isHandlerResponse } from \"../shared/json-response\";\nimport { resolveIntelligenceUser } from \"../shared/resolve-intelligence-user\";\nimport { grantAllowsMemory, resolveWebMemory } from \"../shared/memory-policy\";\nimport { platformErrorResponse } from \"../shared/platform-error\";\n\ninterface MemoriesHandlerParams {\n runtime: CopilotRuntimeLike;\n request: Request;\n}\n\ninterface MemoryMutationParams extends MemoriesHandlerParams {\n memoryId: string;\n}\n\nasync function resolveClientMemory(\n runtime: CopilotIntelligenceRuntimeLike,\n request: Request,\n) {\n const user = await resolveIntelligenceUser({ runtime, request });\n if (isHandlerResponse(user)) return user;\n const access = await resolveWebMemory(runtime, request, user, \"client\");\n if (isHandlerResponse(access)) return access;\n // Unlike an agent run — which proceeds without Memory tools when the policy\n // grants nothing — these routes exist ONLY to serve memories. A caller who\n // asked for them and may not have them gets 403; an empty list would imply\n // there are none, which is a different and false claim.\n if (runtime.memory && !grantAllowsMemory(access.grant)) {\n return errorResponse(\"Memory access denied\", 403);\n }\n return access;\n}\n\nconst MISSING_INTELLIGENCE_MESSAGE =\n \"Missing CopilotKitIntelligence configuration. Memory operations require a CopilotKitIntelligence instance to be provided in CopilotRuntime options.\";\n\n/** Allowed `kind` vocabulary the platform's memory endpoints accept. */\nconst MEMORY_KINDS: ReadonlySet<string> = new Set([\n \"topical\",\n \"episodic\",\n \"operational\",\n]);\n/** Allowed `scope` vocabulary the platform's memory endpoints accept. */\nconst MEMORY_SCOPES: ReadonlySet<string> = new Set([\"user\", \"project\"]);\n\n/**\n * Maps a thrown error to a `Response`.\n *\n * The reasoning now lives with the implementation in\n * `../shared/platform-error`, which the thread handlers share. This alias is\n * kept so the many call sites below read the same as they always did.\n */\nconst memoryErrorResponse = platformErrorResponse;\n\nasync function parseJsonBody(\n request: Request,\n): Promise<Record<string, unknown> | Response> {\n try {\n return (await request.json()) as Record<string, unknown>;\n } catch (error) {\n logger.error({ err: error }, \"Malformed JSON in memory request body\");\n return errorResponse(\"Invalid request body\", 400);\n }\n}\n\n/**\n * Extracts and validates the create/supersede body fields the platform's\n * memory endpoints require. Returns a `Response` (400) on invalid input.\n */\nfunction parseMemoryBody(body: Record<string, unknown>):\n | {\n content: string;\n kind: string;\n scope?: string;\n sourceThreadIds?: string[];\n }\n | Response {\n const { content, kind, scope, sourceThreadIds } = body;\n if (typeof content !== \"string\" || typeof kind !== \"string\") {\n return errorResponse(\"Memory requires string `content` and `kind`\", 400);\n }\n // `kind` must be one of the platform's known kinds. Reject an out-of-vocabulary\n // value here rather than forwarding it for the platform to reject.\n if (!MEMORY_KINDS.has(kind)) {\n return errorResponse(\n \"Memory `kind` must be one of: topical, episodic, operational\",\n 400,\n );\n }\n // `scope` is optional: when omitted the platform applies its default\n // (`\"user\"`). Only reject a present-but-wrong-typed scope.\n if (scope !== undefined && typeof scope !== \"string\") {\n return errorResponse(\"Memory `scope` must be a string when provided\", 400);\n }\n // When `scope` is present, it must be one of the known scopes.\n if (typeof scope === \"string\" && !MEMORY_SCOPES.has(scope)) {\n return errorResponse(\"Memory `scope` must be one of: user, project\", 400);\n }\n // `sourceThreadIds` is optional, but when present it must be a string array.\n // Validate every element so non-string ids are not forwarded to the platform.\n if (\n sourceThreadIds !== undefined &&\n (!Array.isArray(sourceThreadIds) ||\n !sourceThreadIds.every((id) => typeof id === \"string\"))\n ) {\n return errorResponse(\n \"Memory `sourceThreadIds` must be an array of strings when provided\",\n 400,\n );\n }\n return {\n content,\n kind,\n ...(typeof scope === \"string\" ? { scope } : {}),\n ...(Array.isArray(sourceThreadIds)\n ? { sourceThreadIds: sourceThreadIds as string[] }\n : {}),\n // `sourceThreadIds` elements are validated as strings above; the cast is safe.\n };\n}\n\n/**\n * Validates the recall body: `query` required non-empty string (trimmed);\n * `limit` optional finite positive integer; `scope` optional and in the known\n * scopes. Returns a 400 Response on invalid input. The returned `query` is the\n * trimmed value so a whitespace-padded query is never forwarded to the platform.\n */\nfunction parseRecallBody(\n body: Record<string, unknown>,\n): { query: string; limit?: number; scope?: string } | Response {\n const { query, limit, scope } = body;\n // Trim before the emptiness check so whitespace-only queries (e.g. \" \")\n // are rejected rather than forwarded as a useless query to the platform.\n const trimmedQuery = typeof query === \"string\" ? query.trim() : query;\n if (typeof trimmedQuery !== \"string\" || trimmedQuery.length === 0) {\n return errorResponse(\"Recall requires a non-empty string `query`\", 400);\n }\n // When provided, `limit` must be a finite positive integer. `Number.isInteger`\n // already rejects NaN, Infinity, and fractions (NaN/Infinity would otherwise\n // JSON-serialize to `null` and silently corrupt the forwarded request);\n // the `> 0` guard rejects zero and negatives.\n if (\n limit !== undefined &&\n !(typeof limit === \"number\" && Number.isInteger(limit) && limit > 0)\n ) {\n return errorResponse(\"Recall `limit` must be a positive integer\", 400);\n }\n if (scope !== undefined && typeof scope !== \"string\") {\n return errorResponse(\"Recall `scope` must be a string when provided\", 400);\n }\n if (typeof scope === \"string\" && !MEMORY_SCOPES.has(scope)) {\n return errorResponse(\"Recall `scope` must be one of: user, project\", 400);\n }\n return {\n query: trimmedQuery,\n ...(typeof limit === \"number\" ? { limit } : {}),\n ...(typeof scope === \"string\" ? { scope } : {}),\n };\n}\n\n/**\n * Lists the resolved user's long-term memories via CopilotKit Intelligence.\n *\n * Mirrors {@link handleListThreads}: requires a `CopilotKitIntelligence`\n * runtime, resolves the user with `identifyUser` (never trusting a\n * client-supplied id), and proxies to the platform's `GET /api/memories`\n * with the project API key + resolved user. The `?includeInvalidated=true`\n * query is forwarded so callers can opt into retired rows. The response is\n * the platform's `{ memories }` envelope, which the client memory store\n * consumes directly.\n */\nexport async function handleListMemories({\n runtime,\n request,\n}: MemoriesHandlerParams): Promise<Response> {\n if (isIntelligenceRuntime(runtime)) {\n try {\n const url = new URL(request.url);\n const includeInvalidated =\n url.searchParams.get(\"includeInvalidated\") === \"true\";\n\n const access = await resolveClientMemory(runtime, request);\n if (isHandlerResponse(access)) return access;\n\n const data = await runtime.intelligence.listMemories({\n userId: access.user.id,\n ...(runtime.memory ? { memoryGrant: access.grant } : {}),\n ...(includeInvalidated ? { includeInvalidated: true } : {}),\n });\n\n // The client memory store consumes the `{ memories: [...] }` envelope\n // directly. Assert the shape before forwarding so a platform contract\n // violation surfaces as a clear 502 (the runtime is healthy but its\n // dependency returned the wrong shape) instead of a 200 the client will\n // choke on.\n if (\n data == null ||\n typeof data !== \"object\" ||\n !Array.isArray((data as { memories?: unknown }).memories)\n ) {\n logger.error(\n { data },\n \"listMemories: platform returned a response without a `memories` array\",\n );\n return errorResponse(\n \"Memory platform returned an invalid list response\",\n 502,\n );\n }\n\n return Response.json(data);\n } catch (error) {\n logger.error({ err: error }, \"Error listing memories\");\n return memoryErrorResponse(error, \"Failed to list memories\");\n }\n }\n\n return errorResponse(MISSING_INTELLIGENCE_MESSAGE, 422);\n}\n\n/**\n * Semantically recalls the resolved user's memories via the platform (`POST\n * /api/memories/recall`, hybrid RAG). Mirrors {@link handleListMemories}:\n * requires a `CopilotKitIntelligence` runtime, resolves the user with\n * `identifyUser` (never a client-supplied id), proxies with the project API\n * key + resolved user. Body `{ query, limit?, scope? }`; response `{ memories }`,\n * each optionally carrying `score`.\n */\nexport async function handleRecallMemories({\n runtime,\n request,\n}: MemoriesHandlerParams): Promise<Response> {\n if (!isIntelligenceRuntime(runtime)) {\n return errorResponse(MISSING_INTELLIGENCE_MESSAGE, 422);\n }\n try {\n const body = await parseJsonBody(request);\n if (isHandlerResponse(body)) return body;\n const fields = parseRecallBody(body);\n if (isHandlerResponse(fields)) return fields;\n\n const access = await resolveClientMemory(runtime, request);\n if (isHandlerResponse(access)) return access;\n\n const data = await runtime.intelligence.recallMemories({\n userId: access.user.id,\n ...(runtime.memory ? { memoryGrant: access.grant } : {}),\n ...fields,\n });\n\n if (\n data == null ||\n typeof data !== \"object\" ||\n !Array.isArray((data as { memories?: unknown }).memories)\n ) {\n logger.error(\n { data },\n \"recallMemories: platform returned a response without a `memories` array\",\n );\n return errorResponse(\n \"Memory platform returned an invalid recall response\",\n 502,\n );\n }\n return Response.json(data);\n } catch (error) {\n logger.error({ err: error }, \"Error recalling memories\");\n return memoryErrorResponse(error, \"Failed to recall memories\");\n }\n}\n\n/**\n * Mints memory-realtime join credentials (platform `POST\n * /api/memories/subscribe`). Mirrors {@link handleSubscribeToThreads}: requires\n * a `CopilotKitIntelligence` runtime and resolves the user with `identifyUser`\n * (never a client-supplied id). Returns `{ joinToken, joinCode }` — memory needs\n * the `joinCode` here (unlike threads, where it rides the thread-list response)\n * because the client builds the `user_meta:memories:<joinCode>` channel topic\n * from it.\n *\n * When the platform also resolves a project scope, the response additionally\n * carries `projectJoinToken` / `projectJoinCode`, which the client uses to open\n * a second `project_meta:memories:<projectJoinCode>` channel. These are\n * optional: absent project scope → both fields are omitted (silent-degrade\n * contract; the client opens only the user channel).\n */\nexport async function handleSubscribeToMemories({\n runtime,\n request,\n}: MemoriesHandlerParams): Promise<Response> {\n if (isIntelligenceRuntime(runtime)) {\n try {\n const access = await resolveClientMemory(runtime, request);\n if (isHandlerResponse(access)) return access;\n\n const credentials = await runtime.intelligence.ɵsubscribeToMemories({\n userId: access.user.id,\n ...(runtime.memory ? { memoryGrant: access.grant } : {}),\n });\n\n return Response.json({\n ...(credentials.joinToken !== undefined\n ? { joinToken: credentials.joinToken }\n : {}),\n ...(credentials.joinCode !== undefined\n ? { joinCode: credentials.joinCode }\n : {}),\n // Project-scoped credentials ride along only when the platform minted\n // them; omit both when absent (silent-degrade contract).\n ...(credentials.projectJoinToken !== undefined\n ? { projectJoinToken: credentials.projectJoinToken }\n : {}),\n ...(credentials.projectJoinCode !== undefined\n ? { projectJoinCode: credentials.projectJoinCode }\n : {}),\n });\n } catch (error) {\n logger.error({ err: error }, \"Error subscribing to memories\");\n return memoryErrorResponse(error, \"Failed to subscribe to memories\");\n }\n }\n\n return errorResponse(MISSING_INTELLIGENCE_MESSAGE, 422);\n}\n\n/**\n * Creates a memory for the resolved user (platform `POST /api/memories`).\n * Identity comes from `identifyUser`, never the request body. Returns 201\n * with the stored memory (the client store applies it server-authoritatively).\n */\nexport async function handleCreateMemory({\n runtime,\n request,\n}: MemoriesHandlerParams): Promise<Response> {\n if (!isIntelligenceRuntime(runtime)) {\n return errorResponse(MISSING_INTELLIGENCE_MESSAGE, 422);\n }\n try {\n const body = await parseJsonBody(request);\n if (isHandlerResponse(body)) return body;\n const fields = parseMemoryBody(body);\n if (isHandlerResponse(fields)) return fields;\n\n const access = await resolveClientMemory(runtime, request);\n if (isHandlerResponse(access)) return access;\n\n const data = await runtime.intelligence.createMemory({\n userId: access.user.id,\n ...(runtime.memory ? { memoryGrant: access.grant } : {}),\n ...fields,\n });\n return Response.json(data, { status: 201 });\n } catch (error) {\n logger.error({ err: error }, \"Error creating memory\");\n return memoryErrorResponse(error, \"Failed to create memory\");\n }\n}\n\n/**\n * Supersedes a memory (platform `PATCH /api/memories/:id`): retires `:id` and\n * inserts the new content atomically; the response carries `retiredId`.\n */\nexport async function handleUpdateMemory({\n runtime,\n request,\n memoryId,\n}: MemoryMutationParams): Promise<Response> {\n if (!isIntelligenceRuntime(runtime)) {\n return errorResponse(MISSING_INTELLIGENCE_MESSAGE, 422);\n }\n try {\n const body = await parseJsonBody(request);\n if (isHandlerResponse(body)) return body;\n const fields = parseMemoryBody(body);\n if (isHandlerResponse(fields)) return fields;\n\n const access = await resolveClientMemory(runtime, request);\n if (isHandlerResponse(access)) return access;\n\n const data = await runtime.intelligence.updateMemory({\n userId: access.user.id,\n ...(runtime.memory ? { memoryGrant: access.grant } : {}),\n id: memoryId,\n ...fields,\n });\n return Response.json(data);\n } catch (error) {\n logger.error({ err: error }, \"Error updating memory\");\n return memoryErrorResponse(error, \"Failed to update memory\");\n }\n}\n\n/**\n * Retires (forgets) a memory (platform `DELETE /api/memories/:id`). Non-lossy\n * on the platform side; returns 204.\n */\nexport async function handleRemoveMemory({\n runtime,\n request,\n memoryId,\n}: MemoryMutationParams): Promise<Response> {\n if (!isIntelligenceRuntime(runtime)) {\n return errorResponse(MISSING_INTELLIGENCE_MESSAGE, 422);\n }\n try {\n const access = await resolveClientMemory(runtime, request);\n if (isHandlerResponse(access)) return access;\n\n await runtime.intelligence.removeMemory({\n userId: access.user.id,\n id: memoryId,\n ...(runtime.memory ? { memoryGrant: access.grant } : {}),\n });\n return new Response(null, { status: 204 });\n } catch (error) {\n logger.error({ err: error }, \"Error removing memory\");\n return memoryErrorResponse(error, \"Failed to remove memory\");\n }\n}\n"],"mappings":";;;;;;;;;AAoBA,eAAe,oBACb,SACA,SACA;CACA,MAAM,O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HandlerResponse } from "../shared/json-response.mjs";
2
+ import { resolveIntelligenceUser } from "../shared/resolve-intelligence-user.mjs";
3
+ import { isIntelligenceRuntime } from "../../core/runtime.mjs";
4
+ import { grantAllowsMemory, resolveWebMemory } from "../shared/memory-policy.mjs";
5
+ import { platformErrorResponse } from "../shared/platform-error.mjs";
6
+ import { logger } from "@copilotkit/shared";
7
+
8
+ //#region src/runtime/handlers/intelligence/memories.ts
9
+ async function resolveClientMemory(runtime, request) {
10
+ const user = await resolveIntelligenceUser({
11
+ runtime,
12
+ request
13
+ });
14
+ if (isHandlerResponse(user)) return user;
15
+ const access = await resolveWebMemory(runtime, request, user, "client");
16
+ if (isHandlerResponse(access)) return access;
17
+ if (runtime.memory && !grantAllowsMemory(access.grant)) return errorResponse("Memory access denied", 403);
18
+ return access;
19
+ }
20
+ const MISSING_INTELLIGENCE_MESSAGE = "Missing CopilotKitIntelligence configuration. Memory operations require a CopilotKitIntelligence instance to be provided in CopilotRuntime options.";
21
+ /** Allowed `kind` vocabulary the platform's memory endpoints accept. */
22
+ const MEMORY_KINDS = new Set([
23
+ "topical",
24
+ "episodic",
25
+ "operational"
26
+ ]);
27
+ /** Allowed `scope` vocabulary the platform's memory endpoints accept. */
28
+ const MEMORY_SCOPES = new Set(["user", "project"]);
29
+ /**
30
+ * Maps a thrown error to a `Response`.
31
+ *
32
+ * The reasoning now lives with the implementation in
33
+ * `../shared/platform-error`, which the thread handlers share. This alias is
34
+ * kept so the many call sites below read the same as they always did.
35
+ */
36
+ const memoryErrorResponse = platformErrorResponse;
37
+ async function parseJsonBody(request) {
38
+ try {
39
+ return await request.json();
40
+ } catch (error) {
41
+ logger.error({ err: error }, "Malformed JSON in memory request body");
42
+ return errorResponse("Invalid request body", 400);
43
+ }
44
+ }
45
+ /**
46
+ * Extracts and validates the create/supersede body fields the platform's
47
+ * memory endpoints require. Returns a `Response` (400) on invalid input.
48
+ */
49
+ function parseMemoryBody(body) {
50
+ const { content, kind, scope, sourceThreadIds } = body;
51
+ if (typeof content !== "string" || typeof kind !== "string") return errorResponse("Memory requires string `content` and `kind`", 400);
52
+ if (!MEMORY_KINDS.has(kind)) return errorResponse("Memory `kind` must be one of: topical, episodic, operational", 400);
53
+ if (scope !== void 0 && typeof scope !== "string") return errorResponse("Memory `scope` must be a string when provided", 400);
54
+ if (typeof scope === "string" && !MEMORY_SCOPES.has(scope)) return errorResponse("Memory `scope` must be one of: user, project", 400);
55
+ if (sourceThreadIds !== void 0 && (!Array.isArray(sourceThreadIds) || !sourceThreadIds.every((id) => typeof id === "string"))) return errorResponse("Memory `sourceThreadIds` must be an array of strings when provided", 400);
56
+ return {
57
+ content,
58
+ kind,
59
+ ...typeof scope === "string" ? { scope } : {},
60
+ ...Array.isArray(sourceThreadIds) ? { sourceThreadIds } : {}
61
+ };
62
+ }
63
+ /**
64
+ * Validates the recall body: `query` required non-empty string (trimmed);
65
+ * `limit` optional finite positive integer; `scope` optional and in the known
66
+ * scopes. Returns a 400 Response on invalid input. The returned `query` is the
67
+ * trimmed value so a whitespace-padded query is never forwarded to the platform.
68
+ */
69
+ function parseRecallBody(body) {
70
+ const { query, limit, scope } = body;
71
+ const trimmedQuery = typeof query === "string" ? query.trim() : query;
72
+ if (typeof trimmedQuery !== "string" || trimmedQuery.length === 0) return errorResponse("Recall requires a non-empty string `query`", 400);
73
+ if (limit !== void 0 && !(typeof limit === "number" && Number.isInteger(limit) && limit > 0)) return errorResponse("Recall `limit` must be a positive integer", 400);
74
+ if (scope !== void 0 && typeof scope !== "string") return errorResponse("Recall `scope` must be a string when provided", 400);
75
+ if (typeof scope === "string" && !MEMORY_SCOPES.has(scope)) return errorResponse("Recall `scope` must be one of: user, project", 400);
76
+ return {
77
+ query: trimmedQuery,
78
+ ...typeof limit === "number" ? { limit } : {},
79
+ ...typeof scope === "string" ? { scope } : {}
80
+ };
81
+ }
82
+ /**
83
+ * Lists the resolved user's long-term memories via CopilotKit Intelligence.
84
+ *
85
+ * Mirrors {@link handleListThreads}: requires a `CopilotKitIntelligence`
86
+ * runtime, resolves the user with `identifyUser` (never trusting a
87
+ * client-supplied id), and proxies to the platform's `GET /api/memories`
88
+ * with the project API key + resolved user. The `?includeInvalidated=true`
89
+ * query is forwarded so callers can opt into retired rows. The response is
90
+ * the platform's `{ memories }` envelope, which the client memory store
91
+ * consumes directly.
92
+ */
93
+ async function handleListMemories({ runtime, request }) {
94
+ if (isIntelligenceRuntime(runtime)) try {
95
+ const includeInvalidated = new URL(request.url).searchParams.get("includeInvalidated") === "true";
96
+ const access = await resolveClientMemory(runtime, request);
97
+ if (isHandlerResponse(access)) return access;
98
+ const data = await runtime.intelligence.listMemories({
99
+ userId: access.user.id,
100
+ ...runtime.memory ? { memoryGrant: access.grant } : {},
101
+ ...includeInvalidated ? { includeInvalidated: true } : {}
102
+ });
103
+ if (data == null || typeof data !== "object" || !Array.isArray(data.memories)) {
104
+ logger.error({ data }, "listMemories: platform returned a response without a `memories` array");
105
+ return errorResponse("Memory platform returned an invalid list response", 502);
106
+ }
107
+ return Response.json(data);
108
+ } catch (error) {
109
+ logger.error({ err: error }, "Error listing memories");
110
+ return memoryErrorResponse(error, "Failed to list memories");
111
+ }
112
+ return errorResponse(MISSING_INTELLIGENCE_MESSAGE, 422);
113
+ }
114
+ /**
115
+ * Semantically recalls the resolved user's memories via the platform (`POST
116
+ * /api/memories/recall`, hybrid RAG). Mirrors {@link handleListMemories}:
117
+ * requires a `CopilotKitIntelligence` runtime, resolves the user with
118
+ * `identifyUser` (never a client-supplied id), proxies with the project API
119
+ * key + resolved user. Body `{ query, limit?, scope? }`; response `{ memories }`,
120
+ * each optionally carrying `score`.
121
+ */
122
+ async function handleRecallMemories({ runtime, request }) {
123
+ if (!isIntelligenceRuntime(runtime)) return errorResponse(MISSING_INTELLIGENCE_MESSAGE, 422);
124
+ try {
125
+ const body = await parseJsonBody(request);
126
+ if (isHandlerResponse(body)) return body;
127
+ const fields = parseRecallBody(body);
128
+ if (isHandlerResponse(fields)) return fields;
129
+ const access = await resolveClientMemory(runtime, request);
130
+ if (isHandlerResponse(access)) return access;
131
+ const data = await runtime.intelligence.recallMemories({
132
+ userId: access.user.id,
133
+ ...runtime.memory ? { memoryGrant: access.grant } : {},
134
+ ...fields
135
+ });
136
+ if (data == null || typeof data !== "object" || !Array.isArray(data.memories)) {
137
+ logger.error({ data }, "recallMemories: platform returned a response without a `memories` array");
138
+ return errorResponse("Memory platform returned an invalid recall response", 502);
139
+ }
140
+ return Response.json(data);
141
+ } catch (error) {
142
+ logger.error({ err: error }, "Error recalling memories");
143
+ return memoryErrorResponse(error, "Failed to recall memories");
144
+ }
145
+ }
146
+ /**
147
+ * Mints memory-realtime join credentials (platform `POST
148
+ * /api/memories/subscribe`). Mirrors {@link handleSubscribeToThreads}: requires
149
+ * a `CopilotKitIntelligence` runtime and resolves the user with `identifyUser`
150
+ * (never a client-supplied id). Returns `{ joinToken, joinCode }` — memory needs
151
+ * the `joinCode` here (unlike threads, where it rides the thread-list response)
152
+ * because the client builds the `user_meta:memories:<joinCode>` channel topic
153
+ * from it.
154
+ *
155
+ * When the platform also resolves a project scope, the response additionally
156
+ * carries `projectJoinToken` / `projectJoinCode`, which the client uses to open
157
+ * a second `project_meta:memories:<projectJoinCode>` channel. These are
158
+ * optional: absent project scope → both fields are omitted (silent-degrade
159
+ * contract; the client opens only the user channel).
160
+ */
161
+ async function handleSubscribeToMemories({ runtime, request }) {
162
+ if (isIntelligenceRuntime(runtime)) try {
163
+ const access = await resolveClientMemory(runtime, request);
164
+ if (isHandlerResponse(access)) return access;
165
+ const credentials = await runtime.intelligence.ɵsubscribeToMemories({
166
+ userId: access.user.id,
167
+ ...runtime.memory ? { memoryGrant: access.grant } : {}
168
+ });
169
+ return Response.json({
170
+ ...credentials.joinToken !== void 0 ? { joinToken: credentials.joinToken } : {},
171
+ ...credentials.joinCode !== void 0 ? { joinCode: credentials.joinCode } : {},
172
+ ...credentials.projectJoinToken !== void 0 ? { projectJoinToken: credentials.projectJoinToken } : {},
173
+ ...credentials.projectJoinCode !== void 0 ? { projectJoinCode: credentials.projectJoinCode } : {}
174
+ });
175
+ } catch (error) {
176
+ logger.error({ err: error }, "Error subscribing to memories");
177
+ return memoryErrorResponse(error, "Failed to subscribe to memories");
178
+ }
179
+ return errorResponse(MISSING_INTELLIGENCE_MESSAGE, 422);
180
+ }
181
+ /**
182
+ * Creates a memory for the resolved user (platform `POST /api/memories`).
183
+ * Identity comes from `identifyUser`, never the request body. Returns 201
184
+ * with the stored memory (the client store applies it server-authoritatively).
185
+ */
186
+ async function handleCreateMemory({ runtime, request }) {
187
+ if (!isIntelligenceRuntime(runtime)) return errorResponse(MISSING_INTELLIGENCE_MESSAGE, 422);
188
+ try {
189
+ const body = await parseJsonBody(request);
190
+ if (isHandlerResponse(body)) return body;
191
+ const fields = parseMemoryBody(body);
192
+ if (isHandlerResponse(fields)) return fields;
193
+ const access = await resolveClientMemory(runtime, request);
194
+ if (isHandlerResponse(access)) return access;
195
+ const data = await runtime.intelligence.createMemory({
196
+ userId: access.user.id,
197
+ ...runtime.memory ? { memoryGrant: access.grant } : {},
198
+ ...fields
199
+ });
200
+ return Response.json(data, { status: 201 });
201
+ } catch (error) {
202
+ logger.error({ err: error }, "Error creating memory");
203
+ return memoryErrorResponse(error, "Failed to create memory");
204
+ }
205
+ }
206
+ /**
207
+ * Supersedes a memory (platform `PATCH /api/memories/:id`): retires `:id` and
208
+ * inserts the new content atomically; the response carries `retiredId`.
209
+ */
210
+ async function handleUpdateMemory({ runtime, request, memoryId }) {
211
+ if (!isIntelligenceRuntime(runtime)) return errorResponse(MISSING_INTELLIGENCE_MESSAGE, 422);
212
+ try {
213
+ const body = await parseJsonBody(request);
214
+ if (isHandlerResponse(body)) return body;
215
+ const fields = parseMemoryBody(body);
216
+ if (isHandlerResponse(fields)) return fields;
217
+ const access = await resolveClientMemory(runtime, request);
218
+ if (isHandlerResponse(access)) return access;
219
+ const data = await runtime.intelligence.updateMemory({
220
+ userId: access.user.id,
221
+ ...runtime.memory ? { memoryGrant: access.grant } : {},
222
+ id: memoryId,
223
+ ...fields
224
+ });
225
+ return Response.json(data);
226
+ } catch (error) {
227
+ logger.error({ err: error }, "Error updating memory");
228
+ return memoryErrorResponse(error, "Failed to update memory");
229
+ }
230
+ }
231
+ /**
232
+ * Retires (forgets) a memory (platform `DELETE /api/memories/:id`). Non-lossy
233
+ * on the platform side; returns 204.
234
+ */
235
+ async function handleRemoveMemory({ runtime, request, memoryId }) {
236
+ if (!isIntelligenceRuntime(runtime)) return errorResponse(MISSING_INTELLIGENCE_MESSAGE, 422);
237
+ try {
238
+ const access = await resolveClientMemory(runtime, request);
239
+ if (isHandlerResponse(access)) return access;
240
+ await runtime.intelligence.removeMemory({
241
+ userId: access.user.id,
242
+ id: memoryId,
243
+ ...runtime.memory ? { memoryGrant: access.grant } : {}
244
+ });
245
+ return new Response(null, { status: 204 });
246
+ } catch (error) {
247
+ logger.error({ err: error }, "Error removing memory");
248
+ return memoryErrorResponse(error, "Failed to remove memory");
249
+ }
250
+ }
251
+
252
+ //#endregion
253
+ export { handleCreateMemory, handleListMemories, handleRecallMemories, handleRemoveMemory, handleSubscribeToMemories, handleUpdateMemory };
254
+ //# sourceMappingURL=memories.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"memories.mjs","names":[],"sources":["../../../../src/runtime/handlers/intelligence/memories.ts"],"sourcesContent":["import type {\n CopilotIntelligenceRuntimeLike,\n CopilotRuntimeLike,\n} from \"../../core/runtime\";\nimport { isIntelligenceRuntime } from \"../../core/runtime\";\nimport { logger } from \"@copilotkit/shared\";\nimport { errorResponse, isHandlerResponse } from \"../shared/json-response\";\nimport { resolveIntelligenceUser } from \"../shared/resolve-intelligence-user\";\nimport { grantAllowsMemory, resolveWebMemory } from \"../shared/memory-policy\";\nimport { platformErrorResponse } from \"../shared/platform-error\";\n\ninterface MemoriesHandlerParams {\n runtime: CopilotRuntimeLike;\n request: Request;\n}\n\ninterface MemoryMutationParams extends MemoriesHandlerParams {\n memoryId: string;\n}\n\nasync function resolveClientMemory(\n runtime: CopilotIntelligenceRuntimeLike,\n request: Request,\n) {\n const user = await resolveIntelligenceUser({ runtime, request });\n if (isHandlerResponse(user)) return user;\n const access = await resolveWebMemory(runtime, request, user, \"client\");\n if (isHandlerResponse(access)) return access;\n // Unlike an agent run — which proceeds without Memory tools when the policy\n // grants nothing — these routes exist ONLY to serve memories. A caller who\n // asked for them and may not have them gets 403; an empty list would imply\n // there are none, which is a different and false claim.\n if (runtime.memory && !grantAllowsMemory(access.grant)) {\n return errorResponse(\"Memory access denied\", 403);\n }\n return access;\n}\n\nconst MISSING_INTELLIGENCE_MESSAGE =\n \"Missing CopilotKitIntelligence configuration. Memory operations require a CopilotKitIntelligence instance to be provided in CopilotRuntime options.\";\n\n/** Allowed `kind` vocabulary the platform's memory endpoints accept. */\nconst MEMORY_KINDS: ReadonlySet<string> = new Set([\n \"topical\",\n \"episodic\",\n \"operational\",\n]);\n/** Allowed `scope` vocabulary the platform's memory endpoints accept. */\nconst MEMORY_SCOPES: ReadonlySet<string> = new Set([\"user\", \"project\"]);\n\n/**\n * Maps a thrown error to a `Response`.\n *\n * The reasoning now lives with the implementation in\n * `../shared/platform-error`, which the thread handlers share. This alias is\n * kept so the many call sites below read the same as they always did.\n */\nconst memoryErrorResponse = platformErrorResponse;\n\nasync function parseJsonBody(\n request: Request,\n): Promise<Record<string, unknown> | Response> {\n try {\n return (await request.json()) as Record<string, unknown>;\n } catch (error) {\n logger.error({ err: error }, \"Malformed JSON in memory request body\");\n return errorResponse(\"Invalid request body\", 400);\n }\n}\n\n/**\n * Extracts and validates the create/supersede body fields the platform's\n * memory endpoints require. Returns a `Response` (400) on invalid input.\n */\nfunction parseMemoryBody(body: Record<string, unknown>):\n | {\n content: string;\n kind: string;\n scope?: string;\n sourceThreadIds?: string[];\n }\n | Response {\n const { content, kind, scope, sourceThreadIds } = body;\n if (typeof content !== \"string\" || typeof kind !== \"string\") {\n return errorResponse(\"Memory requires string `content` and `kind`\", 400);\n }\n // `kind` must be one of the platform's known kinds. Reject an out-of-vocabulary\n // value here rather than forwarding it for the platform to reject.\n if (!MEMORY_KINDS.has(kind)) {\n return errorResponse(\n \"Memory `kind` must be one of: topical, episodic, operational\",\n 400,\n );\n }\n // `scope` is optional: when omitted the platform applies its default\n // (`\"user\"`). Only reject a present-but-wrong-typed scope.\n if (scope !== undefined && typeof scope !== \"string\") {\n return errorResponse(\"Memory `scope` must be a string when provided\", 400);\n }\n // When `scope` is present, it must be one of the known scopes.\n if (typeof scope === \"string\" && !MEMORY_SCOPES.has(scope)) {\n return errorResponse(\"Memory `scope` must be one of: user, project\", 400);\n }\n // `sourceThreadIds` is optional, but when present it must be a string array.\n // Validate every element so non-string ids are not forwarded to the platform.\n if (\n sourceThreadIds !== undefined &&\n (!Array.isArray(sourceThreadIds) ||\n !sourceThreadIds.every((id) => typeof id === \"string\"))\n ) {\n return errorResponse(\n \"Memory `sourceThreadIds` must be an array of strings when provided\",\n 400,\n );\n }\n return {\n content,\n kind,\n ...(typeof scope === \"string\" ? { scope } : {}),\n ...(Array.isArray(sourceThreadIds)\n ? { sourceThreadIds: sourceThreadIds as string[] }\n : {}),\n // `sourceThreadIds` elements are validated as strings above; the cast is safe.\n };\n}\n\n/**\n * Validates the recall body: `query` required non-empty string (trimmed);\n * `limit` optional finite positive integer; `scope` optional and in the known\n * scopes. Returns a 400 Response on invalid input. The returned `query` is the\n * trimmed value so a whitespace-padded query is never forwarded to the platform.\n */\nfunction parseRecallBody(\n body: Record<string, unknown>,\n): { query: string; limit?: number; scope?: string } | Response {\n const { query, limit, scope } = body;\n // Trim before the emptiness check so whitespace-only queries (e.g. \" \")\n // are rejected rather than forwarded as a useless query to the platform.\n const trimmedQuery = typeof query === \"string\" ? query.trim() : query;\n if (typeof trimmedQuery !== \"string\" || trimmedQuery.length === 0) {\n return errorResponse(\"Recall requires a non-empty string `query`\", 400);\n }\n // When provided, `limit` must be a finite positive integer. `Number.isInteger`\n // already rejects NaN, Infinity, and fractions (NaN/Infinity would otherwise\n // JSON-serialize to `null` and silently corrupt the forwarded request);\n // the `> 0` guard rejects zero and negatives.\n if (\n limit !== undefined &&\n !(typeof limit === \"number\" && Number.isInteger(limit) && limit > 0)\n ) {\n return errorResponse(\"Recall `limit` must be a positive integer\", 400);\n }\n if (scope !== undefined && typeof scope !== \"string\") {\n return errorResponse(\"Recall `scope` must be a string when provided\", 400);\n }\n if (typeof scope === \"string\" && !MEMORY_SCOPES.has(scope)) {\n return errorResponse(\"Recall `scope` must be one of: user, project\", 400);\n }\n return {\n query: trimmedQuery,\n ...(typeof limit === \"number\" ? { limit } : {}),\n ...(typeof scope === \"string\" ? { scope } : {}),\n };\n}\n\n/**\n * Lists the resolved user's long-term memories via CopilotKit Intelligence.\n *\n * Mirrors {@link handleListThreads}: requires a `CopilotKitIntelligence`\n * runtime, resolves the user with `identifyUser` (never trusting a\n * client-supplied id), and proxies to the platform's `GET /api/memories`\n * with the project API key + resolved user. The `?includeInvalidated=true`\n * query is forwarded so callers can opt into retired rows. The response is\n * the platform's `{ memories }` envelope, which the client memory store\n * consumes directly.\n */\nexport async function handleListMemories({\n runtime,\n request,\n}: MemoriesHandlerParams): Promise<Response> {\n if (isIntelligenceRuntime(runtime)) {\n try {\n const url = new URL(request.url);\n const includeInvalidated =\n url.searchParams.get(\"includeInvalidated\") === \"true\";\n\n const access = await resolveClientMemory(runtime, request);\n if (isHandlerResponse(access)) return access;\n\n const data = await runtime.intelligence.listMemories({\n userId: access.user.id,\n ...(runtime.memory ? { memoryGrant: access.grant } : {}),\n ...(includeInvalidated ? { includeInvalidated: true } : {}),\n });\n\n // The client memory store consumes the `{ memories: [...] }` envelope\n // directly. Assert the shape before forwarding so a platform contract\n // violation surfaces as a clear 502 (the runtime is healthy but its\n // dependency returned the wrong shape) instead of a 200 the client will\n // choke on.\n if (\n data == null ||\n typeof data !== \"object\" ||\n !Array.isArray((data as { memories?: unknown }).memories)\n ) {\n logger.error(\n { data },\n \"listMemories: platform returned a response without a `memories` array\",\n );\n return errorResponse(\n \"Memory platform returned an invalid list response\",\n 502,\n );\n }\n\n return Response.json(data);\n } catch (error) {\n logger.error({ err: error }, \"Error listing memories\");\n return memoryErrorResponse(error, \"Failed to list memories\");\n }\n }\n\n return errorResponse(MISSING_INTELLIGENCE_MESSAGE, 422);\n}\n\n/**\n * Semantically recalls the resolved user's memories via the platform (`POST\n * /api/memories/recall`, hybrid RAG). Mirrors {@link handleListMemories}:\n * requires a `CopilotKitIntelligence` runtime, resolves the user with\n * `identifyUser` (never a client-supplied id), proxies with the project API\n * key + resolved user. Body `{ query, limit?, scope? }`; response `{ memories }`,\n * each optionally carrying `score`.\n */\nexport async function handleRecallMemories({\n runtime,\n request,\n}: MemoriesHandlerParams): Promise<Response> {\n if (!isIntelligenceRuntime(runtime)) {\n return errorResponse(MISSING_INTELLIGENCE_MESSAGE, 422);\n }\n try {\n const body = await parseJsonBody(request);\n if (isHandlerResponse(body)) return body;\n const fields = parseRecallBody(body);\n if (isHandlerResponse(fields)) return fields;\n\n const access = await resolveClientMemory(runtime, request);\n if (isHandlerResponse(access)) return access;\n\n const data = await runtime.intelligence.recallMemories({\n userId: access.user.id,\n ...(runtime.memory ? { memoryGrant: access.grant } : {}),\n ...fields,\n });\n\n if (\n data == null ||\n typeof data !== \"object\" ||\n !Array.isArray((data as { memories?: unknown }).memories)\n ) {\n logger.error(\n { data },\n \"recallMemories: platform returned a response without a `memories` array\",\n );\n return errorResponse(\n \"Memory platform returned an invalid recall response\",\n 502,\n );\n }\n return Response.json(data);\n } catch (error) {\n logger.error({ err: error }, \"Error recalling memories\");\n return memoryErrorResponse(error, \"Failed to recall memories\");\n }\n}\n\n/**\n * Mints memory-realtime join credentials (platform `POST\n * /api/memories/subscribe`). Mirrors {@link handleSubscribeToThreads}: requires\n * a `CopilotKitIntelligence` runtime and resolves the user with `identifyUser`\n * (never a client-supplied id). Returns `{ joinToken, joinCode }` — memory needs\n * the `joinCode` here (unlike threads, where it rides the thread-list response)\n * because the client builds the `user_meta:memories:<joinCode>` channel topic\n * from it.\n *\n * When the platform also resolves a project scope, the response additionally\n * carries `projectJoinToken` / `projectJoinCode`, which the client uses to open\n * a second `project_meta:memories:<projectJoinCode>` channel. These are\n * optional: absent project scope → both fields are omitted (silent-degrade\n * contract; the client opens only the user channel).\n */\nexport async function handleSubscribeToMemories({\n runtime,\n request,\n}: MemoriesHandlerParams): Promise<Response> {\n if (isIntelligenceRuntime(runtime)) {\n try {\n const access = await resolveClientMemory(runtime, request);\n if (isHandlerResponse(access)) return access;\n\n const credentials = await runtime.intelligence.ɵsubscribeToMemories({\n userId: access.user.id,\n ...(runtime.memory ? { memoryGrant: access.grant } : {}),\n });\n\n return Response.json({\n ...(credentials.joinToken !== undefined\n ? { joinToken: credentials.joinToken }\n : {}),\n ...(credentials.joinCode !== undefined\n ? { joinCode: credentials.joinCode }\n : {}),\n // Project-scoped credentials ride along only when the platform minted\n // them; omit both when absent (silent-degrade contract).\n ...(credentials.projectJoinToken !== undefined\n ? { projectJoinToken: credentials.projectJoinToken }\n : {}),\n ...(credentials.projectJoinCode !== undefined\n ? { projectJoinCode: credentials.projectJoinCode }\n : {}),\n });\n } catch (error) {\n logger.error({ err: error }, \"Error subscribing to memories\");\n return memoryErrorResponse(error, \"Failed to subscribe to memories\");\n }\n }\n\n return errorResponse(MISSING_INTELLIGENCE_MESSAGE, 422);\n}\n\n/**\n * Creates a memory for the resolved user (platform `POST /api/memories`).\n * Identity comes from `identifyUser`, never the request body. Returns 201\n * with the stored memory (the client store applies it server-authoritatively).\n */\nexport async function handleCreateMemory({\n runtime,\n request,\n}: MemoriesHandlerParams): Promise<Response> {\n if (!isIntelligenceRuntime(runtime)) {\n return errorResponse(MISSING_INTELLIGENCE_MESSAGE, 422);\n }\n try {\n const body = await parseJsonBody(request);\n if (isHandlerResponse(body)) return body;\n const fields = parseMemoryBody(body);\n if (isHandlerResponse(fields)) return fields;\n\n const access = await resolveClientMemory(runtime, request);\n if (isHandlerResponse(access)) return access;\n\n const data = await runtime.intelligence.createMemory({\n userId: access.user.id,\n ...(runtime.memory ? { memoryGrant: access.grant } : {}),\n ...fields,\n });\n return Response.json(data, { status: 201 });\n } catch (error) {\n logger.error({ err: error }, \"Error creating memory\");\n return memoryErrorResponse(error, \"Failed to create memory\");\n }\n}\n\n/**\n * Supersedes a memory (platform `PATCH /api/memories/:id`): retires `:id` and\n * inserts the new content atomically; the response carries `retiredId`.\n */\nexport async function handleUpdateMemory({\n runtime,\n request,\n memoryId,\n}: MemoryMutationParams): Promise<Response> {\n if (!isIntelligenceRuntime(runtime)) {\n return errorResponse(MISSING_INTELLIGENCE_MESSAGE, 422);\n }\n try {\n const body = await parseJsonBody(request);\n if (isHandlerResponse(body)) return body;\n const fields = parseMemoryBody(body);\n if (isHandlerResponse(fields)) return fields;\n\n const access = await resolveClientMemory(runtime, request);\n if (isHandlerResponse(access)) return access;\n\n const data = await runtime.intelligence.updateMemory({\n userId: access.user.id,\n ...(runtime.memory ? { memoryGrant: access.grant } : {}),\n id: memoryId,\n ...fields,\n });\n return Response.json(data);\n } catch (error) {\n logger.error({ err: error }, \"Error updating memory\");\n return memoryErrorResponse(error, \"Failed to update memory\");\n }\n}\n\n/**\n * Retires (forgets) a memory (platform `DELETE /api/memories/:id`). Non-lossy\n * on the platform side; returns 204.\n */\nexport async function handleRemoveMemory({\n runtime,\n request,\n memoryId,\n}: MemoryMutationParams): Promise<Response> {\n if (!isIntelligenceRuntime(runtime)) {\n return errorResponse(MISSING_INTELLIGENCE_MESSAGE, 422);\n }\n try {\n const access = await resolveClientMemory(runtime, request);\n if (isHandlerResponse(access)) return access;\n\n await runtime.intelligence.removeMemory({\n userId: access.user.id,\n id: memoryId,\n ...(runtime.memory ? { memoryGrant: access.grant } : {}),\n });\n return new Response(null, { status: 204 });\n } catch (error) {\n logger.error({ err: error }, \"Error removing memory\");\n return memoryErrorResponse(error, \"Failed to remove memory\");\n }\n}\n"],"mappings":";;;;;;;;AAoBA,e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