playwright-mimic 0.1.0 → 0.1.1

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 (110) hide show
  1. package/README.md +633 -446
  2. package/dist/agentic/agent.d.ts +106 -0
  3. package/dist/agentic/agent.d.ts.map +1 -0
  4. package/dist/agentic/agent.js +528 -0
  5. package/dist/agentic/agent.js.map +1 -0
  6. package/dist/agentic/index.d.ts +13 -0
  7. package/dist/agentic/index.d.ts.map +1 -0
  8. package/dist/agentic/index.js +12 -0
  9. package/dist/agentic/index.js.map +1 -0
  10. package/dist/agentic/planner.d.ts +41 -0
  11. package/dist/agentic/planner.d.ts.map +1 -0
  12. package/dist/agentic/planner.js +136 -0
  13. package/dist/agentic/planner.js.map +1 -0
  14. package/dist/agentic/react.d.ts +35 -0
  15. package/dist/agentic/react.d.ts.map +1 -0
  16. package/dist/agentic/react.js +170 -0
  17. package/dist/agentic/react.js.map +1 -0
  18. package/dist/agentic/recovery.d.ts +55 -0
  19. package/dist/agentic/recovery.d.ts.map +1 -0
  20. package/dist/agentic/recovery.js +200 -0
  21. package/dist/agentic/recovery.js.map +1 -0
  22. package/dist/agentic/reflection.d.ts +40 -0
  23. package/dist/agentic/reflection.d.ts.map +1 -0
  24. package/dist/agentic/reflection.js +142 -0
  25. package/dist/agentic/reflection.js.map +1 -0
  26. package/dist/agentic/types.d.ts +177 -0
  27. package/dist/agentic/types.d.ts.map +1 -0
  28. package/dist/agentic/types.js +8 -0
  29. package/dist/agentic/types.js.map +1 -0
  30. package/dist/agentic/wait.d.ts +50 -0
  31. package/dist/agentic/wait.d.ts.map +1 -0
  32. package/dist/agentic/wait.js +140 -0
  33. package/dist/agentic/wait.js.map +1 -0
  34. package/dist/agentic-mimic.d.ts +56 -0
  35. package/dist/agentic-mimic.d.ts.map +1 -0
  36. package/dist/agentic-mimic.js +98 -0
  37. package/dist/agentic-mimic.js.map +1 -0
  38. package/dist/index.d.ts +11 -8
  39. package/dist/index.d.ts.map +1 -1
  40. package/dist/index.js +12 -9
  41. package/dist/index.js.map +1 -1
  42. package/dist/mimic/actionType.d.ts +7 -0
  43. package/dist/mimic/actionType.d.ts.map +1 -0
  44. package/dist/mimic/actionType.js +44 -0
  45. package/dist/mimic/actionType.js.map +1 -0
  46. package/dist/mimic/annotations.d.ts +20 -0
  47. package/dist/mimic/annotations.d.ts.map +1 -0
  48. package/dist/mimic/annotations.js +30 -0
  49. package/dist/mimic/annotations.js.map +1 -0
  50. package/dist/mimic/cli.d.ts +15 -0
  51. package/dist/mimic/cli.d.ts.map +1 -0
  52. package/dist/mimic/cli.js +17 -0
  53. package/dist/mimic/cli.js.map +1 -0
  54. package/dist/mimic/click.d.ts +39 -0
  55. package/dist/mimic/click.d.ts.map +1 -0
  56. package/dist/mimic/click.js +233 -0
  57. package/dist/mimic/click.js.map +1 -0
  58. package/dist/mimic/forms.d.ts +47 -0
  59. package/dist/mimic/forms.d.ts.map +1 -0
  60. package/dist/mimic/forms.js +264 -0
  61. package/dist/mimic/forms.js.map +1 -0
  62. package/dist/mimic/navigation.d.ts +19 -0
  63. package/dist/mimic/navigation.d.ts.map +1 -0
  64. package/dist/mimic/navigation.js +117 -0
  65. package/dist/mimic/navigation.js.map +1 -0
  66. package/dist/mimic/replay.d.ts +21 -0
  67. package/dist/mimic/replay.d.ts.map +1 -0
  68. package/dist/mimic/replay.js +133 -0
  69. package/dist/mimic/replay.js.map +1 -0
  70. package/dist/mimic/schema/action.d.ts +315 -0
  71. package/dist/mimic/schema/action.d.ts.map +1 -0
  72. package/dist/mimic/schema/action.js +204 -0
  73. package/dist/mimic/schema/action.js.map +1 -0
  74. package/dist/mimic/selector.d.ts +139 -0
  75. package/dist/mimic/selector.d.ts.map +1 -0
  76. package/dist/mimic/selector.js +1103 -0
  77. package/dist/mimic/selector.js.map +1 -0
  78. package/dist/mimic/selectorDescriptor.d.ts +13 -0
  79. package/dist/mimic/selectorDescriptor.d.ts.map +1 -0
  80. package/dist/mimic/selectorDescriptor.js +9 -0
  81. package/dist/mimic/selectorDescriptor.js.map +1 -0
  82. package/dist/mimic/selectorSerialization.d.ts +30 -0
  83. package/dist/mimic/selectorSerialization.d.ts.map +1 -0
  84. package/dist/mimic/selectorSerialization.js +170 -0
  85. package/dist/mimic/selectorSerialization.js.map +1 -0
  86. package/dist/mimic/selectorTypes.d.ts +200 -0
  87. package/dist/mimic/selectorTypes.d.ts.map +1 -0
  88. package/dist/mimic/selectorTypes.js +2 -0
  89. package/dist/mimic/selectorTypes.js.map +1 -0
  90. package/dist/mimic/selectorUtils.d.ts +26 -0
  91. package/dist/mimic/selectorUtils.d.ts.map +1 -0
  92. package/dist/mimic/selectorUtils.js +144 -0
  93. package/dist/mimic/selectorUtils.js.map +1 -0
  94. package/dist/mimic/storage.d.ts +75 -0
  95. package/dist/mimic/storage.d.ts.map +1 -0
  96. package/dist/mimic/storage.js +197 -0
  97. package/dist/mimic/storage.js.map +1 -0
  98. package/dist/mimic/types.d.ts +63 -0
  99. package/dist/mimic/types.d.ts.map +1 -0
  100. package/dist/mimic/types.js +7 -0
  101. package/dist/mimic/types.js.map +1 -0
  102. package/dist/mimic.d.ts +28 -4
  103. package/dist/mimic.d.ts.map +1 -1
  104. package/dist/mimic.js +374 -32
  105. package/dist/mimic.js.map +1 -1
  106. package/dist/mimicry.d.ts +4 -4
  107. package/dist/mimicry.d.ts.map +1 -1
  108. package/dist/mimicry.js +22 -13
  109. package/dist/mimicry.js.map +1 -1
  110. package/package.json +5 -2
