pentesting 0.7.37 → 0.7.39
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/index.js +51 -17
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -5216,23 +5216,8 @@ ${this.state.findings.filter((f) => f.severity !== "info").map((f) => `- Address
|
|
|
5216
5216
|
}
|
|
5217
5217
|
}
|
|
5218
5218
|
if (hasToolCalls && response.stop_reason === "tool_use") {
|
|
5219
|
-
const
|
|
5220
|
-
|
|
5221
|
-
max_tokens: LLM_MAX_TOKENS,
|
|
5222
|
-
system: systemPrompt,
|
|
5223
|
-
messages: this.state.history,
|
|
5224
|
-
tools: this.tools
|
|
5225
|
-
});
|
|
5226
|
-
for (const block of followUp.content) {
|
|
5227
|
-
if (block.type === "text") {
|
|
5228
|
-
textResponse += block.text;
|
|
5229
|
-
this.emit(AGENT_EVENT.RESPONSE, block.text);
|
|
5230
|
-
}
|
|
5231
|
-
}
|
|
5232
|
-
this.state.history.push({
|
|
5233
|
-
role: "assistant",
|
|
5234
|
-
content: followUp.content
|
|
5235
|
-
});
|
|
5219
|
+
const continuedResponse = await this.processChatToolLoop(systemPrompt);
|
|
5220
|
+
textResponse += continuedResponse;
|
|
5236
5221
|
} else if (!hasToolCalls) {
|
|
5237
5222
|
this.state.history.push({
|
|
5238
5223
|
role: "assistant",
|
|
@@ -5248,6 +5233,55 @@ ${this.state.findings.filter((f) => f.severity !== "info").map((f) => `- Address
|
|
|
5248
5233
|
return `Error: ${errMsg}`;
|
|
5249
5234
|
}
|
|
5250
5235
|
}
|
|
5236
|
+
/**
|
|
5237
|
+
* Process chat tool loop recursively until we get a text response
|
|
5238
|
+
*/
|
|
5239
|
+
async processChatToolLoop(systemPrompt, maxIterations = 5) {
|
|
5240
|
+
let textResponse = "";
|
|
5241
|
+
let iteration = 0;
|
|
5242
|
+
while (iteration < maxIterations) {
|
|
5243
|
+
iteration++;
|
|
5244
|
+
const response = await this.client.messages.create({
|
|
5245
|
+
model: LLM_MODEL,
|
|
5246
|
+
max_tokens: LLM_MAX_TOKENS,
|
|
5247
|
+
system: systemPrompt,
|
|
5248
|
+
messages: this.state.history,
|
|
5249
|
+
tools: this.tools
|
|
5250
|
+
});
|
|
5251
|
+
let hasToolCalls = false;
|
|
5252
|
+
for (const block of response.content) {
|
|
5253
|
+
if (block.type === "text") {
|
|
5254
|
+
textResponse += block.text;
|
|
5255
|
+
this.emit(AGENT_EVENT.RESPONSE, block.text);
|
|
5256
|
+
} else if (block.type === "tool_use") {
|
|
5257
|
+
hasToolCalls = true;
|
|
5258
|
+
this.emit(AGENT_EVENT.TOOL_CALL, { name: block.name, input: block.input });
|
|
5259
|
+
const result = await executeToolCall(block.name, block.input);
|
|
5260
|
+
this.emit(AGENT_EVENT.TOOL_RESULT, { name: block.name, result });
|
|
5261
|
+
this.state.history.push({
|
|
5262
|
+
role: "assistant",
|
|
5263
|
+
content: response.content
|
|
5264
|
+
});
|
|
5265
|
+
this.state.history.push({
|
|
5266
|
+
role: "user",
|
|
5267
|
+
content: [{
|
|
5268
|
+
type: "tool_result",
|
|
5269
|
+
tool_use_id: block.id,
|
|
5270
|
+
content: typeof result === "string" ? result : JSON.stringify(result)
|
|
5271
|
+
}]
|
|
5272
|
+
});
|
|
5273
|
+
}
|
|
5274
|
+
}
|
|
5275
|
+
if (!hasToolCalls || response.stop_reason !== "tool_use") {
|
|
5276
|
+
this.state.history.push({
|
|
5277
|
+
role: "assistant",
|
|
5278
|
+
content: response.content
|
|
5279
|
+
});
|
|
5280
|
+
break;
|
|
5281
|
+
}
|
|
5282
|
+
}
|
|
5283
|
+
return textResponse;
|
|
5284
|
+
}
|
|
5251
5285
|
/**
|
|
5252
5286
|
* Build a context-aware prompt for chat interactions
|
|
5253
5287
|
*/
|