@saltcorn/agents 0.4.10 → 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 +23 -9
- 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
|
@@ -106,18 +106,25 @@ module.exports = {
|
|
|
106
106
|
run: async (agent_name, prompt, opts = {}) => {
|
|
107
107
|
const action = await Trigger.findOne({ name: agent_name });
|
|
108
108
|
let run;
|
|
109
|
-
|
|
110
|
-
|
|
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 });
|
|
111
122
|
else
|
|
112
123
|
run = await WorkflowRun.create({
|
|
113
124
|
status: "Running",
|
|
114
125
|
started_by: opts.user?.id,
|
|
115
126
|
trigger_id: action.id,
|
|
116
|
-
context
|
|
117
|
-
implemented_fcall_ids: [],
|
|
118
|
-
interactions: [{ role: "user", content: prompt }],
|
|
119
|
-
funcalls: {},
|
|
120
|
-
},
|
|
127
|
+
context,
|
|
121
128
|
});
|
|
122
129
|
const result = await process_interaction(
|
|
123
130
|
run,
|
|
@@ -125,11 +132,18 @@ module.exports = {
|
|
|
125
132
|
{
|
|
126
133
|
user: opts?.user,
|
|
127
134
|
body: {},
|
|
128
|
-
disable_markdown_render:
|
|
135
|
+
disable_markdown_render:
|
|
136
|
+
typeof opts.disable_markdown_render !== "undefined"
|
|
137
|
+
? opts.disable_markdown_render
|
|
138
|
+
: !opts?.render_markdown,
|
|
129
139
|
},
|
|
130
140
|
null
|
|
131
141
|
);
|
|
132
|
-
return {
|
|
142
|
+
return {
|
|
143
|
+
text: result.json.response,
|
|
144
|
+
run,
|
|
145
|
+
...(run.id ? { run_id: run.id } : {}),
|
|
146
|
+
};
|
|
133
147
|
},
|
|
134
148
|
isAsync: true,
|
|
135
149
|
description: "Run an agent on a prompt",
|