@saltcorn/agents 0.5.8 → 0.6.1

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/action.js ADDED
@@ -0,0 +1,109 @@
1
+ const FieldRepeat = require("@saltcorn/data/models/fieldrepeat");
2
+ const Table = require("@saltcorn/data/models/table");
3
+ const { get_skills, process_interaction } = require("./common");
4
+ const { applyAsync } = require("@saltcorn/data/utils");
5
+ const WorkflowRun = require("@saltcorn/data/models/workflow_run");
6
+ const { interpolate } = require("@saltcorn/data/utils");
7
+
8
+ module.exports = {
9
+ disableInBuilder: true,
10
+ disableInList: true,
11
+ disableInWorkflow: true,
12
+ configFields: async ({ table, mode }) => {
13
+ const skills = get_skills();
14
+ const skills_fields = [];
15
+ for (const skill of skills) {
16
+ if (skill.configFields) {
17
+ const fields = await applyAsync(skill.configFields, undefined);
18
+ for (const field of fields) {
19
+ if (!field.showIf) field.showIf = {};
20
+ field.showIf.skill_type = skill.skill_name;
21
+ skills_fields.push(field);
22
+ }
23
+ }
24
+ }
25
+ const tables_with_json_field = (await Table.find({})).filter(
26
+ (table) =>
27
+ !table.external &&
28
+ !table.provider_name &&
29
+ table.fields.some((f) => f.type?.name === "JSON"),
30
+ );
31
+ return [
32
+ ...(table
33
+ ? [
34
+ {
35
+ name: "prompt",
36
+ label: "Prompt",
37
+ sublabel:
38
+ "When triggered from table event or table view button. Use handlebars <code>{{}}</code> to access table fields. Ignored if run in Agent Chat view.",
39
+ type: "String",
40
+ required: true,
41
+ attributes: { options: table.fields.map((f) => f.name) },
42
+ },
43
+ ]
44
+ : []),
45
+ {
46
+ name: "sys_prompt",
47
+ label: "System prompt",
48
+ sublabel:
49
+ "Additional information for the system prompt. Use interpolations <code>{{ }}</code> to access triggering row variables or user",
50
+ type: "String",
51
+ fieldview: "textarea",
52
+ },
53
+ {
54
+ name: "model",
55
+ label: "Model",
56
+ sublabel: "Override default model name",
57
+ type: "String",
58
+ },
59
+ new FieldRepeat({
60
+ name: "skills",
61
+ label: "Skills",
62
+ fields: [
63
+ {
64
+ name: "skill_type",
65
+ label: "Type",
66
+ type: "String",
67
+ required: true,
68
+ attributes: { options: skills.map((s) => s.skill_name) },
69
+ },
70
+ ...skills_fields,
71
+ ],
72
+ }),
73
+ ];
74
+ },
75
+ run: async ({
76
+ configuration,
77
+ user,
78
+ row,
79
+ trigger_id,
80
+ run_id,
81
+ req,
82
+ ...rest
83
+ }) => {
84
+ const userinput = interpolate(configuration.prompt, row, user);
85
+
86
+ const run = run_id
87
+ ? await WorkflowRun.findOne({ id: run_id })
88
+ : await WorkflowRun.create({
89
+ status: "Running",
90
+ started_by: user?.id,
91
+ trigger_id: trigger_id || undefined,
92
+ context: {
93
+ implemented_fcall_ids: [],
94
+ interactions: [{ role: "user", content: userinput }],
95
+ funcalls: {},
96
+ },
97
+ });
98
+ if (run_id)
99
+ run.context.interactions.push({ role: "user", content: userinput });
100
+ return await process_interaction(
101
+ run,
102
+ configuration,
103
+ req,
104
+ undefined,
105
+ [],
106
+ row,
107
+ );
108
+ },
109
+ };