@saltcorn/agents 0.4.7 → 0.4.8
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 +29 -14
- package/common.js +23 -9
- package/index.js +35 -1
- package/package.json +1 -1
package/agent-view.js
CHANGED
|
@@ -162,23 +162,38 @@ const realTimeCollabScript = (viewname) => {
|
|
|
162
162
|
const view = View.findOne({ name: viewname });
|
|
163
163
|
return script(
|
|
164
164
|
domReady(`
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
);
|
|
165
|
+
const callback = () => {
|
|
166
|
+
const collabCfg = {
|
|
167
|
+
events: {
|
|
168
|
+
['${view.getRealTimeEventName(
|
|
169
|
+
"STREAM_CHUNK"
|
|
170
|
+
)}' + \`?page_load_tag=\${_sc_pageloadtag}\`]: async (data) => {
|
|
171
|
+
$('form.agent-view div.next_response_scratch').append(
|
|
172
|
+
data.content
|
|
173
|
+
);
|
|
174
|
+
}
|
|
176
175
|
}
|
|
176
|
+
};
|
|
177
|
+
let retries = 0
|
|
178
|
+
function init_it() {
|
|
179
|
+
if(window.io) init_collab_room('${viewname}', collabCfg);
|
|
180
|
+
else setTimeout(init_it, retries * 100);
|
|
181
|
+
retries+=1;
|
|
177
182
|
}
|
|
183
|
+
init_it();
|
|
178
184
|
};
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
185
|
+
|
|
186
|
+
if (ensure_script_loaded.length >= 2) {
|
|
187
|
+
ensure_script_loaded("/static_assets/${
|
|
188
|
+
db.connectObj.version_tag
|
|
189
|
+
}/socket.io.min.js", callback);
|
|
190
|
+
}
|
|
191
|
+
else {
|
|
192
|
+
ensure_script_loaded("/static_assets/${
|
|
193
|
+
db.connectObj.version_tag
|
|
194
|
+
}/socket.io.min.js");
|
|
195
|
+
callback();
|
|
196
|
+
}`)
|
|
182
197
|
);
|
|
183
198
|
};
|
|
184
199
|
|
package/common.js
CHANGED
|
@@ -164,11 +164,13 @@ const addToContext = async (run, newCtx) => {
|
|
|
164
164
|
};
|
|
165
165
|
|
|
166
166
|
const wrapSegment = (html, who) =>
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
167
|
+
who === null
|
|
168
|
+
? html
|
|
169
|
+
: '<div class="interaction-segment"><span class="badge bg-secondary">' +
|
|
170
|
+
who +
|
|
171
|
+
"</span>" +
|
|
172
|
+
html +
|
|
173
|
+
"</div>";
|
|
172
174
|
|
|
173
175
|
const wrapCard = (title, ...inners) =>
|
|
174
176
|
span({ class: "badge bg-info ms-1" }, title) +
|
|
@@ -220,13 +222,13 @@ const process_interaction = async (
|
|
|
220
222
|
const debugCollector = {};
|
|
221
223
|
if (debugMode) complArgs.debugCollector = debugCollector;
|
|
222
224
|
if (stream && viewname) {
|
|
225
|
+
const view = View.findOne({ name: viewname });
|
|
223
226
|
complArgs.streamCallback = (response) => {
|
|
224
227
|
const content =
|
|
225
228
|
typeof response === "string"
|
|
226
229
|
? response
|
|
227
230
|
: response.choices[0].content || response.choices[0].delta?.content;
|
|
228
231
|
if (content) {
|
|
229
|
-
const view = View.findOne({ name: viewname });
|
|
230
232
|
const pageLoadTag = req.body.page_load_tag;
|
|
231
233
|
view.emitRealTimeEvent(`STREAM_CHUNK?page_load_tag=${pageLoadTag}`, {
|
|
232
234
|
content,
|
|
@@ -272,7 +274,11 @@ const process_interaction = async (
|
|
|
272
274
|
}
|
|
273
275
|
}
|
|
274
276
|
if (answer.content && !answer.tool_calls)
|
|
275
|
-
responses.push(
|
|
277
|
+
responses.push(
|
|
278
|
+
req.disable_markdown_render
|
|
279
|
+
? answer
|
|
280
|
+
: wrapSegment(md.render(answer.content), agent_label)
|
|
281
|
+
);
|
|
276
282
|
}
|
|
277
283
|
if (answer.ai_sdk)
|
|
278
284
|
await addToContext(run, {
|
|
@@ -297,7 +303,11 @@ const process_interaction = async (
|
|
|
297
303
|
(answer.tool_calls || answer.mcp_calls)
|
|
298
304
|
) {
|
|
299
305
|
if (answer.content)
|
|
300
|
-
responses.push(
|
|
306
|
+
responses.push(
|
|
307
|
+
req.disable_markdown_render
|
|
308
|
+
? answer
|
|
309
|
+
: wrapSegment(md.render(answer.content), agent_label)
|
|
310
|
+
);
|
|
301
311
|
//const actions = [];
|
|
302
312
|
let hasResult = false;
|
|
303
313
|
if ((answer.mcp_calls || []).length && !answer.content) hasResult = true;
|
|
@@ -430,7 +440,11 @@ const process_interaction = async (
|
|
|
430
440
|
agentsViewCfg
|
|
431
441
|
);
|
|
432
442
|
} else if (typeof answer === "string")
|
|
433
|
-
responses.push(
|
|
443
|
+
responses.push(
|
|
444
|
+
req.disable_markdown_render
|
|
445
|
+
? answer
|
|
446
|
+
: wrapSegment(md.render(answer), agent_label)
|
|
447
|
+
);
|
|
434
448
|
|
|
435
449
|
return {
|
|
436
450
|
json: {
|
package/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const Workflow = require("@saltcorn/data/models/workflow");
|
|
2
2
|
const Form = require("@saltcorn/data/models/form");
|
|
3
3
|
const FieldRepeat = require("@saltcorn/data/models/fieldrepeat");
|
|
4
|
-
const
|
|
4
|
+
const Trigger = require("@saltcorn/data/models/trigger");
|
|
5
5
|
const {
|
|
6
6
|
get_skills,
|
|
7
7
|
getCompletionArguments,
|
|
@@ -101,6 +101,40 @@ module.exports = {
|
|
|
101
101
|
},
|
|
102
102
|
},
|
|
103
103
|
},
|
|
104
|
+
functions: {
|
|
105
|
+
agent_generate: {
|
|
106
|
+
run: async (agent_name, prompt, opts = {}) => {
|
|
107
|
+
const action = await Trigger.findOne({ name: agent_name });
|
|
108
|
+
const run = await WorkflowRun.create({
|
|
109
|
+
status: "Running",
|
|
110
|
+
started_by: opts.user?.id,
|
|
111
|
+
trigger_id: action.id,
|
|
112
|
+
context: {
|
|
113
|
+
implemented_fcall_ids: [],
|
|
114
|
+
interactions: [{ role: "user", content: prompt }],
|
|
115
|
+
funcalls: {},
|
|
116
|
+
},
|
|
117
|
+
});
|
|
118
|
+
const result = await process_interaction(
|
|
119
|
+
run,
|
|
120
|
+
action.configuration,
|
|
121
|
+
{
|
|
122
|
+
user: opts?.user,
|
|
123
|
+
body: {},
|
|
124
|
+
disable_markdown: opts?.disable_markdown_render
|
|
125
|
+
},
|
|
126
|
+
null
|
|
127
|
+
);
|
|
128
|
+
return result.json.response;
|
|
129
|
+
},
|
|
130
|
+
isAsync: true,
|
|
131
|
+
description: "Run an agent on a prompt",
|
|
132
|
+
arguments: [
|
|
133
|
+
{ name: "agent_name", type: "String" },
|
|
134
|
+
{ name: "prompt", type: "String" },
|
|
135
|
+
],
|
|
136
|
+
},
|
|
137
|
+
},
|
|
104
138
|
};
|
|
105
139
|
|
|
106
140
|
/*
|