@agent-smith/cli 0.0.96 → 0.0.97

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.
package/dist/cli.js CHANGED
@@ -7,7 +7,7 @@ async function query(program) {
7
7
  const args = q.split(" ");
8
8
  await program.parseAsync(args, { from: "user" });
9
9
  if (isChatMode.value) {
10
- await chat(program);
10
+ await chat(program, {});
11
11
  }
12
12
  await query(program);
13
13
  }
@@ -1,6 +1,7 @@
1
+ import { InferenceOptions } from "@locallm/types/dist/inference.js";
1
2
  import { Command } from "commander";
2
3
  declare const program: Command;
3
- declare function chat(program: Command): Promise<void>;
4
+ declare function chat(program: Command, options: InferenceOptions): Promise<void>;
4
5
  declare function buildCmds(): Promise<Command>;
5
6
  declare function parseCmd(program: Command): Promise<void>;
6
- export { program, buildCmds, chat, parseCmd, };
7
+ export { buildCmds, chat, parseCmd, program };
package/dist/cmd/cmds.js CHANGED
@@ -1,15 +1,14 @@
1
1
  import { input } from "@inquirer/prompts";
2
- import { toRaw } from "@vue/reactivity";
3
2
  import { Command } from "commander";
4
3
  import { query } from "../cli.js";
5
4
  import { readAliases, readFeatures } from "../db/read.js";
6
- import { chatInferenceParams } from "../state/chat.js";
5
+ import { chatInferenceParams, chatTemplate } from "../state/chat.js";
7
6
  import { agent, isChatMode, runMode } from "../state/state.js";
8
7
  import { initCommandsFromAliases } from "./clicmds/aliases.js";
9
8
  import { initBaseCommands } from "./clicmds/base.js";
10
9
  import { initUserCmds } from "./clicmds/cmds.js";
11
10
  const program = new Command();
