@mobileai/react-native 0.9.0 → 0.9.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 (173) hide show
  1. package/README.md +121 -0
  2. package/lib/module/components/AIAgent.js +248 -53
  3. package/lib/module/components/AIAgent.js.map +1 -1
  4. package/lib/module/components/AIZone.js +140 -0
  5. package/lib/module/components/AIZone.js.map +1 -0
  6. package/lib/module/components/AgentErrorBoundary.js +9 -0
  7. package/lib/module/components/AgentErrorBoundary.js.map +1 -1
  8. package/lib/module/components/HighlightOverlay.js +138 -0
  9. package/lib/module/components/HighlightOverlay.js.map +1 -0
  10. package/lib/module/components/ProactiveHint.js +138 -0
  11. package/lib/module/components/ProactiveHint.js.map +1 -0
  12. package/lib/module/components/cards/InfoCard.js +65 -0
  13. package/lib/module/components/cards/InfoCard.js.map +1 -0
  14. package/lib/module/components/cards/ReviewSummary.js +74 -0
  15. package/lib/module/components/cards/ReviewSummary.js.map +1 -0
  16. package/lib/module/core/AgentRuntime.js +16 -3
  17. package/lib/module/core/AgentRuntime.js.map +1 -1
  18. package/lib/module/core/FiberTreeWalker.js +62 -85
  19. package/lib/module/core/FiberTreeWalker.js.map +1 -1
  20. package/lib/module/core/IdleDetector.js +51 -0
  21. package/lib/module/core/IdleDetector.js.map +1 -0
  22. package/lib/module/core/ZoneRegistry.js +47 -0
  23. package/lib/module/core/ZoneRegistry.js.map +1 -0
  24. package/lib/module/core/systemPrompt.js +2 -0
  25. package/lib/module/core/systemPrompt.js.map +1 -1
  26. package/lib/module/index.js +21 -0
  27. package/lib/module/index.js.map +1 -1
  28. package/lib/module/services/AudioOutputService.js +10 -0
  29. package/lib/module/services/AudioOutputService.js.map +1 -1
  30. package/lib/module/services/flags/FlagService.js +117 -0
  31. package/lib/module/services/flags/FlagService.js.map +1 -0
  32. package/lib/module/services/telemetry/MobileAI.js +66 -0
  33. package/lib/module/services/telemetry/MobileAI.js.map +1 -0
  34. package/lib/module/services/telemetry/PiiScrubber.js +17 -0
  35. package/lib/module/services/telemetry/PiiScrubber.js.map +1 -0
  36. package/lib/module/services/telemetry/TelemetryService.js +260 -0
  37. package/lib/module/services/telemetry/TelemetryService.js.map +1 -0
  38. package/lib/module/services/telemetry/TouchAutoCapture.js +159 -0
  39. package/lib/module/services/telemetry/TouchAutoCapture.js.map +1 -0
  40. package/lib/module/services/telemetry/device.js +19 -0
  41. package/lib/module/services/telemetry/device.js.map +1 -0
  42. package/lib/module/services/telemetry/index.js +9 -0
  43. package/lib/module/services/telemetry/index.js.map +1 -0
  44. package/lib/module/services/telemetry/types.js +2 -0
  45. package/lib/module/services/telemetry/types.js.map +1 -0
  46. package/lib/module/support/CSATSurvey.js +273 -0
  47. package/lib/module/support/CSATSurvey.js.map +1 -0
  48. package/lib/module/support/EscalationSocket.js +92 -0
  49. package/lib/module/support/EscalationSocket.js.map +1 -0
  50. package/lib/module/support/SupportGreeting.js +142 -0
  51. package/lib/module/support/SupportGreeting.js.map +1 -0
  52. package/lib/module/support/escalateTool.js +120 -0
  53. package/lib/module/support/escalateTool.js.map +1 -0
  54. package/lib/module/support/index.js +18 -0
  55. package/lib/module/support/index.js.map +1 -0
  56. package/lib/module/support/supportPrompt.js +47 -0
  57. package/lib/module/support/supportPrompt.js.map +1 -0
  58. package/lib/module/support/types.js +2 -0
  59. package/lib/module/support/types.js.map +1 -0
  60. package/lib/module/tools/guideTool.js +61 -0
  61. package/lib/module/tools/guideTool.js.map +1 -0
  62. package/lib/module/tools/index.js +3 -0
  63. package/lib/module/tools/index.js.map +1 -1
  64. package/lib/module/tools/restoreTool.js +31 -0
  65. package/lib/module/tools/restoreTool.js.map +1 -0
  66. package/lib/module/tools/simplifyTool.js +31 -0
  67. package/lib/module/tools/simplifyTool.js.map +1 -0
  68. package/lib/module/types/jsx.d.js +4 -0
  69. package/lib/module/types/jsx.d.js.map +1 -0
  70. package/lib/typescript/src/components/AIAgent.d.ts +21 -2
  71. package/lib/typescript/src/components/AIAgent.d.ts.map +1 -1
  72. package/lib/typescript/src/components/AIZone.d.ts +16 -0
  73. package/lib/typescript/src/components/AIZone.d.ts.map +1 -0
  74. package/lib/typescript/src/components/AgentErrorBoundary.d.ts +1 -0
  75. package/lib/typescript/src/components/AgentErrorBoundary.d.ts.map +1 -1
  76. package/lib/typescript/src/components/HighlightOverlay.d.ts +10 -0
  77. package/lib/typescript/src/components/HighlightOverlay.d.ts.map +1 -0
  78. package/lib/typescript/src/components/ProactiveHint.d.ts +10 -0
  79. package/lib/typescript/src/components/ProactiveHint.d.ts.map +1 -0
  80. package/lib/typescript/src/components/cards/InfoCard.d.ts +19 -0
  81. package/lib/typescript/src/components/cards/InfoCard.d.ts.map +1 -0
  82. package/lib/typescript/src/components/cards/ReviewSummary.d.ts +19 -0
  83. package/lib/typescript/src/components/cards/ReviewSummary.d.ts.map +1 -0
  84. package/lib/typescript/src/core/AgentRuntime.d.ts +1 -0
  85. package/lib/typescript/src/core/AgentRuntime.d.ts.map +1 -1
  86. package/lib/typescript/src/core/FiberTreeWalker.d.ts.map +1 -1
  87. package/lib/typescript/src/core/IdleDetector.d.ts +27 -0
  88. package/lib/typescript/src/core/IdleDetector.d.ts.map +1 -0
  89. package/lib/typescript/src/core/ZoneRegistry.d.ts +13 -0
  90. package/lib/typescript/src/core/ZoneRegistry.d.ts.map +1 -0
  91. package/lib/typescript/src/core/systemPrompt.d.ts.map +1 -1
  92. package/lib/typescript/src/core/types.d.ts +54 -0
  93. package/lib/typescript/src/core/types.d.ts.map +1 -1
  94. package/lib/typescript/src/index.d.ts +5 -0
  95. package/lib/typescript/src/index.d.ts.map +1 -1
  96. package/lib/typescript/src/services/AudioOutputService.d.ts.map +1 -1
  97. package/lib/typescript/src/services/flags/FlagService.d.ts +25 -0
  98. package/lib/typescript/src/services/flags/FlagService.d.ts.map +1 -0
  99. package/lib/typescript/src/services/telemetry/MobileAI.d.ts +38 -0
  100. package/lib/typescript/src/services/telemetry/MobileAI.d.ts.map +1 -0
  101. package/lib/typescript/src/services/telemetry/PiiScrubber.d.ts +6 -0
  102. package/lib/typescript/src/services/telemetry/PiiScrubber.d.ts.map +1 -0
  103. package/lib/typescript/src/services/telemetry/TelemetryService.d.ts +49 -0
  104. package/lib/typescript/src/services/telemetry/TelemetryService.d.ts.map +1 -0
  105. package/lib/typescript/src/services/telemetry/TouchAutoCapture.d.ts +28 -0
  106. package/lib/typescript/src/services/telemetry/TouchAutoCapture.d.ts.map +1 -0
  107. package/lib/typescript/src/services/telemetry/device.d.ts +7 -0
  108. package/lib/typescript/src/services/telemetry/device.d.ts.map +1 -0
  109. package/lib/typescript/src/services/telemetry/index.d.ts +7 -0
  110. package/lib/typescript/src/services/telemetry/index.d.ts.map +1 -0
  111. package/lib/typescript/src/services/telemetry/types.d.ts +50 -0
  112. package/lib/typescript/src/services/telemetry/types.d.ts.map +1 -0
  113. package/lib/typescript/src/support/CSATSurvey.d.ts +20 -0
  114. package/lib/typescript/src/support/CSATSurvey.d.ts.map +1 -0
  115. package/lib/typescript/src/support/EscalationSocket.d.ts +38 -0
  116. package/lib/typescript/src/support/EscalationSocket.d.ts.map +1 -0
  117. package/lib/typescript/src/support/SupportGreeting.d.ts +19 -0
  118. package/lib/typescript/src/support/SupportGreeting.d.ts.map +1 -0
  119. package/lib/typescript/src/support/escalateTool.d.ts +25 -0
  120. package/lib/typescript/src/support/escalateTool.d.ts.map +1 -0
  121. package/lib/typescript/src/support/index.d.ts +11 -0
  122. package/lib/typescript/src/support/index.d.ts.map +1 -0
  123. package/lib/typescript/src/support/supportPrompt.d.ts +12 -0
  124. package/lib/typescript/src/support/supportPrompt.d.ts.map +1 -0
  125. package/lib/typescript/src/support/types.d.ts +114 -0
  126. package/lib/typescript/src/support/types.d.ts.map +1 -0
  127. package/lib/typescript/src/tools/guideTool.d.ts +4 -0
  128. package/lib/typescript/src/tools/guideTool.d.ts.map +1 -0
  129. package/lib/typescript/src/tools/index.d.ts +3 -0
  130. package/lib/typescript/src/tools/index.d.ts.map +1 -1
  131. package/lib/typescript/src/tools/restoreTool.d.ts +3 -0
  132. package/lib/typescript/src/tools/restoreTool.d.ts.map +1 -0
  133. package/lib/typescript/src/tools/simplifyTool.d.ts +3 -0
  134. package/lib/typescript/src/tools/simplifyTool.d.ts.map +1 -0
  135. package/lib/typescript/src/tools/types.d.ts +2 -0
  136. package/lib/typescript/src/tools/types.d.ts.map +1 -1
  137. package/package.json +5 -1
  138. package/src/components/AIAgent.tsx +253 -15
  139. package/src/components/AIZone.tsx +147 -0
  140. package/src/components/AgentErrorBoundary.tsx +10 -0
  141. package/src/components/HighlightOverlay.tsx +136 -0
  142. package/src/components/ProactiveHint.tsx +145 -0
  143. package/src/components/cards/InfoCard.tsx +58 -0
  144. package/src/components/cards/ReviewSummary.tsx +76 -0
  145. package/src/core/AgentRuntime.ts +18 -0
  146. package/src/core/FiberTreeWalker.ts +71 -93
  147. package/src/core/IdleDetector.ts +72 -0
  148. package/src/core/ZoneRegistry.ts +44 -0
  149. package/src/core/systemPrompt.ts +2 -0
  150. package/src/core/types.ts +60 -0
  151. package/src/index.ts +31 -0
  152. package/src/services/AudioOutputService.ts +13 -0
  153. package/src/services/flags/FlagService.ts +137 -0
  154. package/src/services/telemetry/MobileAI.ts +66 -0
  155. package/src/services/telemetry/PiiScrubber.ts +17 -0
  156. package/src/services/telemetry/TelemetryService.ts +291 -0
  157. package/src/services/telemetry/TouchAutoCapture.ts +165 -0
  158. package/src/services/telemetry/device.ts +16 -0
  159. package/src/services/telemetry/index.ts +13 -0
  160. package/src/services/telemetry/types.ts +75 -0
  161. package/src/support/CSATSurvey.tsx +304 -0
  162. package/src/support/EscalationSocket.ts +113 -0
  163. package/src/support/SupportGreeting.tsx +161 -0
  164. package/src/support/escalateTool.ts +134 -0
  165. package/src/support/index.ts +27 -0
  166. package/src/support/supportPrompt.ts +55 -0
  167. package/src/support/types.ts +141 -0
  168. package/src/tools/guideTool.ts +67 -0
  169. package/src/tools/index.ts +3 -0
  170. package/src/tools/restoreTool.ts +33 -0
  171. package/src/tools/simplifyTool.ts +33 -0
  172. package/src/tools/types.ts +2 -0
  173. package/src/types/jsx.d.ts +20 -0
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Support Mode — barrel export.
3
+ */
4
+
5
+ // Types
6
+ export type {
7
+ SupportModeConfig,
8
+ QuickReply,
9
+ EscalationConfig,
10
+ EscalationContext,
11
+ CSATConfig,
12
+ CSATRating,
13
+ BusinessHoursConfig,
14
+ } from './types';
15
+
16
+ // Prompt injection
17
+ export { buildSupportPrompt } from './supportPrompt';
18
+
19
+ // Escalation tool + WebSocket manager
20
+ export { createEscalateTool } from './escalateTool';
21
+ export { EscalationSocket } from './EscalationSocket';
22
+ export type { SocketReplyHandler } from './EscalationSocket';
23
+
24
+ // UI Components
25
+ export { SupportGreeting } from './SupportGreeting';
26
+ export { CSATSurvey } from './CSATSurvey';
27
+
@@ -0,0 +1,55 @@
1
+ /**
2
+ * Support Mode prompt — injected into the system prompt when support mode is enabled.
3
+ *
4
+ * Uses POSITIVE framing (what TO DO) instead of negative rules (per user's prompt engineering rules).
5
+ */
6
+
7
+ import type { SupportModeConfig } from './types';
8
+
9
+ /**
10
+ * Build the support mode system prompt addition.
11
+ * This gets appended to the main system prompt when support mode is active.
12
+ */
13
+ export function buildSupportPrompt(config: SupportModeConfig): string {
14
+ const parts: string[] = [];
15
+
16
+ // Core support persona
17
+ parts.push(`
18
+ ## Support Mode Active
19
+
20
+ You are a helpful customer support assistant. Your primary goal is to resolve the user's issue quickly and empathetically.
21
+
22
+ ### Behavior Guidelines
23
+ - Greet the user warmly and acknowledge their issue
24
+ - Ask clarifying questions when the user's request is ambiguous
25
+ - Provide step-by-step guidance when helping with app features
26
+ - Use the app's UI tools to demonstrate solutions visually (tap, navigate, type)
27
+ - After resolving, confirm with the user that their issue is fixed
28
+ - Stay focused on the user's current issue — complete one task before moving to another
29
+ `);
30
+
31
+ // Custom system context from the consumer
32
+ if (config.systemContext) {
33
+ parts.push(`### App Context\n${config.systemContext}\n`);
34
+ }
35
+
36
+ // Auto-escalate topics
37
+ if (config.autoEscalateTopics?.length) {
38
+ parts.push(
39
+ `### Auto-Escalation Topics\n` +
40
+ `When the user's query matches any of these topics, use the escalate_to_human tool immediately:\n` +
41
+ config.autoEscalateTopics.map((t) => `- ${t}`).join('\n') + '\n'
42
+ );
43
+ }
44
+
45
+ // Business hours context
46
+ if (config.businessHours) {
47
+ parts.push(
48
+ `### Business Hours\n` +
49
+ `The support team operates in timezone: ${config.businessHours.timezone}.\n` +
50
+ `If outside business hours, inform the user and offer to help with what you can.\n`
51
+ );
52
+ }
53
+
54
+ return parts.join('\n');
55
+ }
@@ -0,0 +1,141 @@
1
+ /**
2
+ * Support Mode — types and configuration.
3
+ *
4
+ * Transforms the AI agent into a customer support assistant with:
5
+ * - Custom greeting message
6
+ * - Quick reply suggestions
7
+ * - Human escalation capability
8
+ * - CSAT (Customer Satisfaction) collection after conversation
9
+ */
10
+
11
+ // ─── Support Mode Config ──────────────────────────────────
12
+
13
+ export interface SupportModeConfig {
14
+ /** Enable support mode. Default: false */
15
+ enabled: boolean;
16
+
17
+ /** Greeting message shown when the chat opens */
18
+ greeting?: {
19
+ /** Main greeting text (e.g., "Hi! 👋 How can I help you today?") */
20
+ message: string;
21
+ /** Agent name shown above the greeting (e.g., "MobileAI Support") */
22
+ agentName?: string;
23
+ /** Avatar URL for the support agent */
24
+ avatarUrl?: string;
25
+ };
26
+
27
+ /** Quick reply buttons shown below the greeting */
28
+ quickReplies?: QuickReply[];
29
+
30
+ /** Escalation configuration */
31
+ escalation?: EscalationConfig;
32
+
33
+ /** CSAT survey configuration */
34
+ csat?: CSATConfig;
35
+
36
+ /** Business hours (optional — shows offline message outside hours) */
37
+ businessHours?: BusinessHoursConfig;
38
+
39
+ /**
40
+ * Additional system prompt context for the support persona.
41
+ * Merged with the base system prompt.
42
+ * Example: "You are a friendly support agent for FeedYum food delivery app."
43
+ */
44
+ systemContext?: string;
45
+
46
+ /**
47
+ * Topics the AI should NOT attempt to resolve — escalate immediately.
48
+ * Example: ['billing dispute', 'account deletion', 'legal']
49
+ */
50
+ autoEscalateTopics?: string[];
51
+ }
52
+
53
+ // ─── Quick Replies ────────────────────────────────────────
54
+
55
+ export interface QuickReply {
56
+ /** Display text on the button */
57
+ label: string;
58
+ /** Message sent when tapped (defaults to label if not set) */
59
+ message?: string;
60
+ /** Icon emoji (optional) */
61
+ icon?: string;
62
+ }
63
+
64
+ // ─── Escalation ───────────────────────────────────────────
65
+
66
+ export interface EscalationConfig {
67
+ /**
68
+ * Where to route the escalation.
69
+ * - 'mobileai' (default when analyticsKey is set): ticket goes to MobileAI
70
+ * dashboard inbox via POST /api/v1/escalations + WebSocket reply delivery.
71
+ * - 'custom': fires the onEscalate callback — wire to Intercom, Zendesk, etc.
72
+ */
73
+ provider?: 'mobileai' | 'custom';
74
+
75
+ /**
76
+ * Callback when user requests human support (required when provider='custom').
77
+ * Use this to open a live chat widget, send email, etc.
78
+ */
79
+ onEscalate?: (context: EscalationContext) => void;
80
+
81
+ /** Label for the escalate button. Default: "Talk to a human" */
82
+ buttonLabel?: string;
83
+
84
+ /** Message shown to user when escalated. Default: "Connecting you to a human agent..." */
85
+ escalationMessage?: string;
86
+ }
87
+
88
+ export interface EscalationContext {
89
+ /** Summary of the conversation so far */
90
+ conversationSummary: string;
91
+ /** Current screen the user is on */
92
+ currentScreen: string;
93
+ /** User's original question/issue */
94
+ originalQuery: string;
95
+ /** Number of AI steps taken before escalation */
96
+ stepsBeforeEscalation: number;
97
+ }
98
+
99
+ // ─── CSAT (Customer Satisfaction) ─────────────────────────
100
+
101
+ export interface CSATConfig {
102
+ /** Enable CSAT survey after conversation. Default: true if support mode enabled */
103
+ enabled?: boolean;
104
+
105
+ /** Question text. Default: "How was your experience?" */
106
+ question?: string;
107
+
108
+ /** Rating type. Default: 'emoji' */
109
+ ratingType?: 'stars' | 'emoji' | 'thumbs';
110
+
111
+ /** Callback when user submits rating */
112
+ onSubmit: (rating: CSATRating) => void;
113
+
114
+ /** Show after N seconds of inactivity. Default: 10 */
115
+ showAfterIdleSeconds?: number;
116
+ }
117
+
118
+ export interface CSATRating {
119
+ /** Numeric score (1-5 for stars/emoji, 0-1 for thumbs) */
120
+ score: number;
121
+ /** Optional text feedback */
122
+ feedback?: string;
123
+ /** Conversation metadata */
124
+ metadata: {
125
+ conversationDuration: number;
126
+ stepsCount: number;
127
+ wasEscalated: boolean;
128
+ screen: string;
129
+ };
130
+ }
131
+
132
+ // ─── Business Hours ───────────────────────────────────────
133
+
134
+ export interface BusinessHoursConfig {
135
+ /** Timezone (IANA format, e.g., 'Africa/Cairo') */
136
+ timezone: string;
137
+ /** Schedule per day of week (0=Sunday, 6=Saturday) */
138
+ schedule: Record<number, { start: string; end: string } | null>;
139
+ /** Message shown outside business hours */
140
+ offlineMessage?: string;
141
+ }
@@ -0,0 +1,67 @@
1
+ import { DeviceEventEmitter } from 'react-native';
2
+ import type { ToolDefinition } from '../core/types';
3
+ import type { ToolContext } from './types';
4
+ import { logger } from '../utils/logger';
5
+
6
+ export function createGuideTool(context: ToolContext): ToolDefinition {
7
+ return {
8
+ name: 'guide_user',
9
+ description: 'Highlight a specific element to draw the user\'s attention. Use when you want to show the user where to tap next. Auto-dismisses after a few seconds.',
10
+ parameters: {
11
+ index: {
12
+ type: 'number',
13
+ description: 'Fiber element index from the screen layout',
14
+ required: true,
15
+ },
16
+ message: {
17
+ type: 'string',
18
+ description: 'Short instruction shown near the highlighted element (e.g. "Tap here to continue")',
19
+ required: true,
20
+ },
21
+ autoRemoveAfterMs: {
22
+ type: 'number',
23
+ description: 'Auto-dismiss after this many milliseconds. Default: 5000',
24
+ required: false,
25
+ }
26
+ },
27
+ execute: async (args: Record<string, any>) => {
28
+ const lastDehydratedRoot = context.getLastDehydratedRoot?.();
29
+ if (!lastDehydratedRoot) {
30
+ return '❌ Cannot guide user: No screen layout structure available.';
31
+ }
32
+
33
+ const index = Number(args.index);
34
+ const element = lastDehydratedRoot.elements[index];
35
+
36
+ if (!element) {
37
+ return `❌ Element at index ${index} not found on current screen.`;
38
+ }
39
+
40
+ const stateNode = element.fiberNode?.stateNode;
41
+ if (!stateNode || typeof stateNode.measure !== 'function') {
42
+ return `❌ Element at index ${index} (${element.label}) cannot be highlighted because its layout position cannot be measured.`;
43
+ }
44
+
45
+ return new Promise((resolve) => {
46
+ stateNode.measure((_x: number, _y: number, width: number, height: number, pageX: number, pageY: number) => {
47
+ if (width === 0 || height === 0) {
48
+ resolve(`❌ Element at index ${index} is not visible (0x0 size)`);
49
+ return;
50
+ }
51
+
52
+ DeviceEventEmitter.emit('MOBILE_AI_HIGHLIGHT', {
53
+ pageX,
54
+ pageY,
55
+ width,
56
+ height,
57
+ message: args.message,
58
+ autoRemoveAfterMs: args.autoRemoveAfterMs || 5000,
59
+ });
60
+
61
+ logger.info('GuideTool', `Highlighted element ${index} ("${element.label}") at ${pageX},${pageY}`);
62
+ resolve(`✅ Highlighted element ${index} ("${element.label}") with message: "${args.message}"`);
63
+ });
64
+ });
65
+ },
66
+ };
67
+ }
@@ -13,5 +13,8 @@ export { createSliderTool } from './sliderTool';
13
13
  export { createPickerTool } from './pickerTool';
