@chat-js/registry 0.2.0-beta.3 → 0.2.0-beta.4

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 (133) hide show
  1. package/README.md +1 -1
  2. package/dist/r/ai-titles.json +1 -1
  3. package/dist/r/attach-workspace-file.json +82 -0
  4. package/dist/r/attachment-uploads.json +1 -2
  5. package/dist/r/base/ai-titles.json +1 -1
  6. package/dist/r/base/attach-workspace-file.json +82 -0
  7. package/dist/r/base/attachment-uploads.json +1 -2
  8. package/dist/r/base/deep-research.json +46 -123
  9. package/dist/r/base/default-sandbox.json +35 -0
  10. package/dist/r/base/docker-sandbox.json +35 -0
  11. package/dist/r/base/generate-image.json +10 -4
  12. package/dist/r/base/generate-video.json +9 -3
  13. package/dist/r/base/guest-chat.json +2 -2
  14. package/dist/r/base/image-viewer.json +55 -0
  15. package/dist/r/base/just-bash-sandbox.json +32 -0
  16. package/dist/r/base/litellm-gateway.json +1 -1
  17. package/dist/r/base/mcp.json +1 -1
  18. package/dist/r/base/openai-compatible-gateway.json +1 -1
  19. package/dist/r/base/openai-gateway.json +1 -1
  20. package/dist/r/base/openrouter-gateway.json +1 -1
  21. package/dist/r/base/projects.json +3 -3
  22. package/dist/r/base/registry.json +965 -1746
  23. package/dist/r/base/search.json +6 -6
  24. package/dist/r/base/sharing.json +3 -3
  25. package/dist/r/base/spreadsheet-grid.json +20 -0
  26. package/dist/r/base/spreadsheet-viewer.json +68 -0
  27. package/dist/r/base/vercel-gateway.json +1 -1
  28. package/dist/r/base/vercel-sandbox.json +8 -26
  29. package/dist/r/base/video-viewer.json +48 -0
  30. package/dist/r/deep-research.json +46 -123
  31. package/dist/r/default-sandbox.json +35 -0
  32. package/dist/r/docker-sandbox.json +35 -0
  33. package/dist/r/eve/deep-research.json +47 -0
  34. package/dist/r/eve/registry.json +53 -0
  35. package/dist/r/generate-image.json +10 -4
  36. package/dist/r/generate-video.json +9 -3
  37. package/dist/r/guest-chat.json +2 -2
  38. package/dist/r/image-viewer.json +55 -0
  39. package/dist/r/just-bash-sandbox.json +32 -0
  40. package/dist/r/litellm-gateway.json +1 -1
  41. package/dist/r/mcp.json +1 -1
  42. package/dist/r/openai-compatible-gateway.json +1 -1
  43. package/dist/r/openai-gateway.json +1 -1
  44. package/dist/r/openrouter-gateway.json +1 -1
  45. package/dist/r/projects.json +3 -3
  46. package/dist/r/radix/ai-titles.json +1 -1
  47. package/dist/r/radix/attach-workspace-file.json +82 -0
  48. package/dist/r/radix/attachment-uploads.json +1 -2
  49. package/dist/r/radix/deep-research.json +46 -123
  50. package/dist/r/radix/default-sandbox.json +35 -0
  51. package/dist/r/radix/docker-sandbox.json +35 -0
  52. package/dist/r/radix/generate-image.json +10 -4
  53. package/dist/r/radix/generate-video.json +9 -3
  54. package/dist/r/radix/guest-chat.json +2 -2
  55. package/dist/r/radix/image-viewer.json +55 -0
  56. package/dist/r/radix/just-bash-sandbox.json +32 -0
  57. package/dist/r/radix/litellm-gateway.json +1 -1
  58. package/dist/r/radix/mcp.json +1 -1
  59. package/dist/r/radix/openai-compatible-gateway.json +1 -1
  60. package/dist/r/radix/openai-gateway.json +1 -1
  61. package/dist/r/radix/openrouter-gateway.json +1 -1
  62. package/dist/r/radix/projects.json +3 -3
  63. package/dist/r/radix/registry.json +968 -1749
  64. package/dist/r/radix/search.json +6 -6
  65. package/dist/r/radix/sharing.json +3 -3
  66. package/dist/r/radix/spreadsheet-grid.json +20 -0
  67. package/dist/r/radix/spreadsheet-viewer.json +68 -0
  68. package/dist/r/radix/vercel-gateway.json +1 -1
  69. package/dist/r/radix/vercel-sandbox.json +8 -26
  70. package/dist/r/radix/video-viewer.json +48 -0
  71. package/dist/r/registry.json +965 -1746
  72. package/dist/r/search.json +6 -6
  73. package/dist/r/sharing.json +3 -3
  74. package/dist/r/spreadsheet-grid.json +20 -0
  75. package/dist/r/spreadsheet-viewer.json +68 -0
  76. package/dist/r/vercel-gateway.json +1 -1
  77. package/dist/r/vercel-sandbox.json +8 -26
  78. package/dist/r/video-viewer.json +48 -0
  79. package/package.json +5 -26
  80. package/dist/r/base/code-documents.json +0 -101
  81. package/dist/r/base/code-execution-runtime.json +0 -25
  82. package/dist/r/base/code-execution-ui.json +0 -32
  83. package/dist/r/base/code-execution.json +0 -69
  84. package/dist/r/base/daytona-sandbox.json +0 -55
  85. package/dist/r/base/delete-document.json +0 -58
  86. package/dist/r/base/firecrawl-search.json +0 -72
  87. package/dist/r/base/get-weather.json +0 -59
  88. package/dist/r/base/langfuse.json +0 -63
  89. package/dist/r/base/read-document.json +0 -34
  90. package/dist/r/base/retrieve-url.json +0 -72
  91. package/dist/r/base/saved-code-execution.json +0 -84
  92. package/dist/r/base/sheet-documents.json +0 -99
  93. package/dist/r/base/tavily-search.json +0 -72
  94. package/dist/r/base/text-documents.json +0 -122
  95. package/dist/r/base/vercel-analytics.json +0 -46
  96. package/dist/r/base/vercel-speed-insights.json +0 -46
  97. package/dist/r/base/word-count.json +0 -58
  98. package/dist/r/code-documents.json +0 -101
  99. package/dist/r/code-execution-runtime.json +0 -25
  100. package/dist/r/code-execution-ui.json +0 -32
  101. package/dist/r/code-execution.json +0 -69
  102. package/dist/r/daytona-sandbox.json +0 -55
  103. package/dist/r/delete-document.json +0 -58
  104. package/dist/r/firecrawl-search.json +0 -72
  105. package/dist/r/get-weather.json +0 -59
  106. package/dist/r/langfuse.json +0 -63
  107. package/dist/r/radix/code-documents.json +0 -101
  108. package/dist/r/radix/code-execution-runtime.json +0 -25
  109. package/dist/r/radix/code-execution-ui.json +0 -32
  110. package/dist/r/radix/code-execution.json +0 -69
  111. package/dist/r/radix/daytona-sandbox.json +0 -55
  112. package/dist/r/radix/delete-document.json +0 -58
  113. package/dist/r/radix/firecrawl-search.json +0 -72
  114. package/dist/r/radix/get-weather.json +0 -59
  115. package/dist/r/radix/langfuse.json +0 -63
  116. package/dist/r/radix/read-document.json +0 -34
  117. package/dist/r/radix/retrieve-url.json +0 -72
  118. package/dist/r/radix/saved-code-execution.json +0 -84
  119. package/dist/r/radix/sheet-documents.json +0 -99
  120. package/dist/r/radix/tavily-search.json +0 -72
  121. package/dist/r/radix/text-documents.json +0 -122
  122. package/dist/r/radix/vercel-analytics.json +0 -46
  123. package/dist/r/radix/vercel-speed-insights.json +0 -46
  124. package/dist/r/radix/word-count.json +0 -58
  125. package/dist/r/read-document.json +0 -34
  126. package/dist/r/retrieve-url.json +0 -72
  127. package/dist/r/saved-code-execution.json +0 -84
  128. package/dist/r/sheet-documents.json +0 -99
  129. package/dist/r/tavily-search.json +0 -72
  130. package/dist/r/text-documents.json +0 -122
  131. package/dist/r/vercel-analytics.json +0 -46
  132. package/dist/r/vercel-speed-insights.json +0 -46
  133. package/dist/r/word-count.json +0 -58
