Files
openclaw/extensions/qa-channel/src/setup.ts
Peter Steinberger f236e83de7 refactor(channels): shrink ChannelSetupInput to a generic envelope with a deprecated compatibility tier (#112319)
* refactor(channels)!: shrink ChannelSetupInput to a generic envelope with a deprecated compatibility tier

* fix(channels): keep ChannelSetupInput structurally assignable without an index signature

* docs: regenerate docs map
2026-07-21 22:17:03 -07:00

47 lines
1.5 KiB
TypeScript

// Qa Channel setup module handles plugin onboarding behavior.
import type { ChannelSetupInput } from "openclaw/plugin-sdk/channel-setup";
import type { OpenClawConfig } from "openclaw/plugin-sdk/config-contracts";
import { DEFAULT_ACCOUNT_ID } from "./accounts.js";
import type { CoreConfig } from "./types.js";
export type QaChannelSetupInput = ChannelSetupInput & {
baseUrl?: string;
botUserId?: string;
botDisplayName?: string;
};
export function applyQaSetup(params: {
cfg: OpenClawConfig;
accountId: string;
input: QaChannelSetupInput;
}): OpenClawConfig {
const nextCfg = structuredClone(params.cfg) as CoreConfig;
const section = nextCfg.channels?.["qa-channel"] ?? {};
const accounts = { ...section.accounts };
const target =
params.accountId === DEFAULT_ACCOUNT_ID ? { ...section } : { ...accounts[params.accountId] };
if (typeof params.input.baseUrl === "string") {
target.baseUrl = params.input.baseUrl;
}
if (typeof params.input.botUserId === "string") {
target.botUserId = params.input.botUserId;
}
if (typeof params.input.botDisplayName === "string") {
target.botDisplayName = params.input.botDisplayName;
}
nextCfg.channels ??= {};
if (params.accountId === DEFAULT_ACCOUNT_ID) {
nextCfg.channels["qa-channel"] = {
...section,
...target,
};
} else {
accounts[params.accountId] = target;
nextCfg.channels["qa-channel"] = {
...section,
accounts,
};
}
return nextCfg as OpenClawConfig;
}