Files
reverse-engineering-anything/src/domain/browserSession.ts
T
郭立 Guo Li 7590b50801 perf(schema): reduce retained integer validator allocations (#4360)
Construct integer formats directly while preserving bounds, refinements, metadata and current shared schema owners. Keep Incur-dependent CLI numeric coercion declarations unchanged.

Verify canonical advertisements, 126 numeric boundary cases, 974 actual CLI parser cases, broad source tests and real public-artifact SDK workflows. Record 72 normal tasks and 12 separate owned-inspector heap diagnostics with whole-family resource bounds; distinguish SDK spans and asymmetric audit overhead. Generate numerical report sections from receipts and reject stale tables through documentation conformance checks.

Closes #6236. Current-head CI and Greptile pass; actionable review findings are addressed. Codex review was unavailable due repository usage limits.
2026-10-22 05:11:08 +00:00

79 lines
2.3 KiB
TypeScript

import { z } from "zod";
import { webRuntimeCommandTimeoutSchema } from "./browserDeadline.js";
import {
browserAllowedOriginsSchema,
browserObservationEndpointSchema,
} from "./browserObservation.js";
import { browserCompletenessSchema } from "./browserCompleteness.js";
import { browserVersionSchema } from "./browserObservationSchemas.js";
/** Input for a navigation-aware browser observation window. */
export const observeWebSessionInputSchema = z.strictObject({
cdp_endpoint: browserObservationEndpointSchema,
allowed_origins: browserAllowedOriginsSchema,
target_id: z.string().trim().min(1),
observation_ms: z.int().min(1).default(10_000),
command_timeout_ms: webRuntimeCommandTimeoutSchema,
});
export type ObserveWebSessionInput = z.infer<
typeof observeWebSessionInputSchema
>;
const timelineEventSchema = z.object({
sequence: z.int().min(1),
type: z.enum([
"navigation_requested",
"navigation_committed",
"same_origin_reload",
"same_document_navigation",
"redirect",
"load_failed",
"lifecycle",
"target_terminated",
"session_detached",
"transport_disconnected",
]),
timestamp: z
.number()
.min(0)
.nullable()
.describe(
"CDP monotonic seconds when supplied; null when the event has no valid comparable producer timestamp.",
),
frame_id: z.string().nullable(),
loader_id: z.string().nullable(),
request_id: z.string().nullable(),
url: z.string().nullable(),
destination_scope: z
.enum(["approved", "outside_policy", "unsupported"])
.nullable(),
detail: z.string().nullable(),
});
/** Navigation-aware session result for external user actions. */
export const webObservationSessionSchema = z.object({
browser: browserVersionSchema,
target: z.object({
target_id: z.string(),
initial_url: z.string(),
final_url: z.string().nullable(),
}),
window: z.object({
armed_at: z.iso.datetime(),
ended_at: z.iso.datetime(),
requested_ms: z.int().min(1),
end_reason: z.enum([
"window_elapsed",
"target_left_scope",
"target_terminated",
"session_detached",
"transport_disconnected",
]),
}),
timeline: z.array(timelineEventSchema),
completeness: browserCompletenessSchema,
limitations: z.array(z.string()),
});
export type WebObservationSession = z.infer<typeof webObservationSessionSchema>;