Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 48 additions & 1 deletion ts/packages/agents/browser/src/agent/browserActionHandler.mts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ import registerDebug from "debug";

import { handleInstacartAction } from "./instacart/actionHandler.mjs";
import * as website from "website-memory";
import { createGraphologyPersistenceManager } from "./knowledge/utils/graphologyPersistence.mjs";
import { handleKnowledgeAction } from "./knowledge/actions/knowledgeActionRouter.mjs";
import { ExtractKnowledgeHandler } from "./knowledge/extractKnowledgeCommand.mjs";
import {
Expand Down Expand Up @@ -655,7 +656,6 @@ async function processBrowserAgentMessage(
case "getTopicMetrics":
case "getTopicTimelines":
case "getViewportBasedNeighborhood":
case "testMergeTopicHierarchies":
case "mergeTopicHierarchies":
case "discoverRelatedKnowledge":
case "getTopicDetails":
Expand Down Expand Up @@ -792,6 +792,10 @@ async function initializeWebsiteIndex(
websiteIndexes[0].path,
"index",
);

// Initialize JSON storage alongside SQLite
await initializeGraphologyStorage(context, websiteIndexes[0].path);

debug(
`Loaded website index with ${context.agentContext.websiteCollection?.messages.length || 0} websites`,
);
Expand Down Expand Up @@ -848,6 +852,12 @@ async function initializeWebsiteIndex(
sizeOnDisk: 0,
};

// Initialize JSON storage and perform migration if needed
await initializeGraphologyStorage(
context,
indexPath,
);

debug(
`Loaded existing website collection with ${websiteCollection.messages.length} websites from ${indexPath}`,
);
Expand Down Expand Up @@ -891,6 +901,9 @@ async function initializeWebsiteIndex(
sizeOnDisk: 0,
};

// Initialize JSON storage for new index
await initializeGraphologyStorage(context, indexPath);

debug(
`Index will be created at ${indexPath} when first page is indexed`,
);
Expand Down Expand Up @@ -918,6 +931,40 @@ async function initializeWebsiteIndex(
}
}

/**
* Initialize Graphology storage for pure Graphology architecture
*/
async function initializeGraphologyStorage(
context: SessionContext<BrowserActionContext>,
indexPath: string,
): Promise<void> {
try {
debug("Initializing Graphology storage");

// Create storage path for Graphology files
const graphologyStoragePath = path.join(indexPath, "storage");

// Create Graphology persistence manager
const persistenceManager = createGraphologyPersistenceManager(
graphologyStoragePath,
);

// Store reference in context for later use (maintaining compatibility)
if (!context.agentContext.graphJsonStorage) {
context.agentContext.graphJsonStorage = {
manager: persistenceManager,
lastEntityGraphUpdate: null,
lastTopicGraphUpdate: null,
};
}

debug("Graphology storage initialization complete");
} catch (error) {
debug(`Error initializing Graphology storage: ${error}`);
// Don't throw - this should not break the main initialization
}
}

async function getSessionFolderPath(
context: SessionContext<BrowserActionContext>,
) {
Expand Down
1 change: 1 addition & 0 deletions ts/packages/agents/browser/src/agent/browserActions.mts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export type BrowserActionContext = {
tabTitleIndex?: TabTitleIndex | undefined;
allowDynamicAgentDomains?: string[];
websiteCollection?: website.WebsiteCollection | undefined;
graphJsonStorage?: any | undefined; // GraphologyPersistenceManager - field name maintained for compatibility
fuzzyMatchingModel?: TextEmbeddingModel | undefined;
index: website.IndexData | undefined;
viewProcess?: ChildProcess | undefined;
Expand Down
Loading