@supa-media/tex-contract 0.0.0-stage → 0.3.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 +21 -0
- package/README.md +33 -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/capabilities.cjs +47 -0
- package/texContract/capabilities.d.cts +27 -0
- package/texContract/capabilities.generated.json +77 -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/reactEmoji.cjs +79 -0
- package/texContract/reactEmoji.d.cts +2 -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/texNumber.cjs +20 -0
- package/texContract/texNumber.d.cts +3 -0
- package/texContract/texOwnSources.cjs +9 -0
- package/texContract/texOwnSources.d.cts +3 -0
- package/texContract/texSettings.cjs +22 -0
- package/texContract/texSettings.d.cts +20 -0
- package/texContract/texSettings.generated.json +25 -0
- package/texContract/texStateFiles.cjs +22 -0
- package/texContract/texStateFiles.d.cts +9 -0
- package/texContract/texSteps.cjs +27 -0
- package/texContract/texSteps.d.cts +14 -0
- package/texContract/texSteps.generated.json +41 -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 +159 -0
- package/texShared/flags.d.cts +23 -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,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WHETHER A CONNECTION SEES EVERY NOTE OF ITS PERSONAL WORKSPACE: the
|
|
3
|
+
* person's own connection to their personal workspace, as its owner, with
|
|
4
|
+
* the private tier.
|
|
5
|
+
*
|
|
6
|
+
* Tex reads its desk's notes by key only on such a connection
|
|
7
|
+
* (`packages/tex/gateway/agent/texDesk.js`, which re-exports this), and
|
|
8
|
+
* Context reads the person's history file straight from their ledger on it
|
|
9
|
+
* (`apps/mcp/src/tools/notes/historyRead.js`): that connection sees every
|
|
10
|
+
* note there, so neither shows anything `read_note` would not. One rule, so
|
|
11
|
+
* both sides make it the same way. Reads only the store's `contexts`.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
/** Whether this connection may read the desk's notes by key: its own personal workspace, as owner, private tier. */
|
|
15
|
+
function deskEligible(store) {
|
|
16
|
+
const current = (Array.isArray(store?.contexts) ? store.contexts : []).find((entry) => entry?.current === true);
|
|
17
|
+
return current?.kind === "personal" && current.role === "owner" && current.tier === "private";
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
module.exports = { deskEligible };
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared by Tex, which keeps a file (`agent/downloads.js`), and the gateway, which attaches one to an email
|
|
3
|
+
* (`tools/emailAttach.js`).
|
|
4
|
+
*
|
|
5
|
+
* FILES TEX DOWNLOADED, KEPT FOR A WHILE (the owner, 2026-10-22: "it should be
|
|
6
|
+
* able to download a pdf and email it"). Tex found a Google Voice invoice in
|
|
7
|
+
* the Admin console and told the owner to download it and attach it himself.
|
|
8
|
+
* Now the browser's `download` step (`browse.js`, `infra/site-shots/src/download.ts`)
|
|
9
|
+
* hands the file back, and it is kept here, in the person's own bucket, under
|
|
10
|
+
* an id the model passes on:
|
|
11
|
+
*
|
|
12
|
+
* - `send_email` / `save_email_draft` `attach: ["download:<id>"]` (`tools/email.js`);
|
|
13
|
+
* - a browse `upload` step with `file: "download:<id>"` (`uploads.js`).
|
|
14
|
+
*
|
|
15
|
+
* Where: `.context/agent/downloads/<id>.json`, a hidden folder of the
|
|
16
|
+
* workspace's own bucket, so a later text, or a background job, can still
|
|
17
|
+
* use it (the owner, 2026-10-22: "store it in a hidden folder in the bucket
|
|
18
|
+
* just so that it persists across Tex sessions"). How long: a file up to
|
|
19
|
+
* `LONG_KEEP_BYTES` for `LONG_KEEP_MS`, a bigger one (up to the 10 MB a file
|
|
20
|
+
* is read at) for `SHORT_KEEP_MS`, enough for an email waiting on a yes. The
|
|
21
|
+
* id carries when it was kept, so an expired file is refused without reading
|
|
22
|
+
* it and swept on the next download.
|
|
23
|
+
*
|
|
24
|
+
* The id is random: knowing one names nothing outside this bucket, and the
|
|
25
|
+
* bucket is the tenancy boundary, so another person's id finds nothing here.
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
const DOWNLOADS_PREFIX = ".context/agent/downloads/";
|
|
29
|
+
const LONG_KEEP_BYTES = 5 * 1024 * 1024;
|
|
30
|
+
const LONG_KEEP_MS = 30 * 24 * 60 * 60 * 1000;
|
|
31
|
+
const SHORT_KEEP_MS = 24 * 60 * 60 * 1000;
|
|
32
|
+
const MAX_DOWNLOAD_BYTES = 10 * 1024 * 1024;
|
|
33
|
+
|
|
34
|
+
/** `download:<ms>-<s|l>-<hex>`: when it was kept, for how long, and 16 random bytes. */
|
|
35
|
+
const ID = /^download:(\d{13})-([sl])-([a-f0-9]{32})$/;
|
|
36
|
+
|
|
37
|
+
const TYPE = /^[a-z]+\/[a-z0-9.+-]{1,100}$/;
|
|
38
|
+
|
|
39
|
+
/** A file name a person may be shown: its last part, no control characters or slashes. */
|
|
40
|
+
function downloadName(raw, fallback = "download") {
|
|
41
|
+
const leaf = String(raw ?? "").split(/[\\/]/).pop() ?? "";
|
|
42
|
+
const clean = leaf.replace(/[\u0000-\u001f\u007f\u202a-\u202e\u2066-\u2069]/g, "").trim().slice(0, 200);
|
|
43
|
+
return clean || fallback;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** Whether a string is a download id at all. */
|
|
47
|
+
const isDownloadId = (value) => typeof value === "string" && ID.test(value.trim());
|
|
48
|
+
|
|
49
|
+
function keyOf(id) {
|
|
50
|
+
const m = ID.exec(id);
|
|
51
|
+
return m ? `${DOWNLOADS_PREFIX}${m[1]}-${m[2]}-${m[3]}.json` : null;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function expired(id, now) {
|
|
55
|
+
const m = ID.exec(id);
|
|
56
|
+
if (!m) return true;
|
|
57
|
+
return now - Number(m[1]) > (m[2] === "l" ? LONG_KEEP_MS : SHORT_KEEP_MS);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function sizeOf(data) {
|
|
61
|
+
return Math.floor((data.length * 3) / 4) - (data.endsWith("==") ? 2 : data.endsWith("=") ? 1 : 0);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Keep a file the browser handed back, `{ name, type, data }` with `data` as
|
|
66
|
+
* base64, and answer `{ id, name, type, size, keptFor }` or `{ error }`.
|
|
67
|
+
*/
|
|
68
|
+
async function keepDownload(store, file, { now = Date.now() } = {}) {
|
|
69
|
+
if (typeof store?.put !== "function") return { error: "files can't be kept here; tell the person, and link the page instead" };
|
|
70
|
+
const data = typeof file?.data === "string" ? file.data : "";
|
|
71
|
+
if (!data || !/^[A-Za-z0-9+/]+=*$/.test(data)) return { error: "the browser gave back no file; open the page again and retry the download step" };
|
|
72
|
+
const size = sizeOf(data);
|
|
73
|
+
if (size > MAX_DOWNLOAD_BYTES) return { error: "that file is over the 10 MB a file can be; link it instead of attaching it" };
|
|
74
|
+
const name = downloadName(file.name);
|
|
75
|
+
const type = typeof file.type === "string" && TYPE.test(file.type) ? file.type : "application/octet-stream";
|
|
76
|
+
const long = size <= LONG_KEEP_BYTES;
|
|
77
|
+
const random = [...crypto.getRandomValues(new Uint8Array(16))].map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
78
|
+
const id = `download:${now}-${long ? "l" : "s"}-${random}`;
|
|
79
|
+
await sweepDownloads(store, now).catch(() => undefined);
|
|
80
|
+
await store.put(keyOf(id), JSON.stringify({ version: 1, name, type, size, keptAt: new Date(now).toISOString(), data }));
|
|
81
|
+
return { id, name, type, size, keptFor: long ? "30 days" : "24 hours" };
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* A kept file by its id: `{ file: { name, type, size, data } }`, or `{ error }`
|
|
86
|
+
* in words the model is shown.
|
|
87
|
+
*/
|
|
88
|
+
async function readDownload(store, rawId, { now = Date.now() } = {}) {
|
|
89
|
+
const id = String(rawId ?? "").trim();
|
|
90
|
+
if (!ID.test(id)) return { error: "a downloaded file is named by the download:… id the download step gave; pass that id" };
|
|
91
|
+
if (expired(id, now)) return { error: `${id} is no longer kept; download it again` };
|
|
92
|
+
let parsed = null;
|
|
93
|
+
try {
|
|
94
|
+
const object = await store.get(keyOf(id));
|
|
95
|
+
parsed = object ? JSON.parse(await object.text()) : null;
|
|
96
|
+
} catch {
|
|
97
|
+
parsed = null;
|
|
98
|
+
}
|
|
99
|
+
if (typeof parsed?.data !== "string") return { error: `${id} is not kept here; download it again` };
|
|
100
|
+
return {
|
|
101
|
+
file: {
|
|
102
|
+
name: downloadName(parsed.name),
|
|
103
|
+
type: typeof parsed.type === "string" && TYPE.test(parsed.type) ? parsed.type : "application/octet-stream",
|
|
104
|
+
size: sizeOf(parsed.data),
|
|
105
|
+
data: parsed.data,
|
|
106
|
+
},
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/** Delete every kept file past its time. Best-effort: a missed sweep only leaves a file a little longer. */
|
|
111
|
+
async function sweepDownloads(store, now = Date.now()) {
|
|
112
|
+
if (typeof store?.list !== "function" || typeof store?.delete !== "function") return 0;
|
|
113
|
+
let swept = 0;
|
|
114
|
+
let cursor;
|
|
115
|
+
for (let page = 0; page < 5; page += 1) {
|
|
116
|
+
const listed = await store.list({ prefix: DOWNLOADS_PREFIX, ...(cursor ? { cursor } : {}) });
|
|
117
|
+
for (const object of listed?.objects ?? []) {
|
|
118
|
+
const leaf = String(object.key ?? "").slice(DOWNLOADS_PREFIX.length).replace(/\.json$/, "");
|
|
119
|
+
if (!expired(`download:${leaf}`, now)) continue;
|
|
120
|
+
await store.delete(object.key).catch(() => undefined);
|
|
121
|
+
swept += 1;
|
|
122
|
+
}
|
|
123
|
+
if (!listed?.truncated || !listed.cursor) break;
|
|
124
|
+
cursor = listed.cursor;
|
|
125
|
+
}
|
|
126
|
+
return swept;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
module.exports = { DOWNLOADS_PREFIX, LONG_KEEP_BYTES, LONG_KEEP_MS, SHORT_KEEP_MS, MAX_DOWNLOAD_BYTES, downloadName, isDownloadId, keepDownload, readDownload, sweepDownloads };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/** Types for `downloads.cjs`; see that file. */
|
|
2
|
+
|
|
3
|
+
export type KeptFile = { name: string; type: string; size: number; data: string };
|
|
4
|
+
export type Kept = { id: string; name: string; type: string; size: number; keptFor: string };
|
|
5
|
+
|
|
6
|
+
export declare const DOWNLOADS_PREFIX: string;
|
|
7
|
+
export declare const LONG_KEEP_BYTES: number;
|
|
8
|
+
export declare const LONG_KEEP_MS: number;
|
|
9
|
+
export declare const SHORT_KEEP_MS: number;
|
|
10
|
+
export declare const MAX_DOWNLOAD_BYTES: number;
|
|
11
|
+
export declare function downloadName(raw: unknown, fallback?: string): string;
|
|
12
|
+
export declare function isDownloadId(value: unknown): boolean;
|
|
13
|
+
export declare function keepDownload(store: unknown, file: unknown, options?: { now?: number }): Promise<Kept | { error: string }>;
|
|
14
|
+
export declare function readDownload(store: unknown, rawId: unknown, options?: { now?: number }): Promise<{ file: KeptFile } | { error: string }>;
|
|
15
|
+
export declare function sweepDownloads(store: unknown, now?: number): Promise<number>;
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A turn's egress ledger, and which calls could share something (`apps/mcp/src/privacy/egress.js`, which re-exports
|
|
3
|
+
* these and keeps `recordRead`, the one part that judges a note's path).
|
|
4
|
+
*
|
|
5
|
+
* Tex starts a ledger for each turn it sees whole and marks it as it reads; the gateway's dispatcher marks the same
|
|
6
|
+
* ledger as the turn's tool calls read (`tools/session.js`). Pure, so both sides hold one copy.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/** The `share` values on `write_note` that mint a link (`notes/write.js`). */
|
|
10
|
+
const SHARE_VALUES = new Set(["members", "anyone", "collect"]);
|
|
11
|
+
|
|
12
|
+
/** A fresh ledger for one turn the gateway sees whole. */
|
|
13
|
+
function newLedger() {
|
|
14
|
+
return { untrusted: false, outside: false, asked: [] };
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** Mark the ledger: the turn took in something from outside the workspace. */
|
|
18
|
+
function markUntrusted(ledger) {
|
|
19
|
+
if (ledger) ledger.untrusted = ledger.outside = true;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Mark a group chat's turn: it carries other people's words, so its sends stay held as any untrusted turn's, but the
|
|
24
|
+
* people in the chat are not outside it (the owner, 2026-11-02), so `outside` is left for what came from beyond the
|
|
25
|
+
* chat: a page, an email, a file. Only a chat's own learned skills read it (`agent/chatSkills.js`).
|
|
26
|
+
*/
|
|
27
|
+
function markChatWords(ledger) {
|
|
28
|
+
if (ledger) ledger.untrusted = true;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* A summary is one plain line. It is built from arguments the model wrote (a
|
|
33
|
+
* path, an address) and read by a person who is about to say yes to it, in
|
|
34
|
+
* the gateway's own voice: a line break, a control character or a bidi
|
|
35
|
+
* override in it would let the model add sentences the person takes to be the
|
|
36
|
+
* gateway's, or reorder the ones that are.
|
|
37
|
+
*/
|
|
38
|
+
function oneLine(text) {
|
|
39
|
+
return String(text)
|
|
40
|
+
.replace(/[\u0000-\u001f\u007f-\u009f\u061c\u200b\u200e\u200f\u2028\u2029\u202a-\u202e\u2060\u2066-\u2069\ufeff]+/g, " ")
|
|
41
|
+
.replace(/\s+/g, " ")
|
|
42
|
+
.trim();
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** The write tools to treat as writes when a caller does not say. */
|
|
46
|
+
const WRITE_TOOLS_THAT_CAN_REACH_ELSEWHERE = new Set([
|
|
47
|
+
"write_note",
|
|
48
|
+
"create_form",
|
|
49
|
+
"set_visibility",
|
|
50
|
+
"set_folder_visibility",
|
|
51
|
+
"save_context",
|
|
52
|
+
"move_note",
|
|
53
|
+
"move_notes",
|
|
54
|
+
"move_folder",
|
|
55
|
+
"remember",
|
|
56
|
+
"submit_form",
|
|
57
|
+
"update_submission",
|
|
58
|
+
]);
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Whether this call could let more people see something, judged from its tool
|
|
62
|
+
* and arguments alone: the manifest is not read, so this is a superset and
|
|
63
|
+
* errs wide. Tex's housekeeping refuses anything it says yes to
|
|
64
|
+
* (`agent/housekeepingGuard.js`), since nobody is watching while it works.
|
|
65
|
+
*
|
|
66
|
+
* Never true for a dry run, which changes nothing.
|
|
67
|
+
*
|
|
68
|
+
* @param {string} name the tool, already resolved from any alias
|
|
69
|
+
* @param {object} args the arguments, `context` already stripped
|
|
70
|
+
* @param {object} options
|
|
71
|
+
* @param {string|null} options.into the other workspace addressed, as `@name`, or null
|
|
72
|
+
* @param {boolean} [options.writes] the tool changes something; addressed into
|
|
73
|
+
* another workspace it then counts, whatever else it does
|
|
74
|
+
* @returns {boolean}
|
|
75
|
+
*/
|
|
76
|
+
function mightWiden(name, args, { into = null, writes } = {}) {
|
|
77
|
+
const a = args && typeof args === "object" ? args : {};
|
|
78
|
+
if (a.dry_run === true) return false;
|
|
79
|
+
if (name === "create_link") return true;
|
|
80
|
+
if (typeof into === "string" && into !== "") return writes ?? WRITE_TOOLS_THAT_CAN_REACH_ELSEWHERE.has(name);
|
|
81
|
+
switch (name) {
|
|
82
|
+
case "write_note":
|
|
83
|
+
return (
|
|
84
|
+
a.site?.action === "publish" ||
|
|
85
|
+
SHARE_VALUES.has(a.share) ||
|
|
86
|
+
(Array.isArray(a.images) && a.images.some((image) => typeof image?.url === "string" && image.url.trim() !== "")) ||
|
|
87
|
+
a.visibility === "team"
|
|
88
|
+
);
|
|
89
|
+
case "create_form":
|
|
90
|
+
return a.visibility === "team";
|
|
91
|
+
// A bot's logo by address is fetched from outside, as write_note's images by url are.
|
|
92
|
+
case "set_area":
|
|
93
|
+
return [a.bot?.avatar?.url, a.bot?.avatar_dark?.url].some((url) => typeof url === "string" && url.trim() !== "");
|
|
94
|
+
case "vault_list":
|
|
95
|
+
return Boolean(a.fetch && typeof a.fetch === "object");
|
|
96
|
+
case "set_visibility":
|
|
97
|
+
return a.visibility === "team" || (a.people !== undefined && a.people !== null);
|
|
98
|
+
case "set_folder_visibility":
|
|
99
|
+
return a.visibility === "team" || a.visibility === "inherit";
|
|
100
|
+
case "save_context":
|
|
101
|
+
return a.visibility === "team" || a.visibility === "public";
|
|
102
|
+
case "move_note":
|
|
103
|
+
case "move_notes":
|
|
104
|
+
case "move_folder":
|
|
105
|
+
return a.confirm_team_publish === true;
|
|
106
|
+
case "create_workspace":
|
|
107
|
+
case "invite_member":
|
|
108
|
+
return true;
|
|
109
|
+
default:
|
|
110
|
+
return false;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
module.exports = { newLedger, markUntrusted, markChatWords, oneLine, mightWiden };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/** Types for `egressLedger.cjs`; see that file. */
|
|
2
|
+
|
|
3
|
+
export interface EgressLedger {
|
|
4
|
+
untrusted: boolean;
|
|
5
|
+
outside: boolean;
|
|
6
|
+
asked: unknown[];
|
|
7
|
+
[key: string]: unknown;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export declare function newLedger(): EgressLedger;
|
|
11
|
+
export declare function markUntrusted(ledger: EgressLedger | null | undefined): void;
|
|
12
|
+
export declare function markChatWords(ledger: EgressLedger | null | undefined): void;
|
|
13
|
+
export declare function oneLine(text: unknown): string;
|
|
14
|
+
export declare function mightWiden(name: string, args: unknown, options?: { into?: string | null; writes?: boolean }): boolean;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The email id and refusal contract (`apps/mcp/src/tools/emailRead.js`): an `email:<address>/<id>` id as a search gives it,
|
|
3
|
+
* its parser, and the refusal text the email reader and Tex's readers share. Pure: no store, no network.
|
|
4
|
+
*
|
|
5
|
+
* Plain CommonJS. `REFUSED` reads `AI_ACCESS_STEP` from `googleAiAccess.cjs`, the sentence the Google readers share.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
const { AI_ACCESS_STEP } = require("./googleAiAccess.cjs");
|
|
9
|
+
|
|
10
|
+
const EMAIL_ID_PREFIX = "email:";
|
|
11
|
+
|
|
12
|
+
const ACCOUNT = /^[^\s@/]{1,64}@[^\s@/]{1,190}$/;
|
|
13
|
+
const MESSAGE_ID = /^[A-Za-z0-9_-]{1,64}$/;
|
|
14
|
+
|
|
15
|
+
const REFUSED = {
|
|
16
|
+
invalid: "That is not a search or an email this can read.",
|
|
17
|
+
not_allowed: "This connection cannot read the person's email: only their own personal workspace's mail, with private access.",
|
|
18
|
+
no_mailbox: "The person has no Gmail connected. They can connect one with manage connect_google.",
|
|
19
|
+
rate_limited: "Too many email reads this hour. Try again later, or look in their synced mail notes by date.",
|
|
20
|
+
reconnect_required: "Their Gmail sign-in stopped working, so it cannot be read and its mail has stopped syncing. They need to reconnect it with manage connect_google.",
|
|
21
|
+
ai_access_needed: `AI access isn't allowed yet for their Gmail, so it can't be read. ${AI_ACCESS_STEP}`,
|
|
22
|
+
not_found: "Gmail no longer has that email, or that attachment.",
|
|
23
|
+
too_large: "That attachment is over the 10 MB a file is read at.",
|
|
24
|
+
unavailable: "Gmail did not answer just now.",
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
/** `email:<address>/<id>`, or null. */
|
|
28
|
+
function parseEmailId(id) {
|
|
29
|
+
if (typeof id !== "string" || !id.startsWith(EMAIL_ID_PREFIX)) return null;
|
|
30
|
+
const rest = id.slice(EMAIL_ID_PREFIX.length);
|
|
31
|
+
const slash = rest.lastIndexOf("/");
|
|
32
|
+
if (slash === -1) return null;
|
|
33
|
+
const address = rest.slice(0, slash).toLowerCase();
|
|
34
|
+
const messageId = rest.slice(slash + 1);
|
|
35
|
+
return ACCOUNT.test(address) && MESSAGE_ID.test(messageId) ? { address, messageId } : null;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
module.exports = { ACCOUNT, EMAIL_ID_PREFIX, parseEmailId, REFUSED };
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/** Types for `emailRead.cjs`; see that file for the rules and the reasons. */
|
|
2
|
+
export declare const ACCOUNT: RegExp;
|
|
3
|
+
export declare const EMAIL_ID_PREFIX: "email:";
|
|
4
|
+
export declare function parseEmailId(id: unknown): { address: string; messageId: string } | null;
|
|
5
|
+
export declare const REFUSED: Record<string, string>;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One chat event's words as a line, as every reader of a chat shows them: Tex's (`packages/tex/gateway/agent/logRender.js`
|
|
3
|
+
* `words`) and Context's door, which reads a chat's ledger for a turn's history (`turnWords.cjs` `chatTurnsIn`). Pure.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/*
|
|
7
|
+
One event is always one line: a line break or any other control character in
|
|
8
|
+
someone's words is shown as a visible mark, so a message can never forge a
|
|
9
|
+
line of its own ("\n[12:16 PM] You: I sent the email").
|
|
10
|
+
*/
|
|
11
|
+
const BREAKS = /[\u0000-\u001f\u007f-\u009f\u2028\u2029]+/g;
|
|
12
|
+
const oneLine = (text) => text.replace(BREAKS, " \u23ce ");
|
|
13
|
+
|
|
14
|
+
/** `text` (already one line) marked as the kind of event it came in: `event.kind` a picture, a file, a tapback... */
|
|
15
|
+
function eventLine(event, text) {
|
|
16
|
+
switch (event.kind) {
|
|
17
|
+
case "picture":
|
|
18
|
+
return text ? `(a picture) ${text}` : "(a picture)";
|
|
19
|
+
case "file":
|
|
20
|
+
if (event.heard === "voice") return text ? `(a voice message) ${text}` : "(a voice message)";
|
|
21
|
+
return text ? `(a file) ${text}` : "(a file)";
|
|
22
|
+
case "reaction":
|
|
23
|
+
return `(a tapback) ${text}`.trim();
|
|
24
|
+
case "ask_settled":
|
|
25
|
+
return text ? `(the ask was settled) ${text}` : "(the ask was settled)";
|
|
26
|
+
case "delivery":
|
|
27
|
+
return text ? `(delivery) ${text}` : "(delivery)";
|
|
28
|
+
default:
|
|
29
|
+
// A person's edit of an earlier text (`packages/tex/worker/editStep.ts`): its new words, marked by the Worker's field, never by them.
|
|
30
|
+
if (event.unsent === true) return "(unsent an earlier text)";
|
|
31
|
+
return event.edited === true ? `(edited an earlier text to) ${text}` : text;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
module.exports = { eventLine, oneLine };
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A file's words in parts, and which files are tables (`apps/mcp/src/tools/fileParts.js`): the part a reader hands back,
|
|
3
|
+
* where the next part starts, and the table rule. Pure: no I/O. The original module keeps the table facts.
|
|
4
|
+
*
|
|
5
|
+
* Plain CommonJS with no imports.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/** Most characters handed back in one part. */
|
|
9
|
+
const PART_CHARS = 100_000;
|
|
10
|
+
|
|
11
|
+
const TABLE_TYPES = new Set(["text/csv", "text/tab-separated-values"]);
|
|
12
|
+
const TABLE_NAME = /\.(?:csv|tsv)$/i;
|
|
13
|
+
|
|
14
|
+
/** Whether a file is a table whose facts are worked out here. */
|
|
15
|
+
function isTable(name, type) {
|
|
16
|
+
return TABLE_TYPES.has(String(type ?? "").split(";")[0].trim().toLowerCase()) || TABLE_NAME.test(String(name ?? ""));
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* One part of `text` from `from`: at most `PART_CHARS`, ending at a line break
|
|
21
|
+
* when there is one, so no row is cut in two. `{ part, from, to, total }`, or
|
|
22
|
+
* null when `from` is past the end.
|
|
23
|
+
*/
|
|
24
|
+
function partOf(text, from = 0) {
|
|
25
|
+
const total = text.length;
|
|
26
|
+
const start = Number.isInteger(from) && from > 0 ? from : 0;
|
|
27
|
+
if (start > 0 && start >= total) return null;
|
|
28
|
+
let to = Math.min(total, start + PART_CHARS);
|
|
29
|
+
if (to < total) {
|
|
30
|
+
const lineEnd = text.lastIndexOf("\n", to);
|
|
31
|
+
if (lineEnd > start) to = lineEnd + 1;
|
|
32
|
+
}
|
|
33
|
+
return { part: text.slice(start, to), from: start, to, total };
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** The lines that say which part this is and how to read the next one. */
|
|
37
|
+
function partLines(part, next) {
|
|
38
|
+
const lines = [`characters: ${part.from} to ${part.to} of ${part.total}`];
|
|
39
|
+
if (part.to < part.total) lines.push(`more: ${next(part.to)} reads the next part; read every part before you total anything`);
|
|
40
|
+
return lines;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
module.exports = { PART_CHARS, isTable, partLines, partOf };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/** Types for `fileParts.cjs`; see that file for the rules and the reasons. */
|
|
2
|
+
export declare const PART_CHARS: number;
|
|
3
|
+
export declare function isTable(name: unknown, type: unknown): boolean;
|
|
4
|
+
export interface FilePart { part: string; from: number; to: number; total: number }
|
|
5
|
+
export declare function partOf(text: string, from?: number): FilePart | null;
|
|
6
|
+
export declare function partLines(part: FilePart, next: (at: number) => string): string[];
|