@chat-js/registry 0.2.0-beta.1 → 0.2.0-beta.10

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 (280) hide show
  1. package/README.md +16 -12
  2. package/dist/r/ai-titles.json +14 -17
  3. package/dist/r/akamai-storage.json +13 -1
  4. package/dist/r/alibaba-storage.json +13 -1
  5. package/dist/r/appwrite-storage.json +8 -1
  6. package/dist/r/archil-storage.json +8 -1
  7. package/dist/r/attach-workspace-file.json +82 -0
  8. package/dist/r/attachment-uploads.json +24 -35
  9. package/dist/r/azure-storage.json +8 -1
  10. package/dist/r/backblaze-b2-storage.json +13 -1
  11. package/dist/r/base/ai-titles.json +14 -17
  12. package/dist/r/base/akamai-storage.json +13 -1
  13. package/dist/r/base/alibaba-storage.json +13 -1
  14. package/dist/r/base/appwrite-storage.json +8 -1
  15. package/dist/r/base/archil-storage.json +8 -1
  16. package/dist/r/base/attach-workspace-file.json +82 -0
  17. package/dist/r/base/attachment-uploads.json +24 -35
  18. package/dist/r/base/azure-storage.json +8 -1
  19. package/dist/r/base/backblaze-b2-storage.json +13 -1
  20. package/dist/r/base/bunny-storage-storage.json +2 -1
  21. package/dist/r/base/cloudinary-storage.json +2 -1
  22. package/dist/r/base/credits.json +24 -46
  23. package/dist/r/base/deep-research.json +55 -141
  24. package/dist/r/base/default-sandbox.json +35 -0
  25. package/dist/r/base/desktop.json +129 -0
  26. package/dist/r/base/digitalocean-spaces-storage.json +13 -1
  27. package/dist/r/base/docker-sandbox.json +35 -0
  28. package/dist/r/base/dropbox-storage.json +2 -1
  29. package/dist/r/base/exoscale-storage.json +13 -1
  30. package/dist/r/base/feedback.json +31 -53
  31. package/dist/r/base/filebase-storage.json +8 -1
  32. package/dist/r/base/firebase-storage-storage.json +2 -1
  33. package/dist/r/base/followup-suggestions.json +44 -66
  34. package/dist/r/base/ftp-storage.json +18 -1
  35. package/dist/r/base/gcs-storage.json +8 -1
  36. package/dist/r/base/generate-image.json +22 -16
  37. package/dist/r/base/generate-video.json +16 -10
  38. package/dist/r/base/google-drive-storage.json +2 -1
  39. package/dist/r/base/guest-chat.json +166 -0
  40. package/dist/r/base/hetzner-storage.json +13 -1
  41. package/dist/r/base/ibm-cos-storage.json +13 -1
  42. package/dist/r/base/idrive-e2-storage.json +13 -1
  43. package/dist/r/base/image-viewer.json +49 -0
  44. package/dist/r/base/just-bash-sandbox.json +32 -0
  45. package/dist/r/base/litellm-gateway.json +5 -8
  46. package/dist/r/base/mcp.json +128 -121
  47. package/dist/r/base/memory-storage.json +5 -3
  48. package/dist/r/base/minio-storage.json +13 -1
  49. package/dist/r/base/model-preferences.json +41 -55
  50. package/dist/r/base/neon-storage.json +8 -1
  51. package/dist/r/base/netlify-blobs-storage.json +10 -2
  52. package/dist/r/base/onedrive-storage.json +2 -1
  53. package/dist/r/base/openai-compatible-gateway.json +5 -8
  54. package/dist/r/base/openai-gateway.json +5 -8
  55. package/dist/r/base/openrouter-gateway.json +4 -8
  56. package/dist/r/base/oracle-cloud-storage.json +18 -1
  57. package/dist/r/base/ovhcloud-storage.json +13 -1
  58. package/dist/r/base/pocketbase-storage.json +2 -1
  59. package/dist/r/base/projects.json +107 -108
  60. package/dist/r/base/r2-storage.json +9 -1
  61. package/dist/r/base/registry.json +2340 -2555
  62. package/dist/r/base/s3-storage.json +15 -1
  63. package/dist/r/base/scaleway-storage.json +13 -1
  64. package/dist/r/base/search.json +74 -66
  65. package/dist/r/base/sftp-storage.json +18 -1
  66. package/dist/r/base/sharepoint-storage.json +2 -1
  67. package/dist/r/base/sharing.json +58 -64
  68. package/dist/r/base/spreadsheet-grid.json +20 -0
  69. package/dist/r/base/spreadsheet-viewer.json +62 -0
  70. package/dist/r/base/storj-storage.json +8 -1
  71. package/dist/r/base/streamdown-math.json +35 -0
  72. package/dist/r/base/streamdown-mermaid.json +34 -0
  73. package/dist/r/base/supabase-storage.json +8 -1
  74. package/dist/r/base/tencent-storage.json +13 -1
  75. package/dist/r/base/tigris-storage.json +8 -1
  76. package/dist/r/base/uploadthing-storage.json +2 -1
  77. package/dist/r/base/vercel-blob-storage.json +3 -1
  78. package/dist/r/base/vercel-gateway.json +7 -9
  79. package/dist/r/base/vercel-sandbox.json +8 -26
  80. package/dist/r/base/video-viewer.json +42 -0
  81. package/dist/r/base/vultr-storage.json +13 -1
  82. package/dist/r/base/wasabi-storage.json +13 -1
  83. package/dist/r/base/webdav-storage.json +13 -1
  84. package/dist/r/base/yandex-storage.json +8 -1
  85. package/dist/r/bunny-storage-storage.json +2 -1
  86. package/dist/r/cloudinary-storage.json +2 -1
  87. package/dist/r/credits.json +24 -46
  88. package/dist/r/deep-research.json +55 -141
  89. package/dist/r/default-sandbox.json +35 -0
  90. package/dist/r/desktop.json +129 -0
  91. package/dist/r/digitalocean-spaces-storage.json +13 -1
  92. package/dist/r/docker-sandbox.json +35 -0
  93. package/dist/r/dropbox-storage.json +2 -1
  94. package/dist/r/eve/deep-research.json +47 -0
  95. package/dist/r/eve/registry.json +53 -0
  96. package/dist/r/exoscale-storage.json +13 -1
  97. package/dist/r/feedback.json +31 -53
  98. package/dist/r/filebase-storage.json +8 -1
  99. package/dist/r/firebase-storage-storage.json +2 -1
  100. package/dist/r/followup-suggestions.json +44 -66
  101. package/dist/r/ftp-storage.json +18 -1
  102. package/dist/r/gcs-storage.json +8 -1
  103. package/dist/r/generate-image.json +22 -16
  104. package/dist/r/generate-video.json +16 -10
  105. package/dist/r/google-drive-storage.json +2 -1
  106. package/dist/r/guest-chat.json +166 -0
  107. package/dist/r/hetzner-storage.json +13 -1
  108. package/dist/r/ibm-cos-storage.json +13 -1
  109. package/dist/r/idrive-e2-storage.json +13 -1
  110. package/dist/r/image-viewer.json +49 -0
  111. package/dist/r/just-bash-sandbox.json +32 -0
  112. package/dist/r/litellm-gateway.json +5 -8
  113. package/dist/r/mcp.json +128 -121
  114. package/dist/r/memory-storage.json +5 -3
  115. package/dist/r/minio-storage.json +13 -1
  116. package/dist/r/model-preferences.json +41 -55
  117. package/dist/r/neon-storage.json +8 -1
  118. package/dist/r/netlify-blobs-storage.json +10 -2
  119. package/dist/r/onedrive-storage.json +2 -1
  120. package/dist/r/openai-compatible-gateway.json +5 -8
  121. package/dist/r/openai-gateway.json +5 -8
  122. package/dist/r/openrouter-gateway.json +4 -8
  123. package/dist/r/oracle-cloud-storage.json +18 -1
  124. package/dist/r/ovhcloud-storage.json +13 -1
  125. package/dist/r/pocketbase-storage.json +2 -1
  126. package/dist/r/projects.json +107 -108
  127. package/dist/r/r2-storage.json +9 -1
  128. package/dist/r/radix/ai-titles.json +14 -17
  129. package/dist/r/radix/akamai-storage.json +13 -1
  130. package/dist/r/radix/alibaba-storage.json +13 -1
  131. package/dist/r/radix/appwrite-storage.json +8 -1
  132. package/dist/r/radix/archil-storage.json +8 -1
  133. package/dist/r/radix/attach-workspace-file.json +82 -0
  134. package/dist/r/radix/attachment-uploads.json +24 -35
  135. package/dist/r/radix/azure-storage.json +8 -1
  136. package/dist/r/radix/backblaze-b2-storage.json +13 -1
  137. package/dist/r/radix/bunny-storage-storage.json +2 -1
  138. package/dist/r/radix/cloudinary-storage.json +2 -1
  139. package/dist/r/radix/credits.json +24 -46
  140. package/dist/r/radix/deep-research.json +55 -141
  141. package/dist/r/radix/default-sandbox.json +35 -0
  142. package/dist/r/radix/desktop.json +129 -0
  143. package/dist/r/radix/digitalocean-spaces-storage.json +13 -1
  144. package/dist/r/radix/docker-sandbox.json +35 -0
  145. package/dist/r/radix/dropbox-storage.json +2 -1
  146. package/dist/r/radix/exoscale-storage.json +13 -1
  147. package/dist/r/radix/feedback.json +31 -53
  148. package/dist/r/radix/filebase-storage.json +8 -1
  149. package/dist/r/radix/firebase-storage-storage.json +2 -1
  150. package/dist/r/radix/followup-suggestions.json +44 -66
  151. package/dist/r/radix/ftp-storage.json +18 -1
  152. package/dist/r/radix/gcs-storage.json +8 -1
  153. package/dist/r/radix/generate-image.json +22 -16
  154. package/dist/r/radix/generate-video.json +16 -10
  155. package/dist/r/radix/google-drive-storage.json +2 -1
  156. package/dist/r/radix/guest-chat.json +166 -0
  157. package/dist/r/radix/hetzner-storage.json +13 -1
  158. package/dist/r/radix/ibm-cos-storage.json +13 -1
  159. package/dist/r/radix/idrive-e2-storage.json +13 -1
  160. package/dist/r/radix/image-viewer.json +49 -0
  161. package/dist/r/radix/just-bash-sandbox.json +32 -0
  162. package/dist/r/radix/litellm-gateway.json +5 -8
  163. package/dist/r/radix/mcp.json +128 -121
  164. package/dist/r/radix/memory-storage.json +5 -3
  165. package/dist/r/radix/minio-storage.json +13 -1
  166. package/dist/r/radix/model-preferences.json +41 -55
  167. package/dist/r/radix/neon-storage.json +8 -1
  168. package/dist/r/radix/netlify-blobs-storage.json +10 -2
  169. package/dist/r/radix/onedrive-storage.json +2 -1
  170. package/dist/r/radix/openai-compatible-gateway.json +5 -8
  171. package/dist/r/radix/openai-gateway.json +5 -8
  172. package/dist/r/radix/openrouter-gateway.json +4 -8
  173. package/dist/r/radix/oracle-cloud-storage.json +18 -1
  174. package/dist/r/radix/ovhcloud-storage.json +13 -1
  175. package/dist/r/radix/pocketbase-storage.json +2 -1
  176. package/dist/r/radix/projects.json +107 -108
  177. package/dist/r/radix/r2-storage.json +9 -1
  178. package/dist/r/radix/registry.json +2339 -2554
  179. package/dist/r/radix/s3-storage.json +15 -1
  180. package/dist/r/radix/scaleway-storage.json +13 -1
  181. package/dist/r/radix/search.json +74 -66
  182. package/dist/r/radix/sftp-storage.json +18 -1
  183. package/dist/r/radix/sharepoint-storage.json +2 -1
  184. package/dist/r/radix/sharing.json +58 -64
  185. package/dist/r/radix/spreadsheet-grid.json +20 -0
  186. package/dist/r/radix/spreadsheet-viewer.json +62 -0
  187. package/dist/r/radix/storj-storage.json +8 -1
  188. package/dist/r/radix/streamdown-math.json +35 -0
  189. package/dist/r/radix/streamdown-mermaid.json +34 -0
  190. package/dist/r/radix/supabase-storage.json +8 -1
  191. package/dist/r/radix/tencent-storage.json +13 -1
  192. package/dist/r/radix/tigris-storage.json +8 -1
  193. package/dist/r/radix/uploadthing-storage.json +2 -1
  194. package/dist/r/radix/vercel-blob-storage.json +3 -1
  195. package/dist/r/radix/vercel-gateway.json +7 -9
  196. package/dist/r/radix/vercel-sandbox.json +8 -26
  197. package/dist/r/radix/video-viewer.json +42 -0
  198. package/dist/r/radix/vultr-storage.json +13 -1
  199. package/dist/r/radix/wasabi-storage.json +13 -1
  200. package/dist/r/radix/webdav-storage.json +13 -1
  201. package/dist/r/radix/yandex-storage.json +8 -1
  202. package/dist/r/registry.json +2340 -2555
  203. package/dist/r/s3-storage.json +15 -1
  204. package/dist/r/scaleway-storage.json +13 -1
  205. package/dist/r/search.json +74 -66
  206. package/dist/r/sftp-storage.json +18 -1
  207. package/dist/r/sharepoint-storage.json +2 -1
  208. package/dist/r/sharing.json +58 -64
  209. package/dist/r/spreadsheet-grid.json +20 -0
  210. package/dist/r/spreadsheet-viewer.json +62 -0
  211. package/dist/r/storj-storage.json +8 -1
  212. package/dist/r/streamdown-math.json +35 -0
  213. package/dist/r/streamdown-mermaid.json +34 -0
  214. package/dist/r/supabase-storage.json +8 -1
  215. package/dist/r/tencent-storage.json +13 -1
  216. package/dist/r/tigris-storage.json +8 -1
  217. package/dist/r/uploadthing-storage.json +2 -1
  218. package/dist/r/vercel-blob-storage.json +3 -1
  219. package/dist/r/vercel-gateway.json +7 -9
  220. package/dist/r/vercel-sandbox.json +8 -26
  221. package/dist/r/video-viewer.json +42 -0
  222. package/dist/r/vultr-storage.json +13 -1
  223. package/dist/r/wasabi-storage.json +13 -1
  224. package/dist/r/webdav-storage.json +13 -1
  225. package/dist/r/yandex-storage.json +8 -1
  226. package/package.json +19 -40
  227. package/dist/r/base/code-documents.json +0 -96
  228. package/dist/r/base/code-execution-runtime.json +0 -25
  229. package/dist/r/base/code-execution-ui.json +0 -32
  230. package/dist/r/base/code-execution.json +0 -69
  231. package/dist/r/base/daytona-sandbox.json +0 -55
  232. package/dist/r/base/delete-document.json +0 -58
  233. package/dist/r/base/firecrawl-search.json +0 -72
  234. package/dist/r/base/get-weather.json +0 -52
  235. package/dist/r/base/langfuse.json +0 -63
  236. package/dist/r/base/read-document.json +0 -34
  237. package/dist/r/base/retrieve-url.json +0 -69
  238. package/dist/r/base/saved-code-execution.json +0 -84
  239. package/dist/r/base/sheet-documents.json +0 -94
  240. package/dist/r/base/tavily-search.json +0 -72
  241. package/dist/r/base/text-documents.json +0 -117
  242. package/dist/r/base/vercel-analytics.json +0 -46
  243. package/dist/r/base/vercel-speed-insights.json +0 -46
  244. package/dist/r/base/word-count.json +0 -51
  245. package/dist/r/code-documents.json +0 -96
  246. package/dist/r/code-execution-runtime.json +0 -25
  247. package/dist/r/code-execution-ui.json +0 -32
  248. package/dist/r/code-execution.json +0 -69
  249. package/dist/r/daytona-sandbox.json +0 -55
  250. package/dist/r/delete-document.json +0 -58
  251. package/dist/r/firecrawl-search.json +0 -72
  252. package/dist/r/get-weather.json +0 -52
  253. package/dist/r/langfuse.json +0 -63
  254. package/dist/r/radix/code-documents.json +0 -96
  255. package/dist/r/radix/code-execution-runtime.json +0 -25
  256. package/dist/r/radix/code-execution-ui.json +0 -32
  257. package/dist/r/radix/code-execution.json +0 -69
  258. package/dist/r/radix/daytona-sandbox.json +0 -55
  259. package/dist/r/radix/delete-document.json +0 -58
  260. package/dist/r/radix/firecrawl-search.json +0 -72
  261. package/dist/r/radix/get-weather.json +0 -52
  262. package/dist/r/radix/langfuse.json +0 -63
  263. package/dist/r/radix/read-document.json +0 -34
  264. package/dist/r/radix/retrieve-url.json +0 -69
  265. package/dist/r/radix/saved-code-execution.json +0 -84
  266. package/dist/r/radix/sheet-documents.json +0 -94
  267. package/dist/r/radix/tavily-search.json +0 -72
  268. package/dist/r/radix/text-documents.json +0 -117
  269. package/dist/r/radix/vercel-analytics.json +0 -46
  270. package/dist/r/radix/vercel-speed-insights.json +0 -46
  271. package/dist/r/radix/word-count.json +0 -51
  272. package/dist/r/read-document.json +0 -34
  273. package/dist/r/retrieve-url.json +0 -69
  274. package/dist/r/saved-code-execution.json +0 -84
  275. package/dist/r/sheet-documents.json +0 -94
  276. package/dist/r/tavily-search.json +0 -72
  277. package/dist/r/text-documents.json +0 -117
  278. package/dist/r/vercel-analytics.json +0 -46
  279. package/dist/r/vercel-speed-insights.json +0 -46
  280. package/dist/r/word-count.json +0 -51
