@saltcorn/agents 0.3.4 → 0.3.6
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 +60 -5
- package/common.js +12 -5
- package/package.json +1 -1
package/agent-view.js
CHANGED
|
@@ -17,6 +17,7 @@ const {
|
|
|
17
17
|
code,
|
|
18
18
|
input,
|
|
19
19
|
h4,
|
|
20
|
+
h3,
|
|
20
21
|
style,
|
|
21
22
|
h5,
|
|
22
23
|
button,
|
|
@@ -40,6 +41,7 @@ const {
|
|
|
40
41
|
wrapSegment,
|
|
41
42
|
process_interaction,
|
|
42
43
|
find_image_tool,
|
|
44
|
+
is_debug_mode,
|
|
43
45
|
} = require("./common");
|
|
44
46
|
const MarkdownIt = require("markdown-it"),
|
|
45
47
|
md = new MarkdownIt();
|
|
@@ -187,10 +189,9 @@ const run = async (
|
|
|
187
189
|
break;
|
|
188
190
|
case "assistant":
|
|
189
191
|
case "system":
|
|
190
|
-
|
|
191
192
|
for (const tool_call of interact.tool_calls || []) {
|
|
192
193
|
const toolSkill = find_tool(
|
|
193
|
-
tool_call.function
|
|
194
|
+
tool_call.function?.name,
|
|
194
195
|
action.configuration
|
|
195
196
|
);
|
|
196
197
|
if (toolSkill) {
|
|
@@ -214,7 +215,6 @@ const run = async (
|
|
|
214
215
|
}
|
|
215
216
|
}
|
|
216
217
|
for (const image_call of interact.content?.image_calls || []) {
|
|
217
|
-
|
|
218
218
|
const toolSkill = find_image_tool(action.configuration);
|
|
219
219
|
if (toolSkill) {
|
|
220
220
|
if (toolSkill.tool.renderToolResponse) {
|
|
@@ -285,6 +285,7 @@ const run = async (
|
|
|
285
285
|
}
|
|
286
286
|
runInteractions = interactMarkups.join("");
|
|
287
287
|
}
|
|
288
|
+
const debugMode = is_debug_mode(action.configuration, req.user);
|
|
288
289
|
const input_form = form(
|
|
289
290
|
{
|
|
290
291
|
onsubmit: `event.preventDefault();spin_send_button();view_post('${viewname}', 'interact', new FormData(this), processCopilotResponse);return false;`,
|
|
@@ -318,6 +319,11 @@ const run = async (
|
|
|
318
319
|
i({ id: "sendbuttonicon", class: "far fa-paper-plane" })
|
|
319
320
|
),
|
|
320
321
|
image_upload && uploadForm(viewname, req),
|
|
322
|
+
debugMode &&
|
|
323
|
+
i({
|
|
324
|
+
onclick: "press_agent_debug_button()",
|
|
325
|
+
class: "debugicon fas fa-bug",
|
|
326
|
+
}),
|
|
321
327
|
explainer && small({ class: "explainer" }, i(explainer))
|
|
322
328
|
)
|
|
323
329
|
);
|
|
@@ -380,6 +386,12 @@ const run = async (
|
|
|
380
386
|
position: relative;
|
|
381
387
|
top: -1.8rem;
|
|
382
388
|
left: 0.1rem;
|
|
389
|
+
}
|
|
390
|
+
.copilot-entry .debugicon {
|
|
391
|
+
position: relative;
|
|
392
|
+
top: -1.8rem;
|
|
393
|
+
left: 0.1rem;
|
|
394
|
+
cursor: pointer;
|
|
383
395
|
}
|
|
384
396
|
.copilot-entry span.attach_agent_image_wrap {
|
|
385
397
|
position: relative;
|
|
@@ -425,6 +437,22 @@ const run = async (
|
|
|
425
437
|
btn.css({ width: "" }).prop("disabled", false);
|
|
426
438
|
btn.removeData("old-text");
|
|
427
439
|
}
|
|
440
|
+
function press_agent_debug_button() {
|
|
441
|
+
const $runidin= $("input[name=run_id")
|
|
442
|
+
const runid = $runidin.val()
|
|
443
|
+
if(runid)
|
|
444
|
+
view_post('${viewname}', 'debug_info', {run_id:runid}, show_agent_debug_info)
|
|
445
|
+
}
|
|
446
|
+
function show_agent_debug_info(info) {
|
|
447
|
+
console.log(info)
|
|
448
|
+
ensure_modal_exists_and_closed();
|
|
449
|
+
$("#scmodal .modal-body").html(info.debug_html);
|
|
450
|
+
$("#scmodal .modal-title").html(decodeURIComponent("Agent session information"));
|
|
451
|
+
$(".modal-dialog").css("min-width", "80%");
|
|
452
|
+
new bootstrap.Modal($("#scmodal"), {
|
|
453
|
+
focus: false,
|
|
454
|
+
}).show();
|
|
455
|
+
}
|
|
428
456
|
function delprevrun(e, runid) {
|
|
429
457
|
e.preventDefault();
|
|
430
458
|
e.stopPropagation();
|
|
@@ -549,6 +577,32 @@ const delprevrun = async (table_id, viewname, config, body, { req, res }) => {
|
|
|
549
577
|
return;
|
|
550
578
|
};
|
|
551
579
|
|
|
580
|
+
const debug_info = async (table_id, viewname, config, body, { req, res }) => {
|
|
581
|
+
const { run_id } = body;
|
|
582
|
+
const action = await Trigger.findOne({ id: config.action_id });
|
|
583
|
+
|
|
584
|
+
const run = await WorkflowRun.findOne({ id: +run_id });
|
|
585
|
+
const complArgs = await getCompletionArguments(
|
|
586
|
+
action.configuration,
|
|
587
|
+
req.user
|
|
588
|
+
);
|
|
589
|
+
const debug_html = div(
|
|
590
|
+
div(h4("System prompt"), pre(complArgs.systemPrompt)),
|
|
591
|
+
div(
|
|
592
|
+
h4("API interactions"),
|
|
593
|
+
pre(JSON.stringify(run.context.api_interactions, null, 2))
|
|
594
|
+
)
|
|
595
|
+
);
|
|
596
|
+
if (run && req.user?.role_id === 1)
|
|
597
|
+
return {
|
|
598
|
+
json: {
|
|
599
|
+
success: "ok",
|
|
600
|
+
debug_html,
|
|
601
|
+
},
|
|
602
|
+
};
|
|
603
|
+
|
|
604
|
+
return;
|
|
605
|
+
};
|
|
552
606
|
const wrapAction = (
|
|
553
607
|
inner_markup,
|
|
554
608
|
viewname,
|
|
@@ -585,7 +639,8 @@ module.exports = {
|
|
|
585
639
|
configuration_workflow,
|
|
586
640
|
display_state_form: false,
|
|
587
641
|
get_state_fields,
|
|
588
|
-
tableless: true,
|
|
642
|
+
//tableless: true,
|
|
643
|
+
table_optional: true,
|
|
589
644
|
run,
|
|
590
|
-
routes: { interact, delprevrun },
|
|
645
|
+
routes: { interact, delprevrun, debug_info },
|
|
591
646
|
};
|
package/common.js
CHANGED
|
@@ -42,7 +42,7 @@ const find_tool = (name, config) => {
|
|
|
42
42
|
: Array.isArray(skillTools)
|
|
43
43
|
? skillTools
|
|
44
44
|
: [skillTools];
|
|
45
|
-
const found = tools.find((t) => t?.function
|
|
45
|
+
const found = tools.find((t) => t?.function?.name === name);
|
|
46
46
|
if (found) return { tool: found, skill };
|
|
47
47
|
}
|
|
48
48
|
};
|
|
@@ -156,6 +156,8 @@ const only_response_text_if_present = (interact) => {
|
|
|
156
156
|
return interact;
|
|
157
157
|
};
|
|
158
158
|
|
|
159
|
+
const is_debug_mode = (config, user) => user?.role_id === 1;
|
|
160
|
+
|
|
159
161
|
const process_interaction = async (
|
|
160
162
|
run,
|
|
161
163
|
config,
|
|
@@ -167,10 +169,14 @@ const process_interaction = async (
|
|
|
167
169
|
complArgs.chat = run.context.interactions.map(only_response_text_if_present);
|
|
168
170
|
//complArgs.debugResult = true;
|
|
169
171
|
//console.log("complArgs", JSON.stringify(complArgs, null, 2));
|
|
170
|
-
|
|
172
|
+
const debugMode = is_debug_mode(config, req.user);
|
|
173
|
+
const debugCollector = {};
|
|
174
|
+
if (debugMode) complArgs.debugCollector = debugCollector;
|
|
171
175
|
const answer = await getState().functions.llm_generate.run("", complArgs);
|
|
172
|
-
|
|
173
|
-
|
|
176
|
+
if (debugMode)
|
|
177
|
+
await addToContext(run, {
|
|
178
|
+
api_interactions: [debugCollector],
|
|
179
|
+
});
|
|
174
180
|
const responses = [];
|
|
175
181
|
if (answer && typeof answer === "object" && answer.image_calls) {
|
|
176
182
|
for (const image_call of answer.image_calls) {
|
|
@@ -232,7 +238,7 @@ const process_interaction = async (
|
|
|
232
238
|
funcalls: { [tool_call.id]: tool_call.function },
|
|
233
239
|
});
|
|
234
240
|
|
|
235
|
-
const tool = find_tool(tool_call.function
|
|
241
|
+
const tool = find_tool(tool_call.function?.name, config);
|
|
236
242
|
|
|
237
243
|
if (tool) {
|
|
238
244
|
if (tool.tool.renderToolCall) {
|
|
@@ -323,4 +329,5 @@ module.exports = {
|
|
|
323
329
|
wrapSegment,
|
|
324
330
|
process_interaction,
|
|
325
331
|
find_image_tool,
|
|
332
|
+
is_debug_mode,
|
|
326
333
|
};
|