qlogicagent 2.10.18 → 2.10.19
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 +1 -1
- package/dist/index.js +1 -1
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -849,7 +849,7 @@ ${c||"(\u65E0)"}`].join(`
|
|
|
849
849
|
`),u="";try{for await(let h of s.transport.stream({model:s.model,messages:[{role:"user",content:l}],temperature:.1,maxTokens:900,tools:[]},s.apiKey))h.type==="delta"&&(u+=h.text)}catch{return null}let d=WI(u),m=(Array.isArray(d?.memories)?d.memories:[]).map(h=>({id:`candidate-${Bh()}`,text:typeof h?.text=="string"?h.text.trim().slice(0,1400):"",category:lo(h?.category),importance:Dr(h?.importance,.1,1,.65),confidence:Dr(h?.confidence,.05,1,.65),source:typeof h?.source=="string"&&h.source.trim()?h.source.trim().slice(0,80):"manual",eventDate:typeof h?.eventDate=="string"?h.eventDate.trim().slice(0,32):"",tags:uo(h?.tags),relatedMemoryIds:Array.isArray(h?.relatedMemoryIds)?h.relatedMemoryIds.filter(f=>typeof f=="string").slice(0,8):[],evidence:[...o?[{type:"text",excerpt:o.slice(0,500)}]:[],...i.map(f=>({type:f.type,filename:f.filename,mimeType:f.mimeType}))],requiresConfirmation:h?.requiresConfirmation!==!1,reason:typeof h?.reason=="string"?h.reason.trim().slice(0,300):""})).filter(h=>h.text.length>=6);return m.length>0?m:null}async function Hh(n,e,t){let r=typeof e?.text=="string"?e.text.trim():"",s=Array.isArray(e?.attachments)?e.attachments.map(Zc):[],o=await GI(n,[r,...s.map(el)].join(`
|
|
850
850
|
`),t),i=e?.autoExtract===!1?null:await VI(n,e,o);return{candidates:i??KI(e,o),relatedMemories:o,extractor:i?"llm":"deterministic"}}async function qh(n,e,t){let r=0;for(let s of t){let o=typeof s?.text=="string"?s.text.trim():"";if(!o)continue;let i=uo([...s.tags??[],...(s.relatedMemoryIds??[]).map(c=>`related:${c}`)]),a={text:o,category:lo(s.category),importance:Dr(s.importance,.1,1,.6),event_date:typeof s.eventDate=="string"?s.eventDate:"",tags:i};if(typeof n.memoryProvider.ingestExtracted=="function"){let c=await n.memoryProvider.ingestExtracted([a],e,{source:typeof s.source=="string"&&s.source.trim()?s.source.trim():"manual"});r+=c?.memoriesAdded??0}else{let c=await n.memoryProvider.addText(o,e,{category:a.category,importance:a.importance,source:typeof s.source=="string"&&s.source.trim()?s.source.trim():"manual",tags:i});r+=c?.memoriesAdded??0}}return r}function Ln(n,e){let r=(typeof e=="string"&&e.trim()?e:typeof n.memoryUserId=="string"&&n.memoryUserId.trim()?n.memoryUserId:"").trim();return r||null}function Fh(){return{totalCount:0,records:[],buckets:[],clusters:[],windowCursor:null,timeRange:null,stats:{formed:0,insights:0,preferences:0}}}function zI(n,e){let t=0,r=0;for(let s of e??[])s?.kind==="category"&&((s.label==="insight"||s.label==="lesson")&&(t+=Number(s.count??0)),s.label==="preference"&&(r+=Number(s.count??0)));return{formed:n,insights:t,preferences:r}}async function Wh(n){let e=[];this.memdir&&e.push({id:"memdir",type:"file",path:xc(this.getActiveProjectRoot())}),this.memoryProvider&&e.push({id:"local",type:"vector"}),n.id!==void 0&&this.sendResponse(n.id,{sources:e})}async function Gh(n){let e=n.params;if(this.ensureMemoryProvider?.(),!this.memoryProvider||typeof this.memoryProvider.getAtlas!="function"){n.id!==void 0&&this.sendResponse(n.id,Fh());return}try{let t=Ln(this,e?.userId);if(!t){n.id!==void 0&&this.sendResponse(n.id,Fh());return}let r=this.memoryProvider.getAtlas(t,{pageSize:e?.pageSize??360,windowStartAt:e?.windowStartAt,windowEndAt:e?.windowEndAt,windowCenterAt:e?.windowCenterAt,bucketCount:e?.bucketCount??96,clusterLimit:e?.clusterLimit??48,activeOnly:!0}),s=(r.records??[]).map(a=>({id:a.id,text:a.text,category:a.category,importance:a.importance,confidence:a.confidence,source:a.source,sessionId:a.sessionId,eventDate:a.eventDate,tags:a.tags,createdAt:a.createdAt,updatedAt:a.updatedAt,accessCount:a.accessCount,lastAccessedAt:a.lastAccessedAt,isArchived:a.isArchived})),o=Number(r.totalCount??s.length),i=r.clusters??[];n.id!==void 0&&this.sendResponse(n.id,{totalCount:o,records:s,buckets:r.buckets??[],clusters:i,windowCursor:r.windowCursor??null,timeRange:r.timeRange??null,stats:zI(o,i)})}catch(t){n.id!==void 0&&this.sendResponse(n.id,void 0,{code:k.INTERNAL_ERROR,message:t instanceof Error?t.message:String(t)})}}async function Kh(n){let e=n.params;if(this.ensureMemoryProvider?.(),!this.memoryProvider||typeof this.memoryProvider.getActivitySummary!="function"){n.id!==void 0&&this.sendResponse(n.id,{dailyCounts:[],highlights:[]});return}try{let t=Ln(this,e?.userId);if(!t){n.id!==void 0&&this.sendResponse(n.id,{dailyCounts:[],highlights:[]});return}let r=this.memoryProvider.getActivitySummary(t,e?.days??180);n.id!==void 0&&this.sendResponse(n.id,r)}catch(t){n.id!==void 0&&this.sendResponse(n.id,void 0,{code:k.INTERNAL_ERROR,message:t instanceof Error?t.message:String(t)})}}async function Vh(n){let e=n.params;if(this.ensureMemoryProvider?.(),!this.memoryProvider||typeof this.memoryProvider.addText!="function"){n.id!==void 0&&this.sendResponse(n.id,void 0,{code:k.INTERNAL_ERROR,message:"Long-term memory provider is not initialized."});return}let t=typeof e?.text=="string"?e.text.trim():"";if(!t){n.id!==void 0&&this.sendResponse(n.id,void 0,{code:k.INVALID_PARAMS,message:"text is required."});return}let r=Ln(this,e?.userId);if(!r){n.id!==void 0&&this.sendResponse(n.id,void 0,{code:k.INVALID_PARAMS,message:"llmrouter user id is required for long-term memory."});return}let s=new Set(["fact","preference","insight","lesson","decision","plan","event","general"]),o=typeof e?.category=="string"&&s.has(e.category)?e.category:"general",i=typeof e?.importance=="number"&&Number.isFinite(e.importance)?Math.max(.1,Math.min(1,e.importance)):.6;try{let{candidates:a}=await Hh(this,{...e,text:t,category:o,importance:i,source:typeof e?.source=="string"&&e.source.trim()?e.source.trim():"manual",autoExtract:e?.autoExtract??!0},r),c=await qh(this,r,a);n.id!==void 0&&this.sendResponse(n.id,{ok:!0,memoriesAdded:c}),this.sendNotification?.("memory.updated",{source:"local",target:"atlas"})}catch(a){n.id!==void 0&&this.sendResponse(n.id,void 0,{code:k.INTERNAL_ERROR,message:a instanceof Error?a.message:String(a)})}}async function zh(n){let e=n.params;if(this.ensureMemoryProvider?.(),!this.memoryProvider){n.id!==void 0&&this.sendResponse(n.id,void 0,{code:k.INTERNAL_ERROR,message:"Long-term memory provider is not initialized."});return}let t=typeof e?.text=="string"?e.text.trim():"",r=Array.isArray(e?.attachments)?e.attachments:[];if(!t&&r.length===0){n.id!==void 0&&this.sendResponse(n.id,void 0,{code:k.INVALID_PARAMS,message:"text or attachments are required."});return}let s=Ln(this,e?.userId);if(!s){n.id!==void 0&&this.sendResponse(n.id,void 0,{code:k.INVALID_PARAMS,message:"llmrouter user id is required for long-term memory."});return}try{let o=await Hh(this,e??{},s);n.id!==void 0&&this.sendResponse(n.id,{ok:!0,candidates:o.candidates,relatedMemories:o.relatedMemories,extractor:o.extractor})}catch(o){n.id!==void 0&&this.sendResponse(n.id,void 0,{code:k.INTERNAL_ERROR,message:o instanceof Error?o.message:String(o)})}}async function Xh(n){let e=n.params;if(this.ensureMemoryProvider?.(),!this.memoryProvider||typeof this.memoryProvider.addText!="function"){n.id!==void 0&&this.sendResponse(n.id,void 0,{code:k.INTERNAL_ERROR,message:"Long-term memory provider is not initialized."});return}let t=Ln(this,e?.userId);if(!t){n.id!==void 0&&this.sendResponse(n.id,void 0,{code:k.INVALID_PARAMS,message:"llmrouter user id is required for long-term memory."});return}let r=Array.isArray(e?.candidates)?e.candidates:[];if(r.length===0){n.id!==void 0&&this.sendResponse(n.id,void 0,{code:k.INVALID_PARAMS,message:"candidates are required."});return}try{let s=await qh(this,t,r);n.id!==void 0&&this.sendResponse(n.id,{ok:!0,memoriesAdded:s}),this.sendNotification?.("memory.updated",{source:"local",target:"atlas"})}catch(s){n.id!==void 0&&this.sendResponse(n.id,void 0,{code:k.INTERNAL_ERROR,message:s instanceof Error?s.message:String(s)})}}async function Yh(n){let e=n.params,t=e?.source??"memdir",r=e?.target??"index";if(t==="memdir"||t==="local"){if(!this.memdir){n.id!==void 0&&this.sendResponse(n.id,{source:"memdir",target:r,content:""});return}try{if(r==="index"){let s=this.memdir.getIndexRaw();n.id!==void 0&&this.sendResponse(n.id,{source:"memdir",target:"index",content:s})}else{let s=await this.memdir.readFile(r);n.id!==void 0&&this.sendResponse(n.id,{source:"memdir",target:r,content:s.content??""})}}catch{n.id!==void 0&&this.sendResponse(n.id,{source:"memdir",target:r,content:""})}}else n.id!==void 0&&this.sendResponse(n.id,void 0,{code:k.INVALID_PARAMS,message:`Unknown memory source: ${t}`})}async function Jh(n){let e=n.params,t=e?.target??"index",r=e?.content;if(r==null){n.id!==void 0&&this.sendResponse(n.id,void 0,{code:k.INVALID_PARAMS,message:"content is required."});return}if(!this.memdir){n.id!==void 0&&this.sendResponse(n.id,void 0,{code:k.INTERNAL_ERROR,message:"Memory system not initialized."});return}try{if(t==="index"){let s=await this.memdir.addToIndex(r);n.id!==void 0&&this.sendResponse(n.id,{ok:s.ok,target:"index",message:s.message})}else{let s=await this.memdir.writeFile(t,r);n.id!==void 0&&this.sendResponse(n.id,{ok:s.ok,target:t,message:s.message})}this.sendNotification("memory.updated",{target:t,source:"rpc"})}catch(s){n.id!==void 0&&this.sendResponse(n.id,void 0,{code:k.INTERNAL_ERROR,message:s instanceof Error?s.message:String(s)})}}async function Qh(n){let e=n.params;if(!e?.query){n.id!==void 0&&this.sendResponse(n.id,void 0,{code:k.INVALID_PARAMS,message:"query is required."});return}if(this.memoryProvider){let t=Ln(this,e.userId);if(!t){n.id!==void 0&&this.sendResponse(n.id,{results:[]});return}try{let r=await this.memoryProvider.search(e.query,t,{limit:e.limit??10});n.id!==void 0&&this.sendResponse(n.id,{results:r.map(s=>({id:s.blockId??"",text:s.text,score:s.score,source:"local",metadata:s.metadata}))})}catch(r){n.id!==void 0&&this.sendResponse(n.id,void 0,{code:k.INTERNAL_ERROR,message:r instanceof Error?r.message:String(r)})}}else if(this.memdir)try{let t=await this.memdir.searchLocal(e.query);n.id!==void 0&&this.sendResponse(n.id,{results:t.slice(0,e.limit??10).map((r,s)=>({id:`memdir-${s}`,text:r.snippet,score:r.score,source:"memdir",metadata:{file:r.file}}))})}catch{n.id!==void 0&&this.sendResponse(n.id,{results:[]})}else n.id!==void 0&&this.sendResponse(n.id,{results:[]})}async function Zh(n){let e=n.params;if(!e?.match){n.id!==void 0&&this.sendResponse(n.id,void 0,{code:k.INVALID_PARAMS,message:"match is required."});return}let t=e.source??"memdir";if(t==="memdir"||t==="local"){if(!this.memdir){n.id!==void 0&&this.sendResponse(n.id,void 0,{code:k.INTERNAL_ERROR,message:"Memory system not initialized."});return}let r=e.target??"index";try{if(r==="index"){let s=await this.memdir.removeFromIndex(e.match);n.id!==void 0&&this.sendResponse(n.id,{ok:s.ok,removedCount:s.ok?1:0,message:s.message}),s.ok&&this.sendNotification("memory.updated",{source:"memdir",target:"index"})}else{let s=await this.memdir.deleteFile(r);n.id!==void 0&&this.sendResponse(n.id,{ok:s.ok,removedCount:s.ok?1:0,message:s.message}),s.ok&&this.sendNotification("memory.updated",{source:"memdir",target:r})}}catch(s){n.id!==void 0&&this.sendResponse(n.id,void 0,{code:k.INTERNAL_ERROR,message:s instanceof Error?s.message:String(s)})}}else if(t==="vector"&&this.memoryProvider)try{await this.memoryProvider.remove(e.match),n.id!==void 0&&this.sendResponse(n.id,{ok:!0,removedCount:1,message:"Removed from local memory."}),this.sendNotification("memory.updated",{source:"local"})}catch(r){n.id!==void 0&&this.sendResponse(n.id,void 0,{code:k.INTERNAL_ERROR,message:r instanceof Error?r.message:String(r)})}else n.id!==void 0&&this.sendResponse(n.id,void 0,{code:k.INVALID_PARAMS,message:`Unknown or unavailable source: ${t}`})}async function ey(n){let e=n.params,t=typeof e?.id=="string"?e.id.trim():"";if(!t){n.id!==void 0&&this.sendResponse(n.id,void 0,{code:k.INVALID_PARAMS,message:"id is required."});return}if(this.ensureMemoryProvider?.(),!this.memoryProvider||typeof this.memoryProvider.update!="function"){n.id!==void 0&&this.sendResponse(n.id,void 0,{code:k.INTERNAL_ERROR,message:"Long-term memory provider does not support updates."});return}try{let r=await this.memoryProvider.update(t,{text:typeof e?.text=="string"?e.text:void 0,category:typeof e?.category=="string"?lo(e.category):void 0,importance:typeof e?.importance=="number"?Dr(e.importance,.1,1,.6):void 0,source:typeof e?.source=="string"?e.source.trim().slice(0,80):void 0,eventDate:typeof e?.eventDate=="string"?e.eventDate.trim().slice(0,32):void 0,tags:Array.isArray(e?.tags)?uo(e.tags):void 0});n.id!==void 0&&this.sendResponse(n.id,{ok:r,updated:r?1:0}),r&&this.sendNotification("memory.updated",{source:"local",target:"atlas"})}catch(r){n.id!==void 0&&this.sendResponse(n.id,void 0,{code:k.INTERNAL_ERROR,message:r instanceof Error?r.message:String(r)})}}ae();dt();import*as Ht from"node:fs";import*as tl from"node:path";je();function ty(n){let e=n.params,r=At(e?.includeDeferred??!1).map(s=>({name:s.function.name,description:s.function.description??"",parameters:s.function.parameters,source:"builtin"}));if(e?.category){let s=r.filter(o=>o.name.startsWith(e.category)||o.description.toLowerCase().includes(e.category.toLowerCase()));n.id!==void 0&&this.sendResponse(n.id,{tools:s,total:s.length})}else n.id!==void 0&&this.sendResponse(n.id,{tools:r,total:r.length})}function ny(n){let e=X().listProviderDefs(),t=new Map;for(let s of e){let o=s.group??s.id;t.has(o)||t.set(o,[]);let i=!!X().resolveProviderApiKey(s.id);t.get(o).push({id:s.id,name:s.name,transport:s.transport,baseUrl:s.baseUrl,defaultModel:s.defaultModel,modelCount:s.models?.length??0,available:i})}let r=[...t.entries()].map(([s,o])=>({group:s,variants:o}));n.id!==void 0&&this.sendResponse(n.id,{providers:r})}function ry(n){try{let t=X().exportConfig();n.id!==void 0&&this.sendResponse(n.id,{config:{providers:t.providers,models:t.models,bindings:t.bindings},paths:{userSettings:lt(),agentHome:q()}})}catch(e){n.id!==void 0&&this.sendResponse(n.id,void 0,{code:k.INTERNAL_ERROR,message:e instanceof Error?e.message:String(e)})}}var XI=new Set(["providers","models","bindings","provider","model","apiKey","baseUrl","providerKeys"]);async function sy(n){let e=n.params;if(!e?.updates||typeof e.updates!="object"){n.id!==void 0&&this.sendResponse(n.id,void 0,{code:k.INVALID_PARAMS,message:"updates (object) is required."});return}let t=[],r={};for(let[s,o]of Object.entries(e.updates))XI.has(s)?t.push({key:s,reason:"Use settings.* RPC methods for model/key management"}):r[s]=o;if(t.length>0&&Object.keys(r).length===0){n.id!==void 0&&this.sendResponse(n.id,void 0,{code:k.INVALID_PARAMS,message:`Rejected keys: ${t.map(s=>s.key).join(", ")}. Use settings.* RPC for model management.`});return}try{let s=lt(),o={};try{let i=await Ht.promises.readFile(s,"utf-8");o=JSON.parse(i)}catch{}Object.assign(o,r),await Ht.promises.mkdir(tl.dirname(s),{recursive:!0}),await Ht.promises.writeFile(s,JSON.stringify(o,null,2),"utf-8"),n.id!==void 0&&this.sendResponse(n.id,{ok:!0,applied:Object.keys(r),rejected:t})}catch(s){n.id!==void 0&&this.sendResponse(n.id,void 0,{code:k.INTERNAL_ERROR,message:s instanceof Error?s.message:String(s)})}}function oy(n){try{let e=Ri(),t=lt(),r={};try{let s=Ht.readFileSync(t,"utf-8"),o=JSON.parse(s);o.tunables&&typeof o.tunables=="object"&&(r=o.tunables)}catch{}n.id!==void 0&&this.sendResponse(n.id,{defaults:e,overrides:r})}catch(e){n.id!==void 0&&this.sendResponse(n.id,void 0,{code:k.INTERNAL_ERROR,message:e instanceof Error?e.message:String(e)})}}async function iy(n){let e=n.params,t=e?.key,r=e?.value;if(!t||typeof t!="string"){n.id!==void 0&&this.sendResponse(n.id,void 0,{code:k.INVALID_PARAMS,message:"Missing required param: key (string)"});return}let s=Ri();if(!(t in s)){n.id!==void 0&&this.sendResponse(n.id,void 0,{code:k.INVALID_PARAMS,message:`Unknown tunable key: "${t}". Valid keys: ${Object.keys(s).join(", ")}`});return}let o=typeof s[t];if(r==null||typeof r!==o){n.id!==void 0&&this.sendResponse(n.id,void 0,{code:k.INVALID_PARAMS,message:`Invalid value for "${t}": expected ${o}, got ${typeof r}`});return}try{let i=lt(),a={};try{let c=await Ht.promises.readFile(i,"utf-8");a=JSON.parse(c)}catch{}(!a.tunables||typeof a.tunables!="object")&&(a.tunables={}),a.tunables[t]=r,await Ht.promises.mkdir(tl.dirname(i),{recursive:!0}),await Ht.promises.writeFile(i,JSON.stringify(a,null,2),"utf-8"),t==="teamBudgetTokens"&&typeof r=="number"&&(Re.teamBudget.budgetTokens=r),n.id!==void 0&&this.sendResponse(n.id,{ok:!0,key:t,value:r})}catch(i){n.id!==void 0&&this.sendResponse(n.id,void 0,{code:k.INTERNAL_ERROR,message:i instanceof Error?i.message:String(i)})}}async function ay(n){let e=tt("task");if(!e){n.id!==void 0&&this.sendResponse(n.id,{items:[],summary:sr([])});return}try{let s=(await e.execute("rpc-todos-list",{action:"list"},void 0)).details?.taskList??[];n.id!==void 0&&this.sendResponse(n.id,{items:s,summary:sr(s)})}catch{n.id!==void 0&&this.sendResponse(n.id,{items:[],summary:sr([])})}}function cy(n){let t=n.params?.lifecycle??"all",r=this.taskStore.getAllTasks(),s=t==="all"?r:r.filter(o=>o.lifecycle===t);n.id!==void 0&&this.sendResponse(n.id,{tasks:s.map(o=>({taskId:o.taskId,type:o.type,lifecycle:o.lifecycle,label:o.label}))})}function ly(n){let e=n.params;if(!e?.taskId){n.id!==void 0&&this.sendResponse(n.id,void 0,{code:k.INVALID_PARAMS,message:"taskId is required."});return}let r=this.taskStore.getAllTasks().find(s=>s.taskId===e.taskId);if(!r){n.id!==void 0&&this.sendResponse(n.id,{ok:!1,message:`Task ${e.taskId} not found.`});return}if(r.lifecycle!=="running"&&r.lifecycle!=="pending"){n.id!==void 0&&this.sendResponse(n.id,{ok:!1,message:`Task ${e.taskId} is already ${r.lifecycle}.`});return}this.taskStore.updateTask(e.taskId,s=>(s.lifecycle="cancelled",s)),n.id!==void 0&&this.sendResponse(n.id,{ok:!0,message:`Task ${e.taskId} cancelled.`})}ae();import*as dy from"node:fs";import*as po from"node:path";import{randomUUID as YI}from"node:crypto";async function uy(n){try{let e=n.params,t=await this.ensureAgentConfigStore();this.acpDetector.setConfigStore(t.getData());let r=this.acpDetector.scan(e?.force);n.id!==void 0&&this.sendResponse(n.id,r)}catch(e){n.id!==void 0&&this.sendResponse(n.id,void 0,{code:k.INTERNAL_ERROR,message:e instanceof Error?e.message:String(e)})}}async function py(n){try{let e=await this.ensureAgentConfigStore();this.acpDetector.setConfigStore(e.getData());let t=this.acpDetector.list();n.id!==void 0&&this.sendResponse(n.id,t)}catch(e){n.id!==void 0&&this.sendResponse(n.id,void 0,{code:k.INTERNAL_ERROR,message:e instanceof Error?e.message:String(e)})}}async function my(n){try{let e=n.params;if(!e?.action||!e?.agent){n.id!==void 0&&this.sendResponse(n.id,void 0,{code:k.INVALID_PARAMS,message:"action and agent are required."});return}let t=await this.ensureAgentConfigStore();switch(e.action){case"register":t.registerCustomAgent(e.agent);break;case"unregister":t.unregisterCustomAgent(e.agent.id);break;case"update":t.registerCustomAgent(e.agent);break}this.acpDetector.setConfigStore(t.getData()),this.acpDetector.clearCache(),n.id!==void 0&&this.sendResponse(n.id,{ok:!0})}catch(e){n.id!==void 0&&this.sendResponse(n.id,void 0,{code:k.INTERNAL_ERROR,message:e instanceof Error?e.message:String(e)})}}async function gy(n){try{let e=n.params;if(!e?.agentId){n.id!==void 0&&this.sendResponse(n.id,void 0,{code:k.INVALID_PARAMS,message:"agentId is required."});return}let t=await this.ensureAgentConfigStore(),{agentId:r,...s}=e;await t.setAgentConfig(r,s),this.acpDetector.setConfigStore(t.getData()),n.id!==void 0&&this.sendResponse(n.id,{ok:!0})}catch(e){n.id!==void 0&&this.sendResponse(n.id,void 0,{code:k.INTERNAL_ERROR,message:e instanceof Error?e.message:String(e)})}}async function fy(n){try{let e=n.params;if(!e?.agentId){n.id!==void 0&&this.sendResponse(n.id,void 0,{code:k.INVALID_PARAMS,message:"agentId is required."});return}let r=(await this.ensureAgentConfigStore()).getAgentConfig(e.agentId);n.id!==void 0&&this.sendResponse(n.id,r)}catch(e){n.id!==void 0&&this.sendResponse(n.id,void 0,{code:k.INTERNAL_ERROR,message:e instanceof Error?e.message:String(e)})}}async function hy(n){try{let e=n.params;if(!e?.agentId){n.id!==void 0&&this.sendResponse(n.id,void 0,{code:k.INVALID_PARAMS,message:"agentId is required."});return}let t=await this.ensureAgentConfigStore();await t.removeAgentConfig(e.agentId),this.acpDetector.setConfigStore(t.getData()),n.id!==void 0&&this.sendResponse(n.id,{ok:!0})}catch(e){n.id!==void 0&&this.sendResponse(n.id,void 0,{code:k.INTERNAL_ERROR,message:e instanceof Error?e.message:String(e)})}}async function yy(n){try{let e=n.params;if(!e?.url){n.id!==void 0&&this.sendResponse(n.id,void 0,{code:k.INVALID_PARAMS,message:"url is required."});return}await(await this.ensureAgentConfigStore()).setGatewayUrl(e.url),n.id!==void 0&&this.sendResponse(n.id,{ok:!0})}catch(e){n.id!==void 0&&this.sendResponse(n.id,void 0,{code:k.INTERNAL_ERROR,message:e instanceof Error?e.message:String(e)})}}async function by(n){try{let t=(await this.ensureAgentConfigStore()).getGatewayUrl();n.id!==void 0&&this.sendResponse(n.id,{url:t})}catch(e){n.id!==void 0&&this.sendResponse(n.id,void 0,{code:k.INTERNAL_ERROR,message:e instanceof Error?e.message:String(e)})}}async function ky(n){try{let t=(await this.ensureAgentConfigStore()).getData(),r=Object.entries(t.agents).map(([s,o])=>({agentId:s,hasApiKey:!!o.apiKey,hasBaseUrl:!!o.baseUrl,hasModel:!!o.model}));n.id!==void 0&&this.sendResponse(n.id,r)}catch(e){n.id!==void 0&&this.sendResponse(n.id,void 0,{code:k.INTERNAL_ERROR,message:e instanceof Error?e.message:String(e)})}}function vy(n){try{let e=[],t=(r,s)=>{if(r)for(let o of r.getAllHandles())e.push({memberId:o.memberId,name:o.name,pid:o.pid,state:o.state,startedAt:o.startedAt,endedAt:o.endedAt,source:s})};t(this.soloProcessManager,"solo"),t(this.productProcessManager,"product"),n.id!==void 0&&this.sendResponse(n.id,e)}catch(e){n.id!==void 0&&this.sendResponse(n.id,void 0,{code:k.INTERNAL_ERROR,message:e instanceof Error?e.message:String(e)})}}function Sy(n){try{let e=n.params;if(!e?.memberId){n.id!==void 0&&this.sendResponse(n.id,void 0,{code:k.INVALID_PARAMS,message:"memberId is required."});return}let t=!1;for(let r of[this.soloProcessManager,this.productProcessManager])if(r?.getHandle(e.memberId)){r.kill(e.memberId),t=!0;break}n.id!==void 0&&this.sendResponse(n.id,{ok:t})}catch(e){n.id!==void 0&&this.sendResponse(n.id,void 0,{code:k.INTERNAL_ERROR,message:e instanceof Error?e.message:String(e)})}}async function Ty(n){try{let e=n.params;if(!e?.agentId){n.id!==void 0&&this.sendResponse(n.id,void 0,{code:k.INVALID_PARAMS,message:"agentId is required."});return}let t=po.join(q(),"agent-logs"),r=po.join(t,`${e.agentId}.stderr.log`),s="";try{s=dy.readFileSync(r,"utf-8")}catch{}e.tail&&e.tail>0&&s&&(s=s.split(`
|
|
851
851
|
`).slice(-e.tail).join(`
|
|
852
|
-
`)),n.id!==void 0&&this.sendResponse(n.id,{log:s})}catch(e){n.id!==void 0&&this.sendResponse(n.id,void 0,{code:k.INTERNAL_ERROR,message:e instanceof Error?e.message:String(e)})}}async function Ry(n){try{let e=n.params;if(!e?.agentId){n.id!==void 0&&this.sendResponse(n.id,void 0,{code:k.INVALID_PARAMS,message:"agentId is required."});return}let t=await this.ensureAgentConfigStore();this.acpDetector.setConfigStore(t.getData());let s=this.acpDetector.list().find(i=>i.id===e.agentId);if(!s){n.id!==void 0&&this.sendResponse(n.id,{ok:!1,error:`Agent ${e.agentId} not found`,durationMs:0});return}if(s.status==="not_installed"){n.id!==void 0&&this.sendResponse(n.id,{ok:!1,error:`Agent ${e.agentId} is not installed`,durationMs:0});return}let o=Date.now();n.id!==void 0&&this.sendResponse(n.id,{ok:s.status==="available",version:s.version,capabilities:s.capabilities,error:s.status!=="available"?`Agent status: ${s.status}`:void 0,durationMs:Date.now()-o})}catch(e){n.id!==void 0&&this.sendResponse(n.id,void 0,{code:k.INTERNAL_ERROR,message:e instanceof Error?e.message:String(e)})}}async function wy(n){let e=null,t="";try{let r=n.params??{},s=typeof r.agentId=="string"?r.agentId.trim():"",o=typeof r.prompt=="string"?r.prompt:"";if(!s||!o.trim()){n.id!==void 0&&this.sendResponse(n.id,void 0,{code:k.INVALID_PARAMS,message:"agentId and prompt are required."});return}let i=await this.ensureAgentConfigStore();this.acpDetector.setConfigStore(i.getData()),this.acpDetector.scan(!1);let a=this.acpDetector.buildExternalDescriptor(s);if(!a){n.id!==void 0&&this.sendResponse(n.id,void 0,{code:k.INVALID_PARAMS,message:`Agent ${s} is not available or not ACP-compatible.`});return}let c=typeof r.cwd=="string"&&r.cwd?r.cwd:typeof this.getActiveProjectRoot=="function"?this.getActiveProjectRoot():process.cwd(),l=typeof r.timeoutMs=="number"&&r.timeoutMs>0?r.timeoutMs:3e5;t=`chat-${s}-${YI().slice(0,8)}`;let u=[];e=new _t({onNotification:(h,f,y)=>{if(f!=="turn.delta")return;let b=typeof y?.text=="string"?y.text:"";b&&u.push(b)},onMcpToolCall:async(h,f,y)=>typeof this.handleMcpToolCall=="function"?this.handleMcpToolCall(h,f,y):{ok:!1,error:"MCP tool call unavailable"},log:{info:h=>this.log?.(`[agents.prompt] ${h}`),warn:h=>this.log?.(`[agents.prompt] WARN: ${h}`),debug:h=>this.log?.(`[agents.prompt] ${h}`)},sessionDir:po.join(q(),"agent-logs")}),await e.spawn({memberId:t,name:`chat-${s}`,cwd:c,prompt:o,external:a,systemPrompt:typeof r.systemPrompt=="string"?r.systemPrompt:void 0});let d=await e.sendTask(t,o,{
|
|
852
|
+
`)),n.id!==void 0&&this.sendResponse(n.id,{log:s})}catch(e){n.id!==void 0&&this.sendResponse(n.id,void 0,{code:k.INTERNAL_ERROR,message:e instanceof Error?e.message:String(e)})}}async function Ry(n){try{let e=n.params;if(!e?.agentId){n.id!==void 0&&this.sendResponse(n.id,void 0,{code:k.INVALID_PARAMS,message:"agentId is required."});return}let t=await this.ensureAgentConfigStore();this.acpDetector.setConfigStore(t.getData());let s=this.acpDetector.list().find(i=>i.id===e.agentId);if(!s){n.id!==void 0&&this.sendResponse(n.id,{ok:!1,error:`Agent ${e.agentId} not found`,durationMs:0});return}if(s.status==="not_installed"){n.id!==void 0&&this.sendResponse(n.id,{ok:!1,error:`Agent ${e.agentId} is not installed`,durationMs:0});return}let o=Date.now();n.id!==void 0&&this.sendResponse(n.id,{ok:s.status==="available",version:s.version,capabilities:s.capabilities,error:s.status!=="available"?`Agent status: ${s.status}`:void 0,durationMs:Date.now()-o})}catch(e){n.id!==void 0&&this.sendResponse(n.id,void 0,{code:k.INTERNAL_ERROR,message:e instanceof Error?e.message:String(e)})}}async function wy(n){let e=null,t="";try{let r=n.params??{},s=typeof r.agentId=="string"?r.agentId.trim():"",o=typeof r.prompt=="string"?r.prompt:"";if(!s||!o.trim()){n.id!==void 0&&this.sendResponse(n.id,void 0,{code:k.INVALID_PARAMS,message:"agentId and prompt are required."});return}let i=await this.ensureAgentConfigStore();this.acpDetector.setConfigStore(i.getData()),this.acpDetector.scan(!1);let a=this.acpDetector.buildExternalDescriptor(s);if(!a){n.id!==void 0&&this.sendResponse(n.id,void 0,{code:k.INVALID_PARAMS,message:`Agent ${s} is not available or not ACP-compatible.`});return}let c=typeof r.cwd=="string"&&r.cwd?r.cwd:typeof this.getActiveProjectRoot=="function"?this.getActiveProjectRoot():process.cwd(),l=typeof r.timeoutMs=="number"&&r.timeoutMs>0?r.timeoutMs:3e5;t=`chat-${s}-${YI().slice(0,8)}`;let u=[];e=new _t({onNotification:(h,f,y)=>{if(f!=="turn.delta")return;let b=typeof y?.text=="string"?y.text:"";b&&u.push(b)},onMcpToolCall:async(h,f,y)=>typeof this.handleMcpToolCall=="function"?this.handleMcpToolCall(h,f,y):{ok:!1,error:"MCP tool call unavailable"},log:{info:h=>this.log?.(`[agents.prompt] ${h}`),warn:h=>this.log?.(`[agents.prompt] WARN: ${h}`),debug:h=>this.log?.(`[agents.prompt] ${h}`)},sessionDir:po.join(q(),"agent-logs")}),await e.spawn({memberId:t,name:`chat-${s}`,cwd:c,prompt:o,external:a,systemPrompt:typeof r.systemPrompt=="string"?r.systemPrompt:void 0});let d=await e.sendTask(t,o,{timeout:l}),p=u.join("")||(typeof d?.content=="string"?d.content:""),m=e.getUsageTracker(t)?.getUsage();n.id!==void 0&&this.sendResponse(n.id,{ok:!0,agentId:s,content:p,stopReason:d?.stopReason,usage:m?{inputTokens:m.inputTokens,outputTokens:m.outputTokens,totalTokens:m.totalTokens,cacheRead:m.cachedReadTokens,thoughtTokens:m.thoughtTokens,cost:m.cost}:void 0})}catch(r){n.id!==void 0&&this.sendResponse(n.id,void 0,{code:k.INTERNAL_ERROR,message:r instanceof Error?r.message:String(r)})}finally{if(e&&t){try{e.kill(t)}catch{}try{e.dispose()}catch{}}}}import{isAsyncMediaTransport as Ay}from"@xiaozhiclaw/provider-core";dt();async function xy(n){try{if(!this.mediaClient){n.id!==void 0&&this.sendResponse(n.id,{models:[]});return}let e=await this.mediaClient.listModels();n.id!==void 0&&this.sendResponse(n.id,{models:e})}catch(e){n.id!==void 0&&this.sendResponse(n.id,void 0,{code:k.INTERNAL_ERROR,message:e instanceof Error?e.message:String(e)})}}async function Py(n){let e=n.params;if(!e?.taskId){n.id!==void 0&&this.sendResponse(n.id,void 0,{code:k.INVALID_PARAMS,message:"taskId is required."});return}try{if(!this.mediaClient||!Ay(this.mediaClient)){n.id!==void 0&&this.sendResponse(n.id,{ok:!1,message:"Media client does not support async cancel."});return}await this.mediaClient.cancel(e.taskId),n.id!==void 0&&this.sendResponse(n.id,{ok:!0})}catch(t){n.id!==void 0&&this.sendResponse(n.id,void 0,{code:k.INTERNAL_ERROR,message:t instanceof Error?t.message:String(t)})}}async function Iy(n){let e=n.params;if(!e?.taskId){n.id!==void 0&&this.sendResponse(n.id,void 0,{code:k.INVALID_PARAMS,message:"taskId is required."});return}try{if(!this.mediaClient||!Ay(this.mediaClient)){n.id!==void 0&&this.sendResponse(n.id,{status:"unknown",message:"Media client does not support status queries."});return}let t=await this.mediaClient.queryStatus(e.taskId);n.id!==void 0&&this.sendResponse(n.id,t)}catch(t){n.id!==void 0&&this.sendResponse(n.id,void 0,{code:k.INTERNAL_ERROR,message:t instanceof Error?t.message:String(t)})}}async function _y(n){let e=n.params;if(!e?.audioBase64){n.id!==void 0&&this.sendResponse(n.id,void 0,{code:k.INVALID_PARAMS,message:"audioBase64 is required."});return}let r=X().getActiveModel("stt");if(!r){n.id!==void 0&&this.sendResponse(n.id,void 0,{code:k.INTERNAL_ERROR,message:"STT not configured. Add an STT model and bind it in settings."});return}let{apiKey:s,model:o,baseUrl:i,keyHandle:a}=r;if(!i){a.release({success:!1}),n.id!==void 0&&this.sendResponse(n.id,void 0,{code:k.INTERNAL_ERROR,message:"STT baseUrl not configured. Set baseUrl on the STT model entry."});return}try{let c=`----STTBoundary${Date.now()}`,l=[];l.push(`--${c}\r
|
|
853
853
|
Content-Disposition: form-data; name="model"\r
|
|
854
854
|
\r
|
|
855
855
|
${o}`),l.push(`--${c}\r
|
package/dist/index.js
CHANGED
|
@@ -848,7 +848,7 @@ ${c||"(\u65E0)"}`].join(`
|
|
|
848
848
|
`),u="";try{for await(let h of s.transport.stream({model:s.model,messages:[{role:"user",content:l}],temperature:.1,maxTokens:900,tools:[]},s.apiKey))h.type==="delta"&&(u+=h.text)}catch{return null}let d=LI(u),m=(Array.isArray(d?.memories)?d.memories:[]).map(h=>({id:`candidate-${$h()}`,text:typeof h?.text=="string"?h.text.trim().slice(0,1400):"",category:lo(h?.category),importance:Dr(h?.importance,.1,1,.65),confidence:Dr(h?.confidence,.05,1,.65),source:typeof h?.source=="string"&&h.source.trim()?h.source.trim().slice(0,80):"manual",eventDate:typeof h?.eventDate=="string"?h.eventDate.trim().slice(0,32):"",tags:uo(h?.tags),relatedMemoryIds:Array.isArray(h?.relatedMemoryIds)?h.relatedMemoryIds.filter(f=>typeof f=="string").slice(0,8):[],evidence:[...o?[{type:"text",excerpt:o.slice(0,500)}]:[],...i.map(f=>({type:f.type,filename:f.filename,mimeType:f.mimeType}))],requiresConfirmation:h?.requiresConfirmation!==!1,reason:typeof h?.reason=="string"?h.reason.trim().slice(0,300):""})).filter(h=>h.text.length>=6);return m.length>0?m:null}async function jh(n,e,t){let r=typeof e?.text=="string"?e.text.trim():"",s=Array.isArray(e?.attachments)?e.attachments.map(Jc):[],o=await $I(n,[r,...s.map(Qc)].join(`
|
|
849
849
|
`),t),i=e?.autoExtract===!1?null:await UI(n,e,o);return{candidates:i??jI(e,o),relatedMemories:o,extractor:i?"llm":"deterministic"}}async function Uh(n,e,t){let r=0;for(let s of t){let o=typeof s?.text=="string"?s.text.trim():"";if(!o)continue;let i=uo([...s.tags??[],...(s.relatedMemoryIds??[]).map(c=>`related:${c}`)]),a={text:o,category:lo(s.category),importance:Dr(s.importance,.1,1,.6),event_date:typeof s.eventDate=="string"?s.eventDate:"",tags:i};if(typeof n.memoryProvider.ingestExtracted=="function"){let c=await n.memoryProvider.ingestExtracted([a],e,{source:typeof s.source=="string"&&s.source.trim()?s.source.trim():"manual"});r+=c?.memoriesAdded??0}else{let c=await n.memoryProvider.addText(o,e,{category:a.category,importance:a.importance,source:typeof s.source=="string"&&s.source.trim()?s.source.trim():"manual",tags:i});r+=c?.memoriesAdded??0}}return r}function Ln(n,e){let r=(typeof e=="string"&&e.trim()?e:typeof n.memoryUserId=="string"&&n.memoryUserId.trim()?n.memoryUserId:"").trim();return r||null}function Lh(){return{totalCount:0,records:[],buckets:[],clusters:[],windowCursor:null,timeRange:null,stats:{formed:0,insights:0,preferences:0}}}function FI(n,e){let t=0,r=0;for(let s of e??[])s?.kind==="category"&&((s.label==="insight"||s.label==="lesson")&&(t+=Number(s.count??0)),s.label==="preference"&&(r+=Number(s.count??0)));return{formed:n,insights:t,preferences:r}}async function Fh(n){let e=[];this.memdir&&e.push({id:"memdir",type:"file",path:wc(this.getActiveProjectRoot())}),this.memoryProvider&&e.push({id:"local",type:"vector"}),n.id!==void 0&&this.sendResponse(n.id,{sources:e})}async function Bh(n){let e=n.params;if(this.ensureMemoryProvider?.(),!this.memoryProvider||typeof this.memoryProvider.getAtlas!="function"){n.id!==void 0&&this.sendResponse(n.id,Lh());return}try{let t=Ln(this,e?.userId);if(!t){n.id!==void 0&&this.sendResponse(n.id,Lh());return}let r=this.memoryProvider.getAtlas(t,{pageSize:e?.pageSize??360,windowStartAt:e?.windowStartAt,windowEndAt:e?.windowEndAt,windowCenterAt:e?.windowCenterAt,bucketCount:e?.bucketCount??96,clusterLimit:e?.clusterLimit??48,activeOnly:!0}),s=(r.records??[]).map(a=>({id:a.id,text:a.text,category:a.category,importance:a.importance,confidence:a.confidence,source:a.source,sessionId:a.sessionId,eventDate:a.eventDate,tags:a.tags,createdAt:a.createdAt,updatedAt:a.updatedAt,accessCount:a.accessCount,lastAccessedAt:a.lastAccessedAt,isArchived:a.isArchived})),o=Number(r.totalCount??s.length),i=r.clusters??[];n.id!==void 0&&this.sendResponse(n.id,{totalCount:o,records:s,buckets:r.buckets??[],clusters:i,windowCursor:r.windowCursor??null,timeRange:r.timeRange??null,stats:FI(o,i)})}catch(t){n.id!==void 0&&this.sendResponse(n.id,void 0,{code:k.INTERNAL_ERROR,message:t instanceof Error?t.message:String(t)})}}async function Hh(n){let e=n.params;if(this.ensureMemoryProvider?.(),!this.memoryProvider||typeof this.memoryProvider.getActivitySummary!="function"){n.id!==void 0&&this.sendResponse(n.id,{dailyCounts:[],highlights:[]});return}try{let t=Ln(this,e?.userId);if(!t){n.id!==void 0&&this.sendResponse(n.id,{dailyCounts:[],highlights:[]});return}let r=this.memoryProvider.getActivitySummary(t,e?.days??180);n.id!==void 0&&this.sendResponse(n.id,r)}catch(t){n.id!==void 0&&this.sendResponse(n.id,void 0,{code:k.INTERNAL_ERROR,message:t instanceof Error?t.message:String(t)})}}async function qh(n){let e=n.params;if(this.ensureMemoryProvider?.(),!this.memoryProvider||typeof this.memoryProvider.addText!="function"){n.id!==void 0&&this.sendResponse(n.id,void 0,{code:k.INTERNAL_ERROR,message:"Long-term memory provider is not initialized."});return}let t=typeof e?.text=="string"?e.text.trim():"";if(!t){n.id!==void 0&&this.sendResponse(n.id,void 0,{code:k.INVALID_PARAMS,message:"text is required."});return}let r=Ln(this,e?.userId);if(!r){n.id!==void 0&&this.sendResponse(n.id,void 0,{code:k.INVALID_PARAMS,message:"llmrouter user id is required for long-term memory."});return}let s=new Set(["fact","preference","insight","lesson","decision","plan","event","general"]),o=typeof e?.category=="string"&&s.has(e.category)?e.category:"general",i=typeof e?.importance=="number"&&Number.isFinite(e.importance)?Math.max(.1,Math.min(1,e.importance)):.6;try{let{candidates:a}=await jh(this,{...e,text:t,category:o,importance:i,source:typeof e?.source=="string"&&e.source.trim()?e.source.trim():"manual",autoExtract:e?.autoExtract??!0},r),c=await Uh(this,r,a);n.id!==void 0&&this.sendResponse(n.id,{ok:!0,memoriesAdded:c}),this.sendNotification?.("memory.updated",{source:"local",target:"atlas"})}catch(a){n.id!==void 0&&this.sendResponse(n.id,void 0,{code:k.INTERNAL_ERROR,message:a instanceof Error?a.message:String(a)})}}async function Wh(n){let e=n.params;if(this.ensureMemoryProvider?.(),!this.memoryProvider){n.id!==void 0&&this.sendResponse(n.id,void 0,{code:k.INTERNAL_ERROR,message:"Long-term memory provider is not initialized."});return}let t=typeof e?.text=="string"?e.text.trim():"",r=Array.isArray(e?.attachments)?e.attachments:[];if(!t&&r.length===0){n.id!==void 0&&this.sendResponse(n.id,void 0,{code:k.INVALID_PARAMS,message:"text or attachments are required."});return}let s=Ln(this,e?.userId);if(!s){n.id!==void 0&&this.sendResponse(n.id,void 0,{code:k.INVALID_PARAMS,message:"llmrouter user id is required for long-term memory."});return}try{let o=await jh(this,e??{},s);n.id!==void 0&&this.sendResponse(n.id,{ok:!0,candidates:o.candidates,relatedMemories:o.relatedMemories,extractor:o.extractor})}catch(o){n.id!==void 0&&this.sendResponse(n.id,void 0,{code:k.INTERNAL_ERROR,message:o instanceof Error?o.message:String(o)})}}async function Gh(n){let e=n.params;if(this.ensureMemoryProvider?.(),!this.memoryProvider||typeof this.memoryProvider.addText!="function"){n.id!==void 0&&this.sendResponse(n.id,void 0,{code:k.INTERNAL_ERROR,message:"Long-term memory provider is not initialized."});return}let t=Ln(this,e?.userId);if(!t){n.id!==void 0&&this.sendResponse(n.id,void 0,{code:k.INVALID_PARAMS,message:"llmrouter user id is required for long-term memory."});return}let r=Array.isArray(e?.candidates)?e.candidates:[];if(r.length===0){n.id!==void 0&&this.sendResponse(n.id,void 0,{code:k.INVALID_PARAMS,message:"candidates are required."});return}try{let s=await Uh(this,t,r);n.id!==void 0&&this.sendResponse(n.id,{ok:!0,memoriesAdded:s}),this.sendNotification?.("memory.updated",{source:"local",target:"atlas"})}catch(s){n.id!==void 0&&this.sendResponse(n.id,void 0,{code:k.INTERNAL_ERROR,message:s instanceof Error?s.message:String(s)})}}async function Kh(n){let e=n.params,t=e?.source??"memdir",r=e?.target??"index";if(t==="memdir"||t==="local"){if(!this.memdir){n.id!==void 0&&this.sendResponse(n.id,{source:"memdir",target:r,content:""});return}try{if(r==="index"){let s=this.memdir.getIndexRaw();n.id!==void 0&&this.sendResponse(n.id,{source:"memdir",target:"index",content:s})}else{let s=await this.memdir.readFile(r);n.id!==void 0&&this.sendResponse(n.id,{source:"memdir",target:r,content:s.content??""})}}catch{n.id!==void 0&&this.sendResponse(n.id,{source:"memdir",target:r,content:""})}}else n.id!==void 0&&this.sendResponse(n.id,void 0,{code:k.INVALID_PARAMS,message:`Unknown memory source: ${t}`})}async function Vh(n){let e=n.params,t=e?.target??"index",r=e?.content;if(r==null){n.id!==void 0&&this.sendResponse(n.id,void 0,{code:k.INVALID_PARAMS,message:"content is required."});return}if(!this.memdir){n.id!==void 0&&this.sendResponse(n.id,void 0,{code:k.INTERNAL_ERROR,message:"Memory system not initialized."});return}try{if(t==="index"){let s=await this.memdir.addToIndex(r);n.id!==void 0&&this.sendResponse(n.id,{ok:s.ok,target:"index",message:s.message})}else{let s=await this.memdir.writeFile(t,r);n.id!==void 0&&this.sendResponse(n.id,{ok:s.ok,target:t,message:s.message})}this.sendNotification("memory.updated",{target:t,source:"rpc"})}catch(s){n.id!==void 0&&this.sendResponse(n.id,void 0,{code:k.INTERNAL_ERROR,message:s instanceof Error?s.message:String(s)})}}async function zh(n){let e=n.params;if(!e?.query){n.id!==void 0&&this.sendResponse(n.id,void 0,{code:k.INVALID_PARAMS,message:"query is required."});return}if(this.memoryProvider){let t=Ln(this,e.userId);if(!t){n.id!==void 0&&this.sendResponse(n.id,{results:[]});return}try{let r=await this.memoryProvider.search(e.query,t,{limit:e.limit??10});n.id!==void 0&&this.sendResponse(n.id,{results:r.map(s=>({id:s.blockId??"",text:s.text,score:s.score,source:"local",metadata:s.metadata}))})}catch(r){n.id!==void 0&&this.sendResponse(n.id,void 0,{code:k.INTERNAL_ERROR,message:r instanceof Error?r.message:String(r)})}}else if(this.memdir)try{let t=await this.memdir.searchLocal(e.query);n.id!==void 0&&this.sendResponse(n.id,{results:t.slice(0,e.limit??10).map((r,s)=>({id:`memdir-${s}`,text:r.snippet,score:r.score,source:"memdir",metadata:{file:r.file}}))})}catch{n.id!==void 0&&this.sendResponse(n.id,{results:[]})}else n.id!==void 0&&this.sendResponse(n.id,{results:[]})}async function Xh(n){let e=n.params;if(!e?.match){n.id!==void 0&&this.sendResponse(n.id,void 0,{code:k.INVALID_PARAMS,message:"match is required."});return}let t=e.source??"memdir";if(t==="memdir"||t==="local"){if(!this.memdir){n.id!==void 0&&this.sendResponse(n.id,void 0,{code:k.INTERNAL_ERROR,message:"Memory system not initialized."});return}let r=e.target??"index";try{if(r==="index"){let s=await this.memdir.removeFromIndex(e.match);n.id!==void 0&&this.sendResponse(n.id,{ok:s.ok,removedCount:s.ok?1:0,message:s.message}),s.ok&&this.sendNotification("memory.updated",{source:"memdir",target:"index"})}else{let s=await this.memdir.deleteFile(r);n.id!==void 0&&this.sendResponse(n.id,{ok:s.ok,removedCount:s.ok?1:0,message:s.message}),s.ok&&this.sendNotification("memory.updated",{source:"memdir",target:r})}}catch(s){n.id!==void 0&&this.sendResponse(n.id,void 0,{code:k.INTERNAL_ERROR,message:s instanceof Error?s.message:String(s)})}}else if(t==="vector"&&this.memoryProvider)try{await this.memoryProvider.remove(e.match),n.id!==void 0&&this.sendResponse(n.id,{ok:!0,removedCount:1,message:"Removed from local memory."}),this.sendNotification("memory.updated",{source:"local"})}catch(r){n.id!==void 0&&this.sendResponse(n.id,void 0,{code:k.INTERNAL_ERROR,message:r instanceof Error?r.message:String(r)})}else n.id!==void 0&&this.sendResponse(n.id,void 0,{code:k.INVALID_PARAMS,message:`Unknown or unavailable source: ${t}`})}async function Yh(n){let e=n.params,t=typeof e?.id=="string"?e.id.trim():"";if(!t){n.id!==void 0&&this.sendResponse(n.id,void 0,{code:k.INVALID_PARAMS,message:"id is required."});return}if(this.ensureMemoryProvider?.(),!this.memoryProvider||typeof this.memoryProvider.update!="function"){n.id!==void 0&&this.sendResponse(n.id,void 0,{code:k.INTERNAL_ERROR,message:"Long-term memory provider does not support updates."});return}try{let r=await this.memoryProvider.update(t,{text:typeof e?.text=="string"?e.text:void 0,category:typeof e?.category=="string"?lo(e.category):void 0,importance:typeof e?.importance=="number"?Dr(e.importance,.1,1,.6):void 0,source:typeof e?.source=="string"?e.source.trim().slice(0,80):void 0,eventDate:typeof e?.eventDate=="string"?e.eventDate.trim().slice(0,32):void 0,tags:Array.isArray(e?.tags)?uo(e.tags):void 0});n.id!==void 0&&this.sendResponse(n.id,{ok:r,updated:r?1:0}),r&&this.sendNotification("memory.updated",{source:"local",target:"atlas"})}catch(r){n.id!==void 0&&this.sendResponse(n.id,void 0,{code:k.INTERNAL_ERROR,message:r instanceof Error?r.message:String(r)})}}ae();lt();import*as Bt from"node:fs";import*as Zc from"node:path";je();function Jh(n){let e=n.params,r=wt(e?.includeDeferred??!1).map(s=>({name:s.function.name,description:s.function.description??"",parameters:s.function.parameters,source:"builtin"}));if(e?.category){let s=r.filter(o=>o.name.startsWith(e.category)||o.description.toLowerCase().includes(e.category.toLowerCase()));n.id!==void 0&&this.sendResponse(n.id,{tools:s,total:s.length})}else n.id!==void 0&&this.sendResponse(n.id,{tools:r,total:r.length})}function Qh(n){let e=X().listProviderDefs(),t=new Map;for(let s of e){let o=s.group??s.id;t.has(o)||t.set(o,[]);let i=!!X().resolveProviderApiKey(s.id);t.get(o).push({id:s.id,name:s.name,transport:s.transport,baseUrl:s.baseUrl,defaultModel:s.defaultModel,modelCount:s.models?.length??0,available:i})}let r=[...t.entries()].map(([s,o])=>({group:s,variants:o}));n.id!==void 0&&this.sendResponse(n.id,{providers:r})}function Zh(n){try{let t=X().exportConfig();n.id!==void 0&&this.sendResponse(n.id,{config:{providers:t.providers,models:t.models,bindings:t.bindings},paths:{userSettings:ct(),agentHome:q()}})}catch(e){n.id!==void 0&&this.sendResponse(n.id,void 0,{code:k.INTERNAL_ERROR,message:e instanceof Error?e.message:String(e)})}}var BI=new Set(["providers","models","bindings","provider","model","apiKey","baseUrl","providerKeys"]);async function ey(n){let e=n.params;if(!e?.updates||typeof e.updates!="object"){n.id!==void 0&&this.sendResponse(n.id,void 0,{code:k.INVALID_PARAMS,message:"updates (object) is required."});return}let t=[],r={};for(let[s,o]of Object.entries(e.updates))BI.has(s)?t.push({key:s,reason:"Use settings.* RPC methods for model/key management"}):r[s]=o;if(t.length>0&&Object.keys(r).length===0){n.id!==void 0&&this.sendResponse(n.id,void 0,{code:k.INVALID_PARAMS,message:`Rejected keys: ${t.map(s=>s.key).join(", ")}. Use settings.* RPC for model management.`});return}try{let s=ct(),o={};try{let i=await Bt.promises.readFile(s,"utf-8");o=JSON.parse(i)}catch{}Object.assign(o,r),await Bt.promises.mkdir(Zc.dirname(s),{recursive:!0}),await Bt.promises.writeFile(s,JSON.stringify(o,null,2),"utf-8"),n.id!==void 0&&this.sendResponse(n.id,{ok:!0,applied:Object.keys(r),rejected:t})}catch(s){n.id!==void 0&&this.sendResponse(n.id,void 0,{code:k.INTERNAL_ERROR,message:s instanceof Error?s.message:String(s)})}}function ty(n){try{let e=Si(),t=ct(),r={};try{let s=Bt.readFileSync(t,"utf-8"),o=JSON.parse(s);o.tunables&&typeof o.tunables=="object"&&(r=o.tunables)}catch{}n.id!==void 0&&this.sendResponse(n.id,{defaults:e,overrides:r})}catch(e){n.id!==void 0&&this.sendResponse(n.id,void 0,{code:k.INTERNAL_ERROR,message:e instanceof Error?e.message:String(e)})}}async function ny(n){let e=n.params,t=e?.key,r=e?.value;if(!t||typeof t!="string"){n.id!==void 0&&this.sendResponse(n.id,void 0,{code:k.INVALID_PARAMS,message:"Missing required param: key (string)"});return}let s=Si();if(!(t in s)){n.id!==void 0&&this.sendResponse(n.id,void 0,{code:k.INVALID_PARAMS,message:`Unknown tunable key: "${t}". Valid keys: ${Object.keys(s).join(", ")}`});return}let o=typeof s[t];if(r==null||typeof r!==o){n.id!==void 0&&this.sendResponse(n.id,void 0,{code:k.INVALID_PARAMS,message:`Invalid value for "${t}": expected ${o}, got ${typeof r}`});return}try{let i=ct(),a={};try{let c=await Bt.promises.readFile(i,"utf-8");a=JSON.parse(c)}catch{}(!a.tunables||typeof a.tunables!="object")&&(a.tunables={}),a.tunables[t]=r,await Bt.promises.mkdir(Zc.dirname(i),{recursive:!0}),await Bt.promises.writeFile(i,JSON.stringify(a,null,2),"utf-8"),t==="teamBudgetTokens"&&typeof r=="number"&&(Re.teamBudget.budgetTokens=r),n.id!==void 0&&this.sendResponse(n.id,{ok:!0,key:t,value:r})}catch(i){n.id!==void 0&&this.sendResponse(n.id,void 0,{code:k.INTERNAL_ERROR,message:i instanceof Error?i.message:String(i)})}}async function ry(n){let e=et("task");if(!e){n.id!==void 0&&this.sendResponse(n.id,{items:[],summary:sr([])});return}try{let s=(await e.execute("rpc-todos-list",{action:"list"},void 0)).details?.taskList??[];n.id!==void 0&&this.sendResponse(n.id,{items:s,summary:sr(s)})}catch{n.id!==void 0&&this.sendResponse(n.id,{items:[],summary:sr([])})}}function sy(n){let t=n.params?.lifecycle??"all",r=this.taskStore.getAllTasks(),s=t==="all"?r:r.filter(o=>o.lifecycle===t);n.id!==void 0&&this.sendResponse(n.id,{tasks:s.map(o=>({taskId:o.taskId,type:o.type,lifecycle:o.lifecycle,label:o.label}))})}function oy(n){let e=n.params;if(!e?.taskId){n.id!==void 0&&this.sendResponse(n.id,void 0,{code:k.INVALID_PARAMS,message:"taskId is required."});return}let r=this.taskStore.getAllTasks().find(s=>s.taskId===e.taskId);if(!r){n.id!==void 0&&this.sendResponse(n.id,{ok:!1,message:`Task ${e.taskId} not found.`});return}if(r.lifecycle!=="running"&&r.lifecycle!=="pending"){n.id!==void 0&&this.sendResponse(n.id,{ok:!1,message:`Task ${e.taskId} is already ${r.lifecycle}.`});return}this.taskStore.updateTask(e.taskId,s=>(s.lifecycle="cancelled",s)),n.id!==void 0&&this.sendResponse(n.id,{ok:!0,message:`Task ${e.taskId} cancelled.`})}ae();import*as iy from"node:fs";import*as po from"node:path";import{randomUUID as HI}from"node:crypto";async function ay(n){try{let e=n.params,t=await this.ensureAgentConfigStore();this.acpDetector.setConfigStore(t.getData());let r=this.acpDetector.scan(e?.force);n.id!==void 0&&this.sendResponse(n.id,r)}catch(e){n.id!==void 0&&this.sendResponse(n.id,void 0,{code:k.INTERNAL_ERROR,message:e instanceof Error?e.message:String(e)})}}async function cy(n){try{let e=await this.ensureAgentConfigStore();this.acpDetector.setConfigStore(e.getData());let t=this.acpDetector.list();n.id!==void 0&&this.sendResponse(n.id,t)}catch(e){n.id!==void 0&&this.sendResponse(n.id,void 0,{code:k.INTERNAL_ERROR,message:e instanceof Error?e.message:String(e)})}}async function ly(n){try{let e=n.params;if(!e?.action||!e?.agent){n.id!==void 0&&this.sendResponse(n.id,void 0,{code:k.INVALID_PARAMS,message:"action and agent are required."});return}let t=await this.ensureAgentConfigStore();switch(e.action){case"register":t.registerCustomAgent(e.agent);break;case"unregister":t.unregisterCustomAgent(e.agent.id);break;case"update":t.registerCustomAgent(e.agent);break}this.acpDetector.setConfigStore(t.getData()),this.acpDetector.clearCache(),n.id!==void 0&&this.sendResponse(n.id,{ok:!0})}catch(e){n.id!==void 0&&this.sendResponse(n.id,void 0,{code:k.INTERNAL_ERROR,message:e instanceof Error?e.message:String(e)})}}async function dy(n){try{let e=n.params;if(!e?.agentId){n.id!==void 0&&this.sendResponse(n.id,void 0,{code:k.INVALID_PARAMS,message:"agentId is required."});return}let t=await this.ensureAgentConfigStore(),{agentId:r,...s}=e;await t.setAgentConfig(r,s),this.acpDetector.setConfigStore(t.getData()),n.id!==void 0&&this.sendResponse(n.id,{ok:!0})}catch(e){n.id!==void 0&&this.sendResponse(n.id,void 0,{code:k.INTERNAL_ERROR,message:e instanceof Error?e.message:String(e)})}}async function uy(n){try{let e=n.params;if(!e?.agentId){n.id!==void 0&&this.sendResponse(n.id,void 0,{code:k.INVALID_PARAMS,message:"agentId is required."});return}let r=(await this.ensureAgentConfigStore()).getAgentConfig(e.agentId);n.id!==void 0&&this.sendResponse(n.id,r)}catch(e){n.id!==void 0&&this.sendResponse(n.id,void 0,{code:k.INTERNAL_ERROR,message:e instanceof Error?e.message:String(e)})}}async function py(n){try{let e=n.params;if(!e?.agentId){n.id!==void 0&&this.sendResponse(n.id,void 0,{code:k.INVALID_PARAMS,message:"agentId is required."});return}let t=await this.ensureAgentConfigStore();await t.removeAgentConfig(e.agentId),this.acpDetector.setConfigStore(t.getData()),n.id!==void 0&&this.sendResponse(n.id,{ok:!0})}catch(e){n.id!==void 0&&this.sendResponse(n.id,void 0,{code:k.INTERNAL_ERROR,message:e instanceof Error?e.message:String(e)})}}async function my(n){try{let e=n.params;if(!e?.url){n.id!==void 0&&this.sendResponse(n.id,void 0,{code:k.INVALID_PARAMS,message:"url is required."});return}await(await this.ensureAgentConfigStore()).setGatewayUrl(e.url),n.id!==void 0&&this.sendResponse(n.id,{ok:!0})}catch(e){n.id!==void 0&&this.sendResponse(n.id,void 0,{code:k.INTERNAL_ERROR,message:e instanceof Error?e.message:String(e)})}}async function gy(n){try{let t=(await this.ensureAgentConfigStore()).getGatewayUrl();n.id!==void 0&&this.sendResponse(n.id,{url:t})}catch(e){n.id!==void 0&&this.sendResponse(n.id,void 0,{code:k.INTERNAL_ERROR,message:e instanceof Error?e.message:String(e)})}}async function fy(n){try{let t=(await this.ensureAgentConfigStore()).getData(),r=Object.entries(t.agents).map(([s,o])=>({agentId:s,hasApiKey:!!o.apiKey,hasBaseUrl:!!o.baseUrl,hasModel:!!o.model}));n.id!==void 0&&this.sendResponse(n.id,r)}catch(e){n.id!==void 0&&this.sendResponse(n.id,void 0,{code:k.INTERNAL_ERROR,message:e instanceof Error?e.message:String(e)})}}function hy(n){try{let e=[],t=(r,s)=>{if(r)for(let o of r.getAllHandles())e.push({memberId:o.memberId,name:o.name,pid:o.pid,state:o.state,startedAt:o.startedAt,endedAt:o.endedAt,source:s})};t(this.soloProcessManager,"solo"),t(this.productProcessManager,"product"),n.id!==void 0&&this.sendResponse(n.id,e)}catch(e){n.id!==void 0&&this.sendResponse(n.id,void 0,{code:k.INTERNAL_ERROR,message:e instanceof Error?e.message:String(e)})}}function yy(n){try{let e=n.params;if(!e?.memberId){n.id!==void 0&&this.sendResponse(n.id,void 0,{code:k.INVALID_PARAMS,message:"memberId is required."});return}let t=!1;for(let r of[this.soloProcessManager,this.productProcessManager])if(r?.getHandle(e.memberId)){r.kill(e.memberId),t=!0;break}n.id!==void 0&&this.sendResponse(n.id,{ok:t})}catch(e){n.id!==void 0&&this.sendResponse(n.id,void 0,{code:k.INTERNAL_ERROR,message:e instanceof Error?e.message:String(e)})}}async function by(n){try{let e=n.params;if(!e?.agentId){n.id!==void 0&&this.sendResponse(n.id,void 0,{code:k.INVALID_PARAMS,message:"agentId is required."});return}let t=po.join(q(),"agent-logs"),r=po.join(t,`${e.agentId}.stderr.log`),s="";try{s=iy.readFileSync(r,"utf-8")}catch{}e.tail&&e.tail>0&&s&&(s=s.split(`
|
|
850
850
|
`).slice(-e.tail).join(`
|
|
851
|
-
`)),n.id!==void 0&&this.sendResponse(n.id,{log:s})}catch(e){n.id!==void 0&&this.sendResponse(n.id,void 0,{code:k.INTERNAL_ERROR,message:e instanceof Error?e.message:String(e)})}}async function ky(n){try{let e=n.params;if(!e?.agentId){n.id!==void 0&&this.sendResponse(n.id,void 0,{code:k.INVALID_PARAMS,message:"agentId is required."});return}let t=await this.ensureAgentConfigStore();this.acpDetector.setConfigStore(t.getData());let s=this.acpDetector.list().find(i=>i.id===e.agentId);if(!s){n.id!==void 0&&this.sendResponse(n.id,{ok:!1,error:`Agent ${e.agentId} not found`,durationMs:0});return}if(s.status==="not_installed"){n.id!==void 0&&this.sendResponse(n.id,{ok:!1,error:`Agent ${e.agentId} is not installed`,durationMs:0});return}let o=Date.now();n.id!==void 0&&this.sendResponse(n.id,{ok:s.status==="available",version:s.version,capabilities:s.capabilities,error:s.status!=="available"?`Agent status: ${s.status}`:void 0,durationMs:Date.now()-o})}catch(e){n.id!==void 0&&this.sendResponse(n.id,void 0,{code:k.INTERNAL_ERROR,message:e instanceof Error?e.message:String(e)})}}async function vy(n){let e=null,t="";try{let r=n.params??{},s=typeof r.agentId=="string"?r.agentId.trim():"",o=typeof r.prompt=="string"?r.prompt:"";if(!s||!o.trim()){n.id!==void 0&&this.sendResponse(n.id,void 0,{code:k.INVALID_PARAMS,message:"agentId and prompt are required."});return}let i=await this.ensureAgentConfigStore();this.acpDetector.setConfigStore(i.getData()),this.acpDetector.scan(!1);let a=this.acpDetector.buildExternalDescriptor(s);if(!a){n.id!==void 0&&this.sendResponse(n.id,void 0,{code:k.INVALID_PARAMS,message:`Agent ${s} is not available or not ACP-compatible.`});return}let c=typeof r.cwd=="string"&&r.cwd?r.cwd:typeof this.getActiveProjectRoot=="function"?this.getActiveProjectRoot():process.cwd(),l=typeof r.timeoutMs=="number"&&r.timeoutMs>0?r.timeoutMs:3e5;t=`chat-${s}-${HI().slice(0,8)}`;let u=[];e=new It({onNotification:(h,f,y)=>{if(f!=="turn.delta")return;let b=typeof y?.text=="string"?y.text:"";b&&u.push(b)},onMcpToolCall:async(h,f,y)=>typeof this.handleMcpToolCall=="function"?this.handleMcpToolCall(h,f,y):{ok:!1,error:"MCP tool call unavailable"},log:{info:h=>this.log?.(`[agents.prompt] ${h}`),warn:h=>this.log?.(`[agents.prompt] WARN: ${h}`),debug:h=>this.log?.(`[agents.prompt] ${h}`)},sessionDir:po.join(q(),"agent-logs")}),await e.spawn({memberId:t,name:`chat-${s}`,cwd:c,prompt:o,external:a,systemPrompt:typeof r.systemPrompt=="string"?r.systemPrompt:void 0});let d=await e.sendTask(t,o,{
|
|
851
|
+
`)),n.id!==void 0&&this.sendResponse(n.id,{log:s})}catch(e){n.id!==void 0&&this.sendResponse(n.id,void 0,{code:k.INTERNAL_ERROR,message:e instanceof Error?e.message:String(e)})}}async function ky(n){try{let e=n.params;if(!e?.agentId){n.id!==void 0&&this.sendResponse(n.id,void 0,{code:k.INVALID_PARAMS,message:"agentId is required."});return}let t=await this.ensureAgentConfigStore();this.acpDetector.setConfigStore(t.getData());let s=this.acpDetector.list().find(i=>i.id===e.agentId);if(!s){n.id!==void 0&&this.sendResponse(n.id,{ok:!1,error:`Agent ${e.agentId} not found`,durationMs:0});return}if(s.status==="not_installed"){n.id!==void 0&&this.sendResponse(n.id,{ok:!1,error:`Agent ${e.agentId} is not installed`,durationMs:0});return}let o=Date.now();n.id!==void 0&&this.sendResponse(n.id,{ok:s.status==="available",version:s.version,capabilities:s.capabilities,error:s.status!=="available"?`Agent status: ${s.status}`:void 0,durationMs:Date.now()-o})}catch(e){n.id!==void 0&&this.sendResponse(n.id,void 0,{code:k.INTERNAL_ERROR,message:e instanceof Error?e.message:String(e)})}}async function vy(n){let e=null,t="";try{let r=n.params??{},s=typeof r.agentId=="string"?r.agentId.trim():"",o=typeof r.prompt=="string"?r.prompt:"";if(!s||!o.trim()){n.id!==void 0&&this.sendResponse(n.id,void 0,{code:k.INVALID_PARAMS,message:"agentId and prompt are required."});return}let i=await this.ensureAgentConfigStore();this.acpDetector.setConfigStore(i.getData()),this.acpDetector.scan(!1);let a=this.acpDetector.buildExternalDescriptor(s);if(!a){n.id!==void 0&&this.sendResponse(n.id,void 0,{code:k.INVALID_PARAMS,message:`Agent ${s} is not available or not ACP-compatible.`});return}let c=typeof r.cwd=="string"&&r.cwd?r.cwd:typeof this.getActiveProjectRoot=="function"?this.getActiveProjectRoot():process.cwd(),l=typeof r.timeoutMs=="number"&&r.timeoutMs>0?r.timeoutMs:3e5;t=`chat-${s}-${HI().slice(0,8)}`;let u=[];e=new It({onNotification:(h,f,y)=>{if(f!=="turn.delta")return;let b=typeof y?.text=="string"?y.text:"";b&&u.push(b)},onMcpToolCall:async(h,f,y)=>typeof this.handleMcpToolCall=="function"?this.handleMcpToolCall(h,f,y):{ok:!1,error:"MCP tool call unavailable"},log:{info:h=>this.log?.(`[agents.prompt] ${h}`),warn:h=>this.log?.(`[agents.prompt] WARN: ${h}`),debug:h=>this.log?.(`[agents.prompt] ${h}`)},sessionDir:po.join(q(),"agent-logs")}),await e.spawn({memberId:t,name:`chat-${s}`,cwd:c,prompt:o,external:a,systemPrompt:typeof r.systemPrompt=="string"?r.systemPrompt:void 0});let d=await e.sendTask(t,o,{timeout:l}),p=u.join("")||(typeof d?.content=="string"?d.content:""),m=e.getUsageTracker(t)?.getUsage();n.id!==void 0&&this.sendResponse(n.id,{ok:!0,agentId:s,content:p,stopReason:d?.stopReason,usage:m?{inputTokens:m.inputTokens,outputTokens:m.outputTokens,totalTokens:m.totalTokens,cacheRead:m.cachedReadTokens,thoughtTokens:m.thoughtTokens,cost:m.cost}:void 0})}catch(r){n.id!==void 0&&this.sendResponse(n.id,void 0,{code:k.INTERNAL_ERROR,message:r instanceof Error?r.message:String(r)})}finally{if(e&&t){try{e.kill(t)}catch{}try{e.dispose()}catch{}}}}import{isAsyncMediaTransport as Sy}from"@xiaozhiclaw/provider-core";lt();async function Ty(n){try{if(!this.mediaClient){n.id!==void 0&&this.sendResponse(n.id,{models:[]});return}let e=await this.mediaClient.listModels();n.id!==void 0&&this.sendResponse(n.id,{models:e})}catch(e){n.id!==void 0&&this.sendResponse(n.id,void 0,{code:k.INTERNAL_ERROR,message:e instanceof Error?e.message:String(e)})}}async function Ry(n){let e=n.params;if(!e?.taskId){n.id!==void 0&&this.sendResponse(n.id,void 0,{code:k.INVALID_PARAMS,message:"taskId is required."});return}try{if(!this.mediaClient||!Sy(this.mediaClient)){n.id!==void 0&&this.sendResponse(n.id,{ok:!1,message:"Media client does not support async cancel."});return}await this.mediaClient.cancel(e.taskId),n.id!==void 0&&this.sendResponse(n.id,{ok:!0})}catch(t){n.id!==void 0&&this.sendResponse(n.id,void 0,{code:k.INTERNAL_ERROR,message:t instanceof Error?t.message:String(t)})}}async function wy(n){let e=n.params;if(!e?.taskId){n.id!==void 0&&this.sendResponse(n.id,void 0,{code:k.INVALID_PARAMS,message:"taskId is required."});return}try{if(!this.mediaClient||!Sy(this.mediaClient)){n.id!==void 0&&this.sendResponse(n.id,{status:"unknown",message:"Media client does not support status queries."});return}let t=await this.mediaClient.queryStatus(e.taskId);n.id!==void 0&&this.sendResponse(n.id,t)}catch(t){n.id!==void 0&&this.sendResponse(n.id,void 0,{code:k.INTERNAL_ERROR,message:t instanceof Error?t.message:String(t)})}}async function Ay(n){let e=n.params;if(!e?.audioBase64){n.id!==void 0&&this.sendResponse(n.id,void 0,{code:k.INVALID_PARAMS,message:"audioBase64 is required."});return}let r=X().getActiveModel("stt");if(!r){n.id!==void 0&&this.sendResponse(n.id,void 0,{code:k.INTERNAL_ERROR,message:"STT not configured. Add an STT model and bind it in settings."});return}let{apiKey:s,model:o,baseUrl:i,keyHandle:a}=r;if(!i){a.release({success:!1}),n.id!==void 0&&this.sendResponse(n.id,void 0,{code:k.INTERNAL_ERROR,message:"STT baseUrl not configured. Set baseUrl on the STT model entry."});return}try{let c=`----STTBoundary${Date.now()}`,l=[];l.push(`--${c}\r
|
|
852
852
|
Content-Disposition: form-data; name="model"\r
|
|
853
853
|
\r
|
|
854
854
|
${o}`),l.push(`--${c}\r
|