buckyos 0.7.170 → 0.7.175
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/cli/core/app.ts +2 -0
- package/cli/core/argv.ts +45 -239
- package/cli/core/command.ts +3 -35
- package/cli/dist/cli.mjs +2151 -673
- package/cli/dist/cli.mjs.map +1 -1
- package/cli/modules/agent.ts +3 -1
- package/cli/modules/app.ts +13 -2
- package/cli/modules/pikg.ts +70 -1
- package/cli/modules/runtime.ts +497 -0
- package/cli/modules/skill.ts +583 -161
- package/cli/modules/skill_lint.ts +462 -0
- package/cli/version.ts +1 -1
- package/dist/account-7a7bde6f.mjs +105 -0
- package/dist/account-7a7bde6f.mjs.map +1 -0
- package/dist/account-b12ac6b9.js +2 -0
- package/dist/account-b12ac6b9.js.map +1 -0
- package/dist/aicc-67851c41.mjs +582 -0
- package/dist/aicc-67851c41.mjs.map +1 -0
- package/dist/aicc-ccb36ef7.js +2 -0
- package/dist/aicc-ccb36ef7.js.map +1 -0
- package/dist/browser.cjs +1 -1
- package/dist/browser.cjs.map +1 -1
- package/dist/browser.d.ts +2 -0
- package/dist/browser.d.ts.map +1 -1
- package/dist/browser.mjs +204 -194
- package/dist/browser.mjs.map +1 -1
- package/dist/did_object_client-6a1b108a.js +2 -0
- package/dist/did_object_client-6a1b108a.js.map +1 -0
- package/dist/did_object_client-7fa36f90.mjs +87 -0
- package/dist/did_object_client-7fa36f90.mjs.map +1 -0
- package/dist/did_object_client.d.ts +39 -0
- package/dist/did_object_client.d.ts.map +1 -0
- package/dist/{executor_client-5f4d0468.mjs → executor_client-c620d25c.mjs} +233 -748
- package/dist/executor_client-c620d25c.mjs.map +1 -0
- package/dist/executor_client-d4439d54.js +13 -0
- package/dist/executor_client-d4439d54.js.map +1 -0
- package/dist/executor_client.d.ts +129 -0
- package/dist/executor_client.d.ts.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.mjs +209 -199
- package/dist/index.mjs.map +1 -1
- package/dist/internal/command_args.d.ts +67 -0
- package/dist/internal/command_args.d.ts.map +1 -0
- package/dist/krpc_client-26c2dc8b.js +2 -0
- package/dist/krpc_client-26c2dc8b.js.map +1 -0
- package/dist/krpc_client-673448e5.mjs +173 -0
- package/dist/krpc_client-673448e5.mjs.map +1 -0
- package/dist/krpc_client.d.ts +5 -1
- package/dist/krpc_client.d.ts.map +1 -1
- package/dist/{ndn_types-ab30fac0.mjs → ndn_types-0fac2499.mjs} +115 -215
- package/dist/ndn_types-0fac2499.mjs.map +1 -0
- package/dist/ndn_types-5b138882.js +2 -0
- package/dist/ndn_types-5b138882.js.map +1 -0
- package/dist/node.cjs +1 -1
- package/dist/node.cjs.map +1 -1
- package/dist/node.mjs +201 -194
- package/dist/node.mjs.map +1 -1
- package/dist/object_url-8fb5a7bf.js +2 -0
- package/dist/object_url-8fb5a7bf.js.map +1 -0
- package/dist/object_url-f72c1704.mjs +412 -0
- package/dist/object_url-f72c1704.mjs.map +1 -0
- package/dist/openai-ae2978de.mjs +163 -0
- package/dist/openai-ae2978de.mjs.map +1 -0
- package/dist/openai-f560d518.js +2 -0
- package/dist/openai-f560d518.js.map +1 -0
- package/dist/provision.cjs +6 -6
- package/dist/provision.cjs.map +1 -1
- package/dist/provision.mjs +4 -3
- package/dist/provision.mjs.map +1 -1
- package/dist/site_manager-11a7a468.mjs +6410 -0
- package/dist/site_manager-11a7a468.mjs.map +1 -0
- package/dist/site_manager-334b1a51.js +2 -0
- package/dist/site_manager-334b1a51.js.map +1 -0
- package/dist/{tus_client-b231b248.js → tus_client-809c90ab.js} +2 -2
- package/dist/{tus_client-b231b248.js.map → tus_client-809c90ab.js.map} +1 -1
- package/dist/{tus_client-d1ffe2d6.mjs → tus_client-893a3287.mjs} +2 -2
- package/dist/{tus_client-d1ffe2d6.mjs.map → tus_client-893a3287.mjs.map} +1 -1
- package/dist/xllm/core/action_parser.d.ts +15 -0
- package/dist/xllm/core/action_parser.d.ts.map +1 -0
- package/dist/xllm/core/behavior_loop.d.ts +20 -0
- package/dist/xllm/core/behavior_loop.d.ts.map +1 -0
- package/dist/xllm/core/behavior_result.d.ts +11 -0
- package/dist/xllm/core/behavior_result.d.ts.map +1 -0
- package/dist/xllm/core/config.d.ts +62 -0
- package/dist/xllm/core/config.d.ts.map +1 -0
- package/dist/xllm/core/context_window.d.ts +15 -0
- package/dist/xllm/core/context_window.d.ts.map +1 -0
- package/dist/xllm/core/deps.d.ts +97 -0
- package/dist/xllm/core/deps.d.ts.map +1 -0
- package/dist/xllm/core/errors.d.ts +94 -0
- package/dist/xllm/core/errors.d.ts.map +1 -0
- package/dist/xllm/core/interrupt.d.ts +31 -0
- package/dist/xllm/core/interrupt.d.ts.map +1 -0
- package/dist/xllm/core/json.d.ts +11 -0
- package/dist/xllm/core/json.d.ts.map +1 -0
- package/dist/xllm/core/json_check.d.ts +17 -0
- package/dist/xllm/core/json_check.d.ts.map +1 -0
- package/dist/xllm/core/loop.d.ts +135 -0
- package/dist/xllm/core/loop.d.ts.map +1 -0
- package/dist/xllm/core/messages.d.ts +18 -0
- package/dist/xllm/core/messages.d.ts.map +1 -0
- package/dist/xllm/core/observer.d.ts +14 -0
- package/dist/xllm/core/observer.d.ts.map +1 -0
- package/dist/xllm/core/open_runtime.d.ts +22 -0
- package/dist/xllm/core/open_runtime.d.ts.map +1 -0
- package/dist/xllm/core/prepare.d.ts +54 -0
- package/dist/xllm/core/prepare.d.ts.map +1 -0
- package/dist/xllm/core/prompt.d.ts +40 -0
- package/dist/xllm/core/prompt.d.ts.map +1 -0
- package/dist/xllm/core/protocol.d.ts +15 -0
- package/dist/xllm/core/protocol.d.ts.map +1 -0
- package/dist/xllm/core/result.d.ts +12 -0
- package/dist/xllm/core/result.d.ts.map +1 -0
- package/dist/xllm/core/run.d.ts +198 -0
- package/dist/xllm/core/run.d.ts.map +1 -0
- package/dist/xllm/core/rust_text.d.ts +20 -0
- package/dist/xllm/core/rust_text.d.ts.map +1 -0
- package/dist/xllm/core/site_policy.d.ts +5 -0
- package/dist/xllm/core/site_policy.d.ts.map +1 -0
- package/dist/xllm/core/store.d.ts +60 -0
- package/dist/xllm/core/store.d.ts.map +1 -0
- package/dist/xllm/core/suspension.d.ts +13 -0
- package/dist/xllm/core/suspension.d.ts.map +1 -0
- package/dist/xllm/core/tokenizer.d.ts +8 -0
- package/dist/xllm/core/tokenizer.d.ts.map +1 -0
- package/dist/xllm/core/types.d.ts +826 -0
- package/dist/xllm/core/types.d.ts.map +1 -0
- package/dist/xllm/core/xml.d.ts +19 -0
- package/dist/xllm/core/xml.d.ts.map +1 -0
- package/dist/xllm/dev/openai.d.ts +17 -0
- package/dist/xllm/dev/openai.d.ts.map +1 -0
- package/dist/xllm/dev/scripted.d.ts +46 -0
- package/dist/xllm/dev/scripted.d.ts.map +1 -0
- package/dist/xllm/dev.d.ts +5 -0
- package/dist/xllm/dev.d.ts.map +1 -0
- package/dist/xllm/hosts/browser/store.d.ts +41 -0
- package/dist/xllm/hosts/browser/store.d.ts.map +1 -0
- package/dist/xllm/hosts/deno/deno_api.d.ts +103 -0
- package/dist/xllm/hosts/deno/deno_api.d.ts.map +1 -0
- package/dist/xllm/hosts/deno/identity.d.ts +29 -0
- package/dist/xllm/hosts/deno/identity.d.ts.map +1 -0
- package/dist/xllm/hosts/deno/index.d.ts +47 -0
- package/dist/xllm/hosts/deno/index.d.ts.map +1 -0
- package/dist/xllm/hosts/deno/native_runtime.d.ts +93 -0
- package/dist/xllm/hosts/deno/native_runtime.d.ts.map +1 -0
- package/dist/xllm/hosts/deno/native_tools.d.ts +105 -0
- package/dist/xllm/hosts/deno/native_tools.d.ts.map +1 -0
- package/dist/xllm/hosts/deno/provider.d.ts +13 -0
- package/dist/xllm/hosts/deno/provider.d.ts.map +1 -0
- package/dist/xllm/hosts/deno/store.d.ts +60 -0
- package/dist/xllm/hosts/deno/store.d.ts.map +1 -0
- package/dist/xllm/index.d.ts +48 -0
- package/dist/xllm/index.d.ts.map +1 -0
- package/dist/xllm/providers/aicc.d.ts +22 -0
- package/dist/xllm/providers/aicc.d.ts.map +1 -0
- package/dist/xllm/providers/timeout.d.ts +12 -0
- package/dist/xllm/providers/timeout.d.ts.map +1 -0
- package/dist/xllm/runtime/compress.d.ts +149 -0
- package/dist/xllm/runtime/compress.d.ts.map +1 -0
- package/dist/xllm/runtime/did_object_resources.d.ts +21 -0
- package/dist/xllm/runtime/did_object_resources.d.ts.map +1 -0
- package/dist/xllm/runtime/hints.d.ts +23 -0
- package/dist/xllm/runtime/hints.d.ts.map +1 -0
- package/dist/xllm/runtime/site.d.ts +22 -0
- package/dist/xllm/runtime/site.d.ts.map +1 -0
- package/dist/xllm/runtime/site_manager.d.ts +38 -0
- package/dist/xllm/runtime/site_manager.d.ts.map +1 -0
- package/dist/xllm/runtime/site_tools.d.ts +76 -0
- package/dist/xllm/runtime/site_tools.d.ts.map +1 -0
- package/dist/xllm/runtime/step_renderer.d.ts +54 -0
- package/dist/xllm/runtime/step_renderer.d.ts.map +1 -0
- package/dist/xllm/runtime/task_model.d.ts +64 -0
- package/dist/xllm/runtime/task_model.d.ts.map +1 -0
- package/dist/xllm/runtime/tool_result.d.ts +39 -0
- package/dist/xllm/runtime/tool_result.d.ts.map +1 -0
- package/dist/xllm/runtime/types.d.ts +99 -0
- package/dist/xllm/runtime/types.d.ts.map +1 -0
- package/dist/xllm.cjs +2 -0
- package/dist/xllm.cjs.map +1 -0
- package/dist/xllm.mjs +1167 -0
- package/dist/xllm.mjs.map +1 -0
- package/dist/xllm_deno.cjs +2 -0
- package/dist/xllm_deno.cjs.map +1 -0
- package/dist/xllm_deno.mjs +2487 -0
- package/dist/xllm_deno.mjs.map +1 -0
- package/dist/xllm_dev.cjs +2 -0
- package/dist/xllm_dev.cjs.map +1 -0
- package/dist/xllm_dev.mjs +70 -0
- package/dist/xllm_dev.mjs.map +1 -0
- package/package.json +22 -1
- package/src/internal/command_args.ts +268 -0
- package/dist/executor_client-1ee523cf.js +0 -13
- package/dist/executor_client-1ee523cf.js.map +0 -1
- package/dist/executor_client-5f4d0468.mjs.map +0 -1
- package/dist/ndn_types-8c2696d5.js +0 -2
- package/dist/ndn_types-8c2696d5.js.map +0 -1
- package/dist/ndn_types-ab30fac0.mjs.map +0 -1
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";const e=require("./ndn_types-5b138882.js"),t=["config","dfs","taskmgr","kmsg","bucket","ndm","msg-center","aiworkspace","homestation","opendan","aicc"],n="/obj";class r extends Error{}function o(e){return t.includes(e)}function i(e){const t=(e=e.trim()).indexOf("://");if(t<0)throw new r(`'${e}' has no scheme`);const n=e.slice(0,t).toLowerCase(),o=e.slice(t+3);switch(n){case"https":case"http":try{return{kind:"web",url:new URL(e).toString()}}catch(i){throw new r(`invalid web url '${e}': ${i}`)}case"buckyos":return{kind:"buckyos",url:e};case"file":{const{authority:e,path:t,query:n}=g(o);if(null!==n)throw new r("file url does not take query or fragment");const i=e.toLowerCase();let s;if(""===i||"localhost"===i)s=null;else{if(!x(i))throw new r(`invalid device id '${i}' in file url`);s=i}if(""===t)throw new r("file url requires an absolute path");return{kind:"file",deviceId:s,path:k(t,!1)}}case"cyfs":{const{authority:e,path:t,query:n}=g(o);if(null!==n)throw new r("cyfs url does not take query or fragment");const i=e.toLowerCase();if(""===i||"_"===i){if(""===t)throw new r("cyfs path url requires a path");return{kind:"cyfs_path",zone:null,path:k(t,!1)}}const s=i.indexOf("."),c=s<0?i:i.slice(0,s),a=s<0?null:i.slice(s+1),u=_(c);if(u){if(null!==a&&!x(a))throw new r(`invalid source zone '${a}'`);return{kind:"cyfs_object",objId:u,sourceZone:a,innerPath:""===t||"/"===t?"":k(t,!1)}}if(!x(i)||!i.includes("."))throw new r(`'${i}' is neither a zone host nor an ObjId`);if(""===t)throw new r("cyfs path url requires a path");return{kind:"cyfs_path",zone:i,path:k(t,!1)}}case"obj":{const{authority:e,path:t,query:n}=g(o);return{kind:"obj",host:s(e.toLowerCase()),path:""===t||"/"===t?"":k(t,!0),query:null===n?{}:O(n)}}default:throw new r(`unsupported scheme '${n}'`)}}function s(e){if(""===e)throw new r("obj url requires a host");if(o(e))return{kind:"service",name:e};if(!e.includes("."))throw new r(`'${e}' is not a registered obj:// service name; type shorthands are not supported`);if(!x(e))throw new r(`'${e}' is not a valid entity hostname`);const t=e.split(".")[0];if(o(t))throw new r(`'${e}' expands a service name; write obj://${t}/ for the current zone or use https across zones`);if(_(t))throw new r("NamedObject ids do not go into obj:// host; use cyfs://<objid>/");return{kind:"entity",name:e}}function c(e){switch(e.kind){case"file":return`file://${e.deviceId??""}${e.path}`;case"cyfs_path":return`cyfs://${e.zone??""}${e.path}`;case"cyfs_object":return`cyfs://${e.objId.toBase32()}${e.sourceZone?`.${e.sourceZone}`:""}${e.innerPath||"/"}`;case"obj":{const t=Object.keys(e.query).sort().map((t=>`${j(t)}=${j(e.query[t])}`)).join("&");return`obj://${e.host.name}${e.path}${t?`?${t}`:""}`}case"web":case"buckyos":return e.url}}function a(e,t,n){const r=t.replace(/\/+$/,"");if("obj"===e.kind)return`${r}/kapi/${e.host.name}/obj${c(e).slice(`obj://${e.host.name}`.length)}`;if("cyfs_path"===e.kind&&(null===e.zone||e.zone===n))return`${r}/kapi/dfs/obj${e.path.replace(/\/+$/,"")}`;if("cyfs_object"===e.kind){const t=e.sourceZone&&e.sourceZone!==n?`https://${e.sourceZone}`:r,o=e.innerPath.replace(/^\/+|\/+$/g,"");return`${t}/ndn/${e.objId.toString()}${o?`/@/${o}`:""}`}return"web"===e.kind?e.url:null}function u(e){return c(i(e))}function l(e){return"obj"===e.kind?v(e.path):[]}function f(e){if(""!==e&&/^[A-Za-z0-9_-]+$/.test(e)&&!e.startsWith("x"))return e;let t="x";for(const n of(new TextEncoder).encode(e))t+=n.toString(16).padStart(2,"0");return t}function h(e,t,n){return`${d(e,t)}/${n}`}function d(e,t){return[n,f(e),...t.map(f)].join("/")}function p(e,t){return`obj://${e}${t.map((e=>`/${$(e)}`)).join("")}`}function b(e){if(Array.isArray(e))return`[${e.map(b).join(",")}]`;if(null!==e&&"object"==typeof e){return`{${Object.keys(e).sort().map((t=>`${JSON.stringify(t)}:${b(e[t])}`)).join(",")}}`}return JSON.stringify(e)}function $(e){return w(e,(e=>y(e)||"!$&'()*+,;=:@".includes(String.fromCharCode(e))))}function j(e){return w(e,(e=>y(e)||"!$'()*,;:@/".includes(String.fromCharCode(e))))}function w(e,t){let n="";for(const r of(new TextEncoder).encode(e))n+=t(r)?String.fromCharCode(r):`%${r.toString(16).toUpperCase().padStart(2,"0")}`;return n}function y(e){const t=String.fromCharCode(e);return/[A-Za-z0-9]/.test(t)||"-._~".includes(t)}function m(e,t){return d(e.name,v(t))}function g(e){const t=e.search(/[?#]/),n=t<0?e:e.slice(0,t);let r=null;if(t>=0){const n=e.slice(t).split("#")[0];r=n.startsWith("?")?n.slice(1):n,""===r&&(r=null)}const o=n.indexOf("/");return o<0?{authority:n,path:"",query:r}:{authority:n.slice(0,o),path:n.slice(o),query:r}}function k(e,t){if(!e.startsWith("/"))throw new r(`path '${e}' must be absolute`);let n=e.slice(1);t&&n.endsWith("/")&&(n=n.slice(0,-1));const o=n.split("/");let i="";return o.forEach(((n,s)=>{if(""===n&&s===o.length-1&&!t)return void(i+="/");const c=S(n);if(""===c||"."===c||".."===c)throw new r(`ambiguous path segment in '${e}'`);i+=`/${$(c)}`})),i}function v(e){return e.split("/").filter((e=>""!==e)).map((e=>{try{return S(e)}catch{return e}}))}function O(e){const t={};for(const o of e.split("&")){if(""===o)continue;const e=o.indexOf("="),i=S((e<0?o:o.slice(0,e)).replace(/\+/g," "));let s=S((e<0?"":o.slice(e+1)).replace(/\+/g," "));if("selector"===i)try{s=b(JSON.parse(s))}catch(n){throw new r(`selector must be JSON: ${n}`)}if(Object.prototype.hasOwnProperty.call(t,i))throw new r(`query key '${i}' repeats`);t[i]=s}return t}function S(e){const t=(new TextEncoder).encode(e),n=[];for(let o=0;o<t.length;)if(37===t[o]){const i=String.fromCharCode(t[o+1]??0,t[o+2]??0);if(!/^[0-9A-Fa-f]{2}$/.test(i))throw new r(`invalid escape in '${e}'`);n.push(parseInt(i,16)),o+=3}else n.push(t[o]),o+=1;try{return new TextDecoder("utf-8",{fatal:!0}).decode(new Uint8Array(n))}catch{throw new r(`'${e}' is not UTF-8`)}}function x(e){return""!==e&&e.length<=253&&e.split(".").every((e=>""!==e&&e.length<=63&&/^[a-z0-9-]+$/.test(e)&&!e.startsWith("-")&&!e.endsWith("-")))}function _(t){if(t.length<26)return null;try{const n=e.ObjId.fromString(t);return/^[a-z0-9_-]+$/.test(n.objType)&&n.objHash.length>=16&&n.toBase32()===t?n:null}catch{return null}}const E=Object.freeze(Object.defineProperty({__proto__:null,OBJECT_EVENT_PREFIX:n,OBJ_SERVICE_NAMES:t,ObjectUrlError:r,canonicalJson:b,configKeyFromUrl:function(e){let t=e.startsWith("obj://config/")?e.slice(13):e;return t.startsWith("/config/")&&(t=t.slice(8)),t.replace(/^[/\\]+/,"")},encodeObjQueryComponent:j,encodeObjSegment:$,expandInputShorthand:function(e){if((e=e.trim()).startsWith("//")){const t=e.slice(2);return o(t.split(/[/?]/)[0]??"")?`obj://${t}`:e}return e.startsWith("/")?`file://${e}`:e},formatObjectUrl:c,isObjServiceName:o,keventSegment:f,ndnReadUrl:function(e,t,n){const r=`${e.replace(/\/+$/,"")}/ndn/${t}`;return!n||void 0===n.path&&void 0===n.token?r:`${r}?hint=${encodeURIComponent(b(n))}`},normalizeObjectUrl:u,objEntityUrl:function(e,t){return`obj://${e}${t.map((e=>`/${$(e)}`)).join("")}`},objEventKey:h,objEventPattern:function(e,t){return`${d(e,t)}/**`},objServiceUrl:p,objectDid:function(e,t,n){if("obj"!==e.kind)return null;const r=e.path.split("/").filter((e=>""!==e)).map((e=>e.replace(/:/g,"%3A"))),o="service"===e.host.kind?t:n??`did:web:${e.host.name}`,i="service"===e.host.kind?[e.host.name,...r]:r;return i.length?`${o}:${i.join(":")}`:o},objectEndpoint:a,objectEventKey:function(e,t){if("obj"!==e.kind)throw new r("object events are only defined for obj:// urls");if(!/^[A-Za-z0-9_-]+$/.test(t)||t.startsWith("x"))throw new r(`invalid object event name '${t}'`);const n=`${m(e.host,e.path)}/${t}`;if(n.length>256||n.split("/").length-1>8)throw new r(`object event key too long: ${n}`);return n},objectEventPattern:function(e){if("obj"!==e.kind)throw new r("object events are only defined for obj:// urls");return`${m(e.host,e.path)}/**`},objectSegments:l,parseObjHost:s,parseObjectUrl:i,rbacResourceKey:function(e,t){if("obj"===e.kind)return`obj://${e.host.name}${e.path}`;if("cyfs_path"===e.kind){return null===e.zone||void 0!==t&&e.zone===t.toLowerCase()?`obj://dfs${e.path}`:null}return null}},Symbol.toStringTag,{value:"Module"}));exports.ObjectUrlError=r,exports.canonicalJson=b,exports.encodeObjQueryComponent=j,exports.normalizeObjectUrl=u,exports.objEventKey=h,exports.objServiceUrl=p,exports.objectEndpoint=a,exports.objectSegments=l,exports.object_url=E,exports.parseObjectUrl=i;
|
|
2
|
+
//# sourceMappingURL=object_url-8fb5a7bf.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"object_url-8fb5a7bf.js","sources":["../src/object_url.ts"],"sourcesContent":["// System URL rules: syntax normalization, obj:// host checks, RBAC resource key,\n// object-event kevent key, path DID. The spec is buckyos `doc/key url.md` part one;\n// buckyos-api `object_url.rs` implements the same rules and both sides share\n// `object_url_vectors.json`. Discovery that needs I/O (Card, service lookup,\n// mount mapping) is not here.\n\nimport { ObjId } from './ndn_types'\n\n/** Current-zone service names registered in key url.md §4.1. */\nexport const OBJ_SERVICE_NAMES = [\n 'config',\n 'dfs',\n 'taskmgr',\n 'kmsg',\n 'bucket',\n 'ndm',\n 'msg-center',\n 'aiworkspace',\n 'homestation',\n 'opendan',\n 'aicc',\n] as const\n\nexport const OBJECT_EVENT_PREFIX = '/obj'\n\nexport class ObjectUrlError extends Error {}\n\nexport type ObjHost = { kind: 'service' | 'entity'; name: string }\n\nexport type ObjectUrl =\n | { kind: 'file'; deviceId: string | null; path: string }\n | { kind: 'cyfs_path'; zone: string | null; path: string }\n | { kind: 'cyfs_object'; objId: ObjId; sourceZone: string | null; innerPath: string }\n | { kind: 'obj'; host: ObjHost; path: string; query: Record<string, string> }\n | { kind: 'web'; url: string }\n | { kind: 'buckyos'; url: string }\n\nexport function isObjServiceName(name: string): boolean {\n return (OBJ_SERVICE_NAMES as readonly string[]).includes(name)\n}\n\n/** Strict parse and normalize. Shorthands are expanded by `expandInputShorthand`. */\nexport function parseObjectUrl(input: string): ObjectUrl {\n input = input.trim()\n const sep = input.indexOf('://')\n if (sep < 0) throw new ObjectUrlError(`'${input}' has no scheme`)\n const scheme = input.slice(0, sep).toLowerCase()\n const rest = input.slice(sep + 3)\n switch (scheme) {\n case 'https':\n case 'http': {\n try {\n return { kind: 'web', url: new URL(input).toString() }\n } catch (e) {\n throw new ObjectUrlError(`invalid web url '${input}': ${e}`)\n }\n }\n case 'buckyos':\n return { kind: 'buckyos', url: input }\n case 'file': {\n const { authority, path, query } = splitAuthority(rest)\n if (query !== null) throw new ObjectUrlError('file url does not take query or fragment')\n const host = authority.toLowerCase()\n let deviceId: string | null\n if (host === '' || host === 'localhost') deviceId = null\n else if (isHostname(host)) deviceId = host\n else throw new ObjectUrlError(`invalid device id '${host}' in file url`)\n if (path === '') throw new ObjectUrlError('file url requires an absolute path')\n return { kind: 'file', deviceId, path: normalizePath(path, false) }\n }\n case 'cyfs': {\n const { authority: rawAuthority, path, query } = splitAuthority(rest)\n if (query !== null) throw new ObjectUrlError('cyfs url does not take query or fragment')\n const authority = rawAuthority.toLowerCase()\n if (authority === '' || authority === '_') {\n if (path === '') throw new ObjectUrlError('cyfs path url requires a path')\n return { kind: 'cyfs_path', zone: null, path: normalizePath(path, false) }\n }\n const dot = authority.indexOf('.')\n const firstLabel = dot < 0 ? authority : authority.slice(0, dot)\n const restLabels = dot < 0 ? null : authority.slice(dot + 1)\n const objId = strictObjIdLabel(firstLabel)\n if (objId) {\n if (restLabels !== null && !isHostname(restLabels)) {\n throw new ObjectUrlError(`invalid source zone '${restLabels}'`)\n }\n return {\n kind: 'cyfs_object',\n objId,\n sourceZone: restLabels,\n innerPath: path === '' || path === '/' ? '' : normalizePath(path, false),\n }\n }\n if (!isHostname(authority) || !authority.includes('.')) {\n throw new ObjectUrlError(`'${authority}' is neither a zone host nor an ObjId`)\n }\n if (path === '') throw new ObjectUrlError('cyfs path url requires a path')\n return { kind: 'cyfs_path', zone: authority, path: normalizePath(path, false) }\n }\n case 'obj': {\n const { authority, path, query } = splitAuthority(rest)\n const host = parseObjHost(authority.toLowerCase())\n return {\n kind: 'obj',\n host,\n path: path === '' || path === '/' ? '' : normalizePath(path, true),\n query: query === null ? {} : parseQuery(query),\n }\n }\n default:\n throw new ObjectUrlError(`unsupported scheme '${scheme}'`)\n }\n}\n\n/** Only for inputs that declare the shorthand syntax (CLI, prompt environment), key url.md §8. */\nexport function expandInputShorthand(input: string): string {\n input = input.trim()\n if (input.startsWith('//')) {\n const rest = input.slice(2)\n const service = rest.split(/[/?]/)[0] ?? ''\n return isObjServiceName(service) ? `obj://${rest}` : input\n }\n if (input.startsWith('/')) return `file://${input}`\n return input\n}\n\nexport function parseObjHost(host: string): ObjHost {\n if (host === '') throw new ObjectUrlError('obj url requires a host')\n if (isObjServiceName(host)) return { kind: 'service', name: host }\n if (!host.includes('.')) {\n throw new ObjectUrlError(\n `'${host}' is not a registered obj:// service name; type shorthands are not supported`,\n )\n }\n if (!isHostname(host)) throw new ObjectUrlError(`'${host}' is not a valid entity hostname`)\n const firstLabel = host.split('.')[0]\n if (isObjServiceName(firstLabel)) {\n throw new ObjectUrlError(\n `'${host}' expands a service name; write obj://${firstLabel}/ for the current zone or use https across zones`,\n )\n }\n if (strictObjIdLabel(firstLabel)) {\n throw new ObjectUrlError('NamedObject ids do not go into obj:// host; use cyfs://<objid>/')\n }\n return { kind: 'entity', name: host }\n}\n\nexport function formatObjectUrl(url: ObjectUrl): string {\n switch (url.kind) {\n case 'file':\n return `file://${url.deviceId ?? ''}${url.path}`\n case 'cyfs_path':\n return `cyfs://${url.zone ?? ''}${url.path}`\n case 'cyfs_object':\n return `cyfs://${url.objId.toBase32()}${url.sourceZone ? `.${url.sourceZone}` : ''}${url.innerPath || '/'}`\n case 'obj': {\n const keys = Object.keys(url.query).sort()\n const query = keys.map((k) => `${encodeObjQueryComponent(k)}=${encodeObjQueryComponent(url.query[k])}`).join('&')\n return `obj://${url.host.name}${url.path}${query ? `?${query}` : ''}`\n }\n case 'web':\n case 'buckyos':\n return url.url\n }\n}\n\n/**\n * DID Object endpoint (TODO §1.4): `obj://<host>/<p>?<q>` is `<origin>/kapi/<host>/obj/<p>?<q>`; a path-type cyfs URL\n * of the current Zone is its DFS object `<origin>/kapi/dfs/obj/<p>`; https / http as is. `origin` is a gateway\n * origin (the Zone host or a node gateway). Anything else (files, ObjIds, paths of other Zones) has none.\n */\nexport function objectEndpoint(url: ObjectUrl, origin: string, currentZone?: string | null): string | null {\n const base = origin.replace(/\\/+$/, '')\n if (url.kind === 'obj') return `${base}/kapi/${url.host.name}/obj${formatObjectUrl(url).slice(`obj://${url.host.name}`.length)}`\n if (url.kind === 'cyfs_path' && (url.zone === null || url.zone === currentZone)) return `${base}/kapi/dfs/obj${url.path.replace(/\\/+$/, '')}`\n if (url.kind === 'cyfs_object') {\n const from = url.sourceZone && url.sourceZone !== currentZone ? `https://${url.sourceZone}` : base\n const inner = url.innerPath.replace(/^\\/+|\\/+$/g, '')\n return `${from}/ndn/${url.objId.toString()}${inner ? `/@/${inner}` : ''}`\n }\n if (url.kind === 'web') return url.url\n return null\n}\n\n/** The `hint` of `/ndn/<obj_id>`: canonical JSON, read token and path from the authorization root. */\nexport type NdnHint = { path?: string; token?: string }\n\n/**\n * `<origin>/ndn/<obj_id>[?hint=...]`, the plain-HTTP read of a named object. Built when a\n * request needs it and never stored: a hint may hold a token.\n */\nexport function ndnReadUrl(origin: string, objId: string, hint?: NdnHint | null): string {\n const url = `${origin.replace(/\\/+$/, '')}/ndn/${objId}`\n if (!hint || (hint.path === undefined && hint.token === undefined)) return url\n return `${url}?hint=${encodeURIComponent(canonicalJson(hint))}`\n}\n\nexport function normalizeObjectUrl(input: string): string {\n return formatObjectUrl(parseObjectUrl(input))\n}\n\n/** RBAC resource key: unique after alias normalization, without query. */\nexport function rbacResourceKey(url: ObjectUrl, currentZone?: string): string | null {\n if (url.kind === 'obj') return `obj://${url.host.name}${url.path}`\n if (url.kind === 'cyfs_path') {\n const local =\n url.zone === null || (currentZone !== undefined && url.zone === currentZone.toLowerCase())\n return local ? `obj://dfs${url.path}` : null\n }\n return null\n}\n\nexport function objectSegments(url: ObjectUrl): string[] {\n return url.kind === 'obj' ? decodedSegments(url.path) : []\n}\n\n/** `/obj/<host>/<seg...>/<event>`; segments outside `[A-Za-z0-9_-]` (or starting with `x`) become `x` + hex. */\nexport function objectEventKey(url: ObjectUrl, event: string): string {\n if (url.kind !== 'obj') throw new ObjectUrlError('object events are only defined for obj:// urls')\n if (!/^[A-Za-z0-9_-]+$/.test(event) || event.startsWith('x')) {\n throw new ObjectUrlError(`invalid object event name '${event}'`)\n }\n const key = `${objectEventBase(url.host, url.path)}/${event}`\n if (key.length > 256 || key.split('/').length - 1 > 8) {\n throw new ObjectUrlError(`object event key too long: ${key}`)\n }\n return key\n}\n\nexport function objectEventPattern(url: ObjectUrl): string {\n if (url.kind !== 'obj') throw new ObjectUrlError('object events are only defined for obj:// urls')\n return `${objectEventBase(url.host, url.path)}/**`\n}\n\nexport function keventSegment(segment: string): string {\n if (segment !== '' && /^[A-Za-z0-9_-]+$/.test(segment) && !segment.startsWith('x')) return segment\n let out = 'x'\n for (const byte of new TextEncoder().encode(segment)) out += byte.toString(16).padStart(2, '0')\n return out\n}\n\n/** Object-event kevent key built from an obj:// host and decoded segments, without parsing. */\nexport function objEventKey(host: string, segments: string[], event: string): string {\n return `${objEventBase(host, segments)}/${event}`\n}\n\nexport function objEventPattern(host: string, segments: string[]): string {\n return `${objEventBase(host, segments)}/**`\n}\n\nfunction objEventBase(host: string, segments: string[]): string {\n return [OBJECT_EVENT_PREFIX, keventSegment(host), ...segments.map(keventSegment)].join('/')\n}\n\n/** Path DID (D8): service object `<zoneDid>:<service>:<seg...>`, entity object `<entityDid>:<seg...>`. */\nexport function objectDid(url: ObjectUrl, zoneDid: string, entityDid?: string): string | null {\n if (url.kind !== 'obj') return null\n const segments = url.path\n .split('/')\n .filter((s) => s !== '')\n .map((s) => s.replace(/:/g, '%3A'))\n const base = url.host.kind === 'service' ? zoneDid : entityDid ?? `did:web:${url.host.name}`\n const all = url.host.kind === 'service' ? [url.host.name, ...segments] : segments\n return all.length ? `${base}:${all.join(':')}` : base\n}\n\nexport function objServiceUrl(service: string, segments: string[]): string {\n return `obj://${service}${segments.map((s) => `/${encodeObjSegment(s)}`).join('')}`\n}\n\nexport function objEntityUrl(entityHost: string, segments: string[]): string {\n return `obj://${entityHost}${segments.map((s) => `/${encodeObjSegment(s)}`).join('')}`\n}\n\n/** `obj://config/<key>`, `/config/<key>`, `/<key>` → system-config key. */\nexport function configKeyFromUrl(input: string): string {\n let key = input.startsWith('obj://config/') ? input.slice('obj://config/'.length) : input\n if (key.startsWith('/config/')) key = key.slice('/config/'.length)\n return key.replace(/^[/\\\\]+/, '')\n}\n\n/** Canonical JSON: sorted object keys, no whitespace (selector and other JSON query values). */\nexport function canonicalJson(value: unknown): string {\n if (Array.isArray(value)) return `[${value.map(canonicalJson).join(',')}]`\n if (value !== null && typeof value === 'object') {\n const entries = Object.keys(value as Record<string, unknown>)\n .sort()\n .map((k) => `${JSON.stringify(k)}:${canonicalJson((value as Record<string, unknown>)[k])}`)\n return `{${entries.join(',')}}`\n }\n return JSON.stringify(value)\n}\n\nexport function encodeObjSegment(segment: string): string {\n return encodeWith(segment, (b) => isUnreserved(b) || \"!$&'()*+,;=:@\".includes(String.fromCharCode(b)))\n}\n\n/** Canonical encoding of a query key or value. */\nexport function encodeObjQueryComponent(component: string): string {\n return encodeWith(component, (b) => isUnreserved(b) || \"!$'()*,;:@/\".includes(String.fromCharCode(b)))\n}\n\nfunction encodeWith(input: string, keep: (byte: number) => boolean): string {\n let out = ''\n for (const byte of new TextEncoder().encode(input)) {\n out += keep(byte) ? String.fromCharCode(byte) : `%${byte.toString(16).toUpperCase().padStart(2, '0')}`\n }\n return out\n}\n\nfunction isUnreserved(byte: number): boolean {\n const ch = String.fromCharCode(byte)\n return /[A-Za-z0-9]/.test(ch) || '-._~'.includes(ch)\n}\n\nfunction objectEventBase(host: ObjHost, path: string): string {\n return objEventBase(host.name, decodedSegments(path))\n}\n\nfunction splitAuthority(rest: string): { authority: string; path: string; query: string | null } {\n const qpos = rest.search(/[?#]/)\n const beforeQuery = qpos < 0 ? rest : rest.slice(0, qpos)\n let query: string | null = null\n if (qpos >= 0) {\n const q = rest.slice(qpos).split('#')[0]\n query = q.startsWith('?') ? q.slice(1) : q\n if (query === '') query = null\n }\n const slash = beforeQuery.indexOf('/')\n return slash < 0\n ? { authority: beforeQuery, path: '', query }\n : { authority: beforeQuery.slice(0, slash), path: beforeQuery.slice(slash), query }\n}\n\nfunction normalizePath(path: string, trimTrailingSlash: boolean): string {\n if (!path.startsWith('/')) throw new ObjectUrlError(`path '${path}' must be absolute`)\n let body = path.slice(1)\n if (trimTrailingSlash && body.endsWith('/')) body = body.slice(0, -1)\n const raw = body.split('/')\n let out = ''\n raw.forEach((segment, index) => {\n if (segment === '' && index === raw.length - 1 && !trimTrailingSlash) {\n out += '/'\n return\n }\n const decoded = percentDecode(segment)\n if (decoded === '' || decoded === '.' || decoded === '..') {\n throw new ObjectUrlError(`ambiguous path segment in '${path}'`)\n }\n out += `/${encodeObjSegment(decoded)}`\n })\n return out\n}\n\nfunction decodedSegments(path: string): string[] {\n return path\n .split('/')\n .filter((s) => s !== '')\n .map((s) => {\n try {\n return percentDecode(s)\n } catch {\n return s\n }\n })\n}\n\nfunction parseQuery(query: string): Record<string, string> {\n const out: Record<string, string> = {}\n for (const pair of query.split('&')) {\n if (pair === '') continue\n const eq = pair.indexOf('=')\n const key = percentDecode((eq < 0 ? pair : pair.slice(0, eq)).replace(/\\+/g, ' '))\n let value = percentDecode((eq < 0 ? '' : pair.slice(eq + 1)).replace(/\\+/g, ' '))\n if (key === 'selector') {\n try {\n value = canonicalJson(JSON.parse(value))\n } catch (e) {\n throw new ObjectUrlError(`selector must be JSON: ${e}`)\n }\n }\n if (Object.prototype.hasOwnProperty.call(out, key)) {\n throw new ObjectUrlError(`query key '${key}' repeats`)\n }\n out[key] = value\n }\n return out\n}\n\nfunction percentDecode(input: string): string {\n const raw = new TextEncoder().encode(input)\n const bytes: number[] = []\n for (let i = 0; i < raw.length; ) {\n if (raw[i] === 0x25) {\n const hex = String.fromCharCode(raw[i + 1] ?? 0, raw[i + 2] ?? 0)\n if (!/^[0-9A-Fa-f]{2}$/.test(hex)) throw new ObjectUrlError(`invalid escape in '${input}'`)\n bytes.push(parseInt(hex, 16))\n i += 3\n } else {\n bytes.push(raw[i])\n i += 1\n }\n }\n try {\n return new TextDecoder('utf-8', { fatal: true }).decode(new Uint8Array(bytes))\n } catch {\n throw new ObjectUrlError(`'${input}' is not UTF-8`)\n }\n}\n\nfunction isHostname(host: string): boolean {\n return (\n host !== '' &&\n host.length <= 253 &&\n host\n .split('.')\n .every((label) => label !== '' && label.length <= 63 && /^[a-z0-9-]+$/.test(label) && !label.startsWith('-') && !label.endsWith('-'))\n )\n}\n\nfunction strictObjIdLabel(label: string): ObjId | null {\n if (label.length < 26) return null\n try {\n const objId = ObjId.fromString(label)\n const typeOk = /^[a-z0-9_-]+$/.test(objId.objType)\n return typeOk && objId.objHash.length >= 16 && objId.toBase32() === label ? objId : null\n } catch {\n return null\n }\n}\n"],"names":["OBJ_SERVICE_NAMES","OBJECT_EVENT_PREFIX","ObjectUrlError","Error","isObjServiceName","name","includes","parseObjectUrl","input","sep","trim","indexOf","scheme","slice","toLowerCase","rest","kind","url","URL","toString","e","authority","path","query","splitAuthority","host","deviceId","isHostname","normalizePath","rawAuthority","zone","dot","firstLabel","restLabels","objId","strictObjIdLabel","sourceZone","innerPath","parseObjHost","parseQuery","split","formatObjectUrl","toBase32","Object","keys","sort","map","k","encodeObjQueryComponent","join","objectEndpoint","origin","currentZone","base","replace","length","from","inner","normalizeObjectUrl","objectSegments","decodedSegments","keventSegment","segment","test","startsWith","out","byte","TextEncoder","encode","padStart","objEventKey","segments","event","objEventBase","objServiceUrl","service","s","encodeObjSegment","canonicalJson","value","Array","isArray","JSON","stringify","encodeWith","b","isUnreserved","String","fromCharCode","component","keep","toUpperCase","ch","objectEventBase","qpos","search","beforeQuery","q","slash","trimTrailingSlash","body","endsWith","raw","forEach","index","decoded","percentDecode","filter","pair","eq","key","parse","prototype","hasOwnProperty","call","bytes","i","hex","push","parseInt","TextDecoder","fatal","decode","Uint8Array","every","label","ObjId","fromString","objType","objHash","hint","token","encodeURIComponent","entityHost","zoneDid","entityDid","all"],"mappings":"wDASaA,EAAoB,CAC/B,SACA,MACA,UACA,OACA,SACA,MACA,aACA,cACA,cACA,UACA,QAGWC,EAAsB,OAE5B,MAAMC,UAAuBC,OAY7B,SAASC,EAAiBC,GACvB,OAAAL,EAAwCM,SAASD,EAC3D,CAGO,SAASE,EAAeC,GAEvB,MAAAC,GADND,EAAQA,EAAME,QACIC,QAAQ,OAC1B,GAAIF,EAAM,EAAG,MAAM,IAAIP,EAAe,IAAIM,oBAC1C,MAAMI,EAASJ,EAAMK,MAAM,EAAGJ,GAAKK,cAC7BC,EAAOP,EAAMK,MAAMJ,EAAM,GAC/B,OAAQG,GACN,IAAK,QACL,IAAK,OACC,IACK,MAAA,CAAEI,KAAM,MAAOC,IAAK,IAAIC,IAAIV,GAAOW,kBACnCC,GACP,MAAM,IAAIlB,EAAe,oBAAoBM,OAAWY,IAC1D,CAEF,IAAK,UACH,MAAO,CAAEJ,KAAM,UAAWC,IAAKT,GACj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"config",
|
|
4
|
+
"dfs",
|
|
5
|
+
"taskmgr",
|
|
6
|
+
"kmsg",
|
|
7
|
+
"bucket",
|
|
8
|
+
"ndm",
|
|
9
|
+
"msg-center",
|
|
10
|
+
"aiworkspace",
|
|
11
|
+
"homestation",
|
|
12
|
+
"opendan",
|
|
13
|
+
"aicc"
|
|
14
|
+
];
|
|
15
|
+
const OBJECT_EVENT_PREFIX = "/obj";
|
|
16
|
+
class ObjectUrlError extends Error {
|
|
17
|
+
}
|
|
18
|
+
function isObjServiceName(name) {
|
|
19
|
+
return OBJ_SERVICE_NAMES.includes(name);
|
|
20
|
+
}
|
|
21
|
+
function parseObjectUrl(input) {
|
|
22
|
+
input = input.trim();
|
|
23
|
+
const sep = input.indexOf("://");
|
|
24
|
+
if (sep < 0)
|
|
25
|
+
throw new ObjectUrlError(`'${input}' has no scheme`);
|
|
26
|
+
const scheme = input.slice(0, sep).toLowerCase();
|
|
27
|
+
const rest = input.slice(sep + 3);
|
|
28
|
+
switch (scheme) {
|
|
29
|
+
case "https":
|
|
30
|
+
case "http": {
|
|
31
|
+
try {
|
|
32
|
+
return { kind: "web", url: new URL(input).toString() };
|
|
33
|
+
} catch (e) {
|
|
34
|
+
throw new ObjectUrlError(`invalid web url '${input}': ${e}`);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
case "buckyos":
|
|
38
|
+
return { kind: "buckyos", url: input };
|
|
39
|
+
case "file": {
|
|
40
|
+
const { authority, path, query } = splitAuthority(rest);
|
|
41
|
+
if (query !== null)
|
|
42
|
+
throw new ObjectUrlError("file url does not take query or fragment");
|
|
43
|
+
const host = authority.toLowerCase();
|
|
44
|
+
let deviceId;
|
|
45
|
+
if (host === "" || host === "localhost")
|
|
46
|
+
deviceId = null;
|
|
47
|
+
else if (isHostname(host))
|
|
48
|
+
deviceId = host;
|
|
49
|
+
else
|
|
50
|
+
throw new ObjectUrlError(`invalid device id '${host}' in file url`);
|
|
51
|
+
if (path === "")
|
|
52
|
+
throw new ObjectUrlError("file url requires an absolute path");
|
|
53
|
+
return { kind: "file", deviceId, path: normalizePath(path, false) };
|
|
54
|
+
}
|
|
55
|
+
case "cyfs": {
|
|
56
|
+
const { authority: rawAuthority, path, query } = splitAuthority(rest);
|
|
57
|
+
if (query !== null)
|
|
58
|
+
throw new ObjectUrlError("cyfs url does not take query or fragment");
|
|
59
|
+
const authority = rawAuthority.toLowerCase();
|
|
60
|
+
if (authority === "" || authority === "_") {
|
|
61
|
+
if (path === "")
|
|
62
|
+
throw new ObjectUrlError("cyfs path url requires a path");
|
|
63
|
+
return { kind: "cyfs_path", zone: null, path: normalizePath(path, false) };
|
|
64
|
+
}
|
|
65
|
+
const dot = authority.indexOf(".");
|
|
66
|
+
const firstLabel = dot < 0 ? authority : authority.slice(0, dot);
|
|
67
|
+
const restLabels = dot < 0 ? null : authority.slice(dot + 1);
|
|
68
|
+
const objId = strictObjIdLabel(firstLabel);
|
|
69
|
+
if (objId) {
|
|
70
|
+
if (restLabels !== null && !isHostname(restLabels)) {
|
|
71
|
+
throw new ObjectUrlError(`invalid source zone '${restLabels}'`);
|
|
72
|
+
}
|
|
73
|
+
return {
|
|
74
|
+
kind: "cyfs_object",
|
|
75
|
+
objId,
|
|
76
|
+
sourceZone: restLabels,
|
|
77
|
+
innerPath: path === "" || path === "/" ? "" : normalizePath(path, false)
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
if (!isHostname(authority) || !authority.includes(".")) {
|
|
81
|
+
throw new ObjectUrlError(`'${authority}' is neither a zone host nor an ObjId`);
|
|
82
|
+
}
|
|
83
|
+
if (path === "")
|
|
84
|
+
throw new ObjectUrlError("cyfs path url requires a path");
|
|
85
|
+
return { kind: "cyfs_path", zone: authority, path: normalizePath(path, false) };
|
|
86
|
+
}
|
|
87
|
+
case "obj": {
|
|
88
|
+
const { authority, path, query } = splitAuthority(rest);
|
|
89
|
+
const host = parseObjHost(authority.toLowerCase());
|
|
90
|
+
return {
|
|
91
|
+
kind: "obj",
|
|
92
|
+
host,
|
|
93
|
+
path: path === "" || path === "/" ? "" : normalizePath(path, true),
|
|
94
|
+
query: query === null ? {} : parseQuery(query)
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
default:
|
|
98
|
+
throw new ObjectUrlError(`unsupported scheme '${scheme}'`);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
function expandInputShorthand(input) {
|
|
102
|
+
input = input.trim();
|
|
103
|
+
if (input.startsWith("//")) {
|
|
104
|
+
const rest = input.slice(2);
|
|
105
|
+
const service = rest.split(/[/?]/)[0] ?? "";
|
|
106
|
+
return isObjServiceName(service) ? `obj://${rest}` : input;
|
|
107
|
+
}
|
|
108
|
+
if (input.startsWith("/"))
|
|
109
|
+
return `file://${input}`;
|
|
110
|
+
return input;
|
|
111
|
+
}
|
|
112
|
+
function parseObjHost(host) {
|
|
113
|
+
if (host === "")
|
|
114
|
+
throw new ObjectUrlError("obj url requires a host");
|
|
115
|
+
if (isObjServiceName(host))
|
|
116
|
+
return { kind: "service", name: host };
|
|
117
|
+
if (!host.includes(".")) {
|
|
118
|
+
throw new ObjectUrlError(
|
|
119
|
+
`'${host}' is not a registered obj:// service name; type shorthands are not supported`
|
|
120
|
+
);
|
|
121
|
+
}
|
|
122
|
+
if (!isHostname(host))
|
|
123
|
+
throw new ObjectUrlError(`'${host}' is not a valid entity hostname`);
|
|
124
|
+
const firstLabel = host.split(".")[0];
|
|
125
|
+
if (isObjServiceName(firstLabel)) {
|
|
126
|
+
throw new ObjectUrlError(
|
|
127
|
+
`'${host}' expands a service name; write obj://${firstLabel}/ for the current zone or use https across zones`
|
|
128
|
+
);
|
|
129
|
+
}
|
|
130
|
+
if (strictObjIdLabel(firstLabel)) {
|
|
131
|
+
throw new ObjectUrlError("NamedObject ids do not go into obj:// host; use cyfs://<objid>/");
|
|
132
|
+
}
|
|
133
|
+
return { kind: "entity", name: host };
|
|
134
|
+
}
|
|
135
|
+
function formatObjectUrl(url) {
|
|
136
|
+
switch (url.kind) {
|
|
137
|
+
case "file":
|
|
138
|
+
return `file://${url.deviceId ?? ""}${url.path}`;
|
|
139
|
+
case "cyfs_path":
|
|
140
|
+
return `cyfs://${url.zone ?? ""}${url.path}`;
|
|
141
|
+
case "cyfs_object":
|
|
142
|
+
return `cyfs://${url.objId.toBase32()}${url.sourceZone ? `.${url.sourceZone}` : ""}${url.innerPath || "/"}`;
|
|
143
|
+
case "obj": {
|
|
144
|
+
const keys = Object.keys(url.query).sort();
|
|
145
|
+
const query = keys.map((k) => `${encodeObjQueryComponent(k)}=${encodeObjQueryComponent(url.query[k])}`).join("&");
|
|
146
|
+
return `obj://${url.host.name}${url.path}${query ? `?${query}` : ""}`;
|
|
147
|
+
}
|
|
148
|
+
case "web":
|
|
149
|
+
case "buckyos":
|
|
150
|
+
return url.url;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
function objectEndpoint(url, origin, currentZone) {
|
|
154
|
+
const base = origin.replace(/\/+$/, "");
|
|
155
|
+
if (url.kind === "obj")
|
|
156
|
+
return `${base}/kapi/${url.host.name}/obj${formatObjectUrl(url).slice(`obj://${url.host.name}`.length)}`;
|
|
157
|
+
if (url.kind === "cyfs_path" && (url.zone === null || url.zone === currentZone))
|
|
158
|
+
return `${base}/kapi/dfs/obj${url.path.replace(/\/+$/, "")}`;
|
|
159
|
+
if (url.kind === "cyfs_object") {
|
|
160
|
+
const from = url.sourceZone && url.sourceZone !== currentZone ? `https://${url.sourceZone}` : base;
|
|
161
|
+
const inner = url.innerPath.replace(/^\/+|\/+$/g, "");
|
|
162
|
+
return `${from}/ndn/${url.objId.toString()}${inner ? `/@/${inner}` : ""}`;
|
|
163
|
+
}
|
|
164
|
+
if (url.kind === "web")
|
|
165
|
+
return url.url;
|
|
166
|
+
return null;
|
|
167
|
+
}
|
|
168
|
+
function ndnReadUrl(origin, objId, hint) {
|
|
169
|
+
const url = `${origin.replace(/\/+$/, "")}/ndn/${objId}`;
|
|
170
|
+
if (!hint || hint.path === void 0 && hint.token === void 0)
|
|
171
|
+
return url;
|
|
172
|
+
return `${url}?hint=${encodeURIComponent(canonicalJson(hint))}`;
|
|
173
|
+
}
|
|
174
|
+
function normalizeObjectUrl(input) {
|
|
175
|
+
return formatObjectUrl(parseObjectUrl(input));
|
|
176
|
+
}
|
|
177
|
+
function rbacResourceKey(url, currentZone) {
|
|
178
|
+
if (url.kind === "obj")
|
|
179
|
+
return `obj://${url.host.name}${url.path}`;
|
|
180
|
+
if (url.kind === "cyfs_path") {
|
|
181
|
+
const local = url.zone === null || currentZone !== void 0 && url.zone === currentZone.toLowerCase();
|
|
182
|
+
return local ? `obj://dfs${url.path}` : null;
|
|
183
|
+
}
|
|
184
|
+
return null;
|
|
185
|
+
}
|
|
186
|
+
function objectSegments(url) {
|
|
187
|
+
return url.kind === "obj" ? decodedSegments(url.path) : [];
|
|
188
|
+
}
|
|
189
|
+
function objectEventKey(url, event) {
|
|
190
|
+
if (url.kind !== "obj")
|
|
191
|
+
throw new ObjectUrlError("object events are only defined for obj:// urls");
|
|
192
|
+
if (!/^[A-Za-z0-9_-]+$/.test(event) || event.startsWith("x")) {
|
|
193
|
+
throw new ObjectUrlError(`invalid object event name '${event}'`);
|
|
194
|
+
}
|
|
195
|
+
const key = `${objectEventBase(url.host, url.path)}/${event}`;
|
|
196
|
+
if (key.length > 256 || key.split("/").length - 1 > 8) {
|
|
197
|
+
throw new ObjectUrlError(`object event key too long: ${key}`);
|
|
198
|
+
}
|
|
199
|
+
return key;
|
|
200
|
+
}
|
|
201
|
+
function objectEventPattern(url) {
|
|
202
|
+
if (url.kind !== "obj")
|
|
203
|
+
throw new ObjectUrlError("object events are only defined for obj:// urls");
|
|
204
|
+
return `${objectEventBase(url.host, url.path)}/**`;
|
|
205
|
+
}
|
|
206
|
+
function keventSegment(segment) {
|
|
207
|
+
if (segment !== "" && /^[A-Za-z0-9_-]+$/.test(segment) && !segment.startsWith("x"))
|
|
208
|
+
return segment;
|
|
209
|
+
let out = "x";
|
|
210
|
+
for (const byte of new TextEncoder().encode(segment))
|
|
211
|
+
out += byte.toString(16).padStart(2, "0");
|
|
212
|
+
return out;
|
|
213
|
+
}
|
|
214
|
+
function objEventKey(host, segments, event) {
|
|
215
|
+
return `${objEventBase(host, segments)}/${event}`;
|
|
216
|
+
}
|
|
217
|
+
function objEventPattern(host, segments) {
|
|
218
|
+
return `${objEventBase(host, segments)}/**`;
|
|
219
|
+
}
|
|
220
|
+
function objEventBase(host, segments) {
|
|
221
|
+
return [OBJECT_EVENT_PREFIX, keventSegment(host), ...segments.map(keventSegment)].join("/");
|
|
222
|
+
}
|
|
223
|
+
function objectDid(url, zoneDid, entityDid) {
|
|
224
|
+
if (url.kind !== "obj")
|
|
225
|
+
return null;
|
|
226
|
+
const segments = url.path.split("/").filter((s) => s !== "").map((s) => s.replace(/:/g, "%3A"));
|
|
227
|
+
const base = url.host.kind === "service" ? zoneDid : entityDid ?? `did:web:${url.host.name}`;
|
|
228
|
+
const all = url.host.kind === "service" ? [url.host.name, ...segments] : segments;
|
|
229
|
+
return all.length ? `${base}:${all.join(":")}` : base;
|
|
230
|
+
}
|
|
231
|
+
function objServiceUrl(service, segments) {
|
|
232
|
+
return `obj://${service}${segments.map((s) => `/${encodeObjSegment(s)}`).join("")}`;
|
|
233
|
+
}
|
|
234
|
+
function objEntityUrl(entityHost, segments) {
|
|
235
|
+
return `obj://${entityHost}${segments.map((s) => `/${encodeObjSegment(s)}`).join("")}`;
|
|
236
|
+
}
|
|
237
|
+
function configKeyFromUrl(input) {
|
|
238
|
+
let key = input.startsWith("obj://config/") ? input.slice("obj://config/".length) : input;
|
|
239
|
+
if (key.startsWith("/config/"))
|
|
240
|
+
key = key.slice("/config/".length);
|
|
241
|
+
return key.replace(/^[/\\]+/, "");
|
|
242
|
+
}
|
|
243
|
+
function canonicalJson(value) {
|
|
244
|
+
if (Array.isArray(value))
|
|
245
|
+
return `[${value.map(canonicalJson).join(",")}]`;
|
|
246
|
+
if (value !== null && typeof value === "object") {
|
|
247
|
+
const entries = Object.keys(value).sort().map((k) => `${JSON.stringify(k)}:${canonicalJson(value[k])}`);
|
|
248
|
+
return `{${entries.join(",")}}`;
|
|
249
|
+
}
|
|
250
|
+
return JSON.stringify(value);
|
|
251
|
+
}
|
|
252
|
+
function encodeObjSegment(segment) {
|
|
253
|
+
return encodeWith(segment, (b) => isUnreserved(b) || "!$&'()*+,;=:@".includes(String.fromCharCode(b)));
|
|
254
|
+
}
|
|
255
|
+
function encodeObjQueryComponent(component) {
|
|
256
|
+
return encodeWith(component, (b) => isUnreserved(b) || "!$'()*,;:@/".includes(String.fromCharCode(b)));
|
|
257
|
+
}
|
|
258
|
+
function encodeWith(input, keep) {
|
|
259
|
+
let out = "";
|
|
260
|
+
for (const byte of new TextEncoder().encode(input)) {
|
|
261
|
+
out += keep(byte) ? String.fromCharCode(byte) : `%${byte.toString(16).toUpperCase().padStart(2, "0")}`;
|
|
262
|
+
}
|
|
263
|
+
return out;
|
|
264
|
+
}
|
|
265
|
+
function isUnreserved(byte) {
|
|
266
|
+
const ch = String.fromCharCode(byte);
|
|
267
|
+
return /[A-Za-z0-9]/.test(ch) || "-._~".includes(ch);
|
|
268
|
+
}
|
|
269
|
+
function objectEventBase(host, path) {
|
|
270
|
+
return objEventBase(host.name, decodedSegments(path));
|
|
271
|
+
}
|
|
272
|
+
function splitAuthority(rest) {
|
|
273
|
+
const qpos = rest.search(/[?#]/);
|
|
274
|
+
const beforeQuery = qpos < 0 ? rest : rest.slice(0, qpos);
|
|
275
|
+
let query = null;
|
|
276
|
+
if (qpos >= 0) {
|
|
277
|
+
const q = rest.slice(qpos).split("#")[0];
|
|
278
|
+
query = q.startsWith("?") ? q.slice(1) : q;
|
|
279
|
+
if (query === "")
|
|
280
|
+
query = null;
|
|
281
|
+
}
|
|
282
|
+
const slash = beforeQuery.indexOf("/");
|
|
283
|
+
return slash < 0 ? { authority: beforeQuery, path: "", query } : { authority: beforeQuery.slice(0, slash), path: beforeQuery.slice(slash), query };
|
|
284
|
+
}
|
|
285
|
+
function normalizePath(path, trimTrailingSlash) {
|
|
286
|
+
if (!path.startsWith("/"))
|
|
287
|
+
throw new ObjectUrlError(`path '${path}' must be absolute`);
|
|
288
|
+
let body = path.slice(1);
|
|
289
|
+
if (trimTrailingSlash && body.endsWith("/"))
|
|
290
|
+
body = body.slice(0, -1);
|
|
291
|
+
const raw = body.split("/");
|
|
292
|
+
let out = "";
|
|
293
|
+
raw.forEach((segment, index) => {
|
|
294
|
+
if (segment === "" && index === raw.length - 1 && !trimTrailingSlash) {
|
|
295
|
+
out += "/";
|
|
296
|
+
return;
|
|
297
|
+
}
|
|
298
|
+
const decoded = percentDecode(segment);
|
|
299
|
+
if (decoded === "" || decoded === "." || decoded === "..") {
|
|
300
|
+
throw new ObjectUrlError(`ambiguous path segment in '${path}'`);
|
|
301
|
+
}
|
|
302
|
+
out += `/${encodeObjSegment(decoded)}`;
|
|
303
|
+
});
|
|
304
|
+
return out;
|
|
305
|
+
}
|
|
306
|
+
function decodedSegments(path) {
|
|
307
|
+
return path.split("/").filter((s) => s !== "").map((s) => {
|
|
308
|
+
try {
|
|
309
|
+
return percentDecode(s);
|
|
310
|
+
} catch {
|
|
311
|
+
return s;
|
|
312
|
+
}
|
|
313
|
+
});
|
|
314
|
+
}
|
|
315
|
+
function parseQuery(query) {
|
|
316
|
+
const out = {};
|
|
317
|
+
for (const pair of query.split("&")) {
|
|
318
|
+
if (pair === "")
|
|
319
|
+
continue;
|
|
320
|
+
const eq = pair.indexOf("=");
|
|
321
|
+
const key = percentDecode((eq < 0 ? pair : pair.slice(0, eq)).replace(/\+/g, " "));
|
|
322
|
+
let value = percentDecode((eq < 0 ? "" : pair.slice(eq + 1)).replace(/\+/g, " "));
|
|
323
|
+
if (key === "selector") {
|
|
324
|
+
try {
|
|
325
|
+
value = canonicalJson(JSON.parse(value));
|
|
326
|
+
} catch (e) {
|
|
327
|
+
throw new ObjectUrlError(`selector must be JSON: ${e}`);
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
if (Object.prototype.hasOwnProperty.call(out, key)) {
|
|
331
|
+
throw new ObjectUrlError(`query key '${key}' repeats`);
|
|
332
|
+
}
|
|
333
|
+
out[key] = value;
|
|
334
|
+
}
|
|
335
|
+
return out;
|
|
336
|
+
}
|
|
337
|
+
function percentDecode(input) {
|
|
338
|
+
const raw = new TextEncoder().encode(input);
|
|
339
|
+
const bytes = [];
|
|
340
|
+
for (let i = 0; i < raw.length; ) {
|
|
341
|
+
if (raw[i] === 37) {
|
|
342
|
+
const hex = String.fromCharCode(raw[i + 1] ?? 0, raw[i + 2] ?? 0);
|
|
343
|
+
if (!/^[0-9A-Fa-f]{2}$/.test(hex))
|
|
344
|
+
throw new ObjectUrlError(`invalid escape in '${input}'`);
|
|
345
|
+
bytes.push(parseInt(hex, 16));
|
|
346
|
+
i += 3;
|
|
347
|
+
} else {
|
|
348
|
+
bytes.push(raw[i]);
|
|
349
|
+
i += 1;
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
try {
|
|
353
|
+
return new TextDecoder("utf-8", { fatal: true }).decode(new Uint8Array(bytes));
|
|
354
|
+
} catch {
|
|
355
|
+
throw new ObjectUrlError(`'${input}' is not UTF-8`);
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
function isHostname(host) {
|
|
359
|
+
return host !== "" && host.length <= 253 && host.split(".").every((label) => label !== "" && label.length <= 63 && /^[a-z0-9-]+$/.test(label) && !label.startsWith("-") && !label.endsWith("-"));
|
|
360
|
+
}
|
|
361
|
+
function strictObjIdLabel(label) {
|
|
362
|
+
if (label.length < 26)
|
|
363
|
+
return null;
|
|
364
|
+
try {
|
|
365
|
+
const objId = ObjId.fromString(label);
|
|
366
|
+
const typeOk = /^[a-z0-9_-]+$/.test(objId.objType);
|
|
367
|
+
return typeOk && objId.objHash.length >= 16 && objId.toBase32() === label ? objId : null;
|
|
368
|
+
} catch {
|
|
369
|
+
return null;
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
const object_url = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
373
|
+
__proto__: null,
|
|
374
|
+
OBJECT_EVENT_PREFIX,
|
|
375
|
+
OBJ_SERVICE_NAMES,
|
|
376
|
+
ObjectUrlError,
|
|
377
|
+
canonicalJson,
|
|
378
|
+
configKeyFromUrl,
|
|
379
|
+
encodeObjQueryComponent,
|
|
380
|
+
encodeObjSegment,
|
|
381
|
+
expandInputShorthand,
|
|
382
|
+
formatObjectUrl,
|
|
383
|
+
isObjServiceName,
|
|
384
|
+
keventSegment,
|
|
385
|
+
ndnReadUrl,
|
|
386
|
+
normalizeObjectUrl,
|
|
387
|
+
objEntityUrl,
|
|
388
|
+
objEventKey,
|
|
389
|
+
objEventPattern,
|
|
390
|
+
objServiceUrl,
|
|
391
|
+
objectDid,
|
|
392
|
+
objectEndpoint,
|
|
393
|
+
objectEventKey,
|
|
394
|
+
objectEventPattern,
|
|
395
|
+
objectSegments,
|
|
396
|
+
parseObjHost,
|
|
397
|
+
parseObjectUrl,
|
|
398
|
+
rbacResourceKey
|
|
399
|
+
}, Symbol.toStringTag, { value: "Module" }));
|
|
400
|
+
export {
|
|
401
|
+
ObjectUrlError as O,
|
|
402
|
+
objServiceUrl as a,
|
|
403
|
+
objectSegments as b,
|
|
404
|
+
canonicalJson as c,
|
|
405
|
+
objEventKey as d,
|
|
406
|
+
encodeObjQueryComponent as e,
|
|
407
|
+
objectEndpoint as f,
|
|
408
|
+
normalizeObjectUrl as n,
|
|
409
|
+
object_url as o,
|
|
410
|
+
parseObjectUrl as p
|
|
411
|
+
};
|
|
412
|
+
//# sourceMappingURL=object_url-f72c1704.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"object_url-f72c1704.mjs","sources":["../src/object_url.ts"],"sourcesContent":["// System URL rules: syntax normalization, obj:// host checks, RBAC resource key,\n// object-event kevent key, path DID. The spec is buckyos `doc/key url.md` part one;\n// buckyos-api `object_url.rs` implements the same rules and both sides share\n// `object_url_vectors.json`. Discovery that needs I/O (Card, service lookup,\n// mount mapping) is not here.\n\nimport { ObjId } from './ndn_types'\n\n/** Current-zone service names registered in key url.md §4.1. */\nexport const OBJ_SERVICE_NAMES = [\n 'config',\n 'dfs',\n 'taskmgr',\n 'kmsg',\n 'bucket',\n 'ndm',\n 'msg-center',\n 'aiworkspace',\n 'homestation',\n 'opendan',\n 'aicc',\n] as const\n\nexport const OBJECT_EVENT_PREFIX = '/obj'\n\nexport class ObjectUrlError extends Error {}\n\nexport type ObjHost = { kind: 'service' | 'entity'; name: string }\n\nexport type ObjectUrl =\n | { kind: 'file'; deviceId: string | null; path: string }\n | { kind: 'cyfs_path'; zone: string | null; path: string }\n | { kind: 'cyfs_object'; objId: ObjId; sourceZone: string | null; innerPath: string }\n | { kind: 'obj'; host: ObjHost; path: string; query: Record<string, string> }\n | { kind: 'web'; url: string }\n | { kind: 'buckyos'; url: string }\n\nexport function isObjServiceName(name: string): boolean {\n return (OBJ_SERVICE_NAMES as readonly string[]).includes(name)\n}\n\n/** Strict parse and normalize. Shorthands are expanded by `expandInputShorthand`. */\nexport function parseObjectUrl(input: string): ObjectUrl {\n input = input.trim()\n const sep = input.indexOf('://')\n if (sep < 0) throw new ObjectUrlError(`'${input}' has no scheme`)\n const scheme = input.slice(0, sep).toLowerCase()\n const rest = input.slice(sep + 3)\n switch (scheme) {\n case 'https':\n case 'http': {\n try {\n return { kind: 'web', url: new URL(input).toString() }\n } catch (e) {\n throw new ObjectUrlError(`invalid web url '${input}': ${e}`)\n }\n }\n case 'buckyos':\n return { kind: 'buckyos', url: input }\n case 'file': {\n const { authority, path, query } = splitAuthority(rest)\n if (query !== null) throw new ObjectUrlError('file url does not take query or fragment')\n const host = authority.toLowerCase()\n let deviceId: string | null\n if (host === '' || host === 'localhost') deviceId = null\n else if (isHostname(host)) deviceId = host\n else throw new ObjectUrlError(`invalid device id '${host}' in file url`)\n if (path === '') throw new ObjectUrlError('file url requires an absolute path')\n return { kind: 'file', deviceId, path: normalizePath(path, false) }\n }\n case 'cyfs': {\n const { authority: rawAuthority, path, query } = splitAuthority(rest)\n if (query !== null) throw new ObjectUrlError('cyfs url does not take query or fragment')\n const authority = rawAuthority.toLowerCase()\n if (authority === '' || authority === '_') {\n if (path === '') throw new ObjectUrlError('cyfs path url requires a path')\n return { kind: 'cyfs_path', zone: null, path: normalizePath(path, false) }\n }\n const dot = authority.indexOf('.')\n const firstLabel = dot < 0 ? authority : authority.slice(0, dot)\n const restLabels = dot < 0 ? null : authority.slice(dot + 1)\n const objId = strictObjIdLabel(firstLabel)\n if (objId) {\n if (restLabels !== null && !isHostname(restLabels)) {\n throw new ObjectUrlError(`invalid source zone '${restLabels}'`)\n }\n return {\n kind: 'cyfs_object',\n objId,\n sourceZone: restLabels,\n innerPath: path === '' || path === '/' ? '' : normalizePath(path, false),\n }\n }\n if (!isHostname(authority) || !authority.includes('.')) {\n throw new ObjectUrlError(`'${authority}' is neither a zone host nor an ObjId`)\n }\n if (path === '') throw new ObjectUrlError('cyfs path url requires a path')\n return { kind: 'cyfs_path', zone: authority, path: normalizePath(path, false) }\n }\n case 'obj': {\n const { authority, path, query } = splitAuthority(rest)\n const host = parseObjHost(authority.toLowerCase())\n return {\n kind: 'obj',\n host,\n path: path === '' || path === '/' ? '' : normalizePath(path, true),\n query: query === null ? {} : parseQuery(query),\n }\n }\n default:\n throw new ObjectUrlError(`unsupported scheme '${scheme}'`)\n }\n}\n\n/** Only for inputs that declare the shorthand syntax (CLI, prompt environment), key url.md §8. */\nexport function expandInputShorthand(input: string): string {\n input = input.trim()\n if (input.startsWith('//')) {\n const rest = input.slice(2)\n const service = rest.split(/[/?]/)[0] ?? ''\n return isObjServiceName(service) ? `obj://${rest}` : input\n }\n if (input.startsWith('/')) return `file://${input}`\n return input\n}\n\nexport function parseObjHost(host: string): ObjHost {\n if (host === '') throw new ObjectUrlError('obj url requires a host')\n if (isObjServiceName(host)) return { kind: 'service', name: host }\n if (!host.includes('.')) {\n throw new ObjectUrlError(\n `'${host}' is not a registered obj:// service name; type shorthands are not supported`,\n )\n }\n if (!isHostname(host)) throw new ObjectUrlError(`'${host}' is not a valid entity hostname`)\n const firstLabel = host.split('.')[0]\n if (isObjServiceName(firstLabel)) {\n throw new ObjectUrlError(\n `'${host}' expands a service name; write obj://${firstLabel}/ for the current zone or use https across zones`,\n )\n }\n if (strictObjIdLabel(firstLabel)) {\n throw new ObjectUrlError('NamedObject ids do not go into obj:// host; use cyfs://<objid>/')\n }\n return { kind: 'entity', name: host }\n}\n\nexport function formatObjectUrl(url: ObjectUrl): string {\n switch (url.kind) {\n case 'file':\n return `file://${url.deviceId ?? ''}${url.path}`\n case 'cyfs_path':\n return `cyfs://${url.zone ?? ''}${url.path}`\n case 'cyfs_object':\n return `cyfs://${url.objId.toBase32()}${url.sourceZone ? `.${url.sourceZone}` : ''}${url.innerPath || '/'}`\n case 'obj': {\n const keys = Object.keys(url.query).sort()\n const query = keys.map((k) => `${encodeObjQueryComponent(k)}=${encodeObjQueryComponent(url.query[k])}`).join('&')\n return `obj://${url.host.name}${url.path}${query ? `?${query}` : ''}`\n }\n case 'web':\n case 'buckyos':\n return url.url\n }\n}\n\n/**\n * DID Object endpoint (TODO §1.4): `obj://<host>/<p>?<q>` is `<origin>/kapi/<host>/obj/<p>?<q>`; a path-type cyfs URL\n * of the current Zone is its DFS object `<origin>/kapi/dfs/obj/<p>`; https / http as is. `origin` is a gateway\n * origin (the Zone host or a node gateway). Anything else (files, ObjIds, paths of other Zones) has none.\n */\nexport function objectEndpoint(url: ObjectUrl, origin: string, currentZone?: string | null): string | null {\n const base = origin.replace(/\\/+$/, '')\n if (url.kind === 'obj') return `${base}/kapi/${url.host.name}/obj${formatObjectUrl(url).slice(`obj://${url.host.name}`.length)}`\n if (url.kind === 'cyfs_path' && (url.zone === null || url.zone === currentZone)) return `${base}/kapi/dfs/obj${url.path.replace(/\\/+$/, '')}`\n if (url.kind === 'cyfs_object') {\n const from = url.sourceZone && url.sourceZone !== currentZone ? `https://${url.sourceZone}` : base\n const inner = url.innerPath.replace(/^\\/+|\\/+$/g, '')\n return `${from}/ndn/${url.objId.toString()}${inner ? `/@/${inner}` : ''}`\n }\n if (url.kind === 'web') return url.url\n return null\n}\n\n/** The `hint` of `/ndn/<obj_id>`: canonical JSON, read token and path from the authorization root. */\nexport type NdnHint = { path?: string; token?: string }\n\n/**\n * `<origin>/ndn/<obj_id>[?hint=...]`, the plain-HTTP read of a named object. Built when a\n * request needs it and never stored: a hint may hold a token.\n */\nexport function ndnReadUrl(origin: string, objId: string, hint?: NdnHint | null): string {\n const url = `${origin.replace(/\\/+$/, '')}/ndn/${objId}`\n if (!hint || (hint.path === undefined && hint.token === undefined)) return url\n return `${url}?hint=${encodeURIComponent(canonicalJson(hint))}`\n}\n\nexport function normalizeObjectUrl(input: string): string {\n return formatObjectUrl(parseObjectUrl(input))\n}\n\n/** RBAC resource key: unique after alias normalization, without query. */\nexport function rbacResourceKey(url: ObjectUrl, currentZone?: string): string | null {\n if (url.kind === 'obj') return `obj://${url.host.name}${url.path}`\n if (url.kind === 'cyfs_path') {\n const local =\n url.zone === null || (currentZone !== undefined && url.zone === currentZone.toLowerCase())\n return local ? `obj://dfs${url.path}` : null\n }\n return null\n}\n\nexport function objectSegments(url: ObjectUrl): string[] {\n return url.kind === 'obj' ? decodedSegments(url.path) : []\n}\n\n/** `/obj/<host>/<seg...>/<event>`; segments outside `[A-Za-z0-9_-]` (or starting with `x`) become `x` + hex. */\nexport function objectEventKey(url: ObjectUrl, event: string): string {\n if (url.kind !== 'obj') throw new ObjectUrlError('object events are only defined for obj:// urls')\n if (!/^[A-Za-z0-9_-]+$/.test(event) || event.startsWith('x')) {\n throw new ObjectUrlError(`invalid object event name '${event}'`)\n }\n const key = `${objectEventBase(url.host, url.path)}/${event}`\n if (key.length > 256 || key.split('/').length - 1 > 8) {\n throw new ObjectUrlError(`object event key too long: ${key}`)\n }\n return key\n}\n\nexport function objectEventPattern(url: ObjectUrl): string {\n if (url.kind !== 'obj') throw new ObjectUrlError('object events are only defined for obj:// urls')\n return `${objectEventBase(url.host, url.path)}/**`\n}\n\nexport function keventSegment(segment: string): string {\n if (segment !== '' && /^[A-Za-z0-9_-]+$/.test(segment) && !segment.startsWith('x')) return segment\n let out = 'x'\n for (const byte of new TextEncoder().encode(segment)) out += byte.toString(16).padStart(2, '0')\n return out\n}\n\n/** Object-event kevent key built from an obj:// host and decoded segments, without parsing. */\nexport function objEventKey(host: string, segments: string[], event: string): string {\n return `${objEventBase(host, segments)}/${event}`\n}\n\nexport function objEventPattern(host: string, segments: string[]): string {\n return `${objEventBase(host, segments)}/**`\n}\n\nfunction objEventBase(host: string, segments: string[]): string {\n return [OBJECT_EVENT_PREFIX, keventSegment(host), ...segments.map(keventSegment)].join('/')\n}\n\n/** Path DID (D8): service object `<zoneDid>:<service>:<seg...>`, entity object `<entityDid>:<seg...>`. */\nexport function objectDid(url: ObjectUrl, zoneDid: string, entityDid?: string): string | null {\n if (url.kind !== 'obj') return null\n const segments = url.path\n .split('/')\n .filter((s) => s !== '')\n .map((s) => s.replace(/:/g, '%3A'))\n const base = url.host.kind === 'service' ? zoneDid : entityDid ?? `did:web:${url.host.name}`\n const all = url.host.kind === 'service' ? [url.host.name, ...segments] : segments\n return all.length ? `${base}:${all.join(':')}` : base\n}\n\nexport function objServiceUrl(service: string, segments: string[]): string {\n return `obj://${service}${segments.map((s) => `/${encodeObjSegment(s)}`).join('')}`\n}\n\nexport function objEntityUrl(entityHost: string, segments: string[]): string {\n return `obj://${entityHost}${segments.map((s) => `/${encodeObjSegment(s)}`).join('')}`\n}\n\n/** `obj://config/<key>`, `/config/<key>`, `/<key>` → system-config key. */\nexport function configKeyFromUrl(input: string): string {\n let key = input.startsWith('obj://config/') ? input.slice('obj://config/'.length) : input\n if (key.startsWith('/config/')) key = key.slice('/config/'.length)\n return key.replace(/^[/\\\\]+/, '')\n}\n\n/** Canonical JSON: sorted object keys, no whitespace (selector and other JSON query values). */\nexport function canonicalJson(value: unknown): string {\n if (Array.isArray(value)) return `[${value.map(canonicalJson).join(',')}]`\n if (value !== null && typeof value === 'object') {\n const entries = Object.keys(value as Record<string, unknown>)\n .sort()\n .map((k) => `${JSON.stringify(k)}:${canonicalJson((value as Record<string, unknown>)[k])}`)\n return `{${entries.join(',')}}`\n }\n return JSON.stringify(value)\n}\n\nexport function encodeObjSegment(segment: string): string {\n return encodeWith(segment, (b) => isUnreserved(b) || \"!$&'()*+,;=:@\".includes(String.fromCharCode(b)))\n}\n\n/** Canonical encoding of a query key or value. */\nexport function encodeObjQueryComponent(component: string): string {\n return encodeWith(component, (b) => isUnreserved(b) || \"!$'()*,;:@/\".includes(String.fromCharCode(b)))\n}\n\nfunction encodeWith(input: string, keep: (byte: number) => boolean): string {\n let out = ''\n for (const byte of new TextEncoder().encode(input)) {\n out += keep(byte) ? String.fromCharCode(byte) : `%${byte.toString(16).toUpperCase().padStart(2, '0')}`\n }\n return out\n}\n\nfunction isUnreserved(byte: number): boolean {\n const ch = String.fromCharCode(byte)\n return /[A-Za-z0-9]/.test(ch) || '-._~'.includes(ch)\n}\n\nfunction objectEventBase(host: ObjHost, path: string): string {\n return objEventBase(host.name, decodedSegments(path))\n}\n\nfunction splitAuthority(rest: string): { authority: string; path: string; query: string | null } {\n const qpos = rest.search(/[?#]/)\n const beforeQuery = qpos < 0 ? rest : rest.slice(0, qpos)\n let query: string | null = null\n if (qpos >= 0) {\n const q = rest.slice(qpos).split('#')[0]\n query = q.startsWith('?') ? q.slice(1) : q\n if (query === '') query = null\n }\n const slash = beforeQuery.indexOf('/')\n return slash < 0\n ? { authority: beforeQuery, path: '', query }\n : { authority: beforeQuery.slice(0, slash), path: beforeQuery.slice(slash), query }\n}\n\nfunction normalizePath(path: string, trimTrailingSlash: boolean): string {\n if (!path.startsWith('/')) throw new ObjectUrlError(`path '${path}' must be absolute`)\n let body = path.slice(1)\n if (trimTrailingSlash && body.endsWith('/')) body = body.slice(0, -1)\n const raw = body.split('/')\n let out = ''\n raw.forEach((segment, index) => {\n if (segment === '' && index === raw.length - 1 && !trimTrailingSlash) {\n out += '/'\n return\n }\n const decoded = percentDecode(segment)\n if (decoded === '' || decoded === '.' || decoded === '..') {\n throw new ObjectUrlError(`ambiguous path segment in '${path}'`)\n }\n out += `/${encodeObjSegment(decoded)}`\n })\n return out\n}\n\nfunction decodedSegments(path: string): string[] {\n return path\n .split('/')\n .filter((s) => s !== '')\n .map((s) => {\n try {\n return percentDecode(s)\n } catch {\n return s\n }\n })\n}\n\nfunction parseQuery(query: string): Record<string, string> {\n const out: Record<string, string> = {}\n for (const pair of query.split('&')) {\n if (pair === '') continue\n const eq = pair.indexOf('=')\n const key = percentDecode((eq < 0 ? pair : pair.slice(0, eq)).replace(/\\+/g, ' '))\n let value = percentDecode((eq < 0 ? '' : pair.slice(eq + 1)).replace(/\\+/g, ' '))\n if (key === 'selector') {\n try {\n value = canonicalJson(JSON.parse(value))\n } catch (e) {\n throw new ObjectUrlError(`selector must be JSON: ${e}`)\n }\n }\n if (Object.prototype.hasOwnProperty.call(out, key)) {\n throw new ObjectUrlError(`query key '${key}' repeats`)\n }\n out[key] = value\n }\n return out\n}\n\nfunction percentDecode(input: string): string {\n const raw = new TextEncoder().encode(input)\n const bytes: number[] = []\n for (let i = 0; i < raw.length; ) {\n if (raw[i] === 0x25) {\n const hex = String.fromCharCode(raw[i + 1] ?? 0, raw[i + 2] ?? 0)\n if (!/^[0-9A-Fa-f]{2}$/.test(hex)) throw new ObjectUrlError(`invalid escape in '${input}'`)\n bytes.push(parseInt(hex, 16))\n i += 3\n } else {\n bytes.push(raw[i])\n i += 1\n }\n }\n try {\n return new TextDecoder('utf-8', { fatal: true }).decode(new Uint8Array(bytes))\n } catch {\n throw new ObjectUrlError(`'${input}' is not UTF-8`)\n }\n}\n\nfunction isHostname(host: string): boolean {\n return (\n host !== '' &&\n host.length <= 253 &&\n host\n .split('.')\n .every((label) => label !== '' && label.length <= 63 && /^[a-z0-9-]+$/.test(label) && !label.startsWith('-') && !label.endsWith('-'))\n )\n}\n\nfunction strictObjIdLabel(label: string): ObjId | null {\n if (label.length < 26) return null\n try {\n const objId = ObjId.fromString(label)\n const typeOk = /^[a-z0-9_-]+$/.test(objId.objType)\n return typeOk && objId.objHash.length >= 16 && objId.toBase32() === label ? objId : null\n } catch {\n return null\n }\n}\n"],"names":[],"mappings":";AASO,MAAM,oBAAoB;AAAA,EAC/B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAEO,MAAM,sBAAsB;AAE5B,MAAM,uBAAuB,MAAM;AAAC;AAYpC,SAAS,iBAAiB,MAAuB;AAC9C,SAAA,kBAAwC,SAAS,IAAI;AAC/D;AAGO,SAAS,eAAe,OAA0B;AACvD,UAAQ,MAAM;AACR,QAAA,MAAM,MAAM,QAAQ,KAAK;AAC/B,MAAI,MAAM;AAAG,UAAM,IAAI,eAAe,IAAI,KAAK,iBAAiB;AAChE,QAAM,SAAS,MAAM,MAAM,GAAG,GAAG,EAAE;AACnC,QAAM,OAAO,MAAM,MAAM,MAAM,CAAC;AAChC,UAAQ,QAAQ;AAAA,IACd,KAAK;AAAA,IACL,KAAK,QAAQ;AACP,UAAA;AACK,eAAA,EAAE,MAAM,OAAO,KAAK,IAAI,IAAI,KAAK,EAAE,SAAA;eACnC,GAAG;AACV,cAAM,IAAI,eAAe,oBAAoB,KAAK,MAAM,CAAC,EAAE;AAAA,MAC7D;AAAA,IACF;AAAA,IACA,KAAK;AACH,aAAO,EAAE,MAAM,WAAW,KAAK,MAAM;AAAA,IACvC,KAAK,QAAQ;AACX,YAAM,EAAE,WAAW,MAAM,MAAM,IAAI,eAAe,IAAI;AACtD,UAAI,UAAU;AAAY,cAAA,IAAI,eAAe,0CAA0C;AACjF,YAAA,OAAO,UAAU;AACnB,UAAA;AACA,UAAA,SAAS,MAAM,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