@saltcorn/agents 0.4.9 → 0.4.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/common.js +3 -2
- package/index.js +30 -12
- package/package.json +1 -1
package/common.js
CHANGED
|
@@ -142,6 +142,7 @@ const incompleteCfgMsg = () => {
|
|
|
142
142
|
};
|
|
143
143
|
|
|
144
144
|
const addToContext = async (run, newCtx) => {
|
|
145
|
+
if (!run) return;
|
|
145
146
|
if (run.addToContext) return await run.addToContext(newCtx);
|
|
146
147
|
let changed = true;
|
|
147
148
|
Object.keys(newCtx).forEach((k) => {
|
|
@@ -160,7 +161,7 @@ const addToContext = async (run, newCtx) => {
|
|
|
160
161
|
changed = true;
|
|
161
162
|
}
|
|
162
163
|
});
|
|
163
|
-
if (changed) await run.update({ context: run.context });
|
|
164
|
+
if (changed && run.update) await run.update({ context: run.context });
|
|
164
165
|
};
|
|
165
166
|
|
|
166
167
|
const wrapSegment = (html, who) =>
|
|
@@ -450,7 +451,7 @@ const process_interaction = async (
|
|
|
450
451
|
json: {
|
|
451
452
|
success: "ok",
|
|
452
453
|
response: [...prevResponses, ...responses].join(""),
|
|
453
|
-
run_id: run
|
|
454
|
+
run_id: run?.id,
|
|
454
455
|
},
|
|
455
456
|
};
|
|
456
457
|
};
|
package/index.js
CHANGED
|
@@ -105,27 +105,45 @@ module.exports = {
|
|
|
105
105
|
agent_generate: {
|
|
106
106
|
run: async (agent_name, prompt, opts = {}) => {
|
|
107
107
|
const action = await Trigger.findOne({ name: agent_name });
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
108
|
+
let run;
|
|
109
|
+
let context = {
|
|
110
|
+
implemented_fcall_ids: [],
|
|
111
|
+
interactions: [
|
|
112
|
+
...(opts.interactions || []),
|
|
113
|
+
{ role: "user", content: prompt },
|
|
114
|
+
],
|
|
115
|
+
funcalls: {},
|
|
116
|
+
};
|
|
117
|
+
if (opts.run_id === null || (!opts.run_id && opts.run === null))
|
|
118
|
+
run = { context };
|
|
119
|
+
else if (opts.run) run = opts.run;
|
|
120
|
+
else if (opts.run_id)
|
|
121
|
+
run = await WorkflowRun.findOne({ id: +opts.run_id });
|
|
122
|
+
else
|
|
123
|
+
run = await WorkflowRun.create({
|
|
124
|
+
status: "Running",
|
|
125
|
+
started_by: opts.user?.id,
|
|
126
|
+
trigger_id: action.id,
|
|
127
|
+
context,
|
|
128
|
+
});
|
|
118
129
|
const result = await process_interaction(
|
|
119
130
|
run,
|
|
120
131
|
action.configuration,
|
|
121
132
|
{
|
|
122
133
|
user: opts?.user,
|
|
123
134
|
body: {},
|
|
124
|
-
|
|
135
|
+
disable_markdown_render:
|
|
136
|
+
typeof opts.disable_markdown_render !== "undefined"
|
|
137
|
+
? opts.disable_markdown_render
|
|
138
|
+
: !opts?.render_markdown,
|
|
125
139
|
},
|
|
126
140
|
null
|
|
127
141
|
);
|
|
128
|
-
return {
|
|
142
|
+
return {
|
|
143
|
+
text: result.json.response,
|
|
144
|
+
run,
|
|
145
|
+
...(run.id ? { run_id: run.id } : {}),
|
|
146
|
+
};
|
|
129
147
|
},
|
|
130
148
|
isAsync: true,
|
|
131
149
|
description: "Run an agent on a prompt",
|