12
- async function chat(program) {
11
+ async function chat(program, options) {
13
12
  const data = { message: '>', default: "" };
14
13
  const prompt = await input(data);
15
14
  if (prompt == "/q") {
@@ -21,9 +20,10 @@ async function chat(program) {
21
20
  await query(program);
22
21
  }
23
22
  }
24
- await agent.lm.infer(prompt, toRaw(chatInferenceParams));
23
+ options.history = undefined;
24
+ await agent.run(prompt, chatInferenceParams, options, chatTemplate ? chatTemplate : undefined);
25
25
  console.log();
26
- await chat(program);
26
+ await chat(program, options);
27
27
  }
28
28
  async function buildCmds() {
29
29
  initBaseCommands(program);
@@ -41,4 +41,4 @@ async function parseCmd(program) {
41
41
  program.description('Terminal agents toolkit');
42
42
  await program.parseAsync();
43
43
  }
44
- export { program, buildCmds, chat, parseCmd, };
44
+ export { buildCmds, chat, parseCmd, program };
@@ -1,19 +1,18 @@
1
- import { input } from "@inquirer/prompts";
2
1
  import { compile, serializeGrammar } from "@intrinsicai/gbnfgen";
3
2
  import { default as color, default as colors } from "ansi-colors";
4
3
  import { PromptTemplate } from "modprompt";
5
4
  import ora from 'ora';
6
- import { query } from "../../../cli.js";
7
- import { readClipboard } from "../../../cmd/sys/clipboard.js";
8
5
  import { usePerfTimer } from "../../../main.js";
9
- import { isChatMode, runMode, agent } from "../../../state/state.js";
10
- import { program } from "../../cmds.js";
6
+ import { backend, backends, listBackends } from "../../../state/backends.js";
7
+ import { setChatInferenceParams, setChatTemplate } from "../../../state/chat.js";
8
+ import { agent, isChatMode } from "../../../state/state.js";
9
+ import { initTaskSettings, isTaskSettingsInitialized, tasksSettings } from "../../../state/tasks.js";
10
+ import { chat, program } from "../../cmds.js";
11
11
  import { parseCommandArgs } from "../options_parsers.js";
12
12
  import { runtimeDataError, runtimeError, runtimeWarning } from "../user_msgs.js";
13
- import { formatStats, processOutput, readPromptFile } from "../utils.js";
13
+ import { formatStats, processOutput } from "../utils.js";
14
14
  import { readTask } from "./read.js";
15
- import { backend, backends, listBackends } from "../../../state/backends.js";
16
- import { isTaskSettingsInitialized, initTaskSettings, tasksSettings } from "../../../state/tasks.js";
15
+ import { getTaskPrompt } from "./utils.js";
17
16
  async function executeTask(name, payload, options, quiet) {
18
17
  if (!isTaskSettingsInitialized.value) {
19
18
  initTaskSettings();
@@ -194,6 +193,8 @@ async function executeTask(name, payload, options, quiet) {
194
193
  onToolCallEnd: onToolCallEnd,
195
194
  ...conf,
196
195
  };
196
+ const initialInferParams = Object.assign({}, conf.inferParams);
197
+ initialInferParams.model = tconf.model;
197
198
  let out;
198
199
  try {
199
200
  out = await task.run({ prompt: payload.prompt, ...vars }, tconf);
@@ -225,20 +226,11 @@ async function executeTask(name, payload, options, quiet) {
225
226
  mcpServers.forEach(async (s) => await s.stop());
226
227
  await processOutput(out);
227
228
  if (isChatMode.value) {
228
- const data = { message: '>', default: "" };
229
- const prompt = await input(data);
230
- if (prompt == "/q") {
231
- isChatMode.value = false;
232
- if (runMode.value == "cmd") {
233
- process.exit(0);
234
- }
235
- else {
236
- await query(program);
237
- }
238
- }
239
- else {
240
- await executeTask(name, { ...vars, prompt: prompt }, options, quiet);
229
+ if (tpl) {
230
+ setChatTemplate(tpl);
241
231
  }
232
+ setChatInferenceParams(initialInferParams);
233
+ await chat(program, options);
242
234
  }
243
235
  if (options?.debug === true || options?.verbose === true) {
244
236
  try {
@@ -257,24 +249,8 @@ async function executeTask(name, payload, options, quiet) {
257
249
  return out;
258
250
  }
259
251
  async function executeTaskCmd(name, targs = []) {
260
- const { args, options } = parseCommandArgs(targs);
261
- let pr;
262
- if (options?.clipboardInput === true) {
263
- pr = await readClipboard();
264
- }
265
- else if (options?.inputFile === true) {
266
- pr = readPromptFile();
267
- }
268
- else {
269
- if (args[0] !== undefined) {
270
- pr = args[0];
271
- }
272
- else {
273
- runtimeDataError("task", name, "provide a prompt or use input options");
274
- throw new Error();
275
- }
276
- }
277
- const params = { args: args, prompt: pr };
278
- return await executeTask(name, params, options);
252
+ const ca = parseCommandArgs(targs);
253
+ const prompt = await getTaskPrompt(name, ca.args, ca.options);
254
+ return await executeTask(name, { prompt: prompt }, ca.options);
279
255
  }
280
256
  export { executeTask, executeTaskCmd };
@@ -92,6 +92,7 @@ async function readTask(name, payload, options, agent) {
92
92
  }
93
93
  ;
94
94
  const task = new Task(agent, taskSpec);
95
+ task.addTools(taskSpec.tools);
95
96
  if (model?.inferParams?.tsGrammar) {
96
97
  model.inferParams.grammar = serializeGrammar(await compile(model.inferParams.tsGrammar, "Grammar"));
97
98
  delete model.inferParams.tsGrammar;
@@ -1,3 +1,4 @@
1
1
  import { LmTaskFileSpec } from "../../../interfaces.js";
2
2
  declare function openTaskSpec(name: string): LmTaskFileSpec;
3
- export { openTaskSpec, };
3
+ declare function getTaskPrompt(name: string, args: Array<string>, options: Record<string, any>): Promise<string>;
4
+ export { openTaskSpec, getTaskPrompt, };
@@ -1,6 +1,9 @@
1
1
  import YAML from 'yaml';
2
2
  import { readTask } from "../../../cmd/sys/read_task.js";
3
3
  import { getFeatureSpec } from "../../../state/features.js";
4
+ import { readClipboard } from '../../../cmd/sys/clipboard.js';
5
+ import { readPromptFile } from '../utils.js';
6
+ import { runtimeDataError } from '../user_msgs.js';
4
7
  function openTaskSpec(name) {
5
8
  const { found, path } = getFeatureSpec(name, "task");
6
9
  if (!found) {
@@ -14,4 +17,23 @@ function openTaskSpec(name) {
14
17
  taskFileSpec.name = name;
15
18
  return taskFileSpec;
16
19
  }
17
- export { openTaskSpec, };
20
+ async function getTaskPrompt(name, args, options) {
21
+ let pr;
22
+ if (options?.clipboardInput === true) {
23
+ pr = await readClipboard();
24
+ }
25
+ else if (options?.inputFile === true) {
26
+ pr = readPromptFile();
27
+ }
28
+ else {
29
+ if (args[0] !== undefined) {
30
+ pr = args[0];
31
+ }
32
+ else {
33
+ runtimeDataError("task", name, "provide a prompt or use input options");
34
+ throw new Error();
35
+ }
36
+ }
37
+ return pr;
38
+ }
39
+ export { openTaskSpec, getTaskPrompt, };
@@ -1,3 +1,3 @@
1
- declare function executeWorkflow(name: string, args: any, options?: Record<string, any>): Promise<any>;
1
+ declare function executeWorkflow(wname: string, args: any, options?: Record<string, any>): Promise<any>;
2
2
  declare function executeWorkflowCmd(name: string, wargs: Array<any>): Promise<any>;
3
3
  export { executeWorkflow, executeWorkflowCmd, };
@@ -2,30 +2,51 @@ import { executeAction } from "../actions/cmd.js";
2
2
  import { executeAdaptater } from "../adaptaters/cmd.js";
3
3
  import { parseCommandArgs } from "../options_parsers.js";
4
4
  import { executeTask } from "../tasks/cmd.js";
5
+ import { getTaskPrompt } from "../tasks/utils.js";
5
6
  import { readWorkflow } from "./read.js";
6
7
  import colors from "ansi-colors";
7
- async function executeWorkflow(name, args, options = {}) {
8
- const { workflow, found } = await readWorkflow(name);
8
+ async function executeWorkflow(wname, args, options = {}) {
9
+ const { workflow, found } = await readWorkflow(wname);
9
10
  if (!found) {
10
- throw new Error(`Workflow ${name} not found`);
11
+ throw new Error(`Workflow ${wname} not found`);
11
12
  }
12
13
  const isDebug = options?.debug === true;
13
14
  const isVerbose = options?.verbose === true;
14
15
  const stepNames = Object.keys(workflow);
15
16
  if (isDebug || isVerbose) {
16
- console.log("Running workflow", name, stepNames.length, "steps");
17
+ console.log("Running workflow", wname, stepNames.length, "steps");
17
18
  }
18
19
  let i = 0;
19
20
  const finalTaskIndex = stepNames.length - 1;
20
21
  let taskRes = { cmdArgs: args };
21
- for (const [name, step] of Object.entries(workflow)) {
22
+ let prevStepType = null;
23
+ for (const step of workflow) {
22
24
  if (isDebug || isVerbose) {
23
- console.log(i + 1, name, colors.dim(step.type));
25
+ console.log(i + 1, step.name, colors.dim(step.type));
24
26
  }
25
27
  switch (step.type) {
26
28
  case "task":
27
29
  try {
28
- const tr = await executeTask(name, taskRes, options, true);
30
+ let pr = null;
31
+ if (i == 0) {
32
+ pr = await getTaskPrompt(step.name, taskRes.cmdArgs, options);
33
+ }
34
+ else {
35
+ if (prevStepType) {
36
+ if (prevStepType == "task") {
37
+ pr = taskRes.answer.text;
38
+ }
39
+ }
40
+ if (!pr) {
41
+ if (taskRes?.prompt) {
42
+ pr = taskRes.prompt;
43
+ }
44
+ }
45
+ }
46
+ if (!pr) {
47
+ throw new Error(`Workflow ${wname} step ${i + 1}: provide a prompt for the task ${name}`);
48
+ }
49
+ const tr = await executeTask(step.name, { prompt: pr }, options, true);
29
50
  taskRes = { ...tr, ...taskRes };
30
51
  }
31
52
  catch (e) {
@@ -35,7 +56,7 @@ async function executeWorkflow(name, args, options = {}) {
35
56
  case "action":
36
57
  try {
37
58
  const actArgs = i == 0 ? taskRes.cmdArgs : taskRes;
38
- const ares = await executeAction(name, actArgs, options, true);
59
+ const ares = await executeAction(step.name, actArgs, options, true);
39
60
  if (typeof ares == "string" || Array.isArray(ares)) {
40
61
  taskRes.args = ares;
41
62
  }
@@ -53,7 +74,7 @@ async function executeWorkflow(name, args, options = {}) {
53
74
  case "adaptater":
54
75
  try {
55
76
  const actArgs = i == 0 ? taskRes.cmdArgs : taskRes;
56
- const adres = await executeAdaptater(name, actArgs, options);
77
+ const adres = await executeAdaptater(step.name, actArgs, options);
57
78
  if (typeof adres == "string" || Array.isArray(adres)) {
58
79
  taskRes.args = adres;
59
80
  }
@@ -71,6 +92,7 @@ async function executeWorkflow(name, args, options = {}) {
71
92
  default:
72
93
  throw new Error(`unknown task type ${step.type} in workflow ${name}`);
73
94
  }
95
+ prevStepType = step.type;
74
96
  ++i;
75
97
  }
76
98
  return taskRes;
@@ -1,6 +1,6 @@
1
1
  import { WorkflowStep } from '../../../interfaces.js';
2
2
  declare function readWorkflow(name: string): Promise<{
3
3
  found: boolean;
4
- workflow: Record<string, WorkflowStep>;
4
+ workflow: Array<WorkflowStep>;
5
5
  }>;
6
6
  export { readWorkflow };
@@ -9,17 +9,12 @@ import { pythonAction, systemAction } from '../actions/cmd.js';
9
9
  import { createJsAction } from '../actions/read.js';
10
10
  import { pathToFileURL } from 'url';
11
11
  async function _createWorkflowFromSpec(spec) {
12
- const steps = {};
12
+ const steps = [];
13
+ let i = 1;
13
14
  for (const step of spec.steps) {
14
15
  const type = Object.keys(step)[0];
15
16
  const sval = step[type];
16
- let name;
17
- if (typeof sval == "string") {
18
- name = sval;
19
- }
20
- else {
21
- name = step[type].name;
22
- }
17
+ const name = sval;
23
18
  if (type == "action") {
24
19
  const { found, path, ext } = getFeatureSpec(name, "action");
25
20
  if (!found) {
@@ -31,36 +26,40 @@ async function _createWorkflowFromSpec(spec) {
31
26
  const { action } = await import(url);
32
27
  const at = action;
33
28
  const wf = {
29
+ name: name,
34
30
  type: "action",
35
31
  run: at,
36
32
  };
37
- steps[name] = wf;
33
+ steps.push(wf);
38
34
  break;
39
35
  case "mjs":
40
36
  const url2 = pathToFileURL(path).href;
41
37
  const mjsa = await import(url2);
42
38
  const act = createJsAction(mjsa.action);
43
39
  const wf2 = {
40
+ name: name,
44
41
  type: "action",
45
42
  run: act,
46
43
  };
47
- steps[name] = wf2;
44
+ steps.push(wf2);
48
45
  break;
49
46
  case "yml":
50
47
  const _t1 = systemAction(path);
51
48
  const wf3 = {
49
+ name: name,
52
50
  type: "action",
53
51
  run: _t1,
54
52
  };
55
- steps[name] = wf3;
53
+ steps.push(wf3);
56
54
  break;
57
55
  case "py":
58
56
  const _t = pythonAction(path);
59
57
  const wf4 = {
58
+ name: name,
60
59
  type: "action",
61
60
  run: _t,
62
61
  };
63
- steps[name] = wf4;
62
+ steps.push(wf4);
64
63
  break;
65
64
  default:
66
65
  throw new Error(`Unknown feature extension ${ext}`);
@@ -75,10 +74,11 @@ async function _createWorkflowFromSpec(spec) {
75
74
  const jsa = await import(url);
76
75
  const act = createJsAction(jsa.action);
77
76
  const wf = {
77
+ name: name,
78
78
  type: "adaptater",
79
79
  run: act,
80
80
  };
81
- steps[name] = wf;
81
+ steps.push(wf);
82
82
  }
83
83
  else {
84
84
  const { found, path } = getFeatureSpec(name, "task");
@@ -92,11 +92,13 @@ async function _createWorkflowFromSpec(spec) {
92
92
  const agent = new Agent(backend.value);
93
93
  const tsk = Task.fromYaml(agent, res.ymlTask);
94
94
  const wf = {
95
+ name: name,
95
96
  type: "task",
96
97
  run: tsk.run,
97
98
  };
98
- steps[name] = wf;
99
+ steps.push(wf);
99
100
  }
101
+ ++i;
100
102
  }
101
103
  return steps;
102
104
  }
@@ -116,16 +118,16 @@ async function _readWorkflowFromDisk(name) {
116
118
  async function readWorkflow(name) {
117
119
  const { found, ext } = getFeatureSpec(name, "workflow");
118
120
  if (!found) {
119
- return { found: false, workflow: {} };
121
+ return { found: false, workflow: [] };
120
122
  }
121
- let wf = {};
123
+ let wf = new Array();
122
124
  switch (ext) {
123
125
  case "yml":
124
126
  const { data } = await _readWorkflowFromDisk(name);
125
127
  try {
126
128
  const workflow = await _createWorkflowFromSpec(data);
127
129
  if (!found) {
128
- return { found: false, workflow: {} };
130
+ return { found: false, workflow: [] };
129
131
  }
130
132
  wf = workflow;
131
133
  }
package/dist/db/write.js CHANGED
@@ -297,7 +297,6 @@ function upsertTaskSettings(taskName, settings) {
297
297
  const nq = new Array("?");
298
298
  qnames.forEach(n => nq.push("?"));
299
299
  const q = `INSERT INTO tasksettings (name, ${qnames.join(", ")}) VALUES (${nq.join(", ")})`;
300
- console.log(q);
301
300
  const insertStmt = db.prepare(q);
302
301
  insertStmt.run(taskName, ...qvalues);
303
302
  return true;
@@ -98,6 +98,7 @@ interface FinalLmTaskConfig {
98
98
  modelname?: string;
99
99
  }
100
100
  interface WorkflowStep {
101
+ name: string;
101
102
  type: string;
102
103
  run: FeatureExecutor;
103
104
  }
@@ -1,27 +1,7 @@
1
- declare const chatInferenceParams: {
2
- stream?: boolean | undefined;
3
- model?: {
4
- name: string;
5
- ctx?: number | undefined;
6
- info?: {
7
- size: string;
8
- quant: string;
9
- } | undefined;
10
- extra?: Record<string, any> | undefined;
11
- } | undefined;
12
- template?: string | undefined;
13
- max_tokens?: number | undefined;
14
- top_k?: number | undefined;
15
- top_p?: number | undefined;
16
- min_p?: number | undefined;
17
- temperature?: number | undefined;
18
- repeat_penalty?: number | undefined;
19
- tfs?: number | undefined;
20
- stop?: Array<string> | undefined;
21
- grammar?: string | undefined;
22
- tsGrammar?: string | undefined;
23
- schema?: Record<string, any> | undefined;
24
- images?: Array<string> | undefined;
25
- extra?: Record<string, any> | undefined;
26
- };
27
- export { chatInferenceParams, };
1
+ import { InferenceParams } from "@locallm/types";
2
+ import { PromptTemplate } from "modprompt";
3
+ declare let chatInferenceParams: InferenceParams;
4
+ declare let chatTemplate: PromptTemplate;
5
+ declare function setChatTemplate(tpl: PromptTemplate): void;
6
+ declare function setChatInferenceParams(ip: InferenceParams): void;
7
+ export { chatInferenceParams, chatTemplate, setChatInferenceParams, setChatTemplate, };
@@ -1,3 +1,10 @@
1
- import { reactive } from "@vue/reactivity";
2
- const chatInferenceParams = reactive({ temperature: 0.2, min_p: 0.05, max_tokens: 2048 });
3
- export { chatInferenceParams, };
1
+ import { PromptTemplate } from "modprompt";
2
+ let chatInferenceParams = { temperature: 0.2, min_p: 0.05, max_tokens: 2048 };
3
+ let chatTemplate = new PromptTemplate("none");
4
+ function setChatTemplate(tpl) {
5
+ chatTemplate = tpl;
6
+ }
7
+ function setChatInferenceParams(ip) {
8
+ chatInferenceParams = ip;
9
+ }
10
+ export { chatInferenceParams, chatTemplate, setChatInferenceParams, setChatTemplate, };
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.96",
5
+ "version": "0.0.97",
6
6
  "scripts": {
7
7
  "buildrl": "rm -rf dist/* && rollup -c",
8
8
  "build": "rm -rf dist/* && tsc",
@@ -10,20 +10,19 @@
10
10
  "watch": "tsc --noCheck -p . -w"
11
11
  },
12
12
  "dependencies": {
13
- "@agent-smith/agent": "^0.1.5",
14
- "@agent-smith/task": "^0.1.7",
13
+ "@agent-smith/agent": "^0.1.6",
14
+ "@agent-smith/task": "^0.1.8",
15
15
  "@agent-smith/tfm": "^0.2.0",
16
- "@inquirer/prompts": "^7.10.1",
16
+ "@inquirer/prompts": "^8.1.0",
17
17
  "@intrinsicai/gbnfgen": "0.12.0",
18
- "@locallm/api": "^0.7.2",
19
- "@modelcontextprotocol/sdk": "^1.24.3",
20
- "@vue/reactivity": "^3.5.25",
18
+ "@locallm/api": "^0.7.3",
19
+ "@modelcontextprotocol/sdk": "^1.25.1",
20
+ "@vue/reactivity": "^3.5.26",
21
21
  "ansi-colors": "^4.1.3",
22
22
  "better-sqlite3": "^12.5.0",
23
23
  "clipboardy": "^5.0.2",
24
24
  "commander": "^14.0.2",
25
25
  "marked-terminal": "^7.3.0",
26
- "modprompt": "^0.12.6",
27
26
  "ora": "^9.0.0",
28
27
  "python-shell": "^5.0.0",
29
28
  "yaml": "^2.8.2"
@@ -37,10 +36,10 @@
37
36
  "@rollup/plugin-typescript": "^12.3.0",
38
37
  "@types/better-sqlite3": "^7.6.13",
39
38
  "@types/marked-terminal": "^6.1.1",
40
- "@types/node": "^25.0.2",
41
- "openai": "^6.10.0",
39
+ "@types/node": "^25.0.3",
40
+ "openai": "^6.15.0",
42
41
  "restmix": "^0.6.1",
43
- "rollup": "^4.53.3",
42
+ "rollup": "^4.54.0",
44
43
  "ts-node": "^10.9.2",
45
44
  "tslib": "2.8.1",
46
45
  "typescript": "^5.9.3"