mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 09:10:45 +00:00
fix: lazy-load discord carbon runtime for npm install
This commit is contained in:
@@ -70,7 +70,7 @@ import { discordSetupAdapter } from "./setup-adapter.js";
|
|||||||
import { createDiscordPluginBase, discordConfigAdapter } from "./shared.js";
|
import { createDiscordPluginBase, discordConfigAdapter } from "./shared.js";
|
||||||
import { collectDiscordStatusIssues } from "./status-issues.js";
|
import { collectDiscordStatusIssues } from "./status-issues.js";
|
||||||
import { parseDiscordTarget } from "./target-parsing.js";
|
import { parseDiscordTarget } from "./target-parsing.js";
|
||||||
import { DiscordUiContainer } from "./ui.js";
|
import { normalizeDiscordAccentColor, resolveDiscordAccentColor } from "./ui-colors.js";
|
||||||
|
|
||||||
type DiscordSendFn = typeof import("./send.js").sendMessageDiscord;
|
type DiscordSendFn = typeof import("./send.js").sendMessageDiscord;
|
||||||
type DiscordCarbonModule = typeof import("@buape/carbon");
|
type DiscordCarbonModule = typeof import("@buape/carbon");
|
||||||
@@ -251,7 +251,7 @@ function buildDiscordCrossContextComponents(params: {
|
|||||||
cfg: OpenClawConfig;
|
cfg: OpenClawConfig;
|
||||||
accountId?: string | null;
|
accountId?: string | null;
|
||||||
}) {
|
}) {
|
||||||
const { Separator, TextDisplay } = loadDiscordCarbonModule();
|
const { Container, Separator, TextDisplay } = loadDiscordCarbonModule();
|
||||||
const trimmed = params.message.trim();
|
const trimmed = params.message.trim();
|
||||||
const components: Array<DiscordTextDisplay | DiscordSeparator> = [];
|
const components: Array<DiscordTextDisplay | DiscordSeparator> = [];
|
||||||
if (trimmed) {
|
if (trimmed) {
|
||||||
@@ -259,7 +259,15 @@ function buildDiscordCrossContextComponents(params: {
|
|||||||
components.push(new Separator({ divider: true, spacing: "small" }));
|
components.push(new Separator({ divider: true, spacing: "small" }));
|
||||||
}
|
}
|
||||||
components.push(new TextDisplay(`*From ${params.originLabel}*`));
|
components.push(new TextDisplay(`*From ${params.originLabel}*`));
|
||||||
return [new DiscordUiContainer({ cfg: params.cfg, accountId: params.accountId, components })];
|
const configuredAccent = resolveDiscordAccentColor({
|
||||||
|
cfg: params.cfg,
|
||||||
|
accountId: params.accountId,
|
||||||
|
});
|
||||||
|
return [
|
||||||
|
new Container(components, {
|
||||||
|
accentColor: normalizeDiscordAccentColor(configuredAccent) ?? configuredAccent,
|
||||||
|
}),
|
||||||
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
const resolveDiscordAllowlistGroupOverrides = createNestedAllowlistOverrideResolver({
|
const resolveDiscordAllowlistGroupOverrides = createNestedAllowlistOverrideResolver({
|
||||||
|
|||||||
27
extensions/discord/src/ui-colors.ts
Normal file
27
extensions/discord/src/ui-colors.ts
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
import type { OpenClawConfig } from "openclaw/plugin-sdk/config-runtime";
|
||||||
|
import { inspectDiscordAccount } from "./account-inspect.js";
|
||||||
|
|
||||||
|
export const DEFAULT_DISCORD_ACCENT_COLOR = "#5865F2";
|
||||||
|
|
||||||
|
type ResolveDiscordAccentColorParams = {
|
||||||
|
cfg: OpenClawConfig;
|
||||||
|
accountId?: string | null;
|
||||||
|
};
|
||||||
|
|
||||||
|
export function normalizeDiscordAccentColor(raw?: string | null): string | null {
|
||||||
|
const trimmed = (raw ?? "").trim();
|
||||||
|
if (!trimmed) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
const normalized = trimmed.startsWith("#") ? trimmed : `#${trimmed}`;
|
||||||
|
if (!/^#[0-9a-fA-F]{6}$/.test(normalized)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return normalized.toUpperCase();
|
||||||
|
}
|
||||||
|
|
||||||
|
export function resolveDiscordAccentColor(params: ResolveDiscordAccentColorParams): string {
|
||||||
|
const account = inspectDiscordAccount({ cfg: params.cfg, accountId: params.accountId });
|
||||||
|
const configured = normalizeDiscordAccentColor(account.config.ui?.components?.accentColor);
|
||||||
|
return configured ?? DEFAULT_DISCORD_ACCENT_COLOR;
|
||||||
|
}
|
||||||
@@ -1,34 +1,11 @@
|
|||||||
import { Container } from "@buape/carbon";
|
import { Container } from "@buape/carbon";
|
||||||
import type { OpenClawConfig } from "openclaw/plugin-sdk/config-runtime";
|
import type { OpenClawConfig } from "openclaw/plugin-sdk/config-runtime";
|
||||||
import { inspectDiscordAccount } from "./account-inspect.js";
|
import { normalizeDiscordAccentColor, resolveDiscordAccentColor } from "./ui-colors.js";
|
||||||
|
|
||||||
const DEFAULT_DISCORD_ACCENT_COLOR = "#5865F2";
|
export { normalizeDiscordAccentColor, resolveDiscordAccentColor } from "./ui-colors.js";
|
||||||
|
|
||||||
type DiscordContainerComponents = ConstructorParameters<typeof Container>[0];
|
type DiscordContainerComponents = ConstructorParameters<typeof Container>[0];
|
||||||
|
|
||||||
type ResolveDiscordAccentColorParams = {
|
|
||||||
cfg: OpenClawConfig;
|
|
||||||
accountId?: string | null;
|
|
||||||
};
|
|
||||||
|
|
||||||
export function normalizeDiscordAccentColor(raw?: string | null): string | null {
|
|
||||||
const trimmed = (raw ?? "").trim();
|
|
||||||
if (!trimmed) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
const normalized = trimmed.startsWith("#") ? trimmed : `#${trimmed}`;
|
|
||||||
if (!/^#[0-9a-fA-F]{6}$/.test(normalized)) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return normalized.toUpperCase();
|
|
||||||
}
|
|
||||||
|
|
||||||
export function resolveDiscordAccentColor(params: ResolveDiscordAccentColorParams): string {
|
|
||||||
const account = inspectDiscordAccount({ cfg: params.cfg, accountId: params.accountId });
|
|
||||||
const configured = normalizeDiscordAccentColor(account.config.ui?.components?.accentColor);
|
|
||||||
return configured ?? DEFAULT_DISCORD_ACCENT_COLOR;
|
|
||||||
}
|
|
||||||
|
|
||||||
export class DiscordUiContainer extends Container {
|
export class DiscordUiContainer extends Container {
|
||||||
constructor(params: {
|
constructor(params: {
|
||||||
cfg: OpenClawConfig;
|
cfg: OpenClawConfig;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "openclaw",
|
"name": "openclaw",
|
||||||
"version": "2026.4.20-beta.1",
|
"version": "2026.4.20-beta.2",
|
||||||
"description": "Multi-channel AI gateway with extensible messaging integrations",
|
"description": "Multi-channel AI gateway with extensible messaging integrations",
|
||||||
"keywords": [],
|
"keywords": [],
|
||||||
"homepage": "https://github.com/openclaw/openclaw#readme",
|
"homepage": "https://github.com/openclaw/openclaw#readme",
|
||||||
|
|||||||
@@ -27646,6 +27646,6 @@ export const GENERATED_BASE_CONFIG_SCHEMA: BaseConfigSchemaResponse = {
|
|||||||
tags: ["advanced", "url-secret"],
|
tags: ["advanced", "url-secret"],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
version: "2026.4.20-beta.1",
|
version: "2026.4.20-beta.2",
|
||||||
generatedAt: "2026-03-22T21:17:33.302Z",
|
generatedAt: "2026-03-22T21:17:33.302Z",
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user