@midscene/core 1.2.2-beta-20260116064919.0 → 1.2.2-beta-20260116071350.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 (66) hide show
  1. package/dist/es/agent/agent.mjs +5 -2
  2. package/dist/es/agent/agent.mjs.map +1 -1
  3. package/dist/es/agent/tasks.mjs +4 -2
  4. package/dist/es/agent/tasks.mjs.map +1 -1
  5. package/dist/es/agent/utils.mjs +1 -1
  6. package/dist/es/ai-model/auto-glm/actions.mjs +224 -0
  7. package/dist/es/ai-model/auto-glm/actions.mjs.map +1 -0
  8. package/dist/es/ai-model/auto-glm/index.mjs +6 -0
  9. package/dist/es/ai-model/auto-glm/parser.mjs +239 -0
  10. package/dist/es/ai-model/auto-glm/parser.mjs.map +1 -0
  11. package/dist/es/ai-model/auto-glm/planning.mjs +63 -0
  12. package/dist/es/ai-model/auto-glm/planning.mjs.map +1 -0
  13. package/dist/es/ai-model/auto-glm/prompt.mjs +222 -0
  14. package/dist/es/ai-model/auto-glm/prompt.mjs.map +1 -0
  15. package/dist/es/ai-model/auto-glm/util.mjs +6 -0
  16. package/dist/es/ai-model/auto-glm/util.mjs.map +1 -0
  17. package/dist/es/ai-model/index.mjs +2 -1
  18. package/dist/es/ai-model/inspect.mjs +68 -3
  19. package/dist/es/ai-model/inspect.mjs.map +1 -1
  20. package/dist/es/ai-model/service-caller/index.mjs +5 -0
  21. package/dist/es/ai-model/service-caller/index.mjs.map +1 -1
  22. package/dist/es/ai-model/ui-tars-planning.mjs +24 -21
  23. package/dist/es/ai-model/ui-tars-planning.mjs.map +1 -1
  24. package/dist/es/common.mjs +15 -2
  25. package/dist/es/common.mjs.map +1 -1
  26. package/dist/es/service/index.mjs +5 -0
  27. package/dist/es/service/index.mjs.map +1 -1
  28. package/dist/es/utils.mjs +2 -2
  29. package/dist/lib/agent/agent.js +5 -2
  30. package/dist/lib/agent/agent.js.map +1 -1
  31. package/dist/lib/agent/tasks.js +3 -1
  32. package/dist/lib/agent/tasks.js.map +1 -1
  33. package/dist/lib/agent/utils.js +1 -1
  34. package/dist/lib/ai-model/auto-glm/actions.js +258 -0
  35. package/dist/lib/ai-model/auto-glm/actions.js.map +1 -0
  36. package/dist/lib/ai-model/auto-glm/index.js +63 -0
  37. package/dist/lib/ai-model/auto-glm/index.js.map +1 -0
  38. package/dist/lib/ai-model/auto-glm/parser.js +282 -0
  39. package/dist/lib/ai-model/auto-glm/parser.js.map +1 -0
  40. package/dist/lib/ai-model/auto-glm/planning.js +97 -0
  41. package/dist/lib/ai-model/auto-glm/planning.js.map +1 -0
  42. package/dist/lib/ai-model/auto-glm/prompt.js +259 -0
  43. package/dist/lib/ai-model/auto-glm/prompt.js.map +1 -0
  44. package/dist/lib/ai-model/auto-glm/util.js +40 -0
  45. package/dist/lib/ai-model/auto-glm/util.js.map +1 -0
  46. package/dist/lib/ai-model/index.js +15 -11
  47. package/dist/lib/ai-model/inspect.js +67 -2
  48. package/dist/lib/ai-model/inspect.js.map +1 -1
  49. package/dist/lib/ai-model/service-caller/index.js +5 -0
  50. package/dist/lib/ai-model/service-caller/index.js.map +1 -1
  51. package/dist/lib/ai-model/ui-tars-planning.js +24 -21
  52. package/dist/lib/ai-model/ui-tars-planning.js.map +1 -1
  53. package/dist/lib/common.js +18 -2
  54. package/dist/lib/common.js.map +1 -1
  55. package/dist/lib/service/index.js +5 -0
  56. package/dist/lib/service/index.js.map +1 -1
  57. package/dist/lib/utils.js +2 -2
  58. package/dist/types/ai-model/auto-glm/actions.d.ts +77 -0
  59. package/dist/types/ai-model/auto-glm/index.d.ts +6 -0
  60. package/dist/types/ai-model/auto-glm/parser.d.ts +18 -0
  61. package/dist/types/ai-model/auto-glm/planning.d.ts +9 -0
  62. package/dist/types/ai-model/auto-glm/prompt.d.ts +27 -0
  63. package/dist/types/ai-model/auto-glm/util.d.ts +7 -0
  64. package/dist/types/ai-model/index.d.ts +1 -0
  65. package/dist/types/common.d.ts +10 -0
  66. package/package.json +2 -2
@@ -150,7 +150,7 @@ async function matchElementFromCache(context, cacheEntry, cachePrompt, cacheable
150
150
  return;
151
151
  }
152
152
  }