@@ -9,143 +9,121 @@
9
9
  ],
10
10
  "files": [
11
11
  {
12
- "path": "src/plugins/followup-suggestions/src/chat.ts",
13
- "content": "import { inArray } from \"drizzle-orm\";\nimport type { ChatServerIntegration } from \"@/lib/chat-plugin-contracts\";\nimport { eveFollowup } from \"./followup-schema\";\n\nexport const followupChat = {\n onDeleteConversations: async (tx, { sessionIds }) => {\n if (sessionIds.length > 0) {\n await tx\n .delete(eveFollowup)\n .where(inArray(eveFollowup.sessionId, [...sessionIds]));\n }\n },\n} satisfies ChatServerIntegration;\n",
12
+ "path": "src/plugins/followup-suggestions/src/chat-server.ts",
13
+ "content": "import { inArray } from \"drizzle-orm\";\nimport type { ChatServerIntegration } from \"@/chatjs/core/chat/contracts\";\nimport { eveFollowup } from \"./followup-schema\";\n\nconst followupChat = {\n onDeleteConversations: async (tx, { sessionIds }) => {\n if (sessionIds.length > 0) {\n await tx\n .delete(eveFollowup)\n .where(inArray(eveFollowup.sessionId, [...sessionIds]));\n }\n },\n} satisfies ChatServerIntegration;\n\nexport default followupChat;\n",
14
14
  "type": "registry:file",
15
- "target": "~/plugins/followup-suggestions/chat.ts"
15
+ "target": "~/chatjs/plugins/followup-suggestions/chat-server.ts"
16
16
  },
17
17
  {
18
- "path": "src/plugins/followup-suggestions/src/client-plugin.ts",
19
- "content": "import type { ChatClientPlugin } from \"@/lib/plugin-contracts\";\nimport { FollowupSuggestions } from \"./suggestions\";\n\nexport const followupSuggestionsClient = () =>\n ({\n id: \"followup-suggestions\",\n chat: { Suggestions: FollowupSuggestions },\n }) satisfies ChatClientPlugin;\n",
18
+ "path": "src/plugins/followup-suggestions/src/chat-ui.ts",
19
+ "content": "\"use client\";\nimport { definePlugin, slot } from \"@/chatjs/core/ui/slots\";\nimport { ChatSuggestions } from \"@/components/chat-slots\";\nimport { FollowupSuggestions } from \"./suggestions\";\n\nexport const chatUi = definePlugin({\n id: \"followup-suggestions\",\n slots: [slot(ChatSuggestions, FollowupSuggestions)],\n});\n",
20
20
  "type": "registry:file",
21
- "target": "~/plugins/followup-suggestions/client-plugin.ts"
21
+ "target": "~/chatjs/plugins/followup-suggestions/chat-ui.ts"
22
22
  },
23
23
  {
24
24
  "path": "src/plugins/followup-suggestions/src/followup-completion.ts",
25
- "content": "import type { MessageStreamEvent } from \"eve/client\";\n\n// Preserve native completion identity through replay.\ntype CompletionEvent =\n | {\n readonly type: \"turn.completed\";\n readonly data: { readonly turnId: string };\n readonly meta: { readonly id: string };\n }\n | {\n readonly type: \"turn.started\" | \"turn.failed\" | \"turn.cancelled\";\n readonly data: { readonly turnId: string };\n }\n | {\n readonly type: Exclude<\n MessageStreamEvent[\"type\"],\n \"turn.completed\" | \"turn.started\" | \"turn.failed\" | \"turn.cancelled\"\n >;\n };\n\nexport const followupCompletion = (\n events: readonly CompletionEvent[],\n turnId: string | undefined\n): string | undefined => {\n let id: string | undefined;\n for (const event of events) {\n if (event.type === \"turn.completed\" && event.data.turnId === turnId) {\n ({ id } = event.meta);\n } else if (\n (event.type === \"turn.started\" ||\n event.type === \"turn.failed\" ||\n event.type === \"turn.cancelled\") &&\n event.data.turnId === turnId\n ) {\n id = undefined;\n }\n }\n return id;\n};\n",
25
+ "content": "import type { SessionStreamEvent } from \"eve/client\";\n\nexport const followupEventId = (sessionId: string, turnId: string): string =>\n JSON.stringify([sessionId, turnId, \"completed\"]);\n\nexport const followupCompletion = (\n events: readonly SessionStreamEvent[],\n turnId: string | undefined,\n sessionId: string\n): string | undefined => {\n const last = events.findLast(\n (event) =>\n (event.type === \"turn.started\" || event.type === \"turn.settled\") &&\n event.data.turnId === turnId\n );\n return last?.type === \"turn.settled\" && last.data.outcome === \"completed\"\n ? followupEventId(sessionId, last.data.turnId)\n : undefined;\n};\n",
26
26
  "type": "registry:file",
27
- "target": "~/plugins/followup-suggestions/followup-completion.ts"
27
+ "target": "~/chatjs/plugins/followup-suggestions/followup-completion.ts"
28
28
  },
29
29
  {
30
30
  "path": "src/plugins/followup-suggestions/src/followup-context.ts",
31
- "content": "import type { HookEvent } from \"eve/hooks\";\n\n/** SDK fields this reader does not inspect remain optional and opaque. */\ntype IgnoredSdkFields<Value> = Value extends object\n ? { readonly [Key in keyof Value]?: unknown }\n : unknown;\n\ntype FollowupEvent = IgnoredSdkFields<HookEvent> &\n (\n | { readonly type: \"turn.started\" }\n | {\n readonly type: \"message.received\";\n readonly data: Readonly<\n Pick<\n Extract<HookEvent, { type: \"message.received\" }>[\"data\"],\n \"message\"\n >\n > &\n IgnoredSdkFields<\n Extract<HookEvent, { type: \"message.received\" }>[\"data\"]\n >;\n }\n | {\n readonly type: \"message.completed\";\n readonly data: Readonly<\n Pick<\n Extract<HookEvent, { type: \"message.completed\" }>[\"data\"],\n \"message\" | \"finishReason\"\n >\n > &\n IgnoredSdkFields<\n Extract<HookEvent, { type: \"message.completed\" }>[\"data\"]\n >;\n }\n | {\n readonly type: Exclude<\n HookEvent[\"type\"],\n \"turn.started\" | \"message.received\" | \"message.completed\"\n >;\n }\n );\n\nconst MAX_CONTEXT_CHARACTERS = 12_000;\nexport interface FollowupContext {\n readonly user: string;\n readonly assistant: string;\n}\n\n/**\n * Retain only the current exchange; the native event log owns history.\n * @param {Readonly<FollowupContext>} current Previously retained user and assistant text.\n * @param {HookEvent} event Native turn or message event used to reset or replace the exchange.\n * @returns {FollowupContext} Current exchange with messages bounded to the context limit, or the original object for unrelated events.\n */\nexport const followupContext = (\n current: FollowupContext,\n\n event: FollowupEvent\n): FollowupContext => {\n if (event.type === \"turn.started\") {\n return { assistant: \"\", user: \"\" };\n }\n if (event.type === \"message.received\") {\n return {\n assistant: \"\",\n user: event.data.message.slice(-MAX_CONTEXT_CHARACTERS),\n };\n }\n if (\n event.type === \"message.completed\" &&\n event.data.finishReason !== \"tool-calls\"\n ) {\n return {\n ...current,\n assistant: (event.data.message ?? \"\").slice(-MAX_CONTEXT_CHARACTERS),\n };\n }\n return current;\n};\n",
31
+ "content": "import type { HookEvent } from \"eve/hooks\";\n\nconst MAX_CONTEXT_CHARACTERS = 12_000;\nexport interface FollowupContext {\n readonly user: string;\n readonly assistant: string;\n}\nexport const followupContext = (\n current: FollowupContext,\n event: HookEvent\n): FollowupContext => {\n if (event.type === \"turn.started\") {\n return { assistant: \"\", user: \"\" };\n }\n if (event.type === \"delivery.consumed\") {\n return {\n assistant: \"\",\n user: event.data.parts\n .flatMap((part) => (part.kind === \"text\" ? [part.text] : []))\n .join(\"\\n\")\n .slice(-MAX_CONTEXT_CHARACTERS),\n };\n }\n if (\n event.type === \"content.completed\" &&\n event.data.kind === \"text\" &&\n event.data.phase === \"reply\" &&\n typeof event.data.value === \"string\"\n ) {\n return {\n ...current,\n assistant: event.data.value.slice(-MAX_CONTEXT_CHARACTERS),\n };\n }\n return current;\n};\n",
32
32
  "type": "registry:file",
33
- "target": "~/plugins/followup-suggestions/followup-context.ts"
33
+ "target": "~/chatjs/plugins/followup-suggestions/followup-context.ts"
34
34
  },
35
35
  {
36
36
  "path": "src/plugins/followup-suggestions/src/followup-hook.ts",
37
- "content": "import { isGuestSession } from \"@/lib/eve/session-identity\";\nimport type { FollowupContext } from \"./followup-context\";\nimport type { HookContext } from \"eve/hooks\";\nimport { defineHook } from \"eve/hooks\";\nimport { defineState } from \"eve/context\";\n\nimport { followupContext } from \"./followup-context\";\nimport { generateEveFollowupSuggestions } from \"./generate-suggestions\";\n\nconst context = defineState<FollowupContext>(\n \"chatjs.followups.context\",\n () => ({ assistant: \"\", user: \"\" })\n);\n\nexport default defineHook({\n events: {\n \"message.completed\": (event: Parameters<typeof followupContext>[1]) => {\n context.update((current: FollowupContext) =>\n followupContext(current, event)\n );\n },\n \"message.received\": (event: Parameters<typeof followupContext>[1]) => {\n context.update((current: FollowupContext) =>\n followupContext(current, event)\n );\n },\n \"turn.completed\": (\n event: {\n readonly data: { readonly turnId: string };\n readonly meta: { readonly id: string };\n },\n hookContext: {\n readonly session: Readonly<\n Pick<HookContext[\"session\"], \"parent\" | \"id\" | \"auth\">\n >;\n }\n ): ReturnType<typeof generateEveFollowupSuggestions> | undefined => {\n // Suggestions are actions for the user-facing branch, not a background task.\n if (isGuestSession(hookContext.session) || hookContext.session.parent) {\n return undefined;\n }\n return generateEveFollowupSuggestions(context.get(), {\n ownerId: hookContext.session.auth.initiator?.principalId ?? \"\",\n sessionId: hookContext.session.id,\n turnId: event.data.turnId,\n eventId: event.meta.id,\n });\n },\n \"turn.started\": (event: Parameters<typeof followupContext>[1]) => {\n context.update((current: FollowupContext) =>\n followupContext(current, event)\n );\n },\n },\n});\n",
37
+ "content": "import { followupEventId } from \"./followup-completion\";\nimport { isAccountSession } from \"@/lib/eve/session-identity\";\nimport type { FollowupContext } from \"./followup-context\";\nimport type { HookContext } from \"eve/hooks\";\nimport { defineHook } from \"eve/hooks\";\nimport { defineState } from \"eve/context\";\n\nimport { followupContext } from \"./followup-context\";\nimport { generateEveFollowupSuggestions } from \"./generate-suggestions\";\n\nconst context = defineState<FollowupContext>(\n \"chatjs.followups.context\",\n () => ({ assistant: \"\", user: \"\" })\n);\n\nexport default defineHook({\n events: {\n \"content.completed\": (event: Parameters<typeof followupContext>[1]) => {\n context.update((current: FollowupContext) =>\n followupContext(current, event)\n );\n },\n \"delivery.consumed\": (event: Parameters<typeof followupContext>[1]) => {\n context.update((current: FollowupContext) =>\n followupContext(current, event)\n );\n },\n \"turn.settled\": (\n event: {\n readonly data: { readonly turnId: string; readonly outcome: string };\n },\n hookContext: {\n readonly session: Readonly<\n Pick<HookContext[\"session\"], \"parent\" | \"id\" | \"auth\">\n >;\n }\n ): ReturnType<typeof generateEveFollowupSuggestions> | undefined => {\n // Suggestions are actions for the user-facing branch, not a background task.\n if (\n event.data.outcome !== \"completed\" ||\n !isAccountSession(hookContext.session) ||\n hookContext.session.parent\n ) {\n return undefined;\n }\n return generateEveFollowupSuggestions(context.get(), {\n ownerId: hookContext.session.auth.initiator?.principalId ?? \"\",\n sessionId: hookContext.session.id,\n turnId: event.data.turnId,\n eventId: followupEventId(hookContext.session.id, event.data.turnId),\n });\n },\n \"turn.started\": (event: Parameters<typeof followupContext>[1]) => {\n context.update((current: FollowupContext) =>\n followupContext(current, event)\n );\n },\n },\n});\n",
38
38
  "type": "registry:file",
39
- "target": "~/plugins/followup-suggestions/followup-hook.ts"
39
+ "target": "~/chatjs/plugins/followup-suggestions/followup-hook.ts"
40
40
  },
41
41
  {
42
42
  "path": "src/plugins/followup-suggestions/src/followup-queries.ts",
43
- "content": "import { and, eq } from \"drizzle-orm\";\nimport { db } from \"@/lib/db/client\";\nimport { eveConversation } from \"@/lib/db/schema\";\nimport { eveFollowup } from \"./followup-schema\";\n\n/** Claim before any paid call. A crashed claim is deliberately never retried. */\nexport const claimEveFollowup = async (\n ownerId: string,\n sessionId: string,\n turnId: string,\n eventId: string\n): Promise<string | null> =>\n await db.transaction(async (tx) => {\n const conversations = await tx\n .select({ chatId: eveConversation.chatId })\n .from(eveConversation)\n .where(\n and(\n eq(eveConversation.ownerId, ownerId),\n eq(eveConversation.sessionId, sessionId),\n eq(eveConversation.state, \"bound\")\n )\n )\n .for(\"update\");\n const conversation = conversations.at(0);\n if (conversation === undefined) {\n return null;\n }\n const [claim] = await tx\n .insert(eveFollowup)\n .values({ ...conversation, ownerId, turnId, sessionId, eventId })\n .onConflictDoNothing()\n .returning({ chatId: eveFollowup.chatId });\n return claim?.chatId ?? null;\n });\n\nexport const finishEveFollowup = async (\n ownerId: string,\n chatId: string,\n eventId: string,\n suggestions: readonly string[]\n): Promise<void> => {\n await db\n .update(eveFollowup)\n .set({ suggestions: [...suggestions] })\n .where(\n and(\n eq(eveFollowup.ownerId, ownerId),\n eq(eveFollowup.chatId, chatId),\n eq(eveFollowup.eventId, eventId)\n )\n );\n};\n\nexport const getEveFollowup = async (\n ownerId: string,\n conversationId: string,\n eventId: string\n): Promise<readonly string[] | null> => {\n const [row] = await db\n .select({ suggestions: eveFollowup.suggestions })\n .from(eveFollowup)\n .innerJoin(\n eveConversation,\n and(\n eq(eveFollowup.chatId, eveConversation.chatId),\n eq(eveFollowup.ownerId, eveConversation.ownerId)\n )\n )\n .where(\n and(\n eq(eveConversation.id, conversationId),\n eq(eveConversation.ownerId, ownerId),\n eq(eveConversation.state, \"bound\"),\n eq(eveFollowup.eventId, eventId)\n )\n );\n return row?.suggestions ?? null;\n};\n",
43
+ "content": "import { and, eq } from \"drizzle-orm\";\nimport { db } from \"@/lib/db/client\";\nimport { eveConversation } from \"@/lib/db/schema\";\nimport { eveFollowup } from \"./followup-schema\";\n\n/** Claim before any paid call. A crashed claim is deliberately never retried. */\nexport const claimEveFollowup = async (\n ownerId: string,\n sessionId: string,\n turnId: string,\n eventId: string\n): Promise<string | null> =>\n await db.transaction(async (tx) => {\n const conversations = await tx\n .select({ chatId: eveConversation.chatId })\n .from(eveConversation)\n .where(\n and(\n eq(eveConversation.ownerId, ownerId),\n eq(eveConversation.sessionId, sessionId),\n eq(eveConversation.state, \"bound\")\n )\n )\n .for(\"update\");\n const conversation = conversations.at(0);\n if (conversation === undefined) {\n return null;\n }\n const [claim] = await tx\n .insert(eveFollowup)\n .values({ ...conversation, ownerId, turnId, sessionId, eventId })\n .onConflictDoNothing()\n .returning({ chatId: eveFollowup.chatId });\n return claim?.chatId ?? null;\n });\n\nexport const finishEveFollowup = async (\n ownerId: string,\n chatId: string,\n eventId: string,\n suggestions: readonly string[]\n): Promise<void> => {\n await db\n .update(eveFollowup)\n .set({ suggestions: [...suggestions] })\n .where(\n and(\n eq(eveFollowup.ownerId, ownerId),\n eq(eveFollowup.chatId, chatId),\n eq(eveFollowup.eventId, eventId)\n )\n );\n};\n\nexport const getEveFollowup = async (\n ownerId: string,\n branchId: string,\n eventId: string\n): Promise<readonly string[] | null> => {\n const [row] = await db\n .select({ suggestions: eveFollowup.suggestions })\n .from(eveFollowup)\n .innerJoin(\n eveConversation,\n and(\n eq(eveFollowup.chatId, eveConversation.chatId),\n eq(eveFollowup.ownerId, eveConversation.ownerId)\n )\n )\n .where(\n and(\n eq(eveConversation.id, branchId),\n eq(eveConversation.ownerId, ownerId),\n eq(eveConversation.state, \"bound\"),\n eq(eveFollowup.eventId, eventId)\n )\n );\n return row?.suggestions ?? null;\n};\n",
44
44
  "type": "registry:file",
45
- "target": "~/plugins/followup-suggestions/followup-queries.ts"
45
+ "target": "~/chatjs/plugins/followup-suggestions/followup-queries.ts"
46
46
  },
47
47
  {
48
48
  "path": "src/plugins/followup-suggestions/src/followup-schema.ts",
49
49
  "content": "import {\n foreignKey,\n index,\n jsonb,\n pgTable,\n text,\n unique,\n uuid,\n} from \"drizzle-orm/pg-core\";\nimport { eveChat } from \"@/lib/db/schema\";\n\n/** Optional display output, shared by native branches of the same chat. */\nexport const eveFollowup = pgTable(\n \"EveFollowup\",\n {\n chatId: uuid(\"chatId\").notNull(),\n ownerId: text(\"ownerId\").notNull(),\n turnId: text(\"turnId\").notNull(),\n sessionId: text(\"sessionId\").notNull(),\n eventId: text(\"eventId\").primaryKey(),\n suggestions: jsonb(\"suggestions\").$type<readonly string[]>(),\n },\n (table) => [\n index(\"EveFollowup_chat\").on(table.chatId),\n unique().on(table.sessionId, table.turnId),\n foreignKey({\n columns: [table.chatId, table.ownerId],\n foreignColumns: [eveChat.id, eveChat.ownerId],\n }).onDelete(\"cascade\"),\n ]\n);\n",
50
50
  "type": "registry:file",
51
- "target": "~/plugins/followup-suggestions/followup-schema.ts"
51
+ "target": "~/chatjs/plugins/followup-suggestions/followup-schema.ts"
52
52
  },
53
53
  {
54
54
  "path": "src/plugins/followup-suggestions/src/followup-suggestions-view.tsx",
55
55
  "content": "\"use client\";\n\nimport { Suggestion, Suggestions } from \"@/components/ai-elements/suggestion\";\nimport { PlusIcon } from \"lucide-react\";\nimport React from \"react\";\n\nimport type { JSX as ReactJSX } from \"react\";\n\nimport { cn } from \"@/lib/utils\";\n\nexport const FollowUpSuggestionsView = ({\n suggestions,\n className,\n onSelect,\n disabled = false,\n}: {\n readonly suggestions: readonly string[];\n readonly className?: string;\n readonly onSelect: (suggestion: string) => void;\n readonly disabled?: boolean;\n}): ReactJSX.Element | null => {\n if (suggestions.length === 0) {\n return null;\n }\n\n return (\n <fieldset\n aria-label=\"Related questions\"\n className={cn(\"mt-2 mb-2 flex min-w-0 flex-col gap-2\", className)}\n >\n <legend className=\"text-muted-foreground text-xs font-medium\">\n Related\n </legend>\n <Suggestions className=\"gap-1.5\">\n {(() => {\n const seen = new Map<string, number>();\n return suggestions.map((suggestion) => {\n const count = seen.get(suggestion) ?? 0;\n seen.set(suggestion, count + 1);\n const key = count === 0 ? suggestion : `${suggestion}-${count}`;\n return (\n <Suggestion\n className=\"text-muted-foreground hover:text-foreground h-7\"\n disabled={disabled}\n key={key}\n onClick={onSelect}\n size=\"sm\"\n suggestion={suggestion}\n type=\"button\"\n variant=\"ghost\"\n >\n {suggestion}\n <PlusIcon className=\"size-3 opacity-70\" />\n </Suggestion>\n );\n });\n })()}\n </Suggestions>\n </fieldset>\n );\n};\n",
56
56
  "type": "registry:file",
57
- "target": "~/plugins/followup-suggestions/followup-suggestions-view.tsx"
57
+ "target": "~/chatjs/plugins/followup-suggestions/followup-suggestions-view.tsx"
58
58
  },
59
59
  {
60
60
  "path": "src/plugins/followup-suggestions/src/generate-suggestions.ts",
61
61
  "content": "import { claimEveFollowup, finishEveFollowup } from \"./followup-queries\";\nimport { Output, generateText } from \"ai\";\nimport type { FollowupContext } from \"./followup-context\";\nimport { config } from \"@/lib/config\";\nimport { createModuleLogger } from \"@/lib/logger\";\nimport { eveFollowupSuggestions } from \"./suggestion-output\";\nimport { accountEveModel } from \"@/lib/eve/model-accounting\";\nimport type { ModelCallScope } from \"@/lib/eve/model-ledger\";\nimport { resolveEveModel } from \"@/lib/eve/model-selection\";\n\nconst FOLLOWUP_TIMEOUT_MS = 15_000;\nconst log = createModuleLogger(\"eve.followup-suggestions\");\n\n/** Optional generation is claimed once; failures never fail the completed answer. */\nexport const generateEveFollowupSuggestions = async (\n context: FollowupContext,\n scope: ModelCallScope & { readonly turnId: string; readonly eventId: string }\n): Promise<void> => {\n if (\n !(config.ai.tools.followupSuggestions.enabled && context.assistant.trim())\n ) {\n return undefined;\n }\n const modelId = config.ai.tools.followupSuggestions.default;\n try {\n const chatId = await claimEveFollowup(\n scope.ownerId,\n scope.sessionId,\n scope.turnId,\n scope.eventId\n );\n if (chatId === null) {\n return;\n }\n const resolved = accountEveModel(await resolveEveModel(modelId), scope);\n const result = await generateText({\n model: resolved.model,\n ...resolved.modelOptions,\n abortSignal: AbortSignal.timeout(FOLLOWUP_TIMEOUT_MS),\n maxOutputTokens: 512,\n // Hidden provider retries would lose per-attempt usage evidence.\n maxRetries: 0,\n messages: [\n { content: context.user, role: \"user\" },\n { content: context.assistant, role: \"assistant\" },\n {\n content:\n \"What question should I ask next? Return 3 to 5 distinct suggested questions, each at most 80 characters. Use the conversation's language.\",\n role: \"user\",\n },\n ],\n output: Output.object({ schema: eveFollowupSuggestions }),\n });\n // Attempt receipt capture before parsing: malformed JSON can still cost money.\n await finishEveFollowup(scope.ownerId, chatId, scope.eventId, [\n ...new Set(eveFollowupSuggestions.parse(result.output).suggestions),\n ]);\n } catch (error) {\n log.error(\n {\n eventId: scope.eventId,\n errorType: error instanceof Error ? error.name : \"unknown\",\n sessionId: scope.sessionId,\n turnId: scope.turnId,\n },\n \"Follow-up generation or storage failed\"\n );\n }\n};\n",
62
62
  "type": "registry:file",
63
- "target": "~/plugins/followup-suggestions/generate-suggestions.ts"
63
+ "target": "~/chatjs/plugins/followup-suggestions/generate-suggestions.ts"
64
64
  },
65
65
  {
66
66
  "path": "src/plugins/followup-suggestions/src/router.ts",
67
- "content": "import { z } from \"zod\";\nimport { createTRPCRouter } from \"@/trpc/init\";\nimport { eveOwnedProcedure } from \"@/trpc/eve-owned-procedure\";\nimport { getEveFollowup } from \"./followup-queries\";\n\nexport const followupSuggestionsRouter = createTRPCRouter({\n get: eveOwnedProcedure\n .input(\n z.object({\n conversationId: z.uuid(),\n eventId: z.string().min(1).max(512),\n })\n )\n .query(\n async ({\n ctx,\n input,\n }: {\n readonly ctx: { readonly eveOwnerId: string };\n readonly input: {\n readonly conversationId: string;\n readonly eventId: string;\n };\n }) =>\n await getEveFollowup(\n ctx.eveOwnerId,\n input.conversationId,\n input.eventId\n )\n ),\n});\n",
67
+ "content": "import { z } from \"zod\";\nimport { createTRPCRouter } from \"@/trpc/init\";\nimport { eveOwnedProcedure } from \"@/trpc/eve-owned-procedure\";\nimport { getEveFollowup } from \"./followup-queries\";\n\nconst followupSuggestionsProcedures = {\n get: eveOwnedProcedure\n .input(\n z.object({\n branchId: z.uuid(),\n eventId: z.string().min(1).max(512),\n })\n )\n .query(\n async ({\n ctx,\n input,\n }: {\n readonly ctx: { readonly eveOwnerId: string };\n readonly input: {\n readonly branchId: string;\n readonly eventId: string;\n };\n }) => await getEveFollowup(ctx.eveOwnerId, input.branchId, input.eventId)\n ),\n};\n\nexport const router = createTRPCRouter({\n followupSuggestions: followupSuggestionsProcedures,\n});\n",
68
68
  "type": "registry:file",
69
- "target": "~/plugins/followup-suggestions/router.ts"
70
- },
71
- {
72
- "path": "src/plugins/followup-suggestions/src/server-plugin.ts",
73
- "content": "import type { ChatPlugin } from \"@/lib/plugin-contracts\";\nimport { followupSuggestionsRouter } from \"./router\";\n\nexport const followupSuggestions = () =>\n ({\n id: \"followup-suggestions\",\n routers: { followupSuggestions: followupSuggestionsRouter },\n }) satisfies ChatPlugin;\n",
74
- "type": "registry:file",
75
- "target": "~/plugins/followup-suggestions/server-plugin.ts"
69
+ "target": "~/chatjs/plugins/followup-suggestions/router.ts"
76
70
  },
77
71
  {
78
72
  "path": "src/plugins/followup-suggestions/src/suggestion-output.ts",
79
73
  "content": "import { z } from \"zod\";\n\nexport const eveFollowupSuggestions = z.object({\n suggestions: z.array(z.string().trim().min(1).max(80)).min(3).max(5),\n});\n",
80
74
  "type": "registry:file",
81
- "target": "~/plugins/followup-suggestions/suggestion-output.ts"
75
+ "target": "~/chatjs/plugins/followup-suggestions/suggestion-output.ts"
82
76
  },
83
77
  {
84
78
  "path": "src/plugins/followup-suggestions/src/suggestions.tsx",
85
- "content": "\"use client\";\n\nimport React from \"react\";\nimport type { ChatSuggestionsProps } from \"@/lib/chat-plugin-contracts\";\nimport { useEveFollowups } from \"./use-followups\";\nimport { FollowUpSuggestionsView } from \"./followup-suggestions-view\";\n\nexport const FollowupSuggestions = ({\n conversationId,\n events,\n lastMessage,\n onSelect,\n disabled,\n}: ChatSuggestionsProps): React.JSX.Element | null => {\n const suggestions = useEveFollowups(conversationId, events, lastMessage);\n return (\n <FollowUpSuggestionsView\n suggestions={suggestions}\n onSelect={onSelect}\n disabled={disabled}\n />\n );\n};\n",
79
+ "content": "\"use client\";\n\nimport React from \"react\";\nimport type { ChatSuggestionsProps } from \"@/chatjs/core/chat/contracts\";\nimport { useEveFollowups } from \"./use-followups\";\nimport { FollowUpSuggestionsView } from \"./followup-suggestions-view\";\n\nexport const FollowupSuggestions = ({\n branchId,\n sessionId,\n events,\n lastMessage,\n onSelect,\n disabled,\n}: ChatSuggestionsProps): React.JSX.Element | null => {\n const suggestions = useEveFollowups(branchId, sessionId, events, lastMessage);\n return (\n <FollowUpSuggestionsView\n suggestions={suggestions}\n onSelect={onSelect}\n disabled={disabled}\n />\n );\n};\n",
86
80
  "type": "registry:file",
87
- "target": "~/plugins/followup-suggestions/suggestions.tsx"
81
+ "target": "~/chatjs/plugins/followup-suggestions/suggestions.tsx"
88
82
  },
89
83
  {
90
84
  "path": "src/plugins/followup-suggestions/src/use-followups.ts",
91
- "content": "\"use client\";\n\nimport { useQuery } from \"@tanstack/react-query\";\nimport { useTRPC } from \"@/trpc/react\";\nimport type { ChatSuggestionsProps } from \"@/lib/chat-plugin-contracts\";\nimport { followupCompletion } from \"./followup-completion\";\nimport { config } from \"@/lib/config\";\n\nconst EMPTY_SUGGESTIONS: readonly string[] = [];\nconst POLL_INTERVAL_MS = 1000;\nconst MAX_POLLS = 20;\n\nexport const useEveFollowups = (\n conversationId: string,\n events: Parameters<typeof followupCompletion>[0],\n message: ChatSuggestionsProps[\"lastMessage\"]\n): readonly string[] => {\n const trpc = useTRPC();\n const eventId =\n message?.role === \"assistant\"\n ? followupCompletion(events, message.metadata?.turnId)\n : undefined;\n const query = useQuery({\n ...trpc.followupSuggestions.get.queryOptions({\n conversationId,\n eventId: eventId ?? \"\",\n }),\n enabled:\n config.ai.tools.followupSuggestions.enabled && eventId !== undefined,\n retry: false,\n refetchInterval: (current) =>\n current.state.status !== \"error\" &&\n current.state.data === null &&\n current.state.dataUpdateCount < MAX_POLLS\n ? POLL_INTERVAL_MS\n : false,\n });\n return !config.ai.tools.followupSuggestions.enabled || eventId === undefined\n ? EMPTY_SUGGESTIONS\n : (query.data ?? EMPTY_SUGGESTIONS);\n};\n",
85
+ "content": "\"use client\";\n\nimport { useQuery } from \"@tanstack/react-query\";\nimport { useTRPC } from \"@/trpc/react\";\nimport type { ChatSuggestionsProps } from \"@/chatjs/core/chat/contracts\";\nimport { followupCompletion } from \"./followup-completion\";\nimport { config } from \"@/lib/config\";\n\nconst EMPTY_SUGGESTIONS: readonly string[] = [];\nconst POLL_INTERVAL_MS = 1000;\nconst MAX_POLLS = 20;\n\nexport const useEveFollowups = (\n branchId: string,\n sessionId: string,\n events: Parameters<typeof followupCompletion>[0],\n message: ChatSuggestionsProps[\"lastMessage\"]\n): readonly string[] => {\n const trpc = useTRPC();\n const eventId =\n message?.role === \"assistant\"\n ? followupCompletion(events, message.metadata?.turnId, sessionId)\n : undefined;\n const query = useQuery({\n ...trpc.followupSuggestions.get.queryOptions({\n branchId,\n eventId: eventId ?? \"\",\n }),\n enabled:\n config.ai.tools.followupSuggestions.enabled && eventId !== undefined,\n retry: false,\n refetchInterval: (current) =>\n current.state.status !== \"error\" &&\n current.state.data === null &&\n current.state.dataUpdateCount < MAX_POLLS\n ? POLL_INTERVAL_MS\n : false,\n });\n return !config.ai.tools.followupSuggestions.enabled || eventId === undefined\n ? EMPTY_SUGGESTIONS\n : (query.data ?? EMPTY_SUGGESTIONS);\n};\n",
92
86
  "type": "registry:file",
93
- "target": "~/plugins/followup-suggestions/use-followups.ts"
87
+ "target": "~/chatjs/plugins/followup-suggestions/use-followups.ts"
94
88
  },
95
89
  {
96
90
  "path": "src/plugins/followup-suggestions/adapters/agent/hooks/followup-suggestions.ts",
97
- "content": "export { default } from \"@/plugins/followup-suggestions/followup-hook\";\n",
91
+ "content": "// ChatJS source: followup-suggestions. Ownership: chatjs/plugins/followup-suggestions/plugin.json.\nexport { default } from \"@/chatjs/plugins/followup-suggestions/followup-hook\";\n",
98
92
  "type": "registry:file",
99
93
  "target": "~/agent/hooks/followup-suggestions.ts"
100
94
  },
101
95
  {
102
96
  "path": "dist/source/followup-suggestions.json",
103
- "content": "{\n \"id\": \"followup-suggestions\",\n \"kind\": \"plugin\",\n \"files\": [\n \"plugins/followup-suggestions/chat.ts\",\n \"plugins/followup-suggestions/client-plugin.ts\",\n \"plugins/followup-suggestions/followup-completion.ts\",\n \"plugins/followup-suggestions/followup-context.ts\",\n \"plugins/followup-suggestions/followup-hook.ts\",\n \"plugins/followup-suggestions/followup-queries.ts\",\n \"plugins/followup-suggestions/followup-schema.ts\",\n \"plugins/followup-suggestions/followup-suggestions-view.tsx\",\n \"plugins/followup-suggestions/generate-suggestions.ts\",\n \"plugins/followup-suggestions/router.ts\",\n \"plugins/followup-suggestions/server-plugin.ts\",\n \"plugins/followup-suggestions/suggestion-output.ts\",\n \"plugins/followup-suggestions/suggestions.tsx\",\n \"plugins/followup-suggestions/use-followups.ts\",\n \"agent/hooks/followup-suggestions.ts\"\n ],\n \"databaseSchemas\": [\n \"plugins/followup-suggestions/followup-schema.ts\"\n ],\n \"chat\": {\n \"export\": \"followupChat\"\n },\n \"server\": {\n \"export\": \"followupSuggestions\",\n \"routers\": [\n \"followupSuggestions\"\n ]\n },\n \"client\": {\n \"export\": \"followupSuggestionsClient\",\n \"composerControls\": [],\n \"settingsItems\": [],\n \"chat\": true\n },\n \"contractVersion\": 2,\n \"uiBase\": \"radix\"\n}\n",
97
+ "content": "{\n \"contractVersion\": 3,\n \"uiBase\": \"radix\",\n \"id\": \"followup-suggestions\",\n \"kind\": \"plugin\",\n \"files\": [\n \"chatjs/plugins/followup-suggestions/chat-server.ts\",\n \"chatjs/plugins/followup-suggestions/chat-ui.ts\",\n \"chatjs/plugins/followup-suggestions/followup-completion.ts\",\n \"chatjs/plugins/followup-suggestions/followup-context.ts\",\n \"chatjs/plugins/followup-suggestions/followup-hook.ts\",\n \"chatjs/plugins/followup-suggestions/followup-queries.ts\",\n \"chatjs/plugins/followup-suggestions/followup-schema.ts\",\n \"chatjs/plugins/followup-suggestions/followup-suggestions-view.tsx\",\n \"chatjs/plugins/followup-suggestions/generate-suggestions.ts\",\n \"chatjs/plugins/followup-suggestions/router.ts\",\n \"chatjs/plugins/followup-suggestions/suggestion-output.ts\",\n \"chatjs/plugins/followup-suggestions/suggestions.tsx\",\n \"chatjs/plugins/followup-suggestions/use-followups.ts\",\n \"agent/hooks/followup-suggestions.ts\"\n ],\n \"databaseSchemas\": [\n \"chatjs/plugins/followup-suggestions/followup-schema.ts\"\n ]\n}\n",
104
98
  "type": "registry:file",
105
- "target": "~/plugins/followup-suggestions/chatjs.json"
99
+ "target": "~/chatjs/plugins/followup-suggestions/plugin.json"
106
100
  }
107
101
  ],
