@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.
Files changed (227) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +33 -2
  3. package/package.json +16 -4
  4. package/texContract/aboutLines.cjs +117 -0
  5. package/texContract/aboutLines.d.cts +14 -0
  6. package/texContract/aboutNoteLimits.cjs +41 -0
  7. package/texContract/aboutNoteLimits.d.cts +5 -0
  8. package/texContract/actionManual.cjs +104 -0
  9. package/texContract/activityHint.cjs +40 -0
  10. package/texContract/activityHint.d.cts +4 -0
  11. package/texContract/asks.cjs +16 -0
  12. package/texContract/asks.d.cts +6 -0
  13. package/texContract/asksToFile.cjs +20 -0
  14. package/texContract/asksToFile.d.cts +2 -0
  15. package/texContract/attention.cjs +138 -0
  16. package/texContract/attention.d.cts +20 -0
  17. package/texContract/browserHandback.cjs +13 -0
  18. package/texContract/browserHandback.d.cts +3 -0
  19. package/texContract/browserOwner.cjs +31 -0
  20. package/texContract/browserOwner.d.cts +2 -0
  21. package/texContract/bytes.cjs +12 -0
  22. package/texContract/capabilities.cjs +47 -0
  23. package/texContract/capabilities.d.cts +27 -0
  24. package/texContract/capabilities.generated.json +77 -0
  25. package/texContract/chatHistoryPath.cjs +38 -0
  26. package/texContract/chatHistoryPath.d.cts +5 -0
  27. package/texContract/chatLedger.cjs +91 -0
  28. package/texContract/chatLedger.d.cts +21 -0
  29. package/texContract/computerTool.cjs +102 -0
  30. package/texContract/computerTool.d.cts +16 -0
  31. package/texContract/consentYes.cjs +22 -0
  32. package/texContract/consentYes.d.cts +5 -0
  33. package/texContract/contextGateway.cjs +52 -0
  34. package/texContract/contextGateway.d.cts +19 -0
  35. package/texContract/deskEligible.cjs +20 -0
  36. package/texContract/deskEligible.d.cts +3 -0
  37. package/texContract/downloads.cjs +129 -0
  38. package/texContract/downloads.d.cts +15 -0
  39. package/texContract/egressLedger.cjs +114 -0
  40. package/texContract/egressLedger.d.cts +14 -0
  41. package/texContract/emailRead.cjs +38 -0
  42. package/texContract/emailRead.d.cts +5 -0
  43. package/texContract/eventWords.cjs +35 -0
  44. package/texContract/eventWords.d.cts +4 -0
  45. package/texContract/fileParts.cjs +43 -0
  46. package/texContract/fileParts.d.cts +6 -0
  47. package/texContract/fileTables.cjs +243 -0
  48. package/texContract/fileWords.cjs +169 -0
  49. package/texContract/folded.cjs +16 -0
  50. package/texContract/folded.d.cts +3 -0
  51. package/texContract/googleAiAccess.cjs +12 -0
  52. package/texContract/googleAiAccess.d.cts +2 -0
  53. package/texContract/graphWires.cjs +18 -0
  54. package/texContract/graphWires.d.cts +5 -0
  55. package/texContract/groupSession.cjs +28 -0
  56. package/texContract/groupSession.d.cts +7 -0
  57. package/texContract/guestNames.cjs +136 -0
  58. package/texContract/guestNames.d.cts +35 -0
  59. package/texContract/heard.cjs +19 -0
  60. package/texContract/heard.d.cts +4 -0
  61. package/texContract/heldOffer.cjs +57 -0
  62. package/texContract/heldOffer.d.cts +8 -0
  63. package/texContract/helperCallers.cjs +29 -0
  64. package/texContract/helperCallers.d.cts +4 -0
  65. package/texContract/identity.cjs +179 -0
  66. package/texContract/identity.d.cts +8 -0
  67. package/texContract/jobLogEntries.cjs +93 -0
  68. package/texContract/jobLogEntries.d.cts +12 -0
  69. package/texContract/judgedActions.cjs +20 -0
  70. package/texContract/judgedActions.d.cts +4 -0
  71. package/texContract/labSandboxGate.cjs +63 -0
  72. package/texContract/labSandboxGate.d.cts +9 -0
  73. package/texContract/ledgerReadChars.cjs +4 -0
  74. package/texContract/ledgerReadChars.d.cts +3 -0
  75. package/texContract/mailCheck.cjs +90 -0
  76. package/texContract/mailCheck.d.cts +12 -0
  77. package/texContract/mailEntries.cjs +64 -0
  78. package/texContract/mailEntries.d.cts +13 -0
  79. package/texContract/mailHealth.cjs +60 -0
  80. package/texContract/mailHealth.d.cts +10 -0
  81. package/texContract/notePath.cjs +99 -0
  82. package/texContract/notePath.d.cts +4 -0
  83. package/texContract/noteRunFacts.cjs +136 -0
  84. package/texContract/noteRunFacts.d.cts +32 -0
  85. package/texContract/objectEtag.cjs +84 -0
  86. package/texContract/objectEtag.d.cts +4 -0
  87. package/texContract/objectPlace.cjs +32 -0
  88. package/texContract/objectPlace.d.cts +5 -0
  89. package/texContract/pageJobs.cjs +226 -0
  90. package/texContract/pageJobs.d.cts +13 -0
  91. package/texContract/pdfLinks.cjs +135 -0
  92. package/texContract/pdfLinks.d.cts +4 -0
  93. package/texContract/personHub.cjs +38 -0
  94. package/texContract/personHub.d.cts +5 -0
  95. package/texContract/personNameText.cjs +18 -0
  96. package/texContract/personNameText.d.cts +3 -0
  97. package/texContract/pinnedContext.cjs +12 -0
  98. package/texContract/pinnedContext.d.cts +3 -0
  99. package/texContract/quietHoursWindow.cjs +36 -0
  100. package/texContract/quietHoursWindow.d.cts +3 -0
  101. package/texContract/reactEmoji.cjs +79 -0
  102. package/texContract/reactEmoji.d.cts +2 -0
  103. package/texContract/scopeClamp.cjs +117 -0
  104. package/texContract/scopeClamp.d.cts +5 -0
  105. package/texContract/scopes.cjs +29 -0
  106. package/texContract/scopes.d.cts +7 -0
  107. package/texContract/searchSettings.cjs +54 -0
  108. package/texContract/searchSettings.d.cts +6 -0
  109. package/texContract/settingHabits.cjs +87 -0
  110. package/texContract/settingHabits.d.cts +20 -0
  111. package/texContract/settingsNotes.cjs +217 -0
  112. package/texContract/settingsNotes.d.cts +26 -0
  113. package/texContract/shownEmail.cjs +181 -0
  114. package/texContract/texClients.cjs +53 -0
  115. package/texContract/texClients.d.cts +12 -0
  116. package/texContract/texGraph.cjs +593 -0
  117. package/texContract/texGraph.d.cts +55 -0
  118. package/texContract/texKeys.cjs +100 -0
  119. package/texContract/texKeys.d.cts +13 -0
  120. package/texContract/texNumber.cjs +20 -0
  121. package/texContract/texNumber.d.cts +3 -0
  122. package/texContract/texOwnSources.cjs +9 -0
  123. package/texContract/texOwnSources.d.cts +3 -0
  124. package/texContract/texSettings.cjs +22 -0
  125. package/texContract/texSettings.d.cts +20 -0
  126. package/texContract/texSettings.generated.json +25 -0
  127. package/texContract/texStateFiles.cjs +22 -0
  128. package/texContract/texStateFiles.d.cts +9 -0
  129. package/texContract/texSteps.cjs +27 -0
  130. package/texContract/texSteps.d.cts +14 -0
  131. package/texContract/texSteps.generated.json +41 -0
  132. package/texContract/texStoreNames.cjs +26 -0
  133. package/texContract/texStoreNames.d.cts +12 -0
  134. package/texContract/texStoreWire.cjs +306 -0
  135. package/texContract/texStoreWire.d.cts +32 -0
  136. package/texContract/threadsFold.cjs +75 -0
  137. package/texContract/threadsFold.d.cts +22 -0
  138. package/texContract/toolActions.cjs +253 -0
  139. package/texContract/toolCatalog.cjs +49 -0
  140. package/texContract/toolCatalog.generated.json +90 -0
  141. package/texContract/toolContract.cjs +52 -0
  142. package/texContract/toolContract.d.cts +12 -0
  143. package/texContract/toolShapes.cjs +14 -0
  144. package/texContract/transcription.cjs +101 -0
  145. package/texContract/transcription.d.cts +3 -0
  146. package/texContract/treeJobs.cjs +31 -0
  147. package/texContract/treeJobs.d.cts +3 -0
  148. package/texContract/turnSession.cjs +90 -0
  149. package/texContract/turnSession.d.cts +19 -0
  150. package/texContract/turnWords.cjs +90 -0
  151. package/texContract/turnWords.d.cts +9 -0
  152. package/texContract/uploadImages.cjs +131 -0
  153. package/texContract/uploadImages.d.cts +13 -0
  154. package/texContract/v2Names.cjs +41 -0
  155. package/texContract/v2SearchFetch.cjs +316 -0
  156. package/texContract/v2Translate.cjs +123 -0
  157. package/texContract/vaultTools.cjs +112 -0
  158. package/texContract/vaultTools.d.cts +15 -0
  159. package/texContract/yesWords.cjs +91 -0
  160. package/texShared/argumentCoercion.cjs +93 -0
  161. package/texShared/cellComments.cjs +122 -0
  162. package/texShared/cellComments.d.cts +21 -0
  163. package/texShared/comments.cjs +586 -0
  164. package/texShared/comments.d.cts +115 -0
  165. package/texShared/contentTypes.cjs +85 -0
  166. package/texShared/fileKinds.cjs +123 -0
  167. package/texShared/flags.cjs +159 -0
  168. package/texShared/flags.d.cts +23 -0
  169. package/texShared/folderJobInfo.cjs +301 -0
  170. package/texShared/folderJobInfo.d.cts +40 -0
  171. package/texShared/folderRoles.cjs +512 -0
  172. package/texShared/folderRoles.d.cts +73 -0
  173. package/texShared/githubOidc.ts +98 -0
  174. package/texShared/groupRunQuestions.cjs +98 -0
  175. package/texShared/groupRunQuestions.d.cts +4 -0
  176. package/texShared/inboxFolders.cjs +49 -0
  177. package/texShared/inboxFolders.d.cts +5 -0
  178. package/texShared/ink/drawing.cjs +474 -0
  179. package/texShared/ink/texFigure.cjs +252 -0
  180. package/texShared/ink/texFigure.d.cts +36 -0
  181. package/texShared/ink/texPoses.cjs +180 -0
  182. package/texShared/ink/texPoses.d.cts +20 -0
  183. package/texShared/jobPartEnd.cjs +133 -0
  184. package/texShared/jobPartEnd.d.cts +13 -0
  185. package/texShared/jobResume.cjs +31 -0
  186. package/texShared/jobResume.d.cts +5 -0
  187. package/texShared/jobSplit.cjs +90 -0
  188. package/texShared/jobSplit.d.cts +6 -0
  189. package/texShared/jobStart.cjs +56 -0
  190. package/texShared/jobStart.d.cts +9 -0
  191. package/texShared/mail.cjs +400 -0
  192. package/texShared/mail.d.cts +56 -0
  193. package/texShared/messageAnchors.cjs +38 -0
  194. package/texShared/models/aiKeys.cjs +137 -0
  195. package/texShared/models/aiKeys.d.cts +42 -0
  196. package/texShared/models/aiKeys.json +56 -0
  197. package/texShared/models/creditRest.cjs +269 -0
  198. package/texShared/models/promptBudget.cjs +295 -0
  199. package/texShared/models/promptSections.cjs +29 -0
  200. package/texShared/noteAppLink.cjs +23 -0
  201. package/texShared/notePreview.cjs +219 -0
  202. package/texShared/notePreview.d.cts +21 -0
  203. package/texShared/pages/blocks.cjs +215 -0
  204. package/texShared/pages/cover.cjs +164 -0
  205. package/texShared/pages/css.cjs +181 -0
  206. package/texShared/pages/cssBlocks.cjs +264 -0
  207. package/texShared/pages/draw.cjs +212 -0
  208. package/texShared/pages/drawRich.cjs +232 -0
  209. package/texShared/pages/html.cjs +168 -0
  210. package/texShared/pages/inline.cjs +251 -0
  211. package/texShared/pages/layout.cjs +76 -0
  212. package/texShared/pages/parse.cjs +418 -0
  213. package/texShared/pages/render.cjs +200 -0
  214. package/texShared/pages/skill.cjs +147 -0
  215. package/texShared/pages/skill.d.cts +5 -0
  216. package/texShared/pages/templates.cjs +336 -0
  217. package/texShared/r2Store.cjs +163 -0
  218. package/texShared/remoteImage.cjs +177 -0
  219. package/texShared/routines.cjs +656 -0
  220. package/texShared/routines.d.cts +86 -0
  221. package/texShared/servedListing.cjs +250 -0
  222. package/texShared/servedListing.d.cts +17 -0
  223. package/texShared/sheetCsv.cjs +566 -0
  224. package/texShared/sheetCsv.d.cts +91 -0
  225. package/texShared/storageLayout.cjs +88 -0
  226. package/texShared/storeKeys.cjs +144 -0
  227. package/texShared/toolArguments.cjs +323 -0
