From fca8dbd6cfdcb8a229051b840733b0769e61368a Mon Sep 17 00:00:00 2001 From: kaitranntt Date: Sun, 25 Jan 2026 21:31:20 -0500 Subject: [PATCH] feat(websearch): inject hooks on profile creation Add hook injection at profile creation time (not just runtime): - profile-writer.ts: inject on API profile create/update - variant-settings.ts: inject on CLIProxy variant create Hooks now present immediately after profile creation. --- src/api/services/profile-writer.ts | 8 ++++++++ src/cliproxy/services/variant-settings.ts | 7 +++++++ 2 files changed, 15 insertions(+) diff --git a/src/api/services/profile-writer.ts b/src/api/services/profile-writer.ts index 48c34ff1..6995161b 100644 --- a/src/api/services/profile-writer.ts +++ b/src/api/services/profile-writer.ts @@ -12,6 +12,7 @@ import { saveUnifiedConfig, isUnifiedMode, } from '../../config/unified-config-loader'; +import { ensureProfileHooks } from '../../utils/websearch/profile-hook-injector'; import type { ModelMapping, CreateApiProfileResult, RemoveApiProfileResult } from './profile-types'; /** Check if URL is an OpenRouter endpoint */ @@ -43,6 +44,10 @@ function createSettingsFile( }; fs.writeFileSync(settingsPath, JSON.stringify(settings, null, 2) + '\n', 'utf8'); + + // Inject WebSearch hooks into profile settings + ensureProfileHooks(name); + return settingsPath; } @@ -101,6 +106,9 @@ function createApiProfileUnified( fs.writeFileSync(settingsPath, JSON.stringify(settings, null, 2) + '\n', 'utf8'); + // Inject WebSearch hooks into profile settings + ensureProfileHooks(name); + const config = loadOrCreateUnifiedConfig(); config.profiles[name] = { type: 'api', diff --git a/src/cliproxy/services/variant-settings.ts b/src/cliproxy/services/variant-settings.ts index 646a1a76..872ae910 100644 --- a/src/cliproxy/services/variant-settings.ts +++ b/src/cliproxy/services/variant-settings.ts @@ -13,6 +13,7 @@ import { getCcsDir } from '../../utils/config-manager'; import { expandPath } from '../../utils/helpers'; import { getClaudeEnvVars, CLIPROXY_DEFAULT_PORT } from '../config-generator'; import { CLIProxyProvider } from '../types'; +import { ensureProfileHooks } from '../../utils/websearch/profile-hook-injector'; /** Environment settings structure */ interface SettingsEnv { @@ -105,6 +106,9 @@ export function createSettingsFile( ensureDir(ccsDir); writeSettings(settingsPath, settings); + // Inject WebSearch hooks into variant settings + ensureProfileHooks(`${provider}-${name}`); + return settingsPath; } @@ -127,6 +131,9 @@ export function createSettingsFileUnified( ensureDir(ccsDir); writeSettings(settingsPath, settings); + // Inject WebSearch hooks into variant settings + ensureProfileHooks(`${provider}-${name}`); + return settingsPath; }