dp-worker 0.1.5 → 0.1.7

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 (63) hide show
  1. package/builtin-skills/x.md +36 -28
  2. package/config.example.json +2 -0
  3. package/dist/agent/agent.js +1 -1
  4. package/dist/agent/agent.js.map +1 -1
  5. package/dist/agent/chat-engine.js +36 -13
  6. package/dist/agent/chat-engine.js.map +1 -1
  7. package/dist/agent/context.d.ts +2 -0
  8. package/dist/agent/context.js +4 -2
  9. package/dist/agent/context.js.map +1 -1
  10. package/dist/agent/task-runner.js +17 -16
  11. package/dist/agent/task-runner.js.map +1 -1
  12. package/dist/agent/tool-loop-detection.js +7 -3
  13. package/dist/agent/tool-loop-detection.js.map +1 -1
  14. package/dist/agent/tool-runner.js +2 -2
  15. package/dist/browser/actions.d.ts +26 -1
  16. package/dist/browser/actions.js +493 -242
  17. package/dist/browser/actions.js.map +1 -1
  18. package/dist/browser/chrome-process.d.ts +25 -3
  19. package/dist/browser/chrome-process.js +118 -14
  20. package/dist/browser/chrome-process.js.map +1 -1
  21. package/dist/browser/dispatch.js +32 -8
  22. package/dist/browser/dispatch.js.map +1 -1
  23. package/dist/browser/expect.d.ts +6 -1
  24. package/dist/browser/expect.js +32 -10
  25. package/dist/browser/expect.js.map +1 -1
  26. package/dist/browser/extension-relay.d.ts +9 -0
  27. package/dist/browser/extension-relay.js +579 -0
  28. package/dist/browser/extension-relay.js.map +1 -0
  29. package/dist/browser/manager.d.ts +11 -0
  30. package/dist/browser/manager.js +106 -26
  31. package/dist/browser/manager.js.map +1 -1
  32. package/dist/browser/page-outline.d.ts +36 -0
  33. package/dist/browser/page-outline.js +703 -0
  34. package/dist/browser/page-outline.js.map +1 -0
  35. package/dist/browser/script-runner.js +4 -2
  36. package/dist/browser/script-runner.js.map +1 -1
  37. package/dist/browser/selectors.js +10 -3
  38. package/dist/browser/selectors.js.map +1 -1
  39. package/dist/browser/snapshot.d.ts +19 -1
  40. package/dist/browser/snapshot.js +145 -24
  41. package/dist/browser/snapshot.js.map +1 -1
  42. package/dist/chrome-extension/omni-flow/background.js +304 -21
  43. package/dist/chrome-extension/omni-flow/connect.html +81 -0
  44. package/dist/chrome-extension/omni-flow/connect.js +43 -0
  45. package/dist/chrome-extension/omni-flow/content.js +13 -21
  46. package/dist/chrome-extension/omni-flow/inject.js +77 -56
  47. package/dist/chrome-extension/omni-flow/manifest.json +6 -3
  48. package/dist/config/center-config.js +2 -0
  49. package/dist/config/center-config.js.map +1 -1
  50. package/dist/config/types.d.ts +16 -2
  51. package/dist/config/types.js +21 -1
  52. package/dist/config/types.js.map +1 -1
  53. package/dist/index.js +11 -1
  54. package/dist/index.js.map +1 -1
  55. package/dist/llm/live-tool-result-guard.d.ts +16 -0
  56. package/dist/llm/live-tool-result-guard.js +57 -0
  57. package/dist/llm/live-tool-result-guard.js.map +1 -0
  58. package/dist/llm/message-optimizer.d.ts +10 -0
  59. package/dist/llm/message-optimizer.js +12 -0
  60. package/dist/llm/message-optimizer.js.map +1 -1
  61. package/dist/llm/tools.js +37 -11
  62. package/dist/llm/tools.js.map +1 -1
  63. package/package.json +1 -1
@@ -6,16 +6,17 @@
6
6
 
7
7
  // Cached proxy credentials in memory for synchronous access during onAuthRequired challenges
8
8
  let activeProxyConfig = null;
9
+ let activeRelayConnection = null;
9
10
 
10
11
  // Initialize settings on service worker startup
11
12
  async function init() {
12
- registerStealthInjection();
13
13
  await setDipclawReady({ status: "starting", source: "dipclaw" });
14
14
  try {
15
15
  globalThis.OMNI_FLOW_BOOTSTRAP_CONFIG = await loadDipclawBootstrapConfig();
16
16
  const bootstrap = getDipclawBootstrap();
17
17
  if (bootstrap && bootstrap.sessionFile) {
18
18
  await importDipclawSession(bootstrap);
19
+ await maybeAutoConnectRelay();
19
20
  return;
20
21
  }
21
22
 
@@ -45,6 +46,7 @@ async function init() {
45
46
  cookieCount: 0,
46
47
  importedAt: new Date().toISOString()
47
48
  });
49
+ await maybeAutoConnectRelay();
48
50
  } catch (err) {
49
51
  const message = err && err.message ? err.message : String(err);
50
52
  console.log("OmniFlow: Dipclaw bootstrap failed:", message);
@@ -54,6 +56,7 @@ async function init() {
54
56
  error: message,
55
57
  importedAt: new Date().toISOString()
56
58
  });
59
+ await maybeAutoConnectRelay().catch(() => {});
57
60
  }
58
61
  }
59
62
 
@@ -474,33 +477,288 @@ chrome.webRequest.onAuthRequired.addListener(
474
477
  ["blocking"]
475
478
  );
476
479
 
477
- // Call initialization
478
- init();
480
+ async function maybeAutoConnectRelay() {
481
+ const bootstrap = getDipclawBootstrap();
482
+ if (!bootstrap || !bootstrap.relay || bootstrap.relay.autoConnect === false) {
483
+ return null;
484
+ }
485
+ return await connectDipclawRelay(bootstrap.relay);
486
+ }
479
487
 
