feat(page-ai): add resumable run journal descriptors

This commit is contained in:
lix-2026
2026-06-09 18:48:46 +08:00
parent 6ef233772e
commit 922965d30f
17 changed files with 3254 additions and 58 deletions
@@ -19,6 +19,47 @@ const CHROMIUM_EXECUTABLE_PATH = process.env.PLAYWRIGHT_CHROMIUM_EXECUTABLE_PATH
|| ["/usr/bin/google-chrome-stable", "/usr/bin/google-chrome", "/snap/bin/chromium"]
.find((candidate) => fs.existsSync(candidate));
async function assertKnowledgeRagDescriptor(requestContext) {
const response = await requestContext.get(`${BASE_URL}/api/page-ai/agents/descriptors?profile=task529-knowledge-rag`);
assert(response.ok(), `descriptor API 失败: ${response.status()} ${await response.text()}`);
const payload = await response.json();
const reasonix = (payload.descriptors || []).find((descriptor) => descriptor.agentId === "reasonix");
assert(reasonix, "descriptor 缺少 Reasonix");
assert.equal(reasonix.capabilityStates?.knowledge_rag?.enabled, true, "Reasonix descriptor 应声明 knowledge_rag enabled");
assert((reasonix.capabilities || []).includes("knowledge_rag"), "Reasonix descriptor capabilities 应包含 knowledge_rag");
const toolNames = new Set((reasonix.tools || []).map((tool) => tool.name));
for (const toolName of ["mnote.knowledge_rag.status", "mnote.knowledge_rag.query", "mnote.knowledge_rag.open_reference"]) {
assert(toolNames.has(toolName), `Reasonix descriptor 缺少 ${toolName}`);
}
}
async function status(requestContext) {
const params = new URLSearchParams({ rootUri: ROOT_URI, workspaceId: WORKSPACE_ID });
const response = await requestContext.get(`${BASE_URL}/api/knowledge-rag/status?${params.toString()}`);
assert(response.ok(), `knowledge-rag status 失败: ${response.status()} ${await response.text()}`);
return await response.json();
}
async function ensureIndexed(requestContext) {
const ingestResponse = await requestContext.post(`${BASE_URL}/api/knowledge-rag/ingest`, {
data: {
rootUri: ROOT_URI,
workspaceId: WORKSPACE_ID,
sources: [{ sourcePath: EXPECTED_RESOURCE }],
},
});
assert(ingestResponse.ok(), `knowledge-rag ingest 失败: ${ingestResponse.status()} ${await ingestResponse.text()}`);
const startedAt = Date.now();
let lastEntry = null;
while (Date.now() - startedAt < 90_000) {
const payload = await status(requestContext);
lastEntry = (payload.registry?.entries || []).find((entry) => entry.sourceRootRelativePath === EXPECTED_RESOURCE) || null;
if (lastEntry?.indexedAtMs && lastEntry?.lightRagDocId && !lastEntry?.stale && !lastEntry?.deletedAtMs) return lastEntry;
await new Promise((resolve) => setTimeout(resolve, 5_000));
}
throw new Error(`等待目标资料入库超时: ${JSON.stringify(lastEntry, null, 2)}`);
}
async function main() {
fs.mkdirSync(OUTPUT_DIR, { recursive: true });
const browser = await chromium.launch({ headless: true, executablePath: CHROMIUM_EXECUTABLE_PATH });
@@ -38,6 +79,8 @@ async function main() {
},
});
assert(auth.ok(), `登录失败: ${auth.status()} ${await auth.text()}`);
await assertKnowledgeRagDescriptor(context.request);
await ensureIndexed(context.request);
const queryResponse = await context.request.post(`${BASE_URL}/api/knowledge-rag/query`, {
data: {