generated from obsidianmd/obsidian-sample-plugin
-
-
Notifications
You must be signed in to change notification settings - Fork 62
/
Copy path.cursorrules
412 lines (322 loc) · 13.5 KB
/
.cursorrules
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
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:
- 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-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-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
# Tool Calling
Tools are objects that can be invoked by the model to perform specific tasks. AI SDK Core tools consist of three key elements:
1. **Description**: Optional. Describes the tool's purpose and influences when it is selected.
2. **Parameters**: A Zod schema or JSON schema that defines the tool's parameters. Used to validate tool calls.
3. **Execute**: An optional async function that processes tool calls and returns a result of type `RESULT`.
## Defining Tools
Use the `tool` helper function to define tools:
```javascript
import { z } from 'zod';
import { generateText, tool } from 'ai';
const result = await generateText({
model: yourModel,
tools: {
weather: tool({
description: 'Get the weather in a location',
parameters: z.object({
location: z.string().describe('The location to get the weather for'),
}),
execute: async ({ location }) => ({
location,
temperature: 72 + Math.floor(Math.random() * 21) - 10,
}),
}),
},
prompt: 'What is the weather in San Francisco?',
});
When a tool is used, the process is called a tool call, and its output is the tool result.
Multi-Step Calls
Enable multi-step calls with the maxSteps setting in generateText or streamText. Each step can include a text generation or tool call, looping until no further calls are needed or the maximum number of steps is reached.
Example
import { z } from 'zod';
import { generateText, tool } from 'ai';
const { text, steps } = await generateText({
model: yourModel,
tools: {
weather: tool({
description: 'Get the weather in a location',
parameters: z.object({
location: z.string().describe('The location to get the weather for'),
}),
execute: async ({ location }) => ({
location,
temperature: 72 + Math.floor(Math.random() * 21) - 10,
}),
}),
},
maxSteps: 5,
prompt: 'What is the weather in San Francisco?',
});
Accessing Steps
Retrieve intermediate tool calls and results using the steps property:
const allToolCalls = steps.flatMap(step => step.toolCalls);
onStepFinish Callback
Use onStepFinish to execute logic after each step:
const result = await generateText({
onStepFinish({ text, toolCalls, toolResults }) {
// Save chat history or log usage
},
});
Tool Choice
Control tool selection with the toolChoice setting:
• auto (default): Model decides when and which tool to use.
• required: Model must call a tool.
• none: Model must not use tools.
• { type: 'tool', toolName: string }: Model must call the specified tool.
Example
const result = await generateText({
tools: {
weather: tool({
description: 'Get the weather in a location',
parameters: z.object({ location: z.string() }),
execute: async ({ location }) => ({ location, temperature: 72 }),
}),
},
toolChoice: 'required',
prompt: 'What is the weather in San Francisco?',
});
Error Handling
AI SDK handles the following tool-call errors:
1. NoSuchToolError: Tool not defined in the tools object.
2. InvalidToolArgumentsError: Invalid arguments for the tool’s parameters.
3. ToolExecutionError: Error during tool execution.
Handling Errors
try {
const result = await generateText({
// ...
});
} catch (error) {
if (NoSuchToolError.isInstance(error)) {
// Handle missing tool
} else if (InvalidToolArgumentsError.isInstance(error)) {
// Handle invalid arguments
} else if (ToolExecutionError.isInstance(error)) {
// Handle execution error
}
}
Tool Call Repair
Use experimental_repairToolCall to attempt repairs for invalid tool calls:
const result = await generateText({
experimental_repairToolCall: async ({ toolCall, parameterSchema }) => {
// Repair logic here
},
});
Active Tools
Limit active tools using experimental_activeTools:
const { text } = await generateText({
tools: myToolSet,
experimental_activeTools: ['firstTool'],
});
Types
Ensure type safety with helper types:
import { CoreToolCallUnion, CoreToolResultUnion } from 'ai';
type MyToolCall = CoreToolCallUnion<typeof myToolSet>;
type MyToolResult = CoreToolResultUnion<typeof myToolSet>;