package/README.md CHANGED
@@ -26,7 +26,7 @@ See [gateway authoring](./src/gateways/README.md) for adapter-specific metadata.
26
26
 
27
27
  Source folders group items by category. Each gateway has a `gateway.ts`; each tool has a `tool.ts` and `renderer.tsx`. Receipt and renderer helpers are supplied by the ChatJS scaffold. Category-level gateway catalog, metadata, and defaults live directly under `src/gateways/`.
28
28
 
29
- `meta.chatjs.kind` identifies a gateway or tool independently of its public name. Registry namespace aliases such as `@chatjs` identify a configured registry source. Public item names remain `vercel-gateway`, `word-count`, and the other existing names. Source folders do not determine registry addresses or installation targets.
29
+ `meta.chatjs.kind` identifies a gateway or tool independently of its public name. Registry namespace aliases such as `@chatjs` identify a configured registry source. Public item names remain `vercel-gateway`, `deep-research`, and the other existing names. Source folders do not determine registry addresses or installation targets.
30
30
 
31
31
  The selected gateway installs into the app's `chatjs/providers/gateway.ts` slot. Tools install under `chatjs/tools/<id>/` with generated installation inputs and app-owned integration modules. Third-party destination namespacing is not inferred from registry aliases and is not added by this source reorganization.
32
32
 
@@ -14,7 +14,7 @@
14
14
  },
15
15
  {
16
16
  "path": "src/plugins/ai-titles/src/generate-title.ts",
17
- "content": "import { settleEveRootFallbackTitle } from \"@/lib/db/eve-title\";\nimport { generateText } from \"ai\";\n\nimport { getLanguageModel } from \"@/lib/ai/providers\";\nimport { chatTelemetry } from \"@/lib/ai/telemetry\";\nimport { config } from \"@/lib/config\";\nimport {\n isEveRootTitlePending,\n replaceEveRootFallbackTitle,\n} from \"./title-queries\";\nimport { createModuleLogger } from \"@/lib/logger\";\n\nimport {\n compactTitle,\n eveConversationTitleFallback,\n} from \"@/lib/eve/conversation-title\";\nimport type { ReadonlyEveMessageInput } from \"@/lib/eve/readonly-message-types\";\n\nconst TITLE_GENERATION_TIMEOUT_MS = 15_000;\nconst surroundingQuotes = /^[\\s\"'“”‘’]+|[\\s\"'“”‘’]+$/gu;\nconst log = createModuleLogger(\"eve.ai-titles\");\ntype EveTitleResult =\n | { source: \"generated\"; title: string }\n | { source: \"fallback\"; title: string };\n\nconst normalizeGeneratedTitle = (title: string): string =>\n compactTitle(title.replace(surroundingQuotes, \"\"));\n\n/**\n * Auxiliary title generation must never prevent a conversation from starting.\n * @param {ReadonlyEveMessageInput} message First user message supplied to the auxiliary title model.\n * @returns {Promise<EveTitleResult>} A normalized generated title, or its message-derived fallback if generation fails or is empty.\n */\nconst generateEveConversationTitleResult = async (\n message: ReadonlyEveMessageInput\n): Promise<EveTitleResult> => {\n const fallback = eveConversationTitleFallback(message);\n try {\n const { text } = await generateText({\n abortSignal: AbortSignal.timeout(TITLE_GENERATION_TIMEOUT_MS),\n instructions: `Generate a concise title for a chat conversation based on the user's first message.\n\nRules (strictly follow all):\n- Maximum 40 characters — hard limit, never exceed this\n- 3-6 words is ideal\n- No quotes, colons, or punctuation at the end\n- No filler words like \"How to\" or \"Question about\"\n- Use title case\n- Return ONLY the title, nothing else`,\n maxRetries: 0,\n model: await getLanguageModel(config.ai.workflows.title),\n prompt: JSON.stringify(message),\n telemetry: { integrations: chatTelemetry, isEnabled: true },\n });\n const title = normalizeGeneratedTitle(text);\n\n if (title) {\n return { source: \"generated\", title };\n }\n return { source: \"fallback\", title: fallback };\n } catch {\n return { source: \"fallback\", title: fallback };\n }\n};\nconst persistGeneratedEveConversationTitle = async ({\n conversationId,\n message,\n ownerId,\n}: Readonly<{\n conversationId: string;\n message: ReadonlyEveMessageInput;\n ownerId: string;\n}>): Promise<EveTitleResult | undefined> => {\n const fallbackTitle = eveConversationTitleFallback(message);\n try {\n if (\n !(await isEveRootTitlePending(ownerId, conversationId, fallbackTitle))\n ) {\n return undefined;\n }\n } catch (error) {\n log.warn(\n {\n conversationId,\n errorName: error instanceof Error ? error.name : typeof error,\n },\n \"Eve title eligibility check failed\"\n );\n return undefined;\n }\n const generated = await generateEveConversationTitleResult(message);\n try {\n await (generated.source === \"generated\"\n ? replaceEveRootFallbackTitle(\n ownerId,\n conversationId,\n fallbackTitle,\n generated.title\n )\n : settleEveRootFallbackTitle(ownerId, conversationId, fallbackTitle));\n } catch (error) {\n log.warn(\n {\n conversationId,\n errorName: error instanceof Error ? error.name : typeof error,\n },\n \"Eve title persistence failed\"\n );\n }\n return generated;\n};\nexport {\n generateEveConversationTitleResult,\n persistGeneratedEveConversationTitle,\n};\n",
17
+ "content": "import { settleEveRootFallbackTitle } from \"@/lib/db/eve-title\";\nimport { generateText } from \"ai\";\n\nimport { getLanguageModel } from \"@/lib/ai/providers\";\nimport { config } from \"@/lib/config\";\nimport {\n isEveRootTitlePending,\n replaceEveRootFallbackTitle,\n} from \"./title-queries\";\nimport { createModuleLogger } from \"@/lib/logger\";\n\nimport {\n compactTitle,\n eveConversationTitleFallback,\n} from \"@/lib/eve/conversation-title\";\nimport type { ReadonlyEveMessageInput } from \"@/lib/eve/readonly-message-types\";\n\nconst TITLE_GENERATION_TIMEOUT_MS = 15_000;\nconst surroundingQuotes = /^[\\s\"'“”‘’]+|[\\s\"'“”‘’]+$/gu;\nconst log = createModuleLogger(\"eve.ai-titles\");\ntype EveTitleResult =\n | { source: \"generated\"; title: string }\n | { source: \"fallback\"; title: string };\n\nconst normalizeGeneratedTitle = (title: string): string =>\n compactTitle(title.replace(surroundingQuotes, \"\"));\n\n/**\n * Auxiliary title generation must never prevent a conversation from starting.\n * @param {ReadonlyEveMessageInput} message First user message supplied to the auxiliary title model.\n * @returns {Promise<EveTitleResult>} A normalized generated title, or its message-derived fallback if generation fails or is empty.\n */\nconst generateEveConversationTitleResult = async (\n message: ReadonlyEveMessageInput\n): Promise<EveTitleResult> => {\n const fallback = eveConversationTitleFallback(message);\n try {\n const { text } = await generateText({\n abortSignal: AbortSignal.timeout(TITLE_GENERATION_TIMEOUT_MS),\n instructions: `Generate a concise title for a chat conversation based on the user's first message.\n\nRules (strictly follow all):\n- Maximum 40 characters — hard limit, never exceed this\n- 3-6 words is ideal\n- No quotes, colons, or punctuation at the end\n- No filler words like \"How to\" or \"Question about\"\n- Use title case\n- Return ONLY the title, nothing else`,\n maxRetries: 0,\n model: await getLanguageModel(config.ai.workflows.title),\n prompt: JSON.stringify(message),\n });\n const title = normalizeGeneratedTitle(text);\n\n if (title) {\n return { source: \"generated\", title };\n }\n return { source: \"fallback\", title: fallback };\n } catch {\n return { source: \"fallback\", title: fallback };\n }\n};\nconst persistGeneratedEveConversationTitle = async ({\n conversationId,\n message,\n ownerId,\n}: Readonly<{\n conversationId: string;\n message: ReadonlyEveMessageInput;\n ownerId: string;\n}>): Promise<EveTitleResult | undefined> => {\n const fallbackTitle = eveConversationTitleFallback(message);\n try {\n if (\n !(await isEveRootTitlePending(ownerId, conversationId, fallbackTitle))\n ) {\n return undefined;\n }\n } catch (error) {\n log.warn(\n {\n conversationId,\n errorName: error instanceof Error ? error.name : typeof error,\n },\n \"Eve title eligibility check failed\"\n );\n return undefined;\n }\n const generated = await generateEveConversationTitleResult(message);\n try {\n await (generated.source === \"generated\"\n ? replaceEveRootFallbackTitle(\n ownerId,\n conversationId,\n fallbackTitle,\n generated.title\n )\n : settleEveRootFallbackTitle(ownerId, conversationId, fallbackTitle));\n } catch (error) {\n log.warn(\n {\n conversationId,\n errorName: error instanceof Error ? error.name : typeof error,\n },\n \"Eve title persistence failed\"\n );\n }\n return generated;\n};\nexport {\n generateEveConversationTitleResult,\n persistGeneratedEveConversationTitle,\n};\n",
18
18
  "type": "registry:file",
19
19
  "target": "~/chatjs/plugins/ai-titles/generate-title.ts"
20
20
  },
