create-sidekick-app 0.0.1 → 2.0.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/LICENSE.md +202 -0
- package/NOTICE +27 -0
- package/README.md +29 -2
- package/dist/index.js +59 -0
- package/package.json +65 -4
- package/template/base/ai-chat/.env.example +6 -0
- package/template/base/ai-chat/.prettierignore +2 -0
- package/template/base/ai-chat/.prettierrc.json +5 -0
- package/template/base/ai-chat/README.md +38 -0
- package/template/base/ai-chat/_gitignore +41 -0
- package/template/base/ai-chat/components.json +23 -0
- package/template/base/ai-chat/next.config.ts +5 -0
- package/template/base/ai-chat/package.json +61 -0
- package/template/base/ai-chat/postcss.config.mjs +5 -0
- package/template/base/ai-chat/src/app/api/chat/route.ts +141 -0
- package/template/base/ai-chat/src/app/api/instant/route.ts +5 -0
- package/template/base/ai-chat/src/app/chat/[id]/page.tsx +20 -0
- package/template/base/ai-chat/src/app/globals.css +124 -0
- package/template/base/ai-chat/src/app/layout.tsx +34 -0
- package/template/base/ai-chat/src/app/page.tsx +6 -0
- package/template/base/ai-chat/src/components/AuthGate.tsx +15 -0
- package/template/base/ai-chat/src/components/Chat.tsx +228 -0
- package/template/base/ai-chat/src/components/InstantProvider.tsx +18 -0
- package/template/base/ai-chat/src/components/Login.tsx +163 -0
- package/template/base/ai-chat/src/components/Sidebar.tsx +100 -0
- package/template/base/ai-chat/src/components/ai-elements/agent.tsx +142 -0
- package/template/base/ai-chat/src/components/ai-elements/artifact.tsx +149 -0
- package/template/base/ai-chat/src/components/ai-elements/attachments.tsx +427 -0
- package/template/base/ai-chat/src/components/ai-elements/audio-player.tsx +229 -0
- package/template/base/ai-chat/src/components/ai-elements/canvas.tsx +26 -0
- package/template/base/ai-chat/src/components/ai-elements/chain-of-thought.tsx +223 -0
- package/template/base/ai-chat/src/components/ai-elements/checkpoint.tsx +72 -0
- package/template/base/ai-chat/src/components/ai-elements/code-block.tsx +556 -0
- package/template/base/ai-chat/src/components/ai-elements/commit.tsx +449 -0
- package/template/base/ai-chat/src/components/ai-elements/confirmation.tsx +173 -0
- package/template/base/ai-chat/src/components/ai-elements/connection.tsx +28 -0
- package/template/base/ai-chat/src/components/ai-elements/context.tsx +410 -0
- package/template/base/ai-chat/src/components/ai-elements/controls.tsx +19 -0
- package/template/base/ai-chat/src/components/ai-elements/conversation.tsx +167 -0
- package/template/base/ai-chat/src/components/ai-elements/edge.tsx +144 -0
- package/template/base/ai-chat/src/components/ai-elements/environment-variables.tsx +325 -0
- package/template/base/ai-chat/src/components/ai-elements/file-tree.tsx +298 -0
- package/template/base/ai-chat/src/components/ai-elements/image.tsx +25 -0
- package/template/base/ai-chat/src/components/ai-elements/inline-citation.tsx +294 -0
- package/template/base/ai-chat/src/components/ai-elements/jsx-preview.tsx +250 -0
- package/template/base/ai-chat/src/components/ai-elements/message.tsx +356 -0
- package/template/base/ai-chat/src/components/ai-elements/mic-selector.tsx +372 -0
- package/template/base/ai-chat/src/components/ai-elements/model-selector.tsx +214 -0
- package/template/base/ai-chat/src/components/ai-elements/node.tsx +72 -0
- package/template/base/ai-chat/src/components/ai-elements/open-in-chat.tsx +367 -0
- package/template/base/ai-chat/src/components/ai-elements/package-info.tsx +235 -0
- package/template/base/ai-chat/src/components/ai-elements/panel.tsx +16 -0
- package/template/base/ai-chat/src/components/ai-elements/persona.tsx +280 -0
- package/template/base/ai-chat/src/components/ai-elements/plan.tsx +144 -0
- package/template/base/ai-chat/src/components/ai-elements/prompt-input.tsx +1341 -0
- package/template/base/ai-chat/src/components/ai-elements/queue.tsx +275 -0
- package/template/base/ai-chat/src/components/ai-elements/reasoning.tsx +229 -0
- package/template/base/ai-chat/src/components/ai-elements/sandbox.tsx +128 -0
- package/template/base/ai-chat/src/components/ai-elements/schema-display.tsx +473 -0
- package/template/base/ai-chat/src/components/ai-elements/shimmer.tsx +78 -0
- package/template/base/ai-chat/src/components/ai-elements/snippet.tsx +141 -0
- package/template/base/ai-chat/src/components/ai-elements/sources.tsx +78 -0
- package/template/base/ai-chat/src/components/ai-elements/speech-input.tsx +324 -0
- package/template/base/ai-chat/src/components/ai-elements/stack-trace.tsx +531 -0
- package/template/base/ai-chat/src/components/ai-elements/suggestion.tsx +55 -0
- package/template/base/ai-chat/src/components/ai-elements/task.tsx +88 -0
- package/template/base/ai-chat/src/components/ai-elements/terminal.tsx +277 -0
- package/template/base/ai-chat/src/components/ai-elements/test-results.tsx +497 -0
- package/template/base/ai-chat/src/components/ai-elements/tool.tsx +174 -0
- package/template/base/ai-chat/src/components/ai-elements/toolbar.tsx +17 -0
- package/template/base/ai-chat/src/components/ai-elements/transcription.tsx +126 -0
- package/template/base/ai-chat/src/components/ai-elements/voice-selector.tsx +525 -0
- package/template/base/ai-chat/src/components/ai-elements/web-preview.tsx +282 -0
- package/template/base/ai-chat/src/components/ui/accordion.tsx +66 -0
- package/template/base/ai-chat/src/components/ui/alert.tsx +66 -0
- package/template/base/ai-chat/src/components/ui/avatar.tsx +109 -0
- package/template/base/ai-chat/src/components/ui/badge.tsx +48 -0
- package/template/base/ai-chat/src/components/ui/button-group.tsx +83 -0
- package/template/base/ai-chat/src/components/ui/button.tsx +64 -0
- package/template/base/ai-chat/src/components/ui/card.tsx +92 -0
- package/template/base/ai-chat/src/components/ui/carousel.tsx +241 -0
- package/template/base/ai-chat/src/components/ui/collapsible.tsx +33 -0
- package/template/base/ai-chat/src/components/ui/command.tsx +184 -0
- package/template/base/ai-chat/src/components/ui/dialog.tsx +158 -0
- package/template/base/ai-chat/src/components/ui/dropdown-menu.tsx +257 -0
- package/template/base/ai-chat/src/components/ui/hover-card.tsx +44 -0
- package/template/base/ai-chat/src/components/ui/input-group.tsx +170 -0
- package/template/base/ai-chat/src/components/ui/input.tsx +21 -0
- package/template/base/ai-chat/src/components/ui/popover.tsx +89 -0
- package/template/base/ai-chat/src/components/ui/progress.tsx +31 -0
- package/template/base/ai-chat/src/components/ui/scroll-area.tsx +58 -0
- package/template/base/ai-chat/src/components/ui/select.tsx +190 -0
- package/template/base/ai-chat/src/components/ui/separator.tsx +28 -0
- package/template/base/ai-chat/src/components/ui/spinner.tsx +16 -0
- package/template/base/ai-chat/src/components/ui/switch.tsx +35 -0
- package/template/base/ai-chat/src/components/ui/tabs.tsx +91 -0
- package/template/base/ai-chat/src/components/ui/textarea.tsx +18 -0
- package/template/base/ai-chat/src/components/ui/tooltip.tsx +57 -0
- package/template/base/ai-chat/src/instant.perms.ts +34 -0
- package/template/base/ai-chat/src/instant.schema.ts +107 -0
- package/template/base/ai-chat/src/lib/adminDb.ts +8 -0
- package/template/base/ai-chat/src/lib/db.ts +8 -0
- package/template/base/ai-chat/src/lib/mockModel.ts +119 -0
- package/template/base/ai-chat/src/lib/utils.ts +6 -0
- package/template/base/ai-chat/tsconfig.json +33 -0
- package/template/base/bun-react/.env.example +2 -0
- package/template/base/bun-react/README.md +12 -0
- package/template/base/bun-react/_gitignore +34 -0
- package/template/base/bun-react/bun-env.d.ts +17 -0
- package/template/base/bun-react/bunfig.toml +4 -0
- package/template/base/bun-react/package.json +22 -0
- package/template/base/bun-react/src/App.tsx +168 -0
- package/template/base/bun-react/src/frontend.tsx +20 -0
- package/template/base/bun-react/src/getUnusedPort.ts +32 -0
- package/template/base/bun-react/src/index.css +25 -0
- package/template/base/bun-react/src/index.html +13 -0
- package/template/base/bun-react/src/index.ts +21 -0
- package/template/base/bun-react/src/instant.perms.ts +24 -0
- package/template/base/bun-react/src/instant.schema.ts +46 -0
- package/template/base/bun-react/src/lib/db.ts +8 -0
- package/template/base/bun-react/src/logo.svg +1 -0
- package/template/base/bun-react/tsconfig.json +36 -0
- package/template/base/expo/.env.example +2 -0
- package/template/base/expo/README.md +18 -0
- package/template/base/expo/_gitignore +41 -0
- package/template/base/expo/app/+not-found.tsx +16 -0
- package/template/base/expo/app/_layout.tsx +37 -0
- package/template/base/expo/app/index.tsx +64 -0
- package/template/base/expo/app.json +42 -0
- package/template/base/expo/assets/fonts/SpaceMono-Regular.ttf +0 -0
- package/template/base/expo/assets/images/adaptive-icon.png +0 -0
- package/template/base/expo/assets/images/favicon.png +0 -0
- package/template/base/expo/assets/images/icon.png +0 -0
- package/template/base/expo/assets/images/partial-react-logo.png +0 -0
- package/template/base/expo/assets/images/react-logo.png +0 -0
- package/template/base/expo/assets/images/react-logo@2x.png +0 -0
- package/template/base/expo/assets/images/react-logo@3x.png +0 -0
- package/template/base/expo/assets/images/splash-icon.png +0 -0
- package/template/base/expo/babel.config.js +12 -0
- package/template/base/expo/constants/Colors.ts +26 -0
- package/template/base/expo/eslint.config.js +10 -0
- package/template/base/expo/global.css +3 -0
- package/template/base/expo/hooks/useColorScheme.ts +1 -0
- package/template/base/expo/hooks/useColorScheme.web.ts +21 -0
- package/template/base/expo/hooks/useThemeColor.ts +21 -0
- package/template/base/expo/instant.perms.ts +24 -0
- package/template/base/expo/instant.schema.ts +44 -0
- package/template/base/expo/lib/db.ts +7 -0
- package/template/base/expo/metro.config.js +6 -0
- package/template/base/expo/nativewind-env.d.ts +1 -0
- package/template/base/expo/package.json +57 -0
- package/template/base/expo/scripts/reset-project.js +112 -0
- package/template/base/expo/tailwind.config.js +9 -0
- package/template/base/expo/tsconfig.json +18 -0
- package/template/base/next-js-app-dir/.env.example +2 -0
- package/template/base/next-js-app-dir/README.md +18 -0
- package/template/base/next-js-app-dir/_gitignore +41 -0
- package/template/base/next-js-app-dir/next.config.ts +7 -0
- package/template/base/next-js-app-dir/package.json +27 -0
- package/template/base/next-js-app-dir/postcss.config.mjs +5 -0
- package/template/base/next-js-app-dir/public/file.svg +1 -0
- package/template/base/next-js-app-dir/public/globe.svg +1 -0
- package/template/base/next-js-app-dir/public/next.svg +1 -0
- package/template/base/next-js-app-dir/public/vercel.svg +1 -0
- package/template/base/next-js-app-dir/public/window.svg +1 -0
- package/template/base/next-js-app-dir/src/app/favicon.ico +0 -0
- package/template/base/next-js-app-dir/src/app/globals.css +26 -0
- package/template/base/next-js-app-dir/src/app/layout.tsx +34 -0
- package/template/base/next-js-app-dir/src/app/page.tsx +169 -0
- package/template/base/next-js-app-dir/src/instant.perms.ts +24 -0
- package/template/base/next-js-app-dir/src/instant.schema.ts +50 -0
- package/template/base/next-js-app-dir/src/lib/db.ts +8 -0
- package/template/base/next-js-app-dir/tsconfig.json +41 -0
- package/template/base/solidjs-vite/README.md +15 -0
- package/template/base/solidjs-vite/_gitignore +25 -0
- package/template/base/solidjs-vite/index.html +15 -0
- package/template/base/solidjs-vite/package.json +25 -0
- package/template/base/solidjs-vite/src/App.tsx +171 -0
- package/template/base/solidjs-vite/src/index.css +25 -0
- package/template/base/solidjs-vite/src/index.tsx +16 -0
- package/template/base/solidjs-vite/src/instant.perms.ts +24 -0
- package/template/base/solidjs-vite/src/instant.schema.ts +46 -0
- package/template/base/solidjs-vite/src/lib/db.ts +8 -0
- package/template/base/solidjs-vite/tsconfig.json +20 -0
- package/template/base/solidjs-vite/vite.config.ts +11 -0
- package/template/base/sveltekit/README.md +15 -0
- package/template/base/sveltekit/_gitignore +26 -0
- package/template/base/sveltekit/package.json +25 -0
- package/template/base/sveltekit/src/app.css +25 -0
- package/template/base/sveltekit/src/app.html +11 -0
- package/template/base/sveltekit/src/instant.perms.ts +24 -0
- package/template/base/sveltekit/src/instant.schema.ts +46 -0
- package/template/base/sveltekit/src/lib/db.ts +8 -0
- package/template/base/sveltekit/src/routes/+layout.svelte +6 -0
- package/template/base/sveltekit/src/routes/+page.svelte +236 -0
- package/template/base/sveltekit/src/routes/+page.ts +1 -0
- package/template/base/sveltekit/svelte.config.js +10 -0
- package/template/base/sveltekit/tsconfig.json +14 -0
- package/template/base/sveltekit/vite.config.ts +7 -0
- package/template/base/tanstack-start/.cta.json +12 -0
- package/template/base/tanstack-start/README.md +17 -0
- package/template/base/tanstack-start/_gitignore +13 -0
- package/template/base/tanstack-start/package.json +43 -0
- package/template/base/tanstack-start/public/favicon.ico +0 -0
- package/template/base/tanstack-start/public/logo192.png +0 -0
- package/template/base/tanstack-start/public/logo512.png +0 -0
- package/template/base/tanstack-start/public/manifest.json +25 -0
- package/template/base/tanstack-start/public/robots.txt +3 -0
- package/template/base/tanstack-start/public/tanstack-circle-logo.png +0 -0
- package/template/base/tanstack-start/public/tanstack-word-logo-white.svg +1 -0
- package/template/base/tanstack-start/src/components/Header.tsx +21 -0
- package/template/base/tanstack-start/src/instant.perms.ts +24 -0
- package/template/base/tanstack-start/src/instant.schema.ts +50 -0
- package/template/base/tanstack-start/src/lib/adminDb.ts +12 -0
- package/template/base/tanstack-start/src/lib/db.ts +9 -0
- package/template/base/tanstack-start/src/logo.svg +12 -0
- package/template/base/tanstack-start/src/routeTree.gen.ts +104 -0
- package/template/base/tanstack-start/src/router.tsx +22 -0
- package/template/base/tanstack-start/src/routes/__root.tsx +70 -0
- package/template/base/tanstack-start/src/routes/api/instant.ts +18 -0
- package/template/base/tanstack-start/src/routes/index.tsx +238 -0
- package/template/base/tanstack-start/src/routes/login.tsx +140 -0
- package/template/base/tanstack-start/src/styles.css +18 -0
- package/template/base/tanstack-start/tsconfig.json +28 -0
- package/template/base/tanstack-start/vite.config.ts +33 -0
- package/template/base/tanstack-start-with-tanstack-query/.cta.json +12 -0
- package/template/base/tanstack-start-with-tanstack-query/README.md +18 -0
- package/template/base/tanstack-start-with-tanstack-query/_gitignore +13 -0
- package/template/base/tanstack-start-with-tanstack-query/package.json +46 -0
- package/template/base/tanstack-start-with-tanstack-query/public/favicon.ico +0 -0
- package/template/base/tanstack-start-with-tanstack-query/public/logo192.png +0 -0
- package/template/base/tanstack-start-with-tanstack-query/public/logo512.png +0 -0
- package/template/base/tanstack-start-with-tanstack-query/public/manifest.json +25 -0
- package/template/base/tanstack-start-with-tanstack-query/public/robots.txt +3 -0
- package/template/base/tanstack-start-with-tanstack-query/public/tanstack-circle-logo.png +0 -0
- package/template/base/tanstack-start-with-tanstack-query/public/tanstack-word-logo-white.svg +1 -0
- package/template/base/tanstack-start-with-tanstack-query/src/components/Header.tsx +21 -0
- package/template/base/tanstack-start-with-tanstack-query/src/instant.perms.ts +24 -0
- package/template/base/tanstack-start-with-tanstack-query/src/instant.schema.ts +50 -0
- package/template/base/tanstack-start-with-tanstack-query/src/lib/adminDb.ts +9 -0
- package/template/base/tanstack-start-with-tanstack-query/src/lib/db.ts +11 -0
- package/template/base/tanstack-start-with-tanstack-query/src/lib/instantQuery.ts +93 -0
- package/template/base/tanstack-start-with-tanstack-query/src/logo.svg +12 -0
- package/template/base/tanstack-start-with-tanstack-query/src/routeTree.gen.ts +104 -0
- package/template/base/tanstack-start-with-tanstack-query/src/router.tsx +108 -0
- package/template/base/tanstack-start-with-tanstack-query/src/routes/__root.tsx +76 -0
- package/template/base/tanstack-start-with-tanstack-query/src/routes/api/instant.ts +16 -0
- package/template/base/tanstack-start-with-tanstack-query/src/routes/index.tsx +231 -0
- package/template/base/tanstack-start-with-tanstack-query/src/routes/login.tsx +140 -0
- package/template/base/tanstack-start-with-tanstack-query/src/styles.css +17 -0
- package/template/base/tanstack-start-with-tanstack-query/tsconfig.json +28 -0
- package/template/base/tanstack-start-with-tanstack-query/vite.config.ts +33 -0
- package/template/base/vite-react/README.md +16 -0
- package/template/base/vite-react/_gitignore +26 -0
- package/template/base/vite-react/eslint.config.js +23 -0
- package/template/base/vite-react/index.html +13 -0
- package/template/base/vite-react/package.json +35 -0
- package/template/base/vite-react/public/favicon.svg +1 -0
- package/template/base/vite-react/src/App.tsx +167 -0
- package/template/base/vite-react/src/index.css +1 -0
- package/template/base/vite-react/src/instant.perms.ts +24 -0
- package/template/base/vite-react/src/instant.schema.ts +51 -0
- package/template/base/vite-react/src/lib/db.ts +8 -0
- package/template/base/vite-react/src/main.tsx +10 -0
- package/template/base/vite-react/tsconfig.app.json +25 -0
- package/template/base/vite-react/tsconfig.json +7 -0
- package/template/base/vite-react/tsconfig.node.json +24 -0
- package/template/base/vite-react/vite.config.ts +8 -0
- package/template/base/vite-vanilla/.env.example +2 -0
- package/template/base/vite-vanilla/README.md +17 -0
- package/template/base/vite-vanilla/_gitignore +25 -0
- package/template/base/vite-vanilla/index.html +13 -0
- package/template/base/vite-vanilla/package.json +20 -0
- package/template/base/vite-vanilla/pnpm-lock.yaml +707 -0
- package/template/base/vite-vanilla/public/vite.svg +1 -0
- package/template/base/vite-vanilla/src/instant.perms.ts +24 -0
- package/template/base/vite-vanilla/src/instant.schema.ts +50 -0
- package/template/base/vite-vanilla/src/lib/db.ts +11 -0
- package/template/base/vite-vanilla/src/main.ts +242 -0
- package/template/base/vite-vanilla/src/style.css +96 -0
- package/template/base/vite-vanilla/src/typescript.svg +1 -0
- package/template/base/vite-vanilla/src/vite-env.d.ts +1 -0
- package/template/base/vite-vanilla/tsconfig.json +24 -0
- package/template/base/vue-vite/README.md +15 -0
- package/template/base/vue-vite/_gitignore +43 -0
- package/template/base/vue-vite/env.d.ts +1 -0
- package/template/base/vue-vite/index.html +12 -0
- package/template/base/vue-vite/package.json +34 -0
- package/template/base/vue-vite/src/App.vue +238 -0
- package/template/base/vue-vite/src/assets/main.css +25 -0
- package/template/base/vue-vite/src/instant.perms.ts +24 -0
- package/template/base/vue-vite/src/instant.schema.ts +46 -0
- package/template/base/vue-vite/src/lib/db.ts +8 -0
- package/template/base/vue-vite/src/main.ts +6 -0
- package/template/base/vue-vite/tsconfig.app.json +15 -0
- package/template/base/vue-vite/tsconfig.json +11 -0
- package/template/base/vue-vite/tsconfig.node.json +27 -0
- package/template/base/vue-vite/vite.config.ts +16 -0
- package/template/rules/AGENTS.md +450 -0
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import { openai } from '@ai-sdk/openai';
|
|
2
|
+
import { anthropic } from '@ai-sdk/anthropic';
|
|
3
|
+
import {
|
|
4
|
+
convertToModelMessages,
|
|
5
|
+
streamText,
|
|
6
|
+
type LanguageModel,
|
|
7
|
+
type UIMessage,
|
|
8
|
+
} from 'ai';
|
|
9
|
+
import { mockModel } from '@/lib/mockModel';
|
|
10
|
+
|
|
11
|
+
function getModel(): LanguageModel {
|
|
12
|
+
if (process.env.ANTHROPIC_API_KEY) {
|
|
13
|
+
return anthropic('claude-sonnet-4-6');
|
|
14
|
+
}
|
|
15
|
+
if (process.env.OPENAI_API_KEY) {
|
|
16
|
+
return openai('gpt-4o');
|
|
17
|
+
}
|
|
18
|
+
return mockModel;
|
|
19
|
+
}
|
|
20
|
+
import { after, NextResponse } from 'next/server';
|
|
21
|
+
import { id as generateId } from '@sidekickdb/admin';
|
|
22
|
+
import { adminDb } from '@/lib/adminDb';
|
|
23
|
+
|
|
24
|
+
async function saveChat({
|
|
25
|
+
id,
|
|
26
|
+
messages,
|
|
27
|
+
activeStreamId,
|
|
28
|
+
inactiveStreamId,
|
|
29
|
+
}: {
|
|
30
|
+
id: string;
|
|
31
|
+
messages?: UIMessage[];
|
|
32
|
+
activeStreamId?: string | null;
|
|
33
|
+
inactiveStreamId?: string | null;
|
|
34
|
+
}): Promise<void> {
|
|
35
|
+
const txs: Parameters<typeof adminDb.transact>[0] = [];
|
|
36
|
+
if (activeStreamId) {
|
|
37
|
+
txs.push(adminDb.tx.chats[id].link({ stream: activeStreamId }));
|
|
38
|
+
}
|
|
39
|
+
if (inactiveStreamId) {
|
|
40
|
+
txs.push(adminDb.tx.chats[id].unlink({ stream: inactiveStreamId }));
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if (messages) {
|
|
44
|
+
for (const message of messages) {
|
|
45
|
+
txs.push(
|
|
46
|
+
adminDb.tx.messages[message.id]
|
|
47
|
+
.update({
|
|
48
|
+
role: message.role,
|
|
49
|
+
parts: message.parts,
|
|
50
|
+
metadata: message.metadata,
|
|
51
|
+
})
|
|
52
|
+
.link({ chat: id }),
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (txs.length) {
|
|
58
|
+
await adminDb.transact(txs);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export async function POST(req: Request) {
|
|
63
|
+
const {
|
|
64
|
+
message,
|
|
65
|
+
id,
|
|
66
|
+
}: {
|
|
67
|
+
message: UIMessage | undefined;
|
|
68
|
+
id: string;
|
|
69
|
+
} = await req.json();
|
|
70
|
+
|
|
71
|
+
const user = await adminDb.auth.getUserFromRequest(req);
|
|
72
|
+
if (!user) return new NextResponse(null, { status: 401 });
|
|
73
|
+
|
|
74
|
+
const { chats, messages: existingMessages } = await adminDb.query({
|
|
75
|
+
chats: {
|
|
76
|
+
$: { where: { id, owner: user.id } },
|
|
77
|
+
stream: {},
|
|
78
|
+
},
|
|
79
|
+
messages: {
|
|
80
|
+
$: {
|
|
81
|
+
where: { chat: id },
|
|
82
|
+
order: { serverCreatedAt: 'asc' },
|
|
83
|
+
},
|
|
84
|
+
},
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
const chat = chats?.[0];
|
|
88
|
+
if (!chat) return new NextResponse(null, { status: 404 });
|
|
89
|
+
if (!message) return new NextResponse(null, { status: 400 });
|
|
90
|
+
|
|
91
|
+
const history = (existingMessages || []) as UIMessage[];
|
|
92
|
+
const messages = [...history, message];
|
|
93
|
+
|
|
94
|
+
// Set the chat title from the first user message
|
|
95
|
+
if (!chat.title && message.role === 'user') {
|
|
96
|
+
const text = message.parts
|
|
97
|
+
?.filter((p: { type: string }) => p.type === 'text')
|
|
98
|
+
.map((p: { type: string; text?: string }) => p.text)
|
|
99
|
+
.join('');
|
|
100
|
+
if (text) {
|
|
101
|
+
await adminDb.transact(
|
|
102
|
+
adminDb.tx.chats[id].update({ title: text.slice(0, 60) }),
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// Save the new user message and clear any stale active stream
|
|
108
|
+
await saveChat({
|
|
109
|
+
id,
|
|
110
|
+
messages: [message],
|
|
111
|
+
inactiveStreamId: chat.stream?.id,
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
const result = streamText({
|
|
115
|
+
model: getModel(),
|
|
116
|
+
messages: await convertToModelMessages(messages),
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
return result.toUIMessageStreamResponse({
|
|
120
|
+
originalMessages: messages,
|
|
121
|
+
generateMessageId: generateId,
|
|
122
|
+
onFinish: ({ messages: finalMessages }) => {
|
|
123
|
+
// Save completion
|
|
124
|
+
saveChat({ id, messages: finalMessages });
|
|
125
|
+
},
|
|
126
|
+
async consumeSseStream({ stream }) {
|
|
127
|
+
const writeStream = adminDb.streams.createWriteStream({
|
|
128
|
+
clientId: generateId(),
|
|
129
|
+
waitUntil: after,
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
stream.pipeTo(writeStream).catch((err) => {
|
|
133
|
+
console.error('Failed to pipe SSE stream', err);
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
// Link the stream to the chat so the client can find it
|
|
137
|
+
const streamId = await writeStream.streamId();
|
|
138
|
+
await saveChat({ id, activeStreamId: streamId });
|
|
139
|
+
},
|
|
140
|
+
});
|
|
141
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Chat } from '@/components/Chat';
|
|
2
|
+
import { Sidebar } from '@/components/Sidebar';
|
|
3
|
+
|
|
4
|
+
export default async function ChatPage({
|
|
5
|
+
params,
|
|
6
|
+
}: {
|
|
7
|
+
params: Promise<{ id: string }>;
|
|
8
|
+
}) {
|
|
9
|
+
const { id } = await params;
|
|
10
|
+
return (
|
|
11
|
+
<div className="mx-auto flex h-screen w-full max-w-5xl p-4">
|
|
12
|
+
<div className="flex h-full w-full overflow-hidden rounded-lg border border-gray-200">
|
|
13
|
+
<Sidebar />
|
|
14
|
+
<div className="flex min-h-0 min-w-0 flex-1 flex-col">
|
|
15
|
+
<Chat id={id} />
|
|
16
|
+
</div>
|
|
17
|
+
</div>
|
|
18
|
+
</div>
|
|
19
|
+
);
|
|
20
|
+
}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
@import 'tailwindcss';
|
|
2
|
+
@import "tw-animate-css";
|
|
3
|
+
@import "shadcn/tailwind.css";
|
|
4
|
+
|
|
5
|
+
@custom-variant dark (&:is(.dark *));
|
|
6
|
+
|
|
7
|
+
@theme inline {
|
|
8
|
+
--radius-sm: calc(var(--radius) - 4px);
|
|
9
|
+
--radius-md: calc(var(--radius) - 2px);
|
|
10
|
+
--radius-lg: var(--radius);
|
|
11
|
+
--radius-xl: calc(var(--radius) + 4px);
|
|
12
|
+
--radius-2xl: calc(var(--radius) + 8px);
|
|
13
|
+
--radius-3xl: calc(var(--radius) + 12px);
|
|
14
|
+
--radius-4xl: calc(var(--radius) + 16px);
|
|
15
|
+
--color-background: var(--background);
|
|
16
|
+
--color-foreground: var(--foreground);
|
|
17
|
+
--color-card: var(--card);
|
|
18
|
+
--color-card-foreground: var(--card-foreground);
|
|
19
|
+
--color-popover: var(--popover);
|
|
20
|
+
--color-popover-foreground: var(--popover-foreground);
|
|
21
|
+
--color-primary: var(--primary);
|
|
22
|
+
--color-primary-foreground: var(--primary-foreground);
|
|
23
|
+
--color-secondary: var(--secondary);
|
|
24
|
+
--color-secondary-foreground: var(--secondary-foreground);
|
|
25
|
+
--color-muted: var(--muted);
|
|
26
|
+
--color-muted-foreground: var(--muted-foreground);
|
|
27
|
+
--color-accent: var(--accent);
|
|
28
|
+
--color-accent-foreground: var(--accent-foreground);
|
|
29
|
+
--color-destructive: var(--destructive);
|
|
30
|
+
--color-border: var(--border);
|
|
31
|
+
--color-input: var(--input);
|
|
32
|
+
--color-ring: var(--ring);
|
|
33
|
+
--color-chart-1: var(--chart-1);
|
|
34
|
+
--color-chart-2: var(--chart-2);
|
|
35
|
+
--color-chart-3: var(--chart-3);
|
|
36
|
+
--color-chart-4: var(--chart-4);
|
|
37
|
+
--color-chart-5: var(--chart-5);
|
|
38
|
+
--color-sidebar: var(--sidebar);
|
|
39
|
+
--color-sidebar-foreground: var(--sidebar-foreground);
|
|
40
|
+
--color-sidebar-primary: var(--sidebar-primary);
|
|
41
|
+
--color-sidebar-primary-foreground: var(--sidebar-primary-foreground);
|
|
42
|
+
--color-sidebar-accent: var(--sidebar-accent);
|
|
43
|
+
--color-sidebar-accent-foreground: var(--sidebar-accent-foreground);
|
|
44
|
+
--color-sidebar-border: var(--sidebar-border);
|
|
45
|
+
--color-sidebar-ring: var(--sidebar-ring);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
:root {
|
|
49
|
+
--radius: 0.625rem;
|
|
50
|
+
--background: oklch(1 0 0);
|
|
51
|
+
--foreground: oklch(0.145 0 0);
|
|
52
|
+
--card: oklch(1 0 0);
|
|
53
|
+
--card-foreground: oklch(0.145 0 0);
|
|
54
|
+
--popover: oklch(1 0 0);
|
|
55
|
+
--popover-foreground: oklch(0.145 0 0);
|
|
56
|
+
--primary: oklch(0.205 0 0);
|
|
57
|
+
--primary-foreground: oklch(0.985 0 0);
|
|
58
|
+
--secondary: oklch(0.97 0 0);
|
|
59
|
+
--secondary-foreground: oklch(0.205 0 0);
|
|
60
|
+
--muted: oklch(0.97 0 0);
|
|
61
|
+
--muted-foreground: oklch(0.556 0 0);
|
|
62
|
+
--accent: oklch(0.97 0 0);
|
|
63
|
+
--accent-foreground: oklch(0.205 0 0);
|
|
64
|
+
--destructive: oklch(0.577 0.245 27.325);
|
|
65
|
+
--border: oklch(0.922 0 0);
|
|
66
|
+
--input: oklch(0.922 0 0);
|
|
67
|
+
--ring: oklch(0.708 0 0);
|
|
68
|
+
--chart-1: oklch(0.646 0.222 41.116);
|
|
69
|
+
--chart-2: oklch(0.6 0.118 184.704);
|
|
70
|
+
--chart-3: oklch(0.398 0.07 227.392);
|
|
71
|
+
--chart-4: oklch(0.828 0.189 84.429);
|
|
72
|
+
--chart-5: oklch(0.769 0.188 70.08);
|
|
73
|
+
--sidebar: oklch(0.985 0 0);
|
|
74
|
+
--sidebar-foreground: oklch(0.145 0 0);
|
|
75
|
+
--sidebar-primary: oklch(0.205 0 0);
|
|
76
|
+
--sidebar-primary-foreground: oklch(0.985 0 0);
|
|
77
|
+
--sidebar-accent: oklch(0.97 0 0);
|
|
78
|
+
--sidebar-accent-foreground: oklch(0.205 0 0);
|
|
79
|
+
--sidebar-border: oklch(0.922 0 0);
|
|
80
|
+
--sidebar-ring: oklch(0.708 0 0);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
.dark {
|
|
84
|
+
--background: oklch(0.145 0 0);
|
|
85
|
+
--foreground: oklch(0.985 0 0);
|
|
86
|
+
--card: oklch(0.205 0 0);
|
|
87
|
+
--card-foreground: oklch(0.985 0 0);
|
|
88
|
+
--popover: oklch(0.205 0 0);
|
|
89
|
+
--popover-foreground: oklch(0.985 0 0);
|
|
90
|
+
--primary: oklch(0.922 0 0);
|
|
91
|
+
--primary-foreground: oklch(0.205 0 0);
|
|
92
|
+
--secondary: oklch(0.269 0 0);
|
|
93
|
+
--secondary-foreground: oklch(0.985 0 0);
|
|
94
|
+
--muted: oklch(0.269 0 0);
|
|
95
|
+
--muted-foreground: oklch(0.708 0 0);
|
|
96
|
+
--accent: oklch(0.269 0 0);
|
|
97
|
+
--accent-foreground: oklch(0.985 0 0);
|
|
98
|
+
--destructive: oklch(0.704 0.191 22.216);
|
|
99
|
+
--border: oklch(1 0 0 / 10%);
|
|
100
|
+
--input: oklch(1 0 0 / 15%);
|
|
101
|
+
--ring: oklch(0.556 0 0);
|
|
102
|
+
--chart-1: oklch(0.488 0.243 264.376);
|
|
103
|
+
--chart-2: oklch(0.696 0.17 162.48);
|
|
104
|
+
--chart-3: oklch(0.769 0.188 70.08);
|
|
105
|
+
--chart-4: oklch(0.627 0.265 303.9);
|
|
106
|
+
--chart-5: oklch(0.645 0.246 16.439);
|
|
107
|
+
--sidebar: oklch(0.205 0 0);
|
|
108
|
+
--sidebar-foreground: oklch(0.985 0 0);
|
|
109
|
+
--sidebar-primary: oklch(0.488 0.243 264.376);
|
|
110
|
+
--sidebar-primary-foreground: oklch(0.985 0 0);
|
|
111
|
+
--sidebar-accent: oklch(0.269 0 0);
|
|
112
|
+
--sidebar-accent-foreground: oklch(0.985 0 0);
|
|
113
|
+
--sidebar-border: oklch(1 0 0 / 10%);
|
|
114
|
+
--sidebar-ring: oklch(0.556 0 0);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
@layer base {
|
|
118
|
+
* {
|
|
119
|
+
@apply border-border outline-ring/50;
|
|
120
|
+
}
|
|
121
|
+
body {
|
|
122
|
+
@apply bg-background text-foreground;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { Metadata } from 'next';
|
|
2
|
+
import './globals.css';
|
|
3
|
+
import { InstantProvider } from '@/components/InstantProvider';
|
|
4
|
+
import { AuthGate } from '@/components/AuthGate';
|
|
5
|
+
import { TooltipProvider } from '@/components/ui/tooltip';
|
|
6
|
+
import { getUnverifiedUserFromInstantCookie } from '@sidekickdb/react/nextjs';
|
|
7
|
+
|
|
8
|
+
export const metadata: Metadata = {
|
|
9
|
+
title: 'AI Chat with SidekickDB Streams',
|
|
10
|
+
description:
|
|
11
|
+
'Resumable AI chat using SidekickDB Streams and the Vercel AI SDK',
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export default async function RootLayout({
|
|
15
|
+
children,
|
|
16
|
+
}: {
|
|
17
|
+
children: React.ReactNode;
|
|
18
|
+
}) {
|
|
19
|
+
const user = await getUnverifiedUserFromInstantCookie(
|
|
20
|
+
process.env.NEXT_PUBLIC_INSTANT_APP_ID!,
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
return (
|
|
24
|
+
<html lang="en">
|
|
25
|
+
<body>
|
|
26
|
+
<InstantProvider user={user}>
|
|
27
|
+
<TooltipProvider>
|
|
28
|
+
<AuthGate>{children}</AuthGate>
|
|
29
|
+
</TooltipProvider>
|
|
30
|
+
</InstantProvider>
|
|
31
|
+
</body>
|
|
32
|
+
</html>
|
|
33
|
+
);
|
|
34
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { db } from '@/lib/db';
|
|
4
|
+
import { Login } from '@/components/Login';
|
|
5
|
+
|
|
6
|
+
export function AuthGate({ children }: { children: React.ReactNode }) {
|
|
7
|
+
return (
|
|
8
|
+
<>
|
|
9
|
+
<db.SignedIn>{children}</db.SignedIn>
|
|
10
|
+
<db.SignedOut>
|
|
11
|
+
<Login />
|
|
12
|
+
</db.SignedOut>
|
|
13
|
+
</>
|
|
14
|
+
);
|
|
15
|
+
}
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import React, { useState, useMemo, useEffect, useRef } from 'react';
|
|
4
|
+
import { useChat } from '@ai-sdk/react';
|
|
5
|
+
import { DefaultChatTransport, type UIMessage, type UIMessageChunk } from 'ai';
|
|
6
|
+
import { db } from '@/lib/db';
|
|
7
|
+
import { id as generateId } from '@sidekickdb/react';
|
|
8
|
+
import {
|
|
9
|
+
Conversation,
|
|
10
|
+
ConversationContent,
|
|
11
|
+
ConversationEmptyState,
|
|
12
|
+
} from '@/components/ai-elements/conversation';
|
|
13
|
+
import {
|
|
14
|
+
Message,
|
|
15
|
+
MessageContent,
|
|
16
|
+
MessageResponse,
|
|
17
|
+
} from '@/components/ai-elements/message';
|
|
18
|
+
import {
|
|
19
|
+
PromptInput,
|
|
20
|
+
PromptInputTextarea,
|
|
21
|
+
PromptInputFooter,
|
|
22
|
+
PromptInputSubmit,
|
|
23
|
+
} from '@/components/ai-elements/prompt-input';
|
|
24
|
+
|
|
25
|
+
function getMessageText(message: UIMessage): string {
|
|
26
|
+
return message.parts
|
|
27
|
+
.filter((p): p is { type: 'text'; text: string } => p.type === 'text')
|
|
28
|
+
.map((p) => p.text)
|
|
29
|
+
.join('');
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
class InstantChatTransport extends DefaultChatTransport<UIMessage> {
|
|
33
|
+
async reconnectToStream(
|
|
34
|
+
options: { chatId: string } & Record<string, unknown>,
|
|
35
|
+
): Promise<ReadableStream<UIMessageChunk> | null> {
|
|
36
|
+
const { data } = await db.queryOnce({
|
|
37
|
+
$streams: { $: { where: { chat: options.chatId } } },
|
|
38
|
+
});
|
|
39
|
+
const $stream = data.$streams?.[0];
|
|
40
|
+
if (!$stream) return null;
|
|
41
|
+
|
|
42
|
+
const readStream = db.streams.createReadStream({ streamId: $stream.id });
|
|
43
|
+
const byteStream = readStream.pipeThrough(new TextEncoderStream());
|
|
44
|
+
|
|
45
|
+
return this.processResponseStream(byteStream);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function ChatInner({
|
|
50
|
+
id,
|
|
51
|
+
initialMessages,
|
|
52
|
+
}: {
|
|
53
|
+
id: string;
|
|
54
|
+
initialMessages: UIMessage[];
|
|
55
|
+
}) {
|
|
56
|
+
const [input, setInput] = useState('');
|
|
57
|
+
const [error, setError] = useState<string | null>(null);
|
|
58
|
+
|
|
59
|
+
const transport = useMemo(
|
|
60
|
+
() =>
|
|
61
|
+
new InstantChatTransport({
|
|
62
|
+
api: '/api/chat',
|
|
63
|
+
// Send the id of the chat and the last message
|
|
64
|
+
prepareSendMessagesRequest: ({
|
|
65
|
+
id,
|
|
66
|
+
messages,
|
|
67
|
+
}: {
|
|
68
|
+
id: string;
|
|
69
|
+
messages: UIMessage[];
|
|
70
|
+
}) => {
|
|
71
|
+
return {
|
|
72
|
+
body: {
|
|
73
|
+
id,
|
|
74
|
+
message: messages[messages.length - 1],
|
|
75
|
+
},
|
|
76
|
+
};
|
|
77
|
+
},
|
|
78
|
+
}),
|
|
79
|
+
[],
|
|
80
|
+
);
|
|
81
|
+
|
|
82
|
+
const { messages, sendMessage, status } = useChat({
|
|
83
|
+
id,
|
|
84
|
+
generateId,
|
|
85
|
+
messages: initialMessages,
|
|
86
|
+
resume: true,
|
|
87
|
+
transport,
|
|
88
|
+
onError: (e) => setError(e.message || 'Something went wrong'),
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
const isLoading = status === 'streaming' || status === 'submitted';
|
|
92
|
+
|
|
93
|
+
return (
|
|
94
|
+
<div className="flex min-h-0 flex-1 flex-col">
|
|
95
|
+
<Conversation>
|
|
96
|
+
<ConversationContent>
|
|
97
|
+
{messages.length === 0 ? (
|
|
98
|
+
<ConversationEmptyState
|
|
99
|
+
title="Start a conversation"
|
|
100
|
+
description="Type a message below to begin"
|
|
101
|
+
/>
|
|
102
|
+
) : (
|
|
103
|
+
messages.map((message) => (
|
|
104
|
+
<Message key={message.id} from={message.role}>
|
|
105
|
+
<MessageContent>
|
|
106
|
+
{message.role === 'assistant' ? (
|
|
107
|
+
<MessageResponse>{getMessageText(message)}</MessageResponse>
|
|
108
|
+
) : (
|
|
109
|
+
getMessageText(message)
|
|
110
|
+
)}
|
|
111
|
+
</MessageContent>
|
|
112
|
+
</Message>
|
|
113
|
+
))
|
|
114
|
+
)}
|
|
115
|
+
</ConversationContent>
|
|
116
|
+
</Conversation>
|
|
117
|
+
{error && (
|
|
118
|
+
<div className="flex items-center justify-between border-b border-red-200 bg-red-50 px-4 py-2 text-xs text-red-500">
|
|
119
|
+
<span>{error}</span>
|
|
120
|
+
<button
|
|
121
|
+
onClick={() => setError(null)}
|
|
122
|
+
className="cursor-pointer font-bold hover:text-red-700"
|
|
123
|
+
>
|
|
124
|
+
Dismiss
|
|
125
|
+
</button>
|
|
126
|
+
</div>
|
|
127
|
+
)}
|
|
128
|
+
<div className="border-t p-4">
|
|
129
|
+
<PromptInput
|
|
130
|
+
onSubmit={(message) => {
|
|
131
|
+
if (message.text) {
|
|
132
|
+
sendMessage({
|
|
133
|
+
role: 'user',
|
|
134
|
+
parts: [{ type: 'text', text: message.text }],
|
|
135
|
+
});
|
|
136
|
+
setInput('');
|
|
137
|
+
}
|
|
138
|
+
}}
|
|
139
|
+
>
|
|
140
|
+
<PromptInputTextarea
|
|
141
|
+
autoFocus
|
|
142
|
+
value={input}
|
|
143
|
+
onChange={(e) => setInput(e.target.value)}
|
|
144
|
+
placeholder="Type a message..."
|
|
145
|
+
/>
|
|
146
|
+
<PromptInputFooter className="justify-end">
|
|
147
|
+
<PromptInputSubmit status={status} disabled={isLoading} />
|
|
148
|
+
</PromptInputFooter>
|
|
149
|
+
</PromptInput>
|
|
150
|
+
</div>
|
|
151
|
+
</div>
|
|
152
|
+
);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
export function Chat({ id }: { id: string }) {
|
|
156
|
+
const {
|
|
157
|
+
isLoading: isLoadingData,
|
|
158
|
+
error: queryError,
|
|
159
|
+
data,
|
|
160
|
+
} = db.useQuery({
|
|
161
|
+
chats: { $: { where: { id } } },
|
|
162
|
+
messages: {
|
|
163
|
+
$: {
|
|
164
|
+
where: { chat: id },
|
|
165
|
+
order: { serverCreatedAt: 'asc' },
|
|
166
|
+
},
|
|
167
|
+
},
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
const { isLoading: isLoadingUser, error: authError, user } = db.useAuth();
|
|
171
|
+
|
|
172
|
+
const [createError, setCreateError] = useState<string | null>(null);
|
|
173
|
+
const error = queryError || authError;
|
|
174
|
+
const isLoading = isLoadingUser || isLoadingData;
|
|
175
|
+
const createdChatId = useRef<string | null>(null);
|
|
176
|
+
|
|
177
|
+
// Insert the chat into the db if it doesn't already exist.
|
|
178
|
+
useEffect(() => {
|
|
179
|
+
if (
|
|
180
|
+
!isLoading &&
|
|
181
|
+
!error &&
|
|
182
|
+
!data?.chats?.[0] &&
|
|
183
|
+
user?.id &&
|
|
184
|
+
createdChatId.current !== id
|
|
185
|
+
) {
|
|
186
|
+
createdChatId.current = id;
|
|
187
|
+
db.transact(db.tx.chats[id].update({}).link({ owner: user.id })).catch(
|
|
188
|
+
(err) => setCreateError(err.message || 'Failed to create chat'),
|
|
189
|
+
);
|
|
190
|
+
}
|
|
191
|
+
}, [isLoading, error, user?.id, data?.chats, id]);
|
|
192
|
+
|
|
193
|
+
if (createError) {
|
|
194
|
+
return (
|
|
195
|
+
<div className="flex flex-1 items-center justify-center text-sm text-red-500">
|
|
196
|
+
{createError}
|
|
197
|
+
</div>
|
|
198
|
+
);
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
if (isLoading) {
|
|
202
|
+
return (
|
|
203
|
+
<div className="flex flex-1 items-center justify-center text-sm text-gray-400">
|
|
204
|
+
Loading...
|
|
205
|
+
</div>
|
|
206
|
+
);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
if (error) {
|
|
210
|
+
return (
|
|
211
|
+
<div className="flex flex-1 items-center justify-center text-sm text-red-500">
|
|
212
|
+
{error.message}
|
|
213
|
+
</div>
|
|
214
|
+
);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
if (!user) {
|
|
218
|
+
return (
|
|
219
|
+
<div className="flex flex-1 items-center justify-center text-sm text-gray-400">
|
|
220
|
+
Please log in to continue.
|
|
221
|
+
</div>
|
|
222
|
+
);
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
const messages = (data?.messages || []) as UIMessage[];
|
|
226
|
+
|
|
227
|
+
return <ChatInner id={id} initialMessages={messages} />;
|
|
228
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { db } from '@/lib/db';
|
|
4
|
+
import { type User } from '@sidekickdb/react';
|
|
5
|
+
import { InstantSuspenseProvider } from '@sidekickdb/react/nextjs';
|
|
6
|
+
import React from 'react';
|
|
7
|
+
|
|
8
|
+
export const InstantProvider = ({
|
|
9
|
+
children,
|
|
10
|
+
user,
|
|
11
|
+
}: {
|
|
12
|
+
children: React.ReactNode;
|
|
13
|
+
user: User | null;
|
|
14
|
+
}) => (
|
|
15
|
+
<InstantSuspenseProvider user={user} db={db}>
|
|
16
|
+
{children}
|
|
17
|
+
</InstantSuspenseProvider>
|
|
18
|
+
);
|