mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 18:48:27 +00:00
refactor!: rename chat providers to channels
This commit is contained in:
@@ -1,11 +1,9 @@
|
||||
import { randomUUID } from "node:crypto";
|
||||
import type { IncomingMessage } from "node:http";
|
||||
import { listChannelPlugins } from "../channels/plugins/index.js";
|
||||
import type { ChannelId } from "../channels/plugins/types.js";
|
||||
import type { ClawdbotConfig } from "../config/config.js";
|
||||
import {
|
||||
listProviderPlugins,
|
||||
type ProviderId,
|
||||
} from "../providers/plugins/index.js";
|
||||
import { normalizeMessageProvider } from "../utils/message-provider.js";
|
||||
import { normalizeMessageChannel } from "../utils/message-channel.js";
|
||||
import {
|
||||
type HookMappingResolved,
|
||||
resolveHookMappings,
|
||||
@@ -142,29 +140,29 @@ export type HookAgentPayload = {
|
||||
wakeMode: "now" | "next-heartbeat";
|
||||
sessionKey: string;
|
||||
deliver: boolean;
|
||||
provider: HookMessageProvider;
|
||||
channel: HookMessageChannel;
|
||||
to?: string;
|
||||
model?: string;
|
||||
thinking?: string;
|
||||
timeoutSeconds?: number;
|
||||
};
|
||||
|
||||
const HOOK_PROVIDER_VALUES = [
|
||||
const HOOK_CHANNEL_VALUES = [
|
||||
"last",
|
||||
...listProviderPlugins().map((plugin) => plugin.id),
|
||||
...listChannelPlugins().map((plugin) => plugin.id),
|
||||
];
|
||||
|
||||
export type HookMessageProvider = ProviderId | "last";
|
||||
export type HookMessageChannel = ChannelId | "last";
|
||||
|
||||
const hookProviderSet = new Set<string>(HOOK_PROVIDER_VALUES);
|
||||
export const HOOK_PROVIDER_ERROR = `provider must be ${HOOK_PROVIDER_VALUES.join("|")}`;
|
||||
const hookChannelSet = new Set<string>(HOOK_CHANNEL_VALUES);
|
||||
export const HOOK_CHANNEL_ERROR = `channel must be ${HOOK_CHANNEL_VALUES.join("|")}`;
|
||||
|
||||
export function resolveHookProvider(raw: unknown): HookMessageProvider | null {
|
||||
export function resolveHookChannel(raw: unknown): HookMessageChannel | null {
|
||||
if (raw === undefined) return "last";
|
||||
if (typeof raw !== "string") return null;
|
||||
const normalized = normalizeMessageProvider(raw);
|
||||
if (!normalized || !hookProviderSet.has(normalized)) return null;
|
||||
return normalized as HookMessageProvider;
|
||||
const normalized = normalizeMessageChannel(raw);
|
||||
if (!normalized || !hookChannelSet.has(normalized)) return null;
|
||||
return normalized as HookMessageChannel;
|
||||
}
|
||||
|
||||
export function resolveHookDeliver(raw: unknown): boolean {
|
||||
@@ -194,8 +192,8 @@ export function normalizeAgentPayload(
|
||||
typeof sessionKeyRaw === "string" && sessionKeyRaw.trim()
|
||||
? sessionKeyRaw.trim()
|
||||
: `hook:${idFactory()}`;
|
||||
const provider = resolveHookProvider(payload.provider);
|
||||
if (!provider) return { ok: false, error: HOOK_PROVIDER_ERROR };
|
||||
const channel = resolveHookChannel(payload.channel);
|
||||
if (!channel) return { ok: false, error: HOOK_CHANNEL_ERROR };
|
||||
const toRaw = payload.to;
|
||||
const to =
|
||||
typeof toRaw === "string" && toRaw.trim() ? toRaw.trim() : undefined;
|
||||
@@ -228,7 +226,7 @@ export function normalizeAgentPayload(
|
||||
wakeMode,
|
||||
sessionKey,
|
||||
deliver,
|
||||
provider,
|
||||
channel,
|
||||
to,
|
||||
model,
|
||||
thinking,
|
||||
|
||||
Reference in New Issue
Block a user