108
102
  "meta": {
109
103
  "chatjs": {
104
+ "contractVersion": 3,
105
+ "uiBase": "radix",
110
106
  "id": "followup-suggestions",
111
107
  "kind": "plugin",
112
108
  "files": [
113
- "plugins/followup-suggestions/chat.ts",
114
- "plugins/followup-suggestions/client-plugin.ts",
115
- "plugins/followup-suggestions/followup-completion.ts",
116
- "plugins/followup-suggestions/followup-context.ts",
117
- "plugins/followup-suggestions/followup-hook.ts",
118
- "plugins/followup-suggestions/followup-queries.ts",
119
- "plugins/followup-suggestions/followup-schema.ts",
120
- "plugins/followup-suggestions/followup-suggestions-view.tsx",
121
- "plugins/followup-suggestions/generate-suggestions.ts",
122
- "plugins/followup-suggestions/router.ts",
123
- "plugins/followup-suggestions/server-plugin.ts",
124
- "plugins/followup-suggestions/suggestion-output.ts",
125
- "plugins/followup-suggestions/suggestions.tsx",
126
- "plugins/followup-suggestions/use-followups.ts",
109
+ "chatjs/plugins/followup-suggestions/chat-server.ts",
110
+ "chatjs/plugins/followup-suggestions/chat-ui.ts",
111
+ "chatjs/plugins/followup-suggestions/followup-completion.ts",
112
+ "chatjs/plugins/followup-suggestions/followup-context.ts",
113
+ "chatjs/plugins/followup-suggestions/followup-hook.ts",
114
+ "chatjs/plugins/followup-suggestions/followup-queries.ts",
115
+ "chatjs/plugins/followup-suggestions/followup-schema.ts",
116
+ "chatjs/plugins/followup-suggestions/followup-suggestions-view.tsx",
117
+ "chatjs/plugins/followup-suggestions/generate-suggestions.ts",
118
+ "chatjs/plugins/followup-suggestions/router.ts",
119
+ "chatjs/plugins/followup-suggestions/suggestion-output.ts",
120
+ "chatjs/plugins/followup-suggestions/suggestions.tsx",
121
+ "chatjs/plugins/followup-suggestions/use-followups.ts",
127
122
  "agent/hooks/followup-suggestions.ts"
128
123
  ],
129
124
  "databaseSchemas": [
130
- "plugins/followup-suggestions/followup-schema.ts"
131
- ],
132
- "chat": {
133
- "export": "followupChat"
134
- },
135
- "server": {
136
- "export": "followupSuggestions",
137
- "routers": [
138
- "followupSuggestions"
139
- ]
140
- },
141
- "client": {
142
- "export": "followupSuggestionsClient",
143
- "composerControls": [],
144
- "settingsItems": [],
145
- "chat": true
146
- },
147
- "contractVersion": 2,
148
- "uiBase": "radix"
125
+ "chatjs/plugins/followup-suggestions/followup-schema.ts"
126
+ ]
149
127
  }
