sentienceapi 0.90.1

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.
Files changed (107) hide show
  1. package/LICENSE.md +43 -0
  2. package/README.md +946 -0
  3. package/dist/actions.d.ts +54 -0
  4. package/dist/actions.d.ts.map +1 -0
  5. package/dist/actions.js +349 -0
  6. package/dist/actions.js.map +1 -0
  7. package/dist/agent.d.ts +157 -0
  8. package/dist/agent.d.ts.map +1 -0
  9. package/dist/agent.js +437 -0
  10. package/dist/agent.js.map +1 -0
  11. package/dist/browser.d.ts +46 -0
  12. package/dist/browser.d.ts.map +1 -0
  13. package/dist/browser.js +622 -0
  14. package/dist/browser.js.map +1 -0
  15. package/dist/cli.d.ts +5 -0
  16. package/dist/cli.d.ts.map +1 -0
  17. package/dist/cli.js +174 -0
  18. package/dist/cli.js.map +1 -0
  19. package/dist/conversational-agent.d.ts +123 -0
  20. package/dist/conversational-agent.d.ts.map +1 -0
  21. package/dist/conversational-agent.js +327 -0
  22. package/dist/conversational-agent.js.map +1 -0
  23. package/dist/expect.d.ts +16 -0
  24. package/dist/expect.d.ts.map +1 -0
  25. package/dist/expect.js +66 -0
  26. package/dist/expect.js.map +1 -0
  27. package/dist/generator.d.ts +16 -0
  28. package/dist/generator.d.ts.map +1 -0
  29. package/dist/generator.js +205 -0
  30. package/dist/generator.js.map +1 -0
  31. package/dist/index.d.ts +21 -0
  32. package/dist/index.d.ts.map +1 -0
  33. package/dist/index.js +70 -0
  34. package/dist/index.js.map +1 -0
  35. package/dist/inspector.d.ts +13 -0
  36. package/dist/inspector.d.ts.map +1 -0
  37. package/dist/inspector.js +147 -0
  38. package/dist/inspector.js.map +1 -0
  39. package/dist/llm-provider.d.ts +60 -0
  40. package/dist/llm-provider.d.ts.map +1 -0
  41. package/dist/llm-provider.js +106 -0
  42. package/dist/llm-provider.js.map +1 -0
  43. package/dist/query.d.ts +8 -0
  44. package/dist/query.d.ts.map +1 -0
  45. package/dist/query.js +337 -0
  46. package/dist/query.js.map +1 -0
  47. package/dist/read.d.ts +40 -0
  48. package/dist/read.d.ts.map +1 -0
  49. package/dist/read.js +86 -0
  50. package/dist/read.js.map +1 -0
  51. package/dist/recorder.d.ts +44 -0
  52. package/dist/recorder.d.ts.map +1 -0
  53. package/dist/recorder.js +256 -0
  54. package/dist/recorder.js.map +1 -0
  55. package/dist/screenshot.d.ts +17 -0
  56. package/dist/screenshot.d.ts.map +1 -0
  57. package/dist/screenshot.js +37 -0
  58. package/dist/screenshot.js.map +1 -0
  59. package/dist/snapshot.d.ts +23 -0
  60. package/dist/snapshot.d.ts.map +1 -0
  61. package/dist/snapshot.js +187 -0
  62. package/dist/snapshot.js.map +1 -0
  63. package/dist/tracing/cloud-sink.d.ts +74 -0
  64. package/dist/tracing/cloud-sink.d.ts.map +1 -0
  65. package/dist/tracing/cloud-sink.js +262 -0
  66. package/dist/tracing/cloud-sink.js.map +1 -0
  67. package/dist/tracing/index.d.ts +12 -0
  68. package/dist/tracing/index.d.ts.map +1 -0
  69. package/dist/tracing/index.js +28 -0
  70. package/dist/tracing/index.js.map +1 -0
  71. package/dist/tracing/jsonl-sink.d.ts +41 -0
  72. package/dist/tracing/jsonl-sink.d.ts.map +1 -0
  73. package/dist/tracing/jsonl-sink.js +168 -0
  74. package/dist/tracing/jsonl-sink.js.map +1 -0
  75. package/dist/tracing/sink.d.ts +24 -0
  76. package/dist/tracing/sink.d.ts.map +1 -0
  77. package/dist/tracing/sink.js +15 -0
  78. package/dist/tracing/sink.js.map +1 -0
  79. package/dist/tracing/tracer-factory.d.ts +57 -0
  80. package/dist/tracing/tracer-factory.d.ts.map +1 -0
  81. package/dist/tracing/tracer-factory.js +274 -0
  82. package/dist/tracing/tracer-factory.js.map +1 -0
  83. package/dist/tracing/tracer.d.ts +74 -0
  84. package/dist/tracing/tracer.d.ts.map +1 -0
  85. package/dist/tracing/tracer.js +131 -0
  86. package/dist/tracing/tracer.js.map +1 -0
  87. package/dist/tracing/types.d.ts +63 -0
  88. package/dist/tracing/types.d.ts.map +1 -0
  89. package/dist/tracing/types.js +8 -0
  90. package/dist/tracing/types.js.map +1 -0
  91. package/dist/types.d.ts +110 -0
  92. package/dist/types.d.ts.map +1 -0
  93. package/dist/types.js +6 -0
  94. package/dist/types.js.map +1 -0
  95. package/dist/utils.d.ts +29 -0
  96. package/dist/utils.d.ts.map +1 -0
  97. package/dist/utils.js +74 -0
  98. package/dist/utils.js.map +1 -0
  99. package/dist/wait.d.ts +20 -0
  100. package/dist/wait.d.ts.map +1 -0
  101. package/dist/wait.js +63 -0
  102. package/dist/wait.js.map +1 -0
  103. package/package.json +72 -0
  104. package/spec/README.md +72 -0
  105. package/spec/SNAPSHOT_V1.md +208 -0
  106. package/spec/sdk-types.md +259 -0
  107. package/spec/snapshot.schema.json +148 -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
+