@agent-smith/cli 0.0.35 → 0.0.36

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.
@@ -26,7 +26,12 @@ function pythonAction(path) {
26
26
  title: "",
27
27
  run: async (args) => {
28
28
  const out = await runPyScript(pyShell, "python3", path, args);
29
- return { data: out.join("\n"), error: "", ok: true };
29
+ const txt = out.join("\n");
30
+ let data = txt;
31
+ if (txt.startsWith("{") || txt.startsWith("[")) {
32
+ data = JSON.parse(data);
33
+ }
34
+ return { data: data, error: "", ok: true };
30
35
  }
31
36
  });
32
37
  return action;
@@ -4,7 +4,7 @@ import { useAgentJob } from "@agent-smith/jobs";
4
4
  import { brain, marked, taskBuilder } from '../../agent.js';
5
5
  import { getFeatureSpec } from '../../state/features.js';
6
6
  import { formatMode, isDebug, isVerbose } from '../../state/state.js';
7
- import { createJsAction, initTaskConf, initTaskParams, initTaskVars, parseInputOptions, readTask } from './utils.js';
7
+ import { createJsAction, initActionVars, initTaskConf, initTaskParams, initTaskVars, parseInputOptions, readTask } from './utils.js';
8
8
  import { pythonAction, systemAction } from './execute_action.js';
9
9
  async function executeJobCmd(name, args = [], options = {}) {
10
10
  const { job, found } = await _dispatchReadJob(name);
@@ -54,7 +54,7 @@ async function executeJobCmd(name, args = [], options = {}) {
54
54
  params.prompt = params.text;
55
55
  }
56
56
  else {
57
- throw new Error(`No prompt provided for task ${name}.\Params: ${params}`);
57
+ throw new Error(`No prompt provided for task ${name}.\Params: ${JSON.stringify(params, null, 2)}`);
58
58
  }
59
59
  }
60
60
  const vs = initTaskParams(params, taskSpec?.inferParams ? taskSpec.inferParams : {});
@@ -87,6 +87,7 @@ async function executeJobCmd(name, args = [], options = {}) {
87
87
  ex.backend.setOnToken((t) => {
88
88
  process.stdout.write(t);
89
89
  });
90
+ brain.setDefaultExpert(ex);
90
91
  conf["expert"] = ex;
91
92
  try {
92
93
  if (isDebug.value || isVerbose.value) {
@@ -96,6 +97,7 @@ async function executeJobCmd(name, args = [], options = {}) {
96
97
  const invars = { ...params, ...vars };
97
98
  try {
98
99
  res = await job.runTask(name, invars, conf);
100
+ console.log("");
99
101
  }
100
102
  catch (e) {
101
103
  throw new Error(`Error running task ${name}: ${e}`);
@@ -139,6 +141,11 @@ async function executeJobCmd(name, args = [], options = {}) {
139
141
  else {
140
142
  try {
141
143
  const _p = i == 0 ? args : params;
144
+ let nextParams = {};
145
+ if (i == 0) {
146
+ const { vars } = initActionVars(args);
147
+ nextParams = vars;
148
+ }
142
149
  if (isDebug.value) {
143
150
  console.log(i + 1, "Running action", name, _p);
144
151
  }
@@ -160,7 +167,7 @@ async function executeJobCmd(name, args = [], options = {}) {
160
167
  else {
161
168
  params = res.data;
162
169
  }
163
- params = res.data;
170
+ params = { ...res.data, ...nextParams };
164
171
  }
165
172
  catch (err) {
166
173
  return { error: `Error executing (${task.type}) task ${name}: ${err}` };
@@ -14,10 +14,11 @@ declare function initTaskParams(params: Record<string, any>, inferParams: Record
14
14
  conf: Record<string, any>;
15
15
  vars: Record<string, any>;
16
16
  };
17
+ declare function initActionVars(args: Array<any>): Record<string, any>;
17
18
  declare function initTaskVars(args: Array<any>, inferParams: Record<string, any>): {
18
19
  conf: Record<string, any>;
19
20
  vars: Record<string, any>;
20
21
  };
21
22
  declare function parseInputOptions(options: any): Promise<string | null>;
22
23
  declare function createJsAction(action: CallableFunction): AgentTask<FeatureType>;
23
- export { createJsAction, initTaskConf, initTaskParams, initTaskVars, parseInputOptions, processOutput, readPromptFile, readTask, readTasksDir, setOptions };
24
+ export { createJsAction, initTaskConf, initTaskParams, initTaskVars, initActionVars, parseInputOptions, processOutput, readPromptFile, readTask, readTasksDir, setOptions };
@@ -135,9 +135,56 @@ function initTaskParams(params, inferParams) {
135
135
  conf.inferParams.images = params.images;
136
136
  delete params.images;
137
137
  }
138
+ if (params?.size) {
139
+ conf.size = params.size;
140
+ delete params.size;
141
+ }
142
+ if (params?.model) {
143
+ conf.model = params.model;
144
+ delete params.model;
145
+ }
146
+ if (params?.template) {
147
+ conf.template = params.template;
148
+ delete params.template;
149
+ }
138
150
  const res = { conf: conf, vars: params };
139
151
  return res;
140
152
  }
153
+ function initActionVars(args) {
154
+ const vars = {};
155
+ args.forEach((a) => {
156
+ if (a.includes("=")) {
157
+ const t = a.split("=");
158
+ const k = t[0];
159
+ const v = t[1];
160
+ switch (k) {
161
+ case "m":
162
+ if (v.includes("/")) {
163
+ const _s = v.split("/");
164
+ vars.model = _s[0];
165
+ vars.template = _s[1];
166
+ }
167
+ else {
168
+ vars.model = v;
169
+ }
170
+ break;
171
+ case "ip":
172
+ v.split(",").forEach((p) => {
173
+ const s = p.split(":");
174
+ vars["inferParams"][s[0]] = parseFloat(s[1]);
175
+ });
176
+ break;
177
+ case "s":
178
+ vars.size = v;
179
+ break;
180
+ default:
181
+ vars[k] = v;
182
+ break;
183
+ }
184
+ }
185
+ });
186
+ return { vars };
187
+ }
141
188
  function initTaskVars(args, inferParams) {
142
189
  const conf = { inferParams: inferParams };
143
190
  const vars = {};
@@ -195,4 +242,4 @@ function createJsAction(action) {
195
242
  });
196
243
  return task;
197
244
  }
198
- export { createJsAction, initTaskConf, initTaskParams, initTaskVars, parseInputOptions, processOutput, readPromptFile, readTask, readTasksDir, setOptions };
245
+ export { createJsAction, initTaskConf, initTaskParams, initTaskVars, initActionVars, parseInputOptions, processOutput, readPromptFile, readTask, readTasksDir, setOptions };
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.35",
5
+ "version": "0.0.36",
6
6
  "scripts": {
7
7
  "buildrl": "rm -rf dist/* && rollup -c",
8
8
  "build": "rm -rf dist/* && tsc --noCheck",