@midscene/shared 1.7.7-beta-20260429033400.0 → 1.7.7

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.
@@ -384,6 +384,35 @@ function generateCommonTools(getAgent, initArgSchema = {}, initArgCliMetadata) {
384
384
  return createErrorResult(`Failed to execute act: ${errorMessage}`);
385
385
  }
386
386
  }
387
+ },
388
+ {
389
+ name: 'assert',
390
+ description: 'Assert a natural language statement against the current page/screen.',
391
+ schema: {
392
+ prompt: z.string().describe('Natural language assertion to verify, e.g. "there is a login button visible"'),
393
+ ...initArgSchema
394
+ },
395
+ cli: mergeToolCliMetadata(void 0, initArgCliMetadata),
396
+ handler: async (args = {})=>{
397
+ const prompt = args.prompt;
398
+ try {
399
+ const agent = await getAgent(args);
400
+ if (!agent.aiAssert) return createErrorResult('assert is not supported by this agent');
401
+ await agent.aiAssert(prompt);
402
+ return {
403
+ content: [
404
+ {
405
+ type: 'text',
406
+ text: 'Assertion passed.'
407
+ }
408
+ ]
409
+ };
410
+ } catch (error) {
411
+ const errorMessage = getErrorMessage(error);
412
+ console.error('Error executing assert:', errorMessage);
413
+ return createErrorResult(`Failed to execute assert: ${errorMessage}`);
414
+ }
415
+ }
387
416
  }
388
417
  ];
389
418
  }
@@ -413,6 +413,35 @@ function generateCommonTools(getAgent, initArgSchema = {}, initArgCliMetadata) {
413
413
  return createErrorResult(`Failed to execute act: ${errorMessage}`);
414
414
  }
415
415
  }
416
+ },
417
+ {
418
+ name: 'assert',
419
+ description: 'Assert a natural language statement against the current page/screen.',
420
+ schema: {
421
+ prompt: external_zod_namespaceObject.z.string().describe('Natural language assertion to verify, e.g. "there is a login button visible"'),
422
+ ...initArgSchema
423
+ },
424
+ cli: mergeToolCliMetadata(void 0, initArgCliMetadata),
425
+ handler: async (args = {})=>{
426
+ const prompt = args.prompt;
427
+ try {
428
+ const agent = await getAgent(args);
429
+ if (!agent.aiAssert) return createErrorResult('assert is not supported by this agent');
430
+ await agent.aiAssert(prompt);
431
+ return {
432
+ content: [
433
+ {
434
+ type: 'text',
435
+ text: 'Assertion passed.'
436
+ }
437
+ ]
438
+ };
439
+ } catch (error) {
440
+ const errorMessage = (0, external_error_formatter_js_namespaceObject.getErrorMessage)(error);
441
+ console.error('Error executing assert:', errorMessage);
442
+ return createErrorResult(`Failed to execute assert: ${errorMessage}`);
443
+ }
444
+ }
416
445
  }
417
446
  ];
418
447
  }
@@ -94,6 +94,7 @@ export interface BaseAgent {
94
94
  callActionInActionSpace?: (actionName: string, params?: unknown) => Promise<unknown>;
95
95
  aiAction?: (description: string, params?: Record<string, unknown>) => Promise<unknown>;
96
96
  aiWaitFor?: (assertion: string, options: Record<string, unknown>) => Promise<unknown>;
97
+ aiAssert?: (assertion: string, msg?: string, options?: Record<string, unknown>) => Promise<unknown>;
97
98
  }
98
99
  /**
99
100
  * Base device interface for temporary device instances
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@midscene/shared",
3
- "version": "1.7.7-beta-20260429033400.0",
3
+ "version": "1.7.7",
4
4
  "repository": "https://github.com/web-infra-dev/midscene",
5
5
  "homepage": "https://midscenejs.com/",
6
6
  "types": "./dist/types/index.d.ts",
@@ -621,5 +621,38 @@ export function generateCommonTools(
621
621
  }
622
622
  },
623
623
  },
624
+ {
625
+ name: 'assert',
626
+ description:
627
+ 'Assert a natural language statement against the current page/screen.',
628
+ schema: {
629
+ prompt: z
630
+ .string()
631
+ .describe(
632
+ 'Natural language assertion to verify, e.g. "there is a login button visible"',
633
+ ),
634
+ ...initArgSchema,
635
+ },
636
+ cli: mergeToolCliMetadata(undefined, initArgCliMetadata),
637
+ handler: async (
638
+ args: Record<string, unknown> = {},
639
+ ): Promise<ToolResult> => {
640
+ const prompt = args.prompt as string;
641
+ try {
642
+ const agent = await getAgent(args);
643
+ if (!agent.aiAssert) {
644
+ return createErrorResult('assert is not supported by this agent');
645
+ }
646
+ await agent.aiAssert(prompt);
647
+ return {
648
+ content: [{ type: 'text', text: 'Assertion passed.' }],
649
+ };
650
+ } catch (error: unknown) {
651
+ const errorMessage = getErrorMessage(error);
652
+ console.error('Error executing assert:', errorMessage);
653
+ return createErrorResult(`Failed to execute assert: ${errorMessage}`);
654
+ }
655
+ },
656
+ },
624
657
  ];
625
658
  }
package/src/mcp/types.ts CHANGED
@@ -106,6 +106,11 @@ export interface BaseAgent {
106
106
  assertion: string,
107
107
  options: Record<string, unknown>,
108
108
  ) => Promise<unknown>;
109
+ aiAssert?: (
110
+ assertion: string,
111
+ msg?: string,
112
+ options?: Record<string, unknown>,
113
+ ) => Promise<unknown>;
109
114
  }
110
115
 
111
116
  /**