@mobileai/react-native 0.9.16 → 0.9.18
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 +2 -2
- package/package.json +5 -8
- package/lib/module/__cli_tmp__.js.map +0 -1
- package/lib/module/components/AIAgent.js.map +0 -1
- package/lib/module/components/AIZone.js.map +0 -1
- package/lib/module/components/AgentChatBar.js.map +0 -1
- package/lib/module/components/AgentErrorBoundary.js.map +0 -1
- package/lib/module/components/AgentOverlay.js.map +0 -1
- package/lib/module/components/DiscoveryTooltip.js.map +0 -1
- package/lib/module/components/HighlightOverlay.js.map +0 -1
- package/lib/module/components/Icons.js.map +0 -1
- package/lib/module/components/ProactiveHint.js.map +0 -1
- package/lib/module/components/cards/InfoCard.js.map +0 -1
- package/lib/module/components/cards/ReviewSummary.js.map +0 -1
- package/lib/module/config/endpoints.js.map +0 -1
- package/lib/module/core/ActionRegistry.js.map +0 -1
- package/lib/module/core/AgentRuntime.js.map +0 -1
- package/lib/module/core/FiberTreeWalker.js.map +0 -1
- package/lib/module/core/IdleDetector.js.map +0 -1
- package/lib/module/core/MCPBridge.js.map +0 -1
- package/lib/module/core/ScreenDehydrator.js.map +0 -1
- package/lib/module/core/ZoneRegistry.js.map +0 -1
- package/lib/module/core/systemPrompt.js.map +0 -1
- package/lib/module/core/types.js.map +0 -1
- package/lib/module/hooks/useAction.js.map +0 -1
- package/lib/module/index.js.map +0 -1
- package/lib/module/plugin/withAppIntents.js.map +0 -1
- package/lib/module/providers/GeminiProvider.js.map +0 -1
- package/lib/module/providers/OpenAIProvider.js.map +0 -1
- package/lib/module/providers/ProviderFactory.js.map +0 -1
- package/lib/module/services/AudioInputService.js.map +0 -1
- package/lib/module/services/AudioOutputService.js.map +0 -1
- package/lib/module/services/KnowledgeBaseService.js.map +0 -1
- package/lib/module/services/VoiceService.js.map +0 -1
- package/lib/module/services/flags/FlagService.js.map +0 -1
- package/lib/module/services/telemetry/MobileAI.js.map +0 -1
- package/lib/module/services/telemetry/PiiScrubber.js.map +0 -1
- package/lib/module/services/telemetry/TelemetryService.js.map +0 -1
- package/lib/module/services/telemetry/TouchAutoCapture.js.map +0 -1
- package/lib/module/services/telemetry/device.js.map +0 -1
- package/lib/module/services/telemetry/deviceMetadata.js.map +0 -1
- package/lib/module/services/telemetry/index.js.map +0 -1
- package/lib/module/services/telemetry/types.js.map +0 -1
- package/lib/module/support/CSATSurvey.js.map +0 -1
- package/lib/module/support/EscalationEventSource.js.map +0 -1
- package/lib/module/support/EscalationSocket.js.map +0 -1
- package/lib/module/support/SupportChatModal.js.map +0 -1
- package/lib/module/support/SupportGreeting.js.map +0 -1
- package/lib/module/support/TicketStore.js.map +0 -1
- package/lib/module/support/escalateTool.js.map +0 -1
- package/lib/module/support/index.js.map +0 -1
- package/lib/module/support/supportPrompt.js.map +0 -1
- package/lib/module/support/types.js.map +0 -1
- package/lib/module/tools/datePickerTool.js.map +0 -1
- package/lib/module/tools/guideTool.js.map +0 -1
- package/lib/module/tools/index.js.map +0 -1
- package/lib/module/tools/keyboardTool.js.map +0 -1
- package/lib/module/tools/longPressTool.js.map +0 -1
- package/lib/module/tools/pickerTool.js.map +0 -1
- package/lib/module/tools/restoreTool.js.map +0 -1
- package/lib/module/tools/scrollTool.js.map +0 -1
- package/lib/module/tools/simplifyTool.js.map +0 -1
- package/lib/module/tools/sliderTool.js.map +0 -1
- package/lib/module/tools/tapTool.js.map +0 -1
- package/lib/module/tools/typeTool.js.map +0 -1
- package/lib/module/tools/types.js.map +0 -1
- package/lib/module/types/jsx.d.js.map +0 -1
- package/lib/module/utils/audioUtils.js.map +0 -1
- package/lib/module/utils/logger.js.map +0 -1
- package/lib/typescript/babel.config.d.ts.map +0 -1
- package/lib/typescript/bin/generate-map.d.cts.map +0 -1
- package/lib/typescript/eslint.config.d.mts.map +0 -1
- package/lib/typescript/generate-map.d.ts.map +0 -1
- package/lib/typescript/src/__cli_tmp__.d.ts.map +0 -1
- package/lib/typescript/src/components/AIAgent.d.ts.map +0 -1
- package/lib/typescript/src/components/AIZone.d.ts.map +0 -1
- package/lib/typescript/src/components/AgentChatBar.d.ts.map +0 -1
- package/lib/typescript/src/components/AgentErrorBoundary.d.ts.map +0 -1
- package/lib/typescript/src/components/AgentOverlay.d.ts.map +0 -1
- package/lib/typescript/src/components/DiscoveryTooltip.d.ts.map +0 -1
- package/lib/typescript/src/components/HighlightOverlay.d.ts.map +0 -1
- package/lib/typescript/src/components/Icons.d.ts.map +0 -1
- package/lib/typescript/src/components/ProactiveHint.d.ts.map +0 -1
- package/lib/typescript/src/components/cards/InfoCard.d.ts.map +0 -1
- package/lib/typescript/src/components/cards/ReviewSummary.d.ts.map +0 -1
- package/lib/typescript/src/config/endpoints.d.ts.map +0 -1
- package/lib/typescript/src/core/ActionRegistry.d.ts.map +0 -1
- package/lib/typescript/src/core/AgentRuntime.d.ts.map +0 -1
- package/lib/typescript/src/core/FiberTreeWalker.d.ts.map +0 -1
- package/lib/typescript/src/core/IdleDetector.d.ts.map +0 -1
- package/lib/typescript/src/core/MCPBridge.d.ts.map +0 -1
- package/lib/typescript/src/core/ScreenDehydrator.d.ts.map +0 -1
- package/lib/typescript/src/core/ZoneRegistry.d.ts.map +0 -1
- package/lib/typescript/src/core/systemPrompt.d.ts.map +0 -1
- package/lib/typescript/src/core/types.d.ts.map +0 -1
- package/lib/typescript/src/hooks/useAction.d.ts.map +0 -1
- package/lib/typescript/src/index.d.ts.map +0 -1
- package/lib/typescript/src/plugin/withAppIntents.d.ts.map +0 -1
- package/lib/typescript/src/providers/GeminiProvider.d.ts.map +0 -1
- package/lib/typescript/src/providers/OpenAIProvider.d.ts.map +0 -1
- package/lib/typescript/src/providers/ProviderFactory.d.ts.map +0 -1
- package/lib/typescript/src/services/AudioInputService.d.ts.map +0 -1
- package/lib/typescript/src/services/AudioOutputService.d.ts.map +0 -1
- package/lib/typescript/src/services/KnowledgeBaseService.d.ts.map +0 -1
- package/lib/typescript/src/services/VoiceService.d.ts.map +0 -1
- package/lib/typescript/src/services/flags/FlagService.d.ts.map +0 -1
- package/lib/typescript/src/services/telemetry/MobileAI.d.ts.map +0 -1
- package/lib/typescript/src/services/telemetry/PiiScrubber.d.ts.map +0 -1
- package/lib/typescript/src/services/telemetry/TelemetryService.d.ts.map +0 -1
- package/lib/typescript/src/services/telemetry/TouchAutoCapture.d.ts.map +0 -1
- package/lib/typescript/src/services/telemetry/device.d.ts.map +0 -1
- package/lib/typescript/src/services/telemetry/deviceMetadata.d.ts.map +0 -1
- package/lib/typescript/src/services/telemetry/index.d.ts.map +0 -1
- package/lib/typescript/src/services/telemetry/types.d.ts.map +0 -1
- package/lib/typescript/src/support/CSATSurvey.d.ts.map +0 -1
- package/lib/typescript/src/support/EscalationEventSource.d.ts.map +0 -1
- package/lib/typescript/src/support/EscalationSocket.d.ts.map +0 -1
- package/lib/typescript/src/support/SupportChatModal.d.ts.map +0 -1
- package/lib/typescript/src/support/SupportGreeting.d.ts.map +0 -1
- package/lib/typescript/src/support/TicketStore.d.ts.map +0 -1
- package/lib/typescript/src/support/escalateTool.d.ts.map +0 -1
- package/lib/typescript/src/support/index.d.ts.map +0 -1
- package/lib/typescript/src/support/supportPrompt.d.ts.map +0 -1
- package/lib/typescript/src/support/types.d.ts.map +0 -1
- package/lib/typescript/src/tools/datePickerTool.d.ts.map +0 -1
- package/lib/typescript/src/tools/guideTool.d.ts.map +0 -1
- package/lib/typescript/src/tools/index.d.ts.map +0 -1
- package/lib/typescript/src/tools/keyboardTool.d.ts.map +0 -1
- package/lib/typescript/src/tools/longPressTool.d.ts.map +0 -1
- package/lib/typescript/src/tools/pickerTool.d.ts.map +0 -1
- package/lib/typescript/src/tools/restoreTool.d.ts.map +0 -1
- package/lib/typescript/src/tools/scrollTool.d.ts.map +0 -1
- package/lib/typescript/src/tools/simplifyTool.d.ts.map +0 -1
- package/lib/typescript/src/tools/sliderTool.d.ts.map +0 -1
- package/lib/typescript/src/tools/tapTool.d.ts.map +0 -1
- package/lib/typescript/src/tools/typeTool.d.ts.map +0 -1
- package/lib/typescript/src/tools/types.d.ts.map +0 -1
- package/lib/typescript/src/utils/audioUtils.d.ts.map +0 -1
- package/lib/typescript/src/utils/logger.d.ts.map +0 -1
- package/src/__cli_tmp__.tsx +0 -9
- package/src/cli/analyzers/chain-analyzer.ts +0 -183
- package/src/cli/extractors/ai-extractor.ts +0 -6
- package/src/cli/extractors/ast-extractor.ts +0 -551
- package/src/cli/generate-intents.ts +0 -140
- package/src/cli/generate-map.ts +0 -121
- package/src/cli/generate-swift.ts +0 -116
- package/src/cli/scanners/expo-scanner.ts +0 -203
- package/src/cli/scanners/rn-scanner.ts +0 -445
- package/src/components/AIAgent.tsx +0 -1716
- package/src/components/AIZone.tsx +0 -147
- package/src/components/AgentChatBar.tsx +0 -1143
- package/src/components/AgentErrorBoundary.tsx +0 -78
- package/src/components/AgentOverlay.tsx +0 -73
- package/src/components/DiscoveryTooltip.tsx +0 -148
- package/src/components/HighlightOverlay.tsx +0 -136
- package/src/components/Icons.tsx +0 -253
- package/src/components/ProactiveHint.tsx +0 -145
- package/src/components/cards/InfoCard.tsx +0 -58
- package/src/components/cards/ReviewSummary.tsx +0 -76
- package/src/config/endpoints.ts +0 -22
- package/src/core/ActionRegistry.ts +0 -105
- package/src/core/AgentRuntime.ts +0 -1471
- package/src/core/FiberTreeWalker.ts +0 -930
- package/src/core/IdleDetector.ts +0 -72
- package/src/core/MCPBridge.ts +0 -163
- package/src/core/ScreenDehydrator.ts +0 -53
- package/src/core/ZoneRegistry.ts +0 -44
- package/src/core/systemPrompt.ts +0 -431
- package/src/core/types.ts +0 -521
- package/src/hooks/useAction.ts +0 -182
- package/src/index.ts +0 -83
- package/src/plugin/withAppIntents.ts +0 -98
- package/src/providers/GeminiProvider.ts +0 -357
- package/src/providers/OpenAIProvider.ts +0 -379
- package/src/providers/ProviderFactory.ts +0 -36
- package/src/services/AudioInputService.ts +0 -226
- package/src/services/AudioOutputService.ts +0 -236
- package/src/services/KnowledgeBaseService.ts +0 -156
- package/src/services/VoiceService.ts +0 -451
- package/src/services/flags/FlagService.ts +0 -137
- package/src/services/telemetry/MobileAI.ts +0 -66
- package/src/services/telemetry/PiiScrubber.ts +0 -17
- package/src/services/telemetry/TelemetryService.ts +0 -323
- package/src/services/telemetry/TouchAutoCapture.ts +0 -165
- package/src/services/telemetry/device.ts +0 -93
- package/src/services/telemetry/deviceMetadata.ts +0 -13
- package/src/services/telemetry/index.ts +0 -13
- package/src/services/telemetry/types.ts +0 -75
- package/src/support/CSATSurvey.tsx +0 -304
- package/src/support/EscalationEventSource.ts +0 -190
- package/src/support/EscalationSocket.ts +0 -152
- package/src/support/SupportChatModal.tsx +0 -563
- package/src/support/SupportGreeting.tsx +0 -161
- package/src/support/TicketStore.ts +0 -100
- package/src/support/escalateTool.ts +0 -174
- package/src/support/index.ts +0 -29
- package/src/support/supportPrompt.ts +0 -55
- package/src/support/types.ts +0 -155
- package/src/tools/datePickerTool.ts +0 -60
- package/src/tools/guideTool.ts +0 -76
- package/src/tools/index.ts +0 -20
- package/src/tools/keyboardTool.ts +0 -30
- package/src/tools/longPressTool.ts +0 -61
- package/src/tools/pickerTool.ts +0 -115
- package/src/tools/restoreTool.ts +0 -33
- package/src/tools/scrollTool.ts +0 -156
- package/src/tools/simplifyTool.ts +0 -33
- package/src/tools/sliderTool.ts +0 -65
- package/src/tools/tapTool.ts +0 -93
- package/src/tools/typeTool.ts +0 -113
- package/src/tools/types.ts +0 -58
- package/src/types/jsx.d.ts +0 -20
- package/src/utils/audioUtils.ts +0 -54
- package/src/utils/logger.ts +0 -38
package/src/core/IdleDetector.ts
DELETED
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
export interface IdleDetectorConfig {
|
|
2
|
-
/** Time in ms before the agent pulses subtly (e.g. 120_000 for 2m) */
|
|
3
|
-
pulseAfterMs: number;
|
|
4
|
-
/** Time in ms before the agent shows a badge (e.g. 240_000 for 4m) */
|
|
5
|
-
badgeAfterMs: number;
|
|
6
|
-
/** Callback fired when the user is idle enough for a subtle pulse */
|
|
7
|
-
onPulse: () => void;
|
|
8
|
-
/** Callback fired when the user is idle enough for a proactive badge. Receives the context suggestion. */
|
|
9
|
-
onBadge: (suggestion: string) => void;
|
|
10
|
-
/** Callback fired when the user interacts, cancelling idle states */
|
|
11
|
-
onReset: () => void;
|
|
12
|
-
/** Dynamic context suggestion generator based on current screen */
|
|
13
|
-
generateSuggestion?: () => string;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export class IdleDetector {
|
|
17
|
-
private pulseTimer: ReturnType<typeof setTimeout> | null = null;
|
|
18
|
-
private badgeTimer: ReturnType<typeof setTimeout> | null = null;
|
|
19
|
-
private dismissed = false;
|
|
20
|
-
private config: IdleDetectorConfig | null = null;
|
|
21
|
-
|
|
22
|
-
start(config: IdleDetectorConfig): void {
|
|
23
|
-
this.config = config;
|
|
24
|
-
this.dismissed = false;
|
|
25
|
-
this.resetTimers();
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
reset(): void {
|
|
29
|
-
if (!this.config || this.dismissed) return;
|
|
30
|
-
this.config.onReset();
|
|
31
|
-
this.resetTimers();
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
dismiss(): void {
|
|
35
|
-
this.dismissed = true;
|
|
36
|
-
this.clearTimers();
|
|
37
|
-
if (this.config) {
|
|
38
|
-
this.config.onReset();
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
destroy(): void {
|
|
43
|
-
this.clearTimers();
|
|
44
|
-
this.config = null;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
private resetTimers(): void {
|
|
48
|
-
this.clearTimers();
|
|
49
|
-
|
|
50
|
-
if (!this.config || this.dismissed) return;
|
|
51
|
-
|
|
52
|
-
this.pulseTimer = setTimeout(() => {
|
|
53
|
-
this.config?.onPulse();
|
|
54
|
-
}, this.config.pulseAfterMs);
|
|
55
|
-
|
|
56
|
-
this.badgeTimer = setTimeout(() => {
|
|
57
|
-
const suggestion = this.config?.generateSuggestion?.() ?? "Need help with this screen?";
|
|
58
|
-
this.config?.onBadge(suggestion);
|
|
59
|
-
}, this.config.badgeAfterMs);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
private clearTimers(): void {
|
|
63
|
-
if (this.pulseTimer) {
|
|
64
|
-
clearTimeout(this.pulseTimer);
|
|
65
|
-
this.pulseTimer = null;
|
|
66
|
-
}
|
|
67
|
-
if (this.badgeTimer) {
|
|
68
|
-
clearTimeout(this.badgeTimer);
|
|
69
|
-
this.badgeTimer = null;
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
}
|
package/src/core/MCPBridge.ts
DELETED
|
@@ -1,163 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* MCPBridge — Connects the React Native app to the local MCP Server bridge.
|
|
3
|
-
*
|
|
4
|
-
* Flow:
|
|
5
|
-
* - Connects via WebSocket to the Node.js MCP server
|
|
6
|
-
* - Listens for 'request' messages containing an MCP command
|
|
7
|
-
* - Forwards the command to AgentRuntime.execute()
|
|
8
|
-
* - Sends the ExecutionResult back via WebSocket as a 'response'
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
import { logger } from '../utils/logger';
|
|
12
|
-
import type { AgentRuntime } from './AgentRuntime';
|
|
13
|
-
|
|
14
|
-
export class MCPBridge {
|
|
15
|
-
private url: string;
|
|
16
|
-
private ws: WebSocket | null = null;
|
|
17
|
-
private runtime: AgentRuntime;
|
|
18
|
-
private reconnectTimer: ReturnType<typeof setTimeout> | null = null;
|
|
19
|
-
private isDestroyed = false;
|
|
20
|
-
|
|
21
|
-
constructor(url: string, runtime: AgentRuntime) {
|
|
22
|
-
this.url = url;
|
|
23
|
-
this.runtime = runtime;
|
|
24
|
-
this.connect();
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
private connect() {
|
|
28
|
-
if (this.isDestroyed) return;
|
|
29
|
-
|
|
30
|
-
logger.info('MCPBridge', `Connecting to MCP bridge at ${this.url}...`);
|
|
31
|
-
this.ws = new WebSocket(this.url);
|
|
32
|
-
|
|
33
|
-
this.ws.onopen = () => {
|
|
34
|
-
logger.info('MCPBridge', '✅ Connected to MCP bridge.');
|
|
35
|
-
if (this.reconnectTimer) {
|
|
36
|
-
clearTimeout(this.reconnectTimer);
|
|
37
|
-
this.reconnectTimer = null;
|
|
38
|
-
}
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
this.ws.onmessage = async (event) => {
|
|
42
|
-
try {
|
|
43
|
-
const data = JSON.parse(event.data);
|
|
44
|
-
const serverMode = this.runtime.getConfig().mcpServerMode ?? 'auto';
|
|
45
|
-
const serverEnabled = serverMode === 'enabled' || (serverMode !== 'disabled' && __DEV__);
|
|
46
|
-
|
|
47
|
-
switch (data.type) {
|
|
48
|
-
case 'request': {
|
|
49
|
-
if (!data.command || !data.requestId) return;
|
|
50
|
-
logger.info('MCPBridge', `Received task from MCP: "${data.command}"`);
|
|
51
|
-
|
|
52
|
-
if (this.runtime.getIsRunning()) {
|
|
53
|
-
this.sendResponse(data.requestId, {
|
|
54
|
-
success: false,
|
|
55
|
-
message: 'Agent is already running a task. Please wait.',
|
|
56
|
-
steps: [],
|
|
57
|
-
});
|
|
58
|
-
return;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
// Execute the task using the SDK's existing runtime loop
|
|
62
|
-
const result = await this.runtime.execute(data.command);
|
|
63
|
-
|
|
64
|
-
// Send result back to MCP server
|
|
65
|
-
this.sendResponse(data.requestId, result);
|
|
66
|
-
break;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
case 'tools/list': {
|
|
70
|
-
if (!serverEnabled) {
|
|
71
|
-
this.sendResponse(data.requestId, { error: 'MCP server mode is disabled.' });
|
|
72
|
-
break;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
const tools = this.runtime.getTools().map(t => ({
|
|
76
|
-
name: t.name,
|
|
77
|
-
description: t.description,
|
|
78
|
-
inputSchema: {
|
|
79
|
-
type: 'object',
|
|
80
|
-
properties: t.parameters || {},
|
|
81
|
-
required: Object.entries(t.parameters || {})
|
|
82
|
-
.filter(([_, p]: [string, any]) => p.required !== false)
|
|
83
|
-
.map(([k]) => k),
|
|
84
|
-
}
|
|
85
|
-
}));
|
|
86
|
-
|
|
87
|
-
this.sendResponse(data.requestId, { tools });
|
|
88
|
-
break;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
case 'tools/call': {
|
|
92
|
-
if (!serverEnabled) {
|
|
93
|
-
this.sendResponse(data.requestId, { error: 'MCP server mode is disabled.' });
|
|
94
|
-
break;
|
|
95
|
-
}
|
|
96
|
-
try {
|
|
97
|
-
const result = await this.runtime.executeTool(data.name, data.arguments || {});
|
|
98
|
-
this.sendResponse(data.requestId, { result });
|
|
99
|
-
} catch (err: any) {
|
|
100
|
-
this.sendResponse(data.requestId, { error: err.message });
|
|
101
|
-
}
|
|
102
|
-
break;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
case 'screen/state': {
|
|
106
|
-
if (!serverEnabled) {
|
|
107
|
-
this.sendResponse(data.requestId, { error: 'MCP server mode is disabled.' });
|
|
108
|
-
break;
|
|
109
|
-
}
|
|
110
|
-
const screen = this.runtime.getScreenContext();
|
|
111
|
-
this.sendResponse(data.requestId, { screen });
|
|
112
|
-
break;
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
} catch (err) {
|
|
116
|
-
logger.error('MCPBridge', 'Error handling message:', err);
|
|
117
|
-
}
|
|
118
|
-
};
|
|
119
|
-
|
|
120
|
-
this.ws.onclose = () => {
|
|
121
|
-
if (!this.isDestroyed) {
|
|
122
|
-
logger.warn('MCPBridge', 'Disconnected from MCP bridge. Reconnecting in 5s...');
|
|
123
|
-
this.ws = null;
|
|
124
|
-
this.scheduleReconnect();
|
|
125
|
-
}
|
|
126
|
-
};
|
|
127
|
-
|
|
128
|
-
this.ws.onerror = (e) => {
|
|
129
|
-
logger.warn('MCPBridge', 'WebSocket error:', e);
|
|
130
|
-
// onclose will handle reconnect
|
|
131
|
-
};
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
private sendResponse(requestId: string, payload: any) {
|
|
135
|
-
if (this.ws && this.ws.readyState === WebSocket.OPEN) {
|
|
136
|
-
this.ws.send(JSON.stringify({
|
|
137
|
-
type: 'response',
|
|
138
|
-
requestId,
|
|
139
|
-
payload,
|
|
140
|
-
}));
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
private scheduleReconnect() {
|
|
145
|
-
if (!this.reconnectTimer) {
|
|
146
|
-
this.reconnectTimer = setTimeout(() => {
|
|
147
|
-
this.connect();
|
|
148
|
-
}, 5000);
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
public destroy() {
|
|
153
|
-
this.isDestroyed = true;
|
|
154
|
-
if (this.reconnectTimer) {
|
|
155
|
-
clearTimeout(this.reconnectTimer);
|
|
156
|
-
this.reconnectTimer = null;
|
|
157
|
-
}
|
|
158
|
-
if (this.ws) {
|
|
159
|
-
this.ws.close();
|
|
160
|
-
this.ws = null;
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
}
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ScreenDehydrator — Converts discovered interactive elements into
|
|
3
|
-
* a text representation for the LLM.
|
|
4
|
-
*
|
|
5
|
-
* Output example:
|
|
6
|
-
* ```
|
|
7
|
-
* Screen: Home | Available screens: Home, Menu, Cart
|
|
8
|
-
* Interactive elements:
|
|
9
|
-
* [0]<pressable>🍕 Pizzas</>
|
|
10
|
-
* [1]<pressable>🍔 Burgers</>
|
|
11
|
-
* [2]<pressable>🥤 Drinks</>
|
|
12
|
-
* [3]<pressable>🛒 View Cart</>
|
|
13
|
-
* ```
|
|
14
|
-
*/
|
|
15
|
-
|
|
16
|
-
import type { InteractiveElement, DehydratedScreen } from './types';
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Dehydrate the current screen state into a text format for the LLM.
|
|
20
|
-
*/
|
|
21
|
-
export function dehydrateScreen(
|
|
22
|
-
screenName: string,
|
|
23
|
-
availableScreens: string[],
|
|
24
|
-
elementsText: string,
|
|
25
|
-
elements: InteractiveElement[],
|
|
26
|
-
): DehydratedScreen {
|
|
27
|
-
const lines: string[] = [];
|
|
28
|
-
|
|
29
|
-
// Header
|
|
30
|
-
lines.push(`Screen: ${screenName} | Available screens: ${availableScreens.join(', ')}`);
|
|
31
|
-
lines.push('');
|
|
32
|
-
|
|
33
|
-
if (!elementsText || elementsText.trim().length === 0) {
|
|
34
|
-
if (elements.length === 0) {
|
|
35
|
-
lines.push('No interactive elements or visible text detected on this screen.');
|
|
36
|
-
} else {
|
|
37
|
-
lines.push('Interactive elements:');
|
|
38
|
-
lines.push(elementsText);
|
|
39
|
-
}
|
|
40
|
-
} else {
|
|
41
|
-
lines.push('Screen Layout & Elements:');
|
|
42
|
-
lines.push(elementsText);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
const finalElementsText = lines.join('\n');
|
|
46
|
-
|
|
47
|
-
return {
|
|
48
|
-
screenName,
|
|
49
|
-
availableScreens,
|
|
50
|
-
elementsText: finalElementsText,
|
|
51
|
-
elements,
|
|
52
|
-
};
|
|
53
|
-
}
|
package/src/core/ZoneRegistry.ts
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import React, { createContext } from 'react';
|
|
2
|
-
import type { AIZoneConfig, RegisteredZone } from './types';
|
|
3
|
-
|
|
4
|
-
export class ZoneRegistry {
|
|
5
|
-
private zones = new Map<string, RegisteredZone>();
|
|
6
|
-
|
|
7
|
-
register(config: AIZoneConfig, ref: React.RefObject<any>): void {
|
|
8
|
-
if (this.zones.has(config.id)) {
|
|
9
|
-
console.warn(`[MobileAI] Zone ID "${config.id}" is already registered on this screen. Overwriting.`);
|
|
10
|
-
}
|
|
11
|
-
this.zones.set(config.id, { ...config, ref });
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
unregister(id: string): void {
|
|
15
|
-
this.zones.delete(id);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
get(id: string): RegisteredZone | undefined {
|
|
19
|
-
return this.zones.get(id);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
getAll(): RegisteredZone[] {
|
|
23
|
-
return Array.from(this.zones.values());
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
isActionAllowed(zoneId: string, action: 'highlight' | 'hint' | 'simplify' | 'card'): boolean {
|
|
27
|
-
const zone = this.get(zoneId);
|
|
28
|
-
if (!zone) return false;
|
|
29
|
-
|
|
30
|
-
switch (action) {
|
|
31
|
-
case 'highlight': return !!zone.allowHighlight;
|
|
32
|
-
case 'hint': return !!zone.allowInjectHint;
|
|
33
|
-
case 'simplify': return !!zone.allowSimplify;
|
|
34
|
-
case 'card': return !!zone.allowInjectCard;
|
|
35
|
-
default: return false;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
// Global registry instance shared across the Agent session
|
|
41
|
-
export const globalZoneRegistry = new ZoneRegistry();
|
|
42
|
-
|
|
43
|
-
// Export context so AIZone components can register themselves
|
|
44
|
-
export const ZoneRegistryContext = createContext<ZoneRegistry>(globalZoneRegistry);
|