@midscene/core 0.8.4 → 0.8.5-beta-20241126063126.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/lib/ai-model.js +147 -92
- package/dist/lib/env.js +102 -0
- package/dist/lib/index.js +904 -843
- package/dist/lib/types/ai-model.d.ts +7 -3
- package/dist/lib/types/env.d.ts +48 -0
- package/dist/lib/types/{index-690c2a06.d.ts → index-41db6188.d.ts} +3 -36
- package/dist/lib/types/index.d.ts +6 -5
- package/dist/lib/types/{types-29994b1b.d.ts → types-0d8eeece.d.ts} +3 -1
- package/dist/lib/types/utils.d.ts +3 -3
- package/dist/lib/utils.js +15 -30
- package/package.json +6 -2
- package/report/index.html +2 -2
package/dist/lib/ai-model.js
CHANGED
|
@@ -4293,7 +4293,49 @@ module.exports = __toCommonJS(ai_model_exports);
|
|
|
4293
4293
|
// src/ai-model/openai/index.ts
|
|
4294
4294
|
var import_node_assert3 = __toESM(require("assert"));
|
|
4295
4295
|
var import_utils = require("@midscene/shared/utils");
|
|
4296
|
-
var
|
|
4296
|
+
var import_openai2 = __toESM(require("openai"));
|
|
4297
|
+
|
|
4298
|
+
// src/env.ts
|
|
4299
|
+
var MIDSCENE_OPENAI_INIT_CONFIG_JSON = "MIDSCENE_OPENAI_INIT_CONFIG_JSON";
|
|
4300
|
+
var MIDSCENE_MODEL_NAME = "MIDSCENE_MODEL_NAME";
|
|
4301
|
+
var MIDSCENE_LANGSMITH_DEBUG = "MIDSCENE_LANGSMITH_DEBUG";
|
|
4302
|
+
var MIDSCENE_DEBUG_AI_PROFILE = "MIDSCENE_DEBUG_AI_PROFILE";
|
|
4303
|
+
var MIDSCENE_DANGEROUSLY_PRINT_ALL_CONFIG = "MIDSCENE_DANGEROUSLY_PRINT_ALL_CONFIG";
|
|
4304
|
+
var MIDSCENE_DEBUG_MODE = "MIDSCENE_DEBUG_MODE";
|
|
4305
|
+
var OPENAI_API_KEY = "OPENAI_API_KEY";
|
|
4306
|
+
var OPENAI_BASE_URL = "OPENAI_BASE_URL";
|
|
4307
|
+
var MIDSCENE_MODEL_TEXT_ONLY = "MIDSCENE_MODEL_TEXT_ONLY";
|
|
4308
|
+
var OPENAI_USE_AZURE = "OPENAI_USE_AZURE";
|
|
4309
|
+
var MIDSCENE_CACHE = "MIDSCENE_CACHE";
|
|
4310
|
+
var MATCH_BY_POSITION = "MATCH_BY_POSITION";
|
|
4311
|
+
var MIDSCENE_REPORT_TAG_NAME = "MIDSCENE_REPORT_TAG_NAME";
|
|
4312
|
+
var allConfigFromEnv = () => {
|
|
4313
|
+
return {
|
|
4314
|
+
[MIDSCENE_OPENAI_INIT_CONFIG_JSON]: process.env[MIDSCENE_OPENAI_INIT_CONFIG_JSON] || void 0,
|
|
4315
|
+
[MIDSCENE_MODEL_NAME]: process.env[MIDSCENE_MODEL_NAME] || void 0,
|
|
4316
|
+
[MIDSCENE_DEBUG_MODE]: process.env[MIDSCENE_DEBUG_MODE] || void 0,
|
|
4317
|
+
[MIDSCENE_LANGSMITH_DEBUG]: process.env[MIDSCENE_LANGSMITH_DEBUG] || void 0,
|
|
4318
|
+
[MIDSCENE_DEBUG_AI_PROFILE]: process.env[MIDSCENE_DEBUG_AI_PROFILE] || void 0,
|
|
4319
|
+
[MIDSCENE_DANGEROUSLY_PRINT_ALL_CONFIG]: process.env[MIDSCENE_DANGEROUSLY_PRINT_ALL_CONFIG] || void 0,
|
|
4320
|
+
[OPENAI_API_KEY]: process.env[OPENAI_API_KEY] || void 0,
|
|
4321
|
+
[OPENAI_BASE_URL]: process.env[OPENAI_BASE_URL] || void 0,
|
|
4322
|
+
[MIDSCENE_MODEL_TEXT_ONLY]: process.env[MIDSCENE_MODEL_TEXT_ONLY] || void 0,
|
|
4323
|
+
[OPENAI_USE_AZURE]: process.env[OPENAI_USE_AZURE] || void 0,
|
|
4324
|
+
[MIDSCENE_CACHE]: process.env[MIDSCENE_CACHE] || void 0,
|
|
4325
|
+
[MATCH_BY_POSITION]: process.env[MATCH_BY_POSITION] || void 0,
|
|
4326
|
+
[MIDSCENE_REPORT_TAG_NAME]: process.env[MIDSCENE_REPORT_TAG_NAME] || void 0
|
|
4327
|
+
};
|
|
4328
|
+
};
|
|
4329
|
+
var userConfig = {};
|
|
4330
|
+
var getAIConfig = (configKey) => {
|
|
4331
|
+
if (typeof userConfig[configKey] !== "undefined") {
|
|
4332
|
+
return userConfig[configKey];
|
|
4333
|
+
}
|
|
4334
|
+
return allConfigFromEnv()[configKey];
|
|
4335
|
+
};
|
|
4336
|
+
var allAIConfig = () => {
|
|
4337
|
+
return { ...allConfigFromEnv(), ...userConfig };
|
|
4338
|
+
};
|
|
4297
4339
|
|
|
4298
4340
|
// src/ai-model/coze/index.ts
|
|
4299
4341
|
var import_node_assert = __toESM(require("assert"));
|
|
@@ -4497,7 +4539,7 @@ Input Example:
|
|
|
4497
4539
|
},
|
|
4498
4540
|
"elementInfos": [
|
|
4499
4541
|
{
|
|
4500
|
-
"id": "
|
|
4542
|
+
"id": "1231", // ID of the element
|
|
4501
4543
|
"indexId": "0", // Index of the element,The image is labeled to the left of the element
|
|
4502
4544
|
"attributes": { // Attributes of the element
|
|
4503
4545
|
"nodeType": "IMG Node", // Type of element, types include: TEXT Node, IMG Node, BUTTON Node, INPUT Node
|
|
@@ -4513,7 +4555,7 @@ Input Example:
|
|
|
4513
4555
|
}
|
|
4514
4556
|
},
|
|
4515
4557
|
{
|
|
4516
|
-
"id": "
|
|
4558
|
+
"id": "66551", // ID of the element
|
|
4517
4559
|
"indexId": "1", // Index of the element,The image is labeled to the left of the element
|
|
4518
4560
|
"attributes": { // Attributes of the element
|
|
4519
4561
|
"nodeType": "IMG Node", // Type of element, types include: TEXT Node, IMG Node, BUTTON Node, INPUT Node
|
|
@@ -4530,7 +4572,7 @@ Input Example:
|
|
|
4530
4572
|
},
|
|
4531
4573
|
...
|
|
4532
4574
|
{
|
|
4533
|
-
"id": "
|
|
4575
|
+
"id": "12344",
|
|
4534
4576
|
"indexId": "2", // Index of the element,The image is labeled to the left of the element
|
|
4535
4577
|
"attributes": {
|
|
4536
4578
|
"nodeType": "TEXT Node",
|
|
@@ -4563,7 +4605,7 @@ Output Example:
|
|
|
4563
4605
|
"reason": "Reason for finding element 4: It is located in the upper right corner, is an image type, and according to the screenshot, it is a shopping cart icon button",
|
|
4564
4606
|
"text": "",
|
|
4565
4607
|
// ID(**use id not indexId**) of this element, replace with actual value in practice, **use id not indexId**
|
|
4566
|
-
"id": "
|
|
4608
|
+
"id": "1231"
|
|
4567
4609
|
}
|
|
4568
4610
|
],
|
|
4569
4611
|
"errors": []
|
|
@@ -4650,6 +4692,19 @@ var findElementSchema = {
|
|
|
4650
4692
|
};
|
|
4651
4693
|
|
|
4652
4694
|
// src/ai-model/prompt/planning.ts
|
|
4695
|
+
var quickAnswerFormat = () => {
|
|
4696
|
+
const matchByPosition = getAIConfig(MATCH_BY_POSITION);
|
|
4697
|
+
const description = `
|
|
4698
|
+
${matchByPosition ? `"position": { x: number; y: number } // Represents the position of the element; replace with actual values in practice (ensure it reflects the element's position)` : '"id": string // Represents the ID of the element; replace with actual values in practice'}
|
|
4699
|
+
`;
|
|
4700
|
+
const format = matchByPosition ? '"position": { x: number; y: number }' : '"id": string';
|
|
4701
|
+
const sample = matchByPosition ? '{"position": { x: 100, y: 200 }}' : '{"id": "14562"}';
|
|
4702
|
+
return {
|
|
4703
|
+
description,
|
|
4704
|
+
format,
|
|
4705
|
+
sample
|
|
4706
|
+
};
|
|
4707
|
+
};
|
|
4653
4708
|
function systemPromptToTaskPlanning() {
|
|
4654
4709
|
return `
|
|
4655
4710
|
## Role:
|
|
@@ -4673,32 +4728,24 @@ Each action has a type and corresponding param. To be detailed:
|
|
|
4673
4728
|
* type: 'KeyboardPress', press a key
|
|
4674
4729
|
* param: { value: string }, the value to input or the key to press. Use (Enter, Shift, Control, Alt, Meta, ShiftLeft, ControlOrMeta, ControlOrMeta) to represent the key.
|
|
4675
4730
|
* type: 'Scroll'
|
|
4676
|
-
* param: { scrollType: 'scrollDownOneScreen'
|
|
4731
|
+
* param: { scrollType: 'scrollDownOneScreen' | 'scrollUpOneScreen' | 'scrollUntilBottom' | 'scrollUntilTop' }
|
|
4677
4732
|
* type: 'Error'
|
|
4678
4733
|
* param: { message: string }, the error message
|
|
4679
4734
|
* type: 'Sleep'
|
|
4680
4735
|
* param: { timeMs: number }, wait for timeMs milliseconds
|
|
4681
4736
|
|
|
4682
|
-
Here is an example of how to decompose a task.
|
|
4683
|
-
When a user says 'Input "Weather in Shanghai" into the search bar, wait 1 second, hit enter', by viewing the page screenshot and description, you may decompose this task into something like this:
|
|
4684
|
-
* Locate: 'The search bar'
|
|
4685
|
-
* Input: 'Weather in Shanghai'
|
|
4686
|
-
* Sleep: 1000
|
|
4687
|
-
* KeyboardPress: 'Enter'
|
|
4688
|
-
|
|
4689
4737
|
Remember:
|
|
4690
4738
|
1. The actions you composed MUST be based on the page context information you get. Instead of making up actions that are not related to the page context.
|
|
4691
|
-
2. In most cases, you should Locate one element first, then do other actions on it. For example,
|
|
4692
|
-
|
|
4693
|
-
If the planned tasks are sequential and tasks may appear only after the execution of previous tasks, this is considered normal. Thoughts, prompts, and error messages should all be in the same language as the user query.
|
|
4739
|
+
2. In most cases, you should Locate one element first, then do other actions on it. For example, Locate one element, then hover on it. But if you think it's necessary to do other actions first (like global scroll, global key press), you can do that.
|
|
4740
|
+
3. If the planned actions are sequential and some actions may appear only after the execution of previous actions, this is considered normal. Thoughts, prompts, and error messages should all be in the same language as the user's description.
|
|
4694
4741
|
|
|
4695
|
-
## Objective 2 (sub objective, only for action with type "Locate"): Give a quick answer to the action with type "Locate" you just planned, append a \`quickAnswer\` field
|
|
4742
|
+
## Objective 2 (sub objective, only for action with type "Locate"): Give a quick answer to the action with type "Locate" you just planned, append a \`quickAnswer\` field as a sibling of the \`param\` field
|
|
4696
4743
|
|
|
4697
|
-
If the action type is 'Locate',
|
|
4744
|
+
If the action type is 'Locate', think about this: does any element on screen meet the description in the prompt? If so, answer with the following format, as the \`quickAnswer\` field in the output JSON:
|
|
4698
4745
|
{
|
|
4699
|
-
"reason": "
|
|
4746
|
+
"reason": "It is located (somewhere), is an (node type). According to the screenshot, it is a shopping cart icon button (or it's text is 'Shopping Cart')",
|
|
4700
4747
|
"text": "PLACEHOLDER", // Replace PLACEHOLDER with the text of elementInfo, if none, leave empty
|
|
4701
|
-
${
|
|
4748
|
+
${quickAnswerFormat().description}
|
|
4702
4749
|
}
|
|
4703
4750
|
|
|
4704
4751
|
If there is no element meets the description in the prompt (usually because it will show up later after some interaction), the \`quickAnswer\` field should be null.
|
|
@@ -4711,33 +4758,71 @@ Please return the result in JSON format as follows:
|
|
|
4711
4758
|
actions: [ // always return in Array
|
|
4712
4759
|
{
|
|
4713
4760
|
"thought": "find out the search bar",
|
|
4714
|
-
"type": "Locate", //
|
|
4715
|
-
"param": {
|
|
4761
|
+
"type": "Locate", // type of action according to Object 1, like 'Tap' 'Hover' ...
|
|
4762
|
+
"param": { //
|
|
4716
4763
|
"prompt": "The search bar"
|
|
4717
4764
|
},
|
|
4718
|
-
"quickAnswer": {
|
|
4719
|
-
"reason": "
|
|
4720
|
-
"text":
|
|
4721
|
-
${
|
|
4765
|
+
"quickAnswer": {
|
|
4766
|
+
"reason": "This is ...",
|
|
4767
|
+
"text": string, // Replace PLACEHOLDER with the text of elementInfo, if none, leave empty
|
|
4768
|
+
${quickAnswerFormat().format}
|
|
4722
4769
|
} | null,
|
|
4723
4770
|
},
|
|
4724
4771
|
{
|
|
4725
4772
|
"thought": "Reasons for generating this task, and why this task is feasible on this page",
|
|
4726
|
-
"type": "Tap",
|
|
4727
|
-
"param":
|
|
4773
|
+
"type": "Tap",
|
|
4774
|
+
"param": null,
|
|
4728
4775
|
},
|
|
4776
|
+
// ... more actions
|
|
4777
|
+
],
|
|
4778
|
+
error?: string, // Overall error messages. If there is any error occurs during the task planning (i.e. error in previous 'actions' array), conclude the errors again, put error messages here,
|
|
4779
|
+
}
|
|
4780
|
+
|
|
4781
|
+
## Here is an example of how to decompose a task
|
|
4782
|
+
|
|
4783
|
+
When a user says 'Click the language switch button, wait 1s, click "English"', by viewing the page screenshot and description, you should consider this:
|
|
4784
|
+
|
|
4785
|
+
* The main steps are: Find the switch button, tap it, sleep, find the 'English' element, and tap on it.
|
|
4786
|
+
* Think and look in detail and fill all the fields in the JSON format.
|
|
4787
|
+
|
|
4788
|
+
\`\`\`json
|
|
4789
|
+
{
|
|
4790
|
+
queryLanguage: 'English',
|
|
4791
|
+
actions:[
|
|
4729
4792
|
{
|
|
4730
|
-
|
|
4731
|
-
|
|
4732
|
-
|
|
4733
|
-
|
|
4793
|
+
thought: "Locate the language switch button with the text '中文'.",
|
|
4794
|
+
type: 'Locate',
|
|
4795
|
+
param: { prompt: "The language switch button with the text '中文'" },
|
|
4796
|
+
quickAnswer: { // according to Objective 2, this action type is 'Locate', and we can find the element, so we need to give a quick answer
|
|
4797
|
+
reason: "It is located near the top center, is an text node. According to the screenshot, it is a language switch button with the text '中文'.",
|
|
4798
|
+
text: '中文',
|
|
4799
|
+
${quickAnswerFormat().sample}
|
|
4734
4800
|
},
|
|
4735
|
-
"quickAnswer": null,
|
|
4736
4801
|
},
|
|
4737
|
-
|
|
4802
|
+
{
|
|
4803
|
+
thought: 'Click the language switch button to open the language options.',
|
|
4804
|
+
type: 'Tap',
|
|
4805
|
+
param: null,
|
|
4806
|
+
},
|
|
4807
|
+
{
|
|
4808
|
+
thought: 'Wait for 1 second to ensure the language options are displayed.',
|
|
4809
|
+
type: 'Sleep',
|
|
4810
|
+
param: { timeMs: 1000 },
|
|
4811
|
+
},
|
|
4812
|
+
{
|
|
4813
|
+
thought: "Locate the 'English' option in the language menu.",
|
|
4814
|
+
type: 'Locate',
|
|
4815
|
+
param: { prompt: "The 'English' option in the language menu" },
|
|
4816
|
+
quickAnswer: null, // we cannot find this item in the description (it will show only after the previous interactions), so the quick answer is null here
|
|
4817
|
+
},
|
|
4818
|
+
{
|
|
4819
|
+
thought: "Click the 'English' option to switch the language.",
|
|
4820
|
+
type: 'Tap',
|
|
4821
|
+
param: null,
|
|
4822
|
+
}
|
|
4738
4823
|
],
|
|
4739
|
-
error?: string, // Overall error messages. If there is any error occurs during the task planning (i.e. error in previous 'actions' array), conclude the errors again, put error messages here,
|
|
4740
4824
|
}
|
|
4825
|
+
\`\`\`
|
|
4741
4826
|
`;
|
|
4742
4827
|
}
|
|
4743
4828
|
var planSchema = {
|
|
@@ -4775,7 +4860,7 @@ var planSchema = {
|
|
|
4775
4860
|
properties: {
|
|
4776
4861
|
reason: {
|
|
4777
4862
|
type: "string",
|
|
4778
|
-
description: "Reason for finding element
|
|
4863
|
+
description: "Reason for finding this element"
|
|
4779
4864
|
},
|
|
4780
4865
|
text: {
|
|
4781
4866
|
type: "string",
|
|
@@ -4833,8 +4918,6 @@ skill content:
|
|
|
4833
4918
|
|
|
4834
4919
|
Return in this way: prefix + the id / comma-separated ids, for example: LOCATE_ONE_ELEMENT/1 , LOCATE_ONE_OR_MORE_ELEMENTS/1,2,3 . If not found, keep the prefix and leave the suffix empty, like LOCATE_ONE_ELEMENT/ .
|
|
4835
4920
|
|
|
4836
|
-
|
|
4837
|
-
|
|
4838
4921
|
Return in the following JSON format:
|
|
4839
4922
|
{
|
|
4840
4923
|
language: "en", // "en" or "zh", the language of the page. Use the same language to describe section name, description, and similar fields.
|
|
@@ -4882,8 +4965,7 @@ var assertSchema = {
|
|
|
4882
4965
|
function describeSize(size) {
|
|
4883
4966
|
return `${size.width} x ${size.height}`;
|
|
4884
4967
|
}
|
|
4885
|
-
function truncateText(text) {
|
|
4886
|
-
const maxLength = 50;
|
|
4968
|
+
function truncateText(text, maxLength = 20) {
|
|
4887
4969
|
if (text && text.length > maxLength) {
|
|
4888
4970
|
return `${text.slice(0, maxLength)}...`;
|
|
4889
4971
|
}
|
|
@@ -4915,16 +4997,15 @@ async function describeUserPage(context) {
|
|
|
4915
4997
|
const elementInfosDescription = cropFieldInformation(elementsInfo);
|
|
4916
4998
|
return {
|
|
4917
4999
|
description: `
|
|
4918
|
-
|
|
4919
|
-
|
|
4920
|
-
|
|
5000
|
+
{
|
|
5001
|
+
// The size of the page
|
|
5002
|
+
"pageSize": ${describeSize({ width, height })},
|
|
4921
5003
|
|
|
4922
|
-
|
|
4923
|
-
|
|
4924
|
-
|
|
4925
|
-
|
|
4926
|
-
|
|
4927
|
-
}`,
|
|
5004
|
+
${// if match by id, use the description of the element
|
|
5005
|
+
getAIConfig(MATCH_BY_POSITION) ? "" : `// json description of the element
|
|
5006
|
+
"content": ${JSON.stringify(elementInfosDescription)}
|
|
5007
|
+
`}
|
|
5008
|
+
}`,
|
|
4928
5009
|
elementById(id) {
|
|
4929
5010
|
(0, import_node_assert2.default)(typeof id !== "undefined", "id is required for query");
|
|
4930
5011
|
const item = idElementMap[`${id}`];
|
|
@@ -4943,7 +5024,13 @@ function cropFieldInformation(elementsInfo) {
|
|
|
4943
5024
|
const tailorAttributes = Object.keys(attributes).reduce(
|
|
4944
5025
|
(res, currentKey) => {
|
|
4945
5026
|
const attributeVal = attributes[currentKey];
|
|
4946
|
-
|
|
5027
|
+
if (currentKey === "style" || currentKey === "src")
|
|
5028
|
+
return res;
|
|
5029
|
+
if (currentKey === "nodeType") {
|
|
5030
|
+
res[currentKey] = attributeVal.replace(/\sNode$/, "");
|
|
5031
|
+
} else {
|
|
5032
|
+
res[currentKey] = truncateText(attributeVal);
|
|
5033
|
+
}
|
|
4947
5034
|
return res;
|
|
4948
5035
|
},
|
|
4949
5036
|
{}
|
|
@@ -4952,53 +5039,21 @@ function cropFieldInformation(elementsInfo) {
|
|
|
4952
5039
|
id,
|
|
4953
5040
|
markerId: item.indexId,
|
|
4954
5041
|
attributes: tailorAttributes,
|
|
4955
|
-
rect
|
|
5042
|
+
rect: {
|
|
5043
|
+
left: rect.left,
|
|
5044
|
+
top: rect.top,
|
|
5045
|
+
width: rect.width,
|
|
5046
|
+
height: rect.height
|
|
5047
|
+
// remove 'zoom' if it exists
|
|
5048
|
+
},
|
|
4956
5049
|
content: tailorContent
|
|
4957
5050
|
};
|
|
4958
5051
|
}
|
|
4959
5052
|
);
|
|
4960
|
-
return
|
|
5053
|
+
return elementInfosDescription;
|
|
4961
5054
|
}
|
|
4962
5055
|
|
|
4963
5056
|
// src/ai-model/openai/index.ts
|
|
4964
|
-
var MIDSCENE_OPENAI_INIT_CONFIG_JSON = "MIDSCENE_OPENAI_INIT_CONFIG_JSON";
|
|
4965
|
-
var MIDSCENE_MODEL_NAME = "MIDSCENE_MODEL_NAME";
|
|
4966
|
-
var MIDSCENE_LANGSMITH_DEBUG = "MIDSCENE_LANGSMITH_DEBUG";
|
|
4967
|
-
var MIDSCENE_DEBUG_AI_PROFILE = "MIDSCENE_DEBUG_AI_PROFILE";
|
|
4968
|
-
var MIDSCENE_DANGEROUSLY_PRINT_ALL_CONFIG = "MIDSCENE_DANGEROUSLY_PRINT_ALL_CONFIG";
|
|
4969
|
-
var MIDSCENE_DEBUG_MODE = "MIDSCENE_DEBUG_MODE";
|
|
4970
|
-
var OPENAI_API_KEY = "OPENAI_API_KEY";
|
|
4971
|
-
var OPENAI_BASE_URL = "OPENAI_BASE_URL";
|
|
4972
|
-
var MIDSCENE_MODEL_TEXT_ONLY = "MIDSCENE_MODEL_TEXT_ONLY";
|
|
4973
|
-
var OPENAI_USE_AZURE = "OPENAI_USE_AZURE";
|
|
4974
|
-
var MIDSCENE_CACHE = "MIDSCENE_CACHE";
|
|
4975
|
-
var MATCH_BY_POSITION = "MATCH_BY_POSITION";
|
|
4976
|
-
var allConfigFromEnv = () => {
|
|
4977
|
-
return {
|
|
4978
|
-
[MIDSCENE_OPENAI_INIT_CONFIG_JSON]: process.env[MIDSCENE_OPENAI_INIT_CONFIG_JSON] || void 0,
|
|
4979
|
-
[MIDSCENE_MODEL_NAME]: process.env[MIDSCENE_MODEL_NAME] || void 0,
|
|
4980
|
-
[MIDSCENE_DEBUG_MODE]: process.env[MIDSCENE_DEBUG_MODE] || void 0,
|
|
4981
|
-
[MIDSCENE_LANGSMITH_DEBUG]: process.env[MIDSCENE_LANGSMITH_DEBUG] || void 0,
|
|
4982
|
-
[MIDSCENE_DEBUG_AI_PROFILE]: process.env[MIDSCENE_DEBUG_AI_PROFILE] || void 0,
|
|
4983
|
-
[MIDSCENE_DANGEROUSLY_PRINT_ALL_CONFIG]: process.env[MIDSCENE_DANGEROUSLY_PRINT_ALL_CONFIG] || void 0,
|
|
4984
|
-
[OPENAI_API_KEY]: process.env[OPENAI_API_KEY] || void 0,
|
|
4985
|
-
[OPENAI_BASE_URL]: process.env[OPENAI_BASE_URL] || void 0,
|
|
4986
|
-
[MIDSCENE_MODEL_TEXT_ONLY]: process.env[MIDSCENE_MODEL_TEXT_ONLY] || void 0,
|
|
4987
|
-
[OPENAI_USE_AZURE]: process.env[OPENAI_USE_AZURE] || void 0,
|
|
4988
|
-
[MIDSCENE_CACHE]: process.env[MIDSCENE_CACHE] || void 0,
|
|
4989
|
-
[MATCH_BY_POSITION]: process.env[MATCH_BY_POSITION] || void 0
|
|
4990
|
-
};
|
|
4991
|
-
};
|
|
4992
|
-
var userConfig = {};
|
|
4993
|
-
var getAIConfig = (configKey) => {
|
|
4994
|
-
if (typeof userConfig[configKey] !== "undefined") {
|
|
4995
|
-
return userConfig[configKey];
|
|
4996
|
-
}
|
|
4997
|
-
return allConfigFromEnv()[configKey];
|
|
4998
|
-
};
|
|
4999
|
-
var allAIConfig = () => {
|
|
5000
|
-
return { ...allConfigFromEnv(), ...userConfig };
|
|
5001
|
-
};
|
|
5002
5057
|
function preferOpenAIModel(preferVendor) {
|
|
5003
5058
|
if (preferVendor && preferVendor !== "openAI")
|
|
5004
5059
|
return false;
|
|
@@ -5020,14 +5075,14 @@ async function createOpenAI() {
|
|
|
5020
5075
|
const extraConfigString = getAIConfig(MIDSCENE_OPENAI_INIT_CONFIG_JSON);
|
|
5021
5076
|
const extraConfig = extraConfigString ? JSON.parse(extraConfigString) : {};
|
|
5022
5077
|
if (getAIConfig(OPENAI_USE_AZURE)) {
|
|
5023
|
-
openai = new
|
|
5078
|
+
openai = new import_openai2.AzureOpenAI({
|
|
5024
5079
|
baseURL: getAIConfig(OPENAI_BASE_URL),
|
|
5025
5080
|
apiKey: getAIConfig(OPENAI_API_KEY),
|
|
5026
5081
|
...extraConfig,
|
|
5027
5082
|
dangerouslyAllowBrowser: true
|
|
5028
5083
|
});
|
|
5029
5084
|
} else {
|
|
5030
|
-
openai = new
|
|
5085
|
+
openai = new import_openai2.default({
|
|
5031
5086
|
baseURL: getAIConfig(OPENAI_BASE_URL),
|
|
5032
5087
|
apiKey: getAIConfig(OPENAI_API_KEY),
|
|
5033
5088
|
...extraConfig,
|
package/dist/lib/env.js
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/env.ts
|
|
21
|
+
var env_exports = {};
|
|
22
|
+
__export(env_exports, {
|
|
23
|
+
MATCH_BY_POSITION: () => MATCH_BY_POSITION,
|
|
24
|
+
MIDSCENE_CACHE: () => MIDSCENE_CACHE,
|
|
25
|
+
MIDSCENE_DANGEROUSLY_PRINT_ALL_CONFIG: () => MIDSCENE_DANGEROUSLY_PRINT_ALL_CONFIG,
|
|
26
|
+
MIDSCENE_DEBUG_AI_PROFILE: () => MIDSCENE_DEBUG_AI_PROFILE,
|
|
27
|
+
MIDSCENE_DEBUG_MODE: () => MIDSCENE_DEBUG_MODE,
|
|
28
|
+
MIDSCENE_LANGSMITH_DEBUG: () => MIDSCENE_LANGSMITH_DEBUG,
|
|
29
|
+
MIDSCENE_MODEL_NAME: () => MIDSCENE_MODEL_NAME,
|
|
30
|
+
MIDSCENE_MODEL_TEXT_ONLY: () => MIDSCENE_MODEL_TEXT_ONLY,
|
|
31
|
+
MIDSCENE_OPENAI_INIT_CONFIG_JSON: () => MIDSCENE_OPENAI_INIT_CONFIG_JSON,
|
|
32
|
+
MIDSCENE_REPORT_TAG_NAME: () => MIDSCENE_REPORT_TAG_NAME,
|
|
33
|
+
OPENAI_API_KEY: () => OPENAI_API_KEY,
|
|
34
|
+
OPENAI_BASE_URL: () => OPENAI_BASE_URL,
|
|
35
|
+
OPENAI_USE_AZURE: () => OPENAI_USE_AZURE,
|
|
36
|
+
allAIConfig: () => allAIConfig,
|
|
37
|
+
getAIConfig: () => getAIConfig,
|
|
38
|
+
overrideAIConfig: () => overrideAIConfig
|
|
39
|
+
});
|
|
40
|
+
module.exports = __toCommonJS(env_exports);
|
|
41
|
+
var MIDSCENE_OPENAI_INIT_CONFIG_JSON = "MIDSCENE_OPENAI_INIT_CONFIG_JSON";
|
|
42
|
+
var MIDSCENE_MODEL_NAME = "MIDSCENE_MODEL_NAME";
|
|
43
|
+
var MIDSCENE_LANGSMITH_DEBUG = "MIDSCENE_LANGSMITH_DEBUG";
|
|
44
|
+
var MIDSCENE_DEBUG_AI_PROFILE = "MIDSCENE_DEBUG_AI_PROFILE";
|
|
45
|
+
var MIDSCENE_DANGEROUSLY_PRINT_ALL_CONFIG = "MIDSCENE_DANGEROUSLY_PRINT_ALL_CONFIG";
|
|
46
|
+
var MIDSCENE_DEBUG_MODE = "MIDSCENE_DEBUG_MODE";
|
|
47
|
+
var OPENAI_API_KEY = "OPENAI_API_KEY";
|
|
48
|
+
var OPENAI_BASE_URL = "OPENAI_BASE_URL";
|
|
49
|
+
var MIDSCENE_MODEL_TEXT_ONLY = "MIDSCENE_MODEL_TEXT_ONLY";
|
|
50
|
+
var OPENAI_USE_AZURE = "OPENAI_USE_AZURE";
|
|
51
|
+
var MIDSCENE_CACHE = "MIDSCENE_CACHE";
|
|
52
|
+
var MATCH_BY_POSITION = "MATCH_BY_POSITION";
|
|
53
|
+
var MIDSCENE_REPORT_TAG_NAME = "MIDSCENE_REPORT_TAG_NAME";
|
|
54
|
+
var allConfigFromEnv = () => {
|
|
55
|
+
return {
|
|
56
|
+
[MIDSCENE_OPENAI_INIT_CONFIG_JSON]: process.env[MIDSCENE_OPENAI_INIT_CONFIG_JSON] || void 0,
|
|
57
|
+
[MIDSCENE_MODEL_NAME]: process.env[MIDSCENE_MODEL_NAME] || void 0,
|
|
58
|
+
[MIDSCENE_DEBUG_MODE]: process.env[MIDSCENE_DEBUG_MODE] || void 0,
|
|
59
|
+
[MIDSCENE_LANGSMITH_DEBUG]: process.env[MIDSCENE_LANGSMITH_DEBUG] || void 0,
|
|
60
|
+
[MIDSCENE_DEBUG_AI_PROFILE]: process.env[MIDSCENE_DEBUG_AI_PROFILE] || void 0,
|
|
61
|
+
[MIDSCENE_DANGEROUSLY_PRINT_ALL_CONFIG]: process.env[MIDSCENE_DANGEROUSLY_PRINT_ALL_CONFIG] || void 0,
|
|
62
|
+
[OPENAI_API_KEY]: process.env[OPENAI_API_KEY] || void 0,
|
|
63
|
+
[OPENAI_BASE_URL]: process.env[OPENAI_BASE_URL] || void 0,
|
|
64
|
+
[MIDSCENE_MODEL_TEXT_ONLY]: process.env[MIDSCENE_MODEL_TEXT_ONLY] || void 0,
|
|
65
|
+
[OPENAI_USE_AZURE]: process.env[OPENAI_USE_AZURE] || void 0,
|
|
66
|
+
[MIDSCENE_CACHE]: process.env[MIDSCENE_CACHE] || void 0,
|
|
67
|
+
[MATCH_BY_POSITION]: process.env[MATCH_BY_POSITION] || void 0,
|
|
68
|
+
[MIDSCENE_REPORT_TAG_NAME]: process.env[MIDSCENE_REPORT_TAG_NAME] || void 0
|
|
69
|
+
};
|
|
70
|
+
};
|
|
71
|
+
var userConfig = {};
|
|
72
|
+
var getAIConfig = (configKey) => {
|
|
73
|
+
if (typeof userConfig[configKey] !== "undefined") {
|
|
74
|
+
return userConfig[configKey];
|
|
75
|
+
}
|
|
76
|
+
return allConfigFromEnv()[configKey];
|
|
77
|
+
};
|
|
78
|
+
var allAIConfig = () => {
|
|
79
|
+
return { ...allConfigFromEnv(), ...userConfig };
|
|
80
|
+
};
|
|
81
|
+
var overrideAIConfig = (newConfig, extendMode) => {
|
|
82
|
+
userConfig = extendMode ? { ...userConfig, ...newConfig } : { ...newConfig };
|
|
83
|
+
};
|
|
84
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
85
|
+
0 && (module.exports = {
|
|
86
|
+
MATCH_BY_POSITION,
|
|
87
|
+
MIDSCENE_CACHE,
|
|
88
|
+
MIDSCENE_DANGEROUSLY_PRINT_ALL_CONFIG,
|
|
89
|
+
MIDSCENE_DEBUG_AI_PROFILE,
|
|
90
|
+
MIDSCENE_DEBUG_MODE,
|
|
91
|
+
MIDSCENE_LANGSMITH_DEBUG,
|
|
92
|
+
MIDSCENE_MODEL_NAME,
|
|
93
|
+
MIDSCENE_MODEL_TEXT_ONLY,
|
|
94
|
+
MIDSCENE_OPENAI_INIT_CONFIG_JSON,
|
|
95
|
+
MIDSCENE_REPORT_TAG_NAME,
|
|
96
|
+
OPENAI_API_KEY,
|
|
97
|
+
OPENAI_BASE_URL,
|
|
98
|
+
OPENAI_USE_AZURE,
|
|
99
|
+
allAIConfig,
|
|
100
|
+
getAIConfig,
|
|
101
|
+
overrideAIConfig
|
|
102
|
+
});
|