beeos-claw 0.5.9 → 0.5.10

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/a2a/tools.js CHANGED
@@ -1 +1 @@
1
- import{agentFetch}from"../agent-auth.js";import{resolveAgentIdFromMentions}from"./mention-resolver.js";async function a2aFetch(e,t,n){const a=`${e.agentGatewayUrl}${t}`;return e.agentKeys?agentFetch(a,e.agentKeys,n):fetch(a,n)}export{a2aFetch};export class TaskHandleRegistry{seq=0;handles=new Map;taskIdToHandle=new Map;create(e,t,n,a){const s="bth_"+ ++this.seq;return this.handles.set(s,{taskId:e,agentId:t,contextId:n,sessionKey:a}),this.taskIdToHandle.set(e,s),s}resolveTaskId(e){const t=this.handles.get(e);return t?t.taskId:e}}const defaultRegistry=new TaskHandleRegistry;export function registerA2ATools(e,t,n=defaultRegistry,a,s,r){e.registerTool({name:"beeos_discover_agents",description:"Find other agents that can help with a task. Returns a list of agents matching the query. Results include your own agents and publicly available agents.",parameters:{type:"object",properties:{query:{type:"string",description:"What capability or skill you are looking for"}},required:["query"]},async execute(e,n,a){const{query:s}=n;try{const e=await a2aFetch(t,`/api/v1/a2a/discover?query=${encodeURIComponent(s)}&limit=20`,{signal:a});if(!e.ok)return{content:JSON.stringify({error:`discover failed: ${e.status}`})};const n=await e.json();return{content:JSON.stringify(n,null,2)}}catch(e){if(a?.aborted)throw e;return{content:JSON.stringify({error:e instanceof Error?e.message:String(e)})}}}}),e.registerTool({name:"beeos_call_agent",description:"Ask another agent to perform a task. Waits for the agent to complete the task and returns the result. Timeout defaults to 10 minutes (configurable via timeoutMs).",parameters:{type:"object",properties:{agentId:{type:"string",description:"The target agent UUID (e.g. d04080d1-...) or display name. Prefer the UUID from discover results or @mention metadata when available."},message:{type:"string",description:"The task description or message to send to the agent"},taskId:{type:"string",description:"Optional existing task ID to continue a multi-turn conversation. When provided, the message is appended to the existing task instead of creating a new one."},files:{type:"array",items:{type:"string"},description:"Optional file URLs to include with the request"},contextId:{type:"string",description:"Optional context ID for multi-turn conversations with the same agent"},timeoutMs:{type:"number",description:"Task timeout in milliseconds. Defaults to 600000 (10 minutes). Set higher for long-running tasks."}},required:["agentId","message"]},async execute(e,o,i){let{agentId:c,message:d,files:g,contextId:l,timeoutMs:u,taskId:f}=o;const p=a?.(e),m=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;if(!m.test(c)){const n=s?.(e);if(n?.length){const e=resolveAgentIdFromMentions(n,c);e&&(t.logger.info?.(`beeos_call_agent: resolved "${c}" → ${e} via mention context`),c=e)}if(!m.test(c))try{const e=await a2aFetch(t,`/api/v1/a2a/discover?query=${encodeURIComponent(c)}&limit=10`,{signal:i});if(e.ok){const n=await e.json(),a=n?.data??[],s=c.toLowerCase(),r=a.find(e=>e.name.toLowerCase()===s)??a.find(e=>e.name.toLowerCase().includes(s));if(!r)return{content:JSON.stringify({error:`Could not resolve agent name "${c}". Available agents: ${a.map(e=>`${e.name} (${e.id})`).join(", ")||"none"}`})};t.logger.info?.(`beeos_call_agent: resolved "${c}" → ${r.id} (${r.name}) via discover`),c=r.id}}catch{}}const h=l||(p?`session:${p}`:""),y=u||6e5;try{const e={jsonrpc:"2.0",id:`claw-${Date.now()}`,method:"SendMessage",params:{message:{role:"user",parts:[{text:d}],...h?{contextId:h}:{},...f?{taskId:f}:{}},configuration:{timeoutMs:y}}},a=`/api/v1/a2a/${encodeURIComponent(c)}`,s=AbortSignal.timeout(y+1e4),o=i?AbortSignal.any([i,s]):s,g=await a2aFetch(t,a,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e),signal:o}),u=await g.text();let m;try{m=JSON.parse(u)}catch{m={}}if(!g.ok||m.error){if(401===g.status||403===g.status){const e=m.error??{};-32600===e.code&&r&&r("_beeos/auth_required",{type:"auth_required",target_agent_id:c,target_agent_name:c,title:"Authentication Required",content:`Agent **${c}** requires authentication.`})}const e=m.error?JSON.stringify(m.error):u;return{content:JSON.stringify({error:`send task failed: ${g.status} ${e}`})}}const k=m.result,v=k?.id,I=k?.status?.state;if(v&&n.create(v,c,l,p),"completed"===I){const e=k?.artifacts,t=e?.flatMap(e=>e.parts??[]).filter(e=>"text"===e.kind).map(e=>e.text).join("\n");if(t)return{content:t}}if("failed"===I){const e=k?.status,t=e?.message?.parts,n=t?.[0]?.text??"task failed";return{content:JSON.stringify({error:n})}}return{content:JSON.stringify(k,null,2)}}catch(e){if(i?.aborted)throw e;return e instanceof DOMException&&"TimeoutError"===e.name?{content:JSON.stringify({error:`task timed out after ${y}ms`,agent:c})}:{content:JSON.stringify({error:e instanceof Error?e.message:String(e)})}}}})}
1
+ import{agentFetch}from"../agent-auth.js";import{resolveAgentIdFromMentions}from"./mention-resolver.js";async function a2aFetch(t,e,n){const a=`${t.agentGatewayUrl}${e}`;return t.agentKeys?agentFetch(a,t.agentKeys,n):fetch(a,n)}export{a2aFetch};export class TaskHandleRegistry{seq=0;handles=new Map;taskIdToHandle=new Map;create(t,e,n,a){const s="bth_"+ ++this.seq;return this.handles.set(s,{taskId:t,agentId:e,contextId:n,sessionKey:a}),this.taskIdToHandle.set(t,s),s}resolveTaskId(t){const e=this.handles.get(t);return e?e.taskId:t}}const defaultRegistry=new TaskHandleRegistry;export function registerA2ATools(t,e,n=defaultRegistry,a,s,r){t.registerTool({name:"beeos_discover_agents",description:"Find other agents that can help with a task. Returns a list of agents matching the query. Results include your own agents and publicly available agents.",parameters:{type:"object",properties:{query:{type:"string",description:"What capability or skill you are looking for"}},required:["query"]},async execute(t,n,a){const{query:s}=n;try{const t=await a2aFetch(e,`/api/v1/a2a/discover?query=${encodeURIComponent(s)}&limit=20`,{signal:a});if(!t.ok)return{content:JSON.stringify({error:`discover failed: ${t.status}`})};const n=await t.json();return{content:JSON.stringify(n,null,2)}}catch(t){if(a?.aborted)throw t;return{content:JSON.stringify({error:t instanceof Error?t.message:String(t)})}}}}),t.registerTool({name:"beeos_call_agent",description:"Ask another agent to perform a task. Waits for the agent to complete the task and returns the result. Timeout defaults to 10 minutes (configurable via timeoutMs).",parameters:{type:"object",properties:{agentId:{type:"string",description:"The target agent UUID (e.g. d04080d1-...) or display name. Prefer the UUID from discover results or @mention metadata when available."},message:{type:"string",description:"The task description or message to send to the agent"},taskId:{type:"string",description:"Optional existing task ID to continue a multi-turn conversation. When provided, the message is appended to the existing task instead of creating a new one."},files:{type:"array",items:{type:"string"},description:"Optional file URLs to include with the request"},contextId:{type:"string",description:"Optional context ID for multi-turn conversations with the same agent"},timeoutMs:{type:"number",description:"Task timeout in milliseconds. Defaults to 600000 (10 minutes). Set higher for long-running tasks."}},required:["agentId","message"]},async execute(t,o,i){let{agentId:c,message:d,files:l,contextId:g,timeoutMs:u,taskId:f}=o;const m=a?.(t),p=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;if(!p.test(c)){const n=s?.(t);if(n?.length){const t=resolveAgentIdFromMentions(n,c);t&&(e.logger.info?.(`beeos_call_agent: resolved "${c}" → ${t} via mention context`),c=t)}if(!p.test(c))try{const t=await a2aFetch(e,`/api/v1/a2a/discover?query=${encodeURIComponent(c)}&limit=10`,{signal:i});if(t.ok){const n=await t.json(),a=n?.data??[],s=c.toLowerCase(),r=a.find(t=>t.name.toLowerCase()===s)??a.find(t=>t.name.toLowerCase().includes(s));if(!r)return{content:JSON.stringify({error:`Could not resolve agent name "${c}". Available agents: ${a.map(t=>`${t.name} (${t.id})`).join(", ")||"none"}`})};e.logger.info?.(`beeos_call_agent: resolved "${c}" → ${r.id} (${r.name}) via discover`),c=r.id}}catch{}}const h=g||(m?`session:${m}`:""),y=u||6e5;try{const t={jsonrpc:"2.0",id:`claw-${Date.now()}`,method:"SendMessage",params:{message:{role:"user",parts:[{text:d}],...h?{contextId:h}:{},...f?{taskId:f}:{}},configuration:{timeoutMs:y}}},a=`/api/v1/a2a/${encodeURIComponent(c)}`,s=AbortSignal.timeout(y+1e4),o=i?AbortSignal.any([i,s]):s,l=await a2aFetch(e,a,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t),signal:o}),u=await l.text();let p;try{p=JSON.parse(u)}catch{p={}}if(!l.ok||p.error){if(401===l.status||403===l.status){const t=p.error??{};-32600===t.code&&r&&r("_beeos/auth_required",{type:"auth_required",target_agent_id:c,target_agent_name:c,title:"Authentication Required",content:`Agent **${c}** requires authentication.`})}const t=p.error?JSON.stringify(p.error):u;return{content:JSON.stringify({error:`send task failed: ${l.status} ${t}`})}}const k=p.result,w=k?.id,v=k?.status?.state;w&&n.create(w,c,g,m);const I=t=>{const e=t?.artifacts,n=e?.flatMap(t=>t.parts??[]).filter(t=>"text"===t.kind).map(t=>t.text).join("\n");return n||void 0};if("working"===v&&w){const t=2e3,n=Date.now()+y;for(;Date.now()<n;){if(await new Promise(e=>setTimeout(e,t)),i?.aborted)throw new DOMException("Aborted","AbortError");const n=await a2aFetch(e,`/api/v1/a2a/tasks/${encodeURIComponent(w)}`,{signal:i});if(!n.ok)break;const a=await n.json(),s=a.result??a,r=s?.status?.state;if("completed"===r){return{content:I(s)??JSON.stringify(s,null,2)}}if("failed"===r||"timeout"===r||"canceled"===r||"rejected"===r){const t=s?.status,e=t?.message?.parts,n=e?.[0]?.text??r??"task failed";return{content:JSON.stringify({error:n,task_id:w})}}}return{content:JSON.stringify({status:"working",task_id:w,message:`Task is still running. Use task_id "${w}" to check the result later.`})}}if("completed"===v){const t=I(k??{});if(t)return{content:t}}if("failed"===v){const t=k?.status,e=t?.message?.parts,n=e?.[0]?.text??"task failed";return{content:JSON.stringify({error:n})}}return{content:JSON.stringify(k,null,2)}}catch(t){if(i?.aborted)throw t;return t instanceof DOMException&&"TimeoutError"===t.name?{content:JSON.stringify({error:`task timed out after ${y}ms`,agent:c})}:{content:JSON.stringify({error:t instanceof Error?t.message:String(t)})}}}})}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "beeos-claw",
3
- "version": "0.5.9",
3
+ "version": "0.5.10",
4
4
  "description": "OpenClaw plugin that bridges the BeeOS platform with the local OpenClaw Gateway, providing file transfer, ACP bridge, and observability.",
5
5
  "license": "MIT",
6
6
  "author": "BeeOS <dev@beeos.ai>",