@saltcorn/agents 0.8.8 → 0.8.9

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/agent-view.js +55 -14
  2. package/package.json +1 -1
package/agent-view.js CHANGED
@@ -337,14 +337,25 @@ const run = async (
337
337
  let hasInputForm = true;
338
338
 
339
339
  const initial_q = state.run_id ? undefined : state._q;
340
+ let run;
340
341
  if (state.run_id) {
341
- let run = prevRuns ? prevRuns.find((r) => r.id == state.run_id) : null;
342
+ run = prevRuns ? prevRuns.find((r) => r.id == state.run_id) : null;
342
343
  if (!run)
343
344
  run = await WorkflowRun.findOne({
344
345
  trigger_id: action.id,
345
- ...(shared ? {} : { started_by: req.user?.id }),
346
+ //...(shared ? {} : { started_by: req.user?.id }),
346
347
  id: state.run_id,
347
348
  });
349
+
350
+ if (
351
+ run &&
352
+ !shared &&
353
+ run.started_by != req.user?.id &&
354
+ run.context.share_token !== (state.share_token || "none")
355
+ )
356
+ run = null;
357
+ }
358
+ if (run) {
348
359
  const interactMarkups = [];
349
360
  if (run.context.html_interactions) {
350
361
  interactMarkups.push(...run.context.html_interactions);
@@ -508,9 +519,7 @@ const run = async (
508
519
  onsubmit: `event.preventDefault();const _fd=new FormData(this);spin_send_button();view_post('${viewname}', 'interact', _fd, ${dyn_updates ? "null" : "processCopilotResponse"});return false;`,
509
520
  class: [
510
521
  "form-namespace copilot agent-view",
511
- footerInputMode
512
- ? "mt-auto sticky-bottom bg-body py-1"
513
- : "mt-2",
522
+ footerInputMode ? "mt-auto sticky-bottom bg-body py-1" : "mt-2",
514
523
  ],
515
524
  method: "post",
516
525
  },
@@ -752,6 +761,7 @@ const run = async (
752
761
  $("textarea[name=userinput]").val("")
753
762
  $('div.next_response_scratch').html("")
754
763
  window['stream scratch ${viewname} ${rndid}'] = []
764
+ $("button.modern-share").show()
755
765
  if(res.response) {
756
766
  $(".agent-waiting-indicator").remove();
757
767
  $("#copilotinteractions").append(res.response);
@@ -1044,6 +1054,20 @@ const run = async (
1044
1054
  if (a) { try { a.pause(); } catch(e){} a.src = ''; }
1045
1055
  }
1046
1056
  };
1057
+
1058
+ window.share_agent_chat = function(btn, viewname) {
1059
+ const runid = $("input[name=run_id").val()
1060
+ view_post(viewname, 'share_chat', {run_id:runid}, async (data)=>{
1061
+ console.log(data)
1062
+ const clipboardItemData = {
1063
+ ["text/plain"]: window.location.origin+'/view/'+viewname+'?run_id='+runid+(data.share_token ? "&share_token="+data.share_token:"")
1064
+ };
1065
+ const clipboardItem = new ClipboardItem(clipboardItemData);
1066
+ await navigator.clipboard.write([clipboardItem]);
1067
+ common_done({notify: "Share link copied to clipboard", remove_delay: 1})
1068
+
1069
+ })
1070
+ };
1047
1071
  /* Restore toggle state on load */
1048
1072
  (function() {
1049
1073
  try {
@@ -1166,16 +1190,22 @@ const run = async (
1166
1190
  i({ class: "fas fa-bars" }),
1167
1191
  )
1168
1192
  : "",
1169
- span(
1170
- { class: "flex-grow-1 text-truncate fw-semibold" },
1171
- headerTitle,
1193
+ span({ class: "flex-grow-1 text-truncate fw-semibold" }, headerTitle),
1194
+ button(
1195
+ {
1196
+ type: "button",
1197
+ style: run ? undefined : { display: "none" },
1198
+ class: "btn btn-sm btn-outline-secondary modern-share",
1199
+ onclick: `share_agent_chat(this, '${viewname}')`,
1200
+ title: req.__("Share chat"),
1201
+ },
1202
+ i({ class: "fas fa-share-alt" }),
1172
1203
  ),
1173
1204
  hasTTS
1174
1205
  ? button(
1175
1206
  {
1176
1207
  type: "button",
1177
- class:
1178
- "btn btn-sm btn-outline-secondary modern-tts-toggle",
1208
+ class: "btn btn-sm btn-outline-secondary modern-tts-toggle",
1179
1209
  onclick: `toggle_agent_tts(this, '${viewname}')`,
1180
1210
  title: req.__("Read responses aloud"),
1181
1211
  "data-tts-state": "off",
@@ -1199,10 +1229,7 @@ const run = async (
1199
1229
  ? div(
1200
1230
  { class: "modern-chat-noncard d-flex flex-column" },
1201
1231
  modern_chat_header,
1202
- div(
1203
- { class: "modern-chat-layout d-flex flex-column" },
1204
- main_inner,
1205
- ),
1232
+ div({ class: "modern-chat-layout d-flex flex-column" }, main_inner),
1206
1233
  )
1207
1234
  : layout === "No card"
1208
1235
  ? div({ class: "mx-1" }, main_inner)
@@ -1409,6 +1436,19 @@ const cancel = async (table_id, viewname, config, body, { req, res }) => {
1409
1436
  return;
1410
1437
  };
1411
1438
 
1439
+ const share_chat = async (table_id, viewname, config, body, { req, res }) => {
1440
+ const { run_id } = body;
1441
+ const run = await WorkflowRun.findOne({ id: +run_id });
1442
+ if (run.context.share_token)
1443
+ return { json: { share_token: run.context.share_token } };
1444
+ else {
1445
+ if (run.started_by != req.user?.id && !config.shared) return;
1446
+ const rndid = Math.floor(Math.random() * 16777215).toString(16);
1447
+ await run.update({ context: { ...run.context, share_token: rndid } });
1448
+ return { json: { share_token: rndid } };
1449
+ }
1450
+ };
1451
+
1412
1452
  const debug_info = async (table_id, viewname, config, body, { req, res }) => {
1413
1453
  const { run_id, triggering_row_id } = body;
1414
1454
  const action =
@@ -1726,6 +1766,7 @@ module.exports = {
1726
1766
  execute_user_action,
1727
1767
  cancel,
1728
1768
  tts,
1769
+ share_chat,
1729
1770
  },
1730
1771
  mobile_render_server_side: true,
1731
1772
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@saltcorn/agents",
3
- "version": "0.8.8",
3
+ "version": "0.8.9",
4
4
  "description": "AI agents for Saltcorn",
5
5
  "main": "index.js",
6
6
  "dependencies": {