src / index.ts
import { toolsProvider } from "./toolsProvider";
import {
configSchematics,
globalConfigSchematics,
} from "./config";
import type { PluginContext } from "@lmstudio/sdk";
// 1. Named exports as required by the LM Studio SDK / module loaders.
export {
toolsProvider,
configSchematics,
globalConfigSchematics,
};
// 2. Default export for compatibility with various module loaders.
export default {
toolsProvider,
configSchematics,
globalConfigSchematics,
};
// 3. Entry point consumed by the LM Studio runtime.
//
// `lms dev` (and installed plugins) compile .lmstudio/entry.ts, which does:
//
// import("../src/index.ts").then(async m => await m.main(pluginContext))
// .then(() => selfRegistrationHost.initCompleted())
//
// So `main()` MUST receive the `PluginContext` and REGISTER each provider
// through it (each `with*` returns the chainable `PluginContext`), then
// return that context so the host can finish initialization. Returning an
// object without calling `withToolsProvider(...)` leaves nothing registered,
// which is why the plugin appeared to start and immediately stop with no tools.
export async function main(
pluginContext: PluginContext,
): Promise<PluginContext> {
return pluginContext
.withToolsProvider(toolsProvider)
.withConfigSchematics(configSchematics)
.withGlobalConfigSchematics(globalConfigSchematics);
}
src / index.ts
import { toolsProvider } from "./toolsProvider";
import {
configSchematics,
globalConfigSchematics,
} from "./config";
import type { PluginContext } from "@lmstudio/sdk";
// 1. Named exports as required by the LM Studio SDK / module loaders.
export {
toolsProvider,
configSchematics,
globalConfigSchematics,
};
// 2. Default export for compatibility with various module loaders.
export default {
toolsProvider,
configSchematics,
globalConfigSchematics,
};
// 3. Entry point consumed by the LM Studio runtime.
//
// `lms dev` (and installed plugins) compile .lmstudio/entry.ts, which does:
//
// import("../src/index.ts").then(async m => await m.main(pluginContext))
// .then(() => selfRegistrationHost.initCompleted())
//
// So `main()` MUST receive the `PluginContext` and REGISTER each provider
// through it (each `with*` returns the chainable `PluginContext`), then
// return that context so the host can finish initialization. Returning an
// object without calling `withToolsProvider(...)` leaves nothing registered,
// which is why the plugin appeared to start and immediately stop with no tools.
export async function main(
pluginContext: PluginContext,
): Promise<PluginContext> {
return pluginContext
.withToolsProvider(toolsProvider)
.withConfigSchematics(configSchematics)
.withGlobalConfigSchematics(globalConfigSchematics);
}