@grknbyk/agent-wire 0.13.4 → 0.13.5
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/package.json +1 -1
- package/src/protocol.mjs +8 -1
package/package.json
CHANGED
package/src/protocol.mjs
CHANGED
|
@@ -86,6 +86,12 @@ const RECIPIENT_MARK = { agent: '@', human: '+' };
|
|
|
86
86
|
export const addressLine = ({ from, to, toKind }) =>
|
|
87
87
|
`${from} => ${to === 'all' ? 'all' : `${RECIPIENT_MARK[toKind] ?? ''}${to}`}`;
|
|
88
88
|
|
|
89
|
+
// A mark set as ":fire:" is six characters here and one emoji in Slack, so
|
|
90
|
+
// measuring the string overshot the padding by four columns on every line this
|
|
91
|
+
// agent sent. Slack is the only place this header is read, so Slack's width wins.
|
|
92
|
+
const SHORTCODE = /^:[a-z0-9_+-]+:$/i;
|
|
93
|
+
const markWidth = (mark) => (SHORTCODE.test(mark) ? 2 : displayWidth(mark));
|
|
94
|
+
|
|
89
95
|
export function formatMessage({ mark, from, to, toKind, text, ref, channel }) {
|
|
90
96
|
const left = `${mark ? `${mark} ` : ''}${addressLine({ from, to, toKind })}`;
|
|
91
97
|
if (!ref) return `${left}\n${toSlackText(text)}\n`;
|
|
@@ -95,7 +101,8 @@ export function formatMessage({ mark, from, to, toKind, text, ref, channel }) {
|
|
|
95
101
|
if (!channel) throw new TypeError(`formatMessage: ref ${ref} with no channel to put in front of it`);
|
|
96
102
|
|
|
97
103
|
const handle = `${channel}@${ref}`;
|
|
98
|
-
const
|
|
104
|
+
const drawn = mark ? markWidth(mark) + 1 + displayWidth(addressLine({ from, to, toKind })) : displayWidth(left);
|
|
105
|
+
const gap = Math.max(1, HEADER_WIDTH - drawn - handle.length);
|
|
99
106
|
return `${left}${' '.repeat(gap)}${handle}\n${toSlackText(text)}\n`;
|
|
100
107
|
}
|
|
101
108
|
|