import { extension_settings, getContext } from "/scripts/extensions.js";
import { characters } from "/script.js";
import { world_names } from "/scripts/world-info.js";
import { extensionName } from "../utils/settings.js";
import { extractContentByTag, replaceContentByTag, extractFullTagBlock } from '../utils/tagProcessor.js';
import {
getCombinedWorldbookContent,
findLatestSummaryLore,
DEDICATED_LOREBOOK_NAME,
getChatIdentifier,
} from "./lore.js";
import { checkAndFixWithAPI as summarizerCheckAndFix } from './summarizer.js';
// 导入 Google 适配器和轮询管理器
import {
isGoogleEndpoint,
convertToGoogleRequest,
parseGoogleResponse,
buildGoogleApiUrl
} from '../core/utils/googleAdapter.js';
import {
intelligentPoll,
createGooglePollingTask,
progressTracker
} from '../core/utils/pollingManager.js';
let ChatCompletionService = undefined;
try {
const module = await import('/scripts/custom-request.js');
ChatCompletionService = module.ChatCompletionService;
console.log('[Amily2号-外交部] 已成功召唤“皇家信使”(ChatCompletionService)。');
} catch (e) {
console.warn("[Amily2号-外交部] 未能召唤“皇家信使”,部分高级功能(如Claw代理)将受限。请考虑更新SillyTavern版本。", e);
}
const UPDATE_CHECK_URL =
"https://raw.githubusercontent.com/Wx-2025/ST-Amily2-Chat-Optimisation/refs/heads/main/amily2_update_info.json";
const MESSAGE_BOARD_URL =
"https://raw.githubusercontent.com/Wx-2025/ST-Amily2-Chat-Optimisation/refs/heads/main/amily2_message_board.json";
export async function fetchMessageBoardContent() {
if (!MESSAGE_BOARD_URL) {
console.log('[Amily2号-内务府] 任务取消:陛下尚未配置留言板URL。');
return null;
}
try {
const response = await fetch(MESSAGE_BOARD_URL, { cache: 'no-store' });
if (!response.ok) {
throw new Error(`服务器响应异常: ${response.status}`);
}
const data = await response.json();
return data;
} catch (error) {
console.error('[Amily2号-内务府] 获取留言板内容失败:', error);
return null;
}
}
export async function checkForUpdates() {
if (!UPDATE_CHECK_URL || UPDATE_CHECK_URL.includes('YourUsername')) {
console.log('[Amily2号-外交部] 任务取消:陛下尚未配置情报来源URL。');
return null;
}
try {
console.log('[Amily2号-外交部] 已派遣使者前往云端获取最新情报...');
const response = await fetch(UPDATE_CHECK_URL, {
method: 'GET',
cache: 'no-store',
mode: 'cors'
});
if (!response.ok) {
throw new Error(`远方服务器响应异常,状态: ${response.status}`);
}
const data = await response.json();
console.log('[Amily2号-外交部] 情报已成功获取并解析。');
return data;
} catch (error) {
console.error('[Amily2号-外交部] 紧急军情:外交任务失败!', error);
return null;
}
}
let isFetchingModels = false;
export async function fetchSupportedModels() {
const settings = extension_settings[extensionName];
if (settings && settings.forceProxyForCustomApi) {
console.log('[Amily2号-使节团] 已启用“皇家密道”模式,跳过模型列表获取。请手动输入模型ID并保存。');
toastr.info("已启用手动模式,请直接输入模型ID。", "模式切换");
const $selector = $("#amily2_model");
$selector.empty().append($('