Skip to content

Commit

Permalink
Feat/screen-shot (#35)
Browse files Browse the repository at this point in the history
* main(packages/qllm-cli/src/chat): handle errors in getUserInput, remove ioManager.close(), and update displaySettings message

* feat/screen-shot change the implementation and fix screenshot
  • Loading branch information
raphaelmansuy authored Aug 30, 2024
1 parent 00e5cfd commit bf738fc
Show file tree
Hide file tree
Showing 14 changed files with 652 additions and 7,033 deletions.
14 changes: 5 additions & 9 deletions packages/qllm-cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "qllm",
"version": "2.1.19",
"version": "2.2.0",
"description": "QLLM CLI: A versatile CLI tool for interacting with multiple AI/LLM providers. Features include chat sessions, one-time queries, image handling, and conversation management. Streamlines AI development with easy provider/model switching and configuration.",
"keywords": [
"ai",
Expand All @@ -23,11 +23,12 @@
"scripts": {
"build:ts": "tsc",
"build": "pnpm run build:ts",
"build:prod": "pnpm install --prod && pnpm run build:ts",
"clean": "rimraf dist tsconfig.tsbuildinfo",
"lint": "eslint . --ext .ts",
"format": "prettier --write .",
"test": "jest",
"prepublishOnly": "pnpm run build"
"prepublishOnly": "pnpm run build:prod"
},
"repository": {
"type": "git",
Expand All @@ -54,8 +55,8 @@
"@types/prompts": "^2.4.9",
"@types/screenshot-desktop": "^1.12.3",
"@types/uuid": "^10.0.0",
"@typescript-eslint/eslint-plugin": "^8.2.0",
"@typescript-eslint/parser": "^8.2.0",
"@typescript-eslint/eslint-plugin": "^8.3.0",
"@typescript-eslint/parser": "^8.3.0",
"eslint": "^9.9.1",
"jest": "^29.7.0",
"prettier": "^3.3.3",
Expand All @@ -69,16 +70,11 @@
"commander": "^12.1.0",
"console-table-printer": "^2.12.1",
"copy-paste": "^1.5.3",
"gradient-string": "^2.0.2",
"jimp": "^0.22.12",
"kleur": "^4.1.5",
"lru-cache": "^11.0.0",
"mime-types": "^2.1.35",
"nanospinner": "^1.1.0",
"prompts": "^2.4.2",
"qllm-lib": "workspace:*",
"readline": "^1.3.0",
"screenshot-desktop": "^1.15.0",
"table": "^6.8.2",
"uuid": "^10.0.0",
"zod": "^3.23.8"
Expand Down
6 changes: 5 additions & 1 deletion packages/qllm-cli/src/chat/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,11 @@ export class Chat {
await this.sendUserMessage(input, this.imageManager.getImages());
}
} catch (error) {
console.error("Error getting user input:", error);
if(error instanceof Error) {
ioManager.displayError(`Error getting user input: $error.message`);
} else {
ioManager.displayError(`Error getting user input: ${String(error)}`);
}
} finally {
// Continue prompting the user
this.promptUser();
Expand Down
1 change: 0 additions & 1 deletion packages/qllm-cli/src/chat/command-processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ export class CommandProcessor {
{ ioManager }: CommandContext
): Promise<void> {
ioManager.displaySystemMessage("Stopping chat session...");
ioManager.close();
process.exit(0);
}

Expand Down
15 changes: 13 additions & 2 deletions packages/qllm-cli/src/commands/ask-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,19 @@ async function prepareImageInputs({
const screenshotCapture = new ScreenshotCapture();
await screenshotCapture.initialize();
const screenshotBase64 =
await screenshotCapture.captureAndGetBase64(screenshot);
images.push(screenshotBase64);
await screenshotCapture.captureAndGetBase64({
interactive: false,
fullScreen: true,
windowName: undefined,
displayNumber: screenshot
})
if (!screenshotBase64) {
ioManager.displayError(
`No screenshot captured from display ${screenshot}`);
}
else {
images.push(screenshotBase64);
}
ioManager.displaySuccess(
`Screenshot captured successfully from display ${screenshot}`
);
Expand Down
2 changes: 1 addition & 1 deletion packages/qllm-cli/src/types/ask-command-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const BaseAskCommandOptionsSchema = z.object({
useClipboard: z.boolean().optional(),

/** Display number for screenshot capture */
screenshot: z.number().int().positive().optional(),
screenshot: z.number().int().optional(),
});

export const AskCommandOptionsPartialSchema = BaseAskCommandOptionsSchema.extend({
Expand Down
29 changes: 5 additions & 24 deletions packages/qllm-cli/src/utils/io-manager/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// packages/qllm-cli/src/utils/io-manager/io-manager.ts

import readline from "readline";
import kleur from "kleur";
import { getBorderCharacters, table } from "table";
import { createSpinner } from "nanospinner";
Expand All @@ -13,8 +12,8 @@ const stdout = {
},
write: (text: string) => {
process.stdout.write(text);
}
}
},
};

const stderr = {
log: (...args: any[]) => {
Expand All @@ -26,7 +25,7 @@ const stderr = {
error: (...args: any[]) => {
console.error(...args);
},
}
};

type ColorName = keyof typeof kleur;

Expand Down Expand Up @@ -115,15 +114,6 @@ class DisplayManager {
}

class InputManager {
private rl: readline.Interface;

constructor() {
this.rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
});
}

async getUserInput(prompt: string): Promise<string> {
const response = await prompts({
type: "text",
Expand All @@ -142,10 +132,6 @@ class InputManager {
});
return response.confirmed;
}

close(): void {
this.rl.close();
}
}

class SpinnerManager {
Expand Down Expand Up @@ -272,10 +258,6 @@ export class IOManager {
process.stdout.write(text);
}

close(): void {
this.input.close();
}

// Specialized display methods
displayUserMessage(message: string): void {
this.displayInfo(this.display.colorize(`You: ${message}`, "green"));
Expand Down Expand Up @@ -351,7 +333,7 @@ export class IOManager {
this.newLine();
this.displayInfo(
this.display.colorize(
"Use '/set <option> <value>' to change a setting",
"Use '/set <setting> <value>' to change a setting",
"dim"
)
);
Expand Down Expand Up @@ -400,5 +382,4 @@ export class IOManager {

// Create a singleton instance for easy access
export const ioManager = new IOManager();

export { Spinner };
export { Spinner };
109 changes: 0 additions & 109 deletions packages/qllm-cli/src/utils/screenshot.ts

This file was deleted.

Loading

0 comments on commit bf738fc

Please sign in to comment.