skill-monster 0.0.0-stage → 0.1.0
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/LICENSE +202 -0
- package/README.md +155 -2
- package/desk-ui/app.css +73 -0
- package/desk-ui/app.js +182 -0
- package/desk-ui/fonts/bricolage-grotesque-800.woff2 +0 -0
- package/desk-ui/fonts/ibm-plex-mono-400.woff2 +0 -0
- package/desk-ui/fonts/ibm-plex-mono-600.woff2 +0 -0
- package/desk-ui/fonts/ibm-plex-sans-400.woff2 +0 -0
- package/desk-ui/fonts/silkscreen-400.woff2 +0 -0
- package/desk-ui/fonts.css +70 -0
- package/desk-ui/index.html +29 -0
- package/desk-ui/mascot.svg +1 -0
- package/dist/build.json +1 -0
- package/dist/cli/index.d.ts +2 -0
- package/dist/cli/index.js +640 -0
- package/dist/cli/ui.d.ts +18 -0
- package/dist/cli/ui.js +120 -0
- package/dist/core/checkup.d.ts +14 -0
- package/dist/core/checkup.js +69 -0
- package/dist/core/corrections.d.ts +54 -0
- package/dist/core/corrections.js +138 -0
- package/dist/core/digest.d.ts +36 -0
- package/dist/core/digest.js +91 -0
- package/dist/core/export.d.ts +8 -0
- package/dist/core/export.js +28 -0
- package/dist/core/external.d.ts +48 -0
- package/dist/core/external.js +127 -0
- package/dist/core/guard.d.ts +10 -0
- package/dist/core/guard.js +48 -0
- package/dist/core/mirror.d.ts +37 -0
- package/dist/core/mirror.js +148 -0
- package/dist/core/release.d.ts +69 -0
- package/dist/core/release.js +173 -0
- package/dist/core/report.d.ts +10 -0
- package/dist/core/report.js +65 -0
- package/dist/core/scrub.d.ts +20 -0
- package/dist/core/scrub.js +67 -0
- package/dist/core/sign.d.ts +25 -0
- package/dist/core/sign.js +86 -0
- package/dist/core/skill.d.ts +26 -0
- package/dist/core/skill.js +68 -0
- package/dist/core/starters.d.ts +54 -0
- package/dist/core/starters.js +184 -0
- package/dist/core/types.d.ts +187 -0
- package/dist/core/types.js +1 -0
- package/dist/core/version.d.ts +4 -0
- package/dist/core/version.js +17 -0
- package/dist/core/workspace.d.ts +23 -0
- package/dist/core/workspace.js +79 -0
- package/dist/desk/server.d.ts +10 -0
- package/dist/desk/server.js +140 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +10 -0
- package/dist/mcp/server.d.ts +8 -0
- package/dist/mcp/server.js +112 -0
- package/dist/providers/index.d.ts +15 -0
- package/dist/providers/index.js +123 -0
- package/dist/slack/api.d.ts +6 -0
- package/dist/slack/api.js +18 -0
- package/dist/slack/app.d.ts +70 -0
- package/dist/slack/app.js +387 -0
- package/dist/slack/manifest.d.ts +50 -0
- package/dist/slack/manifest.js +71 -0
- package/dist/slack/messages.d.ts +414 -0
- package/dist/slack/messages.js +226 -0
- package/dist/slack/socket.d.ts +24 -0
- package/dist/slack/socket.js +84 -0
- package/dist/stores/airtable.d.ts +26 -0
- package/dist/stores/airtable.js +52 -0
- package/dist/stores/confluence-format.d.ts +34 -0
- package/dist/stores/confluence-format.js +458 -0
- package/dist/stores/confluence.d.ts +55 -0
- package/dist/stores/confluence.js +204 -0
- package/dist/stores/index.d.ts +30 -0
- package/dist/stores/index.js +53 -0
- package/dist/stores/notion.d.ts +43 -0
- package/dist/stores/notion.js +313 -0
- package/docs/SECURITY.md +45 -0
- package/docs/slack.md +78 -0
- package/package.json +48 -4
- package/starters/_core/SKILL.md +30 -0
- package/starters/customer-support-answers/starter.yaml +98 -0
- package/starters/data-warehouse-kb/starter.yaml +119 -0
- package/starters/engineering-house-rules/starter.yaml +106 -0
- package/starters/people-policies/starter.yaml +89 -0
- package/starters/pricing-and-packaging/starter.yaml +90 -0
- package/starters/product-analytics-kb/starter.yaml +109 -0
- package/starters/security-questionnaire-answers/starter.yaml +94 -0
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
import { mrkdwn } from '../core/digest.js';
|
|
2
|
+
export const INVITE = "Want this for your own team's playbook? About 15 minutes, no sign-up, nothing leaves the company.";
|
|
3
|
+
export const DEFAULT_SETUP_URL = 'https://skillmonster.ai/start';
|
|
4
|
+
const md = (text) => ({ type: 'mrkdwn', text });
|
|
5
|
+
const plain = (text) => ({ type: 'plain_text', text: text.slice(0, 150), emoji: false });
|
|
6
|
+
const section = (text, extra = {}) => ({ type: 'section', text: md(text), ...extra });
|
|
7
|
+
const context = (...texts) => ({ type: 'context', elements: texts.map(md) });
|
|
8
|
+
const linkButton = (text, url, action_id, style) => ({ type: 'button', text: plain(text), url, action_id, ...(style ? { style } : {}) });
|
|
9
|
+
const list = (xs) => xs.length <= 1 ? xs.join('') : `${xs.slice(0, -1).join(', ')} and ${xs[xs.length - 1]}`;
|
|
10
|
+
/** Adds only a source tag naming the moment (from=receipt). No name, no id, nothing else. */
|
|
11
|
+
export function withSource(url, tag) {
|
|
12
|
+
try {
|
|
13
|
+
const u = new URL(url);
|
|
14
|
+
u.searchParams.set('from', tag);
|
|
15
|
+
return u.toString();
|
|
16
|
+
}
|
|
17
|
+
catch {
|
|
18
|
+
return url;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
export const setupUrl = (cfg, tag) => withSource(cfg.slack?.setup_url ?? DEFAULT_SETUP_URL, tag);
|
|
22
|
+
/* ---------- Receipts and decisions, sent to the person who flagged ---------- */
|
|
23
|
+
export function receiptMessage(cfg, r) {
|
|
24
|
+
const won = r.works_on.length > 0;
|
|
25
|
+
const blocks = [
|
|
26
|
+
section(won ? '*Fix live.* The monster ate the old rule.' : '*Fix approved.* The monster is still chewing.'),
|
|
27
|
+
section(mrkdwn(r.message)),
|
|
28
|
+
context(`${mrkdwn(r.correction)} · ${mrkdwn(r.skill)} ${mrkdwn(r.version)} · a guard test now checks it, so this mistake can't come back.`),
|
|
29
|
+
];
|
|
30
|
+
if (cfg.sharing.share_invitations && won) {
|
|
31
|
+
blocks.push(section(INVITE, { accessory: linkButton('Set up your own →', setupUrl(cfg, 'receipt'), 'sm_setup_receipt') }));
|
|
32
|
+
}
|
|
33
|
+
return { text: r.message, blocks };
|
|
34
|
+
}
|
|
35
|
+
export function declinedMessage(c) {
|
|
36
|
+
const note = c.resolution?.note?.trim() || 'No note given.';
|
|
37
|
+
return {
|
|
38
|
+
text: `${c.id} was reviewed and not taken into ${c.skill}.`,
|
|
39
|
+
blocks: [
|
|
40
|
+
section(`*${mrkdwn(c.id)} was reviewed and not taken into ${mrkdwn(c.skill)}.*`),
|
|
41
|
+
section(`The curator's note: ${mrkdwn(note)}`),
|
|
42
|
+
context('Still think the answer is wrong? Flag it again with more detail. Nobody is keeping score.'),
|
|
43
|
+
],
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
/* ---------- Flagging a wrong answer ---------- */
|
|
47
|
+
export const FLAG_CALLBACK = 'sm_flag';
|
|
48
|
+
export const FLAG_CONFIRM_CALLBACK = 'sm_flag_confirm';
|
|
49
|
+
export function flagModal(skills, prefill = {}) {
|
|
50
|
+
const options = skills.slice(0, 100).map(s => ({ text: plain(`${s.title || s.name} (${s.name})`), value: s.name }));
|
|
51
|
+
const input = (block_id, label, opts) => ({
|
|
52
|
+
type: 'input', block_id, optional: !!opts.optional, label: plain(label),
|
|
53
|
+
...(opts.hint ? { hint: plain(opts.hint) } : {}),
|
|
54
|
+
element: {
|
|
55
|
+
type: 'plain_text_input', action_id: 'v', multiline: !!opts.multiline, max_length: opts.max ?? 1000,
|
|
56
|
+
...(opts.initial ? { initial_value: opts.initial.slice(0, opts.max ?? 1000) } : {}),
|
|
57
|
+
...(opts.placeholder ? { placeholder: plain(opts.placeholder) } : {}),
|
|
58
|
+
},
|
|
59
|
+
});
|
|
60
|
+
return {
|
|
61
|
+
type: 'modal', callback_id: FLAG_CALLBACK,
|
|
62
|
+
title: plain('Flag a wrong answer'), submit: plain('Preview'), close: plain('Cancel'),
|
|
63
|
+
blocks: [
|
|
64
|
+
context("Nothing is sent until you see the preview. Names, customer data, amounts and secrets are removed first."),
|
|
65
|
+
{
|
|
66
|
+
type: 'input', block_id: 'skill', label: plain('Which skill gave the answer?'),
|
|
67
|
+
element: { type: 'static_select', action_id: 'v', options, ...(options.length === 1 ? { initial_option: options[0] } : {}), placeholder: plain('Pick a skill') },
|
|
68
|
+
},
|
|
69
|
+
input('question', 'What was asked?', { multiline: true, initial: prefill.question, max: 500 }),
|
|
70
|
+
input('answer', 'The answer you got', { multiline: true, initial: prefill.answer, optional: true, max: 600, hint: 'Only the first 600 characters are kept.' }),
|
|
71
|
+
input('wrong', 'What was wrong?', { multiline: true, max: 800, placeholder: "e.g. pending refunds shouldn't count in the running balance" }),
|
|
72
|
+
input('rule', 'What should the rule say? (optional)', { multiline: true, optional: true, max: 800 }),
|
|
73
|
+
input('role', 'Your team or role (optional)', { optional: true, max: 40, hint: 'Shown to the curator instead of your name.', placeholder: 'Growth' }),
|
|
74
|
+
],
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
const SECRET_KINDS = ['API key', 'AWS key', 'GitHub token', 'Slack token', 'Google key', 'Notion token', 'private key', 'password-like value'];
|
|
78
|
+
/** The serious one. Shown when the text held something that looks like a credential. */
|
|
79
|
+
export function securityWarning(removed) {
|
|
80
|
+
const secrets = removed.filter(r => SECRET_KINDS.includes(r));
|
|
81
|
+
if (!secrets.length)
|
|
82
|
+
return undefined;
|
|
83
|
+
return section(`*Security: this text held something that looks like a ${list(secrets)}.* It was removed and is not in the correction. If it is real, rotate it now: anyone who can read the original message may have seen it.`);
|
|
84
|
+
}
|
|
85
|
+
export function flagPreviewModal(p, owner, pendingId) {
|
|
86
|
+
const field = (label, v) => v ? section(`*${label}*\n${mrkdwn(v)}`) : undefined;
|
|
87
|
+
const warn = securityWarning(p.removed);
|
|
88
|
+
return {
|
|
89
|
+
type: 'modal', callback_id: FLAG_CONFIRM_CALLBACK, private_metadata: pendingId,
|
|
90
|
+
title: plain('Check before sending'), submit: plain(`Send to ${owner}`.slice(0, 24)), close: plain('Cancel'),
|
|
91
|
+
blocks: [
|
|
92
|
+
...(warn ? [warn] : []),
|
|
93
|
+
section(`This is exactly what *${mrkdwn(owner)}* (owner of *${mrkdwn(p.skill)}*) will get. Your name is not on it.`),
|
|
94
|
+
{ type: 'divider' },
|
|
95
|
+
field('Skill', `${p.skill} ${p.version}`),
|
|
96
|
+
field('Question', p.question),
|
|
97
|
+
field('Answer', p.answer_excerpt),
|
|
98
|
+
field('What was wrong', p.what_was_wrong),
|
|
99
|
+
field('Suggested rule', p.suggested_rule),
|
|
100
|
+
field('From', p.reporter_role),
|
|
101
|
+
...(p.removed.length ? [context(`Removed before sending: ${mrkdwn(list(p.removed))}.`)] : [context('Nothing needed removing.')]),
|
|
102
|
+
].filter(Boolean),
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
export function flagFiledModal(c, owner) {
|
|
106
|
+
return {
|
|
107
|
+
type: 'modal', title: plain('Fed to the monster'), close: plain('Done'),
|
|
108
|
+
blocks: [
|
|
109
|
+
section(`*${mrkdwn(c.id)} filed.* It's in ${mrkdwn(owner)}'s review queue for ${mrkdwn(c.skill)}.`),
|
|
110
|
+
context("You'll get a receipt in your Skill Monster DMs when the fix is live."),
|
|
111
|
+
],
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
export function flagFiledMessage(c, owner) {
|
|
115
|
+
return {
|
|
116
|
+
text: `${c.id} filed. It's in ${owner}'s review queue.`,
|
|
117
|
+
blocks: [
|
|
118
|
+
section(`*${mrkdwn(c.id)} filed.* Fed to ${mrkdwn(owner)}'s review queue for ${mrkdwn(c.skill)}. The monster has the scent.`),
|
|
119
|
+
context("You'll get a receipt right here when the fix is live. Your name isn't on the correction."),
|
|
120
|
+
],
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
/* ---------- Curator decisions ---------- */
|
|
124
|
+
export const APPROVE_CALLBACK = 'sm_approve_submit';
|
|
125
|
+
export const DECLINE_CALLBACK = 'sm_decline_submit';
|
|
126
|
+
export function approveModal(cors, meta, nextVersion) {
|
|
127
|
+
const c = cors[0];
|
|
128
|
+
const sections = meta.sections.slice(0, 100).map(s => ({ text: plain(s), value: s }));
|
|
129
|
+
const ids = cors.map(x => x.id).join(', ');
|
|
130
|
+
const ti = (block_id, label, o) => ({
|
|
131
|
+
type: 'input', block_id, optional: !!o.optional, label: plain(label), ...(o.hint ? { hint: plain(o.hint) } : {}),
|
|
132
|
+
element: { type: 'plain_text_input', action_id: 'v', multiline: !!o.multiline, max_length: o.max ?? 3000, ...(o.initial ? { initial_value: o.initial.slice(0, o.max ?? 3000) } : {}) },
|
|
133
|
+
});
|
|
134
|
+
return {
|
|
135
|
+
type: 'modal', callback_id: APPROVE_CALLBACK, private_metadata: cors.map(x => x.id).join(','),
|
|
136
|
+
title: plain(`Approve ${nextVersion}`), submit: plain('Sign and release'), close: plain('Cancel'),
|
|
137
|
+
blocks: [
|
|
138
|
+
section(`*${mrkdwn(ids)} · ${mrkdwn(meta.name)}*\n${mrkdwn(c.what_was_wrong)}`),
|
|
139
|
+
context(`Asked: ${mrkdwn(c.question.slice(0, 200))}`),
|
|
140
|
+
{ type: 'input', block_id: 'section', label: plain('Section to change'), element: { type: 'static_select', action_id: 'v', options: sections, placeholder: plain('Pick a section') } },
|
|
141
|
+
ti('old', 'Old text to replace (optional)', { multiline: true, optional: true, hint: 'Leave empty to add the new rule to the end of the section.' }),
|
|
142
|
+
ti('new', 'New rule', { multiline: true, initial: c.suggested_rule }),
|
|
143
|
+
ti('test', 'Guard test question', { initial: c.question, max: 500, hint: 'Asked on every model before release. This mistake can never come back without failing it.' }),
|
|
144
|
+
ti('expect', 'The answer must include', { max: 500, hint: 'Use | between acceptable phrasings and ; between things that must all appear, e.g. exclude|not include;pending refunds' }),
|
|
145
|
+
ti('exclude', 'The answer must not include (optional)', { optional: true, max: 500, hint: 'Separate with ;' }),
|
|
146
|
+
],
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
export function declineModal(cors) {
|
|
150
|
+
return {
|
|
151
|
+
type: 'modal', callback_id: DECLINE_CALLBACK, private_metadata: cors.map(x => x.id).join(','),
|
|
152
|
+
title: plain('Decline'), submit: plain('Decline'), close: plain('Cancel'),
|
|
153
|
+
blocks: [
|
|
154
|
+
section(`*${mrkdwn(cors.map(c => c.id).join(', '))}* · ${mrkdwn(cors[0].what_was_wrong)}`),
|
|
155
|
+
{ type: 'input', block_id: 'note', label: plain('Note for the person who flagged it'), element: { type: 'plain_text_input', action_id: 'v', multiline: true, max_length: 500 } },
|
|
156
|
+
],
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
export function workingModal(title, line) {
|
|
160
|
+
return { type: 'modal', title: plain(title), close: plain('Close'), blocks: [section(line), context("I'll DM you when it's done. You can close this.")] };
|
|
161
|
+
}
|
|
162
|
+
export function approveResultMessage(cfg, rec, receiptsSent, previous) {
|
|
163
|
+
const entries = Object.entries(rec.works_on);
|
|
164
|
+
const live = entries.filter(([, w]) => w.tested && w.failed.length === 0).map(([m]) => m);
|
|
165
|
+
const aud = cfg.audience ?? {};
|
|
166
|
+
const head = live.length
|
|
167
|
+
? `*${mrkdwn(rec.skill)} ${mrkdwn(rec.version)} signed and released.* The monster ate the old rule.`
|
|
168
|
+
: `*${mrkdwn(rec.skill)} ${mrkdwn(rec.version)} signed, but held on every model until the guard tests pass.* Nobody gets it yet.`;
|
|
169
|
+
const lines = entries.map(([m, w]) => !w.tested ? `${mrkdwn(m)}: not tested`
|
|
170
|
+
: w.failed.length ? `${mrkdwn(m)} held (${w.pass}/${w.total}): fails ${mrkdwn(w.failed.join(', '))}.${aud[m] ? ` The ${aud[m]} ${mrkdwn(m)} users stay on ${mrkdwn(previous ?? 'the last version')} automatically.` : ''}`
|
|
171
|
+
: `${mrkdwn(m)} ${w.pass}/${w.total}`);
|
|
172
|
+
const blocks = [section(head), section(`*Works-on check*\n${lines.join('\n')}`)];
|
|
173
|
+
blocks.push(context(`Guard test added: this mistake can't come back without failing a check. Receipts sent: ${receiptsSent}. Signed with key ${mrkdwn(rec.key_id)}.`));
|
|
174
|
+
if (cfg.slack?.release_channel && live.length) {
|
|
175
|
+
blocks.push({ type: 'actions', elements: [{ type: 'button', text: plain('Post release note'), action_id: 'sm_post_note', value: `${rec.skill}@${rec.version}` }] });
|
|
176
|
+
}
|
|
177
|
+
return { text: `${rec.skill} ${rec.version} signed${live.length ? ' and released' : ', held'}.`, blocks };
|
|
178
|
+
}
|
|
179
|
+
export function blockedMessage(findings) {
|
|
180
|
+
const items = findings.filter(f => f.level === 'block').map(f => `• ${mrkdwn(f.message)}`);
|
|
181
|
+
return {
|
|
182
|
+
text: 'Release blocked by the check-up. Nothing was released.',
|
|
183
|
+
blocks: [
|
|
184
|
+
section('*Release blocked by the check-up. Nothing was released.*'),
|
|
185
|
+
section(items.join('\n') || 'See the Desk for details.'),
|
|
186
|
+
context('Fix these in the skill, then approve again. Corrections stay open.'),
|
|
187
|
+
],
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
export function errorMessage(what, err) {
|
|
191
|
+
return { text: `${what} failed: ${err}`, blocks: [section(`*${mrkdwn(what)} failed.* Nothing was changed.`), context(mrkdwn(err.slice(0, 500)))] };
|
|
192
|
+
}
|
|
193
|
+
export function notCuratorText(cfg) {
|
|
194
|
+
return `Only curators can approve, decline or post release notes from Slack, and your Slack account isn't on the list. Ask ${cfg.curator} to add your Slack member ID under slack.curators in skill-monster.yaml.`;
|
|
195
|
+
}
|
|
196
|
+
/* ---------- Release note (the team-chat note) ---------- */
|
|
197
|
+
export function releaseNote(cfg, meta, rec, storeDescription) {
|
|
198
|
+
const live = Object.entries(rec.works_on).filter(([, w]) => w.tested && w.failed.length === 0).map(([m]) => m);
|
|
199
|
+
const facts = [
|
|
200
|
+
live.length ? `Works on ${list(live)}` : 'Waiting on guard tests',
|
|
201
|
+
`stays in ${cfg.org}'s ${storeDescription}`,
|
|
202
|
+
'connects via MCP',
|
|
203
|
+
].join(' · ');
|
|
204
|
+
const buttons = [];
|
|
205
|
+
if (cfg.slack?.install_url)
|
|
206
|
+
buttons.push(linkButton('Install in assistant', cfg.slack.install_url, 'sm_install', 'primary'));
|
|
207
|
+
if (cfg.sharing.share_invitations)
|
|
208
|
+
buttons.push(linkButton('Set up your own →', setupUrl(cfg, 'release-note'), 'sm_setup_note'));
|
|
209
|
+
const title = meta.title && meta.title !== meta.name ? ` (${meta.title})` : '';
|
|
210
|
+
return {
|
|
211
|
+
text: `${meta.name} ${rec.version} is signed and released. ${facts}.`,
|
|
212
|
+
blocks: [
|
|
213
|
+
section(`*${mrkdwn(meta.name)} ${mrkdwn(rec.version)} · signed*${mrkdwn(title)}\n${mrkdwn(rec.changelog)}`),
|
|
214
|
+
context(mrkdwn(facts)),
|
|
215
|
+
...(buttons.length ? [{ type: 'actions', elements: buttons }] : []),
|
|
216
|
+
...(cfg.sharing.share_invitations ? [context('Made with Skill Monster. Set up your own.')] : []),
|
|
217
|
+
],
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
export const HELP_TEXT = [
|
|
221
|
+
'*Skill Monster* · wrong answers have a natural predator.',
|
|
222
|
+
'• `/skill-monster flag` flags a wrong answer (or use *Flag a wrong answer* from any message\'s ⋯ menu)',
|
|
223
|
+
'• `/skill-monster digest` shows what is waiting for review (curators)',
|
|
224
|
+
'• `/skill-monster note <skill>` previews a release note you can post (curators)',
|
|
225
|
+
'Runs on your company\'s own server. Nothing is sent to Skill Monster.',
|
|
226
|
+
].join('\n');
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Slack Socket Mode: the app dials out to Slack over a WebSocket, so it needs no public URL,
|
|
3
|
+
* no inbound firewall rule and no signing-secret endpoint. Uses Node's built-in WebSocket.
|
|
4
|
+
*/
|
|
5
|
+
import type { Handled } from './app.js';
|
|
6
|
+
export interface SocketLike {
|
|
7
|
+
addEventListener(type: 'open' | 'message' | 'close' | 'error', fn: (ev: any) => void): void;
|
|
8
|
+
send(data: string): void;
|
|
9
|
+
close(): void;
|
|
10
|
+
}
|
|
11
|
+
export type SocketFactory = (url: string) => SocketLike;
|
|
12
|
+
export interface SocketModeOptions {
|
|
13
|
+
appToken: string;
|
|
14
|
+
handle: (type: string, payload: any) => Promise<Handled>;
|
|
15
|
+
fetchImpl?: typeof fetch;
|
|
16
|
+
socket?: SocketFactory;
|
|
17
|
+
log?: (m: string) => void;
|
|
18
|
+
/** Stop reconnecting when this signal aborts. */
|
|
19
|
+
signal?: AbortSignal;
|
|
20
|
+
}
|
|
21
|
+
export declare function openConnection(appToken: string, fetchImpl?: typeof fetch): Promise<string>;
|
|
22
|
+
/** Handles one Socket Mode frame: acks envelopes (with the handler's payload), then runs slower work. */
|
|
23
|
+
export declare function onFrame(raw: string, sock: SocketLike, handle: SocketModeOptions['handle'], log: (m: string) => void): Promise<'reconnect' | void>;
|
|
24
|
+
export declare function runSocketMode(o: SocketModeOptions): Promise<void>;
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
export async function openConnection(appToken, fetchImpl = fetch) {
|
|
2
|
+
const r = await fetchImpl('https://slack.com/api/apps.connections.open', { method: 'POST', headers: { Authorization: `Bearer ${appToken}`, 'Content-Type': 'application/x-www-form-urlencoded' } });
|
|
3
|
+
const d = await r.json();
|
|
4
|
+
if (!d.ok)
|
|
5
|
+
throw new Error(`Slack apps.connections.open: ${d.error ?? r.status}. Check SLACK_APP_TOKEN (xapp-…, with connections:write).`);
|
|
6
|
+
return d.url;
|
|
7
|
+
}
|
|
8
|
+
/** Handles one Socket Mode frame: acks envelopes (with the handler's payload), then runs slower work. */
|
|
9
|
+
export async function onFrame(raw, sock, handle, log) {
|
|
10
|
+
let msg;
|
|
11
|
+
try {
|
|
12
|
+
msg = JSON.parse(raw);
|
|
13
|
+
}
|
|
14
|
+
catch {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
if (msg.type === 'hello') {
|
|
18
|
+
log('Connected to Slack.');
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
if (msg.type === 'disconnect')
|
|
22
|
+
return 'reconnect';
|
|
23
|
+
if (!msg.envelope_id)
|
|
24
|
+
return;
|
|
25
|
+
let h = {};
|
|
26
|
+
try {
|
|
27
|
+
h = await handle(msg.type, msg.payload);
|
|
28
|
+
}
|
|
29
|
+
catch (e) {
|
|
30
|
+
log(`Couldn't handle ${msg.type}: ${e.message}`);
|
|
31
|
+
}
|
|
32
|
+
sock.send(JSON.stringify(h.ack === undefined ? { envelope_id: msg.envelope_id } : { envelope_id: msg.envelope_id, payload: h.ack }));
|
|
33
|
+
if (h.after)
|
|
34
|
+
h.after().catch(e => log(`After ${msg.type}: ${e.message}`));
|
|
35
|
+
}
|
|
36
|
+
export async function runSocketMode(o) {
|
|
37
|
+
const log = o.log ?? (() => { });
|
|
38
|
+
const make = o.socket ?? (url => {
|
|
39
|
+
const WS = globalThis.WebSocket;
|
|
40
|
+
if (!WS)
|
|
41
|
+
throw new Error('Socket Mode needs Node 22 or newer (it uses the built-in WebSocket).');
|
|
42
|
+
return new WS(url);
|
|
43
|
+
});
|
|
44
|
+
let backoff = 1;
|
|
45
|
+
while (!o.signal?.aborted) {
|
|
46
|
+
try {
|
|
47
|
+
const url = await openConnection(o.appToken, o.fetchImpl);
|
|
48
|
+
await new Promise((resolve) => {
|
|
49
|
+
const sock = make(url);
|
|
50
|
+
let done = false;
|
|
51
|
+
const finish = () => { if (!done) {
|
|
52
|
+
done = true;
|
|
53
|
+
resolve();
|
|
54
|
+
} };
|
|
55
|
+
sock.addEventListener('open', () => { backoff = 1; });
|
|
56
|
+
sock.addEventListener('message', (ev) => {
|
|
57
|
+
onFrame(String(ev.data), sock, o.handle, log).then(r => { if (r === 'reconnect') {
|
|
58
|
+
log('Slack asked to reconnect.');
|
|
59
|
+
try {
|
|
60
|
+
sock.close();
|
|
61
|
+
}
|
|
62
|
+
catch { /* closed */ }
|
|
63
|
+
finish();
|
|
64
|
+
} });
|
|
65
|
+
});
|
|
66
|
+
sock.addEventListener('close', finish);
|
|
67
|
+
sock.addEventListener('error', () => { log('Connection to Slack dropped.'); finish(); });
|
|
68
|
+
o.signal?.addEventListener('abort', () => { try {
|
|
69
|
+
sock.close();
|
|
70
|
+
}
|
|
71
|
+
catch { /* closed */ } finish(); });
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
catch (e) {
|
|
75
|
+
log(e.message);
|
|
76
|
+
if (/invalid_auth|not_authed|Node 22/.test(e.message))
|
|
77
|
+
throw e;
|
|
78
|
+
}
|
|
79
|
+
if (o.signal?.aborted)
|
|
80
|
+
break;
|
|
81
|
+
await new Promise(r => setTimeout(r, backoff * 1000));
|
|
82
|
+
backoff = Math.min(60, backoff * 2);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { SkillMeta, StoreConfig } from '../core/types.js';
|
|
2
|
+
import type { Workspace } from '../core/workspace.js';
|
|
3
|
+
import { type KnowledgeStore } from './index.js';
|
|
4
|
+
type AirtableCfg = Extract<StoreConfig, {
|
|
5
|
+
type: 'airtable';
|
|
6
|
+
}>;
|
|
7
|
+
/**
|
|
8
|
+
* Airtable store. One table with the columns Skill, Section and Content (long text, markdown).
|
|
9
|
+
* Uses the team's own personal access token.
|
|
10
|
+
*/
|
|
11
|
+
export declare class AirtableStore implements KnowledgeStore {
|
|
12
|
+
private ws;
|
|
13
|
+
private cfg;
|
|
14
|
+
kind: string;
|
|
15
|
+
constructor(ws: Workspace, cfg: AirtableCfg);
|
|
16
|
+
describe(): string;
|
|
17
|
+
private url;
|
|
18
|
+
private call;
|
|
19
|
+
private rows;
|
|
20
|
+
readSections(skill: SkillMeta): Promise<{
|
|
21
|
+
[k: string]: string;
|
|
22
|
+
}>;
|
|
23
|
+
writeSection(skill: SkillMeta, id: string, md: string): Promise<void>;
|
|
24
|
+
applyChange(skill: SkillMeta, id: string, oldText: string, newText: string): Promise<void>;
|
|
25
|
+
}
|
|
26
|
+
export {};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { replaceOrAppend } from './index.js';
|
|
2
|
+
/**
|
|
3
|
+
* Airtable store. One table with the columns Skill, Section and Content (long text, markdown).
|
|
4
|
+
* Uses the team's own personal access token.
|
|
5
|
+
*/
|
|
6
|
+
export class AirtableStore {
|
|
7
|
+
ws;
|
|
8
|
+
cfg;
|
|
9
|
+
kind = 'airtable';
|
|
10
|
+
constructor(ws, cfg) {
|
|
11
|
+
this.ws = ws;
|
|
12
|
+
this.cfg = cfg;
|
|
13
|
+
}
|
|
14
|
+
describe() { return `Airtable (base ${this.cfg.base}, table ${this.cfg.table})`; }
|
|
15
|
+
url(q = '') { return `https://api.airtable.com/v0/${this.cfg.base}/${encodeURIComponent(this.cfg.table)}${q}`; }
|
|
16
|
+
async call(method, q, body) {
|
|
17
|
+
const env = this.cfg.token_env ?? 'AIRTABLE_TOKEN';
|
|
18
|
+
const t = process.env[env];
|
|
19
|
+
if (!t)
|
|
20
|
+
throw new Error(`Set ${env} to your company's Airtable token to read the knowledge store.`);
|
|
21
|
+
const r = await fetch(this.url(q), { method, headers: { Authorization: `Bearer ${t}`, 'Content-Type': 'application/json' }, body: body ? JSON.stringify(body) : undefined });
|
|
22
|
+
if (!r.ok)
|
|
23
|
+
throw new Error(`Airtable ${method} failed: ${r.status} ${await r.text()}`);
|
|
24
|
+
return r.json();
|
|
25
|
+
}
|
|
26
|
+
async rows(skill) {
|
|
27
|
+
const out = [];
|
|
28
|
+
let offset;
|
|
29
|
+
const f = encodeURIComponent(`{Skill}='${skill.replace(/'/g, "\\'")}'`);
|
|
30
|
+
do {
|
|
31
|
+
const res = await this.call('GET', `?filterByFormula=${f}${offset ? `&offset=${offset}` : ''}`);
|
|
32
|
+
out.push(...res.records);
|
|
33
|
+
offset = res.offset;
|
|
34
|
+
} while (offset);
|
|
35
|
+
return out;
|
|
36
|
+
}
|
|
37
|
+
async readSections(skill) {
|
|
38
|
+
const rows = await this.rows(skill.name);
|
|
39
|
+
return Object.fromEntries(skill.sections.map(id => [id, rows.find(r => r.fields.Section === id)?.fields.Content ?? '']));
|
|
40
|
+
}
|
|
41
|
+
async writeSection(skill, id, md) {
|
|
42
|
+
const row = (await this.rows(skill.name)).find(r => r.fields.Section === id);
|
|
43
|
+
if (row)
|
|
44
|
+
await this.call('PATCH', '', { records: [{ id: row.id, fields: { Content: md } }] });
|
|
45
|
+
else
|
|
46
|
+
await this.call('POST', '', { records: [{ fields: { Skill: skill.name, Section: id, Content: md } }] });
|
|
47
|
+
}
|
|
48
|
+
async applyChange(skill, id, oldText, newText) {
|
|
49
|
+
const cur = (await this.readSections(skill))[id] ?? '';
|
|
50
|
+
await this.writeSection(skill, id, replaceOrAppend(cur, oldText, newText));
|
|
51
|
+
}
|
|
52
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Confluence storage format (XHTML plus ac:/ri: macros) to Markdown and back.
|
|
3
|
+
* Used by the Confluence store, and by "write --dir" when a connector hands back a page's
|
|
4
|
+
* storage format instead of Markdown. Small and tolerant on purpose: it reads what people
|
|
5
|
+
* actually put on KB pages (headings, lists, tasks, tables, code, panels, links) and says
|
|
6
|
+
* so in the text when it meets a macro it can't read, instead of dropping it silently.
|
|
7
|
+
*/
|
|
8
|
+
export type HNode = {
|
|
9
|
+
tag: '#text';
|
|
10
|
+
text: string;
|
|
11
|
+
cdata?: boolean;
|
|
12
|
+
start: number;
|
|
13
|
+
end: number;
|
|
14
|
+
} | {
|
|
15
|
+
tag: string;
|
|
16
|
+
attrs: Record<string, string>;
|
|
17
|
+
children: HNode[];
|
|
18
|
+
start: number;
|
|
19
|
+
end: number;
|
|
20
|
+
};
|
|
21
|
+
export declare const decodeEntities: (s: string) => string;
|
|
22
|
+
export declare const esc: (s: string) => string;
|
|
23
|
+
/** Parses storage format into a tree. Each node keeps its source offsets, so one block can be rewritten in place. */
|
|
24
|
+
export declare function parseStorage(src: string): HNode[];
|
|
25
|
+
/** Renders a list of block nodes as Markdown, blocks separated by blank lines. */
|
|
26
|
+
export declare function blocks(nodes: HNode[]): string;
|
|
27
|
+
export declare function storageToMarkdown(xhtml: string): string;
|
|
28
|
+
/** True when a string looks like Confluence storage format or HTML rather than Markdown. */
|
|
29
|
+
export declare function looksLikeStorage(s: string): boolean;
|
|
30
|
+
/** Inline Markdown (code, bold, italic, links) to storage format. */
|
|
31
|
+
export declare function inlineToStorage(s: string): string;
|
|
32
|
+
export declare function markdownToStorage(md: string): string;
|
|
33
|
+
/** Storage-format features this converter can't write back, found in a fragment. */
|
|
34
|
+
export declare function unreadable(nodes: HNode[]): string[];
|