@@ -0,0 +1,82 @@
1
+ {
2
+ "$schema": "https://ui.shadcn.com/schema/registry-item.json",
3
+ "name": "attach-workspace-file",
4
+ "description": "Attach workspace files to the conversation as downloads, or import earlier files into the workspace for revision.",
5
+ "dependencies": [
6
+ "eve@npm:@chat-js/eve@1.0.0-rc.6-chatjs.1",
7
+ "zod@4.5.4",
8
+ "lucide-react@0.553.0"
9
+ ],
10
+ "files": [
11
+ {
12
+ "path": "src/tools/attach-workspace-file/tool.ts",
13
+ "content": "import { defineTool, toolOutput } from \"eve/tools\";\nimport { resolveEveConversationScope } from \"@/lib/eve/conversation-scope\";\nimport { attachConversationFile } from \"./attach-conversation-file\";\nimport {\n attachWorkspaceFileInput,\n attachWorkspaceFileResult,\n importFileInput,\n importFileResult,\n} from \"./schemas\";\nimport { importStoredFile } from \"./import\";\nimport { withEveConversationFile } from \"@/lib/db/eve-files\";\nimport { downloadFile, getFileMetadata } from \"@/lib/file-storage\";\n\nexport const attach_workspace_file = defineTool({\n description:\n \"Attach a finished workspace file to the current ChatJS conversation as a downloadable artifact. Creates a new durable snapshot; later sandbox edits do not change it. Use for user-requested deliverables, not intermediate files. To revise an earlier artifact, import_file using its exact fileId, edit the workspace copy with native tools, then attach_workspace_file again. Earlier downloads remain unchanged. Maximum 32 MiB. Delegated agents return the file path to the parent so it can attach the file.\",\n inputSchema: attachWorkspaceFileInput,\n outputSchema: attachWorkspaceFileResult,\n availableInSubagents: false,\n async execute(input, context) {\n return await attachConversationFile(input, context);\n },\n toModelOutput: (output) => toolOutput.json(output),\n});\n\nexport const import_file = defineTool({\n description:\n \"Import a published artifact or uploaded file referenced in the current ChatJS conversation into the current EVE workspace. Use before revising an earlier file, including after its original sandbox is gone. Supply its exact fileId and filename from conversation history; ask the user to identify or upload the file if ambiguous. Returns a fresh local copy. Edit it with native tools and attach_workspace_file to deliver a new snapshot. The original is never changed. Maximum 32 MiB.\",\n inputSchema: importFileInput,\n outputSchema: importFileResult,\n availableInSubagents: false,\n async execute(input, context) {\n const { current, initiator } = context.session.auth;\n if (\n context.session.parent ||\n current?.authenticator !== \"chatjs-gateway\" ||\n current.principalId !== initiator?.principalId\n ) {\n throw new Error(\n \"File import requires the current ChatJS conversation owner's authority.\"\n );\n }\n const { ownerId, conversationId } = await resolveEveConversationScope(\n current.principalId,\n context.session.id,\n context.abortSignal\n );\n return await withEveConversationFile(\n ownerId,\n conversationId,\n input.fileId,\n async () =>\n await importStoredFile(input, {\n stat: async () => await getFileMetadata(input.fileId),\n read: async () => await downloadFile(input.fileId),\n getSandbox: async () => await context.getSandbox(),\n signal: context.abortSignal,\n })\n );\n },\n toModelOutput: (output) => toolOutput.json(output),\n});\n",
14
+ "type": "registry:file",
15
+ "target": "~/chatjs/tools/attach-workspace-file/tool.ts"
16
+ },
17
+ {
18
+ "path": "src/tools/attach-workspace-file/attach.ts",
19
+ "content": "import nodePath from \"node:path\";\nimport type { SandboxSession } from \"eve/sandbox\";\nimport type { FileUploader } from \"@/lib/file-storage\";\nimport type { z } from \"zod\";\nimport type { attachWorkspaceFileInput } from \"./schemas\";\nimport {\n maximumWorkspaceFileBytes,\n attachWorkspaceFileResult,\n} from \"./schemas\";\n\n// Active browser formats such as HTML and SVG are delivered as downloads.\nconst mediaTypes: Readonly<Record<string, string>> = {\n \".txt\": \"text/plain\",\n \".md\": \"text/plain\",\n \".csv\": \"text/csv\",\n \".json\": \"application/json\",\n \".pdf\": \"application/pdf\",\n \".xlsx\": \"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet\",\n \".docx\":\n \"application/vnd.openxmlformats-officedocument.wordprocessingml.document\",\n \".pptx\":\n \"application/vnd.openxmlformats-officedocument.presentationml.presentation\",\n \".png\": \"image/png\",\n \".jpg\": \"image/jpeg\",\n \".jpeg\": \"image/jpeg\",\n \".webp\": \"image/webp\",\n \".gif\": \"image/gif\",\n \".mp4\": \"video/mp4\",\n \".webm\": \"video/webm\",\n \".mp3\": \"audio/mpeg\",\n \".wav\": \"audio/wav\",\n \".zip\": \"application/zip\",\n};\nconst shellQuote = (value: string): string =>\n `'${value.replaceAll(\"'\", \"'\\\\''\")}'`;\nconst inWorkspace = (path: string, root: string): boolean =>\n path.startsWith(`${root}/`);\n\nexport const attachSandboxFile = async (\n input: z.infer<typeof attachWorkspaceFileInput>,\n {\n sandbox,\n upload,\n signal,\n }: {\n readonly sandbox: Pick<SandboxSession, \"resolvePath\" | \"run\" | \"readFile\">;\n readonly upload: FileUploader;\n readonly signal: AbortSignal;\n }\n): Promise<z.infer<typeof attachWorkspaceFileResult>> => {\n signal.throwIfAborted();\n const root = nodePath.posix.normalize(sandbox.resolvePath(\".\"));\n const path = nodePath.posix.normalize(sandbox.resolvePath(input.path));\n if (!inWorkspace(path, root)) {\n throw new Error(\"Attach a file inside the sandbox workspace.\");\n }\n const quoted = shellQuote(path);\n const resolved = await sandbox.run({\n command: `if [ -f ${quoted} ]; then readlink -f -- ${quoted}; fi`,\n signal,\n });\n const realPath = resolved.stdout.replace(/\\n$/u, \"\");\n if (resolved.exitCode !== 0 || !inWorkspace(realPath, root)) {\n throw new Error(\n \"The file is missing, is not a regular file, or resolves outside the workspace.\"\n );\n }\n const stream = await sandbox.readFile({ path: realPath, signal });\n if (!stream) {\n throw new Error(\"The sandbox file is no longer available.\");\n }\n const reader = stream.getReader();\n const chunks: Uint8Array[] = [];\n let size = 0;\n try {\n for (;;) {\n signal.throwIfAborted();\n // oxlint-disable-next-line eslint/no-await-in-loop -- Read ordered chunks and enforce a limit before storing bytes.\n const { done, value } = await reader.read();\n if (done) {\n break;\n }\n size += value.byteLength;\n if (size > maximumWorkspaceFileBytes) {\n throw new Error(\"Files must be 32 MiB or smaller.\");\n }\n chunks.push(value);\n }\n } finally {\n await reader.cancel();\n reader.releaseLock();\n }\n signal.throwIfAborted();\n const name = input.name ?? nodePath.posix.basename(path);\n const mediaType =\n mediaTypes[nodePath.posix.extname(name).toLowerCase()] ??\n \"application/octet-stream\";\n const stored = await upload(name, Buffer.concat(chunks, size), mediaType);\n return attachWorkspaceFileResult.parse({\n fileId: stored.fileId,\n url: stored.url,\n name: stored.pathname,\n mediaType,\n size,\n });\n};\n",
20
+ "type": "registry:file",
21
+ "target": "~/chatjs/tools/attach-workspace-file/attach.ts"
22
+ },
23
+ {
24
+ "path": "src/tools/attach-workspace-file/attach-conversation-file.ts",
25
+ "content": "import type { WorkflowStepToolContext } from \"eve/tools\";\nimport type { z } from \"zod\";\nimport { eveGeneratedFileUploader } from \"@/lib/eve/generated-files\";\nimport { resolveEveConversationScope } from \"@/lib/eve/conversation-scope\";\nimport { attachSandboxFile } from \"./attach\";\nimport type { attachWorkspaceFileInput } from \"./schemas\";\n\n/** Application boundary shared by tools and durable workflows publishing sandbox files. */\nexport const attachConversationFile = async (\n input: z.infer<typeof attachWorkspaceFileInput>,\n context: Readonly<WorkflowStepToolContext>\n) => {\n const { current, initiator } = context.session.auth;\n if (\n context.session.parent ||\n current?.authenticator !== \"chatjs-gateway\" ||\n current.principalId !== initiator?.principalId\n ) {\n throw new Error(\n \"Publication requires the current ChatJS conversation owner's authority.\"\n );\n }\n // Authorize the application resource before reading sandbox bytes.\n await resolveEveConversationScope(\n current.principalId,\n context.session.id,\n context.abortSignal\n );\n return await attachSandboxFile(input, {\n sandbox: await context.getSandbox(),\n upload: eveGeneratedFileUploader(context),\n signal: context.abortSignal,\n });\n};\n",
26
+ "type": "registry:file",
27
+ "target": "~/chatjs/tools/attach-workspace-file/attach-conversation-file.ts"
28
+ },
29
+ {
30
+ "path": "src/tools/attach-workspace-file/import.ts",
31
+ "content": "import { randomUUID } from \"node:crypto\";\nimport type { SandboxSession } from \"eve/sandbox\";\nimport type { z } from \"zod\";\nimport { maximumWorkspaceFileBytes } from \"./schemas\";\nimport type { importFileInput } from \"./schemas\";\n\n/** Copy authorized stored bytes into a fresh native workspace path. */\nexport const importStoredFile = async (\n input: z.infer<typeof importFileInput>,\n {\n stat,\n read,\n getSandbox,\n signal,\n }: {\n readonly stat: () => Promise<{ readonly size: number }>;\n readonly read: () => Promise<{\n readonly type: string;\n readonly stream: () => ReadableStream<Uint8Array>;\n }>;\n readonly getSandbox: () => PromiseLike<\n Pick<SandboxSession, \"resolvePath\" | \"writeBinaryFile\">\n >;\n readonly signal: AbortSignal;\n }\n) => {\n signal.throwIfAborted();\n const metadata = await stat();\n if (metadata.size > maximumWorkspaceFileBytes) {\n throw new Error(\"Files must be 32 MiB or smaller.\");\n }\n signal.throwIfAborted();\n const file = await read();\n const reader = file.stream().getReader();\n const chunks: Uint8Array[] = [];\n let size = 0;\n try {\n for (;;) {\n signal.throwIfAborted();\n // oxlint-disable-next-line eslint/no-await-in-loop -- Bound storage reads before acquiring a sandbox or writing any bytes.\n const { done, value } = await reader.read();\n if (done) {\n break;\n }\n size += value.byteLength;\n if (size > maximumWorkspaceFileBytes) {\n throw new Error(\"Files must be 32 MiB or smaller.\");\n }\n chunks.push(value);\n }\n } finally {\n await reader.cancel();\n reader.releaseLock();\n }\n signal.throwIfAborted();\n const sandbox = await getSandbox();\n // Fresh flat filenames cannot follow user-selected directories or overwrite an earlier import.\n const path = sandbox.resolvePath(`import-${randomUUID()}-${input.name}`);\n await sandbox.writeBinaryFile({\n path,\n content: Buffer.concat(chunks, size),\n signal,\n });\n return {\n fileId: input.fileId,\n path,\n name: input.name,\n mediaType: file.type,\n size,\n };\n};\n",
32
+ "type": "registry:file",
33
+ "target": "~/chatjs/tools/attach-workspace-file/import.ts"
34
+ },
35
+ {
36
+ "path": "src/tools/attach-workspace-file/schemas.ts",
37
+ "content": "import { z } from \"zod\";\nimport { isFileStorageKey } from \"@/lib/file-url\";\n\nexport const maximumWorkspaceFileBytes = 32 * 1024 * 1024;\n\nexport const attachWorkspaceFileInput = z.object({\n path: z\n .string()\n .min(1)\n .max(4096)\n .regex(/^[^\\p{Cc}]+$/u)\n .describe(\n \"File in the current EVE sandbox workspace, e.g. /workspace/report.xlsx.\"\n ),\n name: z\n .string()\n .trim()\n .min(1)\n .max(180)\n .regex(/^[^/\\\\\\p{Cc}]+$/u)\n .optional()\n .describe(\"Optional download filename, including its extension.\"),\n});\n\nexport const attachWorkspaceFileResult = z.object({\n fileId: z.string().min(1),\n name: z.string().min(1),\n mediaType: z.string().min(1),\n size: z.number().int().nonnegative().max(maximumWorkspaceFileBytes),\n url: z.string().min(1),\n});\n\nexport const importFileInput = z.object({\n fileId: z\n .string()\n .refine(isFileStorageKey, \"Use a fileId from this conversation.\")\n .describe(\n \"Exact fileId returned by attach_workspace_file, or the storage key in a file attachment URL in this conversation. Never guess a file ID.\"\n ),\n name: attachWorkspaceFileInput.shape.name\n .unwrap()\n .describe(\n \"Filename from the referenced artifact, including its extension.\"\n ),\n});\n\nexport const importFileResult = attachWorkspaceFileResult\n .omit({ url: true })\n .extend({\n path: z.string().min(1),\n });\n",
38
+ "type": "registry:file",
39
+ "target": "~/chatjs/tools/attach-workspace-file/schemas.ts"
40
+ },
41
+ {
42
+ "path": "src/tools/attach-workspace-file/renderer.tsx",
43
+ "content": "\"use client\";\nimport React from \"react\";\nimport { FileArtifactCard } from \"@/components/file-artifact-card\";\nimport { defineToolRenderer } from \"@/chatjs/core/tools/define-renderer\";\nimport { attachWorkspaceFileInput, attachWorkspaceFileResult } from \"./schemas\";\n\nexport const AttachWorkspaceFileRenderer = defineToolRenderer({\n inputSchema: attachWorkspaceFileInput,\n outputSchema: attachWorkspaceFileResult,\n render: ({ tool }) =>\n tool.state === \"output-available\" ? (\n <FileArtifactCard artifact={tool.output} />\n ) : (\n <output className=\"text-muted-foreground block rounded-lg border p-4 text-sm\">\n Preparing download\n {tool.input?.name === undefined ? \"…\" : `: ${tool.input.name}`}\n </output>\n ),\n});\n",
44
+ "type": "registry:file",
45
+ "target": "~/chatjs/tools/attach-workspace-file/renderer.tsx"
46
+ },
47
+ {
48
+ "path": "dist/source/attach-workspace-file.json",
49
+ "content": "{\n \"agentCategory\": \"tool\",\n \"requiresChatJS\": true,\n \"channelSupport\": { \"web\": \"supported\", \"slack\": \"unsupported\" },\n \"envRequirements\": [],\n \"id\": \"attach-workspace-file\",\n \"kind\": \"tool\",\n \"requiresStorage\": true,\n \"requiresTools\": [],\n \"tools\": [\n { \"accounting\": \"none\", \"toolExport\": \"import_file\" },\n {\n \"accounting\": \"none\",\n \"rendererExport\": \"AttachWorkspaceFileRenderer\",\n \"toolExport\": \"attach_workspace_file\"\n }\n ],\n \"contractVersion\": 1\n}\n",
50
+ "type": "registry:file",
51
+ "target": "~/chatjs/tools/attach-workspace-file/chatjs.json"
52
+ }
53
+ ],
54
+ "meta": {
55
+ "chatjs": {
56
+ "agentCategory": "tool",
57
+ "requiresChatJS": true,
58
+ "channelSupport": {
59
+ "web": "supported",
60
+ "slack": "unsupported"
61
+ },
62
+ "envRequirements": [],
63
+ "id": "attach-workspace-file",
64
+ "kind": "tool",
65
+ "requiresStorage": true,
66
+ "requiresTools": [],
67
+ "tools": [
68
+ {
69
+ "accounting": "none",
70
+ "toolExport": "import_file"
71
+ },
72
+ {
73
+ "accounting": "none",
74
+ "rendererExport": "AttachWorkspaceFileRenderer",
75
+ "toolExport": "attach_workspace_file"
76
+ }
77
+ ],
78
+ "contractVersion": 1
79
+ }
80
+ },
81
+ "type": "registry:item"
82
+ }
@@ -52,7 +52,7 @@
52
52
  },
