@agent-smith/cli 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. package/dist/agent.d.ts +15 -0
  2. package/dist/agent.js +47 -0
  3. package/dist/cli.d.ts +2 -0
  4. package/dist/cli.js +44 -0
  5. package/dist/cmd/cmds.d.ts +7 -0
  6. package/dist/cmd/cmds.js +205 -0
  7. package/dist/cmd/lib/execute_action.d.ts +2 -0
  8. package/dist/cmd/lib/execute_action.js +58 -0
  9. package/dist/cmd/lib/execute_job.d.ts +6 -0
  10. package/dist/cmd/lib/execute_job.js +86 -0
  11. package/dist/cmd/lib/execute_task.d.ts +2 -0
  12. package/dist/cmd/lib/execute_task.js +28 -0
  13. package/dist/cmd/lib/utils.d.ts +4 -0
  14. package/dist/cmd/lib/utils.js +44 -0
  15. package/dist/cmd/options/modes.d.ts +3 -0
  16. package/dist/cmd/options/modes.js +58 -0
  17. package/dist/cmd/sys/clipboard.d.ts +3 -0
  18. package/dist/cmd/sys/clipboard.js +17 -0
  19. package/dist/cmd/sys/execute.d.ts +13 -0
  20. package/dist/cmd/sys/execute.js +44 -0
  21. package/dist/cmd/sys/read_cmds.d.ts +3 -0
  22. package/dist/cmd/sys/read_cmds.js +26 -0
  23. package/dist/cmd/sys/read_conf.d.ts +6 -0
  24. package/dist/cmd/sys/read_conf.js +11 -0
  25. package/dist/cmd/sys/read_features.d.ts +3 -0
  26. package/dist/cmd/sys/read_features.js +83 -0
  27. package/dist/cmd/sys/read_yml_action.d.ts +5 -0
  28. package/dist/cmd/sys/read_yml_action.js +11 -0
  29. package/dist/cmd/sys/run_python.d.ts +3 -0
  30. package/dist/cmd/sys/run_python.js +43 -0
  31. package/dist/conf.d.ts +4 -0
  32. package/dist/conf.js +12 -0
  33. package/dist/db/db.d.ts +5 -0
  34. package/dist/db/db.js +16 -0
  35. package/dist/db/read.d.ts +9 -0
  36. package/dist/db/read.js +53 -0
  37. package/dist/db/schemas.d.ts +2 -0
  38. package/dist/db/schemas.js +42 -0
  39. package/dist/db/write.d.ts +6 -0
  40. package/dist/db/write.js +56 -0
  41. package/dist/index.d.ts +2 -0
  42. package/dist/index.js +25 -0
  43. package/dist/interfaces.d.ts +49 -0
  44. package/dist/interfaces.js +1 -0
  45. package/dist/main.d.ts +5 -0
  46. package/dist/main.js +5 -0
  47. package/dist/state/features.d.ts +8 -0
  48. package/dist/state/features.js +29 -0
  49. package/dist/state/plugins.d.ts +6 -0
  50. package/dist/state/plugins.js +24 -0
  51. package/dist/state/state.d.ts +15 -0
  52. package/dist/state/state.js +39 -0
  53. package/package.json +60 -0
