@mobileai/react-native 0.1.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 (65) hide show
  1. package/LICENSE +20 -0
  2. package/README.md +190 -0
  3. package/lib/module/components/AIAgent.js +149 -0
  4. package/lib/module/components/AIAgent.js.map +1 -0
  5. package/lib/module/components/AgentChatBar.js +120 -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 +498 -0
  10. package/lib/module/core/AgentRuntime.js.map +1 -0
  11. package/lib/module/core/FiberTreeWalker.js +308 -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/types.js +2 -0
  18. package/lib/module/core/types.js.map +1 -0
  19. package/lib/module/hooks/useAction.js +32 -0
  20. package/lib/module/hooks/useAction.js.map +1 -0
  21. package/lib/module/index.js +17 -0
  22. package/lib/module/index.js.map +1 -0
  23. package/lib/module/package.json +1 -0
  24. package/lib/module/providers/GeminiProvider.js +178 -0
  25. package/lib/module/providers/GeminiProvider.js.map +1 -0
  26. package/lib/module/utils/logger.js +17 -0
  27. package/lib/module/utils/logger.js.map +1 -0
  28. package/lib/typescript/package.json +1 -0
  29. package/lib/typescript/src/components/AIAgent.d.ts +57 -0
  30. package/lib/typescript/src/components/AIAgent.d.ts.map +1 -0
  31. package/lib/typescript/src/components/AgentChatBar.d.ts +14 -0
  32. package/lib/typescript/src/components/AgentChatBar.d.ts.map +1 -0
  33. package/lib/typescript/src/components/AgentOverlay.d.ts +10 -0
  34. package/lib/typescript/src/components/AgentOverlay.d.ts.map +1 -0
  35. package/lib/typescript/src/core/AgentRuntime.d.ts +37 -0
  36. package/lib/typescript/src/core/AgentRuntime.d.ts.map +1 -0
  37. package/lib/typescript/src/core/FiberTreeWalker.d.ts +26 -0
  38. package/lib/typescript/src/core/FiberTreeWalker.d.ts.map +1 -0
  39. package/lib/typescript/src/core/MCPBridge.d.ts +23 -0
  40. package/lib/typescript/src/core/MCPBridge.d.ts.map +1 -0
  41. package/lib/typescript/src/core/ScreenDehydrator.d.ts +20 -0
  42. package/lib/typescript/src/core/ScreenDehydrator.d.ts.map +1 -0
  43. package/lib/typescript/src/core/types.d.ts +138 -0
  44. package/lib/typescript/src/core/types.d.ts.map +1 -0
  45. package/lib/typescript/src/hooks/useAction.d.ts +13 -0
  46. package/lib/typescript/src/hooks/useAction.d.ts.map +1 -0
  47. package/lib/typescript/src/index.d.ts +10 -0
  48. package/lib/typescript/src/index.d.ts.map +1 -0
  49. package/lib/typescript/src/providers/GeminiProvider.d.ts +23 -0
  50. package/lib/typescript/src/providers/GeminiProvider.d.ts.map +1 -0
  51. package/lib/typescript/src/utils/logger.d.ts +7 -0
  52. package/lib/typescript/src/utils/logger.d.ts.map +1 -0
  53. package/package.json +143 -0
  54. package/src/components/AIAgent.tsx +222 -0
  55. package/src/components/AgentChatBar.tsx +136 -0
  56. package/src/components/AgentOverlay.tsx +48 -0
  57. package/src/core/AgentRuntime.ts +505 -0
  58. package/src/core/FiberTreeWalker.ts +349 -0
  59. package/src/core/MCPBridge.ts +110 -0
  60. package/src/core/ScreenDehydrator.ts +53 -0
  61. package/src/core/types.ts +185 -0
  62. package/src/hooks/useAction.ts +40 -0
  63. package/src/index.ts +22 -0
  64. package/src/providers/GeminiProvider.ts +210 -0
  65. package/src/utils/logger.ts +21 -0