@@ -0,0 +1,140 @@
1
+ /**
2
+ * Smart Wait Module
3
+ *
4
+ * Implements intelligent waiting that detects loading indicators and waits
5
+ * for them to disappear, rather than using fixed timeouts.
6
+ */
7
+ /**
8
+ * Common loading indicator selectors
9
+ * These are common patterns for loading spinners, progress bars, etc.
10
+ */
11
+ const LOADING_INDICATORS = [
12
+ // Spinners and loaders
13
+ '[class*="loading"]',
14
+ '[class*="spinner"]',
15
+ '[class*="loader"]',
16
+ '[id*="loading"]',
17
+ '[id*="spinner"]',
18
+ '[id*="loader"]',
19
+ // Progress indicators
20
+ '[class*="progress"]',
21
+ '[role="progressbar"]',
22
+ // Common loading text
23
+ 'text=/loading/i',
24
+ 'text=/please wait/i',
25
+ // Skeleton loaders
26
+ '[class*="skeleton"]',
27
+ // Overlay loaders
28
+ '[class*="overlay"][class*="loading"]',
29
+ // Data attributes
30
+ '[data-loading="true"]',
31
+ '[data-state="loading"]',
32
+ '[aria-busy="true"]',
33
+ ];
34
+ /**
35
+ * Detect if there are any loading indicators visible on the page
36
+ *
37
+ * @param page - Playwright Page object
38
+ * @returns Promise resolving to array of visible loading indicator selectors
39
+ */
40
+ export async function detectLoadingIndicators(page) {
41
+ const visibleLoaders = [];
42
+ for (const selector of LOADING_INDICATORS) {
43
+ try {
44
+ // Check if selector matches any visible elements
45
+ const count = await page.locator(selector).filter({ hasNotText: '' }).count();
46
+ if (count > 0) {
47
+ // Verify at least one is actually visible
48
+ const first = page.locator(selector).first();
49
+ const isVisible = await first.isVisible().catch(() => false);
50
+ if (isVisible) {
51
+ visibleLoaders.push(selector);
52
+ }
53
+ }
54
+ }
55
+ catch (error) {
56
+ // Ignore errors from invalid selectors
57
+ continue;
58
+ }
59
+ }
60
+ return visibleLoaders;
61
+ }
62
+ /**
63
+ * Wait for all loading indicators to disappear
64
+ *
65
+ * @param page - Playwright Page object
66
+ * @param timeout - Maximum time to wait in milliseconds (default: 10000)
67
+ * @returns Promise that resolves when all loaders are gone, or rejects on timeout
68
+ */
69
+ export async function waitForLoadersToDisappear(page, timeout = 10000) {
70
+ const startTime = Date.now();
71
+ while (Date.now() - startTime < timeout) {
72
+ const loaders = await detectLoadingIndicators(page);
73
+ if (loaders.length === 0) {
74
+ // All loaders are gone
75
+ return;
76
+ }
77
+ // Wait a bit before checking again
78
+ await page.waitForTimeout(100);
79
+ }
80
+ // Timeout reached, but don't throw - just log
81
+ const remainingLoaders = await detectLoadingIndicators(page);
82
+ if (remainingLoaders.length > 0) {
83
+ console.warn(`⚠️ Loading indicators still visible after ${timeout}ms: ${remainingLoaders.join(', ')}`);
84
+ }
85
+ }
86
+ /**
87
+ * Smart wait that detects and waits for loading indicators
88
+ * Falls back to fixed timeout if no loaders are detected
89
+ *
90
+ * @param page - Playwright Page object
91
+ * @param options - Wait options
92
+ * @returns Promise that resolves when wait is complete
93
+ */
94
+ export async function smartWait(page, options = {}) {
95
+ const startTime = Date.now();
96
+ const { loaderTimeout = 10000, fallbackTimeout = 1000, waitForNetworkIdle = false, } = options;
97
+ // First, check for loading indicators
98
+ const loaders = await detectLoadingIndicators(page);
99
+ if (loaders.length > 0) {
100
+ console.log(`⏳ Detected ${loaders.length} loading indicator(s), waiting for them to disappear...`);
101
+ await waitForLoadersToDisappear(page, loaderTimeout);
102
+ const duration = Date.now() - startTime;
103
+ return {
104
+ waitedForLoaders: true,
105
+ loaderCount: loaders.length,
106
+ duration,
107
+ };
108
+ }
109
+ // No loaders detected, use fallback timeout
110
+ if (fallbackTimeout > 0) {
111
+ console.log(`⏳ No loaders detected, waiting ${fallbackTimeout}ms...`);
112
+ await page.waitForTimeout(fallbackTimeout);
113
+ }
114
+ // Optionally wait for network idle
115
+ if (waitForNetworkIdle) {
116
+ try {
117
+ await page.waitForLoadState('networkidle', { timeout: 5000 });
118
+ }
119
+ catch (error) {
120
+ // Ignore timeout errors for network idle
121
+ }
122
+ }
123
+ const duration = Date.now() - startTime;
124
+ return {
125
+ waitedForLoaders: false,
126
+ loaderCount: 0,
127
+ duration,
128
+ };
129
+ }
130
+ /**
131
+ * Check if the page appears to be in a loading state
132
+ *
133
+ * @param page - Playwright Page object
134
+ * @returns Promise resolving to whether page is loading
135
+ */
136
+ export async function isPageLoading(page) {
137
+ const loaders = await detectLoadingIndicators(page);
138
+ return loaders.length > 0;
139
+ }
140
+ //# sourceMappingURL=wait.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wait.js","sourceRoot":"","sources":["../../src/agentic/wait.ts"],"names":[],"mappings":"AAAA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E,GAAG,SAAS,CAAC;QACxC,OAAO;YACL,gBAAgB,EAAE,IAAI;YACtB,WAAW,EAAE,OAAO,CAAC,MAAM;YAC3B,QAAQ;SACT,CAAC;IACJ,CAAC;IAED,4CAA4C;IAC5C,IAAI,eAAe,GAAG,CAAC,EAAE,CAAC;QACxB,OAAO,CAAC,GAAG,CAAC,kCAAkC,eAAe,OAAO,CAAC,CAAC;QACtE,MAAM,IAAI,CAAC,cAAc,CAAC,eAAe,CAAC,CAAC;IAC7C,CAAC;IAED,mCAAmC;IACnC,IAAI,kBAAkB,EAAE,CAAC;QACvB,IAAI,CAAC;YACH,MAAM,IAAI,CAAC,gBAAgB,CAAC,aAAa,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC;QAChE,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,yCAAyC;QAC3C,CAAC;IACH,CAAC;IAED,MAAM,QAAQ,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,SAAS,CAAC;IACxC,OAAO;QACL,gBAAgB,EAAE,KAAK;QACvB,WAAW,EAAE,CAAC;QACd,QAAQ;KACT,CAAC;AACJ,CAAC;AAED;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CAAC,IAAU;IAC5C,MAAM,OAAO,GAAG,MAAM,uBAAuB,CAAC,IAAI,CAAC,CAAC;IACpD,OAAO,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC;AAC5B,CAAC"}
@@ -0,0 +1,56 @@
1
+ /**
2
+ * Agentic Mimic Integration
3
+ *
4
+ * Provides an agentic version of the mimic function that uses the Agent class
5
+ * for goal-oriented, autonomous browser automation.
6
+ */
7
+ import { Page, TestInfo } from '@playwright/test';
8
+ import type { LanguageModel } from 'ai';
9
+ import { type AgentConfig } from './agentic/index.js';
10
+ /**
11
+ * Agentic Mimic function type
12
+ * Similar to Mimic but uses goal-oriented agentic execution
13
+ */
14
+ export type AgenticMimic = (goal: TemplateStringsArray, ...args: unknown[]) => Promise<{
15
+ success: boolean;
16
+ actionsTaken: number;
17
+ goalAchieved: boolean;
18
+ }>;
19
+ /**
20
+ * Agentic mimic function that uses goal-oriented agentic execution
21
+ *
22
+ * Instead of executing steps sequentially, this function uses an agent
23
+ * that plans, reasons, acts, and reflects to achieve the goal.
24
+ *
25
+ * @param goal - High-level goal to achieve (can be multi-line)
26
+ * @param config - Configuration with page, brains, and optional testInfo
27
+ * @returns Promise resolving to execution result
28
+ */
29
+ export declare function agenticMimic(goal: string, { page, brains, testInfo, ...agentConfig }: {
30
+ page: Page;
31
+ brains: LanguageModel;
32
+ testInfo?: TestInfo;
33
+ } & Partial<Omit<AgentConfig, 'page' | 'brain'>>): Promise<{
34
+ success: boolean;
35
+ actionsTaken: number;
36
+ goalAchieved: boolean;
37
+ }>;
38
+ /**
39
+ * Create an agentic mimic function with configuration
40
+ *
41
+ * Similar to createMimic but returns an agentic version that uses
42
+ * goal-oriented agentic execution instead of step-by-step execution.
43
+ *
44
+ * @param config - Configuration with page, brains, testInfo, and optional agent config
45
+ * @returns Agentic mimic function
46
+ */
47
+ export declare const createAgenticMimic: (config: {
48
+ page: Page;
49
+ brains: LanguageModel;
50
+ testInfo?: TestInfo;
51
+ } & Partial<Omit<AgentConfig, "page" | "brain">>) => (goal: TemplateStringsArray, ...args: unknown[]) => Promise<{
52
+ success: boolean;
53
+ actionsTaken: number;
54
+ goalAchieved: boolean;
55
+ }>;
56
+ //# sourceMappingURL=agentic-mimic.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agentic-mimic.d.ts","sourceRoot":"","sources":["../src/agentic-mimic.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAQ,MAAM,kBAAkB,CAAC;AACxD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,IAAI,CAAC;AACxC,OAAO,EAAS,KAAK,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAG7D;;;GAGG;AACH,MAAM,MAAM,YAAY,GAAG,CAAC,IAAI,EAAE,oBAAoB,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,CAAC;IACrF,OAAO,EAAE,OAAO,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;IACrB,YAAY,EAAE,OAAO,CAAC;CACvB,CAAC,CAAC;AAsBH;;;;;;;;;GASG;AACH,wBAAsB,YAAY,CAChC,IAAI,EAAE,MAAM,EACZ,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG,WAAW,EAAE,EAAE;IAC1C,IAAI,EAAE,IAAI,CAAC;IACX,MAAM,EAAE,aAAa,CAAC;IACtB,QAAQ,CAAC,EAAE,QAAQ,CAAC;CACrB,GAAG,OAAO,CAAC,IAAI,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,GAC/C,OAAO,CAAC;IACT,OAAO,EAAE,OAAO,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;IACrB,YAAY,EAAE,OAAO,CAAC;CACvB,CAAC,CAoDD;AAED;;;;;;;;GAQG;AACH,eAAO,MAAM,kBAAkB,GAAI,QAAQ;IACzC,IAAI,EAAE,IAAI,CAAC;IACX,MAAM,EAAE,aAAa,CAAC;IACtB,QAAQ,CAAC,EAAE,QAAQ,CAAC;CACrB,GAAG,OAAO,CAAC,IAAI,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,MAChC,MAAM,oBAAoB,EAAE,GAAG,MAAM,OAAO,EAAE;aAvEnD,OAAO;kBACF,MAAM;kBACN,OAAO;EAyEtB,CAAC"}
@@ -0,0 +1,98 @@
1
+ /**
2
+ * Agentic Mimic Integration
3
+ *
4
+ * Provides an agentic version of the mimic function that uses the Agent class
5
+ * for goal-oriented, autonomous browser automation.
6
+ */
7
+ import { test } from '@playwright/test';
8
+ import { Agent } from './agentic/index.js';
9
+ import { startTestCase } from './utils/token-counter.js';
10
+ /**
11
+ * Trim template string and combine with interpolated values
12
+ *
13
+ * @param strings - Template string array
14
+ * @param values - Interpolated values
15
+ * @returns Combined and trimmed string
16
+ */
17
+ function trimTemplate(strings, ...values) {
18
+ let result = strings.reduce((acc, str, i) => {
19
+ return acc + str + (values[i] ?? '');
20
+ }, '');
21
+ // Split into lines, trim each, filter out empty lines, and join back
22
+ return result
23
+ .split('\n')
24
+ .map(line => line.trim())
25
+ .filter(line => line.length > 0)
26
+ .join('\n');
27
+ }
28
+ /**
29
+ * Agentic mimic function that uses goal-oriented agentic execution
30
+ *
31
+ * Instead of executing steps sequentially, this function uses an agent
32
+ * that plans, reasons, acts, and reflects to achieve the goal.
33
+ *
34
+ * @param goal - High-level goal to achieve (can be multi-line)
35
+ * @param config - Configuration with page, brains, and optional testInfo
36
+ * @returns Promise resolving to execution result
37
+ */
38
+ export async function agenticMimic(goal, { page, brains, testInfo, ...agentConfig }) {
39
+ if (testInfo?.title)
40
+ await startTestCase(testInfo.title);
41
+ // Combine multi-line goal into a single goal statement
42
+ const goalLines = goal.split('\n')
43
+ .map(line => line.trim())
44
+ .filter(line => line.length > 0);
45
+ const combinedGoal = goalLines.length > 1
46
+ ? goalLines.join(' and then ')
47
+ : goalLines[0] || goal;
48
+ // Create agent configuration
49
+ const config = {
50
+ brain: brains,
51
+ page,
52
+ maxActions: agentConfig.maxActions ?? 50,
53
+ maxRetries: agentConfig.maxRetries ?? 3,
54
+ enableReflection: agentConfig.enableReflection ?? true,
55
+ enablePlanning: agentConfig.enablePlanning ?? true,
56
+ actionTimeout: agentConfig.actionTimeout ?? 30000,
57
+ };
58
+ // Create and initialize agent
59
+ const agent = new Agent(config);
60
+ await agent.initialize();
61
+ // Execute goal within a test step for better traceability
62
+ const stepDescription = combinedGoal.length > 50
63
+ ? combinedGoal.substring(0, 50) + '...'
64
+ : combinedGoal;
65
+ return await test.step(stepDescription, async () => {
66
+ const result = await agent.executeGoal(combinedGoal);
67
+ // Log summary
68
+ console.log(`\n📊 Execution Summary:`);
69
+ console.log(` Goal: ${combinedGoal}`);
70
+ console.log(` Success: ${result.success ? '✓' : '✗'}`);
71
+ console.log(` Actions Taken: ${result.actionsTaken}`);
72
+ console.log(` Goal Achieved: ${result.goalAchieved ? 'Yes' : 'No'}`);
73
+ if (result.finalState.errors.length > 0) {
74
+ console.log(` Errors: ${result.finalState.errors.length}`);
75
+ }
76
+ return {
77
+ success: result.success,
78
+ actionsTaken: result.actionsTaken,
79
+ goalAchieved: result.goalAchieved,
80
+ };
81
+ });
82
+ }
83
+ /**
84
+ * Create an agentic mimic function with configuration
85
+ *
86
+ * Similar to createMimic but returns an agentic version that uses
87
+ * goal-oriented agentic execution instead of step-by-step execution.
88
+ *
89
+ * @param config - Configuration with page, brains, testInfo, and optional agent config
90
+ * @returns Agentic mimic function
91
+ */
92
+ export const createAgenticMimic = (config) => {
93
+ return async (goal, ...args) => {
94
+ const goalString = trimTemplate(goal, ...args);
95
+ return await agenticMimic(goalString, config);
96
+ };
97
+ };
98
+ //# sourceMappingURL=agentic-mimic.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agentic-mimic.js","sourceRoot":"","sources":["../src/agentic-mimic.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAkB,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAExD,OAAO,EAAE,KAAK,EAAoB,MAAM,oBAAoB,CAAC;AAC7D,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAYzD;;;;;;GAMG;AACH,SAAS,YAAY,CAAC,OAA6B,EAAE,GAAG,MAAa;IACnE,IAAI,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,CAAC,EAAE,EAAE;QAC1C,OAAO,GAAG,GAAG,GAAG,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;IACvC,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,qEAAqE;IACrE,OAAO,MAAM;SACV,KAAK,CAAC,IAAI,CAAC;SAC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EAAE,EAAE;IAClD,OAAO,KAAK,EAAE,IAA0B,EAAE,GAAG,IAAe,EAAE,EAAE;QAC9D,MAAM,UAAU,GAAG,YAAY,CAAC,IAAI,EAAE,GAAG,IAAI,CAAC,CAAC;QAC/C,OAAO,MAAM,YAAY,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC;IAChD,CAAC,CAAC;AACJ,CAAC,CAAC"}
package/dist/index.d.ts CHANGED
@@ -1,13 +1,16 @@
1
1
  /**
2
- * Mimicry - AI-powered browser testing framework
2
+ * Mimic - AI-powered browser testing framework
3
3
  *
4
4
  * Main entry point exporting all public APIs
5
5
  */
