@saltcorn/agents 0.7.11 → 0.7.13
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 +56 -1
- package/common.js +14 -63
- package/package.json +1 -1
- package/skills/PlanApproval.js +4 -0
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,35 @@ 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
|
+
const { layout } = config;
|
|
1479
|
+
|
|
1480
|
+
const resp = JSON.stringify(
|
|
1481
|
+
wrapSegment(uadata.click_replace_text, "You", true, layout),
|
|
1482
|
+
);
|
|
1483
|
+
getState().emitDynamicUpdate(
|
|
1484
|
+
db.getTenantSchema(),
|
|
1485
|
+
{
|
|
1486
|
+
eval_js: `spin_send_button();$("button[data-useraction-id=${uadata.rndid}]").replaceWith("");processCopilotResponse({response: ${resp}, run_id: ${run.id}}, true)`,
|
|
1487
|
+
page_load_tag: req?.headers?.["page-load-tag"],
|
|
1488
|
+
},
|
|
1489
|
+
[req.user.id],
|
|
1490
|
+
);
|
|
1491
|
+
// remove from html_interactions
|
|
1492
|
+
run.context.html_interactions = run.context.html_interactions.map(
|
|
1493
|
+
(hi) => {
|
|
1494
|
+
if (hi.includes(`button data-useraction-id="${uadata.rndid}"`))
|
|
1495
|
+
return wrapSegment(
|
|
1496
|
+
uadata.click_replace_text,
|
|
1497
|
+
"You",
|
|
1498
|
+
true,
|
|
1499
|
+
config.layout,
|
|
1500
|
+
);
|
|
1501
|
+
return hi;
|
|
1502
|
+
},
|
|
1503
|
+
);
|
|
1504
|
+
await run.update({ context: run.context });
|
|
1505
|
+
}
|
|
1450
1506
|
await process_interaction(
|
|
1451
1507
|
run,
|
|
1452
1508
|
action.configuration,
|
|
@@ -1462,7 +1518,6 @@ const execute_user_action = async (
|
|
|
1462
1518
|
json: {
|
|
1463
1519
|
success: "ok",
|
|
1464
1520
|
...restResult,
|
|
1465
|
-
reload_embedded_view: viewname,
|
|
1466
1521
|
},
|
|
1467
1522
|
};
|
|
1468
1523
|
}
|
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
|
|
506
|
-
|
|
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(
|
|
510
|
-
|
|
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
|
-
!
|
|
477
|
+
!tool_response || typeof tool_response === "string"
|
|
527
478
|
? {
|
|
528
479
|
type: "text",
|
|
529
|
-
value:
|
|
480
|
+
value: tool_response || "Action run",
|
|
530
481
|
}
|
|
531
482
|
: {
|
|
532
483
|
type: "json",
|
|
533
|
-
value: JSON.parse(JSON.stringify(
|
|
484
|
+
value: JSON.parse(JSON.stringify(tool_response)),
|
|
534
485
|
},
|
|
535
486
|
{
|
|
536
487
|
chat: run.context.interactions,
|
package/package.json
CHANGED
package/skills/PlanApproval.js
CHANGED
|
@@ -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:
|