@pensar/apex 0.0.36-canary.0 → 0.0.39-canary.2f181ec5

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/build/swarm.js CHANGED
@@ -39513,6 +39513,12 @@ var OPENROUTER_MODELS = [
39513
39513
  provider: "openrouter",
39514
39514
  contextLength: 64000
39515
39515
  },
39516
+ {
39517
+ id: "mistralai/mistral-large-2512",
39518
+ name: "Mistral Large 3 2512",
39519
+ provider: "openrouter",
39520
+ contextLength: 262144
39521
+ },
39516
39522
  {
39517
39523
  id: "moonshotai/kimi-k2-thinking",
39518
39524
  name: "Kimi K2 Thinking",
@@ -40114,11 +40120,38 @@ async function summarizeConversation(messages, opts, model) {
40114
40120
  content: `Summarize this conversation to pass to another agent. This was the system prompt: ${opts.system} `
40115
40121
  }
40116
40122
  ];
40117
- const { text: summary } = await generateText({
40123
+ const { text: summary, usage: summaryUsage } = await generateText({
40118
40124
  model,
40119
40125
  system: `You are a helpful assistant that summarizes conversations to pass to another agent. Review the conversation and system prompt at the end provided by the user.`,
40120
40126
  messages: summarizedMessages
40121
40127
  });
40128
+ if (opts.onStepFinish && summaryUsage) {
40129
+ opts.onStepFinish({
40130
+ text: "",
40131
+ reasoning: undefined,
40132
+ reasoningDetails: [],
40133
+ files: [],
40134
+ sources: [],
40135
+ toolCalls: [],
40136
+ toolResults: [],
40137
+ finishReason: "stop",
40138
+ usage: {
40139
+ inputTokens: summaryUsage.inputTokens ?? 0,
40140
+ outputTokens: summaryUsage.outputTokens ?? 0,
40141
+ totalTokens: summaryUsage.totalTokens ?? 0
40142
+ },
40143
+ warnings: [],
40144
+ request: {},
40145
+ response: {
40146
+ id: "summarization",
40147
+ timestamp: new Date,
40148
+ modelId: ""
40149
+ },
40150
+ providerMetadata: undefined,
40151
+ stepType: "initial",
40152
+ isContinued: false
40153
+ });
40154
+ }
40122
40155
  const originalLength = typeof opts.prompt === "string" ? opts.prompt.length : 0;
40123
40156
  const enhancedPrompt = originalLength > 1e5 ? `Context: The previous conversation contained very long content that was summarized.
40124
40157
 
@@ -40266,6 +40299,7 @@ function streamResponse(opts) {
40266
40299
  } = opts;
40267
40300
  const messagesContainer = { current: messages || [] };
40268
40301
  const providerModel = getProviderModel(model, authConfig);
40302
+ let rateLimitRetryCount = 0;
40269
40303
  try {
40270
40304
  const response = streamText({
40271
40305
  model: providerModel,
@@ -40279,6 +40313,16 @@ function streamResponse(opts) {
40279
40313
  messagesContainer.current = opts2.messages;
40280
40314
  return;
40281
40315
  },
40316
+ onError: async ({ error: error46 }) => {
40317
+ if (error46.message.toLowerCase().includes("too many tokens") || error46.message.toLowerCase().includes("overloaded")) {
40318
+ rateLimitRetryCount++;
40319
+ await new Promise((resolve2) => setTimeout(resolve2, 1000 * rateLimitRetryCount));
40320
+ if (rateLimitRetryCount < 20) {
40321
+ return;
40322
+ }
40323
+ }
40324
+ throw error46;
40325
+ },
40282
40326
  onStepFinish,
40283
40327
  abortSignal,
40284
40328
  activeTools,
@@ -40297,7 +40341,7 @@ function streamResponse(opts) {
40297
40341
  throw new Error(`Tool ${toolCall.toolName} not found or has no schema`);
40298
40342
  }
40299
40343
  const jsonSchema2 = inputSchema({ toolName: toolCall.toolName });
40300
- const { object: repairedArgs } = await generateObject({
40344
+ const { object: repairedArgs, usage: repairUsage } = await generateObject({
40301
40345
  model: providerModel,
40302
40346
  schema: tool2.inputSchema,
40303
40347
  prompt: [
@@ -40310,6 +40354,33 @@ function streamResponse(opts) {
40310
40354
  ].join(`
40311
40355
  `)
40312
40356
  });
40357
+ if (onStepFinish && repairUsage) {
40358
+ onStepFinish({
40359
+ text: "",
40360
+ reasoning: undefined,
40361
+ reasoningDetails: [],
40362
+ files: [],
40363
+ sources: [],
40364
+ toolCalls: [],
40365
+ toolResults: [],
40366
+ finishReason: "stop",
40367
+ usage: {
40368
+ inputTokens: repairUsage.inputTokens ?? 0,
40369
+ outputTokens: repairUsage.outputTokens ?? 0,
40370
+ totalTokens: repairUsage.totalTokens ?? 0
40371
+ },
40372
+ warnings: [],
40373
+ request: {},
40374
+ response: {
40375
+ id: "tool-repair",
40376
+ timestamp: new Date,
40377
+ modelId: ""
40378
+ },
40379
+ providerMetadata: undefined,
40380
+ stepType: "initial",
40381
+ isContinued: false
40382
+ });
40383
+ }
40313
40384
  return { ...toolCall, input: JSON.stringify(repairedArgs) };
40314
40385
  } catch (repairError) {
40315
40386
  if (!silent) {
@@ -40336,9 +40407,9 @@ function streamResponse(opts) {
40336
40407
  }
40337
40408
  }
40338
40409
  async function generateObjectResponse(opts) {
40339
- const { model, schema, prompt, system, maxTokens, temperature, authConfig } = opts;
40410
+ const { model, schema, prompt, system, maxTokens, temperature, authConfig, onTokenUsage } = opts;
40340
40411
  const providerModel = getProviderModel(model, authConfig);
40341
- const { object: object3 } = await generateObject({
40412
+ const { object: object3, usage } = await generateObject({
40342
40413
  model: providerModel,
40343
40414
  schema,
40344
40415
  prompt,
@@ -40346,6 +40417,9 @@ async function generateObjectResponse(opts) {
40346
40417
  maxTokens,
40347
40418
  temperature
40348
40419
  });
40420
+ if (onTokenUsage && usage) {
40421
+ onTokenUsage(usage.inputTokens ?? 0, usage.outputTokens ?? 0);
40422
+ }
40349
40423
  return object3;
40350
40424
  }
40351
40425
  // src/core/agent/pentestAgent/prompts.ts
@@ -43698,7 +43772,7 @@ Example workflow:
43698
43772
  execute: async (params) => recordTestResultCore(session, params)
43699
43773
  });
43700
43774
  }
43701
- async function generateTestStrategy(params, model) {
43775
+ async function generateTestStrategy(params, model, onTokenUsage) {
43702
43776
  const prompt = `You are a penetration testing expert. Generate a concise testing strategy:
43703
43777
 
43704
43778
  Attack Type: ${params.knowledge.name}
@@ -43724,12 +43798,15 @@ Be tactical and specific.`;
43724
43798
  model: providerModel,
43725
43799
  prompt
43726
43800
  });
43801
+ if (onTokenUsage && result.usage) {
43802
+ onTokenUsage(result.usage.inputTokens ?? 0, result.usage.outputTokens ?? 0);
43803
+ }
43727
43804
  return result.text;
43728
43805
  } catch (error46) {
43729
43806
  return params.knowledge.adaptiveStrategy;
43730
43807
  }
43731
43808
  }
43732
- async function generatePayload(params, model) {
43809
+ async function generatePayload(params, model, onTokenUsage) {
43733
43810
  const prompt = `Generate ONE ${params.knowledge.name} payload for testing.
43734
43811
 
43735
43812
  Techniques:
@@ -43753,7 +43830,8 @@ Generate ONE specific payload. Return ONLY JSON:
43753
43830
  const result = await generateObjectResponse({
43754
43831
  model,
43755
43832
  schema: PayloadSchema,
43756
- prompt
43833
+ prompt,
43834
+ onTokenUsage
43757
43835
  });
43758
43836
  return result;
43759
43837
  } catch (error46) {
@@ -43766,7 +43844,7 @@ Generate ONE specific payload. Return ONLY JSON:
43766
43844
  technique: technique.name
43767
43845
  };
43768
43846
  }
