clean-up few things

* remove un-used files like readabilty

* posthog key to ENV

* update sample env

* dropped v2 prefix

* fix build

* fix package.json files
This commit is contained in:
Nikhil
2025-07-19 13:46:58 -07:00
committed by GitHub
parent 381b8d649f
commit 48c19c775f
24 changed files with 1180 additions and 26355 deletions

View File

@@ -1,3 +1,2 @@
ANTHROPIC_API_KEY=""
OPENAI_API_KEY=""
GEMINI_API_KEY=""
LITELLM_API_KEY=""
POSTHOG_API_KEY=""

View File

@@ -43,7 +43,7 @@
"content_scripts": [
{
"matches": ["<all_urls>"],
"js": ["buildDomTree.js", "content.js"],
"js": ["content.js"],
"run_at": "document_start",
"all_frames": true
}

15865
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -45,7 +45,6 @@
"ollama": "^0.5.16",
"openai": "^4.98.0",
"posthog-js": "^1.252.0",
"puppeteer-core": "^24.8.2",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-markdown": "^10.1.0",
@@ -69,7 +68,6 @@
"@types/chrome": "^0.0.260",
"@types/react": "^18.2.45",
"@types/react-dom": "^18.2.18",
"@types/webextension-polyfill": "^0.12.3",
"@typescript-eslint/eslint-plugin": "^6.15.0",
"@typescript-eslint/parser": "^6.15.0",
"@vitest/ui": "^1.6.0",

5181
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -7,7 +7,7 @@ import { UIEventHandler } from '@/lib/events/UIEventHandler'
// Removed deprecated IStreamingCallbacks import
import { IntentPredictionOrchestrator } from '@/lib/orchestrators/IntentPredictionOrchestrator'
import { ExecutionContext } from '@/lib/runtime/ExecutionContext'
import BrowserContext from '@/lib/browser/BrowserContextV2'
import BrowserContext from '@/lib/browser/BrowserContext'
import MessageManager from '@/lib/runtime/MessageManager'
import posthog from 'posthog-js'
import { isDevelopmentMode } from '@/config'
@@ -19,14 +19,20 @@ import { isDevelopmentMode } from '@/config'
// Initialize LogUtility first
Logging.initialize({ debugMode: isDevelopmentMode() })
// Initialize PostHog for analytics
posthog.init('phc_nWs0kBH4Kx4lYOQNFL4lzUncjnEHuDPsCwhewmEgOOJ', {
api_host: 'https://us.i.posthog.com',
person_profiles: 'identified_only',
})
// Initialize PostHog for analytics only if API key is provided
const posthogApiKey = process.env.POSTHOG_API_KEY
if (posthogApiKey) {
posthog.init(posthogApiKey, {
api_host: 'https://us.i.posthog.com',
person_profiles: 'identified_only',
})
}
// Function to capture events with ai_chat prefix
function captureEvent(eventName: string, properties?: Record<string, any>) {
if (!posthogApiKey) {
return // Skip if PostHog is not configured
}
const prefixedEventName = `ai_chat:${eventName}`
posthog.capture(prefixedEventName, properties)
// debugLog(`📊 PostHog event: ${prefixedEventName}`, 'info')
@@ -106,67 +112,6 @@ const connectedPorts = new Map<string, chrome.runtime.Port>();
let isPanelOpen = false;
let isToggling = false; // Prevent rapid toggle issues
/**
* Check if buildDomTree script is already injected in the tab
* @param tabId - The tab to check
* @returns True if script is already injected
*/
async function isScriptInjected(tabId: number): Promise<boolean> {
try {
const results = await chrome.scripting.executeScript({
target: { tabId },
func: () => Object.prototype.hasOwnProperty.call(window, 'buildDomTree'),
})
return results[0]?.result || false
} catch (err) {
debugLog(`Failed to check script injection status for tab ${tabId}: ${err}`, 'warning')
return false
}
}
/**
* Inject the buildDomTree script into a tab
* @param tabId - The tab to inject into
*/
async function injectBuildDomTree(tabId: number): Promise<void> {
try {
// Check if already injected
const alreadyInjected = await isScriptInjected(tabId)
if (alreadyInjected) {
// Scripts already injected, skipping
return
}
await chrome.scripting.executeScript({
target: { tabId },
files: ['buildDomTree.js'],
})
// buildDomTree.js successfully injected
} catch (err) {
debugLog(`Failed to inject scripts into tab ${tabId}: ${err}`, 'error')
}
}
/**
* Ensure buildDomTree script is injected in specified tabs
* @param tabIds - Array of tab IDs to check and inject if needed
*/
async function ensureScriptInjected(tabIds?: number[]): Promise<void> {
if (!tabIds || tabIds.length === 0) {
// If no specific tabs, inject into all active HTTP/HTTPS tabs
const tabs = await chrome.tabs.query({ url: ['http://*/*', 'https://*/*'] })
tabIds = tabs.map(tab => tab.id).filter((id): id is number => id !== undefined)
}
// Ensuring buildDomTree script is injected
// Inject script into each tab
await Promise.all(tabIds.map(tabId =>
injectBuildDomTree(tabId).catch(err =>
debugLog(`Failed to inject into tab ${tabId}: ${err}`, 'warning')
)
))
}
/**
* Handle intent bubble click from content script
@@ -221,17 +166,6 @@ function initialize(): void {
debugLog(`Failed to initialize NxtScape at startup: ${error}`, 'error')
})
// Inject buildDomTree script into all existing HTTP/HTTPS tabs
chrome.tabs.query({ url: ['http://*/*', 'https://*/*'] }, (tabs) => {
tabs.forEach(tab => {
if (tab.id) {
injectBuildDomTree(tab.id).catch(error => {
debugLog(`Failed to inject script into existing tab ${tab.id}: ${error}`, 'warning')
})
}
})
// Injected buildDomTree.js into existing tabs
})
// Register port connection listener (port-based messaging only)
chrome.runtime.onConnect.addListener(handlePortConnection)
@@ -317,10 +251,6 @@ function initialize(): void {
// triggerIntentPrediction(tabId)
// }
//
// // Inject buildDomTree script
// injectBuildDomTree(tabId).catch(error => {
// debugLog(`Error injecting script into tab ${tabId}: ${error}`, 'error')
// })
// }
}
})
@@ -652,8 +582,6 @@ async function handleExecuteQueryPort(
// Initialize NxtScape if not already done
await ensureNxtScapeInitialized()
// Ensure buildDomTree script is injected in the target tabs
await ensureScriptInjected(payload.tabIds)
// Create EventBus for streaming
const { eventBus, cleanup: cleanupFn } = createStreamingEventBus()

View File

@@ -21,7 +21,7 @@ import { StreamEventBus } from "@/lib/events";
import { StreamEventProcessor } from "../events/StreamEventProcessor";
// Removed deprecated IStreamProcessor import
import { ToolRegistry } from "@/lib/tools/base/ToolRegistry";
import BrowserContext from "../browser/BrowserContextV2";
import BrowserContext from "../browser/BrowserContext";
import { getDomainFromUrl } from "../browser/Utils";
import { Runnable } from "@langchain/core/runnables";
import { RunnableConfig } from "@langchain/core/runnables";

View File

@@ -7,71 +7,61 @@
*/
// Base agent
export {
export {
BaseAgent as LangChainBaseAgent,
AgentOptions as LangChainAgentOptions,
AgentOptionsSchema as LangChainAgentOptionsSchema,
} from './BaseAgent';
} from "./BaseAgent";
// Productivity agent
export {
export {
ProductivityAgent,
ProductivityOutput,
ProductivityOutputSchema
} from './ProductivityAgent';
ProductivityOutputSchema,
} from "./ProductivityAgent";
// Browse agent
export {
BrowseAgent,
BrowseOutput,
BrowseOutputSchema
} from './BrowseAgent';
export { BrowseAgent, BrowseOutput, BrowseOutputSchema } from "./BrowseAgent";
// Classification agent
export {
export {
ClassificationAgent,
ClassificationOutput,
ClassificationOutputSchema
} from './ClassificationAgent';
ClassificationOutputSchema,
} from "./ClassificationAgent";
// Planner agent
export { PlannerAgent } from './PlannerAgent';
export { PlannerAgent } from "./PlannerAgent";
// Validator agent
export {
ValidatorAgent
} from './ValidatorAgent';
export { ValidatorAgent } from "./ValidatorAgent";
// Answer agent
export {
AnswerAgent,
AnswerOutput,
AnswerOutputSchema
} from './AnswerAgent';
export { AnswerAgent, AnswerOutput, AnswerOutputSchema } from "./AnswerAgent";
// Intent prediction agent
export {
IntentPredictionAgent,
IntentPredictionOutput,
IntentPredictionOutputSchema
} from './IntentPredictionAgent';
// Streaming components
export * from './streaming';
IntentPredictionOutputSchema,
} from "./IntentPredictionAgent";
// Agent categories for reference
export const AGENT_TYPES = {
PRODUCTIVITY: 'productivity', // Tab management and browser operations
NAVIGATION: 'navigation', // Web navigation and automation (future)
BROWSE: 'browse', // Full web browsing automation
ANSWER: 'answer', // Question answering about web content
PRODUCTIVITY: "productivity", // Tab management and browser operations
NAVIGATION: "navigation", // Web navigation and automation (future)
BROWSE: "browse", // Full web browsing automation
ANSWER: "answer", // Question answering about web content
} as const;
/**
* Agent descriptions for UI/documentation
*/
export const AGENT_DESCRIPTIONS = {
[AGENT_TYPES.PRODUCTIVITY]: 'Tab management and browser productivity features',
[AGENT_TYPES.BROWSE]: 'Complete web browsing automation with planning and validation',
[AGENT_TYPES.ANSWER]: 'Question answering and content analysis for web pages'
} as const;
[AGENT_TYPES.PRODUCTIVITY]:
"Tab management and browser productivity features",
[AGENT_TYPES.BROWSE]:
"Complete web browsing automation with planning and validation",
[AGENT_TYPES.ANSWER]: "Question answering and content analysis for web pages",
} as const;

View File

@@ -1,2 +0,0 @@
// Streaming infrastructure for LangChain-based agents
export { StreamEventProcessor } from '../../events/StreamEventProcessor';

View File

@@ -1,5 +1,5 @@
import { z } from 'zod';
import BrowserPage from './BrowserPageV2';
import BrowserPage from './BrowserPage';
import { Logging } from '../utils/Logging';
import { profileAsync } from '../utils/Profiler';

View File

@@ -1,5 +1,5 @@
import { z } from 'zod';
import { type BrowserContextConfig } from './BrowserContextV2';
import { type BrowserContextConfig } from './BrowserContext';
import { Logging } from '../utils/Logging';
import { getBrowserOSAdapter, type InteractiveNode, type InteractiveSnapshot, type Snapshot, type SnapshotOptions } from './BrowserOSAdapter';
import { profileAsync, profileSync } from '../utils/Profiler';

View File

@@ -1,7 +1,7 @@
import { z } from "zod";
import { StreamEventBus } from "@/lib/events";
import { Logging } from "@/lib/utils/Logging";
import { BrowserContext } from "@/lib/browser/BrowserContextV2";
import { BrowserContext } from "@/lib/browser/BrowserContext";
import { ExecutionContext } from "@/lib/runtime/ExecutionContext";
import MessageManager, {
MessageManagerSettingsSchema,

View File

@@ -3,7 +3,7 @@ import { AgentGraph, createInitialState, AgentGraphStateType } from '@/lib/graph
import { ExecutionContext } from '@/lib/runtime/ExecutionContext';
import { StreamEventBus } from '@/lib/events';
import { Logging } from '@/lib/utils/Logging';
import { BrowserContext } from '@/lib/browser/BrowserContextV2';
import { BrowserContext } from '@/lib/browser/BrowserContext';
import { profileStart, profileEnd, profileAsync } from '@/lib/utils/Profiler';
/**

View File

@@ -1,5 +1,5 @@
import { z } from 'zod'
import BrowserContext from '../browser/BrowserContextV2'
import BrowserContext from '../browser/BrowserContext'
import MessageManager from '@/lib/runtime/MessageManager'
import { StreamEventBus } from '@/lib/events'

View File

@@ -3,7 +3,7 @@ import { NxtscapeTool } from '../base/NxtscapeTool';
import { ToolConfig } from '../base/ToolConfig';
import { ExecutionContext } from '@/lib/runtime/ExecutionContext';
import { Logging } from '@/lib/utils/Logging';
import BrowserPage from '@/lib/browser/BrowserPageV2';
import BrowserPage from '@/lib/browser/BrowserPage';
import type { SnapshotContext, SectionType, Snapshot, LinkInfo } from '@/lib/browser/BrowserOSAdapter';
/**

View File

@@ -5,7 +5,7 @@ import { ExecutionContext } from "@/lib/runtime/ExecutionContext";
import { ToolConfig } from "./ToolConfig";
import { LangChainProviderFactory, LLMOverrides } from "@/lib/llm";
import { Logging } from "@/lib/utils/Logging";
import BrowserContext from "@/lib/browser/BrowserContextV2";
import BrowserContext from "@/lib/browser/BrowserContext";
import { profileStart, profileEnd } from "@/lib/utils/Profiler";
/**

View File

@@ -4,7 +4,7 @@ import { ToolConfig } from '../base/ToolConfig';
import { ExecutionContext } from '@/lib/runtime/ExecutionContext';
import { HumanMessage, SystemMessage } from '@langchain/core/messages';
import { withFlexibleStructuredOutput } from '@/lib/llm/utils/structuredOutput';
import { BrowserState } from '@/lib/browser/BrowserContextV2';
import { BrowserState } from '@/lib/browser/BrowserContext';
import { Logging } from '@/lib/utils/Logging';
import { profileAsync } from '@/lib/utils/Profiler';

View File

@@ -2,7 +2,7 @@ import { z } from 'zod';
import { NxtscapeTool } from '../base/NxtscapeTool';
import { ToolConfig } from '../base/ToolConfig';
import { ExecutionContext } from '@/lib/runtime/ExecutionContext';
import { BrowserPage } from '@/lib/browser/BrowserPageV2';
import { BrowserPage } from '@/lib/browser/BrowserPage';
import { Logging } from '@/lib/utils/Logging';
import { profileAsync } from '@/lib/utils/Profiler';

View File

@@ -2,7 +2,7 @@ import { z } from 'zod';
import { NxtscapeTool } from '../base/NxtscapeTool';
import { ToolConfig } from '../base/ToolConfig';
import { ExecutionContext } from '@/lib/runtime/ExecutionContext';
import { BrowserPage } from '@/lib/browser/BrowserPageV2';
import { BrowserPage } from '@/lib/browser/BrowserPage';
/**
* Enum for navigation operations

View File

@@ -2,7 +2,7 @@ import { z } from 'zod';
import { NxtscapeTool } from '../base/NxtscapeTool';
import { ToolConfig } from '../base/ToolConfig';
import { ExecutionContext } from '@/lib/runtime/ExecutionContext';
import { BrowserPage } from '@/lib/browser/BrowserPageV2';
import { BrowserPage } from '@/lib/browser/BrowserPage';
/**
* Enum for scroll operations

View File

@@ -27,6 +27,7 @@ if (!envKeys.LITELLM_API_KEY) {
// Create environment variables to inject
const processEnv = {
'process.env.LITELLM_API_KEY': JSON.stringify(envKeys.LITELLM_API_KEY),
'process.env.POSTHOG_API_KEY': JSON.stringify(envKeys.POSTHOG_API_KEY || ''),
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV || 'development')
}
@@ -139,9 +140,7 @@ module.exports = {
return content;
}
},
{ from: 'assets', to: 'assets', noErrorOnMissing: true },
{ from: 'public/Readability.js', to: '.' },
{ from: 'public/buildDomTree.js', to: '.' }
{ from: 'assets', to: 'assets', noErrorOnMissing: true }
]
}),
new webpack.DefinePlugin(processEnv),

2231
yarn.lock

File diff suppressed because it is too large Load Diff