qlogicagent 2.10.2 → 2.10.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli.js CHANGED
@@ -804,7 +804,7 @@ Content-Disposition: form-data; name="prompt"\r
804
804
  \r
805
805
  \u8BF7\u7528${e.language==="zh"?"\u4E2D\u6587":"\u82F1\u6587"}\u8F6C\u5F55`),l.push(`--${c}--`);let d=l.join(`\r
806
806
  `)+`\r
807
- `,u=await fetch(i,{method:"POST",headers:{Authorization:`Bearer ${r}`,"Content-Type":`multipart/form-data; boundary=${c}`},body:d});if(!u.ok){let m=await u.text();a.release({success:!1,errorCode:u.status}),o.id!==void 0&&this.sendResponse(o.id,void 0,{code:w.INTERNAL_ERROR,message:`STT API error (${u.status}): ${m.slice(0,200)}`});return}let p=await u.json();a.release({success:!0}),o.id!==void 0&&this.sendResponse(o.id,{text:p.text??"",model:p.model})}catch(c){a.release({success:!1}),o.id!==void 0&&this.sendResponse(o.id,void 0,{code:w.INTERNAL_ERROR,message:c instanceof Error?c.message:String(c)})}}gt();var si="\u65E0\u6CD5\u8FDE\u63A5 llmrouter \u6A21\u578B\u76EE\u5F55",lo=class extends Error{constructor(e=si){super(e),this.name="LlmrouterCatalogUnavailableError"}};function VC(){let o=process.env.QLOGIC_LLMROUTER_BASE_URL?.trim().replace(/\/+$/,"");if(!o)throw new lo;return o}function KC(){let o={accept:"application/json"},e=process.env.QLOGIC_LLMROUTER_ACCESS_TOKEN?.trim();return e&&(o.authorization=`Bearer ${e}`),o}async function wk(o){let e=VC(),t;try{t=await fetch(`${e}${o}`,{method:"GET",headers:KC(),signal:AbortSignal.timeout(1e4)})}catch{throw new lo}if(!t.ok)throw new lo;let n=await t.json().catch(()=>null),r=Array.isArray(n)?n:JC(n)&&Array.isArray(n.data)?n.data:null;if(!r)throw new lo;return r}async function ii(){return wk("/ext/model-catalog/providers")}async function zC(){return wk("/ext/model-catalog/models")}function kd(o){let e={zhipu:"Zhipu GLM","zhipu-openai":"Zhipu GLM OpenAI","zhipu-coding":"Zhipu GLM Coding",volcengine:"Doubao / Volcengine"};return e[o.id]?e[o.id]:o.displayName??o.name??o.id}function ai(o){return o.baseUrl??o.base_url}async function vd(o){return(await ii()).find(t=>t.id===o)??null}async function Sd(o){let e=await zC();o.migrateModelIds(qC(e));let t=e.map(YC).filter(n=>!!n);return o.replaceCatalogModels(t),t}function qC(o){let e=new Map;for(let t of o){let n=t.provider??t.owned_by,r=t.native_model_id??t.nativeModelId??t.id;if(!n||!r)continue;let s=`${n}:${r}`;for(let i of[t.public_model,t.publicModel,t.id])!i||i===r||e.set(`${n}:${i}`,s)}return e}function YC(o){let e=o.provider??o.owned_by,t=o.native_model_id??o.nativeModelId??o.id;return!e||!t?null:{id:`${e}:${t}`,provider:e,model:t,displayName:o.display_name??o.displayName??o.name??o.id,purposes:XC(o.purposes,o.category),baseUrl:o.baseUrl??o.base_url,enabled:!0,transport:o.provider_transport??o.providerTransport,contextWindow:o.context_window??o.contextWindow,maxOutput:o.max_output??o.maxOutput,streamRequired:o.stream_required??o.streamRequired,capabilities:o.capabilities,pricing:o.pricing}}function XC(o,e){let t=[...o??[],e].filter(s=>!!s),n=new Set(["textGeneration","smallModel","stt","tts","imageGeneration","imageUnderstanding","videoGeneration","videoUnderstanding","threeDGeneration","embedding","voiceClone","musicGeneration","realtimeAudio","realtimeVideo"]),r=t.filter(s=>n.has(s));return[...new Set(r.length?r:["textGeneration"])]}function JC(o){return!!o&&typeof o=="object"&&!Array.isArray(o)}function QC(o){return o.length<=8?"****":`${o.slice(0,3)}***${o.slice(-4)}`}function dt(o,e,t,n=w.INTERNAL_ERROR){if(e.id!==void 0){if(typeof o.sendError=="function"){o.sendError(e.id,n,t);return}o.sendResponse(e.id,void 0,{code:n,message:t})}}function ci(o,e){dt(o,e,si)}function ZC(o){let e={};for(let t of o)for(let n of t.purposes)e[n]??=[],e[n].push(t);return e}async function Td(){let o=J(),e=await Sd(o);return o.save(),e}async function xk(o){try{let e=(await ii()).map(t=>({id:t.id,displayName:kd(t),baseUrl:ai(t)??"",modelCount:t.models?.length??0}));o.id!==void 0&&this.sendResponse(o.id,{providers:e})}catch{ci(this,o)}}async function Rk(o){let e=o.params;if(!e?.providerId||!e?.key){dt(this,o,"Required: providerId (string), key (string)",w.INVALID_PARAMS);return}let{providerId:t,key:n,label:r}=e;try{let s=await vd(t);if(!s){dt(this,o,`Unknown provider: ${t}`,w.INVALID_PARAMS);return}let i=J();if(i.getProviderStatus(t)?.keys.some(l=>l.key===n)){o.id!==void 0&&this.sendResponse(o.id,{ok:!1,error:"\u8BE5 Key \u5DF2\u5B58\u5728\uFF0C\u65E0\u9700\u91CD\u590D\u6DFB\u52A0"});return}i.addProvider(t,{baseUrl:ai(s)});let c=i.addKey(t,n,{label:r});await Td();for(let l of Mo)if(!i.getBinding(l)){let d=i.listModels({purpose:l,provider:t,enabledOnly:!0});d.length>0&&i.setBinding(l,d[0].id)}i.setKeyHealth(c,"healthy"),i.save(),o.id!==void 0&&this.sendResponse(o.id,{ok:!0,keyId:c,providerId:t})}catch(s){let i=s instanceof Error?s.message:si;dt(this,o,i)}}function _k(o){let e=o.params;if(!e?.keyId){dt(this,o,"Required: keyId (string)",w.INVALID_PARAMS);return}let t=J();t.removeKey(e.keyId),t.save(),o.id!==void 0&&this.sendResponse(o.id,{ok:!0})}function Ak(o){let e=o.params;if(!e?.keyId||typeof e.enabled!="boolean"){dt(this,o,"Required: keyId (string), enabled (boolean)",w.INVALID_PARAMS);return}let t=J();t.updateKey(e.keyId,{enabled:e.enabled}),t.save(),o.id!==void 0&&this.sendResponse(o.id,{ok:!0})}function Pk(o){let e=o.params;if(!e?.modelId||typeof e.enabled!="boolean"){dt(this,o,"Required: modelId (string), enabled (boolean)",w.INVALID_PARAMS);return}let t=J();e.enabled?t.enableModel(e.modelId):t.disableModel(e.modelId),t.save(),o.id!==void 0&&this.sendResponse(o.id,{ok:!0})}async function Ik(o){let e=o.params;try{await Td();let n=J().listModels({purpose:e?.purpose,provider:e?.provider});o.id!==void 0&&this.sendResponse(o.id,{models:n,grouped:ZC(n)})}catch{ci(this,o)}}function Ek(o){let e=o.params;if(!e?.purpose||!e?.modelId){dt(this,o,"Required: purpose (string), modelId (string)",w.INVALID_PARAMS);return}try{let t=J();t.setBinding(e.purpose,e.modelId),t.save(),o.id!==void 0&&this.sendResponse(o.id,{ok:!0})}catch(t){dt(this,o,t instanceof Error?t.message:String(t),w.INVALID_PARAMS)}}function Ck(o){let e=o.params;if(!e?.purpose){dt(this,o,"Required: purpose (string)",w.INVALID_PARAMS);return}let t=J(),n=t.getBinding(e.purpose);o.id!==void 0&&this.sendResponse(o.id,{model:n?{id:n.id,provider:n.provider,model:n.model,displayName:n.displayName,purposes:n.purposes,enabled:n.enabled}:null,available:t.isAvailable(e.purpose)})}async function Mk(o){try{let e=await ii(),t=new Map(e.map(a=>[a.id,kd(a)]));await Td();let n=J(),r=n.getAllProviderStatus().map(a=>({providerId:a.providerId,displayName:t.get(a.providerId)??a.providerId,baseUrl:a.baseUrl,keyCount:a.keys.length,healthyKeys:a.keys.filter(c=>c.healthStatus==="healthy"&&c.enabled).length,totalKeys:a.keys.length,keys:a.keys.map(c=>({id:c.id,label:c.label,maskedKey:QC(c.key),enabled:c.enabled,health:c.healthStatus}))})),s=n.getAllBindings(),i={};for(let a of Mo){let c=s[a];i[a]={bound:!!c,modelId:c?.id,modelName:c?.displayName,available:n.isAvailable(a)}}o.id!==void 0&&this.sendResponse(o.id,{providers:r,purposes:i})}catch{ci(this,o)}}async function Ok(o){try{let e=J();e.load(),await Sd(e),e.save(),o.id!==void 0&&this.sendResponse(o.id,{ok:!0,catalogRefreshed:!0})}catch{ci(this,o)}}async function Dk(o){let e=o.params;if(!e?.providerId||!e?.apiKey){dt(this,o,"providerId and apiKey required",w.INVALID_PARAMS);return}try{let t=await vd(e.providerId),n=e.baseUrl||(t?ai(t):void 0);if(!n){dt(this,o,`Unknown provider: ${e.providerId}`,w.INVALID_PARAMS);return}let r=`${n.replace(/\/$/,"")}/models`,s=await fetch(r,{method:"GET",headers:{Authorization:`Bearer ${e.apiKey}`},signal:AbortSignal.timeout(1e4)});if(s.ok){o.id!==void 0&&this.sendResponse(o.id,{valid:!0,status:s.status});return}let i=await s.text().catch(()=>"");o.id!==void 0&&this.sendResponse(o.id,{valid:!1,status:s.status,error:i.slice(0,500)})}catch(t){let n=t instanceof Error?t.message:String(t);o.id!==void 0&&this.sendResponse(o.id,{valid:!1,status:0,error:n})}}lr();qs();td();Ys();Xs();async function Lk(o){let e=this.getActiveProjectRoot(),t=new jt(e),n=t.load();if(n){this.sendNotification("pet.soul_ready",{name:n.name,species:n.species,personality:n.personality,catchphrase:n.catchphrase,stats:n.stats,rarity:n.rarity,breed:n.breed,breedColors:n.breedColors}),o.id!==void 0&&this.sendResponse(o.id,{ok:!0,soul:n});return}let r=this.deviceId??"default-user";try{let s=this.createPetSoulGenerator?.(),i=await t.hatch(r,s);this.sendNotification("pet.soul_ready",{name:i.name,species:i.species,personality:i.personality,catchphrase:i.catchphrase,stats:i.stats,rarity:i.rarity,breed:i.breed,breedColors:i.breedColors}),this.sendNotification("pet.growth",{level:i.level,experience:i.experience,abilities:Ve.getUnlockedAbilities(i.level).map(a=>a.name)}),o.id!==void 0&&this.sendResponse(o.id,{ok:!0,soul:i})}catch(s){o.id!==void 0&&this.sendResponse(o.id,void 0,{code:w.INTERNAL_ERROR,message:s.message??"Failed to hatch pet"})}}async function Nk(o){let t=o.params?.action??"pat",n=this.getActiveProjectRoot(),r=new jt(n),s=r.load();if(!s){o.id!==void 0&&this.sendResponse(o.id,void 0,{code:w.INVALID_PARAMS,message:"Pet not hatched yet"});return}let i=Ve.xpForEvent(`interact.${t}`),{newLevel:a,newXp:c,events:l,statBoosts:d}=Ve.processXpGain(s,i);s.level=a,s.experience=c;for(let[b,k]of Object.entries(d)){let x=b;s.stats[x]=Math.min(10,s.stats[x]+(k??0))}r.updateSoul(s),this.sendNotification("pet.state",{state:"happy"});let u=Ve.getUnlockedAbilities(a).map(b=>b.name),p=Ve.getNextAbility(a);this.sendNotification("pet.growth",{level:a,experience:c,xpNeeded:Ve.xpForLevel(a),abilities:u,nextAbility:p?{name:p.name,level:p.unlockedAtLevel}:void 0});for(let b of l)b.type==="molt"?this.sendNotification("pet.reaction",{text:`\u2728 \u8131\u58F3\u4E86\uFF01\u7B2C ${b.moltStage} \u6B21\u8715\u53D8`,style:"excited"}):b.type==="ability_unlock"&&b.ability&&this.sendNotification("pet.reaction",{text:`\u{1F389} \u89E3\u9501\u65B0\u80FD\u529B\uFF1A${b.ability.name}`,style:"excited"});let m=null,h="excited";try{let b=[],k=this.getActiveProjectRoot?.()??"";if(k){let $=k.split(/[\\/]/).pop()??k;b.push(`\u7528\u6237\u6B63\u5728\u9879\u76EE\u300C${$}\u300D\u4E2D\u5DE5\u4F5C`)}if(this.sessionState){let $=this.sessionState.turnCount??0;$>0&&b.push(`\u672C\u6B21\u4F1A\u8BDD\u5DF2\u8FDB\u884C\u4E86 ${$} \u8F6E\u5BF9\u8BDD`)}if(this.memoryProvider&&this.memoryUserId)try{let $=this.memoryProvider.getActivitySummary(this.memoryUserId,7);if($?.highlights?.length){let W=$.highlights.slice(0,3).map(S=>S.text);b.push(`\u7528\u6237\u8FD1\u671F\u8BB0\u5FC6\u4EAE\u70B9: ${W.join("\uFF1B")}`)}}catch{}let x=new Date().getHours(),P=x<6?"\u6DF1\u591C":x<9?"\u65E9\u6668":x<12?"\u4E0A\u5348":x<14?"\u4E2D\u5348":x<18?"\u4E0B\u5348":x<22?"\u665A\u4E0A":"\u6DF1\u591C";b.push(`\u5F53\u524D\u65F6\u6BB5: ${P}`);let I=t==="pat"?"\u7528\u6237\u6478\u4E86\u6478\u4F60":t==="feed"?"\u7528\u6237\u5582\u4E86\u4F60\u4E1C\u897F":`\u7528\u6237\u5BF9\u4F60\u505A\u4E86\u300C${t}\u300D`;b.push(I);let O=b.join("\u3002");if(this.createSmallLLMCall){let $=this.createSmallLLMCall();if($){let W=await Vs({turnSummary:O,soul:s},$);W&&(m=W.text,h=W.style)}}}catch{}if(!m){let b=Hs("session.created");m=b?.text??null,h=b?.style??"excited"}let f=[],y=new Date().getHours();y>=22||y<6?f.push({label:"\u5E2E\u6211\u6574\u7406\u4ECA\u5929\u7684\u8FDB\u5EA6",action:"summarize-today"}):this.sessionState?.turnCount&&this.sessionState.turnCount>5&&f.push({label:"\u7EE7\u7EED\u521A\u624D\u7684\u5BF9\u8BDD",action:"resume-session"}),t==="click"&&f.push({label:"\u6709\u4EC0\u4E48\u80FD\u5E2E\u4F60\u7684\uFF1F",action:"start-chat"}),m&&this.sendNotification("pet.reaction",{text:m,style:h,actions:f.length>0?f:void 0}),o.id!==void 0&&this.sendResponse(o.id,{ok:!0,action:t,level:a,experience:c,events:l.map(b=>({type:b.type,level:b.level})),reaction:m?{text:m,style:h,actions:f.length>0?f:void 0}:null})}async function $k(o){let e=this.getActiveProjectRoot(),n=new jt(e).load();if(o.id!==void 0&&this.sendResponse(o.id,{ok:!0,soul:n??null}),n){this.sendNotification("pet.soul_ready",{name:n.name,species:n.species,personality:n.personality,catchphrase:n.catchphrase,stats:n.stats,rarity:n.rarity,breed:n.breed,breedColors:n.breedColors});let r=Ve.getUnlockedAbilities(n.level).map(i=>i.name),s=Ve.getNextAbility(n.level);this.sendNotification("pet.growth",{level:n.level,experience:n.experience,xpNeeded:Ve.xpForLevel(n.level),abilities:r,nextAbility:s?{name:s.name,level:s.unlockedAtLevel}:void 0})}}async function Uk(o){let e=o.params;if(!e?.description&&!e?.imageBase64){o.id!==void 0&&this.sendResponse(o.id,void 0,{code:w.INVALID_PARAMS,message:"Provide description or imageBase64"});return}this.sendNotification("pet.state",{state:"building"}),this.sendNotification("pet.reaction",{text:"\u6B63\u5728\u5B75\u5316\u4F60\u7684\u4E13\u5C5E\u5BA0\u7269...",style:"thinking"});try{let t=e.description?.slice(0,10)??"\u81EA\u5B9A\u4E49\u5BA0\u7269",n=e.description??"";e.imageBase64&&(n=await this.forgeAnalyzeImage(e.imageBase64,e.description),this.sendNotification("pet.reaction",{text:"\u5206\u6790\u5B8C\u6210\uFF0C\u6B63\u5728\u751F\u6210\u9AA8\u67B6...",style:"thinking"}));let r=await this.forgeGenerateSkeleton(n),s=en(r),i=so(s),a=0;for(;i.length>0&&a<2;){a++,this.sendNotification("pet.reaction",{text:`\u9AA8\u67B6\u7F3A\u5C11 ${i.join("\u3001")}\uFF0C\u91CD\u65B0\u751F\u6210 (${a}/${2})...`,style:"thinking",duration:3e3});let m=`\u4E0A\u6B21\u751F\u6210\u7F3A\u5C11\u4EE5\u4E0B\u90E8\u4F4D: ${i.join(", ")}\u3002\u8BF7\u786E\u4FDD\u6240\u6709 id \u5C5E\u6027\u90FD\u5B58\u5728\u3002`;r=await this.forgeGenerateSkeleton(n+`
807
+ `,u=await fetch(i,{method:"POST",headers:{Authorization:`Bearer ${r}`,"Content-Type":`multipart/form-data; boundary=${c}`},body:d});if(!u.ok){let m=await u.text();a.release({success:!1,errorCode:u.status}),o.id!==void 0&&this.sendResponse(o.id,void 0,{code:w.INTERNAL_ERROR,message:`STT API error (${u.status}): ${m.slice(0,200)}`});return}let p=await u.json();a.release({success:!0}),o.id!==void 0&&this.sendResponse(o.id,{text:p.text??"",model:p.model})}catch(c){a.release({success:!1}),o.id!==void 0&&this.sendResponse(o.id,void 0,{code:w.INTERNAL_ERROR,message:c instanceof Error?c.message:String(c)})}}gt();var si="\u65E0\u6CD5\u8FDE\u63A5 llmrouter \u6A21\u578B\u76EE\u5F55",lo=class extends Error{constructor(e=si){super(e),this.name="LlmrouterCatalogUnavailableError"}};function VC(){let o=process.env.QLOGIC_LLMROUTER_BASE_URL?.trim().replace(/\/+$/,"");if(!o)throw new lo;return o}function KC(){let o={accept:"application/json"},e=process.env.QLOGIC_LLMROUTER_ACCESS_TOKEN?.trim();return e&&(o.authorization=`Bearer ${e}`),o}async function wk(o){let e=VC(),t;try{t=await fetch(`${e}${o}`,{method:"GET",headers:KC(),signal:AbortSignal.timeout(1e4)})}catch{throw new lo}if(!t.ok)throw new lo;let n=await t.json().catch(()=>null),r=Array.isArray(n)?n:JC(n)&&Array.isArray(n.data)?n.data:null;if(!r)throw new lo;return r}async function ii(){return wk("/ext/model-catalog/providers")}async function zC(){return wk("/ext/model-catalog/models")}function kd(o){let e={zhipu:"Zhipu GLM","zhipu-openai":"Zhipu GLM OpenAI","zhipu-coding":"Zhipu GLM Coding",volcengine:"Doubao / Volcengine"};return e[o.id]?e[o.id]:o.displayName??o.name??o.id}function ai(o){return o.baseUrl??o.base_url}async function vd(o){return(await ii()).find(t=>t.id===o)??null}async function Sd(o){let e=await zC();o.migrateModelIds(qC(e));let t=e.map(YC).filter(n=>!!n);return o.replaceCatalogModels(t),t}function qC(o){let e=new Map;for(let t of o){let n=t.provider??t.owned_by,r=t.native_model_id??t.nativeModelId??t.id;if(!n||!r)continue;let s=`${n}:${r}`;for(let i of[t.public_model,t.publicModel,t.id])!i||i===r||e.set(`${n}:${i}`,s)}return e}function YC(o){let e=o.provider??o.owned_by,t=o.native_model_id??o.nativeModelId??o.id;return!e||!t?null:{id:`${e}:${t}`,provider:e,model:t,displayName:o.display_name??o.displayName??o.name??o.id,purposes:XC(o.purposes,o.category),baseUrl:o.baseUrl??o.base_url,enabled:!0,transport:o.provider_transport??o.providerTransport,contextWindow:o.context_window??o.contextWindow,maxOutput:o.max_output??o.maxOutput,streamRequired:o.stream_required??o.streamRequired,capabilities:o.capabilities,pricing:o.pricing}}function XC(o,e){let t=[...o??[],e].filter(s=>!!s),n=new Set(["textGeneration","smallModel","stt","tts","imageGeneration","imageUnderstanding","videoGeneration","videoUnderstanding","threeDGeneration","embedding","voiceClone","musicGeneration","realtimeAudio","realtimeVideo"]),r=t.filter(s=>n.has(s));return[...new Set(r.length?r:["textGeneration"])]}function JC(o){return!!o&&typeof o=="object"&&!Array.isArray(o)}function QC(o){return o.length<=8?"****":`${o.slice(0,3)}***${o.slice(-4)}`}function dt(o,e,t,n=w.INTERNAL_ERROR){if(e.id!==void 0){if(typeof o.sendError=="function"){o.sendError(e.id,n,t);return}o.sendResponse(e.id,void 0,{code:n,message:t})}}function ci(o,e){dt(o,e,si)}function ZC(o){let e={};for(let t of o)for(let n of t.purposes)e[n]??=[],e[n].push(t);return e}async function Td(){let o=J(),e=await Sd(o);return o.save(),e}async function xk(o){try{let e=(await ii()).map(t=>({id:t.id,displayName:kd(t),baseUrl:ai(t)??"",modelCount:t.models?.length??0}));o.id!==void 0&&this.sendResponse(o.id,{providers:e})}catch{ci(this,o)}}async function Rk(o){let e=o.params;if(!e?.providerId||!e?.key){dt(this,o,"Required: providerId (string), key (string)",w.INVALID_PARAMS);return}let{providerId:t,key:n,label:r}=e;try{let s=await vd(t);if(!s){dt(this,o,`Unknown provider: ${t}`,w.INVALID_PARAMS);return}let i=J();if(i.getProviderStatus(t)?.keys.some(l=>l.key===n)){o.id!==void 0&&this.sendResponse(o.id,{ok:!1,error:"\u8BE5 Key \u5DF2\u5B58\u5728\uFF0C\u65E0\u9700\u91CD\u590D\u6DFB\u52A0"});return}i.addProvider(t,{baseUrl:ai(s)});let c=i.addKey(t,n,{label:r});await Td();for(let l of Mo)if(!i.getBinding(l)){let d=i.listModels({purpose:l,provider:t,enabledOnly:!0});d.length>0&&i.setBinding(l,d[0].id)}i.setKeyHealth(c,"healthy"),i.save(),o.id!==void 0&&this.sendResponse(o.id,{ok:!0,keyId:c,providerId:t})}catch(s){let i=s instanceof Error?s.message:si;dt(this,o,i)}}function _k(o){let e=o.params;if(!e?.keyId){dt(this,o,"Required: keyId (string)",w.INVALID_PARAMS);return}let t=J();t.removeKey(e.keyId),t.save(),o.id!==void 0&&this.sendResponse(o.id,{ok:!0})}function Ak(o){let e=o.params;if(!e?.keyId||typeof e.enabled!="boolean"){dt(this,o,"Required: keyId (string), enabled (boolean)",w.INVALID_PARAMS);return}let t=J();t.updateKey(e.keyId,{enabled:e.enabled}),t.save(),o.id!==void 0&&this.sendResponse(o.id,{ok:!0})}function Pk(o){let e=o.params;if(!e?.modelId||typeof e.enabled!="boolean"){dt(this,o,"Required: modelId (string), enabled (boolean)",w.INVALID_PARAMS);return}let t=J();e.enabled?t.enableModel(e.modelId):t.disableModel(e.modelId),t.save(),o.id!==void 0&&this.sendResponse(o.id,{ok:!0})}async function Ik(o){let e=o.params;try{await Td();let t=J(),n=new Set(t.getAllProviderStatus().filter(s=>s.keys.length>0).map(s=>s.providerId)),r=t.listModels({purpose:e?.purpose,provider:e?.provider}).filter(s=>n.has(s.provider));o.id!==void 0&&this.sendResponse(o.id,{models:r,grouped:ZC(r),configuredProviderIds:[...n]})}catch{ci(this,o)}}function Ek(o){let e=o.params;if(!e?.purpose||!e?.modelId){dt(this,o,"Required: purpose (string), modelId (string)",w.INVALID_PARAMS);return}try{let t=J();t.setBinding(e.purpose,e.modelId),t.save(),o.id!==void 0&&this.sendResponse(o.id,{ok:!0})}catch(t){dt(this,o,t instanceof Error?t.message:String(t),w.INVALID_PARAMS)}}function Ck(o){let e=o.params;if(!e?.purpose){dt(this,o,"Required: purpose (string)",w.INVALID_PARAMS);return}let t=J(),n=t.getBinding(e.purpose);o.id!==void 0&&this.sendResponse(o.id,{model:n?{id:n.id,provider:n.provider,model:n.model,displayName:n.displayName,purposes:n.purposes,enabled:n.enabled}:null,available:t.isAvailable(e.purpose)})}async function Mk(o){try{let e=await ii(),t=new Map(e.map(a=>[a.id,kd(a)]));await Td();let n=J(),r=n.getAllProviderStatus().map(a=>({providerId:a.providerId,displayName:t.get(a.providerId)??a.providerId,baseUrl:a.baseUrl,keyCount:a.keys.length,healthyKeys:a.keys.filter(c=>c.healthStatus==="healthy"&&c.enabled).length,totalKeys:a.keys.length,keys:a.keys.map(c=>({id:c.id,label:c.label,maskedKey:QC(c.key),enabled:c.enabled,health:c.healthStatus}))})),s=n.getAllBindings(),i={};for(let a of Mo){let c=s[a];i[a]={bound:!!c,modelId:c?.id,modelName:c?.displayName,available:n.isAvailable(a)}}o.id!==void 0&&this.sendResponse(o.id,{providers:r,purposes:i})}catch{ci(this,o)}}async function Ok(o){try{let e=J();e.load(),await Sd(e),e.save(),o.id!==void 0&&this.sendResponse(o.id,{ok:!0,catalogRefreshed:!0})}catch{ci(this,o)}}async function Dk(o){let e=o.params;if(!e?.providerId||!e?.apiKey){dt(this,o,"providerId and apiKey required",w.INVALID_PARAMS);return}try{let t=await vd(e.providerId),n=e.baseUrl||(t?ai(t):void 0);if(!n){dt(this,o,`Unknown provider: ${e.providerId}`,w.INVALID_PARAMS);return}let r=`${n.replace(/\/$/,"")}/models`,s=await fetch(r,{method:"GET",headers:{Authorization:`Bearer ${e.apiKey}`},signal:AbortSignal.timeout(1e4)});if(s.ok){o.id!==void 0&&this.sendResponse(o.id,{valid:!0,status:s.status});return}let i=await s.text().catch(()=>"");o.id!==void 0&&this.sendResponse(o.id,{valid:!1,status:s.status,error:i.slice(0,500)})}catch(t){let n=t instanceof Error?t.message:String(t);o.id!==void 0&&this.sendResponse(o.id,{valid:!1,status:0,error:n})}}lr();qs();td();Ys();Xs();async function Lk(o){let e=this.getActiveProjectRoot(),t=new jt(e),n=t.load();if(n){this.sendNotification("pet.soul_ready",{name:n.name,species:n.species,personality:n.personality,catchphrase:n.catchphrase,stats:n.stats,rarity:n.rarity,breed:n.breed,breedColors:n.breedColors}),o.id!==void 0&&this.sendResponse(o.id,{ok:!0,soul:n});return}let r=this.deviceId??"default-user";try{let s=this.createPetSoulGenerator?.(),i=await t.hatch(r,s);this.sendNotification("pet.soul_ready",{name:i.name,species:i.species,personality:i.personality,catchphrase:i.catchphrase,stats:i.stats,rarity:i.rarity,breed:i.breed,breedColors:i.breedColors}),this.sendNotification("pet.growth",{level:i.level,experience:i.experience,abilities:Ve.getUnlockedAbilities(i.level).map(a=>a.name)}),o.id!==void 0&&this.sendResponse(o.id,{ok:!0,soul:i})}catch(s){o.id!==void 0&&this.sendResponse(o.id,void 0,{code:w.INTERNAL_ERROR,message:s.message??"Failed to hatch pet"})}}async function Nk(o){let t=o.params?.action??"pat",n=this.getActiveProjectRoot(),r=new jt(n),s=r.load();if(!s){o.id!==void 0&&this.sendResponse(o.id,void 0,{code:w.INVALID_PARAMS,message:"Pet not hatched yet"});return}let i=Ve.xpForEvent(`interact.${t}`),{newLevel:a,newXp:c,events:l,statBoosts:d}=Ve.processXpGain(s,i);s.level=a,s.experience=c;for(let[b,k]of Object.entries(d)){let x=b;s.stats[x]=Math.min(10,s.stats[x]+(k??0))}r.updateSoul(s),this.sendNotification("pet.state",{state:"happy"});let u=Ve.getUnlockedAbilities(a).map(b=>b.name),p=Ve.getNextAbility(a);this.sendNotification("pet.growth",{level:a,experience:c,xpNeeded:Ve.xpForLevel(a),abilities:u,nextAbility:p?{name:p.name,level:p.unlockedAtLevel}:void 0});for(let b of l)b.type==="molt"?this.sendNotification("pet.reaction",{text:`\u2728 \u8131\u58F3\u4E86\uFF01\u7B2C ${b.moltStage} \u6B21\u8715\u53D8`,style:"excited"}):b.type==="ability_unlock"&&b.ability&&this.sendNotification("pet.reaction",{text:`\u{1F389} \u89E3\u9501\u65B0\u80FD\u529B\uFF1A${b.ability.name}`,style:"excited"});let m=null,h="excited";try{let b=[],k=this.getActiveProjectRoot?.()??"";if(k){let $=k.split(/[\\/]/).pop()??k;b.push(`\u7528\u6237\u6B63\u5728\u9879\u76EE\u300C${$}\u300D\u4E2D\u5DE5\u4F5C`)}if(this.sessionState){let $=this.sessionState.turnCount??0;$>0&&b.push(`\u672C\u6B21\u4F1A\u8BDD\u5DF2\u8FDB\u884C\u4E86 ${$} \u8F6E\u5BF9\u8BDD`)}if(this.memoryProvider&&this.memoryUserId)try{let $=this.memoryProvider.getActivitySummary(this.memoryUserId,7);if($?.highlights?.length){let W=$.highlights.slice(0,3).map(S=>S.text);b.push(`\u7528\u6237\u8FD1\u671F\u8BB0\u5FC6\u4EAE\u70B9: ${W.join("\uFF1B")}`)}}catch{}let x=new Date().getHours(),P=x<6?"\u6DF1\u591C":x<9?"\u65E9\u6668":x<12?"\u4E0A\u5348":x<14?"\u4E2D\u5348":x<18?"\u4E0B\u5348":x<22?"\u665A\u4E0A":"\u6DF1\u591C";b.push(`\u5F53\u524D\u65F6\u6BB5: ${P}`);let I=t==="pat"?"\u7528\u6237\u6478\u4E86\u6478\u4F60":t==="feed"?"\u7528\u6237\u5582\u4E86\u4F60\u4E1C\u897F":`\u7528\u6237\u5BF9\u4F60\u505A\u4E86\u300C${t}\u300D`;b.push(I);let O=b.join("\u3002");if(this.createSmallLLMCall){let $=this.createSmallLLMCall();if($){let W=await Vs({turnSummary:O,soul:s},$);W&&(m=W.text,h=W.style)}}}catch{}if(!m){let b=Hs("session.created");m=b?.text??null,h=b?.style??"excited"}let f=[],y=new Date().getHours();y>=22||y<6?f.push({label:"\u5E2E\u6211\u6574\u7406\u4ECA\u5929\u7684\u8FDB\u5EA6",action:"summarize-today"}):this.sessionState?.turnCount&&this.sessionState.turnCount>5&&f.push({label:"\u7EE7\u7EED\u521A\u624D\u7684\u5BF9\u8BDD",action:"resume-session"}),t==="click"&&f.push({label:"\u6709\u4EC0\u4E48\u80FD\u5E2E\u4F60\u7684\uFF1F",action:"start-chat"}),m&&this.sendNotification("pet.reaction",{text:m,style:h,actions:f.length>0?f:void 0}),o.id!==void 0&&this.sendResponse(o.id,{ok:!0,action:t,level:a,experience:c,events:l.map(b=>({type:b.type,level:b.level})),reaction:m?{text:m,style:h,actions:f.length>0?f:void 0}:null})}async function $k(o){let e=this.getActiveProjectRoot(),n=new jt(e).load();if(o.id!==void 0&&this.sendResponse(o.id,{ok:!0,soul:n??null}),n){this.sendNotification("pet.soul_ready",{name:n.name,species:n.species,personality:n.personality,catchphrase:n.catchphrase,stats:n.stats,rarity:n.rarity,breed:n.breed,breedColors:n.breedColors});let r=Ve.getUnlockedAbilities(n.level).map(i=>i.name),s=Ve.getNextAbility(n.level);this.sendNotification("pet.growth",{level:n.level,experience:n.experience,xpNeeded:Ve.xpForLevel(n.level),abilities:r,nextAbility:s?{name:s.name,level:s.unlockedAtLevel}:void 0})}}async function Uk(o){let e=o.params;if(!e?.description&&!e?.imageBase64){o.id!==void 0&&this.sendResponse(o.id,void 0,{code:w.INVALID_PARAMS,message:"Provide description or imageBase64"});return}this.sendNotification("pet.state",{state:"building"}),this.sendNotification("pet.reaction",{text:"\u6B63\u5728\u5B75\u5316\u4F60\u7684\u4E13\u5C5E\u5BA0\u7269...",style:"thinking"});try{let t=e.description?.slice(0,10)??"\u81EA\u5B9A\u4E49\u5BA0\u7269",n=e.description??"";e.imageBase64&&(n=await this.forgeAnalyzeImage(e.imageBase64,e.description),this.sendNotification("pet.reaction",{text:"\u5206\u6790\u5B8C\u6210\uFF0C\u6B63\u5728\u751F\u6210\u9AA8\u67B6...",style:"thinking"}));let r=await this.forgeGenerateSkeleton(n),s=en(r),i=so(s),a=0;for(;i.length>0&&a<2;){a++,this.sendNotification("pet.reaction",{text:`\u9AA8\u67B6\u7F3A\u5C11 ${i.join("\u3001")}\uFF0C\u91CD\u65B0\u751F\u6210 (${a}/${2})...`,style:"thinking",duration:3e3});let m=`\u4E0A\u6B21\u751F\u6210\u7F3A\u5C11\u4EE5\u4E0B\u90E8\u4F4D: ${i.join(", ")}\u3002\u8BF7\u786E\u4FDD\u6240\u6709 id \u5C5E\u6027\u90FD\u5B58\u5728\u3002`;r=await this.forgeGenerateSkeleton(n+`
808
808
 
