@supa-media/tex-contract 0.0.0-stage → 0.2.7
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 +21 -0
- package/README.md +11 -2
- package/package.json +16 -4
- package/texContract/aboutLines.cjs +117 -0
- package/texContract/aboutLines.d.cts +14 -0
- package/texContract/aboutNoteLimits.cjs +41 -0
- package/texContract/aboutNoteLimits.d.cts +5 -0
- package/texContract/actionManual.cjs +104 -0
- package/texContract/activityHint.cjs +40 -0
- package/texContract/activityHint.d.cts +4 -0
- package/texContract/asks.cjs +16 -0
- package/texContract/asks.d.cts +6 -0
- package/texContract/asksToFile.cjs +20 -0
- package/texContract/asksToFile.d.cts +2 -0
- package/texContract/attention.cjs +138 -0
- package/texContract/attention.d.cts +20 -0
- package/texContract/browserHandback.cjs +13 -0
- package/texContract/browserHandback.d.cts +3 -0
- package/texContract/browserOwner.cjs +31 -0
- package/texContract/browserOwner.d.cts +2 -0
- package/texContract/bytes.cjs +12 -0
- package/texContract/chatHistoryPath.cjs +38 -0
- package/texContract/chatHistoryPath.d.cts +5 -0
- package/texContract/chatLedger.cjs +91 -0
- package/texContract/chatLedger.d.cts +21 -0
- package/texContract/computerTool.cjs +102 -0
- package/texContract/computerTool.d.cts +16 -0
- package/texContract/consentYes.cjs +22 -0
- package/texContract/consentYes.d.cts +5 -0
- package/texContract/contextGateway.cjs +52 -0
- package/texContract/contextGateway.d.cts +19 -0
- package/texContract/deskEligible.cjs +20 -0
- package/texContract/deskEligible.d.cts +3 -0
- package/texContract/downloads.cjs +129 -0
- package/texContract/downloads.d.cts +15 -0
- package/texContract/egressLedger.cjs +114 -0
- package/texContract/egressLedger.d.cts +14 -0
- package/texContract/emailRead.cjs +38 -0
- package/texContract/emailRead.d.cts +5 -0
- package/texContract/eventWords.cjs +35 -0
- package/texContract/eventWords.d.cts +4 -0
- package/texContract/fileParts.cjs +43 -0
- package/texContract/fileParts.d.cts +6 -0
- package/texContract/fileTables.cjs +243 -0
- package/texContract/fileWords.cjs +169 -0
- package/texContract/folded.cjs +16 -0
- package/texContract/folded.d.cts +3 -0
- package/texContract/googleAiAccess.cjs +12 -0
- package/texContract/googleAiAccess.d.cts +2 -0
- package/texContract/graphWires.cjs +18 -0
- package/texContract/graphWires.d.cts +5 -0
- package/texContract/groupSession.cjs +28 -0
- package/texContract/groupSession.d.cts +7 -0
- package/texContract/guestNames.cjs +136 -0
- package/texContract/guestNames.d.cts +35 -0
- package/texContract/heard.cjs +19 -0
- package/texContract/heard.d.cts +4 -0
- package/texContract/heldOffer.cjs +57 -0
- package/texContract/heldOffer.d.cts +8 -0
- package/texContract/helperCallers.cjs +29 -0
- package/texContract/helperCallers.d.cts +4 -0
- package/texContract/identity.cjs +179 -0
- package/texContract/identity.d.cts +8 -0
- package/texContract/jobLogEntries.cjs +93 -0
- package/texContract/jobLogEntries.d.cts +12 -0
- package/texContract/judgedActions.cjs +20 -0
- package/texContract/judgedActions.d.cts +4 -0
- package/texContract/labSandboxGate.cjs +63 -0
- package/texContract/labSandboxGate.d.cts +9 -0
- package/texContract/ledgerReadChars.cjs +4 -0
- package/texContract/ledgerReadChars.d.cts +3 -0
- package/texContract/mailCheck.cjs +90 -0
- package/texContract/mailCheck.d.cts +12 -0
- package/texContract/mailEntries.cjs +64 -0
- package/texContract/mailEntries.d.cts +13 -0
- package/texContract/mailHealth.cjs +60 -0
- package/texContract/mailHealth.d.cts +10 -0
- package/texContract/notePath.cjs +99 -0
- package/texContract/notePath.d.cts +4 -0
- package/texContract/noteRunFacts.cjs +136 -0
- package/texContract/noteRunFacts.d.cts +32 -0
- package/texContract/objectEtag.cjs +84 -0
- package/texContract/objectEtag.d.cts +4 -0
- package/texContract/objectPlace.cjs +32 -0
- package/texContract/objectPlace.d.cts +5 -0
- package/texContract/pageJobs.cjs +226 -0
- package/texContract/pageJobs.d.cts +13 -0
- package/texContract/pdfLinks.cjs +135 -0
- package/texContract/pdfLinks.d.cts +4 -0
- package/texContract/personHub.cjs +38 -0
- package/texContract/personHub.d.cts +5 -0
- package/texContract/personNameText.cjs +18 -0
- package/texContract/personNameText.d.cts +3 -0
- package/texContract/pinnedContext.cjs +12 -0
- package/texContract/pinnedContext.d.cts +3 -0
- package/texContract/quietHoursWindow.cjs +36 -0
- package/texContract/quietHoursWindow.d.cts +3 -0
- package/texContract/scopeClamp.cjs +117 -0
- package/texContract/scopeClamp.d.cts +5 -0
- package/texContract/scopes.cjs +29 -0
- package/texContract/scopes.d.cts +7 -0
- package/texContract/searchSettings.cjs +54 -0
- package/texContract/searchSettings.d.cts +6 -0
- package/texContract/settingHabits.cjs +87 -0
- package/texContract/settingHabits.d.cts +20 -0
- package/texContract/settingsNotes.cjs +217 -0
- package/texContract/settingsNotes.d.cts +26 -0
- package/texContract/shownEmail.cjs +181 -0
- package/texContract/texClients.cjs +53 -0
- package/texContract/texClients.d.cts +12 -0
- package/texContract/texGraph.cjs +593 -0
- package/texContract/texGraph.d.cts +55 -0
- package/texContract/texKeys.cjs +100 -0
- package/texContract/texKeys.d.cts +13 -0
- package/texContract/texOwnSources.cjs +9 -0
- package/texContract/texOwnSources.d.cts +3 -0
- package/texContract/texStoreNames.cjs +26 -0
- package/texContract/texStoreNames.d.cts +12 -0
- package/texContract/texStoreWire.cjs +306 -0
- package/texContract/texStoreWire.d.cts +32 -0
- package/texContract/threadsFold.cjs +75 -0
- package/texContract/threadsFold.d.cts +22 -0
- package/texContract/toolActions.cjs +253 -0
- package/texContract/toolCatalog.cjs +49 -0
- package/texContract/toolCatalog.generated.json +90 -0
- package/texContract/toolContract.cjs +52 -0
- package/texContract/toolContract.d.cts +12 -0
- package/texContract/toolShapes.cjs +14 -0
- package/texContract/transcription.cjs +101 -0
- package/texContract/transcription.d.cts +3 -0
- package/texContract/treeJobs.cjs +31 -0
- package/texContract/treeJobs.d.cts +3 -0
- package/texContract/turnSession.cjs +90 -0
- package/texContract/turnSession.d.cts +19 -0
- package/texContract/turnWords.cjs +90 -0
- package/texContract/turnWords.d.cts +9 -0
- package/texContract/uploadImages.cjs +131 -0
- package/texContract/uploadImages.d.cts +13 -0
- package/texContract/v2Names.cjs +41 -0
- package/texContract/v2SearchFetch.cjs +316 -0
- package/texContract/v2Translate.cjs +123 -0
- package/texContract/vaultTools.cjs +112 -0
- package/texContract/vaultTools.d.cts +15 -0
- package/texContract/yesWords.cjs +91 -0
- package/texShared/argumentCoercion.cjs +93 -0
- package/texShared/cellComments.cjs +122 -0
- package/texShared/cellComments.d.cts +21 -0
- package/texShared/comments.cjs +586 -0
- package/texShared/comments.d.cts +115 -0
- package/texShared/contentTypes.cjs +85 -0
- package/texShared/fileKinds.cjs +123 -0
- package/texShared/flags.cjs +124 -0
- package/texShared/flags.d.cts +21 -0
- package/texShared/folderJobInfo.cjs +301 -0
- package/texShared/folderJobInfo.d.cts +40 -0
- package/texShared/folderRoles.cjs +512 -0
- package/texShared/folderRoles.d.cts +73 -0
- package/texShared/githubOidc.ts +98 -0
- package/texShared/groupRunQuestions.cjs +98 -0
- package/texShared/groupRunQuestions.d.cts +4 -0
- package/texShared/inboxFolders.cjs +49 -0
- package/texShared/inboxFolders.d.cts +5 -0
- package/texShared/ink/drawing.cjs +474 -0
- package/texShared/ink/texFigure.cjs +252 -0
- package/texShared/ink/texFigure.d.cts +36 -0
- package/texShared/ink/texPoses.cjs +180 -0
- package/texShared/ink/texPoses.d.cts +20 -0
- package/texShared/jobPartEnd.cjs +133 -0
- package/texShared/jobPartEnd.d.cts +13 -0
- package/texShared/jobResume.cjs +31 -0
- package/texShared/jobResume.d.cts +5 -0
- package/texShared/jobSplit.cjs +90 -0
- package/texShared/jobSplit.d.cts +6 -0
- package/texShared/jobStart.cjs +56 -0
- package/texShared/jobStart.d.cts +9 -0
- package/texShared/mail.cjs +400 -0
- package/texShared/mail.d.cts +56 -0
- package/texShared/messageAnchors.cjs +38 -0
- package/texShared/models/aiKeys.cjs +137 -0
- package/texShared/models/aiKeys.d.cts +42 -0
- package/texShared/models/aiKeys.json +56 -0
- package/texShared/models/creditRest.cjs +269 -0
- package/texShared/models/promptBudget.cjs +295 -0
- package/texShared/models/promptSections.cjs +29 -0
- package/texShared/noteAppLink.cjs +23 -0
- package/texShared/notePreview.cjs +219 -0
- package/texShared/notePreview.d.cts +21 -0
- package/texShared/pages/blocks.cjs +215 -0
- package/texShared/pages/cover.cjs +164 -0
- package/texShared/pages/css.cjs +181 -0
- package/texShared/pages/cssBlocks.cjs +264 -0
- package/texShared/pages/draw.cjs +212 -0
- package/texShared/pages/drawRich.cjs +232 -0
- package/texShared/pages/html.cjs +168 -0
- package/texShared/pages/inline.cjs +251 -0
- package/texShared/pages/layout.cjs +76 -0
- package/texShared/pages/parse.cjs +418 -0
- package/texShared/pages/render.cjs +200 -0
- package/texShared/pages/skill.cjs +147 -0
- package/texShared/pages/skill.d.cts +5 -0
- package/texShared/pages/templates.cjs +336 -0
- package/texShared/r2Store.cjs +163 -0
- package/texShared/remoteImage.cjs +177 -0
- package/texShared/routines.cjs +656 -0
- package/texShared/routines.d.cts +86 -0
- package/texShared/servedListing.cjs +250 -0
- package/texShared/servedListing.d.cts +17 -0
- package/texShared/sheetCsv.cjs +566 -0
- package/texShared/sheetCsv.d.cts +91 -0
- package/texShared/storageLayout.cjs +88 -0
- package/texShared/storeKeys.cjs +144 -0
- package/texShared/toolArguments.cjs +323 -0
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The web addresses a PDF's links and buttons go to.
|
|
3
|
+
*
|
|
4
|
+
* `toMarkdown` hands back a PDF's words and drops its link annotations, so a
|
|
5
|
+
* contract's "CLICK HERE to make payment" button reached the model as those
|
|
6
|
+
* words and nothing else, and Tex told the person to open the PDF and tap it
|
|
7
|
+
* themselves (Dev, 2026-10-20: "another stupid text limitation"). A link is a
|
|
8
|
+
* `/URI` action in the file: written as a plain or hex string, either in the
|
|
9
|
+
* open or inside a compressed object stream. Both are read here, with no
|
|
10
|
+
* dependency (`DecompressionStream`, which Workers and Node both have).
|
|
11
|
+
*
|
|
12
|
+
* Bounded throughout: a file is at most `MAX_FILE_BYTES` already, a picture
|
|
13
|
+
* or a font is never inflated, inflating stops past `MAX_INFLATED_BYTES`, and
|
|
14
|
+
* at most `MAX_LINKS` addresses come back. What comes back is the file's
|
|
15
|
+
* author's, so it is a quotation like the file's words (`readFile.js`).
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
const MAX_LINKS = 50;
|
|
19
|
+
const MAX_INFLATED_BYTES = 20 * 1024 * 1024;
|
|
20
|
+
const MAX_URL_CHARS = 2_000;
|
|
21
|
+
/** How far back from `stream` a stream's dictionary is looked for. */
|
|
22
|
+
const DICT_LOOKBACK = 2_000;
|
|
23
|
+
|
|
24
|
+
/** Bytes as one char per byte, the way PDF syntax is written. */
|
|
25
|
+
function latin1(bytes) {
|
|
26
|
+
let out = "";
|
|
27
|
+
for (let i = 0; i < bytes.length; i += 0x8000) out += String.fromCharCode(...bytes.subarray(i, i + 0x8000));
|
|
28
|
+
return out;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** A PDF literal string's escapes, undone (`\(`, `\)`, `\\`, `\n`, octal). */
|
|
32
|
+
function literal(raw) {
|
|
33
|
+
return raw.replace(/\\(?:([0-7]{1,3})|(\r\n|\r|\n)|(.))/g, (_, octal, newline, ch) => {
|
|
34
|
+
if (octal) return String.fromCharCode(parseInt(octal, 8) & 0xff);
|
|
35
|
+
if (newline) return "";
|
|
36
|
+
return { n: "\n", r: "\r", t: "\t", b: "\b", f: "\f" }[ch] ?? ch;
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function hex(raw) {
|
|
41
|
+
const digits = raw.replace(/\s+/g, "");
|
|
42
|
+
let out = "";
|
|
43
|
+
for (let i = 0; i < digits.length; i += 2) out += String.fromCharCode(parseInt(digits.slice(i, i + 2).padEnd(2, "0"), 16));
|
|
44
|
+
return out;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** A string PDF wrote as UTF-16 (it starts with a byte-order mark) read as text; anything else as it is. */
|
|
48
|
+
function text(s) {
|
|
49
|
+
if (s.charCodeAt(0) === 0xfe && s.charCodeAt(1) === 0xff) {
|
|
50
|
+
let out = "";
|
|
51
|
+
for (let i = 2; i + 1 < s.length; i += 2) out += String.fromCharCode((s.charCodeAt(i) << 8) | s.charCodeAt(i + 1));
|
|
52
|
+
return out;
|
|
53
|
+
}
|
|
54
|
+
return s;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const URI = /\/URI\s*(?:\(((?:\\[\s\S]|[^\\)])*)\)|<([0-9A-Fa-f\s]*)>)/g;
|
|
58
|
+
|
|
59
|
+
function urisIn(source, found) {
|
|
60
|
+
for (const match of source.matchAll(URI)) {
|
|
61
|
+
const value = text(match[1] !== undefined ? literal(match[1]) : hex(match[2])).trim();
|
|
62
|
+
if (value.length === 0 || value.length > MAX_URL_CHARS) continue;
|
|
63
|
+
if (!/^(https?:\/\/|mailto:)/i.test(value)) continue;
|
|
64
|
+
if (/[\u0000-\u001f\s]/.test(value)) continue;
|
|
65
|
+
found.add(value);
|
|
66
|
+
if (found.size >= MAX_LINKS) return;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
async function inflate(bytes) {
|
|
71
|
+
const stream = new Blob([bytes]).stream().pipeThrough(new DecompressionStream("deflate"));
|
|
72
|
+
const reader = stream.getReader();
|
|
73
|
+
const parts = [];
|
|
74
|
+
let size = 0;
|
|
75
|
+
try {
|
|
76
|
+
while (size <= MAX_INFLATED_BYTES) {
|
|
77
|
+
const { value, done } = await reader.read();
|
|
78
|
+
if (done) break;
|
|
79
|
+
parts.push(value);
|
|
80
|
+
size += value.byteLength;
|
|
81
|
+
}
|
|
82
|
+
} catch {
|
|
83
|
+
// A stream cut short still gives up what it held before the break.
|
|
84
|
+
} finally {
|
|
85
|
+
reader.cancel().catch(() => undefined);
|
|
86
|
+
}
|
|
87
|
+
const out = new Uint8Array(size);
|
|
88
|
+
let at = 0;
|
|
89
|
+
for (const part of parts) {
|
|
90
|
+
out.set(part, at);
|
|
91
|
+
at += part.byteLength;
|
|
92
|
+
}
|
|
93
|
+
return out;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Every web or mail address a PDF links to, in the order the file has them.
|
|
98
|
+
* Never throws: a file it cannot make sense of has no links.
|
|
99
|
+
*
|
|
100
|
+
* @param {Uint8Array} bytes
|
|
101
|
+
* @returns {Promise<string[]>}
|
|
102
|
+
*/
|
|
103
|
+
async function pdfLinks(bytes) {
|
|
104
|
+
const found = new Set();
|
|
105
|
+
try {
|
|
106
|
+
const source = latin1(bytes);
|
|
107
|
+
urisIn(source, found);
|
|
108
|
+
let inflated = 0;
|
|
109
|
+
const streams = /stream\r?\n/g;
|
|
110
|
+
for (let match = streams.exec(source); match !== null && found.size < MAX_LINKS; match = streams.exec(source)) {
|
|
111
|
+
const start = match.index + match[0].length;
|
|
112
|
+
const end = source.indexOf("endstream", start);
|
|
113
|
+
if (end === -1) break;
|
|
114
|
+
streams.lastIndex = end + "endstream".length;
|
|
115
|
+
const dict = source.slice(Math.max(0, match.index - DICT_LOOKBACK), match.index);
|
|
116
|
+
const own = dict.slice(dict.lastIndexOf("obj") + 1);
|
|
117
|
+
if (!/\/FlateDecode/.test(own) || /\/Subtype\s*\/Image|\/FontFile|\/Length1/.test(own)) continue;
|
|
118
|
+
if (inflated > MAX_INFLATED_BYTES) break;
|
|
119
|
+
const plain = await inflate(bytes.subarray(start, end));
|
|
120
|
+
inflated += plain.byteLength;
|
|
121
|
+
urisIn(latin1(plain), found);
|
|
122
|
+
}
|
|
123
|
+
} catch {
|
|
124
|
+
// Best effort: the words are still read.
|
|
125
|
+
}
|
|
126
|
+
return [...found].slice(0, MAX_LINKS);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/** The lines `read_file` adds under a PDF's words, or nothing when it links nowhere. */
|
|
130
|
+
function linksSection(links) {
|
|
131
|
+
if (links.length === 0) return "";
|
|
132
|
+
return `\n\nLinks in this file (where its buttons and linked words go):\n${links.map((link) => `- ${link}`).join("\n")}`;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
module.exports = { linksSection, MAX_LINKS, MAX_INFLATED_BYTES, pdfLinks };
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A person's own Tex hub address (`hubLinks.js`) and the handle it is built from (`ownHandle`, `http/texComputer.js`):
|
|
3
|
+
* the handle is read off the grant, never off the request.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
const { appOriginOf } = require("../texShared/noteAppLink.cjs");
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* The handle a person's own page lives at: the slug of the personal workspace
|
|
10
|
+
* they own, or null. Never somebody else's personal workspace they are a
|
|
11
|
+
* member of, which also has kind "personal".
|
|
12
|
+
*/
|
|
13
|
+
function ownHandle(session) {
|
|
14
|
+
const own = (session?.workspaces || []).find((w) => w?.kind === "personal" && w?.role === "owner");
|
|
15
|
+
return typeof own?.slug === "string" && own.slug ? own.slug : null;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const HANDLE = /^[a-z0-9-]{2,32}$/;
|
|
19
|
+
|
|
20
|
+
/** `<origin>/tex/@<handle>`, or null without an https origin or a handle. */
|
|
21
|
+
function personHubUrl(env, session) {
|
|
22
|
+
const origin = appOriginOf(env);
|
|
23
|
+
const handle = String(ownHandle(session) ?? "").toLowerCase();
|
|
24
|
+
return origin !== null && HANDLE.test(handle) ? `${origin}/tex/@${handle}` : null;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* The person's own browser view, full screen, where they take a handoff over (`http/texComputer.js`, `agent/turnWeb.js`):
|
|
29
|
+
* `<origin>/tex/@<handle>?view=computer&full=1`, or null without an https origin or a handle.
|
|
30
|
+
*/
|
|
31
|
+
function texViewerUrl(env, session) {
|
|
32
|
+
const handle = ownHandle(session);
|
|
33
|
+
const origin = typeof env?.APP_ORIGIN === "string" ? env.APP_ORIGIN : "";
|
|
34
|
+
if (handle === null || !/^https:\/\/[^/]+$/.test(origin.replace(/\/$/, ""))) return null;
|
|
35
|
+
return `${origin.replace(/\/$/, "")}/tex/@${handle}?view=computer&full=1`;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
module.exports = { ownHandle, personHubUrl, texViewerUrl };
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/** Types for `personHub.cjs`; see that file. */
|
|
2
|
+
|
|
3
|
+
export declare function ownHandle(session: unknown): string | null;
|
|
4
|
+
export declare function personHubUrl(env: unknown, session: unknown): string | null;
|
|
5
|
+
export declare function texViewerUrl(env: unknown, session: unknown): string | null;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A chat member's name as the group turn is told it (`groupNames.js`): letters and marks on one short line, so a name
|
|
3
|
+
* cannot carry an instruction. The gateway's contacts page cleans names the same way.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
const MAX_NAME = 80;
|
|
7
|
+
/** A name as told to the turn: letters, marks, spaces, apostrophes, hyphens and periods, one line. */
|
|
8
|
+
function cleanName(name) {
|
|
9
|
+
if (typeof name !== "string") return "";
|
|
10
|
+
return name
|
|
11
|
+
.replace(/[^\p{L}\p{M}\s'’.-]/gu, " ")
|
|
12
|
+
.replace(/\s+/g, " ")
|
|
13
|
+
.trim()
|
|
14
|
+
.slice(0, MAX_NAME)
|
|
15
|
+
.trim();
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
module.exports = { cleanName };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The pinned workspace, addressed as a tool call would address it. Mirrors
|
|
3
|
+
* `PINNED_CONTEXT_SLUG` in `packages/shared/src/pinnedContext.ts` (the gateway
|
|
4
|
+
* takes no dependency on that package); a test holds the two together
|
|
5
|
+
* (`apps/mcp/test/globalOrientNote.test.mjs`). The gateway's
|
|
6
|
+
* `orient/globalNote.js` re-exports it, and Tex reads it here.
|
|
7
|
+
*/
|
|
8
|
+
"use strict";
|
|
9
|
+
|
|
10
|
+
const PINNED_CONTEXT_NAME = "@context-lc";
|
|
11
|
+
|
|
12
|
+
module.exports = { PINNED_CONTEXT_NAME };
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A `quiet-hours:` value read as a window (`packages/tex/gateway/agent/quietHours.js` says what quiet hours hold), with
|
|
3
|
+
* no imports: Tex's check-ins and its settings by text, and the Tex page's settings (`settingHabits.cjs`), read the
|
|
4
|
+
* same words.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/** One time of day, `11 pm`, `7am`, `22:00`, `7:30 am`, as minutes after midnight, or null. */
|
|
8
|
+
function minutesOf(words) {
|
|
9
|
+
const match = /^\s*(\d{1,2})(?::(\d{2}))?\s*(am|pm|a\.m\.|p\.m\.)?\s*$/i.exec(words);
|
|
10
|
+
if (match === null) return null;
|
|
11
|
+
let hour = Number(match[1]);
|
|
12
|
+
const minute = match[2] === undefined ? 0 : Number(match[2]);
|
|
13
|
+
if (minute > 59) return null;
|
|
14
|
+
const half = match[3]?.toLowerCase().replace(/\./g, "");
|
|
15
|
+
if (half !== undefined) {
|
|
16
|
+
if (hour < 1 || hour > 12) return null;
|
|
17
|
+
hour = (hour % 12) + (half === "pm" ? 12 : 0);
|
|
18
|
+
} else if (match[2] === undefined || hour > 23) {
|
|
19
|
+
// A bare number is too unsure to keep anyone from being texted.
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
return hour * 60 + minute;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** The window a `quiet-hours:` value names, `{ from, until }` in minutes after midnight, or null when it names none. */
|
|
26
|
+
function readQuietHours(value) {
|
|
27
|
+
if (typeof value !== "string") return null;
|
|
28
|
+
const parts = value.replace(/^["']|["']$/g, "").split(/\s*(?:\bto\b|–|—|-|until)\s*/i);
|
|
29
|
+
if (parts.length !== 2) return null;
|
|
30
|
+
const from = minutesOf(parts[0]);
|
|
31
|
+
const until = minutesOf(parts[1]);
|
|
32
|
+
if (from === null || until === null || from === until) return null;
|
|
33
|
+
return { from, until };
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
module.exports = { readQuietHours };
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A grant's scopes clamped by the role its person holds: what a live request may do in one workspace
|
|
3
|
+
* (`apps/mcp/src/session.js`, which imports these and is where every request is clamped), and what orientation says a
|
|
4
|
+
* connection may do in each context it reaches (`texContract/identity.cjs` `contextsFor`). Pure, and one copy, so the
|
|
5
|
+
* description and the decision cannot disagree.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
const { SCOPE_READ, SCOPE_WRITE, SCOPE_CAPTURE, SCOPE_PRIVATE } = require("./scopes.cjs");
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* The privacy tier this grant was given.
|
|
12
|
+
*
|
|
13
|
+
* **Read from the grant, then clamped by role — never derived from role.**
|
|
14
|
+
* That inversion is the whole change. `visibilityTierForRole(role)` used to
|
|
15
|
+
* live here and answered `private` for every owner, which meant an owner could
|
|
16
|
+
* not connect a client at team level even if that was exactly what they wanted:
|
|
17
|
+
* every note they had ever marked private went to whatever they connected. The
|
|
18
|
+
* tier is now something a person decided at consent time and the grant carries,
|
|
19
|
+
* so an owner who granted `team` gets `team` on every later request, forever.
|
|
20
|
+
*
|
|
21
|
+
* The role clamp stays, and is not redundant with the control plane's. The
|
|
22
|
+
* control plane decides what may be *written* into a grant, at approval time;
|
|
23
|
+
* this decides what a *live request* may do with one, now. Between those two
|
|
24
|
+
* moments a membership can change — and while an owner cannot be demoted, a
|
|
25
|
+
* grant is not the only thing that can go stale. Reading a value the control
|
|
26
|
+
* plane vouched for and enforcing it against the role the control plane
|
|
27
|
+
* reported in the same breath costs one `Set` and closes the gap.
|
|
28
|
+
*/
|
|
29
|
+
function visibilityTierForGrant(grantScopes, role) {
|
|
30
|
+
if (role !== "owner") return "team";
|
|
31
|
+
return new Set(grantScopes).has(SCOPE_PRIVATE) ? "private" : "team";
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** Roles that may change content at all, before per-grant scopes narrow it. */
|
|
35
|
+
function roleCanWrite(role) {
|
|
36
|
+
return role === "owner" || role === "editor";
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Grant scopes ∩ what the role permits.
|
|
41
|
+
*
|
|
42
|
+
* Both halves matter and neither implies the other. A read-only grant issued to
|
|
43
|
+
* an owner must not write — the person deliberately connected a client that way
|
|
44
|
+
* — and a full-scope grant issued to a read-only `member` must not write
|
|
45
|
+
* either, because the grant cannot confer authority the membership never had.
|
|
46
|
+
*
|
|
47
|
+
* `SCOPE_PRIVATE` goes through the same intersection as everything else: it
|
|
48
|
+
* survives only if the grant carries it *and* the caller is the owner. It is
|
|
49
|
+
* kept on a capture-only grant too, where it means nothing — the tier only
|
|
50
|
+
* matters to reads — because filtering it out there would be a special case
|
|
51
|
+
* that has to stay in sync with which scopes read, and there is nothing to gain
|
|
52
|
+
* from one.
|
|
53
|
+
*/
|
|
54
|
+
function effectiveScopes(grantScopes, role) {
|
|
55
|
+
const granted = new Set(grantScopes);
|
|
56
|
+
const effective = [SCOPE_READ];
|
|
57
|
+
if (granted.has(SCOPE_WRITE) && roleCanWrite(role)) {
|
|
58
|
+
effective.push(SCOPE_WRITE, SCOPE_CAPTURE);
|
|
59
|
+
} else if (granted.has(SCOPE_CAPTURE) && roleCanWrite(role)) {
|
|
60
|
+
effective.push(SCOPE_CAPTURE);
|
|
61
|
+
}
|
|
62
|
+
// The tier the person granted, and only for the one role that could grant it.
|
|
63
|
+
// A grant that predates the tier being grantable carries no `context:private`
|
|
64
|
+
// and therefore lands on `team` — a narrowing, which is always allowed, and
|
|
65
|
+
// the only reading that does not leave every legacy grant at full access.
|
|
66
|
+
if (granted.has(SCOPE_PRIVATE) && role === "owner") {
|
|
67
|
+
effective.push(SCOPE_PRIVATE);
|
|
68
|
+
}
|
|
69
|
+
// A grant with no read scope is capture-only: it may drop things into the
|
|
70
|
+
// inbox and may not look at anything.
|
|
71
|
+
if (!granted.has(SCOPE_READ)) {
|
|
72
|
+
return effective.filter((scope) => scope !== SCOPE_READ);
|
|
73
|
+
}
|
|
74
|
+
return effective;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* What this connection may actually do in a context where its person holds
|
|
79
|
+
* `role` — the tier it reads at there, and whether it may write.
|
|
80
|
+
*
|
|
81
|
+
* `writesAnywhere`'s question asked of one context instead of all of them, and
|
|
82
|
+
* here for the same reason that one is: the clamp that answers it is this
|
|
83
|
+
* module's, and a second copy of `effectiveScopes` reasoning is the drift this
|
|
84
|
+
* file exists to prevent. `orient` describes every context a connection
|
|
85
|
+
* reaches, and it described them from the *role* alone — which is neither
|
|
86
|
+
* half of the answer. A read-only grant held by an `editor` was announced as
|
|
87
|
+
* writable; an `owner` was described as reading private notes on a grant that
|
|
88
|
+
* carries no `context:private` and reads that context at `team`.
|
|
89
|
+
*
|
|
90
|
+
* It answers from the grant's own scopes, never the connection's already
|
|
91
|
+
* clamped set, exactly as `sessionForContext` does: re-clamping intersects two
|
|
92
|
+
* roles and would describe a context somebody owns by the role they hold
|
|
93
|
+
* somewhere else.
|
|
94
|
+
*
|
|
95
|
+
* This is a description, never a decision. The gate in `callToolForSession`
|
|
96
|
+
* still decides, from the session `sessionForContext` builds — but both read
|
|
97
|
+
* the same clamp, so what orientation promises and what the call does cannot
|
|
98
|
+
* disagree.
|
|
99
|
+
*/
|
|
100
|
+
function reachForRole(session, role) {
|
|
101
|
+
const granted = session?.grantScopes || session?.scopes || [];
|
|
102
|
+
const scopes = effectiveScopes(granted, role);
|
|
103
|
+
return {
|
|
104
|
+
tier: visibilityTierForGrant(scopes, role),
|
|
105
|
+
canWrite: scopes.includes(SCOPE_WRITE),
|
|
106
|
+
/*
|
|
107
|
+
Which of the two halves said no, because the remedies differ and
|
|
108
|
+
`callToolForSession` already refuses in exactly these two voices. A grant
|
|
109
|
+
that was never given write is a reconnection the person can make; a role
|
|
110
|
+
that cannot back one up is not, and telling them to reconnect for write
|
|
111
|
+
they can never hold there sends them round a loop that cannot end.
|
|
112
|
+
*/
|
|
113
|
+
grantWrites: new Set(granted).has(SCOPE_WRITE),
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
module.exports = { visibilityTierForGrant, effectiveScopes, reachForRole };
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/** Types for `scopeClamp.cjs`; see that file. */
|
|
2
|
+
|
|
3
|
+
export declare function visibilityTierForGrant(grantScopes: Iterable<string>, role: string): "private" | "team";
|
|
4
|
+
export declare function effectiveScopes(grantScopes: Iterable<string>, role: string): string[];
|
|
5
|
+
export declare function reachForRole(session: unknown, role: string): { tier: "private" | "team"; canWrite: boolean; grantWrites: boolean };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The scope strings a Context grant carries, and the one check on them.
|
|
3
|
+
*
|
|
4
|
+
* Shared by the gateway and Tex, so both name a scope the same way. `apps/mcp/src/session.js` re-exports these, and
|
|
5
|
+
* keeps `SUPPORTED_SCOPES`; `SCOPE_CAPTURE` is here for the role clamp (`scopeClamp.cjs`).
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/** Read every visible note. */
|
|
9
|
+
const SCOPE_READ = "context:read";
|
|
10
|
+
/** Create, update, move, and archive notes. Implies capture. */
|
|
11
|
+
const SCOPE_WRITE = "context:write";
|
|
12
|
+
/** File into the inbox and nowhere else. */
|
|
13
|
+
const SCOPE_CAPTURE = "context:capture";
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Reach notes marked private.
|
|
17
|
+
*
|
|
18
|
+
* Not an operation — holding it lets a client *do* nothing new. It widens the
|
|
19
|
+
* set of notes every other scope applies to, which is why it is the one scope
|
|
20
|
+
* a person is asked about separately on the consent screen and the one a
|
|
21
|
+
* client's request cannot decide.
|
|
22
|
+
*/
|
|
23
|
+
const SCOPE_PRIVATE = "context:private";
|
|
24
|
+
|
|
25
|
+
function hasScope(session, scope) {
|
|
26
|
+
return Array.isArray(session?.scopes) && session.scopes.includes(scope);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
module.exports = { SCOPE_READ, SCOPE_WRITE, SCOPE_CAPTURE, SCOPE_PRIVATE, hasScope };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/** Types for `scopes.cjs`; see that file for the reasons. */
|
|
2
|
+
|
|
3
|
+
export declare const SCOPE_READ: "context:read";
|
|
4
|
+
export declare const SCOPE_WRITE: "context:write";
|
|
5
|
+
export declare const SCOPE_CAPTURE: "context:capture";
|
|
6
|
+
export declare const SCOPE_PRIVATE: "context:private";
|
|
7
|
+
export declare function hasScope(session: { scopes?: readonly string[] } | null | undefined, scope: string): boolean;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A setup's `search:` section, read and checked: the person-facing search
|
|
3
|
+
* settings (`minScore`, `extraNotes`, `snippetChars`, `everywhere`), what each
|
|
4
|
+
* may be, and their front-matter keys. A pure contract the gateway
|
|
5
|
+
* (`apps/mcp/src/search/settings.js` and `config/searchConfig.cjs`, which take
|
|
6
|
+
* the bounds from here) and Tex (`agent/production.js`) both read. Moved verbatim.
|
|
7
|
+
*/
|
|
8
|
+
"use strict";
|
|
9
|
+
|
|
10
|
+
/** What each person-facing setting may be; `searchConfig.cjs` lists them with the ranking knobs. */
|
|
11
|
+
const PERSON_SEARCH_BOUNDS = Object.freeze({
|
|
12
|
+
minScore: Object.freeze({ min: 0, max: 1, integer: false }),
|
|
13
|
+
extraNotes: Object.freeze({ min: 0, max: 10, integer: true }),
|
|
14
|
+
snippetChars: Object.freeze({ min: 50, max: 2000, integer: true }),
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
/** The front-matter and JSON key for each setting. */
|
|
18
|
+
const SEARCH_SETTING_KEYS = Object.freeze({
|
|
19
|
+
everywhere: "everywhere",
|
|
20
|
+
min_score: "minScore",
|
|
21
|
+
extra_notes: "extraNotes",
|
|
22
|
+
snippet_chars: "snippetChars",
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Settings from a plain object of wire keys (`min_score`, …), each checked, or
|
|
27
|
+
* `null` when a value is outside what it may be. Missing keys stay missing,
|
|
28
|
+
* so a partial section lays over another without blanking it.
|
|
29
|
+
*
|
|
30
|
+
* @param {unknown} raw e.g. `{ everywhere: "true", min_score: "0.35" }`
|
|
31
|
+
*/
|
|
32
|
+
function readSearchSettings(raw) {
|
|
33
|
+
if (raw === undefined || raw === null) return {};
|
|
34
|
+
if (typeof raw !== "object" || Array.isArray(raw)) return null;
|
|
35
|
+
const out = {};
|
|
36
|
+
for (const [key, value] of Object.entries(raw)) {
|
|
37
|
+
const name = SEARCH_SETTING_KEYS[key];
|
|
38
|
+
if (!name) return null;
|
|
39
|
+
if (name === "everywhere") {
|
|
40
|
+
if (value === true || value === "true") out.everywhere = true;
|
|
41
|
+
else if (value === false || value === "false") out.everywhere = false;
|
|
42
|
+
else return null;
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
const number = typeof value === "number" ? value : typeof value === "string" && /^\d+(\.\d+)?$/.test(value.trim()) ? Number(value) : NaN;
|
|
46
|
+
const bound = PERSON_SEARCH_BOUNDS[name];
|
|
47
|
+
if (!Number.isFinite(number) || number < bound.min || number > bound.max) return null;
|
|
48
|
+
if (bound.integer && !Number.isInteger(number)) return null;
|
|
49
|
+
out[name] = number;
|
|
50
|
+
}
|
|
51
|
+
return out;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
module.exports = { PERSON_SEARCH_BOUNDS, SEARCH_SETTING_KEYS, readSearchSettings };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/** Types for `searchSettings.cjs`; see that file. */
|
|
2
|
+
|
|
3
|
+
type Bound = { readonly min: number; readonly max: number; readonly integer: boolean };
|
|
4
|
+
export declare const PERSON_SEARCH_BOUNDS: { readonly minScore: Bound; readonly extraNotes: Bound; readonly snippetChars: Bound };
|
|
5
|
+
export declare const SEARCH_SETTING_KEYS: Readonly<Record<"everywhere" | "min_score" | "extra_notes" | "snippet_chars", string>>;
|
|
6
|
+
export declare function readSearchSettings(raw: unknown): { everywhere?: boolean; minScore?: number; extraNotes?: number; snippetChars?: number } | null;
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `setting` switches Tex changes by text (`packages/tex/gateway/agent/settingsTools.js`; Dev2, 2026-11-12,
|
|
3
|
+
* `docs/decisions/texting-assistant/settings-by-text.md`), read and set through one door, `call(name, args)`, an MCP
|
|
4
|
+
* tool call as the person. Tex's `tex_setting_set` and the Tex page's Settings (`apps/mcp/src/http/texPage/serve.js`)
|
|
5
|
+
* both use these setters, so a value the chat would refuse is refused on the page too, and both read the same notes.
|
|
6
|
+
* What each switch is called and how a change is said stays with Tex (`SETTING_HANDLERS`).
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
const { DREAMS_SETTINGS_PATH, HEARTBEAT_SETTINGS_PATH, HOUSEKEEPING_SETTINGS_PATH, frontSet, readCheckinSettings, readSwitches } = require("./settingsNotes.cjs");
|
|
10
|
+
const { ATTENTION_SETTINGS_PATH, TOLERANCES, readAttentionSettings } = require("./attention.cjs");
|
|
11
|
+
const { readQuietHours } = require("./quietHoursWindow.cjs");
|
|
12
|
+
|
|
13
|
+
/** Read one note's front matter through the turn's own tool door, or null. */
|
|
14
|
+
async function readFront(dispatch, path) {
|
|
15
|
+
try {
|
|
16
|
+
const result = await dispatch("read_note", { path });
|
|
17
|
+
if (result?.isError === true) return "";
|
|
18
|
+
const all = (Array.isArray(result?.content) ? result.content : []).map((part) => part?.text ?? "").join("\n");
|
|
19
|
+
const split = all.indexOf("\n\n");
|
|
20
|
+
return split === -1 ? "" : all.slice(split + 2);
|
|
21
|
+
} catch {
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const onOff = (value) => (value === true || /^(on|yes|true)$/i.test(String(value ?? "").trim()) ? true : value === false || /^(off|no|false)$/i.test(String(value ?? "").trim()) ? false : null);
|
|
27
|
+
|
|
28
|
+
/** Whether a `quiet_hours` value turns them off. */
|
|
29
|
+
const quietOff = (value) => /^(off|none|no|clear)$/i.test(String(value ?? "").trim());
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Each `setting` switch's setter, by `texSettings.cjs` key: it reads `value` and changes one note's front matter, or
|
|
33
|
+
* answers null when the value is not one it takes.
|
|
34
|
+
*/
|
|
35
|
+
const SETTING_SETTERS = Object.freeze({
|
|
36
|
+
checkins: (call, value) => (onOff(value) === null ? null : frontSet(call, HEARTBEAT_SETTINGS_PATH, "paused", onOff(value) ? "no" : "yes")),
|
|
37
|
+
quiet_hours: (call, value) => {
|
|
38
|
+
const words = String(value ?? "").trim();
|
|
39
|
+
if (quietOff(words)) return frontSet(call, HEARTBEAT_SETTINGS_PATH, "quiet-hours", null);
|
|
40
|
+
return readQuietHours(words) === null ? null : frontSet(call, HEARTBEAT_SETTINGS_PATH, "quiet-hours", words);
|
|
41
|
+
},
|
|
42
|
+
pings: async (call, value) => {
|
|
43
|
+
const words = String(value ?? "").trim().toLowerCase().replace(/ only$/, "");
|
|
44
|
+
if (words === "off") return frontSet(call, ATTENTION_SETTINGS_PATH, "paused", "yes");
|
|
45
|
+
if (!TOLERANCES.includes(words)) return null;
|
|
46
|
+
const paused = await frontSet(call, ATTENTION_SETTINGS_PATH, "paused", null);
|
|
47
|
+
return paused?.ok === true ? frontSet(call, ATTENTION_SETTINGS_PATH, "tolerance", words) : paused;
|
|
48
|
+
},
|
|
49
|
+
overnight: (call, value) => (onOff(value) === null ? null : frontSet(call, DREAMS_SETTINGS_PATH, "paused", onOff(value) ? "no" : "yes")),
|
|
50
|
+
tidy: (call, value) => (onOff(value) === null ? null : frontSet(call, HOUSEKEEPING_SETTINGS_PATH, "paused", onOff(value) ? "no" : "yes")),
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* The `setting` switches as the app's settings page reads them (`/tex/page/list`, kind `settings`, the person's own
|
|
55
|
+
* chat): the same notes `settingsSnapshot` reads for a text, so the page and the chat can't disagree. A note that is
|
|
56
|
+
* missing reads as its default; one that can't be read is null, never guessed.
|
|
57
|
+
*/
|
|
58
|
+
async function readHabits(call) {
|
|
59
|
+
const [checkins, switches, attention] = await Promise.all([
|
|
60
|
+
readCheckinSettings(call).catch(() => null),
|
|
61
|
+
readSwitches(call).catch(() => null),
|
|
62
|
+
readFront(call, ATTENTION_SETTINGS_PATH),
|
|
63
|
+
]);
|
|
64
|
+
const said = attention === null ? null : readAttentionSettings(attention);
|
|
65
|
+
return {
|
|
66
|
+
checkins: checkins === null ? null : !checkins.paused,
|
|
67
|
+
quietHours: checkins === null ? null : (checkins.quietHours ?? ""),
|
|
68
|
+
pings: said === null ? null : said.paused ? "off" : said.tolerance,
|
|
69
|
+
overnight: switches === null ? null : switches.dreams,
|
|
70
|
+
tidy: switches === null ? null : switches.housekeeping,
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* One `setting` switch changed from the app's settings page (`setting.set`): the setter a text uses, so a value the
|
|
76
|
+
* chat would refuse is refused here too. `value` is a boolean for an on/off switch, or the words a text would send.
|
|
77
|
+
*/
|
|
78
|
+
async function settingSet(call, key, value) {
|
|
79
|
+
const setter = typeof key === "string" && Object.hasOwn(SETTING_SETTERS, key) ? SETTING_SETTERS[key] : null;
|
|
80
|
+
const words = typeof value === "boolean" ? (value ? "on" : "off") : typeof value === "string" && value.length <= 80 ? value : null;
|
|
81
|
+
if (setter === null || words === null) return { ok: false, error: "invalid" };
|
|
82
|
+
const done = await Promise.resolve(setter(call, words)).catch(() => ({ ok: false, error: "failed" }));
|
|
83
|
+
if (done === null) return { ok: false, error: "invalid" };
|
|
84
|
+
return done?.ok === true ? { ok: true } : { ok: false, error: done?.error ?? "failed" };
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
module.exports = { SETTING_SETTERS, onOff, quietOff, readFront, readHabits, settingSet };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/** Types for `settingHabits.cjs`; see that file. */
|
|
2
|
+
|
|
3
|
+
type Call = (name: string, args: Record<string, unknown>) => Promise<any>;
|
|
4
|
+
type Done = { ok: true } | { ok: false; error: string };
|
|
5
|
+
type Setter = (call: Call, value: unknown) => Promise<Done> | Done | null;
|
|
6
|
+
|
|
7
|
+
export type SettingKey = "checkins" | "quiet_hours" | "pings" | "overnight" | "tidy";
|
|
8
|
+
export interface Habits {
|
|
9
|
+
checkins: boolean | null;
|
|
10
|
+
quietHours: string | null;
|
|
11
|
+
pings: string | null;
|
|
12
|
+
overnight: boolean | null;
|
|
13
|
+
tidy: boolean | null;
|
|
14
|
+
}
|
|
15
|
+
export declare const SETTING_SETTERS: Readonly<Record<SettingKey, Setter>>;
|
|
16
|
+
export declare function onOff(value: unknown): boolean | null;
|
|
17
|
+
export declare function quietOff(value: unknown): boolean;
|
|
18
|
+
export declare function readFront(dispatch: Call, path: string): Promise<string | null>;
|
|
19
|
+
export declare function readHabits(call: Call): Promise<Habits>;
|
|
20
|
+
export declare function settingSet(call: Call, key: unknown, value: unknown): Promise<Done>;
|