@dexto/core 1.13.4 → 1.13.5

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.
@@ -27,7 +27,7 @@ __export(tool_output_spill_exports, {
27
27
  module.exports = __toCommonJS(tool_output_spill_exports);
28
28
  const TOOL_OUTPUT_READ_TOOL_NAME = "tool_output_read";
29
29
  const CHARS_PER_TOKEN = 4;
30
- const MAX_INLINE_TOKENS = 25e3;
30
+ const MAX_INLINE_TOKENS = 6e3;
31
31
  const INLINE_WINDOW_RATIO = 0.1;
32
32
  const STEP_WINDOW_RATIO = 0.4;
33
33
  const STEP_SPILL_PREVIEW_CHARS = 16e3;
@@ -53,11 +53,13 @@ function planToolOutputSpills(results, budget) {
53
53
  }
54
54
  }
55
55
  const stepPreviewChars = Math.min(budget.inlineCapChars, STEP_SPILL_PREVIEW_CHARS);
56
- const largestFirst = results.filter((result) => !previewChars.has(result.toolCallId)).filter((result) => result.textLength > stepPreviewChars).sort((left, right) => right.textLength - left.textLength);
56
+ const largestFirst = results.filter((result) => result.textLength > stepPreviewChars).sort((left, right) => right.textLength - left.textLength);
57
57
  for (const result of largestFirst) {
58
58
  if (inlineChars <= budget.stepBudgetChars) break;
59
+ const inlineNow = previewChars.get(result.toolCallId) ?? result.textLength;
60
+ if (inlineNow <= stepPreviewChars) continue;
59
61
  previewChars.set(result.toolCallId, stepPreviewChars);
60
- inlineChars -= result.textLength - stepPreviewChars;
62
+ inlineChars -= inlineNow - stepPreviewChars;
61
63
  }
62
64
  return previewChars;
63
65
  }
@@ -9,8 +9,9 @@ export declare function toolOutputBudget(maxInputTokens: number): ToolOutputBudg
9
9
  export declare function toolResultText(result: SanitizedToolResult): string;
10
10
  /**
11
11
  * Decides which of one step's results to store outside history, and how much of each to keep
12
- * inline. Every result over the inline cap is stored; if the rest still exceed the step budget,
13
- * the largest are stored next (earlier calls first on ties) so the decision is deterministic.
12
+ * inline. Every result over the inline cap is stored; if the step still exceeds its budget, the
13
+ * largest results, stored or not, are cut to the step preview (earlier calls first on ties) so the
14
+ * decision is deterministic.
14
15
  */
