@predicatelabs/sdk 0.99.9
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/LICENSE +24 -0
- package/README.md +252 -0
- package/dist/actions.d.ts +185 -0
- package/dist/actions.d.ts.map +1 -0
- package/dist/actions.js +1120 -0
- package/dist/actions.js.map +1 -0
- package/dist/agent-runtime.d.ts +352 -0
- package/dist/agent-runtime.d.ts.map +1 -0
- package/dist/agent-runtime.js +1170 -0
- package/dist/agent-runtime.js.map +1 -0
- package/dist/agent.d.ts +164 -0
- package/dist/agent.d.ts.map +1 -0
- package/dist/agent.js +408 -0
- package/dist/agent.js.map +1 -0
- package/dist/asserts/expect.d.ts +159 -0
- package/dist/asserts/expect.d.ts.map +1 -0
- package/dist/asserts/expect.js +547 -0
- package/dist/asserts/expect.js.map +1 -0
- package/dist/asserts/index.d.ts +58 -0
- package/dist/asserts/index.d.ts.map +1 -0
- package/dist/asserts/index.js +70 -0
- package/dist/asserts/index.js.map +1 -0
- package/dist/asserts/query.d.ts +199 -0
- package/dist/asserts/query.d.ts.map +1 -0
- package/dist/asserts/query.js +288 -0
- package/dist/asserts/query.js.map +1 -0
- package/dist/backends/actions.d.ts +119 -0
- package/dist/backends/actions.d.ts.map +1 -0
- package/dist/backends/actions.js +291 -0
- package/dist/backends/actions.js.map +1 -0
- package/dist/backends/browser-use-adapter.d.ts +131 -0
- package/dist/backends/browser-use-adapter.d.ts.map +1 -0
- package/dist/backends/browser-use-adapter.js +219 -0
- package/dist/backends/browser-use-adapter.js.map +1 -0
- package/dist/backends/cdp-backend.d.ts +66 -0
- package/dist/backends/cdp-backend.d.ts.map +1 -0
- package/dist/backends/cdp-backend.js +273 -0
- package/dist/backends/cdp-backend.js.map +1 -0
- package/dist/backends/index.d.ts +80 -0
- package/dist/backends/index.d.ts.map +1 -0
- package/dist/backends/index.js +101 -0
- package/dist/backends/index.js.map +1 -0
- package/dist/backends/protocol.d.ts +156 -0
- package/dist/backends/protocol.d.ts.map +1 -0
- package/dist/backends/protocol.js +16 -0
- package/dist/backends/protocol.js.map +1 -0
- package/dist/backends/sentience-context.d.ts +143 -0
- package/dist/backends/sentience-context.d.ts.map +1 -0
- package/dist/backends/sentience-context.js +359 -0
- package/dist/backends/sentience-context.js.map +1 -0
- package/dist/backends/snapshot.d.ts +188 -0
- package/dist/backends/snapshot.d.ts.map +1 -0
- package/dist/backends/snapshot.js +360 -0
- package/dist/backends/snapshot.js.map +1 -0
- package/dist/browser.d.ts +154 -0
- package/dist/browser.d.ts.map +1 -0
- package/dist/browser.js +920 -0
- package/dist/browser.js.map +1 -0
- package/dist/canonicalization.d.ts +126 -0
- package/dist/canonicalization.d.ts.map +1 -0
- package/dist/canonicalization.js +161 -0
- package/dist/canonicalization.js.map +1 -0
- package/dist/captcha/strategies.d.ts +12 -0
- package/dist/captcha/strategies.d.ts.map +1 -0
- package/dist/captcha/strategies.js +43 -0
- package/dist/captcha/strategies.js.map +1 -0
- package/dist/captcha/types.d.ts +45 -0
- package/dist/captcha/types.d.ts.map +1 -0
- package/dist/captcha/types.js +12 -0
- package/dist/captcha/types.js.map +1 -0
- package/dist/cli.d.ts +5 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +422 -0
- package/dist/cli.js.map +1 -0
- package/dist/conversational-agent.d.ts +123 -0
- package/dist/conversational-agent.d.ts.map +1 -0
- package/dist/conversational-agent.js +341 -0
- package/dist/conversational-agent.js.map +1 -0
- package/dist/cursor-policy.d.ts +41 -0
- package/dist/cursor-policy.d.ts.map +1 -0
- package/dist/cursor-policy.js +81 -0
- package/dist/cursor-policy.js.map +1 -0
- package/dist/debugger.d.ts +28 -0
- package/dist/debugger.d.ts.map +1 -0
- package/dist/debugger.js +107 -0
- package/dist/debugger.js.map +1 -0
- package/dist/expect.d.ts +16 -0
- package/dist/expect.d.ts.map +1 -0
- package/dist/expect.js +67 -0
- package/dist/expect.js.map +1 -0
- package/dist/failure-artifacts.d.ts +95 -0
- package/dist/failure-artifacts.d.ts.map +1 -0
- package/dist/failure-artifacts.js +805 -0
- package/dist/failure-artifacts.js.map +1 -0
- package/dist/generator.d.ts +16 -0
- package/dist/generator.d.ts.map +1 -0
- package/dist/generator.js +205 -0
- package/dist/generator.js.map +1 -0
- package/dist/index.d.ts +37 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +160 -0
- package/dist/index.js.map +1 -0
- package/dist/inspector.d.ts +13 -0
- package/dist/inspector.d.ts.map +1 -0
- package/dist/inspector.js +153 -0
- package/dist/inspector.js.map +1 -0
- package/dist/llm-provider.d.ts +144 -0
- package/dist/llm-provider.d.ts.map +1 -0
- package/dist/llm-provider.js +460 -0
- package/dist/llm-provider.js.map +1 -0
- package/dist/ordinal.d.ts +90 -0
- package/dist/ordinal.d.ts.map +1 -0
- package/dist/ordinal.js +249 -0
- package/dist/ordinal.js.map +1 -0
- package/dist/overlay.d.ts +63 -0
- package/dist/overlay.d.ts.map +1 -0
- package/dist/overlay.js +102 -0
- package/dist/overlay.js.map +1 -0
- package/dist/protocols/browser-protocol.d.ts +79 -0
- package/dist/protocols/browser-protocol.d.ts.map +1 -0
- package/dist/protocols/browser-protocol.js +9 -0
- package/dist/protocols/browser-protocol.js.map +1 -0
- package/dist/query.d.ts +66 -0
- package/dist/query.d.ts.map +1 -0
- package/dist/query.js +482 -0
- package/dist/query.js.map +1 -0
- package/dist/read.d.ts +47 -0
- package/dist/read.d.ts.map +1 -0
- package/dist/read.js +128 -0
- package/dist/read.js.map +1 -0
- package/dist/recorder.d.ts +44 -0
- package/dist/recorder.d.ts.map +1 -0
- package/dist/recorder.js +262 -0
- package/dist/recorder.js.map +1 -0
- package/dist/runtime-agent.d.ts +72 -0
- package/dist/runtime-agent.d.ts.map +1 -0
- package/dist/runtime-agent.js +357 -0
- package/dist/runtime-agent.js.map +1 -0
- package/dist/screenshot.d.ts +17 -0
- package/dist/screenshot.d.ts.map +1 -0
- package/dist/screenshot.js +40 -0
- package/dist/screenshot.js.map +1 -0
- package/dist/snapshot-diff.d.ts +23 -0
- package/dist/snapshot-diff.d.ts.map +1 -0
- package/dist/snapshot-diff.js +119 -0
- package/dist/snapshot-diff.js.map +1 -0
- package/dist/snapshot.d.ts +47 -0
- package/dist/snapshot.d.ts.map +1 -0
- package/dist/snapshot.js +358 -0
- package/dist/snapshot.js.map +1 -0
- package/dist/textSearch.d.ts +64 -0
- package/dist/textSearch.d.ts.map +1 -0
- package/dist/textSearch.js +113 -0
- package/dist/textSearch.js.map +1 -0
- package/dist/tools/context.d.ts +18 -0
- package/dist/tools/context.d.ts.map +1 -0
- package/dist/tools/context.js +40 -0
- package/dist/tools/context.js.map +1 -0
- package/dist/tools/defaults.d.ts +5 -0
- package/dist/tools/defaults.d.ts.map +1 -0
- package/dist/tools/defaults.js +368 -0
- package/dist/tools/defaults.js.map +1 -0
- package/dist/tools/filesystem.d.ts +12 -0
- package/dist/tools/filesystem.d.ts.map +1 -0
- package/dist/tools/filesystem.js +137 -0
- package/dist/tools/filesystem.js.map +1 -0
- package/dist/tools/index.d.ts +5 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +15 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools/registry.d.ts +38 -0
- package/dist/tools/registry.d.ts.map +1 -0
- package/dist/tools/registry.js +100 -0
- package/dist/tools/registry.js.map +1 -0
- package/dist/tracing/cloud-sink.d.ts +189 -0
- package/dist/tracing/cloud-sink.d.ts.map +1 -0
- package/dist/tracing/cloud-sink.js +1067 -0
- package/dist/tracing/cloud-sink.js.map +1 -0
- package/dist/tracing/index-schema.d.ts +231 -0
- package/dist/tracing/index-schema.d.ts.map +1 -0
- package/dist/tracing/index-schema.js +235 -0
- package/dist/tracing/index-schema.js.map +1 -0
- package/dist/tracing/index.d.ts +12 -0
- package/dist/tracing/index.d.ts.map +1 -0
- package/dist/tracing/index.js +28 -0
- package/dist/tracing/index.js.map +1 -0
- package/dist/tracing/indexer.d.ts +20 -0
- package/dist/tracing/indexer.d.ts.map +1 -0
- package/dist/tracing/indexer.js +347 -0
- package/dist/tracing/indexer.js.map +1 -0
- package/dist/tracing/jsonl-sink.d.ts +51 -0
- package/dist/tracing/jsonl-sink.d.ts.map +1 -0
- package/dist/tracing/jsonl-sink.js +329 -0
- package/dist/tracing/jsonl-sink.js.map +1 -0
- package/dist/tracing/sink.d.ts +25 -0
- package/dist/tracing/sink.d.ts.map +1 -0
- package/dist/tracing/sink.js +15 -0
- package/dist/tracing/sink.js.map +1 -0
- package/dist/tracing/tracer-factory.d.ts +102 -0
- package/dist/tracing/tracer-factory.d.ts.map +1 -0
- package/dist/tracing/tracer-factory.js +375 -0
- package/dist/tracing/tracer-factory.js.map +1 -0
- package/dist/tracing/tracer.d.ts +140 -0
- package/dist/tracing/tracer.d.ts.map +1 -0
- package/dist/tracing/tracer.js +336 -0
- package/dist/tracing/tracer.js.map +1 -0
- package/dist/tracing/types.d.ts +203 -0
- package/dist/tracing/types.d.ts.map +1 -0
- package/dist/tracing/types.js +8 -0
- package/dist/tracing/types.js.map +1 -0
- package/dist/types.d.ts +422 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +6 -0
- package/dist/types.js.map +1 -0
- package/dist/utils/action-executor.d.ts +25 -0
- package/dist/utils/action-executor.d.ts.map +1 -0
- package/dist/utils/action-executor.js +121 -0
- package/dist/utils/action-executor.js.map +1 -0
- package/dist/utils/browser-evaluator.d.ts +76 -0
- package/dist/utils/browser-evaluator.d.ts.map +1 -0
- package/dist/utils/browser-evaluator.js +130 -0
- package/dist/utils/browser-evaluator.js.map +1 -0
- package/dist/utils/browser.d.ts +30 -0
- package/dist/utils/browser.d.ts.map +1 -0
- package/dist/utils/browser.js +75 -0
- package/dist/utils/browser.js.map +1 -0
- package/dist/utils/element-filter.d.ts +76 -0
- package/dist/utils/element-filter.d.ts.map +1 -0
- package/dist/utils/element-filter.js +195 -0
- package/dist/utils/element-filter.js.map +1 -0
- package/dist/utils/grid-utils.d.ts +37 -0
- package/dist/utils/grid-utils.d.ts.map +1 -0
- package/dist/utils/grid-utils.js +283 -0
- package/dist/utils/grid-utils.js.map +1 -0
- package/dist/utils/llm-interaction-handler.d.ts +41 -0
- package/dist/utils/llm-interaction-handler.d.ts.map +1 -0
- package/dist/utils/llm-interaction-handler.js +171 -0
- package/dist/utils/llm-interaction-handler.js.map +1 -0
- package/dist/utils/llm-response-builder.d.ts +56 -0
- package/dist/utils/llm-response-builder.d.ts.map +1 -0
- package/dist/utils/llm-response-builder.js +130 -0
- package/dist/utils/llm-response-builder.js.map +1 -0
- package/dist/utils/selector-utils.d.ts +12 -0
- package/dist/utils/selector-utils.d.ts.map +1 -0
- package/dist/utils/selector-utils.js +32 -0
- package/dist/utils/selector-utils.js.map +1 -0
- package/dist/utils/snapshot-event-builder.d.ts +28 -0
- package/dist/utils/snapshot-event-builder.d.ts.map +1 -0
- package/dist/utils/snapshot-event-builder.js +88 -0
- package/dist/utils/snapshot-event-builder.js.map +1 -0
- package/dist/utils/snapshot-processor.d.ts +27 -0
- package/dist/utils/snapshot-processor.d.ts.map +1 -0
- package/dist/utils/snapshot-processor.js +47 -0
- package/dist/utils/snapshot-processor.js.map +1 -0
- package/dist/utils/trace-event-builder.d.ts +122 -0
- package/dist/utils/trace-event-builder.d.ts.map +1 -0
- package/dist/utils/trace-event-builder.js +365 -0
- package/dist/utils/trace-event-builder.js.map +1 -0
- package/dist/utils/trace-file-manager.d.ts +70 -0
- package/dist/utils/trace-file-manager.d.ts.map +1 -0
- package/dist/utils/trace-file-manager.js +194 -0
- package/dist/utils/trace-file-manager.js.map +1 -0
- package/dist/utils/zod.d.ts +5 -0
- package/dist/utils/zod.d.ts.map +1 -0
- package/dist/utils/zod.js +80 -0
- package/dist/utils/zod.js.map +1 -0
- package/dist/utils.d.ts +8 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +13 -0
- package/dist/utils.js.map +1 -0
- package/dist/verification.d.ts +194 -0
- package/dist/verification.d.ts.map +1 -0
- package/dist/verification.js +530 -0
- package/dist/verification.js.map +1 -0
- package/dist/vision-executor.d.ts +18 -0
- package/dist/vision-executor.d.ts.map +1 -0
- package/dist/vision-executor.js +60 -0
- package/dist/vision-executor.js.map +1 -0
- package/dist/visual-agent.d.ts +120 -0
- package/dist/visual-agent.d.ts.map +1 -0
- package/dist/visual-agent.js +796 -0
- package/dist/visual-agent.js.map +1 -0
- package/dist/wait.d.ts +35 -0
- package/dist/wait.d.ts.map +1 -0
- package/dist/wait.js +76 -0
- package/dist/wait.js.map +1 -0
- package/package.json +94 -0
- package/spec/README.md +72 -0
- package/spec/SNAPSHOT_V1.md +208 -0
- package/spec/sdk-types.md +259 -0
- package/spec/snapshot.schema.json +148 -0
- package/src/extension/background.js +104 -0
- package/src/extension/content.js +162 -0
- package/src/extension/injected_api.js +1399 -0
- package/src/extension/manifest.json +36 -0
- package/src/extension/pkg/README.md +1340 -0
- package/src/extension/pkg/package.json +15 -0
- package/src/extension/pkg/sentience_core.d.ts +51 -0
- package/src/extension/pkg/sentience_core.js +371 -0
- package/src/extension/pkg/sentience_core_bg.wasm +0 -0
- package/src/extension/pkg/sentience_core_bg.wasm.d.ts +10 -0
- package/src/extension/release.json +116 -0
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
# SDK-Level Type Definitions
|
|
2
|
+
|
|
3
|
+
**Purpose**: Define SDK-level types that extend the snapshot contract with action results, wait results, and trace steps.
|
|
4
|
+
|
|
5
|
+
## Core Types
|
|
6
|
+
|
|
7
|
+
### Snapshot
|
|
8
|
+
```typescript
|
|
9
|
+
interface Snapshot {
|
|
10
|
+
status: "success" | "error";
|
|
11
|
+
timestamp?: string;
|
|
12
|
+
url: string;
|
|
13
|
+
viewport?: { width: number; height: number };
|
|
14
|
+
elements: Element[];
|
|
15
|
+
screenshot?: string;
|
|
16
|
+
screenshot_format?: "png" | "jpeg";
|
|
17
|
+
error?: string;
|
|
18
|
+
requires_license?: boolean;
|
|
19
|
+
}
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
### Element
|
|
23
|
+
```typescript
|
|
24
|
+
interface Element {
|
|
25
|
+
id: number;
|
|
26
|
+
role: string;
|
|
27
|
+
text: string | null;
|
|
28
|
+
importance: number;
|
|
29
|
+
bbox: BBox;
|
|
30
|
+
visual_cues: VisualCues;
|
|
31
|
+
in_viewport: boolean;
|
|
32
|
+
is_occluded: boolean;
|
|
33
|
+
z_index: number;
|
|
34
|
+
}
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
### BBox
|
|
38
|
+
```typescript
|
|
39
|
+
interface BBox {
|
|
40
|
+
x: number;
|
|
41
|
+
y: number;
|
|
42
|
+
width: number;
|
|
43
|
+
height: number;
|
|
44
|
+
}
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
### Viewport
|
|
48
|
+
```typescript
|
|
49
|
+
interface Viewport {
|
|
50
|
+
width: number;
|
|
51
|
+
height: number;
|
|
52
|
+
}
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### VisualCues
|
|
56
|
+
```typescript
|
|
57
|
+
interface VisualCues {
|
|
58
|
+
is_primary: boolean;
|
|
59
|
+
background_color_name: string | null;
|
|
60
|
+
is_clickable: boolean;
|
|
61
|
+
}
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## Action Types
|
|
65
|
+
|
|
66
|
+
### ActionResult
|
|
67
|
+
```typescript
|
|
68
|
+
interface ActionResult {
|
|
69
|
+
success: boolean;
|
|
70
|
+
duration_ms: number;
|
|
71
|
+
outcome?: "navigated" | "dom_updated" | "no_change" | "error";
|
|
72
|
+
url_changed?: boolean;
|
|
73
|
+
snapshot_after?: Snapshot; // Optional in Week 1, required in Week 2
|
|
74
|
+
error?: {
|
|
75
|
+
code: string;
|
|
76
|
+
reason: string;
|
|
77
|
+
recovery_hint?: string;
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
**Fields**:
|
|
83
|
+
- `success`: True if action completed successfully
|
|
84
|
+
- `duration_ms`: Time taken in milliseconds
|
|
85
|
+
- `outcome`: What happened after action (navigation, DOM update, no change, error)
|
|
86
|
+
- `url_changed`: True if URL changed (for navigation detection)
|
|
87
|
+
- `snapshot_after`: Post-action snapshot (optional in MVP, required for recorder)
|
|
88
|
+
- `error`: Error details if action failed
|
|
89
|
+
|
|
90
|
+
## Wait & Assert Types
|
|
91
|
+
|
|
92
|
+
### WaitResult
|
|
93
|
+
```typescript
|
|
94
|
+
interface WaitResult {
|
|
95
|
+
found: boolean;
|
|
96
|
+
element?: Element;
|
|
97
|
+
duration_ms: number;
|
|
98
|
+
timeout: boolean;
|
|
99
|
+
}
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
**Fields**:
|
|
103
|
+
- `found`: True if element was found
|
|
104
|
+
- `element`: Found element (if found)
|
|
105
|
+
- `duration_ms`: Time taken to find (or timeout)
|
|
106
|
+
- `timeout`: True if wait timed out
|
|
107
|
+
|
|
108
|
+
### AssertionError
|
|
109
|
+
```typescript
|
|
110
|
+
class AssertionError extends Error {
|
|
111
|
+
predicate: string | object;
|
|
112
|
+
timeout: number;
|
|
113
|
+
element?: Element;
|
|
114
|
+
}
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
## Trace Types (for Recorder)
|
|
118
|
+
|
|
119
|
+
### Trace
|
|
120
|
+
```typescript
|
|
121
|
+
interface Trace {
|
|
122
|
+
version: string; // "1.0.0"
|
|
123
|
+
created_at: string; // ISO 8601
|
|
124
|
+
start_url: string;
|
|
125
|
+
steps: TraceStep[];
|
|
126
|
+
}
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
### TraceStep
|
|
130
|
+
```typescript
|
|
131
|
+
interface TraceStep {
|
|
132
|
+
ts: number; // Timestamp (milliseconds since start)
|
|
133
|
+
type: "navigation" | "click" | "type" | "press" | "wait" | "assert";
|
|
134
|
+
selector?: string; // Semantic selector (inferred)
|
|
135
|
+
element_id?: number; // Element ID
|
|
136
|
+
text?: string; // For type actions (may be masked)
|
|
137
|
+
key?: string; // For press actions
|
|
138
|
+
url?: string; // For navigation
|
|
139
|
+
snapshot?: Snapshot; // Optional: snapshot at this step
|
|
140
|
+
}
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
**Step Types**:
|
|
144
|
+
- `navigation`: `goto(url)`
|
|
145
|
+
- `click`: Click on element
|
|
146
|
+
- `type`: Type text into element
|
|
147
|
+
- `press`: Press keyboard key
|
|
148
|
+
- `wait`: Wait for element/predicate
|
|
149
|
+
- `assert`: Assertion check
|
|
150
|
+
|
|
151
|
+
## Query Types
|
|
152
|
+
|
|
153
|
+
### QuerySelector
|
|
154
|
+
```typescript
|
|
155
|
+
// String DSL
|
|
156
|
+
type QuerySelectorString = string; // e.g., "role=button text~'Sign in'"
|
|
157
|
+
|
|
158
|
+
// Structured object
|
|
159
|
+
interface QuerySelectorObject {
|
|
160
|
+
role?: string;
|
|
161
|
+
text?: string | RegExp;
|
|
162
|
+
name?: string | RegExp;
|
|
163
|
+
clickable?: boolean;
|
|
164
|
+
isPrimary?: boolean;
|
|
165
|
+
importance?: number | { min?: number; max?: number };
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
type QuerySelector = QuerySelectorString | QuerySelectorObject;
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
## Python Equivalents (Pydantic)
|
|
172
|
+
|
|
173
|
+
```python
|
|
174
|
+
from pydantic import BaseModel
|
|
175
|
+
from typing import Optional, List, Union
|
|
176
|
+
from datetime import datetime
|
|
177
|
+
|
|
178
|
+
class BBox(BaseModel):
|
|
179
|
+
x: float
|
|
180
|
+
y: float
|
|
181
|
+
width: float
|
|
182
|
+
height: float
|
|
183
|
+
|
|
184
|
+
class Viewport(BaseModel):
|
|
185
|
+
width: float
|
|
186
|
+
height: float
|
|
187
|
+
|
|
188
|
+
class VisualCues(BaseModel):
|
|
189
|
+
is_primary: bool
|
|
190
|
+
background_color_name: Optional[str]
|
|
191
|
+
is_clickable: bool
|
|
192
|
+
|
|
193
|
+
class Element(BaseModel):
|
|
194
|
+
id: int
|
|
195
|
+
role: str
|
|
196
|
+
text: Optional[str]
|
|
197
|
+
importance: int
|
|
198
|
+
bbox: BBox
|
|
199
|
+
visual_cues: VisualCues
|
|
200
|
+
in_viewport: bool = True
|
|
201
|
+
is_occluded: bool = False
|
|
202
|
+
z_index: int = 0
|
|
203
|
+
|
|
204
|
+
class Snapshot(BaseModel):
|
|
205
|
+
status: str # "success" | "error"
|
|
206
|
+
timestamp: Optional[str] = None
|
|
207
|
+
url: str
|
|
208
|
+
viewport: Optional[Viewport] = None
|
|
209
|
+
elements: List[Element]
|
|
210
|
+
screenshot: Optional[str] = None
|
|
211
|
+
screenshot_format: Optional[str] = None
|
|
212
|
+
error: Optional[str] = None
|
|
213
|
+
requires_license: Optional[bool] = None
|
|
214
|
+
|
|
215
|
+
class ActionResult(BaseModel):
|
|
216
|
+
success: bool
|
|
217
|
+
duration_ms: int
|
|
218
|
+
outcome: Optional[str] = None
|
|
219
|
+
url_changed: Optional[bool] = None
|
|
220
|
+
snapshot_after: Optional[Snapshot] = None
|
|
221
|
+
error: Optional[dict] = None
|
|
222
|
+
|
|
223
|
+
class WaitResult(BaseModel):
|
|
224
|
+
found: bool
|
|
225
|
+
element: Optional[Element] = None
|
|
226
|
+
duration_ms: int
|
|
227
|
+
timeout: bool
|
|
228
|
+
|
|
229
|
+
class TraceStep(BaseModel):
|
|
230
|
+
ts: int
|
|
231
|
+
type: str
|
|
232
|
+
selector: Optional[str] = None
|
|
233
|
+
element_id: Optional[int] = None
|
|
234
|
+
text: Optional[str] = None
|
|
235
|
+
key: Optional[str] = None
|
|
236
|
+
url: Optional[str] = None
|
|
237
|
+
snapshot: Optional[Snapshot] = None
|
|
238
|
+
|
|
239
|
+
class Trace(BaseModel):
|
|
240
|
+
version: str
|
|
241
|
+
created_at: str
|
|
242
|
+
start_url: str
|
|
243
|
+
steps: List[TraceStep]
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
## Type Validation Rules
|
|
247
|
+
|
|
248
|
+
1. **Required Fields**: Must be present and non-null
|
|
249
|
+
2. **Optional Fields**: May be omitted or null
|
|
250
|
+
3. **Type Coercion**: Numbers should be validated (no NaN, Infinity)
|
|
251
|
+
4. **Enum Values**: String enums must match exactly
|
|
252
|
+
5. **Array Bounds**: Elements array should be validated (not empty for success status)
|
|
253
|
+
|
|
254
|
+
## Compatibility Notes
|
|
255
|
+
|
|
256
|
+
- SDKs should handle missing optional fields gracefully
|
|
257
|
+
- Default values should match extension behavior
|
|
258
|
+
- Type coercion should be minimal (prefer validation errors)
|
|
259
|
+
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "http://json-schema.org/draft-07/schema#",
|
|
3
|
+
"title": "Sentience Snapshot Schema v1",
|
|
4
|
+
"description": "Single source of truth for snapshot data structure between extension and SDKs",
|
|
5
|
+
"version": "1.0.0",
|
|
6
|
+
"type": "object",
|
|
7
|
+
"required": ["status", "url", "elements"],
|
|
8
|
+
"properties": {
|
|
9
|
+
"status": {
|
|
10
|
+
"type": "string",
|
|
11
|
+
"enum": ["success", "error"],
|
|
12
|
+
"description": "Operation status"
|
|
13
|
+
},
|
|
14
|
+
"timestamp": {
|
|
15
|
+
"type": "string",
|
|
16
|
+
"format": "date-time",
|
|
17
|
+
"description": "ISO 8601 timestamp of snapshot"
|
|
18
|
+
},
|
|
19
|
+
"url": {
|
|
20
|
+
"type": "string",
|
|
21
|
+
"format": "uri",
|
|
22
|
+
"description": "Current page URL"
|
|
23
|
+
},
|
|
24
|
+
"viewport": {
|
|
25
|
+
"type": "object",
|
|
26
|
+
"required": ["width", "height"],
|
|
27
|
+
"properties": {
|
|
28
|
+
"width": {
|
|
29
|
+
"type": "number",
|
|
30
|
+
"description": "Viewport width in pixels"
|
|
31
|
+
},
|
|
32
|
+
"height": {
|
|
33
|
+
"type": "number",
|
|
34
|
+
"description": "Viewport height in pixels"
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
"elements": {
|
|
39
|
+
"type": "array",
|
|
40
|
+
"items": {
|
|
41
|
+
"$ref": "#/definitions/Element"
|
|
42
|
+
},
|
|
43
|
+
"description": "Array of analyzed elements, sorted by importance (descending)"
|
|
44
|
+
},
|
|
45
|
+
"screenshot": {
|
|
46
|
+
"type": "string",
|
|
47
|
+
"description": "Base64-encoded screenshot data URL (optional)",
|
|
48
|
+
"pattern": "^data:image/(png|jpeg);base64,"
|
|
49
|
+
},
|
|
50
|
+
"screenshot_format": {
|
|
51
|
+
"type": "string",
|
|
52
|
+
"enum": ["png", "jpeg"],
|
|
53
|
+
"description": "Screenshot format (optional)"
|
|
54
|
+
},
|
|
55
|
+
"error": {
|
|
56
|
+
"type": "string",
|
|
57
|
+
"description": "Error message if status is 'error'"
|
|
58
|
+
},
|
|
59
|
+
"requires_license": {
|
|
60
|
+
"type": "boolean",
|
|
61
|
+
"description": "True if operation requires license key (headless mode)"
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
"definitions": {
|
|
65
|
+
"Element": {
|
|
66
|
+
"type": "object",
|
|
67
|
+
"required": ["id", "role", "importance", "bbox", "visual_cues"],
|
|
68
|
+
"properties": {
|
|
69
|
+
"id": {
|
|
70
|
+
"type": "integer",
|
|
71
|
+
"description": "Unique element identifier (index in registry)"
|
|
72
|
+
},
|
|
73
|
+
"role": {
|
|
74
|
+
"type": "string",
|
|
75
|
+
"enum": ["button", "link", "textbox", "searchbox", "checkbox", "radio", "combobox", "image", "generic"],
|
|
76
|
+
"description": "Semantic role of the element"
|
|
77
|
+
},
|
|
78
|
+
"text": {
|
|
79
|
+
"type": ["string", "null"],
|
|
80
|
+
"description": "Text content, aria-label, or placeholder (max 100 chars)"
|
|
81
|
+
},
|
|
82
|
+
"importance": {
|
|
83
|
+
"type": "integer",
|
|
84
|
+
"description": "Importance score (-300 to ~1800), higher = more important"
|
|
85
|
+
},
|
|
86
|
+
"bbox": {
|
|
87
|
+
"$ref": "#/definitions/BBox"
|
|
88
|
+
},
|
|
89
|
+
"visual_cues": {
|
|
90
|
+
"$ref": "#/definitions/VisualCues"
|
|
91
|
+
},
|
|
92
|
+
"in_viewport": {
|
|
93
|
+
"type": "boolean",
|
|
94
|
+
"description": "True if element is visible in viewport"
|
|
95
|
+
},
|
|
96
|
+
"is_occluded": {
|
|
97
|
+
"type": "boolean",
|
|
98
|
+
"description": "True if element is covered by another element"
|
|
99
|
+
},
|
|
100
|
+
"z_index": {
|
|
101
|
+
"type": "integer",
|
|
102
|
+
"description": "CSS z-index value (0 if auto or not set)"
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
},
|
|
106
|
+
"BBox": {
|
|
107
|
+
"type": "object",
|
|
108
|
+
"required": ["x", "y", "width", "height"],
|
|
109
|
+
"properties": {
|
|
110
|
+
"x": {
|
|
111
|
+
"type": "number",
|
|
112
|
+
"description": "X coordinate (left edge) in pixels"
|
|
113
|
+
},
|
|
114
|
+
"y": {
|
|
115
|
+
"type": "number",
|
|
116
|
+
"description": "Y coordinate (top edge) in pixels"
|
|
117
|
+
},
|
|
118
|
+
"width": {
|
|
119
|
+
"type": "number",
|
|
120
|
+
"description": "Width in pixels"
|
|
121
|
+
},
|
|
122
|
+
"height": {
|
|
123
|
+
"type": "number",
|
|
124
|
+
"description": "Height in pixels"
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
},
|
|
128
|
+
"VisualCues": {
|
|
129
|
+
"type": "object",
|
|
130
|
+
"required": ["is_primary", "is_clickable"],
|
|
131
|
+
"properties": {
|
|
132
|
+
"is_primary": {
|
|
133
|
+
"type": "boolean",
|
|
134
|
+
"description": "True if element is visually prominent primary action"
|
|
135
|
+
},
|
|
136
|
+
"background_color_name": {
|
|
137
|
+
"type": ["string", "null"],
|
|
138
|
+
"description": "Nearest named color from 32-color palette (e.g., 'blue', 'red')"
|
|
139
|
+
},
|
|
140
|
+
"is_clickable": {
|
|
141
|
+
"type": "boolean",
|
|
142
|
+
"description": "True if element has pointer cursor or actionable role"
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import init, { analyze_page_with_options, analyze_page, prune_for_api } from "./pkg/sentience_core.js";
|
|
2
|
+
|
|
3
|
+
let wasmReady = !1, wasmInitPromise = null;
|
|
4
|
+
|
|
5
|
+
async function initWASM() {
|
|
6
|
+
if (!wasmReady) return wasmInitPromise || (wasmInitPromise = (async () => {
|
|
7
|
+
try {
|
|
8
|
+
globalThis.js_click_element = () => {}, await init(), wasmReady = !0;
|
|
9
|
+
} catch (error) {
|
|
10
|
+
throw error;
|
|
11
|
+
}
|
|
12
|
+
})(), wasmInitPromise);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
async function handleScreenshotCapture(_tabId, options = {}) {
|
|
16
|
+
try {
|
|
17
|
+
const {format: format = "png", quality: quality = 90} = options;
|
|
18
|
+
return await chrome.tabs.captureVisibleTab(null, {
|
|
19
|
+
format: format,
|
|
20
|
+
quality: quality
|
|
21
|
+
});
|
|
22
|
+
} catch (error) {
|
|
23
|
+
throw new Error(`Failed to capture screenshot: ${error.message}`);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
async function handleSnapshotProcessing(rawData, options = {}) {
|
|
28
|
+
const startTime = performance.now();
|
|
29
|
+
try {
|
|
30
|
+
if (!Array.isArray(rawData)) throw new Error("rawData must be an array");
|
|
31
|
+
if (rawData.length > 1e4 && (rawData = rawData.slice(0, 1e4)), await initWASM(),
|
|
32
|
+
!wasmReady) throw new Error("WASM module not initialized");
|
|
33
|
+
let analyzedElements, prunedRawData;
|
|
34
|
+
try {
|
|
35
|
+
const wasmPromise = new Promise((resolve, reject) => {
|
|
36
|
+
try {
|
|
37
|
+
let result;
|
|
38
|
+
result = options.limit || options.filter ? analyze_page_with_options(rawData, options) : analyze_page(rawData),
|
|
39
|
+
resolve(result);
|
|
40
|
+
} catch (e) {
|
|
41
|
+
reject(e);
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
analyzedElements = await Promise.race([ wasmPromise, new Promise((_, reject) => setTimeout(() => reject(new Error("WASM processing timeout (>18s)")), 18e3)) ]);
|
|
45
|
+
} catch (e) {
|
|
46
|
+
const errorMsg = e.message || "Unknown WASM error";
|
|
47
|
+
throw new Error(`WASM analyze_page failed: ${errorMsg}`);
|
|
48
|
+
}
|
|
49
|
+
try {
|
|
50
|
+
prunedRawData = prune_for_api(rawData);
|
|
51
|
+
} catch (e) {
|
|
52
|
+
prunedRawData = rawData;
|
|
53
|
+
}
|
|
54
|
+
performance.now();
|
|
55
|
+
return {
|
|
56
|
+
elements: analyzedElements,
|
|
57
|
+
raw_elements: prunedRawData
|
|
58
|
+
};
|
|
59
|
+
} catch (error) {
|
|
60
|
+
performance.now();
|
|
61
|
+
throw error;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
initWASM().catch(err => {}), chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
|
|
66
|
+
try {
|
|
67
|
+
return "captureScreenshot" === request.action ? (handleScreenshotCapture(sender.tab.id, request.options).then(screenshot => {
|
|
68
|
+
sendResponse({
|
|
69
|
+
success: !0,
|
|
70
|
+
screenshot: screenshot
|
|
71
|
+
});
|
|
72
|
+
}).catch(error => {
|
|
73
|
+
sendResponse({
|
|
74
|
+
success: !1,
|
|
75
|
+
error: error.message || "Screenshot capture failed"
|
|
76
|
+
});
|
|
77
|
+
}), !0) : "processSnapshot" === request.action ? (handleSnapshotProcessing(request.rawData, request.options).then(result => {
|
|
78
|
+
sendResponse({
|
|
79
|
+
success: !0,
|
|
80
|
+
result: result
|
|
81
|
+
});
|
|
82
|
+
}).catch(error => {
|
|
83
|
+
sendResponse({
|
|
84
|
+
success: !1,
|
|
85
|
+
error: error.message || "Snapshot processing failed"
|
|
86
|
+
});
|
|
87
|
+
}), !0) : (sendResponse({
|
|
88
|
+
success: !1,
|
|
89
|
+
error: "Unknown action"
|
|
90
|
+
}), !1);
|
|
91
|
+
} catch (error) {
|
|
92
|
+
try {
|
|
93
|
+
sendResponse({
|
|
94
|
+
success: !1,
|
|
95
|
+
error: `Fatal error: ${error.message || "Unknown error"}`
|
|
96
|
+
});
|
|
97
|
+
} catch (e) {}
|
|
98
|
+
return !1;
|
|
99
|
+
}
|
|
100
|
+
}), self.addEventListener("error", event => {
|
|
101
|
+
event.preventDefault();
|
|
102
|
+
}), self.addEventListener("unhandledrejection", event => {
|
|
103
|
+
event.preventDefault();
|
|
104
|
+
});
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
!function() {
|
|
2
|
+
"use strict";
|
|
3
|
+
window, window.top;
|
|
4
|
+
document.documentElement.dataset.sentienceExtensionId = chrome.runtime.id, window.addEventListener("message", event => {
|
|
5
|
+
var data;
|
|
6
|
+
if (event.source === window) switch (event.data.type) {
|
|
7
|
+
case "SENTIENCE_SCREENSHOT_REQUEST":
|
|
8
|
+
data = event.data, chrome.runtime.sendMessage({
|
|
9
|
+
action: "captureScreenshot",
|
|
10
|
+
options: data.options
|
|
11
|
+
}, response => {
|
|
12
|
+
window.postMessage({
|
|
13
|
+
type: "SENTIENCE_SCREENSHOT_RESULT",
|
|
14
|
+
requestId: data.requestId,
|
|
15
|
+
screenshot: response?.success ? response.screenshot : null,
|
|
16
|
+
error: response?.error
|
|
17
|
+
}, "*");
|
|
18
|
+
});
|
|
19
|
+
break;
|
|
20
|
+
|
|
21
|
+
case "SENTIENCE_SNAPSHOT_REQUEST":
|
|
22
|
+
!function(data) {
|
|
23
|
+
const startTime = performance.now();
|
|
24
|
+
let responded = !1;
|
|
25
|
+
const timeoutId = setTimeout(() => {
|
|
26
|
+
if (!responded) {
|
|
27
|
+
responded = !0;
|
|
28
|
+
const duration = performance.now() - startTime;
|
|
29
|
+
window.postMessage({
|
|
30
|
+
type: "SENTIENCE_SNAPSHOT_RESULT",
|
|
31
|
+
requestId: data.requestId,
|
|
32
|
+
error: "WASM processing timeout - background script may be unresponsive",
|
|
33
|
+
duration: duration
|
|
34
|
+
}, "*");
|
|
35
|
+
}
|
|
36
|
+
}, 2e4);
|
|
37
|
+
try {
|
|
38
|
+
chrome.runtime.sendMessage({
|
|
39
|
+
action: "processSnapshot",
|
|
40
|
+
rawData: data.rawData,
|
|
41
|
+
options: data.options
|
|
42
|
+
}, response => {
|
|
43
|
+
if (responded) return;
|
|
44
|
+
responded = !0, clearTimeout(timeoutId);
|
|
45
|
+
const duration = performance.now() - startTime;
|
|
46
|
+
chrome.runtime.lastError ? window.postMessage({
|
|
47
|
+
type: "SENTIENCE_SNAPSHOT_RESULT",
|
|
48
|
+
requestId: data.requestId,
|
|
49
|
+
error: `Chrome runtime error: ${chrome.runtime.lastError.message}`,
|
|
50
|
+
duration: duration
|
|
51
|
+
}, "*") : response?.success ? window.postMessage({
|
|
52
|
+
type: "SENTIENCE_SNAPSHOT_RESULT",
|
|
53
|
+
requestId: data.requestId,
|
|
54
|
+
elements: response.result.elements,
|
|
55
|
+
raw_elements: response.result.raw_elements,
|
|
56
|
+
duration: duration
|
|
57
|
+
}, "*") : window.postMessage({
|
|
58
|
+
type: "SENTIENCE_SNAPSHOT_RESULT",
|
|
59
|
+
requestId: data.requestId,
|
|
60
|
+
error: response?.error || "Processing failed",
|
|
61
|
+
duration: duration
|
|
62
|
+
}, "*");
|
|
63
|
+
});
|
|
64
|
+
} catch (error) {
|
|
65
|
+
if (!responded) {
|
|
66
|
+
responded = !0, clearTimeout(timeoutId);
|
|
67
|
+
const duration = performance.now() - startTime;
|
|
68
|
+
window.postMessage({
|
|
69
|
+
type: "SENTIENCE_SNAPSHOT_RESULT",
|
|
70
|
+
requestId: data.requestId,
|
|
71
|
+
error: `Failed to send message: ${error.message}`,
|
|
72
|
+
duration: duration
|
|
73
|
+
}, "*");
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}(event.data);
|
|
77
|
+
break;
|
|
78
|
+
|
|
79
|
+
case "SENTIENCE_SHOW_OVERLAY":
|
|
80
|
+
!function(data) {
|
|
81
|
+
const {elements: elements, targetElementId: targetElementId} = data;
|
|
82
|
+
if (!elements || "object" != typeof elements || "number" != typeof elements.length) return;
|
|
83
|
+
const elementsArray = Array.isArray(elements) ? elements : Array.from(elements);
|
|
84
|
+
removeOverlay();
|
|
85
|
+
const host = document.createElement("div");
|
|
86
|
+
host.id = OVERLAY_HOST_ID, host.style.cssText = "\n position: fixed !important;\n top: 0 !important;\n left: 0 !important;\n width: 100vw !important;\n height: 100vh !important;\n pointer-events: none !important;\n z-index: 2147483647 !important;\n margin: 0 !important;\n padding: 0 !important;\n ",
|
|
87
|
+
document.body.appendChild(host);
|
|
88
|
+
const shadow = host.attachShadow({
|
|
89
|
+
mode: "closed"
|
|
90
|
+
}), maxImportance = Math.max(...elementsArray.map(e => e.importance || 0), 1);
|
|
91
|
+
elementsArray.forEach(element => {
|
|
92
|
+
const bbox = element.bbox;
|
|
93
|
+
if (!bbox) return;
|
|
94
|
+
const isTarget = element.id === targetElementId, isPrimary = element.visual_cues?.is_primary || !1, importance = element.importance || 0;
|
|
95
|
+
let color;
|
|
96
|
+
color = isTarget ? "#FF0000" : isPrimary ? "#0066FF" : "#00FF00";
|
|
97
|
+
const importanceRatio = maxImportance > 0 ? importance / maxImportance : .5, borderOpacity = isTarget ? 1 : isPrimary ? .9 : Math.max(.4, .5 + .5 * importanceRatio), fillOpacity = .2 * borderOpacity, borderWidth = isTarget ? 2 : isPrimary ? 1.5 : Math.max(.5, Math.round(2 * importanceRatio)), hexOpacity = Math.round(255 * fillOpacity).toString(16).padStart(2, "0"), box = document.createElement("div");
|
|
98
|
+
if (box.style.cssText = `\n position: absolute;\n left: ${bbox.x}px;\n top: ${bbox.y}px;\n width: ${bbox.width}px;\n height: ${bbox.height}px;\n border: ${borderWidth}px solid ${color};\n background-color: ${color}${hexOpacity};\n box-sizing: border-box;\n opacity: ${borderOpacity};\n pointer-events: none;\n `,
|
|
99
|
+
importance > 0 || isPrimary) {
|
|
100
|
+
const badge = document.createElement("span");
|
|
101
|
+
badge.textContent = isPrimary ? `⭐${importance}` : `${importance}`, badge.style.cssText = `\n position: absolute;\n top: -18px;\n left: 0;\n background: ${color};\n color: white;\n font-size: 11px;\n font-weight: bold;\n padding: 2px 6px;\n font-family: Arial, sans-serif;\n border-radius: 3px;\n opacity: 0.95;\n white-space: nowrap;\n pointer-events: none;\n `,
|
|
102
|
+
box.appendChild(badge);
|
|
103
|
+
}
|
|
104
|
+
if (isTarget) {
|
|
105
|
+
const targetIndicator = document.createElement("span");
|
|
106
|
+
targetIndicator.textContent = "🎯", targetIndicator.style.cssText = "\n position: absolute;\n top: -18px;\n right: 0;\n font-size: 16px;\n pointer-events: none;\n ",
|
|
107
|
+
box.appendChild(targetIndicator);
|
|
108
|
+
}
|
|
109
|
+
shadow.appendChild(box);
|
|
110
|
+
}), overlayTimeout = setTimeout(() => {
|
|
111
|
+
removeOverlay();
|
|
112
|
+
}, 5e3);
|
|
113
|
+
}(event.data);
|
|
114
|
+
break;
|
|
115
|
+
|
|
116
|
+
case "SENTIENCE_CLEAR_OVERLAY":
|
|
117
|
+
removeOverlay();
|
|
118
|
+
break;
|
|
119
|
+
|
|
120
|
+
case "SENTIENCE_SHOW_GRID_OVERLAY":
|
|
121
|
+
!function(data) {
|
|
122
|
+
const {grids: grids, targetGridId: targetGridId} = data;
|
|
123
|
+
if (!grids || !Array.isArray(grids)) return;
|
|
124
|
+
removeOverlay();
|
|
125
|
+
const host = document.createElement("div");
|
|
126
|
+
host.id = OVERLAY_HOST_ID, host.style.cssText = "\n position: fixed !important;\n top: 0 !important;\n left: 0 !important;\n width: 100vw !important;\n height: 100vh !important;\n pointer-events: none !important;\n z-index: 2147483647 !important;\n margin: 0 !important;\n padding: 0 !important;\n ",
|
|
127
|
+
document.body.appendChild(host);
|
|
128
|
+
const shadow = host.attachShadow({
|
|
129
|
+
mode: "closed"
|
|
130
|
+
});
|
|
131
|
+
grids.forEach(grid => {
|
|
132
|
+
const bbox = grid.bbox;
|
|
133
|
+
if (!bbox) return;
|
|
134
|
+
const isTarget = grid.grid_id === targetGridId, isDominant = !0 === grid.is_dominant;
|
|
135
|
+
let color = "#9B59B6";
|
|
136
|
+
isTarget ? color = "#FF0000" : isDominant && (color = "#FF8C00");
|
|
137
|
+
const borderStyle = isTarget ? "solid" : "dashed", borderWidth = isTarget ? 3 : isDominant ? 2.5 : 2, opacity = isTarget ? 1 : isDominant ? .9 : .8, fillOpacity = .1 * opacity, hexOpacity = Math.round(255 * fillOpacity).toString(16).padStart(2, "0"), box = document.createElement("div");
|
|
138
|
+
box.style.cssText = `\n position: absolute;\n left: ${bbox.x}px;\n top: ${bbox.y}px;\n width: ${bbox.width}px;\n height: ${bbox.height}px;\n border: ${borderWidth}px ${borderStyle} ${color};\n background-color: ${color}${hexOpacity};\n box-sizing: border-box;\n opacity: ${opacity};\n pointer-events: none;\n `;
|
|
139
|
+
let labelText = grid.label ? `Grid ${grid.grid_id}: ${grid.label}` : `Grid ${grid.grid_id}`;
|
|
140
|
+
grid.is_dominant && (labelText = `⭐ ${labelText} (dominant)`);
|
|
141
|
+
const badge = document.createElement("span");
|
|
142
|
+
if (badge.textContent = labelText, badge.style.cssText = `\n position: absolute;\n top: -18px;\n left: 0;\n background: ${color};\n color: white;\n font-size: 11px;\n font-weight: bold;\n padding: 2px 6px;\n font-family: Arial, sans-serif;\n border-radius: 3px;\n opacity: 0.95;\n white-space: nowrap;\n pointer-events: none;\n `,
|
|
143
|
+
box.appendChild(badge), isTarget) {
|
|
144
|
+
const targetIndicator = document.createElement("span");
|
|
145
|
+
targetIndicator.textContent = "🎯", targetIndicator.style.cssText = "\n position: absolute;\n top: -18px;\n right: 0;\n font-size: 16px;\n pointer-events: none;\n ",
|
|
146
|
+
box.appendChild(targetIndicator);
|
|
147
|
+
}
|
|
148
|
+
shadow.appendChild(box);
|
|
149
|
+
}), overlayTimeout = setTimeout(() => {
|
|
150
|
+
removeOverlay();
|
|
151
|
+
}, 5e3);
|
|
152
|
+
}(event.data);
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
const OVERLAY_HOST_ID = "sentience-overlay-host";
|
|
156
|
+
let overlayTimeout = null;
|
|
157
|
+
function removeOverlay() {
|
|
158
|
+
const existing = document.getElementById(OVERLAY_HOST_ID);
|
|
159
|
+
existing && existing.remove(), overlayTimeout && (clearTimeout(overlayTimeout),
|
|
160
|
+
overlayTimeout = null);
|
|
161
|
+
}
|
|
162
|
+
}();
|