src / index.ts
import { createConfigSchematics, type PluginContext } from "@lmstudio/sdk";
import { LensManager } from "./lensManager";
const configSchematics = createConfigSchematics()
.field(
"enabledLenses",
"stringArray",
{
displayName: "Włączone lupy",
hint: "Lista aktywnych perspektyw",
maxNumItems: 10,
allowEmptyStrings: false,
},
["critical", "creative"],
)
.field(
"temperature",
"numeric",
{
displayName: "Temperatura",
min: 0.1,
max: 1.0,
step: 0.1,
slider: {
min: 0.1,
max: 1.0,
step: 0.1,
},
},
0.7,
)
.build();
export async function main(context: PluginContext) {
context.withConfigSchematics(configSchematics);
context.withGenerator(async (ctl, history) => {
const config = ctl.getPluginConfig(configSchematics);
const enabledLenses = config.get("enabledLenses");
const temperature = config.get("temperature");
const lastUserMessage =
[...history]
.reverse()
.find((message) => message.isUserMessage())
?.getText() ?? "";
const llmClient = {
call: async (opts: {
systemPrompt: string;
userPrompt: string;
temperature: number;
}) => {
const model = await ctl.client.llm.model();
const response = await model.respond(
[
{ role: "system", content: opts.systemPrompt },
{ role: "user", content: opts.userPrompt },
],
{
temperature: opts.temperature,
},
);
return response.content;
},
};
const manager = new LensManager(llmClient);
const result = await manager.runLenses(
lastUserMessage,
enabledLenses,
temperature,
);
ctl.fragmentGenerated(result);
});
}