-
Notifications
You must be signed in to change notification settings - Fork 179
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #93 from warpy-ai/main
Push new updates
- Loading branch information
Showing
32 changed files
with
4,519 additions
and
4,097 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* eslint-disable @typescript-eslint/ban-ts-comment */ | ||
// @ts-ignore | ||
import clearPlugin from "../src/commands/clear"; | ||
import exitPlugin from "../src/commands/exit"; | ||
import chalk from "chalk"; | ||
|
||
// Force chalk to enable color output in test environment | ||
chalk.level = 1; | ||
|
||
describe("Clear Plugin", () => { | ||
let originalStdoutWrite: typeof process.stdout.write; | ||
|
||
beforeEach(() => { | ||
originalStdoutWrite = process.stdout.write; | ||
process.stdout.write = jest.fn(); | ||
}); | ||
|
||
afterEach(() => { | ||
process.stdout.write = originalStdoutWrite; | ||
}); | ||
|
||
it("should have the correct name, keyword, and description", () => { | ||
expect(clearPlugin.name).toBe("clear"); | ||
expect(clearPlugin.keyword).toBe("@clear"); | ||
expect(clearPlugin.description).toBe("Clears the terminal screen"); | ||
}); | ||
|
||
it("should clear the terminal screen when executed", async () => { | ||
const result = await clearPlugin.execute({}); | ||
expect(process.stdout.write).toHaveBeenCalledWith("\x1Bc"); | ||
expect(result).toBe("Terminal screen cleared."); | ||
}); | ||
}); | ||
|
||
describe("Exit Plugin", () => { | ||
let consoleLogSpy: jest.SpyInstance; | ||
let processExitSpy: jest.SpyInstance; | ||
|
||
beforeEach(() => { | ||
consoleLogSpy = jest.spyOn(console, "log").mockImplementation(() => {}); | ||
processExitSpy = jest | ||
.spyOn(process, "exit") | ||
.mockImplementation((code?: number) => { | ||
throw new Error(`Process.exit called with code: ${code}`); | ||
}); | ||
}); | ||
|
||
afterEach(() => { | ||
consoleLogSpy.mockRestore(); | ||
processExitSpy.mockRestore(); | ||
}); | ||
|
||
it("should have the correct name, keyword, and description", () => { | ||
expect(exitPlugin.name).toBe("exit"); | ||
expect(exitPlugin.keyword).toBe("@exit"); | ||
expect(exitPlugin.description).toBe("Exits the application"); | ||
}); | ||
|
||
it("should log goodbye message and exit the process when executed", async () => { | ||
await expect(exitPlugin.execute({})).rejects.toThrow( | ||
"Process.exit called with code: 0" | ||
); | ||
expect(consoleLogSpy).toHaveBeenCalledWith( | ||
expect.stringContaining("Goodbye!") | ||
); | ||
expect(processExitSpy).toHaveBeenCalledWith(0); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,13 @@ | ||
const clearFunc = () => { | ||
process.stdout.write("\x1Bc"); | ||
import { Plugin } from "./index"; | ||
|
||
const clearPlugin: Plugin = { | ||
name: "clear", | ||
keyword: "@clear", | ||
description: "Clears the terminal screen", | ||
execute: async () => { | ||
process.stdout.write("\x1Bc"); | ||
return "Terminal screen cleared."; | ||
}, | ||
}; | ||
|
||
export default clearFunc; | ||
export default clearPlugin; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,14 @@ | ||
import { Plugin } from "./index"; | ||
import chalk from "chalk"; | ||
|
||
const exitFunc = () => { | ||
console.log(chalk.yellow("Goodbye!")); | ||
process.exit(0); | ||
const exitPlugin: Plugin = { | ||
name: "exit", | ||
keyword: "@exit", | ||
description: "Exits the application", | ||
execute: async () => { | ||
console.log(chalk.yellow("Goodbye!")); | ||
process.exit(0); | ||
}, | ||
}; | ||
|
||
export default exitFunc; | ||
export default exitPlugin; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,39 @@ | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
import chalk from "chalk"; | ||
import { Plugin } from "./index"; | ||
import { handleFileReference } from "../handlers/fileHandler"; // Assuming this function exists | ||
import { apiKeyPrompt, promptResponse } from "../utils"; // Assuming this function exists | ||
import { promptResponse } from "../utils"; // Assuming this function exists | ||
|
||
const fileFunc = async (userInput: string) => { | ||
const creds = await apiKeyPrompt(); | ||
// we need to call file handler here | ||
const [, filePath, ...promptParts] = userInput.split(" "); | ||
const promptText = promptParts.join(" "); | ||
if (filePath) { | ||
await handleFileReference(filePath, promptText); | ||
if (creds.apiKey != null) { | ||
await promptResponse(creds.engine, creds.apiKey, userInput, {}); | ||
const filePlugin: Plugin = { | ||
name: "file", | ||
keyword: "@file", | ||
description: "Handles file operations and references", | ||
execute: async (context: { | ||
userInput: string; | ||
engine: string; | ||
apiKey: string; | ||
opts: any; | ||
}) => { | ||
const { userInput, engine, apiKey, opts } = context; | ||
const [, filePath, ...promptParts] = userInput.split(" "); | ||
const promptText = promptParts.join(" "); | ||
|
||
if (filePath) { | ||
try { | ||
await handleFileReference(filePath, promptText); | ||
const response = await promptResponse(engine, apiKey, userInput, opts); | ||
return response; | ||
} catch (error) { | ||
console.error(chalk.red(`Error handling file: ${error}`)); | ||
return `Error: ${error}`; | ||
} | ||
} else { | ||
console.log( | ||
chalk.yellow("Please provide a file path. Usage: @file <path> [prompt]") | ||
); | ||
return "Error: No file path provided"; | ||
} | ||
} else { | ||
console.log( | ||
chalk.yellow("Please provide a file path. Usage: @file <path> [prompt]") | ||
); | ||
} | ||
}, | ||
}; | ||
|
||
export default fileFunc; | ||
export default filePlugin; |
Oops, something went wrong.