480
- // Register stealth injection script in the MAIN world (100% invisible to DOM & Performance audits)
481
- function registerStealthInjection() {
482
- if (chrome.scripting && chrome.scripting.registerContentScripts) {
483
- chrome.scripting.getRegisteredContentScripts({ ids: ["omniShield"] }, (scripts) => {
484
- if (scripts && scripts.length > 0) {
485
- return;
488
+ async function connectDipclawRelay(relayConfig) {
489
+ const endpoint = normalizeRelayEndpoint(
490
+ relayConfig && relayConfig.extensionWebSocketUrl,
491
+ relayConfig && relayConfig.token
492
+ );
493
+ if (
494
+ activeRelayConnection &&
495
+ activeRelayConnection.endpoint === endpoint &&
496
+ activeRelayConnection.isOpen()
497
+ ) {
498
+ return activeRelayConnection.status();
499
+ }
500
+ if (activeRelayConnection) {
501
+ activeRelayConnection.close();
502
+ }
503
+ const connection = new DipclawRelayConnection(endpoint);
504
+ activeRelayConnection = connection;
505
+ await connection.connect();
506
+ return connection.status();
507
+ }
508
+
509
+ function normalizeRelayEndpoint(rawEndpoint, token) {
510
+ if (!rawEndpoint || typeof rawEndpoint !== "string") {
511
+ throw new Error("relay endpoint is required");
512
+ }
513
+ const url = new URL(rawEndpoint);
514
+ if (url.protocol !== "ws:") {
515
+ throw new Error("relay endpoint must use ws://");
516
+ }
517
+ const host = url.hostname.replace(/^\[/, "").replace(/\]$/, "");
518
+ if (!["127.0.0.1", "localhost", "::1"].includes(host)) {
519
+ throw new Error("relay endpoint must be loopback-only");
520
+ }
521
+ if (token) {
522
+ if (url.searchParams.has("token") && url.searchParams.get("token") !== token) {
523
+ throw new Error("relay token mismatch");
524
+ }
525
+ url.searchParams.set("token", token);
526
+ }
527
+ return url.toString();
528
+ }
529
+
530
+ class DipclawRelayConnection {
531
+ constructor(endpoint) {
532
+ this.endpoint = endpoint;
533
+ this.ws = null;
534
+ this.connectedAt = null;
535
+ }
536
+
537
+ connect() {
538
+ return new Promise((resolve, reject) => {
539
+ const ws = new WebSocket(this.endpoint);
540
+ let settled = false;
541
+ this.ws = ws;
542
+
543
+ const finish = (fn, value) => {
544
+ if (settled) return;
545
+ settled = true;
546
+ fn(value);
547
+ };
548
+
549
+ ws.onopen = async () => {
550
+ this.connectedAt = new Date().toISOString();
551
+ try {
552
+ await this.sendInitialState();
553
+ finish(resolve, undefined);
554
+ } catch (err) {
555
+ finish(reject, err);
556
+ }
557
+ };
558
+ ws.onerror = () => {
559
+ finish(reject, new Error("failed to connect relay websocket"));
560
+ };
561
+ ws.onclose = () => {
562
+ if (activeRelayConnection === this) {
563
+ activeRelayConnection = null;
564
+ }
565
+ };
566
+ ws.onmessage = (event) => {
567
+ void this.handleMessage(event.data);
568
+ };
569
+ });
570
+ }
571
+
572
+ isOpen() {
573
+ return this.ws && this.ws.readyState === WebSocket.OPEN;
574
+ }
575
+
576
+ status() {
577
+ return {
578
+ connected: this.isOpen(),
579
+ endpoint: this.endpoint,
580
+ connectedAt: this.connectedAt
581
+ };
582
+ }
583
+
584
+ close() {
585
+ if (this.ws && this.ws.readyState <= WebSocket.OPEN) {
586
+ this.ws.close(1000, "replaced");
587
+ }
588
+ this.ws = null;
589
+ }
590
+
591
+ async sendInitialState() {
592
+ const tabs = await chrome.tabs.query({});
593
+ const targets = await chrome.debugger.getTargets();
594
+ for (const tab of tabs) {
595
+ if (isRelayTab(tab)) {
596
+ this.sendEvent("chrome.tabs.onCreated", [sanitizeTab(tab)]);
486
597
  }
487
- chrome.scripting.registerContentScripts([{
488
- id: "omniShield",
489
- js: ["inject.js"],
490
- matches: ["<all_urls>"],
491
- runAt: "document_start",
492
- world: "MAIN"
493
- }], () => {
494
- if (chrome.runtime.lastError) {
495
- console.log("OmniFlow: Failed to register stealth injection:", chrome.runtime.lastError.message);
496
- } else {
497
- console.log("OmniFlow: Stealth injection registered successfully.");
598
+ }
599
+ this.sendEvent("extension.initialized", [{
600
+ extensionId: chrome.runtime.id,
601
+ readyState: globalThis.OMNI_FLOW_READY_STATE || null,
602
+ targets
603
+ }]);
604
+ }
605
+
606
+ async handleMessage(raw) {
607
+ let message;
608
+ try {
609
+ message = JSON.parse(String(raw));
610
+ } catch (err) {
611
+ return;
612
+ }
613
+ if (!message || typeof message.id !== "number" || typeof message.method !== "string") {
614
+ return;
615
+ }
616
+ try {
617
+ const result = await handleRelayCommand(message.method, message.params || []);
618
+ this.send({ id: message.id, result: result === undefined ? {} : result });
619
+ } catch (err) {
620
+ this.send({
621
+ id: message.id,
622
+ error: {
623
+ message: err && err.message ? err.message : String(err)
498
624
  }
499
625
  });
500
- });
626
+ }
627
+ }
628
+
629
+ sendEvent(method, params) {
630
+ this.send({ method, params });
631
+ }
632
+
633
+ send(payload) {
634
+ if (this.isOpen()) {
635
+ this.ws.send(JSON.stringify(payload));
636
+ }
637
+ }
638
+ }
639
+
640
+ async function handleRelayCommand(method, params) {
641
+ switch (method) {
642
+ case "chrome.debugger.attach":
643
+ await chrome.debugger.attach(params[0], params[1] || "1.3");
644
+ return {};
645
+ case "chrome.debugger.detach":
646
+ await chrome.debugger.detach(params[0]);
647
+ return {};
648
+ case "chrome.debugger.sendCommand":
649
+ return await chrome.debugger.sendCommand(params[0], params[1], params[2] || {});
650
+ case "chrome.debugger.getTargets":
651
+ return await chrome.debugger.getTargets();
652
+ case "chrome.tabs.create":
653
+ return sanitizeTab(await chrome.tabs.create(params[0] || {}));
654
+ case "chrome.tabs.update":
655
+ return sanitizeTab(await chrome.tabs.update(params[0], params[1] || {}));
656
+ case "chrome.tabs.remove":
657
+ await chrome.tabs.remove(params[0]);
658
+ return {};
659
+ case "chrome.tabs.query":
660
+ return (await chrome.tabs.query(params[0] || {})).filter(isRelayTab).map(sanitizeTab);
661
+ default:
662
+ throw new Error(`unsupported relay command: ${method}`);
663
+ }
664
+ }
665
+
666
+ function sanitizeTab(tab) {
667
+ if (!tab) return tab;
668
+ return {
669
+ id: tab.id,
670
+ index: tab.index,
671
+ windowId: tab.windowId,
672
+ openerTabId: tab.openerTabId,
673
+ active: tab.active,
674
+ title: tab.title || "",
675
+ url: tab.url || "about:blank"
676
+ };
677
+ }
678
+
679
+ function isRelayTab(tab) {
680
+ if (!tab || typeof tab.id !== "number") return false;
681
+ const url = tab.url || tab.pendingUrl || "about:blank";
682
+ return !(
683
+ url.startsWith("chrome://") ||
684
+ url.startsWith("chrome-extension://") ||
685
+ url.startsWith("devtools://")
686
+ );
687
+ }
688
+
689
+ function sendRelayEvent(method, params) {
690
+ if (activeRelayConnection && activeRelayConnection.isOpen()) {
691
+ activeRelayConnection.sendEvent(method, params);
501
692
  }
502
693
  }
503
694
 
695
+ chrome.tabs.onCreated.addListener((tab) => {
696
+ if (isRelayTab(tab)) {
697
+ sendRelayEvent("chrome.tabs.onCreated", [sanitizeTab(tab)]);
698
+ }
699
+ });
700
+
701
+ chrome.tabs.onUpdated.addListener((tabId, changeInfo, tab) => {
702
+ if (isRelayTab(tab)) {
703
+ sendRelayEvent("chrome.tabs.onUpdated", [tabId, changeInfo, sanitizeTab(tab)]);
704
+ }
705
+ });
706
+
707
+ chrome.tabs.onRemoved.addListener((tabId, removeInfo) => {
708
+ sendRelayEvent("chrome.tabs.onRemoved", [tabId, removeInfo || {}]);
709
+ });
710
+
711
+ chrome.debugger.onEvent.addListener((source, method, params) => {
712
+ sendRelayEvent("chrome.debugger.onEvent", [source, method, params || {}]);
713
+ });
714
+
715
+ chrome.debugger.onDetach.addListener((source, reason) => {
716
+ sendRelayEvent("chrome.debugger.onDetach", [source, reason]);
717
+ });
718
+
719
+ function applyStealthConfigToSender(sender, config, sendResponse) {
720
+ if (!sender || !sender.tab || typeof sender.tab.id !== "number") {
721
+ sendResponse({ ok: false, error: "missing sender tab" });
722
+ return;
723
+ }
724
+ const target = { tabId: sender.tab.id };
725
+ if (typeof sender.frameId === "number") {
726
+ target.frameIds = [sender.frameId];
727
+ }
728
+ chrome.scripting.executeScript({
729
+ target,
730
+ world: "MAIN",
731
+ injectImmediately: true,
732
+ func: (stealthConfig) => {
733
+ Object.defineProperty(globalThis, "__OMNI_FLOW_STEALTH_CONFIG__", {
734
+ value: stealthConfig,
735
+ configurable: true
736
+ });
737
+ },
738
+ args: [config || {}]
739
+ }, () => {
740
+ if (chrome.runtime.lastError) {
741
+ sendResponse({ ok: false, error: chrome.runtime.lastError.message });
742
+ return;
743
+ }
744
+ chrome.scripting.executeScript({
745
+ target,
746
+ world: "MAIN",
747
+ injectImmediately: true,
748
+ files: ["inject.js"]
749
+ }, () => {
750
+ if (chrome.runtime.lastError) {
751
+ sendResponse({ ok: false, error: chrome.runtime.lastError.message });
752
+ return;
753
+ }
754
+ sendResponse({ ok: true });
755
+ });
756
+ });
757
+ }
758
+
759
+ // Call initialization
760
+ init();
761
+
504
762
  // ============================================================================
505
763
  // Standalone Window Front-Focus Manager (Stealth Recall UX) - Persistent State Machine
506
764
  // ============================================================================
@@ -535,6 +793,31 @@ chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
535
793
  return false;
536
794
  }
537
795
 
796
+ if (message && message.action === "dipclaw:applyStealth") {
797
+ applyStealthConfigToSender(sender, message.config || {}, sendResponse);
798
+ return true;
799
+ }
800
+
801
+ if (message && message.action === "dipclaw:relayConnect") {
802
+ connectDipclawRelay(message.relay || {})
803
+ .then((status) => sendResponse({ ok: true, status }))
804
+ .catch((err) => sendResponse({
805
+ ok: false,
806
+ error: err && err.message ? err.message : String(err)
807
+ }));
808
+ return true;
809
+ }
810
+
811
+ if (message && message.action === "dipclaw:relayStatus") {
812
+ sendResponse({
813
+ ok: true,
814
+ status: activeRelayConnection
815
+ ? activeRelayConnection.status()
816
+ : { connected: false }
817
+ });
818
+ return false;
819
+ }
820
+
538
821
  if (message && message.action === "registerStandaloneWindow") {
539
822
  const targetWinId = message.windowId;
540
823
  chrome.storage.local.set({ standaloneWindowId: targetWinId }, () => {
@@ -0,0 +1,81 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>OmniFlow Relay</title>
7
+ <style>
8
+ body {
9
+ margin: 0;
10
+ font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
11
+ background: #f7f8fb;
12
+ color: #172033;
13
+ }
14
+
15
+ main {
16
+ max-width: 720px;
17
+ margin: 48px auto;
18
+ padding: 0 24px;
19
+ }
20
+
21
+ h1 {
22
+ margin: 0 0 24px;
23
+ font-size: 24px;
24
+ font-weight: 700;
25
+ }
26
+
27
+ label {
28
+ display: block;
29
+ margin: 16px 0 6px;
30
+ font-size: 13px;
31
+ font-weight: 600;
32
+ color: #4b5875;
33
+ }
34
+
35
+ input {
36
+ width: 100%;
37
+ box-sizing: border-box;
38
+ border: 1px solid #c9d1e3;
39
+ border-radius: 6px;
40
+ padding: 10px 12px;
41
+ font: inherit;
42
+ background: #fff;
43
+ }
44
+
45
+ button {
46
+ margin-top: 18px;
47
+ border: 0;
48
+ border-radius: 6px;
49
+ padding: 10px 14px;
50
+ font: inherit;
51
+ font-weight: 650;
52
+ color: #fff;
53
+ background: #2457d6;
54
+ cursor: pointer;
55
+ }
56
+
57
+ #status {
58
+ margin-top: 18px;
59
+ padding: 12px;
60
+ border-radius: 6px;
61
+ background: #e9edf7;
62
+ color: #26324d;
63
+ white-space: pre-wrap;
64
+ }
65
+ </style>
66
+ </head>
67
+ <body>
68
+ <main>
69
+ <h1>OmniFlow Relay</h1>
70
+ <label for="endpoint">Relay WebSocket endpoint</label>
71
+ <input id="endpoint" placeholder="ws://127.0.0.1:PORT/extension/ID?token=TOKEN" autocomplete="off">
72
+
73
+ <label for="token">Token (optional if endpoint already contains token)</label>
74
+ <input id="token" placeholder="relay token" autocomplete="off">
75
+
76
+ <button id="connect" type="button">Connect</button>
77
+ <div id="status">Checking status...</div>
78
+ </main>
79
+ <script src="connect.js"></script>
80
+ </body>
81
+ </html>
@@ -0,0 +1,43 @@
1
+ const endpointInput = document.getElementById("endpoint");
2
+ const tokenInput = document.getElementById("token");
3
+ const connectButton = document.getElementById("connect");
4
+ const statusBox = document.getElementById("status");
5
+
6
+ function setStatus(value) {
7
+ statusBox.textContent = typeof value === "string"
8
+ ? value
9
+ : JSON.stringify(value, null, 2);
10
+ }
11
+
12
+ function refreshStatus() {
13
+ chrome.runtime.sendMessage({ action: "dipclaw:relayStatus" }, (response) => {
14
+ if (chrome.runtime.lastError) {
15
+ setStatus(chrome.runtime.lastError.message);
16
+ return;
17
+ }
18
+ setStatus(response && response.status ? response.status : response);
19
+ });
20
+ }
21
+
22
+ connectButton.addEventListener("click", () => {
23
+ const extensionWebSocketUrl = endpointInput.value.trim();
24
+ const token = tokenInput.value.trim();
25
+ connectButton.disabled = true;
26
+ setStatus("Connecting...");
27
+ chrome.runtime.sendMessage({
28
+ action: "dipclaw:relayConnect",
29
+ relay: {
30
+ extensionWebSocketUrl,
31
+ ...(token ? { token } : {})
32
+ }
33
+ }, (response) => {
34
+ connectButton.disabled = false;
35
+ if (chrome.runtime.lastError) {
36
+ setStatus(chrome.runtime.lastError.message);
37
+ return;
38
+ }
39
+ setStatus(response && response.ok ? response.status : response);
40
+ });
41
+ });
42
+
43
+ refreshStatus();
@@ -1,9 +1,3 @@
1
- /**
2
- * OmniFlow - Content Script (Manifest V3)
3
- * Reads settings from chrome storage and delegates injection safely to inject.js
4
- * in the page's MAIN context, bypassing site Content Security Policy (CSP) headers.
5
- */
6
-
7
1
  chrome.storage.local.get([
8
2
  'spoofTimezone',
9
3
  'timezoneEnabled',
@@ -11,19 +5,17 @@ chrome.storage.local.get([
11
5
  'hardwareMaskingEnabled',
12
6
  'antiBotEnabled'
13
7
  ], (data) => {
14
- const doc = document.documentElement;
15
-
16
- if (data.timezoneEnabled && data.spoofTimezone) {
17
- doc.dataset.omniTz = data.spoofTimezone;
18
- }
19
- if (data.languagesEnabled !== false) {
20
- doc.dataset.omniLang = "true";
21
- }
22
- if (data.hardwareMaskingEnabled !== false) {
23
- doc.dataset.omniHardware = "true";
24
- }
25
- if (data.antiBotEnabled !== false) {
26
- doc.dataset.omniBot = "true";
27
- }
28
-
8
+ chrome.runtime.sendMessage({
9
+ action: "dipclaw:applyStealth",
10
+ config: {
11
+ spoofTimezone: data.spoofTimezone || "",
12
+ timezoneEnabled: data.timezoneEnabled !== false,
13
+ languagesEnabled: data.languagesEnabled !== false,
14
+ hardwareMaskingEnabled: data.hardwareMaskingEnabled !== false,
15
+ antiBotEnabled: data.antiBotEnabled !== false
16
+ }
17
+ }, () => {
18
+ // Ignore service-worker wakeup races and closed-frame errors.
19
+ void chrome.runtime.lastError;
20
+ });
29
21
  });