2026-10-07 16:03:37 +08:00
|
|
|
import type { ExecutionOptions } from "../AnalysisProvider.js";
|
2026-07-14 17:47:50 +08:00
|
|
|
import type { ElectronObservationPort } from "./ElectronObservationPort.js";
|
2026-10-07 16:03:37 +08:00
|
|
|
import type { Evidence } from "../../domain/evidence.js";
|
2026-07-14 17:47:50 +08:00
|
|
|
import type {
|
|
|
|
|
InspectElectronPageInput,
|
|
|
|
|
ListElectronTargetsInput,
|
2026-10-07 17:16:58 +08:00
|
|
|
} from "../../domain/javascript/electronObservation.js";
|
2026-10-07 16:03:37 +08:00
|
|
|
import { AnalysisCapabilityUnavailableError } from "../../domain/analysisErrorCore.js";
|
2026-10-10 21:04:05 -07:00
|
|
|
import type { AnalysisError } from "../../domain/analysisErrorBase.js";
|
2026-10-07 16:03:37 +08:00
|
|
|
import { err, ok, type Result } from "../../domain/result.js";
|
2026-07-14 17:47:50 +08:00
|
|
|
import { createElectronEvidence } from "./ElectronEvidence.js";
|
|
|
|
|
|
2026-10-05 20:16:44 +08:00
|
|
|
/** List local file pages exposed by the explicitly selected endpoint. */
|
2026-07-14 17:47:50 +08:00
|
|
|
export const listElectronTargets = async (
|
|
|
|
|
provider: ElectronObservationPort | undefined,
|
|
|
|
|
input: ListElectronTargetsInput,
|
|
|
|
|
options: ExecutionOptions = {},
|
|
|
|
|
): Promise<Result<Evidence, AnalysisError>> => {
|
2026-10-05 20:16:44 +08:00
|
|
|
const ready = requireProvider(provider, "list_electron_targets");
|
2026-07-14 17:47:50 +08:00
|
|
|
if (!ready.ok) return ready;
|
|
|
|
|
const result = await ready.value.listTargets(input, options);
|
|
|
|
|
return result.ok
|
|
|
|
|
? ok(
|
|
|
|
|
createElectronEvidence(
|
|
|
|
|
"list_electron_targets",
|
|
|
|
|
input,
|
|
|
|
|
result.value,
|
|
|
|
|
ready.value.identity(),
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
: result;
|
|
|
|
|
};
|
|
|
|
|
|
2026-10-05 20:16:44 +08:00
|
|
|
/** Inspect one local file page from the explicitly selected endpoint. */
|
2026-07-14 17:47:50 +08:00
|
|
|
export const inspectElectronPage = async (
|
|
|
|
|
provider: ElectronObservationPort | undefined,
|
|
|
|
|
input: InspectElectronPageInput,
|
|
|
|
|
options: ExecutionOptions = {},
|
|
|
|
|
): Promise<Result<Evidence, AnalysisError>> => {
|
2026-10-05 20:16:44 +08:00
|
|
|
const ready = requireProvider(provider, "inspect_electron_page");
|
2026-07-14 17:47:50 +08:00
|
|
|
if (!ready.ok) return ready;
|
|
|
|
|
const result = await ready.value.inspectPage(input, options);
|
|
|
|
|
return result.ok
|
|
|
|
|
? ok(
|
|
|
|
|
createElectronEvidence(
|
|
|
|
|
"inspect_electron_page",
|
|
|
|
|
input,
|
|
|
|
|
result.value,
|
|
|
|
|
ready.value.identity(),
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
: result;
|
|
|
|
|
};
|
|
|
|
|
|
2026-10-05 20:16:44 +08:00
|
|
|
const requireProvider = (
|
2026-07-14 17:47:50 +08:00
|
|
|
provider: ElectronObservationPort | undefined,
|
|
|
|
|
operation: "list_electron_targets" | "inspect_electron_page",
|
2026-10-05 20:16:44 +08:00
|
|
|
): Result<ElectronObservationPort, AnalysisError> =>
|
|
|
|
|
provider === undefined
|
2026-07-14 17:47:50 +08:00
|
|
|
? err(
|
|
|
|
|
new AnalysisCapabilityUnavailableError(
|
|
|
|
|
"rea-cdp-electron",
|
|
|
|
|
operation,
|
|
|
|
|
"Electron observation provider is not configured",
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
: ok(provider);
|