@agent-smith/cli 0.0.108 → 0.0.110

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 (49) hide show
  1. package/dist/cli.js +1 -0
  2. package/dist/cmd/clicmds/aliases.js +8 -6
  3. package/dist/cmd/clicmds/base.js +5 -2
  4. package/dist/cmd/clicmds/cmds.d.ts +2 -3
  5. package/dist/cmd/clicmds/cmds.js +63 -23
  6. package/dist/cmd/clicmds/updateconf.d.ts +2 -1
  7. package/dist/cmd/clicmds/updateconf.js +39 -9
  8. package/dist/cmd/cmds.js +70 -3
  9. package/dist/cmd/lib/actions/cmd.js +21 -1
  10. package/dist/cmd/lib/actions/read.js +4 -0
  11. package/dist/cmd/lib/adaptaters/cmd.js +8 -1
  12. package/dist/cmd/lib/agents/cmd.js +2 -1
  13. package/dist/cmd/lib/mcp.js +6 -0
  14. package/dist/cmd/lib/options_parsers.js +5 -0
  15. package/dist/cmd/lib/tasks/cmd.js +90 -5
  16. package/dist/cmd/lib/tasks/conf.js +35 -0
  17. package/dist/cmd/lib/tasks/read.js +30 -1
  18. package/dist/cmd/lib/tools.js +10 -4
  19. package/dist/cmd/lib/user_msgs.js +4 -3
  20. package/dist/cmd/lib/utils.js +5 -0
  21. package/dist/cmd/lib/workflows/cmd.js +24 -1
  22. package/dist/cmd/lib/workflows/read.js +5 -0
  23. package/dist/cmd/options.js +1 -0
  24. package/dist/cmd/sys/clipboard.js +25 -0
  25. package/dist/cmd/sys/execute.js +1 -0
  26. package/dist/cmd/sys/read_cmds.d.ts +7 -3
  27. package/dist/cmd/sys/read_cmds.js +21 -3
  28. package/dist/cmd/sys/read_conf.js +1 -0
  29. package/dist/cmd/sys/read_features.js +1 -0
  30. package/dist/cmd/sys/run_python.js +4 -0
  31. package/dist/conf.d.ts +5 -2
  32. package/dist/conf.js +6 -3
  33. package/dist/db/db.js +1 -0
  34. package/dist/db/read.js +1 -0
  35. package/dist/db/write.js +50 -2
  36. package/dist/index.js +8 -0
  37. package/dist/interfaces.d.ts +13 -2
  38. package/dist/main.d.ts +18 -3
  39. package/dist/main.js +17 -2
  40. package/dist/state/backends.js +14 -0
  41. package/dist/state/plugins.js +3 -0
  42. package/dist/state/state.js +21 -2
  43. package/dist/state/tasks.d.ts +2 -1
  44. package/dist/state/tasks.js +8 -1
  45. package/dist/utils/text.js +4 -0
  46. package/dist/utils/user_msgs.js +2 -0
  47. package/package.json +15 -15
  48. package/dist/state/auto/usercmds.d.ts +0 -4
  49. package/dist/state/auto/usercmds.js +0 -3
@@ -15,6 +15,9 @@ import { readTask } from "./read.js";
15
15
  import { getTaskPrompt } from "./utils.js";
16
16
  import { Agent } from "@agent-smith/agent";