150
128
  },
151
129
  "type": "registry:item"
@@ -12,7 +12,7 @@
12
12
  "path": "src/storage/ftp/storage-provider.ts",
13
13
  "content": "import type { FtpAdapter, FtpAdapterOptions } from \"files-sdk/ftp\";\nimport { ftp } from \"files-sdk/ftp\";\n\nconst getSecureDefault = (): true | \"implicit\" => {\n if (process.env.FTP_SECURE === \"implicit\") {\n return \"implicit\";\n }\n return true;\n};\n\nexport const createStorageAdapter = (\n options: Readonly<FtpAdapterOptions> = {}\n): FtpAdapter => {\n const secure = options.secure ?? getSecureDefault();\n return ftp({ ...options, secure });\n};\n",
14
14
  "type": "registry:file",
15
- "target": "~/lib/storage-provider.ts"
15
+ "target": "~/chatjs/providers/storage.ts"
16
16
  }
17
17
  ],
18
18
  "meta": {
@@ -22,6 +22,23 @@
22
22
  "port",
23
23
  "root"
24
24
  ],
25
+ "configFields": [
26
+ {
27
+ "key": "host",
28
+ "label": "host",
29
+ "type": "text"
30
+ },
31
+ {
32
+ "key": "port",
33
+ "label": "port",
34
+ "type": "port"
35
+ },
36
+ {
37
+ "key": "root",
38
+ "label": "root",
39
+ "type": "text"
40
+ }
41
+ ],
25
42
  "contractVersion": 1,