53
53
  {
54
54
  "path": "dist/source/attachment-uploads.json",
55
- "content": "{\n \"id\": \"attachment-uploads\",\n \"kind\": \"plugin\",\n \"files\": [\n \"chatjs/plugins/attachment-uploads/controls.tsx\",\n \"chatjs/plugins/attachment-uploads/integration.tsx\",\n \"chatjs/plugins/attachment-uploads/upload.ts\",\n \"chatjs/plugins/attachment-uploads/upload-prep.ts\",\n \"app/(chat)/api/files/upload/route.ts\",\n \"chatjs/plugins/attachment-uploads/routes/upload.ts\",\n \"chatjs/plugins/attachment-uploads/client-plugin.ts\"\n ],\n \"requiresStorage\": true,\n \"requiresPersistentSandbox\": true,\n \"client\": {\n \"export\": \"attachmentUploadsClient\",\n \"composerControls\": [\"attach-files\", \"take-photo\"],\n \"settingsItems\": [],\n \"uploads\": true\n },\n \"contractVersion\": 2,\n \"uiBase\": \"base\"\n}\n",
55
+ "content": "{\n \"id\": \"attachment-uploads\",\n \"kind\": \"plugin\",\n \"files\": [\n \"chatjs/plugins/attachment-uploads/controls.tsx\",\n \"chatjs/plugins/attachment-uploads/integration.tsx\",\n \"chatjs/plugins/attachment-uploads/upload.ts\",\n \"chatjs/plugins/attachment-uploads/upload-prep.ts\",\n \"app/(chat)/api/files/upload/route.ts\",\n \"chatjs/plugins/attachment-uploads/routes/upload.ts\",\n \"chatjs/plugins/attachment-uploads/client-plugin.ts\"\n ],\n \"requiresStorage\": true,\n \"client\": {\n \"export\": \"attachmentUploadsClient\",\n \"composerControls\": [\"attach-files\", \"take-photo\"],\n \"settingsItems\": [],\n \"uploads\": true\n },\n \"contractVersion\": 2,\n \"uiBase\": \"base\"\n}\n",
56
56
  "type": "registry:file",
57
57
  "target": "~/chatjs/plugins/attachment-uploads/chatjs.json"
58
58
  }
@@ -71,7 +71,6 @@
71
71
  "chatjs/plugins/attachment-uploads/client-plugin.ts"
72
72
  ],
73
73
  "requiresStorage": true,
74
- "requiresPersistentSandbox": true,
75
74
  "client": {
76
75
  "export": "attachmentUploadsClient",
77
76
  "composerControls": [
@@ -14,7 +14,7 @@
14
14
  },
15
15
  {
16
16
  "path": "src/plugins/ai-titles/src/generate-title.ts",
17
- "content": "import { settleEveRootFallbackTitle } from \"@/lib/db/eve-title\";\nimport { generateText } from \"ai\";\n\nimport { getLanguageModel } from \"@/lib/ai/providers\";\nimport { chatTelemetry } from \"@/lib/ai/telemetry\";\nimport { config } from \"@/lib/config\";\nimport {\n isEveRootTitlePending,\n replaceEveRootFallbackTitle,\n} from \"./title-queries\";\nimport { createModuleLogger } from \"@/lib/logger\";\n\nimport {\n compactTitle,\n eveConversationTitleFallback,\n} from \"@/lib/eve/conversation-title\";\nimport type { ReadonlyEveMessageInput } from \"@/lib/eve/readonly-message-types\";\n\nconst TITLE_GENERATION_TIMEOUT_MS = 15_000;\nconst surroundingQuotes = /^[\\s\"'“”‘’]+|[\\s\"'“”‘’]+$/gu;\nconst log = createModuleLogger(\"eve.ai-titles\");\ntype EveTitleResult =\n | { source: \"generated\"; title: string }\n | { source: \"fallback\"; title: string };\n\nconst normalizeGeneratedTitle = (title: string): string =>\n compactTitle(title.replace(surroundingQuotes, \"\"));\n\n/**\n * Auxiliary title generation must never prevent a conversation from starting.\n * @param {ReadonlyEveMessageInput} message First user message supplied to the auxiliary title model.\n * @returns {Promise<EveTitleResult>} A normalized generated title, or its message-derived fallback if generation fails or is empty.\n */\nconst generateEveConversationTitleResult = async (\n message: ReadonlyEveMessageInput\n): Promise<EveTitleResult> => {\n const fallback = eveConversationTitleFallback(message);\n try {\n const { text } = await generateText({\n abortSignal: AbortSignal.timeout(TITLE_GENERATION_TIMEOUT_MS),\n instructions: `Generate a concise title for a chat conversation based on the user's first message.\n\nRules (strictly follow all):\n- Maximum 40 characters — hard limit, never exceed this\n- 3-6 words is ideal\n- No quotes, colons, or punctuation at the end\n- No filler words like \"How to\" or \"Question about\"\n- Use title case\n- Return ONLY the title, nothing else`,\n maxRetries: 0,\n model: await getLanguageModel(config.ai.workflows.title),\n prompt: JSON.stringify(message),\n telemetry: { integrations: chatTelemetry, isEnabled: true },\n });\n const title = normalizeGeneratedTitle(text);\n\n if (title) {\n return { source: \"generated\", title };\n }\n return { source: \"fallback\", title: fallback };\n } catch {\n return { source: \"fallback\", title: fallback };\n }\n};\nconst persistGeneratedEveConversationTitle = async ({\n conversationId,\n message,\n ownerId,\n}: Readonly<{\n conversationId: string;\n message: ReadonlyEveMessageInput;\n ownerId: string;\n}>): Promise<EveTitleResult | undefined> => {\n const fallbackTitle = eveConversationTitleFallback(message);\n try {\n if (\n !(await isEveRootTitlePending(ownerId, conversationId, fallbackTitle))\n ) {\n return undefined;\n }\n } catch (error) {\n log.warn(\n {\n conversationId,\n errorName: error instanceof Error ? error.name : typeof error,\n },\n \"Eve title eligibility check failed\"\n );\n return undefined;\n }\n const generated = await generateEveConversationTitleResult(message);\n try {\n await (generated.source === \"generated\"\n ? replaceEveRootFallbackTitle(\n ownerId,\n conversationId,\n fallbackTitle,\n generated.title\n )\n : settleEveRootFallbackTitle(ownerId, conversationId, fallbackTitle));\n } catch (error) {\n log.warn(\n {\n conversationId,\n errorName: error instanceof Error ? error.name : typeof error,\n },\n \"Eve title persistence failed\"\n );\n }\n return generated;\n};\nexport {\n generateEveConversationTitleResult,\n persistGeneratedEveConversationTitle,\n};\n",
17
+ "content": "import { settleEveRootFallbackTitle } from \"@/lib/db/eve-title\";\nimport { generateText } from \"ai\";\n\nimport { getLanguageModel } from \"@/lib/ai/providers\";\nimport { config } from \"@/lib/config\";\nimport {\n isEveRootTitlePending,\n replaceEveRootFallbackTitle,\n} from \"./title-queries\";\nimport { createModuleLogger } from \"@/lib/logger\";\n\nimport {\n compactTitle,\n eveConversationTitleFallback,\n} from \"@/lib/eve/conversation-title\";\nimport type { ReadonlyEveMessageInput } from \"@/lib/eve/readonly-message-types\";\n\nconst TITLE_GENERATION_TIMEOUT_MS = 15_000;\nconst surroundingQuotes = /^[\\s\"'“”‘’]+|[\\s\"'“”‘’]+$/gu;\nconst log = createModuleLogger(\"eve.ai-titles\");\ntype EveTitleResult =\n | { source: \"generated\"; title: string }\n | { source: \"fallback\"; title: string };\n\nconst normalizeGeneratedTitle = (title: string): string =>\n compactTitle(title.replace(surroundingQuotes, \"\"));\n\n/**\n * Auxiliary title generation must never prevent a conversation from starting.\n * @param {ReadonlyEveMessageInput} message First user message supplied to the auxiliary title model.\n * @returns {Promise<EveTitleResult>} A normalized generated title, or its message-derived fallback if generation fails or is empty.\n */\nconst generateEveConversationTitleResult = async (\n message: ReadonlyEveMessageInput\n): Promise<EveTitleResult> => {\n const fallback = eveConversationTitleFallback(message);\n try {\n const { text } = await generateText({\n abortSignal: AbortSignal.timeout(TITLE_GENERATION_TIMEOUT_MS),\n instructions: `Generate a concise title for a chat conversation based on the user's first message.\n\nRules (strictly follow all):\n- Maximum 40 characters — hard limit, never exceed this\n- 3-6 words is ideal\n- No quotes, colons, or punctuation at the end\n- No filler words like \"How to\" or \"Question about\"\n- Use title case\n- Return ONLY the title, nothing else`,\n maxRetries: 0,\n model: await getLanguageModel(config.ai.workflows.title),\n prompt: JSON.stringify(message),\n });\n const title = normalizeGeneratedTitle(text);\n\n if (title) {\n return { source: \"generated\", title };\n }\n return { source: \"fallback\", title: fallback };\n } catch {\n return { source: \"fallback\", title: fallback };\n }\n};\nconst persistGeneratedEveConversationTitle = async ({\n conversationId,\n message,\n ownerId,\n}: Readonly<{\n conversationId: string;\n message: ReadonlyEveMessageInput;\n ownerId: string;\n}>): Promise<EveTitleResult | undefined> => {\n const fallbackTitle = eveConversationTitleFallback(message);\n try {\n if (\n !(await isEveRootTitlePending(ownerId, conversationId, fallbackTitle))\n ) {\n return undefined;\n }\n } catch (error) {\n log.warn(\n {\n conversationId,\n errorName: error instanceof Error ? error.name : typeof error,\n },\n \"Eve title eligibility check failed\"\n );\n return undefined;\n }\n const generated = await generateEveConversationTitleResult(message);\n try {\n await (generated.source === \"generated\"\n ? replaceEveRootFallbackTitle(\n ownerId,\n conversationId,\n fallbackTitle,\n generated.title\n )\n : settleEveRootFallbackTitle(ownerId, conversationId, fallbackTitle));\n } catch (error) {\n log.warn(\n {\n conversationId,\n errorName: error instanceof Error ? error.name : typeof error,\n },\n \"Eve title persistence failed\"\n );\n }\n return generated;\n};\nexport {\n generateEveConversationTitleResult,\n persistGeneratedEveConversationTitle,\n};\n",
18
18
  "type": "registry:file",
19
19
  "target": "~/chatjs/plugins/ai-titles/generate-title.ts"
20
20
  },
@@ -0,0 +1,82 @@
1
+ {
2
+ "$schema": "https://ui.shadcn.com/schema/registry-item.json",
3
+ "name": "attach-workspace-file",
4
+ "description": "Attach workspace files to the conversation as downloads, or import earlier files into the workspace for revision.",
5
+ "dependencies": [
6
+ "eve@npm:@chat-js/eve@1.0.0-rc.6-chatjs.1",
7
+ "zod@4.5.4",
8
+ "lucide-react@0.553.0"
9
+ ],
10
+ "files": [
11
+ {
12
+ "path": "src/tools/attach-workspace-file/tool.ts",
13
+ "content": "import { defineTool, toolOutput } from \"eve/tools\";\nimport { resolveEveConversationScope } from \"@/lib/eve/conversation-scope\";\nimport { attachConversationFile } from \"./attach-conversation-file\";\nimport {\n attachWorkspaceFileInput,\n attachWorkspaceFileResult,\n importFileInput,\n importFileResult,\n} from \"./schemas\";\nimport { importStoredFile } from \"./import\";\nimport { withEveConversationFile } from \"@/lib/db/eve-files\";\nimport { downloadFile, getFileMetadata } from \"@/lib/file-storage\";\n\nexport const attach_workspace_file = defineTool({\n description:\n \"Attach a finished workspace file to the current ChatJS conversation as a downloadable artifact. Creates a new durable snapshot; later sandbox edits do not change it. Use for user-requested deliverables, not intermediate files. To revise an earlier artifact, import_file using its exact fileId, edit the workspace copy with native tools, then attach_workspace_file again. Earlier downloads remain unchanged. Maximum 32 MiB. Delegated agents return the file path to the parent so it can attach the file.\",\n inputSchema: attachWorkspaceFileInput,\n outputSchema: attachWorkspaceFileResult,\n availableInSubagents: false,\n async execute(input, context) {\n return await attachConversationFile(input, context);\n },\n toModelOutput: (output) => toolOutput.json(output),\n});\n\nexport const import_file = defineTool({\n description:\n \"Import a published artifact or uploaded file referenced in the current ChatJS conversation into the current EVE workspace. Use before revising an earlier file, including after its original sandbox is gone. Supply its exact fileId and filename from conversation history; ask the user to identify or upload the file if ambiguous. Returns a fresh local copy. Edit it with native tools and attach_workspace_file to deliver a new snapshot. The original is never changed. Maximum 32 MiB.\",\n inputSchema: importFileInput,\n outputSchema: importFileResult,\n availableInSubagents: false,\n async execute(input, context) {\n const { current, initiator } = context.session.auth;\n if (\n context.session.parent ||\n current?.authenticator !== \"chatjs-gateway\" ||\n current.principalId !== initiator?.principalId\n ) {\n throw new Error(\n \"File import requires the current ChatJS conversation owner's authority.\"\n );\n }\n const { ownerId, conversationId } = await resolveEveConversationScope(\n current.principalId,\n context.session.id,\n context.abortSignal\n );\n return await withEveConversationFile(\n ownerId,\n conversationId,\n input.fileId,\n async () =>\n await importStoredFile(input, {\n stat: async () => await getFileMetadata(input.fileId),\n read: async () => await downloadFile(input.fileId),\n getSandbox: async () => await context.getSandbox(),\n signal: context.abortSignal,\n })\n );\n },\n toModelOutput: (output) => toolOutput.json(output),\n});\n",
14
+ "type": "registry:file",
15
+ "target": "~/chatjs/tools/attach-workspace-file/tool.ts"
16
+ },
17
+ {
18
+ "path": "src/tools/attach-workspace-file/attach.ts",
19
+ "content": "import nodePath from \"node:path\";\nimport type { SandboxSession } from \"eve/sandbox\";\nimport type { FileUploader } from \"@/lib/file-storage\";\nimport type { z } from \"zod\";\nimport type { attachWorkspaceFileInput } from \"./schemas\";\nimport {\n maximumWorkspaceFileBytes,\n attachWorkspaceFileResult,\n} from \"./schemas\";\n\n// Active browser formats such as HTML and SVG are delivered as downloads.\nconst mediaTypes: Readonly<Record<string, string>> = {\n \".txt\": \"text/plain\",\n \".md\": \"text/plain\",\n \".csv\": \"text/csv\",\n \".json\": \"application/json\",\n \".pdf\": \"application/pdf\",\n \".xlsx\": \"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet\",\n \".docx\":\n \"application/vnd.openxmlformats-officedocument.wordprocessingml.document\",\n \".pptx\":\n \"application/vnd.openxmlformats-officedocument.presentationml.presentation\",\n \".png\": \"image/png\",\n \".jpg\": \"image/jpeg\",\n \".jpeg\": \"image/jpeg\",\n \".webp\": \"image/webp\",\n \".gif\": \"image/gif\",\n \".mp4\": \"video/mp4\",\n \".webm\": \"video/webm\",\n \".mp3\": \"audio/mpeg\",\n \".wav\": \"audio/wav\",\n \".zip\": \"application/zip\",\n};\nconst shellQuote = (value: string): string =>\n `'${value.replaceAll(\"'\", \"'\\\\''\")}'`;\nconst inWorkspace = (path: string, root: string): boolean =>\n path.startsWith(`${root}/`);\n\nexport const attachSandboxFile = async (\n input: z.infer<typeof attachWorkspaceFileInput>,\n {\n sandbox,\n upload,\n signal,\n }: {\n readonly sandbox: Pick<SandboxSession, \"resolvePath\" | \"run\" | \"readFile\">;\n readonly upload: FileUploader;\n readonly signal: AbortSignal;\n }\n): Promise<z.infer<typeof attachWorkspaceFileResult>> => {\n signal.throwIfAborted();\n const root = nodePath.posix.normalize(sandbox.resolvePath(\".\"));\n const path = nodePath.posix.normalize(sandbox.resolvePath(input.path));\n if (!inWorkspace(path, root)) {\n throw new Error(\"Attach a file inside the sandbox workspace.\");\n }\n const quoted = shellQuote(path);\n const resolved = await sandbox.run({\n command: `if [ -f ${quoted} ]; then readlink -f -- ${quoted}; fi`,\n signal,\n });\n const realPath = resolved.stdout.replace(/\\n$/u, \"\");\n if (resolved.exitCode !== 0 || !inWorkspace(realPath, root)) {\n throw new Error(\n \"The file is missing, is not a regular file, or resolves outside the workspace.\"\n );\n }\n const stream = await sandbox.readFile({ path: realPath, signal });\n if (!stream) {\n throw new Error(\"The sandbox file is no longer available.\");\n }\n const reader = stream.getReader();\n const chunks: Uint8Array[] = [];\n let size = 0;\n try {\n for (;;) {\n signal.throwIfAborted();\n // oxlint-disable-next-line eslint/no-await-in-loop -- Read ordered chunks and enforce a limit before storing bytes.\n const { done, value } = await reader.read();\n if (done) {\n break;\n }\n size += value.byteLength;\n if (size > maximumWorkspaceFileBytes) {\n throw new Error(\"Files must be 32 MiB or smaller.\");\n }\n chunks.push(value);\n }\n } finally {\n await reader.cancel();\n reader.releaseLock();\n }\n signal.throwIfAborted();\n const name = input.name ?? nodePath.posix.basename(path);\n const mediaType =\n mediaTypes[nodePath.posix.extname(name).toLowerCase()] ??\n \"application/octet-stream\";\n const stored = await upload(name, Buffer.concat(chunks, size), mediaType);\n return attachWorkspaceFileResult.parse({\n fileId: stored.fileId,\n url: stored.url,\n name: stored.pathname,\n mediaType,\n size,\n });\n};\n",
20
+ "type": "registry:file",
21
+ "target": "~/chatjs/tools/attach-workspace-file/attach.ts"
22
+ },
23
+ {
24
+ "path": "src/tools/attach-workspace-file/attach-conversation-file.ts",
25
+ "content": "import type { WorkflowStepToolContext } from \"eve/tools\";\nimport type { z } from \"zod\";\nimport { eveGeneratedFileUploader } from \"@/lib/eve/generated-files\";\nimport { resolveEveConversationScope } from \"@/lib/eve/conversation-scope\";\nimport { attachSandboxFile } from \"./attach\";\nimport type { attachWorkspaceFileInput } from \"./schemas\";\n\n/** Application boundary shared by tools and durable workflows publishing sandbox files. */\nexport const attachConversationFile = async (\n input: z.infer<typeof attachWorkspaceFileInput>,\n context: Readonly<WorkflowStepToolContext>\n) => {\n const { current, initiator } = context.session.auth;\n if (\n context.session.parent ||\n current?.authenticator !== \"chatjs-gateway\" ||\n current.principalId !== initiator?.principalId\n ) {\n throw new Error(\n \"Publication requires the current ChatJS conversation owner's authority.\"\n );\n }\n // Authorize the application resource before reading sandbox bytes.\n await resolveEveConversationScope(\n current.principalId,\n context.session.id,\n context.abortSignal\n );\n return await attachSandboxFile(input, {\n sandbox: await context.getSandbox(),\n upload: eveGeneratedFileUploader(context),\n signal: context.abortSignal,\n });\n};\n",
26
+ "type": "registry:file",
27
+ "target": "~/chatjs/tools/attach-workspace-file/attach-conversation-file.ts"
28
+ },
29
+ {
30
+ "path": "src/tools/attach-workspace-file/import.ts",
31
+ "content": "import { randomUUID } from \"node:crypto\";\nimport type { SandboxSession } from \"eve/sandbox\";\nimport type { z } from \"zod\";\nimport { maximumWorkspaceFileBytes } from \"./schemas\";\nimport type { importFileInput } from \"./schemas\";\n\n/** Copy authorized stored bytes into a fresh native workspace path. */\nexport const importStoredFile = async (\n input: z.infer<typeof importFileInput>,\n {\n stat,\n read,\n getSandbox,\n signal,\n }: {\n readonly stat: () => Promise<{ readonly size: number }>;\n readonly read: () => Promise<{\n readonly type: string;\n readonly stream: () => ReadableStream<Uint8Array>;\n }>;\n readonly getSandbox: () => PromiseLike<\n Pick<SandboxSession, \"resolvePath\" | \"writeBinaryFile\">\n >;\n readonly signal: AbortSignal;\n }\n) => {\n signal.throwIfAborted();\n const metadata = await stat();\n if (metadata.size > maximumWorkspaceFileBytes) {\n throw new Error(\"Files must be 32 MiB or smaller.\");\n }\n signal.throwIfAborted();\n const file = await read();\n const reader = file.stream().getReader();\n const chunks: Uint8Array[] = [];\n let size = 0;\n try {\n for (;;) {\n signal.throwIfAborted();\n // oxlint-disable-next-line eslint/no-await-in-loop -- Bound storage reads before acquiring a sandbox or writing any bytes.\n const { done, value } = await reader.read();\n if (done) {\n break;\n }\n size += value.byteLength;\n if (size > maximumWorkspaceFileBytes) {\n throw new Error(\"Files must be 32 MiB or smaller.\");\n }\n chunks.push(value);\n }\n } finally {\n await reader.cancel();\n reader.releaseLock();\n }\n signal.throwIfAborted();\n const sandbox = await getSandbox();\n // Fresh flat filenames cannot follow user-selected directories or overwrite an earlier import.\n const path = sandbox.resolvePath(`import-${randomUUID()}-${input.name}`);\n await sandbox.writeBinaryFile({\n path,\n content: Buffer.concat(chunks, size),\n signal,\n });\n return {\n fileId: input.fileId,\n path,\n name: input.name,\n mediaType: file.type,\n size,\n };\n};\n",
32
+ "type": "registry:file",
33
+ "target": "~/chatjs/tools/attach-workspace-file/import.ts"
34
+ },
35
+ {
36
+ "path": "src/tools/attach-workspace-file/schemas.ts",
37
+ "content": "import { z } from \"zod\";\nimport { isFileStorageKey } from \"@/lib/file-url\";\n\nexport const maximumWorkspaceFileBytes = 32 * 1024 * 1024;\n\nexport const attachWorkspaceFileInput = z.object({\n path: z\n .string()\n .min(1)\n .max(4096)\n .regex(/^[^\\p{Cc}]+$/u)\n .describe(\n \"File in the current EVE sandbox workspace, e.g. /workspace/report.xlsx.\"\n ),\n name: z\n .string()\n .trim()\n .min(1)\n .max(180)\n .regex(/^[^/\\\\\\p{Cc}]+$/u)\n .optional()\n .describe(\"Optional download filename, including its extension.\"),\n});\n\nexport const attachWorkspaceFileResult = z.object({\n fileId: z.string().min(1),\n name: z.string().min(1),\n mediaType: z.string().min(1),\n size: z.number().int().nonnegative().max(maximumWorkspaceFileBytes),\n url: z.string().min(1),\n});\n\nexport const importFileInput = z.object({\n fileId: z\n .string()\n .refine(isFileStorageKey, \"Use a fileId from this conversation.\")\n .describe(\n \"Exact fileId returned by attach_workspace_file, or the storage key in a file attachment URL in this conversation. Never guess a file ID.\"\n ),\n name: attachWorkspaceFileInput.shape.name\n .unwrap()\n .describe(\n \"Filename from the referenced artifact, including its extension.\"\n ),\n});\n\nexport const importFileResult = attachWorkspaceFileResult\n .omit({ url: true })\n .extend({\n path: z.string().min(1),\n });\n",
38
+ "type": "registry:file",
39
+ "target": "~/chatjs/tools/attach-workspace-file/schemas.ts"
40
+ },
41
+ {
42
+ "path": "src/tools/attach-workspace-file/renderer.tsx",
43
+ "content": "\"use client\";\nimport React from \"react\";\nimport { FileArtifactCard } from \"@/components/file-artifact-card\";\nimport { defineToolRenderer } from \"@/chatjs/core/tools/define-renderer\";\nimport { attachWorkspaceFileInput, attachWorkspaceFileResult } from \"./schemas\";\n\nexport const AttachWorkspaceFileRenderer = defineToolRenderer({\n inputSchema: attachWorkspaceFileInput,\n outputSchema: attachWorkspaceFileResult,\n render: ({ tool }) =>\n tool.state === \"output-available\" ? (\n <FileArtifactCard artifact={tool.output} />\n ) : (\n <output className=\"text-muted-foreground block rounded-lg border p-4 text-sm\">\n Preparing download\n {tool.input?.name === undefined ? \"…\" : `: ${tool.input.name}`}\n </output>\n ),\n});\n",
44
+ "type": "registry:file",
45
+ "target": "~/chatjs/tools/attach-workspace-file/renderer.tsx"
46
+ },
47
+ {
48
+ "path": "dist/source/attach-workspace-file.json",
49
+ "content": "{\n \"agentCategory\": \"tool\",\n \"requiresChatJS\": true,\n \"channelSupport\": { \"web\": \"supported\", \"slack\": \"unsupported\" },\n \"envRequirements\": [],\n \"id\": \"attach-workspace-file\",\n \"kind\": \"tool\",\n \"requiresStorage\": true,\n \"requiresTools\": [],\n \"tools\": [\n { \"accounting\": \"none\", \"toolExport\": \"import_file\" },\n {\n \"accounting\": \"none\",\n \"rendererExport\": \"AttachWorkspaceFileRenderer\",\n \"toolExport\": \"attach_workspace_file\"\n }\n ],\n \"contractVersion\": 1\n}\n",
50
+ "type": "registry:file",
51
+ "target": "~/chatjs/tools/attach-workspace-file/chatjs.json"
52
+ }
53
+ ],
54
+ "meta": {
55
+ "chatjs": {
56
+ "agentCategory": "tool",
57
+ "requiresChatJS": true,
58
+ "channelSupport": {
59
+ "web": "supported",
60
+ "slack": "unsupported"
61
+ },
62
+ "envRequirements": [],
63
+ "id": "attach-workspace-file",
64
+ "kind": "tool",
65
+ "requiresStorage": true,
66
+ "requiresTools": [],
67
+ "tools": [
68
+ {
69
+ "accounting": "none",
70
+ "toolExport": "import_file"
71
+ },
72
+ {
73
+ "accounting": "none",
74
+ "rendererExport": "AttachWorkspaceFileRenderer",
75
+ "toolExport": "attach_workspace_file"
76
+ }
77
+ ],
78
+ "contractVersion": 1
79
+ }
80
+ },
81
+ "type": "registry:item"
82
+ }
@@ -52,7 +52,7 @@
52
52
  },