153
- const getMidsceneVersion = ()=>"1.2.2-beta-20260116064919.0";
153
+ const getMidsceneVersion = ()=>"1.2.2-beta-20260116071350.0";
154
154
  const parsePrompt = (prompt)=>{
155
155
  if ('string' == typeof prompt) return {
156
156
  textPrompt: prompt,
@@ -0,0 +1,258 @@
1
+ "use strict";
2
+ var __webpack_require__ = {};
3
+ (()=>{
4
+ __webpack_require__.d = (exports1, definition)=>{
5
+ for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
6
+ enumerable: true,
7
+ get: definition[key]
8
+ });
9
+ };
10
+ })();
11
+ (()=>{
12
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
13
+ })();
14
+ (()=>{
15
+ __webpack_require__.r = (exports1)=>{
16
+ if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
17
+ value: 'Module'
18
+ });
19
+ Object.defineProperty(exports1, '__esModule', {
20
+ value: true
21
+ });
22
+ };
23
+ })();
24
+ var __webpack_exports__ = {};
25
+ __webpack_require__.r(__webpack_exports__);
26
+ __webpack_require__.d(__webpack_exports__, {
27
+ transformAutoGLMAction: ()=>transformAutoGLMAction
28
+ });
29
+ const external_common_js_namespaceObject = require("../../common.js");
30
+ const logger_namespaceObject = require("@midscene/shared/logger");
31
+ const debug = (0, logger_namespaceObject.getDebug)('auto-glm-actions');
32
+ const AUTO_GLM_COORDINATE_MAX = 1000;
33
+ function autoGLMCoordinateToBbox(x, y, width, height) {
34
+ const bbox = (0, external_common_js_namespaceObject.pointToBbox)(x, y, 10);
35
+ return (0, external_common_js_namespaceObject.adaptBbox)(bbox, width, height, width, height, 'auto-glm');
36
+ }
37
+ function transformAutoGLMAction(action, size) {
38
+ try {
39
+ switch(action._metadata){
40
+ case 'finish':
41
+ {
42
+ const finishAction = action;
43
+ debug('Transform finish action:', finishAction);
44
+ return [
45
+ {
46
+ type: 'Finished',
47
+ param: {},
48
+ thought: finishAction.message
49
+ }
50
+ ];
51
+ }
52
+ case 'do':
53
+ {
54
+ const doAction = action;
55
+ switch(doAction.action){
56
+ case 'Tap':
57
+ {
58
+ const tapAction = doAction;
59
+ debug('Transform Tap action:', tapAction);
60
+ const [x1, y1, x2, y2] = autoGLMCoordinateToBbox(tapAction.element[0], tapAction.element[1], size.width, size.height);
61
+ const locate = {
62
+ prompt: '',
63
+ bbox: [
64
+ x1,
65
+ y1,
66
+ x2,
67
+ y2
68
+ ]
69
+ };
70
+ return [
71
+ {
72
+ type: 'Tap',
73
+ param: {
74
+ locate
75
+ }
76
+ }
77
+ ];
78
+ }
79
+ case 'Double Tap':
80
+ {
81
+ const doubleTapAction = doAction;
82
+ debug('Transform Double Tap action:', doubleTapAction);
83
+ const [x1, y1, x2, y2] = autoGLMCoordinateToBbox(doubleTapAction.element[0], doubleTapAction.element[1], size.width, size.height);
84
+ const locate = {
85
+ prompt: '',
86
+ bbox: [
87
+ x1,
88
+ y1,
89
+ x2,
90
+ y2
91
+ ]
92
+ };
93
+ return [
94
+ {
95
+ type: 'DoubleClick',
96
+ param: {
97
+ locate
98
+ }
99
+ }
100
+ ];
101
+ }
102
+ case 'Type':
103
+ {
104
+ const typeAction = doAction;
105
+ debug('Transform Type action:', typeAction);
106
+ return [
107
+ {
108
+ type: 'Input',
109
+ param: {
110
+ value: typeAction.text
111
+ }
112
+ }
113
+ ];
114
+ }
115
+ case 'Swipe':
116
+ {
117
+ const swipeAction = doAction;
118
+ debug('Transform Swipe action:', swipeAction);
119
+ const [x1, y1, x2, y2] = autoGLMCoordinateToBbox(swipeAction.start[0], swipeAction.start[1], size.width, size.height);
120
+ const locate = {
121
+ prompt: '',
122
+ bbox: [
123
+ x1,
124
+ y1,
125
+ x2,
126
+ y2
127
+ ]
128
+ };
129
+ const deltaX = swipeAction.end[0] - swipeAction.start[0];
130
+ const deltaY = swipeAction.end[1] - swipeAction.start[1];
131
+ let direction;
132
+ let distance;
133
+ const absDeltaX = Math.abs(deltaX);
134
+ const absDeltaY = Math.abs(deltaY);
135
+ if (absDeltaY > absDeltaX) {
136
+ distance = Math.round(absDeltaY * size.height / AUTO_GLM_COORDINATE_MAX);
137
+ direction = deltaY > 0 ? 'up' : 'down';
138
+ } else {
139
+ distance = Math.round(absDeltaX * size.width / AUTO_GLM_COORDINATE_MAX);
140
+ direction = deltaX > 0 ? 'left' : 'right';
141
+ }
142
+ debug(`Calculate swipe direction: ${direction}, distance: ${distance}`);
143
+ return [
144
+ {
145
+ type: 'Scroll',
146
+ param: {
147
+ locate,
148
+ distance,
149
+ direction
150
+ },
151
+ thought: swipeAction.think || ''
152
+ }
153
+ ];
154
+ }
155
+ case 'Long Press':
156
+ {
157
+ const longPressAction = doAction;
158
+ debug('Transform Long Press action:', longPressAction);
159
+ const [x1, y1, x2, y2] = autoGLMCoordinateToBbox(longPressAction.element[0], longPressAction.element[1], size.width, size.height);
160
+ const locate = {
161
+ prompt: '',
162
+ bbox: [
163
+ x1,
164
+ y1,
165
+ x2,
166
+ y2
167
+ ]
168
+ };
169
+ return [
170
+ {
171
+ type: 'AndroidLongPress',
172
+ param: {
173
+ locate
174
+ },
175
+ thought: longPressAction.think || ''
176
+ }
177
+ ];
178
+ }
179
+ case 'Back':
180
+ {
181
+ const backAction = doAction;
182
+ debug('Transform Back action:', backAction);
183
+ return [
184
+ {
185
+ type: 'AndroidBackButton',
186
+ param: {},
187
+ thought: backAction.think || ''
188
+ }
189
+ ];
190
+ }
191
+ case 'Home':
192
+ {
193
+ const homeAction = doAction;
194
+ debug('Transform Home action:', homeAction);
195
+ return [
196
+ {
197
+ type: 'AndroidHomeButton',
198
+ param: {},
199
+ thought: homeAction.think || ''
200
+ }
201
+ ];
202
+ }
203
+ case 'Wait':
204
+ {
205
+ const waitAction = doAction;
206
+ debug('Transform Wait action:', waitAction);
207
+ return [
208
+ {
209
+ type: 'Sleep',
210
+ param: {
211
+ timeMs: waitAction.durationMs
212
+ },
213
+ thought: waitAction.think || ''
214
+ }
215
+ ];
216
+ }
217
+ case 'Launch':
218
+ {
219
+ const launchAction = doAction;
220
+ debug('Transform Launch action:', launchAction);
221
+ return [
222
+ {
223
+ type: 'Launch',
224
+ param: launchAction.app,
225
+ thought: launchAction.think || ''
226
+ }
227
+ ];
228
+ }
229
+ case 'Interact':
230
+ throw new Error('Action "Interact" from auto-glm is not supported in the current implementation.');
231
+ case 'Call_API':
232
+ throw new Error('Action "Call_API" from auto-glm is not supported in the current implementation.');
233
+ case 'Take_over':
234
+ throw new Error('Action "Take_over" from auto-glm is not supported in the current implementation.');
235
+ case 'Note':
236
+ throw new Error('Action "Note" from auto-glm is not supported in the current implementation.');
237
+ default:
238
+ throw new Error(`Unknown do() action type: ${doAction.action}`);
239
+ }
240
+ }
241
+ default:
242
+ throw new Error(`Unknown action metadata: ${action._metadata}`);
243
+ }
244
+ } catch (error) {
245
+ const errorMessage = error instanceof Error ? error.message : String(error);
246
+ debug('Transform error:', errorMessage);
247
+ throw new Error(`Failed to transform action: ${errorMessage}`);
248
+ }
249
+ }
250
+ exports.transformAutoGLMAction = __webpack_exports__.transformAutoGLMAction;
251
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
252
+ "transformAutoGLMAction"
253
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
254
+ Object.defineProperty(exports, '__esModule', {
255
+ value: true
256
+ });
257
+
258
+ //# sourceMappingURL=actions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ai-model/auto-glm/actions.js","sources":["webpack/runtime/define_property_getters","webpack/runtime/has_own_property","webpack/runtime/make_namespace_object","../../../../src/ai-model/auto-glm/actions.ts"],"sourcesContent":["__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n }\n }\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","import { adaptBbox, pointToBbox } from '@/common';\nimport type { PlanningAction } from '@/types';\nimport { getDebug } from '@midscene/shared/logger';\n\nconst debug = getDebug('auto-glm-actions');\n\n/**\n * Auto-GLM coordinate system range: [0, AUTO_GLM_COORDINATE_MAX]\n */\nconst AUTO_GLM_COORDINATE_MAX = 1000;\n\n/**\n * Convert auto-glm coordinate [0,1000] to bbox in pixel coordinates\n */\nfunction autoGLMCoordinateToBbox(\n x: number,\n y: number,\n width: number,\n height: number,\n): [number, number, number, number] {\n const bbox = pointToBbox(x, y, 10);\n return adaptBbox(bbox, width, height, width, height, 'auto-glm');\n}\n\nexport interface BaseAction {\n _metadata: string;\n think?: string;\n}\n\nexport interface TapAction extends BaseAction {\n _metadata: 'do';\n action: 'Tap';\n element: [number, number];\n}\n\nexport interface DoubleTapAction extends BaseAction {\n _metadata: 'do';\n action: 'Double Tap';\n element: [number, number];\n}\n\nexport interface TypeAction extends BaseAction {\n _metadata: 'do';\n action: 'Type';\n text: string;\n}\n\nexport interface SwipeAction extends BaseAction {\n _metadata: 'do';\n action: 'Swipe';\n start: [number, number];\n end: [number, number];\n}\n\nexport interface LongPressAction extends BaseAction {\n _metadata: 'do';\n action: 'Long Press';\n element: [number, number];\n}\n\nexport interface LaunchAction extends BaseAction {\n _metadata: 'do';\n action: 'Launch';\n app: string;\n}\n\nexport interface BackAction extends BaseAction {\n _metadata: 'do';\n action: 'Back';\n}\n\nexport interface HomeAction extends BaseAction {\n _metadata: 'do';\n action: 'Home';\n}\n\nexport interface WaitAction extends BaseAction {\n _metadata: 'do';\n action: 'Wait';\n durationMs: number;\n}\n\nexport interface InteractAction extends BaseAction {\n _metadata: 'do';\n action: 'Interact';\n}\n\nexport interface CallAPIAction extends BaseAction {\n _metadata: 'do';\n action: 'Call_API';\n instruction: string;\n}\n\nexport interface TakeoverAction extends BaseAction {\n _metadata: 'do';\n action: 'Take_over';\n message: string;\n}\n\nexport interface NoteAction extends BaseAction {\n _metadata: 'do';\n action: 'Note';\n message: string;\n}\n\nexport interface FinishAction extends BaseAction {\n _metadata: 'finish';\n message: string;\n}\n\nexport type ParsedAction =\n | TapAction\n | DoubleTapAction\n | TypeAction\n | SwipeAction\n | LongPressAction\n | LaunchAction\n | BackAction\n | HomeAction\n | WaitAction\n | InteractAction\n | CallAPIAction\n | TakeoverAction\n | NoteAction\n | FinishAction;\n\nexport function transformAutoGLMAction(\n action: ParsedAction,\n size: { width: number; height: number },\n): PlanningAction[] {\n try {\n switch (action._metadata) {\n case 'finish': {\n const finishAction = action as FinishAction;\n debug('Transform finish action:', finishAction);\n return [\n {\n type: 'Finished',\n param: {},\n thought: finishAction.message,\n },\n ];\n }\n case 'do': {\n const doAction = action as\n | TapAction\n | DoubleTapAction\n | TypeAction\n | SwipeAction\n | LongPressAction\n | LaunchAction\n | BackAction\n | HomeAction\n | WaitAction\n | InteractAction\n | CallAPIAction\n | TakeoverAction\n | NoteAction;\n\n switch ((doAction as any).action) {\n case 'Tap': {\n const tapAction = doAction as TapAction;\n debug('Transform Tap action:', tapAction);\n const [x1, y1, x2, y2] = autoGLMCoordinateToBbox(\n tapAction.element[0],\n tapAction.element[1],\n size.width,\n size.height,\n );\n\n const locate: {\n prompt: string;\n bbox: [number, number, number, number];\n } = {\n prompt: '',\n bbox: [x1, y1, x2, y2],\n };\n\n return [\n {\n type: 'Tap',\n param: {\n locate,\n },\n },\n ];\n }\n case 'Double Tap': {\n const doubleTapAction = doAction as DoubleTapAction;\n debug('Transform Double Tap action:', doubleTapAction);\n const [x1, y1, x2, y2] = autoGLMCoordinateToBbox(\n doubleTapAction.element[0],\n doubleTapAction.element[1],\n size.width,\n size.height,\n );\n\n const locate: {\n prompt: string;\n bbox: [number, number, number, number];\n } = {\n prompt: '',\n bbox: [x1, y1, x2, y2],\n };\n\n return [\n {\n type: 'DoubleClick',\n param: {\n locate,\n },\n },\n ];\n }\n case 'Type': {\n const typeAction = doAction as TypeAction;\n debug('Transform Type action:', typeAction);\n\n return [\n {\n type: 'Input',\n param: {\n value: typeAction.text,\n },\n },\n ];\n }\n case 'Swipe': {\n const swipeAction = doAction as SwipeAction;\n debug('Transform Swipe action:', swipeAction);\n\n // Calculate locate using start coordinate\n const [x1, y1, x2, y2] = autoGLMCoordinateToBbox(\n swipeAction.start[0],\n swipeAction.start[1],\n size.width,\n size.height,\n );\n\n const locate: {\n prompt: string;\n bbox: [number, number, number, number];\n } = {\n prompt: '',\n bbox: [x1, y1, x2, y2],\n };\n\n // Calculate horizontal and vertical delta in [0,AUTO_GLM_COORDINATE_MAX] coordinate system\n const deltaX = swipeAction.end[0] - swipeAction.start[0];\n const deltaY = swipeAction.end[1] - swipeAction.start[1];\n\n // Determine direction and distance\n let direction: 'up' | 'down' | 'left' | 'right';\n let distance: number;\n\n const absDeltaX = Math.abs(deltaX);\n const absDeltaY = Math.abs(deltaY);\n\n if (absDeltaY > absDeltaX) {\n // Vertical scroll\n distance = Math.round(\n (absDeltaY * size.height) / AUTO_GLM_COORDINATE_MAX,\n );\n direction = deltaY > 0 ? 'up' : 'down';\n } else {\n // Horizontal scroll\n distance = Math.round(\n (absDeltaX * size.width) / AUTO_GLM_COORDINATE_MAX,\n );\n direction = deltaX > 0 ? 'left' : 'right';\n }\n\n debug(\n `Calculate swipe direction: ${direction}, distance: ${distance}`,\n );\n\n return [\n {\n type: 'Scroll',\n param: {\n locate,\n // The scrolling direction here all refers to which direction of the page's content will appear on the screen.\n distance,\n direction,\n },\n thought: swipeAction.think || '',\n },\n ];\n }\n case 'Long Press': {\n const longPressAction = doAction as LongPressAction;\n debug('Transform Long Press action:', longPressAction);\n const [x1, y1, x2, y2] = autoGLMCoordinateToBbox(\n longPressAction.element[0],\n longPressAction.element[1],\n size.width,\n size.height,\n );\n\n const locate: {\n prompt: string;\n bbox: [number, number, number, number];\n } = {\n prompt: '',\n bbox: [x1, y1, x2, y2],\n };\n\n return [\n {\n type: 'AndroidLongPress',\n param: {\n locate,\n },\n thought: longPressAction.think || '',\n },\n ];\n }\n case 'Back': {\n const backAction = doAction as BackAction;\n debug('Transform Back action:', backAction);\n return [\n {\n type: 'AndroidBackButton',\n param: {},\n thought: backAction.think || '',\n },\n ];\n }\n case 'Home': {\n const homeAction = doAction as HomeAction;\n debug('Transform Home action:', homeAction);\n return [\n {\n type: 'AndroidHomeButton',\n param: {},\n thought: homeAction.think || '',\n },\n ];\n }\n case 'Wait': {\n const waitAction = doAction as WaitAction;\n debug('Transform Wait action:', waitAction);\n return [\n {\n type: 'Sleep',\n param: {\n timeMs: waitAction.durationMs,\n },\n thought: waitAction.think || '',\n },\n ];\n }\n case 'Launch': {\n const launchAction = doAction as LaunchAction;\n debug('Transform Launch action:', launchAction);\n return [\n {\n type: 'Launch',\n param: launchAction.app,\n thought: launchAction.think || '',\n },\n ];\n }\n case 'Interact': {\n throw new Error(\n `Action \"Interact\" from auto-glm is not supported in the current implementation.`,\n );\n }\n case 'Call_API': {\n throw new Error(\n `Action \"Call_API\" from auto-glm is not supported in the current implementation.`,\n );\n }\n case 'Take_over': {\n throw new Error(\n `Action \"Take_over\" from auto-glm is not supported in the current implementation.`,\n );\n }\n case 'Note': {\n throw new Error(\n `Action \"Note\" from auto-glm is not supported in the current implementation.`,\n );\n }\n default:\n throw new Error(\n `Unknown do() action type: ${(doAction as any).action}`,\n );\n }\n }\n default:\n throw new Error(\n `Unknown action metadata: ${(action as any)._metadata}`,\n );\n }\n } catch (error) {\n const errorMessage = error instanceof Error ? error.message : String(error);\n debug('Transform error:', errorMessage);\n throw new Error(`Failed to transform action: ${errorMessage}`);\n }\n}\n"],"names":["__webpack_require__","definition","key","Object","obj","prop","Symbol","debug","getDebug","AUTO_GLM_COORDINATE_MAX","autoGLMCoordinateToBbox","x","y","width","height","bbox","pointToBbox","adaptBbox","transformAutoGLMAction","action","size","finishAction","doAction","tapAction","x1","y1","x2","y2","locate","doubleTapAction","typeAction","swipeAction","deltaX","deltaY","direction","distance","absDeltaX","Math","absDeltaY","longPressAction","backAction","homeAction","waitAction","launchAction","Error","error","errorMessage","String"],"mappings":";;;IAAAA,oBAAoB,CAAC,GAAG,CAAC,UAASC;QACjC,IAAI,IAAIC,OAAOD,WACR,IAAGD,oBAAoB,CAAC,CAACC,YAAYC,QAAQ,CAACF,oBAAoB,CAAC,CAAC,UAASE,MACzEC,OAAO,cAAc,CAAC,UAASD,KAAK;YAAE,YAAY;YAAM,KAAKD,UAAU,CAACC,IAAI;QAAC;IAGzF;;;ICNAF,oBAAoB,CAAC,GAAG,CAACI,KAAKC,OAAUF,OAAO,SAAS,CAAC,cAAc,CAAC,IAAI,CAACC,KAAKC;;;ICClFL,oBAAoB,CAAC,GAAG,CAAC;QACxB,IAAG,AAAkB,eAAlB,OAAOM,UAA0BA,OAAO,WAAW,EACrDH,OAAO,cAAc,CAAC,UAASG,OAAO,WAAW,EAAE;YAAE,OAAO;QAAS;QAEtEH,OAAO,cAAc,CAAC,UAAS,cAAc;YAAE,OAAO;QAAK;IAC5D;;;;;;;;;ACFA,MAAMI,QAAQC,AAAAA,IAAAA,uBAAAA,QAAAA,AAAAA,EAAS;AAKvB,MAAMC,0BAA0B;AAKhC,SAASC,wBACPC,CAAS,EACTC,CAAS,EACTC,KAAa,EACbC,MAAc;IAEd,MAAMC,OAAOC,AAAAA,IAAAA,mCAAAA,WAAAA,AAAAA,EAAYL,GAAGC,GAAG;IAC/B,OAAOK,AAAAA,IAAAA,mCAAAA,SAAAA,AAAAA,EAAUF,MAAMF,OAAOC,QAAQD,OAAOC,QAAQ;AACvD;AAwGO,SAASI,uBACdC,MAAoB,EACpBC,IAAuC;IAEvC,IA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O0B,OAAO;QACd,MAAMC,eAAeD,iBAAiBD,QAAQC,MAAM,OAAO,GAAGE,OAAOF;QACrEtC,MAAM,oBAAoBuC;QAC1B,MAAM,IAAIF,MAAM,CAAC,4BAA4B,EAAEE,cAAc;IAC/D;AACF"}
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+ var __webpack_require__ = {};
3
+ (()=>{
4
+ __webpack_require__.d = (exports1, definition)=>{
5
+ for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
6
+ enumerable: true,
7
+ get: definition[key]
8
+ });
9
+ };
10
+ })();
11
+ (()=>{
12
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
13
+ })();
14
+ (()=>{
15
+ __webpack_require__.r = (exports1)=>{
16
+ if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
17
+ value: 'Module'
18
+ });
19
+ Object.defineProperty(exports1, '__esModule', {
20
+ value: true
21
+ });
22
+ };
23
+ })();
24
+ var __webpack_exports__ = {};
25
+ __webpack_require__.r(__webpack_exports__);
26
+ __webpack_require__.d(__webpack_exports__, {
27
+ parseAction: ()=>external_parser_js_namespaceObject.parseAction,
28
+ isAutoGLM: ()=>external_util_js_namespaceObject.isAutoGLM,
29
+ autoGLMPlanning: ()=>external_planning_js_namespaceObject.autoGLMPlanning,
30
+ getAutoGLMPlanPrompt: ()=>external_prompt_js_namespaceObject.getAutoGLMPlanPrompt,
31
+ getAutoGLMLocatePrompt: ()=>external_prompt_js_namespaceObject.getAutoGLMLocatePrompt,
32
+ transformAutoGLMAction: ()=>external_actions_js_namespaceObject.transformAutoGLMAction,
33
+ parseAutoGLMLocateResponse: ()=>external_parser_js_namespaceObject.parseAutoGLMLocateResponse,
34
+ parseAutoGLMResponse: ()=>external_parser_js_namespaceObject.parseAutoGLMResponse
35
+ });
36
+ const external_prompt_js_namespaceObject = require("./prompt.js");
37
+ const external_parser_js_namespaceObject = require("./parser.js");
38
+ const external_planning_js_namespaceObject = require("./planning.js");
39
+ const external_actions_js_namespaceObject = require("./actions.js");
40
+ const external_util_js_namespaceObject = require("./util.js");
41
+ exports.autoGLMPlanning = __webpack_exports__.autoGLMPlanning;
42
+ exports.getAutoGLMLocatePrompt = __webpack_exports__.getAutoGLMLocatePrompt;
43
+ exports.getAutoGLMPlanPrompt = __webpack_exports__.getAutoGLMPlanPrompt;
44
+ exports.isAutoGLM = __webpack_exports__.isAutoGLM;
45
+ exports.parseAction = __webpack_exports__.parseAction;
46
+ exports.parseAutoGLMLocateResponse = __webpack_exports__.parseAutoGLMLocateResponse;
47
+ exports.parseAutoGLMResponse = __webpack_exports__.parseAutoGLMResponse;
48
+ exports.transformAutoGLMAction = __webpack_exports__.transformAutoGLMAction;
49
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
50
+ "autoGLMPlanning",
51
+ "getAutoGLMLocatePrompt",
52
+ "getAutoGLMPlanPrompt",
53
+ "isAutoGLM",
54
+ "parseAction",
55
+ "parseAutoGLMLocateResponse",
56
+ "parseAutoGLMResponse",
57
+ "transformAutoGLMAction"
58
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
59
+ Object.defineProperty(exports, '__esModule', {
60
+ value: true
61
+ });
62
+
63
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ai-model/auto-glm/index.js","sources":["webpack/runtime/define_property_getters","webpack/runtime/has_own_property","webpack/runtime/make_namespace_object"],"sourcesContent":["__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n }\n }\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};"],"names":["__webpack_require__","definition","key","Object","obj","prop","Symbol"],"mappings":";;;IAAAA,oBAAoB,CAAC,GAAG,CAAC,UAASC;QACjC,IAAI,IAAIC,OAAOD,WACR,IAAGD,oBAAoB,CAAC,CAACC,YAAYC,QAAQ,CAACF,oBAAoB,CAAC,CAAC,UAASE,MACzEC,OAAO,cAAc,CAAC,UAASD,KAAK;YAAE,YAAY;YAAM,KAAKD,UAAU,CAACC,IAAI;QAAC;IAGzF;;;ICNAF,oBAAoB,CAAC,GAAG,CAACI,KAAKC,OAAUF,OAAO,SAAS,CAAC,cAAc,CAAC,IAAI,CAACC,KAAKC;;;ICClFL,oBAAoB,CAAC,GAAG,CAAC;QACxB,IAAG,AAAkB,eAAlB,OAAOM,UAA0BA,OAAO,WAAW,EACrDH,OAAO,cAAc,CAAC,UAASG,OAAO,WAAW,EAAE;YAAE,OAAO;QAAS;QAEtEH,OAAO,cAAc,CAAC,UAAS,cAAc;YAAE,OAAO;QAAK;IAC5D"}
@@ -0,0 +1,282 @@
1
+ "use strict";
2
+ var __webpack_require__ = {};
3
+ (()=>{
4
+ __webpack_require__.d = (exports1, definition)=>{
5
+ for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
6
+ enumerable: true,
7
+ get: definition[key]
8
+ });
9
+ };
10
+ })();
11
+ (()=>{
12
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
13
+ })();
14
+ (()=>{
15
+ __webpack_require__.r = (exports1)=>{
16
+ if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
17
+ value: 'Module'
18
+ });
19
+ Object.defineProperty(exports1, '__esModule', {
20
+ value: true
21
+ });
22
+ };
23
+ })();
24
+ var __webpack_exports__ = {};
25
+ __webpack_require__.r(__webpack_exports__);
26
+ __webpack_require__.d(__webpack_exports__, {
27
+ extractValueAfter: ()=>extractValueAfter,
28
+ parseAction: ()=>parseAction,
29
+ parseAutoGLMLocateResponse: ()=>parseAutoGLMLocateResponse,
30
+ parseAutoGLMResponse: ()=>parseAutoGLMResponse
31
+ });
32
+ const logger_namespaceObject = require("@midscene/shared/logger");
33
+ const debug = (0, logger_namespaceObject.getDebug)('auto-glm-parser');
34
+ const extractValueAfter = (src, key)=>{
35
+ const idx = src.indexOf(key);
36
+ if (-1 === idx) throw new Error(`Missing key ${key} in action payload ${src}`);
37
+ let rest = src.slice(idx + key.length).trim();
38
+ if (rest.endsWith('")')) rest = rest.slice(0, -2);
39
+ return rest;
40
+ };
41
+ function parseAction(response) {
42
+ debug('Parsing action:', response);
43
+ let trimmedResponse = '';
44
+ try {
45
+ trimmedResponse = response.content.trim();
46
+ if (trimmedResponse.startsWith('do(action="Type"') || trimmedResponse.startsWith('do(action="Type_Name"')) {
47
+ const text = extractValueAfter(trimmedResponse, 'text="');
48
+ return {
49
+ _metadata: 'do',
50
+ action: 'Type',
51
+ text,
52
+ think: response.think
53
+ };
54
+ }
55
+ if (trimmedResponse.startsWith('finish(message=')) {
56
+ let message = extractValueAfter(trimmedResponse, 'finish(message="');
57
+ if (message.endsWith(')')) message = message.slice(0, -1);
58
+ return {
59
+ _metadata: 'finish',
60
+ message,
61
+ think: response.think
62
+ };
63
+ }
64
+ if (trimmedResponse.startsWith('do(')) {
65
+ const actionMatch = trimmedResponse.match(/do\(action="([^"]+)"/);
66
+ if (!actionMatch) throw new Error(`Failed to extract action type from do() call; raw="${trimmedResponse}"`);
67
+ const actionType = actionMatch[1];
68
+ const baseAction = {
69
+ _metadata: 'do',
70
+ think: response.think
71
+ };
72
+ switch(actionType){
73
+ case 'Tap':
74
+ {
75
+ const elementMatch = trimmedResponse.match(/element=\[(\d+),(\d+)\]/);
76
+ if (!elementMatch) throw new Error(`Failed to extract element coordinates for Tap; raw="${trimmedResponse}"`);
77
+ return {
78
+ ...baseAction,
79
+ action: 'Tap',
80
+ element: [
81
+ Number(elementMatch[1]),
82
+ Number(elementMatch[2])
83
+ ]
84
+ };
85
+ }
86
+ case 'Double Tap':
87
+ {
88
+ const elementMatch = trimmedResponse.match(/element=\[(\d+),(\d+)\]/);
89
+ if (!elementMatch) throw new Error(`Failed to extract element coordinates for Double Tap; raw="${trimmedResponse}"`);
90
+ return {
91
+ ...baseAction,
92
+ action: 'Double Tap',
93
+ element: [
94
+ Number(elementMatch[1]),
95
+ Number(elementMatch[2])
96
+ ]
97
+ };
98
+ }
99
+ case 'Swipe':
100
+ {
101
+ const startMatch = trimmedResponse.match(/start=\[(\d+),(\d+)\]/);
102
+ const endMatch = trimmedResponse.match(/end=\[(\d+),(\d+)\]/);
103
+ if (!startMatch || !endMatch) throw new Error(`Failed to extract start/end coordinates for Swipe; raw="${trimmedResponse}"`);
104
+ return {
105
+ ...baseAction,
106
+ action: 'Swipe',
107
+ start: [
108
+ Number(startMatch[1]),
109
+ Number(startMatch[2])
110
+ ],
111
+ end: [
112
+ Number(endMatch[1]),
113
+ Number(endMatch[2])
114
+ ]
115
+ };
116
+ }
117
+ case 'Long Press':
118
+ {
119
+ const elementMatch = trimmedResponse.match(/element=\[(\d+),(\d+)\]/);
120
+ if (!elementMatch) throw new Error(`Failed to extract element coordinates for Long Press; raw="${trimmedResponse}"`);
121
+ return {
122
+ ...baseAction,
123
+ action: 'Long Press',
124
+ element: [
125
+ Number(elementMatch[1]),
126
+ Number(elementMatch[2])
127
+ ]
128
+ };
129
+ }
130
+ case 'Launch':
131
+ {
132
+ const app = extractValueAfter(trimmedResponse, 'app="');
133
+ return {
134
+ ...baseAction,
135
+ action: 'Launch',
136
+ app
137
+ };
138
+ }
139
+ case 'Back':
140
+ return {
141
+ ...baseAction,
142
+ action: 'Back'
143
+ };
144
+ case 'Home':
145
+ return {
146
+ ...baseAction,
147
+ action: 'Home'
148
+ };
149
+ case 'Wait':
150
+ {
151
+ const durationMatch = trimmedResponse.match(/duration=(?:["\[])?(\d+)/);
152
+ if (!durationMatch) throw new Error(`Failed to extract duration for Wait; raw="${trimmedResponse}"`);
153
+ const seconds = Number.parseInt(durationMatch[1], 10);
154
+ const durationMs = 1000 * seconds;
155
+ return {
156
+ ...baseAction,
157
+ action: 'Wait',
158
+ durationMs
159
+ };
160
+ }
161
+ case 'Interact':
162
+ return {
163
+ ...baseAction,
164
+ action: 'Interact'
165
+ };
166
+ case 'Call_API':
167
+ {
168
+ const instruction = extractValueAfter(trimmedResponse, 'instruction="');
169
+ return {
170
+ ...baseAction,
171
+ action: 'Call_API',
172
+ instruction
173
+ };
174
+ }
175
+ case 'Take_over':
176
+ {
177
+ const message = extractValueAfter(trimmedResponse, 'message="');
178
+ return {
179
+ ...baseAction,
180
+ action: 'Take_over',
181
+ message
182
+ };
183
+ }
184
+ case 'Note':
185
+ {
186
+ const message = extractValueAfter(trimmedResponse, 'message="');
187
+ return {
188
+ ...baseAction,
189
+ action: 'Note',
190
+ message
191
+ };
192
+ }
193
+ default:
194
+ throw new Error(`Unknown action type: ${actionType}; raw="${trimmedResponse}"`);
195
+ }
196
+ }
197
+ throw new Error(`Failed to parse action: ${trimmedResponse}`);
198
+ } catch (error) {
199
+ const errorMessage = error instanceof Error ? error.message : String(error);
200
+ throw new Error(`Failed to parse action: ${errorMessage}; raw="${trimmedResponse}"`);
201
+ }
202
+ }
203
+ function parseAutoGLMResponse(content) {
204
+ if (content.includes('finish(message=')) {
205
+ const parts = content.split('finish(message=');
206
+ const think = parts[0].trim();
207
+ const actionContent = `finish(message=${parts[1]}`;
208
+ return {
209
+ think,
210
+ content: actionContent
211
+ };
212
+ }
213
+ if (content.includes('do(action=')) {
214
+ const parts = content.split('do(action=');
215
+ const think = parts[0].trim();
216
+ const actionContent = `do(action=${parts[1]}`;
217
+ return {
218
+ think,
219
+ content: actionContent
220
+ };
221
+ }
222
+ if (content.includes('<answer>')) {
223
+ const parts = content.split('<answer>');
224
+ const think = parts[0].replace(/<think>/g, '').replace(/<\/think>/g, '').trim();
225
+ const actionContent = parts[1].replace(/<\/answer>/g, '').trim();
226
+ return {
227
+ think,
228
+ content: actionContent
229
+ };
230
+ }
231
+ return {
232
+ think: '',
233
+ content
234
+ };
235
+ }
236
+ function parseAutoGLMLocateResponse(rawResponse) {
237
+ const { think, content: actionContent } = parseAutoGLMResponse(rawResponse);
238
+ if (!actionContent.startsWith('do(action="Tap"')) return {
239
+ think,
240
+ coordinates: null,
241
+ error: `Unexpected action type in auto-glm locate response: ${actionContent}`
242
+ };
243
+ try {
244
+ const elementMatch = actionContent.match(/element=\[(\d+),(\d+)\]/);
245
+ if (!elementMatch) return {
246
+ think,
247
+ coordinates: null,
248
+ error: `Failed to extract element coordinates from auto-glm response: ${actionContent}`
249
+ };
250
+ const x = Number(elementMatch[1]);
251
+ const y = Number(elementMatch[2]);
252
+ return {
253
+ think,
254
+ coordinates: {
255
+ x,
256
+ y
257
+ }
258
+ };
259
+ } catch (e) {
260
+ const errorMessage = e instanceof Error ? e.message : String(e);
261
+ return {
262
+ think,
263
+ coordinates: null,
264
+ error: `Failed to parse coordinates "${actionContent}" with errorMessage: ${errorMessage}`
265
+ };
266
+ }
267
+ }
268
+ exports.extractValueAfter = __webpack_exports__.extractValueAfter;
269
+ exports.parseAction = __webpack_exports__.parseAction;
270
+ exports.parseAutoGLMLocateResponse = __webpack_exports__.parseAutoGLMLocateResponse;
271
+ exports.parseAutoGLMResponse = __webpack_exports__.parseAutoGLMResponse;
272
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
273
+ "extractValueAfter",
274
+ "parseAction",
275
+ "parseAutoGLMLocateResponse",
276
+ "parseAutoGLMResponse"
277
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
278
+ Object.defineProperty(exports, '__esModule', {
279
+ value: true
280
+ });
281
+
282
+ //# sourceMappingURL=parser.js.map