paperclip-plugin-mattermost 0.18.1 → 0.18.3

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/README.md CHANGED
@@ -85,7 +85,7 @@ PAPERCLIP_REF=<commit> node build.mjs # build for another Paperclip version
85
85
  Bump `version` in `package.json` and `src/manifest.ts`, commit, then tag and push:
86
86
 
87
87
  ```bash
88
- git tag -a v0.18.1 -m v0.18.1 && git push origin main v0.18.1
88
+ git tag -a v0.18.3 -m v0.18.3 && git push origin main v0.18.3
89
89
  ```
90
90
 
91
91
  GitHub Actions builds, tests and publishes to npm through npm trusted publishing, so no npm token is involved.
package/dist/manifest.js CHANGED
@@ -84,7 +84,7 @@ var route = (routeKey, method, path) => ({ routeKey, method, path, auth: "agent"
84
84
  var manifest = {
85
85
  id: "mattermost-bridge",
86
86
  apiVersion: 1,
87
- version: "0.18.1",
87
+ version: "0.18.3",
88
88
  displayName: "Mattermost",
89
89
  description: "Every agent becomes its own Mattermost bot. DM an agent or mention it in a channel and it answers in the thread, showing its steps as it works; follow-ups continue the conversation. Paperclip approvals arrive with Approve / Reject buttons.",
90
90
  author: "Haseeb Azhar",
package/dist/worker.js CHANGED
@@ -45365,6 +45365,8 @@ var STATUS_WORDS = {
45365
45365
  };
45366
45366
  var WorkLinks = class {
45367
45367
  d;
45368
+ /** One task's updates, one at a time: Paperclip sends several at once and each would report the change. */
45369
+ queue = /* @__PURE__ */ new Map();
45368
45370
  constructor(deps) {
45369
45371
  this.d = deps;
45370
45372
  }
@@ -45383,33 +45385,60 @@ var WorkLinks = class {
45383
45385
  const c = (await this.d.comments(issueId)).find((x) => x.id === commentId);
45384
45386
  if (!c?.body?.trim()) return;
45385
45387
  const body = c.body.trim().slice(0, 12e3);
45386
- const own2 = c.authorAgentId && this.d.hasBot(c.authorAgentId);
45387
- const text2 = own2 ? body : `**${c.authorAgentId ? this.d.agentName(c.authorAgentId) : "A team member"}** commented on ${this.label(hit.link)}:
45388
+ const quoted = `**${c.authorAgentId ? this.d.agentName(c.authorAgentId) : "A team member"}** commented on ${this.label(hit.link)}:
45388
45389
 
45389
45390
  ${body}`;
45390
- await this.d.post(own2 ? c.authorAgentId : hit.link.agentId, hit.channelId, "", text2);
45391
+ if (c.authorAgentId && c.authorAgentId !== hit.link.agentId && this.d.hasBot(c.authorAgentId)) {
45392
+ try {
45393
+ return await this.d.post(c.authorAgentId, hit.channelId, "", body);
45394
+ } catch {
45395
+ }
45396
+ }
45397
+ await this.d.post(hit.link.agentId, hit.channelId, "", c.authorAgentId === hit.link.agentId ? body : quoted);
45398
+ }
45399
+ serial(key, run) {
45400
+ const next = (this.queue.get(key) ?? Promise.resolve()).catch(() => {
45401
+ }).then(run);
45402
+ this.queue.set(key, next);
45403
+ void next.catch(() => {
45404
+ }).finally(() => {
45405
+ if (this.queue.get(key) === next) this.queue.delete(key);
45406
+ });
45407
+ return next;
45391
45408
  }
45392
45409
  /**
45393
45410
  * A task asked for in a Mattermost thread (created by the agent while answering there): when it is
45394
45411
  * done, cancelled or blocked, its outcome (the last comment) is posted back in that thread, so the
45395
45412
  * result always reaches the conversation it came from.
45396
45413
  */
45397
- async threadUpdate(issueId) {
45414
+ threadUpdate(issueId) {
45415
+ return this.serial(`thread:${issueId}`, () => this.reportToThread(issueId));
45416
+ }
45417
+ async reportToThread(issueId) {
45398
45418
  const at = await this.d.store.get(`issuethread:${issueId}`);
45399
45419
  if (!at) return;
45400
45420
  const task2 = await this.d.task(issueId);
45401
45421
  if (!task2 || task2.status === at.status || !THREAD_REPORTS[task2.status]) return;
45422
+ const by = [at.agentId, task2.assigneeAgentId].find((a) => Boolean(a && this.d.hasBot(a)));
45423
+ if (!by) return;
45402
45424
  await this.d.store.set(`issuethread:${issueId}`, { ...at, status: task2.status });
45403
45425
  const last = (await this.d.comments(issueId)).at(-1)?.body?.trim();
45404
45426
  const outcome = last ? `
45405
45427
 
45406
45428
  ${last.length > 3e3 ? last.slice(0, 3e3) + "\u2026" : last}` : "";
45407
- const by = [task2.assigneeAgentId, at.agentId].find((a) => Boolean(a && this.d.hasBot(a)));
45408
- if (!by) return;
45409
- await this.d.post(by, at.channelId, at.rootId, `${THREAD_REPORTS[task2.status]} **${task2.identifier ?? "The task"}** ${task2.title}${outcome}`);
45429
+ const doer = task2.assigneeAgentId && task2.assigneeAgentId !== by ? ` _(by ${this.d.agentName(task2.assigneeAgentId)})_` : "";
45430
+ try {
45431
+ await this.d.post(by, at.channelId, at.rootId, `${THREAD_REPORTS[task2.status]} **${task2.identifier ?? "The task"}** ${task2.title}${doer}${outcome}`);
45432
+ } catch (err) {
45433
+ await this.d.store.set(`issuethread:${issueId}`, at);
45434
+ throw err;
45435
+ }
45410
45436
  }
45411
45437
  /** The task changed: note a new status; on done or cancelled, archive and report back. */
45412
- async updated(issueId) {
45438
+ updated(issueId) {
45439
+ return this.serial(`link:${issueId}`, () => this.followLink(issueId));
45440
+ }
45441
+ async followLink(issueId) {
45413
45442
  const hit = await this.linked(issueId);
45414
45443
  if (!hit) return;
45415
45444
  const task2 = await this.d.task(issueId);
@@ -46365,7 +46394,7 @@ var route = (routeKey, method, path3) => ({ routeKey, method, path: path3, auth:
46365
46394
  var manifest = {
46366
46395
  id: "mattermost-bridge",
46367
46396
  apiVersion: 1,
46368
- version: "0.18.1",
46397
+ version: "0.18.3",
46369
46398
  displayName: "Mattermost",
46370
46399
  description: "Every agent becomes its own Mattermost bot. DM an agent or mention it in a channel and it answers in the thread, showing its steps as it works; follow-ups continue the conversation. Paperclip approvals arrive with Approve / Reject buttons.",
46371
46400
  author: "Haseeb Azhar",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "paperclip-plugin-mattermost",
3
- "version": "0.18.1",
3
+ "version": "0.18.3",
4
4
  "description": "Paperclip agents in Mattermost: a bot per agent, live progress, files, approval and decision buttons, and per-person access, for each Paperclip company.",
5
5
  "type": "module",
6
6
  "license": "MIT",