@saltcorn/agents 0.3.1 → 0.3.2

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 CHANGED
@@ -13,6 +13,7 @@ const get_skills = () => {
13
13
  require("./skills/Table"),
14
14
  require("./skills/PreloadData"),
15
15
  require("./skills/GenerateImage"),
16
+ require("./skills/ModelContextProtocol"),
16
17
  //require("./skills/AdaptiveFeedback"),
17
18
  ];
18
19
  };
@@ -151,10 +152,10 @@ const process_interaction = async (
151
152
  //console.log("complArgs", JSON.stringify(complArgs, null, 2));
152
153
 
153
154
  const answer = await getState().functions.llm_generate.run("", complArgs);
154
- //console.log("answer", answer);
155
+ console.log("answer", answer);
155
156
 
156
157
  const responses = [];
157
- if (typeof answer === "object" && answer.image_calls) {
158
+ if (answer && typeof answer === "object" && answer.image_calls) {
158
159
  for (const image_call of answer.image_calls) {
159
160
  const tool = find_image_tool(config);
160
161
  let prcRes;
@@ -197,12 +198,13 @@ const process_interaction = async (
197
198
  ]
198
199
  : [{ role: "assistant", content: answer }],
199
200
  });
200
- if (typeof answer === "object" && answer.tool_calls) {
201
+ if (answer && typeof answer === "object" && (answer.tool_calls || answer.mcp_calls)) {
201
202
  if (answer.content)
202
203
  responses.push(wrapSegment(md.render(answer.content), agent_label));
203
204
  //const actions = [];
204
205
  let hasResult = false;
205
- for (const tool_call of answer.tool_calls) {
206
+ if ((answer.mcp_calls || []).length && !answer.content) hasResult = true;
207
+ for (const tool_call of answer.tool_calls || []) {
206
208
  console.log("call function", tool_call.function);
207
209
 
208
210
  await addToContext(run, {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@saltcorn/agents",
3
- "version": "0.3.1",
3
+ "version": "0.3.2",
4
4
  "description": "AI agents for Saltcorn",
5
5
  "main": "index.js",
6
6
  "dependencies": {
@@ -0,0 +1,67 @@
1
+ const { div, pre } = require("@saltcorn/markup/tags");
2
+ const Workflow = require("@saltcorn/data/models/workflow");
3
+ const Form = require("@saltcorn/data/models/form");
4
+ const Table = require("@saltcorn/data/models/table");
5
+ const File = require("@saltcorn/data/models/file");
6
+ const View = require("@saltcorn/data/models/view");
7
+ const { getState } = require("@saltcorn/data/db/state");
8
+ const db = require("@saltcorn/data/db");
9
+ const { eval_expression } = require("@saltcorn/data/models/expression");
10
+ const { interpolate } = require("@saltcorn/data/utils");
11
+
12
+ class ModelContextProtocol {
13
+ static skill_name = "Model Context Protocol";
14
+
15
+ get skill_label() {
16
+ return `Model Context Protocol: ${this.server_label}`;
17
+ }
18
+
19
+ constructor(cfg) {
20
+ Object.assign(this, cfg);
21
+ }
22
+
23
+ static async configFields() {
24
+ return [
25
+ {
26
+ name: "server_label",
27
+ label: "Server label",
28
+ type: "String",
29
+ required: true,
30
+ },
31
+ {
32
+ name: "server_url",
33
+ label: "Server URL",
34
+ type: "String",
35
+ required: true,
36
+ },
37
+ {
38
+ name: "header_key",
39
+ label: "Header key",
40
+ type: "String",
41
+ sublabel:
42
+ "Optional, for authorization. Which HTTP header should be set? For example <code>Authorization</code>",
43
+ },
44
+ {
45
+ name: "header_value",
46
+ label: "Header value",
47
+ type: "String",
48
+ sublabel:
49
+ "Optional, for authorization. What is the value of the HTTP header? For example <code>Bearer {api_key}</code>",
50
+ },
51
+ ];
52
+ }
53
+
54
+ provideTools() {
55
+ const tool = {
56
+ type: "mcp",
57
+ server_label: this.server_label,
58
+ server_url: this.server_url,
59
+ require_approval: "never",
60
+ };
61
+ if (this.header_key && this.header_value)
62
+ tool.headers = { [this.header_key]: this.header_value };
63
+ return tool;
64
+ }
65
+ }
66
+
67
+ module.exports = ModelContextProtocol;