@saltcorn/copilot 0.4.0 → 0.4.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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/user-copilot.js +23 -22
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@saltcorn/copilot",
3
- "version": "0.4.0",
3
+ "version": "0.4.1",
4
4
  "description": "AI assistant for building Saltcorn applications",
5
5
  "main": "index.js",
6
6
  "dependencies": {
package/user-copilot.js CHANGED
@@ -193,15 +193,16 @@ const run = async (table_id, viewname, config, state, { res, req }) => {
193
193
  );
194
194
  if (action) {
195
195
  const row = JSON.parse(tool_call.function.arguments);
196
- interactMarkups.push(
197
- wrapSegment(
198
- wrapCard(
199
- action.trigger_name,
200
- pre(JSON.stringify(row, null, 2))
201
- ),
202
- "Copilot"
203
- )
204
- );
196
+ if (Object.keys(row || {}).length)
197
+ interactMarkups.push(
198
+ wrapSegment(
199
+ wrapCard(
200
+ action.trigger_name,
201
+ pre(JSON.stringify(row, null, 2))
202
+ ),
203
+ "Copilot"
204
+ )
205
+ );
205
206
  }
206
207
  }
207
208
  } else
@@ -233,11 +234,7 @@ const run = async (table_id, viewname, config, state, { res, req }) => {
233
234
  wrapSegment(
234
235
  wrapCard(
235
236
  interact.name,
236
- pre(
237
- interact.name.startsWith("Query")
238
- ? JSON.stringify(JSON.parse(interact.content), null, 2)
239
- : JSON.stringify(interact.content, null, 2)
240
- )
237
+ pre(JSON.stringify(JSON.parse(interact.content), null, 2))
241
238
  ),
242
239
  "Copilot"
243
240
  )
@@ -636,12 +633,13 @@ const process_interaction = async (
636
633
  if (action) {
637
634
  const trigger = Trigger.findOne({ name: action.trigger_name });
638
635
  const row = JSON.parse(tool_call.function.arguments);
639
- responses.push(
640
- wrapSegment(
641
- wrapCard(action.trigger_name, pre(JSON.stringify(row, null, 2))),
642
- "Copilot"
643
- )
644
- );
636
+ if (Object.keys(row || {}).length)
637
+ responses.push(
638
+ wrapSegment(
639
+ wrapCard(action.trigger_name, pre(JSON.stringify(row, null, 2))),
640
+ "Copilot"
641
+ )
642
+ );
645
643
  const result = await trigger.runWithoutRow({ user: req.user, row });
646
644
  console.log("ran trigger with result", {
647
645
  name: trigger.name,
@@ -667,7 +665,7 @@ const process_interaction = async (
667
665
  role: "tool",
668
666
  tool_call_id: tool_call.id,
669
667
  name: tool_call.function.name,
670
- content: result || "Action run",
668
+ content: result ? JSON.stringify(result) : "Action run",
671
669
  },
672
670
  ],
673
671
  });
@@ -676,7 +674,10 @@ const process_interaction = async (
676
674
  name: tool_call.function.name.replace("Query", ""),
677
675
  });
678
676
  const query = JSON.parse(tool_call.function.arguments);
679
- const result = await table.getRows(query);
677
+ const result = await table.getRows(query, {
678
+ forUser: req.user,
679
+ forPublic: !req.user,
680
+ });
680
681
  await addToContext(run, {
681
682
  interactions: [
682
683
  {