@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,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The gateway's tool contract, shared with Tex: the tool names Tex's own code is keyed by, the id prefixes and folder
|
|
3
|
+
* name those tools use, the handle rule, the MCP result shapes and the v2 action lookup. Each piece moved here from the
|
|
4
|
+
* file that named it, byte for byte, so the gateway and Tex read the same rule; the original module re-exports it.
|
|
5
|
+
*
|
|
6
|
+
* Plain CommonJS with no imports, so the gateway and the texting Worker read the same names.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
const EMAIL_TOOL = "send_email";
|
|
10
|
+
|
|
11
|
+
const REPORT_TOOL = "report_problem";
|
|
12
|
+
|
|
13
|
+
const TEXTS_ID_PREFIX = "texts:";
|
|
14
|
+
|
|
15
|
+
/** A Google Chat space's id as search and fetch name it (`apps/mcp/src/tools/googleChatRead.js`). */
|
|
16
|
+
const GOOGLE_CHAT_ID_PREFIX = "chat:";
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Where a fact with no note goes: its own folder in the inbox, so memories do
|
|
20
|
+
* not mix with everything else waiting there (the owner, 2026-10-07). The name
|
|
21
|
+
* is ours, so the control plane lists it among the paths a share preview must
|
|
22
|
+
* not confirm (`PRODUCT_MANDATED_PATHS`).
|
|
23
|
+
*/
|
|
24
|
+
const MEMORY_FOLDER = "inbox/memories";
|
|
25
|
+
|
|
26
|
+
function toolText(text) {
|
|
27
|
+
return { content: [{ type: "text", text }] };
|
|
28
|
+
}
|
|
29
|
+
function toolError(text) {
|
|
30
|
+
return { content: [{ type: "text", text }], isError: true };
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** The action a call names, with `write`'s default. */
|
|
34
|
+
function actionOf(tool, args) {
|
|
35
|
+
if (tool === "write" && (args.action === undefined || args.action === null || args.action === "")) return "save";
|
|
36
|
+
return args.action;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** A handle as `functions/lib/names.ts` allows one. */
|
|
40
|
+
const HANDLE = /^[a-z0-9](?:[a-z0-9-]{0,63})$/;
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Whether words someone said yes or 👍 to were put to them by name (Tex names whom an offer or a group's ask is
|
|
44
|
+
* for), so a yes in a group counts as the yes to that preview only from the person it asks. The handle is read
|
|
45
|
+
* whole: "@jo" is not named by "@joan".
|
|
46
|
+
*/
|
|
47
|
+
function addressedTo(words, who) {
|
|
48
|
+
if (typeof words !== "string" || !HANDLE.test(who ?? "")) return false;
|
|
49
|
+
return new RegExp(`(?:^|[^a-z0-9-])@${who}(?![a-z0-9-])`, "i").test(words);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
module.exports = { EMAIL_TOOL, REPORT_TOOL, TEXTS_ID_PREFIX, GOOGLE_CHAT_ID_PREFIX, MEMORY_FOLDER, toolText, toolError, actionOf, HANDLE, addressedTo };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/** Types for `toolContract.cjs`; see that file for the rules and the reasons. */
|
|
2
|
+
export declare const EMAIL_TOOL: "send_email";
|
|
3
|
+
export declare const REPORT_TOOL: "report_problem";
|
|
4
|
+
export declare const TEXTS_ID_PREFIX: "texts:";
|
|
5
|
+
export declare const MEMORY_FOLDER: "inbox/memories";
|
|
6
|
+
export interface ToolText { content: { type: "text"; text: string }[] }
|
|
7
|
+
export interface ToolError extends ToolText { isError: true }
|
|
8
|
+
export declare function toolText(text: string): ToolText;
|
|
9
|
+
export declare function toolError(text: string): ToolError;
|
|
10
|
+
export declare function actionOf(tool: string, args: { action?: unknown }): unknown;
|
|
11
|
+
export declare const HANDLE: RegExp;
|
|
12
|
+
export declare function addressedTo(words: unknown, who: string | null | undefined): boolean;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* One shape of a listed set: `all` as it is, `v1` (the older names) or `v2` (the six). The gateway's own rule
|
|
4
|
+
* (`tools/advertised.js` `toolsOfShape` calls it with its live sets), so Tex reads the other shapes off one `all`.
|
|
5
|
+
*/
|
|
6
|
+
function toolsOfShapeBy({ unlisted, v2, v2Only }, all, shape = "v2") {
|
|
7
|
+
if (shape === "all") return all;
|
|
8
|
+
// Last, so that everything above still reasons about the whole surface: an unlisted tool is one the server stopped
|
|
9
|
+
// recommending, not one it stopped answering.
|
|
10
|
+
const listed = all.filter((tool) => !unlisted.has(tool.name));
|
|
11
|
+
return shape === "v1" ? listed.filter((tool) => !v2Only.has(tool.name)) : listed.filter((tool) => v2.has(tool.name));
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
module.exports = { toolsOfShapeBy };
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The forwarder that relays audio to the transcription service: meetings (`apps/mcp/src/ingestion/transcription.js`)
|
|
3
|
+
* and Tex's voice messages (`packages/tex/gateway/agent/texEntryPoint/readTheHistory.js`) use the same one.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The transcription service this deployment is configured with, or `null`.
|
|
8
|
+
*
|
|
9
|
+
* ## Two variables, or nothing at all
|
|
10
|
+
*
|
|
11
|
+
* `TRANSCRIBE_WORKER_URL` and `TRANSCRIBE_WORKER_SECRET`, both or neither. A
|
|
12
|
+
* URL with no secret would post somebody's meeting audio to an endpoint
|
|
13
|
+
* unauthenticated, which is worse than the refusal it replaces; a secret with
|
|
14
|
+
* no URL is a deployment that thinks it is configured and is not. Absent is a
|
|
15
|
+
* first-class state: the route answers 501 and every recorder degrades to typed
|
|
16
|
+
* notes, which is exactly what a self-hoster who has not set this up should get.
|
|
17
|
+
*
|
|
18
|
+
* The URL must be `https`. It is where audio goes.
|
|
19
|
+
*
|
|
20
|
+
* ## What crosses, and what deliberately does not
|
|
21
|
+
*
|
|
22
|
+
* The audio, its container, and how long it is. **Not** the session id, not the
|
|
23
|
+
* chunk id, not the workspace id and not the note it will become: a stateless
|
|
24
|
+
* transcriber that also knew where a chunk sat in a recording would be holding
|
|
25
|
+
* a fragment of somebody's meeting, and `infra/transcribe-worker` is built so
|
|
26
|
+
* that it cannot. The offsets and the ids are added back on this side, where
|
|
27
|
+
* they came from.
|
|
28
|
+
*
|
|
29
|
+
* `X-Caller-Hash` is the one identifier that travels, and it is an **HMAC of
|
|
30
|
+
* the workspace id under the shared secret** rather than the id. It exists so a
|
|
31
|
+
* surprising bill has an account behind it and so the service can bound one
|
|
32
|
+
* account's spend; it is not reversible by anyone who does not already hold the
|
|
33
|
+
* secret, and holding the secret is what being that service means. Same
|
|
34
|
+
* construction, for the same reason, as the control plane's `callerHash`.
|
|
35
|
+
*
|
|
36
|
+
* Nothing here logs the audio, its length, or the words that come back. A
|
|
37
|
+
* transcript is note content, and the standard is that logs never carry it.
|
|
38
|
+
*/
|
|
39
|
+
function transcriptionForwarder(env) {
|
|
40
|
+
const endpoint = typeof env?.TRANSCRIBE_WORKER_URL === "string" ? env.TRANSCRIBE_WORKER_URL.trim() : "";
|
|
41
|
+
const secret = typeof env?.TRANSCRIBE_WORKER_SECRET === "string" ? env.TRANSCRIBE_WORKER_SECRET.trim() : "";
|
|
42
|
+
if (!endpoint || !secret) return null;
|
|
43
|
+
let url;
|
|
44
|
+
try {
|
|
45
|
+
url = new URL(endpoint);
|
|
46
|
+
} catch {
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
if (url.protocol !== "https:") return null;
|
|
50
|
+
const target = new URL("transcribe", url.href.endsWith("/") ? url.href : `${url.href}/`).href;
|
|
51
|
+
|
|
52
|
+
return async ({ audioBase64, mimeType, durationMs, callerId }) => {
|
|
53
|
+
const response = await fetch(target, {
|
|
54
|
+
method: "POST",
|
|
55
|
+
headers: {
|
|
56
|
+
Authorization: `Bearer ${secret}`,
|
|
57
|
+
"Content-Type": "application/json",
|
|
58
|
+
"X-Caller-Hash": await callerHash(callerId, secret),
|
|
59
|
+
},
|
|
60
|
+
body: JSON.stringify({ audioBase64, mimeType, durationMs }),
|
|
61
|
+
});
|
|
62
|
+
if (!response.ok) {
|
|
63
|
+
// The status and nothing else. Never the body: it is the far end's prose
|
|
64
|
+
// about a request that carried audio.
|
|
65
|
+
console.warn(JSON.stringify({ event: "transcribe_upstream", status: response.status }));
|
|
66
|
+
throw new Error(`transcription answered ${response.status}`);
|
|
67
|
+
}
|
|
68
|
+
/*
|
|
69
|
+
The whole answer, not just its segments.
|
|
70
|
+
|
|
71
|
+
It used to be `payload?.segments`, which threw away the one field that
|
|
72
|
+
says why an answer is short: `refused` is how many segments the service
|
|
73
|
+
dropped because the engine's own evidence said they were not speech. An
|
|
74
|
+
empty transcript with `refused: 3` is a quiet room and one with
|
|
75
|
+
`refused: 0` is a broken engine, and a caller that cannot tell them apart
|
|
76
|
+
shows the wrong sentence for one of them. See
|
|
77
|
+
`infra/transcribe-worker/src/transcribe.ts`.
|
|
78
|
+
*/
|
|
79
|
+
return await response.json();
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Who is spending, opaquely.
|
|
85
|
+
*
|
|
86
|
+
* HMAC-SHA256 of the workspace id under the shared secret, hex. Not the id, and
|
|
87
|
+
* not a hash anybody without the secret can build a rainbow table for.
|
|
88
|
+
*/
|
|
89
|
+
async function callerHash(workspaceId, secret) {
|
|
90
|
+
const key = await crypto.subtle.importKey(
|
|
91
|
+
"raw",
|
|
92
|
+
new TextEncoder().encode(secret),
|
|
93
|
+
{ name: "HMAC", hash: "SHA-256" },
|
|
94
|
+
false,
|
|
95
|
+
["sign"]
|
|
96
|
+
);
|
|
97
|
+
const signature = await crypto.subtle.sign("HMAC", key, new TextEncoder().encode(String(workspaceId)));
|
|
98
|
+
return [...new Uint8Array(signature)].map((byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
module.exports = { transcriptionForwarder };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Which folder does each built-in job, as the tree's facts say (`factJobs`):
|
|
3
|
+
* moved verbatim from `apps/mcp/src/tree/facts.js`, which re-exports it. It
|
|
4
|
+
* asks only the store it is handed (`store.treeFacts`), so Tex reads it here.
|
|
5
|
+
*/
|
|
6
|
+
"use strict";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Which folder does each built-in job (`apps/convex/functions/lib/nodes/folderJobs.ts`),
|
|
10
|
+
* as far as this connection can see: `{jobs, roots}` in the shape
|
|
11
|
+
* `folderJobs` gives (`packages/shared/src/folderRoles.cjs`), or `null` when
|
|
12
|
+
* the facts cannot answer. A folder this connection cannot see is `null`.
|
|
13
|
+
*
|
|
14
|
+
* @param {object} store
|
|
15
|
+
* @returns {Promise<{ jobs: Record<string, string | null>, roots: string[] } | null>}
|
|
16
|
+
*/
|
|
17
|
+
async function factJobs(store) {
|
|
18
|
+
if (typeof store?.treeFacts !== "function") return null;
|
|
19
|
+
let answer;
|
|
20
|
+
try {
|
|
21
|
+
answer = await store.treeFacts({ ask: "jobs" });
|
|
22
|
+
} catch {
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
if (answer?.served !== true || !answer.jobs || typeof answer.jobs !== "object" || !Array.isArray(answer.roots)) return null;
|
|
26
|
+
const jobs = {};
|
|
27
|
+
for (const [job, path] of Object.entries(answer.jobs)) jobs[job] = typeof path === "string" && path !== "" ? path : null;
|
|
28
|
+
return { jobs, roots: answer.roots.filter((name) => typeof name === "string") };
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
module.exports = { factJobs };
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* THE SESSION A TEXTED TURN RUNS ON IN TEX'S OWN WORKER, AS CONTEXT RESOLVED IT
|
|
3
|
+
* (`docs/decisions/texting-assistant/tex-service.md`, "The main texted turn in Tex's Worker").
|
|
4
|
+
*
|
|
5
|
+
* In the gateway, `/agent` runs its turn on the session the request's token resolves to (`apps/mcp/src/session.js`
|
|
6
|
+
* `sessionFromPayload`) and a store the gateway laid its facts on (`http/requestStore.js`). When the turn runs in Tex's
|
|
7
|
+
* Worker, those facts come from Context and from nowhere else: Tex asks the door's `tex_session` action
|
|
8
|
+
* (`apps/mcp/src/tools/texSession.js`) with the person's own grant token, the door resolves that token exactly as
|
|
9
|
+
* `/mcp` does, and answers the session's own fields with `turnSessionFacts`. Tex rebuilds the session with
|
|
10
|
+
* `turnSessionOf`. Nothing the chat object or the turn's caller says is read for any of them, so the facts that widen
|
|
11
|
+
* (the contexts a session reaches, its roles and scopes, the grant's names, whether it is cleared for the person's
|
|
12
|
+
* texts) are always what Context resolved for that grant.
|
|
13
|
+
*
|
|
14
|
+
* Pure: one copy both sides read, never a token (the door leaves the token out; Tex puts its own back, unlisted).
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
/** The resolved session's own fields, as `sessionFromPayload` writes them. Anything else on a session is not answered. */
|
|
18
|
+
const SESSION_FIELDS = Object.freeze([
|
|
19
|
+
"grantId",
|
|
20
|
+
"workspaceId",
|
|
21
|
+
"workspaceSlug",
|
|
22
|
+
"workspaceKind",
|
|
23
|
+
"role",
|
|
24
|
+
"scope",
|
|
25
|
+
"actorUserId",
|
|
26
|
+
"actorClientId",
|
|
27
|
+
"actorClientName",
|
|
28
|
+
"scopes",
|
|
29
|
+
"grantedGroups",
|
|
30
|
+
"chatNames",
|
|
31
|
+
"grantScopes",
|
|
32
|
+
"workspaces",
|
|
33
|
+
"setupReach",
|
|
34
|
+
"texChatId",
|
|
35
|
+
"texTaggerId",
|
|
36
|
+
"helper",
|
|
37
|
+
"expiresAt",
|
|
38
|
+
"toolsListedAt",
|
|
39
|
+
"texterIdentity",
|
|
40
|
+
"flags",
|
|
41
|
+
]);
|
|
42
|
+
|
|
43
|
+
const isObject = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
|
|
44
|
+
const isText = (value) => typeof value === "string" && value !== "";
|
|
45
|
+
const isTexts = (value) => Array.isArray(value) && value.every((item) => typeof item === "string");
|
|
46
|
+
/** A copy that holds data only: what JSON carries, so nothing of a function or a class crosses. */
|
|
47
|
+
const plain = (value) => (value === undefined ? undefined : JSON.parse(JSON.stringify(value)));
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Context's side: the session's own fields and the store facts a turn reads (`searchSettings`, the deployment's search
|
|
51
|
+
* settings; `textsCleared`, whether the session may read the person's texts; `readsAsChat`, whether its grant reads
|
|
52
|
+
* only its chat's home, the privacy engine's own answer), as data. `grantedGroups` is a set on the
|
|
53
|
+
* session and a list here. The token is never answered: it is unlisted on the session and not one of the fields.
|
|
54
|
+
*/
|
|
55
|
+
function turnSessionFacts(session, { searchSettings = null, textsCleared = false, readsAsChat = false } = {}) {
|
|
56
|
+
const facts = {};
|
|
57
|
+
for (const name of SESSION_FIELDS) {
|
|
58
|
+
const value = session?.[name];
|
|
59
|
+
if (value === undefined) continue;
|
|
60
|
+
facts[name] = name === "grantedGroups" ? [...value] : plain(value);
|
|
61
|
+
}
|
|
62
|
+
return { session: facts, searchSettings: isObject(searchSettings) ? plain(searchSettings) : null, textsCleared: textsCleared === true, readsAsChat: readsAsChat === true };
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Tex's side: the session `facts` describe, with `token` (the grant token Tex already holds and asked with) put back as
|
|
67
|
+
* `accessToken` and `grantToken`, both unlisted as the gateway's session keeps its token, and Context's answers about
|
|
68
|
+
* it as `contextSays` (`readsAsChat`), which Tex reads instead of asking the privacy engine itself. Null for facts that
|
|
69
|
+
* are not the shape Context answers: a session is never pieced together from part of one.
|
|
70
|
+
*/
|
|
71
|
+
function turnSessionOf(facts, token) {
|
|
72
|
+
if (!isObject(facts) || !isObject(facts.session) || !isText(token)) return null;
|
|
73
|
+
const given = facts.session;
|
|
74
|
+
if (!isText(given.grantId) || !isText(given.workspaceId) || !isText(given.actorUserId) || !isText(given.actorClientId)) return null;
|
|
75
|
+
if (!isTexts(given.scopes) || !isTexts(given.grantedGroups ?? []) || !Array.isArray(given.workspaces) || !given.workspaces.every(isObject)) return null;
|
|
76
|
+
const session = {};
|
|
77
|
+
for (const name of SESSION_FIELDS) if (given[name] !== undefined) session[name] = given[name];
|
|
78
|
+
session.grantedGroups = new Set(given.grantedGroups ?? []);
|
|
79
|
+
Object.defineProperty(session, "accessToken", { value: token, enumerable: false, writable: false });
|
|
80
|
+
Object.defineProperty(session, "grantToken", { value: token, enumerable: false, writable: false });
|
|
81
|
+
session.contextSays = Object.freeze({ readsAsChat: facts.readsAsChat === true });
|
|
82
|
+
return {
|
|
83
|
+
session,
|
|
84
|
+
searchSettings: isObject(facts.searchSettings) ? facts.searchSettings : null,
|
|
85
|
+
textsCleared: facts.textsCleared === true,
|
|
86
|
+
readsAsChat: facts.readsAsChat === true,
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
module.exports = { SESSION_FIELDS, turnSessionFacts, turnSessionOf };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/** Types for `turnSession.cjs`; see that file. */
|
|
2
|
+
|
|
3
|
+
export interface TurnFacts {
|
|
4
|
+
session: Record<string, unknown>;
|
|
5
|
+
searchSettings: Record<string, unknown> | null;
|
|
6
|
+
textsCleared: boolean;
|
|
7
|
+
readsAsChat: boolean;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface TurnSession {
|
|
11
|
+
session: Record<string, unknown> & { workspaceId: string; actorClientId: string; grantedGroups: Set<string> };
|
|
12
|
+
searchSettings: Record<string, unknown> | null;
|
|
13
|
+
textsCleared: boolean;
|
|
14
|
+
readsAsChat: boolean;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export declare const SESSION_FIELDS: readonly string[];
|
|
18
|
+
export declare function turnSessionFacts(session: unknown, facts?: { searchSettings?: unknown; textsCleared?: boolean; readsAsChat?: boolean }): TurnFacts;
|
|
19
|
+
export declare function turnSessionOf(facts: unknown, token: unknown): TurnSession | null;
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The person's own words this turn, for the sharing judge (`privacy/judge.js`, through `tools/session.js`): what
|
|
3
|
+
* they sent, after the last thing they were told, so a bare "yeah do it" reads as the answer to the question it
|
|
4
|
+
* answers. A routine's words are its own note instead, never the last run's answer (`texEntryPoint.js`). Tex keeps
|
|
5
|
+
* the conversation (`agent/conversation.js`); the gateway only reads the words a turn hands it.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/** The most of the last answer the judge is shown: its end, where a question is. */
|
|
9
|
+
const MAX_ANSWER = 1_000;
|
|
10
|
+
|
|
11
|
+
const { eventLine, oneLine } = require("./eventWords.cjs");
|
|
12
|
+
|
|
13
|
+
function wordsOfTurn(history, question) {
|
|
14
|
+
const lastAnswer = [...history].reverse().find((turn) => turn.role === "assistant")?.text ?? "";
|
|
15
|
+
return `${lastAnswer ? `Assistant: ${lastAnswer.slice(-MAX_ANSWER)}\nPerson: ` : ""}${question}`;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** The most turns of the chat a door turn keeps, each side counted: the Mail checker's twelve (`agent/mailChecker.js`). */
|
|
19
|
+
const MAX_CHAT_TURNS = 12;
|
|
20
|
+
/** Each kept turn is cut to this, from its end. */
|
|
21
|
+
const MAX_TURN_CHARS = 2_000;
|
|
22
|
+
/** Events that are no text of anybody's (`agent/ledgerConversation.js` `SKIPPED_EVENTS`). */
|
|
23
|
+
const SKIPPED_EVENTS = new Set(["delivery", "ask_settled"]);
|
|
24
|
+
|
|
25
|
+
const said = (entry) => (typeof entry?.text === "string" ? entry.text.trim() : "");
|
|
26
|
+
/** A person's text as the conversation shows it (`eventWords.cjs`), labelled by its sender in a group. */
|
|
27
|
+
function personLine(entry, group) {
|
|
28
|
+
const shown = eventLine({ ...entry, kind: entry.event }, oneLine(typeof entry.text === "string" ? entry.text : "")).trim();
|
|
29
|
+
if (!group) return shown;
|
|
30
|
+
const name = typeof entry.from?.name === "string" ? entry.from.name.trim().replace(/^@*/, "") : "";
|
|
31
|
+
return `${name === "" ? "Someone" : `@${name}`}: ${shown}`;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* The chat's last turns before this one, `[{ role, text }]` oldest first, from its ledger's entries (any order), as
|
|
36
|
+
* the conversation rebuilt from that ledger shows them (`agent/ledgerConversation.js`): a run of the person's texts is
|
|
37
|
+
* one user turn; Tex's texts of one answered turn (a turn with a `reply` entry, not a note sent by itself) one
|
|
38
|
+
* assistant turn; a line the texting Worker sent with no model, or a note Tex texted, one too. The texts after the last
|
|
39
|
+
* thing the chat was told are this turn's own and are left off. Context reads it from the ledger it holds when the
|
|
40
|
+
* inbound handoff keeps a turn's words (`apps/mcp/src/tools/texTurnHistory.js`), so the door's judge and Mail checker
|
|
41
|
+
* read what the in-process turn's read, and never anything a call sends. `group` labels each text with its sender.
|
|
42
|
+
*/
|
|
43
|
+
function chatTurnsIn(entries, { group = false } = {}) {
|
|
44
|
+
const list = (Array.isArray(entries) ? entries : []).filter((entry) => entry !== null && typeof entry === "object").sort((a, b) => (a.seq ?? 0) - (b.seq ?? 0));
|
|
45
|
+
const replied = new Set(list.filter((entry) => entry.kind === "reply" && typeof entry.turn === "string").map((entry) => entry.turn));
|
|
46
|
+
const byItself = new Set(list.filter((entry) => entry.kind === "note" && typeof entry.turn === "string").map((entry) => entry.turn));
|
|
47
|
+
const turns = [];
|
|
48
|
+
// A run of their texts is one question.
|
|
49
|
+
const ask = (text) => {
|
|
50
|
+
if (text === "") return;
|
|
51
|
+
const last = turns.at(-1);
|
|
52
|
+
if (last?.role === "user") last.text = `${last.text}\n${text}`;
|
|
53
|
+
else turns.push({ role: "user", text });
|
|
54
|
+
};
|
|
55
|
+
let answering = null;
|
|
56
|
+
for (const entry of list) {
|
|
57
|
+
const from = entry.from?.kind;
|
|
58
|
+
if (entry.kind === "text" && from === "person" && !SKIPPED_EVENTS.has(entry.event)) {
|
|
59
|
+
answering = null;
|
|
60
|
+
ask(personLine(entry, group));
|
|
61
|
+
} else if (entry.kind === "text" && from === "tex" && entry.delivered !== false && said(entry) !== "") {
|
|
62
|
+
const turn = entry.turn;
|
|
63
|
+
if (typeof turn !== "string" || !replied.has(turn) || byItself.has(turn)) continue;
|
|
64
|
+
if (answering === turn) turns.at(-1).text = `${turns.at(-1).text}\n${said(entry)}`;
|
|
65
|
+
else {
|
|
66
|
+
turns.push({ role: "assistant", text: said(entry) });
|
|
67
|
+
answering = turn;
|
|
68
|
+
}
|
|
69
|
+
} else if (entry.kind === "text" && from === "system" && entry.told === undefined && entry.delivered !== false && said(entry) !== "") {
|
|
70
|
+
answering = null;
|
|
71
|
+
turns.push({ role: "assistant", text: said(entry) });
|
|
72
|
+
} else if (entry.kind === "note" && entry.others !== true && entry.backfill === undefined && said(entry) !== "") {
|
|
73
|
+
answering = null;
|
|
74
|
+
turns.push({ role: "assistant", text: said(entry) });
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
while (turns.length > 0 && turns.at(-1).role === "user") turns.pop();
|
|
78
|
+
return turns.slice(-MAX_CHAT_TURNS).map((turn) => ({ role: turn.role, text: turn.text.slice(-MAX_TURN_CHARS) }));
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** A kept history read back strictly: `[{ role, text }]`, or [] for anything else. */
|
|
82
|
+
function keptTurns(value) {
|
|
83
|
+
if (!Array.isArray(value)) return [];
|
|
84
|
+
return value
|
|
85
|
+
.filter((turn) => turn !== null && typeof turn === "object" && (turn.role === "user" || turn.role === "assistant") && typeof turn.text === "string")
|
|
86
|
+
.slice(-MAX_CHAT_TURNS)
|
|
87
|
+
.map((turn) => ({ role: turn.role, text: turn.text.slice(-MAX_TURN_CHARS) }));
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
module.exports = { MAX_ANSWER, MAX_CHAT_TURNS, MAX_TURN_CHARS, chatTurnsIn, keptTurns, wordsOfTurn };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/** Types for `turnWords.cjs`; see that file. */
|
|
2
|
+
|
|
3
|
+
export type ChatTurn = { role: "user" | "assistant"; text: string };
|
|
4
|
+
export declare const MAX_ANSWER: number;
|
|
5
|
+
export declare const MAX_CHAT_TURNS: number;
|
|
6
|
+
export declare const MAX_TURN_CHARS: number;
|
|
7
|
+
export declare function wordsOfTurn(history: Array<{ role?: string; text?: string }>, question: string): string;
|
|
8
|
+
export declare function chatTurnsIn(entries: unknown, options?: { group?: boolean }): ChatTurn[];
|
|
9
|
+
export declare function keptTurns(value: unknown): ChatTurn[];
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A picture attached to a write: its ceilings, the name it is stored under, and
|
|
3
|
+
* whether it can be stored at all. Pure, and moved verbatim from
|
|
4
|
+
* `apps/mcp/src/notes/uploadedImages.js` (which re-exports it), so Tex names a
|
|
5
|
+
* texted picture and checks a found photo without reaching a gateway module.
|
|
6
|
+
*/
|
|
7
|
+
"use strict";
|
|
8
|
+
|
|
9
|
+
const { MAX_REMOTE_IMAGE_BYTES, sniffImageType } = require("../texShared/remoteImage.cjs");
|
|
10
|
+
|
|
11
|
+
/** At most this many images per write. A note is a document, not a bulk import. */
|
|
12
|
+
const MAX_IMAGES_PER_WRITE = 10;
|
|
13
|
+
|
|
14
|
+
/** The most one image may be: the app's paste ceiling and `read_image`'s inline one. */
|
|
15
|
+
const MAX_UPLOADED_IMAGE_BYTES = MAX_REMOTE_IMAGE_BYTES;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* The most one write may carry across all its images. A Worker holds the
|
|
19
|
+
* decoded bytes and the base64 they arrived as at the same time, so ten images
|
|
20
|
+
* at the per-image ceiling would be a request that runs out of memory rather
|
|
21
|
+
* than one that is refused in a sentence.
|
|
22
|
+
*/
|
|
23
|
+
const MAX_UPLOADED_BYTES_PER_WRITE = 15_000_000;
|
|
24
|
+
|
|
25
|
+
/** Base64 of the ceiling, with room for padding and stray whitespace. */
|
|
26
|
+
const MAX_BASE64_CHARS = Math.ceil(MAX_UPLOADED_IMAGE_BYTES / 3) * 4 + 1024;
|
|
27
|
+
|
|
28
|
+
/** A full SHA-256, lowercase hex: how an upload link names the bytes it takes. */
|
|
29
|
+
const SHA256_PATTERN = /^[a-f0-9]{64}$/;
|
|
30
|
+
|
|
31
|
+
/** Every extension the sniffer names, in the order a stored upload is looked for. */
|
|
32
|
+
const UPLOAD_EXTENSIONS = ["png", "jpg", "gif", "webp", "heic", "heif"];
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* The upload this note embeds under the same hash as `leaf` but another extension, or null.
|
|
37
|
+
*
|
|
38
|
+
* A picture is named for its bytes' hash before it is stored, and the store may then keep a compressed copy under the
|
|
39
|
+
* same hash with its own extension (`pictureCompression.js`, #2575): `upload-<hash>.jpg` is embedded as
|
|
40
|
+
* `upload-<hash>.webp`. A caller holding the first name (Tex's record of a texted picture, 2026-11-23: every texted
|
|
41
|
+
* picture since 2026-11-01 read back "not found") is answered from the second. Only a name this note itself embeds is
|
|
42
|
+
* answered, so this reaches nothing `noteReferencesImage` would not.
|
|
43
|
+
* @param {string} noteText the note's text
|
|
44
|
+
* @param {string} leaf the name asked for, `upload-<hex>.<ext>`
|
|
45
|
+
*/
|
|
46
|
+
function embeddedUploadLeaf(noteText, leaf) {
|
|
47
|
+
const stem = /^(upload-[0-9a-f]{16,64})\.[a-z0-9]+$/i.exec(String(leaf ?? ""))?.[1];
|
|
48
|
+
if (!stem || typeof noteText !== "string") return null;
|
|
49
|
+
return new RegExp(`(?<![0-9a-f])${stem}\\.(?:${UPLOAD_EXTENSIONS.join("|")}|jpeg)(?![A-Za-z0-9])`, "i").exec(noteText)?.[0] ?? null;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* The leaf a picture attached in the call itself is stored at, named from its
|
|
55
|
+
* own content: a repeat is one object. Sixteen hex characters, which is the
|
|
56
|
+
* name notes already written point at, so it does not change.
|
|
57
|
+
*
|
|
58
|
+
* Enough for dedupe, which is all it decides here: the bytes arrived in the
|
|
59
|
+
* call, so nothing is looked up by this name. An upload link is the other
|
|
60
|
+
* way round — there the name is the lookup — and uses the whole hash.
|
|
61
|
+
*/
|
|
62
|
+
function uploadLeaf(sha256, extension) {
|
|
63
|
+
return `upload-${sha256.slice(0, 16)}.${extension}`;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
async function sha256Hex(bytes) {
|
|
68
|
+
const digest = await crypto.subtle.digest("SHA-256", bytes);
|
|
69
|
+
return [...new Uint8Array(digest)].map((byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
/** The bytes of a base64 string or a `data:` URI, or null when it is not one or is past the ceiling. */
|
|
74
|
+
function decodeBase64(value) {
|
|
75
|
+
// A data: URI is what most clients have to hand; its header is not trusted,
|
|
76
|
+
// only stripped — the bytes decide the type below.
|
|
77
|
+
const comma = value.startsWith("data:") ? value.indexOf(",") : -1;
|
|
78
|
+
const raw = (comma === -1 ? value : value.slice(comma + 1)).replace(/\s+/g, "");
|
|
79
|
+
if (!raw || raw.length > MAX_BASE64_CHARS) return null;
|
|
80
|
+
if (!/^[A-Za-z0-9+/_-]*={0,2}$/.test(raw)) return null;
|
|
81
|
+
const standard = raw.replace(/-/g, "+").replace(/_/g, "/");
|
|
82
|
+
try {
|
|
83
|
+
const binary = atob(standard);
|
|
84
|
+
const bytes = new Uint8Array(binary.length);
|
|
85
|
+
for (let i = 0; i < binary.length; i += 1) bytes[i] = binary.charCodeAt(i);
|
|
86
|
+
return bytes;
|
|
87
|
+
} catch {
|
|
88
|
+
return null;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* The stored type of a base64 picture a write would accept, or null: what a
|
|
94
|
+
* caller attaching pictures it found itself checks first, so one it could
|
|
95
|
+
* never store (an AVIF, an SVG, an oversized photo) is left out rather than
|
|
96
|
+
* refusing the whole write (`agent/visuals/pagePhotos.js`). The same checks
|
|
97
|
+
* as `prepareNoteImages` below, which still decides.
|
|
98
|
+
*/
|
|
99
|
+
function storableImage(data) {
|
|
100
|
+
const bytes = typeof data === "string" ? decodeBase64(data) : null;
|
|
101
|
+
if (!bytes || bytes.byteLength === 0 || bytes.byteLength > MAX_UPLOADED_IMAGE_BYTES) return null;
|
|
102
|
+
const type = sniffImageType(bytes);
|
|
103
|
+
return type ? { contentType: type.contentType, bytes: bytes.byteLength } : null;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* The leaf `write_note` stores one picture's `data` under when the store keeps it as sent, and its size, or null:
|
|
108
|
+
* what Tex names a texted picture before it writes it (`agent/textedPictures.js`). The write still checks
|
|
109
|
+
* everything; a store that compresses names its copy under the same hash (`embeddedUploadLeaf`).
|
|
110
|
+
*/
|
|
111
|
+
async function sentPictureLeaf(data) {
|
|
112
|
+
const bytes = typeof data === "string" ? decodeBase64(data) : null;
|
|
113
|
+
if (!bytes || bytes.byteLength === 0 || bytes.byteLength > MAX_UPLOADED_IMAGE_BYTES) return null;
|
|
114
|
+
const type = sniffImageType(bytes);
|
|
115
|
+
if (!type) return null;
|
|
116
|
+
return { leaf: uploadLeaf(await sha256Hex(bytes), type.extension), bytes: bytes.byteLength };
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
module.exports = {
|
|
120
|
+
MAX_IMAGES_PER_WRITE,
|
|
121
|
+
MAX_UPLOADED_IMAGE_BYTES,
|
|
122
|
+
MAX_UPLOADED_BYTES_PER_WRITE,
|
|
123
|
+
SHA256_PATTERN,
|
|
124
|
+
UPLOAD_EXTENSIONS,
|
|
125
|
+
embeddedUploadLeaf,
|
|
126
|
+
uploadLeaf,
|
|
127
|
+
sha256Hex,
|
|
128
|
+
decodeBase64,
|
|
129
|
+
storableImage,
|
|
130
|
+
sentPictureLeaf,
|
|
131
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/** Types for `uploadImages.cjs`; see that file. */
|
|
2
|
+
|
|
3
|
+
export declare const MAX_IMAGES_PER_WRITE: number;
|
|
4
|
+
export declare const MAX_UPLOADED_IMAGE_BYTES: number;
|
|
5
|
+
export declare const MAX_UPLOADED_BYTES_PER_WRITE: number;
|
|
6
|
+
export declare const SHA256_PATTERN: RegExp;
|
|
7
|
+
export declare const UPLOAD_EXTENSIONS: string[];
|
|
8
|
+
export declare function embeddedUploadLeaf(noteText: string, leaf: string): string | null;
|
|
9
|
+
export declare function uploadLeaf(sha256: string, extension: string): string;
|
|
10
|
+
export declare function sha256Hex(bytes: BufferSource): Promise<string>;
|
|
11
|
+
export declare function decodeBase64(value: string): Uint8Array | null;
|
|
12
|
+
export declare function storableImage(data: unknown): { contentType: string; bytes: number } | null;
|
|
13
|
+
export declare function sentPictureLeaf(data: unknown): Promise<{ leaf: string; bytes: number } | null>;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Text written for the older tools, in the six tools' words. The gate's
|
|
4
|
+
* refusals and the write-surface section were written when `write_note`
|
|
5
|
+
* and `scope_info` were what every app held, and they stay that
|
|
6
|
+
* way for the texting assistant, which still is (`tools/advertised.js`). An app
|
|
7
|
+
* offered the six is told the same thing in calls it can make: a translated
|
|
8
|
+
* call's answer passes through `inV2Names`, and so does orient's access text.
|
|
9
|
+
* The reverse, for the assistant, is `orient/howToWork.js`'s `inToolNames`.
|
|
10
|
+
*/
|
|
11
|
+
const V2_NAMES = [
|
|
12
|
+
["Call scope_info for the authorized write surface.", 'Call orient with about: "access" for the authorized write surface.'],
|
|
13
|
+
["## Forms and links, on write_note", "## Forms and links, on write"],
|
|
14
|
+
[
|
|
15
|
+
"write_note's own description carries the block's grammar",
|
|
16
|
+
'orient about: "save" carries the block\'s grammar',
|
|
17
|
+
],
|
|
18
|
+
["on the same write_note call", "on the same write call"],
|
|
19
|
+
["write_note's share argument", "write's share argument"],
|
|
20
|
+
];
|
|
21
|
+
|
|
22
|
+
/** `text` with the older tools' names put as the six tools' calls. */
|
|
23
|
+
function inV2Names(text) {
|
|
24
|
+
return V2_NAMES.reduce((out, [from, to]) => out.split(from).join(to), text);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* A refusal in the six tools' words. Only a refusal: any other answer can
|
|
29
|
+
* carry a note's own text, which is the person's and is passed on as written.
|
|
30
|
+
*/
|
|
31
|
+
function resultInV2Names(result) {
|
|
32
|
+
if (result?.isError !== true || !Array.isArray(result.content)) return result;
|
|
33
|
+
const content = result.content.map((part) =>
|
|
34
|
+
part?.type === "text" && typeof part.text === "string"
|
|
35
|
+
? { ...part, text: inV2Names(part.text) }
|
|
36
|
+
: part,
|
|
37
|
+
);
|
|
38
|
+
return { ...result, content };
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
module.exports = { inV2Names, resultInV2Names };
|