Skip to content

Commit f1c22cc

Browse files
authored
docs
1 parent ccf1e41 commit f1c22cc

File tree

8 files changed

+40
-14
lines changed

8 files changed

+40
-14
lines changed

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

Lines changed: 15 additions & 4 deletions
Large diffs are not rendered by default.

apps/www/public/r/ai-kit.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"files": [
1717
{
1818
"path": "src/registry/components/editor/plugins/ai-kit.tsx",
19-
"content": "'use client';\n\nimport { withAIBatch } from '@platejs/ai';\nimport {\n AIChatPlugin,\n AIPlugin,\n applyAISuggestions,\n streamInsertChunk,\n useChatChunk,\n} from '@platejs/ai/react';\nimport { getPluginType, KEYS, PathApi } from 'platejs';\nimport { usePluginOption } from 'platejs/react';\n\nimport { AILoadingBar, AIMenu } from '@/registry/ui/ai-menu';\nimport { AIAnchorElement, AILeaf } from '@/registry/ui/ai-node';\n\nimport { useChat } from '../use-chat';\nimport { CursorOverlayKit } from './cursor-overlay-kit';\nimport { MarkdownKit } from './markdown-kit';\n\nexport const aiChatPlugin = AIChatPlugin.extend({\n options: {\n chatOptions: {\n api: '/api/ai/command',\n body: {},\n },\n },\n render: {\n afterContainer: AILoadingBar,\n afterEditable: AIMenu,\n node: AIAnchorElement,\n },\n shortcuts: { show: { keys: 'mod+j' } },\n useHooks: ({ editor, getOption }) => {\n useChat();\n\n const mode = usePluginOption(AIChatPlugin, 'mode');\n const toolName = usePluginOption(AIChatPlugin, 'toolName');\n\n useChatChunk({\n onChunk: ({ chunk, isFirst, nodes, text: content }) => {\n if (isFirst && mode == 'insert') {\n editor.tf.withoutSaving(() => {\n editor.tf.insertNodes(\n {\n children: [{ text: '' }],\n type: getPluginType(editor, KEYS.aiChat),\n },\n {\n at: PathApi.next(editor.selection!.focus.path.slice(0, 1)),\n }\n );\n });\n editor.setOption(AIChatPlugin, 'streaming', true);\n }\n\n if (mode === 'insert' && nodes.length > 0) {\n withAIBatch(\n editor,\n () => {\n if (!getOption('streaming')) return;\n editor.tf.withScrolling(() => {\n streamInsertChunk(editor, chunk, {\n textProps: {\n [getPluginType(editor, KEYS.ai)]: true,\n },\n });\n });\n },\n { split: isFirst }\n );\n }\n\n if (toolName === 'edit' && mode === 'chat') {\n withAIBatch(\n editor,\n () => {\n applyAISuggestions(editor, content);\n },\n {\n split: isFirst,\n }\n );\n }\n },\n onFinish: () => {\n editor.setOption(AIChatPlugin, 'streaming', false);\n editor.setOption(AIChatPlugin, '_blockChunks', '');\n editor.setOption(AIChatPlugin, '_blockPath', null);\n editor.setOption(AIChatPlugin, '_mdxName', null);\n },\n });\n },\n});\n\nexport const AIKit = [\n ...CursorOverlayKit,\n ...MarkdownKit,\n AIPlugin.withComponent(AILeaf),\n aiChatPlugin,\n];\n",
19+
"content": "'use client';\n\nimport { withAIBatch } from '@platejs/ai';\nimport {\n AIChatPlugin,\n AIPlugin,\n applyAISuggestions,\n streamInsertChunk,\n useChatChunk,\n} from '@platejs/ai/react';\nimport { getPluginType, KEYS, PathApi } from 'platejs';\nimport { usePluginOption } from 'platejs/react';\n\nimport { AILoadingBar, AIMenu } from '@/registry/ui/ai-menu';\nimport { AIAnchorElement, AILeaf } from '@/registry/ui/ai-node';\n\nimport { useChat } from '../use-chat';\nimport { CursorOverlayKit } from './cursor-overlay-kit';\nimport { MarkdownKit } from './markdown-kit';\n\nexport const aiChatPlugin = AIChatPlugin.extend({\n options: {\n chatOptions: {\n api: '/api/ai/command',\n body: {},\n },\n },\n render: {\n afterContainer: AILoadingBar,\n afterEditable: AIMenu,\n node: AIAnchorElement,\n },\n shortcuts: { show: { keys: 'mod+j' } },\n useHooks: ({ editor, getOption }) => {\n useChat();\n\n const mode = usePluginOption(AIChatPlugin, 'mode');\n const toolName = usePluginOption(AIChatPlugin, 'toolName');\n useChatChunk({\n onChunk: ({ chunk, isFirst, nodes, text: content }) => {\n if (isFirst && mode == 'insert') {\n editor.tf.withoutSaving(() => {\n editor.tf.insertNodes(\n {\n children: [{ text: '' }],\n type: getPluginType(editor, KEYS.aiChat),\n },\n {\n at: PathApi.next(editor.selection!.focus.path.slice(0, 1)),\n }\n );\n });\n editor.setOption(AIChatPlugin, 'streaming', true);\n }\n\n if (mode === 'insert' && nodes.length > 0) {\n withAIBatch(\n editor,\n () => {\n if (!getOption('streaming')) return;\n editor.tf.withScrolling(() => {\n streamInsertChunk(editor, chunk, {\n textProps: {\n [getPluginType(editor, KEYS.ai)]: true,\n },\n });\n });\n },\n { split: isFirst }\n );\n }\n\n if (toolName === 'edit' && mode === 'chat') {\n withAIBatch(\n editor,\n () => {\n applyAISuggestions(editor, content);\n },\n {\n split: isFirst,\n }\n );\n }\n },\n onFinish: () => {\n editor.setOption(AIChatPlugin, 'streaming', false);\n editor.setOption(AIChatPlugin, '_blockChunks', '');\n editor.setOption(AIChatPlugin, '_blockPath', null);\n editor.setOption(AIChatPlugin, '_mdxName', null);\n },\n });\n },\n});\n\nexport const AIKit = [\n ...CursorOverlayKit,\n ...MarkdownKit,\n AIPlugin.withComponent(AILeaf),\n aiChatPlugin,\n];\n",
2020
"type": "registry:component"
2121
}
2222
]