14
14
  export { createDatePickerTool } from './datePickerTool';
15
15
  export { createKeyboardTool } from './keyboardTool';
16
+ export { createGuideTool } from './guideTool';
17
+ export { createSimplifyTool } from './simplifyTool';
18
+ export { createRestoreTool } from './restoreTool';
16
19
 
17
20
  export type { AgentTool, ToolContext, ToolParameter } from './types';
@@ -0,0 +1,33 @@
1
+ import type { ToolDefinition } from '../core/types';
2
+ import { globalZoneRegistry } from '../core/ZoneRegistry';
3
+ import { logger } from '../utils/logger';
4
+
5
+ export function createRestoreTool(): ToolDefinition {
6
+ return {
7
+ name: 'restore_zone',
8
+ description: 'Restore a specific Zone to its default state, reversing any previous simplify_zone or inject_card operations.',
9
+ parameters: {
10
+ zoneId: {
11
+ type: 'string',
12
+ description: 'The ID of the AIZone to restore',
13
+ required: true,
14
+ }
15
+ },
16
+ execute: async (args) => {
17
+ const zoneId = String(args.zoneId);
18
+
19
+ const zone = globalZoneRegistry.get(zoneId) as any;
20
+ if (!zone) {
21
+ return `❌ Cannot restore zone "${zoneId}": Zone does not exist.`;
22
+ }
23
+
24
+ if (zone._controller) {
25
+ zone._controller.restore();
26
+ logger.info('RestoreTool', `Restored zone: ${zoneId}`);
27
+ return `✅ Successfully restored zone "${zoneId}" to its default state.`;
28
+ }
29
+
30
+ return `❌ Cannot restore zone "${zoneId}": Controller not attached.`;
31
+ },
32
+ };
33
+ }
@@ -0,0 +1,33 @@
1
+ import type { ToolDefinition } from '../core/types';
2
+ import { globalZoneRegistry } from '../core/ZoneRegistry';
3
+ import { logger } from '../utils/logger';
4
+
5
+ export function createSimplifyTool(): ToolDefinition {
6
+ return {
7
+ name: 'simplify_zone',
8
+ description: 'Simplify the UI in a specific Zone by telling it to hide elements marked as aiPriority="low". Use this when a screen zone looks cluttered and you want to reduce cognitive load for the user.',
9
+ parameters: {
10
+ zoneId: {
11
+ type: 'string',
12
+ description: 'The ID of the AIZone you want to simplify (e.g. from the screen layout context)',
13
+ required: true,
14
+ }
15
+ },
16
+ execute: async (args) => {
17
+ const zoneId = String(args.zoneId);
18
+
19
+ if (!globalZoneRegistry.isActionAllowed(zoneId, 'simplify')) {
20
+ return `❌ Cannot simplify zone "${zoneId}": Zone does not exist or allowSimplify is false.`;
21
+ }
22
+
23
+ const zone = globalZoneRegistry.get(zoneId) as any;
24
+ if (zone && zone._controller) {
25
+ zone._controller.simplify();
26
+ logger.info('SimplifyTool', `Simplified zone: ${zoneId}`);
27
+ return `✅ Successfully requested simplification for zone "${zoneId}".`;
28
+ }
29
+
30
+ return `❌ Cannot simplify zone "${zoneId}": Controller not attached. Is the zone currently rendered on screen?`;
31
+ },
32
+ };
33
+ }
@@ -53,4 +53,6 @@ export interface ToolContext {
53
53
  buildNestedParams?: (path: string[], params?: any) => any;
54
54
  /** Capture screenshot (optional) */
55
55
  captureScreenshot?: () => Promise<string | null>;
56
+ /** Get the most recently dehydrated screen (with layout coords) */
57
+ getLastDehydratedRoot?: () => any;
56
58
  }
@@ -0,0 +1,20 @@
1
+ import 'react-native';
2
+
3
+ declare module 'react-native' {
4
+ // Augment core component props to support declarative AI priorities
5
+ interface ViewProps {
6
+ aiPriority?: 'high' | 'low';
7
+ }
8
+ interface TextProps {
9
+ aiPriority?: 'high' | 'low';
10
+ }
11
+ interface PressableProps {
12
+ aiPriority?: 'high' | 'low';
13
+ }
14
+ interface TextInputProps {
15
+ aiPriority?: 'high' | 'low';
16
+ }
17
+ interface ImageProps {
18
+ aiPriority?: 'high' | 'low';
19
+ }
20
+ }