@cyberstrike-io/cyberstrike 1.1.12-beta.0 → 1.1.12

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.
Files changed (2) hide show
  1. package/hackbrowser-worker.js +28 -12
  2. package/package.json +12 -12
@@ -40663,7 +40663,7 @@ async function resolveModel(override) {
40663
40663
  }
40664
40664
  throw new Error("No AI provider available. Set ANTHROPIC_API_KEY or OPENAI_API_KEY, " + "or invoke runCrawl({ model }) with a pre-resolved model.");
40665
40665
  }
40666
- async function planPage(snapshot, model) {
40666
+ async function planPage(snapshot, model, usageAcc) {
40667
40667
  const systemPrompt = loadPlannerPrompt();
40668
40668
  const userMessage = JSON.stringify(snapshot);
40669
40669
  const attempt = async () => {
@@ -40674,6 +40674,11 @@ async function planPage(snapshot, model) {
40674
40674
  maxOutputTokens: 2048,
40675
40675
  temperature: 0
40676
40676
  });
40677
+ if (usageAcc) {
40678
+ usageAcc.inputTokens += result.usage.inputTokens ?? 0;
40679
+ usageAcc.outputTokens += result.usage.outputTokens ?? 0;
40680
+ usageAcc.cacheReadTokens += result.usage.cachedInputTokens ?? 0;
40681
+ }
40677
40682
  const raw = result.text.trim();
40678
40683
  log3.debug("planner response", { length: raw.length, raw: raw.slice(0, 500) });
40679
40684
  const start = raw.indexOf("{");
@@ -40697,7 +40702,7 @@ async function planPage(snapshot, model) {
40697
40702
  }
40698
40703
  }
40699
40704
  }
