Skip to content

Commit ce4267a

Browse files
WebMemories: Add a new "summary" extraction mode (#1350)
- add new mode that is more expensive than the manual-only basic mode but not as comprehensive as the content mode. - Add indexing service in browser agent project. this maximizes code re-use. - Enable agents to declare their index servers in the manifest. Without this change, we would have needed dispatcher to have a build-time dependency on the particular indexing service provider.
1 parent aa895ac commit ce4267a

39 files changed

+2412
-174
lines changed

ts/packages/agentSdk/src/agentInterface.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,16 @@ import { Entity } from "./memory.js";
88
import { Profiler } from "./profiler.js";
99
import { TemplateSchema } from "./templateInput.js";
1010

11+
//==============================================================================
12+
// Indexing Service Types
13+
//==============================================================================
14+
export type IndexingServiceConfig = {
15+
serviceScript: string;
16+
description?: string;
17+
};
18+
19+
export type IndexingServicesManifest = Record<string, IndexingServiceConfig>;
20+
1121
//==============================================================================
1222
// Manifest
1323
//==============================================================================
@@ -17,6 +27,7 @@ export type AppAgentManifest = {
1727
commandDefaultEnabled?: boolean;
1828
localView?: boolean; // whether the agent serve a local view, default is false
1929
sharedLocalView?: string[]; // list of agents to share the local view with, default is none
30+
indexingServices?: IndexingServicesManifest;
2031
} & ActionManifest;
2132

2233
export type SchemaTypeNames = {

ts/packages/agents/browser/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"./agent/manifest": "./src/agent/manifest.json",
1818
"./agent/handlers": "./dist/agent/actionHandler.mjs",
1919
"./agent/types": "./dist/common/browserControl.mjs",
20+
"./agent/indexing": "./dist/agent/indexing/browserIndexingService.js",
2021
"./contentScriptRpc/types": "./dist/common/contentScriptRpc/types.mjs",
2122
"./contentScriptRpc/client": "./dist/common/contentScriptRpc/client.mjs"
2223
},

ts/packages/agents/browser/src/agent/actionHandler.mts

Lines changed: 69 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1325,10 +1325,6 @@ async function handleWebsiteAction(
13251325
// Create progress callback similar to importWebsiteDataWithProgress
13261326
const folderProgressCallback = (message: string) => {
13271327
// Extract progress info from message if possible
1328-
// Updated regex to match format: "X/Y files processed (Z%): description"
1329-
const progressMatch = message.match(
1330-
/(\d+)\/(\d+)\s+files\s+processed.*?:\s*(.+)/,
1331-
);
13321328
let current = 0,
13331329
total = 0,
13341330
item = "";
@@ -1341,46 +1337,85 @@ async function handleWebsiteAction(
13411337
| "complete"
13421338
| "error" = "processing";
13431339

1344-
if (progressMatch) {
1345-
current = parseInt(progressMatch[1]);
1346-
total = parseInt(progressMatch[2]);
1347-
item = progressMatch[3];
1340+
// Handle JSON progress format from logStructuredProgress
1341+
if (message.includes("PROGRESS_JSON:")) {
1342+
try {
1343+
const jsonStart =
1344+
message.indexOf("PROGRESS_JSON:") +
1345+
"PROGRESS_JSON:".length;
1346+
const progressData = JSON.parse(
1347+
message.substring(jsonStart),
1348+
);
13481349

1349-
// Determine phase based on progress
1350-
if (current === 0) {
1351-
phase = "initializing";
1352-
} else if (current === total) {
1353-
phase = "complete";
1354-
} else {
1355-
phase = "processing";
1350+
current = progressData.current ?? 0;
1351+
total = progressData.total ?? 0;
1352+
item = progressData.description ?? "";
1353+
phase = progressData.phase ?? "processing";
1354+
1355+
console.log(
1356+
"✅ Parsed JSON progress data:",
1357+
progressData,
1358+
);
1359+
console.log(
1360+
"✅ Extracted values - current:",
1361+
current,
1362+
"total:",
1363+
total,
1364+
"item:",
1365+
item,
1366+
);
1367+
} catch (error) {
1368+
console.warn("Failed to parse JSON progress:", error);
1369+
// Fall back to regex parsing
13561370
}
13571371
} else {
1358-
// Fallback: try to extract just the description for other message types
1359-
item = message;
1372+
// Existing regex logic for other message formats
1373+
// Updated regex to match format: "X/Y files processed (Z%): description"
1374+
const progressMatch = message.match(
1375+
/(\d+)\/(\d+)\s+files\s+processed.*?:\s*(.+)/,
1376+
);
13601377

1361-
// Determine phase from message content
1362-
if (
1363-
message.includes("complete") ||
1364-
message.includes("finished")
1365-
) {
1366-
phase = "complete";
1367-
} else if (
1368-
message.includes("Found") ||
1369-
message.includes("Starting")
1370-
) {
1371-
phase = "initializing";
1372-
} else if (message.startsWith("Processing:")) {
1373-
phase = "processing";
1374-
// For individual file processing, preserve any previously known total
1375-
total = parameters.totalItems || 0;
1378+
if (progressMatch) {
1379+
current = parseInt(progressMatch[1]);
1380+
total = parseInt(progressMatch[2]);
1381+
item = progressMatch[3];
1382+
1383+
// Determine phase based on progress
1384+
if (current === 0) {
1385+
phase = "initializing";
1386+
} else if (current === total) {
1387+
phase = "complete";
1388+
} else {
1389+
phase = "processing";
1390+
}
1391+
} else {
1392+
// Fallback: try to extract just the description for other message types
1393+
item = message;
1394+
1395+
// Determine phase from message content
1396+
if (
1397+
message.includes("complete") ||
1398+
message.includes("finished")
1399+
) {
1400+
phase = "complete";
1401+
} else if (
1402+
message.includes("Found") ||
1403+
message.includes("Starting")
1404+
) {
1405+
phase = "initializing";
1406+
} else if (message.startsWith("Processing:")) {
1407+
phase = "processing";
1408+
// For individual file processing, preserve any previously known total
1409+
total = parameters.totalItems || 0;
1410+
}
13761411
}
13771412
}
13781413

13791414
// Create progress data matching ImportProgress interface
13801415
const progressData = {
13811416
phase,
1382-
totalItems: total || parameters.totalItems || 0,
1383-
processedItems: current || 0,
1417+
totalItems: total,
1418+
processedItems: current,
13841419
currentItem: item,
13851420
importId: parameters.importId,
13861421
errors: [],

0 commit comments

Comments
 (0)