mirror of
https://github.com/jackwener/OpenCLI.git
synced 2026-09-14 18:25:42 +08:00
c42b040af4
* Rename chatgpt adapters: desktop → chatgpt-app, web → chatgpt Aligns with existing `-app` suffix convention (discord-app, doubao-app): - clis/chatgpt/ (desktop, AppleScript) → clis/chatgpt-app/ - clis/chatgptweb/ (browser, chatgpt.com) → clis/chatgpt/ - electron-apps.ts: chatgpt → chatgpt-app - Updated all docs and README references Closes #283 * Fix review findings: update cli-manifest.json and skill docs - cli-manifest.json: update site/modulePath/sourceFile from chatgpt to chatgpt-app - skills/opencli-usage/desktop.md: update commands from chatgpt to chatgpt-app
53 lines
2.0 KiB
JavaScript
53 lines
2.0 KiB
JavaScript
import { execSync, spawnSync } from 'node:child_process';
|
|
import { cli, Strategy } from '@jackwener/opencli/registry';
|
|
import { getErrorMessage } from '@jackwener/opencli/errors';
|
|
import { activateChatGPT, selectModel, MODEL_CHOICES } from './ax.js';
|
|
export const sendCommand = cli({
|
|
site: 'chatgpt-app',
|
|
name: 'send',
|
|
description: 'Send a message to the active ChatGPT Desktop App window',
|
|
domain: 'localhost',
|
|
strategy: Strategy.PUBLIC,
|
|
browser: false,
|
|
args: [
|
|
{ name: 'text', required: true, positional: true, help: 'Message to send' },
|
|
{ name: 'model', required: false, help: 'Model/mode to use: auto, instant, thinking, 5.2-instant, 5.2-thinking', choices: MODEL_CHOICES },
|
|
],
|
|
columns: ['Status'],
|
|
func: async (page, kwargs) => {
|
|
const text = kwargs.text;
|
|
const model = kwargs.model;
|
|
try {
|
|
// Switch model before sending if requested
|
|
if (model) {
|
|
activateChatGPT();
|
|
selectModel(model);
|
|
}
|
|
// Backup current clipboard content
|
|
let clipBackup = '';
|
|
try {
|
|
clipBackup = execSync('pbpaste', { encoding: 'utf-8' });
|
|
}
|
|
catch { /* clipboard may be empty */ }
|
|
// Copy text to clipboard
|
|
spawnSync('pbcopy', { input: text });
|
|
activateChatGPT();
|
|
const cmd = "osascript " +
|
|
"-e 'tell application \"System Events\"' " +
|
|
"-e 'keystroke \"v\" using command down' " +
|
|
"-e 'delay 0.2' " +
|
|
"-e 'keystroke return' " +
|
|
"-e 'end tell'";
|
|
execSync(cmd);
|
|
// Restore original clipboard content
|
|
if (clipBackup) {
|
|
spawnSync('pbcopy', { input: clipBackup });
|
|
}
|
|
return [{ Status: 'Success' }];
|
|
}
|
|
catch (err) {
|
|
return [{ Status: "Error: " + getErrorMessage(err) }];
|
|
}
|
|
},
|
|
});
|