@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,316 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `search` and `fetch`, translated into the one existing call each stands for.
|
|
3
|
+
*
|
|
4
|
+
* `v2Translate.cjs` calls these with the top-level arguments of the v2 call:
|
|
5
|
+
* `query` or `id`, the open `args` object, and `context` / `mailbox`. Those
|
|
6
|
+
* two address the call and `v2Translate.cjs` carries them; nothing returned here
|
|
7
|
+
* contains them. Routing (`@name/path` sugar, `addressByPath`) is left to the
|
|
8
|
+
* existing tool path, so a path that opens with a workspace name goes through
|
|
9
|
+
* unchanged.
|
|
10
|
+
*
|
|
11
|
+
* ChatGPT's deep-research connector sends `search` and `fetch` with no `args`
|
|
12
|
+
* and expects the JSON answers of `toolOpenAiSearch` / `toolOpenAiFetch`, so
|
|
13
|
+
* that shape is kept for it. With `args` given, ChatGPT gets the same
|
|
14
|
+
* translation as everybody else.
|
|
15
|
+
*
|
|
16
|
+
* Moved from `apps/mcp/src/tools/v2/searchFetch.js`, which re-exports it, so Tex translates the six's calls with the
|
|
17
|
+
* same code the gateway does.
|
|
18
|
+
*/
|
|
19
|
+
"use strict";
|
|
20
|
+
|
|
21
|
+
const { splitMessageAnchor } = require("../texShared/messageAnchors.cjs");
|
|
22
|
+
const { EMAIL_ID_PREFIX } = require("./emailRead.cjs");
|
|
23
|
+
const { GOOGLE_CHAT_ID_PREFIX, TEXTS_ID_PREFIX } = require("./toolContract.cjs");
|
|
24
|
+
const { readableFileType } = require("./fileWords.cjs");
|
|
25
|
+
const { isSheetPath } = require("../texShared/sheetCsv.cjs");
|
|
26
|
+
|
|
27
|
+
const CHATGPT = /chatgpt|openai/i;
|
|
28
|
+
|
|
29
|
+
/** Longest caller text echoed back in a refusal. */
|
|
30
|
+
const ECHO_CAP = 40;
|
|
31
|
+
|
|
32
|
+
/** Named on the call, never inside `args`: routing reads only the top level. */
|
|
33
|
+
const ADDRESSING = ["context", "mailbox", "person_said"];
|
|
34
|
+
|
|
35
|
+
function isChatGpt(app) {
|
|
36
|
+
return typeof app?.client === "string" && CHATGPT.test(app.client);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function echo(text) {
|
|
40
|
+
return text.length > ECHO_CAP ? `${text.slice(0, ECHO_CAP)}…` : text;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* The open `args` as the caller sent them, with undefined values dropped.
|
|
45
|
+
* `args` undefined (or null) means none was given; anything that is not a
|
|
46
|
+
* plain object is refused.
|
|
47
|
+
*
|
|
48
|
+
* @returns {{args: object | undefined} | {error: string}}
|
|
49
|
+
*/
|
|
50
|
+
function openArgs(call) {
|
|
51
|
+
let raw = call.args;
|
|
52
|
+
if (raw === undefined || raw === null) return { args: undefined };
|
|
53
|
+
if (typeof raw !== "object" || Array.isArray(raw)) {
|
|
54
|
+
return { error: "args has to be an object of named options: call it again with args like { limit: 5 }, or without args." };
|
|
55
|
+
}
|
|
56
|
+
// An email search's address written as mailbox, a note-mail id everywhere else, was meant as the account
|
|
57
|
+
// (2026-11-14: Tex was refused here, moved it to the top, and the search ran over every mailbox; `emailRead.js`).
|
|
58
|
+
if (raw.email === true && raw.account === undefined && typeof raw.mailbox === "string" && raw.mailbox.includes("@")) {
|
|
59
|
+
const { mailbox, ...rest } = raw;
|
|
60
|
+
return openArgs({ args: { ...rest, account: mailbox } });
|
|
61
|
+
}
|
|
62
|
+
// A field left empty, as a client that fills every field it is shown sends one (`""`, `null`, `false` for a flag): not given.
|
|
63
|
+
raw = Object.fromEntries(Object.entries(raw).filter(([key, value]) => !leftEmpty(key, value)));
|
|
64
|
+
for (const key of ADDRESSING) {
|
|
65
|
+
if (Object.hasOwn(raw, key)) {
|
|
66
|
+
return { error: `${key} goes beside args, at the top of the call, not inside it: call it again with ${key} moved out of args.` };
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return { args: Object.fromEntries(Object.entries(raw).filter(([, value]) => value !== undefined)) };
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Keys whose `false` still picks what is read: a meeting without its transcript, a day without its messages, a
|
|
74
|
+
* contact without its activity (`translateFetch`).
|
|
75
|
+
*/
|
|
76
|
+
const FALSE_STILL_CHOOSES = new Set(["transcript", "messages", "activity"]);
|
|
77
|
+
|
|
78
|
+
/** Every other open arg of search and fetch is a choice or a flag, so blank, null and false all mean "not this". */
|
|
79
|
+
function leftEmpty(key, value) {
|
|
80
|
+
if (value === false) return !FALSE_STILL_CHOOSES.has(key);
|
|
81
|
+
return value === null || (typeof value === "string" && value.trim() === "");
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* One target. `fixed` is what the id or query itself names. `copy` lists the
|
|
86
|
+
* args keys the target takes; they are passed under their own names. `consumed`
|
|
87
|
+
* lists keys that choose the target and are not passed on. Any other key is
|
|
88
|
+
* refused, with the keys this target takes.
|
|
89
|
+
*/
|
|
90
|
+
function target(label, a, { name, action, fixed = {}, copy = [], consumed = [], others = "" }) {
|
|
91
|
+
const extra = Object.keys(a).filter((key) => !copy.includes(key) && !consumed.includes(key));
|
|
92
|
+
if (extra.length > 0) {
|
|
93
|
+
const takes = copy.length > 0 ? `args: ${copy.join(", ")}` : "no args";
|
|
94
|
+
if (copy.length === 0) return { error: `${label} takes ${takes}${others}. Call it again without args; orient lists what each id takes.` };
|
|
95
|
+
return { error: `${label} takes ${takes}${others}. Call it again with only those; orient lists what each id takes.` };
|
|
96
|
+
}
|
|
97
|
+
const out = { ...fixed };
|
|
98
|
+
for (const key of copy) if (a[key] !== undefined) out[key] = a[key];
|
|
99
|
+
return { name, arguments: out, action };
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Every other way a note id reads, said when a call to one names an arg none of them takes. The refusal used to
|
|
104
|
+
* name only `mail`, so a job asking for `{ images: true }` was told a note takes nothing else, and guessed again
|
|
105
|
+
* (the Nov Babies chat, 2026-11-12).
|
|
106
|
+
*/
|
|
107
|
+
const NOTE_READS =
|
|
108
|
+
'; or, instead, one of: image: "<a picture\'s file name, as the note embeds it>" (one picture the note holds), ' +
|
|
109
|
+
"related: true (with limit), lists: true, transcript, messages, activity";
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* `note.md#Plan#Risks` as `{ path: "note.md", section: "Plan > Risks" }`, or null. Only after a `.md`, so a folder
|
|
113
|
+
* or file whose own name holds a `#` is read as written.
|
|
114
|
+
*/
|
|
115
|
+
function headingFragment(id) {
|
|
116
|
+
const at = id.indexOf(".md#");
|
|
117
|
+
if (at === -1) return null;
|
|
118
|
+
const segments = id
|
|
119
|
+
.slice(at + 4)
|
|
120
|
+
.split("#")
|
|
121
|
+
.map((segment) => segment.trim())
|
|
122
|
+
.filter((segment) => segment !== "");
|
|
123
|
+
if (!segments.length) return null;
|
|
124
|
+
return { path: id.slice(0, at + 3), section: segments.map((segment) => segment.replace(/>/g, "\\>")).join(" > ") };
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/** `search` in the v2 shape. */
|
|
128
|
+
function translateSearch(call, app = {}) {
|
|
129
|
+
const open = openArgs(call);
|
|
130
|
+
if (open.error) return { error: open.error };
|
|
131
|
+
if (isChatGpt(app) && open.args === undefined) {
|
|
132
|
+
return { name: "search", arguments: { query: call.query }, action: "notes" };
|
|
133
|
+
}
|
|
134
|
+
// Their texts, from the Mac's backup (`texts.js`).
|
|
135
|
+
if (open.args?.texts === true) {
|
|
136
|
+
return target("search", open.args, {
|
|
137
|
+
name: "search_texts",
|
|
138
|
+
action: "texts",
|
|
139
|
+
fixed: typeof call.query === "string" && call.query.trim() !== "" ? { query: call.query } : {},
|
|
140
|
+
copy: ["with", "since", "limit"],
|
|
141
|
+
consumed: ["texts"],
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
// Their email, through Gmail's own search (`emailRead.js`).
|
|
145
|
+
if (open.args?.email === true) {
|
|
146
|
+
return target("search", open.args, {
|
|
147
|
+
name: "search_email",
|
|
148
|
+
action: "email",
|
|
149
|
+
fixed: { query: call.query },
|
|
150
|
+
copy: ["account", "limit"],
|
|
151
|
+
consumed: ["email"],
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
return target("search", open.args ?? {}, {
|
|
155
|
+
name: "search_notes",
|
|
156
|
+
action: "notes",
|
|
157
|
+
fixed: { query: call.query },
|
|
158
|
+
copy: ["prefix", "from", "to"],
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/** Keyword ids: exact, case-sensitive, after trimming. */
|
|
163
|
+
const KEYWORDS = {
|
|
164
|
+
// Several notes in one call (`read_notes`): args { paths }.
|
|
165
|
+
"notes:": { name: "read_notes", action: "notes", copy: ["paths"] },
|
|
166
|
+
"meetings:": { name: "list_meetings", action: "meetings", copy: ["limit"] },
|
|
167
|
+
"calendar:": { name: "read_calendar", action: "calendar", copy: ["date", "days", "account"] },
|
|
168
|
+
"messages:": { name: "list_channel_days", action: "messages", copy: ["channel", "account", "limit"] },
|
|
169
|
+
"contacts:": { name: "list_contacts", action: "contacts", copy: ["limit"] },
|
|
170
|
+
"activity:": { name: "read_activity", action: "activity", copy: ["limit"] },
|
|
171
|
+
"changes:": { name: "list_changes", action: "changes", copy: ["limit", "reads"] },
|
|
172
|
+
"links:": { name: "list_links", action: "links", copy: [] },
|
|
173
|
+
"vault:": { name: "vault_list", action: "vault", copy: [] },
|
|
174
|
+
"plugins:": { name: "list_plugins", action: "plugins", copy: [] },
|
|
175
|
+
"access:": { name: "scope_info", action: "access", copy: ["path", "workspaces"] },
|
|
176
|
+
"apps:": { name: "app_read", action: "apps", copy: [] },
|
|
177
|
+
"texts:": { name: "list_texts", action: "texts", copy: ["limit"] },
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
/** `calendar:<YYYY-MM-DD>`: the `calendar:` keyword for that day. */
|
|
181
|
+
const CALENDAR_DAY = /^calendar:\s*(\d{4}-\d{2}-\d{2})$/;
|
|
182
|
+
|
|
183
|
+
/** `apps:<app>`: one connected app's tools, or with `tool`, one read through it. */
|
|
184
|
+
const APP_PREFIX = "apps:";
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* A chat's history file (`tex/history.ledger.json`, or `history.ledger.json` in a group chat's home): the chat's
|
|
188
|
+
* ledger as it is now, answered by the chat's Tex object (`texStore/historyView.js`). It is a row like any Tex note
|
|
189
|
+
* and `read_note` reads it with that note's access; only its name is not `.md`, so without this it fell through to a
|
|
190
|
+
* folder listing and answered "no visible notes" (Dev, 2026-11-03: agents should be able to read the history files).
|
|
191
|
+
*/
|
|
192
|
+
// Its conversations file beside it is read the same way (`texStore/historyView.js`).
|
|
193
|
+
const HISTORY_FILE_ID = /(?:^|\/)(?:history|conversations)\.ledger\.json$/i;
|
|
194
|
+
|
|
195
|
+
/** Ids that name something other than a note, which only the table below can route. */
|
|
196
|
+
function routedId(id) {
|
|
197
|
+
if (HISTORY_FILE_ID.test(id)) return true;
|
|
198
|
+
return Object.hasOwn(KEYWORDS, id) || CALENDAR_DAY.test(id) || [APP_PREFIX, TEXTS_ID_PREFIX, EMAIL_ID_PREFIX, GOOGLE_CHAT_ID_PREFIX].some((prefix) => id.startsWith(prefix));
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/** `fetch` in the v2 shape. */
|
|
202
|
+
function translateFetch(call, app = {}) {
|
|
203
|
+
const open = openArgs(call);
|
|
204
|
+
if (open.error) return { error: open.error };
|
|
205
|
+
if (typeof call.id !== "string") {
|
|
206
|
+
return { error: "fetch needs an id: a note path, a search result id, or one of the keywords orient lists." };
|
|
207
|
+
}
|
|
208
|
+
// Everything but an id the table routes itself: the deep-research fetch
|
|
209
|
+
// reads notes only, so an `email:` id, a keyword or a `texts:` chat its own
|
|
210
|
+
// search handed out is translated as for everybody (2026-10-28: ChatGPT's
|
|
211
|
+
// fetch of the `email:` id search returned was refused as an invalid id).
|
|
212
|
+
if (isChatGpt(app) && open.args === undefined && !routedId(call.id.trim())) {
|
|
213
|
+
return { name: "fetch", arguments: { id: call.id }, action: "note" };
|
|
214
|
+
}
|
|
215
|
+
const a = open.args ?? {};
|
|
216
|
+
const id = call.id.trim();
|
|
217
|
+
const label = `fetch "${echo(id)}"`;
|
|
218
|
+
|
|
219
|
+
// A picture of the page in the app (`renderPage.js`): `map:`, `mail:`, `home:`, a note or a folder, as the person sees it.
|
|
220
|
+
if (a.render === true) {
|
|
221
|
+
return target(label, a, { name: "render_page", action: "render", fixed: { page: id }, copy: ["width", "height"], consumed: ["render"] });
|
|
222
|
+
}
|
|
223
|
+
if (Object.hasOwn(KEYWORDS, id)) {
|
|
224
|
+
const { name, action, copy } = KEYWORDS[id];
|
|
225
|
+
return target(label, a, { name, action, copy });
|
|
226
|
+
}
|
|
227
|
+
// `calendar:2026-11-23` is the day it names: Tex wrote the date into the id on a preview (2026-11-22), and it was
|
|
228
|
+
// read as a folder named that, "no visible notes", so it said it couldn't see their calendar.
|
|
229
|
+
const day = CALENDAR_DAY.exec(id);
|
|
230
|
+
if (day) {
|
|
231
|
+
const { name, action, copy } = KEYWORDS["calendar:"];
|
|
232
|
+
return target(label, a, { name, action, fixed: a.date === undefined ? { date: day[1] } : {}, copy });
|
|
233
|
+
}
|
|
234
|
+
if (id.startsWith(APP_PREFIX)) {
|
|
235
|
+
const app = id.slice(APP_PREFIX.length).trim();
|
|
236
|
+
return target(label, a, { name: "app_read", action: "app", fixed: { app }, copy: ["tool", "arguments"] });
|
|
237
|
+
}
|
|
238
|
+
if (id.startsWith(TEXTS_ID_PREFIX)) {
|
|
239
|
+
return target(label, a, { name: "read_texts", action: "texts", fixed: { chat: id.slice(TEXTS_ID_PREFIX.length) }, copy: ["since", "before", "limit"] });
|
|
240
|
+
}
|
|
241
|
+
// Their Google Chat, live (`googleChatRead.js`): `chat:` lists their spaces, `chat:<spaces/…>`
|
|
242
|
+
// reads one, and `chat:` with args `{ to }` reads the direct message with that person. Each
|
|
243
|
+
// names the account it reads (`account`); bare `chat:` without one answers with their accounts.
|
|
244
|
+
if (id.startsWith(GOOGLE_CHAT_ID_PREFIX)) {
|
|
245
|
+
const space = id.slice(GOOGLE_CHAT_ID_PREFIX.length).trim();
|
|
246
|
+
if (space !== "") return target(label, a, { name: "read_google_chat", action: "chat", fixed: { space }, copy: ["limit", "account"] });
|
|
247
|
+
if (a.to !== undefined) return target(label, a, { name: "read_google_chat", action: "chat", copy: ["to", "limit", "account"] });
|
|
248
|
+
return target(label, a, { name: "google_chat", action: "chat_spaces", fixed: { action: "spaces" }, copy: ["account"] });
|
|
249
|
+
}
|
|
250
|
+
if (id.startsWith(EMAIL_ID_PREFIX)) {
|
|
251
|
+
// The email itself takes no args; its three are an attachment's (Dev2, 2026-11-23: a Lab run read `from` as the sender
|
|
252
|
+
// and `summary` as "summarize", was refused twice, and ended with no answer). The offset is `start`, never `from`.
|
|
253
|
+
const ATTACHMENT_ONLY = "; start (where to pick up in a long attachment, the number its more: line gave) and summary (totals over a CSV, an object) go only with attachment";
|
|
254
|
+
if (a.from !== undefined) {
|
|
255
|
+
return { error: `${label} takes no from: the sender is already in the id. Call it again with no args to read the email${ATTACHMENT_ONLY}.` };
|
|
256
|
+
}
|
|
257
|
+
if (a.attachment === undefined && (a.start !== undefined || a.summary !== undefined)) {
|
|
258
|
+
return { error: `${label} reads the whole email with no args${ATTACHMENT_ONLY}. Call it again with no args to read the email.` };
|
|
259
|
+
}
|
|
260
|
+
return target(label, a, { name: "read_email", action: "email", fixed: { id }, copy: ["attachment", "start", "summary"], others: ATTACHMENT_ONLY });
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
// A chat's history file reads as the note it is, with that note's access.
|
|
264
|
+
if (HISTORY_FILE_ID.test(id)) {
|
|
265
|
+
return target(label, a, { name: "read_note", action: "note", fixed: { path: id }, copy: ["before", "job"] });
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
// A message anchor from search (`<note>.md#<anchor>`) reads that one message; `<note>.md#Plan#Risks` reads one
|
|
269
|
+
// section, the way Obsidian links name one (`notes/readPart.js`). Anything else with a `#` is the path as written.
|
|
270
|
+
const split = splitMessageAnchor(id);
|
|
271
|
+
const fragment = headingFragment(id);
|
|
272
|
+
const note = split.anchor !== null && split.path.endsWith(".md") ? split.path : fragment !== null ? fragment.path : id;
|
|
273
|
+
const named = split.anchor !== null && split.path.endsWith(".md") ? split.anchor : fragment?.section ?? null;
|
|
274
|
+
|
|
275
|
+
if (note.endsWith(".md")) {
|
|
276
|
+
if (a.image !== undefined) {
|
|
277
|
+
return target(label, a, { name: "read_image", action: "image", fixed: { note }, copy: ["image"] });
|
|
278
|
+
}
|
|
279
|
+
if (a.related === true) {
|
|
280
|
+
return target(label, a, { name: "related_notes", action: "related", fixed: { path: note }, copy: ["limit"], consumed: ["related"] });
|
|
281
|
+
}
|
|
282
|
+
if (a.lists === true) {
|
|
283
|
+
return target(label, a, { name: "evaluate_lists", action: "lists", fixed: { path: note }, consumed: ["lists"] });
|
|
284
|
+
}
|
|
285
|
+
if (a.transcript !== undefined) {
|
|
286
|
+
return target(label, a, { name: "read_meeting", action: "meeting", fixed: { path: note }, copy: ["transcript"] });
|
|
287
|
+
}
|
|
288
|
+
if (a.messages !== undefined) {
|
|
289
|
+
return target(label, a, { name: "read_channel_day", action: "day", fixed: { path: note }, copy: ["messages"] });
|
|
290
|
+
}
|
|
291
|
+
if (a.activity !== undefined) {
|
|
292
|
+
return target(label, a, { name: "read_contact", action: "contact", fixed: { path: note }, copy: ["activity"] });
|
|
293
|
+
}
|
|
294
|
+
if (named !== null && a.section === undefined && a.lines === undefined && a.outline === undefined && a.mail === undefined) {
|
|
295
|
+
return target(label, a, { name: "read_note", action: "note", fixed: { path: note, section: named }, copy: [], others: NOTE_READS });
|
|
296
|
+
}
|
|
297
|
+
return target(label, a, { name: "read_note", action: "note", fixed: { path: note }, copy: ["mail", "outline", "section", "lines", "full"], others: NOTE_READS });
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
// A sheet (a `.csv` with typed columns): its rows as a table, filtered and sorted by its args (`readSheet.js`).
|
|
301
|
+
// Paging (`from`) and totals (`summary`) are read_file's, for a long CSV such as an email's attachment.
|
|
302
|
+
if (isSheetPath(id) && a.from === undefined && a.summary === undefined) {
|
|
303
|
+
return target(label, a, { name: "read_sheet", action: "sheet", fixed: { path: id }, copy: ["where", "sort", "last", "limit", "columns", "comments"] });
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
// A stored file (a PDF an email carried, a spreadsheet): its words.
|
|
307
|
+
if (readableFileType(id) !== null) {
|
|
308
|
+
return target(label, a, { name: "read_file", action: "file", fixed: { path: id }, copy: ["from", "summary"] });
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
// A folder: named with a trailing slash, or without one. Empty is everything.
|
|
312
|
+
const prefix = id.replace(/\/+$/, "");
|
|
313
|
+
return target(label, a, { name: "list_notes", action: "list", fixed: prefix === "" ? {} : { prefix } });
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
module.exports = { translateSearch, translateFetch };
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A v2 call (the six's), translated into the one existing tool call it stands for.
|
|
3
|
+
*
|
|
4
|
+
* Runs first in `callToolForSession`, before routing, so everything that
|
|
5
|
+
* decides authority (the context a call reaches, the write gate, the egress
|
|
6
|
+
* gate, argument validation against the existing tool's schema, audit) sees
|
|
7
|
+
* the translated call and decides it exactly as it did before v2. This file
|
|
8
|
+
* decides nothing about access: every answer it can give is a function of the
|
|
9
|
+
* caller's own arguments and the published action table.
|
|
10
|
+
*
|
|
11
|
+
* Moved from `apps/mcp/src/tools/v2/translate.js`, which hands it the live schemas and the call's app, so Tex
|
|
12
|
+
* translates a six call with the same code, against its catalog snapshot.
|
|
13
|
+
*/
|
|
14
|
+
"use strict";
|
|
15
|
+
|
|
16
|
+
const { validateArguments } = require("../texShared/toolArguments.cjs");
|
|
17
|
+
const { ACTION_TOOLS, ACTIONS, actionOf } = require("./toolActions.cjs");
|
|
18
|
+
const { translateFetch, translateSearch } = require("./v2SearchFetch.cjs");
|
|
19
|
+
|
|
20
|
+
/** v2 names that are translated here. `orient` is answered by itself. */
|
|
21
|
+
const TRANSLATED_TOOLS = new Set([...ACTION_TOOLS, "search", "fetch"]);
|
|
22
|
+
|
|
23
|
+
/** Longest action name echoed back in a refusal. */
|
|
24
|
+
const ECHO_CAP = 40;
|
|
25
|
+
|
|
26
|
+
function listOf(tool) {
|
|
27
|
+
return Object.keys(ACTIONS[tool]).join(", ");
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* `{ params }` to call instead, or `{ error }` to answer with.
|
|
32
|
+
*
|
|
33
|
+
* @param {{name?: string, arguments?: object}} params
|
|
34
|
+
* @param {{schemaFor: Function, coerce: Function, app: {client?: string | null}}} reading
|
|
35
|
+
* the advertised schema for a name, the coercion against it, and the app the call came from: the gateway's live
|
|
36
|
+
* ones (`apps/mcp/src/tools/v2/translate.js`), or Tex's catalog snapshot (`packages/tex/gateway/contextMcp.js`).
|
|
37
|
+
*/
|
|
38
|
+
function translateV2Params(params, { schemaFor, coerce, app }) {
|
|
39
|
+
const name = params?.name;
|
|
40
|
+
if (!TRANSLATED_TOOLS.has(name)) return { params };
|
|
41
|
+
// Read as the advertised types first, as `routeToolCall` does: an app
|
|
42
|
+
// whose copy of `args` has no type sends it as JSON text.
|
|
43
|
+
const supplied = coerce(name, params?.arguments);
|
|
44
|
+
const args = supplied && typeof supplied === "object" && !Array.isArray(supplied) ? supplied : {};
|
|
45
|
+
|
|
46
|
+
const schema = schemaFor(name);
|
|
47
|
+
if (schema) {
|
|
48
|
+
const refusal = validateArguments(schema, args);
|
|
49
|
+
if (refusal) return { error: refusal };
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
let translated;
|
|
53
|
+
if (name === "search") translated = translateSearch(args, app);
|
|
54
|
+
else if (name === "fetch") translated = translateFetch(args, app);
|
|
55
|
+
else translated = translateAction(name, args);
|
|
56
|
+
if (translated.error) return { error: translated.error };
|
|
57
|
+
|
|
58
|
+
const out = { ...translated.arguments };
|
|
59
|
+
const addressed = addressing(args, out);
|
|
60
|
+
if (addressed.error) return { error: addressed.error };
|
|
61
|
+
return { params: { ...params, name: translated.name, arguments: out }, v2: { tool: name, action: translated.action } };
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function translateAction(tool, args) {
|
|
65
|
+
const action = actionOf(tool, args);
|
|
66
|
+
if (typeof action !== "string" || action === "") {
|
|
67
|
+
return { error: `${tool} needs an action: one of ${listOf(tool)}. Call it again with one of those; orient lists what each takes.` };
|
|
68
|
+
}
|
|
69
|
+
if (!Object.hasOwn(ACTIONS[tool], action)) {
|
|
70
|
+
const shown = action.length > ECHO_CAP ? `${action.slice(0, ECHO_CAP)}…` : action;
|
|
71
|
+
return {
|
|
72
|
+
error: `${tool} has no action "${shown}". Its actions: ${listOf(tool)}. Call it again with one of those; orient lists what each takes.`,
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
const entry = ACTIONS[tool][action];
|
|
76
|
+
const { inner, lifted } = liftAddressing(args.args);
|
|
77
|
+
const call = { path: args.path, content: args.content, expected_etag: args.expected_etag, args: inner };
|
|
78
|
+
return { name: entry.tool, arguments: { ...entry.take(call), ...lifted }, action };
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** Arguments that address the call, never the action's own. */
|
|
82
|
+
const ADDRESSING = ["context", "mailbox", "person_said"];
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* `context`, `mailbox` and `person_said` written inside `args`, taken out before the action reads it: an action that
|
|
86
|
+
* nests its args (mail, comment, upload) would otherwise carry them one level down, where routing never looks, and
|
|
87
|
+
* refuse them as unknown (`mail.mailbox`, 2026-11-25: join's answer says to pass the mailbox on every call, and a bot
|
|
88
|
+
* put it in args). A blank mailbox or person_said is the field left empty and is dropped.
|
|
89
|
+
*/
|
|
90
|
+
function liftAddressing(raw) {
|
|
91
|
+
if (!raw || typeof raw !== "object" || Array.isArray(raw) || !ADDRESSING.some((key) => Object.hasOwn(raw, key))) return { inner: raw, lifted: {} };
|
|
92
|
+
const inner = { ...raw };
|
|
93
|
+
const lifted = {};
|
|
94
|
+
for (const key of ADDRESSING) {
|
|
95
|
+
if (!Object.hasOwn(inner, key)) continue;
|
|
96
|
+
const value = inner[key];
|
|
97
|
+
delete inner[key];
|
|
98
|
+
// A blank mailbox or person_said is the field left empty; a blank context is carried up, where routing refuses it.
|
|
99
|
+
if (value === undefined || (key !== "context" && (value === null || (typeof value === "string" && value.trim() === "")))) continue;
|
|
100
|
+
lifted[key] = value;
|
|
101
|
+
}
|
|
102
|
+
return { inner, lifted };
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* `context`, `mailbox` and `person_said` belong to the call, not the action: carried to the
|
|
107
|
+
* top of the translated arguments, where routing reads them. One written
|
|
108
|
+
* inside `args` counts too, but a call that names two different contexts is
|
|
109
|
+
* refused rather than guessed at.
|
|
110
|
+
*/
|
|
111
|
+
function addressing(args, out) {
|
|
112
|
+
for (const key of ["context", "mailbox", "person_said"]) {
|
|
113
|
+
const outer = key !== "context" && typeof args[key] === "string" && args[key].trim() === "" ? undefined : args[key];
|
|
114
|
+
const inner = out[key];
|
|
115
|
+
if (outer !== undefined && inner !== undefined && outer !== inner) {
|
|
116
|
+
return { error: `that call names two different values for ${key}; pass it once.` };
|
|
117
|
+
}
|
|
118
|
+
if (outer !== undefined) out[key] = outer;
|
|
119
|
+
}
|
|
120
|
+
return {};
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
module.exports = { TRANSLATED_TOOLS, translateV2Params };
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* THE VAULT'S BROWSER TOOLS AS TEX OFFERS THEM: `fill_login`, `fill_card` and `make_login`.
|
|
3
|
+
*
|
|
4
|
+
* Tex shows these to its model and counts their calls per question; Context
|
|
5
|
+
* runs them (`apps/mcp/src/vault/agent/`, reached through the `vault_type`
|
|
6
|
+
* tool), opening the saved login or card and typing it into Tex's browser
|
|
7
|
+
* itself, so no username, password or card number ever passes through Tex
|
|
8
|
+
* (docs/decisions/texting-assistant/vault.md). Both sides read the names
|
|
9
|
+
* and caps here.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
const FILL_LOGIN_TOOL = "fill_login";
|
|
13
|
+
|
|
14
|
+
/** Fills in one question: a sign-in, and a retry or a second step. */
|
|
15
|
+
const MAX_FILLS_PER_TURN = 3;
|
|
16
|
+
|
|
17
|
+
const FILL_LOGIN_DEFINITION = {
|
|
18
|
+
name: FILL_LOGIN_TOOL,
|
|
19
|
+
description:
|
|
20
|
+
"Sign in with a login the person saved: fills the username and password boxes on the page your browser is on. " +
|
|
21
|
+
"First open the site's sign-in page with send action browse, then pass the login's id from fetch vault: and the numbers of the boxes. " +
|
|
22
|
+
"A page with both boxes takes username_ref and password_ref in one call. Only a page that asks for the email first, with no password box yet, takes username_ref alone: press its continue button, then fill again with password_ref on the next page. " +
|
|
23
|
+
"Never type an email or username into a sign-in yourself: only the saved one goes in. " +
|
|
24
|
+
"You never see the username or password; press the sign-in button with send action browse afterwards. " +
|
|
25
|
+
"It only works on the login's own site; a Google login (site google.com) fills on Google's sign-in page, which a site's Continue with Google button opens. If there is no saved login, never ask for the password: ask whether they sign in with Gmail or another email and send manage action vault_add's link for it with its site; Context tells you when it's saved, and you sign in yourself then.",
|
|
26
|
+
inputSchema: {
|
|
27
|
+
type: "object",
|
|
28
|
+
properties: {
|
|
29
|
+
entry: { type: "string", description: "The login's id from fetch vault:." },
|
|
30
|
+
password_ref: { type: "integer", description: "The password box's number from the last reading, when this page has one." },
|
|
31
|
+
username_ref: { type: "integer", description: "The username or email box's number, when this page has one." },
|
|
32
|
+
context: { type: "string", description: "The workspace the login is saved in, like @team; left out, the login is found in whichever workspace's vault holds it." },
|
|
33
|
+
},
|
|
34
|
+
required: ["entry"],
|
|
35
|
+
},
|
|
36
|
+
annotations: { openWorldHint: true },
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
const FILL_CARD_TOOL = "fill_card";
|
|
40
|
+
|
|
41
|
+
/** One checkout gets one fill; a retry after a refused box is the second (and a later turn may fill again on the same yes). */
|
|
42
|
+
const MAX_CARD_FILLS_PER_TURN = 2;
|
|
43
|
+
|
|
44
|
+
const FILL_CARD_DEFINITION = {
|
|
45
|
+
name: FILL_CARD_TOOL,
|
|
46
|
+
description:
|
|
47
|
+
"Pay with a card the person saved: fills the card boxes on the checkout page your browser is on. " +
|
|
48
|
+
"First get to the payment step with send action browse, then pass the card's id from fetch vault:, the total the page shows, and the numbers of the boxes. " +
|
|
49
|
+
"The boxes are often in the payment processor's frame (a card form from another site), read after the page and numbered from 1001: those numbers fill too. " +
|
|
50
|
+
"The person is asked once a purchase to allow that card, that total, on that site; when the answer says they are being asked, tell them what you're buying, and fill again once they allowed it. " +
|
|
51
|
+
"Their yes covers filling again for that purchase (a box refused, a page that reset) while the total stays the same: never ask them again for it. " +
|
|
52
|
+
"You never see the card; it fills and never pays: press the page's pay button with send action browse yourself, after they know the total. " +
|
|
53
|
+
"If there is no saved card, never ask for the number: send manage action vault_add's link with type card.",
|
|
54
|
+
inputSchema: {
|
|
55
|
+
type: "object",
|
|
56
|
+
properties: {
|
|
57
|
+
entry: { type: "string", description: "The card's id from fetch vault:." },
|
|
58
|
+
total: { type: "string", description: "The total to pay, as the checkout shows it, like $131.50." },
|
|
59
|
+
number_ref: { type: "integer", description: "The card number box's number from the last reading." },
|
|
60
|
+
exp_ref: { type: "integer", description: "One expiry box (MM/YY), when the page has one." },
|
|
61
|
+
exp_month_ref: { type: "integer", description: "The expiry month box or menu, when month and year are separate." },
|
|
62
|
+
exp_year_ref: { type: "integer", description: "The expiry year box or menu, when month and year are separate." },
|
|
63
|
+
cvc_ref: { type: "integer", description: "The security code (CVC) box." },
|
|
64
|
+
name_ref: { type: "integer", description: "The name-on-card box, when the page has one." },
|
|
65
|
+
postal_code_ref: { type: "integer", description: "The billing ZIP or postcode box, when the page has one." },
|
|
66
|
+
context: { type: "string", description: "The workspace the card is saved in, like @team; left out, the card is found in whichever workspace's vault holds it." },
|
|
67
|
+
},
|
|
68
|
+
required: ["entry", "total", "number_ref"],
|
|
69
|
+
},
|
|
70
|
+
annotations: { openWorldHint: true },
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
const MAKE_LOGIN_TOOL = "make_login";
|
|
74
|
+
|
|
75
|
+
/** New accounts per question: a sign-up and the one retry it may need. */
|
|
76
|
+
const MAX_NEW_LOGINS_PER_TURN = 2;
|
|
77
|
+
|
|
78
|
+
const MAKE_LOGIN_DEFINITION = {
|
|
79
|
+
name: MAKE_LOGIN_TOOL,
|
|
80
|
+
description:
|
|
81
|
+
"Only when you are creating a NEW account for the person on the sign-up page your browser is on: makes a strong password, saves the login (this site, the username or email you pass, the password) to their vault first, then types it into the page's boxes. " +
|
|
82
|
+
"You never see the password. Pass username (the email or username the account is made with), the box numbers from the last reading (username_ref, password_ref, and confirm_ref when the page asks for the password twice), and name for the vault entry. " +
|
|
83
|
+
"Press the sign-up button with send action browse afterwards; later sign-ins use fill_login with the id it returns. " +
|
|
84
|
+
"Never for an account they already have: then use fill_login with their saved login, or with none saved send manage action vault_add's link. " +
|
|
85
|
+
"Pass symbols: false only when the site refuses symbols.",
|
|
86
|
+
inputSchema: {
|
|
87
|
+
type: "object",
|
|
88
|
+
properties: {
|
|
89
|
+
username: { type: "string", description: "The email or username the account is made with." },
|
|
90
|
+
username_ref: { type: "integer", description: "The username or email box's number, from the last reading." },
|
|
91
|
+
password_ref: { type: "integer", description: "The password box's number, from the last reading." },
|
|
92
|
+
confirm_ref: { type: "integer", description: "The repeat-password box's number, when the page asks for the password twice." },
|
|
93
|
+
name: { type: "string", description: "The vault entry's name, like the site's name." },
|
|
94
|
+
symbols: { type: "boolean", description: "false only when the site refuses symbols." },
|
|
95
|
+
context: { type: "string", description: "The workspace whose vault keeps it, like @team; left out, the turn's own." },
|
|
96
|
+
},
|
|
97
|
+
required: ["username", "password_ref"],
|
|
98
|
+
},
|
|
99
|
+
annotations: { openWorldHint: true },
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
module.exports = {
|
|
103
|
+
FILL_LOGIN_TOOL,
|
|
104
|
+
MAX_FILLS_PER_TURN,
|
|
105
|
+
FILL_LOGIN_DEFINITION,
|
|
106
|
+
FILL_CARD_TOOL,
|
|
107
|
+
MAX_CARD_FILLS_PER_TURN,
|
|
108
|
+
FILL_CARD_DEFINITION,
|
|
109
|
+
MAKE_LOGIN_TOOL,
|
|
110
|
+
MAX_NEW_LOGINS_PER_TURN,
|
|
111
|
+
MAKE_LOGIN_DEFINITION,
|
|
112
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export interface ToolDefinition {
|
|
2
|
+
name: string;
|
|
3
|
+
description: string;
|
|
4
|
+
inputSchema: { type: "object"; properties: Record<string, unknown>; required: string[] };
|
|
5
|
+
annotations: { openWorldHint: boolean };
|
|
6
|
+
}
|
|
7
|
+
export const FILL_LOGIN_TOOL: "fill_login";
|
|
8
|
+
export const MAX_FILLS_PER_TURN: number;
|
|
9
|
+
export const FILL_LOGIN_DEFINITION: ToolDefinition;
|
|
10
|
+
export const FILL_CARD_TOOL: "fill_card";
|
|
11
|
+
export const MAX_CARD_FILLS_PER_TURN: number;
|
|
12
|
+
export const FILL_CARD_DEFINITION: ToolDefinition;
|
|
13
|
+
export const MAKE_LOGIN_TOOL: "make_login";
|
|
14
|
+
export const MAX_NEW_LOGINS_PER_TURN: number;
|
|
15
|
+
export const MAKE_LOGIN_DEFINITION: ToolDefinition;
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Whether a texted text says yes or no, read in code (`packages/tex/gateway/agent/textedApprovals.js`, which settles a
|
|
3
|
+
* held ask on one before any model runs, and `apps/mcp/src/tools/texTurnYes.js`, which reads a turn's kept words the
|
|
4
|
+
* same way over Tex's MCP door). Pure.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/** A text that is nothing but yes, or nothing but no; anything else goes to the model. */
|
|
8
|
+
const YES = /^\s*(?:yes|yes please|yep|yeah|yup|ok|okay|k|sure|do it|go ahead|go for it|confirm|confirmed|approve|approved|allow|y|sounds good|looks good|perfect|lgtm|\u{1F44C})\s*[.!]*\s*$/iu;
|
|
9
|
+
const NO = /^\s*(?:no|nope|no thanks|don'?t|cancel|stop|deny|denied|never ?mind|forget it|drop it|n|\u{1F44E}[\u{1F3FB}-\u{1F3FF}]?)\s*[.!]*\s*$/iu;
|
|
10
|
+
|
|
11
|
+
/*
|
|
12
|
+
A yes said the way people say it (Dev, 2026-10-19: "yes, send it, yes, file
|
|
13
|
+
it, yes, please. These all count as yes"): a yes word followed only by
|
|
14
|
+
phrases that release what was shown, or one of those phrases alone. A fixed
|
|
15
|
+
list, anchored at both ends, so "yes but send it to Sam" is still more than
|
|
16
|
+
a yes and goes to the model.
|
|
17
|
+
*/
|
|
18
|
+
// Each says to go ahead. Courtesies alone ("ok thanks", "great") are an
|
|
19
|
+
// acknowledgement, not a send, so they are left out on purpose.
|
|
20
|
+
const RELEASE =
|
|
21
|
+
String.raw`(?:please|send it|send them|send that|send|file it|file that|file|do it|go ahead|go for it|make the change|book it|add it|` +
|
|
22
|
+
String.raw`looks good|sounds good)`;
|
|
23
|
+
const SEP = String.raw`[\s,.!-]+`;
|
|
24
|
+
const RELEASED_YES = new RegExp(
|
|
25
|
+
String.raw`^\s*(?:(?:yes|yep|yeah|yup|ok|okay|sure|y)(?:${SEP}${RELEASE})+|(?:send it|send them|file it|send that|file that|send)(?:${SEP}${RELEASE})*)\s*[.!]*\s*$`,
|
|
26
|
+
"i",
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
/*
|
|
30
|
+
A yes said in a sentence (Dev2, 2026-10-22: "yes please send it already sent
|
|
31
|
+
👍" got nothing, after a 👍 that got nothing). A text whose every word is
|
|
32
|
+
one of these, with at least one that says yes or says to send it, is a yes.
|
|
33
|
+
Any other word, "but", "to", a name, "not", sends it to the model, so "yes
|
|
34
|
+
but send it to Sam" and "did you send it" are still not a yes.
|
|
35
|
+
*/
|
|
36
|
+
const SAYS_YES = new Set(["yes", "yess", "yesss", "yep", "yeah", "yea", "ya", "yup", "y", "\u{1F44D}", "\u2705", "\u2714"]);
|
|
37
|
+
const SAYS_SEND = new Set(["send", "file", "confirm", "confirmed", "approve", "approved"]);
|
|
38
|
+
const ALSO_SAID = new Set([
|
|
39
|
+
...SAYS_YES, ...SAYS_SEND,
|
|
40
|
+
// "send the draft" is the in-app approval card's reply (Dev2, 2026-11-20). "draft" alone is no verdict: it says no yes and no send.
|
|
41
|
+
"draft", "drafts",
|
|
42
|
+
"ok", "okay", "k", "sure", "please", "pls", "plz", "it", "them", "that", "this", "now", "already", "just", "go", "ahead", "do",
|
|
43
|
+
"for", "right", "away", "asap", "the", "message", "email", "dm", "text", "again", "thanks", "thank", "you", "ty", "sent", "so",
|
|
44
|
+
"and", "then", "absolutely", "definitely", "of", "course", "lol", "haha", "\u{1F64F}", "\u{1F525}", "\u2764", "\u{1F44C}",
|
|
45
|
+
]);
|
|
46
|
+
|
|
47
|
+
/** The words of a short text, emoji as words of their own, punctuation dropped. */
|
|
48
|
+
function wordsOf(text) {
|
|
49
|
+
return text
|
|
50
|
+
.normalize("NFKC")
|
|
51
|
+
.toLowerCase()
|
|
52
|
+
.replace(/[\u{1F3FB}-\u{1F3FF}\uFE0F\u200D]/gu, "")
|
|
53
|
+
.replace(/(\p{Extended_Pictographic}|\u2705|\u2714)/gu, " $1 ")
|
|
54
|
+
.replace(/[^\p{L}\p{N}\p{Extended_Pictographic}\u2705\u2714]+/gu, " ")
|
|
55
|
+
.trim()
|
|
56
|
+
.split(" ")
|
|
57
|
+
.filter(Boolean);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** Whether a text is a yes said in a sentence. */
|
|
61
|
+
function sentenceYes(text) {
|
|
62
|
+
const words = wordsOf(text);
|
|
63
|
+
if (words.length === 0 || words.length > 12 || !words.every((word) => ALSO_SAID.has(word))) return false;
|
|
64
|
+
if (words.some((word) => SAYS_YES.has(word) || SAYS_SEND.has(word))) return true;
|
|
65
|
+
// "go ahead", "do it": a release in two words.
|
|
66
|
+
return words.includes("ahead") || (words.includes("do") && words.includes("it"));
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** Words that take a yes back, or hold it: a text with any of them is never a yes by its sentences alone. */
|
|
70
|
+
const HELD_BACK = /\b(?:not|don'?t|dont|wait|hold|but|unless|instead|change|edit|fix)\b/i;
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Whether a text says yes in one of its sentences, for an email Tex showed (`emailGate.js` `saidYes`): "send it from my
|
|
74
|
+
* gmail. draft is good. go ahead" is a yes; "what else is on thursday?" and "go ahead but change the time" are not. A
|
|
75
|
+
* whole-text yes (`approvalVerdict`) is one too.
|
|
76
|
+
*/
|
|
77
|
+
function saysYes(text) {
|
|
78
|
+
if (approvalVerdict(text) === "approve") return true;
|
|
79
|
+
if (typeof text !== "string" || text.length > 300 || HELD_BACK.test(text)) return false;
|
|
80
|
+
const sentences = text.split(/[.!?\n]+/).map((part) => part.trim()).filter(Boolean);
|
|
81
|
+
return sentences.some((part) => approvalVerdict(part) === "approve") && !sentences.some((part) => approvalVerdict(part) === "deny");
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function approvalVerdict(text) {
|
|
85
|
+
if (typeof text !== "string") return null;
|
|
86
|
+
if (YES.test(text) || RELEASED_YES.test(text) || sentenceYes(text)) return "approve";
|
|
87
|
+
if (NO.test(text)) return "deny";
|
|
88
|
+
return null;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
module.exports = { approvalVerdict, saysYes };
|