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,78 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import type { ComponentProps } from 'react';
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
Collapsible,
|
|
7
|
+
CollapsibleContent,
|
|
8
|
+
CollapsibleTrigger,
|
|
9
|
+
} from '@/components/ui/collapsible';
|
|
10
|
+
import { cn } from '@/lib/utils';
|
|
11
|
+
import { BookIcon, ChevronDownIcon } from 'lucide-react';
|
|
12
|
+
|
|
13
|
+
export type SourcesProps = ComponentProps<'div'>;
|
|
14
|
+
|
|
15
|
+
export const Sources = ({ className, ...props }: SourcesProps) => (
|
|
16
|
+
<Collapsible
|
|
17
|
+
className={cn('not-prose text-primary mb-4 text-xs', className)}
|
|
18
|
+
{...props}
|
|
19
|
+
/>
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
export type SourcesTriggerProps = ComponentProps<typeof CollapsibleTrigger> & {
|
|
23
|
+
count: number;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export const SourcesTrigger = ({
|
|
27
|
+
className,
|
|
28
|
+
count,
|
|
29
|
+
children,
|
|
30
|
+
...props
|
|
31
|
+
}: SourcesTriggerProps) => (
|
|
32
|
+
<CollapsibleTrigger
|
|
33
|
+
className={cn('flex items-center gap-2', className)}
|
|
34
|
+
{...props}
|
|
35
|
+
>
|
|
36
|
+
{children ?? (
|
|
37
|
+
<>
|
|
38
|
+
<p className="font-medium">Used {count} sources</p>
|
|
39
|
+
<ChevronDownIcon className="h-4 w-4" />
|
|
40
|
+
</>
|
|
41
|
+
)}
|
|
42
|
+
</CollapsibleTrigger>
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
export type SourcesContentProps = ComponentProps<typeof CollapsibleContent>;
|
|
46
|
+
|
|
47
|
+
export const SourcesContent = ({
|
|
48
|
+
className,
|
|
49
|
+
...props
|
|
50
|
+
}: SourcesContentProps) => (
|
|
51
|
+
<CollapsibleContent
|
|
52
|
+
className={cn(
|
|
53
|
+
'mt-3 flex w-fit flex-col gap-2',
|
|
54
|
+
'data-[state=closed]:fade-out-0 data-[state=closed]:slide-out-to-top-2 data-[state=open]:slide-in-from-top-2 data-[state=closed]:animate-out data-[state=open]:animate-in outline-none',
|
|
55
|
+
className,
|
|
56
|
+
)}
|
|
57
|
+
{...props}
|
|
58
|
+
/>
|
|
59
|
+
);
|
|
60
|
+
|
|
61
|
+
export type SourceProps = ComponentProps<'a'>;
|
|
62
|
+
|
|
63
|
+
export const Source = ({ href, title, children, ...props }: SourceProps) => (
|
|
64
|
+
<a
|
|
65
|
+
className="flex items-center gap-2"
|
|
66
|
+
href={href}
|
|
67
|
+
rel="noreferrer"
|
|
68
|
+
target="_blank"
|
|
69
|
+
{...props}
|
|
70
|
+
>
|
|
71
|
+
{children ?? (
|
|
72
|
+
<>
|
|
73
|
+
<BookIcon className="h-4 w-4" />
|
|
74
|
+
<span className="block font-medium">{title}</span>
|
|
75
|
+
</>
|
|
76
|
+
)}
|
|
77
|
+
</a>
|
|
78
|
+
);
|
|
@@ -0,0 +1,324 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import type { ComponentProps } from 'react';
|
|
4
|
+
|
|
5
|
+
import { Button } from '@/components/ui/button';
|
|
6
|
+
import { Spinner } from '@/components/ui/spinner';
|
|
7
|
+
import { cn } from '@/lib/utils';
|
|
8
|
+
import { MicIcon, SquareIcon } from 'lucide-react';
|
|
9
|
+
import { useCallback, useEffect, useRef, useState } from 'react';
|
|
10
|
+
|
|
11
|
+
interface SpeechRecognition extends EventTarget {
|
|
12
|
+
continuous: boolean;
|
|
13
|
+
interimResults: boolean;
|
|
14
|
+
lang: string;
|
|
15
|
+
start(): void;
|
|
16
|
+
stop(): void;
|
|
17
|
+
onstart: ((this: SpeechRecognition, ev: Event) => void) | null;
|
|
18
|
+
onend: ((this: SpeechRecognition, ev: Event) => void) | null;
|
|
19
|
+
onresult:
|
|
20
|
+
| ((this: SpeechRecognition, ev: SpeechRecognitionEvent) => void)
|
|
21
|
+
| null;
|
|
22
|
+
onerror:
|
|
23
|
+
| ((this: SpeechRecognition, ev: SpeechRecognitionErrorEvent) => void)
|
|
24
|
+
| null;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
interface SpeechRecognitionEvent extends Event {
|
|
28
|
+
results: SpeechRecognitionResultList;
|
|
29
|
+
resultIndex: number;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
interface SpeechRecognitionResultList {
|
|
33
|
+
readonly length: number;
|
|
34
|
+
item(index: number): SpeechRecognitionResult;
|
|
35
|
+
[index: number]: SpeechRecognitionResult;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
interface SpeechRecognitionResult {
|
|
39
|
+
readonly length: number;
|
|
40
|
+
item(index: number): SpeechRecognitionAlternative;
|
|
41
|
+
[index: number]: SpeechRecognitionAlternative;
|
|
42
|
+
isFinal: boolean;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
interface SpeechRecognitionAlternative {
|
|
46
|
+
transcript: string;
|
|
47
|
+
confidence: number;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
interface SpeechRecognitionErrorEvent extends Event {
|
|
51
|
+
error: string;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
declare global {
|
|
55
|
+
interface Window {
|
|
56
|
+
SpeechRecognition: new () => SpeechRecognition;
|
|
57
|
+
webkitSpeechRecognition: new () => SpeechRecognition;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
type SpeechInputMode = 'speech-recognition' | 'media-recorder' | 'none';
|
|
62
|
+
|
|
63
|
+
export type SpeechInputProps = ComponentProps<typeof Button> & {
|
|
64
|
+
onTranscriptionChange?: (text: string) => void;
|
|
65
|
+
/**
|
|
66
|
+
* Callback for when audio is recorded using MediaRecorder fallback.
|
|
67
|
+
* This is called in browsers that don't support the Web Speech API (Firefox, Safari).
|
|
68
|
+
* The callback receives an audio Blob that should be sent to a transcription service.
|
|
69
|
+
* Return the transcribed text, which will be passed to onTranscriptionChange.
|
|
70
|
+
*/
|
|
71
|
+
onAudioRecorded?: (audioBlob: Blob) => Promise<string>;
|
|
72
|
+
lang?: string;
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
const detectSpeechInputMode = (): SpeechInputMode => {
|
|
76
|
+
if (typeof window === 'undefined') {
|
|
77
|
+
return 'none';
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if ('SpeechRecognition' in window || 'webkitSpeechRecognition' in window) {
|
|
81
|
+
return 'speech-recognition';
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
if ('MediaRecorder' in window && 'mediaDevices' in navigator) {
|
|
85
|
+
return 'media-recorder';
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
return 'none';
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
export const SpeechInput = ({
|
|
92
|
+
className,
|
|
93
|
+
onTranscriptionChange,
|
|
94
|
+
onAudioRecorded,
|
|
95
|
+
lang = 'en-US',
|
|
96
|
+
...props
|
|
97
|
+
}: SpeechInputProps) => {
|
|
98
|
+
const [isListening, setIsListening] = useState(false);
|
|
99
|
+
const [isProcessing, setIsProcessing] = useState(false);
|
|
100
|
+
const [mode] = useState<SpeechInputMode>(detectSpeechInputMode);
|
|
101
|
+
const [isRecognitionReady, setIsRecognitionReady] = useState(false);
|
|
102
|
+
const recognitionRef = useRef<SpeechRecognition | null>(null);
|
|
103
|
+
const mediaRecorderRef = useRef<MediaRecorder | null>(null);
|
|
104
|
+
const streamRef = useRef<MediaStream | null>(null);
|
|
105
|
+
const audioChunksRef = useRef<Blob[]>([]);
|
|
106
|
+
const onTranscriptionChangeRef = useRef<
|
|
107
|
+
SpeechInputProps['onTranscriptionChange']
|
|
108
|
+
>(onTranscriptionChange);
|
|
109
|
+
const onAudioRecordedRef =
|
|
110
|
+
useRef<SpeechInputProps['onAudioRecorded']>(onAudioRecorded);
|
|
111
|
+
|
|
112
|
+
// Keep refs in sync
|
|
113
|
+
onTranscriptionChangeRef.current = onTranscriptionChange;
|
|
114
|
+
onAudioRecordedRef.current = onAudioRecorded;
|
|
115
|
+
|
|
116
|
+
// Initialize Speech Recognition when mode is speech-recognition
|
|
117
|
+
useEffect(() => {
|
|
118
|
+
if (mode !== 'speech-recognition') {
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
const SpeechRecognition =
|
|
123
|
+
window.SpeechRecognition || window.webkitSpeechRecognition;
|
|
124
|
+
const speechRecognition = new SpeechRecognition();
|
|
125
|
+
|
|
126
|
+
speechRecognition.continuous = true;
|
|
127
|
+
speechRecognition.interimResults = true;
|
|
128
|
+
speechRecognition.lang = lang;
|
|
129
|
+
|
|
130
|
+
const handleStart = () => {
|
|
131
|
+
setIsListening(true);
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
const handleEnd = () => {
|
|
135
|
+
setIsListening(false);
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
const handleResult = (event: Event) => {
|
|
139
|
+
const speechEvent = event as SpeechRecognitionEvent;
|
|
140
|
+
let finalTranscript = '';
|
|
141
|
+
|
|
142
|
+
for (
|
|
143
|
+
let i = speechEvent.resultIndex;
|
|
144
|
+
i < speechEvent.results.length;
|
|
145
|
+
i += 1
|
|
146
|
+
) {
|
|
147
|
+
const result = speechEvent.results[i];
|
|
148
|
+
if (result.isFinal) {
|
|
149
|
+
finalTranscript += result[0]?.transcript ?? '';
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
if (finalTranscript) {
|
|
154
|
+
onTranscriptionChangeRef.current?.(finalTranscript);
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
const handleError = () => {
|
|
159
|
+
setIsListening(false);
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
speechRecognition.addEventListener('start', handleStart);
|
|
163
|
+
speechRecognition.addEventListener('end', handleEnd);
|
|
164
|
+
speechRecognition.addEventListener('result', handleResult);
|
|
165
|
+
speechRecognition.addEventListener('error', handleError);
|
|
166
|
+
|
|
167
|
+
recognitionRef.current = speechRecognition;
|
|
168
|
+
setIsRecognitionReady(true);
|
|
169
|
+
|
|
170
|
+
return () => {
|
|
171
|
+
speechRecognition.removeEventListener('start', handleStart);
|
|
172
|
+
speechRecognition.removeEventListener('end', handleEnd);
|
|
173
|
+
speechRecognition.removeEventListener('result', handleResult);
|
|
174
|
+
speechRecognition.removeEventListener('error', handleError);
|
|
175
|
+
speechRecognition.stop();
|
|
176
|
+
recognitionRef.current = null;
|
|
177
|
+
setIsRecognitionReady(false);
|
|
178
|
+
};
|
|
179
|
+
}, [mode, lang]);
|
|
180
|
+
|
|
181
|
+
// Cleanup MediaRecorder and stream on unmount
|
|
182
|
+
useEffect(
|
|
183
|
+
() => () => {
|
|
184
|
+
if (mediaRecorderRef.current?.state === 'recording') {
|
|
185
|
+
mediaRecorderRef.current.stop();
|
|
186
|
+
}
|
|
187
|
+
if (streamRef.current) {
|
|
188
|
+
for (const track of streamRef.current.getTracks()) {
|
|
189
|
+
track.stop();
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
},
|
|
193
|
+
[],
|
|
194
|
+
);
|
|
195
|
+
|
|
196
|
+
// Start MediaRecorder recording
|
|
197
|
+
const startMediaRecorder = useCallback(async () => {
|
|
198
|
+
if (!onAudioRecordedRef.current) {
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
try {
|
|
203
|
+
const stream = await navigator.mediaDevices.getUserMedia({ audio: true });
|
|
204
|
+
streamRef.current = stream;
|
|
205
|
+
const mediaRecorder = new MediaRecorder(stream);
|
|
206
|
+
audioChunksRef.current = [];
|
|
207
|
+
|
|
208
|
+
const handleDataAvailable = (event: BlobEvent) => {
|
|
209
|
+
if (event.data.size > 0) {
|
|
210
|
+
audioChunksRef.current.push(event.data);
|
|
211
|
+
}
|
|
212
|
+
};
|
|
213
|
+
|
|
214
|
+
const handleStop = async () => {
|
|
215
|
+
for (const track of stream.getTracks()) {
|
|
216
|
+
track.stop();
|
|
217
|
+
}
|
|
218
|
+
streamRef.current = null;
|
|
219
|
+
|
|
220
|
+
const audioBlob = new Blob(audioChunksRef.current, {
|
|
221
|
+
type: 'audio/webm',
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
if (audioBlob.size > 0 && onAudioRecordedRef.current) {
|
|
225
|
+
setIsProcessing(true);
|
|
226
|
+
try {
|
|
227
|
+
const transcript = await onAudioRecordedRef.current(audioBlob);
|
|
228
|
+
if (transcript) {
|
|
229
|
+
onTranscriptionChangeRef.current?.(transcript);
|
|
230
|
+
}
|
|
231
|
+
} catch {
|
|
232
|
+
// Error handling delegated to the onAudioRecorded caller
|
|
233
|
+
} finally {
|
|
234
|
+
setIsProcessing(false);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
};
|
|
238
|
+
|
|
239
|
+
const handleError = () => {
|
|
240
|
+
setIsListening(false);
|
|
241
|
+
for (const track of stream.getTracks()) {
|
|
242
|
+
track.stop();
|
|
243
|
+
}
|
|
244
|
+
streamRef.current = null;
|
|
245
|
+
};
|
|
246
|
+
|
|
247
|
+
mediaRecorder.addEventListener('dataavailable', handleDataAvailable);
|
|
248
|
+
mediaRecorder.addEventListener('stop', handleStop);
|
|
249
|
+
mediaRecorder.addEventListener('error', handleError);
|
|
250
|
+
|
|
251
|
+
mediaRecorderRef.current = mediaRecorder;
|
|
252
|
+
mediaRecorder.start();
|
|
253
|
+
setIsListening(true);
|
|
254
|
+
} catch {
|
|
255
|
+
setIsListening(false);
|
|
256
|
+
}
|
|
257
|
+
}, []);
|
|
258
|
+
|
|
259
|
+
// Stop MediaRecorder recording
|
|
260
|
+
const stopMediaRecorder = useCallback(() => {
|
|
261
|
+
if (mediaRecorderRef.current?.state === 'recording') {
|
|
262
|
+
mediaRecorderRef.current.stop();
|
|
263
|
+
}
|
|
264
|
+
setIsListening(false);
|
|
265
|
+
}, []);
|
|
266
|
+
|
|
267
|
+
const toggleListening = useCallback(() => {
|
|
268
|
+
if (mode === 'speech-recognition' && recognitionRef.current) {
|
|
269
|
+
if (isListening) {
|
|
270
|
+
recognitionRef.current.stop();
|
|
271
|
+
} else {
|
|
272
|
+
recognitionRef.current.start();
|
|
273
|
+
}
|
|
274
|
+
} else if (mode === 'media-recorder') {
|
|
275
|
+
if (isListening) {
|
|
276
|
+
stopMediaRecorder();
|
|
277
|
+
} else {
|
|
278
|
+
startMediaRecorder();
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
}, [mode, isListening, startMediaRecorder, stopMediaRecorder]);
|
|
282
|
+
|
|
283
|
+
// Determine if button should be disabled
|
|
284
|
+
const isDisabled =
|
|
285
|
+
mode === 'none' ||
|
|
286
|
+
(mode === 'speech-recognition' && !isRecognitionReady) ||
|
|
287
|
+
(mode === 'media-recorder' && !onAudioRecorded) ||
|
|
288
|
+
isProcessing;
|
|
289
|
+
|
|
290
|
+
return (
|
|
291
|
+
<div className="relative inline-flex items-center justify-center">
|
|
292
|
+
{/* Animated pulse rings */}
|
|
293
|
+
{isListening &&
|
|
294
|
+
[0, 1, 2].map((index) => (
|
|
295
|
+
<div
|
|
296
|
+
className="absolute inset-0 animate-ping rounded-full border-2 border-red-400/30"
|
|
297
|
+
key={index}
|
|
298
|
+
style={{
|
|
299
|
+
animationDelay: `${index * 0.3}s`,
|
|
300
|
+
animationDuration: '2s',
|
|
301
|
+
}}
|
|
302
|
+
/>
|
|
303
|
+
))}
|
|
304
|
+
|
|
305
|
+
{/* Main record button */}
|
|
306
|
+
<Button
|
|
307
|
+
className={cn(
|
|
308
|
+
'relative z-10 rounded-full transition-all duration-300',
|
|
309
|
+
isListening
|
|
310
|
+
? 'bg-destructive hover:bg-destructive/80 text-white hover:text-white'
|
|
311
|
+
: 'bg-primary text-primary-foreground hover:bg-primary/80 hover:text-primary-foreground',
|
|
312
|
+
className,
|
|
313
|
+
)}
|
|
314
|
+
disabled={isDisabled}
|
|
315
|
+
onClick={toggleListening}
|
|
316
|
+
{...props}
|
|
317
|
+
>
|
|
318
|
+
{isProcessing && <Spinner />}
|
|
319
|
+
{!isProcessing && isListening && <SquareIcon className="size-4" />}
|
|
320
|
+
{!(isProcessing || isListening) && <MicIcon className="size-4" />}
|
|
321
|
+
</Button>
|
|
322
|
+
</div>
|
|
323
|
+
);
|
|
324
|
+
};
|