@@ -0,0 +1,498 @@
1
+ "use strict";
2
+
3
+ /**
4
+ * AgentRuntime — The main agent loop, inspired by page-agent.js.
5
+ *
6
+ * Flow:
7
+ * 1. Walk Fiber tree → detect interactive elements
8
+ * 2. Dehydrate screen → text for LLM
9
+ * 3. Send to AI provider with tools
10
+ * 4. Parse tool call → execute (tap, type, navigate, done)
11
+ * 5. If not done, repeat from step 1 (re-dehydrate after UI change)
12
+ */
13
+
14
+ import { logger } from "../utils/logger.js";
15
+ import { walkFiberTree } from "./FiberTreeWalker.js";
16
+ import { dehydrateScreen } from "./ScreenDehydrator.js";
17
+ const DEFAULT_MAX_STEPS = 10;
18
+
19
+ // ─── System Prompt ─────────────────────────────────────────────
20
+
21
+ function buildSystemPrompt(language) {
22
+ const isArabic = language === 'ar';
23
+ return `You are an AI agent that controls a React Native mobile app. You operate in an iterative loop to accomplish user requests.
24
+
25
+ ${isArabic ? 'Respond to the user in Arabic.' : 'Respond to the user in English.'}
26
+
27
+ <input>
28
+ At every step you receive:
29
+ 1. <screen_state>: Current screen name, available screens, and interactive elements indexed for actions.
30
+ 2. <agent_history>: Your previous steps and their results.
31
+ 3. <user_request>: The user's original request.
32
+ </input>
33
+
34
+ <screen_state>
35
+ Interactive elements are listed as [index]<type attrs>label</>
36
+ - index: numeric identifier for interaction
37
+ - type: element type (pressable, text-input, switch)
38
+ - label: visible text content of the element
39
+
40
+ Only elements with [index] are interactive. Use the index to tap or type into them.
41
+ </screen_state>
42
+
43
+ <tools>
44
+ Available tools:
45
+ - tap(index): Tap an interactive element by its index. This triggers its onPress handler.
46
+ - type(index, text): Type text into a text-input element by its index.
47
+ - navigate(screen, params): Navigate to a specific screen. params is optional JSON object.
48
+ - done(text, success): Complete the task. text is your response to the user.
49
+ - ask_user(question): Ask the user for clarification if needed.
50
+ </tools>
51
+
52
+ <rules>
53
+ - Only interact with elements that have an [index].
54
+ - After tapping an element, the screen may change. Wait for the next step to see updated elements.
55
+ - If the current screen doesn't have what you need, use navigate() to go to another screen.
56
+ - If you're stuck or need more info, use ask_user().
57
+ - When the task is complete, ALWAYS call done() with a summary.
58
+ - Be efficient — complete tasks in as few steps as possible.
59
+ - If a tap navigates to another screen, the next step will show the new screen's elements.
60
+ </rules>`;
61
+ }
62
+
63
+ // ─── Agent Runtime ─────────────────────────────────────────────
64
+
65
+ export class AgentRuntime {
66
+ tools = new Map();
67
+ actions = new Map();
68
+ history = [];
69
+ isRunning = false;
70
+ lastAskUserQuestion = null;
71
+ constructor(provider, config, rootRef, navRef) {
72
+ this.provider = provider;
73
+ this.config = config;
74
+ this.rootRef = rootRef;
75
+ this.navRef = navRef;
76
+ this.registerBuiltInTools();
77
+
78
+ // Apply customTools — mirrors page-agent: null = remove, otherwise override
79
+ if (config.customTools) {
80
+ for (const [name, tool] of Object.entries(config.customTools)) {
81
+ if (tool === null) {
82
+ this.tools.delete(name);
83
+ logger.info('AgentRuntime', `Removed tool: ${name}`);
84
+ } else {
85
+ this.tools.set(name, tool);
86
+ logger.info('AgentRuntime', `Overrode tool: ${name}`);
87
+ }
88
+ }
89
+ }
90
+ }
91
+
92
+ // ─── Tool Registration ─────────────────────────────────────
93
+
94
+ registerBuiltInTools() {
95
+ // tap — tap an interactive element by index
96
+ this.tools.set('tap', {
97
+ name: 'tap',
98
+ description: 'Tap an interactive element by its index to trigger its onPress handler.',
99
+ parameters: {
100
+ index: {
101
+ type: 'number',
102
+ description: 'The index of the element to tap',
103
+ required: true
104
+ }
105
+ },
106
+ execute: async args => {
107
+ const {
108
+ interactives: elements
109
+ } = walkFiberTree(this.rootRef, this.getWalkConfig());
110
+ const element = elements.find(el => el.index === args.index);
111
+ if (!element) {
112
+ return `❌ Element with index ${args.index} not found. Available indexes: ${elements.map(e => e.index).join(', ')}`;
113
+ }
114
+ if (!element.props.onPress) {
115
+ return `❌ Element [${args.index}] "${element.label}" does not have an onPress handler.`;
116
+ }
117
+ try {
118
+ element.props.onPress();
119
+ // Wait for UI to update after tap
120
+ await new Promise(resolve => setTimeout(resolve, 500));
121
+ return `✅ Tapped [${args.index}] "${element.label}"`;
122
+ } catch (error) {
123
+ return `❌ Error tapping [${args.index}]: ${error.message}`;
124
+ }
125
+ }
126
+ });
127
+
128
+ // type — type text into a TextInput
129
+ this.tools.set('type', {
130
+ name: 'type',
131
+ description: 'Type text into a text-input element by its index.',
132
+ parameters: {
133
+ index: {
134
+ type: 'number',
135
+ description: 'The index of the text-input element',
136
+ required: true
137
+ },
138
+ text: {
139
+ type: 'string',
140
+ description: 'The text to type',
141
+ required: true
142
+ }
143
+ },
144
+ execute: async args => {
145
+ const {
146
+ interactives: elements
147
+ } = walkFiberTree(this.rootRef, this.getWalkConfig());
148
+ const element = elements.find(el => el.index === args.index);
149
+ if (!element) {
150
+ return `❌ Element with index ${args.index} not found.`;
151
+ }
152
+ if (!element.props.onChangeText) {
153
+ return `❌ Element [${args.index}] "${element.label}" is not a text input.`;
154
+ }
155
+ try {
156
+ element.props.onChangeText(args.text);
157
+ return `✅ Typed "${args.text}" into [${args.index}] "${element.label}"`;
158
+ } catch (error) {
159
+ return `❌ Error typing: ${error.message}`;
160
+ }
161
+ }
162
+ });
163
+
164
+ // navigate — navigate to a screen
165
+ this.tools.set('navigate', {
166
+ name: 'navigate',
167
+ description: 'Navigate to a specific screen in the app.',
168
+ parameters: {
169
+ screen: {
170
+ type: 'string',
171
+ description: 'Screen name to navigate to',
172
+ required: true
173
+ },
174
+ params: {
175
+ type: 'string',
176
+ description: 'Optional JSON params object',
177
+ required: false
178
+ }
179
+ },
180
+ execute: async args => {
181
+ if (!this.navRef) {
182
+ return '❌ Navigation ref not available.';
183
+ }
184
+ // Per React Navigation docs: must check isReady() before navigate
185
+ // https://reactnavigation.org/docs/navigating-without-navigation-prop#handling-initialization
186
+ if (!this.navRef.isReady()) {
187
+ // Wait a bit and retry — navigator may still be mounting
188
+ await new Promise(resolve => setTimeout(resolve, 1000));
189
+ if (!this.navRef.isReady()) {
190
+ return '❌ Navigation is not ready yet. The navigator may not have finished mounting.';
191
+ }
192
+ }
193
+ try {
194
+ const params = args.params ? typeof args.params === 'string' ? JSON.parse(args.params) : args.params : undefined;
195
+ this.navRef.navigate(args.screen, params);
196
+ await new Promise(resolve => setTimeout(resolve, 500));
197
+ return `✅ Navigated to "${args.screen}"${params ? ` with params: ${JSON.stringify(params)}` : ''}`;
198
+ } catch (error) {
199
+ return `❌ Navigation error: ${error.message}. Available screens: ${this.getRouteNames().join(', ')}`;
200
+ }
201
+ }
202
+ });
203
+
204
+ // done — complete the task
205
+ this.tools.set('done', {
206
+ name: 'done',
207
+ description: 'Complete the task with a message to the user.',
208
+ parameters: {
209
+ text: {
210
+ type: 'string',
211
+ description: 'Response message to the user',
212
+ required: true
213
+ },
214
+ success: {
215
+ type: 'boolean',
216
+ description: 'Whether the task was completed successfully',
217
+ required: true
218
+ }
219
+ },
220
+ execute: async args => {
221
+ return args.text;
222
+ }
223
+ });
224
+
225
+ // ask_user — ask for clarification
226
+ this.tools.set('ask_user', {
227
+ name: 'ask_user',
228
+ description: 'Ask the user for clarification or more information.',
229
+ parameters: {
230
+ question: {
231
+ type: 'string',
232
+ description: 'Question to ask the user',
233
+ required: true
234
+ }
235
+ },
236
+ execute: async args => {
237
+ return `❓ ${args.question}`;
238
+ }
239
+ });
240
+ }
241
+
242
+ // ─── Action Registration (useAction hook) ──────────────────
243
+
244
+ registerAction(action) {
245
+ this.actions.set(action.name, action);
246
+ logger.info('AgentRuntime', `Registered action: ${action.name}`);
247
+ }
248
+ unregisterAction(name) {
249
+ this.actions.delete(name);
250
+ }
251
+
252
+ // ─── Navigation Helpers ────────────────────────────────────
253
+
254
+ getRouteNames() {
255
+ try {
256
+ if (!this.navRef?.isReady?.()) return [];
257
+ const state = this.navRef?.getRootState?.() || this.navRef?.getState?.();
258
+ if (state?.routeNames) return state.routeNames;
259
+ if (state?.routes) return state.routes.map(r => r.name);
260
+ return [];
261
+ } catch {
262
+ return [];
263
+ }
264
+ }
265
+ getCurrentScreenName() {
266
+ try {
267
+ if (!this.navRef?.isReady?.()) return 'Unknown';
268
+ const state = this.navRef?.getRootState?.() || this.navRef?.getState?.();
269
+ if (!state) return 'Unknown';
270
+ const route = state.routes[state.index];
271
+ return route?.name || 'Unknown';
272
+ } catch {
273
+ return 'Unknown';
274
+ }
275
+ }
276
+
277
+ // ─── Build Tools Array for Provider ────────────────────────
278
+
279
+ buildToolsForProvider() {
280
+ const allTools = [...this.tools.values()];
281
+
282
+ // Add registered actions as tools
283
+ for (const action of this.actions.values()) {
284
+ allTools.push({
285
+ name: action.name,
286
+ description: action.description,
287
+ parameters: Object.fromEntries(Object.entries(action.parameters).map(([key, typeStr]) => [key, {
288
+ type: typeStr,
289
+ description: key,
290
+ required: true
291
+ }])),
292
+ execute: async args => {
293
+ try {
294
+ const result = action.handler(args);
295
+ return typeof result === 'string' ? result : JSON.stringify(result);
296
+ } catch (error) {
297
+ return `❌ Action "${action.name}" failed: ${error.message}`;
298
+ }
299
+ }
300
+ });
301
+ }
302
+ return allTools;
303
+ }
304
+
305
+ // ─── Walk Config (passes security settings to FiberTreeWalker) ─
306
+
307
+ getWalkConfig() {
308
+ return {
309
+ interactiveBlacklist: this.config.interactiveBlacklist,
310
+ interactiveWhitelist: this.config.interactiveWhitelist
311
+ };
312
+ }
313
+
314
+ // ─── Instructions (mirrors page-agent #getInstructions) ───────
315
+
316
+ getInstructions(screenName) {
317
+ const {
318
+ instructions
319
+ } = this.config;
320
+ if (!instructions) return '';
321
+ let result = '';
322
+ if (instructions.system?.trim()) {
323
+ result += `<system_instructions>\n${instructions.system.trim()}\n</system_instructions>\n`;
324
+ }
325
+ if (instructions.getScreenInstructions) {
326
+ try {
327
+ const screenInstructions = instructions.getScreenInstructions(screenName)?.trim();
328
+ if (screenInstructions) {
329
+ result += `<screen_instructions>\n${screenInstructions}\n</screen_instructions>\n`;
330
+ }
331
+ } catch (error) {
332
+ logger.error('AgentRuntime', 'Failed to get screen instructions:', error);
333
+ }
334
+ }
335
+ return result ? `<instructions>\n${result}</instructions>\n\n` : '';
336
+ }
337
+
338
+ // ─── Main Execution Loop (mirrors PageAgentCore.execute) ───────
339
+
340
+ async execute(userMessage) {
341
+ if (this.isRunning) {
342
+ return {
343
+ success: false,
344
+ message: 'Agent is already running.',
345
+ steps: []
346
+ };
347
+ }
348
+ this.isRunning = true;
349
+ this.history = [];
350
+ const maxSteps = this.config.maxSteps || DEFAULT_MAX_STEPS;
351
+ const stepDelay = this.config.stepDelay ?? 300;
352
+
353
+ // Inject conversational context if we are answering the AI's question
354
+ let contextualMessage = userMessage;
355
+ if (this.lastAskUserQuestion) {
356
+ contextualMessage = `(Note: You just asked the user: "${this.lastAskUserQuestion}")\n\nUser replied: ${userMessage}`;
357
+ this.lastAskUserQuestion = null; // Consume the question
358
+ }
359
+ logger.info('AgentRuntime', `Starting execution: "${contextualMessage}"`);
360
+
361
+ // Lifecycle: onBeforeTask (mirrors page-agent)
362
+ await this.config.onBeforeTask?.();
363
+ try {
364
+ for (let step = 0; step < maxSteps; step++) {
365
+ logger.info('AgentRuntime', `===== Step ${step + 1}/${maxSteps} =====`);
366
+
367
+ // Lifecycle: onBeforeStep (mirrors page-agent)
368
+ await this.config.onBeforeStep?.(step);
369
+
370
+ // 1. Walk Fiber tree with security config and dehydrate screen
371
+ const walkResult = walkFiberTree(this.rootRef, this.getWalkConfig());
372
+ const screenName = this.getCurrentScreenName();
373
+ const screen = dehydrateScreen(screenName, this.getRouteNames(), walkResult.elementsText, walkResult.interactives);
374
+ logger.info('AgentRuntime', `Screen: ${screen.screenName}`);
375
+ logger.debug('AgentRuntime', `Dehydrated:\n${screen.elementsText}`);
376
+
377
+ // 2. Apply transformScreenContent (mirrors page-agent transformPageContent)
378
+ let screenContent = screen.elementsText;
379
+ if (this.config.transformScreenContent) {
380
+ screenContent = await this.config.transformScreenContent(screenContent);
381
+ }
382
+
383
+ // 3. Build context message with instructions + screen state
384
+ const instructionsBlock = this.getInstructions(screenName);
385
+ const contextMessage = step === 0 ? `${instructionsBlock}<user_request>${contextualMessage}</user_request>\n\n<screen_state>\n${screenContent}\n</screen_state>` : `${instructionsBlock}<screen_state>\n${screenContent}\n</screen_state>`;
386
+
387
+ // 4. Send to AI provider
388
+ const systemPrompt = buildSystemPrompt(this.config.language || 'en');
389
+ const tools = this.buildToolsForProvider();
390
+ logger.info('AgentRuntime', `Sending to AI with ${tools.length} tools...`);
391
+ const response = await this.provider.generateContent(systemPrompt, contextMessage, tools, this.history);
392
+
393
+ // 5. Process tool calls
394
+ if (!response.toolCalls || response.toolCalls.length === 0) {
395
+ logger.warn('AgentRuntime', 'No tool calls in response. Text:', response.text);
396
+ const result = {
397
+ success: true,
398
+ message: response.text || 'Task completed.',
399
+ steps: this.history
400
+ };
401
+ await this.config.onAfterTask?.(result);
402
+ return result;
403
+ }
404
+ for (const toolCall of response.toolCalls) {
405
+ logger.info('AgentRuntime', `Tool: ${toolCall.name}(${JSON.stringify(toolCall.args)})`);
406
+
407
+ // Find and execute the tool
408
+ const tool = this.tools.get(toolCall.name) || this.buildToolsForProvider().find(t => t.name === toolCall.name);
409
+ let output;
410
+ if (tool) {
411
+ output = await tool.execute(toolCall.args);
412
+ } else {
413
+ output = `❌ Unknown tool: ${toolCall.name}`;
414
+ }
415
+ logger.info('AgentRuntime', `Result: ${output}`);
416
+
417
+ // Record step
418
+ const agentStep = {
419
+ stepIndex: step,
420
+ reflection: {
421
+ evaluationPreviousGoal: step > 0 ? 'Evaluating...' : 'First step',
422
+ memory: '',
423
+ nextGoal: ''
424
+ },
425
+ action: {
426
+ name: toolCall.name,
427
+ input: toolCall.args,
428
+ output
429
+ }
430
+ };
431
+ this.history.push(agentStep);
432
+
433
+ // Lifecycle: onAfterStep (mirrors page-agent)
434
+ await this.config.onAfterStep?.(this.history);
435
+
436
+ // Check if done
437
+ if (toolCall.name === 'done') {
438
+ const result = {
439
+ success: toolCall.args.success !== false,
440
+ message: output,
441
+ steps: this.history
442
+ };
443
+ logger.info('AgentRuntime', `Task completed: ${output}`);
444
+ await this.config.onAfterTask?.(result);
445
+ return result;
446
+ }
447
+
448
+ // Check if asking user
449
+ if (toolCall.name === 'ask_user') {
450
+ this.lastAskUserQuestion = toolCall.args.question || output;
451
+ const result = {
452
+ success: true,
453
+ message: output,
454
+ steps: this.history
455
+ };
456
+ await this.config.onAfterTask?.(result);
457
+ return result;
458
+ }
459
+ }
460
+
461
+ // Step delay (mirrors page-agent stepDelay)
462
+ await new Promise(resolve => setTimeout(resolve, stepDelay));
463
+ }
464
+
465
+ // Max steps reached
466
+ const result = {
467
+ success: false,
468
+ message: `Reached maximum steps (${maxSteps}) without completing the task.`,
469
+ steps: this.history
470
+ };
471
+ await this.config.onAfterTask?.(result);
472
+ return result;
473
+ } catch (error) {
474
+ logger.error('AgentRuntime', 'Execution error:', error);
475
+ const result = {
476
+ success: false,
477
+ message: `Error: ${error.message}`,
478
+ steps: this.history
479
+ };
480
+ await this.config.onAfterTask?.(result);
481
+ return result;
482
+ } finally {
483
+ this.isRunning = false;
484
+ }
485
+ }
486
+
487
+ /** Update refs (called when component re-renders) */
488
+ updateRefs(rootRef, navRef) {
489
+ this.rootRef = rootRef;
490
+ this.navRef = navRef;
491
+ }
492
+
493
+ /** Check if agent is currently executing */
494
+ getIsRunning() {
495
+ return this.isRunning;
496
+ }
497
+ }
498
+ //# sourceMappingURL=AgentRuntime.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["logger","walkFiberTree","dehydrateScreen","DEFAULT_MAX_STEPS","buildSystemPrompt","language","isArabic","AgentRuntime","tools","Map","actions","history","isRunning","lastAskUserQuestion","constructor","provider","config","rootRef","navRef","registerBuiltInTools","customTools","name","tool","Object","entries","delete","info","set","description","parameters","index","type","required","execute","args","interactives","elements","getWalkConfig","element","find","el","map","e","join","props","onPress","label","Promise","resolve","setTimeout","error","message","text","onChangeText","screen","params","isReady","JSON","parse","undefined","navigate","stringify","getRouteNames","success","question","registerAction","action","unregisterAction","state","getRootState","getState","routeNames","routes","r","getCurrentScreenName","route","buildToolsForProvider","allTools","values","push","fromEntries","key","typeStr","result","handler","interactiveBlacklist","interactiveWhitelist","getInstructions","screenName","instructions","system","trim","getScreenInstructions","screenInstructions","userMessage","steps","maxSteps","stepDelay","contextualMessage","onBeforeTask","step","onBeforeStep","walkResult","elementsText","debug","screenContent","transformScreenContent","instructionsBlock","contextMessage","systemPrompt","length","response","generateContent","toolCalls","warn","onAfterTask","toolCall","get","t","output","agentStep","stepIndex","reflection","evaluationPreviousGoal","memory","nextGoal","input","onAfterStep","updateRefs","getIsRunning"],"sourceRoot":"../../../src","sources":["core/AgentRuntime.ts"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAASA,MAAM,QAAQ,oBAAiB;AACxC,SAASC,aAAa,QAAQ,sBAAmB;AAEjD,SAASC,eAAe,QAAQ,uBAAoB;AAUpD,MAAMC,iBAAiB,GAAG,EAAE;;AAE5B;;AAEA,SAASC,iBAAiBA,CAACC,QAAgB,EAAU;EACnD,MAAMC,QAAQ,GAAGD,QAAQ,KAAK,IAAI;EAElC,OAAO;AACT;AACA,EAAEC,QAAQ,GAAG,gCAAgC,GAAG,iCAAiC;AACjF;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,SAAS;AACT;;AAEA;;AAEA,OAAO,MAAMC,YAAY,CAAC;EAKhBC,KAAK,GAAgC,IAAIC,GAAG,CAAC,CAAC;EAC9CC,OAAO,GAAkC,IAAID,GAAG,CAAC,CAAC;EAClDE,OAAO,GAAgB,EAAE;EACzBC,SAAS,GAAG,KAAK;EACjBC,mBAAmB,GAAkB,IAAI;EAEjDC,WAAWA,CACTC,QAAoB,EACpBC,MAAmB,EACnBC,OAAY,EACZC,MAAW,EACX;IACA,IAAI,CAACH,QAAQ,GAAGA,QAAQ;IACxB,IAAI,CAACC,MAAM,GAAGA,MAAM;IACpB,IAAI,CAACC,OAAO,GAAGA,OAAO;IACtB,IAAI,CAACC,MAAM,GAAGA,MAAM;IAEpB,IAAI,CAACC,oBAAoB,CAAC,CAAC;;IAE3B;IACA,IAAIH,MA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