@ai11y/core 0.0.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/.turbo/turbo-build.log +87 -0
- package/CHANGELOG.md +29 -0
- package/README.md +37 -0
- package/dist/agent/agent-adapter.d.mts +17 -0
- package/dist/agent/agent-adapter.d.mts.map +1 -0
- package/dist/agent/agent-adapter.mjs +45 -0
- package/dist/agent/agent-adapter.mjs.map +1 -0
- package/dist/agent/llm-agent.d.mts +13 -0
- package/dist/agent/llm-agent.d.mts.map +1 -0
- package/dist/agent/llm-agent.mjs +41 -0
- package/dist/agent/llm-agent.mjs.map +1 -0
- package/dist/agent/plan.d.mts +27 -0
- package/dist/agent/plan.d.mts.map +1 -0
- package/dist/agent/plan.mjs +28 -0
- package/dist/agent/plan.mjs.map +1 -0
- package/dist/agent/rule-based-agent.d.mts +13 -0
- package/dist/agent/rule-based-agent.d.mts.map +1 -0
- package/dist/agent/rule-based-agent.mjs +152 -0
- package/dist/agent/rule-based-agent.mjs.map +1 -0
- package/dist/agent/tool-contract.d.mts +19 -0
- package/dist/agent/tool-contract.d.mts.map +1 -0
- package/dist/agent/types.d.mts +77 -0
- package/dist/agent/types.d.mts.map +1 -0
- package/dist/client-api.d.mts +49 -0
- package/dist/client-api.d.mts.map +1 -0
- package/dist/client-api.mjs +68 -0
- package/dist/client-api.mjs.map +1 -0
- package/dist/context.d.mts +29 -0
- package/dist/context.d.mts.map +1 -0
- package/dist/dom-actions/click.d.mts +15 -0
- package/dist/dom-actions/click.d.mts.map +1 -0
- package/dist/dom-actions/click.mjs +36 -0
- package/dist/dom-actions/click.mjs.map +1 -0
- package/dist/dom-actions/fill-input.d.mts +17 -0
- package/dist/dom-actions/fill-input.d.mts.map +1 -0
- package/dist/dom-actions/fill-input.mjs +69 -0
- package/dist/dom-actions/fill-input.mjs.map +1 -0
- package/dist/dom-actions/find-element.mjs +17 -0
- package/dist/dom-actions/find-element.mjs.map +1 -0
- package/dist/dom-actions/highlight.d.mts +34 -0
- package/dist/dom-actions/highlight.d.mts.map +1 -0
- package/dist/dom-actions/highlight.mjs +60 -0
- package/dist/dom-actions/highlight.mjs.map +1 -0
- package/dist/dom-actions/navigate.d.mts +16 -0
- package/dist/dom-actions/navigate.d.mts.map +1 -0
- package/dist/dom-actions/navigate.mjs +22 -0
- package/dist/dom-actions/navigate.mjs.map +1 -0
- package/dist/dom-actions/scroll.d.mts +16 -0
- package/dist/dom-actions/scroll.d.mts.map +1 -0
- package/dist/dom-actions/scroll.mjs +32 -0
- package/dist/dom-actions/scroll.mjs.map +1 -0
- package/dist/dom.d.mts +23 -0
- package/dist/dom.d.mts.map +1 -0
- package/dist/dom.mjs +60 -0
- package/dist/dom.mjs.map +1 -0
- package/dist/events.d.mts +35 -0
- package/dist/events.d.mts.map +1 -0
- package/dist/events.mjs +49 -0
- package/dist/events.mjs.map +1 -0
- package/dist/index.d.mts +21 -0
- package/dist/index.mjs +18 -0
- package/dist/instruction.d.mts +21 -0
- package/dist/instruction.d.mts.map +1 -0
- package/dist/marker.d.mts +35 -0
- package/dist/marker.d.mts.map +1 -0
- package/dist/marker.mjs +137 -0
- package/dist/marker.mjs.map +1 -0
- package/dist/store.d.mts +56 -0
- package/dist/store.d.mts.map +1 -0
- package/dist/store.mjs +114 -0
- package/dist/store.mjs.map +1 -0
- package/dist/util/attributes.d.mts +57 -0
- package/dist/util/attributes.d.mts.map +1 -0
- package/dist/util/attributes.mjs +68 -0
- package/dist/util/attributes.mjs.map +1 -0
- package/dist/util/format.d.mts +18 -0
- package/dist/util/format.d.mts.map +1 -0
- package/dist/util/format.mjs +21 -0
- package/dist/util/format.mjs.map +1 -0
- package/package.json +26 -0
- package/src/agent/agent-adapter.ts +75 -0
- package/src/agent/index.ts +21 -0
- package/src/agent/llm-agent.ts +64 -0
- package/src/agent/plan.ts +41 -0
- package/src/agent/rule-based-agent.ts +269 -0
- package/src/agent/tool-contract.ts +22 -0
- package/src/agent/types.ts +83 -0
- package/src/client-api.ts +107 -0
- package/src/context.ts +28 -0
- package/src/dom-actions/click.ts +39 -0
- package/src/dom-actions/fill-input.ts +113 -0
- package/src/dom-actions/find-element.ts +14 -0
- package/src/dom-actions/highlight.ts +93 -0
- package/src/dom-actions/index.ts +5 -0
- package/src/dom-actions/navigate.ts +17 -0
- package/src/dom-actions/scroll.ts +29 -0
- package/src/dom.ts +89 -0
- package/src/events.ts +55 -0
- package/src/index.ts +55 -0
- package/src/instruction.ts +6 -0
- package/src/marker.ts +237 -0
- package/src/store.ts +138 -0
- package/src/util/attributes.ts +68 -0
- package/src/util/format.ts +16 -0
- package/src/util/index.ts +2 -0
- package/tsconfig.json +18 -0
- package/tsdown.config.ts +10 -0
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
|
|
2
|
+
> @ai11y/core@0.0.1 build /home/runner/work/ai11y/ai11y/packages/core
|
|
3
|
+
> tsdown
|
|
4
|
+
|
|
5
|
+
[34mℹ[39m tsdown [2mv0.18.1[22m powered by rolldown [2mv1.0.0-beta.55[22m
|
|
6
|
+
[34mℹ[39m config file: [4m/home/runner/work/ai11y/ai11y/packages/core/tsdown.config.ts[24m (unrun)
|
|
7
|
+
[34mℹ[39m entry: [34msrc/index.ts[39m
|
|
8
|
+
[34mℹ[39m tsconfig: [34mtsconfig.json[39m
|
|
9
|
+
[34mℹ[39m Build start
|
|
10
|
+
[34mℹ[39m [2mdist/[22m[1mindex.mjs[22m [2m 1.67 kB[22m [2m│ gzip: 0.48 kB[22m
|
|
11
|
+
[34mℹ[39m [2mdist/[22magent/rule-based-agent.mjs.map [2m13.04 kB[22m [2m│ gzip: 3.34 kB[22m
|
|
12
|
+
[34mℹ[39m [2mdist/[22mmarker.mjs.map [2m 8.74 kB[22m [2m│ gzip: 2.69 kB[22m
|
|
13
|
+
[34mℹ[39m [2mdist/[22magent/rule-based-agent.mjs [2m 6.28 kB[22m [2m│ gzip: 1.58 kB[22m
|
|
14
|
+
[34mℹ[39m [2mdist/[22mdom-actions/fill-input.mjs.map [2m 5.46 kB[22m [2m│ gzip: 1.94 kB[22m
|
|
15
|
+
[34mℹ[39m [2mdist/[22mmarker.mjs [2m 4.72 kB[22m [2m│ gzip: 1.52 kB[22m
|
|
16
|
+
[34mℹ[39m [2mdist/[22mstore.mjs.map [2m 4.60 kB[22m [2m│ gzip: 1.60 kB[22m
|
|
17
|
+
[34mℹ[39m [2mdist/[22mdom-actions/highlight.mjs.map [2m 3.71 kB[22m [2m│ gzip: 1.48 kB[22m
|
|
18
|
+
[34mℹ[39m [2mdist/[22mdom.mjs.map [2m 3.65 kB[22m [2m│ gzip: 1.37 kB[22m
|
|
19
|
+
[34mℹ[39m [2mdist/[22mclient-api.mjs.map [2m 3.34 kB[22m [2m│ gzip: 1.25 kB[22m
|
|
20
|
+
[34mℹ[39m [2mdist/[22magent/agent-adapter.mjs.map [2m 3.12 kB[22m [2m│ gzip: 1.24 kB[22m
|
|
21
|
+
[34mℹ[39m [2mdist/[22magent/llm-agent.mjs.map [2m 2.92 kB[22m [2m│ gzip: 1.20 kB[22m
|
|
22
|
+
[34mℹ[39m [2mdist/[22mdom-actions/fill-input.mjs [2m 2.65 kB[22m [2m│ gzip: 0.92 kB[22m
|
|
23
|
+
[34mℹ[39m [2mdist/[22mstore.mjs [2m 2.50 kB[22m [2m│ gzip: 0.97 kB[22m
|
|
24
|
+
[34mℹ[39m [2mdist/[22mutil/attributes.mjs.map [2m 2.43 kB[22m [2m│ gzip: 0.75 kB[22m
|
|
25
|
+
[34mℹ[39m [2mdist/[22mdom.mjs [2m 2.26 kB[22m [2m│ gzip: 0.90 kB[22m
|
|
26
|
+
[34mℹ[39m [2mdist/[22mdom-actions/highlight.mjs [2m 1.98 kB[22m [2m│ gzip: 0.85 kB[22m
|
|
27
|
+
[34mℹ[39m [2mdist/[22mutil/attributes.mjs [2m 1.91 kB[22m [2m│ gzip: 0.59 kB[22m
|
|
28
|
+
[34mℹ[39m [2mdist/[22mclient-api.mjs [2m 1.65 kB[22m [2m│ gzip: 0.65 kB[22m
|
|
29
|
+
[34mℹ[39m [2mdist/[22magent/agent-adapter.mjs [2m 1.63 kB[22m [2m│ gzip: 0.67 kB[22m
|
|
30
|
+
[34mℹ[39m [2mdist/[22mevents.mjs.map [2m 1.58 kB[22m [2m│ gzip: 0.75 kB[22m
|
|
31
|
+
[34mℹ[39m [2mdist/[22mdom-actions/click.mjs.map [2m 1.42 kB[22m [2m│ gzip: 0.74 kB[22m
|
|
32
|
+
[34mℹ[39m [2mdist/[22magent/llm-agent.mjs [2m 1.40 kB[22m [2m│ gzip: 0.66 kB[22m
|
|
33
|
+
[34mℹ[39m [2mdist/[22magent/plan.mjs.map [2m 1.29 kB[22m [2m│ gzip: 0.63 kB[22m
|
|
34
|
+
[34mℹ[39m [2mdist/[22mdom-actions/scroll.mjs.map [2m 1.06 kB[22m [2m│ gzip: 0.59 kB[22m
|
|
35
|
+
[34mℹ[39m [2mdist/[22mevents.mjs [2m 1.02 kB[22m [2m│ gzip: 0.51 kB[22m
|
|
36
|
+
[34mℹ[39m [2mdist/[22mdom-actions/click.mjs [2m 0.79 kB[22m [2m│ gzip: 0.43 kB[22m
|
|
37
|
+
[34mℹ[39m [2mdist/[22magent/plan.mjs [2m 0.78 kB[22m [2m│ gzip: 0.43 kB[22m
|
|
38
|
+
[34mℹ[39m [2mdist/[22mdom-actions/scroll.mjs [2m 0.75 kB[22m [2m│ gzip: 0.43 kB[22m
|
|
39
|
+
[34mℹ[39m [2mdist/[22mdom-actions/find-element.mjs.map [2m 0.68 kB[22m [2m│ gzip: 0.42 kB[22m
|
|
40
|
+
[34mℹ[39m [2mdist/[22mutil/format.mjs.map [2m 0.64 kB[22m [2m│ gzip: 0.41 kB[22m
|
|
41
|
+
[34mℹ[39m [2mdist/[22mdom-actions/navigate.mjs.map [2m 0.60 kB[22m [2m│ gzip: 0.36 kB[22m
|
|
42
|
+
[34mℹ[39m [2mdist/[22mdom-actions/find-element.mjs [2m 0.50 kB[22m [2m│ gzip: 0.31 kB[22m
|
|
43
|
+
[34mℹ[39m [2mdist/[22mutil/format.mjs [2m 0.47 kB[22m [2m│ gzip: 0.31 kB[22m
|
|
44
|
+
[34mℹ[39m [2mdist/[22mstore.d.mts.map [2m 0.45 kB[22m [2m│ gzip: 0.25 kB[22m
|
|
45
|
+
[34mℹ[39m [2mdist/[22mdom-actions/navigate.mjs [2m 0.45 kB[22m [2m│ gzip: 0.27 kB[22m
|
|
46
|
+
[34mℹ[39m [2mdist/[22mutil/attributes.d.mts.map [2m 0.39 kB[22m [2m│ gzip: 0.24 kB[22m
|
|
47
|
+
[34mℹ[39m [2mdist/[22magent/types.d.mts.map [2m 0.39 kB[22m [2m│ gzip: 0.26 kB[22m
|
|
48
|
+
[34mℹ[39m [2mdist/[22mcontext.d.mts.map [2m 0.32 kB[22m [2m│ gzip: 0.21 kB[22m
|
|
49
|
+
[34mℹ[39m [2mdist/[22magent/tool-contract.d.mts.map [2m 0.31 kB[22m [2m│ gzip: 0.21 kB[22m
|
|
50
|
+
[34mℹ[39m [2mdist/[22magent/agent-adapter.d.mts.map [2m 0.29 kB[22m [2m│ gzip: 0.20 kB[22m
|
|
51
|
+
[34mℹ[39m [2mdist/[22magent/llm-agent.d.mts.map [2m 0.28 kB[22m [2m│ gzip: 0.19 kB[22m
|
|
52
|
+
[34mℹ[39m [2mdist/[22mclient-api.d.mts.map [2m 0.27 kB[22m [2m│ gzip: 0.20 kB[22m
|
|
53
|
+
[34mℹ[39m [2mdist/[22mevents.d.mts.map [2m 0.24 kB[22m [2m│ gzip: 0.17 kB[22m
|
|
54
|
+
[34mℹ[39m [2mdist/[22mdom-actions/highlight.d.mts.map [2m 0.21 kB[22m [2m│ gzip: 0.17 kB[22m
|
|
55
|
+
[34mℹ[39m [2mdist/[22mmarker.d.mts.map [2m 0.19 kB[22m [2m│ gzip: 0.15 kB[22m
|
|
56
|
+
[34mℹ[39m [2mdist/[22magent/plan.d.mts.map [2m 0.18 kB[22m [2m│ gzip: 0.15 kB[22m
|
|
57
|
+
[34mℹ[39m [2mdist/[22magent/rule-based-agent.d.mts.map [2m 0.18 kB[22m [2m│ gzip: 0.15 kB[22m
|
|
58
|
+
[34mℹ[39m [2mdist/[22mdom-actions/fill-input.d.mts.map [2m 0.16 kB[22m [2m│ gzip: 0.14 kB[22m
|
|
59
|
+
[34mℹ[39m [2mdist/[22mdom-actions/navigate.d.mts.map [2m 0.16 kB[22m [2m│ gzip: 0.13 kB[22m
|
|
60
|
+
[34mℹ[39m [2mdist/[22mdom-actions/scroll.d.mts.map [2m 0.15 kB[22m [2m│ gzip: 0.13 kB[22m
|
|
61
|
+
[34mℹ[39m [2mdist/[22mdom.d.mts.map [2m 0.15 kB[22m [2m│ gzip: 0.13 kB[22m
|
|
62
|
+
[34mℹ[39m [2mdist/[22minstruction.d.mts.map [2m 0.15 kB[22m [2m│ gzip: 0.13 kB[22m
|
|
63
|
+
[34mℹ[39m [2mdist/[22mdom-actions/click.d.mts.map [2m 0.15 kB[22m [2m│ gzip: 0.13 kB[22m
|
|
64
|
+
[34mℹ[39m [2mdist/[22mutil/format.d.mts.map [2m 0.15 kB[22m [2m│ gzip: 0.13 kB[22m
|
|
65
|
+
[34mℹ[39m [2mdist/[22m[32m[1mindex.d.mts[22m[39m [2m 2.39 kB[22m [2m│ gzip: 0.67 kB[22m
|
|
66
|
+
[34mℹ[39m [2mdist/[22m[32magent/types.d.mts[39m [2m 2.09 kB[22m [2m│ gzip: 0.72 kB[22m
|
|
67
|
+
[34mℹ[39m [2mdist/[22m[32mstore.d.mts[39m [2m 1.94 kB[22m [2m│ gzip: 0.74 kB[22m
|
|
68
|
+
[34mℹ[39m [2mdist/[22m[32mutil/attributes.d.mts[39m [2m 1.89 kB[22m [2m│ gzip: 0.56 kB[22m
|
|
69
|
+
[34mℹ[39m [2mdist/[22m[32mclient-api.d.mts[39m [2m 1.22 kB[22m [2m│ gzip: 0.59 kB[22m
|
|
70
|
+
[34mℹ[39m [2mdist/[22m[32mdom-actions/highlight.d.mts[39m [2m 1.03 kB[22m [2m│ gzip: 0.52 kB[22m
|
|
71
|
+
[34mℹ[39m [2mdist/[22m[32magent/plan.d.mts[39m [2m 0.91 kB[22m [2m│ gzip: 0.48 kB[22m
|
|
72
|
+
[34mℹ[39m [2mdist/[22m[32mmarker.d.mts[39m [2m 0.90 kB[22m [2m│ gzip: 0.45 kB[22m
|
|
73
|
+
[34mℹ[39m [2mdist/[22m[32mevents.d.mts[39m [2m 0.87 kB[22m [2m│ gzip: 0.43 kB[22m
|
|
74
|
+
[34mℹ[39m [2mdist/[22m[32magent/agent-adapter.d.mts[39m [2m 0.72 kB[22m [2m│ gzip: 0.40 kB[22m
|
|
75
|
+
[34mℹ[39m [2mdist/[22m[32mdom-actions/fill-input.d.mts[39m [2m 0.66 kB[22m [2m│ gzip: 0.37 kB[22m
|
|
76
|
+
[34mℹ[39m [2mdist/[22m[32mdom.d.mts[39m [2m 0.65 kB[22m [2m│ gzip: 0.38 kB[22m
|
|
77
|
+
[34mℹ[39m [2mdist/[22m[32mcontext.d.mts[39m [2m 0.58 kB[22m [2m│ gzip: 0.30 kB[22m
|
|
78
|
+
[34mℹ[39m [2mdist/[22m[32magent/llm-agent.d.mts[39m [2m 0.52 kB[22m [2m│ gzip: 0.32 kB[22m
|
|
79
|
+
[34mℹ[39m [2mdist/[22m[32magent/tool-contract.d.mts[39m [2m 0.51 kB[22m [2m│ gzip: 0.30 kB[22m
|
|
80
|
+
[34mℹ[39m [2mdist/[22m[32magent/rule-based-agent.d.mts[39m [2m 0.45 kB[22m [2m│ gzip: 0.28 kB[22m
|
|
81
|
+
[34mℹ[39m [2mdist/[22m[32mdom-actions/scroll.d.mts[39m [2m 0.44 kB[22m [2m│ gzip: 0.28 kB[22m
|
|
82
|
+
[34mℹ[39m [2mdist/[22m[32mutil/format.d.mts[39m [2m 0.42 kB[22m [2m│ gzip: 0.27 kB[22m
|
|
83
|
+
[34mℹ[39m [2mdist/[22m[32mdom-actions/navigate.d.mts[39m [2m 0.38 kB[22m [2m│ gzip: 0.24 kB[22m
|
|
84
|
+
[34mℹ[39m [2mdist/[22m[32minstruction.d.mts[39m [2m 0.35 kB[22m [2m│ gzip: 0.18 kB[22m
|
|
85
|
+
[34mℹ[39m [2mdist/[22m[32mdom-actions/click.d.mts[39m [2m 0.32 kB[22m [2m│ gzip: 0.23 kB[22m
|
|
86
|
+
[34mℹ[39m 76 files, total: 115.71 kB
|
|
87
|
+
[32m✔[39m Build complete in [32m1542ms[39m
|
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# @ai11y/core
|
|
2
|
+
|
|
3
|
+
## 0.0.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#10](https://github.com/maerzhase/ai11y/pull/10)
|
|
8
|
+
[`a578f29`](https://github.com/maerzhase/ai11y/commit/a578f296c21cd19c935ff8003442677f7a1cb72d)
|
|
9
|
+
Thanks [@maerzhase](https://github.com/maerzhase)! - Docs and demo
|
|
10
|
+
improvements: naming (ai11y ≠ a11y), Describe/Plan/Act boundaries, UI context
|
|
11
|
+
payload viewer, annotation guidance, Why not ARIA, Security & privacy,
|
|
12
|
+
multi-step demo
|
|
13
|
+
|
|
14
|
+
- [#10](https://github.com/maerzhase/ai11y/pull/10)
|
|
15
|
+
[`a578f29`](https://github.com/maerzhase/ai11y/commit/a578f296c21cd19c935ff8003442677f7a1cb72d)
|
|
16
|
+
Thanks [@maerzhase](https://github.com/maerzhase)! - Add custom state
|
|
17
|
+
management and privacy protection features
|
|
18
|
+
- **Custom State API**: `setState()` now merges with existing state (like
|
|
19
|
+
React's setState), allowing multiple components to independently manage
|
|
20
|
+
state keys. Added `clearState()` helper for resetting state.
|
|
21
|
+
- **Privacy Protection**: Automatically redact sensitive input values
|
|
22
|
+
(passwords, hidden fields, credit card fields) from UI context. Values are
|
|
23
|
+
replaced with `[REDACTED]` to prevent exposure to AI agents.
|
|
24
|
+
- **Sensitive Marker Support**: Added `data-ai-sensitive` attribute and
|
|
25
|
+
`sensitive` prop to Marker component for explicitly marking sensitive
|
|
26
|
+
fields.
|
|
27
|
+
- **Agent Improvements**: Enhanced agent prompts with security rules to
|
|
28
|
+
prevent filling password fields and improved pronoun resolution for better
|
|
29
|
+
context tracking in conversations.
|
package/README.md
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# @ai11y/core
|
|
2
|
+
|
|
3
|
+
Framework-agnostic core. Your app exposes UI via markers (elements with
|
|
4
|
+
`data-ai-id`, `data-ai-label`, optional `data-ai-intent`). The API is **describe
|
|
5
|
+
→ plan → act**.
|
|
6
|
+
|
|
7
|
+
## API
|
|
8
|
+
|
|
9
|
+
- **`createClient(options?)`** — Returns
|
|
10
|
+
`{ describe, act, track, reportError }`. Options:
|
|
11
|
+
`onNavigate?: (route: string) => void`.
|
|
12
|
+
- **`describe()`** — Returns `Ai11yContext`: markers, route, state, optional
|
|
13
|
+
error. Scans the DOM for marked elements and which are in view.
|
|
14
|
+
- **`act(instruction)`** — Executes one instruction: click, navigate, highlight,
|
|
15
|
+
scroll, or fillInput.
|
|
16
|
+
- **`plan(ui, input, config?, messages?)`** — Runs the agent (LLM or rule-based)
|
|
17
|
+
and returns `Promise<{ reply, instructions }>`.
|
|
18
|
+
|
|
19
|
+
**JavaScript example:**
|
|
20
|
+
|
|
21
|
+
```ts
|
|
22
|
+
import { createClient, plan } from "@ai11y/core";
|
|
23
|
+
|
|
24
|
+
const client = createClient({
|
|
25
|
+
onNavigate: (route) => window.history.pushState({}, "", route),
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
const ui = client.describe();
|
|
29
|
+
const { reply, instructions } = await plan(ui, "click the save button");
|
|
30
|
+
for (const instruction of instructions ?? []) {
|
|
31
|
+
client.act(instruction);
|
|
32
|
+
}
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
Types (`Ai11yContext`, `Instruction`, `AgentResponse`, etc.) and DOM helpers
|
|
36
|
+
(`clickMarker`, `highlightMarker`, `navigateToRoute`, etc.) are exported from
|
|
37
|
+
the main entry. See generated docs for full reference.
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Ai11yContext } from "../context.mjs";
|
|
2
|
+
import { AgentAdapterConfig, AgentResponse, ConversationMessage } from "./types.mjs";
|
|
3
|
+
|
|
4
|
+
//#region src/agent/agent-adapter.d.ts
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Select and run the appropriate agent based on configuration.
|
|
8
|
+
*
|
|
9
|
+
* This adapter handles agent selection logic:
|
|
10
|
+
* - "llm": Always use LLM agent (requires llmConfig)
|
|
11
|
+
* - "rule-based": Always use rule-based agent
|
|
12
|
+
* - "auto": Use LLM if configured, fallback to rule-based on error or when offline
|
|
13
|
+
*/
|
|
14
|
+
declare function runAgentAdapter(input: string, context: Ai11yContext, config?: AgentAdapterConfig, messages?: ConversationMessage[]): Promise<AgentResponse>;
|
|
15
|
+
//#endregion
|
|
16
|
+
export { runAgentAdapter };
|
|
17
|
+
//# sourceMappingURL=agent-adapter.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent-adapter.d.mts","names":[],"sources":["../../src/agent/agent-adapter.ts"],"sourcesContent":[],"mappings":";;;;;;;AA2BA;;;;;;AAKU,iBALY,eAAA,CAKZ,KAAA,EAAA,MAAA,EAAA,OAAA,EAHA,YAGA,EAAA,MAAA,CAAA,EAFD,kBAEC,EAAA,QAAA,CAAA,EADE,mBACF,EAAA,CAAA,EAAP,OAAO,CAAC,aAAD,CAAA"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { runLLMAgent } from "./llm-agent.mjs";
|
|
2
|
+
import { runRuleBasedAgent } from "./rule-based-agent.mjs";
|
|
3
|
+
|
|
4
|
+
//#region src/agent/agent-adapter.ts
|
|
5
|
+
/**
|
|
6
|
+
* Detect if we're likely offline (browser only)
|
|
7
|
+
*/
|
|
8
|
+
function isLikelyOffline() {
|
|
9
|
+
if (typeof navigator !== "undefined" && "onLine" in navigator) return !navigator.onLine;
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Select and run the appropriate agent based on configuration.
|
|
14
|
+
*
|
|
15
|
+
* This adapter handles agent selection logic:
|
|
16
|
+
* - "llm": Always use LLM agent (requires llmConfig)
|
|
17
|
+
* - "rule-based": Always use rule-based agent
|
|
18
|
+
* - "auto": Use LLM if configured, fallback to rule-based on error or when offline
|
|
19
|
+
*/
|
|
20
|
+
async function runAgentAdapter(input, context, config = {}, messages) {
|
|
21
|
+
const { mode = "auto", llmConfig = null, forceRuleBased = false } = config;
|
|
22
|
+
if (forceRuleBased || mode === "rule-based") return runRuleBasedAgent(input, context);
|
|
23
|
+
if (mode === "llm") {
|
|
24
|
+
if (!llmConfig) {
|
|
25
|
+
console.warn("LLM mode requested but no llmConfig provided. Falling back to rule-based agent.");
|
|
26
|
+
return runRuleBasedAgent(input, context);
|
|
27
|
+
}
|
|
28
|
+
return runLLMAgent(input, context, llmConfig, messages);
|
|
29
|
+
}
|
|
30
|
+
if (mode === "auto" || !mode) {
|
|
31
|
+
if (isLikelyOffline()) return runRuleBasedAgent(input, context);
|
|
32
|
+
if (llmConfig) try {
|
|
33
|
+
return await runLLMAgent(input, context, llmConfig, messages);
|
|
34
|
+
} catch (error) {
|
|
35
|
+
console.warn("LLM agent failed, using rule-based fallback:", error);
|
|
36
|
+
return runRuleBasedAgent(input, context);
|
|
37
|
+
}
|
|
38
|
+
return runRuleBasedAgent(input, context);
|
|
39
|
+
}
|
|
40
|
+
return runRuleBasedAgent(input, context);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
//#endregion
|
|
44
|
+
export { runAgentAdapter };
|
|
45
|
+
//# sourceMappingURL=agent-adapter.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent-adapter.mjs","names":[],"sources":["../../src/agent/agent-adapter.ts"],"sourcesContent":["import type { Ai11yContext } from \"../context.js\";\nimport { runLLMAgent } from \"./llm-agent.js\";\nimport { runRuleBasedAgent } from \"./rule-based-agent.js\";\nimport type {\n\tAgentAdapterConfig,\n\tAgentResponse,\n\tConversationMessage,\n} from \"./types.js\";\n\n/**\n * Detect if we're likely offline (browser only)\n */\nfunction isLikelyOffline(): boolean {\n\tif (typeof navigator !== \"undefined\" && \"onLine\" in navigator) {\n\t\treturn !navigator.onLine;\n\t}\n\treturn false;\n}\n\n/**\n * Select and run the appropriate agent based on configuration.\n *\n * This adapter handles agent selection logic:\n * - \"llm\": Always use LLM agent (requires llmConfig)\n * - \"rule-based\": Always use rule-based agent\n * - \"auto\": Use LLM if configured, fallback to rule-based on error or when offline\n */\nexport async function runAgentAdapter(\n\tinput: string,\n\tcontext: Ai11yContext,\n\tconfig: AgentAdapterConfig = {},\n\tmessages?: ConversationMessage[],\n): Promise<AgentResponse> {\n\tconst { mode = \"auto\", llmConfig = null, forceRuleBased = false } = config;\n\n\t// Force rule-based agent if explicitly requested\n\tif (forceRuleBased || mode === \"rule-based\") {\n\t\treturn runRuleBasedAgent(input, context);\n\t}\n\n\tif (mode === \"llm\") {\n\t\tif (!llmConfig) {\n\t\t\tconsole.warn(\n\t\t\t\t\"LLM mode requested but no llmConfig provided. Falling back to rule-based agent.\",\n\t\t\t);\n\t\t\treturn runRuleBasedAgent(input, context);\n\t\t}\n\t\treturn runLLMAgent(input, context, llmConfig, messages);\n\t}\n\n\t// Auto mode: try LLM if available, fallback to rule-based\n\tif (mode === \"auto\" || !mode) {\n\t\t// Check if we're offline - use rule-based\n\t\tif (isLikelyOffline()) {\n\t\t\treturn runRuleBasedAgent(input, context);\n\t\t}\n\n\t\t// Try LLM if configured\n\t\tif (llmConfig) {\n\t\t\ttry {\n\t\t\t\treturn await runLLMAgent(input, context, llmConfig, messages);\n\t\t\t} catch (error) {\n\t\t\t\t// runLLMAgent already falls back to rule-based, but we catch here for safety\n\t\t\t\tconsole.warn(\"LLM agent failed, using rule-based fallback:\", error);\n\t\t\t\treturn runRuleBasedAgent(input, context);\n\t\t\t}\n\t\t}\n\n\t\t// Default to rule-based\n\t\treturn runRuleBasedAgent(input, context);\n\t}\n\n\t// Fallback (shouldn't reach here)\n\treturn runRuleBasedAgent(input, context);\n}\n"],"mappings":";;;;;;;AAYA,SAAS,kBAA2B;AACnC,KAAI,OAAO,cAAc,eAAe,YAAY,UACnD,QAAO,CAAC,UAAU;AAEnB,QAAO;;;;;;;;;;AAWR,eAAsB,gBACrB,OACA,SACA,SAA6B,EAAE,EAC/B,UACyB;CACzB,MAAM,EAAE,OAAO,QAAQ,YAAY,MAAM,iBAAiB,UAAU;AAGpE,KAAI,kBAAkB,SAAS,aAC9B,QAAO,kBAAkB,OAAO,QAAQ;AAGzC,KAAI,SAAS,OAAO;AACnB,MAAI,CAAC,WAAW;AACf,WAAQ,KACP,kFACA;AACD,UAAO,kBAAkB,OAAO,QAAQ;;AAEzC,SAAO,YAAY,OAAO,SAAS,WAAW,SAAS;;AAIxD,KAAI,SAAS,UAAU,CAAC,MAAM;AAE7B,MAAI,iBAAiB,CACpB,QAAO,kBAAkB,OAAO,QAAQ;AAIzC,MAAI,UACH,KAAI;AACH,UAAO,MAAM,YAAY,OAAO,SAAS,WAAW,SAAS;WACrD,OAAO;AAEf,WAAQ,KAAK,gDAAgD,MAAM;AACnE,UAAO,kBAAkB,OAAO,QAAQ;;AAK1C,SAAO,kBAAkB,OAAO,QAAQ;;AAIzC,QAAO,kBAAkB,OAAO,QAAQ"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Ai11yContext } from "../context.mjs";
|
|
2
|
+
import { AgentResponse, ConversationMessage, LLMAgentConfig } from "./types.mjs";
|
|
3
|
+
|
|
4
|
+
//#region src/agent/llm-agent.d.ts
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* LLM-based agent using server-side API endpoint.
|
|
8
|
+
* Falls back to rule-based agent if the API is not available.
|
|
9
|
+
*/
|
|
10
|
+
declare function runLLMAgent(input: string, context: Ai11yContext, config: LLMAgentConfig, messages?: ConversationMessage[]): Promise<AgentResponse>;
|
|
11
|
+
//#endregion
|
|
12
|
+
export { runLLMAgent };
|
|
13
|
+
//# sourceMappingURL=llm-agent.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"llm-agent.d.mts","names":[],"sources":["../../src/agent/llm-agent.ts"],"sourcesContent":[],"mappings":";;;;;;;AAWA;;AAGS,iBAHa,WAAA,CAGb,KAAA,EAAA,MAAA,EAAA,OAAA,EADC,YACD,EAAA,MAAA,EAAA,cAAA,EAAA,QAAA,CAAA,EACG,mBADH,EAAA,CAAA,EAEN,OAFM,CAEE,aAFF,CAAA"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
//#region src/agent/llm-agent.ts
|
|
2
|
+
/**
|
|
3
|
+
* LLM-based agent using server-side API endpoint.
|
|
4
|
+
* Falls back to rule-based agent if the API is not available.
|
|
5
|
+
*/
|
|
6
|
+
async function runLLMAgent(input, context, config, messages) {
|
|
7
|
+
try {
|
|
8
|
+
const response = await fetch(config.apiEndpoint, {
|
|
9
|
+
method: "POST",
|
|
10
|
+
headers: { "Content-Type": "application/json" },
|
|
11
|
+
body: JSON.stringify({
|
|
12
|
+
input,
|
|
13
|
+
context: {
|
|
14
|
+
markers: context.markers,
|
|
15
|
+
...context.inViewMarkerIds !== void 0 && { inViewMarkerIds: context.inViewMarkerIds },
|
|
16
|
+
...context.route !== void 0 && { route: context.route },
|
|
17
|
+
...context.state !== void 0 && { state: context.state },
|
|
18
|
+
...context.error !== void 0 && { error: context.error ? {
|
|
19
|
+
error: { message: context.error.error.message },
|
|
20
|
+
meta: context.error.meta,
|
|
21
|
+
timestamp: context.error.timestamp
|
|
22
|
+
} : null }
|
|
23
|
+
},
|
|
24
|
+
messages: messages?.slice(-10)
|
|
25
|
+
})
|
|
26
|
+
});
|
|
27
|
+
if (!response.ok) {
|
|
28
|
+
const errorText = await response.text();
|
|
29
|
+
throw new Error(`API request failed: ${response.status} ${response.statusText}. ${errorText}`);
|
|
30
|
+
}
|
|
31
|
+
return await response.json();
|
|
32
|
+
} catch (error) {
|
|
33
|
+
console.warn("LLM agent error, falling back to rule-based agent:", error);
|
|
34
|
+
const { runRuleBasedAgent } = await import("./rule-based-agent.mjs");
|
|
35
|
+
return runRuleBasedAgent(input, context);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
//#endregion
|
|
40
|
+
export { runLLMAgent };
|
|
41
|
+
//# sourceMappingURL=llm-agent.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"llm-agent.mjs","names":[],"sources":["../../src/agent/llm-agent.ts"],"sourcesContent":["import type { Ai11yContext } from \"../context.js\";\nimport type {\n\tAgentResponse,\n\tConversationMessage,\n\tLLMAgentConfig,\n} from \"./types.js\";\n\n/**\n * LLM-based agent using server-side API endpoint.\n * Falls back to rule-based agent if the API is not available.\n */\nexport async function runLLMAgent(\n\tinput: string,\n\tcontext: Ai11yContext,\n\tconfig: LLMAgentConfig,\n\tmessages?: ConversationMessage[],\n): Promise<AgentResponse> {\n\ttry {\n\t\tconst response = await fetch(config.apiEndpoint, {\n\t\t\tmethod: \"POST\",\n\t\t\theaders: {\n\t\t\t\t\"Content-Type\": \"application/json\",\n\t\t\t},\n\t\t\tbody: JSON.stringify({\n\t\t\t\tinput,\n\t\t\t\tcontext: {\n\t\t\t\t\tmarkers: context.markers,\n\t\t\t\t\t...(context.inViewMarkerIds !== undefined && {\n\t\t\t\t\t\tinViewMarkerIds: context.inViewMarkerIds,\n\t\t\t\t\t}),\n\t\t\t\t\t...(context.route !== undefined && { route: context.route }),\n\t\t\t\t\t...(context.state !== undefined && { state: context.state }),\n\t\t\t\t\t...(context.error !== undefined && {\n\t\t\t\t\t\terror: context.error\n\t\t\t\t\t\t\t? {\n\t\t\t\t\t\t\t\t\terror: {\n\t\t\t\t\t\t\t\t\t\tmessage: context.error.error.message,\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\tmeta: context.error.meta,\n\t\t\t\t\t\t\t\t\ttimestamp: context.error.timestamp,\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t: null,\n\t\t\t\t\t}),\n\t\t\t\t},\n\t\t\t\tmessages: messages?.slice(-10),\n\t\t\t}),\n\t\t});\n\n\t\tif (!response.ok) {\n\t\t\tconst errorText = await response.text();\n\t\t\tthrow new Error(\n\t\t\t\t`API request failed: ${response.status} ${response.statusText}. ${errorText}`,\n\t\t\t);\n\t\t}\n\n\t\tconst data: AgentResponse = await response.json();\n\t\treturn data;\n\t} catch (error) {\n\t\t// If API is not available or there's an error, fall back to rule-based\n\t\tconsole.warn(\"LLM agent error, falling back to rule-based agent:\", error);\n\t\tconst { runRuleBasedAgent } = await import(\"./rule-based-agent.js\");\n\t\treturn runRuleBasedAgent(input, context);\n\t}\n}\n"],"mappings":";;;;;AAWA,eAAsB,YACrB,OACA,SACA,QACA,UACyB;AACzB,KAAI;EACH,MAAM,WAAW,MAAM,MAAM,OAAO,aAAa;GAChD,QAAQ;GACR,SAAS,EACR,gBAAgB,oBAChB;GACD,MAAM,KAAK,UAAU;IACpB;IACA,SAAS;KACR,SAAS,QAAQ;KACjB,GAAI,QAAQ,oBAAoB,UAAa,EAC5C,iBAAiB,QAAQ,iBACzB;KACD,GAAI,QAAQ,UAAU,UAAa,EAAE,OAAO,QAAQ,OAAO;KAC3D,GAAI,QAAQ,UAAU,UAAa,EAAE,OAAO,QAAQ,OAAO;KAC3D,GAAI,QAAQ,UAAU,UAAa,EAClC,OAAO,QAAQ,QACZ;MACA,OAAO,EACN,SAAS,QAAQ,MAAM,MAAM,SAC7B;MACD,MAAM,QAAQ,MAAM;MACpB,WAAW,QAAQ,MAAM;MACzB,GACA,MACH;KACD;IACD,UAAU,UAAU,MAAM,IAAI;IAC9B,CAAC;GACF,CAAC;AAEF,MAAI,CAAC,SAAS,IAAI;GACjB,MAAM,YAAY,MAAM,SAAS,MAAM;AACvC,SAAM,IAAI,MACT,uBAAuB,SAAS,OAAO,GAAG,SAAS,WAAW,IAAI,YAClE;;AAIF,SAD4B,MAAM,SAAS,MAAM;UAEzC,OAAO;AAEf,UAAQ,KAAK,sDAAsD,MAAM;EACzE,MAAM,EAAE,sBAAsB,MAAM,OAAO;AAC3C,SAAO,kBAAkB,OAAO,QAAQ"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Ai11yContext } from "../context.mjs";
|
|
2
|
+
import { AgentAdapterConfig, AgentResponse, ConversationMessage } from "./types.mjs";
|
|
3
|
+
|
|
4
|
+
//#region src/agent/plan.d.ts
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Plans instructions based on UI context and user input
|
|
8
|
+
*
|
|
9
|
+
* @param ui - The current UI context
|
|
10
|
+
* @param input - User input/command
|
|
11
|
+
* @param config - Optional agent configuration
|
|
12
|
+
* @param messages - Optional conversation history
|
|
13
|
+
* @returns The full agent response containing both reply and instructions
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```ts
|
|
17
|
+
* const ui = ctx.describe()
|
|
18
|
+
* const response = await plan(ui, "click save button", config)
|
|
19
|
+
* for (const instruction of response.instructions || []) {
|
|
20
|
+
* ctx.act(instruction)
|
|
21
|
+
* }
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
declare function plan(ui: Ai11yContext, input: string, config?: AgentAdapterConfig, messages?: ConversationMessage[]): Promise<AgentResponse>;
|
|
25
|
+
//#endregion
|
|
26
|
+
export { plan };
|
|
27
|
+
//# sourceMappingURL=plan.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plan.d.mts","names":[],"sources":["../../src/agent/plan.ts"],"sourcesContent":[],"mappings":";;;;;;;AA0BA;;;;;;;;;;;;;;;;iBAAsB,IAAA,KACjB,sCAEK,+BACE,wBACT,QAAQ"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { runAgentAdapter } from "./agent-adapter.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/agent/plan.ts
|
|
4
|
+
/**
|
|
5
|
+
* Plans instructions based on UI context and user input
|
|
6
|
+
*
|
|
7
|
+
* @param ui - The current UI context
|
|
8
|
+
* @param input - User input/command
|
|
9
|
+
* @param config - Optional agent configuration
|
|
10
|
+
* @param messages - Optional conversation history
|
|
11
|
+
* @returns The full agent response containing both reply and instructions
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```ts
|
|
15
|
+
* const ui = ctx.describe()
|
|
16
|
+
* const response = await plan(ui, "click save button", config)
|
|
17
|
+
* for (const instruction of response.instructions || []) {
|
|
18
|
+
* ctx.act(instruction)
|
|
19
|
+
* }
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
async function plan(ui, input, config, messages) {
|
|
23
|
+
return await runAgentAdapter(input, ui, config, messages);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
//#endregion
|
|
27
|
+
export { plan };
|
|
28
|
+
//# sourceMappingURL=plan.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plan.mjs","names":[],"sources":["../../src/agent/plan.ts"],"sourcesContent":["import type { Ai11yContext } from \"../context.js\";\nimport { runAgentAdapter } from \"./agent-adapter.js\";\nimport type {\n\tAgentAdapterConfig,\n\tAgentResponse,\n\tConversationMessage,\n} from \"./types.js\";\n\n/**\n * Plans instructions based on UI context and user input\n *\n * @param ui - The current UI context\n * @param input - User input/command\n * @param config - Optional agent configuration\n * @param messages - Optional conversation history\n * @returns The full agent response containing both reply and instructions\n *\n * @example\n * ```ts\n * const ui = ctx.describe()\n * const response = await plan(ui, \"click save button\", config)\n * for (const instruction of response.instructions || []) {\n * ctx.act(instruction)\n * }\n * ```\n */\nexport async function plan(\n\tui: Ai11yContext,\n\tinput: string,\n\tconfig?: AgentAdapterConfig,\n\tmessages?: ConversationMessage[],\n): Promise<AgentResponse> {\n\tconst response: AgentResponse = await runAgentAdapter(\n\t\tinput,\n\t\tui,\n\t\tconfig,\n\t\tmessages,\n\t);\n\n\treturn response;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AA0BA,eAAsB,KACrB,IACA,OACA,QACA,UACyB;AAQzB,QAPgC,MAAM,gBACrC,OACA,IACA,QACA,SACA"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Ai11yContext } from "../context.mjs";
|
|
2
|
+
import { AgentResponse } from "./types.mjs";
|
|
3
|
+
|
|
4
|
+
//#region src/agent/rule-based-agent.d.ts
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Rule-based agent that uses pattern matching for common commands.
|
|
8
|
+
* Provides immediate responses without requiring an LLM.
|
|
9
|
+
*/
|
|
10
|
+
declare function runRuleBasedAgent(input: string, context: Ai11yContext): AgentResponse;
|
|
11
|
+
//#endregion
|
|
12
|
+
export { runRuleBasedAgent };
|
|
13
|
+
//# sourceMappingURL=rule-based-agent.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rule-based-agent.d.mts","names":[],"sources":["../../src/agent/rule-based-agent.ts"],"sourcesContent":[],"mappings":";;;;;;;AAQA;;iBAAgB,iBAAA,yBAEN,eACP"}
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
//#region src/agent/rule-based-agent.ts
|
|
2
|
+
/**
|
|
3
|
+
* Rule-based agent that uses pattern matching for common commands.
|
|
4
|
+
* Provides immediate responses without requiring an LLM.
|
|
5
|
+
*/
|
|
6
|
+
function runRuleBasedAgent(input, context) {
|
|
7
|
+
const lowerInput = input.toLowerCase().trim();
|
|
8
|
+
if (lowerInput.includes("go to") || lowerInput.includes("navigate to") || lowerInput.includes("open") || lowerInput.includes("take me to")) {
|
|
9
|
+
const searchText = lowerInput.replace(/go to|navigate to|open|take me to/g, "").trim();
|
|
10
|
+
const matchingMarker = context.markers.find((m) => {
|
|
11
|
+
return `${m.label} ${m.intent}`.toLowerCase().includes(searchText) || lowerInput.includes(m.label.toLowerCase()) || lowerInput.includes(m.intent.toLowerCase());
|
|
12
|
+
});
|
|
13
|
+
if (matchingMarker) {
|
|
14
|
+
const isInView = context.inViewMarkerIds?.includes(matchingMarker.id) ?? false;
|
|
15
|
+
const isLink = matchingMarker.elementType === "a";
|
|
16
|
+
if (isLink && isInView) return {
|
|
17
|
+
reply: `Navigating to ${matchingMarker.label}...`,
|
|
18
|
+
instructions: [{
|
|
19
|
+
action: "click",
|
|
20
|
+
id: matchingMarker.id
|
|
21
|
+
}]
|
|
22
|
+
};
|
|
23
|
+
if (isLink && !isInView) return {
|
|
24
|
+
reply: `Scrolling to ${matchingMarker.label}...`,
|
|
25
|
+
instructions: [{
|
|
26
|
+
action: "scroll",
|
|
27
|
+
id: matchingMarker.id
|
|
28
|
+
}]
|
|
29
|
+
};
|
|
30
|
+
return {
|
|
31
|
+
reply: `Scrolling to ${matchingMarker.label}...`,
|
|
32
|
+
instructions: [{
|
|
33
|
+
action: "scroll",
|
|
34
|
+
id: matchingMarker.id
|
|
35
|
+
}]
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
const instructions = [];
|
|
39
|
+
let route = "/";
|
|
40
|
+
if (lowerInput.includes("billing")) route = "/billing";
|
|
41
|
+
else if (lowerInput.includes("integrations")) route = "/integrations";
|
|
42
|
+
else if (lowerInput.includes("home")) route = "/";
|
|
43
|
+
if (route !== context.route) {
|
|
44
|
+
instructions.push({
|
|
45
|
+
action: "navigate",
|
|
46
|
+
route
|
|
47
|
+
});
|
|
48
|
+
return {
|
|
49
|
+
reply: `Navigating to ${route === "/" ? "home" : route}...`,
|
|
50
|
+
instructions
|
|
51
|
+
};
|
|
52
|
+
} else return { reply: `You're already on ${route === "/" ? "home" : route}.` };
|
|
53
|
+
}
|
|
54
|
+
if (lowerInput.includes("click") || lowerInput.includes("press")) {
|
|
55
|
+
const matchingMarker = context.markers.find((m) => {
|
|
56
|
+
return `${m.label} ${m.intent}`.toLowerCase().includes(lowerInput.replace(/click|press/g, "").trim()) || lowerInput.includes(m.label.toLowerCase()) || lowerInput.includes(m.intent.toLowerCase());
|
|
57
|
+
});
|
|
58
|
+
if (matchingMarker) return {
|
|
59
|
+
reply: `Clicking ${matchingMarker.label}...`,
|
|
60
|
+
instructions: [{
|
|
61
|
+
action: "click",
|
|
62
|
+
id: matchingMarker.id
|
|
63
|
+
}]
|
|
64
|
+
};
|
|
65
|
+
else return { reply: `I couldn't find a button or element matching "${input}". Available options: ${context.markers.map((m) => m.label).join(", ") || "none"}` };
|
|
66
|
+
}
|
|
67
|
+
if (lowerInput.includes("scroll to") || lowerInput.includes("scroll") || lowerInput.includes("show me")) {
|
|
68
|
+
const matchingMarker = context.markers.find((m) => {
|
|
69
|
+
const markerText = `${m.label} ${m.intent}`.toLowerCase();
|
|
70
|
+
const searchText = lowerInput.replace(/scroll to|scroll|show me/g, "").trim();
|
|
71
|
+
return markerText.includes(searchText) || lowerInput.includes(m.label.toLowerCase());
|
|
72
|
+
});
|
|
73
|
+
if (matchingMarker) {
|
|
74
|
+
if (lowerInput.includes("scroll")) return {
|
|
75
|
+
reply: `Scrolling to ${matchingMarker.label}...`,
|
|
76
|
+
instructions: [{
|
|
77
|
+
action: "scroll",
|
|
78
|
+
id: matchingMarker.id
|
|
79
|
+
}]
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
if (lowerInput.includes("highlight") || lowerInput.includes("show")) {
|
|
84
|
+
const matchingMarker = context.markers.find((m) => {
|
|
85
|
+
return `${m.label} ${m.intent}`.toLowerCase().includes(lowerInput.replace(/highlight|show/g, "").trim()) || lowerInput.includes(m.label.toLowerCase());
|
|
86
|
+
});
|
|
87
|
+
if (matchingMarker) return {
|
|
88
|
+
reply: `Highlighting ${matchingMarker.label}...`,
|
|
89
|
+
instructions: [{
|
|
90
|
+
action: "highlight",
|
|
91
|
+
id: matchingMarker.id
|
|
92
|
+
}]
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
if (lowerInput.includes("fill") || lowerInput.includes("enter") || lowerInput.includes("type") || lowerInput.includes("put")) {
|
|
96
|
+
let value;
|
|
97
|
+
let markerSearchText = lowerInput;
|
|
98
|
+
const fillWithMatch = lowerInput.match(/(?:fill|enter|type|put)\s+(.+?)\s+(?:with|in|into)\s+(.+)/i);
|
|
99
|
+
if (fillWithMatch) {
|
|
100
|
+
markerSearchText = fillWithMatch[1].trim();
|
|
101
|
+
value = fillWithMatch[2].trim();
|
|
102
|
+
} else {
|
|
103
|
+
const fillInMatch = lowerInput.match(/(?:fill|enter|type|put)\s+(.+?)\s+in\s+(.+)/i);
|
|
104
|
+
if (fillInMatch) {
|
|
105
|
+
value = fillInMatch[1].trim();
|
|
106
|
+
markerSearchText = fillInMatch[2].trim();
|
|
107
|
+
} else {
|
|
108
|
+
const inMatch = lowerInput.match(/(.+?)\s+in\s+(.+)/i);
|
|
109
|
+
if (inMatch) {
|
|
110
|
+
value = inMatch[1].trim();
|
|
111
|
+
markerSearchText = inMatch[2].trim();
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
const matchingMarker = context.markers.find((m) => {
|
|
116
|
+
const markerText = `${m.label} ${m.intent}`.toLowerCase();
|
|
117
|
+
const cleanedMarkerSearch = markerSearchText.replace(/fill|enter|type|put|input|field/g, "").trim();
|
|
118
|
+
return markerText.includes(cleanedMarkerSearch) || cleanedMarkerSearch.includes(m.label.toLowerCase()) || cleanedMarkerSearch.includes(m.id.toLowerCase());
|
|
119
|
+
});
|
|
120
|
+
if (matchingMarker && value) return {
|
|
121
|
+
reply: `Filling ${matchingMarker.label} with "${value}"...`,
|
|
122
|
+
instructions: [{
|
|
123
|
+
action: "fillInput",
|
|
124
|
+
id: matchingMarker.id,
|
|
125
|
+
value
|
|
126
|
+
}]
|
|
127
|
+
};
|
|
128
|
+
else if (matchingMarker && !value) return { reply: `I found ${matchingMarker.label}, but I need a value to fill. Please specify what to enter, for example: "fill ${matchingMarker.label.toLowerCase()} with [value]"` };
|
|
129
|
+
}
|
|
130
|
+
if (context.error) {
|
|
131
|
+
const errorMessage = context.error.error.message || "An error occurred";
|
|
132
|
+
if (lowerInput.includes("retry") || lowerInput.includes("try again") || lowerInput.includes("fix")) {
|
|
133
|
+
if (context.error.meta?.markerId) {
|
|
134
|
+
const marker = context.markers.find((m) => m.id === context.error?.meta?.markerId);
|
|
135
|
+
if (marker) return {
|
|
136
|
+
reply: `Retrying ${marker.label}...`,
|
|
137
|
+
instructions: [{
|
|
138
|
+
action: "click",
|
|
139
|
+
id: marker.id
|
|
140
|
+
}]
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
return { reply: `I can help you retry. The error was: ${errorMessage}. Would you like me to try clicking the button again?` };
|
|
144
|
+
}
|
|
145
|
+
return { reply: `I noticed an error: ${errorMessage}. You can ask me to "retry" or "try again" to attempt the action once more.` };
|
|
146
|
+
}
|
|
147
|
+
return { reply: `I can help you navigate, click buttons, highlight elements, or fill inputs. Try saying "go to billing", "click connect stripe", "show me the enable billing button", or "fill email with test@example.com".` };
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
//#endregion
|
|
151
|
+
export { runRuleBasedAgent };
|
|
152
|
+
//# sourceMappingURL=rule-based-agent.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rule-based-agent.mjs","names":["instructions: Instruction[]","value: string | undefined"],"sources":["../../src/agent/rule-based-agent.ts"],"sourcesContent":["import type { Ai11yContext } from \"../context.js\";\nimport type { Instruction } from \"../instruction.js\";\nimport type { AgentResponse } from \"./types.js\";\n\n/**\n * Rule-based agent that uses pattern matching for common commands.\n * Provides immediate responses without requiring an LLM.\n */\nexport function runRuleBasedAgent(\n\tinput: string,\n\tcontext: Ai11yContext,\n): AgentResponse {\n\tconst lowerInput = input.toLowerCase().trim();\n\n\t// Handle navigation commands\n\tif (\n\t\tlowerInput.includes(\"go to\") ||\n\t\tlowerInput.includes(\"navigate to\") ||\n\t\tlowerInput.includes(\"open\") ||\n\t\tlowerInput.includes(\"take me to\")\n\t) {\n\t\t// First, check if input matches any marker\n\t\tconst searchText = lowerInput\n\t\t\t.replace(/go to|navigate to|open|take me to/g, \"\")\n\t\t\t.trim();\n\t\tconst matchingMarker = context.markers.find((m) => {\n\t\t\tconst markerText = `${m.label} ${m.intent}`.toLowerCase();\n\t\t\treturn (\n\t\t\t\tmarkerText.includes(searchText) ||\n\t\t\t\tlowerInput.includes(m.label.toLowerCase()) ||\n\t\t\t\tlowerInput.includes(m.intent.toLowerCase())\n\t\t\t);\n\t\t});\n\n\t\t// If a marker matches, decide based on element type and visibility\n\t\tif (matchingMarker) {\n\t\t\tconst isInView =\n\t\t\t\tcontext.inViewMarkerIds?.includes(matchingMarker.id) ?? false;\n\t\t\tconst isLink = matchingMarker.elementType === \"a\";\n\n\t\t\t// If it's a link marker and in view, click it (navigate)\n\t\t\tif (isLink && isInView) {\n\t\t\t\treturn {\n\t\t\t\t\treply: `Navigating to ${matchingMarker.label}...`,\n\t\t\t\t\tinstructions: [{ action: \"click\", id: matchingMarker.id }],\n\t\t\t\t};\n\t\t\t}\n\n\t\t\t// If it's a link marker but not in view, scroll to it first\n\t\t\tif (isLink && !isInView) {\n\t\t\t\treturn {\n\t\t\t\t\treply: `Scrolling to ${matchingMarker.label}...`,\n\t\t\t\t\tinstructions: [{ action: \"scroll\", id: matchingMarker.id }],\n\t\t\t\t};\n\t\t\t}\n\n\t\t\t// For non-link markers (sections, divs), scroll to them\n\t\t\treturn {\n\t\t\t\treply: `Scrolling to ${matchingMarker.label}...`,\n\t\t\t\tinstructions: [{ action: \"scroll\", id: matchingMarker.id }],\n\t\t\t};\n\t\t}\n\n\t\t// No marker found, proceed with route navigation\n\t\tconst instructions: Instruction[] = [];\n\n\t\t// Extract route from input\n\t\tlet route = \"/\";\n\t\tif (lowerInput.includes(\"billing\")) {\n\t\t\troute = \"/billing\";\n\t\t} else if (lowerInput.includes(\"integrations\")) {\n\t\t\troute = \"/integrations\";\n\t\t} else if (lowerInput.includes(\"home\")) {\n\t\t\troute = \"/\";\n\t\t}\n\n\t\tif (route !== context.route) {\n\t\t\tinstructions.push({ action: \"navigate\", route });\n\t\t\treturn {\n\t\t\t\treply: `Navigating to ${route === \"/\" ? \"home\" : route}...`,\n\t\t\t\tinstructions,\n\t\t\t};\n\t\t} else {\n\t\t\treturn {\n\t\t\t\treply: `You're already on ${route === \"/\" ? \"home\" : route}.`,\n\t\t\t};\n\t\t}\n\t}\n\n\t// Handle click commands\n\tif (lowerInput.includes(\"click\") || lowerInput.includes(\"press\")) {\n\t\t// Find matching marker\n\t\tconst matchingMarker = context.markers.find((m) => {\n\t\t\tconst markerText = `${m.label} ${m.intent}`.toLowerCase();\n\t\t\treturn (\n\t\t\t\tmarkerText.includes(lowerInput.replace(/click|press/g, \"\").trim()) ||\n\t\t\t\tlowerInput.includes(m.label.toLowerCase()) ||\n\t\t\t\tlowerInput.includes(m.intent.toLowerCase())\n\t\t\t);\n\t\t});\n\n\t\tif (matchingMarker) {\n\t\t\treturn {\n\t\t\t\treply: `Clicking ${matchingMarker.label}...`,\n\t\t\t\tinstructions: [{ action: \"click\", id: matchingMarker.id }],\n\t\t\t};\n\t\t} else {\n\t\t\treturn {\n\t\t\t\treply: `I couldn't find a button or element matching \"${input}\". Available options: ${context.markers.map((m) => m.label).join(\", \") || \"none\"}`,\n\t\t\t};\n\t\t}\n\t}\n\n\t// Handle scroll commands (scroll to element)\n\tif (\n\t\tlowerInput.includes(\"scroll to\") ||\n\t\tlowerInput.includes(\"scroll\") ||\n\t\tlowerInput.includes(\"show me\")\n\t) {\n\t\tconst matchingMarker = context.markers.find((m) => {\n\t\t\tconst markerText = `${m.label} ${m.intent}`.toLowerCase();\n\t\t\tconst searchText = lowerInput\n\t\t\t\t.replace(/scroll to|scroll|show me/g, \"\")\n\t\t\t\t.trim();\n\t\t\treturn (\n\t\t\t\tmarkerText.includes(searchText) ||\n\t\t\t\tlowerInput.includes(m.label.toLowerCase())\n\t\t\t);\n\t\t});\n\n\t\tif (matchingMarker) {\n\t\t\t// If user explicitly wants to scroll, use scroll tool\n\t\t\t// Otherwise, if they say \"show me\" or \"highlight\", use highlight (which now scrolls)\n\t\t\tif (lowerInput.includes(\"scroll\")) {\n\t\t\t\treturn {\n\t\t\t\t\treply: `Scrolling to ${matchingMarker.label}...`,\n\t\t\t\t\tinstructions: [{ action: \"scroll\", id: matchingMarker.id }],\n\t\t\t\t};\n\t\t\t}\n\t\t}\n\t}\n\n\t// Handle highlight commands\n\tif (lowerInput.includes(\"highlight\") || lowerInput.includes(\"show\")) {\n\t\tconst matchingMarker = context.markers.find((m) => {\n\t\t\tconst markerText = `${m.label} ${m.intent}`.toLowerCase();\n\t\t\treturn (\n\t\t\t\tmarkerText.includes(lowerInput.replace(/highlight|show/g, \"\").trim()) ||\n\t\t\t\tlowerInput.includes(m.label.toLowerCase())\n\t\t\t);\n\t\t});\n\n\t\tif (matchingMarker) {\n\t\t\treturn {\n\t\t\t\treply: `Highlighting ${matchingMarker.label}...`,\n\t\t\t\tinstructions: [{ action: \"highlight\", id: matchingMarker.id }],\n\t\t\t};\n\t\t}\n\t}\n\n\t// Handle fill input commands\n\tif (\n\t\tlowerInput.includes(\"fill\") ||\n\t\tlowerInput.includes(\"enter\") ||\n\t\tlowerInput.includes(\"type\") ||\n\t\tlowerInput.includes(\"put\")\n\t) {\n\t\t// Try to extract value from commands like:\n\t\t// \"fill email with test@example.com\"\n\t\t// \"enter test@example.com in email\"\n\t\t// \"type test@example.com in email input\"\n\t\t// \"put test@example.com in email\"\n\t\tlet value: string | undefined;\n\t\tlet markerSearchText = lowerInput;\n\n\t\t// Pattern: \"fill [marker] with [value]\" or \"fill [marker] [value]\"\n\t\tconst fillWithMatch = lowerInput.match(\n\t\t\t/(?:fill|enter|type|put)\\s+(.+?)\\s+(?:with|in|into)\\s+(.+)/i,\n\t\t);\n\t\tif (fillWithMatch) {\n\t\t\tmarkerSearchText = fillWithMatch[1].trim();\n\t\t\tvalue = fillWithMatch[2].trim();\n\t\t} else {\n\t\t\t// Pattern: \"fill [value] in [marker]\" or \"enter [value] in [marker]\"\n\t\t\tconst fillInMatch = lowerInput.match(\n\t\t\t\t/(?:fill|enter|type|put)\\s+(.+?)\\s+in\\s+(.+)/i,\n\t\t\t);\n\t\t\tif (fillInMatch) {\n\t\t\t\tvalue = fillInMatch[1].trim();\n\t\t\t\tmarkerSearchText = fillInMatch[2].trim();\n\t\t\t} else {\n\t\t\t\t// Pattern: \"[value] in [marker]\"\n\t\t\t\tconst inMatch = lowerInput.match(/(.+?)\\s+in\\s+(.+)/i);\n\t\t\t\tif (inMatch) {\n\t\t\t\t\tvalue = inMatch[1].trim();\n\t\t\t\t\tmarkerSearchText = inMatch[2].trim();\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// Find matching marker (look for input-like elements)\n\t\tconst matchingMarker = context.markers.find((m) => {\n\t\t\tconst markerText = `${m.label} ${m.intent}`.toLowerCase();\n\t\t\tconst cleanedMarkerSearch = markerSearchText\n\t\t\t\t.replace(/fill|enter|type|put|input|field/g, \"\")\n\t\t\t\t.trim();\n\t\t\treturn (\n\t\t\t\tmarkerText.includes(cleanedMarkerSearch) ||\n\t\t\t\tcleanedMarkerSearch.includes(m.label.toLowerCase()) ||\n\t\t\t\tcleanedMarkerSearch.includes(m.id.toLowerCase())\n\t\t\t);\n\t\t});\n\n\t\tif (matchingMarker && value) {\n\t\t\treturn {\n\t\t\t\treply: `Filling ${matchingMarker.label} with \"${value}\"...`,\n\t\t\t\tinstructions: [\n\t\t\t\t\t{\n\t\t\t\t\t\taction: \"fillInput\",\n\t\t\t\t\t\tid: matchingMarker.id,\n\t\t\t\t\t\tvalue: value,\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t};\n\t\t} else if (matchingMarker && !value) {\n\t\t\treturn {\n\t\t\t\treply: `I found ${matchingMarker.label}, but I need a value to fill. Please specify what to enter, for example: \"fill ${matchingMarker.label.toLowerCase()} with [value]\"`,\n\t\t\t};\n\t\t}\n\t}\n\n\t// Handle error context\n\tif (context.error) {\n\t\tconst error = context.error.error;\n\t\tconst errorMessage = error.message || \"An error occurred\";\n\n\t\tif (\n\t\t\tlowerInput.includes(\"retry\") ||\n\t\t\tlowerInput.includes(\"try again\") ||\n\t\t\tlowerInput.includes(\"fix\")\n\t\t) {\n\t\t\t// Try to find a retry action\n\t\t\tif (context.error.meta?.markerId) {\n\t\t\t\tconst marker = context.markers.find(\n\t\t\t\t\t(m) => m.id === context.error?.meta?.markerId,\n\t\t\t\t);\n\t\t\t\tif (marker) {\n\t\t\t\t\treturn {\n\t\t\t\t\t\treply: `Retrying ${marker.label}...`,\n\t\t\t\t\t\tinstructions: [{ action: \"click\", id: marker.id }],\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\treply: `I can help you retry. The error was: ${errorMessage}. Would you like me to try clicking the button again?`,\n\t\t\t};\n\t\t}\n\n\t\treturn {\n\t\t\treply: `I noticed an error: ${errorMessage}. You can ask me to \"retry\" or \"try again\" to attempt the action once more.`,\n\t\t};\n\t}\n\n\t// Default response\n\treturn {\n\t\treply: `I can help you navigate, click buttons, highlight elements, or fill inputs. Try saying \"go to billing\", \"click connect stripe\", \"show me the enable billing button\", or \"fill email with test@example.com\".`,\n\t};\n}\n"],"mappings":"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"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Ai11yContext } from "../context.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/agent/tool-contract.d.ts
|
|
4
|
+
interface ToolDefinition {
|
|
5
|
+
name: string;
|
|
6
|
+
description: string;
|
|
7
|
+
parameters: {
|
|
8
|
+
type: "object";
|
|
9
|
+
properties: Record<string, {
|
|
10
|
+
type: string;
|
|
11
|
+
description: string;
|
|
12
|
+
}>;
|
|
13
|
+
required?: string[];
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
type ToolExecutor = (args: Record<string, unknown>, context: Ai11yContext) => Promise<unknown> | unknown;
|
|
17
|
+
//#endregion
|
|
18
|
+
export { ToolDefinition, ToolExecutor };
|
|
19
|
+
//# sourceMappingURL=tool-contract.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool-contract.d.mts","names":[],"sources":["../../src/agent/tool-contract.ts"],"sourcesContent":[],"mappings":";;;UAEiB,cAAA;;EAAA,WAAA,EAAA,MAAc;EAgBnB,UAAA,EAAA;IACL,IAAA,EAAA,QAAA;IACG,UAAA,EAbI,MAaJ,CAAA,MAAA,EAAA;MACL,IAAA,EAAA,MAAA;MAAO,WAAA,EAAA,MAAA;;;;;KAHA,YAAA,UACL,kCACG,iBACL"}
|