@mobileaidev/ai-app-bridge 0.2.2 → 0.2.3
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/bin/ai-app-bridge.js +49 -32
- package/package.json +1 -1
package/bin/ai-app-bridge.js
CHANGED
|
@@ -782,25 +782,41 @@ async function ensureForward(ctx) {
|
|
|
782
782
|
};
|
|
783
783
|
}
|
|
784
784
|
|
|
785
|
-
async function resolveDevicePort(ctx) {
|
|
786
|
-
if (ctx.explicitPort) return { port: ctx.port, source: 'explicit-port' };
|
|
787
|
-
try {
|
|
788
|
-
const result = await adb(ctx, ['shell', 'run-as', ctx.packageName, 'cat', 'files/ai_app_bridge_port.json']);
|
|
789
|
-
const state = JSON.parse(result.stdout.trim());
|
|
790
|
-
const discoveredPort = Number(state.port);
|
|
791
|
-
if (state.ok === true && Number.isInteger(discoveredPort) && discoveredPort > 0) {
|
|
792
|
-
return { port: discoveredPort, source: 'package-port-file', state };
|
|
793
|
-
}
|
|
794
|
-
} catch (error) {
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
}
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
785
|
+
async function resolveDevicePort(ctx) {
|
|
786
|
+
if (ctx.explicitPort) return { port: ctx.port, source: 'explicit-port' };
|
|
787
|
+
try {
|
|
788
|
+
const result = await adb(ctx, ['shell', 'run-as', ctx.packageName, 'cat', 'files/ai_app_bridge_port.json']);
|
|
789
|
+
const state = JSON.parse(result.stdout.trim());
|
|
790
|
+
const discoveredPort = Number(state.port);
|
|
791
|
+
if (state.ok === true && Number.isInteger(discoveredPort) && discoveredPort > 0) {
|
|
792
|
+
return { port: discoveredPort, source: 'package-port-file', state };
|
|
793
|
+
}
|
|
794
|
+
} catch (error) {
|
|
795
|
+
if (!shouldUseDefaultPortFallback(ctx)) {
|
|
796
|
+
ctx.devicePortSource = 'package-port-file';
|
|
797
|
+
ctx.devicePortError = firstErrorLine(error);
|
|
798
|
+
error.aiAppBridgePortDiscovery = true;
|
|
799
|
+
throw error;
|
|
800
|
+
}
|
|
801
|
+
return {
|
|
802
|
+
port: ctx.port,
|
|
803
|
+
source: 'default-port',
|
|
804
|
+
error: firstErrorLine(error),
|
|
805
|
+
};
|
|
806
|
+
}
|
|
807
|
+
if (!shouldUseDefaultPortFallback(ctx)) {
|
|
808
|
+
const error = new Error(`bridge port discovery failed for explicit package: ${ctx.packageName}`);
|
|
809
|
+
error.aiAppBridgePortDiscovery = true;
|
|
810
|
+
ctx.devicePortSource = 'package-port-file';
|
|
811
|
+
ctx.devicePortError = firstErrorLine(error);
|
|
812
|
+
throw error;
|
|
813
|
+
}
|
|
814
|
+
return { port: ctx.port, source: 'default-port' };
|
|
815
|
+
}
|
|
816
|
+
|
|
817
|
+
function shouldUseDefaultPortFallback(ctx) {
|
|
818
|
+
return !ctx.explicitPackageName;
|
|
819
|
+
}
|
|
804
820
|
|
|
805
821
|
async function bridgeStatus(ctx, options = {}) {
|
|
806
822
|
try {
|
|
@@ -953,17 +969,17 @@ function normalizeBridgeError(error) {
|
|
|
953
969
|
suggestion: 'Confirm the target app is running and that the resolved bridge port belongs to this package.',
|
|
954
970
|
};
|
|
955
971
|
}
|
|
956
|
-
if (lower.includes('adb timed out')) {
|
|
957
|
-
return {
|
|
958
|
-
code: 'adb_timeout',
|
|
959
|
-
message,
|
|
960
|
-
suggestion: 'Check the device state and retry; if the bridge port is known, pass --port to skip package port discovery.',
|
|
961
|
-
};
|
|
962
|
-
}
|
|
963
|
-
if (lower.includes('run-as') || lower.includes('package not found')) {
|
|
964
|
-
return {
|
|
965
|
-
code: 'bridge_port_discovery_failed',
|
|
966
|
-
message,
|
|
972
|
+
if (lower.includes('adb timed out')) {
|
|
973
|
+
return {
|
|
974
|
+
code: 'adb_timeout',
|
|
975
|
+
message,
|
|
976
|
+
suggestion: 'Check the device state and retry; if the bridge port is known, pass --port to skip package port discovery.',
|
|
977
|
+
};
|
|
978
|
+
}
|
|
979
|
+
if (error?.aiAppBridgePortDiscovery || lower.includes('bridge port discovery failed') || lower.includes('run-as') || lower.includes('package not found')) {
|
|
980
|
+
return {
|
|
981
|
+
code: 'bridge_port_discovery_failed',
|
|
982
|
+
message,
|
|
967
983
|
suggestion: 'Install a debuggable build for the requested package or pass --port explicitly.',
|
|
968
984
|
};
|
|
969
985
|
}
|
|
@@ -4299,8 +4315,9 @@ module.exports = {
|
|
|
4299
4315
|
compactNetworkRecord,
|
|
4300
4316
|
pruneGeneratedArtifacts,
|
|
4301
4317
|
shouldSkipInstallerTapForInstalledPackage,
|
|
4302
|
-
shouldDismissKeyboardForPoint,
|
|
4303
|
-
|
|
4318
|
+
shouldDismissKeyboardForPoint,
|
|
4319
|
+
shouldUseDefaultPortFallback,
|
|
4320
|
+
screenshotOutputPath,
|
|
4304
4321
|
statusSearchText,
|
|
4305
4322
|
uiautomatorLockPath,
|
|
4306
4323
|
waitTextConditionsMet,
|