react-native-agentic-ai 0.0.2 → 0.2.0

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 (70) hide show
  1. package/LICENSE +20 -0
  2. package/README.md +253 -14
  3. package/lib/module/components/AIAgent.js +185 -0
  4. package/lib/module/components/AIAgent.js.map +1 -0
  5. package/lib/module/components/AgentChatBar.js +268 -0
  6. package/lib/module/components/AgentChatBar.js.map +1 -0
  7. package/lib/module/components/AgentOverlay.js +53 -0
  8. package/lib/module/components/AgentOverlay.js.map +1 -0
  9. package/lib/module/core/AgentRuntime.js +640 -0
  10. package/lib/module/core/AgentRuntime.js.map +1 -0
  11. package/lib/module/core/FiberTreeWalker.js +362 -0
  12. package/lib/module/core/FiberTreeWalker.js.map +1 -0
  13. package/lib/module/core/MCPBridge.js +98 -0
  14. package/lib/module/core/MCPBridge.js.map +1 -0
  15. package/lib/module/core/ScreenDehydrator.js +46 -0
  16. package/lib/module/core/ScreenDehydrator.js.map +1 -0
  17. package/lib/module/core/systemPrompt.js +164 -0
  18. package/lib/module/core/systemPrompt.js.map +1 -0
  19. package/lib/module/core/types.js +2 -0
  20. package/lib/module/core/types.js.map +1 -0
  21. package/lib/module/hooks/useAction.js +32 -0
  22. package/lib/module/hooks/useAction.js.map +1 -0
  23. package/lib/module/index.js +17 -0
  24. package/lib/module/index.js.map +1 -0
  25. package/lib/module/package.json +1 -0
  26. package/lib/module/providers/GeminiProvider.js +294 -0
  27. package/lib/module/providers/GeminiProvider.js.map +1 -0
  28. package/lib/module/utils/logger.js +17 -0
  29. package/lib/module/utils/logger.js.map +1 -0
  30. package/lib/typescript/package.json +1 -0
  31. package/lib/typescript/src/components/AIAgent.d.ts +65 -0
  32. package/lib/typescript/src/components/AIAgent.d.ts.map +1 -0
  33. package/lib/typescript/src/components/AgentChatBar.d.ts +15 -0
  34. package/lib/typescript/src/components/AgentChatBar.d.ts.map +1 -0
  35. package/lib/typescript/src/components/AgentOverlay.d.ts +10 -0
  36. package/lib/typescript/src/components/AgentOverlay.d.ts.map +1 -0
  37. package/lib/typescript/src/core/AgentRuntime.d.ts +53 -0
  38. package/lib/typescript/src/core/AgentRuntime.d.ts.map +1 -0
  39. package/lib/typescript/src/core/FiberTreeWalker.d.ts +31 -0
  40. package/lib/typescript/src/core/FiberTreeWalker.d.ts.map +1 -0
  41. package/lib/typescript/src/core/MCPBridge.d.ts +23 -0
  42. package/lib/typescript/src/core/MCPBridge.d.ts.map +1 -0
  43. package/lib/typescript/src/core/ScreenDehydrator.d.ts +20 -0
  44. package/lib/typescript/src/core/ScreenDehydrator.d.ts.map +1 -0
  45. package/lib/typescript/src/core/systemPrompt.d.ts +9 -0
  46. package/lib/typescript/src/core/systemPrompt.d.ts.map +1 -0
  47. package/lib/typescript/src/core/types.d.ts +176 -0
  48. package/lib/typescript/src/core/types.d.ts.map +1 -0
  49. package/lib/typescript/src/hooks/useAction.d.ts +13 -0
  50. package/lib/typescript/src/hooks/useAction.d.ts.map +1 -0
  51. package/lib/typescript/src/index.d.ts +10 -0
  52. package/lib/typescript/src/index.d.ts.map +1 -0
  53. package/lib/typescript/src/providers/GeminiProvider.d.ts +43 -0
  54. package/lib/typescript/src/providers/GeminiProvider.d.ts.map +1 -0
  55. package/lib/typescript/src/utils/logger.d.ts +7 -0
  56. package/lib/typescript/src/utils/logger.d.ts.map +1 -0
  57. package/package.json +135 -12
  58. package/src/components/AIAgent.tsx +262 -0
  59. package/src/components/AgentChatBar.tsx +258 -0
  60. package/src/components/AgentOverlay.tsx +48 -0
  61. package/src/core/AgentRuntime.ts +661 -0
  62. package/src/core/FiberTreeWalker.ts +404 -0
  63. package/src/core/MCPBridge.ts +110 -0
  64. package/src/core/ScreenDehydrator.ts +53 -0
  65. package/src/core/systemPrompt.ts +162 -0
  66. package/src/core/types.ts +233 -0
  67. package/src/hooks/useAction.ts +40 -0
  68. package/src/index.ts +22 -0
  69. package/src/providers/GeminiProvider.ts +283 -0
  70. package/src/utils/logger.ts +21 -0
