@saltcorn/agents 0.6.9 → 0.6.11
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 +10 -4
- package/common.js +15 -3
- package/package.json +1 -1
- package/skills/GenerateAndRunJsCode.js +21 -7
package/agent-view.js
CHANGED
|
@@ -533,9 +533,11 @@ const run = async (
|
|
|
533
533
|
|
|
534
534
|
p(
|
|
535
535
|
{ class: "prevrun_content" },
|
|
536
|
-
|
|
537
|
-
.
|
|
538
|
-
|
|
536
|
+
escapeHtml(
|
|
537
|
+
run.context.interactions
|
|
538
|
+
.find((i) => typeof i?.content === "string")
|
|
539
|
+
?.content?.substring?.(0, 80),
|
|
540
|
+
),
|
|
539
541
|
),
|
|
540
542
|
),
|
|
541
543
|
),
|
|
@@ -894,7 +896,11 @@ const interact = async (table_id, viewname, config, body, { req, res }) => {
|
|
|
894
896
|
await saveInteractions(run);
|
|
895
897
|
fileBadges = div({ class: "d-flex" }, badges);
|
|
896
898
|
}
|
|
897
|
-
const userInteractions = wrapSegment(
|
|
899
|
+
const userInteractions = wrapSegment(
|
|
900
|
+
p(escapeHtml(userinput)) + fileBadges,
|
|
901
|
+
"You",
|
|
902
|
+
true,
|
|
903
|
+
);
|
|
898
904
|
|
|
899
905
|
await addToContext(run, {
|
|
900
906
|
interactions: [
|
package/common.js
CHANGED
|
@@ -326,9 +326,10 @@ const process_interaction = async (
|
|
|
326
326
|
let stop = false,
|
|
327
327
|
myHasResult = false;
|
|
328
328
|
if (stream && viewname) {
|
|
329
|
-
let content =
|
|
330
|
-
|
|
331
|
-
tool.skill.constructor.skill_name
|
|
329
|
+
let content = span(
|
|
330
|
+
{ class: "badge text-bg-secondary me-1" },
|
|
331
|
+
tool.skill.skill_label || tool.skill.constructor.skill_name,
|
|
332
|
+
);
|
|
332
333
|
const view = View.findOne({ name: viewname });
|
|
333
334
|
const pageLoadTag = req.body.page_load_tag;
|
|
334
335
|
view.emitRealTimeEvent(
|
|
@@ -418,6 +419,17 @@ const process_interaction = async (
|
|
|
418
419
|
...opts,
|
|
419
420
|
});
|
|
420
421
|
},
|
|
422
|
+
emit_update(s) {
|
|
423
|
+
if (!stream || !viewname) return;
|
|
424
|
+
const view = View.findOne({ name: viewname });
|
|
425
|
+
const pageLoadTag = req.body.page_load_tag;
|
|
426
|
+
view.emitRealTimeEvent(
|
|
427
|
+
`STREAM_CHUNK?page_load_tag=${pageLoadTag}`,
|
|
428
|
+
{
|
|
429
|
+
content: span({ class: "badge text-bg-secondary me-1" }, s),
|
|
430
|
+
},
|
|
431
|
+
);
|
|
432
|
+
},
|
|
421
433
|
});
|
|
422
434
|
if (generateUsed)
|
|
423
435
|
await addToContext(run, {
|
package/package.json
CHANGED
|
@@ -27,7 +27,7 @@ class GenerateAndRunJsCodeSkill {
|
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
constructor(cfg) {
|
|
30
|
-
Object.assign(this, cfg);
|
|
30
|
+
Object.assign(this, cfg);
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
async runCode(code, { user, req }) {
|
|
@@ -42,10 +42,14 @@ class GenerateAndRunJsCodeSkill {
|
|
|
42
42
|
}
|
|
43
43
|
: {}),
|
|
44
44
|
...(this.allow_fetch ? { fetch } : {}),
|
|
45
|
+
...(this.allow_functions ? sysState.eval_context : {}),
|
|
45
46
|
user,
|
|
46
47
|
console,
|
|
47
48
|
sleep,
|
|
48
49
|
setTimeout,
|
|
50
|
+
URL,
|
|
51
|
+
Buffer,
|
|
52
|
+
console,
|
|
49
53
|
});
|
|
50
54
|
return await f();
|
|
51
55
|
}
|
|
@@ -94,6 +98,11 @@ class GenerateAndRunJsCodeSkill {
|
|
|
94
98
|
label: "Allow access to tables",
|
|
95
99
|
type: "Bool",
|
|
96
100
|
},
|
|
101
|
+
{
|
|
102
|
+
name: "allow_functions",
|
|
103
|
+
label: "Allow calls to functions from codepages and modules",
|
|
104
|
+
type: "Bool",
|
|
105
|
+
},
|
|
97
106
|
...(Table.subClass
|
|
98
107
|
? [
|
|
99
108
|
{
|
|
@@ -117,9 +126,15 @@ class GenerateAndRunJsCodeSkill {
|
|
|
117
126
|
/*renderToolCall({ phrase }, { req }) {
|
|
118
127
|
return div({ class: "border border-primary p-2 m-2" }, phrase);
|
|
119
128
|
},*/
|
|
120
|
-
postProcess: async ({
|
|
129
|
+
postProcess: async ({
|
|
130
|
+
tool_call,
|
|
131
|
+
req,
|
|
132
|
+
generate,
|
|
133
|
+
emit_update,
|
|
134
|
+
...rest
|
|
135
|
+
}) => {
|
|
121
136
|
//console.log("postprocess args", { tool_call, ...rest });
|
|
122
|
-
|
|
137
|
+
emit_update("Generating code");
|
|
123
138
|
const str = await generate(
|
|
124
139
|
`You will now be asked to write JavaScript code.
|
|
125
140
|
${this.code_description ? "\nSome more information: " + this.code_description : ""}
|
|
@@ -131,15 +146,14 @@ The code you write can use await at the top level, and should return
|
|
|
131
146
|
|
|
132
147
|
Now generate the JavaScript code required by the user.`,
|
|
133
148
|
);
|
|
134
|
-
|
|
135
|
-
|
|
149
|
+
getState().log(6, "Generated code: \n" + str);
|
|
136
150
|
const js_code = str.includes("```javascript")
|
|
137
151
|
? str.split("```javascript")[1].split("```")[0]
|
|
138
152
|
: str;
|
|
139
|
-
|
|
153
|
+
emit_update("Running code");
|
|
140
154
|
const res = await this.runCode(js_code, { user: req.user });
|
|
141
155
|
//console.log("code response", res);
|
|
142
|
-
|
|
156
|
+
getState().log(6, "Code answer: " + JSON.stringify(res));
|
|
143
157
|
return {
|
|
144
158
|
//stop: true,
|
|
145
159
|
add_response: res,
|