40700
- async function planUnexploredElements(snapshot, unexploredLabels, model) {
40705
+ async function planUnexploredElements(snapshot, unexploredLabels, model, usageAcc) {
40701
40706
  const systemPrompt = loadPlannerPrompt();
40702
40707
  const unexploredSet = new Set(unexploredLabels.map((l) => {
40703
40708
  const match = l.match(/^\[.*?\]\s*(.+)$/);
@@ -40719,6 +40724,11 @@ async function planUnexploredElements(snapshot, unexploredLabels, model) {
40719
40724
  maxOutputTokens: 2048,
40720
40725
  temperature: 0
40721
40726
  });
40727
+ if (usageAcc) {
40728
+ usageAcc.inputTokens += result.usage.inputTokens ?? 0;
40729
+ usageAcc.outputTokens += result.usage.outputTokens ?? 0;
40730
+ usageAcc.cacheReadTokens += result.usage.cachedInputTokens ?? 0;
40731
+ }
40722
40732
  const raw = result.text.trim();
40723
40733
  log3.debug("unexplored planner response", { length: raw.length, raw: raw.slice(0, 500) });
40724
40734
  const start = raw.indexOf("{");
@@ -52830,7 +52840,7 @@ function getPathPatternKey(url2) {
52830
52840
  return null;
52831
52841
  }
52832
52842
  }
52833
- async function explorePageWithAI(page, pageUrl, interceptor, model, globalState, inScope, credentialId, maxPages) {
52843
+ async function explorePageWithAI(page, pageUrl, interceptor, model, globalState, inScope, credentialId, maxPages, usageAcc) {
52834
52844
  const linksToEnqueue = [];
52835
52845
  const semanticActionsDone = new Set;
52836
52846
  csEmit(page, {
@@ -52851,7 +52861,7 @@ async function explorePageWithAI(page, pageUrl, interceptor, model, globalState,
52851
52861
  const vcBlocked = await isViewportCenterBlocked(page);
52852
52862
  const snapshot = buildPlannerSnapshot(pageUrl, elements, globalState, credentialId, vcBlocked);
52853
52863
  csEmit(page, { type: "llm-thinking", reason: "page-plan", elements: elements.length, credential: credentialId });
52854
- const plan = await planPage(snapshot, model);
52864
+ const plan = await planPage(snapshot, model, usageAcc);
52855
52865
  log6.info("page plan received", {
52856
52866
  tasks: plan.tasks.length,
52857
52867
  pageState: plan.pageState ?? "unknown",
@@ -52913,7 +52923,7 @@ async function explorePageWithAI(page, pageUrl, interceptor, model, globalState,
52913
52923
  elements: freshElements.length,
52914
52924
  credential: credentialId
52915
52925
  });
52916
- const newPlan = await planPage(snapshot2, model);
52926
+ const newPlan = await planPage(snapshot2, model, usageAcc);
52917
52927
  applyPlanIntelligence(newPlan, pageUrl, globalState, credentialId, page);
52918
52928
  if (newPlan.tasks.length > 0) {
52919
52929
  log6.debug("re-plan after state change", {
@@ -52977,7 +52987,7 @@ async function explorePageWithAI(page, pageUrl, interceptor, model, globalState,
52977
52987
  elements: currentElements.length,
52978
52988
  credential: credentialId
52979
52989
  });
52980
- const additionalPlan = await planUnexploredElements(snap, unexplored, model);
52990
+ const additionalPlan = await planUnexploredElements(snap, unexplored, model, usageAcc);
52981
52991
  applyPlanIntelligence(additionalPlan, pageUrl, globalState, credentialId, page);
52982
52992
  if (additionalPlan.tasks.length === 0)
52983
52993
  break;
@@ -53033,7 +53043,7 @@ async function explorePageWithAI(page, pageUrl, interceptor, model, globalState,
53033
53043
  elements: freshElements.length,
53034
53044
  credential: credentialId
53035
53045
  });
53036
- const newPlan = await planPage(freshSnap, model);
53046
+ const newPlan = await planPage(freshSnap, model, usageAcc);
53037
53047
  applyPlanIntelligence(newPlan, pageUrl, globalState, credentialId, page);
53038
53048
  if (newPlan.tasks.length > 0) {
53039
53049
  csEmit(page, {
@@ -53474,6 +53484,7 @@ async function runMultiCredential(config2, credentials) {
53474
53484
  const dryRun = config2.dryRun ?? false;
53475
53485
  const panelOn = config2.panel ?? true;
53476
53486
  setPanelEnabled(panelOn);
53487
+ const usageAcc = { inputTokens: 0, outputTokens: 0, cacheReadTokens: 0, cacheWriteTokens: 0 };
53477
53488
  logScope(targetUrl, scopePatterns, !!config2.scope);
53478
53489
  log6.info(`starting multi-credential crawl${dryRun ? " (DRY-RUN)" : ""}`, {
53479
53490
  target: targetUrl,
@@ -53659,7 +53670,7 @@ async function runMultiCredential(config2, credentials) {
53659
53670
  }
53660
53671
  for (const ctx of visitableContexts) {
53661
53672
  log6.info("exploring", { credential: ctx.id, url: entry.url });
53662
- const discovered = await explorePageWithAI(ctx.page, entry.url, ctx.interceptor, model, globalState, inScope, ctx.id, maxPages);
53673
+ const discovered = await explorePageWithAI(ctx.page, entry.url, ctx.interceptor, model, globalState, inScope, ctx.id, maxPages, usageAcc);
53663
53674
  for (const url2 of discovered) {
53664
53675
  enqueueWithContext(url2, ctx.id, pageQueue, visitedPages, inScope, pathPatternCounts);
53665
53676
  }
@@ -53703,7 +53714,8 @@ async function runMultiCredential(config2, credentials) {
53703
53714
  capturedEndpoints: globalState.capturedEndpoints.size,
53704
53715
  pagesExplored,
53705
53716
  totalSteps: globalState.totalSteps,
53706
- errors: []
53717
+ errors: [],
53718
+ usage: usageAcc
53707
53719
  };
53708
53720
  }
53709
53721
  async function run(config2) {
@@ -53717,6 +53729,7 @@ async function run(config2) {
53717
53729
  const serverUrl = config2.cyberstrike.serverUrl ?? "http://127.0.0.1:4096";
53718
53730
  const maxPages = config2.maxSteps ?? 50;
53719
53731
  const dryRun = config2.dryRun ?? false;
53732
+ const usageAcc = { inputTokens: 0, outputTokens: 0, cacheReadTokens: 0, cacheWriteTokens: 0 };
53720
53733
  let credentialId = config2.cyberstrike.credentialId;
53721
53734
  const panelOn = config2.panel ?? true;
53722
53735
  setPanelEnabled(panelOn);
@@ -53891,7 +53904,7 @@ async function run(config2) {
53891
53904
  }
53892
53905
  log6.info("page changed after auth, re-exploring", { url: currentUrl });
53893
53906
  }
53894
- const discovered = await explorePageWithAI(page, currentUrl, interceptor, model, globalState, inScope, SINGLE_CRED, maxPages);
53907
+ const discovered = await explorePageWithAI(page, currentUrl, interceptor, model, globalState, inScope, SINGLE_CRED, maxPages, usageAcc);
53895
53908
  let newEnqueued = 0;
53896
53909
  for (const url2 of discovered) {
53897
53910
  if (enqueueUrl(url2, globalState, inScope))
@@ -53943,7 +53956,8 @@ async function run(config2) {
53943
53956
  capturedEndpoints: globalState.capturedEndpoints.size,
53944
53957
  pagesExplored,
53945
53958
  totalSteps: globalState.totalSteps,
53946
- errors: []
53959
+ errors: [],
53960
+ usage: usageAcc
53947
53961
  };
53948
53962
  }
53949
53963
 
@@ -54025,6 +54039,7 @@ async function runCrawl(opts) {
54025
54039
  capturedEndpoints: 0,
54026
54040
  pagesExplored: 0,
54027
54041
  totalSteps: 0,
54042
+ usage: { inputTokens: 0, outputTokens: 0, cacheReadTokens: 0, cacheWriteTokens: 0 },
54028
54043
  errors: [message]
54029
54044
  };
54030
54045
  } finally {
@@ -54144,7 +54159,8 @@ async function runWorker(opts, signal) {
54144
54159
  type: "result",
54145
54160
  pagesExplored: result.pagesExplored,
54146
54161
  capturedEndpoints: result.capturedEndpoints,
54147
- errors: result.errors
54162
+ errors: result.errors,
54163
+ usage: result.usage
54148
54164
  });
54149
54165
  } catch (err) {
54150
54166
  const message = err instanceof Error ? err.message : String(err);
package/package.json CHANGED
@@ -7,7 +7,7 @@
7
7
  "scripts": {
8
8
  "postinstall": "bun ./postinstall.mjs || node ./postinstall.mjs"
9
9
  },
10
- "version": "1.1.12-beta.0",
10
+ "version": "1.1.12",
11
11
  "license": "AGPL-3.0-only",
12
12
  "keywords": [
13
13
  "cyberstrike",
@@ -40,16 +40,16 @@
40
40
  "playwright": "1.58.2"
41
41
  },
42
42
  "optionalDependencies": {
43
- "@cyberstrike-io/cyberstrike-darwin-x64": "1.1.12-beta.0",
44
- "@cyberstrike-io/cyberstrike-linux-x64-baseline": "1.1.12-beta.0",
45
- "@cyberstrike-io/cyberstrike-linux-arm64": "1.1.12-beta.0",
46
- "@cyberstrike-io/cyberstrike-windows-x64-baseline": "1.1.12-beta.0",
47
- "@cyberstrike-io/cyberstrike-darwin-x64-baseline": "1.1.12-beta.0",
48
- "@cyberstrike-io/cyberstrike-linux-arm64-musl": "1.1.12-beta.0",
49
- "@cyberstrike-io/cyberstrike-linux-x64": "1.1.12-beta.0",
50
- "@cyberstrike-io/cyberstrike-windows-x64": "1.1.12-beta.0",
51
- "@cyberstrike-io/cyberstrike-linux-x64-baseline-musl": "1.1.12-beta.0",
52
- "@cyberstrike-io/cyberstrike-linux-x64-musl": "1.1.12-beta.0",
53
- "@cyberstrike-io/cyberstrike-darwin-arm64": "1.1.12-beta.0"
43
+ "@cyberstrike-io/cyberstrike-darwin-x64": "1.1.12",
44
+ "@cyberstrike-io/cyberstrike-linux-x64-baseline": "1.1.12",
45
+ "@cyberstrike-io/cyberstrike-linux-arm64": "1.1.12",
46
+ "@cyberstrike-io/cyberstrike-windows-x64-baseline": "1.1.12",
47
+ "@cyberstrike-io/cyberstrike-darwin-x64-baseline": "1.1.12",
48
+ "@cyberstrike-io/cyberstrike-linux-arm64-musl": "1.1.12",
49
+ "@cyberstrike-io/cyberstrike-linux-x64": "1.1.12",
50
+ "@cyberstrike-io/cyberstrike-windows-x64": "1.1.12",
51
+ "@cyberstrike-io/cyberstrike-linux-x64-baseline-musl": "1.1.12",
52
+ "@cyberstrike-io/cyberstrike-linux-x64-musl": "1.1.12",
53
+ "@cyberstrike-io/cyberstrike-darwin-arm64": "1.1.12"
54
54
  }
55
55
  }