@@ -0,0 +1,164 @@
1
+ "use strict";
2
+
3
+ /**
4
+ * System prompt for the AI agent — adapted from page-agent reference.
5
+ *
6
+ * Separated into its own file for maintainability.
7
+ * The prompt uses XML-style tags (matching page-agent's structure)
8
+ * to give the LLM clear, structured instructions.
9
+ */
10
+
11
+ export function buildSystemPrompt(language) {
12
+ const isArabic = language === 'ar';
13
+ return `You are an AI agent designed to operate in an iterative loop to automate tasks in a React Native mobile app. Your ultimate goal is accomplishing the task provided in <user_request>.
14
+
15
+ <intro>
16
+ You excel at the following tasks:
17
+ 1. Reading and understanding mobile app screens to extract precise information
18
+ 2. Automating UI interactions like tapping buttons and filling forms
19
+ 3. Gathering information from the screen and reporting it to the user
20
+ 4. Operating effectively in an agent loop
21
+ 5. Answering user questions based on what is visible on screen
22
+ </intro>
23
+
24
+ <language_settings>
25
+ ${isArabic ? '- Working language: **Arabic**. Respond in Arabic.' : '- Working language: **English**. Respond in English.'}
26
+ - Use the language that the user is using. Return in user's language.
27
+ </language_settings>
28
+
29
+ <input>
30
+ At every step, your input will consist of:
31
+ 1. <agent_history>: Your previous steps and their results.
32
+ 2. <user_request>: The user's original request.
33
+ 3. <screen_state>: Current screen name, available screens, and interactive elements indexed for actions.
34
+
35
+ Agent history uses the following format per step:
36
+ <step_N>
37
+ Previous Goal Eval: Assessment of last action
38
+ Memory: Key facts to remember
39
+ Plan: What you did next
40
+ Action Result: Result of the action
41
+ </step_N>
42
+
43
+ System messages may appear as <sys>...</sys> between steps.
44
+ </input>
45
+
46
+ <screen_state>
47
+ Interactive elements are listed as [index]<type attrs>label />
48
+ - index: numeric identifier for interaction
49
+ - type: element type (pressable, text-input, switch)
50
+ - attrs: state attributes like value="true", checked="false", role="switch"
51
+ - label: visible text content of the element
52
+
53
+ Only elements with [index] are interactive. Use the index to tap or type into them.
54
+ Pure text elements without [] are NOT interactive — they are informational content you can read.
55
+ </screen_state>
56
+
57
+ <tools>
58
+ Available tools:
59
+ - tap(index): Tap an interactive element by its index. Works universally on buttons, switches, and custom components. For switches, this toggles their state.
60
+ - type(index, text): Type text into a text-input element by its index.
61
+ - navigate(screen, params): Navigate to a specific screen. params is optional JSON object.
62
+ - done(text, success): Complete task. Text is your final response to the user — keep it concise unless the user explicitly asks for detail.
63
+ - ask_user(question): Ask the user for clarification ONLY when you cannot determine what action to take.
64
+ </tools>
65
+
66
+ <rules>
67
+ - There are 2 types of requests — always determine which type BEFORE acting:
68
+ 1. Information requests (e.g. "what's available?", "how much is X?", "list the items"):
69
+ Read the screen content and call done() with the answer. Do NOT perform any tap/type/navigate actions.
70
+ 2. Action requests (e.g. "add margherita to cart", "go to checkout", "fill in my name"):
71
+ Execute the required UI interactions using tap/type/navigate tools.
72
+ - For action requests, determine whether the user gave specific step-by-step instructions or an open-ended task:
73
+ 1. Specific instructions: Follow each step precisely, do not skip.
74
+ 2. Open-ended tasks: Plan the steps yourself.
75
+ - Only interact with elements that have an [index].
76
+ - After tapping an element, the screen may change. Wait for the next step to see updated elements.
77
+ - If the current screen doesn't have what you need, use navigate() to go to another screen.
78
+ - If a tap navigates to another screen, the next step will show the new screen's elements.
79
+ - Do not repeat one action for more than 3 times unless some conditions changed.
80
+ - After typing into a text input, check if the screen changed (e.g., suggestions or autocomplete appeared). If so, interact with the new elements.
81
+ - After typing into a search field, you may need to tap a search button, press enter, or select from a dropdown to complete the search.
82
+ - If the user request includes specific details (product type, price, category), use available filters or search to be more efficient.
83
+ - Do not fill in login/signup forms unless the user provides credentials. If asked to log in, use ask_user to request their email and password first.
84
+ - Do not guess or auto-fill sensitive data (passwords, payment info, personal details). Always ask the user.
85
+ - Trying too hard can be harmful. If stuck, call done() with partial results rather than repeating failed actions.
86
+ - If you do not know how to proceed with the current screen, use ask_user to request specific instructions from the user.
87
+ </rules>
88
+
89
+ <task_completion_rules>
90
+ You must call the done action in one of these cases:
91
+ - When you have fully completed the USER REQUEST.
92
+ - When the user asked for information and you can see the answer on screen.
93
+ - When you reach the final allowed step, even if the task is incomplete.
94
+ - When you feel stuck or unable to solve the user request.
95
+
96
+ BEFORE calling done() for action requests that changed state (added items, submitted forms, etc.):
97
+ 1. First, navigate to the result screen (e.g., Cart, confirmation, order summary) so the user can see the outcome.
98
+ 2. Wait for the next step to see the result screen content.
99
+ 3. THEN call done() with a summary of what you did.
100
+ Do NOT call done() immediately after the last action — the user needs to SEE the result.
101
+
102
+ The done action is your opportunity to communicate findings and provide a coherent reply to the user:
103
+ - Set success to true only if the full USER REQUEST has been completed.
104
+ - Use the text field to answer questions, summarize what you found, or explain what you did.
105
+ - You are ONLY ALLOWED to call done as a single action. Do not call it together with other actions.
106
+
107
+ The ask_user action should ONLY be used when the user gave an action request but you lack specific information to execute it (e.g., user says "order a pizza" but there are multiple options and you don't know which one).
108
+ - Do NOT use ask_user to confirm actions the user explicitly requested. If they said "place my order", just do it.
109
+ - NEVER ask for the same confirmation twice. If the user already answered, proceed with their answer.
110
+ - For destructive/purchase actions (place order, delete, pay), tap the button exactly ONCE. Do not repeat the same action — the user could be charged multiple times.
111
+ </task_completion_rules>
112
+
113
+ <capability>
114
+ - It is ok to just provide information without performing any actions.
115
+ - User can ask questions about what's on screen — answer them directly via done().
116
+ - It is ok to fail the task. User would rather you report failure than repeat failed actions endlessly.
117
+ - The user can be wrong. If the request is not achievable, tell the user via done().
118
+ - The app can have bugs. If something is not working as expected, report it to the user.
119
+ </capability>
120
+
121
+ <ux_rules>
122
+ UX best practices for mobile agent interactions:
123
+ - Confirm what you did: When completing actions, summarize exactly what happened (e.g., "Added 2x Margherita ($10 each) to your cart. Total: $20").
124
+ - Be transparent about errors: If an action fails, explain what failed and why — do not silently skip it or pretend it succeeded.
125
+ - Track multi-item progress: For requests involving multiple items, keep track and report which ones succeeded and which did not.
126
+ - Stay on the user's screen: For information requests, read from the current screen. Only navigate away if the needed information is on another screen.
127
+ - Fail gracefully: If stuck after multiple attempts, call done() with what you accomplished and what remains, rather than repeating failed actions.
128
+ - Be concise: Keep responses short and actionable. Users are on mobile — avoid walls of text.
129
+ - Suggest next steps: After completing an action, briefly suggest what the user might want to do next (e.g., "Added to cart. Would you like to checkout or add more items?").
130
+ - When a request is ambiguous, pick the most common interpretation rather than always asking. State your assumption in the done() text.
131
+ </ux_rules>
132
+
133
+ <reasoning_rules>
134
+ Exhibit the following reasoning patterns to successfully achieve the <user_request>:
135
+ - Reason about <agent_history> to track progress and context toward <user_request>.
136
+ - Analyze the most recent action result in <agent_history> and clearly state what you previously tried to achieve.
137
+ - Explicitly judge success/failure of the last action. If the expected change is missing, mark the last action as failed and plan a recovery.
138
+ - Analyze whether you are stuck, e.g. when you repeat the same actions multiple times without any progress. Then consider alternative approaches.
139
+ - If you see information relevant to <user_request>, include it in your response via done().
140
+ - Always compare the current trajectory with the user request — make sure every action moves you closer to the goal.
141
+ - Save important information to memory: field values you collected, items found, pages visited, etc.
142
+ </reasoning_rules>
143
+
144
+ <output>
145
+ You MUST call the agent_step tool on every step. Provide:
146
+
147
+ 1. previous_goal_eval: "One-sentence result of your last action — success, failure, or uncertain. Skip on first step."
148
+ 2. memory: "Key facts to persist: values collected, items found, progress so far. Be specific."
149
+ 3. plan: "Your immediate next goal — what action you will take and why."
150
+ 4. action_name: Choose one action to execute
151
+ 5. Action parameters (index, text, screen, etc. depending on the action)
152
+
153
+ Examples:
154
+
155
+ previous_goal_eval: "Typed email into field [0]. Verdict: Success"
156
+ memory: "Email: user@test.com entered. Still need password."
157
+ plan: "Ask the user for their password using ask_user."
158
+
159
+ previous_goal_eval: "Navigated to Cart screen. Verdict: Success"
160
+ memory: "Added 2x Margherita pizza. Cart total visible."
161
+ plan: "Call done to report the cart contents to the user."
162
+ </output>`;
163
+ }
164
+ //# sourceMappingURL=systemPrompt.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["buildSystemPrompt","language","isArabic"],"sourceRoot":"../../../src","sources":["core/systemPrompt.ts"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,OAAO,SAASA,iBAAiBA,CAACC,QAAgB,EAAU;EAC1D,MAAMC,QAAQ,GAAGD,QAAQ,KAAK,IAAI;EAElC,OAAO;AACT;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,EAAEC,QAAQ,GAAG,oDAAoD,GAAG,sDAAsD;AAC1H;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,UAAU;AACV","ignoreList":[]}
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sourceRoot":"../../../src","sources":["core/types.ts"],"mappings":"","ignoreList":[]}
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+
3
+ /**
4
+ * useAction — Optional hook to register non-UI actions for the AI agent.
5
+ *
6
+ * Use this for business logic that doesn't correspond to a visible UI element,
7
+ * e.g., API calls, cart operations, calculations.
8
+ *
9
+ * The Fiber tree walker handles visible UI elements automatically.
10
+ * useAction is for invisible operations the AI should be able to trigger.
11
+ */
12
+
13
+ import { useEffect, useContext, createContext } from 'react';
14
+ // Re-export context creation — AIAgent.tsx will provide the value
15
+ export const AgentContext = /*#__PURE__*/createContext(null);
16
+ export function useAction(name, description, parameters, handler) {
17
+ const agentRuntime = useContext(AgentContext);
18
+ useEffect(() => {
19
+ if (!agentRuntime) return;
20
+ agentRuntime.registerAction({
21
+ name,
22
+ description,
23
+ parameters,
24
+ handler
25
+ });
26
+ return () => {
27
+ agentRuntime.unregisterAction(name);
28
+ };
29
+ // eslint-disable-next-line react-hooks/exhaustive-deps
30
+ }, [name, description]);
31
+ }
32
+ //# sourceMappingURL=useAction.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["useEffect","useContext","createContext","AgentContext","useAction","name","description","parameters","handler","agentRuntime","registerAction","unregisterAction"],"sourceRoot":"../../../src","sources":["hooks/useAction.ts"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAASA,SAAS,EAAEC,UAAU,EAAEC,aAAa,QAAQ,OAAO;AAG5D;AACA,OAAO,MAAMC,YAAY,gBAAGD,aAAa,CAAsB,IAAI,CAAC;AAEpE,OAAO,SAASE,SAASA,CACvBC,IAAY,EACZC,WAAmB,EACnBC,UAAkC,EAClCC,OAA2C,EACrC;EACN,MAAMC,YAAY,GAAGR,UAAU,CAACE,YAAY,CAAC;EAE7CH,SAAS,CAAC,MAAM;IACd,IAAI,CAACS,YAAY,EAAE;IAEnBA,YAAY,CAACC,cAAc,CAAC;MAC1BL,IAAI;MACJC,WAAW;MACXC,UAAU;MACVC;IACF,CAAC,CAAC;IAEF,OAAO,MAAM;MACXC,YAAY,CAACE,gBAAgB,CAACN,IAAI,CAAC;IACrC,CAAC;IACD;EACF,CAAC,EAAE,CAACA,IAAI,EAAEC,WAAW,CAAC,CAAC;AACzB","ignoreList":[]}
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+
3
+ /**
4
+ * @mobileai/react-native — Page-Agent Architecture
5
+ *
6
+ * Zero-wrapper AI agent for React Native.
7
+ * Auto-detects interactive elements via React Fiber tree traversal.
8
+ */
9
+
10
+ // ─── Components ──────────────────────────────────────────────
11
+ export { AIAgent } from "./components/AIAgent.js";
12
+
13
+ // ─── Hooks ───────────────────────────────────────────────────
14
+ export { useAction } from "./hooks/useAction.js";
15
+
16
+ // ─── Types ───────────────────────────────────────────────────
17
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["AIAgent","useAction"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA,SAASA,OAAO,QAAQ,yBAAsB;;AAE9C;AACA,SAASC,SAAS,QAAQ,sBAAmB;;AAE7C","ignoreList":[]}
@@ -0,0 +1 @@
1
+ {"type":"module"}
@@ -0,0 +1,294 @@
1
+ "use strict";
2
+
3
+ /**
4
+ * GeminiProvider — Gemini API integration with structured action pattern.
5
+ *
6
+ * Uses a single forced function call (`agent_step`) that bundles
7
+ * structured reasoning (evaluation, memory, plan) alongside the action.
8
+ * This replaces free-form text + separate tool calls for stability.
9
+ */
10
+
11
+ import { logger } from "../utils/logger.js";
12
+ // ─── Constants ─────────────────────────────────────────────────
13
+
14
+ const AGENT_STEP_FN = 'agent_step';
15
+
16
+ // Reasoning fields that are always present in the agent_step schema
17
+ const REASONING_FIELDS = ['previous_goal_eval', 'memory', 'plan'];
18
+
19
+ // ─── Gemini API Types ──────────────────────────────────────────
20
+
21
+ // ─── Provider ──────────────────────────────────────────────────
22
+
23
+ export class GeminiProvider {
24
+ constructor(apiKey, model = 'gemini-2.5-flash') {
25
+ this.apiKey = apiKey;
26
+ this.model = model;
27
+ }
28
+ async generateContent(systemPrompt, userMessage, tools, history) {
29
+ logger.info('GeminiProvider', `Sending request. Model: ${this.model}, Tools: ${tools.length}`);
30
+
31
+ // Build single agent_step function declaration
32
+ const agentStepDeclaration = this.buildAgentStepDeclaration(tools);
33
+
34
+ // Build conversation history with proper function call/response pairs
35
+ const contents = this.buildContents(userMessage, history);
36
+
37
+ // Make API request
38
+ const url = `https://generativelanguage.googleapis.com/v1beta/models/${this.model}:generateContent?key=${this.apiKey}`;
39
+ const body = {
40
+ contents,
41
+ tools: [{
42
+ functionDeclarations: [agentStepDeclaration]
43
+ }],
44
+ systemInstruction: {
45
+ parts: [{
46
+ text: systemPrompt
47
+ }]
48
+ },
49
+ // Force the model to always call agent_step
50
+ tool_config: {
51
+ function_calling_config: {
52
+ mode: 'ANY',
53
+ allowed_function_names: [AGENT_STEP_FN]
54
+ }
55
+ },
56
+ generationConfig: {
57
+ temperature: 0.2,
58
+ maxOutputTokens: 2048
59
+ }
60
+ };
61
+ const startTime = Date.now();
62
+ try {
63
+ const response = await fetch(url, {
64
+ method: 'POST',
65
+ headers: {
66
+ 'Content-Type': 'application/json'
67
+ },
68
+ body: JSON.stringify(body)
69
+ });
70
+ const elapsed = Date.now() - startTime;
71
+ logger.info('GeminiProvider', `Response received in ${elapsed}ms`);
72
+ if (!response.ok) {
73
+ const errorText = await response.text();
74
+ logger.error('GeminiProvider', `API error ${response.status}: ${errorText}`);
75
+ throw new Error(`Gemini API error ${response.status}: ${errorText}`);
76
+ }
77
+ const data = await response.json();
78
+ return this.parseAgentStepResponse(data, tools);
79
+ } catch (error) {
80
+ logger.error('GeminiProvider', 'Request failed:', error.message);
81
+ throw error;
82
+ }
83
+ }
84
+
85
+ // ─── Build agent_step Declaration ──────────────────────────
86
+
87
+ /**
88
+ * Builds a single `agent_step` function declaration that combines:
89
+ * - Structured reasoning fields (previous_goal_eval, memory, plan)
90
+ * - action_name (enum of all available tool names)
91
+ * - All tool parameter fields as flat top-level properties
92
+ *
93
+ * Flat schema avoids Gemini's "deeply nested schema" rejection in ANY mode.
94
+ */
95
+ buildAgentStepDeclaration(tools) {
96
+ const toolNames = tools.map(t => t.name);
97
+
98
+ // Collect all unique parameter fields across all tools
99
+ const actionProperties = {};
100
+ for (const tool of tools) {
101
+ for (const [paramName, param] of Object.entries(tool.parameters)) {
102
+ // Skip if already added (shared field names like 'text', 'index')
103
+ if (actionProperties[paramName]) continue;
104
+ actionProperties[paramName] = {
105
+ type: this.mapParamType(param.type),
106
+ description: param.description,
107
+ ...(param.enum ? {
108
+ enum: param.enum
109
+ } : {})
110
+ };
111
+ }
112
+ }
113
+
114
+ // Build tool descriptions for the action_name enum
115
+ const toolDescriptions = tools.map(t => {
116
+ const params = Object.keys(t.parameters).join(', ');
117
+ return `- ${t.name}(${params}): ${t.description}`;
118
+ }).join('\n');
119
+ return {
120
+ name: AGENT_STEP_FN,
121
+ description: `Execute one agent step. Choose an action and provide reasoning.\n\nAvailable actions:\n${toolDescriptions}`,
122
+ parameters: {
123
+ type: 'OBJECT',
124
+ properties: {
125
+ // ── Reasoning fields ──
126
+ previous_goal_eval: {
127
+ type: 'STRING',
128
+ description: 'One-sentence assessment of your last action. State success, failure, or uncertain. Skip on first step.'
129
+ },
130
+ memory: {
131
+ type: 'STRING',
132
+ description: 'Key facts to remember for future steps: progress made, items found, counters, field values already collected.'
133
+ },
134
+ plan: {
135
+ type: 'STRING',
136
+ description: 'Your immediate next goal — what action you will take and why.'
137
+ },
138
+ // ── Action selection ──
139
+ action_name: {
140
+ type: 'STRING',
141
+ description: 'Which action to execute.',
142
+ enum: toolNames
143
+ },
144
+ // ── Action parameters (flat) ──
145
+ ...actionProperties
146
+ },
147
+ required: ['plan', 'action_name']
148
+ }
149
+ };
150
+ }
151
+ mapParamType(type) {
152
+ switch (type) {
153
+ case 'number':
154
+ return 'NUMBER';
155
+ case 'integer':
156
+ return 'INTEGER';
157
+ case 'boolean':
158
+ return 'BOOLEAN';
159
+ case 'string':
160
+ default:
161
+ return 'STRING';
162
+ }
163
+ }
164
+
165
+ // ─── Build Contents ────────────────────────────────────────
166
+
167
+ /**
168
+ * Builds Gemini conversation contents.
169
+ *
170
+ * Each step is a STATELESS single-turn request (matching page-agent's approach):
171
+ * - System prompt has general instructions
172
+ * - User message contains full context: task, history, screen state
173
+ * - Model responds with agent_step function call
174
+ *
175
+ * History is embedded as text in assembleUserPrompt (via <agent_history>),
176
+ * NOT as functionCall/functionResponse pairs. This avoids Gemini's
177
+ * conversation format requirements and thought_signature complexity.
178
+ */
179
+ buildContents(userMessage, _history) {
180
+ return [{
181
+ role: 'user',
182
+ parts: [{
183
+ text: userMessage
184
+ }]
185
+ }];
186
+ }
187
+
188
+ // ─── Parse Response ────────────────────────────────────────
189
+
190
+ /**
191
+ * Parses the Gemini response expecting a single agent_step function call.
192
+ * Extracts structured reasoning + action, and determines which tool to execute.
193
+ */
194
+ parseAgentStepResponse(data, tools) {
195
+ if (!data.candidates || data.candidates.length === 0) {
196
+ logger.warn('GeminiProvider', 'No candidates in response');
197
+ return {
198
+ toolCalls: [{
199
+ name: 'done',
200
+ args: {
201
+ text: 'No response generated.',
202
+ success: false
203
+ }
204
+ }],
205
+ reasoning: {
206
+ previousGoalEval: '',
207
+ memory: '',
208
+ plan: ''
209
+ },
210
+ text: 'No response generated.'
211
+ };
212
+ }
213
+ const candidate = data.candidates[0];
214
+ const parts = candidate.content?.parts || [];
215
+
216
+ // Find the function call part
217
+ const fnCallPart = parts.find(p => p.functionCall);
218
+ const textPart = parts.find(p => p.text);
219
+ if (!fnCallPart?.functionCall) {
220
+ logger.warn('GeminiProvider', 'No function call in response. Text:', textPart?.text);
221
+ return {
222
+ toolCalls: [{
223
+ name: 'done',
224
+ args: {
225
+ text: textPart?.text || 'No action taken.',
226
+ success: false
227
+ }
228
+ }],
229
+ reasoning: {
230
+ previousGoalEval: '',
231
+ memory: '',
232
+ plan: ''
233
+ },
234
+ text: textPart?.text
235
+ };
236
+ }
237
+ const args = fnCallPart.functionCall.args || {};
238
+
239
+ // Extract reasoning fields
240
+ const reasoning = {
241
+ previousGoalEval: args.previous_goal_eval || '',
242
+ memory: args.memory || '',
243
+ plan: args.plan || ''
244
+ };
245
+
246
+ // Extract action
247
+ const actionName = args.action_name;
248
+ if (!actionName) {
249
+ logger.warn('GeminiProvider', 'No action_name in agent_step. Falling back to done.');
250
+ return {
251
+ toolCalls: [{
252
+ name: 'done',
253
+ args: {
254
+ text: 'Agent did not choose an action.',
255
+ success: false
256
+ }
257
+ }],
258
+ reasoning,
259
+ text: textPart?.text
260
+ };
261
+ }
262
+
263
+ // Build action args: everything except reasoning fields and action_name
264
+ const actionArgs = {};
265
+ const reservedKeys = new Set([...REASONING_FIELDS, 'action_name']);
266
+
267
+ // Find the matching tool to know which params belong to it
268
+ const matchedTool = tools.find(t => t.name === actionName);
269
+ if (matchedTool) {
270
+ for (const paramName of Object.keys(matchedTool.parameters)) {
271
+ if (args[paramName] !== undefined) {
272
+ actionArgs[paramName] = args[paramName];
273
+ }
274
+ }
275
+ } else {
276
+ // Custom/registered tool — grab all non-reserved fields
277
+ for (const [key, value] of Object.entries(args)) {
278
+ if (!reservedKeys.has(key)) {
279
+ actionArgs[key] = value;
280
+ }
281
+ }
282
+ }
283
+ logger.info('GeminiProvider', `Parsed: action=${actionName}, plan="${reasoning.plan}"`);
284
+ return {
285
+ toolCalls: [{
286
+ name: actionName,
287
+ args: actionArgs
288
+ }],
289
+ reasoning,
290
+ text: textPart?.text
291
+ };
292
+ }
293
+ }
294
+ //# sourceMappingURL=GeminiProvider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["logger","AGENT_STEP_FN","REASONING_FIELDS","GeminiProvider","constructor","apiKey","model","generateContent","systemPrompt","userMessage","tools","history","info","length","agentStepDeclaration","buildAgentStepDeclaration","contents","buildContents","url","body","functionDeclarations","systemInstruction","parts","text","tool_config","function_calling_config","mode","allowed_function_names","generationConfig","temperature","maxOutputTokens","startTime","Date","now","response","fetch","method","headers","JSON","stringify","elapsed","ok","errorText","error","status","Error","data","json","parseAgentStepResponse","message","toolNames","map","t","name","actionProperties","tool","paramName","param","Object","entries","parameters","type","mapParamType","description","enum","toolDescriptions","params","keys","join","properties","previous_goal_eval","memory","plan","action_name","required","_history","role","candidates","warn","toolCalls","args","success","reasoning","previousGoalEval","candidate","content","fnCallPart","find","p","functionCall","textPart","actionName","actionArgs","reservedKeys","Set","matchedTool","undefined","key","value","has"],"sourceRoot":"../../../src","sources":["providers/GeminiProvider.ts"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAASA,MAAM,QAAQ,oBAAiB;AAGxC;;AAEA,MAAMC,aAAa,GAAG,YAAY;;AAElC;AACA,MAAMC,gBAAgB,GAAG,CAAC,oBAAoB,EAAE,QAAQ,EAAE,MAAM,CAAU;;AAE1E;;AAWA;;AAEA,OAAO,MAAMC,cAAc,CAAuB;EAIhDC,WAAWA,CAACC,MAAc,EAAEC,KAAa,GAAG,kBAAkB,EAAE;IAC9D,IAAI,CAACD,MAAM,GAAGA,MAAM;IACpB,IAAI,CAACC,KAAK,GAAGA,KAAK;EACpB;EAEA,MAAMC,eAAeA,CACnBC,YAAoB,EACpBC,WAAmB,EACnBC,KAAuB,EACvBC,OAAoB,EACK;IAEzBX,MAAM,CAACY,IAAI,CAAC,gBAAgB,EAAE,2BAA2B,IAAI,CAACN,KAAK,YAAYI,KAAK,CAACG,MAAM,EAAE,CAAC;;IAE9F;IACA,MAAMC,oBAAoB,GAAG,IAAI,CAACC,yBAAyB,CAACL,KAAK,CAAC;;IAElE;IACA,MAAMM,QAAQ,GAAG,IAAI,CAACC,aAAa,CAACR,WAAW,EAAEE,OAAO,CAAC;;IAEzD;IACA,MAAMO,GAAG,GAAG,2DAA2D,IAAI,CAACZ,KAAK,wBAAwB,IAAI,CAACD,MAAM,EAAE;IAEtH,MAAMc,IAAS,GAAG;MAChBH,QAAQ;MACRN,KAAK,EAAE,CAAC;QAAEU,oBAAoB,EAAE,CAACN,oBAAoB;MAAE,CAAC,CAAC;MACzDO,iBAAiB,EAAE;QAAEC,KAAK,EAAE,CAAC;UAAEC,IAAI,EAAEf;QAAa,CAAC;MAAE,CAAC;MACtD;MACAgB,WAAW,EAAE;QACXC,uBAAuB,EAAE;UACvBC,IAAI,EAAE,KAAK;UAC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ACnDV,SAAS;MACT3D,IAAI,EAAEmE,QAAQ,EAAEnE;IAClB,CAAC;EACH;AACF","ignoreList":[]}
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+
3
+ /**
4
+ * Logger utility — prefixed console output for easy filtering.
5
+ */
6
+ const TAG = '[AIAgent]';
7
+ export const logger = {
8
+ info: (context, ...args) => console.log(`${TAG} [${context}]`, ...args),
9
+ warn: (context, ...args) => console.warn(`${TAG} [${context}]`, ...args),
10
+ error: (context, ...args) => console.error(`${TAG} [${context}]`, ...args),
11
+ debug: (context, ...args) => {
12
+ if (__DEV__) {
13
+ console.log(`${TAG} [${context}] 🐛`, ...args);
14
+ }
15
+ }
16
+ };
17
+ //# sourceMappingURL=logger.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["TAG","logger","info","context","args","console","log","warn","error","debug","__DEV__"],"sourceRoot":"../../../src","sources":["utils/logger.ts"],"mappings":";;AAAA;AACA;AACA;AACA,MAAMA,GAAG,GAAG,WAAW;AAEvB,OAAO,MAAMC,MAAM,GAAG;EACpBC,IAAI,EAAEA,CAACC,OAAe,EAAE,GAAGC,IAAW,KACpCC,OAAO,CAACC,GAAG,CAAC,GAAGN,GAAG,KAAKG,OAAO,GAAG,EAAE,GAAGC,IAAI,CAAC;EAE7CG,IAAI,EAAEA,CAACJ,OAAe,EAAE,GAAGC,IAAW,KACpCC,OAAO,CAACE,IAAI,CAAC,GAAGP,GAAG,KAAKG,OAAO,GAAG,EAAE,GAAGC,IAAI,CAAC;EAE9CI,KAAK,EAAEA,CAACL,OAAe,EAAE,GAAGC,IAAW,KACrCC,OAAO,CAACG,KAAK,CAAC,GAAGR,GAAG,KAAKG,OAAO,GAAG,EAAE,GAAGC,IAAI,CAAC;EAE/CK,KAAK,EAAEA,CAACN,OAAe,EAAE,GAAGC,IAAW,KAAK;IAC1C,IAAIM,OAAO,EAAE;MACXL,OAAO,CAACC,GAAG,CAAC,GAAGN,GAAG,KAAKG,OAAO,MAAM,EAAE,GAAGC,IAAI,CAAC;IAChD;EACF;AACF,CAAC","ignoreList":[]}
@@ -0,0 +1 @@
1
+ {"type":"module"}
@@ -0,0 +1,65 @@
1
+ /**
2
+ * AIAgent — Root provider component for the AI agent.
3
+ *
4
+ * Wraps the app and provides:
5
+ * - Fiber tree root ref for element auto-detection
6
+ * - Navigation ref for auto-navigation
7
+ * - Floating chat bar for user input
8
+ * - Agent runtime context for useAction hooks
9
+ */
10
+ import React from 'react';
11
+ import type { ExecutionResult, ToolDefinition, AgentStep } from '../core/types';
12
+ interface AIAgentProps {
13
+ /** Gemini API key */
14
+ apiKey: string;
15
+ /** Gemini model name */
16
+ model?: string;
17
+ /** Navigation container ref (from useNavigationContainerRef) */
18
+ navRef?: any;
19
+ /** UI language */
20
+ language?: 'en' | 'ar';
21
+ /** Max agent steps per request */
22
+ maxSteps?: number;
23
+ /** Show/hide the chat bar */
24
+ showChatBar?: boolean;
25
+ /** Children — the actual app */
26
+ children: React.ReactNode;
27
+ /** Callback when agent completes */
28
+ onResult?: (result: ExecutionResult) => void;
29
+ /** Refs of elements the AI must NOT interact with */
30
+ interactiveBlacklist?: React.RefObject<any>[];
31
+ /** If set, AI can ONLY interact with these elements */
32
+ interactiveWhitelist?: React.RefObject<any>[];
33
+ /** Called before each step */
34
+ onBeforeStep?: (stepCount: number) => Promise<void> | void;
35
+ /** Called after each step */
36
+ onAfterStep?: (history: AgentStep[]) => Promise<void> | void;
37
+ /** Called before task starts */
38
+ onBeforeTask?: () => Promise<void> | void;
39
+ /** Called after task completes */
40
+ onAfterTask?: (result: ExecutionResult) => Promise<void> | void;
41
+ /** Transform screen content before LLM sees it (for data masking) */
42
+ transformScreenContent?: (content: string) => Promise<string> | string;
43
+ /** Override or remove built-in tools (null = remove) */
44
+ customTools?: Record<string, ToolDefinition | null>;
45
+ /** Instructions to guide agent behavior */
46
+ instructions?: {
47
+ system?: string;
48
+ getScreenInstructions?: (screenName: string) => string | undefined | null;
49
+ };
50
+ /** Delay between steps in ms */
51
+ stepDelay?: number;
52
+ /** WebSocket URL to companion MCP server bridge (e.g., ws://localhost:3101) */
53
+ mcpServerUrl?: string;
54
+ /** Expo Router instance (from useRouter()) */
55
+ router?: {
56
+ push: (href: string) => void;
57
+ replace: (href: string) => void;
58
+ back: () => void;
59
+ };
60
+ /** Expo Router pathname (from usePathname()) */
61
+ pathname?: string;
62
+ }
63
+ export declare function AIAgent({ apiKey, model, navRef, language, maxSteps, showChatBar, children, onResult, interactiveBlacklist, interactiveWhitelist, onBeforeStep, onAfterStep, onBeforeTask, onAfterTask, transformScreenContent, customTools, instructions, stepDelay, mcpServerUrl, router, pathname, }: AIAgentProps): import("react/jsx-runtime").JSX.Element;
64
+ export {};
65
+ //# sourceMappingURL=AIAgent.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AIAgent.d.ts","sourceRoot":"","sources":["../../../../src/components/AIAgent.tsx"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAMN,MAAM,OAAO,CAAC;AASf,OAAO,KAAK,EAAe,eAAe,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAO7F,UAAU,YAAY;IACpB,qBAAqB;IACrB,MAAM,EAAE,MAAM,CAAC;IACf,wBAAwB;IACxB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,gEAAgE;IAChE,MAAM,CAAC,EAAE,GAAG,CAAC;IACb,kBAAkB;IAClB,QAAQ,CAAC,EAAE,IAAI,GAAG,IAAI,CAAC;IACvB,kCAAkC;IAClC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,6BAA6B;IAC7B,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,gCAAgC;IAChC,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;IAC1B,oCAAoC;IACpC,QAAQ,CAAC,EAAE,CAAC,MAAM,EAAE,eAAe,KAAK,IAAI,CAAC;IAI7C,qDAAqD;IACrD,oBAAoB,CAAC,EAAE,KAAK,CAAC,SAAS,C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