@mottyjs /设置
Motty SDK的插件。 settings(groups) 在代码中定义一个motty的设置,每组a
模式,其每个值都有默认值。使用它们的部分从上下文中读出它们,
主机可以覆盖任何子集。一个错误的覆盖在开始时失败,尽管一个是异步模式
reject只写入stderr,因为mount立即返回,并且在第一次请求时写入Workers。
模式是任何标准模式验证器。这个例子使用了zod,而这个包没有 安装:
bun add @mottyjs/settings zod
import { settings, type Settings } from "@mottyjs/settings";
用zod定义的两个组,以及读取其中一个的部分:
import { motty } from "@mottyjs/core";
import { settings, type Settings } from "@mottyjs/settings";
import { z } from "zod";
const probability = z.number().min(0).max(1);
export const tuning = settings({
offTopic: z.object({
onTopicProbability: probability.default(0.1),
}),
structured: z.object({
smallProbability: probability.default(0.7),
}),
});
export type Tuning = Settings<typeof tuning>;
export const offTopic = motty({ name: "off-topic" })
.use(tuning)
.beforeHandle(({ settings }) => {
console.log(settings.offTopic.onTopicProbability);
});
SDK作为一个整体在 根的自述,以及其设计背后的原因 ARCHITECTURE.md.