@midscene/shared 1.15.5 → 1.16.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 (34) hide show
  1. package/dist/es/env/constants.mjs +26 -2
  2. package/dist/es/env/global-config-manager.mjs +1 -6
  3. package/dist/es/env/model-config-manager.mjs +10 -2
  4. package/dist/es/env/parse-model-config.mjs +8 -2
  5. package/dist/es/env/types.mjs +43 -2
  6. package/dist/es/img/index.mjs +2 -2
  7. package/dist/es/img/transform.mjs +52 -1
  8. package/dist/lib/env/constants.js +27 -0
  9. package/dist/lib/env/global-config-manager.js +0 -5
  10. package/dist/lib/env/model-config-manager.js +10 -2
  11. package/dist/lib/env/parse-model-config.js +7 -1
  12. package/dist/lib/env/types.js +102 -1
  13. package/dist/lib/img/index.js +3 -0
  14. package/dist/lib/img/transform.js +54 -0
  15. package/dist/types/env/constants.d.ts +2 -0
  16. package/dist/types/env/constants.d.ts.map +1 -1
  17. package/dist/types/env/global-config-manager.d.ts.map +1 -1
  18. package/dist/types/env/model-config-manager.d.ts.map +1 -1
  19. package/dist/types/env/parse-model-config.d.ts +2 -2
  20. package/dist/types/env/parse-model-config.d.ts.map +1 -1
  21. package/dist/types/env/types.d.ts +48 -8
  22. package/dist/types/env/types.d.ts.map +1 -1
  23. package/dist/types/img/index.d.ts +1 -1
  24. package/dist/types/img/index.d.ts.map +1 -1
  25. package/dist/types/img/transform.d.ts +6 -0
  26. package/dist/types/img/transform.d.ts.map +1 -1
  27. package/package.json +1 -1
  28. package/src/env/constants.ts +65 -0
  29. package/src/env/global-config-manager.ts +0 -10
  30. package/src/env/model-config-manager.ts +17 -3
  31. package/src/env/parse-model-config.ts +12 -0
  32. package/src/env/types.ts +93 -6
  33. package/src/img/index.ts +1 -0
  34. package/src/img/transform.ts +67 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@midscene/shared",
3
- "version": "1.15.5",
3
+ "version": "1.16.0",
4
4
  "repository": "https://github.com/web-infra-dev/midscene",
5
5
  "homepage": "https://midscenejs.com/",
6
6
  "types": "./dist/types/index.d.ts",
