cdp-toolkit 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/types.ts ADDED
@@ -0,0 +1,63 @@
1
+ /**
2
+ * Shared types for the raw-CDP toolkit.
3
+ *
4
+ * The toolkit speaks the Chrome DevTools Protocol directly over the
5
+ * remote-debugging WebSocket (default ws://127.0.0.1:9222), with no Puppeteer
6
+ * / chrome-devtools-mcp layer in between. See CONTRACT.md for the design rules
7
+ * every tool module follows.
8
+ */
9
+
10
+ /** A CDP target as returned by GET /json/list. */
11
+ export interface Target {
12
+ id: string;
13
+ type: "page" | "background_page" | "service_worker" | "shared_worker" | "browser" | "other" | string;
14
+ title: string;
15
+ url: string;
16
+ webSocketDebuggerUrl: string;
17
+ /** present on some Chromium builds */
18
+ parentId?: string;
19
+ faviconUrl?: string;
20
+ }
21
+
22
+ /** Raw CDP response envelope. */
23
+ export interface CdpResponse<T = unknown> {
24
+ id: number;
25
+ result?: T;
26
+ error?: { code: number; message: string; data?: unknown };
27
+ }
28
+
29
+ /** Raw CDP event envelope. */
30
+ export interface CdpEvent<P = Record<string, unknown>> {
31
+ method: string;
32
+ params: P;
33
+ /** flat-session id when attached via Target.attachToTarget(flatten:true) */
34
+ sessionId?: string;
35
+ }
36
+
37
+ /**
38
+ * Target selector grammar accepted by resolveTarget():
39
+ * - undefined / "active" -> first page-type target
40
+ * - "<32-hex targetId>" -> exact target by id
41
+ * - "index:N" -> Nth page-type target (0-based)
42
+ * - "url:<substring>" -> first page whose url contains substring
43
+ * - "title:<substring>" -> first page whose title contains substring
44
+ */
45
+ export type TargetSelector = string | undefined;
46
+
47
+ /**
48
+ * The canonical element-reference scheme shared across take_snapshot and every
49
+ * interaction tool (click/hover/fill/...). A `uid` IS a CDP backendDOMNodeId
50
+ * (a number, stable while the node exists in the live DOM). This makes refs
51
+ * stateless: take_snapshot emits them, interaction tools resolve them via
52
+ * DOM.resolveNode({ backendNodeId: uid }). No server-side ref table is kept.
53
+ */
54
+ export type Uid = number;
55
+
56
+ export interface ToolResult<T = unknown> {
57
+ ok: boolean;
58
+ tool: string;
59
+ data?: T;
60
+ error?: string;
61
+ /** terminal-state evidence: artifact paths, observed values, etc. */
62
+ evidence?: Record<string, unknown>;
63
+ }