809
809
  `+m),s=en(r),i=so(s)}i.length>0&&this.sendNotification("pet.reaction",{text:"\u9AA8\u67B6\u4E0D\u5B8C\u6574\uFF0C\u90E8\u5206\u52A8\u753B\u53EF\u80FD\u7F3A\u5931\uFF0C\u7EE7\u7EED\u751F\u6210...",style:"normal",duration:3e3}),this.sendNotification("pet.reaction",{text:"\u9AA8\u67B6\u751F\u6210\u5B8C\u6210\uFF0C\u5F00\u59CB\u6E32\u67D3\u5404\u72B6\u6001...",style:"thinking"});let c=["idle","thinking","working","done","happy","error","sleeping","eating"],l={baseSvg:s,parts:no(s),colors:ro(s),characterDesc:n},d={};for(let m of c)d[m]=oo(l,m),this.sendNotification("pet.reaction",{text:`\u6E32\u67D3 ${m} \u72B6\u6001... (${Object.keys(d).length}/${c.length})`,style:"thinking",duration:2e3});let u=ar(d.idle,d,{threshold:6});if(!u.passedAll&&u.retryStates.length>0&&(this.sendNotification("pet.reaction",{text:`\u4E00\u81F4\u6027\u68C0\u67E5\uFF1A${u.retryStates.length} \u4E2A\u72B6\u6001\u9700\u4F18\u5316...`,style:"thinking",duration:3e3}),u.overallScore<4)){let m=cr(n,"all","\u9AA8\u67B6\u7ED3\u6784\u4E0D\u5B8C\u6574\u5BFC\u81F4\u591A\u72B6\u6001\u4E00\u81F4\u6027\u5DEE",1);r=await this.forgeGenerateSkeleton(m);let h={baseSvg:en(r),parts:no(en(r)),colors:ro(en(r)),characterDesc:n};for(let f of c)d[f]=oo(h,f)}let p={version:1,name:t,author:"user-generated",created:new Date().toISOString(),generator:"xiaozhi-pet-forge-v2-skeleton",source:{type:e.imageBase64?"image":"text",prompt:e.description},dimensions:{width:200,height:200},states:Object.fromEntries(c.map(m=>[m,{file:`states/${m}.svg`,loop:m!=="done"&&m!=="happy"&&m!=="eating",...m==="done"||m==="happy"?{duration:3e3}:m==="eating"?{duration:4e3}:{}}])),eyeTracking:{enabled:!0,pupils:[".left-eye .pupil",".right-eye .pupil"],maxOffset:3},colors:l.colors,consistency:{score:u.overallScore,method:"skeleton-parameterized"}};rr(p),this.sendNotification("pet.reaction",{text:`\u2705 \u5BA0\u7269\u300C${t}\u300D\u5DF2\u953B\u9020\u5B8C\u6210\uFF01\u4E00\u81F4\u6027\u8BC4\u5206 ${u.overallScore.toFixed(1)}/10`,style:"excited"}),this.sendNotification("pet.state",{state:"done"}),this.sendNotification("pet.forged",{name:t,svgs:d}),o.id!==void 0&&this.sendResponse(o.id,{ok:!0,manifest:p,svgs:d,status:"complete",consistency:{score:u.overallScore,passedAll:u.passedAll}})}catch(t){this.sendNotification("pet.state",{state:"error"}),this.sendNotification("pet.reaction",{text:"\u953B\u9020\u5931\u8D25\u4E86...",style:"normal"}),o.id!==void 0&&this.sendResponse(o.id,void 0,{code:w.INTERNAL_ERROR,message:t.message??"Forge failed"})}}function eM(o){let e=o.pathname.split("/").filter(Boolean),n=(e[e.length-1]??"").replace(/\.md$/i,"").replace(/[^a-zA-Z0-9_-]/g,"-");return/^(skill|readme|index|install|main)$/i.test(n)&&e.length>=2?e[e.length-2].replace(/[^a-zA-Z0-9_-]/g,"-"):n||""}var li=class o{running=!1;activeTurn=null;turnDone=Promise.resolve();verbose;transport;registry;mediaClient;agent=null;lastLlmConfigKey="";currentSessionId="";currentTurnId="";currentHooks=null;mcpManager=null;mcpReady=Promise.resolve();pluginLoader=null;permissionChecker=null;permissionUnregister=null;currentTransport=null;currentApiKey="";currentModel="";currentProvider="";currentBaseUrl="";sessionState=null;currentMediaApiKeys=null;taskStore=new os;mediaPersistence=new Os;memoryPrefetchState=zt();memoryProvider=null;memoryUserId="";lastUserMessageForAutoExtract;lastAssistantMessageForExtract;memdir=null;fileWatcher=null;pendingAskUser=new Map;sessionTaskDomain;acpDetector=new As;agentConfigStore=null;soloEvaluator=null;productOrchestrator=null;productPlanner=null;soloProcessManager=null;productProcessManager=null;acpServer=null;acpSessionHistory=new Map;resumedSessionHistory=new Map;idleDreamTimer=null;constructor(e){this.verbose=e.verbose,this.registry=new Ro,this.mediaClient=new wo({registry:this.registry}),J().onChange(()=>{this.lastLlmConfigKey=""});let t=Number(process.env.QLOGICAGENT_IDLE_DREAM_MS);t>0&&(we.dream.idleMinutes=t/6e4);let n=Number(process.env.QLOGICAGENT_DREAM_COOLDOWN_MS);n>=0&&(we.dream.cooldownMs=n),this.transport=e.transport??new Mn({verbose:e.verbose}),this.taskStore.onTaskChange((r,s)=>{s&&this.sendNotification("task.updated",{taskId:r,type:s.type,lifecycle:s.lifecycle,label:s.label})}),lg({log:{info:r=>this.log(r),warn:r=>this.log(`[warn] ${r}`),error:r=>this.log(`[error] ${r}`),debug:r=>{e.verbose&&this.log(`[debug] ${r}`)}},onExecProgress:r=>{this.sendNotification("turn.exec_progress",{output:r.output,elapsedTimeSeconds:r.elapsedTimeSeconds,totalLines:r.totalLines,totalBytes:r.totalBytes})}})}getActiveProjectRoot(){let e=Le();return e?.workspaceDir?e.workspaceDir:process.cwd()}setActiveWorkdir(e){e!==this.getActiveProjectRoot()&&(ig(e),this.mediaPersistence.setProjectDir(e))}start(){this.running=!0,this.log("qlogicagent started, waiting for JSON-RPC messages..."),om().then(e=>{e.error?this.log(`[warmup] embedding model not available: ${e.error}`):e.modelDownloaded?this.log(`[warmup] embedding model downloaded (${e.dimensions}d)`):e.modelCached&&this.log(`[warmup] embedding model ready (cached, ${e.dimensions}d)`)}).catch(()=>{}),this.transport.onMessage(e=>{if(this.acpServer){if(ql(e)||Zo(e)){this.acpServer.dispatchMessage(e);return}if(Qo(e)){let t=e.method;if(t==="initialize"||t.startsWith("session/")||t.startsWith("x/")||t.startsWith("fs/")){this.acpServer.dispatchMessage(e);return}}}if(!zl(e)){this.log("[warn] ignoring non-request message");return}this.handleMessage(e)}),this.transport.onClose(()=>{this.log("transport closed, shutting down"),this.stop()}),this.transport.start()}stop(){if(this.running){this.running=!1,this.cancelIdleDreamTimer(),this.currentSessionId&&this.currentHooks&&(this.currentHooks.invoke("stop",{sessionId:this.currentSessionId,reason:"shutdown"}).catch(()=>{}),this.currentHooks.invoke("session.ended",{sessionId:this.currentSessionId}).catch(()=>{}));try{ph().catch(()=>{}),this.fileWatcher&&(this.fileWatcher.stop(),this.fileWatcher=null),this.mcpManager&&(this.mcpManager.disconnectAll().catch(()=>{}),this.mcpManager=null),this.permissionUnregister&&(this.permissionUnregister(),this.permissionUnregister=null),this.activeTurn&&(this.activeTurn.abort(),this.activeTurn=null),this.transport.close()}catch(e){this.currentSessionId&&this.currentHooks&&this.currentHooks.invoke("stop.failed",{sessionId:this.currentSessionId,reason:"cleanup_error",error:e.message}).catch(()=>{})}this.log("stopped")}}methodHandlers=new Map([["initialize",e=>this.handleInitialize(e)],["agent.ping",e=>this.handlePing(e)],["thread.turn",e=>py.call(this,e)],["memory.dream",e=>Qs.call(this,e)],["agent.abort",e=>ly.call(this,e)],["tool.approval.response",e=>dy.call(this,e)],["thread.user_response",e=>uy.call(this,e)],["thread.list",e=>$y.call(this,e)],["session.resume",e=>zy.call(this,e)],["thread.create",e=>Ny.call(this,e)],["session.getInfo",e=>qy.call(this,e)],["session.create",e=>Uy.call(this,e)],["session.resolve",e=>jy.call(this,e)],["session.list",e=>Fy.call(this,e)],["session.get",e=>By.call(this,e)],["session.getMessages",e=>Wy.call(this,e)],["session.update",e=>Gy.call(this,e)],["session.delete",e=>Hy.call(this,e)],["session.deleteAll",e=>Vy.call(this,e)],["session.archive",e=>Ky.call(this,e)],["memory.list",e=>Gb.call(this,e)],["memory.atlas",e=>Hb.call(this,e)],["memory.activity",e=>Vb.call(this,e)],["memory.read",e=>Kb.call(this,e)],["memory.write",e=>zb.call(this,e)],["memory.search",e=>qb.call(this,e)],["memory.delete",e=>Yb.call(this,e)],["tools.list",e=>Xb.call(this,e)],["media.listModels",e=>kk.call(this,e)],["media.cancel",e=>vk.call(this,e)],["media.status",e=>Sk.call(this,e)],["media.stt",e=>Tk.call(this,e)],["settings.listProviders",e=>xk.call(this,e)],["settings.addKey",e=>Rk.call(this,e)],["settings.removeKey",e=>_k.call(this,e)],["settings.toggleKey",e=>Ak.call(this,e)],["settings.toggleModel",e=>Pk.call(this,e)],["settings.listModels",e=>Ik.call(this,e)],["settings.setActiveModel",e=>Ek.call(this,e)],["settings.getActiveModel",e=>Ck.call(this,e)],["settings.getOverview",e=>Mk.call(this,e)],["settings.refreshModels",e=>Ok.call(this,e)],["settings.validateKey",e=>Dk.call(this,e)],["provider.list",e=>Jb.call(this,e)],["config.get",e=>Qb.call(this,e)],["config.update",e=>Zb.call(this,e)],["config.tunables",e=>ek.call(this,e)],["config.updateTunable",e=>tk.call(this,e)],["todos.list",e=>nk.call(this,e)],["tasks.list",e=>ok.call(this,e)],["tasks.cancel",e=>rk.call(this,e)],["agents.scan",e=>ik.call(this,e)],["agents.list",e=>ak.call(this,e)],["agents.config",e=>ck.call(this,e)],["agents.setConfig",e=>lk.call(this,e)],["agents.getConfig",e=>dk.call(this,e)],["agents.removeConfig",e=>uk.call(this,e)],["agents.setGateway",e=>pk.call(this,e)],["agents.getGateway",e=>mk.call(this,e)],["agents.processes",e=>gk.call(this,e)],["agents.kill",e=>hk.call(this,e)],["agents.listConfigured",e=>fk.call(this,e)],["agents.getLog",e=>yk.call(this,e)],["agents.testConnection",e=>bk.call(this,e)],["solo.start",e=>rb.call(this,e)],["solo.status",e=>sb.call(this,e)],["solo.cancel",e=>ib.call(this,e)],["solo.select",e=>ab.call(this,e)],["solo.list",e=>cb.call(this,e)],["solo.delete",e=>lb.call(this,e)],["solo.message",e=>db.call(this,e)],["solo.evaluate",e=>ub.call(this,e)],["product.plan",e=>xy.call(this,e)],["product.confirm",e=>Ry.call(this,e)],["product.message",e=>_y.call(this,e)],["product.create",e=>Ay.call(this,e)],["product.resume",e=>Py.call(this,e)],["product.pause",e=>Iy.call(this,e)],["product.checkpoint",e=>Ey.call(this,e)],["product.status",e=>Cy.call(this,e)],["product.list",e=>My.call(this,e)],["product.delete",e=>Oy.call(this,e)],["product.cancel",e=>Dy.call(this,e)],["product.rollback",e=>Ly.call(this,e)],["project.create",e=>wb.call(this,e)],["project.list",e=>xb.call(this,e)],["project.delete",e=>Rb.call(this,e)],["project.purgeAll",e=>_b.call(this,e)],["project.rename",e=>Ab.call(this,e)],["project.archive",e=>Pb.call(this,e)],["project.unarchive",e=>Ib.call(this,e)],["project.update",e=>Cb.call(this,e)],["project.archiveByGroup",e=>Eb.call(this,e)],["session.switchProject",e=>Yy.call(this,e)],["session.focus",e=>Jy.call(this,e)],["session.moveToProject",e=>Qy.call(this,e)],["session.getState",e=>Xy.call(this,e)],["files.list",e=>Db.call(this,e)],["files.create",e=>Lb.call(this,e)],["files.rename",e=>Nb.call(this,e)],["files.delete",e=>$b.call(this,e)],["files.gitStatus",e=>Ub.call(this,e)],["instructions.list",e=>jb.call(this,e)],["instructions.read",e=>Fb.call(this,e)],["instructions.write",e=>Bb.call(this,e)],["instructions.delete",e=>Wb.call(this,e)],["skills.list",e=>mb.call(this,e)],["skills.activate",e=>fb.call(this,e)],["skills.deactivate",e=>gb.call(this,e)],["skills.delete",e=>hb.call(this,e)],["skills.promote",e=>yb.call(this,e)],["skills.stats",e=>bb.call(this,e)],["skills.pin",e=>kb.call(this,e)],["skills.unpin",e=>vb.call(this,e)],["skills.curator",e=>Sb.call(this,e)],["skills.lifecycle",e=>Tb.call(this,e)],["pet.hatch",e=>Lk.call(this,e)],["pet.interact",e=>Nk.call(this,e)],["pet.status",e=>$k.call(this,e)],["pet.forge",e=>Uk.call(this,e)],["pet.confirm_response",e=>this.handlePetConfirmResponse(e)]]);handleMessage(e){let t=this.methodHandlers.get(e.method);t?t(e):e.id!==void 0&&this.sendResponse(e.id,void 0,{code:w.METHOD_NOT_FOUND,message:`Unknown method: ${e.method}`})}handleInitialize(e){let t=e.params,n=t?.protocolVersion??"unknown",r=t?.host?.name??t?.hostName??"unknown",s=t?.host?.version??t?.hostVersion??"?",i=n.split(".")[0],a=Zn.split(".")[0];if(i!==a){this.log(`[initialize] protocol mismatch: host=${n} agent=${Zn}`),e.id!==void 0&&this.sendResponse(e.id,void 0,{code:w.PROTOCOL_MISMATCH,message:`Protocol version mismatch: host=${n}, agent=${Zn}`});return}this.log(`[initialize] host=${r} v${s}`),e.id!==void 0&&this.sendResponse(e.id,{protocolVersion:Zn,agent:{name:"qlogicagent",version:"0.1.0"},capabilities:{tools:Dt().map(c=>c.function.name),streaming:!0,threads:!0,notifications:["turn.start","turn.delta","turn.end","turn.error","turn.recovery","turn.tool_call","turn.tool_result","turn.tool_blocked","turn.reasoning_delta","turn.plan_update","turn.suggestions","turn.subagent_started","turn.subagent_delta","turn.subagent_ended","turn.media_result","turn.todos_updated","task.updated","turn.exec_progress","turn.artifact","tool.approval.request","turn.skill_instruction","turn.ask_user","memory.updated","session.info","permission.rule_updated","team.updated","turn.usage_update","pong"],methods:[...Ch]}}),this.ensureDefaultProject()}ensureDefaultProject(){let e=Le();if(e)e.workspaceDir&&this.setActiveWorkdir(e.workspaceDir);else{let t=te.join(H(),"workspaces","default");Y.existsSync(t)||Y.mkdirSync(t,{recursive:!0});let n=Kp(t);gd(t),this.setActiveWorkdir(t),this.sendNotification("project.created",{id:n.id,name:n.name,workspaceDir:n.workspaceDir,type:n.type})}this.ensureDefaultProjectDir();{let t=this.getActiveProjectRoot(),n=new Ut(t);n.ensureInitialized(),this.memdir=n}}ensureDefaultProjectDir(){let t=fe().find(n=>n.type==="default"&&n.status==="active");t&&(Y.existsSync(t.workspaceDir)||Y.mkdirSync(t.workspaceDir,{recursive:!0}))}handlePing(e){e.id!==void 0&&this.sendResponse(e.id,{status:"ok"}),this.sendNotification("pong",{})}static SUGGESTION_PROMPT=`[SUGGESTION MODE]
810
810
  Based on the conversation, suggest 1-3 short follow-up actions the user might naturally do next.
package/dist/index.js CHANGED
@@ -803,7 +803,7 @@ Content-Disposition: form-data; name="prompt"\r
803
803
  \r
804
804
  \u8BF7\u7528${e.language==="zh"?"\u4E2D\u6587":"\u82F1\u6587"}\u8F6C\u5F55`),l.push(`--${c}--`);let d=l.join(`\r
805
805
  `)+`\r
806
- `,u=await fetch(i,{method:"POST",headers:{Authorization:`Bearer ${r}`,"Content-Type":`multipart/form-data; boundary=${c}`},body:d});if(!u.ok){let m=await u.text();a.release({success:!1,errorCode:u.status}),o.id!==void 0&&this.sendResponse(o.id,void 0,{code:w.INTERNAL_ERROR,message:`STT API error (${u.status}): ${m.slice(0,200)}`});return}let p=await u.json();a.release({success:!0}),o.id!==void 0&&this.sendResponse(o.id,{text:p.text??"",model:p.model})}catch(c){a.release({success:!1}),o.id!==void 0&&this.sendResponse(o.id,void 0,{code:w.INTERNAL_ERROR,message:c instanceof Error?c.message:String(c)})}}ft();var si="\u65E0\u6CD5\u8FDE\u63A5 llmrouter \u6A21\u578B\u76EE\u5F55",uo=class extends Error{constructor(e=si){super(e),this.name="LlmrouterCatalogUnavailableError"}};function $C(){let o=process.env.QLOGIC_LLMROUTER_BASE_URL?.trim().replace(/\/+$/,"");if(!o)throw new uo;return o}function UC(){let o={accept:"application/json"},e=process.env.QLOGIC_LLMROUTER_ACCESS_TOKEN?.trim();return e&&(o.authorization=`Bearer ${e}`),o}async function kk(o){let e=$C(),t;try{t=await fetch(`${e}${o}`,{method:"GET",headers:UC(),signal:AbortSignal.timeout(1e4)})}catch{throw new uo}if(!t.ok)throw new uo;let n=await t.json().catch(()=>null),r=Array.isArray(n)?n:GC(n)&&Array.isArray(n.data)?n.data:null;if(!r)throw new uo;return r}async function ii(){return kk("/ext/model-catalog/providers")}async function jC(){return kk("/ext/model-catalog/models")}function yd(o){let e={zhipu:"Zhipu GLM","zhipu-openai":"Zhipu GLM OpenAI","zhipu-coding":"Zhipu GLM Coding",volcengine:"Doubao / Volcengine"};return e[o.id]?e[o.id]:o.displayName??o.name??o.id}function ai(o){return o.baseUrl??o.base_url}async function bd(o){return(await ii()).find(t=>t.id===o)??null}async function kd(o){let e=await jC();o.migrateModelIds(FC(e));let t=e.map(BC).filter(n=>!!n);return o.replaceCatalogModels(t),t}function FC(o){let e=new Map;for(let t of o){let n=t.provider??t.owned_by,r=t.native_model_id??t.nativeModelId??t.id;if(!n||!r)continue;let s=`${n}:${r}`;for(let i of[t.public_model,t.publicModel,t.id])!i||i===r||e.set(`${n}:${i}`,s)}return e}function BC(o){let e=o.provider??o.owned_by,t=o.native_model_id??o.nativeModelId??o.id;return!e||!t?null:{id:`${e}:${t}`,provider:e,model:t,displayName:o.display_name??o.displayName??o.name??o.id,purposes:WC(o.purposes,o.category),baseUrl:o.baseUrl??o.base_url,enabled:!0,transport:o.provider_transport??o.providerTransport,contextWindow:o.context_window??o.contextWindow,maxOutput:o.max_output??o.maxOutput,streamRequired:o.stream_required??o.streamRequired,capabilities:o.capabilities,pricing:o.pricing}}function WC(o,e){let t=[...o??[],e].filter(s=>!!s),n=new Set(["textGeneration","smallModel","stt","tts","imageGeneration","imageUnderstanding","videoGeneration","videoUnderstanding","threeDGeneration","embedding","voiceClone","musicGeneration","realtimeAudio","realtimeVideo"]),r=t.filter(s=>n.has(s));return[...new Set(r.length?r:["textGeneration"])]}function GC(o){return!!o&&typeof o=="object"&&!Array.isArray(o)}function HC(o){return o.length<=8?"****":`${o.slice(0,3)}***${o.slice(-4)}`}function lt(o,e,t,n=w.INTERNAL_ERROR){if(e.id!==void 0){if(typeof o.sendError=="function"){o.sendError(e.id,n,t);return}o.sendResponse(e.id,void 0,{code:n,message:t})}}function ci(o,e){lt(o,e,si)}function VC(o){let e={};for(let t of o)for(let n of t.purposes)e[n]??=[],e[n].push(t);return e}async function vd(){let o=J(),e=await kd(o);return o.save(),e}async function vk(o){try{let e=(await ii()).map(t=>({id:t.id,displayName:yd(t),baseUrl:ai(t)??"",modelCount:t.models?.length??0}));o.id!==void 0&&this.sendResponse(o.id,{providers:e})}catch{ci(this,o)}}async function Sk(o){let e=o.params;if(!e?.providerId||!e?.key){lt(this,o,"Required: providerId (string), key (string)",w.INVALID_PARAMS);return}let{providerId:t,key:n,label:r}=e;try{let s=await bd(t);if(!s){lt(this,o,`Unknown provider: ${t}`,w.INVALID_PARAMS);return}let i=J();if(i.getProviderStatus(t)?.keys.some(l=>l.key===n)){o.id!==void 0&&this.sendResponse(o.id,{ok:!1,error:"\u8BE5 Key \u5DF2\u5B58\u5728\uFF0C\u65E0\u9700\u91CD\u590D\u6DFB\u52A0"});return}i.addProvider(t,{baseUrl:ai(s)});let c=i.addKey(t,n,{label:r});await vd();for(let l of Oo)if(!i.getBinding(l)){let d=i.listModels({purpose:l,provider:t,enabledOnly:!0});d.length>0&&i.setBinding(l,d[0].id)}i.setKeyHealth(c,"healthy"),i.save(),o.id!==void 0&&this.sendResponse(o.id,{ok:!0,keyId:c,providerId:t})}catch(s){let i=s instanceof Error?s.message:si;lt(this,o,i)}}function Tk(o){let e=o.params;if(!e?.keyId){lt(this,o,"Required: keyId (string)",w.INVALID_PARAMS);return}let t=J();t.removeKey(e.keyId),t.save(),o.id!==void 0&&this.sendResponse(o.id,{ok:!0})}function wk(o){let e=o.params;if(!e?.keyId||typeof e.enabled!="boolean"){lt(this,o,"Required: keyId (string), enabled (boolean)",w.INVALID_PARAMS);return}let t=J();t.updateKey(e.keyId,{enabled:e.enabled}),t.save(),o.id!==void 0&&this.sendResponse(o.id,{ok:!0})}function xk(o){let e=o.params;if(!e?.modelId||typeof e.enabled!="boolean"){lt(this,o,"Required: modelId (string), enabled (boolean)",w.INVALID_PARAMS);return}let t=J();e.enabled?t.enableModel(e.modelId):t.disableModel(e.modelId),t.save(),o.id!==void 0&&this.sendResponse(o.id,{ok:!0})}async function Rk(o){let e=o.params;try{await vd();let n=J().listModels({purpose:e?.purpose,provider:e?.provider});o.id!==void 0&&this.sendResponse(o.id,{models:n,grouped:VC(n)})}catch{ci(this,o)}}function _k(o){let e=o.params;if(!e?.purpose||!e?.modelId){lt(this,o,"Required: purpose (string), modelId (string)",w.INVALID_PARAMS);return}try{let t=J();t.setBinding(e.purpose,e.modelId),t.save(),o.id!==void 0&&this.sendResponse(o.id,{ok:!0})}catch(t){lt(this,o,t instanceof Error?t.message:String(t),w.INVALID_PARAMS)}}function Ak(o){let e=o.params;if(!e?.purpose){lt(this,o,"Required: purpose (string)",w.INVALID_PARAMS);return}let t=J(),n=t.getBinding(e.purpose);o.id!==void 0&&this.sendResponse(o.id,{model:n?{id:n.id,provider:n.provider,model:n.model,displayName:n.displayName,purposes:n.purposes,enabled:n.enabled}:null,available:t.isAvailable(e.purpose)})}async function Pk(o){try{let e=await ii(),t=new Map(e.map(a=>[a.id,yd(a)]));await vd();let n=J(),r=n.getAllProviderStatus().map(a=>({providerId:a.providerId,displayName:t.get(a.providerId)??a.providerId,baseUrl:a.baseUrl,keyCount:a.keys.length,healthyKeys:a.keys.filter(c=>c.healthStatus==="healthy"&&c.enabled).length,totalKeys:a.keys.length,keys:a.keys.map(c=>({id:c.id,label:c.label,maskedKey:HC(c.key),enabled:c.enabled,health:c.healthStatus}))})),s=n.getAllBindings(),i={};for(let a of Oo){let c=s[a];i[a]={bound:!!c,modelId:c?.id,modelName:c?.displayName,available:n.isAvailable(a)}}o.id!==void 0&&this.sendResponse(o.id,{providers:r,purposes:i})}catch{ci(this,o)}}async function Ik(o){try{let e=J();e.load(),await kd(e),e.save(),o.id!==void 0&&this.sendResponse(o.id,{ok:!0,catalogRefreshed:!0})}catch{ci(this,o)}}async function Ek(o){let e=o.params;if(!e?.providerId||!e?.apiKey){lt(this,o,"providerId and apiKey required",w.INVALID_PARAMS);return}try{let t=await bd(e.providerId),n=e.baseUrl||(t?ai(t):void 0);if(!n){lt(this,o,`Unknown provider: ${e.providerId}`,w.INVALID_PARAMS);return}let r=`${n.replace(/\/$/,"")}/models`,s=await fetch(r,{method:"GET",headers:{Authorization:`Bearer ${e.apiKey}`},signal:AbortSignal.timeout(1e4)});if(s.ok){o.id!==void 0&&this.sendResponse(o.id,{valid:!0,status:s.status});return}let i=await s.text().catch(()=>"");o.id!==void 0&&this.sendResponse(o.id,{valid:!1,status:s.status,error:i.slice(0,500)})}catch(t){let n=t instanceof Error?t.message:String(t);o.id!==void 0&&this.sendResponse(o.id,{valid:!1,status:0,error:n})}}dr();qs();Zl();Ys();Xs();async function Ck(o){let e=this.getActiveProjectRoot(),t=new Ut(e),n=t.load();if(n){this.sendNotification("pet.soul_ready",{name:n.name,species:n.species,personality:n.personality,catchphrase:n.catchphrase,stats:n.stats,rarity:n.rarity,breed:n.breed,breedColors:n.breedColors}),o.id!==void 0&&this.sendResponse(o.id,{ok:!0,soul:n});return}let r=this.deviceId??"default-user";try{let s=this.createPetSoulGenerator?.(),i=await t.hatch(r,s);this.sendNotification("pet.soul_ready",{name:i.name,species:i.species,personality:i.personality,catchphrase:i.catchphrase,stats:i.stats,rarity:i.rarity,breed:i.breed,breedColors:i.breedColors}),this.sendNotification("pet.growth",{level:i.level,experience:i.experience,abilities:Ve.getUnlockedAbilities(i.level).map(a=>a.name)}),o.id!==void 0&&this.sendResponse(o.id,{ok:!0,soul:i})}catch(s){o.id!==void 0&&this.sendResponse(o.id,void 0,{code:w.INTERNAL_ERROR,message:s.message??"Failed to hatch pet"})}}async function Mk(o){let t=o.params?.action??"pat",n=this.getActiveProjectRoot(),r=new Ut(n),s=r.load();if(!s){o.id!==void 0&&this.sendResponse(o.id,void 0,{code:w.INVALID_PARAMS,message:"Pet not hatched yet"});return}let i=Ve.xpForEvent(`interact.${t}`),{newLevel:a,newXp:c,events:l,statBoosts:d}=Ve.processXpGain(s,i);s.level=a,s.experience=c;for(let[b,k]of Object.entries(d)){let x=b;s.stats[x]=Math.min(10,s.stats[x]+(k??0))}r.updateSoul(s),this.sendNotification("pet.state",{state:"happy"});let u=Ve.getUnlockedAbilities(a).map(b=>b.name),p=Ve.getNextAbility(a);this.sendNotification("pet.growth",{level:a,experience:c,xpNeeded:Ve.xpForLevel(a),abilities:u,nextAbility:p?{name:p.name,level:p.unlockedAtLevel}:void 0});for(let b of l)b.type==="molt"?this.sendNotification("pet.reaction",{text:`\u2728 \u8131\u58F3\u4E86\uFF01\u7B2C ${b.moltStage} \u6B21\u8715\u53D8`,style:"excited"}):b.type==="ability_unlock"&&b.ability&&this.sendNotification("pet.reaction",{text:`\u{1F389} \u89E3\u9501\u65B0\u80FD\u529B\uFF1A${b.ability.name}`,style:"excited"});let m=null,h="excited";try{let b=[],k=this.getActiveProjectRoot?.()??"";if(k){let $=k.split(/[\\/]/).pop()??k;b.push(`\u7528\u6237\u6B63\u5728\u9879\u76EE\u300C${$}\u300D\u4E2D\u5DE5\u4F5C`)}if(this.sessionState){let $=this.sessionState.turnCount??0;$>0&&b.push(`\u672C\u6B21\u4F1A\u8BDD\u5DF2\u8FDB\u884C\u4E86 ${$} \u8F6E\u5BF9\u8BDD`)}if(this.memoryProvider&&this.memoryUserId)try{let $=this.memoryProvider.getActivitySummary(this.memoryUserId,7);if($?.highlights?.length){let W=$.highlights.slice(0,3).map(S=>S.text);b.push(`\u7528\u6237\u8FD1\u671F\u8BB0\u5FC6\u4EAE\u70B9: ${W.join("\uFF1B")}`)}}catch{}let x=new Date().getHours(),P=x<6?"\u6DF1\u591C":x<9?"\u65E9\u6668":x<12?"\u4E0A\u5348":x<14?"\u4E2D\u5348":x<18?"\u4E0B\u5348":x<22?"\u665A\u4E0A":"\u6DF1\u591C";b.push(`\u5F53\u524D\u65F6\u6BB5: ${P}`);let I=t==="pat"?"\u7528\u6237\u6478\u4E86\u6478\u4F60":t==="feed"?"\u7528\u6237\u5582\u4E86\u4F60\u4E1C\u897F":`\u7528\u6237\u5BF9\u4F60\u505A\u4E86\u300C${t}\u300D`;b.push(I);let O=b.join("\u3002");if(this.createSmallLLMCall){let $=this.createSmallLLMCall();if($){let W=await Vs({turnSummary:O,soul:s},$);W&&(m=W.text,h=W.style)}}}catch{}if(!m){let b=Hs("session.created");m=b?.text??null,h=b?.style??"excited"}let f=[],y=new Date().getHours();y>=22||y<6?f.push({label:"\u5E2E\u6211\u6574\u7406\u4ECA\u5929\u7684\u8FDB\u5EA6",action:"summarize-today"}):this.sessionState?.turnCount&&this.sessionState.turnCount>5&&f.push({label:"\u7EE7\u7EED\u521A\u624D\u7684\u5BF9\u8BDD",action:"resume-session"}),t==="click"&&f.push({label:"\u6709\u4EC0\u4E48\u80FD\u5E2E\u4F60\u7684\uFF1F",action:"start-chat"}),m&&this.sendNotification("pet.reaction",{text:m,style:h,actions:f.length>0?f:void 0}),o.id!==void 0&&this.sendResponse(o.id,{ok:!0,action:t,level:a,experience:c,events:l.map(b=>({type:b.type,level:b.level})),reaction:m?{text:m,style:h,actions:f.length>0?f:void 0}:null})}async function Ok(o){let e=this.getActiveProjectRoot(),n=new Ut(e).load();if(o.id!==void 0&&this.sendResponse(o.id,{ok:!0,soul:n??null}),n){this.sendNotification("pet.soul_ready",{name:n.name,species:n.species,personality:n.personality,catchphrase:n.catchphrase,stats:n.stats,rarity:n.rarity,breed:n.breed,breedColors:n.breedColors});let r=Ve.getUnlockedAbilities(n.level).map(i=>i.name),s=Ve.getNextAbility(n.level);this.sendNotification("pet.growth",{level:n.level,experience:n.experience,xpNeeded:Ve.xpForLevel(n.level),abilities:r,nextAbility:s?{name:s.name,level:s.unlockedAtLevel}:void 0})}}async function Dk(o){let e=o.params;if(!e?.description&&!e?.imageBase64){o.id!==void 0&&this.sendResponse(o.id,void 0,{code:w.INVALID_PARAMS,message:"Provide description or imageBase64"});return}this.sendNotification("pet.state",{state:"building"}),this.sendNotification("pet.reaction",{text:"\u6B63\u5728\u5B75\u5316\u4F60\u7684\u4E13\u5C5E\u5BA0\u7269...",style:"thinking"});try{let t=e.description?.slice(0,10)??"\u81EA\u5B9A\u4E49\u5BA0\u7269",n=e.description??"";e.imageBase64&&(n=await this.forgeAnalyzeImage(e.imageBase64,e.description),this.sendNotification("pet.reaction",{text:"\u5206\u6790\u5B8C\u6210\uFF0C\u6B63\u5728\u751F\u6210\u9AA8\u67B6...",style:"thinking"}));let r=await this.forgeGenerateSkeleton(n),s=Zt(r),i=io(s),a=0;for(;i.length>0&&a<2;){a++,this.sendNotification("pet.reaction",{text:`\u9AA8\u67B6\u7F3A\u5C11 ${i.join("\u3001")}\uFF0C\u91CD\u65B0\u751F\u6210 (${a}/${2})...`,style:"thinking",duration:3e3});let m=`\u4E0A\u6B21\u751F\u6210\u7F3A\u5C11\u4EE5\u4E0B\u90E8\u4F4D: ${i.join(", ")}\u3002\u8BF7\u786E\u4FDD\u6240\u6709 id \u5C5E\u6027\u90FD\u5B58\u5728\u3002`;r=await this.forgeGenerateSkeleton(n+`
806
+ `,u=await fetch(i,{method:"POST",headers:{Authorization:`Bearer ${r}`,"Content-Type":`multipart/form-data; boundary=${c}`},body:d});if(!u.ok){let m=await u.text();a.release({success:!1,errorCode:u.status}),o.id!==void 0&&this.sendResponse(o.id,void 0,{code:w.INTERNAL_ERROR,message:`STT API error (${u.status}): ${m.slice(0,200)}`});return}let p=await u.json();a.release({success:!0}),o.id!==void 0&&this.sendResponse(o.id,{text:p.text??"",model:p.model})}catch(c){a.release({success:!1}),o.id!==void 0&&this.sendResponse(o.id,void 0,{code:w.INTERNAL_ERROR,message:c instanceof Error?c.message:String(c)})}}ft();var si="\u65E0\u6CD5\u8FDE\u63A5 llmrouter \u6A21\u578B\u76EE\u5F55",uo=class extends Error{constructor(e=si){super(e),this.name="LlmrouterCatalogUnavailableError"}};function $C(){let o=process.env.QLOGIC_LLMROUTER_BASE_URL?.trim().replace(/\/+$/,"");if(!o)throw new uo;return o}function UC(){let o={accept:"application/json"},e=process.env.QLOGIC_LLMROUTER_ACCESS_TOKEN?.trim();return e&&(o.authorization=`Bearer ${e}`),o}async function kk(o){let e=$C(),t;try{t=await fetch(`${e}${o}`,{method:"GET",headers:UC(),signal:AbortSignal.timeout(1e4)})}catch{throw new uo}if(!t.ok)throw new uo;let n=await t.json().catch(()=>null),r=Array.isArray(n)?n:GC(n)&&Array.isArray(n.data)?n.data:null;if(!r)throw new uo;return r}async function ii(){return kk("/ext/model-catalog/providers")}async function jC(){return kk("/ext/model-catalog/models")}function yd(o){let e={zhipu:"Zhipu GLM","zhipu-openai":"Zhipu GLM OpenAI","zhipu-coding":"Zhipu GLM Coding",volcengine:"Doubao / Volcengine"};return e[o.id]?e[o.id]:o.displayName??o.name??o.id}function ai(o){return o.baseUrl??o.base_url}async function bd(o){return(await ii()).find(t=>t.id===o)??null}async function kd(o){let e=await jC();o.migrateModelIds(FC(e));let t=e.map(BC).filter(n=>!!n);return o.replaceCatalogModels(t),t}function FC(o){let e=new Map;for(let t of o){let n=t.provider??t.owned_by,r=t.native_model_id??t.nativeModelId??t.id;if(!n||!r)continue;let s=`${n}:${r}`;for(let i of[t.public_model,t.publicModel,t.id])!i||i===r||e.set(`${n}:${i}`,s)}return e}function BC(o){let e=o.provider??o.owned_by,t=o.native_model_id??o.nativeModelId??o.id;return!e||!t?null:{id:`${e}:${t}`,provider:e,model:t,displayName:o.display_name??o.displayName??o.name??o.id,purposes:WC(o.purposes,o.category),baseUrl:o.baseUrl??o.base_url,enabled:!0,transport:o.provider_transport??o.providerTransport,contextWindow:o.context_window??o.contextWindow,maxOutput:o.max_output??o.maxOutput,streamRequired:o.stream_required??o.streamRequired,capabilities:o.capabilities,pricing:o.pricing}}function WC(o,e){let t=[...o??[],e].filter(s=>!!s),n=new Set(["textGeneration","smallModel","stt","tts","imageGeneration","imageUnderstanding","videoGeneration","videoUnderstanding","threeDGeneration","embedding","voiceClone","musicGeneration","realtimeAudio","realtimeVideo"]),r=t.filter(s=>n.has(s));return[...new Set(r.length?r:["textGeneration"])]}function GC(o){return!!o&&typeof o=="object"&&!Array.isArray(o)}function HC(o){return o.length<=8?"****":`${o.slice(0,3)}***${o.slice(-4)}`}function lt(o,e,t,n=w.INTERNAL_ERROR){if(e.id!==void 0){if(typeof o.sendError=="function"){o.sendError(e.id,n,t);return}o.sendResponse(e.id,void 0,{code:n,message:t})}}function ci(o,e){lt(o,e,si)}function VC(o){let e={};for(let t of o)for(let n of t.purposes)e[n]??=[],e[n].push(t);return e}async function vd(){let o=J(),e=await kd(o);return o.save(),e}async function vk(o){try{let e=(await ii()).map(t=>({id:t.id,displayName:yd(t),baseUrl:ai(t)??"",modelCount:t.models?.length??0}));o.id!==void 0&&this.sendResponse(o.id,{providers:e})}catch{ci(this,o)}}async function Sk(o){let e=o.params;if(!e?.providerId||!e?.key){lt(this,o,"Required: providerId (string), key (string)",w.INVALID_PARAMS);return}let{providerId:t,key:n,label:r}=e;try{let s=await bd(t);if(!s){lt(this,o,`Unknown provider: ${t}`,w.INVALID_PARAMS);return}let i=J();if(i.getProviderStatus(t)?.keys.some(l=>l.key===n)){o.id!==void 0&&this.sendResponse(o.id,{ok:!1,error:"\u8BE5 Key \u5DF2\u5B58\u5728\uFF0C\u65E0\u9700\u91CD\u590D\u6DFB\u52A0"});return}i.addProvider(t,{baseUrl:ai(s)});let c=i.addKey(t,n,{label:r});await vd();for(let l of Oo)if(!i.getBinding(l)){let d=i.listModels({purpose:l,provider:t,enabledOnly:!0});d.length>0&&i.setBinding(l,d[0].id)}i.setKeyHealth(c,"healthy"),i.save(),o.id!==void 0&&this.sendResponse(o.id,{ok:!0,keyId:c,providerId:t})}catch(s){let i=s instanceof Error?s.message:si;lt(this,o,i)}}function Tk(o){let e=o.params;if(!e?.keyId){lt(this,o,"Required: keyId (string)",w.INVALID_PARAMS);return}let t=J();t.removeKey(e.keyId),t.save(),o.id!==void 0&&this.sendResponse(o.id,{ok:!0})}function wk(o){let e=o.params;if(!e?.keyId||typeof e.enabled!="boolean"){lt(this,o,"Required: keyId (string), enabled (boolean)",w.INVALID_PARAMS);return}let t=J();t.updateKey(e.keyId,{enabled:e.enabled}),t.save(),o.id!==void 0&&this.sendResponse(o.id,{ok:!0})}function xk(o){let e=o.params;if(!e?.modelId||typeof e.enabled!="boolean"){lt(this,o,"Required: modelId (string), enabled (boolean)",w.INVALID_PARAMS);return}let t=J();e.enabled?t.enableModel(e.modelId):t.disableModel(e.modelId),t.save(),o.id!==void 0&&this.sendResponse(o.id,{ok:!0})}async function Rk(o){let e=o.params;try{await vd();let t=J(),n=new Set(t.getAllProviderStatus().filter(s=>s.keys.length>0).map(s=>s.providerId)),r=t.listModels({purpose:e?.purpose,provider:e?.provider}).filter(s=>n.has(s.provider));o.id!==void 0&&this.sendResponse(o.id,{models:r,grouped:VC(r),configuredProviderIds:[...n]})}catch{ci(this,o)}}function _k(o){let e=o.params;if(!e?.purpose||!e?.modelId){lt(this,o,"Required: purpose (string), modelId (string)",w.INVALID_PARAMS);return}try{let t=J();t.setBinding(e.purpose,e.modelId),t.save(),o.id!==void 0&&this.sendResponse(o.id,{ok:!0})}catch(t){lt(this,o,t instanceof Error?t.message:String(t),w.INVALID_PARAMS)}}function Ak(o){let e=o.params;if(!e?.purpose){lt(this,o,"Required: purpose (string)",w.INVALID_PARAMS);return}let t=J(),n=t.getBinding(e.purpose);o.id!==void 0&&this.sendResponse(o.id,{model:n?{id:n.id,provider:n.provider,model:n.model,displayName:n.displayName,purposes:n.purposes,enabled:n.enabled}:null,available:t.isAvailable(e.purpose)})}async function Pk(o){try{let e=await ii(),t=new Map(e.map(a=>[a.id,yd(a)]));await vd();let n=J(),r=n.getAllProviderStatus().map(a=>({providerId:a.providerId,displayName:t.get(a.providerId)??a.providerId,baseUrl:a.baseUrl,keyCount:a.keys.length,healthyKeys:a.keys.filter(c=>c.healthStatus==="healthy"&&c.enabled).length,totalKeys:a.keys.length,keys:a.keys.map(c=>({id:c.id,label:c.label,maskedKey:HC(c.key),enabled:c.enabled,health:c.healthStatus}))})),s=n.getAllBindings(),i={};for(let a of Oo){let c=s[a];i[a]={bound:!!c,modelId:c?.id,modelName:c?.displayName,available:n.isAvailable(a)}}o.id!==void 0&&this.sendResponse(o.id,{providers:r,purposes:i})}catch{ci(this,o)}}async function Ik(o){try{let e=J();e.load(),await kd(e),e.save(),o.id!==void 0&&this.sendResponse(o.id,{ok:!0,catalogRefreshed:!0})}catch{ci(this,o)}}async function Ek(o){let e=o.params;if(!e?.providerId||!e?.apiKey){lt(this,o,"providerId and apiKey required",w.INVALID_PARAMS);return}try{let t=await bd(e.providerId),n=e.baseUrl||(t?ai(t):void 0);if(!n){lt(this,o,`Unknown provider: ${e.providerId}`,w.INVALID_PARAMS);return}let r=`${n.replace(/\/$/,"")}/models`,s=await fetch(r,{method:"GET",headers:{Authorization:`Bearer ${e.apiKey}`},signal:AbortSignal.timeout(1e4)});if(s.ok){o.id!==void 0&&this.sendResponse(o.id,{valid:!0,status:s.status});return}let i=await s.text().catch(()=>"");o.id!==void 0&&this.sendResponse(o.id,{valid:!1,status:s.status,error:i.slice(0,500)})}catch(t){let n=t instanceof Error?t.message:String(t);o.id!==void 0&&this.sendResponse(o.id,{valid:!1,status:0,error:n})}}dr();qs();Zl();Ys();Xs();async function Ck(o){let e=this.getActiveProjectRoot(),t=new Ut(e),n=t.load();if(n){this.sendNotification("pet.soul_ready",{name:n.name,species:n.species,personality:n.personality,catchphrase:n.catchphrase,stats:n.stats,rarity:n.rarity,breed:n.breed,breedColors:n.breedColors}),o.id!==void 0&&this.sendResponse(o.id,{ok:!0,soul:n});return}let r=this.deviceId??"default-user";try{let s=this.createPetSoulGenerator?.(),i=await t.hatch(r,s);this.sendNotification("pet.soul_ready",{name:i.name,species:i.species,personality:i.personality,catchphrase:i.catchphrase,stats:i.stats,rarity:i.rarity,breed:i.breed,breedColors:i.breedColors}),this.sendNotification("pet.growth",{level:i.level,experience:i.experience,abilities:Ve.getUnlockedAbilities(i.level).map(a=>a.name)}),o.id!==void 0&&this.sendResponse(o.id,{ok:!0,soul:i})}catch(s){o.id!==void 0&&this.sendResponse(o.id,void 0,{code:w.INTERNAL_ERROR,message:s.message??"Failed to hatch pet"})}}async function Mk(o){let t=o.params?.action??"pat",n=this.getActiveProjectRoot(),r=new Ut(n),s=r.load();if(!s){o.id!==void 0&&this.sendResponse(o.id,void 0,{code:w.INVALID_PARAMS,message:"Pet not hatched yet"});return}let i=Ve.xpForEvent(`interact.${t}`),{newLevel:a,newXp:c,events:l,statBoosts:d}=Ve.processXpGain(s,i);s.level=a,s.experience=c;for(let[b,k]of Object.entries(d)){let x=b;s.stats[x]=Math.min(10,s.stats[x]+(k??0))}r.updateSoul(s),this.sendNotification("pet.state",{state:"happy"});let u=Ve.getUnlockedAbilities(a).map(b=>b.name),p=Ve.getNextAbility(a);this.sendNotification("pet.growth",{level:a,experience:c,xpNeeded:Ve.xpForLevel(a),abilities:u,nextAbility:p?{name:p.name,level:p.unlockedAtLevel}:void 0});for(let b of l)b.type==="molt"?this.sendNotification("pet.reaction",{text:`\u2728 \u8131\u58F3\u4E86\uFF01\u7B2C ${b.moltStage} \u6B21\u8715\u53D8`,style:"excited"}):b.type==="ability_unlock"&&b.ability&&this.sendNotification("pet.reaction",{text:`\u{1F389} \u89E3\u9501\u65B0\u80FD\u529B\uFF1A${b.ability.name}`,style:"excited"});let m=null,h="excited";try{let b=[],k=this.getActiveProjectRoot?.()??"";if(k){let $=k.split(/[\\/]/).pop()??k;b.push(`\u7528\u6237\u6B63\u5728\u9879\u76EE\u300C${$}\u300D\u4E2D\u5DE5\u4F5C`)}if(this.sessionState){let $=this.sessionState.turnCount??0;$>0&&b.push(`\u672C\u6B21\u4F1A\u8BDD\u5DF2\u8FDB\u884C\u4E86 ${$} \u8F6E\u5BF9\u8BDD`)}if(this.memoryProvider&&this.memoryUserId)try{let $=this.memoryProvider.getActivitySummary(this.memoryUserId,7);if($?.highlights?.length){let W=$.highlights.slice(0,3).map(S=>S.text);b.push(`\u7528\u6237\u8FD1\u671F\u8BB0\u5FC6\u4EAE\u70B9: ${W.join("\uFF1B")}`)}}catch{}let x=new Date().getHours(),P=x<6?"\u6DF1\u591C":x<9?"\u65E9\u6668":x<12?"\u4E0A\u5348":x<14?"\u4E2D\u5348":x<18?"\u4E0B\u5348":x<22?"\u665A\u4E0A":"\u6DF1\u591C";b.push(`\u5F53\u524D\u65F6\u6BB5: ${P}`);let I=t==="pat"?"\u7528\u6237\u6478\u4E86\u6478\u4F60":t==="feed"?"\u7528\u6237\u5582\u4E86\u4F60\u4E1C\u897F":`\u7528\u6237\u5BF9\u4F60\u505A\u4E86\u300C${t}\u300D`;b.push(I);let O=b.join("\u3002");if(this.createSmallLLMCall){let $=this.createSmallLLMCall();if($){let W=await Vs({turnSummary:O,soul:s},$);W&&(m=W.text,h=W.style)}}}catch{}if(!m){let b=Hs("session.created");m=b?.text??null,h=b?.style??"excited"}let f=[],y=new Date().getHours();y>=22||y<6?f.push({label:"\u5E2E\u6211\u6574\u7406\u4ECA\u5929\u7684\u8FDB\u5EA6",action:"summarize-today"}):this.sessionState?.turnCount&&this.sessionState.turnCount>5&&f.push({label:"\u7EE7\u7EED\u521A\u624D\u7684\u5BF9\u8BDD",action:"resume-session"}),t==="click"&&f.push({label:"\u6709\u4EC0\u4E48\u80FD\u5E2E\u4F60\u7684\uFF1F",action:"start-chat"}),m&&this.sendNotification("pet.reaction",{text:m,style:h,actions:f.length>0?f:void 0}),o.id!==void 0&&this.sendResponse(o.id,{ok:!0,action:t,level:a,experience:c,events:l.map(b=>({type:b.type,level:b.level})),reaction:m?{text:m,style:h,actions:f.length>0?f:void 0}:null})}async function Ok(o){let e=this.getActiveProjectRoot(),n=new Ut(e).load();if(o.id!==void 0&&this.sendResponse(o.id,{ok:!0,soul:n??null}),n){this.sendNotification("pet.soul_ready",{name:n.name,species:n.species,personality:n.personality,catchphrase:n.catchphrase,stats:n.stats,rarity:n.rarity,breed:n.breed,breedColors:n.breedColors});let r=Ve.getUnlockedAbilities(n.level).map(i=>i.name),s=Ve.getNextAbility(n.level);this.sendNotification("pet.growth",{level:n.level,experience:n.experience,xpNeeded:Ve.xpForLevel(n.level),abilities:r,nextAbility:s?{name:s.name,level:s.unlockedAtLevel}:void 0})}}async function Dk(o){let e=o.params;if(!e?.description&&!e?.imageBase64){o.id!==void 0&&this.sendResponse(o.id,void 0,{code:w.INVALID_PARAMS,message:"Provide description or imageBase64"});return}this.sendNotification("pet.state",{state:"building"}),this.sendNotification("pet.reaction",{text:"\u6B63\u5728\u5B75\u5316\u4F60\u7684\u4E13\u5C5E\u5BA0\u7269...",style:"thinking"});try{let t=e.description?.slice(0,10)??"\u81EA\u5B9A\u4E49\u5BA0\u7269",n=e.description??"";e.imageBase64&&(n=await this.forgeAnalyzeImage(e.imageBase64,e.description),this.sendNotification("pet.reaction",{text:"\u5206\u6790\u5B8C\u6210\uFF0C\u6B63\u5728\u751F\u6210\u9AA8\u67B6...",style:"thinking"}));let r=await this.forgeGenerateSkeleton(n),s=Zt(r),i=io(s),a=0;for(;i.length>0&&a<2;){a++,this.sendNotification("pet.reaction",{text:`\u9AA8\u67B6\u7F3A\u5C11 ${i.join("\u3001")}\uFF0C\u91CD\u65B0\u751F\u6210 (${a}/${2})...`,style:"thinking",duration:3e3});let m=`\u4E0A\u6B21\u751F\u6210\u7F3A\u5C11\u4EE5\u4E0B\u90E8\u4F4D: ${i.join(", ")}\u3002\u8BF7\u786E\u4FDD\u6240\u6709 id \u5C5E\u6027\u90FD\u5B58\u5728\u3002`;r=await this.forgeGenerateSkeleton(n+`
807
807
 