@@ -0,0 +1,15 @@
1
+ import { marked } from 'marked';
2
+ import { RunMode } from "./interfaces.js";
3
+ declare let brain: import("@agent-smith/brain").AgentBrain;
4
+ declare const modelsForExpert: Record<string, string>;
5
+ declare const taskReader: {
6
+ init: (taskPath: string) => import("@agent-smith/jobs").AgentTask;
7
+ read: (taskPath: string) => {
8
+ found: boolean;
9
+ task: import("@agent-smith/lmtask").LmTask;
10
+ };
11
+ readDir: (dir: string) => Array<string>;
12
+ };
13
+ declare function clearOutput(): void;
14
+ declare function initAgent(mode: RunMode, isVerbose?: boolean): Promise<boolean>;
15
+ export { brain, initAgent, clearOutput, marked, modelsForExpert, taskReader };
package/dist/agent.js ADDED
@@ -0,0 +1,47 @@
1
+ import { useAgentBrain } from "@agent-smith/brain";
2
+ import { useLmTask } from "@agent-smith/lmtask";
3
+ import logUpdate from 'log-update';
4
+ import { marked } from 'marked';
5
+ import { markedTerminal } from 'marked-terminal';
6
+ import { formatMode } from "./state/state.js";
7
+ marked.use(markedTerminal());
8
+ let brain = useAgentBrain();
9
+ const modelsForExpert = {};
10
+ const taskReader = useLmTask(brain);
11
+ async function initExperts() {
12
+ brain.experts.forEach((ex) => {
13
+ ex.setOnStartEmit(() => console.log("Start emitting"));
14
+ ex.setOnToken((t) => {
15
+ if (formatMode.value == "markdown") {
16
+ logUpdate(marked.parse(ex.stream.get() + t).trim());
17
+ }
18
+ else {
19
+ logUpdate((ex.stream.get() + t).trim());
20
+ }
21
+ });
22
+ });
23
+ }
24
+ function clearOutput() {
25
+ logUpdate.clear();
26
+ }
27
+ async function initAgent(mode, isVerbose = false) {
28
+ if (!brain.state.get().isOn) {
29
+ brain.resetExperts();
30
+ await brain.discoverLocal();
31
+ await initExperts();
32
+ await brain.expertsForModelsInfo();
33
+ }
34
+ const brainUp = brain.state.get().isOn;
35
+ if (isVerbose) {
36
+ if (!brainUp) {
37
+ console.log("❌ No experts found for inference");
38
+ }
39
+ else {
40
+ brain.experts.forEach((ex) => {
41
+ console.log(`✅ Expert ${ex.name} is up`);
42
+ });
43
+ }
44
+ }
45
+ return brainUp;
46
+ }
47
+ export { brain, initAgent, clearOutput, marked, modelsForExpert, taskReader };
package/dist/cli.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ declare function query(_default?: string): Promise<void>;
2
+ export { query };
package/dist/cli.js ADDED
@@ -0,0 +1,44 @@
1
+ import { input } from '@inquirer/prompts';
2
+ import { runCmd } from './cmd/cmds.js';
3
+ import { lastCmd, inputMode } from './state/state.js';
4
+ import { readPromptFile } from './cmd/lib/utils.js';
5
+ import { readClipboard } from './cmd/sys/clipboard.js';
6
+ function parseParams(params) {
7
+ const regex = /"([^"]*)"|(\S+)/g;
8
+ let match;
9
+ const result = new Array();
10
+ while ((match = regex.exec(params)) !== null) {
11
+ if (match[1]) {
12
+ result.push(match[1]);
13
+ }
14
+ else {
15
+ result.push(match[2]);
16
+ }
17
+ }
18
+ return result;
19
+ }
20
+ async function dispatch(input) {
21
+ let buf = new Array();
22
+ buf = parseParams(input);
23
+ const cmd = buf.shift();
24
+ if (inputMode.value == "promptfile") {
25
+ const p = readPromptFile();
26
+ buf.push(p);
27
+ }
28
+ else if (inputMode.value == "clipboard") {
29
+ const p = await readClipboard();
30
+ buf.push(p);
31
+ }
32
+ await runCmd(cmd, buf);
33
+ }
34
+ async function query(_default) {
35
+ const data = { message: '>', default: "" };
36
+ if (_default) {
37
+ data.default = _default;
38
+ }
39
+ const answer = await input(data);
40
+ await dispatch(answer);
41
+ const lc = lastCmd.name + " " + lastCmd.args.join(" ");
42
+ await query(lc);
43
+ }
44
+ export { query };
@@ -0,0 +1,7 @@
1
+ import { Command } from "@commander-js/extra-typings";
2
+ declare function initCmds(): Promise<void>;
3
+ declare function runCmd(cmdName: string, args?: Array<string>): Promise<void>;
4
+ declare function pingCmd(args: Array<string> | undefined, options: any): Promise<boolean>;
5
+ declare function buildCmds(): Promise<Command>;
6
+ declare function parseCmd(): Promise<void>;
7
+ export { initCmds, runCmd, buildCmds, parseCmd, pingCmd };
@@ -0,0 +1,205 @@
1
+ import { Command } from "@commander-js/extra-typings";
2
+ import { formatMode, initFeatures, lastCmd, runMode } from "../state/state.js";
3
+ import { modes } from "./options/modes.js";
4
+ import { executeTaskCmd } from "./lib/execute_task.js";
5
+ import { clearOutput, initAgent, marked, taskReader } from "../agent.js";
6
+ import { executeActionCmd } from "./lib/execute_action.js";
7
+ import { executeJobCmd, readJob } from "./lib/execute_job.js";
8
+ import { readCmds } from "./sys/read_cmds.js";
9
+ import { processOutput, setOptions } from "./lib/utils.js";
10
+ import { getFeatureSpec, readFeaturesDirs } from "../state/features.js";
11
+ import { readFeatures } from "../db/read.js";
12
+ import { insertFeaturesPathIfNotExists, insertPluginIfNotExists, updateFeatures } from "../db/write.js";
13
+ import { readConf } from "./sys/read_conf.js";
14
+ import { buildPluginsPaths } from "../state/plugins.js";
15
+ let cmds = {
16
+ q: {
17
+ cmd: async () => process.exit(0),
18
+ description: "exit the cli"
19
+ },
20
+ ping: {
21
+ cmd: async () => pingCmd(["verbose"], undefined),
22
+ description: "ping inference servers",
23
+ },
24
+ lt: {
25
+ cmd: _listTasksCmd,
26
+ description: "list all the tasks"
27
+ },
28
+ rt: {
29
+ cmd: _readTaskCmd,
30
+ description: "read a task",
31
+ args: "arguments: \n-task (required): the task name"
32
+ },
33
+ rj: {
34
+ cmd: _readJobCmd,
35
+ description: "read a job",
36
+ args: "arguments: \n-job (required): the job name"
37
+ },
38
+ t: {
39
+ cmd: _executeTaskCmd,
40
+ description: "execute a task",
41
+ args: "arguments: \n-task (required): the task name\n-args: prompt and other arguments if any for the task"
42
+ },
43
+ j: {
44
+ cmd: _executeJobCmd,
45
+ description: "execute a job",
46
+ args: "arguments: \n-job (required): the job name\n-args: arguments if any for the job"
47
+ },
48
+ a: {
49
+ cmd: executeActionCmd,
50
+ description: "execute an action",
51
+ args: "arguments: \n-action (required): the task name\n-args: other arguments if any for the action"
52
+ },
53
+ conf: {
54
+ cmd: _updateConfCmd,
55
+ description: "process config file",
56
+ args: "arguments: \n-path (required): the path to the config.yml file"
57
+ },
58
+ update: {
59
+ cmd: _updateFeaturesCmd,
60
+ description: "reparse the features dirs and update the list",
61
+ }
62
+ };
63
+ let cliCmds = { ...cmds, ...modes };
64
+ async function initCmds() {
65
+ for (const dirpath of new Set(Object.values(readFeatures().cmd))) {
66
+ const c = await readCmds(`${dirpath}`);
67
+ cmds = { ...cmds, ...c };
68
+ }
69
+ cliCmds = { ...cmds, ...modes };
70
+ }
71
+ async function _updateFeaturesCmd(args = [], options) {
72
+ await initFeatures();
73
+ console.log("Features updated");
74
+ }
75
+ async function _updateConfCmd(args = [], options) {
76
+ if (args.length == 0) {
77
+ console.warn("Provide a config.yml file path");
78
+ return;
79
+ }
80
+ const { found, data } = readConf(args[0]);
81
+ if (!found) {
82
+ console.warn(`Config file ${args[0]} not found`);
83
+ }
84
+ const p = new Array();
85
+ if ("features" in data) {
86
+ p.push(...data.features);
87
+ const fts = new Array();
88
+ data.features.forEach((f) => {
89
+ if (!fts.includes(f)) {
90
+ insertFeaturesPathIfNotExists(f);
91
+ fts.push(f);
92
+ }
93
+ });
94
+ }
95
+ if ("plugins" in data) {
96
+ const plugins = await buildPluginsPaths(data.plugins);
97
+ plugins.forEach((_pl) => {
98
+ p.push(_pl.path);
99
+ insertPluginIfNotExists(_pl.name, _pl.path);
100
+ });
101
+ }
102
+ const feats = readFeaturesDirs(p);
103
+ updateFeatures(feats);
104
+ }
105
+ async function _readJobCmd(args = [], options) {
106
+ if (args.length == 0) {
107
+ console.warn("Provide a job name");
108
+ return;
109
+ }
110
+ const t = await readJob(args[0]);
111
+ console.log(t.data);
112
+ }
113
+ async function _executeTaskCmd(args = [], options) {
114
+ if (args.length == 0) {
115
+ console.warn("Provide a task name");
116
+ return;
117
+ }
118
+ const { ok, data, error } = await executeTaskCmd(args);
119
+ if (!ok) {
120
+ console.warn(error);
121
+ }
122
+ clearOutput();
123
+ if (formatMode.value == "markdown") {
124
+ console.log(marked.parse(data).trim());
125
+ }
126
+ else {
127
+ console.log(data);
128
+ }
129
+ return data;
130
+ }
131
+ async function _executeJobCmd(args = [], options) {
132
+ if (args.length == 0) {
133
+ console.warn("Provide a job name");
134
+ return;
135
+ }
136
+ const name = args.shift();
137
+ const t = await executeJobCmd(name, args);
138
+ }
139
+ async function _readTaskCmd(args = [], options) {
140
+ if (args.length == 0) {
141
+ console.warn("Provide a task name");
142
+ return;
143
+ }
144
+ const { found, path } = getFeatureSpec(args[0], "task");
145
+ if (!found) {
146
+ console.warn(`FeatureType ${args[0]} not found`);
147
+ return;
148
+ }
149
+ const r = taskReader.read(path);
150
+ console.log(r.task);
151
+ }
152
+ async function _listTasksCmd(args = [], options) {
153
+ Object.keys(readFeatures().task).forEach((t) => console.log("-", t));
154
+ }
155
+ async function runCmd(cmdName, args = []) {
156
+ if (!(cmdName in cliCmds)) {
157
+ console.log(`Command ${cmdName} not found`);
158
+ return;
159
+ }
160
+ const cmd = cliCmds[cmdName].cmd;
161
+ await cmd(args, {});
162
+ lastCmd.name = cmdName;
163
+ lastCmd.args = args;
164
+ }
165
+ async function pingCmd(args = [], options) {
166
+ let _isVerbose = false;
167
+ if (args.length > 0) {
168
+ _isVerbose = args[0] == "verbose";
169
+ }
170
+ const isUp = await initAgent(runMode.value, _isVerbose);
171
+ return isUp;
172
+ }
173
+ async function buildCmds() {
174
+ const program = new Command();
175
+ for (const [name, spec] of Object.entries(cmds)) {
176
+ const cmd = program.command(name);
177
+ const _cmd = async (args = [], options = {}) => {
178
+ const _args = await setOptions(options, args);
179
+ const res = await spec.cmd(_args, options);
180
+ await processOutput(res);
181
+ return res;
182
+ };
183
+ if ("args" in spec) {
184
+ cmd
185
+ .argument("<args...>", spec.args)
186
+ .description(spec.description)
187
+ .action(_cmd);
188
+ }
189
+ else {
190
+ cmd
191
+ .argument("[args...]", "No arguments")
192
+ .description(spec.description)
193
+ .action(_cmd);
194
+ }
195
+ for (const [_name, _spec] of Object.entries(modes)) {
196
+ cmd.option(_name, _spec.description);
197
+ }
198
+ }
199
+ return program;
200
+ }
201
+ async function parseCmd() {
202
+ const program = await buildCmds();
203
+ await program.parseAsync();
204
+ }
205
+ export { initCmds, runCmd, buildCmds, parseCmd, pingCmd };
@@ -0,0 +1,2 @@
1
+ declare function executeActionCmd(args?: Array<string>, options?: any, quiet?: boolean): Promise<any>;
2
+ export { executeActionCmd };
@@ -0,0 +1,58 @@
1
+ import { useAgentTask } from "@agent-smith/jobs";
2
+ import { getFeatureSpec } from '../../state/features.js';
3
+ import { readYmlAction } from "../sys/read_yml_action.js";
4
+ import { execute } from "../sys/execute.js";
5
+ import { runPyScript } from "../sys/run_python.js";
6
+ import { pyShell } from "../../state/state.js";
7
+ function _systemAction(path) {
8
+ const action = useAgentTask({
9
+ id: "system_action",
10
+ title: "",
11
+ run: async (args) => {
12
+ const actionSpec = readYmlAction(path);
13
+ const out = await execute(actionSpec.data.cmd, [...actionSpec.data.args, ...args]);
14
+ return { data: out, error: "", ok: true };
15
+ }
16
+ });
17
+ return action;
18
+ }
19
+ function _pythonAction(path) {
20
+ const action = useAgentTask({
21
+ id: "python_action",
22
+ title: "",
23
+ run: async (args) => {
24
+ const out = await runPyScript(pyShell, "python3", path, args);
25
+ return { data: out[0], error: "", ok: true };
26
+ }
27
+ });
28
+ return action;
29
+ }
30
+ async function executeActionCmd(args = [], options = {}, quiet = false) {
31
+ const name = args.shift();
32
+ const { found, path, ext } = getFeatureSpec(name, "action");
33
+ if (!found) {
34
+ return { ok: false, data: {}, error: "FeatureType not found" };
35
+ }
36
+ let act;
37
+ switch (ext) {
38
+ case "js":
39
+ const { action } = await import(path);
40
+ act = action;
41
+ break;
42
+ case "yml":
43
+ act = _systemAction(path);
44
+ break;
45
+ case "py":
46
+ act = _pythonAction(path);
47
+ break;
48
+ default:
49
+ throw new Error(`Action ext ${ext} not implemented`);
50
+ break;
51
+ }
52
+ const res = await act.run(args);
53
+ if (!quiet) {
54
+ console.log(res.data);
55
+ }
56
+ return { ok: true, data: res.data, error: "" };
57
+ }
58
+ export { executeActionCmd };
@@ -0,0 +1,6 @@
1
+ declare function executeJobCmd(name: string, args?: Array<any>): Promise<"" | Record<string, any>>;
2
+ declare function readJob(name: string): Promise<{
3
+ found: boolean;
4
+ data: Record<string, any>;
5
+ }>;
6
+ export { readJob, executeJobCmd };
@@ -0,0 +1,86 @@
1
+ import YAML from 'yaml';
2
+ import { default as fs } from "fs";
3
+ import { useAgentJob } from "@agent-smith/jobs";
4
+ import { brain, taskReader } from '../../agent.js';
5
+ import { getFeatureSpec } from '../../state/features.js';
6
+ async function executeJobCmd(name, args = []) {
7
+ const { job, found } = await _dispatchReadJob(name);
8
+ if (!found) {
9
+ console.log(`Job ${name} not found`);
10
+ return "";
11
+ }
12
+ await job.start();
13
+ let params = args;
14
+ let res = {};
15
+ for (const name of Object.keys(job.tasks)) {
16
+ brain.expertsForModelsInfo();
17
+ res = await job.runTask(name, params);
18
+ params = res.data;
19
+ }
20
+ await job.finish(true);
21
+ return res;
22
+ }
23
+ async function _dispatchReadJob(name) {
24
+ const { found, path, ext } = getFeatureSpec(name, "job");
25
+ if (!found) {
26
+ return { found: false, job: {} };
27
+ }
28
+ let jb;
29
+ switch (ext) {
30
+ case "js":
31
+ let { job } = await import(path);
32
+ jb = job;
33
+ break;
34
+ case "yml":
35
+ const { data } = await readJob(name);
36
+ const res = await _createJobFromSpec(data);
37
+ jb = res.job;
38
+ break;
39
+ default:
40
+ throw new Error(`Job extension ${ext} not implemented`);
41
+ break;
42
+ }
43
+ return { found: true, job: jb };
44
+ }
45
+ async function _createJobFromSpec(spec) {
46
+ const job = useAgentJob({
47
+ name: spec.name,
48
+ title: spec.title,
49
+ tasks: []
50
+ });
51
+ const tasks = {};
52
+ for (const t of spec.tasks) {
53
+ if (t.type == "action") {
54
+ const { found, path } = getFeatureSpec(t.name, "action");
55
+ if (!found) {
56
+ return { found: false, job: {} };
57
+ }
58
+ const { action } = await import(path);
59
+ tasks[t.name] = action;
60
+ }
61
+ else {
62
+ const { found, path } = getFeatureSpec(t.name, "task");
63
+ if (!found) {
64
+ return { found: false, job: {} };
65
+ }
66
+ const at = taskReader.init(path);
67
+ tasks[t.name] = at;
68
+ }
69
+ }
70
+ job.tasks = tasks;
71
+ return { job: job, found: true };
72
+ }
73
+ async function readJob(name) {
74
+ const { found, path, ext } = getFeatureSpec(name, "job");
75
+ if (!found) {
76
+ return { found: false, data: {} };
77
+ }
78
+ if (!fs.existsSync(path)) {
79
+ return { data: {}, found: false };
80
+ }
81
+ const file = fs.readFileSync(path, 'utf8');
82
+ const data = YAML.parse(file);
83
+ data.name = name;
84
+ return { data: data, found: true };
85
+ }
86
+ export { readJob, executeJobCmd };
@@ -0,0 +1,2 @@
1
+ declare function executeTaskCmd(args?: Array<string>, options?: any): Promise<any>;
2
+ export { executeTaskCmd };
@@ -0,0 +1,28 @@
1
+ import { initAgent, taskReader } from "../../agent.js";
2
+ import logUpdate from "log-update";
3
+ import { getFeatureSpec } from "../../state/features.js";
4
+ import { runMode } from "../../state/state.js";
5
+ async function executeTaskCmd(args = [], options = {}) {
6
+ await initAgent(runMode.value);
7
+ const name = args.shift();
8
+ const { found, path } = getFeatureSpec(name, "task");
9
+ if (!found) {
10
+ return { ok: false, data: {}, error: `Task ${name} not found` };
11
+ }
12
+ const task = taskReader.init(path);
13
+ const pr = args.shift();
14
+ const vars = {};
15
+ args.forEach((a) => {
16
+ if (a.includes("=")) {
17
+ const t = a.split("=");
18
+ vars[t[0]] = t[1];
19
+ }
20
+ });
21
+ logUpdate("Ingesting prompt ...");
22
+ const data = await task.run({ prompt: pr, ...vars });
23
+ if (data?.error) {
24
+ return { ok: false, data: {}, error: `Error executing task: ${data.error}` };
25
+ }
26
+ return { ok: true, data: data.text, error: "" };
27
+ }
28
+ export { executeTaskCmd };
@@ -0,0 +1,4 @@
1
+ declare function setOptions(options: Record<string, any>, args?: Array<string>): Promise<Array<string>>;
2
+ declare function readPromptFile(): string;
3
+ declare function processOutput(res: any): Promise<void>;
4
+ export { readPromptFile, processOutput, setOptions, };
@@ -0,0 +1,44 @@
1
+ import { default as fs } from "fs";
2
+ import { outputMode, promptfile } from "../../state/state.js";
3
+ import { inputMode, runMode } from "../../state/state.js";
4
+ import { readClipboard, writeToClipboard } from "../sys/clipboard.js";
5
+ import { modes } from "../options/modes.js";
6
+ async function setOptions(options, args = []) {
7
+ if (runMode.value == "cli") {
8
+ return args;
9
+ }
10
+ ;
11
+ for (const k of Object.keys(options)) {
12
+ const opt = modes["-" + k.toLowerCase()];
13
+ await opt.cmd([], undefined);
14
+ }
15
+ if (inputMode.value == "promptfile") {
16
+ const p = readPromptFile();
17
+ args.push(p);
18
+ }
19
+ else if (inputMode.value == "clipboard") {
20
+ const p = await readClipboard();
21
+ args.push(p);
22
+ }
23
+ return args;
24
+ }
25
+ function readPromptFile() {
26
+ const res = fs.readFileSync(promptfile.value, 'utf8');
27
+ return res;
28
+ }
29
+ async function processOutput(res) {
30
+ let data = "";
31
+ if (typeof res == "object") {
32
+ if (!res?.data) {
33
+ throw new Error(`No data in res: ${res}`);
34
+ }
35
+ data = res.data;
36
+ }
37
+ else {
38
+ data = res;
39
+ }
40
+ if (outputMode.value == "clipboard") {
41
+ await writeToClipboard(data);
42
+ }
43
+ }
44
+ export { readPromptFile, processOutput, setOptions, };
@@ -0,0 +1,3 @@
1
+ import { Cmd } from "../../interfaces.js";
2
+ declare const modes: Record<string, Cmd>;
3
+ export { modes };
@@ -0,0 +1,58 @@
1
+ import { formatMode, inputMode, outputMode, runMode } from "../../state/state.js";
2
+ const modes = {
3
+ "-if": {
4
+ cmd: async () => {
5
+ inputMode.value = "promptfile";
6
+ if (runMode.value == "cli") {
7
+ console.log("Prompt file input mode is on");
8
+ }
9
+ },
10
+ description: "use promptfile input mode",
11
+ },
12
+ "-ic": {
13
+ cmd: async () => {
14
+ inputMode.value = "clipboard";
15
+ if (runMode.value == "cli") {
16
+ console.log("Clipboard input mode is on");
17
+ }
18
+ },
19
+ description: "use clipboard input mode"
20
+ },
21
+ "-im": {
22
+ cmd: async () => {
23
+ inputMode.value = "manual";
24
+ if (runMode.value == "cli") {
25
+ console.log("Manual inputMode");
26
+ }
27
+ },
28
+ description: "use manual input mode (default)"
29
+ },
30
+ "-oc": {
31
+ cmd: async () => {
32
+ outputMode.value = "clipboard";
33
+ if (runMode.value == "cli") {
34
+ console.log("Clipboard output mode is on");
35
+ }
36
+ },
37
+ description: "use clipboard output mode"
38
+ },
39
+ "-omd": {
40
+ cmd: async () => {
41
+ formatMode.value = "markdown";
42
+ if (runMode.value == "cli") {
43
+ console.log("Markdown output mode");
44
+ }
45
+ },
46
+ description: "use markdown output (default)"
47
+ },
48
+ "-otxt": {
49
+ cmd: async () => {
50
+ formatMode.value = "text";
51
+ if (runMode.value == "cli") {
52
+ console.log("Text output mode");
53
+ }
54
+ },
55
+ description: "use text output "
56
+ },
57
+ };
58
+ export { modes };
@@ -0,0 +1,3 @@
1
+ declare function readClipboard(): Promise<string>;
2
+ declare function writeToClipboard(data: string): Promise<void>;
3
+ export { readClipboard, writeToClipboard, };
@@ -0,0 +1,17 @@
1
+ import clipboard from 'clipboardy';
2
+ import { execute } from "./execute.js";
3
+ const { platform } = process;
4
+ async function readClipboard() {
5
+ let res = "";
6
+ if (platform == "linux") {
7
+ res = await execute("xclip", ["-o", "-selection", "primary"]);
8
+ }
9
+ else {
10
+ res = await clipboard.read();
11
+ }
12
+ return res;
13
+ }
14
+ async function writeToClipboard(data) {
15
+ await clipboard.write(data);
16
+ }
17
+ export { readClipboard, writeToClipboard, };
@@ -0,0 +1,13 @@
1
+ declare function execute(command: string, args?: Array<string>, { onStdout, onStderr, onError, stream, }?: {
2
+ onStderr?: (data: any) => void;
3
+ onError?: (err: any) => void;
4
+ onStdout?: ((data: any) => void) | undefined;
5
+ stream?: boolean | undefined;
6
+ }): Promise<string>;
7
+ declare function run(command: string, args?: Array<string>, { onStdout, onStderr, onError, onFinished, }?: {
8
+ onStdout?: (data: any) => void;
9
+ onStderr?: (data: any) => void;
10
+ onError?: (err: any) => void;
11
+ onFinished?: () => void;
12
+ }): () => boolean;
13
+ export { execute, run };