@saltcorn/agents 0.7.8 → 0.7.10

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/common.js CHANGED
@@ -40,6 +40,7 @@ const get_skills = () => {
40
40
  require("./skills/Fetch"),
41
41
  require("./skills/WebSearch"),
42
42
  require("./skills/Subagent"),
43
+ require("./skills/ExternalSkill"),
43
44
  //require("./skills/AdaptiveFeedback"),
44
45
  ...exchange_skills,
45
46
  ];
@@ -245,16 +246,16 @@ const process_interaction = async (
245
246
  const sysState = getState();
246
247
  const complArgs = await getCompletionArguments(
247
248
  config,
248
- req.user,
249
+ req?.user,
249
250
  triggering_row,
250
- req.body,
251
+ req?.body,
251
252
  );
252
253
  complArgs.appendToChat = true;
253
254
  complArgs.chat = run.context.interactions;
254
255
  const use_alt_config = complArgs.alt_config;
255
256
  //complArgs.debugResult = true;
256
257
  //console.log("complArgs", JSON.stringify(complArgs, null, 2));
257
- const debugMode = is_debug_mode(config, req.user);
258
+ const debugMode = is_debug_mode(config, req?.user);
258
259
  const debugCollector = {};
259
260
  if (debugMode) complArgs.debugCollector = debugCollector;
260
261
  if (stream && viewname) {
@@ -265,10 +266,11 @@ const process_interaction = async (
265
266
  ? response
266
267
  : response.choices[0].content || response.choices[0].delta?.content;
267
268
  if (content) {
268
- const pageLoadTag = req.body.page_load_tag;
269
- view.emitRealTimeEvent(`STREAM_CHUNK?page_load_tag=${pageLoadTag}`, {
270
- content,
271
- });
269
+ const pageLoadTag = req?.body?.page_load_tag;
270
+ if (pageLoadTag)
271
+ view.emitRealTimeEvent(`STREAM_CHUNK?page_load_tag=${pageLoadTag}`, {
272
+ content,
273
+ });
272
274
  }
273
275
  };
274
276
  }
@@ -303,7 +305,7 @@ const process_interaction = async (
303
305
  eval_js: `processCopilotResponse({response: ${JSON.stringify(resp)}, run_id: ${run.id}}, true)`,
304
306
  page_load_tag: req?.headers?.["page-load-tag"],
305
307
  },
306
- [req.user.id],
308
+ [req?.user?.id],
307
309
  );
308
310
  else responses.push(resp);
