237 lines
9.6 KiB
JavaScript
237 lines
9.6 KiB
JavaScript
'use strict';
|
|
|
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
|
const index = require('./shared/gpt-runner-shared.79ccd90a.cjs');
|
|
require('minimatch');
|
|
require('debug');
|
|
require('zod-to-json-schema');
|
|
require('zod');
|
|
require('axios');
|
|
require('jsonc-parser');
|
|
|
|
function singleFileConfigWithDefault(singleFileConfig) {
|
|
return {
|
|
...singleFileConfig
|
|
};
|
|
}
|
|
function userConfigWithDefault(userConfig) {
|
|
return {
|
|
model: {
|
|
type: index.ChatModelType.Openai,
|
|
modelName: "gpt-3.5-turbo-16k",
|
|
temperature: 0.9,
|
|
maxTokens: 2e3
|
|
},
|
|
rootPath: index.EnvConfig.get("GPTR_DEFAULT_ROOT_PATH") || index.getProcessCwd(),
|
|
includes: null,
|
|
excludes: index.DEFAULT_EXCLUDE_FILES,
|
|
exts: [".gpt.md"],
|
|
respectGitIgnore: true,
|
|
urlConfig: {},
|
|
...userConfig
|
|
};
|
|
}
|
|
function resolveSingleFileConfig(params, withDefault = true) {
|
|
let userConfig = withDefault ? userConfigWithDefault(params.userConfig) : params.userConfig;
|
|
const singleFileConfig = withDefault ? singleFileConfigWithDefault(params.singleFileConfig) : params.singleFileConfig;
|
|
userConfig = removeUserConfigUnsafeKey(userConfig);
|
|
const resolvedConfig = {
|
|
...singleFileConfig,
|
|
model: {
|
|
...userConfig.model,
|
|
...singleFileConfig.model
|
|
}
|
|
};
|
|
return resolvedConfig;
|
|
}
|
|
function removeUserConfigUnsafeKey(userConfig) {
|
|
const userConfigClone = {
|
|
...userConfig,
|
|
model: {
|
|
...userConfig.model
|
|
}
|
|
};
|
|
if (userConfigClone.model?.secrets)
|
|
delete userConfigClone.model.secrets;
|
|
return userConfigClone;
|
|
}
|
|
|
|
function isNumber(value) {
|
|
return Object.prototype.toString.call(value) === "[object Number]";
|
|
}
|
|
function isString(value) {
|
|
return Object.prototype.toString.call(value) === "[object String]";
|
|
}
|
|
function isNotEmptyString(value) {
|
|
return typeof value === "string" && value.length > 0;
|
|
}
|
|
function isBoolean(value) {
|
|
return Object.prototype.toString.call(value) === "[object Boolean]";
|
|
}
|
|
function isFunction(value) {
|
|
return Object.prototype.toString.call(value) === "[object Function]";
|
|
}
|
|
function isObject(value) {
|
|
return Object.prototype.toString.call(value) === "[object Object]";
|
|
}
|
|
function isShallowEqual(objA, objB, compare, compareContext) {
|
|
let ret = compare ? compare.call(compareContext, objA, objB) : void 0;
|
|
if (ret !== void 0)
|
|
return !!ret;
|
|
if (Object.is(objA, objB))
|
|
return true;
|
|
if (typeof objA !== "object" || !objA || typeof objB !== "object" || !objB)
|
|
return false;
|
|
const keysA = Object.keys(objA);
|
|
const keysB = Object.keys(objB);
|
|
if (keysA.length !== keysB.length)
|
|
return false;
|
|
const bHasOwnProperty = Object.prototype.hasOwnProperty.bind(objB);
|
|
for (let idx = 0; idx < keysA.length; idx++) {
|
|
const key = keysA[idx];
|
|
if (!bHasOwnProperty(key))
|
|
return false;
|
|
const valueA = objA[key];
|
|
const valueB = objB[key];
|
|
ret = compare ? compare.call(compareContext, valueA, valueB, key) : void 0;
|
|
if (ret === false || ret === void 0 && !Object.is(valueA, valueB))
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
function isDeepEqual(objA, objB, maxDepth = 20, visited = [], depth = 0) {
|
|
if (depth > maxDepth) {
|
|
return true;
|
|
}
|
|
if (visited.includes(objA) || visited.includes(objB))
|
|
return true;
|
|
const compare = (a, b) => {
|
|
if (typeof a === "object" && a !== null && typeof b === "object" && b !== null) {
|
|
return isDeepEqual(a, b, maxDepth, [...visited, a, b], depth + 1);
|
|
}
|
|
return Object.is(a, b);
|
|
};
|
|
return isShallowEqual(objA, objB, compare);
|
|
}
|
|
|
|
function getModelConfig(modelType, key) {
|
|
const chatModelConfigMap = {
|
|
[index.ChatModelType.Anthropic]: {
|
|
config: index.AnthropicModelConfigSchema,
|
|
secrets: index.AnthropicSecretsSchema
|
|
},
|
|
[index.ChatModelType.HuggingFace]: {
|
|
config: index.HuggingFaceModelConfigSchema,
|
|
secrets: index.HuggingFaceSecretsSchema
|
|
},
|
|
[index.ChatModelType.Openai]: {
|
|
config: index.OpenaiModelConfigSchema,
|
|
secrets: index.OpenaiSecretsSchema
|
|
}
|
|
};
|
|
return chatModelConfigMap[modelType][key];
|
|
}
|
|
|
|
exports.BaseModelConfigSchema = index.BaseModelConfigSchema;
|
|
exports.BaseSecretsSchema = index.BaseSecretsSchema;
|
|
exports.ChatMessageStatus = index.ChatMessageStatus;
|
|
exports.ChatMessageStatusSchema = index.ChatMessageStatusSchema;
|
|
exports.ChatModelSchema = index.ChatModelSchema;
|
|
exports.ChatModelType = index.ChatModelType;
|
|
exports.ChatModelTypeSchema = index.ChatModelTypeSchema;
|
|
exports.ChatRole = index.ChatRole;
|
|
exports.ChatRoleSchema = index.ChatRoleSchema;
|
|
exports.ChatStreamReqParamsSchema = index.ChatStreamReqParamsSchema;
|
|
exports.ClientEventName = index.ClientEventName;
|
|
exports.ClientEventNameSchema = index.ClientEventNameSchema;
|
|
exports.CreateFilePathReqParamsSchema = index.CreateFilePathReqParamsSchema;
|
|
exports.DEFAULT_API_BASE_PATH = index.DEFAULT_API_BASE_PATH;
|
|
exports.DEFAULT_EXCLUDE_FILES = index.DEFAULT_EXCLUDE_FILES;
|
|
exports.DEFAULT_EXCLUDE_FILE_EXTS = index.DEFAULT_EXCLUDE_FILE_EXTS;
|
|
exports.DEFAULT_MODEL_NAMES_FOR_CHOOSE = index.DEFAULT_MODEL_NAMES_FOR_CHOOSE;
|
|
exports.Debug = index.Debug;
|
|
exports.DeleteFilePathReqParamsSchema = index.DeleteFilePathReqParamsSchema;
|
|
exports.EnvConfig = index.EnvConfig;
|
|
exports.FilterPatternSchema = index.FilterPatternSchema;
|
|
exports.FormCheckboxGroupConfigSchema = index.FormCheckboxGroupConfigSchema;
|
|
exports.FormFieldBaseConfigSchema = index.FormFieldBaseConfigSchema;
|
|
exports.FormInputConfigSchema = index.FormInputConfigSchema;
|
|
exports.FormItemConfigSchema = index.FormItemConfigSchema;
|
|
exports.FormOptionSchema = index.FormOptionSchema;
|
|
exports.FormRadioGroupConfigSchema = index.FormRadioGroupConfigSchema;
|
|
exports.FormSelectConfigSchema = index.FormSelectConfigSchema;
|
|
exports.FormTextareaConfigSchema = index.FormTextareaConfigSchema;
|
|
exports.GPT_RUNNER_OFFICIAL_FOLDER = index.GPT_RUNNER_OFFICIAL_FOLDER;
|
|
exports.GetAppConfigReqParamsSchema = index.GetAppConfigReqParamsSchema;
|
|
exports.GetCommonFilesReqParamsSchema = index.GetCommonFilesReqParamsSchema;
|
|
exports.GetFileInfoReqParamsSchema = index.GetFileInfoReqParamsSchema;
|
|
exports.GetGptFileInfoReqParamsSchema = index.GetGptFileInfoReqParamsSchema;
|
|
exports.GetGptFilesReqParamsSchema = index.GetGptFilesReqParamsSchema;
|
|
exports.GetModelNamesForChooseReqParamsSchema = index.GetModelNamesForChooseReqParamsSchema;
|
|
exports.GetUserConfigReqParamsSchema = index.GetUserConfigReqParamsSchema;
|
|
exports.GptFileTreeItemType = index.GptFileTreeItemType;
|
|
exports.GptFileTreeItemTypeSchema = index.GptFileTreeItemTypeSchema;
|
|
exports.InitGptFilesReqParamsSchema = index.InitGptFilesReqParamsSchema;
|
|
exports.LocaleLang = index.LocaleLang;
|
|
exports.LocaleLangSchema = index.LocaleLangSchema;
|
|
exports.MIN_NODE_VERSION = index.MIN_NODE_VERSION;
|
|
exports.MarkAsVisitedAppConfigReqParamsSchema = index.MarkAsVisitedAppConfigReqParamsSchema;
|
|
exports.OpenEditorReqParamsSchema = index.OpenEditorReqParamsSchema;
|
|
exports.OpenaiModelConfigSchema = index.OpenaiModelConfigSchema;
|
|
exports.OpenaiSecretsSchema = index.OpenaiSecretsSchema;
|
|
exports.PartialChatModelTypeMapSchema = index.PartialChatModelTypeMapSchema;
|
|
exports.RenameFilePathReqParamsSchema = index.RenameFilePathReqParamsSchema;
|
|
exports.SECRET_KEY_PLACEHOLDER = index.SECRET_KEY_PLACEHOLDER;
|
|
exports.STREAM_DONE_FLAG = index.STREAM_DONE_FLAG;
|
|
exports.SaveFileContentReqParamsSchema = index.SaveFileContentReqParamsSchema;
|
|
exports.SecretStorageKey = index.SecretStorageKey;
|
|
exports.ServerStorageName = index.ServerStorageName;
|
|
exports.ServerStorageNameSchema = index.ServerStorageNameSchema;
|
|
exports.SingleChatMessageSchema = index.SingleChatMessageSchema;
|
|
exports.SingleFileConfigSchema = index.SingleFileConfigSchema;
|
|
exports.StorageClearReqParamsSchema = index.StorageClearReqParamsSchema;
|
|
exports.StorageGetItemReqParamsSchema = index.StorageGetItemReqParamsSchema;
|
|
exports.StorageRemoveItemReqParamsSchema = index.StorageRemoveItemReqParamsSchema;
|
|
exports.StorageSetItemReqParamsSchema = index.StorageSetItemReqParamsSchema;
|
|
exports.UserConfigForUserSchema = index.UserConfigForUserSchema;
|
|
exports.UserConfigSchema = index.UserConfigSchema;
|
|
exports.VendorTag = index.VendorTag;
|
|
exports.WssActionName = index.WssActionName;
|
|
exports.WssUtils = index.WssUtils;
|
|
exports.buildFailResponse = index.buildFailResponse;
|
|
exports.buildSuccessResponse = index.buildSuccessResponse;
|
|
exports.createFilterByPattern = index.createFilterByPattern;
|
|
exports.debounce = index.debounce;
|
|
exports.formatSourceValue = index.formatSourceValue;
|
|
exports.getErrorMsg = index.getErrorMsg;
|
|
exports.getProcessCwd = index.getProcessCwd;
|
|
exports.hasOwn = index.hasOwn;
|
|
exports.isChineseCharacter = index.isChineseCharacter;
|
|
exports.objectToQueryString = index.objectToQueryString;
|
|
exports.runOnceByKey = index.runOnceByKey;
|
|
exports.singleFileJsonSchema = index.singleFileJsonSchema;
|
|
exports.sleep = index.sleep;
|
|
exports.toUnixPath = index.toUnixPath;
|
|
exports.travelTree = index.travelTree;
|
|
exports.travelTreeDeepFirst = index.travelTreeDeepFirst;
|
|
exports.tryParseJson = index.tryParseJson;
|
|
exports.tryStringifyJson = index.tryStringifyJson;
|
|
exports.urlRemoveLocalhost = index.urlRemoveLocalhost;
|
|
exports.userConfigJsonSchema = index.userConfigJsonSchema;
|
|
exports.verifyZod = index.verifyZod;
|
|
exports.waitForCondition = index.waitForCondition;
|
|
exports.getModelConfig = getModelConfig;
|
|
exports.isBoolean = isBoolean;
|
|
exports.isDeepEqual = isDeepEqual;
|
|
exports.isFunction = isFunction;
|
|
exports.isNotEmptyString = isNotEmptyString;
|
|
exports.isNumber = isNumber;
|
|
exports.isObject = isObject;
|
|
exports.isShallowEqual = isShallowEqual;
|
|
exports.isString = isString;
|
|
exports.removeUserConfigUnsafeKey = removeUserConfigUnsafeKey;
|
|
exports.resolveSingleFileConfig = resolveSingleFileConfig;
|
|
exports.singleFileConfigWithDefault = singleFileConfigWithDefault;
|
|
exports.userConfigWithDefault = userConfigWithDefault;
|