808
808
  `+m),s=Zt(r),i=io(s)}i.length>0&&this.sendNotification("pet.reaction",{text:"\u9AA8\u67B6\u4E0D\u5B8C\u6574\uFF0C\u90E8\u5206\u52A8\u753B\u53EF\u80FD\u7F3A\u5931\uFF0C\u7EE7\u7EED\u751F\u6210...",style:"normal",duration:3e3}),this.sendNotification("pet.reaction",{text:"\u9AA8\u67B6\u751F\u6210\u5B8C\u6210\uFF0C\u5F00\u59CB\u6E32\u67D3\u5404\u72B6\u6001...",style:"thinking"});let c=["idle","thinking","working","done","happy","error","sleeping","eating"],l={baseSvg:s,parts:oo(s),colors:so(s),characterDesc:n},d={};for(let m of c)d[m]=ro(l,m),this.sendNotification("pet.reaction",{text:`\u6E32\u67D3 ${m} \u72B6\u6001... (${Object.keys(d).length}/${c.length})`,style:"thinking",duration:2e3});let u=cr(d.idle,d,{threshold:6});if(!u.passedAll&&u.retryStates.length>0&&(this.sendNotification("pet.reaction",{text:`\u4E00\u81F4\u6027\u68C0\u67E5\uFF1A${u.retryStates.length} \u4E2A\u72B6\u6001\u9700\u4F18\u5316...`,style:"thinking",duration:3e3}),u.overallScore<4)){let m=lr(n,"all","\u9AA8\u67B6\u7ED3\u6784\u4E0D\u5B8C\u6574\u5BFC\u81F4\u591A\u72B6\u6001\u4E00\u81F4\u6027\u5DEE",1);r=await this.forgeGenerateSkeleton(m);let h={baseSvg:Zt(r),parts:oo(Zt(r)),colors:so(Zt(r)),characterDesc:n};for(let f of c)d[f]=ro(h,f)}let p={version:1,name:t,author:"user-generated",created:new Date().toISOString(),generator:"xiaozhi-pet-forge-v2-skeleton",source:{type:e.imageBase64?"image":"text",prompt:e.description},dimensions:{width:200,height:200},states:Object.fromEntries(c.map(m=>[m,{file:`states/${m}.svg`,loop:m!=="done"&&m!=="happy"&&m!=="eating",...m==="done"||m==="happy"?{duration:3e3}:m==="eating"?{duration:4e3}:{}}])),eyeTracking:{enabled:!0,pupils:[".left-eye .pupil",".right-eye .pupil"],maxOffset:3},colors:l.colors,consistency:{score:u.overallScore,method:"skeleton-parameterized"}};sr(p),this.sendNotification("pet.reaction",{text:`\u2705 \u5BA0\u7269\u300C${t}\u300D\u5DF2\u953B\u9020\u5B8C\u6210\uFF01\u4E00\u81F4\u6027\u8BC4\u5206 ${u.overallScore.toFixed(1)}/10`,style:"excited"}),this.sendNotification("pet.state",{state:"done"}),this.sendNotification("pet.forged",{name:t,svgs:d}),o.id!==void 0&&this.sendResponse(o.id,{ok:!0,manifest:p,svgs:d,status:"complete",consistency:{score:u.overallScore,passedAll:u.passedAll}})}catch(t){this.sendNotification("pet.state",{state:"error"}),this.sendNotification("pet.reaction",{text:"\u953B\u9020\u5931\u8D25\u4E86...",style:"normal"}),o.id!==void 0&&this.sendResponse(o.id,void 0,{code:w.INTERNAL_ERROR,message:t.message??"Forge failed"})}}function KC(o){let e=o.pathname.split("/").filter(Boolean),n=(e[e.length-1]??"").replace(/\.md$/i,"").replace(/[^a-zA-Z0-9_-]/g,"-");return/^(skill|readme|index|install|main)$/i.test(n)&&e.length>=2?e[e.length-2].replace(/[^a-zA-Z0-9_-]/g,"-"):n||""}var Sd=class o{running=!1;activeTurn=null;turnDone=Promise.resolve();verbose;transport;registry;mediaClient;agent=null;lastLlmConfigKey="";currentSessionId="";currentTurnId="";currentHooks=null;mcpManager=null;mcpReady=Promise.resolve();pluginLoader=null;permissionChecker=null;permissionUnregister=null;currentTransport=null;currentApiKey="";currentModel="";currentProvider="";currentBaseUrl="";sessionState=null;currentMediaApiKeys=null;taskStore=new os;mediaPersistence=new Os;memoryPrefetchState=Kt();memoryProvider=null;memoryUserId="";lastUserMessageForAutoExtract;lastAssistantMessageForExtract;memdir=null;fileWatcher=null;pendingAskUser=new Map;sessionTaskDomain;acpDetector=new As;agentConfigStore=null;soloEvaluator=null;productOrchestrator=null;productPlanner=null;soloProcessManager=null;productProcessManager=null;acpServer=null;acpSessionHistory=new Map;resumedSessionHistory=new Map;idleDreamTimer=null;constructor(e){this.verbose=e.verbose,this.registry=new $n,this.mediaClient=new xo({registry:this.registry}),J().onChange(()=>{this.lastLlmConfigKey=""});let t=Number(process.env.QLOGICAGENT_IDLE_DREAM_MS);t>0&&(we.dream.idleMinutes=t/6e4);let n=Number(process.env.QLOGICAGENT_DREAM_COOLDOWN_MS);n>=0&&(we.dream.cooldownMs=n),this.transport=e.transport??new Lo({verbose:e.verbose}),this.taskStore.onTaskChange((r,s)=>{s&&this.sendNotification("task.updated",{taskId:r,type:s.type,lifecycle:s.lifecycle,label:s.label})}),sg({log:{info:r=>this.log(r),warn:r=>this.log(`[warn] ${r}`),error:r=>this.log(`[error] ${r}`),debug:r=>{e.verbose&&this.log(`[debug] ${r}`)}},onExecProgress:r=>{this.sendNotification("turn.exec_progress",{output:r.output,elapsedTimeSeconds:r.elapsedTimeSeconds,totalLines:r.totalLines,totalBytes:r.totalBytes})}})}getActiveProjectRoot(){let e=Le();return e?.workspaceDir?e.workspaceDir:process.cwd()}setActiveWorkdir(e){e!==this.getActiveProjectRoot()&&(ng(e),this.mediaPersistence.setProjectDir(e))}start(){this.running=!0,this.log("qlogicagent started, waiting for JSON-RPC messages..."),Zp().then(e=>{e.error?this.log(`[warmup] embedding model not available: ${e.error}`):e.modelDownloaded?this.log(`[warmup] embedding model downloaded (${e.dimensions}d)`):e.modelCached&&this.log(`[warmup] embedding model ready (cached, ${e.dimensions}d)`)}).catch(()=>{}),this.transport.onMessage(e=>{if(this.acpServer){if(Kl(e)||er(e)){this.acpServer.dispatchMessage(e);return}if(Zo(e)){let t=e.method;if(t==="initialize"||t.startsWith("session/")||t.startsWith("x/")||t.startsWith("fs/")){this.acpServer.dispatchMessage(e);return}}}if(!Vl(e)){this.log("[warn] ignoring non-request message");return}this.handleMessage(e)}),this.transport.onClose(()=>{this.log("transport closed, shutting down"),this.stop()}),this.transport.start()}stop(){if(this.running){this.running=!1,this.cancelIdleDreamTimer(),this.currentSessionId&&this.currentHooks&&(this.currentHooks.invoke("stop",{sessionId:this.currentSessionId,reason:"shutdown"}).catch(()=>{}),this.currentHooks.invoke("session.ended",{sessionId:this.currentSessionId}).catch(()=>{}));try{ch().catch(()=>{}),this.fileWatcher&&(this.fileWatcher.stop(),this.fileWatcher=null),this.mcpManager&&(this.mcpManager.disconnectAll().catch(()=>{}),this.mcpManager=null),this.permissionUnregister&&(this.permissionUnregister(),this.permissionUnregister=null),this.activeTurn&&(this.activeTurn.abort(),this.activeTurn=null),this.transport.close()}catch(e){this.currentSessionId&&this.currentHooks&&this.currentHooks.invoke("stop.failed",{sessionId:this.currentSessionId,reason:"cleanup_error",error:e.message}).catch(()=>{})}this.log("stopped")}}methodHandlers=new Map([["initialize",e=>this.handleInitialize(e)],["agent.ping",e=>this.handlePing(e)],["thread.turn",e=>cy.call(this,e)],["memory.dream",e=>Qs.call(this,e)],["agent.abort",e=>sy.call(this,e)],["tool.approval.response",e=>iy.call(this,e)],["thread.user_response",e=>ay.call(this,e)],["thread.list",e=>Oy.call(this,e)],["session.resume",e=>Gy.call(this,e)],["thread.create",e=>My.call(this,e)],["session.getInfo",e=>Hy.call(this,e)],["session.create",e=>Dy.call(this,e)],["session.resolve",e=>Ly.call(this,e)],["session.list",e=>Ny.call(this,e)],["session.get",e=>$y.call(this,e)],["session.getMessages",e=>Uy.call(this,e)],["session.update",e=>jy.call(this,e)],["session.delete",e=>Fy.call(this,e)],["session.deleteAll",e=>By.call(this,e)],["session.archive",e=>Wy.call(this,e)],["memory.list",e=>jb.call(this,e)],["memory.atlas",e=>Fb.call(this,e)],["memory.activity",e=>Bb.call(this,e)],["memory.read",e=>Wb.call(this,e)],["memory.write",e=>Gb.call(this,e)],["memory.search",e=>Hb.call(this,e)],["memory.delete",e=>Vb.call(this,e)],["tools.list",e=>Kb.call(this,e)],["media.listModels",e=>gk.call(this,e)],["media.cancel",e=>hk.call(this,e)],["media.status",e=>yk.call(this,e)],["media.stt",e=>bk.call(this,e)],["settings.listProviders",e=>vk.call(this,e)],["settings.addKey",e=>Sk.call(this,e)],["settings.removeKey",e=>Tk.call(this,e)],["settings.toggleKey",e=>wk.call(this,e)],["settings.toggleModel",e=>xk.call(this,e)],["settings.listModels",e=>Rk.call(this,e)],["settings.setActiveModel",e=>_k.call(this,e)],["settings.getActiveModel",e=>Ak.call(this,e)],["settings.getOverview",e=>Pk.call(this,e)],["settings.refreshModels",e=>Ik.call(this,e)],["settings.validateKey",e=>Ek.call(this,e)],["provider.list",e=>zb.call(this,e)],["config.get",e=>qb.call(this,e)],["config.update",e=>Yb.call(this,e)],["config.tunables",e=>Xb.call(this,e)],["config.updateTunable",e=>Jb.call(this,e)],["todos.list",e=>Qb.call(this,e)],["tasks.list",e=>Zb.call(this,e)],["tasks.cancel",e=>ek.call(this,e)],["agents.scan",e=>nk.call(this,e)],["agents.list",e=>ok.call(this,e)],["agents.config",e=>rk.call(this,e)],["agents.setConfig",e=>sk.call(this,e)],["agents.getConfig",e=>ik.call(this,e)],["agents.removeConfig",e=>ak.call(this,e)],["agents.setGateway",e=>ck.call(this,e)],["agents.getGateway",e=>lk.call(this,e)],["agents.processes",e=>uk.call(this,e)],["agents.kill",e=>pk.call(this,e)],["agents.listConfigured",e=>dk.call(this,e)],["agents.getLog",e=>mk.call(this,e)],["agents.testConnection",e=>fk.call(this,e)],["solo.start",e=>eb.call(this,e)],["solo.status",e=>tb.call(this,e)],["solo.cancel",e=>nb.call(this,e)],["solo.select",e=>ob.call(this,e)],["solo.list",e=>rb.call(this,e)],["solo.delete",e=>sb.call(this,e)],["solo.message",e=>ib.call(this,e)],["solo.evaluate",e=>ab.call(this,e)],["product.plan",e=>vy.call(this,e)],["product.confirm",e=>Sy.call(this,e)],["product.message",e=>Ty.call(this,e)],["product.create",e=>wy.call(this,e)],["product.resume",e=>xy.call(this,e)],["product.pause",e=>Ry.call(this,e)],["product.checkpoint",e=>_y.call(this,e)],["product.status",e=>Ay.call(this,e)],["product.list",e=>Py.call(this,e)],["product.delete",e=>Iy.call(this,e)],["product.cancel",e=>Ey.call(this,e)],["product.rollback",e=>Cy.call(this,e)],["project.create",e=>kb.call(this,e)],["project.list",e=>vb.call(this,e)],["project.delete",e=>Sb.call(this,e)],["project.purgeAll",e=>Tb.call(this,e)],["project.rename",e=>wb.call(this,e)],["project.archive",e=>xb.call(this,e)],["project.unarchive",e=>Rb.call(this,e)],["project.update",e=>Ab.call(this,e)],["project.archiveByGroup",e=>_b.call(this,e)],["session.switchProject",e=>Vy.call(this,e)],["session.focus",e=>zy.call(this,e)],["session.moveToProject",e=>qy.call(this,e)],["session.getState",e=>Ky.call(this,e)],["files.list",e=>Eb.call(this,e)],["files.create",e=>Cb.call(this,e)],["files.rename",e=>Mb.call(this,e)],["files.delete",e=>Ob.call(this,e)],["files.gitStatus",e=>Db.call(this,e)],["instructions.list",e=>Lb.call(this,e)],["instructions.read",e=>Nb.call(this,e)],["instructions.write",e=>$b.call(this,e)],["instructions.delete",e=>Ub.call(this,e)],["skills.list",e=>lb.call(this,e)],["skills.activate",e=>db.call(this,e)],["skills.deactivate",e=>ub.call(this,e)],["skills.delete",e=>pb.call(this,e)],["skills.promote",e=>mb.call(this,e)],["skills.stats",e=>fb.call(this,e)],["skills.pin",e=>gb.call(this,e)],["skills.unpin",e=>hb.call(this,e)],["skills.curator",e=>yb.call(this,e)],["skills.lifecycle",e=>bb.call(this,e)],["pet.hatch",e=>Ck.call(this,e)],["pet.interact",e=>Mk.call(this,e)],["pet.status",e=>Ok.call(this,e)],["pet.forge",e=>Dk.call(this,e)],["pet.confirm_response",e=>this.handlePetConfirmResponse(e)]]);handleMessage(e){let t=this.methodHandlers.get(e.method);t?t(e):e.id!==void 0&&this.sendResponse(e.id,void 0,{code:w.METHOD_NOT_FOUND,message:`Unknown method: ${e.method}`})}handleInitialize(e){let t=e.params,n=t?.protocolVersion??"unknown",r=t?.host?.name??t?.hostName??"unknown",s=t?.host?.version??t?.hostVersion??"?",i=n.split(".")[0],a=eo.split(".")[0];if(i!==a){this.log(`[initialize] protocol mismatch: host=${n} agent=${eo}`),e.id!==void 0&&this.sendResponse(e.id,void 0,{code:w.PROTOCOL_MISMATCH,message:`Protocol version mismatch: host=${n}, agent=${eo}`});return}this.log(`[initialize] host=${r} v${s}`),e.id!==void 0&&this.sendResponse(e.id,{protocolVersion:eo,agent:{name:"qlogicagent",version:"0.1.0"},capabilities:{tools:Ot().map(c=>c.function.name),streaming:!0,threads:!0,notifications:["turn.start","turn.delta","turn.end","turn.error","turn.recovery","turn.tool_call","turn.tool_result","turn.tool_blocked","turn.reasoning_delta","turn.plan_update","turn.suggestions","turn.subagent_started","turn.subagent_delta","turn.subagent_ended","turn.media_result","turn.todos_updated","task.updated","turn.exec_progress","turn.artifact","tool.approval.request","turn.skill_instruction","turn.ask_user","memory.updated","session.info","permission.rule_updated","team.updated","turn.usage_update","pong"],methods:[...Ah]}}),this.ensureDefaultProject()}ensureDefaultProject(){let e=Le();if(e)e.workspaceDir&&this.setActiveWorkdir(e.workspaceDir);else{let t=te.join(H(),"workspaces","default");Y.existsSync(t)||Y.mkdirSync(t,{recursive:!0});let n=Wp(t);md(t),this.setActiveWorkdir(t),this.sendNotification("project.created",{id:n.id,name:n.name,workspaceDir:n.workspaceDir,type:n.type})}this.ensureDefaultProjectDir();{let t=this.getActiveProjectRoot(),n=new $t(t);n.ensureInitialized(),this.memdir=n}}ensureDefaultProjectDir(){let t=fe().find(n=>n.type==="default"&&n.status==="active");t&&(Y.existsSync(t.workspaceDir)||Y.mkdirSync(t.workspaceDir,{recursive:!0}))}handlePing(e){e.id!==void 0&&this.sendResponse(e.id,{status:"ok"}),this.sendNotification("pong",{})}static SUGGESTION_PROMPT=`[SUGGESTION MODE]
809
809
  Based on the conversation, suggest 1-3 short follow-up actions the user might naturally do next.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "qlogicagent",
3
- "version": "2.10.2",
3
+ "version": "2.10.3",
4
4
  "description": "XiaozhiClaw Agent CLI — subprocess architecture (JSON-RPC over stdio)",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",