6
- export { mimicry, createMimicry, type Mimicry } from './mimicry.js';
7
- export { getBaseAction } from './mimicry/actionType.js';
8
- export { getClickAction, executeClickAction } from './mimicry/click.js';
9
- export { getNavigationAction, executeNavigationAction } from './mimicry/navigation.js';
10
- export { getFormAction, executeFormAction, type FormActionResult } from './mimicry/forms.js';
11
- export { captureTargets, buildSelectorForTarget, type TargetInfo, type CaptureTargetsOptions } from './mimicry/selector.js';
12
- export type { NavigationAction, ClickActionResult, Point, } from './mimicry/schema/action.js';
6
+ export { mimic, createMimic, type Mimic } from './mimic.js';
7
+ export { getBaseAction } from './mimic/actionType.js';
8
+ export { getClickAction, executeClickAction } from './mimic/click.js';
9
+ export { getNavigationAction, executeNavigationAction } from './mimic/navigation.js';
10
+ export { getFormAction, executeFormAction, type FormActionResult } from './mimic/forms.js';
11
+ export { captureTargets, buildSelectorForTarget, type TargetInfo, type CaptureTargetsOptions } from './mimic/selector.js';
12
+ export type { NavigationAction, ClickActionResult, Point, } from './mimic/schema/action.js';
13
+ export { createAgenticMimic, type AgenticMimic } from './agentic-mimic.js';
14
+ export { Agent } from './agentic/agent.js';
15
+ export type { AgentState, AgentConfig, ActionRecord, ActionReflection, PlanningResult, PlanStep, ReasoningResult, DecidedAction, } from './agentic/index.js';
13
16
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAE,OAAO,EAAE,aAAa,EAAE,KAAK,OAAO,EAAE,MAAM,cAAc,CAAC;AAGpE,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AACxD,OAAO,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AACxE,OAAO,EAAE,mBAAmB,EAAE,uBAAuB,EAAE,MAAM,yBAAyB,CAAC;AACvF,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,KAAK,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAC7F,OAAO,EAAE,cAAc,EAAE,sBAAsB,EAAE,KAAK,UAAU,EAAE,KAAK,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AAG5H,YAAY,EACV,gBAAgB,EAChB,iBAAiB,EACjB,KAAK,GACN,MAAM,4BAA4B,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,KAAK,KAAK,EAAE,MAAM,YAAY,CAAC;AAG5D,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AACtE,OAAO,EAAE,mBAAmB,EAAE,uBAAuB,EAAE,MAAM,uBAAuB,CAAC;AACrF,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,KAAK,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAC3F,OAAO,EAAE,cAAc,EAAE,sBAAsB,EAAE,KAAK,UAAU,EAAE,KAAK,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AAG1H,YAAY,EACV,gBAAgB,EAChB,iBAAiB,EACjB,KAAK,GACN,MAAM,0BAA0B,CAAC;AAGlC,OAAO,EAAE,kBAAkB,EAAE,KAAK,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAC3E,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,YAAY,EACV,UAAU,EACV,WAAW,EACX,YAAY,EACZ,gBAAgB,EAChB,cAAc,EACd,QAAQ,EACR,eAAe,EACf,aAAa,GACd,MAAM,oBAAoB,CAAC"}
package/dist/index.js CHANGED
@@ -1,14 +1,17 @@
1
1
  /**
2
- * Mimicry - AI-powered browser testing framework
2
+ * Mimic - AI-powered browser testing framework
3
3
  *
4
4
  * Main entry point exporting all public APIs
5
5
  */