53
53
  {
54
54
  "path": "dist/source/attachment-uploads.json",
55
- "content": "{\n \"id\": \"attachment-uploads\",\n \"kind\": \"plugin\",\n \"files\": [\n \"chatjs/plugins/attachment-uploads/controls.tsx\",\n \"chatjs/plugins/attachment-uploads/integration.tsx\",\n \"chatjs/plugins/attachment-uploads/upload.ts\",\n \"chatjs/plugins/attachment-uploads/upload-prep.ts\",\n \"app/(chat)/api/files/upload/route.ts\",\n \"chatjs/plugins/attachment-uploads/routes/upload.ts\",\n \"chatjs/plugins/attachment-uploads/client-plugin.ts\"\n ],\n \"requiresStorage\": true,\n \"requiresPersistentSandbox\": true,\n \"client\": {\n \"export\": \"attachmentUploadsClient\",\n \"composerControls\": [\"attach-files\", \"take-photo\"],\n \"settingsItems\": [],\n \"uploads\": true\n },\n \"contractVersion\": 2,\n \"uiBase\": \"base\"\n}\n",
55
+ "content": "{\n \"id\": \"attachment-uploads\",\n \"kind\": \"plugin\",\n \"files\": [\n \"chatjs/plugins/attachment-uploads/controls.tsx\",\n \"chatjs/plugins/attachment-uploads/integration.tsx\",\n \"chatjs/plugins/attachment-uploads/upload.ts\",\n \"chatjs/plugins/attachment-uploads/upload-prep.ts\",\n \"app/(chat)/api/files/upload/route.ts\",\n \"chatjs/plugins/attachment-uploads/routes/upload.ts\",\n \"chatjs/plugins/attachment-uploads/client-plugin.ts\"\n ],\n \"requiresStorage\": true,\n \"client\": {\n \"export\": \"attachmentUploadsClient\",\n \"composerControls\": [\"attach-files\", \"take-photo\"],\n \"settingsItems\": [],\n \"uploads\": true\n },\n \"contractVersion\": 2,\n \"uiBase\": \"base\"\n}\n",
56
56
  "type": "registry:file",
57
57
  "target": "~/chatjs/plugins/attachment-uploads/chatjs.json"
58
58
  }
@@ -71,7 +71,6 @@
71
71
  "chatjs/plugins/attachment-uploads/client-plugin.ts"
72
72
  ],
73
73
  "requiresStorage": true,
74
- "requiresPersistentSandbox": true,
75
74
  "client": {
76
75
  "export": "attachmentUploadsClient",
77
76
  "composerControls": [