"use strict";exports.id=1336,exports.ids=[1336],exports.modules={71336:(a,b,c)=>{c.d(b,{q7:()=>G});let d="u">typeof process&&process.versions?.node&&!0,e="u">typeof process&&process.env||{},f="false"!==e.ENABLE_REQUEST_LOGS,g=null,h=null,i=null,j={expiresAt:0,config:null},k=new Set;async function l(){if(d&&f&&!g)try{g=await Promise.resolve().then(c.t.bind(c,29021,23)),h=await Promise.resolve().then(c.t.bind(c,33873,23)),i=e.REQUEST_LOG_DIR||(e.DATA_DIR?h.join(e.DATA_DIR,"logs","requests"):null)||h.join("u">typeof process&&process.cwd?process.cwd():".","logs")}catch{}}function m(a,b){k.has(a)||(k.add(a),console.log(b))}function n(a){return Array.isArray(a)?a[0]||"":a||""}function o(a={}){let b={};for(let[c,d]of Object.entries(a||{}))b[c.toLowerCase()]=d;return b}function p(a={}){let b=o(a);return{client_ip:String(n(b["x-9r-client-ip"])||n(b["x-forwarded-for"])||"").split(",")[0].trim().replace(/^::ffff:/,"").replace(/^::1$/,"127.0.0.1"),client_port:String(n(b["x-9r-client-port"])||""),client_user_agent:String(n(b["x-9r-client-user-agent"])||n(b["user-agent"])||""),client_host:String(n(b["x-9r-client-host"])||n(b.host)||"")}}function q(a={}){let b=o(a);return{source_tool:String(n(b["x-9r-source-tool"])||""),source_tool_label:String(n(b["x-9r-source-tool-label"])||""),source_host:String(n(b["x-9r-source-host"])||n(b.host)||"")}}function r(a={},b={}){return{...a,...Object.fromEntries(Object.entries(b||{}).filter(([,a])=>null!=a&&""!==String(a)))}}async function s(a){try{let b=await Promise.resolve().then(c.t.bind(c,87550,23)),d=new(b.default||b)(a);return d.pragma("journal_mode = WAL"),d.pragma("busy_timeout = 5000"),{kind:"better-sqlite3",db:d,get:(a,b=[])=>d.prepare(a).get(...b),exec(a){d.exec(a)},run:(a,b=[])=>d.prepare(a).run(...b),close(){d.close()}}}catch(d){let b=new(await Promise.resolve().then(c.t.bind(c,80099,23))).DatabaseSync(a);return b.exec("PRAGMA journal_mode = WAL"),b.exec("PRAGMA busy_timeout = 5000"),{kind:"node:sqlite",db:b,get:(a,c=[])=>b.prepare(a).get(...c),exec(a){b.exec(a)},run:(a,c=[])=>b.prepare(a).run(...c),close(){b.close()}}}}async function t(){if(await l(),!g||!h)return null;let a=Date.now();if(j.config&&j.expiresAt>a)return j.config;let b=null;try{let a=h?e.PROMPT_LOG_CONFIG_DB?e.PROMPT_LOG_CONFIG_DB:e.DATA_DIR?h.join(e.DATA_DIR,"db","data.sqlite"):null:null;if(a&&g.existsSync(a)){let c=await s(a);try{let a=c.get("SELECT data FROM settings WHERE id = 1");a?.data&&(b=JSON.parse(a.data).promptLogDb||null)}finally{c.close()}}}catch(a){m("config-read",`[PromptDB] Failed to read config: ${a.message}`)}return b||"true"!==e.PROMPT_LOG_DB_ENABLED||(b={enabled:!0,type:"sqlite",sqlitePath:e.PROMPT_LOG_DB||(e.DATA_DIR?h.join(e.DATA_DIR,"logs","promptLogs.sqlite"):""),logClientRequest:!0,logSourceRequest:!0,logTargetRequest:!0,logProviderResponse:"true"===e.PROMPT_LOG_DB_RESPONSE,logErrors:!0}),j={config:b,expiresAt:a+5e3},b}function u(a){return"postgres"===a?`
      CREATE TABLE IF NOT EXISTS prompt_logs (
        id TEXT PRIMARY KEY,
        created_at TIMESTAMPTZ NOT NULL,
        session_id TEXT,
        source_format TEXT,
        target_format TEXT,
        model TEXT,
        endpoint TEXT,
        stage TEXT,
        provider_url TEXT,
        provider TEXT,
        account_name TEXT,
        connection_id TEXT,
        display_model TEXT,
        client_ip TEXT,
        client_port TEXT,
        client_user_agent TEXT,
        client_host TEXT,
        source_tool TEXT,
        source_tool_label TEXT,
        source_host TEXT,
        prompt_text TEXT,
        full_request_json JSONB,
        response_text TEXT,
        status_code INTEGER,
        error_text TEXT,
        meta_json JSONB
      );

      CREATE INDEX IF NOT EXISTS idx_prompt_logs_created_at
        ON prompt_logs(created_at DESC);

      CREATE INDEX IF NOT EXISTS idx_prompt_logs_model
        ON prompt_logs(model);

      CREATE INDEX IF NOT EXISTS idx_prompt_logs_stage
        ON prompt_logs(stage);

      CREATE INDEX IF NOT EXISTS idx_prompt_logs_session
        ON prompt_logs(session_id);

      CREATE INDEX IF NOT EXISTS idx_prompt_logs_client_ip
        ON prompt_logs(client_ip);

      CREATE INDEX IF NOT EXISTS idx_prompt_logs_source_tool
        ON prompt_logs(source_tool);
    `:"mysql"===a?`
      CREATE TABLE IF NOT EXISTS prompt_logs (
        id VARCHAR(80) PRIMARY KEY,
        created_at DATETIME(3) NOT NULL,
        session_id VARCHAR(255),
        source_format VARCHAR(80),
        target_format VARCHAR(80),
        model VARCHAR(255),
        endpoint TEXT,
        stage VARCHAR(80),
        provider_url TEXT,
        provider VARCHAR(120),
        account_name VARCHAR(255),
        connection_id VARCHAR(120),
        display_model VARCHAR(512),
        client_ip VARCHAR(64),
        client_port VARCHAR(32),
        client_user_agent TEXT,
        client_host TEXT,
        source_tool VARCHAR(80),
        source_tool_label VARCHAR(120),
        source_host VARCHAR(255),
        prompt_text LONGTEXT,
        full_request_json JSON,
        response_text LONGTEXT,
        status_code INT,
        error_text TEXT,
        meta_json JSON,
        INDEX idx_prompt_logs_created_at (created_at),
        INDEX idx_prompt_logs_model (model),
        INDEX idx_prompt_logs_stage (stage),
        INDEX idx_prompt_logs_session (session_id),
        INDEX idx_prompt_logs_client_ip (client_ip),
        INDEX idx_prompt_logs_source_tool (source_tool)
      );
    `:`
    CREATE TABLE IF NOT EXISTS prompt_logs (
      id TEXT PRIMARY KEY,
      created_at TEXT NOT NULL,
      session_id TEXT,
      source_format TEXT,
      target_format TEXT,
      model TEXT,
      endpoint TEXT,
      stage TEXT,
      provider_url TEXT,
      provider TEXT,
      account_name TEXT,
      connection_id TEXT,
      display_model TEXT,
      client_ip TEXT,
      client_port TEXT,
      client_user_agent TEXT,
      client_host TEXT,
      source_tool TEXT,
      source_tool_label TEXT,
      source_host TEXT,
      prompt_text TEXT,
      full_request_json TEXT,
      response_text TEXT,
      status_code INTEGER,
      error_text TEXT,
      meta_json TEXT
    );

    CREATE INDEX IF NOT EXISTS idx_prompt_logs_created_at
      ON prompt_logs(created_at DESC);

    CREATE INDEX IF NOT EXISTS idx_prompt_logs_model
      ON prompt_logs(model);

    CREATE INDEX IF NOT EXISTS idx_prompt_logs_stage
      ON prompt_logs(stage);

    CREATE INDEX IF NOT EXISTS idx_prompt_logs_session
      ON prompt_logs(session_id);
  `}async function v(a){a.get;let b=[];try{"better-sqlite3"===a.kind?b=a.db.prepare("PRAGMA table_info(prompt_logs)").all():"node:sqlite"===a.kind&&(b=a.db.prepare("PRAGMA table_info(prompt_logs)").all())}catch{b=[]}let c=new Set(b.map(a=>a.name)),d=(b,d)=>{c.has(b)||a.exec(`ALTER TABLE prompt_logs ADD COLUMN ${b} ${d};`)};d("client_ip","TEXT"),d("client_port","TEXT"),d("client_user_agent","TEXT"),d("client_host","TEXT"),d("source_tool","TEXT"),d("source_tool_label","TEXT"),d("source_host","TEXT"),d("provider","TEXT"),d("account_name","TEXT"),d("connection_id","TEXT"),d("display_model","TEXT"),a.exec("CREATE INDEX IF NOT EXISTS idx_prompt_logs_client_ip ON prompt_logs(client_ip);"),a.exec("CREATE INDEX IF NOT EXISTS idx_prompt_logs_source_tool ON prompt_logs(source_tool);")}async function w(a){await a.query(`
    ALTER TABLE prompt_logs ADD COLUMN IF NOT EXISTS client_ip TEXT;
    ALTER TABLE prompt_logs ADD COLUMN IF NOT EXISTS client_port TEXT;
    ALTER TABLE prompt_logs ADD COLUMN IF NOT EXISTS client_user_agent TEXT;
    ALTER TABLE prompt_logs ADD COLUMN IF NOT EXISTS client_host TEXT;
    ALTER TABLE prompt_logs ADD COLUMN IF NOT EXISTS source_tool TEXT;
    ALTER TABLE prompt_logs ADD COLUMN IF NOT EXISTS source_tool_label TEXT;
    ALTER TABLE prompt_logs ADD COLUMN IF NOT EXISTS source_host TEXT;
    ALTER TABLE prompt_logs ADD COLUMN IF NOT EXISTS provider TEXT;
    ALTER TABLE prompt_logs ADD COLUMN IF NOT EXISTS account_name TEXT;
    ALTER TABLE prompt_logs ADD COLUMN IF NOT EXISTS connection_id TEXT;
    ALTER TABLE prompt_logs ADD COLUMN IF NOT EXISTS display_model TEXT;

    CREATE INDEX IF NOT EXISTS idx_prompt_logs_client_ip
      ON prompt_logs(client_ip);

    CREATE INDEX IF NOT EXISTS idx_prompt_logs_source_tool
      ON prompt_logs(source_tool);
  `)}async function x(a,b,c,d){let[e]=await a.query(`
    SELECT 1 AS found
    FROM INFORMATION_SCHEMA.COLUMNS
    WHERE TABLE_SCHEMA = ?
      AND TABLE_NAME = ?
      AND COLUMN_NAME = ?
    LIMIT 1
    `,[b,c,d]);return e.length>0}async function y(a,b,c,d){let[e]=await a.query(`
    SELECT 1 AS found
    FROM INFORMATION_SCHEMA.STATISTICS
    WHERE TABLE_SCHEMA = ?
      AND TABLE_NAME = ?
      AND INDEX_NAME = ?
    LIMIT 1
    `,[b,c,d]);return e.length>0}async function z(a,b){let c=async(c,d)=>{await x(a,b.database,"prompt_logs",c)||await a.query(`ALTER TABLE prompt_logs ADD COLUMN ${c} ${d}`)};await c("client_ip","VARCHAR(64)"),await c("client_port","VARCHAR(32)"),await c("client_user_agent","TEXT"),await c("client_host","TEXT"),await c("source_tool","VARCHAR(80)"),await c("source_tool_label","VARCHAR(120)"),await c("source_host","VARCHAR(255)"),await c("provider","VARCHAR(120)"),await c("account_name","VARCHAR(255)"),await c("connection_id","VARCHAR(120)"),await c("display_model","VARCHAR(512)"),await y(a,b.database,"prompt_logs","idx_prompt_logs_client_ip")||await a.query("CREATE INDEX idx_prompt_logs_client_ip ON prompt_logs(client_ip)"),await y(a,b.database,"prompt_logs","idx_prompt_logs_source_tool")||await a.query("CREATE INDEX idx_prompt_logs_source_tool ON prompt_logs(source_tool)")}function A(a){return String(a||"").trim()}function B(a){let b=A(a);if(!b)return"";try{return new URL(b).hostname||""}catch{return b.replace(/^https?:\/\//,"").replace(/\/.*$/,"").replace(/:\d+$/,"")}}async function C(a){try{var b;if(await l(),!g||!h)return;let d=await t();if(b=a.stage,!d?.enabled||("client"===b?!1===d.logClientRequest:"source"===b||"openai"===b?!1===d.logSourceRequest:"target"===b?!1===d.logTargetRequest:"provider_response"===b?!0!==d.logProviderResponse:"error"===b&&!1===d.logErrors))return;let f=new Date().toISOString(),i=(a.promptText||(function a(b,c=0,d=[]){if(null==b||c>10||d.join("\n").length>2e5)return d;if("string"==typeof b)return b.trim()&&d.push(b),d;if(Array.isArray(b)){for(let e of b)a(e,c+1,d);return d}if("object"==typeof b)for(let[e,f]of Object.entries(b)){let b=e.toLowerCase();["content","text","prompt","input","message"].includes(b)?a(f,c+1,d):c<5&&("messages"===b||"contents"===b||"parts"===b||"body"===b)&&a(f,c+1,d)}return d})(a.request||a.response||{}).join("\n\n")).slice(0,5e5),j=p(a.headers||a.request?.headers||{}),k=q(a.headers||a.request?.headers||{}),m=r(j,a.clientInfo||{}),n=r(k,a.sourceInfo||{}),o=function(a={}){var b,c;let d,e,f,g=a.context||{},h=function(a){let b=A(a),c=b.indexOf("/");if(c<=0)return"";let d=b.slice(0,c);return/^[a-z][a-z0-9_-]{1,60}$/i.test(d)?d:""}(a.model),i=A(g.provider)||A(a.provider)||A(a.providerId)||A(a.provider_id)||h||"",j=(d=A(i),/^openai-compatible-chat-[0-9a-f-]{20,}$/i.test(d)||/^openai-compatible-[0-9a-f-]{20,}$/i.test(d))?"":i,k=A(g.accountName)||A(g.account_name)||A(g.connectionName)||A(a.accountName)||A(a.account_name)||A(a.keyName)||A(a.key_name)||"",l=A(g.connectionId)||A(a.connectionId)||A(a.connection_id)||"",m=(b=A(a.model),c=j||h,e=A(b),(f=A(c))&&e.startsWith(`${f}/`)?e.slice(f.length+1):e),n=B(a.providerUrl)||B(a.endpoint),o="";return j&&k&&k!==j?o=`${j}/${k}`:j?o=j:k?o=k:n&&(o=n),{provider:j||null,accountName:k||null,connectionId:l||null,displayModel:o&&m?`${o}/${m}`:null}}(a),x={id:`${Date.now()}_${Math.random().toString(16).slice(2)}`,created_at:f,session_id:a.sessionId||null,source_format:a.sourceFormat||null,target_format:a.targetFormat||null,model:a.model||null,endpoint:a.endpoint||null,stage:a.stage||null,provider_url:a.providerUrl||null,provider:o.provider||null,account_name:o.accountName||null,connection_id:o.connectionId||null,display_model:o.displayModel||null,client_ip:m.client_ip||null,client_port:m.client_port||null,client_user_agent:m.client_user_agent||null,client_host:m.client_host||null,source_tool:n.source_tool||null,source_tool_label:n.source_tool_label||null,source_host:n.source_host||null,prompt_text:i||null,full_request_json:a.request?JSON.stringify(a.request):null,response_text:"string"==typeof a.response?a.response:null,status_code:a.statusCode||null,error_text:a.errorText||null,meta_json:a.meta?JSON.stringify(a.meta):null};if("postgres"===d.type){let a=new(await Promise.resolve().then(c.bind(c,64939))).Client({host:d.host,port:Number(d.port||5432),database:d.database,user:d.username,password:d.password,ssl:!!d.ssl&&{rejectUnauthorized:!1}});try{await a.connect(),await a.query(u("postgres")),await w(a),await a.query(`INSERT INTO prompt_logs (
            id, created_at, session_id, source_format, target_format, model,
            endpoint, stage, provider_url, provider, account_name, connection_id, display_model,
            client_ip, client_port, client_user_agent, client_host,
            source_tool, source_tool_label, source_host,
            prompt_text, full_request_json,
            response_text, status_code, error_text, meta_json
          ) VALUES (
            $1, $2, $3, $4, $5, $6,
            $7, $8, $9, $10, $11, $12, $13,
            $14, $15, $16, $17,
            $18, $19, $20,
            $21, $22::jsonb,
            $23, $24, $25, $26::jsonb
          )`,[x.id,x.created_at,x.session_id,x.source_format,x.target_format,x.model,x.endpoint,x.stage,x.provider_url,x.provider,x.account_name,x.connection_id,x.display_model,x.client_ip,x.client_port,x.client_user_agent,x.client_host,x.source_tool,x.source_tool_label,x.source_host,x.prompt_text,x.full_request_json,x.response_text,x.status_code,x.error_text,x.meta_json]),x.session_id&&x.display_model&&await a.query(`UPDATE prompt_logs
             SET provider = COALESCE(provider, $1),
                 account_name = COALESCE(account_name, $2),
                 connection_id = COALESCE(connection_id, $3),
                 display_model = $4
             WHERE session_id = $5`,[x.provider,x.account_name,x.connection_id,x.display_model,x.session_id])}finally{await a.end()}return}if("mysql"===d.type){let a=await c.e(8491).then(c.t.bind(c,38491,19)),b=await a.createConnection({host:d.host,port:Number(d.port||3306),database:d.database,user:d.username,password:d.password,ssl:d.ssl?{}:void 0,multipleStatements:!0});try{await b.query(u("mysql")),await z(b,d),await b.query(`INSERT INTO prompt_logs (
            id, created_at, session_id, source_format, target_format, model,
            endpoint, stage, provider_url, provider, account_name, connection_id, display_model,
            client_ip, client_port, client_user_agent, client_host,
            source_tool, source_tool_label, source_host,
            prompt_text, full_request_json,
            response_text, status_code, error_text, meta_json
          ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, CAST(? AS JSON), ?, ?, ?, CAST(? AS JSON))`,[x.id,x.created_at.replace("T"," ").replace("Z",""),x.session_id,x.source_format,x.target_format,x.model,x.endpoint,x.stage,x.provider_url,x.provider,x.account_name,x.connection_id,x.display_model,x.client_ip,x.client_port,x.client_user_agent,x.client_host,x.source_tool,x.source_tool_label,x.source_host,x.prompt_text,x.full_request_json,x.response_text,x.status_code,x.error_text,x.meta_json]),x.session_id&&x.display_model&&await b.query(`UPDATE prompt_logs
             SET provider = COALESCE(provider, ?),
                 account_name = COALESCE(account_name, ?),
                 connection_id = COALESCE(connection_id, ?),
                 display_model = ?
             WHERE session_id = ?`,[x.provider,x.account_name,x.connection_id,x.display_model,x.session_id])}finally{await b.end()}return}let y=d.sqlitePath||(e.DATA_DIR?h.join(e.DATA_DIR,"logs","promptLogs.sqlite"):null);if(!y)return;g.mkdirSync(h.dirname(y),{recursive:!0});let C=await s(y);try{C.exec(u("sqlite")),await v(C),C.run(`INSERT INTO prompt_logs (
          id, created_at, session_id, source_format, target_format, model,
          endpoint, stage, provider_url, provider, account_name, connection_id, display_model,
          client_ip, client_port, client_user_agent, client_host,
          source_tool, source_tool_label, source_host,
          prompt_text, full_request_json,
          response_text, status_code, error_text, meta_json
        ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,[x.id,x.created_at,x.session_id,x.source_format,x.target_format,x.model,x.endpoint,x.stage,x.provider_url,x.provider,x.account_name,x.connection_id,x.display_model,x.client_ip,x.client_port,x.client_user_agent,x.client_host,x.source_tool,x.source_tool_label,x.source_host,x.prompt_text,x.full_request_json,x.response_text,x.status_code,x.error_text,x.meta_json]),x.session_id&&x.display_model&&C.run(`UPDATE prompt_logs
           SET provider = COALESCE(provider, ?),
               account_name = COALESCE(account_name, ?),
               connection_id = COALESCE(connection_id, ?),
               display_model = ?
           WHERE session_id = ?`,[x.provider,x.account_name,x.connection_id,x.display_model,x.session_id])}finally{C.close()}}catch(a){m("db-write",`[PromptDB] Failed to write prompt log: ${a.message}`)}}async function D(a,b,c){if(await l(),!g||!i)return null;try{g.existsSync(i)||g.mkdirSync(i,{recursive:!0});let d=function(a=new Date){let b=a=>String(a).padStart(2,"0"),c=a.getFullYear(),d=b(a.getMonth()+1),e=b(a.getDate()),f=b(a.getHours()),g=b(a.getMinutes()),h=b(a.getSeconds()),i=String(a.getMilliseconds()).padStart(3,"0");return`${c}${d}${e}_${f}${g}${h}_${i}`}(),e=(c||"unknown").replace(/[/:]/g,"-"),f=`${a}_${b}_${e}_${d}`,j=h.join(i,f);return g.mkdirSync(j,{recursive:!0}),j}catch(a){return console.log("[LOG] Failed to create log session:",a.message),null}}function E(a,b,c){if(g&&a)try{let d=h.join(a,b);g.writeFileSync(d,JSON.stringify(c,null,2))}catch(a){console.log(`[LOG] Failed to write ${b}:`,a.message)}}function F(a){if(!a)return{};let b={...a},c=["authorization","x-api-key","cookie","token","api-key","openai-api-key","anthropic-api-key","gemini-api-key","google-api-key"];for(let a of Object.keys(b)){let d=a.toLowerCase();if(c.some(a=>d.includes(a))){let c=String(b[a]||"");c.length>16?b[a]=`${c.slice(0,6)}...${c.slice(-4)}`:c.length>0&&(b[a]="***")}}return b}async function G(a,b,c,d={}){if(!f)return{sessionPath:null,logClientRawRequest(){},logRawRequest(){},logOpenAIRequest(){},logTargetRequest(){},logProviderResponse(){},appendProviderChunk(){},appendOpenAIChunk(){},logConvertedResponse(){},appendConvertedChunk(){},logError(){}};let e=await D(a,b,c),i=e?String(e).split(/[\\/]/).pop():null,j={},k={};return{get sessionPath(){return e},logClientRawRequest(f,g,h={}){let l={timestamp:new Date().toISOString(),endpoint:f,headers:F(h),body:g};j=r(j,p(h)),k=r(k,q(h)),E(e,"1_req_client.json",l),C({stage:"client",clientInfo:j,sourceInfo:k,sessionId:i,sourceFormat:a,targetFormat:b,model:c,context:d,endpoint:f,request:l})},logRawRequest(f,g={}){let h={timestamp:new Date().toISOString(),headers:F(g),body:f};j=r(j,p(g)),k=r(k,q(g)),E(e,"2_req_source.json",h),C({stage:"source",clientInfo:j,sourceInfo:k,sessionId:i,sourceFormat:a,targetFormat:b,model:c,context:d,request:h})},logOpenAIRequest(f){let g={timestamp:new Date().toISOString(),body:f};E(e,"3_req_openai.json",g),C({stage:"openai",clientInfo:j,sourceInfo:k,sessionId:i,sourceFormat:a,targetFormat:b,model:c,context:d,request:g})},logTargetRequest(f,g,h){let l={timestamp:new Date().toISOString(),url:f,headers:F(g),body:h};E(e,"4_req_target.json",l),C({stage:"target",clientInfo:j,sourceInfo:k,sessionId:i,sourceFormat:a,targetFormat:b,model:c,context:d,endpoint:f,providerUrl:f,request:l})},logProviderResponse(f,g,h,l){let m={timestamp:new Date().toISOString(),status:f,statusText:g,headers:h?"function"==typeof h.entries?Object.fromEntries(h.entries()):h:{},body:l};E(e,"5_res_provider.json",m),C({stage:"provider_response",clientInfo:j,sourceInfo:k,sessionId:i,sourceFormat:a,targetFormat:b,model:c,context:d,statusCode:f,response:l,meta:m})},appendProviderChunk(a){if(g&&e)try{let b=h.join(e,"5_res_provider.txt");g.appendFileSync(b,a)}catch{}},appendOpenAIChunk(a){if(g&&e)try{let b=h.join(e,"6_res_openai.txt");g.appendFileSync(b,a)}catch{}},logConvertedResponse(a){E(e,"7_res_client.json",{timestamp:new Date().toISOString(),body:a})},appendConvertedChunk(a){if(g&&e)try{let b=h.join(e,"7_res_client.txt");g.appendFileSync(b,a)}catch{}},logError(f,g=null){let h={timestamp:new Date().toISOString(),error:f?.message||String(f),stack:f?.stack,requestBody:g};E(e,"6_error.json",h),C({stage:"error",clientInfo:j,sourceInfo:k,sessionId:i,sourceFormat:a,targetFormat:b,model:c,context:d,errorText:h.error,request:g,meta:h})}}}}};