17
17
  async function executeTask(name, payload, options) {
18
+ //console.log("EXEC TASK", payload, options);
19
+ //console.log("TN", name);
20
+ //console.log("AGENT", agent);
18
21
  if (!isTaskSettingsInitialized.value) {
19
22
  initTaskSettings();
20
23
  }
@@ -27,6 +30,7 @@ async function executeTask(name, payload, options) {
27
30
  if (options?.backend) {
28
31
  if (options.backend in backends) {
29
32
  agent.lm = backends[options.backend];
33
+ //console.log("SET AGENT BACKEND TO", backends[options.backend]);
30
34
  }
31
35
  else {
32
36
  const bks = await listBackends(false);
@@ -34,6 +38,7 @@ async function executeTask(name, payload, options) {
34
38
  }
35
39
  }
36
40
  else if (settings?.backend) {
41
+ //console.log("SET AGENT BACKEND TO", backends[options.backend]);
37
42
  agent.lm = backends[settings.backend];
38
43
  }
39
44
  if (options?.debug || options?.backend) {
@@ -51,6 +56,7 @@ async function executeTask(name, payload, options) {
51
56
  console.log("MCP start", mcp.name);
52
57
  }
53
58
  }
59
+ //console.log("TASKCONF IP", conf.inferParams);
54
60
  if (hasSettings) {
55
61
  if (!model?.inferParams) {
56
62
  model.inferParams = {};
@@ -83,14 +89,19 @@ async function executeTask(name, payload, options) {
83
89
  model.inferParams.repeat_penalty = settings.repeat_penalty;
84
90
  }
85
91
  }
92
+ //console.log("TASK MODEL", model);
93
+ // check for grammars
86
94
  if (model?.inferParams?.tsGrammar) {
95
+ //console.log("TSG");
87
96
  model.inferParams.grammar = serializeGrammar(await compile(model.inferParams.tsGrammar, "Grammar"));
88
97
  delete model.inferParams.tsGrammar;
89
98
  }
99
+ //let i = 0;
90
100
  let c = false;
91
101
  const useTemplates = agent.lm.providerType !== "openai";
92
102
  let hasThink = false;
93
103
  let tpl = null;
104
+ //console.log("Use templates:", useTemplates);
94
105
  if (useTemplates) {
95
106
  try {
96
107
  tpl = new PromptTemplate(model.template ?? "none");
@@ -98,12 +109,19 @@ async function executeTask(name, payload, options) {
98
109
  catch (e) {
99
110
  throw new Error(`Can not load template ${model.template}\nAvailable templates: ${Object.keys(templates)}\n`);
100
111
  }
112
+ //console.log("TPL:", tpl.id);
101
113
  hasThink = tpl.tags?.think ? true : false;
114
+ //console.log("HT", hasThink);
102
115
  }
103
116
  if (options?.debug) {
104
117
  console.log("Task model:", model);
105
118
  console.log("Task vars:", vars);
106
119
  }
120
+ //const hasTools = ex.template?.tags?.toolCall;
121
+ //console.log("EX TPL", ex.template);
122
+ //console.log("ST", thinkStart);
123
+ //console.log("ET", thinkEnd);
124
+ //let fullTxt = ""
107
125
  let emittedTokens = 0;
108
126
  const printToken = (t) => {
109
127
  if (options?.tokens === true) {
@@ -113,7 +131,13 @@ async function executeTask(name, payload, options) {
113
131
  c = !c;
114
132
  }
115
133
  else {
134
+ /*if (formatMode.value == "markdown") {
135
+ fullTxt += t;
136
+ process.stdout.write('\u001Bc\u001B[3J');
137
+ process.stdout.write(marked.parse(fullTxt) as string);*/
138
+ //} else {
116
139
  process.stdout.write(t);
140
+ //}
117
141
  }
118
142
  };
119
143
  let hasTools = false;
@@ -122,6 +146,7 @@ async function executeTask(name, payload, options) {
122
146
  hasTools = true;
123
147
  }
124
148
  }
149
+ //console.log("HAS TOOLS", hasTools);
125
150
  let continueWrite = true;
126
151
  let skipNextEmptyLinesToken = false;
127
152
  const spinner = ora("Thinking ...");
@@ -131,19 +156,30 @@ async function executeTask(name, payload, options) {
131
156
  return `${ts} ${color.bold(i.toString())} ${te}`;
132
157
  };
133
158
  const perfTimer = usePerfTimer(false);
159
+ let abort = options?.abort ? options.abort : new AbortController();
160
+ setInterval(() => {
161
+ //console.log("ABS", abort.signal.aborted);
162
+ if (abort.signal.aborted) {
163
+ agent.lm.abort();
164
+ abort = new AbortController();
165
+ }
166
+ }, 200);
134
167
  const processToken = (t) => {
135
168
  if (emittedTokens == 0) {
136
169
  perfTimer.start();
137
170
  }
138
171
  spinner.text = formatTokenCount(emittedTokens);
139
172
  if (!options?.verbose && !options?.debug) {
173
+ //console.log("TTTTTT", hasThink && tpl);
140
174
  if (hasThink && tpl) {
141
175
  if (t == tpl.tags.think?.start) {
176
+ //console.log("Start thinking token", thinkStart);
142
177
  spinner.start();
143
178
  continueWrite = false;
144
179
  return;
145
180
  }
146
181
  else if (t == tpl.tags.think?.end) {
182
+ //console.log("End thinking token", thinkEnd);
147
183
  continueWrite = true;
148
184
  skipNextEmptyLinesToken = true;
149
185
  let msg = color.dim("Thinking:") + ` ${emittedTokens} ${color.dim("tokens")}`;
@@ -163,6 +199,7 @@ async function executeTask(name, payload, options) {
163
199
  }
164
200
  }
165
201
  if (hasTools && tpl) {
202
+ // check for tool call and silence the output
166
203
  if (t == tpl.tags.toolCall?.start) {
167
204
  if (!options?.debug) {
168
205
  continueWrite = false;
@@ -200,14 +237,24 @@ async function executeTask(name, payload, options) {
200
237
  }
201
238
  ++emittedTokens;
202
239
  };
203
- const onToolCall = (tc) => {
240
+ //const spinnerInit = (name: string) => ora(`Executing the ${name} tool ...\n`);
241
+ //let tcspinner: Ora;
242
+ const _onToolCall = (tc) => {
243
+ //console.log("TC START");
204
244
  console.log("âš’ī¸ ", color.bold(name), "=>", `${color.yellowBright(tc.name)}`, tc.arguments);
205
245
  };
206
- const onToolCallEnd = (tr) => {
246
+ const onToolCall = options?.onToolCall ?? _onToolCall;
247
+ const _onToolCallEnd = (tr) => {
207
248
  if (options?.debug) {
208
249
  console.log(tr);
209
250
  }
210
251
  };
252
+ const onToolCallEnd = options?.onToolCallEnd ?? _onToolCallEnd;
253
+ const onToolsTurnStart = options?.onToolsTurnStart ?? undefined;
254
+ const onToolsTurnEnd = options?.onToolsTurnEnd ?? undefined;
255
+ const onTurnEnd = options?.onTurnEnd ?? undefined;
256
+ const onAssistant = options?.onAssistant ?? undefined;
257
+ //console.log("OOT", options?.onToken, "/", processToken);
211
258
  if (options?.onToken) {
212
259
  task.agent.lm.onToken = options.onToken;
213
260
  }
@@ -224,47 +271,73 @@ async function executeTask(name, payload, options) {
224
271
  const tconf = {
225
272
  baseDir: taskDir,
226
273
  model: model,
274
+ //debug: options?.debug ?? false,
227
275
  onToolCall: onToolCall,
228
276
  onToolCallEnd: onToolCallEnd,
277
+ onToolsTurnStart: onToolsTurnStart,
278
+ onToolsTurnEnd: onToolsTurnEnd,
279
+ onTurnEnd: onTurnEnd,
280
+ onAssistant: onAssistant,
229
281
  ...conf,
230
282
  };
283
+ if (options?.history) {
284
+ agent.history = options.history;
285
+ }
231
286
  const initialInferParams = Object.assign({}, conf.inferParams);
232
287
  initialInferParams.model = tconf.model;
288
+ //console.log("CONF", conf);
289
+ //console.log("TCONF", tconf);
290
+ //console.log("RUN", task);
233
291
  let out;
292
+ //console.log("CLI EXEC TASK", payload.prompt, "\nVARS:", vars, "\nOPTS", tconf)
234
293
  try {
235
294
  out = await task.run({ prompt: payload.prompt, ...vars }, tconf);
236
295
  }
237
296
  catch (e) {
297
+ console.log("ERR CATCH", e);
238
298
  const errMsg = `${e}`;
239
299
  if (errMsg.includes("502 Bad Gateway")) {
240
300
  runtimeError("The server answered with a 502 Bad Gateway error. It might be down or misconfigured. Check your inference server.");
241
301
  if (options?.debug) {
242
302
  throw new Error(errMsg);
243
303
  }
304
+ //@ts-ignore
244
305
  return;
245
306
  }
246
307
  else if (errMsg.includes("404 Not Found")) {
247
308
  runtimeError("The server answered with a 404 Not Found error. That might mean that the model you are requesting does not exist on the server.");
309
+ //@ts-ignore
248
310
  return;
249
311
  }
250
312
  else if (errMsg.includes("400 Bad Request")) {
251
- runtimeError("The server answered with a 400 Bad Request error. That might mean that the model you are requesting does not exist on the server or a parameter is missing in your request.");
313
+ runtimeError("The server answered with a 400 Bad Request error. That might mean that the model you are requesting does not exist on the server, a parameter is wrong or missing in your request.");
314
+ //@ts-ignore
252
315
  return;
253
316
  }
254
317
  else if (errMsg.includes("fetch failed")) {
255
318
  runtimeError("The server is not responding. Check if your inference backend is running.");
319
+ //@ts-ignore
256
320
  return;
257
321
  }
322
+ else if (e instanceof DOMException && e.name === 'AbortError') {
323
+ if (options?.debug || options?.verbose) {
324
+ console.log("The request was canceled by the user");
325
+ }
326
+ return {};
327
+ }
258
328
  else {
259
329
  throw new Error(errMsg);
260
330
  }
261
331
  }
332
+ //console.log("END TASK", out);
262
333
  if (!options?.isToolCall) {
263
334
  if (!out.answer.text.endsWith("\n")) {
264
335
  console.log();
265
336
  }
266
337
  }
338
+ //console.log("END", name, "ISCM", isChatMode.value, "isTC", options?.isToolCall)
267
339
  if (!isChatMode.value || options?.isToolCall) {
340
+ // close mcp connections
268
341
  if (options?.debug && mcpServers.length > 0) {
269
342
  console.log("Closing", mcpServers.length, "mcp server(s)");
270
343
  }
@@ -276,6 +349,8 @@ async function executeTask(name, payload, options) {
276
349
  });
277
350
  }
278
351
  await processOutput(out);
352
+ // chat mode
353
+ //console.log("CLI CONF IP", initialInferParams);
279
354
  if (!options?.isToolCall && isChatMode.value) {
280
355
  if (tpl) {
281
356
  setChatTemplate(tpl);
@@ -284,11 +359,14 @@ async function executeTask(name, payload, options) {
284
359
  options.tools = task.def.tools;
285
360
  }
286
361
  if (task.def.shots) {
287
- options.history = task.def.shots;
362
+ options.history = options?.history ? [...options.history, ...task.def.shots] : task.def.shots;
288
363
  }
289
364
  if (task.def.template?.system) {
290
365
  options.system = task.def.template.system;
291
366
  }
367
+ /*if (task.def.template?.afterSystem) {
368
+ options.system = (tpl?.system ?? "") + task.def.template.afterSystem
369
+ }*/
292
370
  if (task.def.template?.assistant) {
293
371
  options.assistant = task.def.template.assistant;
294
372
  }
@@ -298,6 +376,7 @@ async function executeTask(name, payload, options) {
298
376
  if (options?.debug === true || options?.verbose === true) {
299
377
  try {
300
378
  console.log(emittedTokens.toString(), color.dim("tokens"), out.answer.stats.tokensPerSecond, color.dim("tps"));
379
+ //console.log("\n", formatStats(out.answer.stats))
301
380
  if (options?.debug === true) {
302
381
  console.log(out.answer.stats);
303
382
  }
@@ -307,13 +386,19 @@ async function executeTask(name, payload, options) {
307
386
  }
308
387
  }
309
388
  if (options?.backend || settings?.backend) {
389
+ //console.log("SET BACK AGENT BACKEND TO", backend.value);
390
+ // set back the default backend
310
391
  agent.lm = backend.value;
311
392
  }
393
+ //console.log("TASK OUT", out);
312
394
  return out;
313
395
  }
314
396
  async function executeTaskCmd(name, targs = []) {
315
397
  const ca = parseCommandArgs(targs);
398
+ //console.log("ARGS", ca);
316
399
  const prompt = await getTaskPrompt(name, ca.args, ca.options);
317
- return await executeTask(name, { prompt: prompt }, ca.options);
400
+ const tr = await executeTask(name, { prompt: prompt }, ca.options);
401
+ //console.log("TR", tr);
402
+ return tr;
318
403
  }
319
404
  export { executeTask, executeTaskCmd };
@@ -8,6 +8,10 @@ function guessTemplate(modelname) {
8
8
  return gt;
9
9
  }
10
10
  function configureTaskModel(itConf, taskSpec) {
11
+ //console.log("IT CONF", itConf);
12
+ //console.log("TASK SPEC", taskSpec);
13
+ //let modelName: string = "";
14
+ //let templateName: string = "";
11
15
  let ip = itConf.inferParams;
12
16
  let isModelFromTaskFile = false;
13
17
  let model = { template: "", name: "" };
@@ -35,12 +39,15 @@ function configureTaskModel(itConf, taskSpec) {
35
39
  }
36
40
  if (itConf?.model?.name) {
37
41
  if (taskSpec?.models && Object.keys(taskSpec.models).includes(itConf.model.name)) {
42
+ // try to find the model from the task's models
38
43
  for (const [k, v] of Object.entries(taskSpec.models)) {
44
+ //console.log("TSM", modelName, "/", k);
39
45
  if (k == itConf.model.name) {
40
46
  model = v;
41
47
  if (v?.inferParams) {
42
48
  const tip = v.inferParams;
43
49
  for (const [k, v] of Object.entries(tip)) {
50
+ // @ts-ignore
44
51
  ip[k] = v;
45
52
  }
46
53
  }
@@ -68,12 +75,39 @@ function configureTaskModel(itConf, taskSpec) {
68
75
  model = taskSpec.model;
69
76
  foundModel = true;
70
77
  }
78
+ // try to find the models from db models
79
+ /*if (!found) {
80
+ const m = readModel(modelName);
81
+ //console.log("FM", m.found, m)
82
+ //console.log("DBM", templateName, "/", m.modelData.template);
83
+ if (m.found) {
84
+ model = m.modelData as ModelSpec;
85
+ model.template = templateName ?? m.modelData.template;
86
+ found = true
87
+ }
88
+ }*/
89
+ // fallback to use the model name directly
71
90
  if (!foundModel) {
72
91
  throw new Error(`No model found in task`);
73
92
  }
93
+ /*if (!foundTemplate) {
94
+ // try to guess the template
95
+ const gt = tfm.guess(model.name);
96
+ if (gt == "none") {
97
+ throw new Error(`Unable to guess the template for ${model.name}: please provide a template name: --tpl templatename`)
98
+ }
99
+ model.template = gt;
100
+ foundTemplate = true;
101
+ }
102
+ if (!model?.template) {
103
+ throw new Error(`No template found`)
104
+ }*/
105
+ //model.inferParams = ip;
106
+ // use default ctx if the model is not from defined in the task file
74
107
  if (!model?.ctx || !isModelFromTaskFile) {
75
108
  model.ctx = taskSpec.ctx;
76
109
  }
110
+ //model.inferParams = ip;
77
111
  return model;
78
112
  }
79
113
  function mergeConfOptions(conf, options) {
@@ -88,6 +122,7 @@ function mergeConfOptions(conf, options) {
88
122
  }
89
123
  function mergeInferParams(userInferParams, taskInferParams) {
90
124
  const ip = taskInferParams;
125
+ //console.log("IP", ip);
91
126
  for (const [k, v] of Object.entries(userInferParams)) {
92
127
  ip[k] = v;
93
128
  }
@@ -18,6 +18,7 @@ async function readTask(name, payload, options, agent) {
18
18
  }
19
19
  const { taskFileSpec, taskPath } = openTaskSpec(name, options?.isAgent);
20
20
  const taskDir = path.dirname(taskPath);
21
+ // merge passed options from payload
21
22
  const opts = payload?.inferParams ? { ...options, ...payload.inferParams } : options;
22
23
  const conf = parseTaskConfigOptions(opts);
23
24
  if (options?.debug) {
@@ -29,6 +30,7 @@ async function readTask(name, payload, options, agent) {
29
30
  if (options?.ctx) {
30
31
  model.ctx = options.ctx;
31
32
  }
33
+ // vars
32
34
  const taskSpec = taskFileSpec;
33
35
  let vars = {};
34
36
  if (taskSpec?.variables?.optional) {
@@ -43,6 +45,7 @@ async function readTask(name, payload, options, agent) {
43
45
  }
44
46
  if (taskSpec?.variables?.required) {
45
47
  for (const k of Object.keys(taskSpec.variables.required)) {
48
+ //console.log("TASK V required:", Object.keys(taskSpec.variables.required), "/", k in options, "/", k in payload);
46
49
  if (k in options) {
47
50
  vars[k] = options[k];
48
51
  }
@@ -71,8 +74,10 @@ async function readTask(name, payload, options, agent) {
71
74
  console.log("Opening", options.mcp.length, "server(s)");
72
75
  }
73
76
  }
77
+ // mcp tools
74
78
  if (taskFileSpec?.mcp) {
75
79
  for (const [servername, tool] of Object.entries(taskFileSpec.mcp)) {
80
+ //console.log("MCP TOOL:", tool)
76
81
  const authorizedTools = new Array();
77
82
  const askUserTools = new Array();
78
83
  if (tool?.tools) {
@@ -90,9 +95,15 @@ async function readTask(name, payload, options, agent) {
90
95
  margs.push(...mcpServersArgs[servername]);
91
96
  }
92
97
  const mcp = new McpClient(servername, tool.command, tool.arguments, authorizedTools.length > 0 ? authorizedTools : null, askUserTools.length > 0 ? askUserTools : null);
98
+ //console.log("MCP", mcp);
93
99
  mcpServers.push(mcp);
100
+ /*await mcp.start();
101
+ const tools = await mcp.extractTools();
102
+ tools.forEach(t => taskSpec.tools?.push(t))*/
94
103
  }
95
104
  }
105
+ // tools
106
+ //console.log("Task tools list:", taskSpec.toolsList);
96
107
  if (taskSpec.toolsList) {
97
108
  for (const rawToolName of taskSpec.toolsList) {
98
109
  let toolName = rawToolName;
@@ -105,10 +116,12 @@ async function readTask(name, payload, options, agent) {
105
116
  if (!found) {
106
117
  throw new Error(`tool ${toolName} not found for task ${taskSpec.name}`);
107
118
  }
119
+ //console.log("Tool found:", toolName, tool);
108
120
  const quiet = !options?.debug;
109
121
  const lmTool = {
110
122
  ...tool,
111
123
  execute: async (params) => {
124
+ //console.log("EXEC TOOL:", type, toolName, params);
112
125
  switch (type) {
113
126
  case "action":
114
127
  const res = await executeAction(toolName, params, options, quiet);
@@ -118,6 +131,7 @@ async function readTask(name, payload, options, agent) {
118
131
  options.isAgent = false;
119
132
  const tres = await executeTask(toolName, params, options);
120
133
  options.isToolCall = false;
134
+ //console.log("WFTRESP", tres.answer.text);
121
135
  return tres.answer.text;
122
136
  case "agent":
123
137
  options.isToolCall = true;
@@ -125,6 +139,7 @@ async function readTask(name, payload, options, agent) {
125
139
  const agres = await executeTask(toolName, params, options);
126
140
  options.isAgent = false;
127
141
  options.isToolCall = false;
142
+ //console.log("WFTRESP", tres.answer.text);
128
143
  if (agres?.answer?.text) {
129
144
  return agres.answer.text;
130
145
  }
@@ -140,18 +155,32 @@ async function readTask(name, payload, options, agent) {
140
155
  }
141
156
  };
142
157
  if (!autoRunTool) {
143
- lmTool.canRun = confirmToolUsage;
158
+ lmTool.canRun = options?.confirmToolUsage ?
159
+ options.confirmToolUsage :
160
+ confirmToolUsage;
144
161
  }
145
162
  taskSpec.tools.push(lmTool);
146
163
  }
147
164
  delete taskSpec.toolsList;
148
165
  }
149
166
  ;
167
+ if (options?.chatMode) {
168
+ taskSpec.prompt = "{prompt}";
169
+ }
170
+ //console.log("TASK SPEC:", JSON.stringify(taskSpec, null, " "));
150
171
  const task = new NodeTask(agent, taskSpec);
172
+ //task.addTools(taskSpec.tools);
173
+ //console.log("TASK TOOLS", task.agent.tools);
174
+ // check for grammars
151
175
  if (model?.inferParams?.tsGrammar) {
176
+ //console.log("TSG");
152
177
  model.inferParams.grammar = serializeGrammar(await compile(model.inferParams.tsGrammar, "Grammar"));
153
178
  delete model.inferParams.tsGrammar;
154
179
  }
180
+ /*if (options?.debug) {
181
+ console.log("Task model:", model);
182
+ //console.log("Task vars:", vars);
183
+ }*/
155
184
  return { task, model, conf, vars, mcpServers, taskDir };
156
185
  }
157
186
  export { readTask };
@@ -2,15 +2,16 @@ import YAML from 'yaml';
2
2
  import * as fs from 'fs';
3
3
  import { readYmlFile } from '../sys/read_yml_file.js';
4
4
  import { confirm } from '@inquirer/prompts';
5
+ import colors from "ansi-colors";
5
6
  async function confirmToolUsage(toolCall) {
6
- let args;
7
+ console.log("Tool call:", colors.bold(toolCall.name));
7
8
  if (toolCall?.arguments) {
8
- args = `with arguments ${JSON.stringify(toolCall.arguments)}`;
9
+ console.log("Arguments:", toolCall.arguments);
9
10
  }
10
11
  else {
11
- args = "with no arguments";
12
+ console.log("No arguments");
12
13
  }
13
- return await confirm({ message: `Execute tool ${toolCall.name} ${args}?` });
14
+ return await confirm({ message: `Execute tool ${toolCall.name}?` });
14
15
  }
15
16
  function _extractToolDoc(filePath, startComment, endComment) {
16
17
  try {
@@ -50,6 +51,7 @@ function _extractJsToolDoc(filePath) {
50
51
  }
51
52
  function _extractYamlToolDoc(filePath, name) {
52
53
  const { data, found } = readYmlFile(filePath);
54
+ //console.log("_extractYamlToolDoc from", name, data?.tool);
53
55
  if (!found) {
54
56
  return { found: false, tspec: {} };
55
57
  }
@@ -63,6 +65,7 @@ function _parseToolDoc(rawTxt, name) {
63
65
  try {
64
66
  const res = YAML.parse(rawTxt);
65
67
  res["name"] = name;
68
+ //console.log("PARSE TOOL DOC", res);
66
69
  return res;
67
70
  }
68
71
  catch (e) {
@@ -85,6 +88,7 @@ function extractTaskToolDocAndVariables(name, ext, dirPath) {
85
88
  const fp = dirPath + "/" + name + "." + ext;
86
89
  const { data, found } = readYmlFile(fp);
87
90
  const res = { variables: { required: new Array(), optional: new Array() }, toolDoc: "" };
91
+ // tools
88
92
  let tspec;
89
93
  if (!found) {
90
94
  throw new Error(`extractTaskToolDocAndVariables: file ${fp} not found`);
@@ -94,6 +98,7 @@ function extractTaskToolDocAndVariables(name, ext, dirPath) {
94
98
  tspec = data.tool;
95
99
  res.toolDoc = JSON.stringify(tspec, null, " ");
96
100
  }
101
+ // variables
97
102
  const { required, optional } = _parseTaskVariables(data);
98
103
  res.variables.required = required;
99
104
  res.variables.optional = optional;
@@ -122,6 +127,7 @@ function extractToolDoc(name, ext, dirPath) {
122
127
  break;
123
128
  default:
124
129
  return { found: false, toolDoc: "" };
130
+ //throw new Error(`Unknown tool doc feature type`)
125
131
  }
126
132
  if (found) {
127
133
  let ts;
@@ -1,17 +1,18 @@
1
- import { exit } from "process";
2
1
  import chalk from 'chalk';
3
2
  function runtimeError(...msg) {
4
3
  console.warn("đŸ’Ĩ", chalk.dim("Runtime error:"), ...msg);
5
- exit(1);
4
+ //exit(1)
6
5
  }
7
6
  function runtimeWarning(...msg) {
8
7
  console.warn("âš ī¸", chalk.dim("Runtime warning:"), ...msg);
8
+ //exit(1)
9
9
  }
10
10
  function runtimeDataError(...msg) {
11
11
  console.warn("❌", chalk.dim("Runtime data error:"), ...msg);
12
- exit(1);
12
+ //exit(1)
13
13
  }
14
14
  function runtimeInfo(...msg) {
15
+ //console.log("â„šī¸ ", chalk.dim("Info:"), ...msg);
15
16
  console.log("đŸ“Ģ", chalk.dim("Info:"), ...msg);
16
17
  }
17
18
  export { runtimeError, runtimeWarning, runtimeDataError, runtimeInfo, };
@@ -11,10 +11,13 @@ function readPromptFile() {
11
11
  return readFile(promptfilePath.value);
12
12
  }
13
13
  async function processOutput(res) {
14
+ //if (!(outputMode.value == "clipboard")) { return }
14
15
  let data = "";
16
+ //console.log("Process OUTPUT", typeof res);
15
17
  let hasTextData = false;
16
18
  if (typeof res == "object") {
17
19
  if (res?.answer?.text) {
20
+ //console.log("****************** TPL", res?.answer?.template);
18
21
  if (res?.template?.tags?.think) {
19
22
  const { finalAnswer } = splitThinking(res.answer.text, res.template.tags.think.start, res.template.tags.think.end);
20
23
  data = finalAnswer;
@@ -36,7 +39,9 @@ async function processOutput(res) {
36
39
  else {
37
40
  data = res;
38
41
  }
42
+ //onsole.log("OUTPUT", typeof res, data);
39
43
  if (outputMode.value == "clipboard") {
44
+ //console.log("Writing to kb", data)
40
45
  await writeToClipboard(data);
41
46
  }
42
47
  if (hasTextData) {
@@ -22,6 +22,7 @@ async function executeWorkflow(wname, args, options = {}) {
22
22
  let i = 0;
23
23
  const finalTaskIndex = stepNames.length - 1;
24
24
  let taskRes = { cmdArgs: args };
25
+ //console.log("WPARAMS", taskRes);
25
26
  let prevStepType = null;
26
27
  for (const step of workflow) {
27
28
  if (isDebug || isVerbose) {
@@ -93,6 +94,8 @@ async function executeWorkflow(wname, args, options = {}) {
93
94
  break;
94
95
  case "action":
95
96
  try {
97
+ //console.log("EXEC ACTION ARGS", taskRes);
98
+ //const actArgs = i == 0 ? taskRes.cmdArgs : taskRes;
96
99
  let actArgs;
97
100
  if (i == 0) {
98
101
  actArgs = taskRes.cmdArgs;
@@ -105,12 +108,15 @@ async function executeWorkflow(wname, args, options = {}) {
105
108
  actArgs = taskRes;
106
109
  }
107
110
  const ares = await executeAction(step.name, actArgs, options, true);
111
+ //console.log("WF ACTION RES", typeof ares, ares);
112
+ //console.log("LAST ACT", i, finalTaskIndex);
108
113
  if (i == finalTaskIndex && !options?.isToolCall && !options?.quiet) {
109
114
  console.log(ares);
110
115
  break;
111
116
  }
112
117
  if (typeof ares == "string" || Array.isArray(ares)) {
113
118
  taskRes.args = ares;
119
+ //console.log("ARRAY ACTION RES", taskRes)
114
120
  }
115
121
  else {
116
122
  taskRes = { ...ares, ...taskRes };
@@ -122,9 +128,13 @@ async function executeWorkflow(wname, args, options = {}) {
122
128
  break;
123
129
  case "adaptater":
124
130
  try {
131
+ //console.log("WF AD ARGS IN", taskRes);
132
+ //console.log("AD OPTS IN", options);
125
133
  let actArgs;
126
134
  if (i == 0) {
135
+ //console.log("TR", taskRes);
127
136
  actArgs = taskRes.cmdArgs;
137
+ //console.log("ACT ARGS", actArgs);
128
138
  const inputData = await getInputFromOptions(options);
129
139
  if (inputData) {
130
140
  actArgs.push(inputData);
@@ -134,16 +144,21 @@ async function executeWorkflow(wname, args, options = {}) {
134
144
  actArgs = taskRes;
135
145
  }
136
146
  const adres = await executeAdaptater(step.name, actArgs, options);
147
+ //console.log("WF AD FINAL RES", taskRes);
148
+ //console.log("LAST ACT", i, finalTaskIndex);
137
149
  if (i == finalTaskIndex && !options?.isToolCall && !options?.quiet) {
138
150
  console.log(adres);
139
151
  break;
140
152
  }
153
+ //console.log("WF AD RES", typeof adres, adres);
141
154
  if (typeof adres == "string" || Array.isArray(adres)) {
142
155
  taskRes.args = adres;
156
+ //console.log("WF AD IT RES", taskRes);
143
157
  }
144
158
  else {
145
159
  taskRes = { ...adres };
146
160
  }
161
+ //console.log("WF ADAPT RES", typeof ares, Array.isArray(ares) ? ares.length : "NA");
147
162
  }
148
163
  catch (e) {
149
164
  throw new Error(`workflow adaptater ${i + 1}: ${e}`);
@@ -156,7 +171,7 @@ async function executeWorkflow(wname, args, options = {}) {
156
171
  throw new Error(`Command ${step.name} not found`);
157
172
  }
158
173
  const url = pathToFileURL(path).href;
159
- const jsa = await import(url);
174
+ const jsa = await import(/* @vite-ignore */ url);
160
175
  if (!jsa?.runCmd) {
161
176
  runtimeError(`workflow ${wname}: can not import the runCmd function from step ${i} for command ${step.name}: please add a runCmd function export`);
162
177
  return;
@@ -188,12 +203,20 @@ async function executeWorkflow(wname, args, options = {}) {
188
203
  throw new Error(`unknown workflow step type ${step.type} in workflow ${wname}`);
189
204
  }
190
205
  prevStepType = step.type;
206
+ //console.log("WF NODE RES", step.type, taskRes);
207
+ /*if (isDebug) {
208
+ console.log("->", params);
209
+ }*/
210
+ //console.log("WFR", taskRes)
191
211
  ++i;
192
212
  }
193
213
  return taskRes;
194
214
  }
195
215
  async function executeWorkflowCmd(name, wargs) {
216
+ //console.log("WF INITIAL ARGS", typeof wargs, wargs.slice(0, -1));
196
217
  const { args, options } = parseCommandArgs(wargs);
218
+ //console.log("WF ARGS", typeof args, args);
219
+ //console.log("WF OPTS", options);
197
220
  return await executeWorkflow(name, args, options);
198
221
  }
199
222
  export { executeWorkflow, executeWorkflowCmd };