@saltcorn/copilot 0.3.0 → 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.
@@ -20,14 +20,15 @@ class GenerateTables {
20
20
  data_type: { const: ty.name },
21
21
  };
22
22
  const attrs = apply(ty.attributes, {}) || [];
23
- attrs.forEach((a) => {
24
- properties[a.name] = {
25
- description:
26
- a.copilot_description ||
27
- `${a.label}.${a.sublabel ? ` ${a.sublabel}` : ""}`,
28
- ...fieldProperties(a),
29
- };
30
- });
23
+ if (Array.isArray(attrs))
24
+ attrs.forEach((a) => {
25
+ properties[a.name] = {
26
+ description:
27
+ a.copilot_description ||
28
+ `${a.label}.${a.sublabel ? ` ${a.sublabel}` : ""}`,
29
+ ...fieldProperties(a),
30
+ };
31
+ });
31
32
  return {
32
33
  type: "object",
33
34
  description: ty.copilot_description || ty.description,
package/chat-copilot.js CHANGED
@@ -33,6 +33,8 @@ const {
33
33
  getPromptFromTemplate,
34
34
  incompleteCfgMsg,
35
35
  } = require("./common");
36
+ const MarkdownIt = require("markdown-it"),
37
+ md = new MarkdownIt();
36
38
 
37
39
  const get_state_fields = () => [];
38
40
 
@@ -85,7 +87,9 @@ const run = async (table_id, viewname, cfg, state, { res, req }) => {
85
87
  div(
86
88
  { class: "interaction-segment" },
87
89
  span({ class: "badge bg-secondary" }, "Copilot"),
88
- p(interact.content)
90
+ typeof interact.content === "string"
91
+ ? md.render(interact.content)
92
+ : interact.content
89
93
  )
90
94
  );
91
95
  break;
@@ -154,18 +158,19 @@ const run = async (table_id, viewname, cfg, state, { res, req }) => {
154
158
  button(
155
159
  {
156
160
  type: "button",
157
- class: "btn btn-secondary btn-sm",
161
+ class: "btn btn-secondary btn-sm py-0",
162
+ style: "font-size: 0.9em;height:1.5em",
158
163
  onclick: "unset_state_field('run_id')",
159
164
  title: "New session",
160
165
  },
161
- i({ class: "fas fa-redo" })
166
+ i({ class: "fas fa-redo fa-sm" })
162
167
  )
163
168
  ),
164
169
  prevRuns.map((run) =>
165
170
  div(
166
171
  {
167
172
  onclick: `set_state_field('run_id',${run.id})`,
168
- class: "prevcopilotrun",
173
+ class: "prevcopilotrun border p-2",
169
174
  },
170
175
  localeDateTime(run.started_at),
171
176
 
@@ -200,9 +205,8 @@ const run = async (table_id, viewname, cfg, state, { res, req }) => {
200
205
  `div.interaction-segment:not(:first-child) {border-top: 1px solid #e7e7e7; }
201
206
  div.interaction-segment {padding-top: 5px;padding-bottom: 5px;}
202
207
  div.interaction-segment p {margin-bottom: 0px;}
203
- div.interaction-segment div.card {margin-top: 0.5rem;}
204
- div.prevcopilotrun {border-top: 1px solid #e7e7e7;border-right: 1px solid #e7e7e7;padding-top:3px; padding-bottom:3px; padding-right: 1rem;}
205
- div.prevcopilotrun:hover {cursor: pointer}
208
+ div.interaction-segment div.card {margin-top: 0.5rem;}
209
+ div.prevcopilotrun:hover {cursor: pointer; background-color: var(--tblr-secondary-bg-subtle, var(--bs-secondary-bg-subtle, gray));}
206
210
  .copilot-entry .submit-button:hover { cursor: pointer}
207
211
 
208
212
  .copilot-entry .submit-button {
@@ -238,7 +242,7 @@ const run = async (table_id, viewname, cfg, state, { res, req }) => {
238
242
  function restore_old_button_elem(btn) {
239
243
  const oldText = $(btn).data("old-text");
240
244
  btn.html(oldText);
241
- btn.css({ width: "" });
245
+ btn.css({ width: "" }).prop("disabled", false);
242
246
  btn.removeData("old-text");
243
247
  }
244
248
  function processExecuteResponse(res) {
@@ -382,7 +386,10 @@ const interact = async (table_id, viewname, config, body, { req }) => {
382
386
  actions.push(markup);
383
387
  }
384
388
  return { json: { success: "ok", actions, run_id: run.id } };
385
- } else return { json: { success: "ok", response: answer, run_id: run.id } };
389
+ } else
390
+ return {
391
+ json: { success: "ok", response: md.render(answer), run_id: run.id },
392
+ };
386
393
  };
387
394
 
388
395
  const renderToolcall = async (tool_call, viewname, implemented, run) => {
@@ -409,9 +416,9 @@ const wrapAction = (
409
416
  implemented,
410
417
  run
411
418
  ) =>
419
+ span({ class: "badge bg-info ms-1" }, actionClass.title) +
412
420
  div(
413
- { class: "card mb-3" },
414
- div({ class: "card-header" }, h5(actionClass.title)),
421
+ { class: "card mb-3 bg-secondary-subtle" },
415
422
  div(
416
423
  { class: "card-body" },
417
424
  inner_markup,
package/common.js CHANGED
@@ -1,4 +1,3 @@
1
- const axios = require("axios");
2
1
  const fsp = require("fs").promises;
3
2
  const _ = require("underscore");
4
3
  const path = require("path");
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@saltcorn/copilot",
3
- "version": "0.3.0",
3
+ "version": "0.3.2",
4
4
  "description": "AI assistant for building Saltcorn applications",
5
5
  "main": "index.js",
6
6
  "dependencies": {
7
7
  "@saltcorn/data": "^0.9.0",
8
- "axios": "0.16.2",
9
8
  "underscore": "1.13.6",
10
- "node-sql-parser": "4.15.0"
9
+ "node-sql-parser": "4.15.0",
10
+ "markdown-it": "14.1.0"
11
11
  },
12
12
  "author": "Tom Nielsen",
13
13
  "license": "MIT",