26
43
  "envRequirements": [
27
44
  {
@@ -12,7 +12,7 @@
12
12
  "path": "src/storage/gcs/storage-provider.ts",
13
13
  "content": "export { gcs as createStorageAdapter } from \"files-sdk/gcs\";\n",
14
14
  "type": "registry:file",
15
- "target": "~/lib/storage-provider.ts"
15
+ "target": "~/chatjs/providers/storage.ts"
16
16
  }
17
17
  ],
18
18
  "meta": {
@@ -20,6 +20,13 @@
20
20
  "configKeys": [
21
21
  "bucket"
22
22
  ],
23
+ "configFields": [
24
+ {
25
+ "key": "bucket",
26
+ "label": "bucket",
27
+ "type": "text"
28
+ }
29
+ ],
23
30
  "contractVersion": 1,
24
31
  "envRequirements": [],
25
32
  "id": "gcs",
@@ -3,7 +3,7 @@
3
3
  "name": "generate-image",
4
4
  "description": "Generate and edit images using the selected gateway and storage",
5
5
  "dependencies": [
6
- "ai@7.0.137",
6
+ "ai@7.0.172",
7
7
  "zod@4.5.4",
8
8
  "lucide-react@0.553.0"
9
9
  ],
@@ -12,65 +12,67 @@
12
12
  "path": "src/tools/generate-image/configuration-schema.ts",
13
13
  "content": "import { z } from \"zod\";\nimport { imageModelSchema, modelRoles } from \"@/lib/config-models\";\n\nconst configSchema = z\n .strictObject({\n default: imageModelSchema.optional().prefault(modelRoles.image),\n })\n .prefault({});\nexport { configSchema };\n",
14
14
  "type": "registry:file",
15
- "target": "~/tools/chatjs/generate-image/configuration-schema.ts"
15
+ "target": "~/chatjs/tools/generate-image/configuration-schema.ts"
16
16
  },
17
17
  {
18
18
  "path": "src/tools/generate-image/tool.ts",
19
19
  "content": "import type { ImageRequestContext } from \"./image-request\";\nimport { defineTool } from \"eve/tools\";\nimport { generateImageInput } from \"./schemas\";\nimport { runImageRequest } from \"./image-request\";\nimport { toolResultToModelOutput } from \"@/lib/eve/tool-model-output\";\nimport type { z } from \"zod\";\n\nexport const generateImageTool = defineTool({\n description: `Generate an image from a user-provided prompt.\n\nThe assistant may make small, neutral adjustments to improve clarity, composition, or technical quality, while strictly preserving the user’s original intent, meaning, and message.\n\nThe assistant must not add new subjects, claims, branding, or alter the tone or intent of the prompt.\n`,\n execute: async (\n { prompt }: Readonly<z.infer<typeof generateImageInput>>,\n context: Readonly<ImageRequestContext>\n ) => await runImageRequest(prompt, context),\n inputSchema: generateImageInput,\n toModelOutput: toolResultToModelOutput,\n});\n",
20
20
  "type": "registry:file",
21
- "target": "~/tools/chatjs/generate-image/tool.ts"
21
+ "target": "~/chatjs/tools/generate-image/tool.ts"
22
22
  },
23
23
  {
24
24
  "path": "src/tools/generate-image/renderer.tsx",
25
- "content": "\"use client\";\nimport { ImageActions, ImageModal } from \"@/components/image-modal\";\nimport React, { useState } from \"react\";\nimport { generateImageInput, generateImageResult } from \"./schemas\";\nimport Image from \"next/image\";\nimport { ImageOffIcon } from \"lucide-react\";\nimport type { ReadonlyNativeSurface } from \"@/lib/readonly-native-surface\";\nimport type { ToolRendererProps } from \"@/lib/ai/define-tool-renderer\";\nimport { defineToolRenderer } from \"@/lib/ai/define-tool-renderer\";\nimport { useImageLoadError } from \"@/hooks/use-image-load-error\";\n\ntype GenerateImageTool = ToolRendererProps<\n typeof generateImageInput,\n typeof generateImageResult\n>[\"tool\"];\n\nconst GenerateImageView = ({\n tool,\n}: ReadonlyNativeSurface<{\n tool: GenerateImageTool;\n}>): React.JSX.Element | null => {\n const [dialogOpen, setDialogOpen] = useState(false);\n const imageUrl = tool.output?.imageUrl;\n const { handleImageError, imageUnavailable } = useImageLoadError(imageUrl);\n\n if (tool.state === \"input-streaming\" || tool.state === \"input-available\") {\n return (\n <div className=\"flex w-full flex-col items-center justify-center gap-4 rounded-lg border p-8\">\n <div className=\"bg-muted-foreground/20 h-64 w-full animate-pulse rounded-lg\" />\n <div className=\"text-muted-foreground\">\n Generating image: &quot;\n {tool.input?.prompt ?? \"Preparing prompt…\"}\n &quot;\n </div>\n </div>\n );\n }\n const { output } = tool;\n if (output === undefined) {\n return null;\n }\n\n return (\n <>\n <div className=\"flex w-full flex-col gap-4 overflow-hidden rounded-lg border\">\n <div className=\"group relative\">\n {imageUnavailable ? (\n <output className=\"bg-muted/30 text-muted-foreground flex min-h-64 w-full flex-col items-center justify-center gap-2\">\n <ImageOffIcon className=\"size-8\" />\n <span>Generated image unavailable</span>\n </output>\n ) : (\n <>\n <button\n className=\"w-full cursor-pointer text-left\"\n onClick={(): void => {\n setDialogOpen(true);\n }}\n type=\"button\"\n >\n <Image\n alt={output.prompt}\n loading=\"eager\"\n unoptimized\n className=\"h-auto w-full max-w-full\"\n height={512}\n onError={handleImageError}\n src={output.imageUrl}\n width={512}\n />\n </button>\n <ImageActions\n className=\"absolute top-2 right-2 opacity-0 transition-opacity group-focus-within:opacity-100 group-hover:opacity-100\"\n imageUrl={output.imageUrl}\n />\n </>\n )}\n </div>\n <div className=\"p-4 pt-0\">\n <p className=\"text-muted-foreground text-sm\">\n Generated from: &quot;{output.prompt}&quot;\n </p>\n </div>\n </div>\n\n <ImageModal\n imageName={output.prompt}\n imageUrl={output.imageUrl}\n isOpen={dialogOpen}\n onClose={(): void => {\n setDialogOpen(false);\n }}\n />\n </>\n );\n};\n\nexport const GenerateImageRenderer = defineToolRenderer({\n inputSchema: generateImageInput,\n outputSchema: generateImageResult,\n render: GenerateImageView,\n});\n",
25
+ "content": "\"use client\";\nimport { ImageActions } from \"@/components/image-actions\";\nimport { ArtifactViewerActions } from \"@/components/artifact-actions\";\nimport React from \"react\";\nimport { generateImageInput, generateImageResult } from \"./schemas\";\nimport Image from \"next/image\";\nimport { ImageOffIcon } from \"lucide-react\";\nimport type { ReadonlyNativeSurface } from \"@/lib/readonly-native-surface\";\nimport type { ToolRendererProps } from \"@/chatjs/core/tools/define-renderer\";\nimport { defineToolRenderer } from \"@/chatjs/core/tools/define-renderer\";\nimport { useImageLoadError } from \"@/hooks/use-image-load-error\";\n\ntype GenerateImageTool = ToolRendererProps<\n typeof generateImageInput,\n typeof generateImageResult\n>[\"tool\"];\n\nconst GenerateImageView = ({\n tool,\n}: ReadonlyNativeSurface<{\n tool: GenerateImageTool;\n}>): React.JSX.Element | null => {\n const imageUrl = tool.output?.imageUrl;\n const { handleImageError, imageUnavailable } = useImageLoadError(imageUrl);\n\n if (tool.state === \"input-streaming\" || tool.state === \"input-available\") {\n return (\n <div className=\"flex w-full flex-col items-center justify-center gap-4 rounded-lg border p-8\">\n <div className=\"bg-muted-foreground/20 h-64 w-full animate-pulse rounded-lg\" />\n <div className=\"text-muted-foreground\">\n Generating image: &quot;\n {tool.input?.prompt ?? \"Preparing prompt…\"}\n &quot;\n </div>\n </div>\n );\n }\n const { output } = tool;\n if (output === undefined) {\n return null;\n }\n\n return (\n <div className=\"flex w-full flex-col gap-4 overflow-hidden rounded-lg border\">\n <div className=\"group relative\">\n {imageUnavailable ? (\n <output className=\"bg-muted/30 text-muted-foreground flex min-h-64 w-full flex-col items-center justify-center gap-2\">\n <ImageOffIcon className=\"size-8\" />\n <span>Generated image unavailable</span>\n </output>\n ) : (\n <>\n <Image\n alt={output.prompt}\n loading=\"eager\"\n unoptimized\n className=\"h-auto w-full max-w-full\"\n height={512}\n onError={handleImageError}\n src={output.imageUrl}\n width={512}\n />\n <div className=\"absolute top-2 right-2 flex items-center gap-1\">\n <ArtifactViewerActions\n artifact={{\n fileId: output.fileId,\n url: output.imageUrl,\n name: output.prompt,\n mediaType: \"image/*\",\n }}\n />\n <ImageActions imageUrl={output.imageUrl} />\n </div>\n </>\n )}\n </div>\n <div className=\"p-4 pt-0\">\n <p className=\"text-muted-foreground text-sm\">\n Generated from: &quot;{output.prompt}&quot;\n </p>\n </div>\n </div>\n );\n};\n\nexport const GenerateImageRenderer = defineToolRenderer({\n inputSchema: generateImageInput,\n outputSchema: generateImageResult,\n render: GenerateImageView,\n});\n",
26
26
  "type": "registry:file",
27
- "target": "~/tools/chatjs/generate-image/renderer.tsx"
27
+ "target": "~/chatjs/tools/generate-image/renderer.tsx"
28
28
  },
