MCPcopy Create free account
hub / github.com/Stevenic/codepilot / Codepilot

Class Codepilot

src/Codepilot.ts:11–150  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

9 * The main class for the Codepilot application.
10 */
11export class Codepilot {
12 private readonly _index: CodeIndex;
13 private readonly _functions: Map<string, FunctionEntry> = new Map();
14
15 /**
16 * Creates a new `Codepilot` instance.
17 * @param index The code index to use.
18 */
19 public constructor(index: CodeIndex) {
20 this._index = index;
21 }
22
23 /**
24 * Gets the code index.
25 */
26 public get index(): CodeIndex {
27 return this._index;
28 }
29
30 /**
31 * Registers a new function to be used in the chat completion.
32 * @remarks
33 * This is used to add new capabilities to Codepilot's chat feature
34 * @param name The name of the function.
35 * @param schema The schema of the function.
36 * @param fn The function to be executed.
37 */
38 public addFunction<TArgs = Record<string, any>>(schema: ChatCompletionFunction, fn: (args: TArgs) => Promise<any>): this {
39 this._functions.set(schema.name, { schema, fn });
40 return this;
41 }
42
43 /**
44 * Starts the chat session and listens for user input.
45 */
46 public async chat(): Promise<void> {
47 // Create a readline interface object with the standard input and output streams
48 const rl = readline.createInterface({
49 input: process.stdin,
50 output: process.stdout
51 });
52
53 // Create model and wave
54 const model = this.createModel();
55 const wave = new AlphaWave({
56 model,
57 prompt: new Prompt([
58 new SystemMessage([
59 `You are an expert software developer.`,
60 `You are chatting with another developer who is asking for help with the project they're working on.`,
61 ].join('\n')),
62 new SourceCodeSection(this._index, 0.6),
63 new ConversationHistory('history', 0.4),
64 new UserMessage('{{$input}}', 500)
65 ])
66 });
67
68 // Define main chat loop

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected