@xenosystem/agent-sdk 0.10.7 → 0.10.9
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/artifacts/index.cjs +10 -10
- package/dist/artifacts/index.js +10 -10
- package/dist/artifacts/metafile-cjs.json +1 -1
- package/dist/artifacts/metafile-esm.json +1 -1
- package/dist/automation/index.cjs +15 -15
- package/dist/automation/index.js +16 -16
- package/dist/automation/metafile-cjs.json +1 -1
- package/dist/automation/metafile-esm.json +1 -1
- package/dist/control-plane/index.cjs +1 -1
- package/dist/control-plane/index.js +1 -1
- package/dist/electron/index.cjs +2 -2
- package/dist/electron/index.js +2 -2
- package/dist/electron/metafile-cjs.json +1 -1
- package/dist/electron/metafile-esm.json +1 -1
- package/dist/index.cjs +306 -306
- package/dist/index.js +326 -326
- package/dist/intelligence/index.cjs +10 -10
- package/dist/intelligence/index.js +10 -10
- package/dist/intelligence/metafile-cjs.json +1 -1
- package/dist/intelligence/metafile-esm.json +1 -1
- package/dist/metafile-cjs.json +1 -1
- package/dist/metafile-esm.json +1 -1
- package/dist/providers/index.cjs +10 -10
- package/dist/providers/index.js +10 -10
- package/dist/providers/metafile-cjs.json +1 -1
- package/dist/providers/metafile-esm.json +1 -1
- package/dist/recipes/index.cjs +2 -2
- package/dist/recipes/index.js +2 -2
- package/dist/recipes/metafile-cjs.json +1 -1
- package/dist/recipes/metafile-esm.json +1 -1
- package/dist/research/index.cjs +3 -3
- package/dist/research/index.js +3 -3
- package/dist/research/metafile-cjs.json +1 -1
- package/dist/research/metafile-esm.json +1 -1
- package/dist/session/index.cjs +1 -1
- package/dist/session/index.js +1 -1
- package/dist/session/metafile-cjs.json +1 -1
- package/dist/session/metafile-esm.json +1 -1
- package/dist/sharing/index.cjs +4 -4
- package/dist/sharing/index.js +4 -4
- package/dist/sharing/metafile-cjs.json +1 -1
- package/dist/sharing/metafile-esm.json +1 -1
- package/dist/ui/index.cjs +2 -2
- package/dist/ui/index.js +2 -2
- package/dist/ui/metafile-cjs.json +1 -1
- package/dist/ui/metafile-esm.json +1 -1
- package/dist/utils/index.cjs +13 -13
- package/dist/utils/index.d.cts +2 -1
- package/dist/utils/index.d.ts +2 -1
- package/dist/utils/index.js +1 -1
- package/dist/utils/metafile-cjs.json +1 -1
- package/dist/utils/metafile-esm.json +1 -1
- package/package.json +1 -1
package/dist/sharing/index.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";var
|
|
2
|
-
[truncated]`),n}function g(e,r,t,n,o,i){r.lastIndex=0;let s=0,a=e.replace(r,(...d)=>(s+=1,t.includes("$1")?t.replace("$1",String(d[1]??"")):t));for(let d=0;d<s;d+=1)h(i,n,o);return r.lastIndex=0,a}function D(e,r,t,n,o,i){let s=r?.trim().replace(/[\\/]+$/,"");if(!s)return e;let a=new RegExp(ye(s).replace(/[\\/]+/g,"[\\\\/]"),process.platform==="win32"?"gi":"g");return g(e,a,t,n,o,i)}function ye(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function me(e){return e.replace(/[^A-Za-z0-9_-]/g,"_")}var c=require("node:crypto");function m(e){return JSON.stringify(C(e,new Set))}function C(e,r){if(e===null||typeof e!="object"){if(typeof e=="number"&&!Number.isFinite(e))throw new TypeError("Artifact JSON cannot contain non-finite numbers");return e}if(r.has(e))throw new TypeError("Artifact JSON cannot contain cycles");if(r.add(e),Array.isArray(e)){let n=e.map(o=>C(o,r));return r.delete(e),n}let t={};for(let n of Object.keys(e).sort((o,i)=>o.localeCompare(i))){let o=e[n];if(o===void 0)throw new TypeError(`Artifact JSON property ${n} is undefined`);t[n]=C(o,r)}return r.delete(e),t}function S(e,r={}){for(let t of e){let n=t.codePointAt(0);if(n===127)return!0;if(!(n>31)&&!(n===9&&r.allowTab===!0)&&!((n===10||n===13)&&r.allowLineBreaks===!0))return!0}return!1}var Se=10080*60*1e3,Ie=365*24*60*60*1e3;function we(){let{publicKey:e,privateKey:r}=(0,c.generateKeyPairSync)("ed25519"),t=e.export({type:"spki",format:"pem"}).toString(),n=r.export({type:"pkcs8",format:"pem"}).toString();return{keyId:O(t),publicKeyPem:t,privateKeyPem:n}}function O(e){let r=(0,c.createPublicKey)(e).export({type:"spki",format:"der"});return`ed25519:${(0,c.createHash)("sha256").update(r).digest("hex").slice(0,32)}`}function Xe(e){let r=e.now??new Date,t=r.toISOString(),n=q(r,e.expiresAt,e.ttlMs),o=(0,c.randomBytes)(32).toString("base64url"),i=v(e.content,e.redaction),s=e.visibility??"private";_e(s,e.workspaceId,e.teamId,e.allowedPrincipalIds);let a={schemaVersion:2,kind:"xeno-secure-share",shareId:u(e.shareId??`share_${(0,c.randomUUID)()}`,"shareId"),createdAt:t,expiresAt:n,issuer:M(e.issuer),session:U({...e.session,name:e.session.name??e.name}),access:{mode:"read-only",visibility:s,...e.workspaceId?{workspaceId:u(e.workspaceId,"workspaceId")}:{},...e.teamId?{teamId:u(e.teamId,"teamId")}:{},...e.allowedPrincipalIds?.length?{allowedPrincipalIds:X(e.allowedPrincipalIds,"allowedPrincipalIds")}:{},capabilityToken:{algorithm:"sha256",hash:z(o)}},content:i.value,references:j(e.references??[]),redaction:i.report};return{envelope:J(a,e.signingIdentity),capabilityToken:o,url:Ae(e.baseUrl,a.shareId,o)}}function J(e,r){if(r.keyId!==O(r.publicKeyPem))throw new Error("Signing identity keyId does not match public key");let t=K(e,r);return{payload:e,signature:t}}function Re(e,r={}){let t=[],n=!1,o=!1;if(e?.payload?.kind!=="xeno-secure-share"||e.payload.schemaVersion!==2)t.push("Unsupported secure-share envelope");else{let N=B(r.trustedPublicKeys,e.signature.keyId),$=N??(r.allowEmbeddedPublicKey===!1?void 0:e.signature.publicKeySpki);if(o=!!N,!$)t.push("No trusted or embedded issuer public key is available");else try{n=L(e.payload,e.signature,$),n||t.push("Share signature is invalid")}catch(k){t.push(k instanceof Error?k.message:String(k))}}let i=(r.now??new Date).getTime(),s=Date.parse(e?.payload?.expiresAt??""),d=r.revokedShareIds?.has(e?.payload?.shareId??"")??!1?"revoked":Number.isFinite(s)&&s<=i?"expired":"active";d==="revoked"&&t.push("Share has been revoked"),d==="expired"&&t.push("Share has expired");let y=Ee(e?.payload,r.capabilityToken);y||t.push("Capability token is missing or invalid");let b=xe(e?.payload,r.principal);return b||t.push("Principal is outside the share audience"),{valid:n&&y&&b&&d==="active",integrityValid:n,issuerTrusted:o,capabilityValid:y,audienceAllowed:b,status:d,errors:t}}function be(e){let r=e.now??new Date,t={schemaVersion:1,kind:"xeno-session-handoff",handoffId:u(e.handoffId??`handoff_${(0,c.randomUUID)()}`,"handoffId"),createdAt:r.toISOString(),expiresAt:q(r,e.expiresAt,e.ttlMs??1440*60*1e3),issuer:M(e.issuer),source:U(e.source),target:Pe(e.target),resume:ve(e.resume),authority:Ce(e.authority),references:j(e.references??[]),...e.shareId?{shareId:u(e.shareId,"shareId")}:{}};return{payload:t,signature:K(t,e.signingIdentity)}}function ke(e,r={}){let t=[];if(e?.payload?.kind!=="xeno-session-handoff"||e.payload.schemaVersion!==1)return{valid:!1,integrityValid:!1,issuerTrusted:!1,expired:!1,errors:["Unsupported handoff envelope"]};let n=B(r.trustedPublicKeys,e.signature.keyId),o=n??(r.allowEmbeddedPublicKey===!1?void 0:e.signature.publicKeySpki),i=!!n,s=!1;if(!o)t.push("No trusted or embedded issuer public key is available");else try{s=L(e.payload,e.signature,o),s||t.push("Handoff signature is invalid")}catch(d){t.push(d instanceof Error?d.message:String(d))}let a=Date.parse(e.payload.expiresAt)<=(r.now??new Date).getTime();return a&&t.push("Handoff has expired"),{valid:s&&!a,integrityValid:s,issuerTrusted:i,expired:a,errors:t}}function K(e,r){let t=m(e),n=(0,c.sign)(null,Buffer.from(t),(0,c.createPrivateKey)(r.privateKeyPem)).toString("base64");return{algorithm:"ed25519",keyId:r.keyId,value:n,publicKeySpki:r.publicKeyPem}}function L(e,r,t){if(r.algorithm!=="ed25519")return!1;let n=Buffer.from(r.value,"base64");if(n.toString("base64")!==r.value)throw new Error("Signature is not canonical base64");return(0,c.verify)(null,Buffer.from(m(e)),(0,c.createPublicKey)(t),n)}function Ee(e,r){if(!e||!r)return!1;let t=Buffer.from(e.access.capabilityToken.hash,"hex"),n=Buffer.from(z(r),"hex");return t.length===n.length&&(0,c.timingSafeEqual)(t,n)}function xe(e,r){if(!e)return!1;let t=e.access;return t.allowedPrincipalIds?.length&&(!r?.id||!t.allowedPrincipalIds.includes(r.id))?!1:t.visibility==="workspace"?!!(r?.workspaceId&&r.workspaceId===t.workspaceId):t.visibility==="team"?!!(t.teamId&&r?.teamIds?.includes(t.teamId)):t.visibility==="private"?!!(r?.id&&r.id===e.issuer.id):t.visibility==="link"}function Ae(e,r,t){let n=new URL(e??"xeno://share/");if(n.username||n.password)throw new Error("Share base URL cannot contain credentials");if(n.protocol!=="https:"&&n.protocol!=="xeno:")throw new Error("Share base URL must use https: or xeno:");return n.pathname=`${n.pathname.replace(/\/$/,"")}/${encodeURIComponent(r)}`,n.search="",n.hash=new URLSearchParams({access_token:t}).toString(),n.toString()}function q(e,r,t=Se){let n=r?new Date(r):new Date(e.getTime()+t);if(!Number.isFinite(n.getTime()))throw new Error("expiresAt must be a valid timestamp");let o=n.getTime()-e.getTime();if(o<=0)throw new Error("expiresAt must be in the future");if(o>Ie)throw new Error("Share and handoff expiry cannot exceed 365 days");return n.toISOString()}function M(e){return{id:u(e.id,"issuer.id"),...e.displayName?.trim()?{displayName:e.displayName.trim().slice(0,160)}:{},...e.workspaceId?{workspaceId:u(e.workspaceId,"issuer.workspaceId")}:{},...e.teamId?{teamId:u(e.teamId,"issuer.teamId")}:{}}}function U(e){let r={name:w(e.name,"session.name",200),surface:e.surface};for(let t of["sessionId","runId","hostedRunId","conversationId","parentSessionId","forkedFromSessionId","forkedAtEventId"])e[t]&&(r[t]=u(e[t],`session.${t}`));if(!r.sessionId&&!r.runId&&!r.hostedRunId&&!r.conversationId)throw new Error("Session identity requires sessionId, runId, hostedRunId, or conversationId");return e.git&&(r.git={...e.git.repositoryId?{repositoryId:u(e.git.repositoryId,"git.repositoryId")}:{},...e.git.remoteUrl?{remoteUrl:_(e.git.remoteUrl,"git.remoteUrl")}:{},...e.git.branch?{branch:w(e.git.branch,"git.branch",300)}:{},...e.git.commit?{commit:F(e.git.commit,"git.commit")}:{},...e.git.pullRequest?{pullRequest:{provider:e.git.pullRequest.provider,repository:w(e.git.pullRequest.repository,"git.pullRequest.repository",300),number:Oe(e.git.pullRequest.number,"git.pullRequest.number"),...e.git.pullRequest.url?{url:_(e.git.pullRequest.url,"git.pullRequest.url")}:{}}}:{}}),r}function j(e){let r=new Set;return e.map(t=>{let n=`${t.kind}:${t.id}`;if(r.has(n))throw new Error(`Duplicate share reference: ${n}`);return r.add(n),{kind:t.kind,id:u(t.id,"reference.id"),...t.title?.trim()?{title:t.title.trim().slice(0,300)}:{},...t.uri?{uri:_(t.uri,"reference.uri")}:{},...t.hash?{hash:F(t.hash,"reference.hash")}:{}}})}function Pe(e){return{surface:e.surface,...e.workspaceId?{workspaceId:u(e.workspaceId,"target.workspaceId")}:{},...e.teamId?{teamId:u(e.teamId,"target.teamId")}:{},...e.environmentId?{environmentId:u(e.environmentId,"target.environmentId")}:{},...e.repositoryId?{repositoryId:u(e.repositoryId,"target.repositoryId")}:{}}}function ve(e){let r={};for(let t of["sessionId","runId","hostedRunId","checkpointId","transcriptEventId"])e[t]&&(r[t]=u(e[t],`resume.${t}`));if(e.artifactIds?.length&&(r.artifactIds=X(e.artifactIds,"resume.artifactIds")),e.taskIds?.length&&(r.taskIds=X(e.taskIds,"resume.taskIds")),!Object.keys(r).length)throw new Error("Handoff resume point cannot be empty");return r}function Ce(e){return{filesystem:e.filesystem,network:e.network,externalActions:e.externalActions,secretRefs:X(e.secretRefs,"authority.secretRefs")}}function _e(e,r,t,n){if(e==="workspace"&&!r)throw new Error("workspace visibility requires workspaceId");if(e==="team"&&!t)throw new Error("team visibility requires teamId");if(e==="private"&&n?.length)throw new Error("private shares cannot add allowed principals; use link/workspace/team visibility")}function B(e,r){if(!e)return;let t=e;return typeof t.get=="function"?t.get(r):e[r]}function z(e){return(0,c.createHash)("sha256").update(e).digest("hex")}function X(e,r){return[...new Set(e.map(t=>u(t,r)))].sort()}function u(e,r){let t=e.trim();if(!t||t.length>500||S(t))throw new Error(`${r} is invalid`);return t}function F(e,r){let t=e.trim();if(!/^[A-Za-z0-9:+._-]{7,256}$/.test(t))throw new Error(`${r} is invalid`);return t}function w(e,r,t){let n=e.trim();if(!n||n.length>t||S(n,{allowTab:!0,allowLineBreaks:!0}))throw new Error(`${r} is invalid`);return n}function Oe(e,r){if(!Number.isSafeInteger(e)||e<=0)throw new Error(`${r} must be a positive integer`);return e}function _(e,r){let t=w(e,r,2e3),n=new URL(t);if(n.username||n.password)throw new Error(`${r} cannot contain credentials`);if(!["https:","xeno:","artifact:","urn:"].includes(n.protocol))throw new Error(`${r} uses an unsupported scheme`);return n.toString()}var H=require("node:crypto"),l=require("node:fs/promises"),p=require("node:path");var f=require("node:fs"),T=require("node:os"),Y=require("node:path");function Te(){return new Date().toISOString()}function Ve(){return new Date(Date.now()-Math.floor(process.uptime()*1e3)).toISOString()}function G(e){try{return JSON.parse((0,f.readFileSync)(e,"utf8"))}catch{return null}}function He(e){if(!e||e<=0)return!1;try{return process.kill(e,0),!0}catch{return!1}}function Ne(e){return e.hostname!==(0,T.hostname)()?!0:He(e.pid)}function Z(e,r){(0,f.mkdirSync)((0,Y.dirname)(e),{recursive:!0}),(0,f.writeFileSync)(e,JSON.stringify(r,null,2)+`
|
|
3
|
-
`,{encoding:"utf8",flag:"wx"})}function
|
|
4
|
-
`),
|
|
1
|
+
"use strict";var oe=Object.create;var I=Object.defineProperty;var se=Object.getOwnPropertyDescriptor;var ae=Object.getOwnPropertyNames;var ce=Object.getPrototypeOf,de=Object.prototype.hasOwnProperty;var ue=(e,t)=>{for(var r in t)I(e,r,{get:t[r],enumerable:!0})},$=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of ae(t))!de.call(e,i)&&i!==r&&I(e,i,{get:()=>t[i],enumerable:!(n=se(t,i))||n.enumerable});return e};var le=(e,t,r)=>(r=e!=null?oe(ce(e)):{},$(t||!e||!e.__esModule?I(r,"default",{value:e,enumerable:!0}):r,e)),fe=e=>$(I({},"__esModule",{value:!0}),e);var Ue={};ue(Ue,{FileXenoShareRegistry:()=>V,XENO_HANDOFF_SCHEMA_VERSION:()=>v,XENO_SHARE_REGISTRY_SCHEMA_VERSION:()=>x,XENO_SHARE_SCHEMA_VERSION:()=>A,createXenoSecureShare:()=>ke,createXenoSessionHandoff:()=>ve,createXenoShareSigningIdentity:()=>Re,publicKeyFingerprint:()=>_,redactXenoShareValue:()=>T,signSharePayload:()=>J,verifyXenoSecureShare:()=>Ae,verifyXenoSessionHandoff:()=>Pe});module.exports=fe(Ue);var A=2,v=1,x=1;var ge=/(?:^|[_-])(api[_-]?key|access[_-]?token|refresh[_-]?token|id[_-]?token|auth(?:orization)?|bearer|secret|password|passwd|credential|cookie|private[_-]?key|client[_-]?secret)(?:$|[_-])/i,pe=/\b([A-Z][A-Z0-9_]*(?:TOKEN|SECRET|PASSWORD|PASSWD|API_KEY|PRIVATE_KEY|CLIENT_SECRET)[A-Z0-9_]*)\s*=\s*([^\s"']+)/g,he=/\b(Bearer\s+)[A-Za-z0-9._~+/=-]{8,}/gi,me=/\b(?:sk-[A-Za-z0-9_-]{16,}|gh[pousr]_[A-Za-z0-9_]{20,}|github_pat_[A-Za-z0-9_]{20,}|xox[baprs]-[A-Za-z0-9-]{16,}|AKIA[0-9A-Z]{16})\b/g,ye=/-----BEGIN (?:RSA |EC |OPENSSH |)PRIVATE KEY-----[\s\S]*?-----END (?:RSA |EC |OPENSSH |)PRIVATE KEY-----/g,Se=/\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}\b/gi,we=/([?&#](?:access_token|refresh_token|token|key|secret|password|api[_-]?key|signature)=)[^&#\s]+/gi;function T(e,t={}){let r={options:{...t,redactEmails:t.redactEmails??!0,maxDepth:t.maxDepth??48,maxStringLength:t.maxStringLength??2e5,maxEvents:t.maxEvents??256},seen:new Set,events:[],byCategory:{},total:0};return{value:P(e,"$","",0,r),report:{schemaVersion:1,total:r.total,byCategory:r.byCategory,events:r.events,eventsTruncated:r.total>r.events.length}}}function h(e,t,r){e.total+=1,e.byCategory[r]=(e.byCategory[r]??0)+1,e.events.length<e.options.maxEvents&&e.events.push({path:t,category:r})}function P(e,t,r,n,i){if(ge.test(r))return e!=null&&e!==""&&h(i,t,"secret-field"),e==null||e===""?null:"[redacted]";if(n>i.options.maxDepth)return h(i,t,"truncated"),"[redacted:depth-limit]";if(e===null||typeof e=="boolean")return e;if(typeof e=="number")return Number.isFinite(e)?e:String(e);if(typeof e=="bigint")return e.toString();if(typeof e=="string")return Ie(e,t,i);if(e instanceof Date)return e.toISOString();if(e instanceof Uint8Array)return h(i,t,"binary"),`[redacted:binary:${e.byteLength}-bytes]`;if(Array.isArray(e)){if(i.seen.has(e))return h(i,t,"cycle"),"[redacted:cycle]";i.seen.add(e);let o=e.map((s,a)=>P(s,`${t}[${a}]`,"",n+1,i));return i.seen.delete(e),o}if(e&&typeof e=="object"){if(i.seen.has(e))return h(i,t,"cycle"),"[redacted:cycle]";i.seen.add(e);let o={};for(let[s,a]of Object.entries(e))o[s]=P(a,`${t}.${Ee(s)}`,s,n+1,i);return i.seen.delete(e),o}return null}function Ie(e,t,r){let n=e;return n=p(n,ye,"[redacted:private-key]",t,"private-key",r),n=p(n,he,"$1[redacted]",t,"authorization",r),n=p(n,me,"[redacted:credential]",t,"credential-pattern",r),n=p(n,pe,"$1=[redacted]",t,"environment-secret",r),n=p(n,we,"$1[redacted]",t,"url-secret",r),r.options.redactEmails&&(n=p(n,Se,"[redacted:email]",t,"email",r)),n=F(n,r.options.workspaceRoot,"<workspace>",t,"workspace-path",r),n=F(n,r.options.homeDirectory,"<home>",t,"home-path",r),n.length>r.options.maxStringLength&&(h(r,t,"truncated"),n=`${n.slice(0,r.options.maxStringLength)}
|
|
2
|
+
[truncated]`),n}function p(e,t,r,n,i,o){t.lastIndex=0;let s=0,a=e.replace(t,(...d)=>(s+=1,r.includes("$1")?r.replace("$1",String(d[1]??"")):r));for(let d=0;d<s;d+=1)h(o,n,i);return t.lastIndex=0,a}function F(e,t,r,n,i,o){let s=t?.trim().replace(/[\\/]+$/,"");if(!s)return e;let a=new RegExp(xe(s).replace(/[\\/]+/g,"[\\\\/]"),process.platform==="win32"?"gi":"g");return p(e,a,r,n,i,o)}function xe(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function Ee(e){return e.replace(/[^A-Za-z0-9_-]/g,"_")}var c=require("node:crypto");function S(e){return JSON.stringify(C(e,new Set))}function C(e,t){if(e===null||typeof e!="object"){if(typeof e=="number"&&!Number.isFinite(e))throw new TypeError("Artifact JSON cannot contain non-finite numbers");return e}if(t.has(e))throw new TypeError("Artifact JSON cannot contain cycles");if(t.add(e),Array.isArray(e)){let n=e.map(i=>C(i,t));return t.delete(e),n}let r={};for(let n of Object.keys(e).sort((i,o)=>i.localeCompare(o))){let i=e[n];if(i===void 0)throw new TypeError(`Artifact JSON property ${n} is undefined`);r[n]=C(i,t)}return t.delete(e),r}function w(e,t={}){for(let r of e){let n=r.codePointAt(0);if(n===127)return!0;if(!(n>31)&&!(n===9&&t.allowTab===!0)&&!((n===10||n===13)&&t.allowLineBreaks===!0))return!0}return!1}var Xe=10080*60*1e3,be=365*24*60*60*1e3;function Re(){let{publicKey:e,privateKey:t}=(0,c.generateKeyPairSync)("ed25519"),r=e.export({type:"spki",format:"pem"}).toString(),n=t.export({type:"pkcs8",format:"pem"}).toString();return{keyId:_(r),publicKeyPem:r,privateKeyPem:n}}function _(e){let t=(0,c.createPublicKey)(e).export({type:"spki",format:"der"});return`ed25519:${(0,c.createHash)("sha256").update(t).digest("hex").slice(0,32)}`}function ke(e){let t=e.now??new Date,r=t.toISOString(),n=M(t,e.expiresAt,e.ttlMs),i=(0,c.randomBytes)(32).toString("base64url"),o=T(e.content,e.redaction),s=e.visibility??"private";He(s,e.workspaceId,e.teamId,e.allowedPrincipalIds);let a={schemaVersion:2,kind:"xeno-secure-share",shareId:u(e.shareId??`share_${(0,c.randomUUID)()}`,"shareId"),createdAt:r,expiresAt:n,issuer:j(e.issuer),session:q({...e.session,name:e.session.name??e.name}),access:{mode:"read-only",visibility:s,...e.workspaceId?{workspaceId:u(e.workspaceId,"workspaceId")}:{},...e.teamId?{teamId:u(e.teamId,"teamId")}:{},...e.allowedPrincipalIds?.length?{allowedPrincipalIds:X(e.allowedPrincipalIds,"allowedPrincipalIds")}:{},capabilityToken:{algorithm:"sha256",hash:Z(i)}},content:o.value,references:z(e.references??[]),redaction:o.report};return{envelope:J(a,e.signingIdentity),capabilityToken:i,url:Oe(e.baseUrl,a.shareId,i)}}function J(e,t){if(t.keyId!==_(t.publicKeyPem))throw new Error("Signing identity keyId does not match public key");let r=B(e,t);return{payload:e,signature:r}}function Ae(e,t={}){let r=[],n=!1,i=!1;if(e?.payload?.kind!=="xeno-secure-share"||e.payload.schemaVersion!==2)r.push("Unsupported secure-share envelope");else{let L=U(t.trustedPublicKeys,e.signature.keyId),D=L??(t.allowEmbeddedPublicKey===!1?void 0:e.signature.publicKeySpki);if(i=!!L,!D)r.push("No trusted or embedded issuer public key is available");else try{n=K(e.payload,e.signature,D),n||r.push("Share signature is invalid")}catch(k){r.push(k instanceof Error?k.message:String(k))}}let o=(t.now??new Date).getTime(),s=Date.parse(e?.payload?.expiresAt??""),d=t.revokedShareIds?.has(e?.payload?.shareId??"")??!1?"revoked":Number.isFinite(s)&&s<=o?"expired":"active";d==="revoked"&&r.push("Share has been revoked"),d==="expired"&&r.push("Share has expired");let y=Te(e?.payload,t.capabilityToken);y||r.push("Capability token is missing or invalid");let R=Ce(e?.payload,t.principal);return R||r.push("Principal is outside the share audience"),{valid:n&&y&&R&&d==="active",integrityValid:n,issuerTrusted:i,capabilityValid:y,audienceAllowed:R,status:d,errors:r}}function ve(e){let t=e.now??new Date,r={schemaVersion:1,kind:"xeno-session-handoff",handoffId:u(e.handoffId??`handoff_${(0,c.randomUUID)()}`,"handoffId"),createdAt:t.toISOString(),expiresAt:M(t,e.expiresAt,e.ttlMs??1440*60*1e3),issuer:j(e.issuer),source:q(e.source),target:_e(e.target),resume:Ne(e.resume),authority:Ve(e.authority),references:z(e.references??[]),...e.shareId?{shareId:u(e.shareId,"shareId")}:{}};return{payload:r,signature:B(r,e.signingIdentity)}}function Pe(e,t={}){let r=[];if(e?.payload?.kind!=="xeno-session-handoff"||e.payload.schemaVersion!==1)return{valid:!1,integrityValid:!1,issuerTrusted:!1,expired:!1,errors:["Unsupported handoff envelope"]};let n=U(t.trustedPublicKeys,e.signature.keyId),i=n??(t.allowEmbeddedPublicKey===!1?void 0:e.signature.publicKeySpki),o=!!n,s=!1;if(!i)r.push("No trusted or embedded issuer public key is available");else try{s=K(e.payload,e.signature,i),s||r.push("Handoff signature is invalid")}catch(d){r.push(d instanceof Error?d.message:String(d))}let a=Date.parse(e.payload.expiresAt)<=(t.now??new Date).getTime();return a&&r.push("Handoff has expired"),{valid:s&&!a,integrityValid:s,issuerTrusted:o,expired:a,errors:r}}function B(e,t){let r=S(e),n=(0,c.sign)(null,Buffer.from(r),(0,c.createPrivateKey)(t.privateKeyPem)).toString("base64");return{algorithm:"ed25519",keyId:t.keyId,value:n,publicKeySpki:t.publicKeyPem}}function K(e,t,r){if(t.algorithm!=="ed25519")return!1;let n=Buffer.from(t.value,"base64");if(n.toString("base64")!==t.value)throw new Error("Signature is not canonical base64");return(0,c.verify)(null,Buffer.from(S(e)),(0,c.createPublicKey)(r),n)}function Te(e,t){if(!e||!t)return!1;let r=Buffer.from(e.access.capabilityToken.hash,"hex"),n=Buffer.from(Z(t),"hex");return r.length===n.length&&(0,c.timingSafeEqual)(r,n)}function Ce(e,t){if(!e)return!1;let r=e.access;return r.allowedPrincipalIds?.length&&(!t?.id||!r.allowedPrincipalIds.includes(t.id))?!1:r.visibility==="workspace"?!!(t?.workspaceId&&t.workspaceId===r.workspaceId):r.visibility==="team"?!!(r.teamId&&t?.teamIds?.includes(r.teamId)):r.visibility==="private"?!!(t?.id&&t.id===e.issuer.id):r.visibility==="link"}function Oe(e,t,r){let n=new URL(e??"xeno://share/");if(n.username||n.password)throw new Error("Share base URL cannot contain credentials");if(n.protocol!=="https:"&&n.protocol!=="xeno:")throw new Error("Share base URL must use https: or xeno:");return n.pathname=`${n.pathname.replace(/\/$/,"")}/${encodeURIComponent(t)}`,n.search="",n.hash=new URLSearchParams({access_token:r}).toString(),n.toString()}function M(e,t,r=Xe){let n=t?new Date(t):new Date(e.getTime()+r);if(!Number.isFinite(n.getTime()))throw new Error("expiresAt must be a valid timestamp");let i=n.getTime()-e.getTime();if(i<=0)throw new Error("expiresAt must be in the future");if(i>be)throw new Error("Share and handoff expiry cannot exceed 365 days");return n.toISOString()}function j(e){return{id:u(e.id,"issuer.id"),...e.displayName?.trim()?{displayName:e.displayName.trim().slice(0,160)}:{},...e.workspaceId?{workspaceId:u(e.workspaceId,"issuer.workspaceId")}:{},...e.teamId?{teamId:u(e.teamId,"issuer.teamId")}:{}}}function q(e){let t={name:E(e.name,"session.name",200),surface:e.surface};for(let r of["sessionId","runId","hostedRunId","conversationId","parentSessionId","forkedFromSessionId","forkedAtEventId"])e[r]&&(t[r]=u(e[r],`session.${r}`));if(!t.sessionId&&!t.runId&&!t.hostedRunId&&!t.conversationId)throw new Error("Session identity requires sessionId, runId, hostedRunId, or conversationId");return e.git&&(t.git={...e.git.repositoryId?{repositoryId:u(e.git.repositoryId,"git.repositoryId")}:{},...e.git.remoteUrl?{remoteUrl:O(e.git.remoteUrl,"git.remoteUrl")}:{},...e.git.branch?{branch:E(e.git.branch,"git.branch",300)}:{},...e.git.commit?{commit:Y(e.git.commit,"git.commit")}:{},...e.git.pullRequest?{pullRequest:{provider:e.git.pullRequest.provider,repository:E(e.git.pullRequest.repository,"git.pullRequest.repository",300),number:Le(e.git.pullRequest.number,"git.pullRequest.number"),...e.git.pullRequest.url?{url:O(e.git.pullRequest.url,"git.pullRequest.url")}:{}}}:{}}),t}function z(e){let t=new Set;return e.map(r=>{let n=`${r.kind}:${r.id}`;if(t.has(n))throw new Error(`Duplicate share reference: ${n}`);return t.add(n),{kind:r.kind,id:u(r.id,"reference.id"),...r.title?.trim()?{title:r.title.trim().slice(0,300)}:{},...r.uri?{uri:O(r.uri,"reference.uri")}:{},...r.hash?{hash:Y(r.hash,"reference.hash")}:{}}})}function _e(e){return{surface:e.surface,...e.workspaceId?{workspaceId:u(e.workspaceId,"target.workspaceId")}:{},...e.teamId?{teamId:u(e.teamId,"target.teamId")}:{},...e.environmentId?{environmentId:u(e.environmentId,"target.environmentId")}:{},...e.repositoryId?{repositoryId:u(e.repositoryId,"target.repositoryId")}:{}}}function Ne(e){let t={};for(let r of["sessionId","runId","hostedRunId","checkpointId","transcriptEventId"])e[r]&&(t[r]=u(e[r],`resume.${r}`));if(e.artifactIds?.length&&(t.artifactIds=X(e.artifactIds,"resume.artifactIds")),e.taskIds?.length&&(t.taskIds=X(e.taskIds,"resume.taskIds")),!Object.keys(t).length)throw new Error("Handoff resume point cannot be empty");return t}function Ve(e){return{filesystem:e.filesystem,network:e.network,externalActions:e.externalActions,secretRefs:X(e.secretRefs,"authority.secretRefs")}}function He(e,t,r,n){if(e==="workspace"&&!t)throw new Error("workspace visibility requires workspaceId");if(e==="team"&&!r)throw new Error("team visibility requires teamId");if(e==="private"&&n?.length)throw new Error("private shares cannot add allowed principals; use link/workspace/team visibility")}function U(e,t){if(!e)return;let r=e;return typeof r.get=="function"?r.get(t):e[t]}function Z(e){return(0,c.createHash)("sha256").update(e).digest("hex")}function X(e,t){return[...new Set(e.map(r=>u(r,t)))].sort()}function u(e,t){let r=e.trim();if(!r||r.length>500||w(r))throw new Error(`${t} is invalid`);return r}function Y(e,t){let r=e.trim();if(!/^[A-Za-z0-9:+._-]{7,256}$/.test(r))throw new Error(`${t} is invalid`);return r}function E(e,t,r){let n=e.trim();if(!n||n.length>r||w(n,{allowTab:!0,allowLineBreaks:!0}))throw new Error(`${t} is invalid`);return n}function Le(e,t){if(!Number.isSafeInteger(e)||e<=0)throw new Error(`${t} must be a positive integer`);return e}function O(e,t){let r=E(e,t,2e3),n=new URL(r);if(n.username||n.password)throw new Error(`${t} cannot contain credentials`);if(!["https:","xeno:","artifact:","urn:"].includes(n.protocol))throw new Error(`${t} uses an unsupported scheme`);return n.toString()}var H=require("node:crypto"),l=require("node:fs/promises"),m=require("node:path");var f=le(require("node:fs/promises"),1);var De=new Set(["EACCES","EBUSY","EPERM"]),$e=[10,20,40,80,160,320,640];async function W(e,t){for(let r=0;;r+=1)try{await f.rename(e,t);return}catch(n){let i=n.code,o=$e[r];if(process.platform!=="win32"||!i||!De.has(i)||o===void 0)throw n;await new Promise(s=>setTimeout(s,o))}}var g=require("node:fs"),N=require("node:os"),Q=require("node:path");function Fe(){return new Date().toISOString()}function Je(){return new Date(Date.now()-Math.floor(process.uptime()*1e3)).toISOString()}function ee(e){try{return JSON.parse((0,g.readFileSync)(e,"utf8"))}catch{return null}}function Be(e){if(!e||e<=0)return!1;try{return process.kill(e,0),!0}catch{return!1}}function Ke(e){return e.hostname!==(0,N.hostname)()?!0:Be(e.pid)}function G(e,t){(0,g.mkdirSync)((0,Q.dirname)(e),{recursive:!0}),(0,g.writeFileSync)(e,JSON.stringify(t,null,2)+`
|
|
3
|
+
`,{encoding:"utf8",flag:"wx"})}function Me(e,t){let r=ee(e);r?.pid!==t.pid||r.hostname!==t.hostname||(0,g.rmSync)(e,{force:!0})}function te(e,t,r){let n=Fe(),i={schemaVersion:1,name:t,pid:process.pid,hostname:(0,N.hostname)(),processStartedAt:Je(),version:r,acquiredAt:n,updatedAt:n};try{G(e,i)}catch(o){if(o.code!=="EEXIST")throw o;let a=ee(e);if(a&&Ke(a))throw new Error(`${t} is already locked by PID ${a.pid} on ${a.hostname}.`);(0,g.rmSync)(e,{force:!0}),G(e,i)}return{record:i,release:()=>{Me(e,i)}}}var V=class{directory;snapshotPath;lockPath;now;constructor(t){this.directory=(0,m.resolve)(t.directory),this.snapshotPath=(0,m.join)(this.directory,"registry.json"),this.lockPath=(0,m.join)(this.directory,"registry.lock"),this.now=t.now??(()=>new Date)}async register(t,r="created"){return this.mutate(n=>{let i=n.records.find(s=>s.shareId===t.payload.shareId);if(i){if(b(i.envelope)!==b(t))throw new Error(`Share ${t.payload.shareId} already exists with different content`);return{snapshot:n,result:i}}let o={shareId:t.payload.shareId,envelope:t,status:Date.parse(t.payload.expiresAt)<=this.now().getTime()?"expired":"active",registeredAt:this.now().toISOString(),origin:r};return{snapshot:re(n,[...n.records,o],this.now()),result:o}})}async revoke(t,r,n){return this.mutate(i=>{let o=i.records.findIndex(y=>y.shareId===t);if(o<0)throw new Error(`Share not found: ${t}`);let s=i.records[o];if(s.status==="revoked")return{snapshot:i,result:s};let a={...s,status:"revoked",revokedAt:this.now().toISOString(),revokedBy:ne(r,"actor"),revocationReason:ne(n,"reason")},d=[...i.records];return d[o]=a,{snapshot:re(i,d,this.now()),result:a}})}async get(t){return(await this.load()).records.find(r=>r.shareId===t)??null}async list(){let t=this.now().getTime();return(await this.load()).records.map(r=>r.status==="active"&&Date.parse(r.envelope.payload.expiresAt)<=t?{...r,status:"expired"}:r).sort((r,n)=>n.registeredAt.localeCompare(r.registeredAt))}async revokedIds(){return new Set((await this.list()).filter(t=>t.status==="revoked").map(t=>t.shareId))}async load(){try{let t=await(0,l.readFile)(this.snapshotPath,"utf8"),r=JSON.parse(t);return qe(r),r}catch(t){if(t.code==="ENOENT")return je(this.now());throw t}}async mutate(t){await(0,l.mkdir)(this.directory,{recursive:!0,mode:448});let r=te(this.lockPath,"xeno secure-share registry","1");try{let n=await this.load(),{snapshot:i,result:o}=t(n);return i!==n&&await ze(this.snapshotPath,`${JSON.stringify(i,null,2)}
|
|
4
|
+
`),o}finally{r.release()}}};function je(e){return ie({schemaVersion:1,generation:0,updatedAt:e.toISOString(),records:[]})}function re(e,t,r){return ie({schemaVersion:1,generation:e.generation+1,updatedAt:r.toISOString(),records:[...t].sort((n,i)=>n.shareId.localeCompare(i.shareId))})}function ie(e){return{...e,checksum:{algorithm:"sha256",value:(0,H.createHash)("sha256").update(b(e)).digest("hex")}}}function qe(e){if(e.schemaVersion!==1||!Array.isArray(e.records))throw new Error("Invalid secure-share registry snapshot");let{checksum:t,...r}=e,n=(0,H.createHash)("sha256").update(b(r)).digest("hex");if(t?.algorithm!=="sha256"||t.value!==n)throw new Error("Secure-share registry checksum mismatch");let i=new Set;for(let o of e.records){if(o.shareId!==o.envelope?.payload?.shareId)throw new Error("Secure-share registry identity mismatch");if(i.has(o.shareId))throw new Error(`Duplicate secure-share registry record: ${o.shareId}`);i.add(o.shareId)}}async function ze(e,t){await(0,l.mkdir)((0,m.dirname)(e),{recursive:!0,mode:448});let r=`${e}.${process.pid}.${Date.now()}.tmp`,n;try{n=await(0,l.open)(r,"wx",384),await n.writeFile(t,"utf8"),await n.sync(),await n.close(),n=void 0,await W(r,e),await(0,l.chmod)(e,384).catch(()=>{})}finally{n&&await n.close().catch(()=>{}),await(0,l.unlink)(r).catch(()=>{})}}function b(e){return S(e)}function ne(e,t){let r=e.trim();if(!r||r.length>500||w(r))throw new Error(`${t} is invalid`);return r}0&&(module.exports={FileXenoShareRegistry,XENO_HANDOFF_SCHEMA_VERSION,XENO_SHARE_REGISTRY_SCHEMA_VERSION,XENO_SHARE_SCHEMA_VERSION,createXenoSecureShare,createXenoSessionHandoff,createXenoShareSigningIdentity,publicKeyFingerprint,redactXenoShareValue,signSharePayload,verifyXenoSecureShare,verifyXenoSessionHandoff});
|
package/dist/sharing/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var
|
|
2
|
-
[truncated]`),n}function u(e,r,t,n,o,i){r.lastIndex=0;let s=0,a=e.replace(r,(...c)=>(s+=1,t.includes("$1")?t.replace("$1",String(c[1]??"")):t));for(let c=0;c<s;c+=1)l(i,n,o);return r.lastIndex=0,a}function P(e,r,t,n,o,i){let s=r?.trim().replace(/[\\/]+$/,"");if(!s)return e;let a=new RegExp(de(s).replace(/[\\/]+/g,"[\\\\/]"),process.platform==="win32"?"gi":"g");return u(e,a,t,n,o,i)}function de(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function ue(e){return e.replace(/[^A-Za-z0-9_-]/g,"_")}import{createHash as C,createPrivateKey as le,createPublicKey as _,generateKeyPairSync as fe,randomBytes as ge,randomUUID as O,sign as he,timingSafeEqual as pe,verify as ye}from"node:crypto";function g(e){return JSON.stringify(k(e,new Set))}function k(e,r){if(e===null||typeof e!="object"){if(typeof e=="number"&&!Number.isFinite(e))throw new TypeError("Artifact JSON cannot contain non-finite numbers");return e}if(r.has(e))throw new TypeError("Artifact JSON cannot contain cycles");if(r.add(e),Array.isArray(e)){let n=e.map(o=>k(o,r));return r.delete(e),n}let t={};for(let n of Object.keys(e).sort((o,i)=>o.localeCompare(i))){let o=e[n];if(o===void 0)throw new TypeError(`Artifact JSON property ${n} is undefined`);t[n]=k(o,r)}return r.delete(e),t}function h(e,r={}){for(let t of e){let n=t.codePointAt(0);if(n===127)return!0;if(!(n>31)&&!(n===9&&r.allowTab===!0)&&!((n===10||n===13)&&r.allowLineBreaks===!0))return!0}return!1}var me=10080*60*1e3,Se=365*24*60*60*1e3;function tr(){let{publicKey:e,privateKey:r}=fe("ed25519"),t=e.export({type:"spki",format:"pem"}).toString(),n=r.export({type:"pkcs8",format:"pem"}).toString();return{keyId:T(t),publicKeyPem:t,privateKeyPem:n}}function T(e){let r=_(e).export({type:"spki",format:"der"});return`ed25519:${C("sha256").update(r).digest("hex").slice(0,32)}`}function nr(e){let r=e.now??new Date,t=r.toISOString(),n=N(r,e.expiresAt,e.ttlMs),o=ge(32).toString("base64url"),i=v(e.content,e.redaction),s=e.visibility??"private";xe(s,e.workspaceId,e.teamId,e.allowedPrincipalIds);let a={schemaVersion:2,kind:"xeno-secure-share",shareId:d(e.shareId??`share_${O()}`,"shareId"),createdAt:t,expiresAt:n,issuer:$(e.issuer),session:D({...e.session,name:e.session.name??e.name}),access:{mode:"read-only",visibility:s,...e.workspaceId?{workspaceId:d(e.workspaceId,"workspaceId")}:{},...e.teamId?{teamId:d(e.teamId,"teamId")}:{},...e.allowedPrincipalIds?.length?{allowedPrincipalIds:m(e.allowedPrincipalIds,"allowedPrincipalIds")}:{},capabilityToken:{algorithm:"sha256",hash:L(o)}},content:i.value,references:J(e.references??[]),redaction:i.report};return{envelope:Ie(a,e.signingIdentity),capabilityToken:o,url:Re(e.baseUrl,a.shareId,o)}}function Ie(e,r){if(r.keyId!==T(r.publicKeyPem))throw new Error("Signing identity keyId does not match public key");let t=V(e,r);return{payload:e,signature:t}}function or(e,r={}){let t=[],n=!1,o=!1;if(e?.payload?.kind!=="xeno-secure-share"||e.payload.schemaVersion!==2)t.push("Unsupported secure-share envelope");else{let x=K(r.trustedPublicKeys,e.signature.keyId),A=x??(r.allowEmbeddedPublicKey===!1?void 0:e.signature.publicKeySpki);if(o=!!x,!A)t.push("No trusted or embedded issuer public key is available");else try{n=H(e.payload,e.signature,A),n||t.push("Share signature is invalid")}catch(w){t.push(w instanceof Error?w.message:String(w))}}let i=(r.now??new Date).getTime(),s=Date.parse(e?.payload?.expiresAt??""),c=r.revokedShareIds?.has(e?.payload?.shareId??"")??!1?"revoked":Number.isFinite(s)&&s<=i?"expired":"active";c==="revoked"&&t.push("Share has been revoked"),c==="expired"&&t.push("Share has expired");let f=we(e?.payload,r.capabilityToken);f||t.push("Capability token is missing or invalid");let I=Xe(e?.payload,r.principal);return I||t.push("Principal is outside the share audience"),{valid:n&&f&&I&&c==="active",integrityValid:n,issuerTrusted:o,capabilityValid:f,audienceAllowed:I,status:c,errors:t}}function ir(e){let r=e.now??new Date,t={schemaVersion:1,kind:"xeno-session-handoff",handoffId:d(e.handoffId??`handoff_${O()}`,"handoffId"),createdAt:r.toISOString(),expiresAt:N(r,e.expiresAt,e.ttlMs??1440*60*1e3),issuer:$(e.issuer),source:D(e.source),target:be(e.target),resume:ke(e.resume),authority:Ee(e.authority),references:J(e.references??[]),...e.shareId?{shareId:d(e.shareId,"shareId")}:{}};return{payload:t,signature:V(t,e.signingIdentity)}}function sr(e,r={}){let t=[];if(e?.payload?.kind!=="xeno-session-handoff"||e.payload.schemaVersion!==1)return{valid:!1,integrityValid:!1,issuerTrusted:!1,expired:!1,errors:["Unsupported handoff envelope"]};let n=K(r.trustedPublicKeys,e.signature.keyId),o=n??(r.allowEmbeddedPublicKey===!1?void 0:e.signature.publicKeySpki),i=!!n,s=!1;if(!o)t.push("No trusted or embedded issuer public key is available");else try{s=H(e.payload,e.signature,o),s||t.push("Handoff signature is invalid")}catch(c){t.push(c instanceof Error?c.message:String(c))}let a=Date.parse(e.payload.expiresAt)<=(r.now??new Date).getTime();return a&&t.push("Handoff has expired"),{valid:s&&!a,integrityValid:s,issuerTrusted:i,expired:a,errors:t}}function V(e,r){let t=g(e),n=he(null,Buffer.from(t),le(r.privateKeyPem)).toString("base64");return{algorithm:"ed25519",keyId:r.keyId,value:n,publicKeySpki:r.publicKeyPem}}function H(e,r,t){if(r.algorithm!=="ed25519")return!1;let n=Buffer.from(r.value,"base64");if(n.toString("base64")!==r.value)throw new Error("Signature is not canonical base64");return ye(null,Buffer.from(g(e)),_(t),n)}function we(e,r){if(!e||!r)return!1;let t=Buffer.from(e.access.capabilityToken.hash,"hex"),n=Buffer.from(L(r),"hex");return t.length===n.length&&pe(t,n)}function Xe(e,r){if(!e)return!1;let t=e.access;return t.allowedPrincipalIds?.length&&(!r?.id||!t.allowedPrincipalIds.includes(r.id))?!1:t.visibility==="workspace"?!!(r?.workspaceId&&r.workspaceId===t.workspaceId):t.visibility==="team"?!!(t.teamId&&r?.teamIds?.includes(t.teamId)):t.visibility==="private"?!!(r?.id&&r.id===e.issuer.id):t.visibility==="link"}function Re(e,r,t){let n=new URL(e??"xeno://share/");if(n.username||n.password)throw new Error("Share base URL cannot contain credentials");if(n.protocol!=="https:"&&n.protocol!=="xeno:")throw new Error("Share base URL must use https: or xeno:");return n.pathname=`${n.pathname.replace(/\/$/,"")}/${encodeURIComponent(r)}`,n.search="",n.hash=new URLSearchParams({access_token:t}).toString(),n.toString()}function N(e,r,t=me){let n=r?new Date(r):new Date(e.getTime()+t);if(!Number.isFinite(n.getTime()))throw new Error("expiresAt must be a valid timestamp");let o=n.getTime()-e.getTime();if(o<=0)throw new Error("expiresAt must be in the future");if(o>Se)throw new Error("Share and handoff expiry cannot exceed 365 days");return n.toISOString()}function $(e){return{id:d(e.id,"issuer.id"),...e.displayName?.trim()?{displayName:e.displayName.trim().slice(0,160)}:{},...e.workspaceId?{workspaceId:d(e.workspaceId,"issuer.workspaceId")}:{},...e.teamId?{teamId:d(e.teamId,"issuer.teamId")}:{}}}function D(e){let r={name:y(e.name,"session.name",200),surface:e.surface};for(let t of["sessionId","runId","hostedRunId","conversationId","parentSessionId","forkedFromSessionId","forkedAtEventId"])e[t]&&(r[t]=d(e[t],`session.${t}`));if(!r.sessionId&&!r.runId&&!r.hostedRunId&&!r.conversationId)throw new Error("Session identity requires sessionId, runId, hostedRunId, or conversationId");return e.git&&(r.git={...e.git.repositoryId?{repositoryId:d(e.git.repositoryId,"git.repositoryId")}:{},...e.git.remoteUrl?{remoteUrl:E(e.git.remoteUrl,"git.remoteUrl")}:{},...e.git.branch?{branch:y(e.git.branch,"git.branch",300)}:{},...e.git.commit?{commit:q(e.git.commit,"git.commit")}:{},...e.git.pullRequest?{pullRequest:{provider:e.git.pullRequest.provider,repository:y(e.git.pullRequest.repository,"git.pullRequest.repository",300),number:Ae(e.git.pullRequest.number,"git.pullRequest.number"),...e.git.pullRequest.url?{url:E(e.git.pullRequest.url,"git.pullRequest.url")}:{}}}:{}}),r}function J(e){let r=new Set;return e.map(t=>{let n=`${t.kind}:${t.id}`;if(r.has(n))throw new Error(`Duplicate share reference: ${n}`);return r.add(n),{kind:t.kind,id:d(t.id,"reference.id"),...t.title?.trim()?{title:t.title.trim().slice(0,300)}:{},...t.uri?{uri:E(t.uri,"reference.uri")}:{},...t.hash?{hash:q(t.hash,"reference.hash")}:{}}})}function be(e){return{surface:e.surface,...e.workspaceId?{workspaceId:d(e.workspaceId,"target.workspaceId")}:{},...e.teamId?{teamId:d(e.teamId,"target.teamId")}:{},...e.environmentId?{environmentId:d(e.environmentId,"target.environmentId")}:{},...e.repositoryId?{repositoryId:d(e.repositoryId,"target.repositoryId")}:{}}}function ke(e){let r={};for(let t of["sessionId","runId","hostedRunId","checkpointId","transcriptEventId"])e[t]&&(r[t]=d(e[t],`resume.${t}`));if(e.artifactIds?.length&&(r.artifactIds=m(e.artifactIds,"resume.artifactIds")),e.taskIds?.length&&(r.taskIds=m(e.taskIds,"resume.taskIds")),!Object.keys(r).length)throw new Error("Handoff resume point cannot be empty");return r}function Ee(e){return{filesystem:e.filesystem,network:e.network,externalActions:e.externalActions,secretRefs:m(e.secretRefs,"authority.secretRefs")}}function xe(e,r,t,n){if(e==="workspace"&&!r)throw new Error("workspace visibility requires workspaceId");if(e==="team"&&!t)throw new Error("team visibility requires teamId");if(e==="private"&&n?.length)throw new Error("private shares cannot add allowed principals; use link/workspace/team visibility")}function K(e,r){if(!e)return;let t=e;return typeof t.get=="function"?t.get(r):e[r]}function L(e){return C("sha256").update(e).digest("hex")}function m(e,r){return[...new Set(e.map(t=>d(t,r)))].sort()}function d(e,r){let t=e.trim();if(!t||t.length>500||h(t))throw new Error(`${r} is invalid`);return t}function q(e,r){let t=e.trim();if(!/^[A-Za-z0-9:+._-]{7,256}$/.test(t))throw new Error(`${r} is invalid`);return t}function y(e,r,t){let n=e.trim();if(!n||n.length>t||h(n,{allowTab:!0,allowLineBreaks:!0}))throw new Error(`${r} is invalid`);return n}function Ae(e,r){if(!Number.isSafeInteger(e)||e<=0)throw new Error(`${r} must be a positive integer`);return e}function E(e,r){let t=y(e,r,2e3),n=new URL(t);if(n.username||n.password)throw new Error(`${r} cannot contain credentials`);if(!["https:","xeno:","artifact:","urn:"].includes(n.protocol))throw new Error(`${r} uses an unsupported scheme`);return n.toString()}import{createHash as W}from"node:crypto";import{chmod as $e,mkdir as Q,open as De,readFile as Je,rename as Ke,unlink as Le}from"node:fs/promises";import{dirname as qe,join as F,resolve as Me}from"node:path";import{mkdirSync as Pe,readFileSync as ve,rmSync as U,writeFileSync as Ce}from"node:fs";import{hostname as j}from"node:os";import{dirname as _e}from"node:path";function Oe(){return new Date().toISOString()}function Te(){return new Date(Date.now()-Math.floor(process.uptime()*1e3)).toISOString()}function B(e){try{return JSON.parse(ve(e,"utf8"))}catch{return null}}function Ve(e){if(!e||e<=0)return!1;try{return process.kill(e,0),!0}catch{return!1}}function He(e){return e.hostname!==j()?!0:Ve(e.pid)}function M(e,r){Pe(_e(e),{recursive:!0}),Ce(e,JSON.stringify(r,null,2)+`
|
|
3
|
-
`,{encoding:"utf8",flag:"wx"})}function
|
|
4
|
-
`),
|
|
1
|
+
var E=2,X=1,m=1;var ne=/(?:^|[_-])(api[_-]?key|access[_-]?token|refresh[_-]?token|id[_-]?token|auth(?:orization)?|bearer|secret|password|passwd|credential|cookie|private[_-]?key|client[_-]?secret)(?:$|[_-])/i,ie=/\b([A-Z][A-Z0-9_]*(?:TOKEN|SECRET|PASSWORD|PASSWD|API_KEY|PRIVATE_KEY|CLIENT_SECRET)[A-Z0-9_]*)\s*=\s*([^\s"']+)/g,oe=/\b(Bearer\s+)[A-Za-z0-9._~+/=-]{8,}/gi,se=/\b(?:sk-[A-Za-z0-9_-]{16,}|gh[pousr]_[A-Za-z0-9_]{20,}|github_pat_[A-Za-z0-9_]{20,}|xox[baprs]-[A-Za-z0-9-]{16,}|AKIA[0-9A-Z]{16})\b/g,ae=/-----BEGIN (?:RSA |EC |OPENSSH |)PRIVATE KEY-----[\s\S]*?-----END (?:RSA |EC |OPENSSH |)PRIVATE KEY-----/g,ce=/\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}\b/gi,de=/([?&#](?:access_token|refresh_token|token|key|secret|password|api[_-]?key|signature)=)[^&#\s]+/gi;function T(e,t={}){let r={options:{...t,redactEmails:t.redactEmails??!0,maxDepth:t.maxDepth??48,maxStringLength:t.maxStringLength??2e5,maxEvents:t.maxEvents??256},seen:new Set,events:[],byCategory:{},total:0};return{value:b(e,"$","",0,r),report:{schemaVersion:1,total:r.total,byCategory:r.byCategory,events:r.events,eventsTruncated:r.total>r.events.length}}}function f(e,t,r){e.total+=1,e.byCategory[r]=(e.byCategory[r]??0)+1,e.events.length<e.options.maxEvents&&e.events.push({path:t,category:r})}function b(e,t,r,n,i){if(ne.test(r))return e!=null&&e!==""&&f(i,t,"secret-field"),e==null||e===""?null:"[redacted]";if(n>i.options.maxDepth)return f(i,t,"truncated"),"[redacted:depth-limit]";if(e===null||typeof e=="boolean")return e;if(typeof e=="number")return Number.isFinite(e)?e:String(e);if(typeof e=="bigint")return e.toString();if(typeof e=="string")return ue(e,t,i);if(e instanceof Date)return e.toISOString();if(e instanceof Uint8Array)return f(i,t,"binary"),`[redacted:binary:${e.byteLength}-bytes]`;if(Array.isArray(e)){if(i.seen.has(e))return f(i,t,"cycle"),"[redacted:cycle]";i.seen.add(e);let o=e.map((s,a)=>b(s,`${t}[${a}]`,"",n+1,i));return i.seen.delete(e),o}if(e&&typeof e=="object"){if(i.seen.has(e))return f(i,t,"cycle"),"[redacted:cycle]";i.seen.add(e);let o={};for(let[s,a]of Object.entries(e))o[s]=b(a,`${t}.${fe(s)}`,s,n+1,i);return i.seen.delete(e),o}return null}function ue(e,t,r){let n=e;return n=l(n,ae,"[redacted:private-key]",t,"private-key",r),n=l(n,oe,"$1[redacted]",t,"authorization",r),n=l(n,se,"[redacted:credential]",t,"credential-pattern",r),n=l(n,ie,"$1=[redacted]",t,"environment-secret",r),n=l(n,de,"$1[redacted]",t,"url-secret",r),r.options.redactEmails&&(n=l(n,ce,"[redacted:email]",t,"email",r)),n=P(n,r.options.workspaceRoot,"<workspace>",t,"workspace-path",r),n=P(n,r.options.homeDirectory,"<home>",t,"home-path",r),n.length>r.options.maxStringLength&&(f(r,t,"truncated"),n=`${n.slice(0,r.options.maxStringLength)}
|
|
2
|
+
[truncated]`),n}function l(e,t,r,n,i,o){t.lastIndex=0;let s=0,a=e.replace(t,(...c)=>(s+=1,r.includes("$1")?r.replace("$1",String(c[1]??"")):r));for(let c=0;c<s;c+=1)f(o,n,i);return t.lastIndex=0,a}function P(e,t,r,n,i,o){let s=t?.trim().replace(/[\\/]+$/,"");if(!s)return e;let a=new RegExp(le(s).replace(/[\\/]+/g,"[\\\\/]"),process.platform==="win32"?"gi":"g");return l(e,a,r,n,i,o)}function le(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function fe(e){return e.replace(/[^A-Za-z0-9_-]/g,"_")}import{createHash as C,createPrivateKey as ge,createPublicKey as O,generateKeyPairSync as pe,randomBytes as he,randomUUID as _,sign as me,timingSafeEqual as ye,verify as Se}from"node:crypto";function p(e){return JSON.stringify(R(e,new Set))}function R(e,t){if(e===null||typeof e!="object"){if(typeof e=="number"&&!Number.isFinite(e))throw new TypeError("Artifact JSON cannot contain non-finite numbers");return e}if(t.has(e))throw new TypeError("Artifact JSON cannot contain cycles");if(t.add(e),Array.isArray(e)){let n=e.map(i=>R(i,t));return t.delete(e),n}let r={};for(let n of Object.keys(e).sort((i,o)=>i.localeCompare(o))){let i=e[n];if(i===void 0)throw new TypeError(`Artifact JSON property ${n} is undefined`);r[n]=R(i,t)}return t.delete(e),r}function h(e,t={}){for(let r of e){let n=r.codePointAt(0);if(n===127)return!0;if(!(n>31)&&!(n===9&&t.allowTab===!0)&&!((n===10||n===13)&&t.allowLineBreaks===!0))return!0}return!1}var we=10080*60*1e3,Ie=365*24*60*60*1e3;function ot(){let{publicKey:e,privateKey:t}=pe("ed25519"),r=e.export({type:"spki",format:"pem"}).toString(),n=t.export({type:"pkcs8",format:"pem"}).toString();return{keyId:N(r),publicKeyPem:r,privateKeyPem:n}}function N(e){let t=O(e).export({type:"spki",format:"der"});return`ed25519:${C("sha256").update(t).digest("hex").slice(0,32)}`}function st(e){let t=e.now??new Date,r=t.toISOString(),n=L(t,e.expiresAt,e.ttlMs),i=he(32).toString("base64url"),o=T(e.content,e.redaction),s=e.visibility??"private";ve(s,e.workspaceId,e.teamId,e.allowedPrincipalIds);let a={schemaVersion:2,kind:"xeno-secure-share",shareId:d(e.shareId??`share_${_()}`,"shareId"),createdAt:r,expiresAt:n,issuer:D(e.issuer),session:$({...e.session,name:e.session.name??e.name}),access:{mode:"read-only",visibility:s,...e.workspaceId?{workspaceId:d(e.workspaceId,"workspaceId")}:{},...e.teamId?{teamId:d(e.teamId,"teamId")}:{},...e.allowedPrincipalIds?.length?{allowedPrincipalIds:S(e.allowedPrincipalIds,"allowedPrincipalIds")}:{},capabilityToken:{algorithm:"sha256",hash:B(i)}},content:o.value,references:F(e.references??[]),redaction:o.report};return{envelope:xe(a,e.signingIdentity),capabilityToken:i,url:be(e.baseUrl,a.shareId,i)}}function xe(e,t){if(t.keyId!==N(t.publicKeyPem))throw new Error("Signing identity keyId does not match public key");let r=V(e,t);return{payload:e,signature:r}}function at(e,t={}){let r=[],n=!1,i=!1;if(e?.payload?.kind!=="xeno-secure-share"||e.payload.schemaVersion!==2)r.push("Unsupported secure-share envelope");else{let A=J(t.trustedPublicKeys,e.signature.keyId),v=A??(t.allowEmbeddedPublicKey===!1?void 0:e.signature.publicKeySpki);if(i=!!A,!v)r.push("No trusted or embedded issuer public key is available");else try{n=H(e.payload,e.signature,v),n||r.push("Share signature is invalid")}catch(x){r.push(x instanceof Error?x.message:String(x))}}let o=(t.now??new Date).getTime(),s=Date.parse(e?.payload?.expiresAt??""),c=t.revokedShareIds?.has(e?.payload?.shareId??"")??!1?"revoked":Number.isFinite(s)&&s<=o?"expired":"active";c==="revoked"&&r.push("Share has been revoked"),c==="expired"&&r.push("Share has expired");let g=Ee(e?.payload,t.capabilityToken);g||r.push("Capability token is missing or invalid");let I=Xe(e?.payload,t.principal);return I||r.push("Principal is outside the share audience"),{valid:n&&g&&I&&c==="active",integrityValid:n,issuerTrusted:i,capabilityValid:g,audienceAllowed:I,status:c,errors:r}}function ct(e){let t=e.now??new Date,r={schemaVersion:1,kind:"xeno-session-handoff",handoffId:d(e.handoffId??`handoff_${_()}`,"handoffId"),createdAt:t.toISOString(),expiresAt:L(t,e.expiresAt,e.ttlMs??1440*60*1e3),issuer:D(e.issuer),source:$(e.source),target:Re(e.target),resume:ke(e.resume),authority:Ae(e.authority),references:F(e.references??[]),...e.shareId?{shareId:d(e.shareId,"shareId")}:{}};return{payload:r,signature:V(r,e.signingIdentity)}}function dt(e,t={}){let r=[];if(e?.payload?.kind!=="xeno-session-handoff"||e.payload.schemaVersion!==1)return{valid:!1,integrityValid:!1,issuerTrusted:!1,expired:!1,errors:["Unsupported handoff envelope"]};let n=J(t.trustedPublicKeys,e.signature.keyId),i=n??(t.allowEmbeddedPublicKey===!1?void 0:e.signature.publicKeySpki),o=!!n,s=!1;if(!i)r.push("No trusted or embedded issuer public key is available");else try{s=H(e.payload,e.signature,i),s||r.push("Handoff signature is invalid")}catch(c){r.push(c instanceof Error?c.message:String(c))}let a=Date.parse(e.payload.expiresAt)<=(t.now??new Date).getTime();return a&&r.push("Handoff has expired"),{valid:s&&!a,integrityValid:s,issuerTrusted:o,expired:a,errors:r}}function V(e,t){let r=p(e),n=me(null,Buffer.from(r),ge(t.privateKeyPem)).toString("base64");return{algorithm:"ed25519",keyId:t.keyId,value:n,publicKeySpki:t.publicKeyPem}}function H(e,t,r){if(t.algorithm!=="ed25519")return!1;let n=Buffer.from(t.value,"base64");if(n.toString("base64")!==t.value)throw new Error("Signature is not canonical base64");return Se(null,Buffer.from(p(e)),O(r),n)}function Ee(e,t){if(!e||!t)return!1;let r=Buffer.from(e.access.capabilityToken.hash,"hex"),n=Buffer.from(B(t),"hex");return r.length===n.length&&ye(r,n)}function Xe(e,t){if(!e)return!1;let r=e.access;return r.allowedPrincipalIds?.length&&(!t?.id||!r.allowedPrincipalIds.includes(t.id))?!1:r.visibility==="workspace"?!!(t?.workspaceId&&t.workspaceId===r.workspaceId):r.visibility==="team"?!!(r.teamId&&t?.teamIds?.includes(r.teamId)):r.visibility==="private"?!!(t?.id&&t.id===e.issuer.id):r.visibility==="link"}function be(e,t,r){let n=new URL(e??"xeno://share/");if(n.username||n.password)throw new Error("Share base URL cannot contain credentials");if(n.protocol!=="https:"&&n.protocol!=="xeno:")throw new Error("Share base URL must use https: or xeno:");return n.pathname=`${n.pathname.replace(/\/$/,"")}/${encodeURIComponent(t)}`,n.search="",n.hash=new URLSearchParams({access_token:r}).toString(),n.toString()}function L(e,t,r=we){let n=t?new Date(t):new Date(e.getTime()+r);if(!Number.isFinite(n.getTime()))throw new Error("expiresAt must be a valid timestamp");let i=n.getTime()-e.getTime();if(i<=0)throw new Error("expiresAt must be in the future");if(i>Ie)throw new Error("Share and handoff expiry cannot exceed 365 days");return n.toISOString()}function D(e){return{id:d(e.id,"issuer.id"),...e.displayName?.trim()?{displayName:e.displayName.trim().slice(0,160)}:{},...e.workspaceId?{workspaceId:d(e.workspaceId,"issuer.workspaceId")}:{},...e.teamId?{teamId:d(e.teamId,"issuer.teamId")}:{}}}function $(e){let t={name:y(e.name,"session.name",200),surface:e.surface};for(let r of["sessionId","runId","hostedRunId","conversationId","parentSessionId","forkedFromSessionId","forkedAtEventId"])e[r]&&(t[r]=d(e[r],`session.${r}`));if(!t.sessionId&&!t.runId&&!t.hostedRunId&&!t.conversationId)throw new Error("Session identity requires sessionId, runId, hostedRunId, or conversationId");return e.git&&(t.git={...e.git.repositoryId?{repositoryId:d(e.git.repositoryId,"git.repositoryId")}:{},...e.git.remoteUrl?{remoteUrl:k(e.git.remoteUrl,"git.remoteUrl")}:{},...e.git.branch?{branch:y(e.git.branch,"git.branch",300)}:{},...e.git.commit?{commit:K(e.git.commit,"git.commit")}:{},...e.git.pullRequest?{pullRequest:{provider:e.git.pullRequest.provider,repository:y(e.git.pullRequest.repository,"git.pullRequest.repository",300),number:Pe(e.git.pullRequest.number,"git.pullRequest.number"),...e.git.pullRequest.url?{url:k(e.git.pullRequest.url,"git.pullRequest.url")}:{}}}:{}}),t}function F(e){let t=new Set;return e.map(r=>{let n=`${r.kind}:${r.id}`;if(t.has(n))throw new Error(`Duplicate share reference: ${n}`);return t.add(n),{kind:r.kind,id:d(r.id,"reference.id"),...r.title?.trim()?{title:r.title.trim().slice(0,300)}:{},...r.uri?{uri:k(r.uri,"reference.uri")}:{},...r.hash?{hash:K(r.hash,"reference.hash")}:{}}})}function Re(e){return{surface:e.surface,...e.workspaceId?{workspaceId:d(e.workspaceId,"target.workspaceId")}:{},...e.teamId?{teamId:d(e.teamId,"target.teamId")}:{},...e.environmentId?{environmentId:d(e.environmentId,"target.environmentId")}:{},...e.repositoryId?{repositoryId:d(e.repositoryId,"target.repositoryId")}:{}}}function ke(e){let t={};for(let r of["sessionId","runId","hostedRunId","checkpointId","transcriptEventId"])e[r]&&(t[r]=d(e[r],`resume.${r}`));if(e.artifactIds?.length&&(t.artifactIds=S(e.artifactIds,"resume.artifactIds")),e.taskIds?.length&&(t.taskIds=S(e.taskIds,"resume.taskIds")),!Object.keys(t).length)throw new Error("Handoff resume point cannot be empty");return t}function Ae(e){return{filesystem:e.filesystem,network:e.network,externalActions:e.externalActions,secretRefs:S(e.secretRefs,"authority.secretRefs")}}function ve(e,t,r,n){if(e==="workspace"&&!t)throw new Error("workspace visibility requires workspaceId");if(e==="team"&&!r)throw new Error("team visibility requires teamId");if(e==="private"&&n?.length)throw new Error("private shares cannot add allowed principals; use link/workspace/team visibility")}function J(e,t){if(!e)return;let r=e;return typeof r.get=="function"?r.get(t):e[t]}function B(e){return C("sha256").update(e).digest("hex")}function S(e,t){return[...new Set(e.map(r=>d(r,t)))].sort()}function d(e,t){let r=e.trim();if(!r||r.length>500||h(r))throw new Error(`${t} is invalid`);return r}function K(e,t){let r=e.trim();if(!/^[A-Za-z0-9:+._-]{7,256}$/.test(r))throw new Error(`${t} is invalid`);return r}function y(e,t,r){let n=e.trim();if(!n||n.length>r||h(n,{allowTab:!0,allowLineBreaks:!0}))throw new Error(`${t} is invalid`);return n}function Pe(e,t){if(!Number.isSafeInteger(e)||e<=0)throw new Error(`${t} must be a positive integer`);return e}function k(e,t){let r=y(e,t,2e3),n=new URL(r);if(n.username||n.password)throw new Error(`${t} cannot contain credentials`);if(!["https:","xeno:","artifact:","urn:"].includes(n.protocol))throw new Error(`${t} uses an unsupported scheme`);return n.toString()}import{createHash as ee}from"node:crypto";import{chmod as Je,mkdir as te,open as Be,readFile as Ke,unlink as Me}from"node:fs/promises";import{dirname as je,join as Y,resolve as qe}from"node:path";import*as u from"node:fs/promises";var Te=new Set(["EACCES","EBUSY","EPERM"]),Ce=[10,20,40,80,160,320,640];async function M(e,t){for(let r=0;;r+=1)try{await u.rename(e,t);return}catch(n){let i=n.code,o=Ce[r];if(process.platform!=="win32"||!i||!Te.has(i)||o===void 0)throw n;await new Promise(s=>setTimeout(s,o))}}import{mkdirSync as Oe,readFileSync as _e,rmSync as q,writeFileSync as Ne}from"node:fs";import{hostname as z}from"node:os";import{dirname as Ve}from"node:path";function He(){return new Date().toISOString()}function Le(){return new Date(Date.now()-Math.floor(process.uptime()*1e3)).toISOString()}function U(e){try{return JSON.parse(_e(e,"utf8"))}catch{return null}}function De(e){if(!e||e<=0)return!1;try{return process.kill(e,0),!0}catch{return!1}}function $e(e){return e.hostname!==z()?!0:De(e.pid)}function j(e,t){Oe(Ve(e),{recursive:!0}),Ne(e,JSON.stringify(t,null,2)+`
|
|
3
|
+
`,{encoding:"utf8",flag:"wx"})}function Fe(e,t){let r=U(e);r?.pid!==t.pid||r.hostname!==t.hostname||q(e,{force:!0})}function Z(e,t,r){let n=He(),i={schemaVersion:1,name:t,pid:process.pid,hostname:z(),processStartedAt:Le(),version:r,acquiredAt:n,updatedAt:n};try{j(e,i)}catch(o){if(o.code!=="EEXIST")throw o;let a=U(e);if(a&&$e(a))throw new Error(`${t} is already locked by PID ${a.pid} on ${a.hostname}.`);q(e,{force:!0}),j(e,i)}return{record:i,release:()=>{Fe(e,i)}}}var W=class{directory;snapshotPath;lockPath;now;constructor(t){this.directory=qe(t.directory),this.snapshotPath=Y(this.directory,"registry.json"),this.lockPath=Y(this.directory,"registry.lock"),this.now=t.now??(()=>new Date)}async register(t,r="created"){return this.mutate(n=>{let i=n.records.find(s=>s.shareId===t.payload.shareId);if(i){if(w(i.envelope)!==w(t))throw new Error(`Share ${t.payload.shareId} already exists with different content`);return{snapshot:n,result:i}}let o={shareId:t.payload.shareId,envelope:t,status:Date.parse(t.payload.expiresAt)<=this.now().getTime()?"expired":"active",registeredAt:this.now().toISOString(),origin:r};return{snapshot:G(n,[...n.records,o],this.now()),result:o}})}async revoke(t,r,n){return this.mutate(i=>{let o=i.records.findIndex(g=>g.shareId===t);if(o<0)throw new Error(`Share not found: ${t}`);let s=i.records[o];if(s.status==="revoked")return{snapshot:i,result:s};let a={...s,status:"revoked",revokedAt:this.now().toISOString(),revokedBy:Q(r,"actor"),revocationReason:Q(n,"reason")},c=[...i.records];return c[o]=a,{snapshot:G(i,c,this.now()),result:a}})}async get(t){return(await this.load()).records.find(r=>r.shareId===t)??null}async list(){let t=this.now().getTime();return(await this.load()).records.map(r=>r.status==="active"&&Date.parse(r.envelope.payload.expiresAt)<=t?{...r,status:"expired"}:r).sort((r,n)=>n.registeredAt.localeCompare(r.registeredAt))}async revokedIds(){return new Set((await this.list()).filter(t=>t.status==="revoked").map(t=>t.shareId))}async load(){try{let t=await Ke(this.snapshotPath,"utf8"),r=JSON.parse(t);return Ue(r),r}catch(t){if(t.code==="ENOENT")return ze(this.now());throw t}}async mutate(t){await te(this.directory,{recursive:!0,mode:448});let r=Z(this.lockPath,"xeno secure-share registry","1");try{let n=await this.load(),{snapshot:i,result:o}=t(n);return i!==n&&await Ze(this.snapshotPath,`${JSON.stringify(i,null,2)}
|
|
4
|
+
`),o}finally{r.release()}}};function ze(e){return re({schemaVersion:1,generation:0,updatedAt:e.toISOString(),records:[]})}function G(e,t,r){return re({schemaVersion:1,generation:e.generation+1,updatedAt:r.toISOString(),records:[...t].sort((n,i)=>n.shareId.localeCompare(i.shareId))})}function re(e){return{...e,checksum:{algorithm:"sha256",value:ee("sha256").update(w(e)).digest("hex")}}}function Ue(e){if(e.schemaVersion!==1||!Array.isArray(e.records))throw new Error("Invalid secure-share registry snapshot");let{checksum:t,...r}=e,n=ee("sha256").update(w(r)).digest("hex");if(t?.algorithm!=="sha256"||t.value!==n)throw new Error("Secure-share registry checksum mismatch");let i=new Set;for(let o of e.records){if(o.shareId!==o.envelope?.payload?.shareId)throw new Error("Secure-share registry identity mismatch");if(i.has(o.shareId))throw new Error(`Duplicate secure-share registry record: ${o.shareId}`);i.add(o.shareId)}}async function Ze(e,t){await te(je(e),{recursive:!0,mode:448});let r=`${e}.${process.pid}.${Date.now()}.tmp`,n;try{n=await Be(r,"wx",384),await n.writeFile(t,"utf8"),await n.sync(),await n.close(),n=void 0,await M(r,e),await Je(e,384).catch(()=>{})}finally{n&&await n.close().catch(()=>{}),await Me(r).catch(()=>{})}}function w(e){return p(e)}function Q(e,t){let r=e.trim();if(!r||r.length>500||h(r))throw new Error(`${t} is invalid`);return r}export{W as FileXenoShareRegistry,X as XENO_HANDOFF_SCHEMA_VERSION,m as XENO_SHARE_REGISTRY_SCHEMA_VERSION,E as XENO_SHARE_SCHEMA_VERSION,st as createXenoSecureShare,ct as createXenoSessionHandoff,ot as createXenoShareSigningIdentity,N as publicKeyFingerprint,T as redactXenoShareValue,xe as signSharePayload,at as verifyXenoSecureShare,dt as verifyXenoSessionHandoff};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"inputs":{"src/sharing/types.ts":{"bytes":5121,"imports":[],"format":"esm"},"src/sharing/redaction.ts":{"bytes":6716,"imports":[],"format":"esm"},"src/artifacts/hash.ts":{"bytes":1489,"imports":[{"path":"node:crypto","kind":"import-statement","external":true}],"format":"esm"},"src/utils/text-security.ts":{"bytes":809,"imports":[],"format":"esm"},"src/sharing/protocol.ts":{"bytes":19325,"imports":[{"path":"node:crypto","kind":"import-statement","external":true},{"path":"src/artifacts/hash.ts","kind":"import-statement","original":"../artifacts/hash.js"},{"path":"src/utils/text-security.ts","kind":"import-statement","original":"../utils/text-security.js"},{"path":"src/sharing/redaction.ts","kind":"import-statement","original":"./redaction.js"},{"path":"src/sharing/types.ts","kind":"import-statement","original":"./types.js"}],"format":"esm"},"src/control-plane/lock.ts":{"bytes":2496,"imports":[{"path":"node:fs","kind":"import-statement","external":true},{"path":"node:os","kind":"import-statement","external":true},{"path":"node:path","kind":"import-statement","external":true}],"format":"esm"},"src/sharing/file-registry.ts":{"bytes":
|
|
1
|
+
{"inputs":{"src/sharing/types.ts":{"bytes":5121,"imports":[],"format":"esm"},"src/sharing/redaction.ts":{"bytes":6716,"imports":[],"format":"esm"},"src/artifacts/hash.ts":{"bytes":1489,"imports":[{"path":"node:crypto","kind":"import-statement","external":true}],"format":"esm"},"src/utils/text-security.ts":{"bytes":809,"imports":[],"format":"esm"},"src/sharing/protocol.ts":{"bytes":19325,"imports":[{"path":"node:crypto","kind":"import-statement","external":true},{"path":"src/artifacts/hash.ts","kind":"import-statement","original":"../artifacts/hash.js"},{"path":"src/utils/text-security.ts","kind":"import-statement","original":"../utils/text-security.js"},{"path":"src/sharing/redaction.ts","kind":"import-statement","original":"./redaction.js"},{"path":"src/sharing/types.ts","kind":"import-statement","original":"./types.js"}],"format":"esm"},"src/utils/fs.ts":{"bytes":11685,"imports":[{"path":"node:fs","kind":"import-statement","external":true},{"path":"node:fs","kind":"import-statement","external":true},{"path":"node:fs/promises","kind":"import-statement","external":true},{"path":"node:path","kind":"import-statement","external":true}],"format":"esm"},"src/control-plane/lock.ts":{"bytes":2496,"imports":[{"path":"node:fs","kind":"import-statement","external":true},{"path":"node:os","kind":"import-statement","external":true},{"path":"node:path","kind":"import-statement","external":true}],"format":"esm"},"src/sharing/file-registry.ts":{"bytes":7359,"imports":[{"path":"node:crypto","kind":"import-statement","external":true},{"path":"node:fs/promises","kind":"import-statement","external":true},{"path":"node:path","kind":"import-statement","external":true},{"path":"src/utils/fs.ts","kind":"import-statement","original":"../utils/fs.js"},{"path":"src/artifacts/hash.ts","kind":"import-statement","original":"../artifacts/hash.js"},{"path":"src/control-plane/lock.ts","kind":"import-statement","original":"../control-plane/lock.js"},{"path":"src/utils/text-security.ts","kind":"import-statement","original":"../utils/text-security.js"},{"path":"src/sharing/types.ts","kind":"import-statement","original":"./types.js"}],"format":"esm"},"src/sharing/index.ts":{"bytes":127,"imports":[{"path":"src/sharing/types.ts","kind":"import-statement","original":"./types.js"},{"path":"src/sharing/redaction.ts","kind":"import-statement","original":"./redaction.js"},{"path":"src/sharing/protocol.ts","kind":"import-statement","original":"./protocol.js"},{"path":"src/sharing/file-registry.ts","kind":"import-statement","original":"./file-registry.js"}],"format":"esm"}},"outputs":{"dist/sharing/index.cjs":{"imports":[{"path":"node:crypto","kind":"require-call","external":true},{"path":"node:crypto","kind":"require-call","external":true},{"path":"node:fs/promises","kind":"require-call","external":true},{"path":"node:path","kind":"require-call","external":true},{"path":"node:fs/promises","kind":"require-call","external":true},{"path":"node:fs","kind":"require-call","external":true},{"path":"node:os","kind":"require-call","external":true},{"path":"node:path","kind":"require-call","external":true}],"exports":[],"entryPoint":"src/sharing/index.ts","inputs":{"src/sharing/index.ts":{"bytesInOutput":413},"src/sharing/types.ts":{"bytesInOutput":16},"src/sharing/redaction.ts":{"bytesInOutput":3216},"src/sharing/protocol.ts":{"bytesInOutput":9109},"src/artifacts/hash.ts":{"bytesInOutput":559},"src/utils/text-security.ts":{"bytesInOutput":179},"src/sharing/file-registry.ts":{"bytesInOutput":3490},"src/utils/fs.ts":{"bytesInOutput":318},"src/control-plane/lock.ts":{"bytesInOutput":1059}},"bytes":19260}}}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"inputs":{"src/sharing/types.ts":{"bytes":5121,"imports":[],"format":"esm"},"src/sharing/redaction.ts":{"bytes":6716,"imports":[],"format":"esm"},"src/artifacts/hash.ts":{"bytes":1489,"imports":[{"path":"node:crypto","kind":"import-statement","external":true}],"format":"esm"},"src/utils/text-security.ts":{"bytes":809,"imports":[],"format":"esm"},"src/sharing/protocol.ts":{"bytes":19325,"imports":[{"path":"node:crypto","kind":"import-statement","external":true},{"path":"src/artifacts/hash.ts","kind":"import-statement","original":"../artifacts/hash.js"},{"path":"src/utils/text-security.ts","kind":"import-statement","original":"../utils/text-security.js"},{"path":"src/sharing/redaction.ts","kind":"import-statement","original":"./redaction.js"},{"path":"src/sharing/types.ts","kind":"import-statement","original":"./types.js"}],"format":"esm"},"src/control-plane/lock.ts":{"bytes":2496,"imports":[{"path":"node:fs","kind":"import-statement","external":true},{"path":"node:os","kind":"import-statement","external":true},{"path":"node:path","kind":"import-statement","external":true}],"format":"esm"},"src/sharing/file-registry.ts":{"bytes":
|
|
1
|
+
{"inputs":{"src/sharing/types.ts":{"bytes":5121,"imports":[],"format":"esm"},"src/sharing/redaction.ts":{"bytes":6716,"imports":[],"format":"esm"},"src/artifacts/hash.ts":{"bytes":1489,"imports":[{"path":"node:crypto","kind":"import-statement","external":true}],"format":"esm"},"src/utils/text-security.ts":{"bytes":809,"imports":[],"format":"esm"},"src/sharing/protocol.ts":{"bytes":19325,"imports":[{"path":"node:crypto","kind":"import-statement","external":true},{"path":"src/artifacts/hash.ts","kind":"import-statement","original":"../artifacts/hash.js"},{"path":"src/utils/text-security.ts","kind":"import-statement","original":"../utils/text-security.js"},{"path":"src/sharing/redaction.ts","kind":"import-statement","original":"./redaction.js"},{"path":"src/sharing/types.ts","kind":"import-statement","original":"./types.js"}],"format":"esm"},"src/utils/fs.ts":{"bytes":11685,"imports":[{"path":"node:fs","kind":"import-statement","external":true},{"path":"node:fs","kind":"import-statement","external":true},{"path":"node:fs/promises","kind":"import-statement","external":true},{"path":"node:path","kind":"import-statement","external":true}],"format":"esm"},"src/control-plane/lock.ts":{"bytes":2496,"imports":[{"path":"node:fs","kind":"import-statement","external":true},{"path":"node:os","kind":"import-statement","external":true},{"path":"node:path","kind":"import-statement","external":true}],"format":"esm"},"src/sharing/file-registry.ts":{"bytes":7359,"imports":[{"path":"node:crypto","kind":"import-statement","external":true},{"path":"node:fs/promises","kind":"import-statement","external":true},{"path":"node:path","kind":"import-statement","external":true},{"path":"src/utils/fs.ts","kind":"import-statement","original":"../utils/fs.js"},{"path":"src/artifacts/hash.ts","kind":"import-statement","original":"../artifacts/hash.js"},{"path":"src/control-plane/lock.ts","kind":"import-statement","original":"../control-plane/lock.js"},{"path":"src/utils/text-security.ts","kind":"import-statement","original":"../utils/text-security.js"},{"path":"src/sharing/types.ts","kind":"import-statement","original":"./types.js"}],"format":"esm"},"src/sharing/index.ts":{"bytes":127,"imports":[{"path":"src/sharing/types.ts","kind":"import-statement","original":"./types.js"},{"path":"src/sharing/redaction.ts","kind":"import-statement","original":"./redaction.js"},{"path":"src/sharing/protocol.ts","kind":"import-statement","original":"./protocol.js"},{"path":"src/sharing/file-registry.ts","kind":"import-statement","original":"./file-registry.js"}],"format":"esm"}},"outputs":{"dist/sharing/index.js":{"imports":[{"path":"node:crypto","kind":"import-statement","external":true},{"path":"node:crypto","kind":"import-statement","external":true},{"path":"node:fs/promises","kind":"import-statement","external":true},{"path":"node:path","kind":"import-statement","external":true},{"path":"node:fs/promises","kind":"import-statement","external":true},{"path":"node:fs","kind":"import-statement","external":true},{"path":"node:os","kind":"import-statement","external":true},{"path":"node:path","kind":"import-statement","external":true}],"exports":["FileXenoShareRegistry","XENO_HANDOFF_SCHEMA_VERSION","XENO_SHARE_REGISTRY_SCHEMA_VERSION","XENO_SHARE_SCHEMA_VERSION","createXenoSecureShare","createXenoSessionHandoff","createXenoShareSigningIdentity","publicKeyFingerprint","redactXenoShareValue","signSharePayload","verifyXenoSecureShare","verifyXenoSessionHandoff"],"entryPoint":"src/sharing/index.ts","inputs":{"src/sharing/types.ts":{"bytesInOutput":16},"src/sharing/index.ts":{"bytesInOutput":0},"src/sharing/redaction.ts":{"bytesInOutput":3216},"src/sharing/protocol.ts":{"bytesInOutput":9080},"src/artifacts/hash.ts":{"bytesInOutput":559},"src/utils/text-security.ts":{"bytesInOutput":179},"src/sharing/file-registry.ts":{"bytesInOutput":3478},"src/utils/fs.ts":{"bytesInOutput":313},"src/control-plane/lock.ts":{"bytesInOutput":1041}},"bytes":18252}}}
|
package/dist/ui/index.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";var X=Object.defineProperty;var Z=Object.getOwnPropertyDescriptor;var ee=Object.getOwnPropertyNames;var te=Object.prototype.hasOwnProperty;var ne=(n,e)=>{for(var r in e)X(n,r,{get:e[r],enumerable:!0})},oe=(n,e,r,t)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of ee(e))!te.call(n,i)&&i!==r&&X(n,i,{get:()=>e[i],enumerable:!(t=Z(e,i))||t.enumerable});return n};var re=n=>oe(X({},"__esModule",{value:!0}),n);var ye={};ne(ye,{XENO_UI_RENDERER_API_VERSION:()=>I,createAgentUiController:()=>B,createAgentUiView:()=>z,dispatchAgentUiAction:()=>S,isSafeMarkdownHref:()=>q,mountAgentUi:()=>Y,parseMarkdown:()=>D,xenoUiCss:()=>H,xenoUiTokens:()=>K});module.exports=re(ye);var ie={View:"Read",Replace:"Write",GlobTool:"Glob",GrepTool:"Grep",SQLiteAnalyze:"SqliteAnalyze",ReadNotebook:"NotebookRead",NotebookEditCell:"NotebookEdit",CoordinationSend:"Send",CoordinationQuery:"Receive"};function se(n){return ie[n]??n}var ae=new Set(["Read","Glob","Grep","LS","Think","dispatch_agent","ElfAnalyze","Receive","ListAgents","ListSessions","CoordinationQuery"]),le=new Set(["Write","Edit","Send","CoordinationSend"]),ce=new Set(["Bash"]);function G(n){let e=se(n);return ce.has(e)?"high":ae.has(e)?"low":(le.has(e),"medium")}var I=1;function de(n){let e=n.config;return e&&typeof e=="object"?e:null}function F(n){let e=n.tokenUsage;return{input:Number(e.input)||0,output:Number(e.output)||0,total:Number(e.total)||0}}function ue(n){let e=n.toLowerCase();return["rate limit","429","network","timeout","econnrefused","api error","unreachable"].some(r=>e.includes(r))}function B(n){let e=n.agent,r=n.now??Date.now,t=0,i=n.createId??(()=>`xeno-ui-${r()}-${++t}`),m=new Set,g=[],h="idle",
|
|
1
|
+
"use strict";var X=Object.defineProperty;var Z=Object.getOwnPropertyDescriptor;var ee=Object.getOwnPropertyNames;var te=Object.prototype.hasOwnProperty;var ne=(n,e)=>{for(var r in e)X(n,r,{get:e[r],enumerable:!0})},oe=(n,e,r,t)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of ee(e))!te.call(n,i)&&i!==r&&X(n,i,{get:()=>e[i],enumerable:!(t=Z(e,i))||t.enumerable});return n};var re=n=>oe(X({},"__esModule",{value:!0}),n);var ye={};ne(ye,{XENO_UI_RENDERER_API_VERSION:()=>I,createAgentUiController:()=>B,createAgentUiView:()=>z,dispatchAgentUiAction:()=>S,isSafeMarkdownHref:()=>q,mountAgentUi:()=>Y,parseMarkdown:()=>D,xenoUiCss:()=>H,xenoUiTokens:()=>K});module.exports=re(ye);var ie={View:"Read",Replace:"Write",GlobTool:"Glob",GrepTool:"Grep",SQLiteAnalyze:"SqliteAnalyze",ReadNotebook:"NotebookRead",NotebookEditCell:"NotebookEdit",CoordinationSend:"Send",CoordinationQuery:"Receive"};function se(n){return ie[n]??n}var ae=new Set(["Read","Glob","Grep","LS","MemoryRead","Think","dispatch_agent","ElfAnalyze","Receive","ListAgents","ListSessions","CoordinationQuery"]),le=new Set(["Write","Edit","MemoryWrite","Send","CoordinationSend"]),ce=new Set(["Bash"]);function G(n){let e=se(n);return ce.has(e)?"high":ae.has(e)?"low":(le.has(e),"medium")}var I=1;function de(n){let e=n.config;return e&&typeof e=="object"?e:null}function F(n){let e=n.tokenUsage;return{input:Number(e.input)||0,output:Number(e.output)||0,total:Number(e.total)||0}}function ue(n){let e=n.toLowerCase();return["rate limit","429","network","timeout","econnrefused","api error","unreachable"].some(r=>e.includes(r))}function B(n){let e=n.agent,r=n.now??Date.now,t=0,i=n.createId??(()=>`xeno-ui-${r()}-${++t}`),m=new Set,g=[],h="idle",R=F(e),_=null,d=null,k=null,v=null,c="",U=null,N=0,E=!1,b=!1,O=0,p=de(e),w=p?.permissionEngine,$=w?.promptFn;function T(){return Object.freeze({apiVersion:1,revision:O,items:Object.freeze([...g]),isProcessing:E,status:h,tokenUsage:Object.freeze({...R}),permissionRequest:_?Object.freeze({..._}):null,lastUserMessage:k})}function y(){O+=1;let s=T();for(let l of[...m])l(s)}function P(s){g=[...g,s],y()}function V(s){let l=[...g];for(let x=l.length-1;x>=0;x-=1){let a=l[x];if(a?.type==="message"&&a.data.role==="assistant"){l[x]={type:"message",data:s(a.data)},g=l,y();return}}}function j(s,l){let x=[...g];for(let a=x.length-1;a>=0;a-=1){let u=x[a];if(u?.type==="tool_call"&&u.data.id===s){x[a]={type:"tool_call",data:l(u.data)},g=x,y();return}}}function o(){v&&(V(s=>({...s,isStreaming:!1})),v=null,c="")}function C(s){let l={id:i(),message:s,retryable:ue(s),timestamp:r()};P({type:"error",data:l})}function f(s){p&&(p.onText=s.onText,p.onToolStart=s.onToolStart,p.onToolEnd=s.onToolEnd,p.onError=s.onError)}async function L(s){let l=s.trim();if(b||E||!l)return!1;E=!0,k=l,h="thinking",v=null,c="";let x={id:i(),role:"user",content:l,timestamp:r()};g=[...g,{type:"message",data:x}],y();let a={onText:p?.onText,onToolStart:p?.onToolStart,onToolEnd:p?.onToolEnd,onError:p?.onError};p&&(p.onText=u=>{a.onText?.(u),!b&&(c+=u,v?V(A=>({...A,content:c,isStreaming:!0})):(v=i(),P({type:"message",data:{id:v,role:"assistant",content:c,timestamp:r(),isStreaming:!0}})))},p.onToolStart=(u,A)=>{a.onToolStart?.(u,A),!b&&(o(),h="executing",U=i(),N=r(),P({type:"tool_call",data:{id:U,toolName:u,input:A,status:"running",timestamp:r()}}))},p.onToolEnd=(u,A)=>{a.onToolEnd?.(u,A),!b&&(U&&(j(U,J=>({...J,status:A.success?"success":"error",result:A,durationMs:Math.max(0,r()-N)})),U=null),h="thinking",y())},p.onError=(u,A)=>a.onError?.(u,A));try{await e.run(l),b||(o(),h="idle",R=F(e),y())}catch(u){if(!b){o();let A=u instanceof Error?u:new Error(String(u));h=A.name==="AgentInterruptedError"?"idle":"error",A.name!=="AgentInterruptedError"&&C(A.message),R=F(e),y()}}finally{E=!1,f(a),b||y()}return!0}return n.enablePermissionRequests&&w&&(w.promptFn=s=>(d&&d("deny"),new Promise(l=>{d=l,_={id:i(),toolName:s.toolName,detail:s.detail,description:s.description,operation:s.operation,preview:s.preview,riskLevel:G(s.toolName),timestamp:r()},y()}))),{apiVersion:1,getSnapshot:T,subscribe(s){if(b)throw new Error("Agent UI controller is disposed");return m.add(s),s(T()),()=>m.delete(s)},sendMessage:L,cancelExecution(){!b&&E&&e.cancelCurrentTurn()},clearMessages(){b||(g=[],v=null,c="",y())},retryLastMessage(){return b||E||!k?Promise.resolve(!1):(g=g.filter((s,l,x)=>s.type!=="error"?!0:x.slice(l+1).some(a=>a.type!=="error")),h="idle",y(),L(k))},resolvePermission(s,l){if(b||!_||_.id!==s||!d)return!1;let x=d;return d=null,_=null,y(),x(l),!0},dispose(){b||(b=!0,d&&d("deny"),d=null,_=null,w&&(w.promptFn=$),m.clear())}}}function me(n){let e=[],r=[[/```([\w-]*)\n([\s\S]*?)```/,t=>({kind:"code-block",language:t[1]??"",code:t[2]??""})],[/`([^`\n]+)`/,t=>({kind:"inline-code",code:t[1]??""})],[/\*\*(.+?)\*\*/,t=>({kind:"strong",text:t[1]??""})],[/\*([^*\n]+)\*/,t=>({kind:"emphasis",text:t[1]??""})],[/\[([^\]]+)\]\(([^)\s]+)\)/,t=>({kind:"link",text:t[1]??"",href:t[2]??""})]];for(let[t,i]of r){let m=n.match(t);m?.index!==void 0&&e.push({index:m.index,value:i(m),length:m[0].length})}return e.sort((t,i)=>t.index-i.index),e[0]??null}function D(n){let e=[],r=n;for(;r;){let t=me(r);if(!t){e.push({kind:"text",text:r});break}t.index>0&&e.push({kind:"text",text:r.slice(0,t.index)}),e.push(t.value),r=r.slice(t.index+t.length)}return e}function q(n){try{let e=new URL(n,"https://xeno.invalid/");return e.protocol==="https:"||e.protocol==="http:"||e.protocol==="mailto:"}catch{return!1}}var K=Object.freeze({background:"#101214",surface:"#181b1f",surfaceRaised:"#20242a",border:"#343a42",text:"#f2f4f7",textMuted:"#aab2bd",accent:"#5da9e9",success:"#56b881",warning:"#e7b65a",danger:"#e57373",focus:"#8bc5f4"}),H=`
|
|
2
2
|
.xeno-ui{box-sizing:border-box;display:grid;grid-template-rows:auto minmax(12rem,1fr) auto;width:min(32rem,100%);height:min(44rem,100%);min-height:24rem;border:1px solid var(--xeno-border,#343a42);background:var(--xeno-bg,#101214);color:var(--xeno-text,#f2f4f7);font:14px/1.45 ui-sans-serif,system-ui,-apple-system,"Segoe UI",sans-serif;letter-spacing:0}
|
|
3
3
|
.xeno-ui *{box-sizing:border-box;letter-spacing:0}
|
|
4
4
|
.xeno-ui__header{display:flex;align-items:center;gap:.75rem;padding:.75rem 1rem;border-bottom:1px solid var(--xeno-border,#343a42);background:var(--xeno-surface,#181b1f)}
|
|
@@ -32,4 +32,4 @@
|
|
|
32
32
|
@media (max-width:36rem){.xeno-ui{width:100%;height:100%;border-left:0;border-right:0}.xeno-ui__entry--user,.xeno-ui__entry--assistant{margin-left:0;margin-right:0}.xeno-ui__composer{grid-template-columns:1fr}.xeno-ui__controls{justify-content:flex-end}}
|
|
33
33
|
@media (prefers-reduced-motion:reduce){.xeno-ui *{scroll-behavior:auto!important;transition:none!important}}
|
|
34
34
|
`;var Q=64*1024;function pe(n){let e;try{e=JSON.stringify(n,null,2)??String(n)}catch{e="[Unserializable value]"}return e.length<=Q?e:`${e.slice(0,Q)}
|
|
35
|
-
[truncated]`}function ge(n){if(n.type==="message"){let e=n.data.role==="assistant";return{key:n.data.id,kind:e?"assistant-message":"user-message",role:"article",accessibleName:e?"Assistant message":"Your message",text:n.data.content,streaming:n.data.isStreaming}}if(n.type==="tool_call"){let e=n.data.durationMs===void 0?"":` in ${n.data.durationMs} ms`;return{key:n.data.id,kind:"tool-call",role:"status",accessibleName:`${n.data.toolName} tool ${n.data.status}`,text:`${n.data.toolName}: ${n.data.status}${e}`,detail:pe({input:n.data.input,result:n.data.result}),state:n.data.status}}return{key:n.data.id,kind:"error",role:"alert",accessibleName:"Agent error",text:n.data.message,retryable:n.data.retryable}}function z(n,e={}){let r=e.agentName?.trim()||"Xeno Agent",t=n.permissionRequest;return{apiVersion:1,revision:n.revision,region:{role:"region",accessibleName:e.regionLabel?.trim()||`${r} chat`},header:{title:r,statusRole:"status",statusText:n.status,tokenText:`${n.tokenUsage.total.toLocaleString()} tokens`},timeline:{role:"log",live:"polite",busy:n.isProcessing,entries:n.items.map(ge)},permission:t?{role:"alertdialog",accessibleName:`Permission required for ${t.toolName}`,description:t.description||t.detail,riskLevel:t.riskLevel,requestId:t.id,controls:[{label:"Allow once",decision:"allow"},{label:"Always allow",decision:"always"},{label:"Deny",decision:"deny"}]}:null,composer:{role:"form",inputLabel:e.inputLabel?.trim()||"Message Xeno Agent",placeholder:e.inputPlaceholder?.trim()||"Message or command...",disabled:n.isProcessing,sendLabel:"Send",cancelLabel:"Cancel"}}}async function S(n,e){switch(e.type){case"send":return n.sendMessage(e.text);case"cancel":return n.cancelExecution(),!0;case"clear":return n.clearMessages(),!0;case"retry":return n.retryLastMessage();case"permission":return n.resolvePermission(e.requestId,e.decision)}}var W="xeno-owned-agent-ui-v1";function fe(n,e,r){for(let t of D(r)){if(t.kind==="text"){e.append(n.createTextNode(t.text));continue}if(t.kind==="code-block"){let i=n.createElement("pre"),m=n.createElement("code");t.language&&(m.dataset.language=t.language),m.textContent=t.code,i.append(m),e.append(i);continue}if(t.kind==="inline-code"){let i=n.createElement("code");i.textContent=t.code,e.append(i);continue}if(t.kind==="strong"||t.kind==="emphasis"){let i=n.createElement(t.kind==="strong"?"strong":"em");i.textContent=t.text,e.append(i);continue}if(t.kind==="link"){if(!q(t.href)){e.append(n.createTextNode(t.text));continue}let i=n.createElement("a");i.textContent=t.text,i.href=t.href,i.rel="noopener noreferrer",(i.protocol==="http:"||i.protocol==="https:")&&(i.target="_blank"),e.append(i)}}}function M(n,e,r=""){let t=n.createElement("button");return t.type="button",t.className=`xeno-ui__button${r?` ${r}`:""}`,t.textContent=e,t}function xe(n,e,r){let t=n.createElement(e.role==="article"?"article":"div");if(t.className=`xeno-ui__entry xeno-ui__entry--${e.kind==="user-message"?"user":e.kind==="assistant-message"?"assistant":e.kind==="tool-call"?"tool":"error"}`,t.setAttribute("role",e.role),t.setAttribute("aria-label",e.accessibleName),t.dataset.xenoKey=e.key,e.streaming&&t.setAttribute("aria-busy","true"),fe(n,t,e.text),e.detail){let i=n.createElement("details");i.className="xeno-ui__details";let m=n.createElement("summary");m.textContent="Details";let g=n.createElement("pre");g.textContent=e.detail,i.append(m,g),t.append(i)}if(e.retryable){let i=M(n,"Retry");i.addEventListener("click",()=>{S(r,{type:"retry"})}),t.append(n.createTextNode(" "),i)}return t}function be(n,e){if(n.getElementById(W))return;let r=n.createElement("style");r.id=W,e&&(r.nonce=e),r.textContent=H,n.head.append(r)}function Y(n,e,r={}){let t=n.ownerDocument;r.injectStyles!==!1&&be(t,r.styleNonce);let i=t.createElement("section");i.className=`xeno-ui${r.className?` ${r.className}`:""}`;let m=t.createElement("header");m.className="xeno-ui__header";let g=t.createElement("h2");g.className="xeno-ui__title";let h=t.createElement("span");h.className="xeno-ui__status",h.setAttribute("role","status"),h.setAttribute("aria-live","polite");let
|
|
35
|
+
[truncated]`}function ge(n){if(n.type==="message"){let e=n.data.role==="assistant";return{key:n.data.id,kind:e?"assistant-message":"user-message",role:"article",accessibleName:e?"Assistant message":"Your message",text:n.data.content,streaming:n.data.isStreaming}}if(n.type==="tool_call"){let e=n.data.durationMs===void 0?"":` in ${n.data.durationMs} ms`;return{key:n.data.id,kind:"tool-call",role:"status",accessibleName:`${n.data.toolName} tool ${n.data.status}`,text:`${n.data.toolName}: ${n.data.status}${e}`,detail:pe({input:n.data.input,result:n.data.result}),state:n.data.status}}return{key:n.data.id,kind:"error",role:"alert",accessibleName:"Agent error",text:n.data.message,retryable:n.data.retryable}}function z(n,e={}){let r=e.agentName?.trim()||"Xeno Agent",t=n.permissionRequest;return{apiVersion:1,revision:n.revision,region:{role:"region",accessibleName:e.regionLabel?.trim()||`${r} chat`},header:{title:r,statusRole:"status",statusText:n.status,tokenText:`${n.tokenUsage.total.toLocaleString()} tokens`},timeline:{role:"log",live:"polite",busy:n.isProcessing,entries:n.items.map(ge)},permission:t?{role:"alertdialog",accessibleName:`Permission required for ${t.toolName}`,description:t.description||t.detail,riskLevel:t.riskLevel,requestId:t.id,controls:[{label:"Allow once",decision:"allow"},{label:"Always allow",decision:"always"},{label:"Deny",decision:"deny"}]}:null,composer:{role:"form",inputLabel:e.inputLabel?.trim()||"Message Xeno Agent",placeholder:e.inputPlaceholder?.trim()||"Message or command...",disabled:n.isProcessing,sendLabel:"Send",cancelLabel:"Cancel"}}}async function S(n,e){switch(e.type){case"send":return n.sendMessage(e.text);case"cancel":return n.cancelExecution(),!0;case"clear":return n.clearMessages(),!0;case"retry":return n.retryLastMessage();case"permission":return n.resolvePermission(e.requestId,e.decision)}}var W="xeno-owned-agent-ui-v1";function fe(n,e,r){for(let t of D(r)){if(t.kind==="text"){e.append(n.createTextNode(t.text));continue}if(t.kind==="code-block"){let i=n.createElement("pre"),m=n.createElement("code");t.language&&(m.dataset.language=t.language),m.textContent=t.code,i.append(m),e.append(i);continue}if(t.kind==="inline-code"){let i=n.createElement("code");i.textContent=t.code,e.append(i);continue}if(t.kind==="strong"||t.kind==="emphasis"){let i=n.createElement(t.kind==="strong"?"strong":"em");i.textContent=t.text,e.append(i);continue}if(t.kind==="link"){if(!q(t.href)){e.append(n.createTextNode(t.text));continue}let i=n.createElement("a");i.textContent=t.text,i.href=t.href,i.rel="noopener noreferrer",(i.protocol==="http:"||i.protocol==="https:")&&(i.target="_blank"),e.append(i)}}}function M(n,e,r=""){let t=n.createElement("button");return t.type="button",t.className=`xeno-ui__button${r?` ${r}`:""}`,t.textContent=e,t}function xe(n,e,r){let t=n.createElement(e.role==="article"?"article":"div");if(t.className=`xeno-ui__entry xeno-ui__entry--${e.kind==="user-message"?"user":e.kind==="assistant-message"?"assistant":e.kind==="tool-call"?"tool":"error"}`,t.setAttribute("role",e.role),t.setAttribute("aria-label",e.accessibleName),t.dataset.xenoKey=e.key,e.streaming&&t.setAttribute("aria-busy","true"),fe(n,t,e.text),e.detail){let i=n.createElement("details");i.className="xeno-ui__details";let m=n.createElement("summary");m.textContent="Details";let g=n.createElement("pre");g.textContent=e.detail,i.append(m,g),t.append(i)}if(e.retryable){let i=M(n,"Retry");i.addEventListener("click",()=>{S(r,{type:"retry"})}),t.append(n.createTextNode(" "),i)}return t}function be(n,e){if(n.getElementById(W))return;let r=n.createElement("style");r.id=W,e&&(r.nonce=e),r.textContent=H,n.head.append(r)}function Y(n,e,r={}){let t=n.ownerDocument;r.injectStyles!==!1&&be(t,r.styleNonce);let i=t.createElement("section");i.className=`xeno-ui${r.className?` ${r.className}`:""}`;let m=t.createElement("header");m.className="xeno-ui__header";let g=t.createElement("h2");g.className="xeno-ui__title";let h=t.createElement("span");h.className="xeno-ui__status",h.setAttribute("role","status"),h.setAttribute("aria-live","polite");let R=t.createElement("span");R.className="xeno-ui__tokens";let _=M(t,"Clear");if(_.setAttribute("aria-label","Clear conversation"),_.addEventListener("click",()=>{S(e,{type:"clear"})}),m.append(g,h,R,_),r.onClose){let o=M(t,"X");o.setAttribute("aria-label","Close agent chat"),o.addEventListener("click",r.onClose),m.append(o)}let d=t.createElement("div");d.className="xeno-ui__timeline",d.setAttribute("role","log"),d.setAttribute("aria-live","polite"),d.setAttribute("aria-relevant","additions text");let k=t.createElement("div"),v=t.createElement("form");v.className="xeno-ui__composer",v.setAttribute("role","form");let c=t.createElement("textarea");c.className="xeno-ui__input",c.rows=1;let U=t.createElement("div");U.className="xeno-ui__controls";let N=M(t,"Cancel","xeno-ui__button--danger");N.addEventListener("click",()=>{S(e,{type:"cancel"})});let E=M(t,"Send","xeno-ui__button--primary");E.type="submit",U.append(N,E),v.append(c,U),i.append(m,d,k,v),n.replaceChildren(i);function b(){c.style.height="auto";let o=44,C=144,f=Math.max(c.scrollHeight,o);c.style.height=`${Math.min(f,C)}px`,c.style.overflowY=f>C?"auto":"hidden"}async function O(){let o=c.value;await S(e,{type:"send",text:o})&&(c.value="",b())}v.addEventListener("submit",o=>{o.preventDefault(),O()}),c.addEventListener("keydown",o=>{o.key==="Enter"&&(o.ctrlKey||o.metaKey)&&(o.preventDefault(),O())}),c.addEventListener("input",b);let p=null,w=null;function $(o){if(o.permission&&p===o.permission.requestId&&k.children.length>0)return;if(k.replaceChildren(),!o.permission){if(p){let a=w??c;queueMicrotask(()=>a.focus())}p=null,w=null;return}let C=p!==o.permission.requestId;if(C){let a=t.activeElement;w=a&&"focus"in a?a:c,p=o.permission.requestId}let f=t.createElement("section");f.className="xeno-ui__permission",f.setAttribute("role",o.permission.role),f.setAttribute("aria-modal","true"),f.setAttribute("aria-label",o.permission.accessibleName),f.dataset.risk=o.permission.riskLevel;let L=t.createElement("h3");L.className="xeno-ui__permission-title",L.textContent=o.permission.accessibleName;let s=t.createElement("div");s.id=`xeno-ui-permission-${o.permission.requestId}`,s.textContent=o.permission.description,f.setAttribute("aria-describedby",s.id);let l=t.createElement("div");l.className="xeno-ui__permission-actions";let x=null;for(let a of o.permission.controls){let u=M(t,a.label,a.decision==="deny"?"xeno-ui__button--danger":"");u.dataset.decision=a.decision,x??=u,u.addEventListener("click",()=>{S(e,{type:"permission",requestId:o.permission.requestId,decision:a.decision})}),l.append(u)}f.append(L,s,l),k.append(f),C&&x&&queueMicrotask(()=>x?.focus())}function T(){let o=z(e.getSnapshot(),r);i.setAttribute("role",o.region.role),i.setAttribute("aria-label",o.region.accessibleName),g.textContent=o.header.title,h.textContent=o.header.statusText,R.textContent=o.header.tokenText,d.setAttribute("aria-busy",String(o.timeline.busy));let C=d.scrollHeight-d.scrollTop-d.clientHeight;if(o.timeline.entries.length===0){let f=t.createElement("div");f.className="xeno-ui__empty",f.textContent="No messages yet",d.replaceChildren(f)}else d.replaceChildren(...o.timeline.entries.map(f=>xe(t,f,e)));C<48&&(d.scrollTop=d.scrollHeight),$(o),c.disabled=o.composer.disabled,c.setAttribute("aria-label",o.composer.inputLabel),c.placeholder=o.composer.placeholder,E.textContent=o.composer.sendLabel,E.disabled=o.composer.disabled,N.textContent=o.composer.cancelLabel,N.hidden=!o.timeline.busy}let y=null,P=!1;function V(){let o=t.defaultView?.requestAnimationFrame;if(o){if(y!==null)return;y=o.call(t.defaultView,()=>{y=null,T()});return}P||(P=!0,queueMicrotask(()=>{P=!1,T()}))}let j=e.subscribe(V);return T(),b(),{element:i,render:T,focusInput(){c.focus()},dispose(){j(),y!==null&&t.defaultView?.cancelAnimationFrame&&t.defaultView.cancelAnimationFrame(y),i.remove()}}}0&&(module.exports={XENO_UI_RENDERER_API_VERSION,createAgentUiController,createAgentUiView,dispatchAgentUiAction,isSafeMarkdownHref,mountAgentUi,parseMarkdown,xenoUiCss,xenoUiTokens});
|
package/dist/ui/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var Q={View:"Read",Replace:"Write",GlobTool:"Glob",GrepTool:"Grep",SQLiteAnalyze:"SqliteAnalyze",ReadNotebook:"NotebookRead",NotebookEditCell:"NotebookEdit",CoordinationSend:"Send",CoordinationQuery:"Receive"};function W(n){return Q[n]??n}var Y=new Set(["Read","Glob","Grep","LS","Think","dispatch_agent","ElfAnalyze","Receive","ListAgents","ListSessions","CoordinationQuery"]),J=new Set(["Write","Edit","Send","CoordinationSend"]),Z=new Set(["Bash"]);function F(n){let t=W(n);return Z.has(t)?"high":Y.has(t)?"low":(J.has(t),"medium")}var L=1;function ee(n){let t=n.config;return t&&typeof t=="object"?t:null}function H(n){let t=n.tokenUsage;return{input:Number(t.input)||0,output:Number(t.output)||0,total:Number(t.total)||0}}function te(n){let t=n.toLowerCase();return["rate limit","429","network","timeout","econnrefused","api error","unreachable"].some(r=>t.includes(r))}function ne(n){let t=n.agent,r=n.now??Date.now,e=0,i=n.createId??(()=>`xeno-ui-${r()}-${++e}`),m=new Set,g=[],h="idle",S=H(t),_=null,d=null,k=null,v=null,c="",U=null,
|
|
1
|
+
var Q={View:"Read",Replace:"Write",GlobTool:"Glob",GrepTool:"Grep",SQLiteAnalyze:"SqliteAnalyze",ReadNotebook:"NotebookRead",NotebookEditCell:"NotebookEdit",CoordinationSend:"Send",CoordinationQuery:"Receive"};function W(n){return Q[n]??n}var Y=new Set(["Read","Glob","Grep","LS","MemoryRead","Think","dispatch_agent","ElfAnalyze","Receive","ListAgents","ListSessions","CoordinationQuery"]),J=new Set(["Write","Edit","MemoryWrite","Send","CoordinationSend"]),Z=new Set(["Bash"]);function F(n){let t=W(n);return Z.has(t)?"high":Y.has(t)?"low":(J.has(t),"medium")}var L=1;function ee(n){let t=n.config;return t&&typeof t=="object"?t:null}function H(n){let t=n.tokenUsage;return{input:Number(t.input)||0,output:Number(t.output)||0,total:Number(t.total)||0}}function te(n){let t=n.toLowerCase();return["rate limit","429","network","timeout","econnrefused","api error","unreachable"].some(r=>t.includes(r))}function ne(n){let t=n.agent,r=n.now??Date.now,e=0,i=n.createId??(()=>`xeno-ui-${r()}-${++e}`),m=new Set,g=[],h="idle",S=H(t),_=null,d=null,k=null,v=null,c="",U=null,R=0,E=!1,b=!1,O=0,p=ee(t),w=p?.permissionEngine,D=w?.promptFn;function T(){return Object.freeze({apiVersion:1,revision:O,items:Object.freeze([...g]),isProcessing:E,status:h,tokenUsage:Object.freeze({...S}),permissionRequest:_?Object.freeze({..._}):null,lastUserMessage:k})}function y(){O+=1;let s=T();for(let l of[...m])l(s)}function N(s){g=[...g,s],y()}function V(s){let l=[...g];for(let x=l.length-1;x>=0;x-=1){let a=l[x];if(a?.type==="message"&&a.data.role==="assistant"){l[x]={type:"message",data:s(a.data)},g=l,y();return}}}function q(s,l){let x=[...g];for(let a=x.length-1;a>=0;a-=1){let u=x[a];if(u?.type==="tool_call"&&u.data.id===s){x[a]={type:"tool_call",data:l(u.data)},g=x,y();return}}}function o(){v&&(V(s=>({...s,isStreaming:!1})),v=null,c="")}function C(s){let l={id:i(),message:s,retryable:te(s),timestamp:r()};N({type:"error",data:l})}function f(s){p&&(p.onText=s.onText,p.onToolStart=s.onToolStart,p.onToolEnd=s.onToolEnd,p.onError=s.onError)}async function I(s){let l=s.trim();if(b||E||!l)return!1;E=!0,k=l,h="thinking",v=null,c="";let x={id:i(),role:"user",content:l,timestamp:r()};g=[...g,{type:"message",data:x}],y();let a={onText:p?.onText,onToolStart:p?.onToolStart,onToolEnd:p?.onToolEnd,onError:p?.onError};p&&(p.onText=u=>{a.onText?.(u),!b&&(c+=u,v?V(A=>({...A,content:c,isStreaming:!0})):(v=i(),N({type:"message",data:{id:v,role:"assistant",content:c,timestamp:r(),isStreaming:!0}})))},p.onToolStart=(u,A)=>{a.onToolStart?.(u,A),!b&&(o(),h="executing",U=i(),R=r(),N({type:"tool_call",data:{id:U,toolName:u,input:A,status:"running",timestamp:r()}}))},p.onToolEnd=(u,A)=>{a.onToolEnd?.(u,A),!b&&(U&&(q(U,K=>({...K,status:A.success?"success":"error",result:A,durationMs:Math.max(0,r()-R)})),U=null),h="thinking",y())},p.onError=(u,A)=>a.onError?.(u,A));try{await t.run(l),b||(o(),h="idle",S=H(t),y())}catch(u){if(!b){o();let A=u instanceof Error?u:new Error(String(u));h=A.name==="AgentInterruptedError"?"idle":"error",A.name!=="AgentInterruptedError"&&C(A.message),S=H(t),y()}}finally{E=!1,f(a),b||y()}return!0}return n.enablePermissionRequests&&w&&(w.promptFn=s=>(d&&d("deny"),new Promise(l=>{d=l,_={id:i(),toolName:s.toolName,detail:s.detail,description:s.description,operation:s.operation,preview:s.preview,riskLevel:F(s.toolName),timestamp:r()},y()}))),{apiVersion:1,getSnapshot:T,subscribe(s){if(b)throw new Error("Agent UI controller is disposed");return m.add(s),s(T()),()=>m.delete(s)},sendMessage:I,cancelExecution(){!b&&E&&t.cancelCurrentTurn()},clearMessages(){b||(g=[],v=null,c="",y())},retryLastMessage(){return b||E||!k?Promise.resolve(!1):(g=g.filter((s,l,x)=>s.type!=="error"?!0:x.slice(l+1).some(a=>a.type!=="error")),h="idle",y(),I(k))},resolvePermission(s,l){if(b||!_||_.id!==s||!d)return!1;let x=d;return d=null,_=null,y(),x(l),!0},dispose(){b||(b=!0,d&&d("deny"),d=null,_=null,w&&(w.promptFn=D),m.clear())}}}function oe(n){let t=[],r=[[/```([\w-]*)\n([\s\S]*?)```/,e=>({kind:"code-block",language:e[1]??"",code:e[2]??""})],[/`([^`\n]+)`/,e=>({kind:"inline-code",code:e[1]??""})],[/\*\*(.+?)\*\*/,e=>({kind:"strong",text:e[1]??""})],[/\*([^*\n]+)\*/,e=>({kind:"emphasis",text:e[1]??""})],[/\[([^\]]+)\]\(([^)\s]+)\)/,e=>({kind:"link",text:e[1]??"",href:e[2]??""})]];for(let[e,i]of r){let m=n.match(e);m?.index!==void 0&&t.push({index:m.index,value:i(m),length:m[0].length})}return t.sort((e,i)=>e.index-i.index),t[0]??null}function z(n){let t=[],r=n;for(;r;){let e=oe(r);if(!e){t.push({kind:"text",text:r});break}e.index>0&&t.push({kind:"text",text:r.slice(0,e.index)}),t.push(e.value),r=r.slice(e.index+e.length)}return t}function $(n){try{let t=new URL(n,"https://xeno.invalid/");return t.protocol==="https:"||t.protocol==="http:"||t.protocol==="mailto:"}catch{return!1}}var re=Object.freeze({background:"#101214",surface:"#181b1f",surfaceRaised:"#20242a",border:"#343a42",text:"#f2f4f7",textMuted:"#aab2bd",accent:"#5da9e9",success:"#56b881",warning:"#e7b65a",danger:"#e57373",focus:"#8bc5f4"}),j=`
|
|
2
2
|
.xeno-ui{box-sizing:border-box;display:grid;grid-template-rows:auto minmax(12rem,1fr) auto;width:min(32rem,100%);height:min(44rem,100%);min-height:24rem;border:1px solid var(--xeno-border,#343a42);background:var(--xeno-bg,#101214);color:var(--xeno-text,#f2f4f7);font:14px/1.45 ui-sans-serif,system-ui,-apple-system,"Segoe UI",sans-serif;letter-spacing:0}
|
|
3
3
|
.xeno-ui *{box-sizing:border-box;letter-spacing:0}
|
|
4
4
|
.xeno-ui__header{display:flex;align-items:center;gap:.75rem;padding:.75rem 1rem;border-bottom:1px solid var(--xeno-border,#343a42);background:var(--xeno-surface,#181b1f)}
|
|
@@ -32,4 +32,4 @@ var Q={View:"Read",Replace:"Write",GlobTool:"Glob",GrepTool:"Grep",SQLiteAnalyze
|
|
|
32
32
|
@media (max-width:36rem){.xeno-ui{width:100%;height:100%;border-left:0;border-right:0}.xeno-ui__entry--user,.xeno-ui__entry--assistant{margin-left:0;margin-right:0}.xeno-ui__composer{grid-template-columns:1fr}.xeno-ui__controls{justify-content:flex-end}}
|
|
33
33
|
@media (prefers-reduced-motion:reduce){.xeno-ui *{scroll-behavior:auto!important;transition:none!important}}
|
|
34
34
|
`;var G=64*1024;function ie(n){let t;try{t=JSON.stringify(n,null,2)??String(n)}catch{t="[Unserializable value]"}return t.length<=G?t:`${t.slice(0,G)}
|
|
35
|
-
[truncated]`}function se(n){if(n.type==="message"){let t=n.data.role==="assistant";return{key:n.data.id,kind:t?"assistant-message":"user-message",role:"article",accessibleName:t?"Assistant message":"Your message",text:n.data.content,streaming:n.data.isStreaming}}if(n.type==="tool_call"){let t=n.data.durationMs===void 0?"":` in ${n.data.durationMs} ms`;return{key:n.data.id,kind:"tool-call",role:"status",accessibleName:`${n.data.toolName} tool ${n.data.status}`,text:`${n.data.toolName}: ${n.data.status}${t}`,detail:ie({input:n.data.input,result:n.data.result}),state:n.data.status}}return{key:n.data.id,kind:"error",role:"alert",accessibleName:"Agent error",text:n.data.message,retryable:n.data.retryable}}function X(n,t={}){let r=t.agentName?.trim()||"Xeno Agent",e=n.permissionRequest;return{apiVersion:1,revision:n.revision,region:{role:"region",accessibleName:t.regionLabel?.trim()||`${r} chat`},header:{title:r,statusRole:"status",statusText:n.status,tokenText:`${n.tokenUsage.total.toLocaleString()} tokens`},timeline:{role:"log",live:"polite",busy:n.isProcessing,entries:n.items.map(se)},permission:e?{role:"alertdialog",accessibleName:`Permission required for ${e.toolName}`,description:e.description||e.detail,riskLevel:e.riskLevel,requestId:e.id,controls:[{label:"Allow once",decision:"allow"},{label:"Always allow",decision:"always"},{label:"Deny",decision:"deny"}]}:null,composer:{role:"form",inputLabel:t.inputLabel?.trim()||"Message Xeno Agent",placeholder:t.inputPlaceholder?.trim()||"Message or command...",disabled:n.isProcessing,sendLabel:"Send",cancelLabel:"Cancel"}}}async function P(n,t){switch(t.type){case"send":return n.sendMessage(t.text);case"cancel":return n.cancelExecution(),!0;case"clear":return n.clearMessages(),!0;case"retry":return n.retryLastMessage();case"permission":return n.resolvePermission(t.requestId,t.decision)}}var B="xeno-owned-agent-ui-v1";function ae(n,t,r){for(let e of z(r)){if(e.kind==="text"){t.append(n.createTextNode(e.text));continue}if(e.kind==="code-block"){let i=n.createElement("pre"),m=n.createElement("code");e.language&&(m.dataset.language=e.language),m.textContent=e.code,i.append(m),t.append(i);continue}if(e.kind==="inline-code"){let i=n.createElement("code");i.textContent=e.code,t.append(i);continue}if(e.kind==="strong"||e.kind==="emphasis"){let i=n.createElement(e.kind==="strong"?"strong":"em");i.textContent=e.text,t.append(i);continue}if(e.kind==="link"){if(!$(e.href)){t.append(n.createTextNode(e.text));continue}let i=n.createElement("a");i.textContent=e.text,i.href=e.href,i.rel="noopener noreferrer",(i.protocol==="http:"||i.protocol==="https:")&&(i.target="_blank"),t.append(i)}}}function M(n,t,r=""){let e=n.createElement("button");return e.type="button",e.className=`xeno-ui__button${r?` ${r}`:""}`,e.textContent=t,e}function le(n,t,r){let e=n.createElement(t.role==="article"?"article":"div");if(e.className=`xeno-ui__entry xeno-ui__entry--${t.kind==="user-message"?"user":t.kind==="assistant-message"?"assistant":t.kind==="tool-call"?"tool":"error"}`,e.setAttribute("role",t.role),e.setAttribute("aria-label",t.accessibleName),e.dataset.xenoKey=t.key,t.streaming&&e.setAttribute("aria-busy","true"),ae(n,e,t.text),t.detail){let i=n.createElement("details");i.className="xeno-ui__details";let m=n.createElement("summary");m.textContent="Details";let g=n.createElement("pre");g.textContent=t.detail,i.append(m,g),e.append(i)}if(t.retryable){let i=M(n,"Retry");i.addEventListener("click",()=>{P(r,{type:"retry"})}),e.append(n.createTextNode(" "),i)}return e}function ce(n,t){if(n.getElementById(B))return;let r=n.createElement("style");r.id=B,t&&(r.nonce=t),r.textContent=j,n.head.append(r)}function de(n,t,r={}){let e=n.ownerDocument;r.injectStyles!==!1&&ce(e,r.styleNonce);let i=e.createElement("section");i.className=`xeno-ui${r.className?` ${r.className}`:""}`;let m=e.createElement("header");m.className="xeno-ui__header";let g=e.createElement("h2");g.className="xeno-ui__title";let h=e.createElement("span");h.className="xeno-ui__status",h.setAttribute("role","status"),h.setAttribute("aria-live","polite");let S=e.createElement("span");S.className="xeno-ui__tokens";let _=M(e,"Clear");if(_.setAttribute("aria-label","Clear conversation"),_.addEventListener("click",()=>{P(t,{type:"clear"})}),m.append(g,h,S,_),r.onClose){let o=M(e,"X");o.setAttribute("aria-label","Close agent chat"),o.addEventListener("click",r.onClose),m.append(o)}let d=e.createElement("div");d.className="xeno-ui__timeline",d.setAttribute("role","log"),d.setAttribute("aria-live","polite"),d.setAttribute("aria-relevant","additions text");let k=e.createElement("div"),v=e.createElement("form");v.className="xeno-ui__composer",v.setAttribute("role","form");let c=e.createElement("textarea");c.className="xeno-ui__input",c.rows=1;let U=e.createElement("div");U.className="xeno-ui__controls";let
|
|
35
|
+
[truncated]`}function se(n){if(n.type==="message"){let t=n.data.role==="assistant";return{key:n.data.id,kind:t?"assistant-message":"user-message",role:"article",accessibleName:t?"Assistant message":"Your message",text:n.data.content,streaming:n.data.isStreaming}}if(n.type==="tool_call"){let t=n.data.durationMs===void 0?"":` in ${n.data.durationMs} ms`;return{key:n.data.id,kind:"tool-call",role:"status",accessibleName:`${n.data.toolName} tool ${n.data.status}`,text:`${n.data.toolName}: ${n.data.status}${t}`,detail:ie({input:n.data.input,result:n.data.result}),state:n.data.status}}return{key:n.data.id,kind:"error",role:"alert",accessibleName:"Agent error",text:n.data.message,retryable:n.data.retryable}}function X(n,t={}){let r=t.agentName?.trim()||"Xeno Agent",e=n.permissionRequest;return{apiVersion:1,revision:n.revision,region:{role:"region",accessibleName:t.regionLabel?.trim()||`${r} chat`},header:{title:r,statusRole:"status",statusText:n.status,tokenText:`${n.tokenUsage.total.toLocaleString()} tokens`},timeline:{role:"log",live:"polite",busy:n.isProcessing,entries:n.items.map(se)},permission:e?{role:"alertdialog",accessibleName:`Permission required for ${e.toolName}`,description:e.description||e.detail,riskLevel:e.riskLevel,requestId:e.id,controls:[{label:"Allow once",decision:"allow"},{label:"Always allow",decision:"always"},{label:"Deny",decision:"deny"}]}:null,composer:{role:"form",inputLabel:t.inputLabel?.trim()||"Message Xeno Agent",placeholder:t.inputPlaceholder?.trim()||"Message or command...",disabled:n.isProcessing,sendLabel:"Send",cancelLabel:"Cancel"}}}async function P(n,t){switch(t.type){case"send":return n.sendMessage(t.text);case"cancel":return n.cancelExecution(),!0;case"clear":return n.clearMessages(),!0;case"retry":return n.retryLastMessage();case"permission":return n.resolvePermission(t.requestId,t.decision)}}var B="xeno-owned-agent-ui-v1";function ae(n,t,r){for(let e of z(r)){if(e.kind==="text"){t.append(n.createTextNode(e.text));continue}if(e.kind==="code-block"){let i=n.createElement("pre"),m=n.createElement("code");e.language&&(m.dataset.language=e.language),m.textContent=e.code,i.append(m),t.append(i);continue}if(e.kind==="inline-code"){let i=n.createElement("code");i.textContent=e.code,t.append(i);continue}if(e.kind==="strong"||e.kind==="emphasis"){let i=n.createElement(e.kind==="strong"?"strong":"em");i.textContent=e.text,t.append(i);continue}if(e.kind==="link"){if(!$(e.href)){t.append(n.createTextNode(e.text));continue}let i=n.createElement("a");i.textContent=e.text,i.href=e.href,i.rel="noopener noreferrer",(i.protocol==="http:"||i.protocol==="https:")&&(i.target="_blank"),t.append(i)}}}function M(n,t,r=""){let e=n.createElement("button");return e.type="button",e.className=`xeno-ui__button${r?` ${r}`:""}`,e.textContent=t,e}function le(n,t,r){let e=n.createElement(t.role==="article"?"article":"div");if(e.className=`xeno-ui__entry xeno-ui__entry--${t.kind==="user-message"?"user":t.kind==="assistant-message"?"assistant":t.kind==="tool-call"?"tool":"error"}`,e.setAttribute("role",t.role),e.setAttribute("aria-label",t.accessibleName),e.dataset.xenoKey=t.key,t.streaming&&e.setAttribute("aria-busy","true"),ae(n,e,t.text),t.detail){let i=n.createElement("details");i.className="xeno-ui__details";let m=n.createElement("summary");m.textContent="Details";let g=n.createElement("pre");g.textContent=t.detail,i.append(m,g),e.append(i)}if(t.retryable){let i=M(n,"Retry");i.addEventListener("click",()=>{P(r,{type:"retry"})}),e.append(n.createTextNode(" "),i)}return e}function ce(n,t){if(n.getElementById(B))return;let r=n.createElement("style");r.id=B,t&&(r.nonce=t),r.textContent=j,n.head.append(r)}function de(n,t,r={}){let e=n.ownerDocument;r.injectStyles!==!1&&ce(e,r.styleNonce);let i=e.createElement("section");i.className=`xeno-ui${r.className?` ${r.className}`:""}`;let m=e.createElement("header");m.className="xeno-ui__header";let g=e.createElement("h2");g.className="xeno-ui__title";let h=e.createElement("span");h.className="xeno-ui__status",h.setAttribute("role","status"),h.setAttribute("aria-live","polite");let S=e.createElement("span");S.className="xeno-ui__tokens";let _=M(e,"Clear");if(_.setAttribute("aria-label","Clear conversation"),_.addEventListener("click",()=>{P(t,{type:"clear"})}),m.append(g,h,S,_),r.onClose){let o=M(e,"X");o.setAttribute("aria-label","Close agent chat"),o.addEventListener("click",r.onClose),m.append(o)}let d=e.createElement("div");d.className="xeno-ui__timeline",d.setAttribute("role","log"),d.setAttribute("aria-live","polite"),d.setAttribute("aria-relevant","additions text");let k=e.createElement("div"),v=e.createElement("form");v.className="xeno-ui__composer",v.setAttribute("role","form");let c=e.createElement("textarea");c.className="xeno-ui__input",c.rows=1;let U=e.createElement("div");U.className="xeno-ui__controls";let R=M(e,"Cancel","xeno-ui__button--danger");R.addEventListener("click",()=>{P(t,{type:"cancel"})});let E=M(e,"Send","xeno-ui__button--primary");E.type="submit",U.append(R,E),v.append(c,U),i.append(m,d,k,v),n.replaceChildren(i);function b(){c.style.height="auto";let o=44,C=144,f=Math.max(c.scrollHeight,o);c.style.height=`${Math.min(f,C)}px`,c.style.overflowY=f>C?"auto":"hidden"}async function O(){let o=c.value;await P(t,{type:"send",text:o})&&(c.value="",b())}v.addEventListener("submit",o=>{o.preventDefault(),O()}),c.addEventListener("keydown",o=>{o.key==="Enter"&&(o.ctrlKey||o.metaKey)&&(o.preventDefault(),O())}),c.addEventListener("input",b);let p=null,w=null;function D(o){if(o.permission&&p===o.permission.requestId&&k.children.length>0)return;if(k.replaceChildren(),!o.permission){if(p){let a=w??c;queueMicrotask(()=>a.focus())}p=null,w=null;return}let C=p!==o.permission.requestId;if(C){let a=e.activeElement;w=a&&"focus"in a?a:c,p=o.permission.requestId}let f=e.createElement("section");f.className="xeno-ui__permission",f.setAttribute("role",o.permission.role),f.setAttribute("aria-modal","true"),f.setAttribute("aria-label",o.permission.accessibleName),f.dataset.risk=o.permission.riskLevel;let I=e.createElement("h3");I.className="xeno-ui__permission-title",I.textContent=o.permission.accessibleName;let s=e.createElement("div");s.id=`xeno-ui-permission-${o.permission.requestId}`,s.textContent=o.permission.description,f.setAttribute("aria-describedby",s.id);let l=e.createElement("div");l.className="xeno-ui__permission-actions";let x=null;for(let a of o.permission.controls){let u=M(e,a.label,a.decision==="deny"?"xeno-ui__button--danger":"");u.dataset.decision=a.decision,x??=u,u.addEventListener("click",()=>{P(t,{type:"permission",requestId:o.permission.requestId,decision:a.decision})}),l.append(u)}f.append(I,s,l),k.append(f),C&&x&&queueMicrotask(()=>x?.focus())}function T(){let o=X(t.getSnapshot(),r);i.setAttribute("role",o.region.role),i.setAttribute("aria-label",o.region.accessibleName),g.textContent=o.header.title,h.textContent=o.header.statusText,S.textContent=o.header.tokenText,d.setAttribute("aria-busy",String(o.timeline.busy));let C=d.scrollHeight-d.scrollTop-d.clientHeight;if(o.timeline.entries.length===0){let f=e.createElement("div");f.className="xeno-ui__empty",f.textContent="No messages yet",d.replaceChildren(f)}else d.replaceChildren(...o.timeline.entries.map(f=>le(e,f,t)));C<48&&(d.scrollTop=d.scrollHeight),D(o),c.disabled=o.composer.disabled,c.setAttribute("aria-label",o.composer.inputLabel),c.placeholder=o.composer.placeholder,E.textContent=o.composer.sendLabel,E.disabled=o.composer.disabled,R.textContent=o.composer.cancelLabel,R.hidden=!o.timeline.busy}let y=null,N=!1;function V(){let o=e.defaultView?.requestAnimationFrame;if(o){if(y!==null)return;y=o.call(e.defaultView,()=>{y=null,T()});return}N||(N=!0,queueMicrotask(()=>{N=!1,T()}))}let q=t.subscribe(V);return T(),b(),{element:i,render:T,focusInput(){c.focus()},dispose(){q(),y!==null&&e.defaultView?.cancelAnimationFrame&&e.defaultView.cancelAnimationFrame(y),i.remove()}}}export{L as XENO_UI_RENDERER_API_VERSION,ne as createAgentUiController,X as createAgentUiView,P as dispatchAgentUiAction,$ as isSafeMarkdownHref,de as mountAgentUi,z as parseMarkdown,j as xenoUiCss,re as xenoUiTokens};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"inputs":{"src/tools/tool-names.ts":{"bytes":
|
|
1
|
+
{"inputs":{"src/tools/tool-names.ts":{"bytes":2810,"imports":[],"format":"esm"},"src/ui/types.ts":{"bytes":4274,"imports":[],"format":"esm"},"src/ui/controller.ts":{"bytes":10384,"imports":[{"path":"src/tools/tool-names.ts","kind":"import-statement","original":"../tools/tool-names.js"},{"path":"src/ui/types.ts","kind":"import-statement","original":"./types.js"}],"format":"esm"},"src/ui/markdown.ts":{"bytes":2181,"imports":[],"format":"esm"},"src/ui/styles.ts":{"bytes":4255,"imports":[],"format":"esm"},"src/ui/view-model.ts":{"bytes":3744,"imports":[{"path":"src/ui/types.ts","kind":"import-statement","original":"./types.js"}],"format":"esm"},"src/ui/dom-renderer.ts":{"bytes":11767,"imports":[{"path":"src/ui/markdown.ts","kind":"import-statement","original":"./markdown.js"},{"path":"src/ui/styles.ts","kind":"import-statement","original":"./styles.js"},{"path":"src/ui/view-model.ts","kind":"import-statement","original":"./view-model.js"}],"format":"esm"},"src/ui/index.ts":{"bytes":1059,"imports":[{"path":"src/ui/controller.ts","kind":"import-statement","original":"./controller.js"},{"path":"src/ui/dom-renderer.ts","kind":"import-statement","original":"./dom-renderer.js"},{"path":"src/ui/markdown.ts","kind":"import-statement","original":"./markdown.js"},{"path":"src/ui/styles.ts","kind":"import-statement","original":"./styles.js"},{"path":"src/ui/view-model.ts","kind":"import-statement","original":"./view-model.js"},{"path":"src/ui/types.ts","kind":"import-statement","original":"./types.js"}],"format":"esm"}},"outputs":{"dist/ui/index.cjs":{"imports":[],"exports":[],"entryPoint":"src/ui/index.ts","inputs":{"src/ui/index.ts":{"bytesInOutput":257},"src/tools/tool-names.ts":{"bytesInOutput":572},"src/ui/types.ts":{"bytesInOutput":8},"src/ui/controller.ts":{"bytesInOutput":3352},"src/ui/markdown.ts":{"bytesInOutput":864},"src/ui/styles.ts":{"bytesInOutput":4161},"src/ui/view-model.ts":{"bytesInOutput":2008},"src/ui/dom-renderer.ts":{"bytesInOutput":6079}},"bytes":17919}}}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"inputs":{"src/tools/tool-names.ts":{"bytes":
|
|
1
|
+
{"inputs":{"src/tools/tool-names.ts":{"bytes":2810,"imports":[],"format":"esm"},"src/ui/types.ts":{"bytes":4274,"imports":[],"format":"esm"},"src/ui/controller.ts":{"bytes":10384,"imports":[{"path":"src/tools/tool-names.ts","kind":"import-statement","original":"../tools/tool-names.js"},{"path":"src/ui/types.ts","kind":"import-statement","original":"./types.js"}],"format":"esm"},"src/ui/markdown.ts":{"bytes":2181,"imports":[],"format":"esm"},"src/ui/styles.ts":{"bytes":4255,"imports":[],"format":"esm"},"src/ui/view-model.ts":{"bytes":3744,"imports":[{"path":"src/ui/types.ts","kind":"import-statement","original":"./types.js"}],"format":"esm"},"src/ui/dom-renderer.ts":{"bytes":11767,"imports":[{"path":"src/ui/markdown.ts","kind":"import-statement","original":"./markdown.js"},{"path":"src/ui/styles.ts","kind":"import-statement","original":"./styles.js"},{"path":"src/ui/view-model.ts","kind":"import-statement","original":"./view-model.js"}],"format":"esm"},"src/ui/index.ts":{"bytes":1059,"imports":[{"path":"src/ui/controller.ts","kind":"import-statement","original":"./controller.js"},{"path":"src/ui/dom-renderer.ts","kind":"import-statement","original":"./dom-renderer.js"},{"path":"src/ui/markdown.ts","kind":"import-statement","original":"./markdown.js"},{"path":"src/ui/styles.ts","kind":"import-statement","original":"./styles.js"},{"path":"src/ui/view-model.ts","kind":"import-statement","original":"./view-model.js"},{"path":"src/ui/types.ts","kind":"import-statement","original":"./types.js"}],"format":"esm"}},"outputs":{"dist/ui/index.js":{"imports":[],"exports":["XENO_UI_RENDERER_API_VERSION","createAgentUiController","createAgentUiView","dispatchAgentUiAction","isSafeMarkdownHref","mountAgentUi","parseMarkdown","xenoUiCss","xenoUiTokens"],"entryPoint":"src/ui/index.ts","inputs":{"src/tools/tool-names.ts":{"bytesInOutput":562},"src/ui/types.ts":{"bytesInOutput":8},"src/ui/controller.ts":{"bytesInOutput":3353},"src/ui/index.ts":{"bytesInOutput":0},"src/ui/markdown.ts":{"bytesInOutput":864},"src/ui/styles.ts":{"bytesInOutput":4162},"src/ui/view-model.ts":{"bytesInOutput":2008},"src/ui/dom-renderer.ts":{"bytesInOutput":6080}},"bytes":17256}}}
|