29
29
  {
30
30
  "path": "src/tools/generate-image/schemas.ts",
31
31
  "content": "import { z } from \"zod\";\n\nconst generateImageInput = z.object({\n prompt: z\n .string()\n .describe(\n \"The user’s image prompt. The original intent, message, and meaning must remain unchanged. No new ideas, claims, or content may be introduced.\"\n ),\n});\n\nconst generateImageResult = z.object({\n fileId: z.string().optional(),\n imageUrl: z.string(),\n prompt: z.string(),\n});\nexport { generateImageInput, generateImageResult };\n",
32
32
  "type": "registry:file",
33
- "target": "~/tools/chatjs/generate-image/schemas.ts"
33
+ "target": "~/chatjs/tools/generate-image/schemas.ts"
34
34
  },
35
35
  {
36
36
  "path": "src/tools/generate-image/image-model.ts",
37
37
  "content": "import type { ToolModelProvider } from \"@/lib/ai/tool-context\";\nimport { config } from \"@/lib/config\";\n\ntype ImageModelSelection =\n | {\n modelId: string;\n multimodal: true;\n usageModelId: Awaited<\n ReturnType<ToolModelProvider[\"getModelDefinition\"]>\n >[\"id\"];\n }\n | { modelId: string; multimodal: false; usageModelId?: never };\nconst findMultimodalModel = async (\n provider: Readonly<ToolModelProvider>,\n modelId: unknown\n): Promise<\n Extract<ImageModelSelection, { multimodal: true }> | { multimodal: false }\n> => {\n if (typeof modelId !== \"string\" || modelId === \"\") {\n return { multimodal: false };\n }\n try {\n const model = await provider.getModelDefinition(modelId);\n if (model.output.image) {\n return {\n modelId: model.apiModelId,\n multimodal: true,\n usageModelId: model.id,\n };\n }\n } catch {\n /* A model absent from the dynamic registry may be a dedicated image model. */\n }\n return { multimodal: false };\n};\nconst resolveImageModel = async (\n provider: Readonly<ToolModelProvider>,\n selectedModel: unknown\n): Promise<ImageModelSelection> => {\n const selected = await findMultimodalModel(provider, selectedModel);\n if (selected.multimodal) {\n return selected;\n }\n const defaultId = config.ai.tools.image.default;\n if (typeof defaultId !== \"string\") {\n throw new TypeError(\n \"Set ai.tools.image.default to an image model supported by your gateway.\"\n );\n }\n const fallback = await findMultimodalModel(provider, defaultId);\n\n if (fallback.multimodal) {\n return fallback;\n }\n return { modelId: defaultId, multimodal: false };\n};\nexport { resolveImageModel };\nexport type { ImageModelSelection };\n",
38
38
  "type": "registry:file",
39
- "target": "~/tools/chatjs/generate-image/image-model.ts"
39
+ "target": "~/chatjs/tools/generate-image/image-model.ts"
40
40
  },
41
41
  {
42
42
  "path": "src/tools/generate-image/image-input.ts",
43
43
  "content": "import type { FileUIPart } from \"ai\";\nimport { downloadFile } from \"@/lib/file-storage\";\nimport { getBaseUrl } from \"@/lib/url\";\nimport { keyFromFileUrl } from \"@/lib/file-url\";\n\nconst INLINE_IMAGE =\n /^data:image\\/(?:png|jpeg|webp|gif);base64,(?<base64>[A-Za-z0-9+/=]+)$/u;\n\nconst fetchImageBuffer = async (value: string): Promise<Buffer> => {\n // Inline images do not initiate a network request.\n const { groups } = INLINE_IMAGE.exec(value) ?? {};\n if (groups && typeof groups.base64 === \"string\" && groups.base64 !== \"\") {\n return Buffer.from(groups.base64, \"base64\");\n }\n const url = new URL(value, getBaseUrl());\n const { origin } = new URL(getBaseUrl());\n const key = keyFromFileUrl(value);\n if (\n url.origin !== origin ||\n url.username !== \"\" ||\n url.password !== \"\" ||\n !(typeof key === \"string\" && key !== \"\")\n ) {\n throw new Error(\n \"Image editing only accepts uploaded ChatJS files or inline images.\"\n );\n }\n // Read the configured storage directly. Never follow user-supplied URLs or redirects.\n const file = await downloadFile(key);\n return Buffer.from(await file.arrayBuffer());\n};\nconst collectEditImages = async ({\n imageParts,\n lastGeneratedImage,\n}: Readonly<{\n imageParts: readonly Readonly<Pick<FileUIPart, \"url\">>[];\n lastGeneratedImage: Readonly<{ imageUrl: string }> | null;\n}>): Promise<Buffer[]> =>\n await Promise.all([\n ...(lastGeneratedImage\n ? [fetchImageBuffer(lastGeneratedImage.imageUrl)]\n : []),\n ...imageParts.map(\n async (imagePart) => await fetchImageBuffer(imagePart.url)\n ),\n ]);\nexport { collectEditImages };\n",
44
44
  "type": "registry:file",
45
- "target": "~/tools/chatjs/generate-image/image-input.ts"
45
+ "target": "~/chatjs/tools/generate-image/image-input.ts"
46
46
  },
47
47
  {
48
48
  "path": "src/tools/generate-image/image-errors.ts",
49
49
  "content": "const ABSENT_DIAGNOSTIC_VALUE = undefined;\n\nconst serializeError = (\n error: unknown\n): { name?: string; message: string; stack?: string; raw?: unknown } => {\n if (error instanceof Error) {\n return { message: error.message, name: error.name, stack: error.stack };\n }\n if (typeof error === \"object\" && error !== null && \"then\" in error) {\n return { message: \"Error was a Promise - check raw\", raw: error };\n }\n if (typeof error === \"object\" && error !== null && \"message\" in error) {\n const message = String(error.message);\n const hasName = Boolean(Reflect.get(error, \"name\"));\n const name: unknown = hasName\n ? Reflect.get(error, \"name\")\n : ABSENT_DIAGNOSTIC_VALUE;\n return { message, name: hasName ? String(name) : ABSENT_DIAGNOSTIC_VALUE };\n }\n return { message: String(error), raw: error };\n};\nconst resolveError = async (thrownValue: unknown): Promise<unknown> => {\n if (\n typeof thrownValue === \"object\" &&\n thrownValue !== null &&\n \"then\" in thrownValue\n ) {\n try {\n return await Promise.resolve(thrownValue);\n } catch (resolvedError) {\n return resolvedError;\n }\n }\n return thrownValue;\n};\nconst constructorName = (value: unknown): unknown => {\n if (value === null || value === ABSENT_DIAGNOSTIC_VALUE) {\n return ABSENT_DIAGNOSTIC_VALUE;\n }\n const constructor: unknown = Reflect.get(new Object(value), \"constructor\");\n if (constructor === null || constructor === ABSENT_DIAGNOSTIC_VALUE) {\n return ABSENT_DIAGNOSTIC_VALUE;\n }\n return Reflect.get(new Object(constructor), \"name\");\n};\nconst getErrorDebugInfo = (\n error: unknown\n): { errorConstructor: unknown; errorKeys: string[]; errorType: string } => ({\n errorConstructor: constructorName(error),\n errorKeys:\n typeof error === \"object\" && error !== null ? Object.keys(error) : [],\n errorType: typeof error,\n});\nexport {\n serializeError,\n resolveError,\n getErrorDebugInfo,\n ABSENT_DIAGNOSTIC_VALUE,\n};\n",
50
50
  "type": "registry:file",
51
- "target": "~/tools/chatjs/generate-image/image-errors.ts"
51
+ "target": "~/chatjs/tools/generate-image/image-errors.ts"
52
52
  },
