@midscene/shared 1.4.2 → 1.4.3

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.
@@ -13,12 +13,10 @@ async function getPhoton() {
13
13
  const photon = await import("@silvia-odwyer/photon");
14
14
  if ('function' == typeof photon.default) await photon.default();
15
15
  debug('Photon loaded: @silvia-odwyer/photon (browser/worker)');
16
- console.log('[midscene:img] Photon loaded: @silvia-odwyer/photon (browser/worker)');
17
16
  photonModule = photon;
18
17
  } else if (ifInNode) {
19
18
  photonModule = await import("@silvia-odwyer/photon-node");
20
19
  debug('Photon loaded: @silvia-odwyer/photon-node (node)');
21
- console.log('[midscene:img] Photon loaded: @silvia-odwyer/photon-node (node)');
22
20
  }
23
21
  if (!photonModule?.PhotonImage) throw new Error('PhotonImage is not available');
24
22
  if (!photonModule.PhotonImage.new_from_byteslice && !photonModule.PhotonImage.new_from_base64) throw new Error('PhotonImage.new_from_byteslice or new_from_base64 is not available');
@@ -273,8 +273,18 @@ function generateCommonTools(getAgent) {
273
273
  try {
274
274
  const agent = await getAgent();
275
275
  if (!agent.aiAction) return createErrorResult('act is not supported by this agent');
276
- await agent.aiAction(prompt);
277
- return await captureScreenshotResult(agent, 'act');
276
+ const result = await agent.aiAction(prompt, {
277
+ deepThink: true
278
+ });
279
+ const screenshotResult = await captureScreenshotResult(agent, 'act');
280
+ if (result) {
281
+ const message = 'string' == typeof result ? result : JSON.stringify(result);
282
+ screenshotResult.content.unshift({
283
+ type: 'text',
284
+ text: `Task finished, message: ${message}`
285
+ });
286
+ }
287
+ return screenshotResult;
278
288
  } catch (error) {
279
289
  const errorMessage = getErrorMessage(error);
280
290
  console.error('Error executing act:', errorMessage);
@@ -42,12 +42,10 @@ async function getPhoton() {
42
42
  const photon = await import("@silvia-odwyer/photon");
43
43
  if ('function' == typeof photon.default) await photon.default();
44
44
  debug('Photon loaded: @silvia-odwyer/photon (browser/worker)');
45
- console.log('[midscene:img] Photon loaded: @silvia-odwyer/photon (browser/worker)');
46
45
  photonModule = photon;
47
46
  } else if (external_utils_js_namespaceObject.ifInNode) {
48
47
  photonModule = await import("@silvia-odwyer/photon-node");
49
48
  debug('Photon loaded: @silvia-odwyer/photon-node (node)');
50
- console.log('[midscene:img] Photon loaded: @silvia-odwyer/photon-node (node)');
51
49
  }
52
50
  if (!photonModule?.PhotonImage) throw new Error('PhotonImage is not available');
53
51
  if (!photonModule.PhotonImage.new_from_byteslice && !photonModule.PhotonImage.new_from_base64) throw new Error('PhotonImage.new_from_byteslice or new_from_base64 is not available');
@@ -302,8 +302,18 @@ function generateCommonTools(getAgent) {
302
302
  try {
303
303
  const agent = await getAgent();
304
304
  if (!agent.aiAction) return createErrorResult('act is not supported by this agent');
305
- await agent.aiAction(prompt);
306
- return await captureScreenshotResult(agent, 'act');
305
+ const result = await agent.aiAction(prompt, {
306
+ deepThink: true
307
+ });
308
+ const screenshotResult = await captureScreenshotResult(agent, 'act');
309
+ if (result) {
310
+ const message = 'string' == typeof result ? result : JSON.stringify(result);
311
+ screenshotResult.content.unshift({
312
+ type: 'text',
313
+ text: `Task finished, message: ${message}`
314
+ });
315
+ }
316
+ return screenshotResult;
307
317
  } catch (error) {
308
318
  const errorMessage = getErrorMessage(error);
309
319
  console.error('Error executing act:', errorMessage);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@midscene/shared",
3
- "version": "1.4.2",
3
+ "version": "1.4.3",
4
4
  "repository": "https://github.com/web-infra-dev/midscene",
5
5
  "homepage": "https://midscenejs.com/",
6
6
  "types": "./dist/types/index.d.ts",
@@ -45,17 +45,11 @@ export default async function getPhoton(): Promise<{
45
45
  await photon.default();
46
46
  }
47
47
  debug('Photon loaded: @silvia-odwyer/photon (browser/worker)');
48
- console.log(
49
- '[midscene:img] Photon loaded: @silvia-odwyer/photon (browser/worker)',
50
- );
51
48
  photonModule = photon;
52
49
  } else if (ifInNode) {
53
50
  // Node.js environment: use @silvia-odwyer/photon-node
54
51
  photonModule = await import('@silvia-odwyer/photon-node');
55
52
  debug('Photon loaded: @silvia-odwyer/photon-node (node)');
56
- console.log(
57
- '[midscene:img] Photon loaded: @silvia-odwyer/photon-node (node)',
58
- );
59
53
  }
60
54
 
61
55
  // verify that the critical functions exist (only for Photon, not Canvas fallback)
@@ -407,8 +407,17 @@ export function generateCommonTools(
407
407
  if (!agent.aiAction) {
408
408
  return createErrorResult('act is not supported by this agent');
409
409
  }
410
- await agent.aiAction(prompt);
411
- return await captureScreenshotResult(agent, 'act');
410
+ const result = await agent.aiAction(prompt, { deepThink: true });
411
+ const screenshotResult = await captureScreenshotResult(agent, 'act');
412
+ if (result) {
413
+ const message =
414
+ typeof result === 'string' ? result : JSON.stringify(result);
415
+ screenshotResult.content.unshift({
416
+ type: 'text',
417
+ text: `Task finished, message: ${message}`,
418
+ });
419
+ }
420
+ return screenshotResult;
412
421
  } catch (error: unknown) {
413
422
  const errorMessage = getErrorMessage(error);
414
423
  console.error('Error executing act:', errorMessage);