@domglyph/runtime 2.0.0 → 2.1.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/README.md +12 -12
- package/dist/index.d.ts +5 -5
- package/dist/index.js +13 -13
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -9,7 +9,7 @@ The browser runtime that makes DOMglyph pages inspectable by AI agents.
|
|
|
9
9
|
|
|
10
10
|
## Overview
|
|
11
11
|
|
|
12
|
-
`@domglyph/runtime` installs `window.
|
|
12
|
+
`@domglyph/runtime` installs `window.__DOMGLYPH__` — a structured inspection API that AI agents use instead of scraping the DOM.
|
|
13
13
|
|
|
14
14
|
Without this runtime, an AI agent visiting your page would need to traverse the DOM, parse CSS, infer intent from visible text, and guess at state. With this runtime, the agent calls a single function and gets back a typed, structured description of exactly what is on screen and what can be done.
|
|
15
15
|
|
|
@@ -46,10 +46,10 @@ ReactDOM.createRoot(document.getElementById('root')!).render(<App />);
|
|
|
46
46
|
Open the browser console on any DOMglyph page and run:
|
|
47
47
|
|
|
48
48
|
```js
|
|
49
|
-
console.log(window.
|
|
49
|
+
console.log(window.__DOMGLYPH__.getScreenContext());
|
|
50
50
|
```
|
|
51
51
|
|
|
52
|
-
If `
|
|
52
|
+
If `__DOMGLYPH__` is defined and returns a context object, the runtime is installed correctly.
|
|
53
53
|
|
|
54
54
|
---
|
|
55
55
|
|
|
@@ -71,7 +71,7 @@ getScreenContext(): {
|
|
|
71
71
|
Example output:
|
|
72
72
|
|
|
73
73
|
```js
|
|
74
|
-
window.
|
|
74
|
+
window.__DOMGLYPH__.getScreenContext();
|
|
75
75
|
// {
|
|
76
76
|
// screen: "order-detail",
|
|
77
77
|
// entity: "order",
|
|
@@ -98,7 +98,7 @@ getAvailableActions(): Array<{
|
|
|
98
98
|
Example output:
|
|
99
99
|
|
|
100
100
|
```js
|
|
101
|
-
window.
|
|
101
|
+
window.__DOMGLYPH__.getAvailableActions();
|
|
102
102
|
// [
|
|
103
103
|
// { id: "approve-order", action: "approve-order", state: "idle", section: "actions" },
|
|
104
104
|
// { id: "cancel-order", action: "cancel-order", state: "idle", section: "actions" },
|
|
@@ -128,7 +128,7 @@ getFormSchema(formId: string): {
|
|
|
128
128
|
Example output:
|
|
129
129
|
|
|
130
130
|
```js
|
|
131
|
-
window.
|
|
131
|
+
window.__DOMGLYPH__.getFormSchema('edit-shipping-form');
|
|
132
132
|
// {
|
|
133
133
|
// formId: "edit-shipping-form",
|
|
134
134
|
// fields: [
|
|
@@ -156,7 +156,7 @@ getVisibleEntities(): Array<{
|
|
|
156
156
|
Example output:
|
|
157
157
|
|
|
158
158
|
```js
|
|
159
|
-
window.
|
|
159
|
+
window.__DOMGLYPH__.getVisibleEntities();
|
|
160
160
|
// [
|
|
161
161
|
// { entity: "order", entityId: "ord-9142", section: "summary" },
|
|
162
162
|
// { entity: "product", entityId: "prd-001", section: "line-items" },
|
|
@@ -185,7 +185,7 @@ getRecentEvents(): Array<{
|
|
|
185
185
|
Example output:
|
|
186
186
|
|
|
187
187
|
```js
|
|
188
|
-
window.
|
|
188
|
+
window.__DOMGLYPH__.getRecentEvents();
|
|
189
189
|
// [
|
|
190
190
|
// { type: "action_triggered", actionId: "approve-order", timestamp: 1711900000000 },
|
|
191
191
|
// { type: "action_completed", actionId: "approve-order", result: "success", timestamp: 1711900000250 }
|
|
@@ -202,7 +202,7 @@ In development, you can install the extended devtools runtime for additional ins
|
|
|
202
202
|
import { installDOMglyphDevtools } from '@domglyph/runtime';
|
|
203
203
|
|
|
204
204
|
installDOMglyphDevtools(window);
|
|
205
|
-
// window.
|
|
205
|
+
// window.__DOMGLYPH_DEVTOOLS__ is now available
|
|
206
206
|
```
|
|
207
207
|
|
|
208
208
|
The devtools runtime adds:
|
|
@@ -221,18 +221,18 @@ A typical agent interaction loop using the DOMglyph runtime:
|
|
|
221
221
|
|
|
222
222
|
```js
|
|
223
223
|
// Step 1: Orient — where am I and what entity am I looking at?
|
|
224
|
-
const ctx = window.
|
|
224
|
+
const ctx = window.__DOMGLYPH__.getScreenContext();
|
|
225
225
|
// { screen: "profile", entity: "user", entityId: "usr-42", sections: [...] }
|
|
226
226
|
|
|
227
227
|
// Step 2: Survey — what actions can I take right now?
|
|
228
|
-
const actions = window.
|
|
228
|
+
const actions = window.__DOMGLYPH__.getAvailableActions();
|
|
229
229
|
// [{ id: "save-profile", action: "save-profile", state: "idle", section: "contact" }]
|
|
230
230
|
|
|
231
231
|
// Step 3: Act — trigger the desired action deterministically
|
|
232
232
|
document.querySelector(`[data-ai-id="${actions[0].id}"]`).click();
|
|
233
233
|
|
|
234
234
|
// Step 4: Verify — did it work?
|
|
235
|
-
const events = window.
|
|
235
|
+
const events = window.__DOMGLYPH__.getRecentEvents();
|
|
236
236
|
// [{ type: "action_completed", actionId: "save-profile", result: "success", ... }]
|
|
237
237
|
```
|
|
238
238
|
|
package/dist/index.d.ts
CHANGED
|
@@ -91,13 +91,13 @@ declare function installDOMglyphRuntime(targetWindow?: Window): DOMglyphGlobalAP
|
|
|
91
91
|
|
|
92
92
|
declare const runtimeRegistry: RuntimeRegistry;
|
|
93
93
|
declare const defaultRuntimeEvent: "action_triggered";
|
|
94
|
-
declare const
|
|
95
|
-
declare const
|
|
94
|
+
declare const __DOMGLYPH__: DOMglyphGlobalAPI | null;
|
|
95
|
+
declare const __DOMGLYPH_DEVTOOLS__: DOMglyphDevtoolsAPI | null;
|
|
96
96
|
declare global {
|
|
97
97
|
interface Window {
|
|
98
|
-
|
|
99
|
-
|
|
98
|
+
__DOMGLYPH__?: DOMglyphGlobalAPI;
|
|
99
|
+
__DOMGLYPH_DEVTOOLS__?: DOMglyphDevtoolsAPI;
|
|
100
100
|
}
|
|
101
101
|
}
|
|
102
102
|
|
|
103
|
-
export { type AvailableAction,
|
|
103
|
+
export { type AvailableAction, type DOMglyphDevtoolsAPI, type DOMglyphGlobalAPI, DOMglyphRuntime, type FormFieldSchema, type FormSchema, type RuntimeEventLogEntry, type RuntimeRegistry, type ScreenContext, type VisibleEntity, __DOMGLYPH_DEVTOOLS__, __DOMGLYPH__, defaultRuntimeEvent, installDOMglyphDevtools, installDOMglyphRuntime, runtimeRegistry };
|
package/dist/index.js
CHANGED
|
@@ -294,11 +294,11 @@ function installDOMglyphRuntime(targetWindow = window) {
|
|
|
294
294
|
if (typeof targetWindow === "undefined" || targetWindow.document === void 0) {
|
|
295
295
|
return null;
|
|
296
296
|
}
|
|
297
|
-
if (targetWindow.
|
|
298
|
-
return targetWindow.
|
|
297
|
+
if (targetWindow.__DOMGLYPH__ !== void 0) {
|
|
298
|
+
return targetWindow.__DOMGLYPH__;
|
|
299
299
|
}
|
|
300
300
|
const runtime = new DOMglyphRuntime(targetWindow, targetWindow.document);
|
|
301
|
-
targetWindow.
|
|
301
|
+
targetWindow.__DOMGLYPH__ = runtime;
|
|
302
302
|
return runtime;
|
|
303
303
|
}
|
|
304
304
|
function parseStates(value) {
|
|
@@ -363,15 +363,15 @@ function installDOMglyphDevtools(targetWindow = window) {
|
|
|
363
363
|
if (typeof targetWindow === "undefined" || targetWindow.document === void 0) {
|
|
364
364
|
return null;
|
|
365
365
|
}
|
|
366
|
-
if (targetWindow.
|
|
367
|
-
return targetWindow.
|
|
366
|
+
if (targetWindow.__DOMGLYPH_DEVTOOLS__ !== void 0) {
|
|
367
|
+
return targetWindow.__DOMGLYPH_DEVTOOLS__;
|
|
368
368
|
}
|
|
369
|
-
const runtime = targetWindow.
|
|
369
|
+
const runtime = targetWindow.__DOMGLYPH__ ?? installDOMglyphRuntime(targetWindow);
|
|
370
370
|
if (runtime === null) {
|
|
371
371
|
return null;
|
|
372
372
|
}
|
|
373
373
|
const devtools = new DOMglyphDevtoolsOverlay(targetWindow, runtime);
|
|
374
|
-
targetWindow.
|
|
374
|
+
targetWindow.__DOMGLYPH_DEVTOOLS__ = devtools;
|
|
375
375
|
return devtools;
|
|
376
376
|
}
|
|
377
377
|
var DOMglyphDevtoolsOverlay = class {
|
|
@@ -473,8 +473,8 @@ var DOMglyphDevtoolsOverlay = class {
|
|
|
473
473
|
dispose();
|
|
474
474
|
}
|
|
475
475
|
this.root.remove();
|
|
476
|
-
if (this.win.
|
|
477
|
-
delete this.win.
|
|
476
|
+
if (this.win.__DOMGLYPH_DEVTOOLS__ === this) {
|
|
477
|
+
delete this.win.__DOMGLYPH_DEVTOOLS__;
|
|
478
478
|
}
|
|
479
479
|
}
|
|
480
480
|
isVisible() {
|
|
@@ -616,12 +616,12 @@ var runtimeRegistry = {
|
|
|
616
616
|
]
|
|
617
617
|
};
|
|
618
618
|
var defaultRuntimeEvent = AIEvent2.ACTION_TRIGGERED;
|
|
619
|
-
var
|
|
620
|
-
var
|
|
619
|
+
var __DOMGLYPH__ = typeof window === "undefined" ? null : installDOMglyphRuntime(window);
|
|
620
|
+
var __DOMGLYPH_DEVTOOLS__ = typeof window === "undefined" ? null : installDOMglyphDevtools(window);
|
|
621
621
|
export {
|
|
622
|
-
CORTEX_UI,
|
|
623
|
-
CORTEX_UI_DEVTOOLS,
|
|
624
622
|
DOMglyphRuntime,
|
|
623
|
+
__DOMGLYPH_DEVTOOLS__,
|
|
624
|
+
__DOMGLYPH__,
|
|
625
625
|
defaultRuntimeEvent,
|
|
626
626
|
installDOMglyphDevtools,
|
|
627
627
|
installDOMglyphRuntime,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@domglyph/runtime",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"dist"
|
|
16
16
|
],
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@domglyph/ai-contract": "2.
|
|
18
|
+
"@domglyph/ai-contract": "2.1.0"
|
|
19
19
|
},
|
|
20
20
|
"devDependencies": {
|
|
21
21
|
"tsup": "^8.5.1"
|