| 1 | import { IDE } from ".."; |
| 2 | import { joinPathsToUri } from "../util/uri"; |
| 3 | |
| 4 | const DEFAULT_ASSISTANT_FILE = `# This is an example assistant configuration file |
| 5 | # It is used to define custom AI assistants within Continue |
| 6 | # Each assistant file can be accessed by selecting it from the assistant dropdown |
| 7 | |
| 8 | # To learn more, see the full assistant reference: https://docs.continue.dev/reference |
| 9 | |
| 10 | name: Example Assistant |
| 11 | version: 1.0.0 |
| 12 | schema: v1 |
| 13 | |
| 14 | # Models define which AI models this assistant can use |
| 15 | models: |
| 16 | - name: my gpt-5 |
| 17 | provider: openai |
| 18 | model: gpt-5 |
| 19 | apiKey: YOUR_API_KEY_HERE |
| 20 | |
| 21 | # Context providers define what information the assistant can access |
| 22 | context: |
| 23 | - provider: code |
| 24 | - provider: docs |
| 25 | - provider: diff |
| 26 | - provider: terminal |
| 27 | - provider: problems |
| 28 | - provider: folder |
| 29 | - provider: codebase |
| 30 | `; |
| 31 | |
| 32 | export async function createNewAssistantFile( |
| 33 | ide: IDE, |
| 34 | assistantPath: string | undefined, |
| 35 | ): Promise<void> { |
| 36 | const workspaceDirs = await ide.getWorkspaceDirs(); |
| 37 | if (workspaceDirs.length === 0) { |
| 38 | throw new Error( |
| 39 | "No workspace directories found. Make sure you've opened a folder in your IDE.", |
| 40 | ); |
| 41 | } |
| 42 | |
| 43 | const baseDirUri = joinPathsToUri( |
| 44 | workspaceDirs[0], |
| 45 | assistantPath ?? ".continue/assistants", |
| 46 | ); |
| 47 | |
| 48 | // Find the first available filename |
| 49 | let counter = 0; |
| 50 | let assistantFileUri: string; |
| 51 | do { |
| 52 | const suffix = counter === 0 ? "" : `-${counter}`; |
| 53 | assistantFileUri = joinPathsToUri( |
| 54 | baseDirUri, |
| 55 | `new-assistant${suffix}.yaml`, |
| 56 | ); |
| 57 | counter++; |
| 58 | } while (await ide.fileExists(assistantFileUri)); |
| 59 | |
| 60 | await ide.writeFile(assistantFileUri, DEFAULT_ASSISTANT_FILE); |
| 61 | await ide.openFile(assistantFileUri); |
| 62 | } |