@framers/agentos-ext-gmail-source 0.0.0-stage → 0.2.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.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"GmailOAuthFlow.js","sourceRoot":"","sources":["../src/GmailOAuthFlow.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EACL,iBAAiB,EAAE,iBAAiB,GAErC,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,sCAAsC,CAAC;AACnF,OAAO,EACL,oBAAoB,EAAE,eAAe,GAEtC,MAAM,YAAY,CAAC;AAEpB,yEAAyE;AACzE,MAAM,SAAS,GAAwB,MAAM,CAAC,MAAM,CAAC;IACnD,aAAa,EAAE,8CAA8C;IAC7D,KAAK,EAAE,qCAAqC;IAC5C,MAAM,EAAE,sCAAsC;CAC/C,CAAC,CAAC;AACH,+CAA+C;AAC/C,MAAM,QAAQ,GAAG,MAAM,CAAC;AACxB,+DAA+D;AAC/D,MAAM,UAAU,GAAG,MAAM,CAAC;AAC1B,uFAAuF;AACvF,MAAM,WAAW,GAAG,CAAC,KAAc,EAAmB,EAAE,CAAC,OAAO,KAAK,KAAK,QAAQ;OAC7E,KAAK,CAAC,MAAM,GAAG,CAAC,IAAI,KAAK,CAAC,MAAM,IAAI,MAAM,IAAI,CAAC,iBAAiB,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;AAClF,mFAAmF;AACnF,SAAS,SAAS,CAAC,KAAc;IAC/B,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAC;IAC5C,MAAM,MAAM,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IACzC,OAAO,MAAM,CAAC,MAAM,KAAK,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,KAAK,oBAAoB,CAAC;AACnE,CAAC;AACD;;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read-only Gmail source's grant: Google's read-only scope on the AgentOS redirect OAuth flow and
3
+ * sealed-token store, with capped, cancellable OAuth calls and fixed failures; and its text helpers: bounded
4
+ * pre-storage sanitization of mail text, allow-listed headers and metadata, and conservative trimming of reply history
5
+ * and signatures.
6
+ * @module agentos-ext-gmail-source
7
+ */
8
+ export { GmailOAuthFlow } from './GmailOAuthFlow.js';
9
+ export { GMAIL_READONLY_SCOPE, GmailOAuthFault, type GmailOAuthFailure, type GmailGrantCleanup, type GmailOAuthClient, type GmailOAuthEndpoints, type GmailOAuthOptions, } from './types.js';
10
+ export { GmailTextFault, sanitizeMailText, sanitizeMailMetadata, sanitizeMailHeaders, type GmailTextPolicy, type GmailSanitizedText, type GmailHeaderInput, type GmailSanitizedHeaders, type GmailTextFailure, } from './mailSanitize.js';
11
+ export { messageText, type GmailMessageText } from './messageText.js';
12
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EACL,oBAAoB,EAAE,eAAe,EAAE,KAAK,iBAAiB,EAAE,KAAK,iBAAiB,EACrF,KAAK,gBAAgB,EAAE,KAAK,mBAAmB,EAAE,KAAK,iBAAiB,GACxE,MAAM,YAAY,CAAC;AACpB,OAAO,EACL,cAAc,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,mBAAmB,EAC3E,KAAK,eAAe,EAAE,KAAK,kBAAkB,EAAE,KAAK,gBAAgB,EACpE,KAAK,qBAAqB,EAAE,KAAK,gBAAgB,GAClD,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,WAAW,EAAE,KAAK,gBAAgB,EAAE,MAAM,kBAAkB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,12 @@
1
+ /**
2
+ * @fileoverview A read-only Gmail source's grant: Google's read-only scope on the AgentOS redirect OAuth flow and
3
+ * sealed-token store, with capped, cancellable OAuth calls and fixed failures; and its text helpers: bounded
4
+ * pre-storage sanitization of mail text, allow-listed headers and metadata, and conservative trimming of reply history
5
+ * and signatures.
6
+ * @module agentos-ext-gmail-source
7
+ */
8
+ export { GmailOAuthFlow } from './GmailOAuthFlow.js';
9
+ export { GMAIL_READONLY_SCOPE, GmailOAuthFault, } from './types.js';
10
+ export { GmailTextFault, sanitizeMailText, sanitizeMailMetadata, sanitizeMailHeaders, } from './mailSanitize.js';
11
+ export { messageText } from './messageText.js';
12
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EACL,oBAAoB,EAAE,eAAe,GAEtC,MAAM,YAAY,CAAC;AACpB,OAAO,EACL,cAAc,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,mBAAmB,GAG5E,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,WAAW,EAAyB,MAAM,kBAAkB,CAAC"}
@@ -0,0 +1,100 @@
1
+ /**
2
+ * @fileoverview Deterministic pre-storage sanitization of mail text: address tokens, credential assignments, known
3
+ * credential shapes, private-key blocks and long mixed tokens are replaced with fixed marks, and a final gate
4
+ * suppresses any line that still carries a credential cue. Every count is a number; no matched value, offset or
5
+ * reverse mapping is kept, nothing is logged and no model or network is called.
6
+ * @module agentos-ext-gmail-source/mailSanitize
7
+ */
8
+ /**
9
+ * The bounds of one sanitization call, as positive safe integer UTF-16 code-unit counts. The input ceiling is
10
+ * 2,097,152, the line ceiling 65,536, and the output cap cannot exceed the input cap.
11
+ */
12
+ export interface GmailTextPolicy {
13
+ /** The largest input accepted, before and after decoding; larger input throws `GmailTextFault('input_too_large')`. */
14
+ readonly maxInputCharacters: number;
15
+ /** The longest line inspected; a longer line is suppressed whole before any token matching. */
16
+ readonly maxLineCharacters: number;
17
+ /** The longest text returned; the complete input is checked before this cap clips the result. */
18
+ readonly maxOutputCharacters: number;
19
+ }
20
+ /** Sanitized text and content-free counts of what was removed. The counts are not permission to log the text. */
21
+ export interface GmailSanitizedText {
22
+ /** The sanitized text, clipped to the output cap without splitting a surrogate pair. */
23
+ readonly text: string;
24
+ /** How many address tokens became `[address removed]`. */
25
+ readonly addressRedactions: number;
26
+ /** How many credential lines, shapes, long mixed tokens and private-key blocks became `[secret removed]`. */
27
+ readonly secretRedactions: number;
28
+ /** How many lines became `[line removed by the secret gate]`. */
29
+ readonly suppressedLines: number;
30
+ /** Whether the output cap removed text. */
31
+ readonly truncated: boolean;
32
+ }
33
+ /** One message header after bounded MIME header decoding: its name and its decoded value. */
34
+ export interface GmailHeaderInput {
35
+ readonly name: string;
36
+ readonly value: string;
37
+ }
38
+ /** The retained headers, each sanitized; Bcc and every other header are never returned. */
39
+ export interface GmailSanitizedHeaders {
40
+ /** The first Subject, at most 200 characters. */
41
+ readonly subject: string;
42
+ /** The first Date, at most 1,000 characters. */
43
+ readonly date: string;
44
+ /** Every From value, joined with commas, at most 4,000 characters. */
45
+ readonly from: string;
46
+ /** Every To value, joined with commas, at most 4,000 characters. */
47
+ readonly to: string;
48
+ /** Every Cc value, joined with commas, at most 4,000 characters. */
49
+ readonly cc: string;
50
+ }
51
+ /** Why a text helper refused its input, as a fixed word: an invalid policy or input above its cap. */
52
+ export type GmailTextFailure = 'configuration' | 'input_too_large';
53
+ /** A text helper's fixed refusal; its message is `gmail_text_<reason>` and never carries source text. */
54
+ export declare class GmailTextFault extends Error {
55
+ readonly reason: GmailTextFailure;
56
+ /** @param reason Why the helper refused its input. */
57
+ constructor(reason: GmailTextFailure);
58
+ }
59
+ /**
60
+ * Pure pre-storage transformation. It never records matched values or invokes a model.
61
+ *
62
+ * Decodes repeated percent and character-reference encoding (at most four passes), normalizes Unicode and line breaks,
63
+ * then works line by line: private-key blocks, credential assignments and authenticated URLs are replaced, credential
64
+ * shapes and long mixed tokens become `[secret removed]`, address tokens become `[address removed]`, and a line with
65
+ * unresolved encoded bytes or character references, above the line cap or still carrying a credential cue becomes
66
+ * `[line removed by the secret gate]`. An assignment with an empty value, a block scalar or an unclosed quote also
67
+ * suppresses the rest of the text. A replaced assignment and a line the final gate suppresses keep their quote markers
68
+ * (`>`). The complete input is checked before the output cap clips the result.
69
+ *
70
+ * @param input Decoded text: a body or one display field.
71
+ * @param policy The input, line and output bounds.
72
+ * @returns The sanitized text and content-free counts.
73
+ * @throws {GmailTextFault} `configuration` for an invalid policy, `input_too_large` above the input cap.
74
+ */
75
+ export declare function sanitizeMailText(input: string, policy: GmailTextPolicy): GmailSanitizedText;
76
+ /**
77
+ * Use for every filename, label name and display field, after MIME decoding. Applies the same rules as
78
+ * `sanitizeMailText` to the complete value, folds each whitespace run to one space and trims, then applies the
79
+ * output cap.
80
+ *
81
+ * @param input One decoded metadata value.
82
+ * @param policy The input, line and output bounds.
83
+ * @returns The sanitized one-line value and content-free counts.
84
+ * @throws {GmailTextFault} `configuration` for an invalid policy, `input_too_large` above the input cap.
85
+ */
86
+ export declare function sanitizeMailMetadata(input: string, policy: GmailTextPolicy): GmailSanitizedText;
87
+ /**
88
+ * Input values must already have passed bounded MIME header decoding. Retains only Subject, Date, From, To and Cc,
89
+ * matched without regard to case, and sanitizes each as metadata: the first Subject (at most 200 characters) and Date
90
+ * (at most 1,000), and every From, To and Cc value joined with commas (at most 4,000 each), each also within the
91
+ * policy's output cap.
92
+ *
93
+ * @param headers At most 1,000 decoded headers, whose names and values together fit the input cap.
94
+ * @param policy The input, line and output bounds.
95
+ * @returns The five retained fields; a missing header is an empty string.
96
+ * @throws {GmailTextFault} `configuration` for an invalid policy, `input_too_large` for more than 1,000 headers or
97
+ * text above the input cap.
98
+ */
99
+ export declare function sanitizeMailHeaders(headers: readonly GmailHeaderInput[], policy: GmailTextPolicy): GmailSanitizedHeaders;
100
+ //# sourceMappingURL=mailSanitize.d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AACnE,yGAAyG;AACzG,qBAAa,cAAe,SAAQ,KAAK;IAE3B,QAAQ,CAAC,MAAM,EAAE,gBAAgB;IAD7C,sDAAsD;gBACjC,MAAM,EAAE,gBAAgB;CAG9C;AA4FD;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,eAAe,GAAG,kBAAkB,CA2C3F;AACD;;;;;;;;;GASG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,eAAe,GAAG,kBAAkB,CAM/F;AACD;;;;;;;;;;;GAWG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,SAAS,gBAAgB,EAAE,EAAE,MAAM,EAAE,eAAe,GAAG,qBAAqB,CAsBxH"}
@@ -0,0 +1,257 @@
1
+ /**
2
+ * @fileoverview Deterministic pre-storage sanitization of mail text: address tokens, credential assignments, known
3
+ * credential shapes, private-key blocks and long mixed tokens are replaced with fixed marks, and a final gate
4
+ * suppresses any line that still carries a credential cue. Every count is a number; no matched value, offset or
5
+ * reverse mapping is kept, nothing is logged and no model or network is called.
6
+ * @module agentos-ext-gmail-source/mailSanitize
7
+ */
8
+ /** A text helper's fixed refusal; its message is `gmail_text_<reason>` and never carries source text. */
9
+ export class GmailTextFault extends Error {
10
+ reason;
11
+ /** @param reason Why the helper refused its input. */
12
+ constructor(reason) {
13
+ super(`gmail_text_${reason}`);
14
+ this.reason = reason;
15
+ this.name = 'GmailTextFault';
16
+ }
17
+ }
18
+ const addressMark = '[address removed]';
19
+ const secretMark = '[secret removed]';
20
+ const lineMark = '[line removed by the secret gate]';
21
+ // Named character references decoded during canonicalization; any other name stays as written.
22
+ const namedEntities = Object.freeze({
23
+ amp: '&', lt: '<', gt: '>', quot: '"', apos: "'", commat: '@', period: '.',
24
+ colon: ':', sol: '/', bsol: '\\', equals: '=', percnt: '%', num: '#',
25
+ lowbar: '_', hyphen: '-', semi: ';', plus: '+', quest: '?', nbsp: ' ',
26
+ Tab: '\t', NewLine: '\n',
27
+ });
28
+ // Credential shapes replaced in place. They are a conservative policy, not a claim about every provider's format. A
29
+ // prefix right after a letter or digit is part of a word (`risk-adjusted`), not a credential. A JWT is matched only
30
+ // from the start of its run of token characters, so a long `-` joined run cannot make the scan quadratic.
31
+ const shapeSources = [
32
+ String.raw `(?<![A-Za-z0-9])(?:GOCSPX-|ya29\.|1//0|ghp_|github_pat_|xox[bpas]-|sk-ant-|sk-proj-|sk-|tvly-|whsec_)[A-Za-z0-9._~+/=-]{6,}`,
33
+ String.raw `\b(?:AKIA|ASIA)[A-Z0-9]{16}\b`,
34
+ String.raw `\bfc-[0-9a-f]{32}\b`,
35
+ String.raw `\bAIza[A-Za-z0-9_-]{20,}`,
36
+ String.raw `\bre_[A-Za-z0-9]{6,}_[A-Za-z0-9_]{10,}`,
37
+ String.raw `\b[rs]k_(?:live|test)_[A-Za-z0-9]{10,}`,
38
+ String.raw `(?<![A-Za-z0-9_-])eyJ[A-Za-z0-9_-]{4,}\.[A-Za-z0-9_-]{4,}\.[A-Za-z0-9_-]{4,}\b`,
39
+ ];
40
+ // A credential label followed by `:` or `=`: the whole line is replaced. The password words (also plural), `token`,
41
+ // `secret`, `secret key` and the compound labels count at the end of any identifier (`DB_PASSWORD=`, `PGPASSWORD=`,
42
+ // `GITHUB_TOKEN=`, `authToken:`, `SECRET_KEY=`, `Passwords:`). The short or common labels count only after a character
43
+ // other than a letter or digit, so `Compass:` and `Preauthorization:` stay.
44
+ const assignment = /(?:(?<![a-z0-9])(?:pass|pwd|pw|authorization|cookie|set-cookie|database[ _-]?url|signing[ _-]?key|one[ _-]?time[ _-]?code)|pass(?:word|wd|code|phrase)s?|api[ _-]?key|access[ _-]?(?:key|token)|refresh[ _-]?token|client[ _-]?secret|secret(?:[ _-]?key)?|token|auth[ _-]?key|provisioning[ _-]?key|verification[ _-]?code)["']?\s*[:=]\s*/i;
45
+ // The final gate's cues: a line still carrying one after replacement is suppressed whole. The password words (also
46
+ // plural) and the compound cues count at the end of any identifier (`DB_PASSWORD`, `rsaPrivateKey`); `bearer` and the
47
+ // SSH cues need a character other than a letter or digit before them. No cue continues into a letter or digit.
48
+ const residual = /(?:(?<![a-z0-9])(?:bearer|ssh-(?:rsa|ed25519)|sshpass)|pass(?:word|wd|phrase)s?|api[ _-]?(?:key|token)|access[ _-]?token|refresh[ _-]?token|client[ _-]?secret|private[ _-]?key)(?![a-z0-9])/i;
49
+ const beginKey = /-----BEGIN [A-Z0-9 ]*PRIVATE KEY-----/;
50
+ const endKey = /-----END [A-Z0-9 ]*PRIVATE KEY-----/;
51
+ // Encoded bytes still present after the bounded decoding passes.
52
+ const unresolved = /%[0-9a-f]{2}|&#(?:x[0-9a-f]+|[0-9]+);?/i;
53
+ // A named reference the decoder knows, still present after the passes: the text was nested deeper than four levels.
54
+ const unresolvedName = new RegExp(`&(?:${Object.keys(namedEntities).join('|')});`);
55
+ function validate(policy) {
56
+ for (const value of [policy.maxInputCharacters, policy.maxLineCharacters, policy.maxOutputCharacters]) {
57
+ if (!Number.isSafeInteger(value) || value < 1)
58
+ throw new GmailTextFault('configuration');
59
+ }
60
+ if (policy.maxInputCharacters > 2_097_152 || policy.maxLineCharacters > 65_536
61
+ || policy.maxOutputCharacters > policy.maxInputCharacters)
62
+ throw new GmailTextFault('configuration');
63
+ }
64
+ // At most four passes of percent and character-reference decoding, Unicode compatibility normalization, line-break
65
+ // unification and removal of format and control characters. The cap is checked before decoding and again after each
66
+ // pass, since normalization can lengthen text.
67
+ function canonical(input, limit) {
68
+ if (input.length > limit)
69
+ throw new GmailTextFault('input_too_large');
70
+ let text = input;
71
+ for (let pass = 0; pass < 4; pass++) {
72
+ const previous = text;
73
+ text = text.replace(/(?:%[0-9a-f]{2})+/gi, (run) => {
74
+ try {
75
+ return decodeURIComponent(run);
76
+ }
77
+ catch {
78
+ return run;
79
+ }
80
+ }).replace(/&(#x[0-9a-f]+|#[0-9]+|[a-z][a-z0-9]+);/gi, (whole, entity) => {
81
+ if (!entity.startsWith('#'))
82
+ return namedEntities[entity] ?? whole;
83
+ const hex = entity[1]?.toLowerCase() === 'x';
84
+ const point = Number.parseInt(entity.slice(hex ? 2 : 1), hex ? 16 : 10);
85
+ return Number.isSafeInteger(point) && point >= 0 && point <= 0x10ffff
86
+ && !(point >= 0xd800 && point <= 0xdfff) ? String.fromCodePoint(point) : whole;
87
+ });
88
+ text = text.normalize('NFKC').replace(/\r\n?/g, '\n').replace(/[\u2028\u2029]/g, '\n')
89
+ .replace(/\p{Cf}/gu, '').replace(/[\x00-\x08\x0b\x0c\x0e-\x1f\x7f-\x9f]/g, '');
90
+ if (text.length > limit)
91
+ throw new GmailTextFault('input_too_large');
92
+ if (text === previous)
93
+ break;
94
+ }
95
+ return text;
96
+ }
97
+ // Clips without leaving the high half of a surrogate pair at the end.
98
+ function clipped(text, maximum) {
99
+ let end = Math.min(text.length, maximum);
100
+ if (end > 0 && end < text.length && /[\uD800-\uDBFF]/.test(text[end - 1])
101
+ && /[\uDC00-\uDFFF]/.test(text[end]))
102
+ end--;
103
+ return text.slice(0, end);
104
+ }
105
+ // Whether the line holds a URL with a user name or password, or an unparsable URL with an `@`. The scheme is at most
106
+ // 64 characters, so a long run of scheme characters cannot make the scan quadratic; a longer one still leaves the `@`
107
+ // for the address rule.
108
+ function containsAuthenticatedUrl(line) {
109
+ for (const match of line.matchAll(/\b[a-z][a-z0-9+.-]{0,63}:\/\/[^\s<>"']+/gi)) {
110
+ try {
111
+ const url = new URL(match[0]);
112
+ if (url.username || url.password)
113
+ return true;
114
+ }
115
+ catch {
116
+ if (match[0].includes('@'))
117
+ return true;
118
+ }
119
+ }
120
+ return false;
121
+ }
122
+ /**
123
+ * Pure pre-storage transformation. It never records matched values or invokes a model.
124
+ *
125
+ * Decodes repeated percent and character-reference encoding (at most four passes), normalizes Unicode and line breaks,
126
+ * then works line by line: private-key blocks, credential assignments and authenticated URLs are replaced, credential
127
+ * shapes and long mixed tokens become `[secret removed]`, address tokens become `[address removed]`, and a line with
128
+ * unresolved encoded bytes or character references, above the line cap or still carrying a credential cue becomes
129
+ * `[line removed by the secret gate]`. An assignment with an empty value, a block scalar or an unclosed quote also
130
+ * suppresses the rest of the text. A replaced assignment and a line the final gate suppresses keep their quote markers
131
+ * (`>`). The complete input is checked before the output cap clips the result.
132
+ *
133
+ * @param input Decoded text: a body or one display field.
134
+ * @param policy The input, line and output bounds.
135
+ * @returns The sanitized text and content-free counts.
136
+ * @throws {GmailTextFault} `configuration` for an invalid policy, `input_too_large` above the input cap.
137
+ */
138
+ export function sanitizeMailText(input, policy) {
139
+ validate(policy);
140
+ const normalized = canonical(input, policy.maxInputCharacters);
141
+ let addressRedactions = 0;
142
+ let secretRedactions = 0;
143
+ let suppressedLines = 0;
144
+ let insideKey = false;
145
+ let credentialTail = false;
146
+ const lines = [];
147
+ for (const raw of normalized.split('\n')) {
148
+ if (credentialTail) {
149
+ suppressedLines++;
150
+ lines.push(lineMark);
151
+ continue;
152
+ }
153
+ if (insideKey || beginKey.test(raw)) {
154
+ if (!insideKey)
155
+ secretRedactions++;
156
+ insideKey = !endKey.test(raw);
157
+ lines.push(secretMark);
158
+ continue;
159
+ }
160
+ if (raw.length > policy.maxLineCharacters || unresolved.test(raw) || unresolvedName.test(raw)) {
161
+ suppressedLines++;
162
+ lines.push(lineMark);
163
+ continue;
164
+ }
165
+ // Preserve quote depth so removal cannot turn quoted history into fresh text.
166
+ const quote = raw.match(/^([ \t]*(?:>[ \t]*)+)/)?.[0] ?? '';
167
+ let line = raw.slice(quote.length);
168
+ if (assignment.test(line) || containsAuthenticatedUrl(line) || /\bsshpass\s+-p\b/i.test(line)) {
169
+ const found = assignment.exec(line);
170
+ const value = found ? line.slice(found.index + found[0].length).trim() : null;
171
+ credentialTail = value !== null && (value === '' || /^[|>][+-]?$/.test(value) || ((value[0] === '"' || value[0] === "'") && value.lastIndexOf(value[0]) === 0));
172
+ secretRedactions++;
173
+ lines.push(quote + secretMark);
174
+ continue;
175
+ }
176
+ for (const source of shapeSources) {
177
+ line = line.replace(new RegExp(source, 'g'), () => { secretRedactions++; return secretMark; });
178
+ }
179
+ line = line.replace(/[A-Za-z0-9_+/=-]{32,}/g, (token) => {
180
+ if ((/[a-z]/i.test(token) && /[0-9]/.test(token)) || /^[0-9a-f]{40,}$/i.test(token)) {
181
+ secretRedactions++;
182
+ return secretMark;
183
+ }
184
+ return token;
185
+ });
186
+ line = line.replace(/"[^"\n]{1,512}"\s*@[^\s<>;,"']+/gu, () => { addressRedactions++; return addressMark; });
187
+ line = line.replace(/[^\s<>;,"'()\[\]]+/gu, (token) => { if (!token.includes('@'))
188
+ return token; addressRedactions++; return addressMark; });
189
+ const inspected = line.split(secretMark).join('').split(lineMark).join('');
190
+ if (residual.test(inspected) || endKey.test(inspected)) {
191
+ suppressedLines++;
192
+ lines.push(quote + lineMark);
193
+ continue;
194
+ }
195
+ lines.push(quote + line);
196
+ }
197
+ const complete = lines.join('\n');
198
+ const text = clipped(complete, policy.maxOutputCharacters);
199
+ return { text, addressRedactions, secretRedactions, suppressedLines, truncated: text.length < complete.length };
200
+ }
201
+ /**
202
+ * Use for every filename, label name and display field, after MIME decoding. Applies the same rules as
203
+ * `sanitizeMailText` to the complete value, folds each whitespace run to one space and trims, then applies the
204
+ * output cap.
205
+ *
206
+ * @param input One decoded metadata value.
207
+ * @param policy The input, line and output bounds.
208
+ * @returns The sanitized one-line value and content-free counts.
209
+ * @throws {GmailTextFault} `configuration` for an invalid policy, `input_too_large` above the input cap.
210
+ */
211
+ export function sanitizeMailMetadata(input, policy) {
212
+ validate(policy);
213
+ const safe = sanitizeMailText(input, { ...policy, maxOutputCharacters: policy.maxInputCharacters });
214
+ const complete = safe.text.replace(/\s+/gu, ' ').trim();
215
+ const text = clipped(complete, policy.maxOutputCharacters);
216
+ return { ...safe, text, truncated: safe.truncated || text.length < complete.length };
217
+ }
218
+ /**
219
+ * Input values must already have passed bounded MIME header decoding. Retains only Subject, Date, From, To and Cc,
220
+ * matched without regard to case, and sanitizes each as metadata: the first Subject (at most 200 characters) and Date
221
+ * (at most 1,000), and every From, To and Cc value joined with commas (at most 4,000 each), each also within the
222
+ * policy's output cap.
223
+ *
224
+ * @param headers At most 1,000 decoded headers, whose names and values together fit the input cap.
225
+ * @param policy The input, line and output bounds.
226
+ * @returns The five retained fields; a missing header is an empty string.
227
+ * @throws {GmailTextFault} `configuration` for an invalid policy, `input_too_large` for more than 1,000 headers or
228
+ * text above the input cap.
229
+ */
230
+ export function sanitizeMailHeaders(headers, policy) {
231
+ validate(policy);
232
+ if (headers.length > 1000)
233
+ throw new GmailTextFault('input_too_large');
234
+ let characters = 0;
235
+ const retained = new Map();
236
+ for (const header of headers) {
237
+ characters += header.name.length + header.value.length;
238
+ if (characters > policy.maxInputCharacters)
239
+ throw new GmailTextFault('input_too_large');
240
+ const name = header.name.toLowerCase();
241
+ if (!['subject', 'date', 'from', 'to', 'cc'].includes(name))
242
+ continue;
243
+ const values = retained.get(name) ?? [];
244
+ values.push(header.value);
245
+ retained.set(name, values);
246
+ }
247
+ const field = (name, single, maximum) => {
248
+ const values = retained.get(name) ?? [];
249
+ const raw = single ? values[0] ?? '' : values.join(', ');
250
+ return sanitizeMailMetadata(raw, { ...policy, maxOutputCharacters: Math.min(maximum, policy.maxOutputCharacters) }).text;
251
+ };
252
+ return {
253
+ subject: field('subject', true, 200), date: field('date', true, 1000),
254
+ from: field('from', false, 4000), to: field('to', false, 4000), cc: field('cc', false, 4000),
255
+ };
256
+ }
257
+ //# sourceMappingURL=mailSanitize.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mailSanitize.js","sourceRoot":"","sources":["../src/mailSanitize.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AA4CH,yGAAyG;AACzG,MAAM,OAAO,cAAe,SAAQ,KAAK;IAElB;IADrB,sDAAsD;IACtD,YAAqB,MAAwB;QAC3C,KAAK,CAAC,cAAc,MAAM,EAAE,CAAC,CAAC;QADX,WA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a trailing quote block after
3
+ * a blank line and a short signature after its exact separator are removed; explicit forwards, inline answers and
4
+ * ambiguous prose stay. Nothing is summarized or rewritten, so a quote span refers to the returned text.
5
+ * @module agentos-ext-gmail-source/messageText
6
+ */
7
+ import { type GmailSanitizedText, type GmailTextPolicy } from './mailSanitize.js';
8
+ /** A sanitized, trimmed message body, its content-free counts and what trimming removed. */
9
+ export interface GmailMessageText extends GmailSanitizedText {
10
+ /** Whether recognized reply history or a trailing quote block was removed. */
11
+ readonly trimmedQuote: boolean;
12
+ /** Whether a short signature after its exact separator, or a final known mobile signature line, was removed. */
13
+ readonly trimmedSignature: boolean;
14
+ }
15
+ /**
16
+ * Sanitizes a decoded body with `sanitizeMailText`, then trims recognized reply history and short signatures, then
17
+ * applies the output cap without splitting a surrogate pair. A body with an explicit forward marker is not trimmed.
18
+ * Ambiguous prose, sign-offs, unmarked header-looking paragraphs and inline answers stay; nothing is summarized or
19
+ * rewritten, so quote offsets refer to the returned text.
20
+ *
21
+ * @param input A decoded plain-text body, or the inert text of an HTML body.
22
+ * @param policy The input, line and output bounds.
23
+ * @returns The retained text, the sanitizer counts and what trimming and the cap removed.
24
+ * @throws {GmailTextFault} `configuration` for an invalid policy, `input_too_large` above the input cap.
25
+ */
26
+ export declare function messageText(input: string, policy: GmailTextPolicy): GmailMessageText;
27
+ //# sourceMappingURL=messageText.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"messageText.d.ts","sourceRoot":"","sources":["../src/messageText.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAoB,KAAK,kBAAkB,EAAE,KAAK,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEpG,4FAA4F;AAC5F,MAAM,WAAW,gBAAiB,SAAQ,kBAAkB;IAC1D,8EAA8E;IAC9E,QAAQ,CAAC,YAAY,EAAE,OAAO,CAAC;IAC/B,gHAAgH;IAChH,QAAQ,CAAC,gBAAgB,EAAE,OAAO,CAAC;CACpC;AAkFD;;;;;;;;;;GAUG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,eAAe,GAAG,gBAAgB,CAgBpF"}
@@ -0,0 +1,153 @@
1
+ /**
2
+ * @fileoverview Conservative trimming of a sanitized mail body: recognized reply history, a trailing quote block after
3
+ * a blank line and a short signature after its exact separator are removed; explicit forwards, inline answers and
4
+ * ambiguous prose stay. Nothing is summarized or rewritten, so a quote span refers to the returned text.
5
+ * @module agentos-ext-gmail-source/messageText
6
+ */
7
+ import { sanitizeMailText } from './mailSanitize.js';
8
+ // Explicit forward markers, after any quote prefix: they protect the whole body from trimming.
9
+ const forward = /^(?:-{2,}[ \t]*)?(?:forwarded message|begin forwarded message:|转发邮件|转寄邮件)(?:[ \t:-]|$)/i;
10
+ // An original-message separator; it counts only when structured headers follow it.
11
+ const original = /^[ \t]*-{2,}[ \t]*(?:Original Message|Replied Message)[ \t]*-{2,}[ \t]*$/i;
12
+ // A known mobile signature, recognized only as the final line after a blank line.
13
+ const mobile = /^(?:Sent from my iPhone|Sent from my iPad|Sent from my Android)$/i;
14
+ const blank = (line) => line.trim().length === 0;
15
+ const quoted = (line) => /^[ \t]*>/.test(line);
16
+ function trimBlank(lines) {
17
+ let start = 0;
18
+ let end = lines.length;
19
+ while (start < end && blank(lines[start]))
20
+ start++;
21
+ while (end > start && blank(lines[end - 1]))
22
+ end--;
23
+ return lines.slice(start, end);
24
+ }
25
+ // Whether From, Sent or Date, and To or Subject header lines follow the separator before the first blank line.
26
+ function structuredHeaders(lines, start) {
27
+ const found = new Set();
28
+ for (let i = start; i < Math.min(start + 8, lines.length); i++) {
29
+ const line = lines[i];
30
+ if (blank(line)) {
31
+ if (found.size > 0)
32
+ break;
33
+ else
34
+ continue;
35
+ }
36
+ const header = line.match(/^[ \t]*(From|Sent|Date|To|Subject):[ \t]*\S/i);
37
+ if (!header)
38
+ return false;
39
+ found.add(header[1].toLowerCase());
40
+ }
41
+ return found.has('from') && (found.has('sent') || found.has('date'))
42
+ && (found.has('to') || found.has('subject'));
43
+ }
44
+ // The index after a reply introducer at `index`: "On ... wrote:" on one line or wrapped over two short lines.
45
+ function replyEnd(lines, index) {
46
+ const first = lines[index];
47
+ if (first.length <= 300 && /^[ \t]*On .+ wrote:[ \t]*$/i.test(first))
48
+ return index + 1;
49
+ const second = lines[index + 1];
50
+ if (second !== undefined && first.length <= 220 && second.length <= 220
51
+ && /^[ \t]*On .+/i.test(first) && /.+ wrote:[ \t]*$/i.test(second))
52
+ return index + 2;
53
+ return null;
54
+ }
55
+ // Removes reply history only when every nonblank line after its introducer is quoted, or a structured original
56
+ // message, then a trailing quote block that follows a blank line; a body that is only quotes stays.
57
+ function cutQuotes(input) {
58
+ let lines = [...input];
59
+ let changed = false;
60
+ let lastUnquoted = -1;
61
+ let lastNonblank = -1;
62
+ for (let j = 0; j < lines.length; j++) {
63
+ if (!blank(lines[j])) {
64
+ lastNonblank = j;
65
+ if (!quoted(lines[j]))
66
+ lastUnquoted = j;
67
+ }
68
+ }
69
+ for (let i = 1; i < lines.length; i++) {
70
+ if (!blank(lines[i - 1]))
71
+ continue;
72
+ const end = replyEnd(lines, i);
73
+ if (end !== null) {
74
+ const tailIsQuoted = end > lastUnquoted && end <= lastNonblank;
75
+ if (tailIsQuoted) {
76
+ lines = trimBlank(lines.slice(0, i));
77
+ changed = true;
78
+ break;
79
+ }
80
+ }
81
+ if (original.test(lines[i]) && structuredHeaders(lines, i + 1)) {
82
+ lines = trimBlank(lines.slice(0, i));
83
+ changed = true;
84
+ break;
85
+ }
86
+ }
87
+ let cursor = lines.length;
88
+ let count = 0;
89
+ while (cursor > 0 && (blank(lines[cursor - 1]) || quoted(lines[cursor - 1]))) {
90
+ if (quoted(lines[cursor - 1]))
91
+ count++;
92
+ cursor--;
93
+ }
94
+ if (count > 0 && cursor > 0 && cursor < lines.length && blank(lines[cursor])) {
95
+ lines = trimBlank(lines.slice(0, cursor));
96
+ changed = true;
97
+ }
98
+ return { lines, changed };
99
+ }
100
+ // Removes at most 12 short unquoted lines after an exact "-- " line that follows a blank line, or a final known
101
+ // mobile signature line.
102
+ function cutSignature(input) {
103
+ const lines = [...input];
104
+ for (let i = 1; i < lines.length; i++) {
105
+ if (lines[i] !== '-- ' || !blank(lines[i - 1]) || lines.length - i - 1 > 12)
106
+ continue;
107
+ const suffix = lines.slice(i + 1);
108
+ if (suffix.length <= 12 && suffix.join('\n').length <= 1000 && !suffix.some(quoted)) {
109
+ return { lines: trimBlank(lines.slice(0, i)), changed: true };
110
+ }
111
+ }
112
+ const last = lines.length - 1;
113
+ if (last >= 2 && mobile.test(lines[last].trim()) && blank(lines[last - 1])
114
+ && lines.slice(0, last - 1).some((line) => !blank(line))) {
115
+ return { lines: trimBlank(lines.slice(0, last - 1)), changed: true };
116
+ }
117
+ return { lines, changed: false };
118
+ }
119
+ /**
120
+ * Sanitizes a decoded body with `sanitizeMailText`, then trims recognized reply history and short signatures, then
121
+ * applies the output cap without splitting a surrogate pair. A body with an explicit forward marker is not trimmed.
122
+ * Ambiguous prose, sign-offs, unmarked header-looking paragraphs and inline answers stay; nothing is summarized or
123
+ * rewritten, so quote offsets refer to the returned text.
124
+ *
125
+ * @param input A decoded plain-text body, or the inert text of an HTML body.
126
+ * @param policy The input, line and output bounds.
127
+ * @returns The retained text, the sanitizer counts and what trimming and the cap removed.
128
+ * @throws {GmailTextFault} `configuration` for an invalid policy, `input_too_large` above the input cap.
129
+ */
130
+ export function messageText(input, policy) {
131
+ // Validate the caller's output cap before temporarily widening it for trimming.
132
+ sanitizeMailText('', policy);
133
+ const safe = sanitizeMailText(input, { ...policy, maxOutputCharacters: policy.maxInputCharacters });
134
+ let lines = trimBlank(safe.text.split('\n'));
135
+ let trimmedQuote = false;
136
+ let trimmedSignature = false;
137
+ if (!lines.some((line) => forward.test(line.replace(/^[ \t>]*/, '')))) {
138
+ const quotes = cutQuotes(lines);
139
+ lines = quotes.lines;
140
+ trimmedQuote = quotes.changed;
141
+ const signature = cutSignature(lines);
142
+ lines = signature.lines;
143
+ trimmedSignature = signature.changed;
144
+ }
145
+ const complete = lines.join('\n');
146
+ let end = Math.min(complete.length, policy.maxOutputCharacters);
147
+ if (end > 0 && end < complete.length && /[\uD800-\uDBFF]/.test(complete[end - 1])
148
+ && /[\uDC00-\uDFFF]/.test(complete[end]))
149
+ end--;
150
+ const text = complete.slice(0, end);
151
+ return { ...safe, text, truncated: safe.truncated || text.length < complete.length, trimmedQuote, trimmedSignature };
152
+ }
153
+ //# sourceMappingURL=messageText.js.map