@chat-js/registry 0.2.0-beta.0 → 0.2.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/r/ai-titles.json +3 -0
- package/dist/r/attachment-uploads.json +6 -3
- package/dist/r/base/ai-titles.json +50 -0
- package/dist/r/base/akamai-storage.json +44 -0
- package/dist/r/base/alibaba-storage.json +44 -0
- package/dist/r/base/appwrite-storage.json +50 -0
- package/dist/r/base/archil-storage.json +52 -0
- package/dist/r/base/attachment-uploads.json +90 -0
- package/dist/r/base/azure-storage.json +51 -0
- package/dist/r/base/backblaze-b2-storage.json +44 -0
- package/dist/r/base/bunny-storage-storage.json +48 -0
- package/dist/r/base/cloudinary-storage.json +43 -0
- package/dist/r/base/code-documents.json +96 -0
- package/dist/r/base/code-execution-runtime.json +25 -0
- package/dist/r/base/code-execution-ui.json +32 -0
- package/dist/r/base/code-execution.json +69 -0
- package/dist/r/base/credits.json +103 -0
- package/dist/r/base/daytona-sandbox.json +55 -0
- package/dist/r/base/deep-research.json +224 -0
- package/dist/r/base/delete-document.json +58 -0
- package/dist/r/base/digitalocean-spaces-storage.json +44 -0
- package/dist/r/base/dropbox-storage.json +43 -0
- package/dist/r/base/exoscale-storage.json +44 -0
- package/dist/r/base/feedback.json +112 -0
- package/dist/r/base/filebase-storage.json +43 -0
- package/dist/r/base/firebase-storage-storage.json +52 -0
- package/dist/r/base/firecrawl-search.json +72 -0
- package/dist/r/base/followup-suggestions.json +152 -0
- package/dist/r/base/ftp-storage.json +54 -0
- package/dist/r/base/gcs-storage.json +33 -0
- package/dist/r/base/generate-image.json +101 -0
- package/dist/r/base/generate-video.json +70 -0
- package/dist/r/base/get-weather.json +52 -0
- package/dist/r/base/google-drive-storage.json +47 -0
- package/dist/r/base/hetzner-storage.json +44 -0
- package/dist/r/base/ibm-cos-storage.json +44 -0
- package/dist/r/base/idrive-e2-storage.json +44 -0
- package/dist/r/base/langfuse.json +63 -0
- package/dist/r/base/litellm-gateway.json +67 -0
- package/dist/r/base/mcp.json +320 -0
- package/dist/r/base/memory-storage.json +28 -0
- package/dist/r/base/minio-storage.json +44 -0
- package/dist/r/base/model-preferences.json +131 -0
- package/dist/r/base/neon-storage.json +44 -0
- package/dist/r/base/netlify-blobs-storage.json +31 -0
- package/dist/r/base/onedrive-storage.json +48 -0
- package/dist/r/base/openai-compatible-gateway.json +69 -0
- package/dist/r/base/openai-gateway.json +67 -0
- package/dist/r/base/openrouter-gateway.json +75 -0
- package/dist/r/base/oracle-cloud-storage.json +45 -0
- package/dist/r/base/ovhcloud-storage.json +44 -0
- package/dist/r/base/pocketbase-storage.json +50 -0
- package/dist/r/base/projects.json +275 -0
- package/dist/r/base/r2-storage.json +44 -0
- package/dist/r/base/read-document.json +34 -0
- package/dist/r/base/registry.json +4949 -0
- package/dist/r/base/retrieve-url.json +69 -0
- package/dist/r/base/s3-storage.json +44 -0
- package/dist/r/base/saved-code-execution.json +84 -0
- package/dist/r/base/scaleway-storage.json +44 -0
- package/dist/r/base/search.json +146 -0
- package/dist/r/base/sftp-storage.json +58 -0
- package/dist/r/base/sharepoint-storage.json +50 -0
- package/dist/r/base/sharing.json +144 -0
- package/dist/r/base/sheet-documents.json +94 -0
- package/dist/r/base/storj-storage.json +43 -0
- package/dist/r/base/supabase-storage.json +48 -0
- package/dist/r/base/tavily-search.json +72 -0
- package/dist/r/base/tencent-storage.json +44 -0
- package/dist/r/base/text-documents.json +117 -0
- package/dist/r/base/tigris-storage.json +43 -0
- package/dist/r/base/uploadthing-storage.json +38 -0
- package/dist/r/base/vercel-analytics.json +46 -0
- package/dist/r/base/vercel-blob-storage.json +42 -0
- package/dist/r/base/vercel-gateway.json +77 -0
- package/dist/r/base/vercel-sandbox.json +67 -0
- package/dist/r/base/vercel-speed-insights.json +46 -0
- package/dist/r/base/vultr-storage.json +44 -0
- package/dist/r/base/wasabi-storage.json +44 -0
- package/dist/r/base/webdav-storage.json +52 -0
- package/dist/r/base/word-count.json +51 -0
- package/dist/r/base/yandex-storage.json +43 -0
- package/dist/r/code-execution-ui.json +4 -3
- package/dist/r/code-execution.json +2 -2
- package/dist/r/credits.json +5 -0
- package/dist/r/deep-research.json +4 -0
- package/dist/r/feedback.json +7 -0
- package/dist/r/firecrawl-search.json +2 -2
- package/dist/r/followup-suggestions.json +5 -0
- package/dist/r/generate-image.json +3 -3
- package/dist/r/generate-video.json +2 -2
- package/dist/r/get-weather.json +3 -3
- package/dist/r/mcp.json +17 -1
- package/dist/r/model-preferences.json +6 -0
- package/dist/r/openai-compatible-gateway.json +1 -1
- package/dist/r/openai-gateway.json +1 -1
- package/dist/r/openrouter-gateway.json +1 -1
- package/dist/r/projects.json +9 -0
- package/dist/r/radix/ai-titles.json +50 -0
- package/dist/r/radix/akamai-storage.json +44 -0
- package/dist/r/radix/alibaba-storage.json +44 -0
- package/dist/r/radix/appwrite-storage.json +50 -0
- package/dist/r/radix/archil-storage.json +52 -0
- package/dist/r/radix/attachment-uploads.json +90 -0
- package/dist/r/radix/azure-storage.json +51 -0
- package/dist/r/radix/backblaze-b2-storage.json +44 -0
- package/dist/r/radix/bunny-storage-storage.json +48 -0
- package/dist/r/radix/cloudinary-storage.json +43 -0
- package/dist/r/radix/code-documents.json +96 -0
- package/dist/r/radix/code-execution-runtime.json +25 -0
- package/dist/r/radix/code-execution-ui.json +32 -0
- package/dist/r/radix/code-execution.json +69 -0
- package/dist/r/radix/credits.json +103 -0
- package/dist/r/radix/daytona-sandbox.json +55 -0
- package/dist/r/radix/deep-research.json +224 -0
- package/dist/r/radix/delete-document.json +58 -0
- package/dist/r/radix/digitalocean-spaces-storage.json +44 -0
- package/dist/r/radix/dropbox-storage.json +43 -0
- package/dist/r/radix/exoscale-storage.json +44 -0
- package/dist/r/radix/feedback.json +112 -0
- package/dist/r/radix/filebase-storage.json +43 -0
- package/dist/r/radix/firebase-storage-storage.json +52 -0
- package/dist/r/radix/firecrawl-search.json +72 -0
- package/dist/r/radix/followup-suggestions.json +152 -0
- package/dist/r/radix/ftp-storage.json +54 -0
- package/dist/r/radix/gcs-storage.json +33 -0
- package/dist/r/radix/generate-image.json +101 -0
- package/dist/r/radix/generate-video.json +70 -0
- package/dist/r/radix/get-weather.json +52 -0
- package/dist/r/radix/google-drive-storage.json +47 -0
- package/dist/r/radix/hetzner-storage.json +44 -0
- package/dist/r/radix/ibm-cos-storage.json +44 -0
- package/dist/r/radix/idrive-e2-storage.json +44 -0
- package/dist/r/radix/langfuse.json +63 -0
- package/dist/r/radix/litellm-gateway.json +67 -0
- package/dist/r/radix/mcp.json +320 -0
- package/dist/r/radix/memory-storage.json +28 -0
- package/dist/r/radix/minio-storage.json +44 -0
- package/dist/r/radix/model-preferences.json +131 -0
- package/dist/r/radix/neon-storage.json +44 -0
- package/dist/r/radix/netlify-blobs-storage.json +31 -0
- package/dist/r/radix/onedrive-storage.json +48 -0
- package/dist/r/radix/openai-compatible-gateway.json +69 -0
- package/dist/r/radix/openai-gateway.json +67 -0
- package/dist/r/radix/openrouter-gateway.json +75 -0
- package/dist/r/radix/oracle-cloud-storage.json +45 -0
- package/dist/r/radix/ovhcloud-storage.json +44 -0
- package/dist/r/radix/pocketbase-storage.json +50 -0
- package/dist/r/radix/projects.json +275 -0
- package/dist/r/radix/r2-storage.json +44 -0
- package/dist/r/radix/read-document.json +34 -0
- package/dist/r/radix/registry.json +4949 -0
- package/dist/r/radix/retrieve-url.json +69 -0
- package/dist/r/radix/s3-storage.json +44 -0
- package/dist/r/radix/saved-code-execution.json +84 -0
- package/dist/r/radix/scaleway-storage.json +44 -0
- package/dist/r/radix/search.json +146 -0
- package/dist/r/radix/sftp-storage.json +58 -0
- package/dist/r/radix/sharepoint-storage.json +50 -0
- package/dist/r/radix/sharing.json +144 -0
- package/dist/r/radix/sheet-documents.json +94 -0
- package/dist/r/radix/storj-storage.json +43 -0
- package/dist/r/radix/supabase-storage.json +48 -0
- package/dist/r/radix/tavily-search.json +72 -0
- package/dist/r/radix/tencent-storage.json +44 -0
- package/dist/r/radix/text-documents.json +117 -0
- package/dist/r/radix/tigris-storage.json +43 -0
- package/dist/r/radix/uploadthing-storage.json +38 -0
- package/dist/r/radix/vercel-analytics.json +46 -0
- package/dist/r/radix/vercel-blob-storage.json +42 -0
- package/dist/r/radix/vercel-gateway.json +77 -0
- package/dist/r/radix/vercel-sandbox.json +67 -0
- package/dist/r/radix/vercel-speed-insights.json +46 -0
- package/dist/r/radix/vultr-storage.json +44 -0
- package/dist/r/radix/wasabi-storage.json +44 -0
- package/dist/r/radix/webdav-storage.json +52 -0
- package/dist/r/radix/word-count.json +51 -0
- package/dist/r/radix/yandex-storage.json +43 -0
- package/dist/r/registry.json +108 -29
- package/dist/r/retrieve-url.json +5 -3
- package/dist/r/saved-code-execution.json +3 -0
- package/dist/r/search.json +7 -1
- package/dist/r/sharing.json +7 -0
- package/dist/r/sheet-documents.json +2 -1
- package/dist/r/tavily-search.json +2 -2
- package/dist/r/text-documents.json +2 -1
- package/dist/r/word-count.json +2 -2
- package/package.json +4 -1
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://ui.shadcn.com/schema/registry-item.json",
|
|
3
|
+
"name": "code-execution",
|
|
4
|
+
"description": "Execute Python and JavaScript with the selected sandbox provider",
|
|
5
|
+
"dependencies": [
|
|
6
|
+
"ai@7.0.137",
|
|
7
|
+
"zod@4.5.4"
|
|
8
|
+
],
|
|
9
|
+
"registryDependencies": [
|
|
10
|
+
"@chatjs/code-execution-ui",
|
|
11
|
+
"@chatjs/code-execution-runtime"
|
|
12
|
+
],
|
|
13
|
+
"files": [
|
|
14
|
+
{
|
|
15
|
+
"path": "src/tools/code-execution/tool.ts",
|
|
16
|
+
"content": "import type { CodeExecutor } from \"@/lib/eve/code-executor\";\nimport { codeExecutionInput, codeExecutionResult } from \"./schemas\";\nimport { defineTool } from \"eve/tools\";\nimport { eveCodeSandboxOwnership } from \"@/lib/eve/code-sandbox-ownership\";\nimport { createModuleLogger } from \"@/lib/logger\";\nimport { executeJavaScriptInSandbox } from \"@/tools/chatjs/_shared/code-execution/javascript\";\nimport { executePythonInSandbox } from \"@/tools/chatjs/_shared/code-execution/python\";\nimport { executeWithToolUsage } from \"@/lib/eve/tool-usage\";\nimport { toolResultToModelOutput } from \"@/lib/eve/tool-model-output\";\nimport { getSandboxProvider } from \"@/lib/sandbox/runtime\";\nimport { withSandbox } from \"@chat-js/sandboxes/runtime\";\n\nconst EXECUTION_COST_USD = 0.05;\nconst executeCode: CodeExecutor = async (input, context) =>\n await executeWithToolUsage(context, async (usage) => {\n const log = createModuleLogger(\"code-execution\");\n usage.addCostUsd(0);\n try {\n const result = await withSandbox(\n getSandboxProvider(),\n {\n ownership: eveCodeSandboxOwnership(context),\n runtime: input.language,\n signal: context.abortSignal,\n },\n async (sandbox) => {\n const execution = {\n code: input.code,\n log,\n requestId: context.callId,\n sandbox,\n };\n return input.language === \"javascript\"\n ? await executeJavaScriptInSandbox(execution)\n : await executePythonInSandbox(execution);\n }\n );\n const output = codeExecutionResult.parse(result);\n usage.addCostUsd(EXECUTION_COST_USD);\n return output;\n } catch (error) {\n log.error({ error, callId: context.callId }, \"code execution failed\");\n return usage.fail();\n }\n });\n\nconst codeExecution = defineTool({\n description: `Sandboxed code execution for Python and JavaScript.\n\nUse for:\n- Execute Python for calculations, data analysis, and visualisations\n- Execute JavaScript for scripting, transformations, async fetches, and general runtime checks\n\nPython support:\n- matplotlib, pandas, numpy, sympy, yfinance pre-installed — do NOT reinstall them\n- Produce interactive line / scatter / bar charts OR matplotlib PNG charts\n- Install extra libs by adding lines like: '!pip install <pkg> [<pkg2> ...]' (we auto-install and strip these lines; pre-installed packages are ignored)\n\nJavaScript support:\n- Runs in a sandboxed Node.js runtime, never in the browser thread\n- Use console.log(...) to print output\n- You can also assign 'result' or 'results', or return a value from the snippet\n\nChart output — Python only:\n1. Interactive chart (preferred for line/scatter/bar): assign a 'chart' variable matching this schema:\n chart = {\n \"type\": \"line\" | \"scatter\" | \"bar\",\n \"title\": \"My Chart\",\n \"x_label\": \"X\", # optional\n \"y_label\": \"Y\", # optional\n \"x_scale\": \"datetime\" | None, # optional, for time-series x axes\n \"elements\": [\n # for line/scatter: {\"label\": \"Series A\", \"points\": [[x1,y1],[x2,y2],...]}\n # for bar: {\"label\": \"Category\", \"group\": \"Group A\", \"value\": 42}\n ]\n }\n2. Matplotlib PNG: use plt.plot()/plt.savefig() normally (no need to call plt.show())\n\nRestrictions:\n- No images in the assistant response; don't embed them\n- Interactive chart: only line / scatter / bar types\n\nOutput rules:\n- Set language to 'python' or 'javascript'\n- Python charts: assign 'chart' dict for interactive charts (takes priority over matplotlib PNG)\n- Python values: assign 'result' or 'results', or print explicitly\n- JavaScript values: assign 'result' or 'results', return a value, or print explicitly\n- Don't rely on implicit REPL last-expression output`,\n execute: executeCode,\n inputSchema: codeExecutionInput,\n toModelOutput: toolResultToModelOutput,\n});\nexport { codeExecution, executeCode };\n",
|
|
17
|
+
"type": "registry:file",
|
|
18
|
+
"target": "~/tools/chatjs/code-execution/tool.ts"
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
"path": "src/tools/code-execution/renderer.tsx",
|
|
22
|
+
"content": "\"use client\";\nimport { codeExecutionInput, codeExecutionResult } from \"./schemas\";\nimport { CodeExecutionChart } from \"@/tools/chatjs/_shared/code-execution/code-execution-chart\";\nimport React from \"react\";\n// Preserve the exact TSX target: shadcn otherwise confuses it with subagent sandbox.ts files.\nimport { SandboxComposed } from \"@/components/sandbox.tsx\";\nimport type { ToolRendererProps } from \"@/lib/ai/define-tool-renderer\";\nimport { defineToolRenderer } from \"@/lib/ai/define-tool-renderer\";\n\ntype CodeExecutionTool = ToolRendererProps<\n typeof codeExecutionInput,\n typeof codeExecutionResult\n>[\"tool\"];\n\ntype CodeExecutionViewTool = Readonly<{\n state: CodeExecutionTool[\"state\"];\n input?: Readonly<{\n code?: string;\n language?: string;\n title?: string;\n }>;\n output?: Readonly<{\n chart: unknown;\n message: string;\n }>;\n}>;\n\nconst CodeExecutionView = ({\n tool,\n}: Readonly<{ tool: CodeExecutionViewTool }>): React.JSX.Element => {\n const args = tool.input ?? {\n code: \"\",\n icon: \"default\",\n language: \"python\",\n title: \"\",\n };\n const result = tool.state === \"output-available\" ? tool.output : null;\n const code = typeof args.code === \"string\" ? args.code : \"\";\n const title = typeof args.title === \"string\" ? args.title : \"\";\n const language = args.language === \"javascript\" ? \"javascript\" : \"python\";\n return (\n <div className=\"space-y-6\">\n <SandboxComposed\n code={code}\n language={language}\n output={result?.message}\n state={tool.state}\n title={title}\n />\n\n <CodeExecutionChart value={result?.chart} />\n </div>\n );\n};\n\nconst CodeExecution = defineToolRenderer({\n inputSchema: codeExecutionInput,\n outputSchema: codeExecutionResult,\n render: CodeExecutionView,\n streamingInputSchema: codeExecutionInput.partial().extend({\n // oxlint-disable-next-line promise/prefer-await-to-then, unicorn/no-useless-undefined -- oxc-project/oxc#22161: synchronous Zod fallback preserves streamed code on invalid language. Zod requires the undefined fallback argument.\n language: codeExecutionInput.shape.language.optional().catch(undefined),\n // oxlint-disable-next-line promise/prefer-await-to-then, unicorn/no-useless-undefined -- oxc-project/oxc#22161: synchronous Zod fallback preserves streamed code on invalid title. Zod requires the undefined fallback argument.\n title: codeExecutionInput.shape.title.optional().catch(undefined),\n }),\n});\nexport { CodeExecution };\nexport type { CodeExecutionTool };\n",
|
|
23
|
+
"type": "registry:file",
|
|
24
|
+
"target": "~/tools/chatjs/code-execution/renderer.tsx"
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
"path": "src/tools/code-execution/schemas.ts",
|
|
28
|
+
"content": "import { supportedExecutionLanguages } from \"@/tools/chatjs/_shared/code-execution/types\";\nimport { z } from \"zod\";\n\nconst codeExecutionInput = z.object({\n code: z\n .string()\n .describe(\n \"The code to execute in the selected sandbox language. Print anything you want to return, or assign to 'result'/'results'.\"\n ),\n language: z\n .enum(supportedExecutionLanguages)\n .default(\"python\")\n .describe(\"The language to execute: 'python' or 'javascript'.\"),\n title: z.string().describe(\"The title of the code snippet.\"),\n});\n\nconst encodedChart = z.object({ base64: z.string(), format: z.string() });\nconst chartRecord = z.record(z.string(), z.json());\nconst codeExecutionResult = z.object({\n message: z.string(),\n chart: z.union([z.string(), encodedChart, chartRecord]),\n});\nexport { codeExecutionInput, codeExecutionResult };\n",
|
|
29
|
+
"type": "registry:file",
|
|
30
|
+
"target": "~/tools/chatjs/code-execution/schemas.ts"
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
"path": "dist/source/code-execution.json",
|
|
34
|
+
"content": "{\n \"codeExecutionCapabilities\": {\n \"cancellation\": \"terminate\",\n \"cleanup\": \"durable-allocation\",\n \"files\": \"ephemeral\",\n \"languages\": [\"python\", \"javascript\"],\n \"timeout\": \"bounded\",\n \"usage\": \"single-receipt\"\n },\n \"codeExecutorExport\": \"executeCode\",\n \"envRequirements\": [],\n \"id\": \"code-execution\",\n \"kind\": \"tool\",\n \"requiresSandbox\": true,\n \"requiresTools\": [],\n \"slot\": \"codeExecution\",\n \"tools\": [\n { \"rendererExport\": \"CodeExecution\", \"toolExport\": \"codeExecution\" }\n ],\n \"contractVersion\": 1\n}\n",
|
|
35
|
+
"type": "registry:file",
|
|
36
|
+
"target": "~/tools/chatjs/code-execution/chatjs.json"
|
|
37
|
+
}
|
|
38
|
+
],
|
|
39
|
+
"meta": {
|
|
40
|
+
"chatjs": {
|
|
41
|
+
"codeExecutionCapabilities": {
|
|
42
|
+
"cancellation": "terminate",
|
|
43
|
+
"cleanup": "durable-allocation",
|
|
44
|
+
"files": "ephemeral",
|
|
45
|
+
"languages": [
|
|
46
|
+
"python",
|
|
47
|
+
"javascript"
|
|
48
|
+
],
|
|
49
|
+
"timeout": "bounded",
|
|
50
|
+
"usage": "single-receipt"
|
|
51
|
+
},
|
|
52
|
+
"codeExecutorExport": "executeCode",
|
|
53
|
+
"envRequirements": [],
|
|
54
|
+
"id": "code-execution",
|
|
55
|
+
"kind": "tool",
|
|
56
|
+
"requiresSandbox": true,
|
|
57
|
+
"requiresTools": [],
|
|
58
|
+
"slot": "codeExecution",
|
|
59
|
+
"tools": [
|
|
60
|
+
{
|
|
61
|
+
"rendererExport": "CodeExecution",
|
|
62
|
+
"toolExport": "codeExecution"
|
|
63
|
+
}
|
|
64
|
+
],
|
|
65
|
+
"contractVersion": 1
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
"type": "registry:item"
|
|
69
|
+
}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://ui.shadcn.com/schema/registry-item.json",
|
|
3
|
+
"name": "credits",
|
|
4
|
+
"description": "Credit balances, spending admission, and atomic usage debits",
|
|
5
|
+
"dependencies": [
|
|
6
|
+
"@tanstack/react-query@^5.104.1",
|
|
7
|
+
"drizzle-orm@^0.45.1",
|
|
8
|
+
"lucide-react@0.553.0"
|
|
9
|
+
],
|
|
10
|
+
"files": [
|
|
11
|
+
{
|
|
12
|
+
"path": "src/plugins/credits/src/balance.tsx",
|
|
13
|
+
"content": "\"use client\";\n\nimport { DollarSign } from \"lucide-react\";\nimport { useGetCredits } from \"./use-credits\";\n\nconst CENTS_PER_DOLLAR = 100;\nconst DISPLAY_DECIMALS = 2;\n\nexport const CreditBalance = () => {\n const { balanceCents, isError } = useGetCredits();\n if (isError) {\n return <span className=\"truncate text-xs\">Balance unavailable</span>;\n }\n if (balanceCents === undefined) {\n return <span className=\"truncate text-xs\">Loading balance…</span>;\n }\n return (\n <span className=\"flex items-center gap-1 truncate text-xs\">\n <DollarSign aria-hidden=\"true\" className=\"size-3\" />\n {(balanceCents / CENTS_PER_DOLLAR).toFixed(DISPLAY_DECIMALS)}\n </span>\n );\n};\n",
|
|
14
|
+
"type": "registry:file",
|
|
15
|
+
"target": "~/plugins/credits/balance.tsx"
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
"path": "src/plugins/credits/src/billing.ts",
|
|
19
|
+
"content": "import { eq, sql } from \"drizzle-orm\";\nimport type { UsageBilling } from \"@/lib/usage-billing-contracts\";\nimport { getBalanceCents } from \"./credits-queries\";\nimport { userCredit } from \"./credits-schema\";\n\n/** Core supplies its usage transaction, with the registered owner already locked. */\nexport const creditsBilling = {\n canSpend: async (ownerId) => (await getBalanceCents(ownerId)) > 0,\n debit: async (tx, { ownerId, cents }) => {\n await tx\n .insert(userCredit)\n .values({ userId: ownerId })\n .onConflictDoNothing();\n await tx\n .update(userCredit)\n .set({ balanceCents: sql`${userCredit.balanceCents} - ${cents}` })\n .where(eq(userCredit.userId, ownerId));\n },\n} satisfies UsageBilling;\n",
|
|
20
|
+
"type": "registry:file",
|
|
21
|
+
"target": "~/plugins/credits/billing.ts"
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
"path": "src/plugins/credits/src/client-plugin.ts",
|
|
25
|
+
"content": "import type { ChatClientPlugin } from \"@/lib/plugin-contracts\";\nimport { CreditBalance } from \"./balance\";\n\nexport const creditsClient = () =>\n ({ id: \"credits\", accountSummary: CreditBalance }) satisfies ChatClientPlugin;\n",
|
|
26
|
+
"type": "registry:file",
|
|
27
|
+
"target": "~/plugins/credits/client-plugin.ts"
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
"path": "src/plugins/credits/src/credits-queries.ts",
|
|
31
|
+
"content": "import { eq } from \"drizzle-orm\";\n\nimport { db } from \"@/lib/db/client\";\nimport { userCredit } from \"./credits-schema\";\n\nconst NO_CREDITS = 0;\nconst FIRST_CREDIT_ROW_INDEX = 0;\nconst SINGLE_CREDIT_ROW_LIMIT = 1;\n\nconst ensureUserCreditRow = async (userId: string): Promise<void> => {\n await db.insert(userCredit).values({ userId }).onConflictDoNothing();\n};\n/**\n * Get user's current credit balance (in cents).\n * @param {string} userId - User whose balance is read; a missing credit row is created with the database defaults.\n * @returns {Promise<number>} Stored balance in cents, or zero if the retry still has no balance; database failures reject.\n */\nconst getBalanceCents = async (userId: string): Promise<number> => {\n let rows = await db\n .select({ balanceCents: userCredit.balanceCents })\n .from(userCredit)\n .where(eq(userCredit.userId, userId))\n .limit(SINGLE_CREDIT_ROW_LIMIT);\n\n if (rows.length === NO_CREDITS) {\n await ensureUserCreditRow(userId);\n rows = await db\n .select({ balanceCents: userCredit.balanceCents })\n .from(userCredit)\n .where(eq(userCredit.userId, userId))\n .limit(SINGLE_CREDIT_ROW_LIMIT);\n }\n\n return rows[FIRST_CREDIT_ROW_INDEX]?.balanceCents ?? NO_CREDITS;\n};\n\nexport { getBalanceCents };\n",
|
|
32
|
+
"type": "registry:file",
|
|
33
|
+
"target": "~/plugins/credits/credits-queries.ts"
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
"path": "src/plugins/credits/src/credits-schema.ts",
|
|
37
|
+
"content": "import { integer, pgTable, text } from \"drizzle-orm/pg-core\";\nimport { user } from \"@/lib/db/schema\";\n\nconst INITIAL_USER_CREDIT_BALANCE_CENTS = 50;\n\nconst userCredit = pgTable(\"UserCredit\", {\n /** Balance in cents. Default = $0.50 */\n balanceCents: integer(\"credits\")\n .notNull()\n .default(INITIAL_USER_CREDIT_BALANCE_CENTS),\n userId: text(\"userId\")\n .primaryKey()\n .notNull()\n .references(() => user.id, { onDelete: \"cascade\" }),\n});\n\nexport { userCredit };\n",
|
|
38
|
+
"type": "registry:file",
|
|
39
|
+
"target": "~/plugins/credits/credits-schema.ts"
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
"path": "src/plugins/credits/src/router.ts",
|
|
43
|
+
"content": "import { getBalanceCents } from \"./credits-queries\";\nimport { createTRPCRouter, protectedProcedure } from \"@/trpc/init\";\n\nexport const creditsRouter = createTRPCRouter({\n getAvailableCredits: protectedProcedure.query(\n async ({\n ctx,\n }: {\n readonly ctx: { readonly user: { readonly id: string } };\n }) => {\n const balanceCents = await getBalanceCents(ctx.user.id);\n return { balanceCents };\n }\n ),\n});\n",
|
|
44
|
+
"type": "registry:file",
|
|
45
|
+
"target": "~/plugins/credits/router.ts"
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
"path": "src/plugins/credits/src/server-plugin.ts",
|
|
49
|
+
"content": "import type { ChatPlugin } from \"@/lib/plugin-contracts\";\nimport { creditsRouter } from \"./router\";\n\nexport const credits = () =>\n ({ id: \"credits\", routers: { credits: creditsRouter } }) satisfies ChatPlugin;\n",
|
|
50
|
+
"type": "registry:file",
|
|
51
|
+
"target": "~/plugins/credits/server-plugin.ts"
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
"path": "src/plugins/credits/src/use-credits.ts",
|
|
55
|
+
"content": "\"use client\";\n\nimport { useQuery } from \"@tanstack/react-query\";\n\nimport { useSession } from \"@/providers/session-provider\";\nimport { useTRPC } from \"@/trpc/react\";\n\nexport const useGetCredits = (): {\n balanceCents: number | undefined;\n isError: boolean;\n} => {\n const { data: session } = useSession();\n const isAuthenticated = Boolean(session?.user);\n const trpc = useTRPC();\n\n const { data: creditsData, isError } = useQuery({\n ...trpc.credits.getAvailableCredits.queryOptions(),\n enabled: isAuthenticated,\n meta: { refreshOnTurnEnd: true },\n });\n\n return {\n balanceCents: creditsData?.balanceCents,\n isError,\n };\n};\n",
|
|
56
|
+
"type": "registry:file",
|
|
57
|
+
"target": "~/plugins/credits/use-credits.ts"
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
"path": "dist/source/credits.json",
|
|
61
|
+
"content": "{\n \"id\": \"credits\",\n \"kind\": \"plugin\",\n \"files\": [\n \"plugins/credits/balance.tsx\",\n \"plugins/credits/billing.ts\",\n \"plugins/credits/client-plugin.ts\",\n \"plugins/credits/credits-queries.ts\",\n \"plugins/credits/credits-schema.ts\",\n \"plugins/credits/router.ts\",\n \"plugins/credits/server-plugin.ts\",\n \"plugins/credits/use-credits.ts\"\n ],\n \"databaseSchemas\": [\n \"plugins/credits/credits-schema.ts\"\n ],\n \"billing\": {\n \"export\": \"creditsBilling\"\n },\n \"server\": {\n \"export\": \"credits\",\n \"routers\": [\n \"credits\"\n ]\n },\n \"client\": {\n \"export\": \"creditsClient\",\n \"composerControls\": [],\n \"settingsItems\": [],\n \"accountSummary\": true\n },\n \"contractVersion\": 2,\n \"uiBase\": \"radix\"\n}\n",
|
|
62
|
+
"type": "registry:file",
|
|
63
|
+
"target": "~/plugins/credits/chatjs.json"
|
|
64
|
+
}
|
|
65
|
+
],
|
|
66
|
+
"meta": {
|
|
67
|
+
"chatjs": {
|
|
68
|
+
"id": "credits",
|
|
69
|
+
"kind": "plugin",
|
|
70
|
+
"files": [
|
|
71
|
+
"plugins/credits/balance.tsx",
|
|
72
|
+
"plugins/credits/billing.ts",
|
|
73
|
+
"plugins/credits/client-plugin.ts",
|
|
74
|
+
"plugins/credits/credits-queries.ts",
|
|
75
|
+
"plugins/credits/credits-schema.ts",
|
|
76
|
+
"plugins/credits/router.ts",
|
|
77
|
+
"plugins/credits/server-plugin.ts",
|
|
78
|
+
"plugins/credits/use-credits.ts"
|
|
79
|
+
],
|
|
80
|
+
"databaseSchemas": [
|
|
81
|
+
"plugins/credits/credits-schema.ts"
|
|
82
|
+
],
|
|
83
|
+
"billing": {
|
|
84
|
+
"export": "creditsBilling"
|
|
85
|
+
},
|
|
86
|
+
"server": {
|
|
87
|
+
"export": "credits",
|
|
88
|
+
"routers": [
|
|
89
|
+
"credits"
|
|
90
|
+
]
|
|
91
|
+
},
|
|
92
|
+
"client": {
|
|
93
|
+
"export": "creditsClient",
|
|
94
|
+
"composerControls": [],
|
|
95
|
+
"settingsItems": [],
|
|
96
|
+
"accountSummary": true
|
|
97
|
+
},
|
|
98
|
+
"contractVersion": 2,
|
|
99
|
+
"uiBase": "radix"
|
|
100
|
+
}
|
|
101
|
+
},
|
|
102
|
+
"type": "registry:item"
|
|
103
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://ui.shadcn.com/schema/registry-item.json",
|
|
3
|
+
"name": "daytona-sandbox",
|
|
4
|
+
"title": "Daytona",
|
|
5
|
+
"dependencies": [
|
|
6
|
+
"@chat-js/sandboxes@0.2.0",
|
|
7
|
+
"@daytona/sdk@0.220.0"
|
|
8
|
+
],
|
|
9
|
+
"files": [
|
|
10
|
+
{
|
|
11
|
+
"path": "src/sandboxes/daytona/provider.ts",
|
|
12
|
+
"content": "import type { DaytonaProvider } from \"./adapter\";\nimport type { SandboxProvider } from \"@chat-js/sandboxes/provider\";\nimport { readSandboxEnvironment } from \"./daytona-sandbox-env\";\nimport { commandSandbox, createDaytonaProvider } from \"./adapter\";\n\n// Reuse the SDK event connection within each worker process.\nlet client: DaytonaProvider | undefined;\n\nexport const createSandboxProvider = (): SandboxProvider => {\n const env = readSandboxEnvironment();\n client ??= createDaytonaProvider({\n apiKey: env.DAYTONA_API_KEY ?? \"\",\n organizationId: env.DAYTONA_ORGANIZATION_ID ?? \"\",\n });\n const provider = client;\n return {\n scope: provider.cleanup.scope,\n async create({ name, runtime, signal }) {\n const resource = await provider.create(name, runtime);\n return { name: resource.name, ...commandSandbox(resource, signal) };\n },\n deleteAndConfirmAbsent: provider.cleanup.deleteAndConfirmAbsent,\n };\n};\n\n/** Available without resolving provider credentials. */\nexport const supportsPersistentSandbox = false;\n",
|
|
13
|
+
"type": "registry:file",
|
|
14
|
+
"target": "~/lib/sandbox/provider.ts"
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
"path": "src/sandboxes/daytona/daytona-sandbox-env.ts",
|
|
18
|
+
"content": "import { z } from \"zod\";\n\nconst environmentSchema = z.object({\n DAYTONA_API_KEY: z.string().optional(),\n DAYTONA_ORGANIZATION_ID: z.string().optional(),\n});\n\nconst readSandboxEnvironment = (\n environment: Readonly<NodeJS.ProcessEnv> = process.env\n) => environmentSchema.parse(environment);\n\nexport { readSandboxEnvironment };\n",
|
|
19
|
+
"type": "registry:file",
|
|
20
|
+
"target": "~/lib/sandbox/daytona-sandbox-env.ts"
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
"path": "src/sandboxes/daytona/adapter.ts",
|
|
24
|
+
"content": "import type { CreateSandboxFromSnapshotParams, Sandbox } from \"@daytona/sdk\";\nimport { Daytona, DaytonaNotFoundError } from \"@daytona/sdk\";\nimport type {\n SandboxProvider,\n SandboxScope,\n Sandbox as ExecutionSandboxResource,\n} from \"@chat-js/sandboxes/provider\";\nimport type { ReadonlyNativeSurface } from \"@/lib/readonly-native-surface\";\nimport { createHash } from \"node:crypto\";\n\ninterface CodeSandboxCleanupSession {\n deleteAndConfirmAbsent: SandboxProvider[\"deleteAndConfirmAbsent\"];\n scope: SandboxScope;\n}\ntype ExecutionSandbox = Pick<ExecutionSandboxResource, \"runCommand\">;\n\nconst API_URL = \"https://app.daytona.io/api\";\nconst REQUEST_TIMEOUT_MS = 30_000;\nconst OPERATION_TIMEOUT_SECONDS = 60;\nconst EXECUTION_TIMEOUT_SECONDS = 300;\nconst LIFETIME_MINUTES = 10;\n\ninterface DaytonaResource {\n readonly name: string;\n readonly organizationId: string;\n readonly state?: Sandbox[\"state\"];\n readonly process: Readonly<Pick<Sandbox[\"process\"], \"executeCommand\">>;\n readonly delete: Sandbox[\"delete\"];\n}\ninterface DaytonaClient {\n readonly create: (\n params: ReadonlyNativeSurface<\n Pick<\n CreateSandboxFromSnapshotParams,\n | \"autoStopInterval\"\n | \"ephemeral\"\n | \"labels\"\n | \"language\"\n | \"name\"\n | \"public\"\n | \"ttlMinutes\"\n >\n >,\n options?: Readonly<{ timeout?: number }>\n ) => Promise<DaytonaResource>;\n readonly get: (name: string) => Promise<DaytonaResource>;\n}\ninterface DaytonaProvider {\n readonly cleanup: CodeSandboxCleanupSession;\n readonly create: (\n name: string,\n language: \"python\" | \"javascript\"\n ) => Promise<DaytonaResource>;\n}\ntype Credentials = Readonly<{ apiKey: string; organizationId: string }>;\n\nconst shellArgument = (value: string): string =>\n `'${value.replaceAll(\"'\", String.raw`'\\''`)}'`;\n\nconst waitForCommand = async <Result>(\n operation: Readonly<Promise<Result>>,\n signal: ReadonlyNativeSurface<AbortSignal>\n): Promise<Result> => {\n const cancelled = Promise.withResolvers<never>();\n const stop = (): void => {\n cancelled.reject(new Error(\"Daytona command cancelled\"));\n };\n signal.addEventListener(\"abort\", stop, { once: true });\n if (signal.aborted) {\n stop();\n }\n try {\n return await Promise.race([operation, cancelled.promise]);\n } finally {\n signal.removeEventListener(\"abort\", stop);\n }\n};\nconst commandSandbox = (\n resource: DaytonaResource,\n signal: ReadonlyNativeSurface<AbortSignal>\n): ExecutionSandbox => ({\n async runCommand({\n cmd,\n args,\n }: Readonly<{ cmd: string; args: readonly string[] }>) {\n signal.throwIfAborted();\n const result = await waitForCommand(\n resource.process.executeCommand(\n [cmd, ...args].map((argument) => shellArgument(argument)).join(\" \"),\n \"/tmp\",\n {},\n EXECUTION_TIMEOUT_SECONDS\n ),\n signal\n );\n signal.throwIfAborted();\n // Daytona exposes combined command output; keep it once in stdout.\n return {\n exitCode: result.exitCode,\n stderr: async () => await Promise.resolve(\"\"),\n stdout: async () => await Promise.resolve(result.result),\n };\n },\n});\n\nconst assertIdentity = (\n resource: DaytonaResource,\n name: string,\n organizationId: string\n): void => {\n if (resource.name !== name || resource.organizationId !== organizationId) {\n throw new Error(\n \"Daytona sandbox identity does not match its allocation intent.\"\n );\n }\n};\n\nconst findResource = async (\n client: DaytonaClient,\n identity: Readonly<{ name: string; organizationId: string }>\n): Promise<DaytonaResource | null> => {\n try {\n const resource = await client.get(identity.name);\n assertIdentity(resource, identity.name, identity.organizationId);\n return resource;\n } catch (error) {\n if (error instanceof DaytonaNotFoundError) {\n return null;\n }\n throw error;\n }\n};\nconst cleanupSession = (\n client: DaytonaClient,\n credentials: Credentials\n): CodeSandboxCleanupSession => ({\n async deleteAndConfirmAbsent(name) {\n const identity = { name, organizationId: credentials.organizationId };\n const resource = await findResource(client, identity);\n if (resource === null || resource.state === \"destroyed\") {\n return;\n }\n await resource.delete(OPERATION_TIMEOUT_SECONDS, true);\n const remaining = await findResource(client, identity);\n if (remaining !== null && remaining.state !== \"destroyed\") {\n throw new Error(\"Daytona sandbox remains available after deletion.\");\n }\n },\n scope: {\n providerId: \"daytona\",\n // API-key auth ignores organizationId in the SDK. Pin the credential scope\n // so replacing it cannot turn a foreign 404 into proof of prior deletion.\n scopeId: `${API_URL}#${createHash(\"sha256\").update(credentials.apiKey).digest(\"hex\")}`,\n accountId: `daytona:${credentials.organizationId}`,\n },\n});\n\nconst createDaytonaProvider = (\n credentials: Credentials,\n client?: DaytonaClient\n): DaytonaProvider => {\n if (\n credentials.apiKey.trim() === \"\" ||\n credentials.organizationId.trim() === \"\"\n ) {\n throw new Error(\n \"DAYTONA_API_KEY and DAYTONA_ORGANIZATION_ID are required.\"\n );\n }\n const selectedClient =\n client ??\n new Daytona({\n apiKey: credentials.apiKey,\n apiUrl: API_URL,\n organizationId: credentials.organizationId,\n otelEnabled: false,\n requestTimeoutMs: REQUEST_TIMEOUT_MS,\n });\n return {\n cleanup: cleanupSession(selectedClient, credentials),\n async create(name, language): Promise<DaytonaResource> {\n const resource = await selectedClient.create(\n {\n autoStopInterval: LIFETIME_MINUTES,\n ephemeral: true,\n labels: { \"chatjs-allocation\": name },\n language,\n name,\n public: false,\n ttlMinutes: LIFETIME_MINUTES,\n },\n { timeout: OPERATION_TIMEOUT_SECONDS }\n );\n assertIdentity(resource, name, credentials.organizationId);\n return resource;\n },\n };\n};\n\nexport { commandSandbox, createDaytonaProvider };\nexport type { DaytonaProvider, DaytonaResource };\n",
|
|
25
|
+
"type": "registry:file",
|
|
26
|
+
"target": "~/lib/sandbox/adapter.ts"
|
|
27
|
+
}
|
|
28
|
+
],
|
|
29
|
+
"meta": {
|
|
30
|
+
"chatjs": {
|
|
31
|
+
"contractVersion": 1,
|
|
32
|
+
"kind": "sandbox",
|
|
33
|
+
"id": "daytona",
|
|
34
|
+
"capabilities": {
|
|
35
|
+
"runtimes": [
|
|
36
|
+
"python",
|
|
37
|
+
"javascript"
|
|
38
|
+
],
|
|
39
|
+
"cleanup": "durable-allocation",
|
|
40
|
+
"cancellation": "terminate"
|
|
41
|
+
},
|
|
42
|
+
"envRequirements": [
|
|
43
|
+
{
|
|
44
|
+
"options": [
|
|
45
|
+
[
|
|
46
|
+
"DAYTONA_API_KEY",
|
|
47
|
+
"DAYTONA_ORGANIZATION_ID"
|
|
48
|
+
]
|
|
49
|
+
]
|
|
50
|
+
}
|
|
51
|
+
]
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
"type": "registry:item"
|
|
55
|
+
}
|