@mobileaidev/ai-app-bridge 0.2.15 → 0.3.0-rc.2

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 (156) hide show
  1. package/LICENSE +201 -0
  2. package/NOTICE +7 -0
  3. package/README.md +306 -53
  4. package/bin/ai-app-bridge.js +51 -4504
  5. package/bin/android-permissions.js +152 -0
  6. package/bin/android-uia-xml.js +74 -0
  7. package/bin/artifact-paths.js +127 -1
  8. package/bin/bridge-forward.js +56 -0
  9. package/bin/command-discovery.js +86 -0
  10. package/bin/command-errors.js +60 -0
  11. package/bin/command-registry.js +504 -0
  12. package/bin/command-request.js +14 -0
  13. package/bin/command-router.js +80 -0
  14. package/bin/connection-cache.js +119 -0
  15. package/bin/device-provider.js +2934 -0
  16. package/bin/execution-host.js +596 -0
  17. package/bin/execution-runtime.js +101 -0
  18. package/bin/fact-codec.js +321 -0
  19. package/bin/fact-recorder.js +691 -0
  20. package/bin/fact-store.js +226 -0
  21. package/bin/feedback-probe.js +285 -0
  22. package/bin/intent/install-intent.js +267 -0
  23. package/bin/intent/intent-action-executor.js +129 -0
  24. package/bin/intent/intent-autonomous-adapter.js +46 -0
  25. package/bin/intent/intent-capture-port.js +64 -0
  26. package/bin/intent/intent-entry.js +226 -0
  27. package/bin/intent/intent-errors.js +28 -0
  28. package/bin/intent/intent-evidence-store.js +121 -0
  29. package/bin/intent/intent-lifetime.js +62 -0
  30. package/bin/intent/intent-observation-target.js +33 -0
  31. package/bin/intent/intent-observer.js +194 -0
  32. package/bin/intent/intent-production-adapter.js +334 -0
  33. package/bin/intent/intent-provider.js +27 -0
  34. package/bin/intent/intent-runtime.js +63 -0
  35. package/bin/intent/intent-worker.js +432 -0
  36. package/bin/intent/ios-intent-adapter.js +90 -0
  37. package/bin/intent/permission-intent.js +239 -0
  38. package/bin/intent/web-intent-adapter.js +31 -0
  39. package/bin/ios-device-outcome.js +47 -0
  40. package/bin/ios-execution.js +108 -0
  41. package/bin/ios-provider.js +497 -583
  42. package/bin/ios-runtime-binding.js +54 -0
  43. package/bin/ios-wda-execution.js +70 -0
  44. package/bin/ios-wda-port.js +98 -0
  45. package/bin/ios-wda-project.js +79 -0
  46. package/bin/mcp-server.js +83 -1040
  47. package/bin/mmap-scan-index.js +329 -0
  48. package/bin/observation-collector.js +862 -0
  49. package/bin/runtime-client.js +154 -0
  50. package/bin/runtime-directory.js +107 -0
  51. package/bin/runtime-protocol.js +36 -0
  52. package/bin/script/bounded-script-registry.js +103 -0
  53. package/bin/script/node-runtime-adapter.js +233 -0
  54. package/bin/script/progress-projector.js +63 -0
  55. package/bin/script/python-runtime-adapter.js +111 -0
  56. package/bin/script/rolling-summary.js +134 -0
  57. package/bin/script/script-agent-port.js +40 -0
  58. package/bin/script/script-assert.js +95 -0
  59. package/bin/script/script-capture-port.js +76 -0
  60. package/bin/script/script-catalog.js +85 -0
  61. package/bin/script/script-durable-restore.js +195 -0
  62. package/bin/script/script-entry-code.js +26 -0
  63. package/bin/script/script-entry-route.js +38 -0
  64. package/bin/script/script-entry.js +3 -0
  65. package/bin/script/script-errors.js +29 -0
  66. package/bin/script/script-evidence-store.js +22 -0
  67. package/bin/script/script-format-removed.js +26 -0
  68. package/bin/script/script-host-port.js +397 -0
  69. package/bin/script/script-ledger.js +64 -0
  70. package/bin/script/script-result.js +57 -0
  71. package/bin/script/script-sdk.js +152 -0
  72. package/bin/script/script-sdk.py +153 -0
  73. package/bin/script/script-session-channel.js +127 -0
  74. package/bin/script/script-spec.js +86 -0
  75. package/bin/script/script-supervisor.js +919 -0
  76. package/bin/script/templates/checkpoint-reentry.js +13 -0
  77. package/bin/segment-index.js +481 -0
  78. package/bin/segmented-fact-store.js +1571 -0
  79. package/bin/shared-kernel/android-h5-target.js +10 -0
  80. package/bin/shared-kernel/android-install-execution.js +176 -0
  81. package/bin/shared-kernel/android-sdk-endpoint.js +42 -0
  82. package/bin/shared-kernel/android-shell-execution.js +195 -0
  83. package/bin/shared-kernel/argument-schema.js +117 -0
  84. package/bin/shared-kernel/canonical-path.js +17 -0
  85. package/bin/shared-kernel/device-acknowledgements.js +53 -0
  86. package/bin/shared-kernel/device-completion-history.js +52 -0
  87. package/bin/shared-kernel/device-mutation-lease.js +219 -0
  88. package/bin/shared-kernel/device-ownership-recovery.js +95 -0
  89. package/bin/shared-kernel/device-ownership-store.js +94 -0
  90. package/bin/shared-kernel/evidence-adapters.js +251 -0
  91. package/bin/shared-kernel/evidence-archive.js +329 -0
  92. package/bin/shared-kernel/evidence-recording.js +131 -0
  93. package/bin/shared-kernel/evidence-schema.js +194 -0
  94. package/bin/shared-kernel/evidence-store.js +190 -0
  95. package/bin/shared-kernel/execution-admission.js +22 -0
  96. package/bin/shared-kernel/execution-contracts.js +171 -0
  97. package/bin/shared-kernel/execution-io.js +106 -0
  98. package/bin/shared-kernel/execution-ledger.js +125 -0
  99. package/bin/shared-kernel/execution-scope.js +87 -0
  100. package/bin/shared-kernel/execution-target.js +115 -0
  101. package/bin/shared-kernel/flutter-execution.js +13 -0
  102. package/bin/shared-kernel/flutter-h5-port.js +60 -0
  103. package/bin/shared-kernel/flutter-h5-target.js +9 -0
  104. package/bin/shared-kernel/flutter-target.js +75 -0
  105. package/bin/shared-kernel/h5-execution.js +11 -0
  106. package/bin/shared-kernel/h5-target.js +31 -0
  107. package/bin/shared-kernel/host-fact-store.js +49 -0
  108. package/bin/shared-kernel/ios-h5-target.js +9 -0
  109. package/bin/shared-kernel/ios-native-target.js +71 -0
  110. package/bin/shared-kernel/live-capture-query.js +115 -0
  111. package/bin/shared-kernel/managed-sdk-execution.js +78 -0
  112. package/bin/shared-kernel/native-execution.js +13 -0
  113. package/bin/shared-kernel/native-target.js +156 -0
  114. package/bin/shared-kernel/provider-command-contracts.js +55 -0
  115. package/bin/shared-kernel/recorded-payload-archive.js +195 -0
  116. package/bin/shared-kernel/request-context.js +35 -0
  117. package/bin/shared-kernel/semantic-node.js +55 -0
  118. package/bin/shared-kernel/summary-transformer.js +352 -0
  119. package/bin/shared-kernel/target-lease-protocol.js +47 -0
  120. package/bin/shared-kernel/text-wait.js +111 -0
  121. package/bin/shared-kernel/uia-execution.js +96 -0
  122. package/bin/shared-kernel/uia-protocol.js +214 -0
  123. package/bin/shared-kernel/uia-runtime-port.js +377 -0
  124. package/bin/shared-kernel/uia-target.js +39 -0
  125. package/bin/shared-kernel/web-dom-target.js +44 -0
  126. package/bin/shared-kernel/xml-attributes.js +25 -0
  127. package/bin/target-execution.js +275 -0
  128. package/bin/web/command-schema.js +60 -0
  129. package/bin/web/session-store.js +157 -0
  130. package/bin/web-provider.js +334 -553
  131. package/docs/COMMAND_CONTRACT.md +1563 -0
  132. package/docs/EVIDENCE_ARCHIVE.md +214 -0
  133. package/docs/INTENT_FOREGROUND.md +71 -0
  134. package/docs/INTENT_NATIVE_EDITING.md +79 -0
  135. package/docs/RELEASE.md +59 -0
  136. package/docs/SCRIPT_AUTHORING.md +489 -0
  137. package/node_modules/@mobileaidev/segmented-fact-store-native/LICENSE +201 -0
  138. package/node_modules/@mobileaidev/segmented-fact-store-native/NOTICE +7 -0
  139. package/node_modules/@mobileaidev/segmented-fact-store-native/binding.gyp +36 -0
  140. package/node_modules/@mobileaidev/segmented-fact-store-native/bindings/node/sfs_node.c +597 -0
  141. package/node_modules/@mobileaidev/segmented-fact-store-native/include/sfs.h +178 -0
  142. package/node_modules/@mobileaidev/segmented-fact-store-native/index.js +5 -0
  143. package/node_modules/@mobileaidev/segmented-fact-store-native/package.json +24 -0
  144. package/node_modules/@mobileaidev/segmented-fact-store-native/src/sfs.c +2349 -0
  145. package/package.json +60 -5
  146. package/runtime/ios-wda/AABWDABinding.h +19 -0
  147. package/runtime/ios-wda/AABWDABinding.m +97 -0
  148. package/runtime/ios-wda/AABWDAExecution.h +26 -0
  149. package/runtime/ios-wda/AABWDAExecution.m +172 -0
  150. package/runtime/ios-wda/AABWDAIntegration.h +71 -0
  151. package/runtime/ios-wda/AABWDAManagedRoutes.h +392 -0
  152. package/runtime/ios-wda/AABWDAReceiptStore.h +10 -0
  153. package/runtime/ios-wda/AABWDAReceiptStore.m +116 -0
  154. package/runtime/uia/ai-app-bridge-uia.jar +0 -0
  155. package/runtime/uia/manifest.json +22 -0
  156. package/skills/ai-app-bridge-use/SKILL.md +23 -360
@@ -0,0 +1,80 @@
1
+ 'use strict';
2
+
3
+ const { isolatedCommandDefinitions } = require('./command-registry');
4
+ const { commandFailure } = require('./command-errors');
5
+
6
+ function createCommandRouter({ loadScript, loadIntent, loadEvidence, dispatchCommon } = {}) {
7
+ if (typeof dispatchCommon !== 'function') {
8
+ throw new TypeError('dispatchCommon is required');
9
+ }
10
+ const loads = { script: 0, intent: 0, evidence: 0 };
11
+ return {
12
+ isolatedCommandDefinitions,
13
+ loads,
14
+ async route(command, args = {}, dependencies) {
15
+ if (command === 'script') {
16
+ return invokeIsolated('script', loadScript, args, loads);
17
+ }
18
+ if (command === 'intent') {
19
+ return invokeIsolated('intent', loadIntent, args, loads);
20
+ }
21
+ if (command === 'install-apk') {
22
+ return invokeIsolated('intent', loadIntent, { install: args, recordingDir: args.recordingDir }, loads);
23
+ }
24
+ if (command === 'permission-dialog') {
25
+ return invokeIsolated('intent', loadIntent, { permissionDialog: args, recordingDir: args.recordingDir }, loads);
26
+ }
27
+ if (command === 'evidence') {
28
+ return invokeIsolated('evidence', loadEvidence, args, loads);
29
+ }
30
+ return dispatchCommon(command, args, dependencies);
31
+ },
32
+ };
33
+ }
34
+
35
+ async function invokeIsolated(name, loader, args, loads) {
36
+ if (typeof loader !== 'function') {
37
+ return isolatedError(name, 'not_implemented');
38
+ }
39
+ loads[name] += 1;
40
+ let entry;
41
+ try {
42
+ entry = loader();
43
+ } catch (error) {
44
+ return isolatedError(name, 'isolated_module_unavailable', error.message || String(error));
45
+ }
46
+ if (!entry || typeof entry.handle !== 'function') {
47
+ return isolatedError(name, 'isolated_module_unavailable', 'entry handle is missing');
48
+ }
49
+ let handlePromise;
50
+ try {
51
+ handlePromise = Promise.resolve(entry.handle(args));
52
+ } catch (error) {
53
+ return { value: isolatedHandleError(name, error) };
54
+ }
55
+ // Stateful runtimes own cancellation and draining. An outer timer must not
56
+ // report a timeout while their work continues without supervision.
57
+ const result = await handlePromise.catch(error => isolatedHandleError(name, error));
58
+ return { value: result };
59
+ }
60
+
61
+ function isolatedHandleError(name, error) {
62
+ if (error?.code === 'sfs_busy') return { ok: false, error: 'fact_store_writer_busy', command: name, detail: error.message };
63
+ return commandFailure(error, name);
64
+ }
65
+
66
+ function isolatedError(command, error, detail) {
67
+ return {
68
+ value: {
69
+ ok: false,
70
+ error,
71
+ command,
72
+ ...(detail ? { detail } : {}),
73
+ },
74
+ };
75
+ }
76
+
77
+ module.exports = {
78
+ createCommandRouter,
79
+ isolatedCommandDefinitions,
80
+ };
@@ -0,0 +1,119 @@
1
+ 'use strict';
2
+
3
+ class ConnectionCache {
4
+ constructor({ ttlMs = 15_000, maxEntries = 256, now = Date.now } = {}) {
5
+ if (!Number.isFinite(ttlMs) || ttlMs < 0) {
6
+ throw new TypeError('ttlMs must be a non-negative number');
7
+ }
8
+ if (typeof now !== 'function') {
9
+ throw new TypeError('now must be a function');
10
+ }
11
+ if (!Number.isInteger(maxEntries) || maxEntries < 1) {
12
+ throw new TypeError('maxEntries must be a positive integer');
13
+ }
14
+ this.ttlMs = ttlMs;
15
+ this.maxEntries = maxEntries;
16
+ this.now = now;
17
+ this.entries = new Map();
18
+ this.inflight = new Map();
19
+ this.generations = new Map();
20
+ this.nextGeneration = 0;
21
+ }
22
+
23
+ async getOrCreate(key, create, { force = false } = {}) {
24
+ if (typeof key !== 'string' || key.length === 0) {
25
+ throw new TypeError('key is required');
26
+ }
27
+ if (typeof create !== 'function') {
28
+ throw new TypeError('create must be a function');
29
+ }
30
+
31
+ this.pruneEntries();
32
+ if (!force) {
33
+ const cached = this.entries.get(key);
34
+ if (cached && cached.expiresAtMs >= this.now()) {
35
+ this.entries.delete(key);
36
+ this.entries.set(key, cached);
37
+ return cached.value;
38
+ }
39
+ if (cached) this.entries.delete(key);
40
+ if (this.inflight.has(key)) return this.inflight.get(key);
41
+ } else {
42
+ this.entries.delete(key);
43
+ }
44
+
45
+ const generation = ++this.nextGeneration;
46
+ this.generations.set(key, generation);
47
+ const pending = Promise.resolve()
48
+ .then(create)
49
+ .then((value) => {
50
+ if (this.generations.get(key) === generation) {
51
+ this.entries.set(key, {
52
+ value,
53
+ expiresAtMs: this.now() + this.ttlMs,
54
+ });
55
+ this.pruneEntries();
56
+ }
57
+ return value;
58
+ })
59
+ .finally(() => {
60
+ if (this.inflight.get(key) === pending) {
61
+ this.inflight.delete(key);
62
+ }
63
+ if (
64
+ this.generations.get(key) === generation
65
+ && !this.inflight.has(key)
66
+ && !this.entries.has(key)
67
+ ) {
68
+ this.generations.delete(key);
69
+ }
70
+ });
71
+ this.inflight.set(key, pending);
72
+ return pending;
73
+ }
74
+
75
+ has(key) {
76
+ this.pruneEntries();
77
+ const cached = this.entries.get(key);
78
+ if (!cached) return false;
79
+ if (cached.expiresAtMs < this.now()) {
80
+ this.entries.delete(key);
81
+ if (!this.inflight.has(key)) this.generations.delete(key);
82
+ return false;
83
+ }
84
+ return true;
85
+ }
86
+
87
+ pruneEntries() {
88
+ const now = this.now();
89
+ for (const [key, entry] of this.entries) {
90
+ if (entry.expiresAtMs < now) {
91
+ this.entries.delete(key);
92
+ if (!this.inflight.has(key)) this.generations.delete(key);
93
+ }
94
+ }
95
+ while (this.entries.size > this.maxEntries) {
96
+ const oldestKey = this.entries.keys().next().value;
97
+ this.entries.delete(oldestKey);
98
+ if (!this.inflight.has(oldestKey)) this.generations.delete(oldestKey);
99
+ }
100
+ }
101
+
102
+ invalidate(key) {
103
+ this.generations.set(key, ++this.nextGeneration);
104
+ this.inflight.delete(key);
105
+ const deleted = this.entries.delete(key);
106
+ this.generations.delete(key);
107
+ return deleted;
108
+ }
109
+
110
+ clear() {
111
+ this.entries.clear();
112
+ this.inflight.clear();
113
+ this.generations.clear();
114
+ }
115
+ }
116
+
117
+ module.exports = {
118
+ ConnectionCache,
119
+ };