@@ -0,0 +1,5 @@
1
+ /** Types for `objectPlace.cjs`; see that file. */
2
+
3
+ export declare const OBJECT_LOCATION: "enam";
4
+ export declare function objectByName(namespace: any, name: string): any;
5
+ export declare function objectIdOf(namespace: any, name: string): string;
@@ -0,0 +1,226 @@
1
+ /**
2
+ * A chat's background jobs, for its Tex page: read from the chat's inbox in
3
+ * the texting Worker over the `TEXTING` binding (`TexRoutines.pageJobs`,
4
+ * `packages/tex/worker/texPage.ts`), and shaped as the page shows them. Used by the
5
+ * page's routes and by the chat's Tex object while a page is open
6
+ * (`texStore/pageLive.js`), so both say the same thing.
7
+ *
8
+ * Every word is Tex's own (a job's title, its status line, its steps: tool and
9
+ * target, never a note's text).
10
+ */
11
+
12
+ /** How many jobs run at once (`MAX_RUNNING_JOBS`, `packages/tex/worker/jobs.ts`): the page's minion slots. */
13
+ const SLOTS = 3;
14
+ /** The finished jobs the overview shows under "Earlier today". */
15
+ const EARLIER_SHOWN = 2;
16
+ const WEEK_MS = 7 * 24 * 60 * 60 * 1000;
17
+ const MAX_WORDS = 300;
18
+ const MAX_STEPS = 40;
19
+
20
+ const words = (value, max = MAX_WORDS) => (typeof value === "string" ? value.replace(/\s+/g, " ").trim().slice(0, max) : "");
21
+ const instant = (value) => (typeof value === "number" && Number.isFinite(value) && value > 0 ? value : null);
22
+
23
+ /** The page's state words for the inbox's: a stuck job is shown as failed. */
24
+ function stateOf(job) {
25
+ if (job.stopped === true) return "stopped";
26
+ switch (job.state) {
27
+ case "running":
28
+ case "waiting":
29
+ case "done":
30
+ case "failed":
31
+ return job.state;
32
+ case "stuck":
33
+ return "failed";
34
+ default:
35
+ return null;
36
+ }
37
+ }
38
+
39
+ function stepsOf(job) {
40
+ return (Array.isArray(job.steps) ? job.steps : [])
41
+ .flatMap((step) => {
42
+ const at = instant(step?.at);
43
+ const text = words(step?.text);
44
+ if (at === null || !text) return [];
45
+ const failed = step.failed === true;
46
+ const why = failed ? words(step.why, 160) : "";
47
+ return [{ at, text, ...(failed ? { failed: true } : {}), ...(why ? { why } : {}) }];
48
+ })
49
+ .slice(-MAX_STEPS);
50
+ }
51
+
52
+ /** One job as the texting Worker answered it, checked field by field; null when it is not one. */
53
+ function readJob(raw) {
54
+ if (raw === null || typeof raw !== "object" || typeof raw.id !== "string" || !/^[A-Za-z0-9_-]{1,80}$/.test(raw.id)) return null;
55
+ const title = words(raw.title, 160);
56
+ const startedAt = instant(raw.startedAt);
57
+ const state = stateOf(raw);
58
+ if (!title || startedAt === null || state === null) return null;
59
+ const endedAt = instant(raw.finishedAt);
60
+ const status = words(raw.status, 200);
61
+ const who = words(raw.for, 40);
62
+ const result = words(raw.result, 1500);
63
+ const on = machineOf(raw.on);
64
+ return { id: raw.id, title, state, startedAt, ...(endedAt !== null ? { endedAt } : {}), ...(status ? { status } : {}), ...(who ? { for: who } : {}), ...(result ? { result } : {}), ...(on ? { on } : {}), steps: stepsOf(raw) };
65
+ }
66
+
67
+ const TOOL_NAMES = { claude: "Claude Code", codex: "Codex" };
68
+
69
+ /** The person's computer a job runs on, as the inbox names it (`{id, name, tool?}`); null in Tex's cloud. */
70
+ function machineOf(raw) {
71
+ if (raw === null || typeof raw !== "object" || typeof raw.id !== "string" || !/^[A-Za-z0-9_-]{1,80}$/.test(raw.id)) return null;
72
+ const name = words(raw.name, 100) || "your computer";
73
+ return { id: raw.id, name, ...(TOOL_NAMES[raw.tool] ? { tool: TOOL_NAMES[raw.tool] } : {}) };
74
+ }
75
+
76
+ /** The page's `JobSummary` for a read job (`slot` when it holds one). */
77
+ function jobSummary(job, slot = null) {
78
+ const failedSteps = job.steps.filter((step) => step.failed).length;
79
+ const last = job.steps[job.steps.length - 1];
80
+ return {
81
+ id: job.id,
82
+ title: job.title,
83
+ state: job.state,
84
+ startedAt: job.startedAt,
85
+ ...(job.endedAt !== undefined ? { endedAt: job.endedAt } : {}),
86
+ failedSteps,
87
+ ...(job.state === "waiting" && job.status ? { needs: job.status } : {}),
88
+ ...(job.state === "running" && last ? { now: last.text } : {}),
89
+ ...(job.for ? { for: job.for } : {}),
90
+ // Where it runs: the page's place key for the computer, and its name in words (`On Cloud VM`).
91
+ ...(job.on ? { machine: job.on.id, machineName: job.on.name, ranOn: `On ${job.on.name}`, ...(job.on.tool ? { tool: job.on.tool } : {}) } : {}),
92
+ ...(slot !== null ? { slot } : {}),
93
+ };
94
+ }
95
+
96
+ /** The job page: the summary, every step, and what it came back with. */
97
+ function jobDetail(job, slot = null) {
98
+ return { ...jobSummary(job, slot), steps: job.steps, ...(job.result ? { result: { summary: job.result } } : {}) };
99
+ }
100
+
101
+ const live = (job) => job.state === "running" || job.state === "waiting";
102
+
103
+ /** Machine jobs a computer's slots are numbered for at most (its owner sets up to eight). */
104
+ const MACHINE_SLOTS = 8;
105
+
106
+ /**
107
+ * Which slot each live job holds, numbered from 1 in the place it runs: Tex's
108
+ * cloud's three, or each computer's own (a job on a computer never takes a
109
+ * cloud slot: `packages/tex/worker/jobs.ts`), numbered oldest first, as they were
110
+ * started. When a place has more live jobs than slots, running ones get them
111
+ * before ones waiting on the person: Tex counts only running jobs against its
112
+ * limit (`fits`), so a waiting one must never hide a job that is running.
113
+ */
114
+ function slotsOf(jobs) {
115
+ const room = (place) => (place === null ? SLOTS : MACHINE_SLOTS);
116
+ const byStart = (a, b) => a.startedAt - b.startedAt;
117
+ const taken = new Map();
118
+ const chosen = [];
119
+ for (const job of [...jobs.filter((job) => job.state === "running").sort(byStart), ...jobs.filter((job) => job.state === "waiting").sort(byStart)]) {
120
+ const place = job.on?.id ?? null;
121
+ if ((taken.get(place) ?? 0) >= room(place)) continue;
122
+ taken.set(place, (taken.get(place) ?? 0) + 1);
123
+ chosen.push(job);
124
+ }
125
+ const held = new Map();
126
+ const numbered = new Map();
127
+ for (const job of chosen.sort(byStart)) {
128
+ const place = job.on?.id ?? null;
129
+ const next = (numbered.get(place) ?? 0) + 1;
130
+ numbered.set(place, next);
131
+ held.set(job.id, next);
132
+ }
133
+ return held;
134
+ }
135
+
136
+ /** `YYYY-MM-DD` in the zone, or in UTC when the zone is not one. */
137
+ function dayOf(ms, timeZone) {
138
+ try {
139
+ return new Intl.DateTimeFormat("en-CA", { timeZone: timeZone || "UTC", year: "numeric", month: "2-digit", day: "2-digit" }).format(ms);
140
+ } catch {
141
+ return new Date(ms).toISOString().slice(0, 10);
142
+ }
143
+ }
144
+
145
+ /**
146
+ * The overview's job parts: `status` (live jobs, and how many need the
147
+ * person, with `waitingMail` emails waiting for their yes), the three cloud
148
+ * `minions` and each computer's busy ones, `earlier` (the latest jobs finished today) and `earlierWeek`.
149
+ */
150
+ function jobsOverview(jobs, now, { timeZone = null, waitingMail = 0 } = {}) {
151
+ const slots = slotsOf(jobs);
152
+ const cloud = new Map(jobs.filter((job) => !job.on && slots.has(job.id)).map((job) => [slots.get(job.id), job]));
153
+ const minions = [];
154
+ for (let slot = 1; slot <= SLOTS; slot += 1) {
155
+ const job = cloud.get(slot);
156
+ minions.push({ slot, job: job ? jobSummary(job, slot) : null });
157
+ }
158
+ // A computer's busy slots follow, each with its place (the computer's id); the page draws its free ones from the computer's own count.
159
+ for (const job of jobs.filter((candidate) => candidate.on && slots.has(candidate.id))) {
160
+ minions.push({ slot: slots.get(job.id), place: job.on.id, job: jobSummary(job, slots.get(job.id)) });
161
+ }
162
+ const today = dayOf(now, timeZone);
163
+ const ended = jobs
164
+ .filter((job) => !live(job) && now - (job.endedAt ?? job.startedAt) < WEEK_MS)
165
+ .sort((a, b) => (b.endedAt ?? b.startedAt) - (a.endedAt ?? a.startedAt));
166
+ const endedToday = ended.filter((job) => dayOf(job.endedAt ?? job.startedAt, timeZone) === today);
167
+ const waiting = jobs.filter((job) => job.state === "waiting").length;
168
+ return {
169
+ status: { jobs: slots.size, needsYou: waiting + Math.max(0, waitingMail) },
170
+ minions,
171
+ earlier: endedToday.slice(0, EARLIER_SHOWN).map((job) => jobSummary(job)),
172
+ earlierWeek: ended.length,
173
+ };
174
+ }
175
+
176
+ /**
177
+ * The chat's jobs from the texting Worker: `chat` is `{phone}` or `{groupKey}`,
178
+ * and for a group the people hash its browser is tagged by (`people`).
179
+ * `{now, jobs: []}` when there is no binding, no phone, or the Worker fails:
180
+ * the page then shows free slots, never an error.
181
+ */
182
+ async function fetchPageJobs(env, chat, now = Date.now()) {
183
+ const texting = env?.TEXTING;
184
+ if (!texting || typeof texting.pageJobs !== "function" || chat === null) return { now, jobs: [] };
185
+ try {
186
+ const answer = await texting.pageJobs({ chat });
187
+ const jobs = (Array.isArray(answer?.jobs) ? answer.jobs : []).map(readJob).filter((job) => job !== null);
188
+ // A group's people hash, which its browser is tagged by (`texPage/browser.js`).
189
+ const people = typeof answer?.people === "string" && /^[0-9a-f]{64}$/.test(answer.people) ? answer.people : null;
190
+ return { now: instant(answer?.now) ?? now, jobs, ...(people !== null ? { people } : {}) };
191
+ } catch {
192
+ return { now, jobs: [] };
193
+ }
194
+ }
195
+
196
+ /** Asks the chat's inbox to steer or stop one of its own jobs; true when it took it. */
197
+ async function steerPageJob(env, chat, { id, text, stop = false }) {
198
+ const texting = env?.TEXTING;
199
+ if (!texting || typeof texting.pageSteer !== "function" || chat === null) return false;
200
+ try {
201
+ const answer = await texting.pageSteer({ chat, id, ...(typeof text === "string" ? { text } : {}), ...(stop ? { stop: true } : {}) });
202
+ return answer?.taken === true;
203
+ } catch {
204
+ return false;
205
+ }
206
+ }
207
+
208
+ /**
209
+ * Answers the person's waiting ask in their own chat, yes or no, as the ask card's own Yes or Not now would
210
+ * (`TexRoutines.pageAnswer`). `{ ok: false, error }` names why not: `no_ask` (nothing waiting), `stale` (a newer ask
211
+ * replaced it), `full`, or `unavailable` when the texting Worker could not be reached.
212
+ */
213
+ async function answerPageAsk(env, chat, ask, yes) {
214
+ const texting = env?.TEXTING;
215
+ if (!texting || typeof texting.pageAnswer !== "function") return { ok: false, error: "unavailable" };
216
+ try {
217
+ const answer = await texting.pageAnswer({ chat, ask, yes });
218
+ if (answer?.taken === true) return { ok: true };
219
+ const why = answer?.why;
220
+ return { ok: false, error: why === "no_ask" || why === "stale" || why === "full" ? why : "unavailable" };
221
+ } catch {
222
+ return { ok: false, error: "unavailable" };
223
+ }
224
+ }
225
+
226
+ module.exports = { SLOTS, EARLIER_SHOWN, readJob, jobSummary, jobDetail, slotsOf, dayOf, jobsOverview, fetchPageJobs, steerPageJob, answerPageAsk };
@@ -0,0 +1,13 @@
1
+ /** Types for `pageJobs.cjs`; see that file. */
2
+
3
+ export declare const SLOTS: number;
4
+ export declare const EARLIER_SHOWN: number;
5
+ export declare function readJob(raw: unknown): any;
6
+ export declare function jobSummary(job: any, slot?: number | null): any;
7
+ export declare function jobDetail(job: any, slot?: number | null): any;
8
+ export declare function slotsOf(jobs: any[]): Map<string, number>;
9
+ export declare function dayOf(ms: number, timeZone?: string | null): string;
10
+ export declare function jobsOverview(jobs: any[], now: number, options?: { timeZone?: string | null; waitingMail?: number }): any;
11
+ export declare function fetchPageJobs(env: unknown, chat: unknown, now?: number): Promise<{ now: number; jobs: any[]; people?: string }>;
12
+ export declare function steerPageJob(env: unknown, chat: unknown, steer: { id: string; text?: string; stop?: boolean }): Promise<boolean>;
13
+ export declare function answerPageAsk(env: unknown, chat: unknown, ask: unknown, yes: boolean): Promise<{ ok: boolean; error?: string }>;
@@ -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,4 @@
1
+ /** Types for `pdfLinks.cjs`; see that file for the rules and the reasons. */
2
+ export declare const MAX_LINKS: number;
3
+ export declare const MAX_INFLATED_BYTES: number;
4
+ export declare function pdfLinks(bytes: Uint8Array): Promise<string[]>;
@@ -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,3 @@
1
+ /** Types for `personNameText.cjs`; see that file. */
2
+
3
+ export declare function cleanName(name: unknown): string;
@@ -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,3 @@
1
+ /** Types for `pinnedContext.cjs`; see that file. */
2
+
3
+ export declare const PINNED_CONTEXT_NAME: "@context-lc";
@@ -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,3 @@
1
+ /** Types for `quietHoursWindow.cjs`; see that file. */
2
+
3
+ export declare function readQuietHours(value: unknown): { from: number; until: number } | null;
@@ -0,0 +1,79 @@
1
+ /**
2
+ * The 64 emoji Tex may react with, by the short name its judge picks (Dev2, 2026-10-27: a curated set, since one typed
3
+ * question offers at most 64 options). Never ✅ and never a gendered person. Context's control plane keeps them as an
4
+ * allowlist (`apps/convex/functions/lib/reactEmoji.ts`); Tex's own copy, with when each fits, is
5
+ * `packages/tex/src/textDecide.cjs` in Supa-Media/tex, and a test on each side pins the list.
6
+ */
7
+ "use strict";
8
+
9
+ const EMOJI = {
10
+ heart: "❤️",
11
+ thumbs_up: "👍",
12
+ thumbs_down: "👎",
13
+ laugh: "😂",
14
+ rofl: "🤣",
15
+ smile: "😊",
16
+ grin: "😁",
17
+ wink: "😉",
18
+ heart_eyes: "😍",
19
+ hug: "🤗",
20
+ thinking: "🤔",
21
+ eyes: "👀",
22
+ wow: "😮",
23
+ mind_blown: "🤯",
24
+ sad: "😢",
25
+ pensive: "😔",
26
+ frown: "☹️",
27
+ grimace: "😬",
28
+ sweat_smile: "😅",
29
+ facepalm: "🤦",
30
+ shrug: "🤷",
31
+ pray: "🙏",
32
+ clap: "👏",
33
+ raised_hands: "🙌",
34
+ muscle: "💪",
35
+ ok_hand: "👌",
36
+ wave: "👋",
37
+ salute: "🫡",
38
+ handshake: "🤝",
39
+ crossed_fingers: "🤞",
40
+ party: "🎉",
41
+ confetti: "🥳",
42
+ fire: "🔥",
43
+ star: "⭐",
44
+ sparkles: "✨",
45
+ hundred: "💯",
46
+ rocket: "🚀",
47
+ trophy: "🏆",
48
+ bulb: "💡",
49
+ exclamation: "‼️",
50
+ question: "❓",
51
+ check_later: "⏳",
52
+ calendar: "📅",
53
+ clock: "⏰",
54
+ memo: "📝",
55
+ books: "📚",
56
+ laptop: "💻",
57
+ phone: "📱",
58
+ mail: "📧",
59
+ money: "💰",
60
+ chart: "📈",
61
+ house: "🏠",
62
+ plane: "✈️",
63
+ car: "🚗",
64
+ coffee: "☕",
65
+ food: "🍕",
66
+ cheers: "🥂",
67
+ cake: "🎂",
68
+ gift: "🎁",
69
+ music: "🎵",
70
+ sun: "☀️",
71
+ moon: "🌙",
72
+ zipped: "🤐",
73
+ plant: "🌱",
74
+ };
75
+
76
+ /** Name to `{ emoji }`, the shape Tex's own list has. */
77
+ const REACT_EMOJI = Object.freeze(Object.fromEntries(Object.entries(EMOJI).map(([name, emoji]) => [name, Object.freeze({ emoji })])));
78
+
79
+ module.exports = { REACT_EMOJI };
@@ -0,0 +1,2 @@
1
+ /** Types for `reactEmoji.cjs`; see that file. */
2
+ export declare const REACT_EMOJI: Readonly<Record<string, { readonly emoji: string }>>;