@agent-smith/cli 0.0.56 → 0.0.57

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.
@@ -3,7 +3,7 @@ import { getFeatureSpec } from '../../../state/features.js';
3
3
  import { readYmlAction } from "../../sys/read_yml_action.js";
4
4
  import { execute } from "../../sys/execute.js";
5
5
  import { runPyScript } from "../../sys/run_python.js";
6
- import { isStateReady, pyShell } from "../../../state/state.js";
6
+ import { pyShell } from "../../../state/state.js";
7
7
  import { createJsAction } from "./read.js";
8
8
  function systemAction(path) {
9
9
  const action = useAgentTask({
@@ -43,7 +43,6 @@ function pythonAction(path) {
43
43
  return action;
44
44
  }
45
45
  async function executeActionCmd(args = [], options = {}, quiet = false) {
46
- while (!isStateReady.value) { }
47
46
  const isWorkflow = !Array.isArray(args);
48
47
  let name;
49
48
  if (!isWorkflow) {
@@ -8,7 +8,8 @@ import { readTask } from "../../sys/read_task.js";
8
8
  import { executeActionCmd, } from "../actions/cmd.js";
9
9
  import { formatStats, parseInputOptions } from "../utils.js";
10
10
  import { executeWorkflowCmd } from "../workflows/cmd.js";
11
- import { configureTaskModel, parseTaskVars } from "./conf.js";
11
+ import { configureTaskModel, mergeInferParams } from "./conf.js";
12
+ import { parseArgs } from "../../../primitives/args.js";
12
13
  async function executeTaskCmd(args = [], options = {}) {
13
14
  await initAgent();
14
15
  if (isDebug.value) {
@@ -42,9 +43,7 @@ async function executeTaskCmd(args = [], options = {}) {
42
43
  throw new Error("Provide a task prompt param");
43
44
  }
44
45
  name = args.name;
45
- delete args.name;
46
46
  pr = args.prompt;
47
- delete args.prompt;
48
47
  }
49
48
  const { found, path } = getFeatureSpec(name, "task");
50
49
  if (!found) {
@@ -55,18 +54,9 @@ async function executeTaskCmd(args = [], options = {}) {
55
54
  throw new Error(`Task ${name}, ${path} not found`);
56
55
  }
57
56
  const taskFileSpec = YAML.parse(res.ymlTask);
58
- let model;
59
- let vars = {};
60
- if (!isWorkflow) {
61
- const tv = parseTaskVars(args, taskFileSpec?.inferParams ? taskFileSpec.inferParams : {});
62
- vars = tv.vars;
63
- model = configureTaskModel(tv.conf, taskFileSpec);
64
- }
65
- else {
66
- const tv = parseTaskVars({ name: name, prompt: pr, ...args }, taskFileSpec?.inferParams ? taskFileSpec.inferParams : {});
67
- vars = tv.vars;
68
- model = configureTaskModel(tv.conf, taskFileSpec);
69
- }
57
+ const { conf, vars } = parseArgs(args);
58
+ conf.inferParams = mergeInferParams(conf.inferParams, taskFileSpec.inferParams ?? {});
59
+ const model = configureTaskModel(conf, taskFileSpec);
70
60
  const taskSpec = taskFileSpec;
71
61
  if (taskSpec.toolsList) {
72
62
  taskSpec.tools = [];
@@ -128,18 +118,19 @@ async function executeTaskCmd(args = [], options = {}) {
128
118
  c = !c;
129
119
  });
130
120
  }
131
- const conf = {
121
+ const tconf = {
132
122
  expert: ex,
133
123
  model: model,
134
124
  debug: isDebug.value,
125
+ ...conf,
135
126
  };
136
- conf.expert = ex;
127
+ tconf.expert = ex;
137
128
  if (isDebug.value || isVerbose.value) {
138
- conf.debug = true;
129
+ tconf.debug = true;
139
130
  }
140
131
  let out;
141
132
  try {
142
- out = await task.run({ prompt: pr, ...vars }, conf);
133
+ out = await task.run({ prompt: pr, ...vars }, tconf);
143
134
  console.log();
144
135
  }
145
136
  catch (err) {
@@ -1,7 +1,5 @@
1
+ import { InferenceParams } from "@locallm/types";
1
2
  import { LmTaskConfig, LmTaskFileSpec, ModelSpec } from "../../../interfaces.js";
2
3
  declare function configureTaskModel(itConf: LmTaskConfig, taskSpec: LmTaskFileSpec): ModelSpec;
3
- declare function parseTaskVars(params: Array<any> | Record<string, any>, inferParams?: Record<string, any>): {
4
- conf: LmTaskConfig;
5
- vars: Record<string, any>;
6
- };
7
- export { parseTaskVars, configureTaskModel, };
4
+ declare function mergeInferParams(userInferParams: Record<string, any>, taskInferParams: InferenceParams): InferenceParams;
5
+ export { mergeInferParams, configureTaskModel, };
@@ -83,87 +83,11 @@ function configureTaskModel(itConf, taskSpec) {
83
83
  }
84
84
  return model;
85
85
  }
86
- function parseTaskVars(params, inferParams = {}) {
87
- switch (Array.isArray(params)) {
88
- case true:
89
- return _initTaskVars(params, inferParams);
90
- default:
91
- return _initTaskParams(params, inferParams);
86
+ function mergeInferParams(userInferParams, taskInferParams) {
87
+ const ip = taskInferParams;
88
+ for (const [k, v] of Object.entries(userInferParams)) {
89
+ ip[k] = v;
92
90
  }
91
+ return ip;
93
92
  }
94
- function _initTaskParams(params, inferParams) {
95
- const conf = { inferParams: inferParams, modelname: "", templateName: "" };
96
- if (!params?.prompt) {
97
- throw new Error(`Error initializing task params: provide a prompt`);
98
- }
99
- if (params?.images) {
100
- conf.inferParams.images = params.images;
101
- delete params.images;
102
- }
103
- if (params?.modelname) {
104
- conf.modelname = params.modelname;
105
- delete params.modelname;
106
- }
107
- if (params?.template) {
108
- conf.templateName = params.templateName;
109
- delete params.templateName;
110
- }
111
- if (params?.m) {
112
- if (params.m.includes("/")) {
113
- const _s = params.m.split("/");
114
- conf.modelname = _s[0];
115
- conf.templateName = _s[1];
116
- }
117
- else {
118
- conf.modelname = params.m;
119
- }
120
- }
121
- const ip = conf.inferParams;
122
- if (params?.inferParams) {
123
- for (const [k, v] of Object.entries(params.inferParams)) {
124
- ip[k] = v;
125
- }
126
- conf.inferParams = ip;
127
- delete params.inferParams;
128
- }
129
- const res = { conf: conf, vars: params };
130
- return res;
131
- }
132
- function _initTaskVars(args, inferParams) {
133
- const conf = { inferParams: inferParams, modelname: "", templateName: "" };
134
- const vars = {};
135
- args.forEach((a) => {
136
- if (a.includes("=")) {
137
- const delimiter = "=";
138
- const [k, v] = a.split(delimiter, 2);
139
- if (v === undefined) {
140
- throw new Error(`invalid parameter ${a}`);
141
- }
142
- switch (k) {
143
- case "m":
144
- if (v.includes("/")) {
145
- const _s = v.split("/");
146
- conf.modelname = _s[0];
147
- conf.templateName = _s[1];
148
- }
149
- else {
150
- conf.modelname = v;
151
- }
152
- break;
153
- case "ip":
154
- v.split(",").forEach((p) => {
155
- const s = p.split(":");
156
- const cip = conf.inferParams;
157
- cip[s[0]] = parseFloat(s[1]);
158
- conf.inferParams = cip;
159
- });
160
- break;
161
- default:
162
- vars[k] = v;
163
- break;
164
- }
165
- }
166
- });
167
- return { conf, vars };
168
- }
169
- export { parseTaskVars, configureTaskModel, };
93
+ export { mergeInferParams, configureTaskModel, };
@@ -1,7 +1,7 @@
1
- import { InferenceStats } from "@locallm/types/dist/interfaces.js";
1
+ import { InferenceStats } from "@locallm/types";
2
2
  declare function setOptions(args: Array<string> | undefined, options: Record<string, any>): Promise<Array<string>>;
3
3
  declare function readPromptFile(): string;
4
4
  declare function processOutput(res: any): Promise<void>;
5
5
  declare function parseInputOptions(options: any): Promise<string | null>;
6
6
  declare function formatStats(stats: InferenceStats): string;
7
- export { parseInputOptions, processOutput, readPromptFile, setOptions, formatStats, };
7
+ export { formatStats, parseInputOptions, processOutput, readPromptFile, setOptions };
@@ -1,8 +1,8 @@
1
+ import { marked } from "../../agent.js";
1
2
  import { formatMode, initFilepaths, inputMode, outputMode, promptfilePath } from "../../state/state.js";
2
3
  import { modes } from "../clicmds/modes.js";
3
4
  import { readClipboard, writeToClipboard } from "../sys/clipboard.js";
4
5
  import { readFile } from "../sys/read.js";
5
- import { marked } from "../../agent.js";
6
6
  async function setOptions(args = [], options) {
7
7
  for (const k of Object.keys(options)) {
8
8
  let opt;
@@ -71,4 +71,4 @@ function formatStats(stats) {
71
71
  buf.push(`${stats.inferenceTimeSeconds}s inference)`);
72
72
  return buf.join(" ");
73
73
  }
74
- export { parseInputOptions, processOutput, readPromptFile, setOptions, formatStats, };
74
+ export { formatStats, parseInputOptions, processOutput, readPromptFile, setOptions };
package/dist/main.d.ts CHANGED
@@ -8,7 +8,6 @@ import { initAgent } from "./agent.js";
8
8
  import { initState, pluginDataDir } from "./state/state.js";
9
9
  import { usePerfTimer } from "./primitives/perf.js";
10
10
  import { parseArgs } from "./primitives/args.js";
11
- import { parseTaskVars } from "./cmd/lib/tasks/conf.js";
12
11
  import { LmTaskConf } from "@agent-smith/lmtask/dist/interfaces.js";
13
12
  import { extractToolDoc } from "./cmd/lib/tools.js";
14
- export { execute, run, pingCmd, executeWorkflowCmd, executeActionCmd, executeTaskCmd, writeToClipboard, initAgent, initState, pluginDataDir, usePerfTimer, parseArgs, parseTaskVars, extractToolDoc, LmTaskConf, };
13
+ export { execute, run, pingCmd, executeWorkflowCmd, executeActionCmd, executeTaskCmd, writeToClipboard, initAgent, initState, pluginDataDir, usePerfTimer, parseArgs, extractToolDoc, LmTaskConf, };
package/dist/main.js CHANGED
@@ -8,6 +8,5 @@ import { initAgent } from "./agent.js";
8
8
  import { initState, pluginDataDir } from "./state/state.js";
9
9
  import { usePerfTimer } from "./primitives/perf.js";
10
10
  import { parseArgs } from "./primitives/args.js";
11
- import { parseTaskVars } from "./cmd/lib/tasks/conf.js";
12
11
  import { extractToolDoc } from "./cmd/lib/tools.js";
13
- export { execute, run, pingCmd, executeWorkflowCmd, executeActionCmd, executeTaskCmd, writeToClipboard, initAgent, initState, pluginDataDir, usePerfTimer, parseArgs, parseTaskVars, extractToolDoc, };
12
+ export { execute, run, pingCmd, executeWorkflowCmd, executeActionCmd, executeTaskCmd, writeToClipboard, initAgent, initState, pluginDataDir, usePerfTimer, parseArgs, extractToolDoc, };
@@ -1,4 +1,6 @@
1
- declare function parseArgs(args: Array<string>): {
1
+ import { LmTaskConfig } from "../interfaces.js";
2
+ declare function parseArgs(params: Record<string, any> | Array<any>): {
3
+ conf: LmTaskConfig;
2
4
  vars: Record<string, any>;
3
5
  args: Array<string>;
4
6
  };
@@ -1,36 +1,79 @@
1
- function parseArgs(args) {
2
- const _vars = { "inferParams": {} };
1
+ function parseArgs(params) {
2
+ switch (Array.isArray(params)) {
3
+ case true:
4
+ return parseArrayArgs(params);
5
+ default:
6
+ return { ...parseObjectArgs(params), args: [] };
7
+ }
8
+ }
9
+ function parseObjectArgs(params) {
10
+ const conf = { inferParams: {}, modelname: "", templateName: "" };
11
+ if (!params?.prompt) {
12
+ throw new Error(`Error initializing task params: provide a prompt`);
13
+ }
14
+ if (params?.images) {
15
+ conf.inferParams.images = params.images;
16
+ delete params.images;
17
+ }
18
+ if (params?.modelname) {
19
+ conf.modelname = params.modelname;
20
+ delete params.modelname;
21
+ }
22
+ if (params?.template) {
23
+ conf.templateName = params.templateName;
24
+ delete params.templateName;
25
+ }
26
+ if (params?.m) {
27
+ if (params.m.includes("/")) {
28
+ const _s = params.m.split("/");
29
+ conf.modelname = _s[0];
30
+ conf.templateName = _s[1];
31
+ }
32
+ else {
33
+ conf.modelname = params.m;
34
+ }
35
+ }
36
+ if (params?.ip) {
37
+ conf.inferParams = params.ip;
38
+ }
39
+ const res = { conf: conf, vars: params };
40
+ return res;
41
+ }
42
+ function parseArrayArgs(args) {
43
+ const _vars = {};
44
+ const _conf = { inferParams: {} };
3
45
  const _nargs = new Array();
4
46
  args.forEach((a) => {
5
47
  if (a.includes("=")) {
6
- const t = a.split("=");
48
+ const t = a.split("=", 2);
7
49
  const k = t[0];
8
50
  const v = t[1];
9
51
  switch (k) {
10
52
  case "m":
11
53
  if (v.includes("/")) {
12
54
  const _s = v.split("/");
13
- _vars.modelname = _s[0];
14
- _vars.templateName = _s[1];
55
+ _conf.modelname = _s[0];
56
+ _conf.templateName = _s[1];
15
57
  }
16
58
  else {
17
- _vars.modelname = v;
59
+ _conf.modelname = v;
18
60
  }
19
61
  break;
20
62
  case "ip":
21
63
  v.split(",").forEach((p) => {
22
64
  const s = p.split(":");
23
- _vars["inferParams"][s[0]] = parseFloat(s[1]);
65
+ _conf.inferParams[s[0]] = parseFloat(s[1]);
24
66
  });
25
67
  break;
26
68
  default:
27
69
  _vars[k] = v;
70
+ break;
28
71
  }
29
72
  }
30
73
  else {
31
74
  _nargs.push(a);
32
75
  }
33
76
  });
34
- return { vars: _vars, args: _nargs };
77
+ return { conf: _conf, vars: _vars, args: _nargs };
35
78
  }
36
79
  export { parseArgs, };
@@ -11,7 +11,6 @@ declare const isVerbose: import("@vue/reactivity").Ref<boolean, boolean>;
11
11
  declare const isShowTokens: import("@vue/reactivity").Ref<boolean, boolean>;
12
12
  declare const promptfilePath: import("@vue/reactivity").Ref<string, string>;
13
13
  declare const dataDirPath: import("@vue/reactivity").Ref<string, string>;
14
- declare const isStateReady: import("@vue/reactivity").Ref<boolean, boolean>;
15
14
  declare const lastCmd: {
16
15
  name: string;
17
16
  args: Array<string>;
@@ -19,4 +18,4 @@ declare const lastCmd: {
19
18
  declare function initFilepaths(): void;
20
19
  declare function initState(): Promise<void>;
21
20
  declare function pluginDataDir(pluginName: string): string;
22
- export { inputMode, outputMode, isChatMode, isShowTokens, isStateReady, runMode, formatMode, lastCmd, isDebug, isVerbose, promptfilePath, dataDirPath, pluginDataDir, initState, initFilepaths, pyShell, };
21
+ export { inputMode, outputMode, isChatMode, isShowTokens, runMode, formatMode, lastCmd, isDebug, isVerbose, promptfilePath, dataDirPath, pluginDataDir, initState, initFilepaths, pyShell, };
@@ -51,4 +51,4 @@ function pluginDataDir(pluginName) {
51
51
  createDirectoryIfNotExists(pluginDatapath);
52
52
  return pluginDatapath;
53
53
  }
54
- export { inputMode, outputMode, isChatMode, isShowTokens, isStateReady, runMode, formatMode, lastCmd, isDebug, isVerbose, promptfilePath, dataDirPath, pluginDataDir, initState, initFilepaths, pyShell, };
54
+ export { inputMode, outputMode, isChatMode, isShowTokens, runMode, formatMode, lastCmd, isDebug, isVerbose, promptfilePath, dataDirPath, pluginDataDir, initState, initFilepaths, pyShell, };
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@agent-smith/cli",
3
3
  "description": "Agent Smith: terminal client for language model agents",
4
4
  "repository": "https://github.com/synw/agent-smith",
5
- "version": "0.0.56",
5
+ "version": "0.0.57",
6
6
  "scripts": {
7
7
  "buildrl": "rm -rf dist/* && rollup -c",
8
8
  "build": "rm -rf dist/* && tsc",