@midscene/core 1.2.2-beta-20260115092052.0 → 1.2.2-beta-20260116060040.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.
- package/dist/es/agent/agent.mjs +27 -24
- package/dist/es/agent/agent.mjs.map +1 -1
- package/dist/es/agent/tasks.mjs +15 -29
- package/dist/es/agent/tasks.mjs.map +1 -1
- package/dist/es/agent/utils.mjs +4 -2
- package/dist/es/agent/utils.mjs.map +1 -1
- package/dist/es/ai-model/inspect.mjs +3 -3
- package/dist/es/ai-model/inspect.mjs.map +1 -1
- package/dist/es/ai-model/llm-planning.mjs +14 -4
- package/dist/es/ai-model/llm-planning.mjs.map +1 -1
- package/dist/es/ai-model/prompt/llm-planning.mjs +44 -9
- package/dist/es/ai-model/prompt/llm-planning.mjs.map +1 -1
- package/dist/es/ai-model/service-caller/index.mjs +11 -10
- package/dist/es/ai-model/service-caller/index.mjs.map +1 -1
- package/dist/es/ai-model/ui-tars-planning.mjs +3 -2
- package/dist/es/ai-model/ui-tars-planning.mjs.map +1 -1
- package/dist/es/common.mjs +14 -5
- package/dist/es/common.mjs.map +1 -1
- package/dist/es/device/index.mjs +29 -4
- package/dist/es/device/index.mjs.map +1 -1
- package/dist/es/dump/html-utils.mjs +42 -0
- package/dist/es/dump/html-utils.mjs.map +1 -0
- package/dist/es/dump/image-restoration.mjs +31 -0
- package/dist/es/dump/image-restoration.mjs.map +1 -0
- package/dist/es/dump/index.mjs +3 -0
- package/dist/es/index.mjs +4 -2
- package/dist/es/index.mjs.map +1 -1
- package/dist/es/screenshot-item.mjs +34 -0
- package/dist/es/screenshot-item.mjs.map +1 -0
- package/dist/es/service/index.mjs +2 -1
- package/dist/es/service/index.mjs.map +1 -1
- package/dist/es/task-runner.mjs +7 -9
- package/dist/es/task-runner.mjs.map +1 -1
- package/dist/es/types.mjs +78 -1
- package/dist/es/types.mjs.map +1 -1
- package/dist/es/utils.mjs +3 -2
- package/dist/es/utils.mjs.map +1 -1
- package/dist/lib/agent/agent.js +24 -21
- package/dist/lib/agent/agent.js.map +1 -1
- package/dist/lib/agent/tasks.js +15 -29
- package/dist/lib/agent/tasks.js.map +1 -1
- package/dist/lib/agent/utils.js +4 -2
- package/dist/lib/agent/utils.js.map +1 -1
- package/dist/lib/ai-model/inspect.js +3 -3
- package/dist/lib/ai-model/inspect.js.map +1 -1
- package/dist/lib/ai-model/llm-planning.js +13 -3
- package/dist/lib/ai-model/llm-planning.js.map +1 -1
- package/dist/lib/ai-model/prompt/llm-planning.js +44 -9
- package/dist/lib/ai-model/prompt/llm-planning.js.map +1 -1
- package/dist/lib/ai-model/service-caller/index.js +11 -10
- package/dist/lib/ai-model/service-caller/index.js.map +1 -1
- package/dist/lib/ai-model/ui-tars-planning.js +3 -2
- package/dist/lib/ai-model/ui-tars-planning.js.map +1 -1
- package/dist/lib/common.js +20 -5
- package/dist/lib/common.js.map +1 -1
- package/dist/lib/device/index.js +53 -16
- package/dist/lib/device/index.js.map +1 -1
- package/dist/lib/dump/html-utils.js +94 -0
- package/dist/lib/dump/html-utils.js.map +1 -0
- package/dist/lib/dump/image-restoration.js +65 -0
- package/dist/lib/dump/image-restoration.js.map +1 -0
- package/dist/lib/dump/index.js +60 -0
- package/dist/lib/dump/index.js.map +1 -0
- package/dist/lib/index.js +42 -7
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/screenshot-item.js +68 -0
- package/dist/lib/screenshot-item.js.map +1 -0
- package/dist/lib/service/index.js +2 -1
- package/dist/lib/service/index.js.map +1 -1
- package/dist/lib/task-runner.js +7 -9
- package/dist/lib/task-runner.js.map +1 -1
- package/dist/lib/types.js +91 -3
- package/dist/lib/types.js.map +1 -1
- package/dist/lib/utils.js +3 -2
- package/dist/lib/utils.js.map +1 -1
- package/dist/types/agent/agent.d.ts +5 -16
- package/dist/types/agent/tasks.d.ts +4 -4
- package/dist/types/ai-model/service-caller/index.d.ts +3 -3
- package/dist/types/common.d.ts +8 -1
- package/dist/types/device/index.d.ts +85 -23
- package/dist/types/dump/html-utils.d.ts +7 -0
- package/dist/types/dump/image-restoration.d.ts +6 -0
- package/dist/types/dump/index.d.ts +5 -0
- package/dist/types/index.d.ts +3 -1
- package/dist/types/screenshot-item.d.ts +27 -0
- package/dist/types/task-runner.d.ts +1 -1
- package/dist/types/types.d.ts +61 -6
- package/package.json +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"device/index.js","sources":["webpack/runtime/define_property_getters","webpack/runtime/has_own_property","webpack/runtime/make_namespace_object","../../../src/device/index.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 { getMidsceneLocationSchema } from '@/common';\nimport type {\n ActionScrollParam,\n DeviceAction,\n LocateResultElement,\n} from '@/types';\nimport type { IModelConfig } from '@midscene/shared/env';\nimport type { ElementNode } from '@midscene/shared/extractor';\nimport { getDebug } from '@midscene/shared/logger';\nimport { _keyDefinitions } from '@midscene/shared/us-keyboard-layout';\nimport { z } from 'zod';\nimport type { ElementCacheFeature, Rect, Size, UIContext } from '../types';\n\nexport interface FileChooserHandler {\n accept(files: string[]): Promise<void>;\n}\n\nexport abstract class AbstractInterface {\n abstract interfaceType: string;\n\n abstract screenshotBase64(): Promise<string>;\n abstract size(): Promise<Size>;\n abstract actionSpace(): DeviceAction[];\n\n abstract cacheFeatureForRect?(\n rect: Rect,\n options?: {\n targetDescription?: string;\n modelConfig?: IModelConfig;\n },\n ): Promise<ElementCacheFeature>;\n abstract rectMatchesCacheFeature?(\n feature: ElementCacheFeature,\n ): Promise<Rect>;\n\n abstract destroy?(): Promise<void>;\n\n abstract describe?(): string;\n abstract beforeInvokeAction?(actionName: string, param: any): Promise<void>;\n abstract afterInvokeAction?(actionName: string, param: any): Promise<void>;\n\n // for web only\n registerFileChooserListener?(\n handler: (chooser: FileChooserHandler) => Promise<void>,\n ): Promise<{ dispose: () => void; getError: () => Error | undefined }>;\n\n // @deprecated do NOT extend this method\n abstract getElementsNodeTree?: () => Promise<ElementNode>;\n\n // @deprecated do NOT extend this method\n abstract url?: () => string | Promise<string>;\n\n // @deprecated do NOT extend this method\n abstract evaluateJavaScript?<T = any>(script: string): Promise<T>;\n\n // @deprecated do NOT extend this method\n abstract getContext?(): Promise<UIContext>;\n}\n\n// Generic function to define actions with proper type inference\n// TRuntime allows specifying a different type for the runtime parameter (after location resolution)\n// TReturn allows specifying the return type of the action\nexport const defineAction = <\n TSchema extends z.ZodType | undefined = undefined,\n TRuntime = TSchema extends z.ZodType ? z.infer<TSchema> : undefined,\n TReturn = any,\n>(\n config: {\n name: string;\n description: string;\n interfaceAlias?: string;\n paramSchema?: TSchema;\n call: (param: TRuntime) => Promise<TReturn> | TReturn;\n } & Partial<\n Omit<\n DeviceAction<TRuntime, TReturn>,\n 'name' | 'description' | 'interfaceAlias' | 'paramSchema' | 'call'\n >\n >,\n): DeviceAction<TRuntime, TReturn> => {\n return config as any; // Type assertion needed because schema validation type differs from runtime type\n};\n\n// Tap\nexport const actionTapParamSchema = z.object({\n locate: getMidsceneLocationSchema().describe('The element to be tapped'),\n});\nexport type ActionTapParam = {\n locate: LocateResultElement;\n};\n\nexport const defineActionTap = (\n call: (param: ActionTapParam) => Promise<void>,\n): DeviceAction<ActionTapParam> => {\n return defineAction<typeof actionTapParamSchema, ActionTapParam>({\n name: 'Tap',\n description: 'Tap the element',\n interfaceAlias: 'aiTap',\n paramSchema: actionTapParamSchema,\n call,\n });\n};\n\n// RightClick\nexport const actionRightClickParamSchema = z.object({\n locate: getMidsceneLocationSchema().describe(\n 'The element to be right clicked',\n ),\n});\nexport type ActionRightClickParam = {\n locate: LocateResultElement;\n};\n\nexport const defineActionRightClick = (\n call: (param: ActionRightClickParam) => Promise<void>,\n): DeviceAction<ActionRightClickParam> => {\n return defineAction<\n typeof actionRightClickParamSchema,\n ActionRightClickParam\n >({\n name: 'RightClick',\n description: 'Right click the element',\n interfaceAlias: 'aiRightClick',\n paramSchema: actionRightClickParamSchema,\n call,\n });\n};\n\n// DoubleClick\nexport const actionDoubleClickParamSchema = z.object({\n locate: getMidsceneLocationSchema().describe(\n 'The element to be double clicked',\n ),\n});\nexport type ActionDoubleClickParam = {\n locate: LocateResultElement;\n};\n\nexport const defineActionDoubleClick = (\n call: (param: ActionDoubleClickParam) => Promise<void>,\n): DeviceAction<ActionDoubleClickParam> => {\n return defineAction<\n typeof actionDoubleClickParamSchema,\n ActionDoubleClickParam\n >({\n name: 'DoubleClick',\n description: 'Double click the element',\n interfaceAlias: 'aiDoubleClick',\n paramSchema: actionDoubleClickParamSchema,\n call,\n });\n};\n\n// Hover\nexport const actionHoverParamSchema = z.object({\n locate: getMidsceneLocationSchema().describe('The element to be hovered'),\n});\nexport type ActionHoverParam = {\n locate: LocateResultElement;\n};\n\nexport const defineActionHover = (\n call: (param: ActionHoverParam) => Promise<void>,\n): DeviceAction<ActionHoverParam> => {\n return defineAction<typeof actionHoverParamSchema, ActionHoverParam>({\n name: 'Hover',\n description: 'Move the mouse to the element',\n interfaceAlias: 'aiHover',\n paramSchema: actionHoverParamSchema,\n call,\n });\n};\n\n// Input\nconst inputLocateDescription =\n 'the position of the placeholder or text content in the target input field. If there is no content, locate the center of the input field.';\nexport const actionInputParamSchema = z.object({\n value: z\n .union([z.string(), z.number()])\n .transform((val) => String(val))\n .describe(\n 'The text to input. Provide the final content for replace/append modes, or an empty string when using clear mode to remove existing text.',\n ),\n locate: getMidsceneLocationSchema()\n .describe(inputLocateDescription)\n .optional(),\n mode: z\n .enum(['replace', 'clear', 'append'])\n .default('replace')\n .optional()\n .describe(\n 'Input mode: \"replace\" (default) - clear the field and input the value; \"append\" - append the value to existing content; \"clear\" - clear the field without inputting new text.',\n ),\n});\nexport type ActionInputParam = {\n value: string;\n locate?: LocateResultElement;\n mode?: 'replace' | 'clear' | 'append';\n};\n\nexport const defineActionInput = (\n call: (param: ActionInputParam) => Promise<void>,\n): DeviceAction<ActionInputParam> => {\n return defineAction<typeof actionInputParamSchema, ActionInputParam>({\n name: 'Input',\n description: 'Input the value into the element',\n interfaceAlias: 'aiInput',\n paramSchema: actionInputParamSchema,\n call,\n });\n};\n\n// KeyboardPress\nexport const actionKeyboardPressParamSchema = z.object({\n locate: getMidsceneLocationSchema()\n .describe('The element to be clicked before pressing the key')\n .optional(),\n keyName: z\n .string()\n .describe(\n \"The key to be pressed. Use '+' for key combinations, e.g., 'Control+A', 'Shift+Enter'\",\n ),\n});\nexport type ActionKeyboardPressParam = {\n locate?: LocateResultElement;\n keyName: string;\n};\n\nexport const defineActionKeyboardPress = (\n call: (param: ActionKeyboardPressParam) => Promise<void>,\n): DeviceAction<ActionKeyboardPressParam> => {\n return defineAction<\n typeof actionKeyboardPressParamSchema,\n ActionKeyboardPressParam\n >({\n name: 'KeyboardPress',\n description:\n 'Press a key or key combination, like \"Enter\", \"Tab\", \"Escape\", or \"Control+A\", \"Shift+Enter\". Do not use this to type text.',\n interfaceAlias: 'aiKeyboardPress',\n paramSchema: actionKeyboardPressParamSchema,\n call,\n });\n};\n\n// Scroll\nexport const actionScrollParamSchema = z.object({\n scrollType: z\n .enum([\n 'singleAction',\n 'scrollToBottom',\n 'scrollToTop',\n 'scrollToRight',\n 'scrollToLeft',\n ])\n .default('singleAction')\n .describe(\n 'The scroll behavior: \"singleAction\" for a single scroll action, \"scrollToBottom\" for scrolling to the bottom, \"scrollToTop\" for scrolling to the top, \"scrollToRight\" for scrolling to the right, \"scrollToLeft\" for scrolling to the left',\n ),\n direction: z\n .enum(['down', 'up', 'right', 'left'])\n .default('down')\n .describe(\n 'The direction to scroll. Only effective when scrollType is \"singleAction\".',\n ),\n distance: z\n .number()\n .nullable()\n .optional()\n .describe('The distance in pixels to scroll'),\n locate: getMidsceneLocationSchema()\n .optional()\n .describe(\n 'Describe the target element to be scrolled on, like \"the table\" or \"the list\" or \"the content area\" or \"the scrollable area\". Do NOT provide a general intent like \"scroll to find some element\"',\n ),\n});\n\nexport const defineActionScroll = (\n call: (param: ActionScrollParam) => Promise<void>,\n): DeviceAction<ActionScrollParam> => {\n return defineAction<typeof actionScrollParamSchema, ActionScrollParam>({\n name: 'Scroll',\n description:\n 'Scroll the page or an element. The direction to scroll, the scroll type, and the distance to scroll. The distance is the number of pixels to scroll. If not specified, use `down` direction, `once` scroll type, and `null` distance.',\n interfaceAlias: 'aiScroll',\n paramSchema: actionScrollParamSchema,\n call,\n });\n};\n\n// DragAndDrop\nexport const actionDragAndDropParamSchema = z.object({\n from: getMidsceneLocationSchema().describe('The position to be dragged'),\n to: getMidsceneLocationSchema().describe('The position to be dropped'),\n});\nexport type ActionDragAndDropParam = {\n from: LocateResultElement;\n to: LocateResultElement;\n};\n\nexport const defineActionDragAndDrop = (\n call: (param: ActionDragAndDropParam) => Promise<void>,\n): DeviceAction<ActionDragAndDropParam> => {\n return defineAction<\n typeof actionDragAndDropParamSchema,\n ActionDragAndDropParam\n >({\n name: 'DragAndDrop',\n description:\n 'Drag and drop (hold the mouse or finger down and move the mouse) ',\n interfaceAlias: 'aiDragAndDrop',\n paramSchema: actionDragAndDropParamSchema,\n call,\n });\n};\n\nexport const ActionLongPressParamSchema = z.object({\n locate: getMidsceneLocationSchema().describe(\n 'The element to be long pressed',\n ),\n duration: z\n .number()\n .default(500)\n .optional()\n .describe('Long press duration in milliseconds'),\n});\n\nexport type ActionLongPressParam = {\n locate: LocateResultElement;\n duration?: number;\n};\nexport const defineActionLongPress = (\n call: (param: ActionLongPressParam) => Promise<void>,\n): DeviceAction<ActionLongPressParam> => {\n return defineAction<typeof ActionLongPressParamSchema, ActionLongPressParam>({\n name: 'LongPress',\n description: 'Long press the element',\n paramSchema: ActionLongPressParamSchema,\n call,\n });\n};\n\nexport const ActionSwipeParamSchema = z.object({\n start: getMidsceneLocationSchema()\n .optional()\n .describe(\n 'Starting point of the swipe gesture, if not specified, the center of the page will be used',\n ),\n direction: z\n .enum(['up', 'down', 'left', 'right'])\n .optional()\n .describe(\n 'The direction to swipe (required when using distance). The direction means the direction of the finger swipe.',\n ),\n distance: z\n .number()\n .optional()\n .describe('The distance in pixels to swipe (mutually exclusive with end)'),\n end: getMidsceneLocationSchema()\n .optional()\n .describe(\n 'Ending point of the swipe gesture (mutually exclusive with distance)',\n ),\n duration: z\n .number()\n .default(300)\n .describe('Duration of the swipe gesture in milliseconds'),\n repeat: z\n .number()\n .optional()\n .describe(\n 'The number of times to repeat the swipe gesture. 1 for default, 0 for infinite (e.g. endless swipe until the end of the page)',\n ),\n});\n\nexport type ActionSwipeParam = {\n start?: LocateResultElement;\n direction?: 'up' | 'down' | 'left' | 'right';\n distance?: number;\n end?: LocateResultElement;\n duration?: number;\n repeat?: number;\n};\n\nexport const defineActionSwipe = (\n call: (param: ActionSwipeParam) => Promise<void>,\n): DeviceAction<ActionSwipeParam> => {\n return defineAction<typeof ActionSwipeParamSchema, ActionSwipeParam>({\n name: 'Swipe',\n description:\n 'Perform a swipe gesture. You must specify either \"end\" (target location) or \"distance\" + \"direction\" - they are mutually exclusive. Use \"end\" for precise location-based swipes, or \"distance\" + \"direction\" for relative movement.',\n paramSchema: ActionSwipeParamSchema,\n call,\n });\n};\n\n// ClearInput\nexport const actionClearInputParamSchema = z.object({\n locate: getMidsceneLocationSchema().describe('The input field to be cleared'),\n});\nexport type ActionClearInputParam = {\n locate: LocateResultElement;\n};\n\nexport const defineActionClearInput = (\n call: (param: ActionClearInputParam) => Promise<void>,\n): DeviceAction<ActionClearInputParam> => {\n return defineAction<\n typeof actionClearInputParamSchema,\n ActionClearInputParam\n >({\n name: 'ClearInput',\n description: inputLocateDescription,\n interfaceAlias: 'aiClearInput',\n paramSchema: actionClearInputParamSchema,\n call,\n });\n};\n\n// Assert\nexport const actionAssertParamSchema = z.object({\n condition: z.string().describe('The condition of the assertion'),\n thought: z\n .string()\n .describe(\n 'The thought of the assertion, like \"I can see there are A, B, C elements on the page, which means ... , so the assertion is true\"',\n ),\n result: z.boolean().describe('The result of the assertion, true or false'),\n});\nexport type ActionAssertParam = {\n condition: string;\n thought: string;\n result: boolean;\n};\n\nexport const defineActionAssert = (): DeviceAction<ActionAssertParam> => {\n return defineAction<typeof actionAssertParamSchema, ActionAssertParam>({\n name: 'Print_Assert_Result',\n description: 'Print the result of the assertion',\n paramSchema: actionAssertParamSchema,\n call: async (param) => {\n if (typeof param?.result !== 'boolean') {\n throw new Error(\n `The result of the assertion must be a boolean, but got: ${typeof param?.result}. ${param.thought || '(no thought)'}`,\n );\n }\n\n getDebug('device:common-action')(\n `Assert: ${param.condition}, Thought: ${param.thought}, Result: ${param.result}`,\n );\n\n if (!param.result) {\n throw new Error(\n `Assertion failed: ${param.thought || '(no thought)'} (Assertion = ${param.condition})`,\n );\n }\n },\n });\n};\n\nexport type { DeviceAction } from '../types';\nexport type {\n AndroidDeviceOpt,\n AndroidDeviceInputOpt,\n IOSDeviceOpt,\n IOSDeviceInputOpt,\n} from './device-options';\n"],"names":["__webpack_require__","definition","key","Object","obj","prop","Symbol","AbstractInterface","defineAction","config","actionTapParamSchema","z","getMidsceneLocationSchema","defineActionTap","call","actionRightClickParamSchema","defineActionRightClick","actionDoubleClickParamSchema","defineActionDoubleClick","actionHoverParamSchema","defineActionHover","inputLocateDescription","actionInputParamSchema","val","String","defineActionInput","actionKeyboardPressParamSchema","defineActionKeyboardPress","actionScrollParamSchema","defineActionScroll","actionDragAndDropParamSchema","defineActionDragAndDrop","ActionLongPressParamSchema","defineActionLongPress","ActionSwipeParamSchema","defineActionSwipe","actionClearInputParamSchema","defineActionClearInput","actionAssertParamSchema","defineActionAss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AAM;QACN,aAAa;QACb,aAAa8B;QACb,MAAM,OAAOE;YACX,IAAI,AAAyB,aAAzB,OAAOA,OAAO,QAChB,MAAM,IAAIC,MACR,CAAC,wDAAwD,EAAE,OAAOD,OAAO,OAAO,EAAE,EAAEA,MAAM,OAAO,IAAI,gBAAgB;YAIzHE,IAAAA,uBAAAA,QAAAA,AAAAA,EAAS,wBACP,CAAC,QAAQ,EAAEF,MAAM,SAAS,CAAC,WAAW,EAAEA,MAAM,OAAO,CAAC,UAAU,EAAEA,MAAM,MAAM,EAAE;YAGlF,IAAI,CAACA,MAAM,MAAM,EACf,MAAM,IAAIC,MACR,CAAC,kBAAkB,EAAED,MAAM,OAAO,IAAI,eAAe,cAAc,EAAEA,MAAM,SAAS,CAAC,CAAC,CAAC;QAG7F;IACF"}
|
|
1
|
+
{"version":3,"file":"device/index.js","sources":["webpack/runtime/define_property_getters","webpack/runtime/has_own_property","webpack/runtime/make_namespace_object","../../../src/device/index.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 { finalizeActionName, getMidsceneLocationSchema } from '@/common';\nimport type {\n ActionScrollParam,\n DeviceAction,\n LocateResultElement,\n} from '@/types';\nimport type { IModelConfig } from '@midscene/shared/env';\nimport type { ElementNode } from '@midscene/shared/extractor';\nimport { getDebug } from '@midscene/shared/logger';\nimport { _keyDefinitions } from '@midscene/shared/us-keyboard-layout';\nimport { z } from 'zod';\nimport type { ElementCacheFeature, Rect, Size, UIContext } from '../types';\n\nexport interface FileChooserHandler {\n accept(files: string[]): Promise<void>;\n}\n\nexport abstract class AbstractInterface {\n abstract interfaceType: string;\n\n abstract screenshotBase64(): Promise<string>;\n abstract size(): Promise<Size>;\n abstract actionSpace(): DeviceAction[];\n\n abstract cacheFeatureForRect?(\n rect: Rect,\n options?: {\n targetDescription?: string;\n modelConfig?: IModelConfig;\n },\n ): Promise<ElementCacheFeature>;\n abstract rectMatchesCacheFeature?(\n feature: ElementCacheFeature,\n ): Promise<Rect>;\n\n abstract destroy?(): Promise<void>;\n\n abstract describe?(): string;\n abstract beforeInvokeAction?(actionName: string, param: any): Promise<void>;\n abstract afterInvokeAction?(actionName: string, param: any): Promise<void>;\n\n // for web only\n registerFileChooserListener?(\n handler: (chooser: FileChooserHandler) => Promise<void>,\n ): Promise<{ dispose: () => void; getError: () => Error | undefined }>;\n\n // @deprecated do NOT extend this method\n abstract getElementsNodeTree?: () => Promise<ElementNode>;\n\n // @deprecated do NOT extend this method\n abstract url?: () => string | Promise<string>;\n\n // @deprecated do NOT extend this method\n abstract evaluateJavaScript?<T = any>(script: string): Promise<T>;\n\n // @deprecated do NOT extend this method\n abstract getContext?(): Promise<UIContext>;\n}\n\n// Generic function to define actions with proper type inference\n// TRuntime allows specifying a different type for the runtime parameter (after location resolution)\n// TReturn allows specifying the return type of the action\nexport const defineAction = <\n TSchema extends z.ZodType | undefined = undefined,\n TRuntime = TSchema extends z.ZodType ? z.infer<TSchema> : undefined,\n TReturn = any,\n>(\n config: {\n name: string;\n description: string;\n interfaceAlias?: string;\n paramSchema?: TSchema;\n call: (param: TRuntime) => Promise<TReturn> | TReturn;\n } & Partial<\n Omit<\n DeviceAction<TRuntime, TReturn>,\n 'name' | 'description' | 'interfaceAlias' | 'paramSchema' | 'call'\n >\n >,\n): DeviceAction<TRuntime, TReturn> => {\n return config as any; // Type assertion needed because schema validation type differs from runtime type\n};\n\n// Tap\nexport const actionTapParamSchema = z.object({\n locate: getMidsceneLocationSchema().describe('The element to be tapped'),\n});\nexport type ActionTapParam = {\n locate: LocateResultElement;\n};\n\nexport const defineActionTap = (\n call: (param: ActionTapParam) => Promise<void>,\n): DeviceAction<ActionTapParam> => {\n return defineAction<typeof actionTapParamSchema, ActionTapParam>({\n name: 'Tap',\n description: 'Tap the element',\n interfaceAlias: 'aiTap',\n paramSchema: actionTapParamSchema,\n call,\n });\n};\n\n// RightClick\nexport const actionRightClickParamSchema = z.object({\n locate: getMidsceneLocationSchema().describe(\n 'The element to be right clicked',\n ),\n});\nexport type ActionRightClickParam = {\n locate: LocateResultElement;\n};\n\nexport const defineActionRightClick = (\n call: (param: ActionRightClickParam) => Promise<void>,\n): DeviceAction<ActionRightClickParam> => {\n return defineAction<\n typeof actionRightClickParamSchema,\n ActionRightClickParam\n >({\n name: 'RightClick',\n description: 'Right click the element',\n interfaceAlias: 'aiRightClick',\n paramSchema: actionRightClickParamSchema,\n call,\n });\n};\n\n// DoubleClick\nexport const actionDoubleClickParamSchema = z.object({\n locate: getMidsceneLocationSchema().describe(\n 'The element to be double clicked',\n ),\n});\nexport type ActionDoubleClickParam = {\n locate: LocateResultElement;\n};\n\nexport const defineActionDoubleClick = (\n call: (param: ActionDoubleClickParam) => Promise<void>,\n): DeviceAction<ActionDoubleClickParam> => {\n return defineAction<\n typeof actionDoubleClickParamSchema,\n ActionDoubleClickParam\n >({\n name: 'DoubleClick',\n description: 'Double click the element',\n interfaceAlias: 'aiDoubleClick',\n paramSchema: actionDoubleClickParamSchema,\n call,\n });\n};\n\n// Hover\nexport const actionHoverParamSchema = z.object({\n locate: getMidsceneLocationSchema().describe('The element to be hovered'),\n});\nexport type ActionHoverParam = {\n locate: LocateResultElement;\n};\n\nexport const defineActionHover = (\n call: (param: ActionHoverParam) => Promise<void>,\n): DeviceAction<ActionHoverParam> => {\n return defineAction<typeof actionHoverParamSchema, ActionHoverParam>({\n name: 'Hover',\n description: 'Move the mouse to the element',\n interfaceAlias: 'aiHover',\n paramSchema: actionHoverParamSchema,\n call,\n });\n};\n\n// Input\nconst inputLocateDescription =\n 'the position of the placeholder or text content in the target input field. If there is no content, locate the center of the input field.';\nexport const actionInputParamSchema = z.object({\n value: z\n .union([z.string(), z.number()])\n .transform((val) => String(val))\n .describe(\n 'The text to input. Provide the final content for replace/append modes, or an empty string when using clear mode to remove existing text.',\n ),\n locate: getMidsceneLocationSchema()\n .describe(inputLocateDescription)\n .optional(),\n mode: z\n .enum(['replace', 'clear', 'append'])\n .default('replace')\n .optional()\n .describe(\n 'Input mode: \"replace\" (default) - clear the field and input the value; \"append\" - append the value to existing content; \"clear\" - clear the field without inputting new text.',\n ),\n});\nexport type ActionInputParam = {\n value: string;\n locate?: LocateResultElement;\n mode?: 'replace' | 'clear' | 'append';\n};\n\nexport const defineActionInput = (\n call: (param: ActionInputParam) => Promise<void>,\n): DeviceAction<ActionInputParam> => {\n return defineAction<typeof actionInputParamSchema, ActionInputParam>({\n name: 'Input',\n description: 'Input the value into the element',\n interfaceAlias: 'aiInput',\n paramSchema: actionInputParamSchema,\n call,\n });\n};\n\n// KeyboardPress\nexport const actionKeyboardPressParamSchema = z.object({\n locate: getMidsceneLocationSchema()\n .describe('The element to be clicked before pressing the key')\n .optional(),\n keyName: z\n .string()\n .describe(\n \"The key to be pressed. Use '+' for key combinations, e.g., 'Control+A', 'Shift+Enter'\",\n ),\n});\nexport type ActionKeyboardPressParam = {\n locate?: LocateResultElement;\n keyName: string;\n};\n\nexport const defineActionKeyboardPress = (\n call: (param: ActionKeyboardPressParam) => Promise<void>,\n): DeviceAction<ActionKeyboardPressParam> => {\n return defineAction<\n typeof actionKeyboardPressParamSchema,\n ActionKeyboardPressParam\n >({\n name: 'KeyboardPress',\n description:\n 'Press a key or key combination, like \"Enter\", \"Tab\", \"Escape\", or \"Control+A\", \"Shift+Enter\". Do not use this to type text.',\n interfaceAlias: 'aiKeyboardPress',\n paramSchema: actionKeyboardPressParamSchema,\n call,\n });\n};\n\n// Scroll\nexport const actionScrollParamSchema = z.object({\n scrollType: z\n .enum([\n 'singleAction',\n 'scrollToBottom',\n 'scrollToTop',\n 'scrollToRight',\n 'scrollToLeft',\n ])\n .default('singleAction')\n .describe(\n 'The scroll behavior: \"singleAction\" for a single scroll action, \"scrollToBottom\" for scrolling to the bottom, \"scrollToTop\" for scrolling to the top, \"scrollToRight\" for scrolling to the right, \"scrollToLeft\" for scrolling to the left',\n ),\n direction: z\n .enum(['down', 'up', 'right', 'left'])\n .default('down')\n .describe(\n 'The direction to scroll. Only effective when scrollType is \"singleAction\".',\n ),\n distance: z\n .number()\n .nullable()\n .optional()\n .describe('The distance in pixels to scroll'),\n locate: getMidsceneLocationSchema()\n .optional()\n .describe(\n 'Describe the target element to be scrolled on, like \"the table\" or \"the list\" or \"the content area\" or \"the scrollable area\". Do NOT provide a general intent like \"scroll to find some element\"',\n ),\n});\n\nexport const defineActionScroll = (\n call: (param: ActionScrollParam) => Promise<void>,\n): DeviceAction<ActionScrollParam> => {\n return defineAction<typeof actionScrollParamSchema, ActionScrollParam>({\n name: 'Scroll',\n description:\n 'Scroll the page or an element. The direction to scroll, the scroll type, and the distance to scroll. The distance is the number of pixels to scroll. If not specified, use `down` direction, `once` scroll type, and `null` distance.',\n interfaceAlias: 'aiScroll',\n paramSchema: actionScrollParamSchema,\n call,\n });\n};\n\n// DragAndDrop\nexport const actionDragAndDropParamSchema = z.object({\n from: getMidsceneLocationSchema().describe('The position to be dragged'),\n to: getMidsceneLocationSchema().describe('The position to be dropped'),\n});\nexport type ActionDragAndDropParam = {\n from: LocateResultElement;\n to: LocateResultElement;\n};\n\nexport const defineActionDragAndDrop = (\n call: (param: ActionDragAndDropParam) => Promise<void>,\n): DeviceAction<ActionDragAndDropParam> => {\n return defineAction<\n typeof actionDragAndDropParamSchema,\n ActionDragAndDropParam\n >({\n name: 'DragAndDrop',\n description:\n 'Drag and drop (hold the mouse or finger down and move the mouse) ',\n interfaceAlias: 'aiDragAndDrop',\n paramSchema: actionDragAndDropParamSchema,\n call,\n });\n};\n\nexport const ActionLongPressParamSchema = z.object({\n locate: getMidsceneLocationSchema().describe(\n 'The element to be long pressed',\n ),\n duration: z\n .number()\n .default(500)\n .optional()\n .describe('Long press duration in milliseconds'),\n});\n\nexport type ActionLongPressParam = {\n locate: LocateResultElement;\n duration?: number;\n};\nexport const defineActionLongPress = (\n call: (param: ActionLongPressParam) => Promise<void>,\n): DeviceAction<ActionLongPressParam> => {\n return defineAction<typeof ActionLongPressParamSchema, ActionLongPressParam>({\n name: 'LongPress',\n description: 'Long press the element',\n paramSchema: ActionLongPressParamSchema,\n call,\n });\n};\n\nexport const ActionSwipeParamSchema = z.object({\n start: getMidsceneLocationSchema()\n .optional()\n .describe(\n 'Starting point of the swipe gesture, if not specified, the center of the page will be used',\n ),\n direction: z\n .enum(['up', 'down', 'left', 'right'])\n .optional()\n .describe(\n 'The direction to swipe (required when using distance). The direction means the direction of the finger swipe.',\n ),\n distance: z\n .number()\n .optional()\n .describe('The distance in pixels to swipe (mutually exclusive with end)'),\n end: getMidsceneLocationSchema()\n .optional()\n .describe(\n 'Ending point of the swipe gesture (mutually exclusive with distance)',\n ),\n duration: z\n .number()\n .default(300)\n .describe('Duration of the swipe gesture in milliseconds'),\n repeat: z\n .number()\n .optional()\n .describe(\n 'The number of times to repeat the swipe gesture. 1 for default, 0 for infinite (e.g. endless swipe until the end of the page)',\n ),\n});\n\nexport type ActionSwipeParam = {\n start?: LocateResultElement;\n direction?: 'up' | 'down' | 'left' | 'right';\n distance?: number;\n end?: LocateResultElement;\n duration?: number;\n repeat?: number;\n};\n\nexport const defineActionSwipe = (\n call: (param: ActionSwipeParam) => Promise<void>,\n): DeviceAction<ActionSwipeParam> => {\n return defineAction<typeof ActionSwipeParamSchema, ActionSwipeParam>({\n name: 'Swipe',\n description:\n 'Perform a swipe gesture. You must specify either \"end\" (target location) or \"distance\" + \"direction\" - they are mutually exclusive. Use \"end\" for precise location-based swipes, or \"distance\" + \"direction\" for relative movement.',\n paramSchema: ActionSwipeParamSchema,\n call,\n });\n};\n\n// ClearInput\nexport const actionClearInputParamSchema = z.object({\n locate: getMidsceneLocationSchema()\n .describe('The input field to be cleared')\n .optional(),\n});\nexport type ActionClearInputParam = {\n locate?: LocateResultElement;\n};\n\nexport const defineActionClearInput = (\n call: (param: ActionClearInputParam) => Promise<void>,\n): DeviceAction<ActionClearInputParam> => {\n return defineAction<\n typeof actionClearInputParamSchema,\n ActionClearInputParam\n >({\n name: 'ClearInput',\n description: inputLocateDescription,\n interfaceAlias: 'aiClearInput',\n paramSchema: actionClearInputParamSchema,\n call,\n });\n};\n\n// Assert\nexport const actionAssertParamSchema = z.object({\n condition: z.string().describe('The condition of the assertion'),\n thought: z\n .string()\n .describe(\n 'The thought of the assertion, like \"I can see there are A, B, C elements on the page, which means ... , so the assertion is true\"',\n ),\n result: z.boolean().describe('The result of the assertion, true or false'),\n});\nexport type ActionAssertParam = {\n condition: string;\n thought: string;\n result: boolean;\n};\n\nexport const defineActionAssert = (): DeviceAction<ActionAssertParam> => {\n return defineAction<typeof actionAssertParamSchema, ActionAssertParam>({\n name: 'Print_Assert_Result',\n description:\n 'Print the result of the assertion. Use this only when the user asks for an assertion',\n paramSchema: actionAssertParamSchema,\n call: async (param) => {\n if (typeof param?.result !== 'boolean') {\n throw new Error(\n `The result of the assertion must be a boolean, but got: ${typeof param?.result}. ${param.thought || '(no thought)'}`,\n );\n }\n\n getDebug('device:common-action')(\n `Assert: ${param.condition}, Thought: ${param.thought}, Result: ${param.result}`,\n );\n\n if (!param.result) {\n throw new Error(\n `Assertion failed: ${param.thought || '(no thought)'} (Assertion = ${param.condition})`,\n );\n }\n },\n });\n};\n\n// Sleep\nexport const ActionSleepParamSchema = z.object({\n millisecond: z\n .number()\n .default(1000)\n .optional()\n .describe('Sleep duration in milliseconds, defaults to 1000ms (1 second)'),\n});\n\nexport type ActionSleepParam = {\n millisecond?: number;\n};\n\nexport const defineActionSleep = (): DeviceAction<ActionSleepParam> => {\n return defineAction<typeof ActionSleepParamSchema, ActionSleepParam>({\n name: 'Sleep',\n description:\n 'Wait for a specified duration before continuing. Defaults to 1 second (1000ms) if not specified.',\n paramSchema: ActionSleepParamSchema,\n call: async (param) => {\n const duration = param?.millisecond ?? 1000;\n getDebug('device:common-action')(`Sleeping for ${duration}ms`);\n await new Promise((resolve) => setTimeout(resolve, duration));\n },\n });\n};\n\n// Finalize\nexport const actionFinalizeParamSchema = z.object({\n message: z\n .string()\n .optional()\n .describe(\n 'The conclusion, data, or return value that the user needs. This message will be provided to the user when the task is finalized.',\n ),\n});\nexport type ActionFinalizeParam = {\n message?: string;\n};\n\nexport const defineActionFinalize = (): DeviceAction<ActionFinalizeParam> => {\n return defineAction<typeof actionFinalizeParamSchema, ActionFinalizeParam>({\n name: finalizeActionName,\n description:\n 'Finalize the task. You can provide the conclusion, data, or return value that the user needs in the message.',\n paramSchema: actionFinalizeParamSchema,\n call: async (param) => {\n getDebug('device:common-action')(\n `Task finalized${param?.message ? `: ${param.message}` : ''}`,\n );\n return param.message;\n },\n });\n};\n\nexport type { DeviceAction } from '../types';\nexport type {\n AndroidDeviceOpt,\n AndroidDeviceInputOpt,\n IOSDeviceOpt,\n IOSDeviceInputOpt,\n} from './device-options';\n"],"names":["__webpack_require__","definition","key","Object","obj","prop","Symbol","AbstractInterface","defineAction","config","actionTapParamSchema","z","getMidsceneLocationSchema","defineActionTap","call","actionRightClickParamSchema","defineActionRightClick","actionDoubleClickParamSchema","defineActionDoubleClick","actionHoverParamSchema","defineActionHover","inputLocateDescription","actionInputParamSchema","val","String","defineActionInput","actionKeyboardPressParamSchema","defineActionKeyboardPress","actionScrollParamSchema","defineActionScroll","actionDragAndDropParamSchema","defineActionDragAndDrop","ActionLongPressParamSchema","defineActionLongPress","ActionSwipeParamSchema","defineActionSwipe","actionClearInputParamSchema","defineActionClearInput","actionAssertParamSchema","defineActionAssert","param","Error","getDebug","ActionSleepParamSchema","defineActionSleep","duration","Promise","resolve","setTimeout","actionFinalizeParamSchema","defineActionFinalize","finalize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Ac,EAAEF,OAAO,UAAU,CAAC,EAAE,EAAEA,MAAM,OAAO,EAAE,GAAG,IAAI;YAE/D,OAAOA,MAAM,OAAO;QACtB;IACF"}
|
|
@@ -0,0 +1,94 @@
|
|
|
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
|
+
generateDumpScriptTag: ()=>generateDumpScriptTag,
|
|
28
|
+
parseImageScripts: ()=>parseImageScripts,
|
|
29
|
+
parseDumpScriptAttributes: ()=>parseDumpScriptAttributes,
|
|
30
|
+
parseDumpScript: ()=>parseDumpScript,
|
|
31
|
+
escapeContent: ()=>escapeContent,
|
|
32
|
+
unescapeContent: ()=>unescapeContent,
|
|
33
|
+
generateImageScriptTag: ()=>generateImageScriptTag
|
|
34
|
+
});
|
|
35
|
+
const utils_namespaceObject = require("@midscene/shared/utils");
|
|
36
|
+
const escapeContent = utils_namespaceObject.escapeScriptTag;
|
|
37
|
+
const unescapeContent = utils_namespaceObject.antiEscapeScriptTag;
|
|
38
|
+
function parseImageScripts(html) {
|
|
39
|
+
const imageMap = {};
|
|
40
|
+
const regex = /<script type="midscene-image" data-id="([^"]+)">([\s\S]*?)<\/script>/g;
|
|
41
|
+
for (const match of html.matchAll(regex)){
|
|
42
|
+
const [, id, content] = match;
|
|
43
|
+
imageMap[id] = unescapeContent(content);
|
|
44
|
+
}
|
|
45
|
+
return imageMap;
|
|
46
|
+
}
|
|
47
|
+
function parseDumpScript(html) {
|
|
48
|
+
const regex = /<script type="midscene_web_dump"[^>]*>([\s\S]*?)<\/script>/;
|
|
49
|
+
const match = regex.exec(html);
|
|
50
|
+
if (!match) throw new Error("No dump script found in HTML");
|
|
51
|
+
return unescapeContent(match[1]);
|
|
52
|
+
}
|
|
53
|
+
function parseDumpScriptAttributes(html) {
|
|
54
|
+
const regex = /<script type="midscene_web_dump"([^>]*)>/;
|
|
55
|
+
const match = regex.exec(html);
|
|
56
|
+
if (!match) return {};
|
|
57
|
+
const attrString = match[1];
|
|
58
|
+
const attributes = {};
|
|
59
|
+
const attrRegex = /(\w+)="([^"]*)"/g;
|
|
60
|
+
for (const attrMatch of attrString.matchAll(attrRegex)){
|
|
61
|
+
const [, key, value] = attrMatch;
|
|
62
|
+
if ('type' !== key) attributes[key] = decodeURIComponent(value);
|
|
63
|
+
}
|
|
64
|
+
return attributes;
|
|
65
|
+
}
|
|
66
|
+
function generateImageScriptTag(id, data) {
|
|
67
|
+
return '<script type="midscene-image" data-id="' + id + '">' + escapeContent(data) + "<\/script>";
|
|
68
|
+
}
|
|
69
|
+
function generateDumpScriptTag(json, attributes) {
|
|
70
|
+
let attrString = '';
|
|
71
|
+
if (attributes && Object.keys(attributes).length > 0) attrString = ' ' + Object.entries(attributes).map(([k, v])=>k + '="' + encodeURIComponent(v) + '"').join(' ');
|
|
72
|
+
return '<script type="midscene_web_dump"' + attrString + '>' + escapeContent(json) + "<\/script>";
|
|
73
|
+
}
|
|
74
|
+
exports.escapeContent = __webpack_exports__.escapeContent;
|
|
75
|
+
exports.generateDumpScriptTag = __webpack_exports__.generateDumpScriptTag;
|
|
76
|
+
exports.generateImageScriptTag = __webpack_exports__.generateImageScriptTag;
|
|
77
|
+
exports.parseDumpScript = __webpack_exports__.parseDumpScript;
|
|
78
|
+
exports.parseDumpScriptAttributes = __webpack_exports__.parseDumpScriptAttributes;
|
|
79
|
+
exports.parseImageScripts = __webpack_exports__.parseImageScripts;
|
|
80
|
+
exports.unescapeContent = __webpack_exports__.unescapeContent;
|
|
81
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
82
|
+
"escapeContent",
|
|
83
|
+
"generateDumpScriptTag",
|
|
84
|
+
"generateImageScriptTag",
|
|
85
|
+
"parseDumpScript",
|
|
86
|
+
"parseDumpScriptAttributes",
|
|
87
|
+
"parseImageScripts",
|
|
88
|
+
"unescapeContent"
|
|
89
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
90
|
+
Object.defineProperty(exports, '__esModule', {
|
|
91
|
+
value: true
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
//# sourceMappingURL=html-utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dump/html-utils.js","sources":["webpack/runtime/define_property_getters","webpack/runtime/has_own_property","webpack/runtime/make_namespace_object","../../../src/dump/html-utils.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 { antiEscapeScriptTag, escapeScriptTag } from '@midscene/shared/utils';\n\nexport const escapeContent = escapeScriptTag;\nexport const unescapeContent = antiEscapeScriptTag;\n\nexport function parseImageScripts(html: string): Record<string, string> {\n const imageMap: Record<string, string> = {};\n const regex =\n /<script type=\"midscene-image\" data-id=\"([^\"]+)\">([\\s\\S]*?)<\\/script>/g;\n\n for (const match of html.matchAll(regex)) {\n const [, id, content] = match;\n imageMap[id] = unescapeContent(content);\n }\n\n return imageMap;\n}\n\nexport function parseDumpScript(html: string): string {\n const regex = /<script type=\"midscene_web_dump\"[^>]*>([\\s\\S]*?)<\\/script>/;\n const match = regex.exec(html);\n\n if (!match) {\n throw new Error('No dump script found in HTML');\n }\n\n return unescapeContent(match[1]);\n}\n\nexport function parseDumpScriptAttributes(\n html: string,\n): Record<string, string> {\n const regex = /<script type=\"midscene_web_dump\"([^>]*)>/;\n const match = regex.exec(html);\n\n if (!match) {\n return {};\n }\n\n const attrString = match[1];\n const attributes: Record<string, string> = {};\n const attrRegex = /(\\w+)=\"([^\"]*)\"/g;\n\n for (const attrMatch of attrString.matchAll(attrRegex)) {\n const [, key, value] = attrMatch;\n if (key !== 'type') {\n attributes[key] = decodeURIComponent(value);\n }\n }\n\n return attributes;\n}\n\nexport function generateImageScriptTag(id: string, data: string): string {\n // Do not use template string here, will cause bundle error with <script\n return (\n // biome-ignore lint/style/useTemplate: <explanation>\n '<script type=\"midscene-image\" data-id=\"' +\n id +\n '\">' +\n escapeContent(data) +\n '</script>'\n );\n}\n\nexport function generateDumpScriptTag(\n json: string,\n attributes?: Record<string, string>,\n): string {\n let attrString = '';\n if (attributes && Object.keys(attributes).length > 0) {\n // Do not use template string here, will cause bundle error with <script\n attrString =\n // biome-ignore lint/style/useTemplate: <explanation>\n ' ' +\n Object.entries(attributes)\n // biome-ignore lint/style/useTemplate: <explanation>\n .map(([k, v]) => k + '=\"' + encodeURIComponent(v) + '\"')\n .join(' ');\n }\n\n // Do not use template string here, will cause bundle error with <script\n return (\n // biome-ignore lint/style/useTemplate: <explanation>\n '<script type=\"midscene_web_dump\"' +\n attrString +\n '>' +\n escapeContent(json) +\n '</script>'\n );\n}\n"],"names":["__webpack_require__","definition","key","Object","obj","prop","Symbol","escapeContent","escapeScriptTag","unescapeContent","antiEscapeScriptTag","parseImageScripts","html","imageMap","regex","match","id","content","parseDumpScript","Error","parseDumpScriptAttributes","attrString","attributes","attrRegex","attrMatch","value","decodeURIComponent","generateImageScriptTag","data","generateDumpScriptTag","json","k","v","encodeURIComponent"],"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;;;;;;;;;;;;;;ACJO,MAAMI,gBAAgBC,sBAAAA,eAAeA;AACrC,MAAMC,kBAAkBC,sBAAAA,mBAAmBA;AAE3C,SAASC,kBAAkBC,IAAY;IAC5C,MAAMC,WAAmC,CAAC;IAC1C,MAAMC,QACJ;IAEF,KAAK,MAAMC,SAASH,KAAK,QAAQ,CAACE,OAAQ;QACxC,MAAM,GAAGE,IAAIC,QAAQ,GAAGF;QACxBF,QAAQ,CAACG,GAAG,GAAGP,gBAAgBQ;IACjC;IAEA,OAAOJ;AACT;AAEO,SAASK,gBAAgBN,IAAY;IAC1C,MAAME,QAAQ;IACd,MAAMC,QAAQD,MAAM,IAAI,CAACF;IAEzB,IAAI,CAACG,OACH,MAAM,IAAII,MAAM;IAGlB,OAAOV,gBAAgBM,KAAK,CAAC,EAAE;AACjC;AAEO,SAASK,0BACdR,IAAY;IAEZ,MAAME,QAAQ;IACd,MAAMC,QAAQD,MAAM,IAAI,CAACF;IAEzB,IAAI,CAACG,OACH,OAAO,CAAC;IAGV,MAAMM,aAAaN,KAAK,CAAC,EAAE;IAC3B,MAAMO,aAAqC,CAAC;IAC5C,MAAMC,YAAY;IAElB,KAAK,MAAMC,aAAaH,WAAW,QAAQ,CAACE,WAAY;QACtD,MAAM,GAAGrB,KAAKuB,MAAM,GAAGD;QACvB,IAAItB,AAAQ,WAARA,KACFoB,UAAU,CAACpB,IAAI,GAAGwB,mBAAmBD;IAEzC;IAEA,OAAOH;AACT;AAEO,SAASK,uBAAuBX,EAAU,EAAEY,IAAY;IAE7D,OAEE,4CACAZ,KACA,OACAT,cAAcqB,QACd;AAEJ;AAEO,SAASC,sBACdC,IAAY,EACZR,UAAmC;IAEnC,IAAID,aAAa;IACjB,IAAIC,cAAcnB,OAAO,IAAI,CAACmB,YAAY,MAAM,GAAG,GAEjDD,aAEE,MACAlB,OAAO,OAAO,CAACmB,YAEZ,GAAG,CAAC,CAAC,CAACS,GAAGC,EAAE,GAAKD,IAAI,OAAOE,mBAAmBD,KAAK,KACnD,IAAI,CAAC;IAIZ,OAEE,qCACAX,aACA,MACAd,cAAcuB,QACd;AAEJ"}
|
|
@@ -0,0 +1,65 @@
|
|
|
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
|
+
restoreImageReferences: ()=>restoreImageReferences
|
|
28
|
+
});
|
|
29
|
+
function restoreScreenshotValue(screenshot, imageMap) {
|
|
30
|
+
if (null == screenshot) return '';
|
|
31
|
+
if ('string' != typeof screenshot) {
|
|
32
|
+
console.warn('Invalid $screenshot value type:', typeof screenshot);
|
|
33
|
+
return '';
|
|
34
|
+
}
|
|
35
|
+
if (0 === screenshot.length) return '';
|
|
36
|
+
if (screenshot.startsWith('data:image/') || screenshot.startsWith('./') || screenshot.startsWith('/')) return screenshot;
|
|
37
|
+
const base64 = imageMap[screenshot];
|
|
38
|
+
if (base64) return base64;
|
|
39
|
+
const availableIds = Object.keys(imageMap);
|
|
40
|
+
if (availableIds.length > 0) console.warn(`Image not found for ID: ${screenshot}. Available IDs: ${availableIds.join(', ')}`);
|
|
41
|
+
return screenshot;
|
|
42
|
+
}
|
|
43
|
+
function restoreImageReferences(data, imageMap) {
|
|
44
|
+
if ('string' == typeof data) return data;
|
|
45
|
+
if (Array.isArray(data)) return data.map((item)=>restoreImageReferences(item, imageMap));
|
|
46
|
+
if ('object' == typeof data && null !== data) {
|
|
47
|
+
if ('$screenshot' in data) {
|
|
48
|
+
const screenshot = data.$screenshot;
|
|
49
|
+
return restoreScreenshotValue(screenshot, imageMap);
|
|
50
|
+
}
|
|
51
|
+
const result = {};
|
|
52
|
+
for (const [key, value] of Object.entries(data))result[key] = restoreImageReferences(value, imageMap);
|
|
53
|
+
return result;
|
|
54
|
+
}
|
|
55
|
+
return data;
|
|
56
|
+
}
|
|
57
|
+
exports.restoreImageReferences = __webpack_exports__.restoreImageReferences;
|
|
58
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
59
|
+
"restoreImageReferences"
|
|
60
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
61
|
+
Object.defineProperty(exports, '__esModule', {
|
|
62
|
+
value: true
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
//# sourceMappingURL=image-restoration.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dump/image-restoration.js","sources":["webpack/runtime/define_property_getters","webpack/runtime/has_own_property","webpack/runtime/make_namespace_object","../../../src/dump/image-restoration.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};","/**\n * Restore a screenshot value to base64 or file path.\n * Handles: base64 data, file paths, or IDs that need lookup.\n */\nfunction restoreScreenshotValue(\n screenshot: unknown,\n imageMap: Record<string, string>,\n): string {\n if (screenshot === undefined || screenshot === null) {\n return '';\n }\n\n if (typeof screenshot !== 'string') {\n console.warn('Invalid $screenshot value type:', typeof screenshot);\n return '';\n }\n\n if (screenshot.length === 0) {\n return '';\n }\n\n // Already base64 data or file path\n if (\n screenshot.startsWith('data:image/') ||\n screenshot.startsWith('./') ||\n screenshot.startsWith('/')\n ) {\n return screenshot;\n }\n\n // Look up ID in imageMap\n const base64 = imageMap[screenshot];\n if (base64) {\n return base64;\n }\n\n const availableIds = Object.keys(imageMap);\n if (availableIds.length > 0) {\n console.warn(\n `Image not found for ID: ${screenshot}. Available IDs: ${availableIds.join(', ')}`,\n );\n }\n return screenshot;\n}\n\n/**\n * Recursively restore image references in parsed data.\n * Replaces { $screenshot: \"id\" } with base64 values from imageMap.\n * Used by Playground and Extension to render images.\n */\nexport function restoreImageReferences<T>(\n data: T,\n imageMap: Record<string, string>,\n): T {\n if (typeof data === 'string') {\n return data;\n }\n\n if (Array.isArray(data)) {\n return data.map((item) => restoreImageReferences(item, imageMap)) as T;\n }\n\n if (typeof data === 'object' && data !== null) {\n if ('$screenshot' in data) {\n const screenshot = (data as { $screenshot: unknown }).$screenshot;\n return restoreScreenshotValue(screenshot, imageMap) as T;\n }\n\n const result: Record<string, unknown> = {};\n for (const [key, value] of Object.entries(data)) {\n result[key] = restoreImageReferences(value, imageMap);\n }\n return result as T;\n }\n\n return data;\n}\n"],"names":["__webpack_require__","definition","key","Object","obj","prop","Symbol","restoreScreenshotValue","screenshot","imageMap","console","base64","availableIds","restoreImageReferences","data","Array","item","result","value"],"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,SAA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B,MAAM,IAAIf,OAAO,OAAO,CAACW,MACxCG,MAAM,CAACf,IAAI,GAAGW,uBAAuBK,OAAOT;QAE9C,OAAOQ;IACT;IAEA,OAAOH;AACT"}
|
|
@@ -0,0 +1,60 @@
|
|
|
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
|
+
parseDumpScript: ()=>external_html_utils_js_namespaceObject.parseDumpScript,
|
|
28
|
+
restoreImageReferences: ()=>external_image_restoration_js_namespaceObject.restoreImageReferences,
|
|
29
|
+
generateImageScriptTag: ()=>external_html_utils_js_namespaceObject.generateImageScriptTag,
|
|
30
|
+
parseImageScripts: ()=>external_html_utils_js_namespaceObject.parseImageScripts,
|
|
31
|
+
parseDumpScriptAttributes: ()=>external_html_utils_js_namespaceObject.parseDumpScriptAttributes,
|
|
32
|
+
unescapeContent: ()=>external_html_utils_js_namespaceObject.unescapeContent,
|
|
33
|
+
escapeContent: ()=>external_html_utils_js_namespaceObject.escapeContent,
|
|
34
|
+
generateDumpScriptTag: ()=>external_html_utils_js_namespaceObject.generateDumpScriptTag
|
|
35
|
+
});
|
|
36
|
+
const external_image_restoration_js_namespaceObject = require("./image-restoration.js");
|
|
37
|
+
const external_html_utils_js_namespaceObject = require("./html-utils.js");
|
|
38
|
+
exports.escapeContent = __webpack_exports__.escapeContent;
|
|
39
|
+
exports.generateDumpScriptTag = __webpack_exports__.generateDumpScriptTag;
|
|
40
|
+
exports.generateImageScriptTag = __webpack_exports__.generateImageScriptTag;
|
|
41
|
+
exports.parseDumpScript = __webpack_exports__.parseDumpScript;
|
|
42
|
+
exports.parseDumpScriptAttributes = __webpack_exports__.parseDumpScriptAttributes;
|
|
43
|
+
exports.parseImageScripts = __webpack_exports__.parseImageScripts;
|
|
44
|
+
exports.restoreImageReferences = __webpack_exports__.restoreImageReferences;
|
|
45
|
+
exports.unescapeContent = __webpack_exports__.unescapeContent;
|
|
46
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
47
|
+
"escapeContent",
|
|
48
|
+
"generateDumpScriptTag",
|
|
49
|
+
"generateImageScriptTag",
|
|
50
|
+
"parseDumpScript",
|
|
51
|
+
"parseDumpScriptAttributes",
|
|
52
|
+
"parseImageScripts",
|
|
53
|
+
"restoreImageReferences",
|
|
54
|
+
"unescapeContent"
|
|
55
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
56
|
+
Object.defineProperty(exports, '__esModule', {
|
|
57
|
+
value: true
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dump/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"}
|
package/dist/lib/index.js
CHANGED
|
@@ -34,23 +34,34 @@ var __webpack_exports__ = {};
|
|
|
34
34
|
__webpack_require__.r(__webpack_exports__);
|
|
35
35
|
__webpack_require__.d(__webpack_exports__, {
|
|
36
36
|
plan: ()=>external_ai_model_index_js_namespaceObject.plan,
|
|
37
|
-
Service: ()=>index_js_default(),
|
|
38
|
-
MIDSCENE_MODEL_NAME: ()=>env_namespaceObject.MIDSCENE_MODEL_NAME,
|
|
39
37
|
TUserPromptSchema: ()=>external_ai_model_index_js_namespaceObject.TUserPromptSchema,
|
|
38
|
+
MIDSCENE_MODEL_NAME: ()=>env_namespaceObject.MIDSCENE_MODEL_NAME,
|
|
40
39
|
describeUserPage: ()=>external_ai_model_index_js_namespaceObject.describeUserPage,
|
|
41
|
-
|
|
42
|
-
|
|
40
|
+
generateImageScriptTag: ()=>external_dump_index_js_namespaceObject.generateImageScriptTag,
|
|
41
|
+
restoreImageReferences: ()=>external_dump_index_js_namespaceObject.restoreImageReferences,
|
|
42
|
+
parseDumpScriptAttributes: ()=>external_dump_index_js_namespaceObject.parseDumpScriptAttributes,
|
|
43
43
|
z: ()=>external_zod_namespaceObject.z,
|
|
44
|
+
generateDumpScriptTag: ()=>external_dump_index_js_namespaceObject.generateDumpScriptTag,
|
|
44
45
|
SizeSchema: ()=>external_ai_model_index_js_namespaceObject.SizeSchema,
|
|
45
|
-
TaskRunner: ()=>external_task_runner_js_namespaceObject.TaskRunner,
|
|
46
46
|
default: ()=>src,
|
|
47
47
|
getVersion: ()=>external_utils_js_namespaceObject.getVersion,
|
|
48
48
|
getMidsceneLocationSchema: ()=>external_ai_model_index_js_namespaceObject.getMidsceneLocationSchema,
|
|
49
|
+
parseDumpScript: ()=>external_dump_index_js_namespaceObject.parseDumpScript,
|
|
49
50
|
ServiceError: ()=>external_types_js_namespaceObject.ServiceError,
|
|
50
|
-
|
|
51
|
+
parseImageScripts: ()=>external_dump_index_js_namespaceObject.parseImageScripts,
|
|
51
52
|
PointSchema: ()=>external_ai_model_index_js_namespaceObject.PointSchema,
|
|
53
|
+
RectSchema: ()=>external_ai_model_index_js_namespaceObject.RectSchema,
|
|
52
54
|
Agent: ()=>external_agent_index_js_namespaceObject.Agent,
|
|
53
|
-
|
|
55
|
+
Service: ()=>index_js_default(),
|
|
56
|
+
AiLocateElement: ()=>external_ai_model_index_js_namespaceObject.AiLocateElement,
|
|
57
|
+
ScreenshotItem: ()=>external_screenshot_item_js_namespaceObject.ScreenshotItem,
|
|
58
|
+
createAgent: ()=>external_agent_index_js_namespaceObject.createAgent,
|
|
59
|
+
ExecutionDump: ()=>external_types_js_namespaceObject.ExecutionDump,
|
|
60
|
+
escapeContent: ()=>external_dump_index_js_namespaceObject.escapeContent,
|
|
61
|
+
TaskRunner: ()=>external_task_runner_js_namespaceObject.TaskRunner,
|
|
62
|
+
GroupedActionDump: ()=>external_types_js_namespaceObject.GroupedActionDump,
|
|
63
|
+
TMultimodalPromptSchema: ()=>external_ai_model_index_js_namespaceObject.TMultimodalPromptSchema,
|
|
64
|
+
unescapeContent: ()=>external_dump_index_js_namespaceObject.unescapeContent
|
|
54
65
|
});
|
|
55
66
|
const external_zod_namespaceObject = require("zod");
|
|
56
67
|
const index_js_namespaceObject = require("./service/index.js");
|
|
@@ -61,12 +72,17 @@ const external_ai_model_index_js_namespaceObject = require("./ai-model/index.js"
|
|
|
61
72
|
const env_namespaceObject = require("@midscene/shared/env");
|
|
62
73
|
const external_types_js_namespaceObject = require("./types.js");
|
|
63
74
|
const external_agent_index_js_namespaceObject = require("./agent/index.js");
|
|
75
|
+
const external_dump_index_js_namespaceObject = require("./dump/index.js");
|
|
76
|
+
const external_screenshot_item_js_namespaceObject = require("./screenshot-item.js");
|
|
64
77
|
const src = index_js_default();
|
|
65
78
|
exports.Agent = __webpack_exports__.Agent;
|
|
66
79
|
exports.AiLocateElement = __webpack_exports__.AiLocateElement;
|
|
80
|
+
exports.ExecutionDump = __webpack_exports__.ExecutionDump;
|
|
81
|
+
exports.GroupedActionDump = __webpack_exports__.GroupedActionDump;
|
|
67
82
|
exports.MIDSCENE_MODEL_NAME = __webpack_exports__.MIDSCENE_MODEL_NAME;
|
|
68
83
|
exports.PointSchema = __webpack_exports__.PointSchema;
|
|
69
84
|
exports.RectSchema = __webpack_exports__.RectSchema;
|
|
85
|
+
exports.ScreenshotItem = __webpack_exports__.ScreenshotItem;
|
|
70
86
|
exports.Service = __webpack_exports__.Service;
|
|
71
87
|
exports.ServiceError = __webpack_exports__.ServiceError;
|
|
72
88
|
exports.SizeSchema = __webpack_exports__.SizeSchema;
|
|
@@ -76,16 +92,27 @@ exports.TaskRunner = __webpack_exports__.TaskRunner;
|
|
|
76
92
|
exports.createAgent = __webpack_exports__.createAgent;
|
|
77
93
|
exports["default"] = __webpack_exports__["default"];
|
|
78
94
|
exports.describeUserPage = __webpack_exports__.describeUserPage;
|
|
95
|
+
exports.escapeContent = __webpack_exports__.escapeContent;
|
|
96
|
+
exports.generateDumpScriptTag = __webpack_exports__.generateDumpScriptTag;
|
|
97
|
+
exports.generateImageScriptTag = __webpack_exports__.generateImageScriptTag;
|
|
79
98
|
exports.getMidsceneLocationSchema = __webpack_exports__.getMidsceneLocationSchema;
|
|
80
99
|
exports.getVersion = __webpack_exports__.getVersion;
|
|
100
|
+
exports.parseDumpScript = __webpack_exports__.parseDumpScript;
|
|
101
|
+
exports.parseDumpScriptAttributes = __webpack_exports__.parseDumpScriptAttributes;
|
|
102
|
+
exports.parseImageScripts = __webpack_exports__.parseImageScripts;
|
|
81
103
|
exports.plan = __webpack_exports__.plan;
|
|
104
|
+
exports.restoreImageReferences = __webpack_exports__.restoreImageReferences;
|
|
105
|
+
exports.unescapeContent = __webpack_exports__.unescapeContent;
|
|
82
106
|
exports.z = __webpack_exports__.z;
|
|
83
107
|
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
84
108
|
"Agent",
|
|
85
109
|
"AiLocateElement",
|
|
110
|
+
"ExecutionDump",
|
|
111
|
+
"GroupedActionDump",
|
|
86
112
|
"MIDSCENE_MODEL_NAME",
|
|
87
113
|
"PointSchema",
|
|
88
114
|
"RectSchema",
|
|
115
|
+
"ScreenshotItem",
|
|
89
116
|
"Service",
|
|
90
117
|
"ServiceError",
|
|
91
118
|
"SizeSchema",
|
|
@@ -95,9 +122,17 @@ for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
|
95
122
|
"createAgent",
|
|
96
123
|
"default",
|
|
97
124
|
"describeUserPage",
|
|
125
|
+
"escapeContent",
|
|
126
|
+
"generateDumpScriptTag",
|
|
127
|
+
"generateImageScriptTag",
|
|
98
128
|
"getMidsceneLocationSchema",
|
|
99
129
|
"getVersion",
|
|
130
|
+
"parseDumpScript",
|
|
131
|
+
"parseDumpScriptAttributes",
|
|
132
|
+
"parseImageScripts",
|
|
100
133
|
"plan",
|
|
134
|
+
"restoreImageReferences",
|
|
135
|
+
"unescapeContent",
|
|
101
136
|
"z"
|
|
102
137
|
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
103
138
|
Object.defineProperty(exports, '__esModule', {
|
package/dist/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["webpack/runtime/compat_get_default_export","webpack/runtime/define_property_getters","webpack/runtime/has_own_property","webpack/runtime/make_namespace_object","../../src/index.ts"],"sourcesContent":["// getDefaultExport function for compatibility with non-ESM modules\n__webpack_require__.n = (module) => {\n\tvar getter = module && module.__esModule ?\n\t\t() => (module['default']) :\n\t\t() => (module);\n\t__webpack_require__.d(getter, { a: getter });\n\treturn getter;\n};\n","__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 { z } from 'zod';\nimport Service from './service/index';\nimport { TaskRunner } from './task-runner';\nimport { getVersion } from './utils';\n\nexport {\n plan,\n describeUserPage,\n AiLocateElement,\n getMidsceneLocationSchema,\n type MidsceneLocationResultType,\n PointSchema,\n SizeSchema,\n RectSchema,\n TMultimodalPromptSchema,\n TUserPromptSchema,\n type TMultimodalPrompt,\n type TUserPrompt,\n} from './ai-model/index';\n\nexport {\n MIDSCENE_MODEL_NAME,\n type CreateOpenAIClientFn,\n} from '@midscene/shared/env';\n\nexport type * from './types';\nexport {
|
|
1
|
+
{"version":3,"file":"index.js","sources":["webpack/runtime/compat_get_default_export","webpack/runtime/define_property_getters","webpack/runtime/has_own_property","webpack/runtime/make_namespace_object","../../src/index.ts"],"sourcesContent":["// getDefaultExport function for compatibility with non-ESM modules\n__webpack_require__.n = (module) => {\n\tvar getter = module && module.__esModule ?\n\t\t() => (module['default']) :\n\t\t() => (module);\n\t__webpack_require__.d(getter, { a: getter });\n\treturn getter;\n};\n","__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 { z } from 'zod';\nimport Service from './service/index';\nimport { TaskRunner } from './task-runner';\nimport { getVersion } from './utils';\n\nexport {\n plan,\n describeUserPage,\n AiLocateElement,\n getMidsceneLocationSchema,\n type MidsceneLocationResultType,\n PointSchema,\n SizeSchema,\n RectSchema,\n TMultimodalPromptSchema,\n TUserPromptSchema,\n type TMultimodalPrompt,\n type TUserPrompt,\n} from './ai-model/index';\n\nexport {\n MIDSCENE_MODEL_NAME,\n type CreateOpenAIClientFn,\n} from '@midscene/shared/env';\n\nexport type * from './types';\nexport {\n ServiceError,\n ExecutionDump,\n GroupedActionDump,\n type IExecutionDump,\n type IGroupedActionDump,\n} from './types';\n\nexport { z };\n\nexport default Service;\nexport { TaskRunner, Service, getVersion };\n\nexport type {\n MidsceneYamlScript,\n MidsceneYamlTask,\n MidsceneYamlFlowItem,\n MidsceneYamlConfigResult,\n MidsceneYamlConfig,\n MidsceneYamlScriptWebEnv,\n MidsceneYamlScriptAndroidEnv,\n MidsceneYamlScriptIOSEnv,\n MidsceneYamlScriptEnv,\n LocateOption,\n DetailedLocateParam,\n} from './yaml';\n\nexport { Agent, type AgentOpt, type AiActOptions, createAgent } from './agent';\n\n// Dump utilities\nexport {\n restoreImageReferences,\n escapeContent,\n unescapeContent,\n parseImageScripts,\n parseDumpScript,\n parseDumpScriptAttributes,\n generateImageScriptTag,\n generateDumpScriptTag,\n} from './dump';\n\n// ScreenshotItem\nexport { ScreenshotItem } from './screenshot-item';\n"],"names":["__webpack_require__","module","getter","definition","key","Object","obj","prop","Symbol","Service"],"mappings":";;;IACAA,oBAAoB,CAAC,GAAG,CAACC;QACxB,IAAIC,SAASD,UAAUA,OAAO,UAAU,GACvC,IAAOA,MAAM,CAAC,UAAU,GACxB,IAAOA;QACRD,oBAAoB,CAAC,CAACE,QAAQ;YAAE,GAAGA;QAAO;QAC1C,OAAOA;IACR;;;ICPAF,oBAAoB,CAAC,GAAG,CAAC,UAASG;QACjC,IAAI,IAAIC,OAAOD,WACR,IAAGH,oBAAoB,CAAC,CAACG,YAAYC,QAAQ,CAACJ,oBAAoB,CAAC,CAAC,UAASI,MACzEC,OAAO,cAAc,CAAC,UAASD,KAAK;YAAE,YAAY;YAAM,KAAKD,UAAU,CAACC,IAAI;QAAC;IAGzF;;;ICNAJ,oBAAoB,CAAC,GAAG,CAACM,KAAKC,OAAUF,OAAO,SAAS,CAAC,cAAc,CAAC,IAAI,CAACC,KAAKC;;;ICClFP,oBAAoB,CAAC,GAAG,CAAC;QACxB,IAAG,AAAkB,eAAlB,OAAOQ,UAA0BA,OAAO,WAAW,EACrDH,OAAO,cAAc,CAAC,UAASG,OAAO,WAAW,EAAE;YAAE,OAAO;QAAS;QAEtEH,OAAO,cAAc,CAAC,UAAS,cAAc;YAAE,OAAO;QAAK;IAC5D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AC8BA,YAAeI"}
|
|
@@ -0,0 +1,68 @@
|
|
|
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
|
+
ScreenshotItem: ()=>ScreenshotItem
|
|
28
|
+
});
|
|
29
|
+
function _define_property(obj, key, value) {
|
|
30
|
+
if (key in obj) Object.defineProperty(obj, key, {
|
|
31
|
+
value: value,
|
|
32
|
+
enumerable: true,
|
|
33
|
+
configurable: true,
|
|
34
|
+
writable: true
|
|
35
|
+
});
|
|
36
|
+
else obj[key] = value;
|
|
37
|
+
return obj;
|
|
38
|
+
}
|
|
39
|
+
class ScreenshotItem {
|
|
40
|
+
static create(base64) {
|
|
41
|
+
return new ScreenshotItem(base64);
|
|
42
|
+
}
|
|
43
|
+
getData() {
|
|
44
|
+
return this._data;
|
|
45
|
+
}
|
|
46
|
+
toSerializable() {
|
|
47
|
+
return this._data;
|
|
48
|
+
}
|
|
49
|
+
static isSerializedData(value) {
|
|
50
|
+
return 'string' == typeof value && value.length > 0;
|
|
51
|
+
}
|
|
52
|
+
static fromSerializedData(data) {
|
|
53
|
+
return new ScreenshotItem(data);
|
|
54
|
+
}
|
|
55
|
+
constructor(data){
|
|
56
|
+
_define_property(this, "_data", void 0);
|
|
57
|
+
this._data = data;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
exports.ScreenshotItem = __webpack_exports__.ScreenshotItem;
|
|
61
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
62
|
+
"ScreenshotItem"
|
|
63
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
64
|
+
Object.defineProperty(exports, '__esModule', {
|
|
65
|
+
value: true
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
//# sourceMappingURL=screenshot-item.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"screenshot-item.js","sources":["webpack/runtime/define_property_getters","webpack/runtime/has_own_property","webpack/runtime/make_namespace_object","../../src/screenshot-item.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};","/**\n * ScreenshotItem encapsulates screenshot data.\n * This is a simple wrapper class that prepares for future storage optimization.\n *\n * Current implementation: stores base64 string directly in memory\n * Future: can be extended to use storage providers (file system, IndexedDB, etc.)\n */\nexport class ScreenshotItem {\n private _data: string;\n\n private constructor(data: string) {\n this._data = data;\n }\n\n /** Create a new ScreenshotItem from base64 data */\n static create(base64: string): ScreenshotItem {\n return new ScreenshotItem(base64);\n }\n\n /** Get the base64 data synchronously */\n getData(): string {\n return this._data;\n }\n\n /** Serialize to base64 string for JSON */\n toSerializable(): string {\n return this._data;\n }\n\n /**\n * Check if a value looks like serialized screenshot data\n * (non-empty base64 string)\n */\n static isSerializedData(value: unknown): value is string {\n return typeof value === 'string' && value.length > 0;\n }\n\n /**\n * Deserialize from base64 string back to ScreenshotItem\n * This is the counterpart of toSerializable()\n */\n static fromSerializedData(data: string): ScreenshotItem {\n return new ScreenshotItem(data);\n }\n}\n"],"names":["__webpack_require__","definition","key","Object","obj","prop","Symbol","ScreenshotItem","base64","value","data"],"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;;;;;;;ACAC;;;;;;;;;;AACM,MAAMI;IAQX,OAAO,OAAOC,MAAc,EAAkB;QAC5C,OAAO,IAAID,eAAeC;IAC5B;IAGA,UAAkB;QAChB,OAAO,IAAI,CAAC,KAAK;IACnB;IAGA,iBAAyB;QACvB,OAAO,IAAI,CAAC,KAAK;IACnB;IAMA,OAAO,iBAAiBC,KAAc,EAAmB;QACvD,OAAO,AAAiB,YAAjB,OAAOA,SAAsBA,MAAM,MAAM,GAAG;IACrD;IAMA,OAAO,mBAAmBC,IAAY,EAAkB;QACtD,OAAO,IAAIH,eAAeG;IAC5B;IAjCA,YAAoBA,IAAY,CAAE;QAFlC,uBAAQ,SAAR;QAGE,IAAI,CAAC,KAAK,GAAGA;IACf;AAgCF"}
|
|
@@ -181,7 +181,8 @@ class Service {
|
|
|
181
181
|
async describe(target, modelConfig, opt) {
|
|
182
182
|
(0, utils_namespaceObject.assert)(target, 'target is required for service.describe');
|
|
183
183
|
const context = await this.contextRetrieverFn();
|
|
184
|
-
const {
|
|
184
|
+
const { size } = context;
|
|
185
|
+
const screenshotBase64 = context.screenshot.getData();
|
|
185
186
|
(0, utils_namespaceObject.assert)(screenshotBase64, 'screenshot is required for service.describe');
|
|
186
187
|
const { vlMode } = modelConfig;
|
|
187
188
|
const systemPrompt = (0, describe_js_namespaceObject.elementDescriberInstruction)();
|