This works like this
./web - nextjs app router includes everything to related to user accounts
./web/app/api/(new-ai) containts all the ai related functions
./plugin - obsidian plugin
in the ./plugin use this values inside of tailwind classes like so
example:
text[--text-error]
- three plans
- self-hosted (no license key)
- lifetime (license key that also acts as api key with selfhostingurl)
- subscription (license key that also acts as api key)
here's the list of variables you can use:
--accent-h: 258;
--accent-s: 88%;
--accent-l: 66%;
--background-primary: var(--color-base-00);
--background-primary-alt: var(--color-base-10);
--background-secondary: var(--color-base-20);
--background-modifier-hover: rgba(var(--mono-rgb-100), 0.075);
--background-modifier-active-hover: hsla(var(--interactive-accent-hsl), 0.15);
--background-modifier-border: var(--color-base-30);
--background-modifier-border-hover: var(--color-base-35);
--background-modifier-border-focus: var(--color-base-40);
--background-modifier-error-rgb: var(--color-red-rgb);
--background-modifier-error: var(--color-red);
--background-modifier-error-hover: var(--color-red);
--background-modifier-success-rgb: var(--color-green-rgb);
--background-modifier-success: var(--color-green);
--background-modifier-message: rgba(0, 0, 0, 0.9);
--background-modifier-form-field: var(--color-base-00);
--text-normal: var(--color-base-100);
--text-muted: var(--color-base-70);
--text-faint: var(--color-base-50);
--text-on-accent: white;
--text-on-accent-inverted: black;
--text-error: var(--color-red);
--text-warning: var(--color-orange);
--text-success: var(--color-green);
--text-selection: hsla(var(--color-accent-hsl), 0.2);
--text-highlight-bg-rgb: 255, 208, 0;
--text-highlight-bg: rgba(var(--text-highlight-bg-rgb), 0.4);
--text-accent: var(--color-accent);
--text-accent-hover: var(--color-accent-2);
--interactive-normal: var(--color-base-00);
--interactive-hover: var(--color-base-10);
--interactive-accent-hsl: var(--color-accent-hsl);
--interactive-accent: var(--color-accent-1);
--interactive-accent-hover: var(--color-accent-2);
• Access to shadcn/ui components library.
• Prioritize: Ease of Use > Aesthetics > Performance.
• Use Tailwind CSS for utility-first styling.
Recommended Libraries and Tools:
1. State Management:
• React Context API for simple state needs.
• Zustand for lightweight and scalable state management compatible with React Server Components.
2. Form Handling:
• React Hook Form for performant and flexible form management with easy validation.
3. Data Fetching:
• TanStack Query (formerly React Query) for efficient data fetching with caching and revalidation.
4. Authentication:
• Implement authentication using Clerk.
5. Animations:
• Framer Motion for smooth animations and transitions.
6. Icons:
• Use Lucide React for a collection of beautiful open-source icons.
AI Integration with Vercel AI SDK:
• Utilize the Vercel AI SDK, a TypeScript toolkit for building AI-powered applications with frameworks like React and Next.js.
• Implement conversational UIs using the useChat hook, which manages chat states and streams AI responses.
Using Tools with useChat and streamText:
• Types of Tools:
• Automatically executed server-side tools.
• Automatically executed client-side tools.
• User-interactive tools requiring confirmation dialogs.
• Workflow:
1. User inputs a message in the chat UI.
2. Message is sent to the API route.
3. Language model generates tool calls via streamText.
4. Tool calls are forwarded to the client.
5. Server-side tools execute and return results to the client.
6. Client-side tools auto-execute using the onToolCall callback.
7. Interactive tools display in the UI, results managed via toolInvocations.
8. After interactions, use addToolResult to include the result in the chat.
9. If tool calls exist in the last message and all results are available, the client resends messages to the server for further processing.
• Note: Set maxSteps to a value greater than 1 in useChat options to enable multiple iterations (default is disabled for compatibility).
Example Implementation:
• API Route (app/api/chat/route.ts):
import { openai } from '@ai-sdk/openai';
import { streamText } from 'ai';
import { z } from 'zod';
// Allow streaming responses up to 30 seconds
export const maxDuration = 30;
export async function POST(req: Request) {
const { messages } = await req.json();
const result = await streamText({
model: openai('gpt-4o'),
messages,
tools: {
// Server-side tool with execute function:
getWeatherInformation: {
description: 'Show the weather in a given city to the user.',
parameters: z.object({ city: z.string() }),
execute: async ({ city }: { city: string }) => {
const weatherOptions = ['sunny', 'cloudy', 'rainy', 'snowy', 'windy'];
return `${city} is currently ${weatherOptions[Math.floor(Math.random() * weatherOptions.length)]}.`;
},
},
// Client-side tool initiating user interaction:
askForConfirmation: {
description: 'Ask the user for confirmation.',
parameters: z.object({
message: z.string().describe('The message to ask for confirmation.'),
}),
},
// Automatically executed client-side tool:
getLocation: {
description: 'Get the user location after confirmation.',
parameters: z.object({}),
},
},
});
return result.toDataStreamResponse();
}
• Client-Side Page (app/page.tsx):
'use client';
import { ToolInvocation } from 'ai';
import { Message, useChat } from 'ai/react';
import { pipeline } from 'stream'
import { PlaySquareIcon } from 'lucide-react'
export default function Chat() {
const {
messages,
input,
handleInputChange,
handleSubmit,
addToolResult,
} = useChat({
maxSteps: 5,
// Handle automatically executed client-side tools:
async onToolCall({ toolCall }) {
if (toolCall.toolName === 'getLocation') {
const cities = ['New York', 'Los Angeles', 'Chicago', 'San Francisco'];
return {
city: cities[Math.floor(Math.random() * cities.length)],
};
}
},
});
return (
<>
{messages?.map((m: Message) => (
<div key={m.id}>
<strong>{m.role}:</strong> {m.content}
{m.toolInvocations?.map((toolInvocation: ToolInvocation) => {
const toolCallId = toolInvocation.toolCallId;
const addResult = (result: string) =>
addToolResult({ toolCallId, result });
// Render confirmation tool (client-side with user interaction)
if (toolInvocation.toolName === 'askForConfirmation') {
return (
<div key={toolCallId}>
{toolInvocation.args.message}
<div>
{'result' in toolInvocation ? (
<b>{toolInvocation.result}</b>
) : (
<>
<button onClick={() => addResult('Yes')}>Yes</button>
<button onClick={() => addResult('No')}>No</button>
</>
)}
</div>
</div>
);
}
// Display results of other tools
return 'result' in toolInvocation ? (
<div key={toolCallId}>
<em>Tool ({toolInvocation.toolName}):</em> {toolInvocation.result}
</div>
) : (
<div key={toolCallId}>
<em>Executing {toolInvocation.toolName}...</em>
</div>
);
})}
<br />
</div>
))}
<form onSubmit={handleSubmit}>
<input value={input} onChange={handleInputChange} placeholder="Type your message..." />
</form>
</>
);
}
Additional Notes:
• Ensure all tool invocations are properly managed to maintain a seamless user experience.
• Regularly update dependencies and libraries to their latest versions for improved performance and security.
• Test the chatbot thoroughly to handle edge cases and unexpected user inputs.
This revised prompt organizes the information more clearly, making it easier to understand and follow. It highlights key project guidelines, structures, and code examples, providing a comprehensive overview for anyone involved in the development process.
## pipeline
We have an inbox that processes files.
The process happens in these steps:
- preprocess : trim content | check if we support file type | check if we have a license
- extract (ai): extract text from file, we have a function in the plugin/index.ts for that
- classify (ai): classify the file, we have a function in the plugin/index.ts for that
- tag (ai): tag the file, we have a function in the plugin/index.ts for that
- format (ai): format the file, we have a function in the plugin/index.ts for that
- move: move the file to the correct folder, we have a function in the plugin/index.ts for that
each step should be logged in the record manager, and we should record the start and end of each step.
all the ai steps are two folds one api call to get the llm recommendations
and one call to apply the recommendation. add tag after tagging , move file after folder recommendation, rename file after naming
when you classify apply a tag to the document there's append tag funciton on plugin
only format if 1. there's a classification 2. there's no tag with the classification presetn