43769
- async function analyzeResponse(params, model) {
43847
+ async function analyzeResponse(params, model, onTokenUsage) {
43770
43848
  const prompt = `Analyze this security test response:
43771
43849
 
43772
43850
  Attack: ${params.knowledge.name}
@@ -43794,7 +43872,8 @@ Analyze: Is this vulnerable? Return ONLY JSON:
43794
43872
  const result = await generateObjectResponse({
43795
43873
  model,
43796
43874
  schema: AnalysisSchema,
43797
- prompt
43875
+ prompt,
43876
+ onTokenUsage
43798
43877
  });
43799
43878
  return result;
43800
43879
  } catch (error46) {
@@ -43813,7 +43892,7 @@ Analyze: Is this vulnerable? Return ONLY JSON:
43813
43892
  suggestedNextTest: "Try alternative payload or technique"
43814
43893
  };
43815
43894
  }
43816
- function createSmartTestTool(session, model) {
43895
+ function createSmartTestTool(session, model, onTokenUsage) {
43817
43896
  return tool({
43818
43897
  name: "test_parameter",
43819
43898
  description: `Intelligently test a parameter for a vulnerability using AI-powered adaptive testing.
@@ -43883,7 +43962,7 @@ test_parameter({
43883
43962
  parameter,
43884
43963
  endpoint,
43885
43964
  context
43886
- }, model);
43965
+ }, model, onTokenUsage);
43887
43966
  console.log(`Strategy: ${strategy}`);