53
53
  {
54
54
  "path": "src/tools/generate-image/image-generation.ts",
55
- "content": "import { generateImage, generateText } from \"ai\";\nimport type { FileUIPart } from \"ai\";\nimport type { FileUploader } from \"@/lib/file-storage\";\nimport type { ImageModelSelection } from \"./image-model\";\nimport type { ToolModelProvider } from \"@/lib/ai/tool-context\";\nimport type { createEveToolCost } from \"@/lib/eve/tool-cost\";\nimport { createModuleLogger } from \"@/lib/logger\";\nimport { collectEditImages } from \"./image-input\";\nimport type { generateImageResult } from \"./schemas\";\nimport type { z } from \"zod\";\n\nconst log = createModuleLogger(\"ai.tools.generate-image\");\nconst EMPTY_IMAGE_BYTES = 0;\nconst GENERATED_IMAGE_COUNT = 1;\nconst NO_GENERATED_IMAGES = 0;\ntype ReadonlyNativeSurface<Value> = Value extends\n | string\n | number\n | bigint\n | boolean\n | symbol\n | null\n | undefined\n ? Value\n : Value extends (...parameters: readonly never[]) => unknown\n ? Value\n : Value extends abstract new (...parameters: readonly never[]) => unknown\n ? Value\n : Value extends object\n ? {\n readonly [Property in keyof Value]: ReadonlyNativeSurface<\n Value[Property]\n >;\n }\n : Value;\ntype ImageStoreFile = (\n filename: string,\n body: ReadonlyNativeSurface<Buffer>,\n mediaType?: string\n) => ReturnType<FileUploader>;\ntype ImageMode = \"edit\" | \"generate\";\ninterface ImageGenerationOptions {\n readonly mode: ImageMode;\n readonly prompt: string;\n readonly imageParts: readonly Readonly<Pick<FileUIPart, \"url\">>[];\n readonly lastGeneratedImage: Readonly<{\n imageUrl: string;\n name: string;\n }> | null;\n readonly startMs: number;\n readonly costAccumulator?: Readonly<ReturnType<typeof createEveToolCost>>;\n readonly abortSignal?: Readonly<AbortSignal>;\n readonly storeFile: ImageStoreFile;\n readonly modelProvider: Readonly<ToolModelProvider>;\n}\ntype GeneratedImageResult = Required<z.infer<typeof generateImageResult>>;\nconst traditionalPrompt = async (\n options: Readonly<ImageGenerationOptions>\n): Promise<string | { text: string; images: Buffer[] }> => {\n if (options.mode !== \"edit\") {\n return options.prompt;\n }\n log.debug(\n {\n attachmentCount: options.imageParts.length,\n lastGeneratedCount: options.lastGeneratedImage\n ? GENERATED_IMAGE_COUNT\n : NO_GENERATED_IMAGES,\n note: \"OpenAI edit mode\",\n },\n \"generateImage: preparing edit images\"\n );\n return { images: await collectEditImages(options), text: options.prompt };\n};\nconst storeImage = async (\n options: Readonly<ImageGenerationOptions>,\n image: Readonly<{\n buffer: ReadonlyNativeSurface<Buffer>;\n filename: string;\n mediaType: string;\n }>,\n model: Readonly<{ modelId: string; multimodal: boolean }>\n): Promise<GeneratedImageResult> => {\n const result = await options.storeFile(\n image.filename,\n image.buffer,\n image.mediaType\n );\n log.info(\n {\n imageUrl: result.url,\n mode: options.mode,\n ms: Date.now() - options.startMs,\n uploadedFilename: image.filename,\n ...(model.multimodal ? { modelId: model.modelId } : {}),\n },\n model.multimodal\n ? \"generateImage: multimodal success\"\n : \"generateImage: success\"\n );\n return {\n fileId: result.fileId,\n imageUrl: result.url,\n prompt: options.prompt,\n };\n};\nconst runGenerateImageTraditional = async (\n options: Readonly<ImageGenerationOptions>,\n modelId: string\n): Promise<GeneratedImageResult> => {\n const prompt = await traditionalPrompt(options);\n const res = await generateImage({\n abortSignal: options.abortSignal,\n model: options.modelProvider.createImageModel(modelId),\n prompt,\n providerOptions: { telemetry: { isEnabled: true } },\n });\n const [firstImage] = res.images;\n log.debug(\n {\n base64Length: firstImage?.base64?.length ?? EMPTY_IMAGE_BYTES,\n mode: options.mode,\n },\n \"generateImage: provider response received\"\n );\n const buffer = Buffer.from(firstImage.base64, \"base64\");\n const filename = `generated-image-${Date.now()}.png`;\n // Provider usage remains billable if the subsequent storage upload fails.\n const { costAccumulator } = options;\n if (costAccumulator) {\n costAccumulator.addImageCost(\n modelId,\n res.images.length,\n res.usage ?? {},\n \"generateImage-traditional\"\n );\n }\n return await storeImage(\n options,\n { buffer, filename, mediaType: \"image/png\" },\n { modelId, multimodal: false }\n );\n};\ninterface ImageContent {\n image: Readonly<Buffer>;\n type: \"image\";\n}\ninterface TextContent {\n text: string;\n type: \"text\";\n}\nconst multimodalContent = async (\n options: Readonly<ImageGenerationOptions>\n): Promise<(ImageContent | TextContent)[]> => {\n const buffers =\n options.mode === \"edit\" ? await collectEditImages(options) : [];\n const images = buffers.map(\n (image: ReadonlyNativeSurface<Buffer>): ImageContent => ({\n image,\n type: \"image\",\n })\n );\n return [\n ...images,\n {\n text:\n options.mode === \"edit\"\n ? `Based on the provided image(s), ${options.prompt}`\n : `Generate an image: ${options.prompt}`,\n type: \"text\",\n },\n ];\n};\nconst storeMultimodalImage = async (\n options: Readonly<ImageGenerationOptions>,\n selection: Readonly<Extract<ImageModelSelection, { multimodal: true }>>,\n imageFile: ReadonlyNativeSurface<{\n mediaType: string;\n base64: string;\n uint8Array: Uint8Array;\n }>\n): Promise<GeneratedImageResult> => {\n log.debug(\n {\n hasBase64: Boolean(imageFile.base64),\n mediaType: imageFile.mediaType,\n mode: options.mode,\n },\n \"generateImage: multimodal response received\"\n );\n const buffer = Buffer.from(imageFile.uint8Array);\n const timestamp = Date.now();\n const [, subtype] = imageFile.mediaType.split(\"/\");\n const ext = typeof subtype === \"string\" && subtype !== \"\" ? subtype : \"png\";\n return await storeImage(\n options,\n {\n buffer,\n filename: `generated-image-${timestamp}.${ext}`,\n mediaType: imageFile.mediaType,\n },\n selection\n );\n};\nconst multimodalProviderOptions = (\n modelId: string\n): {\n google?: { responseModalities: string[] };\n openai?: { modalities: string[] };\n} => ({\n ...((modelId.startsWith(\"google/\") || modelId.includes(\"gemini\")) && {\n google: { responseModalities: [\"TEXT\", \"IMAGE\"] },\n }),\n ...(modelId.startsWith(\"openai/\") && {\n openai: { modalities: [\"text\", \"image\"] },\n }),\n});\nconst runGenerateImageMultimodal = async (\n options: Readonly<ImageGenerationOptions>,\n selection: Readonly<Extract<ImageModelSelection, { multimodal: true }>>\n): Promise<GeneratedImageResult> => {\n const userContent = await multimodalContent(options);\n log.debug(\n {\n imageCount: userContent.filter(\n (part: Readonly<{ type: string }>): boolean => part.type === \"image\"\n ).length,\n mode: options.mode,\n modelId: selection.modelId,\n },\n \"generateImage: using multimodal model\"\n );\n const res = await generateText({\n abortSignal: options.abortSignal,\n messages: [{ content: userContent, role: \"user\" }],\n model: options.modelProvider.createLanguageModel(selection.modelId),\n providerOptions: multimodalProviderOptions(selection.modelId),\n });\n const { costAccumulator } = options;\n if (costAccumulator) {\n costAccumulator.addLLMCost(\n selection.usageModelId,\n res.usage,\n \"generateImage-multimodal\"\n );\n }\n const imageFile = (res.files ?? []).find(\n (file: Readonly<{ mediaType: string }>): boolean =>\n file.mediaType.startsWith(\"image/\")\n );\n if (!imageFile) {\n throw new Error(\"No image generated by multimodal model\");\n }\n return await storeMultimodalImage(options, selection, imageFile);\n};\nexport { runGenerateImageTraditional, runGenerateImageMultimodal };\nexport type { ImageGenerationOptions, GeneratedImageResult, ImageStoreFile };\n",
55
+ "content": "import { generateImage, generateText } from \"ai\";\nimport type { FileUIPart } from \"ai\";\nimport type { FileUploader } from \"@/lib/file-storage\";\nimport type { ImageModelSelection } from \"./image-model\";\nimport type { ToolModelProvider } from \"@/lib/ai/tool-context\";\nimport type { createEveToolCost } from \"@/lib/eve/tool-cost\";\nimport { createModuleLogger } from \"@/lib/logger\";\nimport { collectEditImages } from \"./image-input\";\nimport type { generateImageResult } from \"./schemas\";\nimport type { z } from \"zod\";\n\nconst log = createModuleLogger(\"ai.tools.generate-image\");\nconst EMPTY_IMAGE_BYTES = 0;\nconst GENERATED_IMAGE_COUNT = 1;\nconst NO_GENERATED_IMAGES = 0;\ntype ReadonlyNativeSurface<Value> = Value extends\n | string\n | number\n | bigint\n | boolean\n | symbol\n | null\n | undefined\n ? Value\n : Value extends (...parameters: readonly never[]) => unknown\n ? Value\n : Value extends abstract new (...parameters: readonly never[]) => unknown\n ? Value\n : Value extends object\n ? {\n readonly [Property in keyof Value]: ReadonlyNativeSurface<\n Value[Property]\n >;\n }\n : Value;\ntype ImageStoreFile = (\n filename: string,\n body: ReadonlyNativeSurface<Buffer>,\n mediaType?: string\n) => ReturnType<FileUploader>;\ntype ImageMode = \"edit\" | \"generate\";\ninterface ImageGenerationOptions {\n readonly mode: ImageMode;\n readonly prompt: string;\n readonly imageParts: readonly Readonly<Pick<FileUIPart, \"url\">>[];\n readonly lastGeneratedImage: Readonly<{\n imageUrl: string;\n name: string;\n }> | null;\n readonly startMs: number;\n readonly costAccumulator?: Readonly<ReturnType<typeof createEveToolCost>>;\n readonly abortSignal?: Readonly<AbortSignal>;\n readonly storeFile: ImageStoreFile;\n readonly modelProvider: Readonly<ToolModelProvider>;\n}\ntype GeneratedImageResult = Required<z.infer<typeof generateImageResult>>;\nconst traditionalPrompt = async (\n options: Readonly<ImageGenerationOptions>\n): Promise<string | { text: string; images: Buffer[] }> => {\n if (options.mode !== \"edit\") {\n return options.prompt;\n }\n log.debug(\n {\n attachmentCount: options.imageParts.length,\n lastGeneratedCount: options.lastGeneratedImage\n ? GENERATED_IMAGE_COUNT\n : NO_GENERATED_IMAGES,\n note: \"OpenAI edit mode\",\n },\n \"generateImage: preparing edit images\"\n );\n return { images: await collectEditImages(options), text: options.prompt };\n};\nconst storeImage = async (\n options: Readonly<ImageGenerationOptions>,\n image: Readonly<{\n buffer: ReadonlyNativeSurface<Buffer>;\n filename: string;\n mediaType: string;\n }>,\n model: Readonly<{ modelId: string; multimodal: boolean }>\n): Promise<GeneratedImageResult> => {\n const result = await options.storeFile(\n image.filename,\n image.buffer,\n image.mediaType\n );\n log.info(\n {\n imageUrl: result.url,\n mode: options.mode,\n ms: Date.now() - options.startMs,\n uploadedFilename: image.filename,\n ...(model.multimodal ? { modelId: model.modelId } : {}),\n },\n model.multimodal\n ? \"generateImage: multimodal success\"\n : \"generateImage: success\"\n );\n return {\n fileId: result.fileId,\n imageUrl: result.url,\n prompt: options.prompt,\n };\n};\nconst runGenerateImageTraditional = async (\n options: Readonly<ImageGenerationOptions>,\n modelId: string\n): Promise<GeneratedImageResult> => {\n const prompt = await traditionalPrompt(options);\n const res = await generateImage({\n abortSignal: options.abortSignal,\n model: options.modelProvider.createImageModel(modelId),\n prompt,\n });\n const [firstImage] = res.images;\n log.debug(\n {\n base64Length: firstImage?.base64?.length ?? EMPTY_IMAGE_BYTES,\n mode: options.mode,\n },\n \"generateImage: provider response received\"\n );\n const buffer = Buffer.from(firstImage.base64, \"base64\");\n const filename = `generated-image-${Date.now()}.png`;\n // Provider usage remains billable if the subsequent storage upload fails.\n const { costAccumulator } = options;\n if (costAccumulator) {\n costAccumulator.addImageCost(\n modelId,\n res.images.length,\n res.usage ?? {},\n \"generateImage-traditional\"\n );\n }\n return await storeImage(\n options,\n { buffer, filename, mediaType: \"image/png\" },\n { modelId, multimodal: false }\n );\n};\ninterface ImageContent {\n image: Readonly<Buffer>;\n type: \"image\";\n}\ninterface TextContent {\n text: string;\n type: \"text\";\n}\nconst multimodalContent = async (\n options: Readonly<ImageGenerationOptions>\n): Promise<(ImageContent | TextContent)[]> => {\n const buffers =\n options.mode === \"edit\" ? await collectEditImages(options) : [];\n const images = buffers.map(\n (image: ReadonlyNativeSurface<Buffer>): ImageContent => ({\n image,\n type: \"image\",\n })\n );\n return [\n ...images,\n {\n text:\n options.mode === \"edit\"\n ? `Based on the provided image(s), ${options.prompt}`\n : `Generate an image: ${options.prompt}`,\n type: \"text\",\n },\n ];\n};\nconst storeMultimodalImage = async (\n options: Readonly<ImageGenerationOptions>,\n selection: Readonly<Extract<ImageModelSelection, { multimodal: true }>>,\n imageFile: ReadonlyNativeSurface<{\n mediaType: string;\n base64: string;\n uint8Array: Uint8Array;\n }>\n): Promise<GeneratedImageResult> => {\n log.debug(\n {\n hasBase64: Boolean(imageFile.base64),\n mediaType: imageFile.mediaType,\n mode: options.mode,\n },\n \"generateImage: multimodal response received\"\n );\n const buffer = Buffer.from(imageFile.uint8Array);\n const timestamp = Date.now();\n const [, subtype] = imageFile.mediaType.split(\"/\");\n const ext = typeof subtype === \"string\" && subtype !== \"\" ? subtype : \"png\";\n return await storeImage(\n options,\n {\n buffer,\n filename: `generated-image-${timestamp}.${ext}`,\n mediaType: imageFile.mediaType,\n },\n selection\n );\n};\nconst multimodalProviderOptions = (\n modelId: string\n): {\n google?: { responseModalities: string[] };\n openai?: { modalities: string[] };\n} => ({\n ...((modelId.startsWith(\"google/\") || modelId.includes(\"gemini\")) && {\n google: { responseModalities: [\"TEXT\", \"IMAGE\"] },\n }),\n ...(modelId.startsWith(\"openai/\") && {\n openai: { modalities: [\"text\", \"image\"] },\n }),\n});\nconst runGenerateImageMultimodal = async (\n options: Readonly<ImageGenerationOptions>,\n selection: Readonly<Extract<ImageModelSelection, { multimodal: true }>>\n): Promise<GeneratedImageResult> => {\n const userContent = await multimodalContent(options);\n log.debug(\n {\n imageCount: userContent.filter(\n (part: Readonly<{ type: string }>): boolean => part.type === \"image\"\n ).length,\n mode: options.mode,\n modelId: selection.modelId,\n },\n \"generateImage: using multimodal model\"\n );\n const res = await generateText({\n abortSignal: options.abortSignal,\n messages: [{ content: userContent, role: \"user\" }],\n model: options.modelProvider.createLanguageModel(selection.modelId),\n providerOptions: multimodalProviderOptions(selection.modelId),\n });\n const { costAccumulator } = options;\n if (costAccumulator) {\n costAccumulator.addLLMCost(\n selection.usageModelId,\n res.usage,\n \"generateImage-multimodal\"\n );\n }\n const imageFile = (res.files ?? []).find(\n (file: Readonly<{ mediaType: string }>): boolean =>\n file.mediaType.startsWith(\"image/\")\n );\n if (!imageFile) {\n throw new Error(\"No image generated by multimodal model\");\n }\n return await storeMultimodalImage(options, selection, imageFile);\n};\nexport { runGenerateImageTraditional, runGenerateImageMultimodal };\nexport type { ImageGenerationOptions, GeneratedImageResult, ImageStoreFile };\n",
56
56
  "type": "registry:file",
57
- "target": "~/tools/chatjs/generate-image/image-generation.ts"
57
+ "target": "~/chatjs/tools/generate-image/image-generation.ts"
58
58
  },