@@ -14,8 +14,27 @@ import {
14
14
  MIDSCENE_INSIGHT_MODEL_RETRY_COUNT,
15
15
  MIDSCENE_INSIGHT_MODEL_RETRY_INTERVAL,
16
16
  MIDSCENE_INSIGHT_MODEL_SOCKS_PROXY,
17
+ MIDSCENE_INSIGHT_MODEL_STREAM_MODE,
17
18
  MIDSCENE_INSIGHT_MODEL_TEMPERATURE,
18
19
  MIDSCENE_INSIGHT_MODEL_TIMEOUT,
20
+ MIDSCENE_LOCATE_MODEL_API_KEY,
21
+ MIDSCENE_LOCATE_MODEL_BASE_URL,
22
+ MIDSCENE_LOCATE_MODEL_EXTRA_BODY_JSON,
23
+ MIDSCENE_LOCATE_MODEL_FAMILY,
24
+ MIDSCENE_LOCATE_MODEL_HTTP_PROXY,
25
+ MIDSCENE_LOCATE_MODEL_INIT_CONFIG_JSON,
26
+ MIDSCENE_LOCATE_MODEL_NAME,
27
+ MIDSCENE_LOCATE_MODEL_PROTOCOL,
28
+ MIDSCENE_LOCATE_MODEL_REASONING_BUDGET,
29
+ MIDSCENE_LOCATE_MODEL_REASONING_EFFORT,
30
+ MIDSCENE_LOCATE_MODEL_REASONING_ENABLED,
31
+ MIDSCENE_LOCATE_MODEL_RESPONSE_FORMAT,
32
+ MIDSCENE_LOCATE_MODEL_RETRY_COUNT,
33
+ MIDSCENE_LOCATE_MODEL_RETRY_INTERVAL,
34
+ MIDSCENE_LOCATE_MODEL_SOCKS_PROXY,
35
+ MIDSCENE_LOCATE_MODEL_STREAM_MODE,
36
+ MIDSCENE_LOCATE_MODEL_TEMPERATURE,
37
+ MIDSCENE_LOCATE_MODEL_TIMEOUT,
19
38
  MIDSCENE_MODEL_API_KEY,
20
39
  MIDSCENE_MODEL_BASE_URL,
21
40
  MIDSCENE_MODEL_EXTRA_BODY_JSON,
@@ -31,6 +50,7 @@ import {
31
50
  MIDSCENE_MODEL_RETRY_COUNT,
32
51
  MIDSCENE_MODEL_RETRY_INTERVAL,
33
52
  MIDSCENE_MODEL_SOCKS_PROXY,
53
+ MIDSCENE_MODEL_STREAM_MODE,
34
54
  MIDSCENE_MODEL_TEMPERATURE,
35
55
  MIDSCENE_MODEL_TIMEOUT,
36
56
  MIDSCENE_OPENAI_HTTP_PROXY,
@@ -51,6 +71,7 @@ import {
51
71
  MIDSCENE_PLANNING_MODEL_RETRY_COUNT,
52
72
  MIDSCENE_PLANNING_MODEL_RETRY_INTERVAL,
53
73
  MIDSCENE_PLANNING_MODEL_SOCKS_PROXY,
74
+ MIDSCENE_PLANNING_MODEL_STREAM_MODE,
54
75
  MIDSCENE_PLANNING_MODEL_TEMPERATURE,
55
76
  MIDSCENE_PLANNING_MODEL_TIMEOUT,
56
77
  OPENAI_API_KEY,
@@ -72,6 +93,7 @@ interface IModelConfigKeys {
72
93
  openaiExtraConfig: string;
73
94
  extraBody: string;
74
95
  protocol: string;
96
+ streamMode: string;
75
97
  /**
76
98
  * Extra
77
99
  */
@@ -110,6 +132,7 @@ export const INSIGHT_MODEL_CONFIG_KEYS: IModelConfigKeys = {
110
132
  openaiExtraConfig: MIDSCENE_INSIGHT_MODEL_INIT_CONFIG_JSON,
111
133
  extraBody: MIDSCENE_INSIGHT_MODEL_EXTRA_BODY_JSON,
112
134
  protocol: MIDSCENE_INSIGHT_MODEL_PROTOCOL,
135
+ streamMode: MIDSCENE_INSIGHT_MODEL_STREAM_MODE,
113
136
  /**
114
137
  * Extra
115
138
  */
@@ -133,6 +156,45 @@ export const INSIGHT_MODEL_CONFIG_KEYS: IModelConfigKeys = {
133
156
  responseFormat: MIDSCENE_INSIGHT_MODEL_RESPONSE_FORMAT,
134
157
  } as const;
135
158
 
159
+ export const LOCATE_MODEL_CONFIG_KEYS: IModelConfigKeys = {
160
+ modelName: MIDSCENE_LOCATE_MODEL_NAME,
161
+ /**
162
+ * proxy
163
+ */
164
+ socksProxy: MIDSCENE_LOCATE_MODEL_SOCKS_PROXY,
165
+ httpProxy: MIDSCENE_LOCATE_MODEL_HTTP_PROXY,
166
+ /**
167
+ * OpenAI
168
+ */
169
+ openaiBaseURL: MIDSCENE_LOCATE_MODEL_BASE_URL,
170
+ openaiApiKey: MIDSCENE_LOCATE_MODEL_API_KEY,
171
+ openaiExtraConfig: MIDSCENE_LOCATE_MODEL_INIT_CONFIG_JSON,
172
+ extraBody: MIDSCENE_LOCATE_MODEL_EXTRA_BODY_JSON,
173
+ protocol: MIDSCENE_LOCATE_MODEL_PROTOCOL,
174
+ streamMode: MIDSCENE_LOCATE_MODEL_STREAM_MODE,
175
+ /**
176
+ * Extra
177
+ */
178
+ modelFamily: MIDSCENE_LOCATE_MODEL_FAMILY,
179
+ /**
180
+ * Timeout
181
+ */
182
+ timeout: MIDSCENE_LOCATE_MODEL_TIMEOUT,
183
+ /**
184
+ * Temperature
185
+ */
186
+ temperature: MIDSCENE_LOCATE_MODEL_TEMPERATURE,
187
+ /**
188
+ * Retry
189
+ */
190
+ retryCount: MIDSCENE_LOCATE_MODEL_RETRY_COUNT,
191
+ retryInterval: MIDSCENE_LOCATE_MODEL_RETRY_INTERVAL,
192
+ reasoningEffort: MIDSCENE_LOCATE_MODEL_REASONING_EFFORT,
193
+ reasoningEnabled: MIDSCENE_LOCATE_MODEL_REASONING_ENABLED,
194
+ reasoningBudget: MIDSCENE_LOCATE_MODEL_REASONING_BUDGET,
195
+ responseFormat: MIDSCENE_LOCATE_MODEL_RESPONSE_FORMAT,
196
+ } as const;
197
+
136
198
  export const PLANNING_MODEL_CONFIG_KEYS: IModelConfigKeys = {
137
199
  modelName: MIDSCENE_PLANNING_MODEL_NAME,
138
200
  /**
@@ -148,6 +210,7 @@ export const PLANNING_MODEL_CONFIG_KEYS: IModelConfigKeys = {
148
210
  openaiExtraConfig: MIDSCENE_PLANNING_MODEL_INIT_CONFIG_JSON,
149
211
  extraBody: MIDSCENE_PLANNING_MODEL_EXTRA_BODY_JSON,
150
212
  protocol: MIDSCENE_PLANNING_MODEL_PROTOCOL,
213
+ streamMode: MIDSCENE_PLANNING_MODEL_STREAM_MODE,
151
214
  /**
152
215
  * Extra
153
216
  */
@@ -187,6 +250,7 @@ export const DEFAULT_MODEL_CONFIG_KEYS: IModelConfigKeys = {
187
250
  openaiExtraConfig: MIDSCENE_MODEL_INIT_CONFIG_JSON,
188
251
  extraBody: MIDSCENE_MODEL_EXTRA_BODY_JSON,
189
252
  protocol: MIDSCENE_MODEL_PROTOCOL,
253
+ streamMode: MIDSCENE_MODEL_STREAM_MODE,
190
254
  /**
191
255
  * Extra
192
256
  */
@@ -226,6 +290,7 @@ export const DEFAULT_MODEL_CONFIG_KEYS_LEGACY: IModelConfigKeys = {
226
290
  openaiExtraConfig: MIDSCENE_OPENAI_INIT_CONFIG_JSON,
227
291
  extraBody: MIDSCENE_MODEL_EXTRA_BODY_JSON,
228
292
  protocol: MIDSCENE_MODEL_PROTOCOL,
293
+ streamMode: MIDSCENE_MODEL_STREAM_MODE,
229
294
  /**
230
295
  * Extra
231
296
  */
@@ -10,7 +10,6 @@ import {
10
10
  import {
11
11
  ALL_ENV_KEYS,
12
12
  MATCH_BY_POSITION,
13
- MIDSCENE_MODEL_STREAM_MODE,
14
13
  MODEL_ENV_KEYS,
15
14
  type TGlobalConfig,
16
15
  } from './types';
@@ -74,15 +73,6 @@ export class GlobalConfigManager {
74
73
 
75
74
  const value = allConfig[key];
76
75
  this.keysHaveBeenRead[key] = true;
77
- if (key === MIDSCENE_MODEL_STREAM_MODE) {
78
- const mode = value?.trim() ?? 'non-stream';
79
- if (mode !== 'stream' && mode !== 'non-stream') {
80
- throw new Error(
81
- `Invalid MIDSCENE_MODEL_STREAM_MODE: "${mode}". Expected "stream" or "non-stream".`,
82
- );
83
- }
84
- return mode;
85
- }
86
76
  if (typeof value === 'string') {
87
77
  return value.trim();
88
78
  }
@@ -53,6 +53,12 @@ export class ModelConfigManager {
53
53
  );
54
54
  }
55
55
 
56
+ if (defaultConfig.modelFamily === 'jev') {
57
+ throw new Error(
58
+ 'Jev cannot be the default model. Configure a general-purpose MIDSCENE_MODEL_FAMILY and use Jev in Locate, Planning, or Insight.',
59
+ );
60
+ }
61
+
56
62
  const insightConfig = decideModelConfigFromIntentConfig(
57
63
  'insight',
58
64
  configMap,
@@ -63,8 +69,10 @@ export class ModelConfigManager {
63
69
  configMap,
64
70
  );
65
71
 
72
+ const locateConfig = decideModelConfigFromIntentConfig('locate', configMap);
73
+
66
74
  // Each intent uses its own timeout from parsed config (MIDSCENE_MODEL_TIMEOUT,
67
- // MIDSCENE_INSIGHT_MODEL_TIMEOUT, MIDSCENE_PLANNING_MODEL_TIMEOUT).
75
+ // MIDSCENE_INSIGHT_MODEL_TIMEOUT, MIDSCENE_PLANNING_MODEL_TIMEOUT, MIDSCENE_LOCATE_MODEL_TIMEOUT).
68
76
  this.modelConfigMap = {
69
77
  default: {
70
78
  ...defaultConfig,
@@ -72,6 +80,12 @@ export class ModelConfigManager {
72
80
  slot: 'default',
73
81
  createOpenAIClient: this.createOpenAIClientFn,
74
82
  },
83
+ locate: {
84
+ ...(locateConfig || defaultConfig),
85
+ intent: 'locate',
86
+ slot: locateConfig ? 'locate' : 'default',
87
+ createOpenAIClient: this.createOpenAIClientFn,
88
+ },
75
89
  insight: {
76
90
  ...(insightConfig || defaultConfig),
77
91
  intent: 'insight',
@@ -144,11 +158,11 @@ export class ModelConfigManager {
144
158
  }
145
159
 
146
160
  throwErrorIfNonVLModel() {
147
- const modelConfig = this.getModelConfig('default');
161
+ const modelConfig = this.getModelConfig('locate');
148
162
 
149
163
  if (!modelConfig.modelFamily) {
150
164
  throw new Error(
151
- 'MIDSCENE_MODEL_FAMILY is not set to a multimodal model with UI localization, so element localization cannot be achieved. Check your model configuration. See https://midscenejs.com/model-strategy.html',
165
+ `${modelConfig.slot === 'locate' ? 'MIDSCENE_LOCATE_MODEL_FAMILY' : 'MIDSCENE_MODEL_FAMILY'} is not set to a multimodal model with UI localization, so element localization cannot be achieved. Check your model configuration. See https://midscenejs.com/model-strategy.html`,
152
166
  );
153
167
  }
154
168
  }
@@ -2,6 +2,7 @@ import {
2
2
  DEFAULT_MODEL_CONFIG_KEYS,
3
3
  type DEFAULT_MODEL_CONFIG_KEYS_LEGACY,
4
4
  INSIGHT_MODEL_CONFIG_KEYS,
5
+ LOCATE_MODEL_CONFIG_KEYS,
5
6
  PLANNING_MODEL_CONFIG_KEYS,
6
7
  } from './constants';
7
8
  import {
@@ -45,12 +46,14 @@ const getInvalidModelFamilyMessage = (modelFamily: TModelFamily): string =>
45
46
  `Invalid MIDSCENE_MODEL_FAMILY value: ${modelFamily}. Current version v${getCurrentVersion()} accepts the following model families: ${MODEL_FAMILY_VALUES.join(', ')}. You can also visit ${MODEL_CONFIG_DOC_URL} for the latest configuration information.`;
46
47
 
47
48
  type TModelConfigKeys =
49
+ | typeof LOCATE_MODEL_CONFIG_KEYS
48
50
  | typeof INSIGHT_MODEL_CONFIG_KEYS
49
51
  | typeof PLANNING_MODEL_CONFIG_KEYS
50
52
  | typeof DEFAULT_MODEL_CONFIG_KEYS
51
53
  | typeof DEFAULT_MODEL_CONFIG_KEYS_LEGACY;
52
54
 
53
55
  const KEYS_MAP: Record<TIntent, TModelConfigKeys> = {
56
+ locate: LOCATE_MODEL_CONFIG_KEYS,
54
57
  insight: INSIGHT_MODEL_CONFIG_KEYS,
55
58
  planning: PLANNING_MODEL_CONFIG_KEYS,
56
59
  default: DEFAULT_MODEL_CONFIG_KEYS,
@@ -278,6 +281,15 @@ export const parseOpenaiSdkConfig = ({
278
281
  return timeout;
279
282
  })(),
280
283
  temperature,
284
+ streamMode: (() => {
285
+ const mode = provider[keys.streamMode]?.trim() ?? 'non-stream';
286
+ if (mode === 'stream' || mode === 'non-stream') {
287
+ return mode;
288
+ }
289
+ throw new Error(
290
+ `Invalid ${keys.streamMode}: "${mode}". Expected "stream" or "non-stream".`,
291
+ );
292
+ })(),
281
293
  retryCount: (() => {
282
294
  if (!provider[keys.retryCount]) return 1;
283
295
  const val = Number(provider[keys.retryCount]);
package/src/env/types.ts CHANGED
@@ -36,6 +36,12 @@ export const MIDSCENE_MODEL_REASONING_ENABLED =
36
36
  export const MIDSCENE_MODEL_REASONING_BUDGET =
37
37
  'MIDSCENE_MODEL_REASONING_BUDGET';
38
38
  export const MIDSCENE_MODEL_PROTOCOL = 'MIDSCENE_MODEL_PROTOCOL';
39
+ export const MIDSCENE_LOCATE_MODEL_STREAM_MODE =
40
+ 'MIDSCENE_LOCATE_MODEL_STREAM_MODE';
41
+ export const MIDSCENE_PLANNING_MODEL_STREAM_MODE =
42
+ 'MIDSCENE_PLANNING_MODEL_STREAM_MODE';
43
+ export const MIDSCENE_INSIGHT_MODEL_STREAM_MODE =
44
+ 'MIDSCENE_INSIGHT_MODEL_STREAM_MODE';
39
45
  export const MIDSCENE_MODEL_STREAM_MODE = 'MIDSCENE_MODEL_STREAM_MODE';
40
46
  export const MIDSCENE_MODEL_RESPONSE_FORMAT = 'MIDSCENE_MODEL_RESPONSE_FORMAT';
41
47
 
@@ -99,7 +105,7 @@ export const MIDSCENE_REPLANNING_CYCLE_LIMIT =
99
105
  export const MIDSCENE_RUN_DIR = 'MIDSCENE_RUN_DIR';
100
106
  export const MIDSCENE_RECORD_MODEL_CALL = 'MIDSCENE_RECORD_MODEL_CALL';
101
107
 
102
- // INSIGHT (unified VQA and Grounding)
108
+ // INSIGHT (visual understanding and extraction)
103
109
  export const MIDSCENE_INSIGHT_MODEL_NAME = 'MIDSCENE_INSIGHT_MODEL_NAME';
104
110
  export const MIDSCENE_INSIGHT_MODEL_SOCKS_PROXY =
105
111
  'MIDSCENE_INSIGHT_MODEL_SOCKS_PROXY';
@@ -131,6 +137,36 @@ export const MIDSCENE_INSIGHT_MODEL_PROTOCOL =
131
137
  export const MIDSCENE_INSIGHT_MODEL_RESPONSE_FORMAT =
132
138
  'MIDSCENE_INSIGHT_MODEL_RESPONSE_FORMAT';
133
139
 
140
+ // LOCATE
141
+ export const MIDSCENE_LOCATE_MODEL_NAME = 'MIDSCENE_LOCATE_MODEL_NAME';
142
+ export const MIDSCENE_LOCATE_MODEL_SOCKS_PROXY =
143
+ 'MIDSCENE_LOCATE_MODEL_SOCKS_PROXY';
144
+ export const MIDSCENE_LOCATE_MODEL_HTTP_PROXY =
145
+ 'MIDSCENE_LOCATE_MODEL_HTTP_PROXY';
146
+ export const MIDSCENE_LOCATE_MODEL_BASE_URL = 'MIDSCENE_LOCATE_MODEL_BASE_URL';
147
+ export const MIDSCENE_LOCATE_MODEL_API_KEY = 'MIDSCENE_LOCATE_MODEL_API_KEY';
148
+ export const MIDSCENE_LOCATE_MODEL_INIT_CONFIG_JSON =
149
+ 'MIDSCENE_LOCATE_MODEL_INIT_CONFIG_JSON';
150
+ export const MIDSCENE_LOCATE_MODEL_EXTRA_BODY_JSON =
151
+ 'MIDSCENE_LOCATE_MODEL_EXTRA_BODY_JSON';
152
+ export const MIDSCENE_LOCATE_MODEL_TIMEOUT = 'MIDSCENE_LOCATE_MODEL_TIMEOUT';
153
+ export const MIDSCENE_LOCATE_MODEL_TEMPERATURE =
154
+ 'MIDSCENE_LOCATE_MODEL_TEMPERATURE';
155
+ export const MIDSCENE_LOCATE_MODEL_RETRY_COUNT =
156
+ 'MIDSCENE_LOCATE_MODEL_RETRY_COUNT';
157
+ export const MIDSCENE_LOCATE_MODEL_RETRY_INTERVAL =
158
+ 'MIDSCENE_LOCATE_MODEL_RETRY_INTERVAL';
159
+ export const MIDSCENE_LOCATE_MODEL_FAMILY = 'MIDSCENE_LOCATE_MODEL_FAMILY';
160
+ export const MIDSCENE_LOCATE_MODEL_REASONING_EFFORT =
161
+ 'MIDSCENE_LOCATE_MODEL_REASONING_EFFORT';
162
+ export const MIDSCENE_LOCATE_MODEL_REASONING_ENABLED =
163
+ 'MIDSCENE_LOCATE_MODEL_REASONING_ENABLED';
164
+ export const MIDSCENE_LOCATE_MODEL_REASONING_BUDGET =
165
+ 'MIDSCENE_LOCATE_MODEL_REASONING_BUDGET';
166
+ export const MIDSCENE_LOCATE_MODEL_PROTOCOL = 'MIDSCENE_LOCATE_MODEL_PROTOCOL';
167
+ export const MIDSCENE_LOCATE_MODEL_RESPONSE_FORMAT =
168
+ 'MIDSCENE_LOCATE_MODEL_RESPONSE_FORMAT';
169
+
134
170
  // PLANNING
135
171
  export const MIDSCENE_PLANNING_MODEL_NAME = 'MIDSCENE_PLANNING_MODEL_NAME';
136
172
  export const MIDSCENE_PLANNING_MODEL_SOCKS_PROXY =
@@ -196,7 +232,6 @@ export const NUMBER_ENV_KEYS = [
196
232
  ] as const;
197
233
 
198
234
  export const STRING_ENV_KEYS = [
199
- MIDSCENE_MODEL_STREAM_MODE,
200
235
  MIDSCENE_ADB_PATH,
201
236
  MIDSCENE_ADB_REMOTE_HOST,
202
237
  MIDSCENE_ADB_REMOTE_PORT,
@@ -229,6 +264,10 @@ export const GLOBAL_ENV_KEYS = [
229
264
  * Can only be access after agent.constructor
230
265
  */
231
266
  export const MODEL_ENV_KEYS = [
267
+ MIDSCENE_INSIGHT_MODEL_STREAM_MODE,
268
+ MIDSCENE_PLANNING_MODEL_STREAM_MODE,
269
+ MIDSCENE_LOCATE_MODEL_STREAM_MODE,
270
+ MIDSCENE_MODEL_STREAM_MODE,
232
271
  // model default
233
272
  MIDSCENE_MODEL_NAME,
234
273
  MIDSCENE_MODEL_INIT_CONFIG_JSON,
@@ -258,7 +297,7 @@ export const MODEL_ENV_KEYS = [
258
297
  MIDSCENE_OPENAI_INIT_CONFIG_JSON,
259
298
  MIDSCENE_OPENAI_HTTP_PROXY,
260
299
  MIDSCENE_OPENAI_SOCKS_PROXY,
261
- // INSIGHT (unified VQA and Grounding)
300
+ // INSIGHT (visual understanding and extraction)
262
301
  MIDSCENE_INSIGHT_MODEL_NAME,
263
302
  MIDSCENE_INSIGHT_MODEL_SOCKS_PROXY,
264
303
  MIDSCENE_INSIGHT_MODEL_HTTP_PROXY,
@@ -276,6 +315,24 @@ export const MODEL_ENV_KEYS = [
276
315
  MIDSCENE_INSIGHT_MODEL_REASONING_BUDGET,
277
316
  MIDSCENE_INSIGHT_MODEL_PROTOCOL,
278
317
  MIDSCENE_INSIGHT_MODEL_RESPONSE_FORMAT,
318
+ // LOCATE
319
+ MIDSCENE_LOCATE_MODEL_NAME,
320
+ MIDSCENE_LOCATE_MODEL_SOCKS_PROXY,
321
+ MIDSCENE_LOCATE_MODEL_HTTP_PROXY,
322
+ MIDSCENE_LOCATE_MODEL_BASE_URL,
323
+ MIDSCENE_LOCATE_MODEL_API_KEY,
324
+ MIDSCENE_LOCATE_MODEL_INIT_CONFIG_JSON,
325
+ MIDSCENE_LOCATE_MODEL_EXTRA_BODY_JSON,
326
+ MIDSCENE_LOCATE_MODEL_TIMEOUT,
327
+ MIDSCENE_LOCATE_MODEL_TEMPERATURE,
328
+ MIDSCENE_LOCATE_MODEL_RETRY_COUNT,
329
+ MIDSCENE_LOCATE_MODEL_RETRY_INTERVAL,
330
+ MIDSCENE_LOCATE_MODEL_FAMILY,
331
+ MIDSCENE_LOCATE_MODEL_REASONING_EFFORT,
332
+ MIDSCENE_LOCATE_MODEL_REASONING_ENABLED,
333
+ MIDSCENE_LOCATE_MODEL_REASONING_BUDGET,
334
+ MIDSCENE_LOCATE_MODEL_PROTOCOL,
335
+ MIDSCENE_LOCATE_MODEL_RESPONSE_FORMAT,
279
336
  // PLANNING
280
337
  MIDSCENE_PLANNING_MODEL_NAME,
281
338
  MIDSCENE_PLANNING_MODEL_SOCKS_PROXY,
@@ -311,6 +368,7 @@ export type TGlobalConfig = Record<TEnvKeys, string | undefined>;
311
368
  * valid Model family types
312
369
  */
313
370
  export type TModelFamily =
371
+ | 'jev'
314
372
  | 'qwen2.5-vl'
315
373
  | 'qwen3-vl'
316
374
  | 'qwen3'
@@ -333,6 +391,7 @@ export type TModelFamily =
333
391
  | 'xiaomi-mimo';
334
392
 
335
393
  export const MODEL_FAMILY_VALUES: TModelFamily[] = [
394
+ 'jev',
336
395
  'doubao-vision',
337
396
  'doubao-seed',
338
397
  'gemini',
@@ -355,6 +414,8 @@ export const MODEL_FAMILY_VALUES: TModelFamily[] = [
355
414
  'xiaomi-mimo',
356
415
  ];
357
416
 
417
+ export type TModelStreamMode = 'stream' | 'non-stream';
418
+
358
419
  export interface IModelConfigForInsight {
359
420
  // model name
360
421
  [MIDSCENE_INSIGHT_MODEL_NAME]: string;
@@ -367,6 +428,7 @@ export interface IModelConfigForInsight {
367
428
  [MIDSCENE_INSIGHT_MODEL_INIT_CONFIG_JSON]?: string;
368
429
  [MIDSCENE_INSIGHT_MODEL_EXTRA_BODY_JSON]?: string;
369
430
  [MIDSCENE_INSIGHT_MODEL_PROTOCOL]?: TModelProtocol;
431
+ [MIDSCENE_INSIGHT_MODEL_STREAM_MODE]?: TModelStreamMode;
370
432
  // timeout
371
433
  [MIDSCENE_INSIGHT_MODEL_TIMEOUT]?: string;
372
434
  // temperature
@@ -375,6 +437,27 @@ export interface IModelConfigForInsight {
375
437
  [MIDSCENE_INSIGHT_MODEL_FAMILY]?: TModelFamily;
376
438
  }
377
439
 
440
+ export interface IModelConfigForLocate {
441
+ // model name
442
+ [MIDSCENE_LOCATE_MODEL_NAME]: string;
443
+ // proxy
444
+ [MIDSCENE_LOCATE_MODEL_SOCKS_PROXY]?: string;
445
+ [MIDSCENE_LOCATE_MODEL_HTTP_PROXY]?: string;
446
+ // OpenAI
447
+ [MIDSCENE_LOCATE_MODEL_BASE_URL]?: string;
448
+ [MIDSCENE_LOCATE_MODEL_API_KEY]?: string;
449
+ [MIDSCENE_LOCATE_MODEL_INIT_CONFIG_JSON]?: string;
450
+ [MIDSCENE_LOCATE_MODEL_EXTRA_BODY_JSON]?: string;
451
+ [MIDSCENE_LOCATE_MODEL_PROTOCOL]?: TModelProtocol;
452
+ [MIDSCENE_LOCATE_MODEL_STREAM_MODE]?: TModelStreamMode;
453
+ // timeout
454
+ [MIDSCENE_LOCATE_MODEL_TIMEOUT]?: string;
455
+ // temperature
456
+ [MIDSCENE_LOCATE_MODEL_TEMPERATURE]?: string;
457
+ // model family
458
+ [MIDSCENE_LOCATE_MODEL_FAMILY]?: TModelFamily;
459
+ }
460
+
378
461
  export interface IModelConfigForPlanning {
379
462
  // model name
380
463
  [MIDSCENE_PLANNING_MODEL_NAME]: string;
@@ -387,6 +470,7 @@ export interface IModelConfigForPlanning {
387
470
  [MIDSCENE_PLANNING_MODEL_INIT_CONFIG_JSON]?: string;
388
471
  [MIDSCENE_PLANNING_MODEL_EXTRA_BODY_JSON]?: string;
389
472
  [MIDSCENE_PLANNING_MODEL_PROTOCOL]?: TModelProtocol;
473
+ [MIDSCENE_PLANNING_MODEL_STREAM_MODE]?: TModelStreamMode;
390
474
  // timeout
391
475
  [MIDSCENE_PLANNING_MODEL_TIMEOUT]?: string;
392
476
  // temperature
@@ -415,6 +499,7 @@ export interface IModelConfigForDefault {
415
499
  [MIDSCENE_MODEL_INIT_CONFIG_JSON]?: string;
416
500
  [MIDSCENE_MODEL_EXTRA_BODY_JSON]?: string;
417
501
  [MIDSCENE_MODEL_PROTOCOL]?: TModelProtocol;
502
+ [MIDSCENE_MODEL_STREAM_MODE]?: TModelStreamMode;
418
503
  // extra
419
504
  [MIDSCENE_MODEL_FAMILY]?: TModelFamily;
420
505
  // temperature
@@ -442,11 +527,12 @@ export interface IModelConfigForDefaultLegacy {
442
527
  }
443
528
 
444
529
  /**
445
- * - insight: Visual Question Answering and Visual Grounding (unified)
530
+ * - locate: visual element localization
531
+ * - insight: visual understanding and extraction
446
532
  * - planning: planning
447
- * - default: all except insight、planning
533
+ * - default: base configuration for all capabilities
448
534
  */
449
- export type TIntent = 'insight' | 'planning' | 'default';
535
+ export type TIntent = 'insight' | 'planning' | 'locate' | 'default';
450
536
 
451
537
  /**
452
538
  * Env-style model configuration map supplied directly to the agent.
@@ -528,6 +614,7 @@ export interface IModelConfig {
528
614
  * Temperature for model sampling.
529
615
  */
530
616
  temperature?: number;
617
+ streamMode?: TModelStreamMode;
531
618
  /**
532
619
  * Number of retries when AI call fails.
533
620
  * Default is 1 (retry once after failure).
package/src/img/index.ts CHANGED
@@ -17,6 +17,7 @@ export {
17
17
  zoomForGPT4o,
18
18
  saveBase64Image,
19
19
  paddingToMatchBlockByBase64,
20
+ padBase64ImageToMinimumSize,
20
21
  cropByRect,
21
22
  scaleImage,
22
23
  localImg2Base64,
@@ -949,3 +949,70 @@ export async function scaleImage(
949
949
  imageBase64: base64,
950
950
  };
951
951
  }
952
+
953
+ /** Pad the right and bottom edges with white without changing content coordinates. */
954
+ export async function padBase64ImageToMinimumSize(
955
+ imageBase64: string,
956
+ minimum: number,
957
+ ) {
958
+ assert(
959
+ Number.isInteger(minimum) && minimum > 0,
960
+ 'minimum must be a positive integer',
961
+ );
962
+ const { body } = parseBase64(imageBase64);
963
+ const buffer = Buffer.from(body, 'base64');
964
+ const size = encodedImageInfoOfBuffer(buffer);
965
+ const width = Math.max(minimum, size.width);
966
+ const height = Math.max(minimum, size.height);
967
+ if (width === size.width && height === size.height) {
968
+ return { imageBase64, width, height };
969
+ }
970
+ if (ifInNode) {
971
+ const Sharp = await getSharp();
972
+ const padded = await Sharp(buffer)
973
+ .extend({
974
+ right: width - size.width,
975
+ bottom: height - size.height,
976
+ background: { r: 255, g: 255, b: 255, alpha: 1 },
977
+ })
978
+ .jpeg({ quality: 90 })
979
+ .toBuffer();
980
+ return {
981
+ imageBase64: createImgBase64ByFormat('jpeg', padded.toString('base64')),
982
+ width,
983
+ height,
984
+ };
985
+ }
986
+ const { padding_right, padding_bottom, Rgba } = await getPhoton();
987
+ const original = await photonFromBase64(imageBase64);
988
+ const right =
989
+ width > size.width
990
+ ? padding_right(
991
+ original,
992
+ width - size.width,
993
+ new Rgba(255, 255, 255, 255),
994
+ )
995
+ : original;
996
+ try {
997
+ const bottom =
998
+ height > size.height
999
+ ? padding_bottom(
1000
+ right,
1001
+ height - size.height,
1002
+ new Rgba(255, 255, 255, 255),
1003
+ )
1004
+ : right;
1005
+ try {
1006
+ return { imageBase64: await photonToBase64(bottom), width, height };
1007
+ } finally {
1008
+ if (bottom !== right) {
1009
+ bottom.free();
1010
+ }
1011
+ }
1012
+ } finally {
1013
+ if (right !== original) {
1014
+ right.free();
1015
+ }
1016
+ original.free();
1017
+ }
1018
+ }