@saltcorn/agents 0.6.8 → 0.6.9

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/agent-view.js CHANGED
@@ -32,6 +32,7 @@ const {
32
32
  a,
33
33
  br,
34
34
  img,
35
+ text,
35
36
  } = require("@saltcorn/markup/tags");
36
37
  const { getState } = require("@saltcorn/data/db/state");
37
38
  const {
@@ -50,7 +51,7 @@ const {
50
51
  } = require("./common");
51
52
  const MarkdownIt = require("markdown-it"),
52
53
  md = new MarkdownIt();
53
- const { isWeb } = require("@saltcorn/data/utils");
54
+ const { isWeb, escapeHtml } = require("@saltcorn/data/utils");
54
55
  const path = require("path");
55
56
 
56
57
  const configuration_workflow = (req) =>
@@ -240,7 +241,7 @@ const run = async (
240
241
  state,
241
242
  { res, req },
242
243
  ) => {
243
- const action = agent_action || await Trigger.findOne({ id: action_id });
244
+ const action = agent_action || (await Trigger.findOne({ id: action_id }));
244
245
  if (!action) throw new Error(`Action not found: ${action_id}`);
245
246
  const prevRuns = show_prev_runs
246
247
  ? (
@@ -820,7 +821,8 @@ const run = async (
820
821
 
821
822
  const interact = async (table_id, viewname, config, body, { req, res }) => {
822
823
  const { userinput, run_id, triggering_row_id } = body;
823
- const action = config.agent_action || await Trigger.findOne({ id: config.action_id });
824
+ const action =
825
+ config.agent_action || (await Trigger.findOne({ id: config.action_id }));
824
826
 
825
827
  let run;
826
828
  let triggering_row;
@@ -951,7 +953,8 @@ const delprevrun = async (table_id, viewname, config, body, { req, res }) => {
951
953
 
952
954
  const debug_info = async (table_id, viewname, config, body, { req, res }) => {
953
955
  const { run_id, triggering_row_id } = body;
954
- const action = config.agent_action || await Trigger.findOne({ id: config.action_id });
956
+ const action =
957
+ config.agent_action || (await Trigger.findOne({ id: config.action_id }));
955
958
  let triggering_row;
956
959
  if (table_id && triggering_row_id) {
957
960
  const table = Table.findOne(table_id);
@@ -974,10 +977,12 @@ const debug_info = async (table_id, viewname, config, body, { req, res }) => {
974
977
  sysPrompt = complArgs.systemPrompt;
975
978
  }
976
979
  const debug_html = div(
977
- div(h4("System prompt"), pre(sysPrompt)),
980
+ div(h4("System prompt"), pre(text(escapeHtml(sysPrompt)))),
978
981
  div(
979
982
  h4("API interactions"),
980
- pre(JSON.stringify(run.context.api_interactions, null, 2)),
983
+ pre(
984
+ text(escapeHtml(JSON.stringify(run.context.api_interactions, null, 2))),
985
+ ),
981
986
  ),
982
987
  );
983
988
  if (run && req.user?.role_id === 1)
@@ -993,7 +998,8 @@ const debug_info = async (table_id, viewname, config, body, { req, res }) => {
993
998
 
994
999
  const skillroute = async (table_id, viewname, config, body, { req, res }) => {
995
1000
  const { run_id, triggering_row_id, skillid } = body;
996
- const action = config.agent_action || await Trigger.findOne({ id: config.action_id });
1001
+ const action =
1002
+ config.agent_action || (await Trigger.findOne({ id: config.action_id }));
997
1003
  let triggering_row;
998
1004
  if (table_id && triggering_row_id) {
999
1005
  const table = Table.findOne(table_id);
@@ -1030,7 +1036,8 @@ const execute_user_action = async (
1030
1036
  ) => {
1031
1037
  const { run_id, rndid, uaname } = body;
1032
1038
 
1033
- const action = config.agent_action || await Trigger.findOne({ id: config.action_id });
1039
+ const action =
1040
+ config.agent_action || (await Trigger.findOne({ id: config.action_id }));
1034
1041
  const run = await WorkflowRun.findOne({ id: +run_id });
1035
1042
  //console.log("run uas",run.context.user_actions );
1036
1043
 
package/common.js CHANGED
@@ -431,7 +431,7 @@ const process_interaction = async (
431
431
  { role: "system", content: postprocres.add_system_prompt },
432
432
  ],
433
433
  });
434
- if (postprocres.add_response)
434
+ if (postprocres.add_response) {
435
435
  add_response(
436
436
  wrapSegment(
437
437
  wrapCard(
@@ -441,6 +441,26 @@ const process_interaction = async (
441
441
  agent_label,
442
442
  ),
443
443
  );
444
+ //replace tool response with this
445
+ // run.context.interactions.forEach((ic) => {});
446
+ const result = postprocres.add_response;
447
+ await sysState.functions.llm_add_message.run(
448
+ "tool_response",
449
+ !result || typeof result === "string"
450
+ ? {
451
+ type: "text",
452
+ value: result || "Action run",
453
+ }
454
+ : {
455
+ type: "json",
456
+ value: JSON.parse(JSON.stringify(result)),
457
+ },
458
+ {
459
+ chat: run.context.interactions,
460
+ tool_call,
461
+ },
462
+ );
463
+ }
444
464
  if (postprocres.add_user_action && viewname) {
445
465
  const user_actions = Array.isArray()
446
466
  ? postprocres.add_user_action
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@saltcorn/agents",
3
- "version": "0.6.8",
3
+ "version": "0.6.9",
4
4
  "description": "AI agents for Saltcorn",
5
5
  "main": "index.js",
6
6
  "dependencies": {
@@ -141,7 +141,7 @@ Now generate the JavaScript code required by the user.`,
141
141
  //console.log("code response", res);
142
142
 
143
143
  return {
144
- stop: true,
144
+ //stop: true,
145
145
  add_response: res,
146
146
  };
147
147
  },