apps/www/public/r/components-changelog-docs.json

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

apps/www/public/r/copilot-api.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,13 @@
33
"name": "copilot-api",
44
"type": "registry:file",
55
"dependencies": [
6-
"@ai-sdk/[email protected]",
76
87
],
98
"registryDependencies": [],
109
"files": [
1110
{
1211
"path": "src/registry/app/api/ai/copilot/route.ts",
13-
"content": "import type { NextRequest } from 'next/server';\n\nimport { createOpenAI } from '@ai-sdk/openai';\nimport { generateText } from 'ai';\nimport { NextResponse } from 'next/server';\n\nexport async function POST(req: NextRequest) {\n const {\n apiKey: key,\n model = 'gpt-4o-mini',\n prompt,\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 = await generateText({\n abortSignal: req.signal,\n maxOutputTokens: 50,\n model: openai(model),\n prompt: prompt,\n system,\n temperature: 0.7,\n });\n\n return NextResponse.json(result);\n } catch (error) {\n if (error instanceof Error && error.name === 'AbortError') {\n return NextResponse.json(null, { status: 408 });\n }\n\n return NextResponse.json(\n { error: 'Failed to process AI request' },\n { status: 500 }\n );\n }\n}\n",
12+
"content": "import type { NextRequest } from 'next/server';\n\nimport { generateText } from 'ai';\nimport { NextResponse } from 'next/server';\n\nexport async function POST(req: NextRequest) {\n const {\n apiKey: key,\n model = 'gpt-4o-mini',\n prompt,\n system,\n } = await req.json();\n\n const apiKey = key || process.env.AI_GATEWAY_API_KEY;\n\n if (!apiKey) {\n return NextResponse.json(\n { error: 'Missing ai gateway API key.' },\n { status: 401 }\n );\n }\n\n try {\n const result = await generateText({\n abortSignal: req.signal,\n maxOutputTokens: 50,\n model: `openai/${model}`,\n prompt: prompt,\n system,\n temperature: 0.7,\n });\n\n return NextResponse.json(result);\n } catch (error) {\n if (error instanceof Error && error.name === 'AbortError') {\n return NextResponse.json(null, { status: 408 });\n }\n\n return NextResponse.json(\n { error: 'Failed to process AI request' },\n { status: 500 }\n );\n }\n}\n",
1413
"type": "registry:file",
1514
"target": "app/api/ai/copilot/route.ts"
1615
}

apps/www/public/r/registry.json

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3849,9 +3849,8 @@
38493849
"type": "registry:file",
38503850
"dependencies": [
38513851
"@ai-sdk/[email protected]",
3852-
"@ai-sdk/[email protected]",
3853-
"@ai-sdk/[email protected]",
3854-
3852+
3853+
38553854
],
38563855
"registryDependencies": [
38573856
"https://platejs.org/r/copilot-api",
@@ -3862,14 +3861,23 @@
38623861
"path": "src/registry/app/api/ai/command/route.ts",
38633862
"type": "registry:file",
38643863
"target": "app/api/ai/command/route.ts"
3864+
},
3865+
{
3866+
"path": "src/registry/app/api/ai/command/utils.ts",
3867+
"type": "registry:file",
3868+
"target": "app/api/ai/command/utils.ts"
3869+
},
3870+
{
3871+
"path": "src/registry/app/api/ai/command/prompts.ts",
3872+
"type": "registry:file",
3873+
"target": "app/api/ai/command/prompts.ts"
38653874
}
38663875
]
38673876
},
38683877
{
38693878
"name": "copilot-api",
38703879
"type": "registry:file",
38713880
"dependencies": [
3872-
"@ai-sdk/[email protected]",
38733881
38743882
],
38753883
"registryDependencies": [],

0 commit comments

Comments
 (0)