文档

集成

config.ts 文件

测试版功能

插件支持目前处于内部测试阶段。在此加入测试

默认情况下,插件脚手架会在 src/ 目录中创建一个 config.ts 文件,其中将包含配置的示意图。如果文件不存在,您可以手动创建它。

import { createConfigSchematics } from "@lmstudio/sdk";

export const configSchematics = createConfigSchematics()
  .field(
    "myCustomField", // The key of the field.
    "numeric", // Type of the field.
    // Options for the field. Different field types will have different options.
    {
      displayName: "My Custom Field",
      hint: "This is my custom field. Doesn't do anything special.",
      slider: { min: 0, max: 100, step: 1 }, // Add a slider to the field.
    },
    80, // Default Value
  )
  // You can add more fields by chaining the field method.
  // For example:
  //   .field("anotherField", ...)
  .build();

export const globalConfigSchematics = createConfigSchematics()
  .field(
    "myGlobalCustomField", // The key of the field.
    "string",
    {
      displayName: "My Global Custom Field",
      hint: "This is my global custom field. Doesn't do anything special.",
    },
    "default value", // Default Value
  )
  // You can add more fields by chaining the field method.
  // For example:
  //  .field("anotherGlobalField", ...)
  .build();

如果您手动添加了配置示意图,则还需要在插件的 index.ts 文件中注册配置。

这可以通过在插件的 main 函数中调用 context.withConfigSchematics(configSchematics)context.withGlobalConfigSchematics(globalConfigSchematics) 来完成。

// ... other imports ...
import { toolsProvider } from "./toolsProvider";

export async function main(context: PluginContext) {
  // ... other plugin setup code ...

  // Register the configuration schematics.
  context.withConfigSchematics(configSchematics);
  // Register the global configuration schematics.
  context.withGlobalConfigSchematics(globalConfigSchematics);

  // ... other plugin setup code ...
}

此页面的源代码可在 GitHub 上获取。