@ineerajrajeev/aios-web-sdk 0.1.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.
package/README.md ADDED
@@ -0,0 +1,278 @@
1
+ # @ineerajrajeev/aios-web-sdk
2
+
3
+ The official Browser JavaScript/TypeScript SDK for [aiOS](https://www.getaios.tech).
4
+
5
+ Provides type-safe bindings for integrating web applications with local AI browser agents through the aiOS Safari Extension. The SDK manages structured page exports, dynamic security capability policies, component-level interaction constraints, and a secure consent-gated communication bridge.
6
+
7
+ ---
8
+
9
+ ## Installation
10
+
11
+ Install the package from npm:
12
+
13
+ ```bash
14
+ npm install @ineerajrajeev/aios-web-sdk
15
+ ```
16
+
17
+ Or link it locally in your project:
18
+
19
+ ```json
20
+ "dependencies": {
21
+ "@ineerajrajeev/aios-web-sdk": "^0.1.0"
22
+ }
23
+ ```
24
+
25
+ ---
26
+
27
+ ## Getting Started
28
+
29
+ Import and initialize the SDK early in your application lifecycle. This establishes a secure connection with the aiOS Safari Extension running in the user's browser.
30
+
31
+ ```typescript
32
+ import { aiOS } from "@ineerajrajeev/aios-web-sdk";
33
+
34
+ aiOS.init({
35
+ appId: "com.example.myapp",
36
+ requireConsent: true
37
+ });
38
+ ```
39
+
40
+ **Parameters**
41
+
42
+ | Parameter | Type | Required | Description |
43
+ |-----------|------|----------|-------------|
44
+ | `appId` | `string` | Yes | Unique reverse-domain identifier for your application. |
45
+ | `requireConsent` | `boolean` | No (default: `true`) | When enabled, a consent modal is shown to the user before any page data is exported to the AI agent. |
46
+
47
+ Once initialized, the SDK injects metadata into the page and begins listening for extension handshake messages. The aiOS Safari Extension will automatically detect the SDK's presence.
48
+
49
+ ---
50
+
51
+ ## API Reference
52
+
53
+ ### aiOS.setPagePolicy(policy)
54
+
55
+ Controls what permissions an AI agent has on the current page. Use this to restrict or grant specific interaction capabilities. Setting `allowed: false` blocks all agent operations entirely.
56
+
57
+ ```typescript
58
+ aiOS.setPagePolicy({
59
+ allowed: true,
60
+ capabilities: {
61
+ read: true,
62
+ write: false,
63
+ execute: true,
64
+ summarize: true
65
+ },
66
+ exportMode: "structured-only"
67
+ });
68
+ ```
69
+
70
+ **Parameters**
71
+
72
+ | Parameter | Type | Description |
73
+ |-----------|------|-------------|
74
+ | `allowed` | `boolean` | Master switch. When `false`, all agent access to this page is denied. |
75
+ | `userMessage` | `string` | Optional custom message shown to the agent when the page is blocked. |
76
+ | `capabilities.read` | `boolean` | Allow the agent to read page content and extract data. |
77
+ | `capabilities.write` | `boolean` | Allow the agent to fill forms and modify input values. |
78
+ | `capabilities.execute` | `boolean` | Allow the agent to click buttons, follow links, scroll, and interact. |
79
+ | `capabilities.summarize` | `boolean` | Allow the agent to generate summaries of page content. |
80
+ | `exportMode` | `"structured-only"` or `"dom-allowed"` | Controls whether the agent can fall back to raw DOM scraping or must rely on SDK-provided structured data only. |
81
+
82
+ **Use cases**: Block AI agents on sensitive pages (payment, authentication), restrict write access on read-only dashboards, or enforce structured-only data access on privacy-critical pages.
83
+
84
+ ---
85
+
86
+ ### aiOS.setPageContext(context)
87
+
88
+ Describes the semantic purpose of the current page to the AI agent. This metadata helps the agent understand what the page is for, what actions it should take, and what information it may need from the user.
89
+
90
+ ```typescript
91
+ aiOS.setPageContext({
92
+ pageType: "job_application",
93
+ title: "Software Engineer Application Form",
94
+ description: "A multi-step form collecting work history and qualifications.",
95
+ agentIntent: "Fill in the user's work history and submit the application form.",
96
+ seekFromUser: [
97
+ {
98
+ id: "salary_expectation",
99
+ label: "Salary",
100
+ description: "Desired yearly compensation",
101
+ inputType: "number"
102
+ }
103
+ ]
104
+ });
105
+ ```
106
+
107
+ **Parameters**
108
+
109
+ | Parameter | Type | Description |
110
+ |-----------|------|-------------|
111
+ | `pageType` | `string` | Page categorization (e.g. `"checkout"`, `"form"`, `"catalog"`, `"generic"`). |
112
+ | `title` | `string` | Human-readable semantic title for the page. |
113
+ | `description` | `string` | Summary of the page content and purpose. |
114
+ | `agentIntent` | `string` | Natural language instructions describing what the AI agent should accomplish on this page. |
115
+ | `seekFromUser` | `SeekField[]` | Optional list of input fields the agent should prompt the user for before proceeding. Each field includes `id`, `label`, `description`, and `inputType`. |
116
+
117
+ **Use cases**: Guide agents through multi-step forms, provide context for product pages, or instruct agents to pause and ask the user for sensitive information like payment preferences.
118
+
119
+ ---
120
+
121
+ ### aiOS.defineZones(zones)
122
+
123
+ Specifies the primary content area of the page and excludes irrelevant or sensitive DOM regions from AI agent access. This prevents the agent from interacting with promotional banners, cookie notices, navigation chrome, or other non-essential elements.
124
+
125
+ ```typescript
126
+ aiOS.defineZones({
127
+ primary: "[data-app-content]",
128
+ excluded: [".promo-banner", "footer", ".cookie-notice"]
129
+ });
130
+ ```
131
+
132
+ **Parameters**
133
+
134
+ | Parameter | Type | Description |
135
+ |-----------|------|-------------|
136
+ | `primary` | `string` | CSS selector for the main content container that the agent should focus on. |
137
+ | `excluded` | `string[]` | Array of CSS selectors matching DOM elements the agent should ignore entirely. |
138
+
139
+ **Use cases**: Focus the agent on the main product listing and hide sidebar ads, exclude footer navigation from agent discovery, or restrict agent attention to a specific form region.
140
+
141
+ ---
142
+
143
+ ### aiOS.markComponent(id, component)
144
+
145
+ Registers a specific DOM element as a policy-managed interactive component. This gives the agent a named, typed handle for the element with explicit capability permissions, rather than relying on generic DOM discovery.
146
+
147
+ ```typescript
148
+ aiOS.markComponent("checkout-btn", {
149
+ kind: "button",
150
+ label: "Proceed to Checkout",
151
+ selector: ".checkout-btn",
152
+ capabilities: ["clickable"],
153
+ visible: true
154
+ });
155
+ ```
156
+
157
+ **Parameters**
158
+
159
+ | Parameter | Type | Description |
160
+ |-----------|------|-------------|
161
+ | `id` | `string` | Unique identifier for this component registration. |
162
+ | `component.kind` | `"button"`, `"input"`, `"link"`, `"cart"`, or `"custom"` | Semantic role of the element. |
163
+ | `component.label` | `string` | Human-readable name describing the element's purpose. |
164
+ | `component.selector` | `string` | CSS selector targeting the DOM element. |
165
+ | `component.capabilities` | `string[]` | Granted interaction rights: `"clickable"`, `"readable"`, `"writable"`, or `"hidden"`. |
166
+ | `component.visible` | `boolean` | Whether the component is currently visible and actionable. |
167
+
168
+ **Use cases**: Expose checkout buttons for agent interaction, mark form fields as writable so agents can fill them, hide sensitive elements like delete buttons from agent access, or label cart items for structured data extraction.
169
+
170
+ ---
171
+
172
+ ### aiOS.unmarkComponent(id)
173
+
174
+ Removes a previously registered component from the SDK's component registry. The element will no longer be exposed to the agent as a named interactive target.
175
+
176
+ ```typescript
177
+ aiOS.unmarkComponent("checkout-btn");
178
+ ```
179
+
180
+ **Parameters**
181
+
182
+ | Parameter | Type | Description |
183
+ |-----------|------|-------------|
184
+ | `id` | `string` | The component identifier that was used during `markComponent`. |
185
+
186
+ **Use cases**: Clean up components when navigating away from a view, remove elements that are no longer relevant after a user action, or dynamically adjust available components based on application state.
187
+
188
+ ---
189
+
190
+ ### aiOS.publish(options)
191
+
192
+ Compiles the current page context, registered components, and any custom data payload into a structured export package. If consent is required, a modal dialog is presented to the user for approval before the data is transmitted to the extension.
193
+
194
+ Returns a `Promise<boolean>` that resolves to `true` if the user approved and the data was sent, or `false` if the user denied.
195
+
196
+ ```typescript
197
+ const approved = await aiOS.publish({
198
+ schema: "cart.v1",
199
+ data: {
200
+ itemsCount: 3,
201
+ total: 89.99,
202
+ currency: "USD"
203
+ }
204
+ });
205
+
206
+ if (approved) {
207
+ console.log("Page data exported to aiOS.");
208
+ } else {
209
+ console.log("User denied the export.");
210
+ }
211
+ ```
212
+
213
+ **Parameters**
214
+
215
+ | Parameter | Type | Description |
216
+ |-----------|------|-------------|
217
+ | `options.schema` | `string` | Optional schema identifier for the data payload (e.g. `"cart.v1"`, `"applicant.v1"`). |
218
+ | `options.data` | `object` | Optional application-specific business data to include in the export (e.g. cart items, form state). |
219
+
220
+ **Use cases**: Export shopping cart contents for comparison agents, send job application form data for auto-fill workflows, or share product catalog information with recommendation agents.
221
+
222
+ ---
223
+
224
+ ### aiOS.onEvent(type, handler)
225
+
226
+ Subscribes to real-time events from the aiOS Safari Extension. This allows your application to react to agent activity, detect extension presence, and track compliance sessions. Returns an unsubscribe function.
227
+
228
+ ```typescript
229
+ const unsubscribe = aiOS.onEvent("agent:active", (event) => {
230
+ console.log("Agent performed action:", event.payload.action);
231
+ console.log("Was it blocked?", event.payload.blocked);
232
+ });
233
+
234
+ // Clean up listener when no longer needed:
235
+ unsubscribe();
236
+ ```
237
+
238
+ **Parameters**
239
+
240
+ | Parameter | Type | Description |
241
+ |-----------|------|-------------|
242
+ | `type` | `string` | Event type to listen for. |
243
+ | `handler` | `Function` | Callback function invoked when the event fires. Receives the event object with a `payload` property. |
244
+
245
+ **Available event types**
246
+
247
+ | Event | Description |
248
+ |-------|-------------|
249
+ | `"extension:present"` | Fired when the aiOS Safari Extension is detected on the page. |
250
+ | `"agent:active"` | Fired when an AI agent performs an action (click, type, scroll) on the page. Payload includes the action type and whether it was blocked by policy. |
251
+ | `"agent:session-start"` | Fired when an AI agent begins a new interaction session. |
252
+ | `"agent:session-end"` | Fired when an agent session concludes. |
253
+
254
+ **Use cases**: Show a status indicator when the extension is connected, log agent actions for audit purposes, display real-time feedback when the agent interacts with page elements, or pause application logic during active agent sessions.
255
+
256
+ ---
257
+
258
+ ## Development
259
+
260
+ ```bash
261
+ # Run the test suite
262
+ npm run test
263
+
264
+ # Build for production (ES modules + CommonJS + type declarations)
265
+ npm run build
266
+
267
+ # Watch mode during development
268
+ npm run dev
269
+
270
+ # TypeScript type checking
271
+ npm run typecheck
272
+ ```
273
+
274
+ ---
275
+
276
+ ## What is Next
277
+
278
+ This is the foundational release of the aiOS Web SDK. Many more capabilities are on the roadmap, including enhanced agent session management, richer event streams, multi-page workflow coordination, and deeper framework integrations for React, Vue, and Angular. Stay tuned at [getaios.tech](https://www.getaios.tech) for updates.