6
- // Main mimicry functionality
7
- export { mimicry, createMimicry } from './mimicry.js';
8
- // Mimicry action types and utilities
9
- export { getBaseAction } from './mimicry/actionType.js';
10
- export { getClickAction, executeClickAction } from './mimicry/click.js';
11
- export { getNavigationAction, executeNavigationAction } from './mimicry/navigation.js';
12
- export { getFormAction, executeFormAction } from './mimicry/forms.js';
13
- export { captureTargets, buildSelectorForTarget } from './mimicry/selector.js';
6
+ // Main mimic functionality
7
+ export { mimic, createMimic } from './mimic.js';
8
+ // Mimic action types and utilities
9
+ export { getBaseAction } from './mimic/actionType.js';
10
+ export { getClickAction, executeClickAction } from './mimic/click.js';
11
+ export { getNavigationAction, executeNavigationAction } from './mimic/navigation.js';
12
+ export { getFormAction, executeFormAction } from './mimic/forms.js';
13
+ export { captureTargets, buildSelectorForTarget } from './mimic/selector.js';
14
+ // Agentic system exports
15
+ export { createAgenticMimic } from './agentic-mimic.js';
16
+ export { Agent } from './agentic/agent.js';
14
17
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,6BAA6B;AAC7B,OAAO,EAAE,OAAO,EAAE,aAAa,EAAgB,MAAM,cAAc,CAAC;AAEpE,qCAAqC;AACrC,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AACxD,OAAO,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AACxE,OAAO,EAAE,mBAAmB,EAAE,uBAAuB,EAAE,MAAM,yBAAyB,CAAC;AACvF,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAyB,MAAM,oBAAoB,CAAC;AAC7F,OAAO,EAAE,cAAc,EAAE,sBAAsB,EAA+C,MAAM,uBAAuB,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,2BAA2B;AAC3B,OAAO,EAAE,KAAK,EAAE,WAAW,EAAc,MAAM,YAAY,CAAC;AAE5D,mCAAmC;AACnC,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AACtE,OAAO,EAAE,mBAAmB,EAAE,uBAAuB,EAAE,MAAM,uBAAuB,CAAC;AACrF,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAyB,MAAM,kBAAkB,CAAC;AAC3F,OAAO,EAAE,cAAc,EAAE,sBAAsB,EAA+C,MAAM,qBAAqB,CAAC;AAS1H,yBAAyB;AACzB,OAAO,EAAE,kBAAkB,EAAqB,MAAM,oBAAoB,CAAC;AAC3E,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC"}
@@ -0,0 +1,7 @@
1
+ import { type LanguageModel } from 'ai';
2
+ import { z } from 'zod';
3
+ import { Page } from '@playwright/test';
4
+ import { zGeneralActionPlan } from './schema/action.js';
5
+ import type { TestContext } from '../mimic.js';
6
+ export declare const getBaseAction: (_page: Page, brain: LanguageModel, action: string, testContext?: TestContext) => Promise<z.infer<typeof zGeneralActionPlan>>;
7
+ //# sourceMappingURL=actionType.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"actionType.d.ts","sourceRoot":"","sources":["../../src/mimic/actionType.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,aAAa,EAAwB,MAAM,IAAI,CAAA;AAC7D,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AACvB,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAA;AAEvC,OAAO,EACL,kBAAkB,EACnB,MAAM,oBAAoB,CAAA;AAE3B,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAI/C,eAAO,MAAM,aAAa,GACxB,OAAO,IAAI,EACX,OAAO,aAAa,EACpB,QAAQ,MAAM,EACd,cAAc,WAAW,KACxB,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,kBAAkB,CAAC,CA2C5C,CAAC"}
@@ -0,0 +1,44 @@
1
+ import { generateText, Output } from 'ai';
2
+ import { zGeneralActionPlan, } from './schema/action.js';
3
+ import { countTokens } from '../utils/token-counter.js';
4
+ export const getBaseAction = async (_page, brain, action, testContext) => {
5
+ // Build context description for the prompt
6
+ const contextDescription = testContext ? `
7
+ **Test Context:**
8
+ - Current URL: ${testContext.currentState.url}
9
+ - Current Page Title: ${testContext.currentState.pageTitle}
10
+ - Step ${testContext.currentStepIndex + 1} of ${testContext.totalSteps}
11
+ ${testContext.previousSteps.length > 0 ? `
12
+ **Previous Steps Executed:**
13
+ ${testContext.previousSteps.map((prevStep, idx) => `${idx + 1}. Step ${prevStep.stepIndex + 1}: "${prevStep.stepText}" (${prevStep.actionKind}${prevStep.url ? ` → ${prevStep.url}` : ''})`).join('\n')}
14
+ ` : ''}
15
+ ` : '';
16
+ const res = await generateText({
17
+ model: brain,
18
+ prompt: `You are an expert in interpreting Gherkin steps and classifying them into base user action types for automated testing using Playwright.
19
+
20
+ For each Gherkin step, output the following:
21
+
22
+ Decision: One of the following categories:
23
+ Form update: Modifying input fields, selecting options, checking boxes, etc.
24
+ Navigation: Moving between pages or URLs, or using "back"/"forward".
25
+ Assertion: Verifying an element's presence, state, or content.
26
+ Click: Clicking on buttons, links, or other interactive elements.
27
+ Hover: Hovering over elements to trigger UI events or tooltips.
28
+ Unknown: Step is too ambiguous to confidently classify.
29
+
30
+ Explanation: Describe the reasoning behind the classification based on the literal intent of the Gherkin step. Do not infer outcomes — classify strictly based on what the step says is being done.
31
+ Format:
32
+ Classification: <one of the 6 categories>
33
+ Reason: <brief explanation of how you arrived at the classification>
34
+
35
+ ${contextDescription}
36
+ **Input Gherkin step:** ${action}
37
+
38
+ `,
39
+ output: Output.object({ schema: zGeneralActionPlan, name: 'generalActionPlan' }),
40
+ });
41
+ await countTokens(res);
42
+ return res.output;
43
+ };
44
+ //# sourceMappingURL=actionType.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"actionType.js","sourceRoot":"","sources":["../../src/mimic/actionType.ts"],"names":[],"mappings":"AAAA,OAAO,EAAsB,YAAY,EAAE,MAAM,EAAE,MAAM,IAAI,CAAA;AAI7D,OAAO,EACL,kBAAkB,GACnB,MAAM,oBAAoB,CAAA;AAC3B,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAKxD,MAAM,CAAC,MAAM,aAAa,GAAG,KAAK,EAChC,KAAW,EACX,KAAoB,EACpB,MAAc,EACd,WAAyB,EACoB,EAAE;IAC/C,2CAA2C;IAC3C,MAAM,kBAAkB,GAAG,WAAW,CAAC,CAAC,CAAC;;iBAE1B,WAAW,CAAC,YAAY,CAAC,GAAG;wBACrB,WAAW,CAAC,YAAY,CAAC,SAAS;SACjD,WAAW,CAAC,gBAAgB,GAAG,CAAC,OAAO,WAAW,CAAC,UAAU;EACpE,WAAW,CAAC,aAAa,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC;;EAEvC,WAAW,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,GAAG,EAAE,EAAE,CAChD,GAAG,GAAG,GAAG,CAAC,UAAU,QAAQ,CAAC,SAAS,GAAG,CAAC,MAAM,QAAQ,CAAC,QAAQ,MAAM,QAAQ,CAAC,UAAU,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,MAAM,QAAQ,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,EAAE,GAAG,CACzI,CAAC,IAAI,CAAC,IAAI,CAAC;CACX,CAAC,CAAC,CAAC,EAAE;CACL,CAAC,CAAC,CAAC,EAAE,CAAC;IAEL,MAAM,GAAG,GAAG,MAAM,YAAY,CAAC;QAC7B,KAAK,EAAE,KAAK;QACZ,MAAM,EAAE;;;;;;;;;;;;;;;;;EAiBV,kBAAkB;0BACM,MAAM;;KAE3B;QACD,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,kBAAkB,EAAE,IAAI,EAAE,mBAAmB,EAAE,CAAC;KACjF,CAAC,CAAC;IACH,MAAM,WAAW,CAAC,GAAG,CAAC,CAAC;IAEvB,OAAO,GAAG,CAAC,MAAM,CAAC;AACpB,CAAC,CAAC"}
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Test Annotation Utility
3
+ *
4
+ * Centralized utility for adding test annotations to Playwright test reports.
5
+ * Provides consistent annotation formatting across all action types.
6
+ */
7
+ import { TestInfo } from '@playwright/test';
8
+ /**
9
+ * Add a test annotation with consistent formatting
10
+ *
11
+ * This function handles the common pattern of adding annotations when testInfo
12
+ * is available, or falling back to console.log when it's not (e.g., in agentic context).
13
+ *
14
+ * @param testInfo - Playwright TestInfo object (optional, for test context)
15
+ * @param gherkinStep - The original Gherkin step that triggered this action (used as annotation type)
16
+ * @param description - The description of what action is being performed (used as annotation description)
17
+ * @returns void
18
+ */
19
+ export declare function addAnnotation(testInfo: TestInfo | undefined, gherkinStep: string | undefined, description: string): void;
20
+ //# sourceMappingURL=annotations.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"annotations.d.ts","sourceRoot":"","sources":["../../src/mimic/annotations.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAE5C;;;;;;;;;;GAUG;AACH,wBAAgB,aAAa,CAC3B,QAAQ,EAAE,QAAQ,GAAG,SAAS,EAC9B,WAAW,EAAE,MAAM,GAAG,SAAS,EAC/B,WAAW,EAAE,MAAM,GAClB,IAAI,CAUN"}
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Test Annotation Utility
3
+ *
4
+ * Centralized utility for adding test annotations to Playwright test reports.
5
+ * Provides consistent annotation formatting across all action types.
6
+ */
7
+ /**
8
+ * Add a test annotation with consistent formatting
9
+ *
10
+ * This function handles the common pattern of adding annotations when testInfo
11
+ * is available, or falling back to console.log when it's not (e.g., in agentic context).
12
+ *
13
+ * @param testInfo - Playwright TestInfo object (optional, for test context)
14
+ * @param gherkinStep - The original Gherkin step that triggered this action (used as annotation type)
15
+ * @param description - The description of what action is being performed (used as annotation description)
16
+ * @returns void
17
+ */
18
+ export function addAnnotation(testInfo, gherkinStep, description) {
19
+ if (testInfo && gherkinStep) {
20
+ testInfo.annotations.push({
21
+ type: gherkinStep,
22
+ description
23
+ });
24
+ }
25
+ else {
26
+ // Fallback to console.log when testInfo is not available (e.g., agentic context)
27
+ console.log(description);
28
+ }
29
+ }
30
+ //# sourceMappingURL=annotations.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"annotations.js","sourceRoot":"","sources":["../../src/mimic/annotations.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH;;;;;;;;;;GAUG;AACH,MAAM,UAAU,aAAa,CAC3B,QAA8B,EAC9B,WAA+B,EAC/B,WAAmB;IAEnB,IAAI,QAAQ,IAAI,WAAW,EAAE,CAAC;QAC5B,QAAQ,CAAC,WAAW,CAAC,IAAI,CAAC;YACxB,IAAI,EAAE,WAAW;YACjB,WAAW;SACZ,CAAC,CAAC;IACL,CAAC;SAAM,CAAC;QACN,iFAAiF;QACjF,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;IAC3B,CAAC;AACH,CAAC"}
@@ -0,0 +1,15 @@
1
+ /**
2
+ * CLI Argument Parsing
3
+ *
4
+ * Utility functions for parsing command-line arguments passed to Playwright tests.
5
+ */
6
+ /**
7
+ * Check if troubleshoot mode is enabled via CLI argument
8
+ *
9
+ * Troubleshoot mode forces tests to rebuild snapshots even when they fail.
10
+ * This is useful for debugging and updating snapshots after fixing issues.
11
+ *
12
+ * @returns true if --troubleshoot flag is present in process.argv
13
+ */
14
+ export declare function isTroubleshootMode(): boolean;
15
+ //# sourceMappingURL=cli.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../../src/mimic/cli.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,IAAI,OAAO,CAE5C"}
@@ -0,0 +1,17 @@
1
+ /**
2
+ * CLI Argument Parsing
3
+ *
4
+ * Utility functions for parsing command-line arguments passed to Playwright tests.
5
+ */
6
+ /**
7
+ * Check if troubleshoot mode is enabled via CLI argument
8
+ *
9
+ * Troubleshoot mode forces tests to rebuild snapshots even when they fail.
10
+ * This is useful for debugging and updating snapshots after fixing issues.
11
+ *
12
+ * @returns true if --troubleshoot flag is present in process.argv
13
+ */
14
+ export function isTroubleshootMode() {
15
+ return true && process.argv.includes('--troubleshoot');
16
+ }
17
+ //# sourceMappingURL=cli.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.js","sourceRoot":"","sources":["../../src/mimic/cli.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;;;;GAOG;AACH,MAAM,UAAU,kBAAkB;IAChC,OAAO,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,gBAAgB,CAAC,CAAC;AACzD,CAAC"}
@@ -0,0 +1,39 @@
1
+ import { type LanguageModel } from 'ai';
2
+ import { Locator, Page, TestInfo } from '@playwright/test';
3
+ import { type ClickActionResult } from './schema/action.js';
4
+ import type { TargetInfo } from './selector.js';
5
+ import type { TestContext } from '../mimic.js';
6
+ /**
7
+ * Get click action by matching Gherkin step against captured target elements
8
+ *
9
+ * This function uses AI to analyze a Gherkin step and match it against
10
+ * all available target elements on the page. It returns the top 5 most
11
+ * likely candidates along with the appropriate click type.
12
+ *
13
+ * @param page - Playwright Page object (currently unused but kept for consistency)
14
+ * @param brain - LanguageModel instance for AI analysis
15
+ * @param gherkinStep - The Gherkin step to match (e.g., "I click on the Submit button")
16
+ * @param targetElements - Array of captured target elements from the page
17
+ * @param testContext - Optional test context with previous steps and current state
18
+ * @returns Promise resolving to ClickActionResult with top candidates and click type
19
+ */
20
+ export declare const getClickAction: (_page: Page, brain: LanguageModel, gherkinStep: string, targetElements: TargetInfo[], testContext?: TestContext) => Promise<ClickActionResult>;
21
+ /**
22
+ * Execute a click action on a page element with plain English annotation
23
+ *
24
+ * This function performs the actual click interaction and logs what action
25
+ * is being performed in human-readable terms for better test traceability.
26
+ * Uses the LLM-generated description from the selected candidate.
27
+ *
28
+ * @param element - Playwright Locator for the target element to interact with
29
+ * @param clickActionResult - Click action result containing click type and target information
30
+ * @param selectedCandidate - The selected candidate element with LLM-generated description
31
+ * @param testInfo - Playwright TestInfo for adding annotations
32
+ * @param gherkinStep - The original Gherkin step for annotation type
33
+ * @returns Promise that resolves to an object containing the action result and selector (for snapshot storage)
34
+ */
35
+ export declare const executeClickAction: (element: Locator | null, clickActionResult: ClickActionResult, selectedCandidate: ClickActionResult["candidates"][0], testInfo: TestInfo | undefined, gherkinStep: string) => Promise<{
36
+ actionResult: ClickActionResult;
37
+ selector: string | null;
38
+ }>;
39
+ //# sourceMappingURL=click.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"click.d.ts","sourceRoot":"","sources":["../../src/mimic/click.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,aAAa,EAAwB,MAAM,IAAI,CAAA;AAC7D,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAA;AAE1D,OAAO,EAEL,KAAK,iBAAiB,EACvB,MAAM,oBAAoB,CAAA;AAC3B,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAG/C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE/C;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,cAAc,GACzB,OAAO,IAAI,EACX,OAAO,aAAa,EACpB,aAAa,MAAM,EACnB,gBAAgB,UAAU,EAAE,EAC5B,cAAc,WAAW,KACxB,OAAO,CAAC,iBAAiB,CA+I3B,CAAC;AAEF;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,kBAAkB,GAC7B,SAAS,OAAO,GAAG,IAAI,EACvB,mBAAmB,iBAAiB,EACpC,mBAAmB,iBAAiB,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,EACrD,UAAU,QAAQ,GAAG,SAAS,EAC9B,aAAa,MAAM,KAClB,OAAO,CAAC;IAAE,YAAY,EAAE,iBAAiB,CAAC;IAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,CAwEtE,CAAC"}