309
311
  await addToContext(run, {
@@ -342,7 +344,7 @@ const process_interaction = async (
342
344
  }
343
345
  if (answer.content && !answer.tool_calls)
344
346
  add_response(
345
- req.disable_markdown_render
347
+ req?.disable_markdown_render
346
348
  ? answer
347
349
  : wrapSegment(md.render(answer.content), agent_label, false, layout),
348
350
  );
@@ -355,7 +357,7 @@ const process_interaction = async (
355
357
  ) {
356
358
  if (answer.content)
357
359
  add_response(
358
- req.disable_markdown_render
360
+ req?.disable_markdown_render
359
361
  ? answer
360
362
  : wrapSegment(md.render(answer.content), agent_label, false, layout),
361
363
  );
@@ -383,13 +385,14 @@ const process_interaction = async (
383
385
  (tool.skill.skill_label || tool.skill.constructor.skill_name) +
384
386
  " ";
385
387
  const view = View.findOne({ name: viewname });
386
- const pageLoadTag = req.body.page_load_tag;
387
- view.emitRealTimeEvent(
388
- `STREAM_CHUNK?page_load_tag=${pageLoadTag}`,
389
- {
390
- content,
391
- },
392
- );
388
+ const pageLoadTag = req?.body?.page_load_tag;
389
+ if (pageLoadTag)
390
+ view.emitRealTimeEvent(
391
+ `STREAM_CHUNK?page_load_tag=${pageLoadTag}`,
392
+ {
393
+ content,
394
+ },
395
+ );
393
396
  }
394
397
  const response_label = is_sub_agent
395
398
  ? agent_label
@@ -411,11 +414,11 @@ const process_interaction = async (
411
414
  );
412
415
  }
413
416
  myHasResult = true;
414
- const result = await tool.tool.process(tool_call.input, {
417
+ let result = await tool.tool.process(tool_call.input, {
415
418
  req,
416
- });
419
+ });
417
420
  toolResults[tool_call.tool_call_id] = result;
418
- if (result.stop) stop = true;
421
+ if (result?.stop) stop = true;
419
422
  if (
420
423
  (typeof result === "object" && Object.keys(result || {}).length) ||
421
424
  typeof result === "string"
@@ -469,7 +472,7 @@ const process_interaction = async (
469
472
  let stop = false,
470
473
  myHasResult = false;
471
474
  if (tool.tool.postProcess && !stop) {
472
- let result = toolResults[tool_call.tool_call_id];
475
+ let result = toolResults[tool_call.tool_call_id];
473
476
  const response_label = is_sub_agent
474
477
  ? agent_label
475
478
  : tool.skill.skill_label || tool.skill.constructor.skill_name;
@@ -477,9 +480,9 @@ const process_interaction = async (
477
480
  let generateUsed = false;
478
481
  const systemPrompt = await getSystemPrompt(
479
482
  config,
480
- req.user,
483
+ req?.user,
481
484
  triggering_row,
482
- req.body,
485
+ req?.body,
483
486
  );
484
487
  const postprocres = await tool.tool.postProcess({
485
488
  tool_call,
@@ -502,13 +505,14 @@ const process_interaction = async (
502
505
  emit_update(s) {
503
506
  if (!stream || !viewname) return;
504
507
  const view = View.findOne({ name: viewname });
505
- const pageLoadTag = req.body.page_load_tag;
506
- view.emitRealTimeEvent(
507
- `STREAM_CHUNK?page_load_tag=${pageLoadTag}`,
508
- {
509
- content: s + " ",
510
- },
511
- );
508
+ const pageLoadTag = req?.body?.page_load_tag;
509
+ if (pageLoadTag)
510
+ view.emitRealTimeEvent(
511
+ `STREAM_CHUNK?page_load_tag=${pageLoadTag}`,
512
+ {
513
+ content: s + " ",
514
+ },
515
+ );
512
516
  },
513
517
  });
514
518
  if (generateUsed)
@@ -645,7 +649,7 @@ const process_interaction = async (
645
649
  );
646
650
  } else if (typeof answer === "string")
647
651
  add_response(
648
- req.disable_markdown_render
652
+ req?.disable_markdown_render
649
653
  ? answer
650
654
  : wrapSegment(md.render(answer), agent_label, false, layout),
651
655
  );
@@ -656,7 +660,7 @@ const process_interaction = async (
656
660
  eval_js: `final_agent_response()`,
657
661
  page_load_tag: req?.headers?.["page-load-tag"],
658
662
  },
659
- [req.user.id],
663
+ [req?.user?.id],
660
664
  );
661
665
 
662
666
  return {
package/index.js CHANGED
@@ -25,13 +25,13 @@ module.exports = {
25
25
  script: `/plugins/public/agents@${
26
26
  require("./package.json").version
27
27
  }/markdown-it.min.js`,
28
- onlyViews: ["Agent Chat"],
28
+ onlyViews: ["Agent Chat", "Saltcorn Agent copilot"],
29
29
  },
30
30
  {
31
31
  script: `/plugins/public/agents@${
32
32
  require("./package.json").version
33
33
  }/jquery.autogrow-textarea.js`,
34
- onlyViews: ["Agent Chat"],
34
+ onlyViews: ["Agent Chat", "Saltcorn Agent copilot"],
35
35
  },
36
36
  ],
37
37
  actions: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@saltcorn/agents",
3
- "version": "0.7.8",
3
+ "version": "0.7.10",
4
4
  "description": "AI agents for Saltcorn",
5
5
  "main": "index.js",
6
6
  "dependencies": {
@@ -0,0 +1,38 @@
1
+ const path = require("path");
2
+ const fs = require("fs").promises;
3
+
4
+ class ExternalSkill {
5
+ static skill_name = "External Skill (SKILL.md)";
6
+
7
+ get skill_label() {
8
+ return "External Skill";
9
+ }
10
+
11
+ constructor(cfg) {
12
+ Object.assign(this, cfg);
13
+ }
14
+
15
+ static async configFields() {
16
+ return [
17
+ {
18
+ name: "skills_dir",
19
+ label: "Skill directory",
20
+ type: "String",
21
+ required: true,
22
+ sublabel: "Path to the directory containing SKILL.md",
23
+ },
24
+ ];
25
+ }
26
+
27
+ async systemPrompt() {
28
+ if (!this.skills_dir) return;
29
+ const skillMdPath = path.join(this.skills_dir, "SKILL.md");
30
+ try {
31
+ return await fs.readFile(skillMdPath, "utf8");
32
+ } catch (e) {
33
+ return `[ExternalSkill: could not read ${skillMdPath}: ${e.message}]`;
34
+ }
35
+ }
36
+ }
37
+
38
+ module.exports = ExternalSkill;
@@ -304,13 +304,14 @@ const getTablePrompt = (read_only) => {
304
304
  const state = getState();
305
305
  const tables = state.tables;
306
306
  const tableLines = [];
307
- tables.forEach((table) => {
307
+ tables.map(t=>new Table(t)).forEach((table) => {
308
308
  const fieldLines = table.fields.map(
309
309
  (f) =>
310
- ` * ${f.name} with type: ${f.pretty_type.replace(
311
- "Key to",
312
- "ForeignKey referencing",
313
- )}.${f.description ? ` ${f.description}` : ""}`,
310
+ ` * ${f.name} with type: ${
311
+ f?.pretty_type
312
+ ? f.pretty_type.replace("Key to", "ForeignKey referencing")
313
+ : "Unknown"
314
+ }.${f?.description ? ` ${f.description}` : ""}`,
314
315
  );
315
316
  tableLines.push(
316
317
  `${table.name}${