59
59
  {
60
60
  "path": "src/tools/generate-image/image-request.ts",
61
- "content": "import {\n ABSENT_DIAGNOSTIC_VALUE,\n getErrorDebugInfo,\n resolveError,\n serializeError,\n} from \"./image-errors\";\nimport type {\n GeneratedImageResult,\n ImageGenerationOptions,\n ImageStoreFile,\n} from \"./image-generation\";\nimport type { ToolUsage } from \"@/lib/eve/tool-usage\";\nimport { eveGeneratedFileUploader } from \"@/lib/eve/generated-files\";\nimport { createEveToolCost } from \"@/lib/eve/tool-cost\";\nimport { createModuleLogger } from \"@/lib/logger\";\nimport { eveToolImageContext } from \"@/lib/eve/tool-image-context\";\nimport { eveToolModelProvider } from \"@/lib/eve/tool-models\";\nimport {\n runGenerateImageMultimodal,\n runGenerateImageTraditional,\n} from \"./image-generation\";\nimport { executeWithToolUsage } from \"@/lib/eve/tool-usage\";\nimport { resolveImageModel } from \"./image-model\";\n\nconst log = createModuleLogger(\"ai.tools.generate-image\");\nconst NO_IMAGE_ATTACHMENTS = 0;\ninterface ImageRequestContext {\n readonly abortSignal: Readonly<AbortSignal>;\n readonly session: Readonly<{\n id: string;\n auth: Readonly<{\n current: Readonly<{\n attributes: Readonly<Record<string, unknown>>;\n }> | null;\n initiator: Readonly<{ principalId: string }> | null;\n }>;\n }>;\n}\ninterface ImageRequest {\n readonly options: Readonly<ImageGenerationOptions>;\n readonly selectedModel: string | undefined;\n}\nconst createImageRequest = (\n prompt: string,\n context: Readonly<ImageRequestContext>,\n usage: Readonly<ToolUsage>\n): ImageRequest => {\n const costAccumulator = createEveToolCost(usage);\n const uploadFile = eveGeneratedFileUploader(context);\n // A provider generation followed by storage failure is an explicit domain result.\n const storeFile: ImageStoreFile = async (filename, body, mediaType) => {\n try {\n return await uploadFile(filename, body, mediaType);\n } catch {\n return usage.fail();\n }\n };\n const { current } = context.session.auth;\n const selected = current && current.attributes.modelId;\n const selectedModel =\n typeof selected === \"string\" ? selected : ABSENT_DIAGNOSTIC_VALUE;\n const { attachments, lastGeneratedImage } = eveToolImageContext.get();\n const startMs = Date.now();\n const imageParts = attachments.filter(\n (part: Readonly<{ type: string; mediaType?: string }>): boolean =>\n part.type === \"file\" && (part.mediaType ?? \"\").startsWith(\"image/\")\n );\n return {\n options: {\n abortSignal: context.abortSignal,\n costAccumulator,\n imageParts,\n lastGeneratedImage,\n mode:\n imageParts.length > NO_IMAGE_ATTACHMENTS || lastGeneratedImage !== null\n ? \"edit\"\n : \"generate\",\n modelProvider: eveToolModelProvider,\n prompt,\n startMs,\n storeFile,\n },\n selectedModel,\n };\n};\nconst executeImageRequest = async (\n request: Readonly<ImageRequest>\n): Promise<GeneratedImageResult> => {\n const { options, selectedModel } = request;\n log.info(\n {\n attachmentCount: options.imageParts.length,\n hasLastGeneratedImage: options.lastGeneratedImage !== null,\n mode: options.mode,\n promptLength: options.prompt.length,\n selectedModel,\n },\n \"generateImage: start\"\n );\n try {\n const selection = await resolveImageModel(\n options.modelProvider,\n selectedModel\n );\n\n if (selection.multimodal) {\n return await runGenerateImageMultimodal(options, selection);\n }\n return await runGenerateImageTraditional(options, selection.modelId);\n } catch (error) {\n const resolvedError = await resolveError(error);\n log.error(\n {\n error: serializeError(resolvedError),\n mode: options.mode,\n ms: Date.now() - options.startMs,\n selectedModel,\n ...getErrorDebugInfo(resolvedError),\n },\n \"generateImage: failure\"\n );\n throw resolvedError;\n }\n};\nconst runImageRequest = async (\n prompt: string,\n context: Readonly<ImageRequestContext>\n): Promise<\n Awaited<ReturnType<typeof executeWithToolUsage<GeneratedImageResult>>>\n> =>\n await executeWithToolUsage(\n context,\n async (usage: Readonly<ToolUsage>) =>\n await executeImageRequest(createImageRequest(prompt, context, usage))\n );\nexport { runImageRequest };\nexport type { ImageRequestContext };\n",
61
+ "content": "import type { z } from \"zod\";\nimport type { ToolResult } from \"@/lib/eve/tool-result\";\nimport { validateToolOutput } from \"@/chatjs/core/tools/validate-output\";\nimport { generateImageResult } from \"./schemas\";\nimport {\n ABSENT_DIAGNOSTIC_VALUE,\n getErrorDebugInfo,\n resolveError,\n serializeError,\n} from \"./image-errors\";\nimport type {\n GeneratedImageResult,\n ImageGenerationOptions,\n ImageStoreFile,\n} from \"./image-generation\";\nimport type { ToolUsage } from \"@/lib/eve/tool-usage\";\nimport { eveGeneratedFileUploader } from \"@/lib/eve/generated-files\";\nimport { createEveToolCost } from \"@/lib/eve/tool-cost\";\nimport { createModuleLogger } from \"@/lib/logger\";\nimport { eveToolImageContext } from \"@/lib/eve/tool-image-context\";\nimport { eveToolModelProvider } from \"@/lib/eve/tool-models\";\nimport {\n runGenerateImageMultimodal,\n runGenerateImageTraditional,\n} from \"./image-generation\";\nimport { executeWithToolUsage } from \"@/lib/eve/tool-usage\";\nimport { resolveImageModel } from \"./image-model\";\n\nconst log = createModuleLogger(\"ai.tools.generate-image\");\nconst NO_IMAGE_ATTACHMENTS = 0;\ninterface ImageRequestContext {\n readonly abortSignal: Readonly<AbortSignal>;\n readonly session: Readonly<{\n id: string;\n auth: Readonly<{\n current: Readonly<{\n attributes: Readonly<Record<string, unknown>>;\n }> | null;\n initiator: Readonly<{ principalId: string }> | null;\n }>;\n }>;\n}\ninterface ImageRequest {\n readonly options: Readonly<ImageGenerationOptions>;\n readonly selectedModel: string | undefined;\n}\nconst createImageRequest = (\n prompt: string,\n context: Readonly<ImageRequestContext>,\n usage: Readonly<ToolUsage>\n): ImageRequest => {\n const costAccumulator = createEveToolCost(usage);\n const uploadFile = eveGeneratedFileUploader(context);\n // A provider generation followed by storage failure is an explicit domain result.\n const storeFile: ImageStoreFile = async (filename, body, mediaType) => {\n try {\n return await uploadFile(filename, body, mediaType);\n } catch {\n return usage.fail();\n }\n };\n const { current } = context.session.auth;\n const selected = current && current.attributes.modelId;\n const selectedModel =\n typeof selected === \"string\" ? selected : ABSENT_DIAGNOSTIC_VALUE;\n const { attachments, lastGeneratedImage } = eveToolImageContext.get();\n const startMs = Date.now();\n const imageParts = attachments.filter(\n (part: Readonly<{ type: string; mediaType?: string }>): boolean =>\n part.type === \"file\" && (part.mediaType ?? \"\").startsWith(\"image/\")\n );\n return {\n options: {\n abortSignal: context.abortSignal,\n costAccumulator,\n imageParts,\n lastGeneratedImage,\n mode:\n imageParts.length > NO_IMAGE_ATTACHMENTS || lastGeneratedImage !== null\n ? \"edit\"\n : \"generate\",\n modelProvider: eveToolModelProvider,\n prompt,\n startMs,\n storeFile,\n },\n selectedModel,\n };\n};\nconst executeImageRequest = async (\n request: Readonly<ImageRequest>\n): Promise<GeneratedImageResult> => {\n const { options, selectedModel } = request;\n log.info(\n {\n attachmentCount: options.imageParts.length,\n hasLastGeneratedImage: options.lastGeneratedImage !== null,\n mode: options.mode,\n promptLength: options.prompt.length,\n selectedModel,\n },\n \"generateImage: start\"\n );\n try {\n const selection = await resolveImageModel(\n options.modelProvider,\n selectedModel\n );\n\n if (selection.multimodal) {\n return await runGenerateImageMultimodal(options, selection);\n }\n return await runGenerateImageTraditional(options, selection.modelId);\n } catch (error) {\n const resolvedError = await resolveError(error);\n log.error(\n {\n error: serializeError(resolvedError),\n mode: options.mode,\n ms: Date.now() - options.startMs,\n selectedModel,\n ...getErrorDebugInfo(resolvedError),\n },\n \"generateImage: failure\"\n );\n throw resolvedError;\n }\n};\nconst runImageRequest = async (\n prompt: string,\n context: Readonly<ImageRequestContext>\n): Promise<ToolResult<z.output<typeof generateImageResult>>> =>\n await executeWithToolUsage(context, async (usage: Readonly<ToolUsage>) =>\n validateToolOutput(\n generateImageResult,\n await executeImageRequest(createImageRequest(prompt, context, usage))\n )\n );\nexport { runImageRequest };\nexport type { ImageRequestContext };\n",
62
62
  "type": "registry:file",
63
- "target": "~/tools/chatjs/generate-image/image-request.ts"
63
+ "target": "~/chatjs/tools/generate-image/image-request.ts"
64
64
  },
65
65
  {
66
66
  "path": "dist/source/generate-image.json",
67
- "content": "{\n \"config\": { \"key\": \"image\" },\n \"envRequirements\": [],\n \"id\": \"generate-image\",\n \"kind\": \"tool\",\n \"requiresGateway\": [\"image\"],\n \"requiresStorage\": true,\n \"requiresTools\": [],\n \"slot\": \"generateImage\",\n \"tools\": [\n {\n \"composer\": {\n \"icon\": \"Images\",\n \"name\": \"Create an image\",\n \"shortName\": \"Image\"\n },\n \"rendererExport\": \"GenerateImageRenderer\",\n \"toolExport\": \"generateImageTool\"\n }\n ],\n \"contractVersion\": 1\n}\n",
67
+ "content": "{\n \"agentCategory\": \"tool\",\n \"requiresChatJS\": true,\n \"config\": { \"key\": \"image\" },\n \"envRequirements\": [],\n \"id\": \"generate-image\",\n \"kind\": \"tool\",\n \"requiresGateway\": [\"image\"],\n \"requiresStorage\": true,\n \"requiresTools\": [],\n \"slot\": \"generateImage\",\n \"tools\": [\n {\n \"composer\": {\n \"icon\": \"Images\",\n \"name\": \"Create an image\",\n \"shortName\": \"Image\"\n },\n \"rendererExport\": \"GenerateImageRenderer\",\n \"toolExport\": \"generateImageTool\"\n }\n ],\n \"contractVersion\": 1,\n \"channelSupport\": { \"web\": \"supported\", \"slack\": \"unverified\" }\n}\n",
68
68
  "type": "registry:file",
69
- "target": "~/tools/chatjs/generate-image/chatjs.json"
69
+ "target": "~/chatjs/tools/generate-image/chatjs.json"
70
70
  }
71
71
  ],
72
72
  "meta": {
73
73
  "chatjs": {
74
+ "agentCategory": "tool",
75
+ "requiresChatJS": true,
74
76
  "config": {
75
77
  "key": "image"
76
78
  },
@@ -94,7 +96,11 @@
94
96
  "toolExport": "generateImageTool"
95
97
  }
96
98
  ],
97
- "contractVersion": 1
99
+ "contractVersion": 1,
100
+ "channelSupport": {
101
+ "web": "supported",
102
+ "slack": "unverified"
103
+ }
98
104
  }
99
105
  },
100
106
  "type": "registry:item"