15
16
  export declare function planToolOutputSpills(results: ReadonlyArray<{
16
17
  toolCallId: string;
@@ -1 +1 @@
1
- {"version":3,"file":"tool-output-spill.d.ts","sourceRoot":"","sources":["../../../src/llm/executor/tool-output-spill.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAe,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAE/E,2DAA2D;AAC3D,eAAO,MAAM,0BAA0B,qBAAqB,CAAC;AAY7D,MAAM,WAAW,gBAAgB;IAC7B,cAAc,EAAE,MAAM,CAAC;IACvB,eAAe,EAAE,MAAM,CAAC;CAC3B;AAED,wBAAgB,gBAAgB,CAAC,cAAc,EAAE,MAAM,GAAG,gBAAgB,CAOzE;AAED,wBAAgB,cAAc,CAAC,MAAM,EAAE,mBAAmB,GAAG,MAAM,CAElE;AAED;;;;GAIG;AACH,wBAAgB,oBAAoB,CAChC,OAAO,EAAE,aAAa,CAAC;IAAE,UAAU,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,CAAA;CAAE,CAAC,EAClE,MAAM,EAAE,gBAAgB,GACzB,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAsBrB;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,CACjC,MAAM,EAAE,mBAAmB,EAC3B,QAAQ,EAAE,MAAM,EAChB,YAAY,EAAE,MAAM,GACrB,mBAAmB,CAqBrB"}
1
+ {"version":3,"file":"tool-output-spill.d.ts","sourceRoot":"","sources":["../../../src/llm/executor/tool-output-spill.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAe,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAE/E,2DAA2D;AAC3D,eAAO,MAAM,0BAA0B,qBAAqB,CAAC;AAgB7D,MAAM,WAAW,gBAAgB;IAC7B,cAAc,EAAE,MAAM,CAAC;IACvB,eAAe,EAAE,MAAM,CAAC;CAC3B;AAED,wBAAgB,gBAAgB,CAAC,cAAc,EAAE,MAAM,GAAG,gBAAgB,CAOzE;AAED,wBAAgB,cAAc,CAAC,MAAM,EAAE,mBAAmB,GAAG,MAAM,CAElE;AAED;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAChC,OAAO,EAAE,aAAa,CAAC;IAAE,UAAU,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,CAAA;CAAE,CAAC,EAClE,MAAM,EAAE,gBAAgB,GACzB,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAwBrB;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,CACjC,MAAM,EAAE,mBAAmB,EAC3B,QAAQ,EAAE,MAAM,EAChB,YAAY,EAAE,MAAM,GACrB,mBAAmB,CAqBrB"}
@@ -1,7 +1,7 @@
1
1
  import "../../chunk-C6A6W6XS.js";
2
2
  const TOOL_OUTPUT_READ_TOOL_NAME = "tool_output_read";
3
3
  const CHARS_PER_TOKEN = 4;
4
- const MAX_INLINE_TOKENS = 25e3;
4
+ const MAX_INLINE_TOKENS = 6e3;
5
5
  const INLINE_WINDOW_RATIO = 0.1;
6
6
  const STEP_WINDOW_RATIO = 0.4;
7
7
  const STEP_SPILL_PREVIEW_CHARS = 16e3;
@@ -27,11 +27,13 @@ function planToolOutputSpills(results, budget) {
27
27
  }
28
28
  }
29
29
  const stepPreviewChars = Math.min(budget.inlineCapChars, STEP_SPILL_PREVIEW_CHARS);
30
- const largestFirst = results.filter((result) => !previewChars.has(result.toolCallId)).filter((result) => result.textLength > stepPreviewChars).sort((left, right) => right.textLength - left.textLength);
30
+ const largestFirst = results.filter((result) => result.textLength > stepPreviewChars).sort((left, right) => right.textLength - left.textLength);
31
31
  for (const result of largestFirst) {
32
32
  if (inlineChars <= budget.stepBudgetChars) break;
33
+ const inlineNow = previewChars.get(result.toolCallId) ?? result.textLength;
34
+ if (inlineNow <= stepPreviewChars) continue;
33
35
  previewChars.set(result.toolCallId, stepPreviewChars);
34
- inlineChars -= result.textLength - stepPreviewChars;
36
+ inlineChars -= inlineNow - stepPreviewChars;
35
37
  }
36
38
  return previewChars;
37
39
  }
@@ -28,7 +28,7 @@ var import_errors = require("./errors.js");
28
28
  var import_define_tool = require("./define-tool.js");
29
29
  var import_presentation = require("./presentation.js");
30
30
  const MAX_READ_LINES = 2e3;
31
- const MAX_READ_CHARS = 5e4;
31
+ const MAX_READ_CHARS = 24e3;
32
32
  const DEFAULT_MAX_MATCHES = 100;
33
33
  const MAX_MATCHES = 500;
34
34
  const MAX_MATCH_LINE_CHARS = 500;
@@ -86,12 +86,15 @@ function readLines(text, input) {
86
86
  const end = Math.min(start - 1 + (input.limit ?? MAX_READ_LINES), lines.length);
87
87
  const selected = [];
88
88
  let chars = 0;
89
- for (let line = start; line <= end && chars < MAX_READ_CHARS; line += 1) {
89
+ for (let line = start; line <= end; line += 1) {
90
+ const prefix = `${line}: `;
91
+ const room = MAX_READ_CHARS - chars - prefix.length;
92
+ if (room <= 0) break;
90
93
  const full = lines[line - 1] ?? "";
91
94
  const from = line === start ? Math.min(input.charOffset ?? 0, full.length) : 0;
92
- const piece = full.slice(from, from + MAX_READ_CHARS - chars);
93
- selected.push(`${line}: ${piece}`);
94
- chars += piece.length + 1;
95
+ const piece = full.slice(from, from + room);
96
+ selected.push(`${prefix}${piece}`);
97
+ chars += prefix.length + piece.length + 1;
95
98
  if (from + piece.length < full.length) {
96
99
  const next = from + piece.length;
97
100
  return `${selected.join("\n")}
@@ -110,15 +113,22 @@ function searchLines(text, pattern, maxMatches) {
110
113
  const lines = text.split("\n");
111
114
  const found = [];
112
115
  let total = 0;
116
+ let chars = 0;
117
+ let outOfRoom = false;
113
118
  lines.forEach((line, index) => {
114
119
  if (!line.toLowerCase().includes(needle)) return;
115
120
  total += 1;
116
- if (found.length < maxMatches) {
117
- found.push(`${index + 1}: ${line.slice(0, MAX_MATCH_LINE_CHARS)}`);
121
+ if (outOfRoom || found.length >= maxMatches) return;
122
+ const match = `${index + 1}: ${line.slice(0, MAX_MATCH_LINE_CHARS)}`;
123
+ if (chars + match.length > MAX_READ_CHARS) {
124
+ outOfRoom = true;
125
+ return;
118
126
  }
127
+ found.push(match);
128
+ chars += match.length + 1;
119
129
  });
120
130
  if (total === 0) return `[No lines contain "${pattern}" in ${lines.length} lines.]`;
121
- const shown = total > found.length ? `Showing ${found.length} of ${total} matching lines; raise maxMatches or narrow the pattern.` : `${total} matching lines of ${lines.length}.`;
131
+ const shown = total === found.length ? `${total} matching lines of ${lines.length}.` : outOfRoom ? `Showing ${found.length} of ${total} matching lines; narrow the pattern to see the rest.` : `Showing ${found.length} of ${total} matching lines; raise maxMatches or narrow the pattern.`;
122
132
  return `${found.join("\n")}
123
133
 
124
134
  [${shown} Read around a match with offset.]`;
@@ -1 +1 @@
1
- {"version":3,"file":"tool-output-read.d.ts","sourceRoot":"","sources":["../../src/tools/tool-output-read.ts"],"names":[],"mappings":"AAAA,gGAAgG;AAChG,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,kCAAkC,CAAC;AAC1E,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAC;AAMxE,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAQvC,QAAA,MAAM,yBAAyB;;;;;;;kBA0ClB,CAAC;AAId,wBAAgB,wBAAwB,CAAC,MAAM,EAAE;IAC7C,YAAY,EAAE,iBAAiB,CAAC;IAChC,WAAW,EAAE,eAAe,CAAC;CAChC,GAAG,IAAI,CAAC,OAAO,yBAAyB,CAAC,CAkCzC"}
1
+ {"version":3,"file":"tool-output-read.d.ts","sourceRoot":"","sources":["../../src/tools/tool-output-read.ts"],"names":[],"mappings":"AAAA,gGAAgG;AAChG,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,kCAAkC,CAAC;AAC1E,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAC;AAMxE,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAYvC,QAAA,MAAM,yBAAyB;;;;;;;kBA0ClB,CAAC;AAId,wBAAgB,wBAAwB,CAAC,MAAM,EAAE;IAC7C,YAAY,EAAE,iBAAiB,CAAC;IAChC,WAAW,EAAE,eAAe,CAAC;CAChC,GAAG,IAAI,CAAC,OAAO,yBAAyB,CAAC,CAkCzC"}
@@ -6,7 +6,7 @@ import { ToolError } from "./errors.js";
6
6
  import { defineTool } from "./define-tool.js";
7
7
  import { createLocalToolCallHeader } from "./presentation.js";
8
8
  const MAX_READ_LINES = 2e3;
9
- const MAX_READ_CHARS = 5e4;
9
+ const MAX_READ_CHARS = 24e3;
10
10
  const DEFAULT_MAX_MATCHES = 100;
11
11
  const MAX_MATCHES = 500;
12
12
  const MAX_MATCH_LINE_CHARS = 500;
@@ -64,12 +64,15 @@ function readLines(text, input) {
64
64
  const end = Math.min(start - 1 + (input.limit ?? MAX_READ_LINES), lines.length);
65
65
  const selected = [];
66
66
  let chars = 0;
67
- for (let line = start; line <= end && chars < MAX_READ_CHARS; line += 1) {
67
+ for (let line = start; line <= end; line += 1) {
68
+ const prefix = `${line}: `;
69
+ const room = MAX_READ_CHARS - chars - prefix.length;
70
+ if (room <= 0) break;
68
71
  const full = lines[line - 1] ?? "";
69
72
  const from = line === start ? Math.min(input.charOffset ?? 0, full.length) : 0;
70
- const piece = full.slice(from, from + MAX_READ_CHARS - chars);
71
- selected.push(`${line}: ${piece}`);
72
- chars += piece.length + 1;
73
+ const piece = full.slice(from, from + room);
74
+ selected.push(`${prefix}${piece}`);
75
+ chars += prefix.length + piece.length + 1;
73
76
  if (from + piece.length < full.length) {
74
77
  const next = from + piece.length;
75
78
  return `${selected.join("\n")}
@@ -88,15 +91,22 @@ function searchLines(text, pattern, maxMatches) {
88
91
  const lines = text.split("\n");
89
92
  const found = [];
90
93
  let total = 0;
94
+ let chars = 0;
95
+ let outOfRoom = false;
91
96
  lines.forEach((line, index) => {
92
97
  if (!line.toLowerCase().includes(needle)) return;
93
98
  total += 1;
94
- if (found.length < maxMatches) {
95
- found.push(`${index + 1}: ${line.slice(0, MAX_MATCH_LINE_CHARS)}`);
99
+ if (outOfRoom || found.length >= maxMatches) return;
100
+ const match = `${index + 1}: ${line.slice(0, MAX_MATCH_LINE_CHARS)}`;
101
+ if (chars + match.length > MAX_READ_CHARS) {
102
+ outOfRoom = true;
103
+ return;
96
104
  }
105
+ found.push(match);
106
+ chars += match.length + 1;
97
107
  });
98
108
  if (total === 0) return `[No lines contain "${pattern}" in ${lines.length} lines.]`;
99
- const shown = total > found.length ? `Showing ${found.length} of ${total} matching lines; raise maxMatches or narrow the pattern.` : `${total} matching lines of ${lines.length}.`;
109
+ const shown = total === found.length ? `${total} matching lines of ${lines.length}.` : outOfRoom ? `Showing ${found.length} of ${total} matching lines; narrow the pattern to see the rest.` : `Showing ${found.length} of ${total} matching lines; raise maxMatches or narrow the pattern.`;
100
110
  return `${found.join("\n")}
101
111
 
102
112
  [${shown} Read around a match with offset.]`;
@@ -41,23 +41,55 @@ const FILE_DATA_FIELDS = [
41
41
  "data"
42
42
  ];
43
43
  const SENSITIVE_PATTERNS = [
44
- /\bsk-[A-Za-z0-9]{20,}\b/g,
45
- // OpenAI API keys (at least 20 chars after sk-)
44
+ // PEM private key block, through its end line or the end of the text if it was cut off
45
+ /-----BEGIN [A-Z ]*PRIVATE KEY-----[\s\S]*?(?:-----END [A-Z ]*PRIVATE KEY-----|$)/g,
46
+ /\b[sr]k_(?:live|test|org)_[A-Za-z0-9_]{16,}/g,
47
+ // Stripe secret, restricted and organization keys
48
+ // GitHub tokens (ghp_, gho_, ghu_, ghr_, ghs_). App installation tokens (ghs_) may be the
49
+ // long stateless form, which has dots, hyphens and underscores after the prefix.
50
+ /\b(?:gh[pour]_[A-Za-z0-9]{36,}|ghs_[A-Za-z0-9._-]{36,})/g,
51
+ /\bgithub_pat_[A-Za-z0-9_]{22,}/g,
52
+ // GitHub fine-grained tokens
53
+ // Slack tokens: bot, user and refresh (xoxb-, xoxp-, xoxe-, ...) and app-level (xapp-, xoxe.xapp-),
54
+ // and workflow tokens (xwfp-)
55
+ /\b(?:xox[a-z]-|xoxe\.xapp-|xapp-|xwfp-)[A-Za-z0-9-]{10,}/g,
56
+ /\bya29\.[A-Za-z0-9_-]{20,}/g,
57
+ // Google OAuth access tokens
46
58
  /\bBearer\s+[A-Za-z0-9\-_.=]+\b/gi,
47
59
  // Bearer tokens
48
- /\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}\b/g
49
- // Emails
60
+ // Emails. The local part is capped at its legal 64 characters: unbounded, a long run of
61
+ // word characters with no "@" was rescanned from every word boundary (quadratic).
62
+ /\b[A-Za-z0-9._%+-]{1,64}@[A-Za-z0-9.-]+\.[A-Za-z]{2,}\b/g
50
63
  ];
64
+ const SK_KEY_CANDIDATE_PATTERN = /\bsk-[A-Za-z0-9_-]{20,}/g;
65
+ function isSkKey(candidate) {
66
+ const body = candidate.slice("sk-".length);
67
+ return /\d/.test(body) || !/[-_]/.test(body);
68
+ }
69
+ const AWS_ACCESS_KEY_ID_PATTERN = /\b(?:AKIA|ASIA)[A-Z0-9]{16}\b/g;
70
+ const AWS_ACCESS_KEY_ID_OUTSIDE_CREDENTIAL_PATTERN = /(?<![?&]X-Amz-Credential=)(?<![?&]AWSAccessKeyId=)\b(?:AKIA|ASIA)[A-Z0-9]{16}\b/g;
71
+ const URL_PATTERN = /(https?:\/\/(?:(?!https?:\/\/)[A-Za-z0-9._~/?&=%+-])+)/i;
72
+ const SIGNED_URL_PLACEHOLDER = /\uE000(\d+)\uE000/g;
51
73
  const JWT_PATTERN = /\beyJ[A-Za-z0-9_-]*\.[A-Za-z0-9_-]*\.[A-Za-z0-9_-]*/g;
74
+ const JWT_OUTSIDE_TOKEN_VALUE_PATTERN = /(?<![?&]token=)\beyJ[A-Za-z0-9_-]*\.[A-Za-z0-9_-]*\.[A-Za-z0-9_-]*/g;
52
75
  const SIGNED_URL_PATTERNS = [
53
- /supabase\.co\/storage\/.*\?token=/i,
54
- // Supabase signed URLs
55
- /\.r2\.cloudflarestorage\.com\/.*\?/i,
56
- // Cloudflare R2 signed URLs
57
- /\.s3\..*amazonaws\.com\/.*\?(X-Amz-|AWSAccessKeyId)/i,
58
- // AWS S3 presigned URLs
59
- /storage\.googleapis\.com\/.*\?/i
60
- // Google Cloud Storage signed URLs
76
+ // Each provider's link counts as signed only on its own host and with a non-empty signature
77
+ // in its query (after the "?") that has the provider's own shape: a 64-hex SigV4 signature, a
78
+ // base64 SigV2 or GCS V2 one, a long hex GCS V4 one, or a JWT for Supabase. A public link, an
79
+ // unsigned one or one with a placeholder value gets no exemption.
80
+ // Supabase signed URLs: the token is the signature.
81
+ /^https?:\/\/[^/?#\s]+\.supabase\.co\/storage\/v1\/object\/sign\/[^?#]*\?(?:[^#]*&)?token=eyJ[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+/i,
82
+ // Cloudflare R2 presigned URLs (SigV4).
83
+ /^https?:\/\/[^/?#\s]+\.r2\.cloudflarestorage\.com\/(?=[^?#]*\?(?:[^#]*&)?X-Amz-Signature=[0-9a-f]{64}(?![0-9a-z]))/i,
84
+ // AWS S3 presigned URLs, virtual-hosted (bucket.s3.region...), path-style (s3.region.../bucket) and
85
+ // S3 Express zonal (bucket--zone--x-s3.s3express-zone.region...).
86
+ // The S3 host must be the URL's own host, not text in another URL's path, and made of whole
87
+ // labels ending in amazonaws.com (amazonaws.com.cn in AWS China), so evilamazonaws.com is not.
88
+ // The link must carry its signature as well as its key id: SigV4 or SigV2.
89
+ /^https?:\/\/(?:[^/?#.\s]+\.)*(?:s3[.-]|s3express-)(?:[^/?#.\s]+\.)*amazonaws\.com(?:\.cn)?\/(?=[^?#]*\?(?:[^#]*&)?X-Amz-Credential=(?:AKIA|ASIA)[A-Z0-9]{16}(?:%2F|\/)\d{8}(?:%2F|\/)[a-z0-9-]+(?:%2F|\/)[a-z0-9-]+(?:%2F|\/)aws4_request)(?=[^?#]*\?(?:[^#]*&)?X-Amz-Signature=[0-9a-f]{64}(?![0-9a-z]))/i,
90
+ /^https?:\/\/(?:[^/?#.\s]+\.)*(?:s3[.-]|s3express-)(?:[^/?#.\s]+\.)*amazonaws\.com(?:\.cn)?\/(?=[^?#]*\?(?:[^#]*&)?AWSAccessKeyId=(?:AKIA|ASIA)[A-Z0-9]{16}(?![A-Z0-9]))(?=[^?#]*\?(?:[^#]*&)?Signature=[A-Za-z0-9%+/=]{20,})/i,
91
+ // Google Cloud Storage signed URLs: V4 (X-Goog-Signature) or V2 (Signature).
92
+ /^https?:\/\/(?:[^/?#\s]+\.)?storage\.googleapis\.com\/(?=[^?#]*\?(?:[^#]*&)?(?:X-Goog-Signature=[0-9a-f]{64,}|Signature=[A-Za-z0-9%+/=]{20,}))/i
61
93
  ];
62
94
  const REDACTED = "[REDACTED]";
63
95
  const REDACTED_CIRCULAR = "[REDACTED_CIRCULAR]";
@@ -78,16 +110,34 @@ function truncateFileData(value, key, parent) {
78
110
  function isSignedUrl(value) {
79
111
  return SIGNED_URL_PATTERNS.some((pattern) => pattern.test(value));
80
112
  }
113
+ function redactText(text, awsAccessKeyIdPattern, jwtPattern) {
114
+ let result = text;
115
+ for (const pattern of SENSITIVE_PATTERNS) {
116
+ result = result.replace(pattern, REDACTED);
117
+ }
118
+ result = result.replace(
119
+ SK_KEY_CANDIDATE_PATTERN,
120
+ (candidate) => isSkKey(candidate) ? REDACTED : candidate
121
+ );
122
+ return result.replace(awsAccessKeyIdPattern, REDACTED).replace(jwtPattern, REDACTED);
123
+ }
81
124
  function redactSensitiveData(input, seen = /* @__PURE__ */ new WeakSet()) {
82
125
  if (typeof input === "string") {
83
- let result = input;
84
- for (const pattern of SENSITIVE_PATTERNS) {
85
- result = result.replace(pattern, REDACTED);
86
- }
87
- if (!isSignedUrl(result)) {
88
- result = result.replace(JWT_PATTERN, REDACTED);
89
- }
90
- return result;
126
+ const signedUrls = [];
127
+ const withPlaceholders = input.includes("\uE000") ? input : input.split(URL_PATTERN).map((part, index) => {
128
+ if (index % 2 === 0 || !isSignedUrl(part)) return part;
129
+ signedUrls.push(part);
130
+ return `\uE000${signedUrls.length - 1}\uE000`;
131
+ }).join("");
132
+ const result = redactText(withPlaceholders, AWS_ACCESS_KEY_ID_PATTERN, JWT_PATTERN);
133
+ return signedUrls.length === 0 ? result : result.replace(SIGNED_URL_PLACEHOLDER, (_placeholder, index) => {
134
+ const url = signedUrls[Number(index)];
135
+ return url === void 0 ? REDACTED : redactText(
136
+ url,
137
+ AWS_ACCESS_KEY_ID_OUTSIDE_CREDENTIAL_PATTERN,
138
+ JWT_OUTSIDE_TOKEN_VALUE_PATTERN
139
+ );
140
+ });
91
141
  }
92
142
  if (Array.isArray(input)) {
93
143
  if (seen.has(input)) return REDACTED_CIRCULAR;
@@ -1 +1 @@
1
- {"version":3,"file":"redactor.d.ts","sourceRoot":"","sources":["../../src/utils/redactor.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AA8FH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,OAAO,EAAE,IAAI,kBAAgB,GAAG,OAAO,CAsCjF"}
1
+ {"version":3,"file":"redactor.d.ts","sourceRoot":"","sources":["../../src/utils/redactor.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAqKH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,OAAO,EAAE,IAAI,kBAAgB,GAAG,OAAO,CAyDjF"}
@@ -19,23 +19,55 @@ const FILE_DATA_FIELDS = [
19
19
  "data"
20
20
  ];
21
21
  const SENSITIVE_PATTERNS = [
22
- /\bsk-[A-Za-z0-9]{20,}\b/g,
23
- // OpenAI API keys (at least 20 chars after sk-)
22
+ // PEM private key block, through its end line or the end of the text if it was cut off
23
+ /-----BEGIN [A-Z ]*PRIVATE KEY-----[\s\S]*?(?:-----END [A-Z ]*PRIVATE KEY-----|$)/g,
24
+ /\b[sr]k_(?:live|test|org)_[A-Za-z0-9_]{16,}/g,
25
+ // Stripe secret, restricted and organization keys
26
+ // GitHub tokens (ghp_, gho_, ghu_, ghr_, ghs_). App installation tokens (ghs_) may be the
27
+ // long stateless form, which has dots, hyphens and underscores after the prefix.
28
+ /\b(?:gh[pour]_[A-Za-z0-9]{36,}|ghs_[A-Za-z0-9._-]{36,})/g,
29
+ /\bgithub_pat_[A-Za-z0-9_]{22,}/g,
30
+ // GitHub fine-grained tokens
31
+ // Slack tokens: bot, user and refresh (xoxb-, xoxp-, xoxe-, ...) and app-level (xapp-, xoxe.xapp-),
32
+ // and workflow tokens (xwfp-)
33
+ /\b(?:xox[a-z]-|xoxe\.xapp-|xapp-|xwfp-)[A-Za-z0-9-]{10,}/g,
34
+ /\bya29\.[A-Za-z0-9_-]{20,}/g,
35
+ // Google OAuth access tokens
24
36
  /\bBearer\s+[A-Za-z0-9\-_.=]+\b/gi,
25
37
  // Bearer tokens
26
- /\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}\b/g
27
- // Emails
38
+ // Emails. The local part is capped at its legal 64 characters: unbounded, a long run of
39
+ // word characters with no "@" was rescanned from every word boundary (quadratic).
40
+ /\b[A-Za-z0-9._%+-]{1,64}@[A-Za-z0-9.-]+\.[A-Za-z]{2,}\b/g
28
41
  ];
42
+ const SK_KEY_CANDIDATE_PATTERN = /\bsk-[A-Za-z0-9_-]{20,}/g;
43
+ function isSkKey(candidate) {
44
+ const body = candidate.slice("sk-".length);
45
+ return /\d/.test(body) || !/[-_]/.test(body);
46
+ }
47
+ const AWS_ACCESS_KEY_ID_PATTERN = /\b(?:AKIA|ASIA)[A-Z0-9]{16}\b/g;
48
+ const AWS_ACCESS_KEY_ID_OUTSIDE_CREDENTIAL_PATTERN = /(?<![?&]X-Amz-Credential=)(?<![?&]AWSAccessKeyId=)\b(?:AKIA|ASIA)[A-Z0-9]{16}\b/g;
49
+ const URL_PATTERN = /(https?:\/\/(?:(?!https?:\/\/)[A-Za-z0-9._~/?&=%+-])+)/i;
50
+ const SIGNED_URL_PLACEHOLDER = /\uE000(\d+)\uE000/g;
29
51
  const JWT_PATTERN = /\beyJ[A-Za-z0-9_-]*\.[A-Za-z0-9_-]*\.[A-Za-z0-9_-]*/g;
52
+ const JWT_OUTSIDE_TOKEN_VALUE_PATTERN = /(?<![?&]token=)\beyJ[A-Za-z0-9_-]*\.[A-Za-z0-9_-]*\.[A-Za-z0-9_-]*/g;
30
53
  const SIGNED_URL_PATTERNS = [
31
- /supabase\.co\/storage\/.*\?token=/i,
32
- // Supabase signed URLs
33
- /\.r2\.cloudflarestorage\.com\/.*\?/i,
34
- // Cloudflare R2 signed URLs
35
- /\.s3\..*amazonaws\.com\/.*\?(X-Amz-|AWSAccessKeyId)/i,
36
- // AWS S3 presigned URLs
37
- /storage\.googleapis\.com\/.*\?/i
38
- // Google Cloud Storage signed URLs
54
+ // Each provider's link counts as signed only on its own host and with a non-empty signature
55
+ // in its query (after the "?") that has the provider's own shape: a 64-hex SigV4 signature, a
56
+ // base64 SigV2 or GCS V2 one, a long hex GCS V4 one, or a JWT for Supabase. A public link, an
57
+ // unsigned one or one with a placeholder value gets no exemption.
58
+ // Supabase signed URLs: the token is the signature.
59
+ /^https?:\/\/[^/?#\s]+\.supabase\.co\/storage\/v1\/object\/sign\/[^?#]*\?(?:[^#]*&)?token=eyJ[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+/i,
60
+ // Cloudflare R2 presigned URLs (SigV4).
61
+ /^https?:\/\/[^/?#\s]+\.r2\.cloudflarestorage\.com\/(?=[^?#]*\?(?:[^#]*&)?X-Amz-Signature=[0-9a-f]{64}(?![0-9a-z]))/i,
62
+ // AWS S3 presigned URLs, virtual-hosted (bucket.s3.region...), path-style (s3.region.../bucket) and
63
+ // S3 Express zonal (bucket--zone--x-s3.s3express-zone.region...).
64
+ // The S3 host must be the URL's own host, not text in another URL's path, and made of whole
65
+ // labels ending in amazonaws.com (amazonaws.com.cn in AWS China), so evilamazonaws.com is not.
66
+ // The link must carry its signature as well as its key id: SigV4 or SigV2.
67
+ /^https?:\/\/(?:[^/?#.\s]+\.)*(?:s3[.-]|s3express-)(?:[^/?#.\s]+\.)*amazonaws\.com(?:\.cn)?\/(?=[^?#]*\?(?:[^#]*&)?X-Amz-Credential=(?:AKIA|ASIA)[A-Z0-9]{16}(?:%2F|\/)\d{8}(?:%2F|\/)[a-z0-9-]+(?:%2F|\/)[a-z0-9-]+(?:%2F|\/)aws4_request)(?=[^?#]*\?(?:[^#]*&)?X-Amz-Signature=[0-9a-f]{64}(?![0-9a-z]))/i,
68
+ /^https?:\/\/(?:[^/?#.\s]+\.)*(?:s3[.-]|s3express-)(?:[^/?#.\s]+\.)*amazonaws\.com(?:\.cn)?\/(?=[^?#]*\?(?:[^#]*&)?AWSAccessKeyId=(?:AKIA|ASIA)[A-Z0-9]{16}(?![A-Z0-9]))(?=[^?#]*\?(?:[^#]*&)?Signature=[A-Za-z0-9%+/=]{20,})/i,
69
+ // Google Cloud Storage signed URLs: V4 (X-Goog-Signature) or V2 (Signature).
70
+ /^https?:\/\/(?:[^/?#\s]+\.)?storage\.googleapis\.com\/(?=[^?#]*\?(?:[^#]*&)?(?:X-Goog-Signature=[0-9a-f]{64,}|Signature=[A-Za-z0-9%+/=]{20,}))/i
39
71
  ];
40
72
  const REDACTED = "[REDACTED]";
41
73
  const REDACTED_CIRCULAR = "[REDACTED_CIRCULAR]";
@@ -56,16 +88,34 @@ function truncateFileData(value, key, parent) {
56
88
  function isSignedUrl(value) {
57
89
  return SIGNED_URL_PATTERNS.some((pattern) => pattern.test(value));
58
90
  }
91
+ function redactText(text, awsAccessKeyIdPattern, jwtPattern) {
92
+ let result = text;
93
+ for (const pattern of SENSITIVE_PATTERNS) {
94
+ result = result.replace(pattern, REDACTED);
95
+ }
96
+ result = result.replace(
97
+ SK_KEY_CANDIDATE_PATTERN,
98
+ (candidate) => isSkKey(candidate) ? REDACTED : candidate
99
+ );
100
+ return result.replace(awsAccessKeyIdPattern, REDACTED).replace(jwtPattern, REDACTED);
101
+ }
59
102
  function redactSensitiveData(input, seen = /* @__PURE__ */ new WeakSet()) {
60
103
  if (typeof input === "string") {
61
- let result = input;
62
- for (const pattern of SENSITIVE_PATTERNS) {
63
- result = result.replace(pattern, REDACTED);
64
- }
65
- if (!isSignedUrl(result)) {
66
- result = result.replace(JWT_PATTERN, REDACTED);
67
- }
68
- return result;
104
+ const signedUrls = [];
105
+ const withPlaceholders = input.includes("\uE000") ? input : input.split(URL_PATTERN).map((part, index) => {
106
+ if (index % 2 === 0 || !isSignedUrl(part)) return part;
107
+ signedUrls.push(part);
108
+ return `\uE000${signedUrls.length - 1}\uE000`;
109
+ }).join("");
110
+ const result = redactText(withPlaceholders, AWS_ACCESS_KEY_ID_PATTERN, JWT_PATTERN);
111
+ return signedUrls.length === 0 ? result : result.replace(SIGNED_URL_PLACEHOLDER, (_placeholder, index) => {
112
+ const url = signedUrls[Number(index)];
113
+ return url === void 0 ? REDACTED : redactText(
114
+ url,
115
+ AWS_ACCESS_KEY_ID_OUTSIDE_CREDENTIAL_PATTERN,
116
+ JWT_OUTSIDE_TOKEN_VALUE_PATTERN
117
+ );
118
+ });
69
119
  }
70
120
  if (Array.isArray(input)) {
71
121
  if (seen.has(input)) return REDACTED_CIRCULAR;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dexto/core",
3
- "version": "1.13.4",
3
+ "version": "1.13.5",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -174,7 +174,7 @@
174
174
  "nanoid": "^5.1.6",
175
175
  "winston": "^3.17.0",
176
176
  "yaml": "^2.8.3",
177
- "@dexto/llm": "1.13.4"
177
+ "@dexto/llm": "1.13.5"
178
178
  },
179
179
  "devDependencies": {
180
180
  "@opentelemetry/context-async-hooks": "^1.28.0",