beeos-claw 0.6.44-staging.4 → 0.6.44-staging.5

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.
@@ -1 +1 @@
1
- import{randomUUID}from"node:crypto";import{mkdir,readFile,rename,stat,unlink,readdir}from"node:fs/promises";import{writeFile}from"node:fs/promises";import{homedir}from"node:os";import{join}from"node:path";const CACHE_TTL_MS=864e5,ENRICHMENT_CACHE_TTL_MS=2592e6,ENRICHMENT_PREFIX="enrich_",CACHE_VERSION=1;function cacheDir(){return join(process.env.OPENCLAW_HOME||join(homedir(),".openclaw"),"beeos-claw","upload_meta")}function safeToolCallId(e){return e.replace(/[^a-zA-Z0-9._-]/g,"_")}function cachePath(e){return join(cacheDir(),`${safeToolCallId(e)}.json`)}async function safeUnlink(e){try{await unlink(e)}catch{}}export async function writeUploadToolResult(e,t,a){await mkdir(cacheDir(),{recursive:!0,mode:448});const n={version:1,createdAt:Date.now(),toolCallId:e,toolName:t,result:a},r=async e=>{const t=`${e}.${randomUUID()}.tmp`;await writeFile(t,JSON.stringify(n),{encoding:"utf8",mode:384}),await rename(t,e)};await r(cachePath(e)),"beeos_upload_file"!==t&&"beeos_desktop_screenshot"!==t||await r(cachePath("latest_beeos_upload_file"))}export async function readUploadToolResult(e){const t=cachePath(e);let a,n,r;try{a=await stat(t)}catch{return}if(Date.now()-a.mtimeMs>=864e5)await safeUnlink(t);else{try{n=await readFile(t,"utf8")}catch{return}try{r=JSON.parse(n)}catch{return void await safeUnlink(t)}if(r&&1===r.version&&"number"==typeof r.createdAt&&!(Date.now()-r.createdAt>=864e5))return r.result;await safeUnlink(t)}}export function uploadCacheIdCandidates(e){const t=e.trim();if(!t)return[];const a=t.startsWith("tool:")?t.slice(5):t,n=[t,a,safeToolCallId(t),safeToolCallId(a)];return[...new Set(n.filter(e=>e.length>0))]}export async function resolveUploadToolResultForEnrichment(e,t="beeos_upload_file",a){const n=Math.max(1,a?.attempts??6),r=Math.max(0,a?.delayMs??40),o=uploadCacheIdCandidates(e);for(let e=0;e<n;e++){for(const e of o){const t=await readUploadToolResult(e);if(null!=t)return t}const a=await readUploadToolResult("latest_beeos_upload_file");if(null!=a)return a;const i=await readLatestUploadToolResult(t);if(null!=i)return i;e+1<n&&r>0&&await new Promise(t=>setTimeout(t,r*(e+1)))}}export async function readLatestUploadToolResult(e,t=12e4){let a;try{a=await readdir(cacheDir())}catch{return}const n=Date.now();let r;for(const o of a){if(!o.endsWith(".json")||o.startsWith("enrich_"))continue;const a=join(cacheDir(),o);let i,c;try{i=await readFile(a,"utf8")}catch{continue}try{c=JSON.parse(i)}catch{continue}!c||1!==c.version||c.toolName!==e||"number"!=typeof c.createdAt||n-c.createdAt>=t||n-c.createdAt>=864e5||(!r||c.createdAt>r.createdAt)&&(r={createdAt:c.createdAt,result:c.result})}return r?.result}function enrichmentCachePath(e){return join(cacheDir(),`enrich_${safeToolCallId(e)}.json`)}export async function writeEnrichmentCache(e,t){if(0===t.length)return;await mkdir(cacheDir(),{recursive:!0,mode:448});const a={version:1,createdAt:Date.now(),toolCallId:e,resourceLinks:t},n=enrichmentCachePath(e),r=`${n}.${randomUUID()}.tmp`;await writeFile(r,JSON.stringify(a),{encoding:"utf8",mode:384}),await rename(r,n)}export async function readEnrichmentCache(e){const t=enrichmentCachePath(e);let a,n,r;try{a=await stat(t)}catch{return}if(Date.now()-a.mtimeMs>=2592e6)await safeUnlink(t);else{try{n=await readFile(t,"utf8")}catch{return}try{r=JSON.parse(n)}catch{return void await safeUnlink(t)}if(r&&1===r.version&&"number"==typeof r.createdAt&&Array.isArray(r.resourceLinks)&&!(Date.now()-r.createdAt>=2592e6))return r.resourceLinks;await safeUnlink(t)}}export async function cleanupUploadToolResultCache(){let e;try{e=await readdir(cacheDir(),{withFileTypes:!0})}catch{return 0}const t=Date.now();let a=0;for(const n of e){if(!n.isFile())continue;if(!n.name.endsWith(".json")&&!n.name.endsWith(".tmp"))continue;const e=join(cacheDir(),n.name),r=n.name.startsWith("enrich_")?2592e6:864e5;try{t-(await stat(e)).mtimeMs>=r&&(await unlink(e),a++)}catch{}}return a}
1
+ import{randomUUID}from"node:crypto";import{mkdir,readFile,rename,stat,unlink,readdir}from"node:fs/promises";import{writeFile}from"node:fs/promises";import{homedir}from"node:os";import{join}from"node:path";const CACHE_TTL_MS=864e5,ENRICHMENT_CACHE_TTL_MS=2592e6,ENRICHMENT_PREFIX="enrich_",CACHE_VERSION=1;function cacheDir(){return join(process.env.OPENCLAW_HOME||join(homedir(),".openclaw"),"beeos-claw","upload_meta")}function safeToolCallId(e){return e.replace(/[^a-zA-Z0-9._-]/g,"_")}function cachePath(e){return join(cacheDir(),`${safeToolCallId(e)}.json`)}async function safeUnlink(e){try{await unlink(e)}catch{}}export async function writeUploadToolResult(e,t,a){await mkdir(cacheDir(),{recursive:!0,mode:448});const n={version:1,createdAt:Date.now(),toolCallId:e,toolName:t,result:a},r=async e=>{const t=`${e}.${randomUUID()}.tmp`;await writeFile(t,JSON.stringify(n),{encoding:"utf8",mode:384}),await rename(t,e)};await r(cachePath(e)),"beeos_upload_file"!==t&&"beeos_desktop_screenshot"!==t||await r(cachePath("latest_beeos_upload_file"))}export async function readUploadToolResult(e){const t=cachePath(e);let a,n,r;try{a=await stat(t)}catch{return}if(Date.now()-a.mtimeMs>=864e5)await safeUnlink(t);else{try{n=await readFile(t,"utf8")}catch{return}try{r=JSON.parse(n)}catch{return void await safeUnlink(t)}if(r&&1===r.version&&"number"==typeof r.createdAt&&!(Date.now()-r.createdAt>=864e5))return r.result;await safeUnlink(t)}}export function uploadCacheIdCandidates(e){const t=e.trim();if(!t)return[];const a=t.startsWith("tool:")?t.slice(5):t,n=[t,a,safeToolCallId(t),safeToolCallId(a)];return[...new Set(n.filter(e=>e.length>0))]}export async function resolveUploadToolResultForEnrichment(e,t="beeos_upload_file",a){const n=Math.max(1,a?.attempts??6),r=Math.max(0,a?.delayMs??40),o=Math.max(0,a?.latestMaxAgeMs??5e3),i=uploadCacheIdCandidates(e);for(let e=0;e<n;e++){for(const e of i){const t=await readUploadToolResult(e);if(null!=t)return t}if(e>=Math.max(1,n-2)&&o>0){const e=await readLatestUploadToolResult(t,o);if(null!=e)return e}e+1<n&&r>0&&await new Promise(t=>setTimeout(t,r*(e+1)))}}export async function readLatestUploadToolResult(e,t=12e4){let a;try{a=await readdir(cacheDir())}catch{return}const n=Date.now();let r;for(const o of a){if(!o.endsWith(".json")||o.startsWith("enrich_"))continue;const a=join(cacheDir(),o);let i,c;try{i=await readFile(a,"utf8")}catch{continue}try{c=JSON.parse(i)}catch{continue}!c||1!==c.version||c.toolName!==e||"number"!=typeof c.createdAt||n-c.createdAt>=t||n-c.createdAt>=864e5||(!r||c.createdAt>r.createdAt)&&(r={createdAt:c.createdAt,result:c.result})}return r?.result}function enrichmentCachePath(e){return join(cacheDir(),`enrich_${safeToolCallId(e)}.json`)}export async function writeEnrichmentCache(e,t){if(0===t.length)return;await mkdir(cacheDir(),{recursive:!0,mode:448});const a={version:1,createdAt:Date.now(),toolCallId:e,resourceLinks:t},n=enrichmentCachePath(e),r=`${n}.${randomUUID()}.tmp`;await writeFile(r,JSON.stringify(a),{encoding:"utf8",mode:384}),await rename(r,n)}export async function readEnrichmentCache(e){const t=enrichmentCachePath(e);let a,n,r;try{a=await stat(t)}catch{return}if(Date.now()-a.mtimeMs>=2592e6)await safeUnlink(t);else{try{n=await readFile(t,"utf8")}catch{return}try{r=JSON.parse(n)}catch{return void await safeUnlink(t)}if(r&&1===r.version&&"number"==typeof r.createdAt&&Array.isArray(r.resourceLinks)&&!(Date.now()-r.createdAt>=2592e6))return r.resourceLinks;await safeUnlink(t)}}export async function cleanupUploadToolResultCache(){let e;try{e=await readdir(cacheDir(),{withFileTypes:!0})}catch{return 0}const t=Date.now();let a=0;for(const n of e){if(!n.isFile())continue;if(!n.name.endsWith(".json")&&!n.name.endsWith(".tmp"))continue;const e=join(cacheDir(),n.name),r=n.name.startsWith("enrich_")?2592e6:864e5;try{t-(await stat(e)).mtimeMs>=r&&(await unlink(e),a++)}catch{}}return a}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "beeos-claw",
3
- "version": "0.6.44-staging.4",
3
+ "version": "0.6.44-staging.5",
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>",