Skip to content

Commit d9d79fe

Browse files
committed
registry
1 parent e6a42f9 commit d9d79fe

File tree

12 files changed

+153
-68
lines changed

12 files changed

+153
-68
lines changed

apps/www/public/r/index.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1765,6 +1765,14 @@
17651765
"path": "plate-ui/ai-menu.tsx",
17661766
"type": "registry:ui"
17671767
},
1768+
{
1769+
"path": "plate-ui/ai-loading-bar.tsx",
1770+
"type": "registry:ui"
1771+
},
1772+
{
1773+
"path": "plate-ui/ai-anchor-element.tsx",
1774+
"type": "registry:ui"
1775+
},
17681776
{
17691777
"path": "plate-ui/ai-menu-items.tsx",
17701778
"type": "registry:ui"

apps/www/public/r/styles/default/ai-menu.json

Lines changed: 13 additions & 1 deletion
Large diffs are not rendered by default.

apps/www/public/r/styles/default/api-ai.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"files": [
77
{
88
"path": "app/api/ai/command/route.ts",
9-
"content": "import type { NextRequest } from 'next/server';\n\nimport { createOpenAI } from '@ai-sdk/openai';\nimport { convertToCoreMessages, streamText } from 'ai';\nimport { NextResponse } from 'next/server';\n\nexport async function POST(req: NextRequest) {\n const {\n apiKey: key,\n messages,\n model = 'gpt-4o-mini',\n system,\n } = await req.json();\n\n const apiKey = key || process.env.OPENAI_API_KEY;\n\n if (!apiKey) {\n return NextResponse.json(\n { error: 'Missing OpenAI API key.' },\n { status: 401 }\n );\n }\n\n const openai = createOpenAI({ apiKey });\n\n try {\n const result = streamText({\n maxTokens: 2048,\n messages: convertToCoreMessages(messages),\n model: openai(model),\n system: system,\n });\n\n return result.toDataStreamResponse();\n } catch {\n return NextResponse.json(\n { error: 'Failed to process AI request' },\n { status: 500 }\n );\n }\n}\n",
9+
"content": "import type { NextRequest } from 'next/server';\n\nimport { createOpenAI } from '@ai-sdk/openai';\nimport { convertToCoreMessages, smoothStream, streamText } from 'ai';\nimport { NextResponse } from 'next/server';\n\nconst CHUNKING_REGEXPS = {\n line: /\\n+/m,\n list: /.{8}/m,\n word: /\\S+\\s+/m,\n};\n\nexport async function POST(req: NextRequest) {\n const { apiKey: key, messages, model = 'gpt-4o', system } = await req.json();\n\n const apiKey = key || process.env.OPENAI_API_KEY;\n\n if (!apiKey) {\n return NextResponse.json(\n { error: 'Missing OpenAI API key.' },\n { status: 401 }\n );\n }\n\n const openai = createOpenAI({ apiKey });\n\n let isInCodeBlock = false;\n let isInTable = false;\n let isInList = false;\n let isInLink = false;\n try {\n const result = streamText({\n experimental_transform: smoothStream({\n chunking: (buffer) => {\n // Check for code block markers\n if (buffer.includes('```')) {\n isInCodeBlock = !isInCodeBlock;\n }\n\n // test case: should not deserialize link with markdown syntax\n if (buffer.includes('http')) {\n isInLink = true;\n } else if (buffer.includes('https')) {\n isInLink = true;\n } else if (buffer.includes('\\n') && isInLink) {\n isInLink = false;\n }\n\n if (buffer.includes('*') || buffer.includes('-')) {\n isInList = true;\n } else if (buffer.includes('\\n') && isInList) {\n isInList = false;\n }\n\n // Simple table detection: enter on |, exit on double newline\n if (!isInTable && buffer.includes('|')) {\n isInTable = true;\n } else if (isInTable && buffer.includes('\\n\\n')) {\n isInTable = false;\n }\n\n // Use line chunking for code blocks and tables, word chunking otherwise\n // Choose the appropriate chunking strategy based on content type\n let match;\n\n if (isInCodeBlock || isInTable || isInLink) {\n // Use line chunking for code blocks and tables\n match = CHUNKING_REGEXPS.line.exec(buffer);\n } else if (isInList) {\n // Use list chunking for lists\n match = CHUNKING_REGEXPS.list.exec(buffer);\n } else {\n // Use word chunking for regular text\n match = CHUNKING_REGEXPS.word.exec(buffer);\n }\n\n if (!match) {\n return null;\n }\n\n return buffer.slice(0, match.index) + match?.[0];\n },\n }),\n maxTokens: 2048,\n messages: convertToCoreMessages(messages),\n model: openai('gpt-4o'),\n system: system,\n });\n\n return result.toDataStreamResponse();\n } catch {\n return NextResponse.json(\n { error: 'Failed to process AI request' },\n { status: 500 }\n );\n }\n}\n",
1010
"type": "registry:lib",
1111
"target": "app/api/ai/command/route.ts"
1212
},

apps/www/public/r/styles/default/editor-plugins.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
"name": "editor-plugins",
2929
"registryDependencies": [
3030
"ai-plugins",
31+
"markdown-plugin",
3132
"basic-nodes-plugins",
3233
"align-plugin",
3334
"autoformat-plugin",
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"dependencies": [
3+
"@udecode/plate-markdown",
4+
"remark-gfm",
5+
"remark-math",
6+
"remark-mdx"
7+
],
8+
"files": [
9+
{
10+
"path": "components/editor/plugins/markdown-plugin.tsx",
11+
"content": "import { MarkdownPlugin, remarkMention } from '@udecode/plate-markdown';\nimport { SuggestionPlugin } from '@udecode/plate-suggestion/react';\nimport remarkGfm from 'remark-gfm';\nimport remarkMath from 'remark-math';\nimport remarkMdx from 'remark-mdx';\nexport const markdownPlugin = MarkdownPlugin.configure({\n options: {\n disallowedNodes: [SuggestionPlugin.key],\n remarkPlugins: [remarkMath, remarkGfm, remarkMdx, remarkMention],\n },\n});\n",
12+
"type": "registry:component",
13+
"target": "components/editor/plugins/markdown-plugin.tsx"
14+
}
15+
],
16+
"name": "markdown-plugin",
17+
"registryDependencies": [],
18+
"type": "registry:component",
19+
"$schema": "https://platejs.org/schema/registry-item.json",
20+
"author": "udecode (https://platejs.org)"
21+
}

apps/www/public/r/styles/default/markdown-to-slate-demo.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

apps/www/public/r/styles/default/use-chat.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

apps/www/src/__registry__/index.tsx

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1042,6 +1042,14 @@ export const Index: Record<string, any> = {
10421042
path: "src/registry/default/plate-ui/ai-menu.tsx",
10431043
type: "registry:ui",
10441044
target: ""
1045+
},{
1046+
path: "src/registry/default/plate-ui/ai-loading-bar.tsx",
1047+
type: "registry:ui",
1048+
target: ""
1049+
},{
1050+
path: "src/registry/default/plate-ui/ai-anchor-element.tsx",
1051+
type: "registry:ui",
1052+
target: ""
10451053
},{
10461054
path: "src/registry/default/plate-ui/ai-menu-items.tsx",
10471055
type: "registry:ui",
@@ -1841,7 +1849,7 @@ export const Index: Record<string, any> = {
18411849
name: "editor-plugins",
18421850
description: "",
18431851
type: "registry:component",
1844-
registryDependencies: ["ai-plugins","basic-nodes-plugins","align-plugin","autoformat-plugin","block-menu-plugins","equation-plugins","cursor-overlay-plugin","comments-plugin","delete-plugins","dnd-plugins","exit-break-plugin","indent-list-plugins","line-height-plugin","link-plugin","media-plugins","mention-plugin","reset-block-type-plugin","skip-mark-plugin","suggestion-plugin","soft-break-plugin","table-plugin","toc-plugin"],
1852+
registryDependencies: ["ai-plugins","markdown-plugin","basic-nodes-plugins","align-plugin","autoformat-plugin","block-menu-plugins","equation-plugins","cursor-overlay-plugin","comments-plugin","delete-plugins","dnd-plugins","exit-break-plugin","indent-list-plugins","line-height-plugin","link-plugin","media-plugins","mention-plugin","reset-block-type-plugin","skip-mark-plugin","suggestion-plugin","soft-break-plugin","table-plugin","toc-plugin"],
18451853
files: [{
18461854
path: "src/registry/default/components/editor/plugins/editor-plugins.tsx",
18471855
type: "registry:component",
@@ -2040,6 +2048,21 @@ export const Index: Record<string, any> = {
20402048
source: "",
20412049
meta: undefined,
20422050
},
2051+
"markdown-plugin": {
2052+
name: "markdown-plugin",
2053+
description: "",
2054+
type: "registry:component",
2055+
registryDependencies: [],
2056+
files: [{
2057+
path: "src/registry/default/components/editor/plugins/markdown-plugin.tsx",
2058+
type: "registry:component",
2059+
target: ""
2060+
}],
2061+
categories: undefined,
2062+
component: React.lazy(() => import("@/registry/default/components/editor/plugins/markdown-plugin.tsx")),
2063+
source: "",
2064+
meta: undefined,
2065+
},
20432066
"copilot-plugins": {
20442067
name: "copilot-plugins",
20452068
description: "",

apps/www/src/registry/default/components/editor/use-chat.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export const useChat = () => {
1616
apiKey: keys.openai,
1717
model: model.value,
1818
},
19+
// Mock the API response. Remove it when you implement the route /api/ai/command
1920
fetch: async (input, init) => {
2021
const res = await fetch(input, init);
2122

@@ -30,7 +31,6 @@ export const useChat = () => {
3031
isMarkdown = false;
3132
}
3233

33-
// Mock the API response. Remove it when you implement the route /api/ai/command
3434
await new Promise((resolve) => setTimeout(resolve, 400));
3535

3636
const stream = fakeStreamText({ isMarkdown });

apps/www/src/registry/registry-components.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ const plugins: Registry['items'] = [
2929
name: 'editor-plugins',
3030
registryDependencies: [
3131
'ai-plugins',
32+
'markdown-plugin',
3233
'basic-nodes-plugins',
3334
'align-plugin',
3435
'autoformat-plugin',
@@ -259,6 +260,23 @@ const plugins: Registry['items'] = [
259260
registryDependencies: ['cursor-overlay'],
260261
type: 'registry:component',
261262
},
263+
{
264+
dependencies: [
265+
'@udecode/plate-markdown',
266+
'remark-gfm',
267+
'remark-math',
268+
'remark-mdx',
269+
],
270+
files: [
271+
{
272+
path: 'components/editor/plugins/markdown-plugin.tsx',
273+
type: 'registry:component',
274+
},
275+
],
276+
name: 'markdown-plugin',
277+
registryDependencies: [],
278+
type: 'registry:component',
279+
},
262280
{
263281
dependencies: [
264282
'@udecode/plate-ai',

0 commit comments

Comments
 (0)