@saltcorn/agents 0.6.9 → 0.6.10
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 +11 -0
- package/package.json +1 -1
- package/skills/GenerateAndRunJsCode.js +18 -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
|
@@ -418,6 +418,17 @@ const process_interaction = async (
|
|
|
418
418
|
...opts,
|
|
419
419
|
});
|
|
420
420
|
},
|
|
421
|
+
emit_update(s) {
|
|
422
|
+
if (!stream || !viewname) return;
|
|
423
|
+
const view = View.findOne({ name: viewname });
|
|
424
|
+
const pageLoadTag = req.body.page_load_tag;
|
|
425
|
+
view.emitRealTimeEvent(
|
|
426
|
+
`STREAM_CHUNK?page_load_tag=${pageLoadTag}`,
|
|
427
|
+
{
|
|
428
|
+
content: s,
|
|
429
|
+
},
|
|
430
|
+
);
|
|
431
|
+
},
|
|
421
432
|
});
|
|
422
433
|
if (generateUsed)
|
|
423
434
|
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,6 +42,7 @@ 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,
|
|
@@ -94,6 +95,11 @@ class GenerateAndRunJsCodeSkill {
|
|
|
94
95
|
label: "Allow access to tables",
|
|
95
96
|
type: "Bool",
|
|
96
97
|
},
|
|
98
|
+
{
|
|
99
|
+
name: "allow_functions",
|
|
100
|
+
label: "Allow calls to functions from codepages and modules",
|
|
101
|
+
type: "Bool",
|
|
102
|
+
},
|
|
97
103
|
...(Table.subClass
|
|
98
104
|
? [
|
|
99
105
|
{
|
|
@@ -117,9 +123,15 @@ class GenerateAndRunJsCodeSkill {
|
|
|
117
123
|
/*renderToolCall({ phrase }, { req }) {
|
|
118
124
|
return div({ class: "border border-primary p-2 m-2" }, phrase);
|
|
119
125
|
},*/
|
|
120
|
-
postProcess: async ({
|
|
126
|
+
postProcess: async ({
|
|
127
|
+
tool_call,
|
|
128
|
+
req,
|
|
129
|
+
generate,
|
|
130
|
+
emit_update,
|
|
131
|
+
...rest
|
|
132
|
+
}) => {
|
|
121
133
|
//console.log("postprocess args", { tool_call, ...rest });
|
|
122
|
-
|
|
134
|
+
emit_update("Generating code");
|
|
123
135
|
const str = await generate(
|
|
124
136
|
`You will now be asked to write JavaScript code.
|
|
125
137
|
${this.code_description ? "\nSome more information: " + this.code_description : ""}
|
|
@@ -131,15 +143,14 @@ The code you write can use await at the top level, and should return
|
|
|
131
143
|
|
|
132
144
|
Now generate the JavaScript code required by the user.`,
|
|
133
145
|
);
|
|
134
|
-
|
|
135
|
-
|
|
146
|
+
getState().log(6, "Generated code: \n" + str);
|
|
136
147
|
const js_code = str.includes("```javascript")
|
|
137
148
|
? str.split("```javascript")[1].split("```")[0]
|
|
138
149
|
: str;
|
|
139
|
-
|
|
150
|
+
emit_update("Running code");
|
|
140
151
|
const res = await this.runCode(js_code, { user: req.user });
|
|
141
152
|
//console.log("code response", res);
|
|
142
|
-
|
|
153
|
+
getState().log(6, "Code answer: " + JSON.stringify(res));
|
|
143
154
|
return {
|
|
144
155
|
//stop: true,
|
|
145
156
|
add_response: res,
|