mirror of
https://github.com/hansjone/oclaw.git
synced 2026-10-11 01:50:46 +08:00
重构主控编排与运行时预热链路,统一工作区提示词/专家调度协议并补齐 wiki 记忆注入与写回闭环。
同时收敛启动与运维脚本默认行为(含 wiki worker)、更新 Admin 可观测性与相关测试,降低首轮时延并提高运行稳定性。 Made-with: Cursor
This commit is contained in:
parent
4a23b715a2
commit
dbbe3add6a
14438 changed files with 2693620 additions and 2546 deletions
90
openclaw/extensions/telegram/src/group-migration.ts
Normal file
90
openclaw/extensions/telegram/src/group-migration.ts
Normal file
|
|
@ -0,0 +1,90 @@
|
|||
import type { OpenClawConfig } from "openclaw/plugin-sdk/config-runtime";
|
||||
import type { TelegramGroupConfig } from "openclaw/plugin-sdk/config-runtime";
|
||||
import { normalizeAccountId } from "openclaw/plugin-sdk/routing";
|
||||
import { normalizeLowercaseStringOrEmpty } from "openclaw/plugin-sdk/text-runtime";
|
||||
|
||||
type TelegramGroups = Record<string, TelegramGroupConfig>;
|
||||
|
||||
type MigrationScope = "account" | "global";
|
||||
|
||||
export type TelegramGroupMigrationResult = {
|
||||
migrated: boolean;
|
||||
skippedExisting: boolean;
|
||||
scopes: MigrationScope[];
|
||||
};
|
||||
|
||||
function resolveAccountGroups(
|
||||
cfg: OpenClawConfig,
|
||||
accountId?: string | null,
|
||||
): { groups?: TelegramGroups } {
|
||||
if (!accountId) {
|
||||
return {};
|
||||
}
|
||||
const normalized = normalizeAccountId(accountId);
|
||||
const accounts = cfg.channels?.telegram?.accounts;
|
||||
if (!accounts || typeof accounts !== "object") {
|
||||
return {};
|
||||
}
|
||||
const exact = accounts[normalized];
|
||||
if (exact?.groups) {
|
||||
return { groups: exact.groups };
|
||||
}
|
||||
const matchKey = Object.keys(accounts).find(
|
||||
(key) => normalizeLowercaseStringOrEmpty(key) === normalizeLowercaseStringOrEmpty(normalized),
|
||||
);
|
||||
return { groups: matchKey ? accounts[matchKey]?.groups : undefined };
|
||||
}
|
||||
|
||||
export function migrateTelegramGroupsInPlace(
|
||||
groups: TelegramGroups | undefined,
|
||||
oldChatId: string,
|
||||
newChatId: string,
|
||||
): { migrated: boolean; skippedExisting: boolean } {
|
||||
if (!groups) {
|
||||
return { migrated: false, skippedExisting: false };
|
||||
}
|
||||
if (oldChatId === newChatId) {
|
||||
return { migrated: false, skippedExisting: false };
|
||||
}
|
||||
if (!Object.hasOwn(groups, oldChatId)) {
|
||||
return { migrated: false, skippedExisting: false };
|
||||
}
|
||||
if (Object.hasOwn(groups, newChatId)) {
|
||||
return { migrated: false, skippedExisting: true };
|
||||
}
|
||||
groups[newChatId] = groups[oldChatId];
|
||||
delete groups[oldChatId];
|
||||
return { migrated: true, skippedExisting: false };
|
||||
}
|
||||
|
||||
export function migrateTelegramGroupConfig(params: {
|
||||
cfg: OpenClawConfig;
|
||||
accountId?: string | null;
|
||||
oldChatId: string;
|
||||
newChatId: string;
|
||||
}): TelegramGroupMigrationResult {
|
||||
const scopes: MigrationScope[] = [];
|
||||
let migrated = false;
|
||||
let skippedExisting = false;
|
||||
|
||||
const migrationTargets: Array<{
|
||||
scope: MigrationScope;
|
||||
groups: TelegramGroups | undefined;
|
||||
}> = [
|
||||
{ scope: "account", groups: resolveAccountGroups(params.cfg, params.accountId).groups },
|
||||
{ scope: "global", groups: params.cfg.channels?.telegram?.groups },
|
||||
];
|
||||
|
||||
for (const target of migrationTargets) {
|
||||
const result = migrateTelegramGroupsInPlace(target.groups, params.oldChatId, params.newChatId);
|
||||
if (result.migrated) {
|
||||
migrated = true;
|
||||
scopes.push(target.scope);
|
||||
}
|
||||
if (result.skippedExisting) {
|
||||
skippedExisting = true;
|
||||
}
|
||||
}
|
||||
|
||||
return { migrated, skippedExisting, scopes };
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue