@saltcorn/agents 0.7.11 → 0.7.12

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
@@ -61,6 +61,14 @@ const configuration_workflow = (req) =>
61
61
  {
62
62
  name: "Agent action",
63
63
  form: async (context) => {
64
+ let run_id_field_opts;
65
+ if (context.table_id) {
66
+ const table = Table.findOne({ id: context.table_id });
67
+ run_id_field_opts = table.fields
68
+ .filter((f) => f.type?.name === "Integer" && !f.primary_key)
69
+ .map((f) => f.name);
70
+ }
71
+
64
72
  const agent_actions = await Trigger.find({ action: "Agent" });
65
73
  return new Form({
66
74
  fields: [
@@ -114,6 +122,17 @@ const configuration_workflow = (req) =>
114
122
  sublabel:
115
123
  "Appears below the input box. Use for additional instructions.",
116
124
  },
125
+ ...(run_id_field_opts
126
+ ? [
127
+ {
128
+ name: "run_id_field",
129
+ type: "String",
130
+ label: "Run ID field",
131
+ sublabel: "Set this field to the run ID",
132
+ attributes: { options: run_id_field_opts },
133
+ },
134
+ ]
135
+ : []),
117
136
  {
118
137
  name: "layout",
119
138
  label: "Layout",
@@ -1158,6 +1177,14 @@ const interact = async (table_id, viewname, config, body, { req, res }) => {
1158
1177
  triggering_row_id,
1159
1178
  },
1160
1179
  });
1180
+ if (table_id && config.run_id_field && triggering_row_id) {
1181
+ const table = Table.findOne(table_id);
1182
+ await table.updateRow(
1183
+ { [config.run_id_field]: run.id },
1184
+ triggering_row_id,
1185
+ );
1186
+ if (triggering_row) triggering_row[config.run_id_field] = run.id;
1187
+ }
1161
1188
  } else {
1162
1189
  run = await WorkflowRun.findOne({ id: +run_id });
1163
1190
  }
@@ -1447,6 +1474,30 @@ const execute_user_action = async (
1447
1474
  });
1448
1475
  const dyn_updates = getState().getConfig("enable_dynamic_updates", true);
1449
1476
 
1477
+ if (dyn_updates && uadata.click_replace_text) {
1478
+ getState().emitDynamicUpdate(
1479
+ db.getTenantSchema(),
1480
+ {
1481
+ eval_js: `spin_send_button();${`$("button[data-useraction-id=${uadata.rndid}]").replaceWith("${uadata.click_replace_text}")`}`,
1482
+ page_load_tag: req?.headers?.["page-load-tag"],
1483
+ },
1484
+ [req.user.id],
1485
+ );
1486
+ // remove from html_interactions
1487
+ run.context.html_interactions = run.context.html_interactions.map(
1488
+ (hi) => {
1489
+ if (hi.includes(`button data-useraction-id="${uadata.rndid}"`))
1490
+ return wrapSegment(
1491
+ uadata.click_replace_text,
1492
+ "You",
1493
+ true,
1494
+ config.layout,
1495
+ );
1496
+ return hi;
1497
+ },
1498
+ );
1499
+ await run.update({ context: run.context });
1500
+ }
1450
1501
  await process_interaction(
1451
1502
  run,
1452
1503
  action.configuration,
@@ -1462,7 +1513,6 @@ const execute_user_action = async (
1462
1513
  json: {
1463
1514
  success: "ok",
1464
1515
  ...restResult,
1465
- reload_embedded_view: viewname,
1466
1516
  },
1467
1517
  };
1468
1518
  }
package/common.js CHANGED
@@ -418,62 +418,8 @@ const process_interaction = async (
418
418
  let result = await tool.tool.process(tool_call.input, {
419
419
  req,
420
420
  });
421
+ const tool_response = result.add_response || result;
421
422
  toolResults[tool_call.tool_call_id] = result;
422
- if (result.add_response) {
423
- if (!result.add_responses)
424
- result.add_responses = [result.add_response];
425
- else result.add_responses.push(result.add_response);
426
- }
427
-
428
- for (const add_resp of result.add_responses || []) {
429
- const content =
430
- add_resp.role && add_resp.content ? add_resp.content : add_resp;
431
- raw_responses.push(content);
432
- if (add_resp.md_response !== null) {
433
- const renderedAddResponse = add_resp.md_response
434
- ? md.render(add_resp.md_response)
435
- : typeof content === "string"
436
- ? md.render(content)
437
- : content;
438
- add_response(
439
- wrapSegment(
440
- wrapCard(response_label, renderedAddResponse),
441
- agent_label,
442
- false,
443
- layout,
444
- ),
445
- );
446
- }
447
- if (typeof add_resp.md_response !== "undefined")
448
- delete add_resp.md_response;
449
-
450
- const result = content;
451
-
452
- if (add_resp.role && add_resp.content) {
453
- await sysState.functions.llm_add_message.run(
454
- add_resp.role,
455
- add_resp.content,
456
- {
457
- chat: run.context.interactions,
458
- },
459
- );
460
- } else
461
- await sysState.functions.llm_add_message.run(
462
- "assistant",
463
-
464
- !result || typeof result === "string"
465
- ? result || "Action run"
466
- : JSON.stringify(result),
467
-
468
- {
469
- chat: run.context.interactions,
470
- },
471
- );
472
-
473
- await addToContext(run, {
474
- interactions: run.context.interactions,
475
- });
476
- }
477
423
  if (result?.stop) stop = true;
478
424
  if (result?.add_user_action && viewname) {
479
425
  const user_actions = Array.isArray()
@@ -492,6 +438,7 @@ const process_interaction = async (
492
438
  user_actions.map((ua) =>
493
439
  button(
494
440
  {
441
+ "data-useraction-id": ua.rndid,
495
442
  class: "btn btn-primary", //press_store_button(this, true);
496
443
  onclick: `view_post('${viewname}', 'execute_user_action', {uaname: "${ua.name}",rndid: "${ua.rndid}", run_id: ${run.id}}, processExecuteResponse)`,
497
444
  },
@@ -502,13 +449,17 @@ const process_interaction = async (
502
449
  );
503
450
  }
504
451
  if (
505
- (typeof result === "object" && Object.keys(result || {}).length) ||
506
- typeof result === "string"
452
+ (typeof tool_response === "object" &&
453
+ Object.keys(tool_response || {}).length) ||
454
+ typeof tool_response === "string"
507
455
  ) {
508
456
  if (tool.tool.renderToolResponse) {
509
- const rendered = await tool.tool.renderToolResponse(result, {
510
- req,
511
- });
457
+ const rendered = await tool.tool.renderToolResponse(
458
+ tool_response,
459
+ {
460
+ req,
461
+ },
462
+ );
512
463
  if (rendered)
513
464
  add_response(
514
465
  wrapSegment(
@@ -523,14 +474,14 @@ const process_interaction = async (
523
474
  }
524
475
  await sysState.functions.llm_add_message.run(
525
476
  "tool_response",
526
- !result || typeof result === "string"
477
+ !tool_response || typeof tool_response === "string"
527
478
  ? {
528
479
  type: "text",
529
- value: result || "Action run",
480
+ value: tool_response || "Action run",
530
481
  }
531
482
  : {
532
483
  type: "json",
533
- value: JSON.parse(JSON.stringify(result)),
484
+ value: JSON.parse(JSON.stringify(tool_response)),
534
485
  },
535
486
  {
536
487
  chat: run.context.interactions,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@saltcorn/agents",
3
- "version": "0.7.11",
3
+ "version": "0.7.12",
4
4
  "description": "AI agents for Saltcorn",
5
5
  "main": "index.js",
6
6
  "dependencies": {
@@ -73,10 +73,14 @@ class PlanApprovalSkill {
73
73
  name: "approve_plan",
74
74
  type: "button",
75
75
  label: `Approve`,
76
+ click_replace_text: "Approved",
76
77
  input: {},
77
78
  },
78
79
  };
79
80
  },
81
+ renderToolCall({ plan }) {
82
+ return plan;
83
+ },
80
84
  function: {
81
85
  name: "submit_plan_for_approval",
82
86
  description: