@tangle-network/agent-app 3.0.30 → 3.0.32
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/dist/chat-routes/index.d.ts +1 -0
- package/dist/chat-routes/index.js +6 -1
- package/dist/chat-routes/index.js.map +1 -1
- package/dist/chat-routes/redact-values.d.ts +6 -0
- package/dist/chat-routes/turn-route-contracts.d.ts +8 -0
- package/dist/chunk-M4QITAQV.js +193 -0
- package/dist/chunk-M4QITAQV.js.map +1 -0
- package/dist/{chunk-LRUH36LD.js → chunk-S4QFJSLR.js} +27 -6
- package/dist/chunk-S4QFJSLR.js.map +1 -0
- package/dist/public-consultation/index.d.ts +1 -1
- package/dist/public-consultation/index.js +2 -1
- package/dist/public-consultation/index.js.map +1 -1
- package/dist/workspace-export/index.js +6 -186
- package/dist/workspace-export/index.js.map +1 -1
- package/package.json +1 -1
- package/dist/chunk-LRUH36LD.js.map +0 -1
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export type ValueRedactor = <T>(value: T) => T;
|
|
2
|
+
/** A redactor for these values, or undefined when none qualifies: object keys and string values alike. Longest first, so
|
|
3
|
+
* a value that contains another wins. */
|
|
4
|
+
export declare function valueRedactor(values: readonly string[] | undefined): ValueRedactor | undefined;
|
|
5
|
+
/** Every event of a stream, redacted. A value split across two text deltas is caught where the turn is stored, not live. */
|
|
6
|
+
export declare function redactEvents<T>(source: AsyncIterable<T>, redact: ValueRedactor): AsyncGenerator<T>;
|
|
@@ -724,6 +724,14 @@ export interface CreateChatTurnRoutesOptions<TContext = void, TResource = unknow
|
|
|
724
724
|
/** Pre-persist transform of the final text (e.g. `/redact`'s `redactPII`).
|
|
725
725
|
* Live stream is never altered. */
|
|
726
726
|
transformFinalText?(text: string): string | Promise<string>;
|
|
727
|
+
/** Secret values this turn could expose (a credential the product placed in its box's environment). Every
|
|
728
|
+
* occurrence becomes `[redacted]` in the live stream, the turn buffer, the draft and the stored row, matched by value,
|
|
729
|
+
* never by pattern; values under 8 characters are ignored. The product redacts its own history reads the same way. */
|
|
730
|
+
redactValues?(turn: {
|
|
731
|
+
tenantId: string;
|
|
732
|
+
userId: string;
|
|
733
|
+
threadId: string;
|
|
734
|
+
}): readonly string[] | Promise<readonly string[]>;
|
|
727
735
|
/** Post-processing after a turn settles (billing, titles, audit). Fires with
|
|
728
736
|
* `failed:true` + `failureReason` when the turn carried a terminal error
|
|
729
737
|
* event (model 402 / rate-limit / server error) instead of a clean
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
// src/workspace-export/secrets.ts
|
|
2
|
+
var REDACTED = "[redacted]";
|
|
3
|
+
var MASK_BYTE = 42;
|
|
4
|
+
var CREDENTIAL_PATTERNS = [
|
|
5
|
+
String.raw`sk-ant-[A-Za-z0-9_-]{16,}`,
|
|
6
|
+
String.raw`sk-(?:proj-|tan-|or-v1-|svcacct-)?[A-Za-z0-9_-]{20,}`,
|
|
7
|
+
String.raw`(?:sk|rk)_(?:live|test|sb)_[A-Za-z0-9_]{12,}`,
|
|
8
|
+
String.raw`whsec_[A-Za-z0-9+/=]{16,}`,
|
|
9
|
+
String.raw`gh[pousr]_[A-Za-z0-9]{30,}`,
|
|
10
|
+
String.raw`github_pat_[A-Za-z0-9_]{40,}`,
|
|
11
|
+
String.raw`xox[abposr]-[A-Za-z0-9-]{10,}`,
|
|
12
|
+
String.raw`AKIA[0-9A-Z]{16}`,
|
|
13
|
+
String.raw`AIza[0-9A-Za-z_-]{35}`,
|
|
14
|
+
String.raw`ya29\.[0-9A-Za-z_-]{20,}`,
|
|
15
|
+
String.raw`glpat-[A-Za-z0-9_-]{20,}`,
|
|
16
|
+
String.raw`npm_[A-Za-z0-9]{36}`,
|
|
17
|
+
String.raw`hf_[A-Za-z0-9]{30,}`,
|
|
18
|
+
String.raw`r8_[A-Za-z0-9]{30,}`,
|
|
19
|
+
String.raw`gsk_[A-Za-z0-9]{40,}`,
|
|
20
|
+
String.raw`xai-[A-Za-z0-9]{40,}`,
|
|
21
|
+
String.raw`lak_[A-Za-z0-9_-]{16,}`,
|
|
22
|
+
String.raw`eyJ[A-Za-z0-9_-]{10,}\.eyJ[A-Za-z0-9_-]{10,}\.[A-Za-z0-9_-]{10,}`,
|
|
23
|
+
String.raw`-----BEGIN [A-Z0-9 ]*PRIVATE KEY-----[A-Za-z0-9+/=\r\n\t ]*(?:-----END [A-Z0-9 ]*PRIVATE KEY-----)?`
|
|
24
|
+
];
|
|
25
|
+
var SECRET_NAME = /(^|_)(secret|secrets|password|passwd|passphrase|token|credential|credentials|ciphertext|encrypted|bearer|apikey|privatekey|cookie)(_|$)|api_?key|private_?key|(key|secret|token|password|challenge|state|nonce|credential)_(hash|digest)$/;
|
|
26
|
+
var TOKEN_METRIC = /token_(count|counts|usage|budget|limit|cost)$|^(input|output|total|max|prompt|completion|reasoning|cached)_tokens?$/;
|
|
27
|
+
function snake(name) {
|
|
28
|
+
return name.replace(/([a-z0-9])([A-Z])/g, "$1_$2").replace(/[-\s.]+/g, "_").toLowerCase();
|
|
29
|
+
}
|
|
30
|
+
function isSecretName(name) {
|
|
31
|
+
const folded = snake(name);
|
|
32
|
+
if (TOKEN_METRIC.test(folded)) return false;
|
|
33
|
+
return SECRET_NAME.test(folded);
|
|
34
|
+
}
|
|
35
|
+
function escapeRegExp(value) {
|
|
36
|
+
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
37
|
+
}
|
|
38
|
+
function createSecretScanner(options = {}) {
|
|
39
|
+
const known = [...new Set(options.knownSecrets ?? [])].filter((s) => typeof s === "string" && s.length >= 8).sort((a, b) => b.length - a.length).map(escapeRegExp);
|
|
40
|
+
const source = [...known, ...CREDENTIAL_PATTERNS].join("|");
|
|
41
|
+
const pattern = () => new RegExp(source, "g");
|
|
42
|
+
function maskText(text) {
|
|
43
|
+
let count = 0;
|
|
44
|
+
const out = text.replace(pattern(), () => {
|
|
45
|
+
count += 1;
|
|
46
|
+
return REDACTED;
|
|
47
|
+
});
|
|
48
|
+
return { text: out, count };
|
|
49
|
+
}
|
|
50
|
+
function redactJson(value, depth) {
|
|
51
|
+
if (typeof value === "string") {
|
|
52
|
+
const masked = maskText(value);
|
|
53
|
+
return { value: masked.text, count: masked.count };
|
|
54
|
+
}
|
|
55
|
+
if (depth > 64 || value === null || typeof value !== "object") return { value, count: 0 };
|
|
56
|
+
let count = 0;
|
|
57
|
+
if (Array.isArray(value)) {
|
|
58
|
+
const out2 = value.map((item) => {
|
|
59
|
+
const result = redactJson(item, depth + 1);
|
|
60
|
+
count += result.count;
|
|
61
|
+
return result.value;
|
|
62
|
+
});
|
|
63
|
+
return { value: out2, count };
|
|
64
|
+
}
|
|
65
|
+
const out = {};
|
|
66
|
+
for (const [key, item] of Object.entries(value)) {
|
|
67
|
+
if (isSecretName(key) && item !== null && item !== "" && typeof item !== "boolean") {
|
|
68
|
+
out[key] = REDACTED;
|
|
69
|
+
count += 1;
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
72
|
+
const result = redactJson(item, depth + 1);
|
|
73
|
+
out[key] = result.value;
|
|
74
|
+
count += result.count;
|
|
75
|
+
}
|
|
76
|
+
return { value: out, count };
|
|
77
|
+
}
|
|
78
|
+
function redactValue(value) {
|
|
79
|
+
if (typeof value === "string") {
|
|
80
|
+
const trimmed = value.trimStart();
|
|
81
|
+
if (trimmed.startsWith("{") || trimmed.startsWith("[")) {
|
|
82
|
+
try {
|
|
83
|
+
const parsed = JSON.parse(value);
|
|
84
|
+
const result = redactJson(parsed, 0);
|
|
85
|
+
return result.count ? { value: JSON.stringify(result.value), count: result.count } : { value, count: 0 };
|
|
86
|
+
} catch {
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
const masked = maskText(value);
|
|
90
|
+
return { value: masked.text, count: masked.count };
|
|
91
|
+
}
|
|
92
|
+
if (value instanceof Uint8Array || value instanceof ArrayBuffer) return { value, count: 0 };
|
|
93
|
+
return redactJson(value, 0);
|
|
94
|
+
}
|
|
95
|
+
function maskBytes(onMask) {
|
|
96
|
+
const window = 8192;
|
|
97
|
+
const maxCarry = 65536;
|
|
98
|
+
let carry = new Uint8Array(0);
|
|
99
|
+
function scan(buffer, final) {
|
|
100
|
+
const text = decodeBytes(buffer);
|
|
101
|
+
const regex = pattern();
|
|
102
|
+
let emitEnd = final ? buffer.length : Math.max(0, buffer.length - window);
|
|
103
|
+
let masked = 0;
|
|
104
|
+
for (let match = regex.exec(text); match; match = regex.exec(text)) {
|
|
105
|
+
const start = match.index;
|
|
106
|
+
const end = start + match[0].length;
|
|
107
|
+
if (match[0].length === 0) {
|
|
108
|
+
regex.lastIndex += 1;
|
|
109
|
+
continue;
|
|
110
|
+
}
|
|
111
|
+
if (!final && end === buffer.length) {
|
|
112
|
+
emitEnd = Math.min(emitEnd, start);
|
|
113
|
+
break;
|
|
114
|
+
}
|
|
115
|
+
buffer.fill(MASK_BYTE, start, end);
|
|
116
|
+
masked += 1;
|
|
117
|
+
}
|
|
118
|
+
if (masked) onMask(masked);
|
|
119
|
+
if (!final && buffer.length - emitEnd > maxCarry) emitEnd = buffer.length - window;
|
|
120
|
+
return emitEnd;
|
|
121
|
+
}
|
|
122
|
+
const block = 256 * 1024;
|
|
123
|
+
let pending = [];
|
|
124
|
+
let pendingLength = 0;
|
|
125
|
+
function drain(controller, final) {
|
|
126
|
+
const buffer = new Uint8Array(carry.length + pendingLength);
|
|
127
|
+
buffer.set(carry, 0);
|
|
128
|
+
let offset = carry.length;
|
|
129
|
+
for (const part of pending) {
|
|
130
|
+
buffer.set(part, offset);
|
|
131
|
+
offset += part.length;
|
|
132
|
+
}
|
|
133
|
+
pending = [];
|
|
134
|
+
pendingLength = 0;
|
|
135
|
+
const emitEnd = scan(buffer, final);
|
|
136
|
+
if (emitEnd > 0) controller.enqueue(buffer.slice(0, emitEnd));
|
|
137
|
+
carry = buffer.slice(emitEnd);
|
|
138
|
+
}
|
|
139
|
+
return new TransformStream({
|
|
140
|
+
transform(chunk, controller) {
|
|
141
|
+
pending.push(chunk);
|
|
142
|
+
pendingLength += chunk.length;
|
|
143
|
+
if (pendingLength >= block) drain(controller, false);
|
|
144
|
+
},
|
|
145
|
+
flush(controller) {
|
|
146
|
+
if (carry.length || pendingLength) drain(controller, true);
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
return { maskText, redactValue, maskBytes };
|
|
151
|
+
}
|
|
152
|
+
var nativeLatin1 = (() => {
|
|
153
|
+
try {
|
|
154
|
+
const decoder = new TextDecoder("latin1");
|
|
155
|
+
return decoder.decode(new Uint8Array([65, 128, 255])).length === 3 ? decoder : null;
|
|
156
|
+
} catch {
|
|
157
|
+
return null;
|
|
158
|
+
}
|
|
159
|
+
})();
|
|
160
|
+
function decodeBytes(buffer) {
|
|
161
|
+
if (nativeLatin1) return nativeLatin1.decode(buffer);
|
|
162
|
+
let text = "";
|
|
163
|
+
for (let i = 0; i < buffer.length; i += 8192) text += String.fromCharCode(...buffer.subarray(i, i + 8192));
|
|
164
|
+
return text;
|
|
165
|
+
}
|
|
166
|
+
var CREDENTIAL_FILES = [
|
|
167
|
+
/(^|\/)\.git-credentials$/,
|
|
168
|
+
/(^|\/)\.netrc$/,
|
|
169
|
+
/(^|\/)\.pgpass$/,
|
|
170
|
+
/(^|\/)\.npmrc$/,
|
|
171
|
+
/(^|\/)\.pypirc$/,
|
|
172
|
+
/(^|\/)\.docker\/config\.json$/,
|
|
173
|
+
/(^|\/)\.aws\/credentials$/,
|
|
174
|
+
/(^|\/)\.kube\/config$/,
|
|
175
|
+
/(^|\/)\.config\/gh\/hosts\.ya?ml$/,
|
|
176
|
+
/(^|\/)\.codex\/auth\.json$/,
|
|
177
|
+
/(^|\/)\.claude\/\.credentials\.json$/,
|
|
178
|
+
/(^|\/)opencode\/auth\.json$/,
|
|
179
|
+
/(^|\/)\.ssh\/id_[^/]*$/
|
|
180
|
+
];
|
|
181
|
+
function isCredentialFile(path) {
|
|
182
|
+
const normalized = path.replace(/^\.\//, "");
|
|
183
|
+
if (normalized.endsWith(".pub")) return false;
|
|
184
|
+
return CREDENTIAL_FILES.some((pattern) => pattern.test(normalized));
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
export {
|
|
188
|
+
REDACTED,
|
|
189
|
+
isSecretName,
|
|
190
|
+
createSecretScanner,
|
|
191
|
+
isCredentialFile
|
|
192
|
+
};
|
|
193
|
+
//# sourceMappingURL=chunk-M4QITAQV.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/workspace-export/secrets.ts"],"sourcesContent":["/**\n * Keeps credentials out of workspace exports.\n *\n * Three layers, applied to every byte an export writes:\n * 1. Column and JSON-key names that hold credentials are replaced with\n * `[redacted]` (`password`, `*_token`, `*_api_key`, `*_ciphertext`, ...).\n * 2. Values that look like credentials (provider key prefixes, JWTs, private\n * keys) and the exact values the product passes as `knownSecrets` are masked\n * wherever they appear: in row values, in nested JSON, and in file bytes.\n * 3. Well-known credential files inside a sandbox tar are blanked.\n *\n * Byte masking is same-length (`*`), so tar headers and offsets stay valid.\n * Everything here fails toward redaction: a false positive costs the owner one\n * masked value; a false negative would publish a credential.\n */\n\nexport const REDACTED = '[redacted]'\nconst MASK_BYTE = 0x2a\n\nconst CREDENTIAL_PATTERNS: readonly string[] = [\n String.raw`sk-ant-[A-Za-z0-9_-]{16,}`,\n String.raw`sk-(?:proj-|tan-|or-v1-|svcacct-)?[A-Za-z0-9_-]{20,}`,\n String.raw`(?:sk|rk)_(?:live|test|sb)_[A-Za-z0-9_]{12,}`,\n String.raw`whsec_[A-Za-z0-9+/=]{16,}`,\n String.raw`gh[pousr]_[A-Za-z0-9]{30,}`,\n String.raw`github_pat_[A-Za-z0-9_]{40,}`,\n String.raw`xox[abposr]-[A-Za-z0-9-]{10,}`,\n String.raw`AKIA[0-9A-Z]{16}`,\n String.raw`AIza[0-9A-Za-z_-]{35}`,\n String.raw`ya29\\.[0-9A-Za-z_-]{20,}`,\n String.raw`glpat-[A-Za-z0-9_-]{20,}`,\n String.raw`npm_[A-Za-z0-9]{36}`,\n String.raw`hf_[A-Za-z0-9]{30,}`,\n String.raw`r8_[A-Za-z0-9]{30,}`,\n String.raw`gsk_[A-Za-z0-9]{40,}`,\n String.raw`xai-[A-Za-z0-9]{40,}`,\n String.raw`lak_[A-Za-z0-9_-]{16,}`,\n String.raw`eyJ[A-Za-z0-9_-]{10,}\\.eyJ[A-Za-z0-9_-]{10,}\\.[A-Za-z0-9_-]{10,}`,\n String.raw`-----BEGIN [A-Z0-9 ]*PRIVATE KEY-----[A-Za-z0-9+/=\\r\\n\\t ]*(?:-----END [A-Z0-9 ]*PRIVATE KEY-----)?`,\n]\n\n/** Names whose value is a credential, after camelCase is folded to snake_case. */\nconst SECRET_NAME =\n /(^|_)(secret|secrets|password|passwd|passphrase|token|credential|credentials|ciphertext|encrypted|bearer|apikey|privatekey|cookie)(_|$)|api_?key|private_?key|(key|secret|token|password|challenge|state|nonce|credential)_(hash|digest)$/\n/** Usage counters that merely mention tokens. */\nconst TOKEN_METRIC = /token_(count|counts|usage|budget|limit|cost)$|^(input|output|total|max|prompt|completion|reasoning|cached)_tokens?$/\n\nfunction snake(name: string): string {\n return name\n .replace(/([a-z0-9])([A-Z])/g, '$1_$2')\n .replace(/[-\\s.]+/g, '_')\n .toLowerCase()\n}\n\n/** True when a column or JSON key named `name` holds a credential. */\nexport function isSecretName(name: string): boolean {\n const folded = snake(name)\n if (TOKEN_METRIC.test(folded)) return false\n return SECRET_NAME.test(folded)\n}\n\nfunction escapeRegExp(value: string): string {\n return value.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&')\n}\n\nexport interface SecretScanner {\n /** Replace credential-shaped substrings. Returns the count replaced. */\n maskText(text: string): { text: string; count: number }\n /** Redact a row or any JSON value: credential names and credential values. */\n redactValue(value: unknown): { value: unknown; count: number }\n /** A same-length byte masker for file contents. `onMask` receives each count. */\n maskBytes(onMask: (count: number) => void): TransformStream<Uint8Array, Uint8Array>\n}\n\n/**\n * Build the scanner for one export. `knownSecrets` are exact values the product\n * holds (its own API keys, the workspace's sandbox key) that must never appear,\n * whatever their shape. Values shorter than 8 characters are ignored.\n */\nexport function createSecretScanner(options: { knownSecrets?: readonly string[] } = {}): SecretScanner {\n const known = [...new Set(options.knownSecrets ?? [])]\n .filter((s) => typeof s === 'string' && s.length >= 8)\n .sort((a, b) => b.length - a.length)\n .map(escapeRegExp)\n const source = [...known, ...CREDENTIAL_PATTERNS].join('|')\n const pattern = () => new RegExp(source, 'g')\n\n function maskText(text: string): { text: string; count: number } {\n let count = 0\n const out = text.replace(pattern(), () => {\n count += 1\n return REDACTED\n })\n return { text: out, count }\n }\n\n function redactJson(value: unknown, depth: number): { value: unknown; count: number } {\n if (typeof value === 'string') {\n const masked = maskText(value)\n return { value: masked.text, count: masked.count }\n }\n if (depth > 64 || value === null || typeof value !== 'object') return { value, count: 0 }\n let count = 0\n if (Array.isArray(value)) {\n const out = value.map((item) => {\n const result = redactJson(item, depth + 1)\n count += result.count\n return result.value\n })\n return { value: out, count }\n }\n const out: Record<string, unknown> = {}\n for (const [key, item] of Object.entries(value)) {\n if (isSecretName(key) && item !== null && item !== '' && typeof item !== 'boolean') {\n out[key] = REDACTED\n count += 1\n continue\n }\n const result = redactJson(item, depth + 1)\n out[key] = result.value\n count += result.count\n }\n return { value: out, count }\n }\n\n function redactValue(value: unknown): { value: unknown; count: number } {\n if (typeof value === 'string') {\n const trimmed = value.trimStart()\n if (trimmed.startsWith('{') || trimmed.startsWith('[')) {\n try {\n const parsed = JSON.parse(value) as unknown\n const result = redactJson(parsed, 0)\n return result.count ? { value: JSON.stringify(result.value), count: result.count } : { value, count: 0 }\n } catch {\n // Not JSON; scan it as text.\n }\n }\n const masked = maskText(value)\n return { value: masked.text, count: masked.count }\n }\n if (value instanceof Uint8Array || value instanceof ArrayBuffer) return { value, count: 0 }\n return redactJson(value, 0)\n }\n\n function maskBytes(onMask: (count: number) => void): TransformStream<Uint8Array, Uint8Array> {\n // Keep a tail so a credential split across two chunks is seen whole.\n const window = 8192\n const maxCarry = 65536\n let carry = new Uint8Array(0)\n\n function scan(buffer: Uint8Array, final: boolean): number {\n const text = decodeBytes(buffer)\n const regex = pattern()\n let emitEnd = final ? buffer.length : Math.max(0, buffer.length - window)\n let masked = 0\n for (let match = regex.exec(text); match; match = regex.exec(text)) {\n const start = match.index\n const end = start + match[0].length\n if (match[0].length === 0) {\n regex.lastIndex += 1\n continue\n }\n if (!final && end === buffer.length) {\n // Possibly truncated; leave it for the next chunk to see whole.\n emitEnd = Math.min(emitEnd, start)\n break\n }\n buffer.fill(MASK_BYTE, start, end)\n masked += 1\n }\n if (masked) onMask(masked)\n if (!final && buffer.length - emitEnd > maxCarry) emitEnd = buffer.length - window\n return emitEnd\n }\n\n // Decompressors emit small chunks. Scanning each one re-reads the carry\n // window, which cost 4x on 4 KiB chunks, so input is gathered into blocks.\n const block = 256 * 1024\n let pending: Uint8Array[] = []\n let pendingLength = 0\n\n function drain(controller: TransformStreamDefaultController<Uint8Array>, final: boolean) {\n const buffer = new Uint8Array(carry.length + pendingLength)\n buffer.set(carry, 0)\n let offset = carry.length\n for (const part of pending) {\n buffer.set(part, offset)\n offset += part.length\n }\n pending = []\n pendingLength = 0\n const emitEnd = scan(buffer, final)\n if (emitEnd > 0) controller.enqueue(buffer.slice(0, emitEnd))\n carry = buffer.slice(emitEnd)\n }\n\n return new TransformStream<Uint8Array, Uint8Array>({\n transform(chunk, controller) {\n pending.push(chunk)\n pendingLength += chunk.length\n if (pendingLength >= block) drain(controller, false)\n },\n flush(controller) {\n if (carry.length || pendingLength) drain(controller, true)\n },\n })\n }\n\n return { maskText, redactValue, maskBytes }\n}\n\n/**\n * One UTF-16 code unit per byte, so string indexes are byte offsets. A native\n * windows-1252 decoder keeps that property and is several times faster; the\n * manual decode covers runtimes whose TextDecoder lacks it.\n */\nconst nativeLatin1 = (() => {\n try {\n const decoder = new TextDecoder('latin1')\n return decoder.decode(new Uint8Array([0x41, 0x80, 0xff])).length === 3 ? decoder : null\n } catch {\n return null\n }\n})()\n\nfunction decodeBytes(buffer: Uint8Array): string {\n if (nativeLatin1) return nativeLatin1.decode(buffer)\n let text = ''\n for (let i = 0; i < buffer.length; i += 8192) text += String.fromCharCode(...buffer.subarray(i, i + 8192))\n return text\n}\n\n/** Credential stores that are blanked wholesale inside a sandbox archive. */\nconst CREDENTIAL_FILES = [\n /(^|\\/)\\.git-credentials$/,\n /(^|\\/)\\.netrc$/,\n /(^|\\/)\\.pgpass$/,\n /(^|\\/)\\.npmrc$/,\n /(^|\\/)\\.pypirc$/,\n /(^|\\/)\\.docker\\/config\\.json$/,\n /(^|\\/)\\.aws\\/credentials$/,\n /(^|\\/)\\.kube\\/config$/,\n /(^|\\/)\\.config\\/gh\\/hosts\\.ya?ml$/,\n /(^|\\/)\\.codex\\/auth\\.json$/,\n /(^|\\/)\\.claude\\/\\.credentials\\.json$/,\n /(^|\\/)opencode\\/auth\\.json$/,\n /(^|\\/)\\.ssh\\/id_[^/]*$/,\n]\n\nexport function isCredentialFile(path: string): boolean {\n const normalized = path.replace(/^\\.\\//, '')\n if (normalized.endsWith('.pub')) return false\n return CREDENTIAL_FILES.some((pattern) => pattern.test(normalized))\n}\n"],"mappings":";AAgBO,IAAM,WAAW;AACxB,IAAM,YAAY;AAElB,IAAM,sBAAyC;AAAA,EAC7C,OAAO;AAAA,EACP,OAAO;AAAA,EACP,OAAO;AAAA,EACP,OAAO;AAAA,EACP,OAAO;AAAA,EACP,OAAO;AAAA,EACP,OAAO;AAAA,EACP,OAAO;AAAA,EACP,OAAO;AAAA,EACP,OAAO;AAAA,EACP,OAAO;AAAA,EACP,OAAO;AAAA,EACP,OAAO;AAAA,EACP,OAAO;AAAA,EACP,OAAO;AAAA,EACP,OAAO;AAAA,EACP,OAAO;AAAA,EACP,OAAO;AAAA,EACP,OAAO;AACT;AAGA,IAAM,cACJ;AAEF,IAAM,eAAe;AAErB,SAAS,MAAM,MAAsB;AACnC,SAAO,KACJ,QAAQ,sBAAs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AA,MACrD;AAAA,MACA,MAAM,YAAY;AAChB,YAAI,MAAM,UAAU,cAAe,OAAM,YAAY,IAAI;AAAA,MAC3D;AAAA,IACF,CAAC;AAAA,EACH;AAEA,SAAO,EAAE,UAAU,aAAa,UAAU;AAC5C;AAOA,IAAM,gBAAgB,MAAM;AAC1B,MAAI;AACF,UAAM,UAAU,IAAI,YAAY,QAAQ;AACxC,WAAO,QAAQ,OAAO,IAAI,WAAW,CAAC,IAAM,KAAM,GAAI,CAAC,CAAC,EAAE,WAAW,IAAI,UAAU;AAAA,EACrF,QAAQ;AACN,WAAO;AAAA,EACT;AACF,GAAG;AAEH,SAAS,YAAY,QAA4B;AAC/C,MAAI,aAAc,QAAO,aAAa,OAAO,MAAM;AACnD,MAAI,OAAO;AACX,WAAS,IAAI,GAAG,IAAI,OAAO,QAAQ,KAAK,KAAM,SAAQ,OAAO,aAAa,GAAG,OAAO,SAAS,GAAG,IAAI,IAAI,CAAC;AACzG,SAAO;AACT;AAGA,IAAM,mBAAmB;AAAA,EACvB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAEO,SAAS,iBAAiB,MAAuB;AACtD,QAAM,aAAa,KAAK,QAAQ,SAAS,EAAE;AAC3C,MAAI,WAAW,SAAS,MAAM,EAAG,QAAO;AACxC,SAAO,iBAAiB,KAAK,CAAC,YAAY,QAAQ,KAAK,UAAU,CAAC;AACpE;","names":["out"]}
|
|
@@ -9,6 +9,9 @@ import {
|
|
|
9
9
|
currentD1QueryCounter,
|
|
10
10
|
withD1QueryCount
|
|
11
11
|
} from "./chunk-MM6RLOXF.js";
|
|
12
|
+
import {
|
|
13
|
+
REDACTED
|
|
14
|
+
} from "./chunk-M4QITAQV.js";
|
|
12
15
|
import {
|
|
13
16
|
SandboxRunError,
|
|
14
17
|
createComputerStep,
|
|
@@ -134,6 +137,19 @@ import {
|
|
|
134
137
|
isWorkspaceFileExportable
|
|
135
138
|
} from "./chunk-TXD5HXLE.js";
|
|
136
139
|
|
|
140
|
+
// src/chat-routes/redact-values.ts
|
|
141
|
+
var MIN_SECRET_LENGTH = 8;
|
|
142
|
+
function valueRedactor(values) {
|
|
143
|
+
const secrets = [...new Set((values ?? []).filter((v) => typeof v === "string" && v.length >= MIN_SECRET_LENGTH))].sort((a, b) => b.length - a.length);
|
|
144
|
+
if (secrets.length === 0) return void 0;
|
|
145
|
+
const text = (s) => secrets.some((v) => s.includes(v)) ? secrets.reduce((acc, v) => acc.split(v).join(REDACTED), s) : s;
|
|
146
|
+
const walk = (v) => typeof v === "string" ? text(v) : Array.isArray(v) ? v.map(walk) : v !== null && typeof v === "object" ? Object.fromEntries(Object.entries(v).map(([k, x]) => [text(k), walk(x)])) : v;
|
|
147
|
+
return walk;
|
|
148
|
+
}
|
|
149
|
+
async function* redactEvents(source, redact) {
|
|
150
|
+
for await (const event of source) yield redact(event);
|
|
151
|
+
}
|
|
152
|
+
|
|
137
153
|
// src/chat-routes/upload.ts
|
|
138
154
|
var UPLOAD_INLINE_MAX_BYTES = 700 * 1024;
|
|
139
155
|
var UPLOAD_MAX_FILE_BYTES = 8 * 1024 * 1024;
|
|
@@ -2908,6 +2924,7 @@ async function runAdmittedTurn({
|
|
|
2908
2924
|
const preparedBatch = await prepareAdmittedTurn(options, trace, log, tenantId, userId, payload, context, request, progress, content, turnId, draftTuning, ctx?.waitUntil);
|
|
2909
2925
|
if (preparedBatch instanceof Response) return preparedBatch;
|
|
2910
2926
|
const { turnStreamId, identity, executionId, chatTurn, readHistory, historyBeforeLock } = preparedBatch;
|
|
2927
|
+
const redact = options.redactValues ? valueRedactor(await options.redactValues({ tenantId, userId, threadId: payload.threadId })) : void 0;
|
|
2911
2928
|
const prompt = fileParts.length === 0 ? content : content ? [{ type: "text", text: content }, ...fileParts] : [...fileParts];
|
|
2912
2929
|
const state = createAdmittedTurnState();
|
|
2913
2930
|
if (options.cancel) state.cancellationAbort = new AbortController();
|
|
@@ -3060,12 +3077,13 @@ async function runAdmittedTurn({
|
|
|
3060
3077
|
messageId: assistantRowIdForTurn(executionId),
|
|
3061
3078
|
snapshot: () => {
|
|
3062
3079
|
if (!state.producer || state.cancellationAbort?.signal.aborted) return null;
|
|
3063
|
-
|
|
3080
|
+
const snapshot = {
|
|
3064
3081
|
content: state.producer.finalText(),
|
|
3065
3082
|
...state.producer.draftParts ? { parts: state.producer.draftParts() } : {},
|
|
3066
3083
|
...state.producer.usage ? { usage: state.producer.usage() } : {},
|
|
3067
3084
|
...state.producer.model ? { model: state.producer.model } : {}
|
|
3068
3085
|
};
|
|
3086
|
+
return redact ? redact(snapshot) : snapshot;
|
|
3069
3087
|
},
|
|
3070
3088
|
...options.transformFinalText ? { transformText: options.transformFinalText } : {},
|
|
3071
3089
|
log
|
|
@@ -3093,7 +3111,7 @@ async function runAdmittedTurn({
|
|
|
3093
3111
|
}
|
|
3094
3112
|
}
|
|
3095
3113
|
streamSetup.end();
|
|
3096
|
-
const { result } = createTurnEngine(identity, ctx, log, state, dispatched, produceArgs, trace, options, selected.produce, request, context, payload, assistantRowId);
|
|
3114
|
+
const { result } = createTurnEngine(identity, ctx, log, state, dispatched, produceArgs, trace, options, selected.produce, request, context, payload, assistantRowId, redact);
|
|
3097
3115
|
const { clientBody } = startTurnDrain(result, log, turnStreamId, state, endTrace, exportTrace, trace, ctx, request, fireTerminalLifecycle, releaseLock, runAfterSettle, early.settle);
|
|
3098
3116
|
early.handOff();
|
|
3099
3117
|
return createTurnReplayResponse(result.contentType, clientBody, turnMarker, trace);
|
|
@@ -3329,7 +3347,7 @@ function createTurnSettlement(state, trace, options, executionId, traceSink, ide
|
|
|
3329
3347
|
};
|
|
3330
3348
|
return { endTrace, exportTraceInBackground, fireTerminalLifecycle, assistantRowId, exportTrace, runAfterSettle };
|
|
3331
3349
|
}
|
|
3332
|
-
function createTurnEngine(identity, ctx, log, state, dispatched, produceArgs, trace, options, produce, request, context, payload, assistantRowId) {
|
|
3350
|
+
function createTurnEngine(identity, ctx, log, state, dispatched, produceArgs, trace, options, produce, request, context, payload, assistantRowId, redact) {
|
|
3333
3351
|
const result = handleChatTurn({
|
|
3334
3352
|
identity,
|
|
3335
3353
|
waitUntil: ctx?.waitUntil,
|
|
@@ -3350,7 +3368,7 @@ function createTurnEngine(identity, ctx, log, state, dispatched, produceArgs, tr
|
|
|
3350
3368
|
state.producer = await started;
|
|
3351
3369
|
yield* state.producer.stream;
|
|
3352
3370
|
};
|
|
3353
|
-
let source = producerStream();
|
|
3371
|
+
let source = redact ? redactEvents(producerStream(), redact) : producerStream();
|
|
3354
3372
|
if (options.cancel && state.cancellationAbort && !state.closeCancellation) {
|
|
3355
3373
|
source = observeTurnCancellation(source, produceArgs, options.cancel, state.cancellationAbort);
|
|
3356
3374
|
}
|
|
@@ -3418,13 +3436,14 @@ function createTurnEngine(identity, ctx, log, state, dispatched, produceArgs, tr
|
|
|
3418
3436
|
}
|
|
3419
3437
|
const usage = state.producer?.usage?.() ?? {};
|
|
3420
3438
|
const attribution = state.producer?.modelAttribution?.();
|
|
3421
|
-
const
|
|
3439
|
+
const unredacted = {
|
|
3422
3440
|
content: finalText,
|
|
3423
3441
|
...parts && parts.length > 0 ? { parts } : {},
|
|
3424
3442
|
...state.producer?.model ? { model: state.producer.model } : {},
|
|
3425
3443
|
...modelAttributionFields(attribution),
|
|
3426
3444
|
...measuredUsage(usage)
|
|
3427
3445
|
};
|
|
3446
|
+
const values = redact ? redact(unredacted) : unredacted;
|
|
3428
3447
|
if (state.draft) {
|
|
3429
3448
|
await state.draft.finalize(values);
|
|
3430
3449
|
state.assistantMessageId = state.draft.rowId() ?? null;
|
|
@@ -4157,6 +4176,8 @@ function toSandboxEvent(event) {
|
|
|
4157
4176
|
}
|
|
4158
4177
|
|
|
4159
4178
|
export {
|
|
4179
|
+
valueRedactor,
|
|
4180
|
+
redactEvents,
|
|
4160
4181
|
UPLOAD_INLINE_MAX_BYTES,
|
|
4161
4182
|
UPLOAD_MAX_FILE_BYTES,
|
|
4162
4183
|
sanitizeUploadFilename,
|
|
@@ -4199,4 +4220,4 @@ export {
|
|
|
4199
4220
|
createChatTurnRoutes,
|
|
4200
4221
|
streamChatRouteAsSandboxEvents
|
|
4201
4222
|
};
|
|
4202
|
-
//# sourceMappingURL=chunk-
|
|
4223
|
+
//# sourceMappingURL=chunk-S4QFJSLR.js.map
|