@dexto/core 1.13.3 → 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.
- package/dist/llm/executor/stream-processor.cjs +34 -7
- package/dist/llm/executor/stream-processor.d.ts +3 -0
- package/dist/llm/executor/stream-processor.d.ts.map +1 -1
- package/dist/llm/executor/stream-processor.js +34 -7
- package/dist/llm/executor/tool-output-spill.cjs +5 -3
- package/dist/llm/executor/tool-output-spill.d.ts +3 -2
- package/dist/llm/executor/tool-output-spill.d.ts.map +1 -1
- package/dist/llm/executor/tool-output-spill.js +5 -3
- package/dist/tools/tool-output-read.cjs +18 -8
- package/dist/tools/tool-output-read.d.ts.map +1 -1
- package/dist/tools/tool-output-read.js +18 -8
- package/dist/utils/redactor.cjs +70 -20
- package/dist/utils/redactor.d.ts.map +1 -1
- package/dist/utils/redactor.js +70 -20
- package/package.json +2 -2
|
@@ -38,6 +38,14 @@ function assistantOutputForFinishReason(finishReason) {
|
|
|
38
38
|
return { status: "complete" };
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
|
+
function blockSeparator(previousBlockId, blockId, accumulated, delta) {
|
|
42
|
+
if (delta === "" || accumulated === "") return "";
|
|
43
|
+
if (blockId === void 0 || previousBlockId === void 0 || blockId === previousBlockId) {
|
|
44
|
+
return "";
|
|
45
|
+
}
|
|
46
|
+
if (accumulated.endsWith("\n\n")) return "";
|
|
47
|
+
return accumulated.endsWith("\n") ? "\n" : "\n\n";
|
|
48
|
+
}
|
|
41
49
|
class StreamProcessor {
|
|
42
50
|
/**
|
|
43
51
|
* @param contextManager Context manager for message persistence
|
|
@@ -65,6 +73,9 @@ class StreamProcessor {
|
|
|
65
73
|
reasoningText = "";
|
|
66
74
|
reasoningMetadata;
|
|
67
75
|
accumulatedText = "";
|
|
76
|
+
/** The stream block the last text or reasoning came from; a new id starts a new paragraph. */
|
|
77
|
+
lastTextBlockId;
|
|
78
|
+
lastReasoningBlockId;
|
|
68
79
|
logger;
|
|
69
80
|
hasStepUsage = false;
|
|
70
81
|
usageScopeId;
|
|
@@ -136,7 +147,7 @@ class StreamProcessor {
|
|
|
136
147
|
try {
|
|
137
148
|
for await (const event of stream.fullStream) {
|
|
138
149
|
switch (event.type) {
|
|
139
|
-
case "text-delta":
|
|
150
|
+
case "text-delta": {
|
|
140
151
|
if (textDeltaCount === 0) {
|
|
141
152
|
markTiming("first_text_delta_received");
|
|
142
153
|
}
|
|
@@ -155,20 +166,28 @@ class StreamProcessor {
|
|
|
155
166
|
}
|
|
156
167
|
);
|
|
157
168
|
}
|
|
169
|
+
const text = blockSeparator(
|
|
170
|
+
this.lastTextBlockId,
|
|
171
|
+
event.id,
|
|
172
|
+
this.accumulatedText,
|
|
173
|
+
event.text
|
|
174
|
+
) + event.text;
|
|
175
|
+
if (event.text !== "") this.lastTextBlockId = event.id;
|
|
158
176
|
await this.contextManager.appendAssistantText(
|
|
159
177
|
this.assistantMessageId,
|
|
160
|
-
|
|
178
|
+
text
|
|
161
179
|
);
|
|
162
|
-
this.accumulatedText +=
|
|
180
|
+
this.accumulatedText += text;
|
|
163
181
|
if (this.streaming) {
|
|
164
182
|
this.eventBus.emit("llm:chunk", {
|
|
165
183
|
chunkType: "text",
|
|
166
|
-
content:
|
|
184
|
+
content: text
|
|
167
185
|
});
|
|
168
186
|
}
|
|
169
187
|
markTiming("last_text_delta_emitted");
|
|
170
188
|
break;
|
|
171
|
-
|
|
189
|
+
}
|
|
190
|
+
case "reasoning-delta": {
|
|
172
191
|
if (reasoningDeltaCount === 0) {
|
|
173
192
|
markTiming("first_reasoning_delta_received");
|
|
174
193
|
}
|
|
@@ -180,18 +199,26 @@ class StreamProcessor {
|
|
|
180
199
|
lastDeltaReceivedAtMs = lastReasoningDeltaReceivedAtMs;
|
|
181
200
|
setStreamAttribute("last_delta_received_ms", lastDeltaReceivedAtMs);
|
|
182
201
|
setStreamAttribute("last_delta_kind", "reasoning");
|
|
183
|
-
|
|
202
|
+
const reasoning = blockSeparator(
|
|
203
|
+
this.lastReasoningBlockId,
|
|
204
|
+
event.id,
|
|
205
|
+
this.reasoningText,
|
|
206
|
+
event.text
|
|
207
|
+
) + event.text;
|
|
208
|
+
if (event.text !== "") this.lastReasoningBlockId = event.id;
|
|
209
|
+
this.reasoningText += reasoning;
|
|
184
210
|
if (event.providerMetadata) {
|
|
185
211
|
this.mergeReasoningMetadata(event.providerMetadata);
|
|
186
212
|
}
|
|
187
213
|
if (this.streaming) {
|
|
188
214
|
this.eventBus.emit("llm:chunk", {
|
|
189
215
|
chunkType: "reasoning",
|
|
190
|
-
content:
|
|
216
|
+
content: reasoning
|
|
191
217
|
});
|
|
192
218
|
}
|
|
193
219
|
markTiming("last_reasoning_delta_emitted");
|
|
194
220
|
break;
|
|
221
|
+
}
|
|
195
222
|
case "tool-input-start": {
|
|
196
223
|
handleToolInputStart(event);
|
|
197
224
|
break;
|
|
@@ -29,6 +29,9 @@ export declare class StreamProcessor {
|
|
|
29
29
|
private reasoningText;
|
|
30
30
|
private reasoningMetadata;
|
|
31
31
|
private accumulatedText;
|
|
32
|
+
/** The stream block the last text or reasoning came from; a new id starts a new paragraph. */
|
|
33
|
+
private lastTextBlockId;
|
|
34
|
+
private lastReasoningBlockId;
|
|
32
35
|
private logger;
|
|
33
36
|
private hasStepUsage;
|
|
34
37
|
private readonly usageScopeId;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stream-processor.d.ts","sourceRoot":"","sources":["../../../src/llm/executor/stream-processor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,IAAI,CAAC;AAEhE,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC1D,OAAO,EAAE,eAAe,EAAmB,MAAM,uBAAuB,CAAC;AACzE,OAAO,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AAEnD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAC;AAKvD,OAAO,KAAK,EAAE,WAAW,EAAoB,gBAAgB,EAAc,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"stream-processor.d.ts","sourceRoot":"","sources":["../../../src/llm/executor/stream-processor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,IAAI,CAAC;AAEhE,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC1D,OAAO,EAAE,eAAe,EAAmB,MAAM,uBAAuB,CAAC;AACzE,OAAO,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AAEnD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAC;AAKvD,OAAO,KAAK,EAAE,WAAW,EAAoB,gBAAgB,EAAc,MAAM,YAAY,CAAC;AAgF9F,MAAM,WAAW,qBAAqB;IAClC,QAAQ,EAAE,WAAW,CAAC;IACtB,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE,OAAO,YAAY,EAAE,aAAa,CAAC;IACjD,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,yEAAyE;IACzE,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,0EAA0E;IAC1E,gBAAgB,CAAC,EAAE,gBAAgB,CAAC;IACpC,gFAAgF;IAChF,qBAAqB,CAAC,EAAE,MAAM,CAAC;CAClC;AAED,qBAAa,eAAe;IAgCpB,OAAO,CAAC,cAAc;IACtB,OAAO,CAAC,QAAQ;IAChB,OAAO,CAAC,WAAW;IACnB,OAAO,CAAC,MAAM;IAEd,OAAO,CAAC,SAAS;IACjB,OAAO,CAAC,eAAe;IArC3B,OAAO,CAAC,kBAAkB,CAAuB;IACjD,OAAO,CAAC,YAAY,CAAmE;IACvF,OAAO,CAAC,YAAY,CAA8B;IAClD,OAAO,CAAC,aAAa,CAAc;IACnC,OAAO,CAAC,iBAAiB,CAAsC;IAC/D,OAAO,CAAC,eAAe,CAAc;IACrC,8FAA8F;IAC9F,OAAO,CAAC,eAAe,CAAqB;IAC5C,OAAO,CAAC,oBAAoB,CAAqB;IACjD,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,YAAY,CAAS;IAC7B,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAqB;IAClD,OAAO,CAAC,cAAc,CAAuB;IAC7C;;;OAGG;IACH,OAAO,CAAC,gBAAgB,CAAgD;IACxE,OAAO,CAAC,gBAAgB,CAAkE;IAE1F;;;;;;;;;OASG;gBAES,cAAc,EAAE,cAAc,EAC9B,QAAQ,EAAE,eAAe,EACzB,WAAW,EAAE,WAAW,EACxB,MAAM,EAAE,qBAAqB,EACrC,MAAM,EAAE,MAAM,EACN,SAAS,GAAE,OAAc,EACzB,eAAe,GAAE,OAAc;IAMrC,OAAO,CACT,QAAQ,EAAE,MAAM,gBAAgB,CAAC,aAAa,EAAE,OAAO,CAAC,GACzD,OAAO,CAAC,qBAAqB,CAAC;IAwgBjC,OAAO,CAAC,kCAAkC;IAoB1C,OAAO,CAAC,cAAc;IA4CtB,OAAO,CAAC,mBAAmB;IAa3B,OAAO,CAAC,0BAA0B;IAclC,OAAO,CAAC,eAAe;YA8BT,gCAAgC;IA4B9C,OAAO,CAAC,sBAAsB;YAwChB,sBAAsB;IAMpC;;;;OAIG;YACW,2BAA2B;IAQzC;;OAEG;YACW,wBAAwB;YAQxB,yBAAyB;CAuC1C"}
|
|
@@ -16,6 +16,14 @@ function assistantOutputForFinishReason(finishReason) {
|
|
|
16
16
|
return { status: "complete" };
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
|
+
function blockSeparator(previousBlockId, blockId, accumulated, delta) {
|
|
20
|
+
if (delta === "" || accumulated === "") return "";
|
|
21
|
+
if (blockId === void 0 || previousBlockId === void 0 || blockId === previousBlockId) {
|
|
22
|
+
return "";
|
|
23
|
+
}
|
|
24
|
+
if (accumulated.endsWith("\n\n")) return "";
|
|
25
|
+
return accumulated.endsWith("\n") ? "\n" : "\n\n";
|
|
26
|
+
}
|
|
19
27
|
class StreamProcessor {
|
|
20
28
|
/**
|
|
21
29
|
* @param contextManager Context manager for message persistence
|
|
@@ -43,6 +51,9 @@ class StreamProcessor {
|
|
|
43
51
|
reasoningText = "";
|
|
44
52
|
reasoningMetadata;
|
|
45
53
|
accumulatedText = "";
|
|
54
|
+
/** The stream block the last text or reasoning came from; a new id starts a new paragraph. */
|
|
55
|
+
lastTextBlockId;
|
|
56
|
+
lastReasoningBlockId;
|
|
46
57
|
logger;
|
|
47
58
|
hasStepUsage = false;
|
|
48
59
|
usageScopeId;
|
|
@@ -114,7 +125,7 @@ class StreamProcessor {
|
|
|
114
125
|
try {
|
|
115
126
|
for await (const event of stream.fullStream) {
|
|
116
127
|
switch (event.type) {
|
|
117
|
-
case "text-delta":
|
|
128
|
+
case "text-delta": {
|
|
118
129
|
if (textDeltaCount === 0) {
|
|
119
130
|
markTiming("first_text_delta_received");
|
|
120
131
|
}
|
|
@@ -133,20 +144,28 @@ class StreamProcessor {
|
|
|
133
144
|
}
|
|
134
145
|
);
|
|
135
146
|
}
|
|
147
|
+
const text = blockSeparator(
|
|
148
|
+
this.lastTextBlockId,
|
|
149
|
+
event.id,
|
|
150
|
+
this.accumulatedText,
|
|
151
|
+
event.text
|
|
152
|
+
) + event.text;
|
|
153
|
+
if (event.text !== "") this.lastTextBlockId = event.id;
|
|
136
154
|
await this.contextManager.appendAssistantText(
|
|
137
155
|
this.assistantMessageId,
|
|
138
|
-
|
|
156
|
+
text
|
|
139
157
|
);
|
|
140
|
-
this.accumulatedText +=
|
|
158
|
+
this.accumulatedText += text;
|
|
141
159
|
if (this.streaming) {
|
|
142
160
|
this.eventBus.emit("llm:chunk", {
|
|
143
161
|
chunkType: "text",
|
|
144
|
-
content:
|
|
162
|
+
content: text
|
|
145
163
|
});
|
|
146
164
|
}
|
|
147
165
|
markTiming("last_text_delta_emitted");
|
|
148
166
|
break;
|
|
149
|
-
|
|
167
|
+
}
|
|
168
|
+
case "reasoning-delta": {
|
|
150
169
|
if (reasoningDeltaCount === 0) {
|
|
151
170
|
markTiming("first_reasoning_delta_received");
|
|
152
171
|
}
|
|
@@ -158,18 +177,26 @@ class StreamProcessor {
|
|
|
158
177
|
lastDeltaReceivedAtMs = lastReasoningDeltaReceivedAtMs;
|
|
159
178
|
setStreamAttribute("last_delta_received_ms", lastDeltaReceivedAtMs);
|
|
160
179
|
setStreamAttribute("last_delta_kind", "reasoning");
|
|
161
|
-
|
|
180
|
+
const reasoning = blockSeparator(
|
|
181
|
+
this.lastReasoningBlockId,
|
|
182
|
+
event.id,
|
|
183
|
+
this.reasoningText,
|
|
184
|
+
event.text
|
|
185
|
+
) + event.text;
|
|
186
|
+
if (event.text !== "") this.lastReasoningBlockId = event.id;
|
|
187
|
+
this.reasoningText += reasoning;
|
|
162
188
|
if (event.providerMetadata) {
|
|
163
189
|
this.mergeReasoningMetadata(event.providerMetadata);
|
|
164
190
|
}
|
|
165
191
|
if (this.streaming) {
|
|
166
192
|
this.eventBus.emit("llm:chunk", {
|
|
167
193
|
chunkType: "reasoning",
|
|
168
|
-
content:
|
|
194
|
+
content: reasoning
|
|
169
195
|
});
|
|
170
196
|
}
|
|
171
197
|
markTiming("last_reasoning_delta_emitted");
|
|
172
198
|
break;
|
|
199
|
+
}
|
|
173
200
|
case "tool-input-start": {
|
|
174
201
|
handleToolInputStart(event);
|
|
175
202
|
break;
|
|
@@ -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 =
|
|
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) =>
|
|
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 -=
|
|
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
|
|
13
|
-
*
|
|
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;
|
|
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 =
|
|
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) =>
|
|
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 -=
|
|
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 =
|
|
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
|
|
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 +
|
|
93
|
-
selected.push(`${
|
|
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
|
|
117
|
-
|
|
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
|
|
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;
|
|
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 =
|
|
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
|
|
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 +
|
|
71
|
-
selected.push(`${
|
|
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
|
|
95
|
-
|
|
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
|
|
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.]`;
|
package/dist/utils/redactor.cjs
CHANGED
|
@@ -41,23 +41,55 @@ const FILE_DATA_FIELDS = [
|
|
|
41
41
|
"data"
|
|
42
42
|
];
|
|
43
43
|
const SENSITIVE_PATTERNS = [
|
|
44
|
-
|
|
45
|
-
|
|
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
|
-
|
|
49
|
-
//
|
|
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
|
-
|
|
54
|
-
//
|
|
55
|
-
|
|
56
|
-
//
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
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
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
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;
|
|
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"}
|
package/dist/utils/redactor.js
CHANGED
|
@@ -19,23 +19,55 @@ const FILE_DATA_FIELDS = [
|
|
|
19
19
|
"data"
|
|
20
20
|
];
|
|
21
21
|
const SENSITIVE_PATTERNS = [
|
|
22
|
-
|
|
23
|
-
|
|
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
|
-
|
|
27
|
-
//
|
|
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
|
-
|
|
32
|
-
//
|
|
33
|
-
|
|
34
|
-
//
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
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
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
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.
|
|
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.
|
|
177
|
+
"@dexto/llm": "1.13.5"
|
|
178
178
|
},
|
|
179
179
|
"devDependencies": {
|
|
180
180
|
"@opentelemetry/context-async-hooks": "^1.28.0",
|