@composable-os/pack-knowledge 0.0.0-stage → 0.1.0-beta.13
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 +109 -0
- package/dist/automations.d.ts +14 -0
- package/dist/automations.js +42 -0
- package/dist/client/index.d.ts +468 -0
- package/dist/client/index.js +101 -0
- package/dist/index.d.ts +453 -0
- package/dist/index.js +325 -0
- package/dist/tools.d.ts +131 -0
- package/dist/tools.js +279 -0
- package/package.json +36 -4
- package/README.md +0 -3
package/dist/tools.js
ADDED
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
// The Knowledge pack's tools (stage 38 step 5, ADR 0706). Each composes host operations and adds
|
|
2
|
+
// no rule of its own: who must read a procedure, whether a confirmation counts, who may see who has
|
|
3
|
+
// confirmed, what staff and the public read, and who publishes are all the host's (ADRs 0700 to
|
|
4
|
+
// 0702, 0480).
|
|
5
|
+
//
|
|
6
|
+
// toRead every staff account, a person what I must read, and what I confirmed
|
|
7
|
+
// confirm every staff account, a person "I have read and understood this", one tap
|
|
8
|
+
// readStatus knowledge:manage, a person who has confirmed, who has not
|
|
9
|
+
// helpTopics anyone the help topics, for a site's menu
|
|
10
|
+
// draftProcedure knowledge:write (and members) write a procedure's working copy
|
|
11
|
+
// draftHelpPage knowledge:write (and members) write a help page's working copy
|
|
12
|
+
//
|
|
13
|
+
// The two draft tools write the working copy only: publishing is a person's (`record.publish`,
|
|
14
|
+
// ADR 0480; an AI's call of it is a request a person approves), and who must read a procedure is
|
|
15
|
+
// set by a person (the host refuses an AI actor's write of it).
|
|
16
|
+
import { defineTool, OpsCallError, z } from "@composable-os/sdk";
|
|
17
|
+
export const PROCEDURE = "knowledge.procedure";
|
|
18
|
+
export const SECTION = "knowledge.section";
|
|
19
|
+
export const HELP_PAGE = "knowledge.helppage";
|
|
20
|
+
export const HELP_TOPIC = "knowledge.helptopic";
|
|
21
|
+
export const MANAGE = "knowledge:manage";
|
|
22
|
+
export const WRITE = "knowledge:write";
|
|
23
|
+
const text = (value) => (typeof value === "string" ? value : null);
|
|
24
|
+
const num = (value) => (typeof value === "number" ? value : null);
|
|
25
|
+
const run = (value) => [{ type: "text", text: value }];
|
|
26
|
+
/**
|
|
27
|
+
* Notes as the platform's rich text (ADR 0440): `#`, `##` and `###` start a heading (a section of
|
|
28
|
+
* the procedure, which search and citations link to), `-` or `*` a bullet, `1.` a numbered step,
|
|
29
|
+
* and a blank line ends a paragraph. Everything else is plain words: no HTML, no marks.
|
|
30
|
+
*/
|
|
31
|
+
export function notesToRichText(notes) {
|
|
32
|
+
const blocks = [];
|
|
33
|
+
let paragraph = [];
|
|
34
|
+
let list = null;
|
|
35
|
+
const flush = () => {
|
|
36
|
+
if (paragraph.length)
|
|
37
|
+
blocks.push({ type: "paragraph", content: run(paragraph.join(" ")) });
|
|
38
|
+
paragraph = [];
|
|
39
|
+
list = null;
|
|
40
|
+
};
|
|
41
|
+
for (const raw of notes.split(/\r?\n/)) {
|
|
42
|
+
const line = raw.trim();
|
|
43
|
+
if (!line) {
|
|
44
|
+
flush();
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
const heading = /^(#{1,3})\s+(.+)$/.exec(line);
|
|
48
|
+
const bullet = /^[-*]\s+(.+)$/.exec(line);
|
|
49
|
+
const step = /^\d{1,3}[.)]\s+(.+)$/.exec(line);
|
|
50
|
+
if (heading?.[1] && heading[2]) {
|
|
51
|
+
flush();
|
|
52
|
+
blocks.push({ type: "heading", level: heading[1].length + 1, content: run(heading[2]) });
|
|
53
|
+
}
|
|
54
|
+
else if ((bullet?.[1] || step?.[1]) && !paragraph.length) {
|
|
55
|
+
const style = bullet ? "bullet" : "ordered";
|
|
56
|
+
const words = (bullet?.[1] ?? step?.[1]);
|
|
57
|
+
if (!list || list.style !== style) {
|
|
58
|
+
list = { type: "list", style, items: [] };
|
|
59
|
+
blocks.push(list);
|
|
60
|
+
}
|
|
61
|
+
list.items.push({ content: run(words) });
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
if (list)
|
|
65
|
+
list = null;
|
|
66
|
+
paragraph.push(line);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
flush();
|
|
70
|
+
return { blocks };
|
|
71
|
+
}
|
|
72
|
+
// --- Read and understood ------------------------------------------------------------------------
|
|
73
|
+
const procedureLine = z.object({
|
|
74
|
+
id: z.string(),
|
|
75
|
+
title: z.string().nullable(),
|
|
76
|
+
version: z.number().int().describe("The current published version"),
|
|
77
|
+
publishedAt: z.string(),
|
|
78
|
+
});
|
|
79
|
+
export const toRead = defineTool({
|
|
80
|
+
description: "My procedures: the published ones I must read and have not yet confirmed (oldest first, " +
|
|
81
|
+
"with the version to read and since when), and the ones I have confirmed (with when). For " +
|
|
82
|
+
"the person themselves, every staff account. Read-only.",
|
|
83
|
+
input: z.object({}),
|
|
84
|
+
output: z.object({
|
|
85
|
+
toRead: z.array(procedureLine.extend({ since: z.string() })),
|
|
86
|
+
confirmed: z.array(procedureLine.extend({ confirmedAt: z.string() })),
|
|
87
|
+
}),
|
|
88
|
+
risk: "read",
|
|
89
|
+
// Every staff account, pack roles included (ADR 0652): the host's ack.mine decides what is
|
|
90
|
+
// theirs, from who the person is (never from the input).
|
|
91
|
+
humanOnly: true,
|
|
92
|
+
anyStaff: true,
|
|
93
|
+
async handler(_input, ctx) {
|
|
94
|
+
const mine = await ctx.ops.call("ack.mine", {});
|
|
95
|
+
const strip = ({ object: _object, ...rest }) => rest;
|
|
96
|
+
return {
|
|
97
|
+
toRead: mine.toRead.filter((r) => r.object === PROCEDURE).map(strip),
|
|
98
|
+
confirmed: mine.confirmed.filter((r) => r.object === PROCEDURE).map(strip),
|
|
99
|
+
};
|
|
100
|
+
},
|
|
101
|
+
});
|
|
102
|
+
export const confirm = defineTool({
|
|
103
|
+
description: "Confirm that I have read and understood a procedure's current published version: one tap, " +
|
|
104
|
+
"by the person themselves. Refused for a version that is not the current one (read it again " +
|
|
105
|
+
"and confirm that), a procedure I am not asked to read, and a second time for the same " +
|
|
106
|
+
"version. A confirmation is kept for good and never changed. Not for an AI.",
|
|
107
|
+
input: z.object({
|
|
108
|
+
id: z.string().min(1).max(64).describe("The procedure"),
|
|
109
|
+
version: z.number().int().min(1).describe("The version I read: the current one"),
|
|
110
|
+
}),
|
|
111
|
+
output: z.object({ id: z.string(), version: z.number().int(), confirmedAt: z.string() }),
|
|
112
|
+
risk: "write",
|
|
113
|
+
humanOnly: true,
|
|
114
|
+
anyStaff: true,
|
|
115
|
+
async handler(input, ctx) {
|
|
116
|
+
const out = await ctx.ops.call("ack.confirm", { object: PROCEDURE, id: input.id, version: input.version });
|
|
117
|
+
return { id: out.id, version: out.version, confirmedAt: out.confirmedAt };
|
|
118
|
+
},
|
|
119
|
+
});
|
|
120
|
+
const statusPerson = z.object({
|
|
121
|
+
account: z.string(),
|
|
122
|
+
name: z.string(),
|
|
123
|
+
email: z.string(),
|
|
124
|
+
confirmed: z.object({ version: z.number().int(), confirmedAt: z.string() }).nullable(),
|
|
125
|
+
lastConfirmed: z.object({ version: z.number().int(), confirmedAt: z.string() }).nullable(),
|
|
126
|
+
since: z.string().nullable(),
|
|
127
|
+
});
|
|
128
|
+
export const readStatus = defineTool({
|
|
129
|
+
description: "Who has read what. With a procedure's id: for its current version, everyone who must read " +
|
|
130
|
+
"it, who has confirmed it and when, and who has not and since when. Without one: every " +
|
|
131
|
+
"published procedure staff must read, with how many have confirmed it of how many must. For " +
|
|
132
|
+
"admins and people granted Read status; never for an AI. Read-only.",
|
|
133
|
+
input: z.object({ id: z.string().min(1).max(64).optional().describe("One procedure") }),
|
|
134
|
+
output: z.object({
|
|
135
|
+
procedures: z.array(procedureLine.extend({ mustRead: z.number().int(), confirmed: z.number() })),
|
|
136
|
+
procedure: procedureLine
|
|
137
|
+
.extend({
|
|
138
|
+
everyone: z.boolean(),
|
|
139
|
+
roles: z.array(z.string()),
|
|
140
|
+
people: z.array(statusPerson),
|
|
141
|
+
})
|
|
142
|
+
.nullable(),
|
|
143
|
+
}),
|
|
144
|
+
risk: "read",
|
|
145
|
+
permission: MANAGE,
|
|
146
|
+
humanOnly: true,
|
|
147
|
+
async handler(input, ctx) {
|
|
148
|
+
if (input.id !== undefined) {
|
|
149
|
+
const s = await ctx.ops.call("ack.status", { object: PROCEDURE, id: input.id });
|
|
150
|
+
return {
|
|
151
|
+
procedures: [],
|
|
152
|
+
procedure: {
|
|
153
|
+
id: s.id,
|
|
154
|
+
title: s.title,
|
|
155
|
+
version: s.version,
|
|
156
|
+
publishedAt: s.publishedAt,
|
|
157
|
+
everyone: s.everyone,
|
|
158
|
+
roles: s.roles,
|
|
159
|
+
people: s.people,
|
|
160
|
+
},
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
const all = await ctx.ops.call("ack.overview", {});
|
|
164
|
+
return {
|
|
165
|
+
procedures: all.items
|
|
166
|
+
.filter((i) => i.object === PROCEDURE)
|
|
167
|
+
.map(({ object: _object, ...rest }) => rest),
|
|
168
|
+
procedure: null,
|
|
169
|
+
};
|
|
170
|
+
},
|
|
171
|
+
});
|
|
172
|
+
// --- Help pages -----------------------------------------------------------------------------------
|
|
173
|
+
export const helpTopics = defineTool({
|
|
174
|
+
description: "Every help topic, in their order: its id, name, address (slug) and icon, for a help " +
|
|
175
|
+
"centre's menu. Open to anyone. Read-only.",
|
|
176
|
+
input: z.object({ limit: z.number().int().min(1).max(200).default(100) }),
|
|
177
|
+
output: z.object({
|
|
178
|
+
topics: z.array(z.object({
|
|
179
|
+
id: z.string(),
|
|
180
|
+
name: z.string().nullable(),
|
|
181
|
+
slug: z.string().nullable(),
|
|
182
|
+
order: z.number().nullable(),
|
|
183
|
+
icon: z.string().nullable(),
|
|
184
|
+
})),
|
|
185
|
+
}),
|
|
186
|
+
risk: "read",
|
|
187
|
+
audiences: ["staff", "customer", "public"],
|
|
188
|
+
async handler(input, ctx) {
|
|
189
|
+
const page = await ctx.ops.call("public.list", {
|
|
190
|
+
object: HELP_TOPIC,
|
|
191
|
+
sort: { field: "order", direction: "asc" },
|
|
192
|
+
limit: input.limit,
|
|
193
|
+
});
|
|
194
|
+
return {
|
|
195
|
+
topics: page.items.map((item) => ({
|
|
196
|
+
id: item.id,
|
|
197
|
+
name: text(item.values.name),
|
|
198
|
+
slug: text(item.values.slug),
|
|
199
|
+
order: num(item.values.order),
|
|
200
|
+
icon: text(item.values.icon),
|
|
201
|
+
})),
|
|
202
|
+
};
|
|
203
|
+
},
|
|
204
|
+
});
|
|
205
|
+
// --- Drafting -------------------------------------------------------------------------------------
|
|
206
|
+
const draftCommon = {
|
|
207
|
+
id: z
|
|
208
|
+
.string()
|
|
209
|
+
.min(1)
|
|
210
|
+
.max(64)
|
|
211
|
+
.optional()
|
|
212
|
+
.describe("Change this one's working copy; left out, a new one is made"),
|
|
213
|
+
title: z.string().trim().min(1).max(200),
|
|
214
|
+
summary: z.string().trim().max(500).optional().describe("One or two sentences for lists"),
|
|
215
|
+
notes: z
|
|
216
|
+
.string()
|
|
217
|
+
.max(60_000)
|
|
218
|
+
.optional()
|
|
219
|
+
.describe("The words, as notes: '# ' or '## ' starts a section heading, '- ' a bullet, '1. ' a " +
|
|
220
|
+
"numbered step, a blank line ends a paragraph"),
|
|
221
|
+
};
|
|
222
|
+
const draftOut = z.object({
|
|
223
|
+
id: z.string(),
|
|
224
|
+
created: z.boolean(),
|
|
225
|
+
open: z.object({ object: z.string(), id: z.string() }),
|
|
226
|
+
});
|
|
227
|
+
async function draft(ctx, object, id, values) {
|
|
228
|
+
if (id !== undefined) {
|
|
229
|
+
await ctx.ops.call("record.update", { object, id, values });
|
|
230
|
+
return { id, created: false, open: { object, id } };
|
|
231
|
+
}
|
|
232
|
+
const made = await ctx.ops.call("record.create", { object, values });
|
|
233
|
+
if (!made?.id)
|
|
234
|
+
throw new OpsCallError("conflict", "The draft was not made");
|
|
235
|
+
return { id: made.id, created: true, open: { object, id: made.id } };
|
|
236
|
+
}
|
|
237
|
+
export const draftProcedure = defineTool({
|
|
238
|
+
description: "Write a procedure's working copy from notes: a new one, or the draft of one that exists. " +
|
|
239
|
+
"Staff read only what a person publishes, so this changes nothing anyone reads until then; " +
|
|
240
|
+
"ask a person to publish it (record.publish waits for their approval). Who must read it and " +
|
|
241
|
+
"how often it is reviewed are set by a person. Name a role, not a person, in the words " +
|
|
242
|
+
"('the duty manager', not 'Sam').",
|
|
243
|
+
input: z.object({
|
|
244
|
+
...draftCommon,
|
|
245
|
+
section: z.string().min(1).max(64).optional().describe("A section's id"),
|
|
246
|
+
}),
|
|
247
|
+
output: draftOut,
|
|
248
|
+
risk: "write",
|
|
249
|
+
permission: WRITE,
|
|
250
|
+
async handler(input, ctx) {
|
|
251
|
+
return draft(ctx, PROCEDURE, input.id, {
|
|
252
|
+
title: input.title,
|
|
253
|
+
...(input.summary !== undefined ? { summary: input.summary } : {}),
|
|
254
|
+
...(input.notes !== undefined ? { body: notesToRichText(input.notes) } : {}),
|
|
255
|
+
...(input.section !== undefined ? { section: input.section } : {}),
|
|
256
|
+
});
|
|
257
|
+
},
|
|
258
|
+
});
|
|
259
|
+
export const draftHelpPage = defineTool({
|
|
260
|
+
description: "Write a help page's working copy from notes: a new one, or the draft of one that exists. " +
|
|
261
|
+
"The public reads only what a person publishes; ask a person to publish it (record.publish " +
|
|
262
|
+
"waits for their approval). Never put a customer's name or details in a help page drafted " +
|
|
263
|
+
"from their question.",
|
|
264
|
+
input: z.object({
|
|
265
|
+
...draftCommon,
|
|
266
|
+
topic: z.string().min(1).max(64).optional().describe("A help topic's id"),
|
|
267
|
+
}),
|
|
268
|
+
output: draftOut,
|
|
269
|
+
risk: "write",
|
|
270
|
+
permission: WRITE,
|
|
271
|
+
async handler(input, ctx) {
|
|
272
|
+
return draft(ctx, HELP_PAGE, input.id, {
|
|
273
|
+
title: input.title,
|
|
274
|
+
...(input.summary !== undefined ? { summary: input.summary } : {}),
|
|
275
|
+
...(input.notes !== undefined ? { body: notesToRichText(input.notes) } : {}),
|
|
276
|
+
...(input.topic !== undefined ? { topic: input.topic } : {}),
|
|
277
|
+
});
|
|
278
|
+
},
|
|
279
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,38 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@composable-os/pack-knowledge",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0-beta.13",
|
|
4
|
+
"license": "FSL-1.1-ALv2",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/timoconnellaus/composable-os.git"
|
|
9
|
+
},
|
|
10
|
+
"homepage": "https://composableos.dev",
|
|
11
|
+
"publishConfig": {
|
|
12
|
+
"access": "public",
|
|
13
|
+
"provenance": true
|
|
14
|
+
},
|
|
15
|
+
"description": "Knowledge: staff procedures read in their published wording and confirmed as read and understood, with a review reminder, and public help pages (stage 38, ADR 0706). Installed in every deployment of a product that lists it. Bundled as source into cos-runner.",
|
|
16
|
+
"exports": {
|
|
17
|
+
".": {
|
|
18
|
+
"types": "./dist/index.d.ts",
|
|
19
|
+
"default": "./dist/index.js"
|
|
20
|
+
},
|
|
21
|
+
"./client": {
|
|
22
|
+
"types": "./dist/client/index.d.ts",
|
|
23
|
+
"default": "./dist/client/index.js"
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
"files": [
|
|
27
|
+
"dist"
|
|
28
|
+
],
|
|
29
|
+
"composableOs": {
|
|
30
|
+
"optional": true,
|
|
31
|
+
"label": "Knowledge",
|
|
32
|
+
"description": "Staff procedures everyone reads in their published wording and confirms with one tap, and help pages for your customers on your website."
|
|
33
|
+
},
|
|
34
|
+
"dependencies": {
|
|
35
|
+
"@composable-os/client": "0.1.0-beta.13",
|
|
36
|
+
"@composable-os/sdk": "0.1.0-beta.13"
|
|
37
|
+
}
|
|
38
|
+
}
|
package/README.md
DELETED