Project Files
docs / index-scaner.ts
//index.ts
import { type PluginContext } from "@lmstudio/sdk";
import { configSchematics, globalConfigSchematics } from "./config";
export async function main(context: PluginContext) {
context.withConfigSchematics(configSchematics);
context.withGlobalConfigSchematics(globalConfigSchematics);
console.log("--- ЗАПУСК ГЛУБОКОГО СКАНЕРА ---");
context.withPromptPreprocessor(async (ctl: any) => {
const scan = (obj: any, label: string, depth = 0) => {
if (depth > 3 || !obj) return; // Ограничение глубины, чтобы не зависнуть
const keys = Object.keys(obj);
const protoKeys = Object.getOwnPropertyNames(Object.getPrototypeOf(obj) || {});
console.log(`[${label}] Уровень ${depth}. Ключи:`, [...keys, ...protoKeys].join(", "));
// Ищем наши заветные поля в значениях
for (const key of keys) {
if (key.includes("save") || key.includes("heck")) {
console.log(`!!! НАЙДЕНО ПОЛЕ [${key}] в ${label}:`, obj[key]);
}
// Рекурсия для вложенных объектов (кроме циклических ссылок)
if (typeof obj[key] === 'object' && obj[key] !== null && !Array.isArray(obj[key])) {
scan(obj[key], `${label}.${key}`, depth + 1);
}
}
};
try {
console.log("--- СКАНИРОВАНИЕ ОБЪЕКТОВ ---");
scan(context, "context");
scan(ctl, "ctl");
// Проверяем наличие истории прямо в контроллере
if (ctl.pullHistory) console.log("МЕТОД НАЙДЕН: ctl.pullHistory()");
if (ctl.getChatHistory) console.log("МЕТОД НАЙДЕН: ctl.getChatHistory()");
} catch (e) {
console.error("Ошибка сканирования:", e);
}
return ctl.prompt || ctl.inputText || "test_msg";
});
}