43888
43967
  const results = [];
43889
43968
  let vulnerable = false;
@@ -43896,7 +43975,7 @@ test_parameter({
43896
43975
  context: { ...context, parameter, endpoint },
43897
43976
  previousResults: results,
43898
43977
  round
43899
- }, model);
43978
+ }, model, onTokenUsage);
43900
43979
  console.log(` Payload: ${payloadData.payload}`);
43901
43980
  console.log(` Reasoning: ${payloadData.reasoning}`);
43902
43981
  let response;
@@ -43925,7 +44004,7 @@ test_parameter({
43925
44004
  attackType,
43926
44005
  knowledge,
43927
44006
  previousResults: results
43928
- }, model);
44007
+ }, model, onTokenUsage);
43929
44008
  console.log(` Analysis: ${analysis.reasoning}`);
43930
44009
  console.log(` Vulnerable: ${analysis.vulnerable} (confidence: ${analysis.confidence})`);
43931
44010
  results.push({
@@ -44375,7 +44454,7 @@ function wrapCommandWithHeaders(command, headers) {
44375
44454
  }
44376
44455
  return wrapped;
44377
44456
  }
44378
- function createPentestTools(session, model, toolOverride) {
44457
+ function createPentestTools(session, model, toolOverride, onTokenUsage) {
44379
44458
  const offensiveHeaders = getOffensiveHeaders(session);
44380
44459
  const rateLimiter = session._rateLimiter;
44381
44460
  const executeCommand = tool({
@@ -44549,7 +44628,7 @@ COMMON TESTING PATTERNS:
44549
44628
  http_request: httpRequest,
44550
44629
  document_finding: createDocumentFindingTool(session),
44551
44630
  record_test_result: createRecordTestResultTool(session),
44552
- test_parameter: createSmartTestTool(session, model || "claude-sonnet-4-20250514"),
44631
+ test_parameter: createSmartTestTool(session, model || "claude-sonnet-4-20250514", onTokenUsage),
44553
44632
  check_testing_coverage: createCheckTestingCoverageTool(session),
44554
44633
  validate_completeness: createValidateCompletenessTool(session),
44555
44634
  enumerate_endpoints: createEnumerateEndpointsTool(session),
@@ -45601,6 +45680,7 @@ function runAgent(opts) {
45601
45680
  objective,
45602
45681
  model,
45603
45682
  onStepFinish,
45683
+ onToolTokenUsage,
45604
45684
  abortSignal,
45605
45685
  silent,
45606
45686
  authConfig,
@@ -45620,7 +45700,7 @@ function runAgent(opts) {
45620
45700
  analyze_scan,
45621
45701
  scratchpad,
45622
45702
  generate_report
45623
- } = createPentestTools(session, undefined, toolOverride);
45703
+ } = createPentestTools(session, undefined, toolOverride, onToolTokenUsage);
45624
45704
  const document_finding = tool({
45625
45705
  name: "document_finding",
45626
45706
  description: `Document a security finding with severity, impact, and remediation guidance.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pensar/apex",
3
- "version": "0.0.36-canary.0",
3
+ "version": "0.0.39-canary.2f181ec5",
4
4
  "description": "AI-powered penetration testing CLI tool with terminal UI",
5
5
  "module": "src/tui/index.tsx",
6
6
  "main": "build/index.js",