@xenosystem/agent-sdk 0.9.10 → 0.9.13
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/LICENSE +15 -15
- package/README.md +511 -511
- package/dist/agents/index.cjs +9 -9
- package/dist/agents/index.d.cts +12 -2
- package/dist/agents/index.d.ts +12 -2
- package/dist/agents/index.js +9 -9
- package/dist/agents/metafile-cjs.json +1 -1
- package/dist/agents/metafile-esm.json +1 -1
- package/dist/artifacts/browser.cjs +1 -1
- package/dist/artifacts/browser.d.cts +2 -2
- package/dist/artifacts/browser.d.ts +2 -2
- package/dist/artifacts/browser.js +1 -1
- package/dist/artifacts/{diff-artifact-C2tQZWcs.d.cts → diff-artifact-CmhmeSu5.d.cts} +87 -7
- package/dist/artifacts/{diff-artifact-C2tQZWcs.d.ts → diff-artifact-CmhmeSu5.d.ts} +87 -7
- package/dist/artifacts/index.cjs +8 -8
- package/dist/artifacts/index.d.cts +22 -5
- package/dist/artifacts/index.d.ts +22 -5
- package/dist/artifacts/index.js +8 -8
- package/dist/artifacts/metafile-cjs.json +1 -1
- package/dist/artifacts/metafile-esm.json +1 -1
- package/dist/automation/index.cjs +2 -2
- package/dist/automation/index.d.cts +98 -7
- package/dist/automation/index.d.ts +98 -7
- package/dist/automation/index.js +2 -2
- package/dist/automation/metafile-cjs.json +1 -1
- package/dist/automation/metafile-esm.json +1 -1
- package/dist/control-plane/index.cjs +7 -7
- package/dist/control-plane/index.d.cts +19 -2
- package/dist/control-plane/index.d.ts +19 -2
- package/dist/control-plane/index.js +7 -7
- package/dist/control-plane/metafile-cjs.json +1 -1
- package/dist/control-plane/metafile-esm.json +1 -1
- package/dist/control-room/metafile-cjs.json +1 -1
- package/dist/control-room/metafile-esm.json +1 -1
- package/dist/electron/index.cjs +143 -143
- package/dist/electron/index.d.cts +25 -4
- package/dist/electron/index.d.ts +25 -4
- package/dist/electron/index.js +141 -141
- package/dist/electron/metafile-cjs.json +1 -1
- package/dist/electron/metafile-esm.json +1 -1
- package/dist/governance/index.cjs +18 -18
- package/dist/governance/index.d.cts +1 -0
- package/dist/governance/index.d.ts +1 -0
- package/dist/governance/index.js +18 -18
- package/dist/governance/metafile-cjs.json +1 -1
- package/dist/governance/metafile-esm.json +1 -1
- package/dist/hooks/index.d.cts +10 -1
- package/dist/hooks/index.d.ts +10 -1
- package/dist/hooks/metafile-cjs.json +1 -1
- package/dist/hooks/metafile-esm.json +1 -1
- package/dist/hosted/index.cjs +1 -1
- package/dist/hosted/index.js +1 -1
- package/dist/hosted/metafile-cjs.json +1 -1
- package/dist/hosted/metafile-esm.json +1 -1
- package/dist/index.cjs +332 -332
- package/dist/index.d.cts +200 -25
- package/dist/index.d.ts +200 -25
- package/dist/index.js +333 -333
- package/dist/intelligence/metafile-cjs.json +1 -1
- package/dist/intelligence/metafile-esm.json +1 -1
- package/dist/mcp/index.cjs +17 -17
- package/dist/mcp/index.d.cts +1 -0
- package/dist/mcp/index.d.ts +1 -0
- package/dist/mcp/index.js +17 -17
- package/dist/mcp/metafile-cjs.json +1 -1
- package/dist/mcp/metafile-esm.json +1 -1
- package/dist/metafile-cjs.json +1 -1
- package/dist/metafile-esm.json +1 -1
- package/dist/oracle/index.cjs +1 -1
- package/dist/oracle/index.d.cts +86 -6
- package/dist/oracle/index.d.ts +86 -6
- package/dist/oracle/index.js +1 -1
- package/dist/oracle/metafile-cjs.json +1 -1
- package/dist/oracle/metafile-esm.json +1 -1
- package/dist/providers/index.cjs +10 -10
- package/dist/providers/index.d.cts +1 -0
- package/dist/providers/index.d.ts +1 -0
- 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.d.cts +10 -1
- package/dist/recipes/index.d.ts +10 -1
- 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.d.cts +86 -6
- package/dist/research/index.d.ts +86 -6
- 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 +20 -20
- package/dist/session/index.d.cts +1 -0
- package/dist/session/index.d.ts +1 -0
- package/dist/session/index.js +21 -21
- package/dist/session/metafile-cjs.json +1 -1
- package/dist/session/metafile-esm.json +1 -1
- package/dist/sharing/metafile-cjs.json +1 -1
- package/dist/sharing/metafile-esm.json +1 -1
- package/dist/skills/index.d.cts +1 -0
- package/dist/skills/index.d.ts +1 -0
- package/dist/skills/metafile-cjs.json +1 -1
- package/dist/skills/metafile-esm.json +1 -1
- package/dist/soul/metafile-cjs.json +1 -1
- package/dist/soul/metafile-esm.json +1 -1
- package/dist/terminal/metafile-cjs.json +1 -1
- package/dist/terminal/metafile-esm.json +1 -1
- package/dist/ui/index.d.cts +1 -0
- package/dist/ui/index.d.ts +1 -0
- package/dist/ui/metafile-cjs.json +1 -1
- package/dist/ui/metafile-esm.json +1 -1
- package/dist/utils/index.cjs +20 -20
- package/dist/utils/index.d.cts +4 -1
- package/dist/utils/index.d.ts +4 -1
- package/dist/utils/index.js +17 -17
- package/dist/utils/metafile-cjs.json +1 -1
- package/dist/utils/metafile-esm.json +1 -1
- package/native/mxc/LICENSE.microsoft-mxc-sdk.md +20 -20
- package/native/mxc/README.md +25 -25
- package/native/mxc/package.json +58 -58
- package/ownership/CLEAN_ROOM_CONTRIBUTOR_GUIDE.md +63 -63
- package/ownership/evidence/PROPRIETARY-COMMAND-1/implementation-record.md +77 -77
- package/ownership/evidence/PROPRIETARY-COMMAND-1/provenance-review.md +51 -51
- package/ownership/evidence/PROPRIETARY-MEDIA-1/implementation-record.md +131 -131
- package/ownership/evidence/PROPRIETARY-MEDIA-1/provenance-review.md +50 -50
- package/ownership/evidence/PROPRIETARY-PTY-1/implementation-record.md +86 -86
- package/ownership/evidence/PROPRIETARY-PTY-1/provenance-review.md +52 -52
- package/ownership/evidence/PROPRIETARY-RUNTIME-1/implementation-record.md +68 -68
- package/ownership/evidence/PROPRIETARY-RUNTIME-1/provenance-review.md +32 -32
- package/ownership/evidence/PROPRIETARY-TOOLCHAIN-1/implementation-record.md +53 -53
- package/ownership/evidence/PROPRIETARY-TOOLCHAIN-1/provenance-review.md +32 -32
- package/ownership/evidence/PROPRIETARY-UI-1/implementation-record.md +96 -96
- package/ownership/evidence/PROPRIETARY-UI-1/provenance-review.md +46 -46
- package/ownership/ownership-policy.schema.json +192 -192
- package/ownership/templates/clean-room-implementation-record.md +70 -70
- package/ownership/templates/provenance-review.md +51 -51
- package/package.json +23 -22
package/dist/oracle/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var E=Object.defineProperty;var ee=Object.getOwnPropertyDescriptor;var te=Object.getOwnPropertyNames;var ne=Object.prototype.hasOwnProperty;var ie=(e,t)=>{for(var n in t)E(e,n,{get:t[n],enumerable:!0})},re=(e,t,n,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of te(t))!ne.call(e,r)&&r!==n&&E(e,r,{get:()=>t[r],enumerable:!(i=ee(t,r))||i.enumerable});return e};var oe=e=>re(E({},"__esModule",{value:!0}),e);var Oe={};ie(Oe,{XENO_ORACLE_REPORT_SCHEMA_VERSION:()=>q,XenoOracleCoordinator:()=>j,XenoOracleValidationError:()=>u,assertValidXenoOracleReport:()=>O,xenoArtifactToOracleReport:()=>Xe,xenoOracleReportToArtifact:()=>Ie});module.exports=oe(Oe);var $=require("node:crypto");var D=require("node:crypto");function y(e){return{algorithm:"sha256",value:(0,D.createHash)("sha256").update(e).digest("hex")}}function k(e){return JSON.stringify(x(e,new Set))}function S(e){return y(k(e))}function x(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 i=e.map(r=>x(r,t));return t.delete(e),i}let n={};for(let i of Object.keys(e).sort((r,a)=>r.localeCompare(a))){let r=e[i];if(r===void 0)throw new TypeError(`Artifact JSON property ${i} is undefined`);n[i]=x(r,t)}return t.delete(e),n}var T=require("node:buffer");var C=class extends Error{code="ARTIFACT_INVALID";issues;constructor(t,n){super(t),this.name="XenoArtifactValidationError",this.issues=n.map(i=>({...i}))}};var se=/^[a-z0-9][a-z0-9._/-]{0,127}$/,ae="[\\u0000-\\u001f\\u007f]",ce=new RegExp(ae),de=/^[a-f0-9]{64}$/,ue=/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/,pe=new Set(["draft","pending_review","approved","rejected","superseded","archived"]),le=new Set(["public","internal","confidential","restricted"]),fe=new Set(["agent","tool","user","system","integration"]),me=new Set(["plan","requirements","design","task-graph","patch","diff","file","document","diagram","screenshot","recording","browser-snapshot","test-report","review-report","security-report","performance-report","release-report","sbom","provenance","attestation"]),ge=new Set(["requirement","design-decision","risk","task","agent","run","tool-call","edit","commit","test-case","test-run","finding","approval","artifact","release","claim"]),he=new Set(["decomposes","depends_on","implements","changes","tests","verifies","finds","fixes","reviews","approves","rejects","supersedes","derived_from","produced_by","supports_claim","contradicts_claim","released_as"]);function o(e,t,n,i){e.push({path:t,code:n,message:i})}function s(e,t,n,i=1024){return typeof e!="string"||e.trim().length===0?(o(n,t,"required_string","Value must be a non-empty string"),!1):(e.length>i&&o(n,t,"string_too_long",`Value must not exceed ${i} characters`),ce.test(e)&&o(n,t,"control_character","Value must not contain control characters"),!0)}function b(e,t,n){e!==void 0&&(!Number.isFinite(Date.parse(e))||!e.includes("T"))&&o(n,t,"invalid_timestamp","Value must be an ISO 8601 timestamp")}function v(e,t,n,i){if(typeof e!="string"||!e.startsWith(t))return;let r=e.slice(t.length);se.test(r)||o(i,n,"invalid_custom_name",`Custom name after ${t} is invalid`)}function ye(e,t,n){if(!e||typeof e!="object"){o(n,t,"missing_actor","Actor is required");return}s(e.kind,`${t}.kind`,n,64),fe.has(e.kind)||o(n,`${t}.kind`,"unknown_actor_kind","Actor kind is not supported"),s(e.id,`${t}.id`,n,512),e?.displayName!==void 0&&s(e.displayName,`${t}.displayName`,n,512),e?.profileFingerprint!==void 0&&!/^[a-f0-9]{64}$/.test(e.profileFingerprint)&&o(n,`${t}.profileFingerprint`,"invalid_fingerprint","Profile fingerprint must be 64 lowercase hexadecimal characters")}function ve(e,t,n){if(!e||typeof e!="object"){o(n,t,"invalid_anchor","Anchor must be an object");return}switch(e.kind){case"file":s(e.path,`${t}.path`,n,4096);break;case"source-line":s(e.path,`${t}.path`,n,4096),(!Number.isInteger(e.startLine)||e.startLine<1)&&o(n,`${t}.startLine`,"invalid_line","startLine must be a positive integer"),e.endLine!==void 0&&(!Number.isInteger(e.endLine)||e.endLine<e.startLine)&&o(n,`${t}.endLine`,"invalid_line_range","endLine must be greater than or equal to startLine");break;case"diff-hunk":s(e.path,`${t}.path`,n,4096),s(e.hunkId,`${t}.hunkId`,n,512);break;case"symbol":s(e.path,`${t}.path`,n,4096),s(e.symbol,`${t}.symbol`,n,1024);break;case"dom-node":s(e.pageId,`${t}.pageId`,n,512),!e.selector&&!e.accessibilityId&&!e.snapshotArtifactId&&o(n,t,"missing_dom_locator","DOM anchors require a selector, accessibility ID, or snapshot artifact ID");break;case"timeline":s(e.recordingArtifactId,`${t}.recordingArtifactId`,n,512),(!Number.isFinite(e.startMs)||e.startMs<0)&&o(n,`${t}.startMs`,"invalid_time","startMs must be a non-negative finite number"),e.endMs!==void 0&&(!Number.isFinite(e.endMs)||e.endMs<e.startMs)&&o(n,`${t}.endMs`,"invalid_time_range","endMs must be greater than or equal to startMs");break;case"region":s(e.mediaArtifactId,`${t}.mediaArtifactId`,n,512),[e.x,e.y,e.width,e.height].every(Number.isFinite)?(e.width<=0||e.height<=0)&&o(n,t,"invalid_region_size","Region width and height must be positive"):o(n,t,"invalid_region","Region coordinates must be finite numbers");break;case"artifact":s(e.artifactId,`${t}.artifactId`,n,512);break;default:typeof e.kind!="string"||!e.kind.startsWith("custom:")?o(n,`${t}.kind`,"unknown_anchor","Anchor kind is not supported"):v(e.kind,"custom:",`${t}.kind`,n)}}function A(e,t,n,i){if(!(e===null||typeof e=="string"||typeof e=="boolean")){if(typeof e=="number"){Number.isFinite(e)||o(n,t,"non_finite_number","JSON numbers must be finite");return}if(typeof e!="object"){o(n,t,"non_json_value","Value must be JSON-serializable");return}if(i.has(e)){o(n,t,"cyclic_value","Value must not contain cycles");return}if(i.add(e),Array.isArray(e))e.forEach((r,a)=>A(r,`${t}[${a}]`,n,i));else for(let[r,a]of Object.entries(e))a===void 0?o(n,`${t}.${r}`,"undefined_value","Undefined is not valid JSON"):A(a,`${t}.${r}`,n,i);i.delete(e)}}function Ae(e){let t=[];if(!e||typeof e!="object")return[{path:"$",code:"invalid_artifact",message:"Artifact must be an object"}];if(e.schemaVersion!==1&&o(t,"schemaVersion","unsupported_schema",`schemaVersion must be ${1}`),s(e.artifactId,"artifactId",t,512),(!Number.isInteger(e.revision)||e.revision<1)&&o(t,"revision","invalid_revision","revision must be a positive integer"),s(e.kind,"kind",t,160),typeof e.kind=="string"&&!me.has(e.kind)&&!e.kind.startsWith("custom:")&&o(t,"kind","unknown_artifact_kind","Artifact kind is not supported"),v(e.kind,"custom:","kind",t),s(e.title,"title",t,1024),e.description!==void 0&&s(e.description,"description",t,32768),s(e.state,"state",t,64),pe.has(e.state)||o(t,"state","unknown_state","Artifact state is not supported"),s(e.createdAt,"createdAt",t,128),b(e.createdAt,"createdAt",t),b(e.updatedAt,"updatedAt",t),e.updatedAt&&Number.isFinite(Date.parse(e.createdAt))&&Date.parse(e.updatedAt)<Date.parse(e.createdAt)&&o(t,"updatedAt","timestamp_order","updatedAt must not precede createdAt"),s(e.mediaType,"mediaType",t,255),s(e.sensitivity,"sensitivity",t,64),le.has(e.sensitivity)||o(t,"sensitivity","unknown_sensitivity","Sensitivity is not supported"),e.identity)for(let[i,r]of Object.entries(e.identity))r!==void 0&&s(r,`identity.${i}`,t,512);if(!e.content||typeof e.content!="object")o(t,"content","missing_content","content descriptor is required");else{!e.content.hash||typeof e.content.hash!="object"?o(t,"content.hash","missing_hash","content hash is required"):(s(e.content.hash.algorithm,"content.hash.algorithm",t,128),v(e.content.hash.algorithm,"custom:","content.hash.algorithm",t),typeof e.content.hash.algorithm=="string"&&e.content.hash.algorithm!=="sha256"&&!e.content.hash.algorithm.startsWith("custom:")&&o(t,"content.hash.algorithm","unknown_hash_algorithm","Hash algorithm is not supported"),s(e.content.hash.value,"content.hash.value",t,512),e.content.hash.algorithm==="sha256"&&!de.test(e.content.hash.value)&&o(t,"content.hash.value","invalid_sha256","SHA-256 hash must be 64 lowercase hexadecimal characters")),(!Number.isSafeInteger(e.content.sizeBytes)||e.content.sizeBytes<0)&&o(t,"content.sizeBytes","invalid_size","sizeBytes must be a non-negative safe integer");let i=e.content.storage;if(!i||typeof i!="object")o(t,"content.storage","missing_storage","storage reference is required");else if(i.type==="inline")if(i.text===void 0==(i.base64===void 0))o(t,"content.storage","invalid_inline_storage","Inline storage requires exactly one of text or base64");else{let r;i.text!==void 0?r=T.Buffer.from(i.text,"utf8"):i.base64!==void 0&&(ue.test(i.base64)?r=T.Buffer.from(i.base64,"base64"):o(t,"content.storage.base64","invalid_base64","Inline base64 content is malformed")),r&&e.content.sizeBytes!==r.byteLength&&o(t,"content.sizeBytes","content_size_mismatch","sizeBytes does not match inline content"),r&&e.content.hash.algorithm==="sha256"&&y(r).value!==e.content.hash.value&&o(t,"content.hash.value","content_hash_mismatch","Hash does not match inline content")}else i.type==="file"?s(i.path,"content.storage.path",t,4096):i.type==="blob"?s(i.uri,"content.storage.uri",t,8192):i.type==="git"?(s(i.commit,"content.storage.commit",t,512),s(i.path,"content.storage.path",t,4096)):i.type==="url"?(s(i.url,"content.storage.url",t,8192),b(i.expiresAt,"content.storage.expiresAt",t)):i.type==="external"?(s(i.provider,"content.storage.provider",t,255),s(i.locator,"content.storage.locator",t,8192)):o(t,"content.storage.type","unknown_storage","Storage type is not supported");e.content.encoding!==void 0&&(typeof e.content.encoding!="string"||e.content.encoding!=="utf8"&&e.content.encoding!=="base64"&&e.content.encoding!=="binary"&&!e.content.encoding.startsWith("custom:"))&&o(t,"content.encoding","unknown_encoding","Content encoding is not supported"),v(e.content.encoding,"custom:","content.encoding",t)}!e.provenance||typeof e.provenance!="object"?o(t,"provenance","missing_provenance","provenance is required"):(ye(e.provenance.producer,"provenance.producer",t),e.provenance.capabilityLeaseIds?.forEach((i,r)=>s(i,`provenance.capabilityLeaseIds[${r}]`,t,512)),e.provenance.sourceArtifactIds?.forEach((i,r)=>s(i,`provenance.sourceArtifactIds[${r}]`,t,512)),e.provenance.attributes&&A(e.provenance.attributes,"provenance.attributes",t,new Set));let n=new Set;return e.relationships?.forEach((i,r)=>{let a=`relationships[${r}]`;s(i.relation,`${a}.relation`,t,160),typeof i.relation=="string"&&!he.has(i.relation)&&!i.relation.startsWith("custom:")&&o(t,`${a}.relation`,"unknown_relationship","Relationship type is not supported"),v(i.relation,"custom:",`${a}.relation`,t),s(i.target?.type,`${a}.target.type`,t,160),typeof i.target?.type=="string"&&!ge.has(i.target.type)&&!i.target.type.startsWith("custom:")&&o(t,`${a}.target.type`,"unknown_reference_type","Evidence reference type is not supported"),v(i.target?.type,"custom:",`${a}.target.type`,t),s(i.target?.id,`${a}.target.id`,t,512);let d=`${i.relation}:${i.target?.type}:${i.target?.id}:${i.target?.revision??""}`;n.has(d)&&o(t,a,"duplicate_relationship","Duplicate relationship"),n.add(d),i.attributes&&A(i.attributes,`${a}.attributes`,t,new Set)}),e.anchors?.forEach((i,r)=>ve(i,`anchors[${r}]`,t)),e.revision===1&&e.predecessorRevision!==void 0&&o(t,"predecessorRevision","unexpected_predecessor","First revision cannot have a predecessor"),e.revision>1&&(!Number.isInteger(e.predecessorRevision)||(e.predecessorRevision??0)>=e.revision)&&o(t,"predecessorRevision","invalid_predecessor","Later revisions require an earlier predecessor revision"),b(e.retention?.retainUntil,"retention.retainUntil",t),e.retention?.legalHold!==void 0&&typeof e.retention.legalHold!="boolean"&&o(t,"retention.legalHold","invalid_boolean","legalHold must be a boolean"),e.extensions&&A(e.extensions,"extensions",t,new Set),t}function J(e){let t=Ae(e);if(t.length>0)throw new C("XENO artifact validation failed",t)}function L(e,t={}){for(let n of e){let i=n.codePointAt(0);if(i===127)return!0;if(!(i>31)&&!(i===9&&t.allowTab===!0)&&!((i===10||i===13)&&t.allowLineBreaks===!0))return!0}return!1}var q="xeno.oracle-report.v1",u=class extends Error{constructor(n){super(`XENO Oracle report is invalid: ${n.join("; ")}`);this.issues=n;this.name="XenoOracleValidationError"}issues;code="XENO_ORACLE_INVALID"},j=class{execute;adjudicate;now;idFactory;constructor(t){if(typeof t?.execute!="function"||typeof t?.adjudicate!="function")throw new TypeError("Oracle execution and adjudication functions are required");this.execute=t.execute,this.adjudicate=t.adjudicate,this.now=t.now??(()=>new Date().toISOString()),this.idFactory=t.idFactory??(n=>`${n}_${(0,$.randomUUID)()}`)}async run(t){let n=W(t.question,"question",128e3),i=t.runId??`oracle_run_${(0,$.randomUUID)()}`;Z(i,"runId");let r=[t.primary,...t.critics,t.adjudicator];we(r,t.primary,t.critics,t.adjudicator);let a=this.now(),d=await this.execute({runId:i,question:n,participant:structuredClone(t.primary)}),p=P(d,t.primary,this.idFactory("opinion"),this.now()),R=await Promise.all(t.critics.map(async l=>{let h=await this.execute({runId:i,question:n,participant:structuredClone(l),primaryOpinion:structuredClone(p)});return P(h,l,this.idFactory("opinion"),this.now())})),c=[p,...R],g=await this.adjudicate({runId:i,question:n,participant:structuredClone(t.adjudicator),opinions:structuredClone(c)}),X=be(g,t.adjudicator,this.now()),G=this.now(),Y=new Set(r.map(_)),Q=new Set(c.flatMap(l=>l.citations.map(h=>h.citationId))),M={schemaVersion:q,reportId:this.idFactory("oracle"),runId:i,question:n,questionHash:y(n),startedAt:a,completedAt:G,opinions:c,adjudication:X,summary:{participantCount:r.length,distinctModelCount:Y.size,totalInputTokens:c.reduce((l,h)=>l+h.usage.inputTokens,X.usage.inputTokens),totalOutputTokens:c.reduce((l,h)=>l+h.usage.outputTokens,X.usage.outputTokens),unresolvedDisagreements:X.disagreements.filter(l=>l.resolution==="unresolved").length,citationCount:Q.size}};return O(M),M}};function O(e){let t=[];e?.schemaVersion!==q&&t.push("schemaVersion must be xeno.oracle-report.v1"),f(e?.reportId,"reportId",t),f(e?.runId,"runId",t),m(e?.question,"question",t,128e3),(e?.questionHash?.algorithm!=="sha256"||e.questionHash.value!==y(e.question??"").value)&&t.push("questionHash does not match question"),I(e?.startedAt,"startedAt",t),I(e?.completedAt,"completedAt",t),Date.parse(e?.completedAt)<Date.parse(e?.startedAt)&&t.push("completedAt cannot precede startedAt"),(!Array.isArray(e?.opinions)||e.opinions.length<2)&&t.push("at least two independent opinions are required");let n=new Set,i=new Set,r=new Set;for(let c of e?.opinions??[]){z(c,t),n.has(c.participant.participantId)&&t.push(`duplicate participant ${c.participant.participantId}`),n.add(c.participant.participantId),i.add(_(c.participant));for(let g of c.citations)r.add(g.citationId)}i.size<2&&t.push("Oracle requires at least two distinct provider/model identities"),B(e?.adjudication,r,t),e?.adjudication?.participant&&(n.add(e.adjudication.participant.participantId),i.add(_(e.adjudication.participant)));let a=[...(e?.opinions??[]).map(c=>c.usage),e?.adjudication?.usage].filter(Boolean),d=a.reduce((c,g)=>c+g.inputTokens,0),p=a.reduce((c,g)=>c+g.outputTokens,0);e?.summary?.participantCount!==n.size&&t.push("summary participantCount is inconsistent"),e?.summary?.distinctModelCount!==i.size&&t.push("summary distinctModelCount is inconsistent"),(e?.summary?.totalInputTokens!==d||e?.summary?.totalOutputTokens!==p)&&t.push("summary token usage is inconsistent"),e?.summary?.citationCount!==r.size&&t.push("summary citationCount is inconsistent");let R=e?.adjudication?.disagreements?.filter(c=>c.resolution==="unresolved").length??0;if(e?.summary?.unresolvedDisagreements!==R&&t.push("summary unresolvedDisagreements is inconsistent"),t.length>0)throw new u([...new Set(t)])}function Ie(e,t){O(e);let n=e,i=k(n),r={schemaVersion:1,artifactId:t.artifactId??`oracle_${y(`${e.runId}:${e.questionHash.value}`).value.slice(0,24)}`,revision:1,kind:"custom:oracle-report",title:"Cross-model Oracle report",description:`${e.summary.distinctModelCount} distinct models; ${e.summary.unresolvedDisagreements} unresolved disagreements`,state:"pending_review",createdAt:e.completedAt,mediaType:"application/vnd.xeno.oracle-report+json",sensitivity:t.sensitivity??"internal",...t.identity?{identity:structuredClone(t.identity)}:{},content:{hash:S(n),sizeBytes:Buffer.byteLength(i,"utf8"),encoding:"utf8",storage:{type:"inline",text:i},redactedPreview:`${e.adjudication.verdict}: ${e.adjudication.conclusion.slice(0,240)}`},provenance:{producer:structuredClone(t.producer),attributes:{distinctModelCount:e.summary.distinctModelCount,participants:e.opinions.map(a=>`${a.participant.providerId}:${a.participant.model}`),adjudicator:`${e.adjudication.participant.providerId}:${e.adjudication.participant.model}`}},...t.accessPolicyId?{accessPolicyId:t.accessPolicyId}:{},extensions:{"xeno.oracle.verdict":e.adjudication.verdict,"xeno.oracle.confidence":e.adjudication.confidence,"xeno.oracle.unresolved":e.summary.unresolvedDisagreements,"xeno.oracle.questionHash":e.questionHash.value}};return J(r),r}function Xe(e){if(e.kind!=="custom:oracle-report"||e.mediaType!=="application/vnd.xeno.oracle-report+json")throw new u([`Artifact ${e.artifactId} is not an Oracle report`]);if(e.content.storage.type!=="inline"||typeof e.content.storage.text!="string")throw new u(["Oracle reports require inline JSON content"]);let t;try{t=JSON.parse(e.content.storage.text)}catch{throw new u(["Oracle report content is invalid JSON"])}if(O(t),S(t).value!==e.content.hash.value)throw new u(["Oracle report content hash does not match the artifact"]);return structuredClone(t)}function P(e,t,n,i){let r=U(e.usage),a={...structuredClone(e.opinion),opinionId:n,participant:structuredClone(t),completedAt:i,usage:r},d=[];if(z(a,d),d.length>0)throw new u(d);return a}function be(e,t,n){let i={...structuredClone(e.adjudication),participant:structuredClone(t),completedAt:n,usage:U(e.usage)},r=[];if(B(i,void 0,r),r.length>0)throw new u(r);return i}function we(e,t,n,i){let r=[];(n.length<1||n.length>8)&&r.push("Oracle requires one through eight critic models"),t.role!=="primary"&&r.push("primary participant role must be primary"),n.some(p=>p.role!=="critic")&&r.push("critic participant roles must be critic"),i.role!=="adjudicator"&&r.push("adjudicator participant role must be adjudicator");let a=new Set,d=new Set;for(let p of e)H(p,r),a.has(p.participantId)&&r.push(`duplicate participant ${p.participantId}`),a.add(p.participantId),d.add(_(p));if(d.size<2&&r.push("Oracle requires at least two distinct provider/model identities"),r.length>0)throw new u([...new Set(r)])}function z(e,t){f(e?.opinionId,"opinionId",t),H(e?.participant,t),m(e?.answer,"opinion answer",t,256e3),m(e?.publicRationale,"opinion publicRationale",t,128e3),V(e?.verdict)||t.push("opinion verdict is invalid"),N(e?.confidence,"opinion confidence",t),I(e?.completedAt,"opinion completedAt",t),K(e?.usage,"opinion usage",t);let n=new Set;for(let r of e?.citations??[])_e(r,t),n.has(r.citationId)&&t.push(`duplicate citation ${r.citationId}`),n.add(r.citationId);let i=new Set;for(let r of e?.claims??[]){f(r?.claimId,"claimId",t),i.has(r.claimId)&&t.push(`duplicate claim ${r.claimId}`),i.add(r.claimId),m(r?.statement,`claim ${r.claimId} statement`,t,32e3),V(r?.verdict)||t.push(`claim ${r.claimId} verdict is invalid`),N(r?.confidence,`claim ${r.claimId} confidence`,t);for(let a of r?.citationIds??[])n.has(a)||t.push(`claim ${r.claimId} references unknown citation ${a}`)}}function B(e,t,n){H(e?.participant,n),e?.participant?.role!=="adjudicator"&&n.push("adjudication participant role must be adjudicator"),m(e?.conclusion,"adjudication conclusion",n,256e3),m(e?.publicRationale,"adjudication publicRationale",n,128e3),V(e?.verdict)||n.push("adjudication verdict is invalid"),N(e?.confidence,"adjudication confidence",n),I(e?.completedAt,"adjudication completedAt",n),K(e?.usage,"adjudication usage",n);let i=new Set;for(let r of e?.disagreements??[])f(r?.disagreementId,"disagreementId",n),i.has(r.disagreementId)&&n.push(`duplicate disagreement ${r.disagreementId}`),i.add(r.disagreementId),m(r?.summary,`disagreement ${r.disagreementId} summary`,n,32e3),(!Array.isArray(r?.participantIds)||r.participantIds.length<2)&&n.push(`disagreement ${r.disagreementId} requires at least two participants`),["low","medium","high"].includes(r?.severity)||n.push(`disagreement ${r.disagreementId} severity is invalid`),r?.resolution!=="resolved"&&r?.resolution!=="unresolved"&&n.push(`disagreement ${r.disagreementId} resolution is invalid`);if(t)for(let r of e?.citationIds??[])t.has(r)||n.push(`adjudication references unknown citation ${r}`)}function H(e,t){f(e?.participantId,"participantId",t),f(e?.providerId,"providerId",t),m(e?.model,"participant model",t,512),e?.connectionId!==void 0&&f(e.connectionId,"connectionId",t),["primary","critic","adjudicator"].includes(e?.role)||t.push("participant role is invalid")}function _e(e,t){f(e?.citationId,"citationId",t);try{let n=new URL(e?.uri);n.protocol!=="https:"&&n.protocol!=="http:"&&t.push(`citation ${e.citationId} must use HTTP(S)`),(n.username||n.password)&&t.push(`citation ${e.citationId} cannot contain credentials`)}catch{t.push(`citation ${e?.citationId??"(unknown)"} URI is invalid`)}e?.retrievedAt!==void 0&&I(e.retrievedAt,`citation ${e.citationId} retrievedAt`,t),e?.contentHash&&(e.contentHash.algorithm!=="sha256"||!/^[a-f0-9]{64}$/u.test(e.contentHash.value))&&t.push(`citation ${e.citationId} contentHash is invalid`)}function U(e){return{inputTokens:F(e?.inputTokens),outputTokens:F(e?.outputTokens)}}function K(e,t,n){(!Number.isInteger(e?.inputTokens)||e.inputTokens<0)&&n.push(`${t} inputTokens must be a non-negative integer`),(!Number.isInteger(e?.outputTokens)||e.outputTokens<0)&&n.push(`${t} outputTokens must be a non-negative integer`)}function F(e){return Number.isInteger(e)&&(e??-1)>=0?e:0}function _(e){return`${e.providerId.trim().toLowerCase()}\0${e.model.trim().toLowerCase()}`}function W(e,t,n){let i=typeof e=="string"?e.trim():"";if(!i||i.length>n||L(i,{allowTab:!0,allowLineBreaks:!0}))throw new u([`${t} must be non-empty bounded text`]);return i}function Z(e,t){let n=typeof e=="string"?e.trim():"";if(!/^[A-Za-z0-9][A-Za-z0-9._:@/-]{0,255}$/u.test(n))throw new u([`${t} is invalid`]);return n}function f(e,t,n){try{Z(e,t)}catch{n.push(`${t} is invalid`)}}function m(e,t,n,i){try{W(e,t,i)}catch{n.push(`${t} must be non-empty bounded text`)}}function N(e,t,n){(typeof e!="number"||!Number.isFinite(e)||e<0||e>1)&&n.push(`${t} must be between 0 and 1`)}function I(e,t,n){(typeof e!="string"||!Number.isFinite(Date.parse(e)))&&n.push(`${t} must be an ISO timestamp`)}function V(e){return e==="supported"||e==="contested"||e==="unsupported"||e==="insufficient-evidence"}0&&(module.exports={XENO_ORACLE_REPORT_SCHEMA_VERSION,XenoOracleCoordinator,XenoOracleValidationError,assertValidXenoOracleReport,xenoArtifactToOracleReport,xenoOracleReportToArtifact});
|
|
1
|
+
"use strict";var R=Object.defineProperty;var ae=Object.getOwnPropertyDescriptor;var ce=Object.getOwnPropertyNames;var de=Object.prototype.hasOwnProperty;var ue=(e,t)=>{for(var n in t)R(e,n,{get:t[n],enumerable:!0})},pe=(e,t,n,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of ce(t))!de.call(e,r)&&r!==n&&R(e,r,{get:()=>t[r],enumerable:!(i=ae(t,r))||i.enumerable});return e};var le=e=>pe(R({},"__esModule",{value:!0}),e);var ke={};ue(ke,{XENO_ORACLE_REPORT_SCHEMA_VERSION:()=>q,XenoOracleCoordinator:()=>$,XenoOracleValidationError:()=>u,assertValidXenoOracleReport:()=>O,xenoArtifactToOracleReport:()=>xe,xenoOracleReportToArtifact:()=>Te});module.exports=le(ke);var k=require("node:crypto");var M=require("node:crypto");function A(e){return{algorithm:"sha256",value:(0,M.createHash)("sha256").update(e).digest("hex")}}function x(e){return JSON.stringify(T(e,new Set))}function S(e){return A(x(e))}function T(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 i=e.map(r=>T(r,t));return t.delete(e),i}let n={};for(let i of Object.keys(e).sort((r,a)=>r.localeCompare(a))){let r=e[i];if(r===void 0)throw new TypeError(`Artifact JSON property ${i} is undefined`);n[i]=T(r,t)}return t.delete(e),n}var F=["plan","requirements","design","task-graph","patch","diff","file","document","diagram","screenshot","recording","browser-snapshot","test-report","review-report","security-report","performance-report","release-report","sbom","provenance","attestation"],P=["draft","pending_review","approved","rejected","superseded","archived"],L=["public","internal","confidential","restricted"],J=["agent","tool","user","system","integration"],z=["requirement","design-decision","risk","task","agent","run","tool-call","edit","commit","test-case","test-run","finding","approval","artifact","release","claim"],B=["decomposes","depends_on","implements","changes","tests","verifies","finds","fixes","reviews","approves","rejects","supersedes","derived_from","produced_by","supports_claim","contradicts_claim","released_as"];var C=require("node:buffer");var fe=/^[a-z0-9][a-z0-9._/-]{0,127}$/,me="custom:";function U(e,t=me){return e.startsWith(t)?fe.test(e.slice(t.length)):!1}var N=class extends Error{code="ARTIFACT_INVALID";issues;constructor(t,n){super(t),this.name="XenoArtifactValidationError",this.issues=n.map(i=>({...i}))}};var ge="[\\u0000-\\u001f\\u007f]",he=new RegExp(ge),Ae=/^[a-f0-9]{64}$/,ye=/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/,Ie=new Set(P),ve=new Set(L),Xe=new Set(J),_e=new Set(F),be=new Set(z),Ee=new Set(B);function o(e,t,n,i){e.push({path:t,code:n,message:i})}function s(e,t,n,i=1024){return typeof e!="string"||e.trim().length===0?(o(n,t,"required_string","Value must be a non-empty string"),!1):(e.length>i&&o(n,t,"string_too_long",`Value must not exceed ${i} characters`),he.test(e)&&o(n,t,"control_character","Value must not contain control characters"),!0)}function _(e,t,n){e!==void 0&&(!Number.isFinite(Date.parse(e))||!e.includes("T"))&&o(n,t,"invalid_timestamp","Value must be an ISO 8601 timestamp")}function y(e,t,n,i){typeof e=="string"&&e.startsWith(t)&&(U(e,t)||o(i,n,"invalid_custom_name",`Custom name after ${t} is invalid`))}function Oe(e,t,n){if(!e||typeof e!="object"){o(n,t,"missing_actor","Actor is required");return}s(e.kind,`${t}.kind`,n,64),Xe.has(e.kind)||o(n,`${t}.kind`,"unknown_actor_kind","Actor kind is not supported"),s(e.id,`${t}.id`,n,512),e?.displayName!==void 0&&s(e.displayName,`${t}.displayName`,n,512),e?.profileFingerprint!==void 0&&!/^[a-f0-9]{64}$/.test(e.profileFingerprint)&&o(n,`${t}.profileFingerprint`,"invalid_fingerprint","Profile fingerprint must be 64 lowercase hexadecimal characters")}function we(e,t,n){if(!e||typeof e!="object"){o(n,t,"invalid_anchor","Anchor must be an object");return}switch(e.kind){case"file":s(e.path,`${t}.path`,n,4096);break;case"source-line":s(e.path,`${t}.path`,n,4096),(!Number.isInteger(e.startLine)||e.startLine<1)&&o(n,`${t}.startLine`,"invalid_line","startLine must be a positive integer"),e.endLine!==void 0&&(!Number.isInteger(e.endLine)||e.endLine<e.startLine)&&o(n,`${t}.endLine`,"invalid_line_range","endLine must be greater than or equal to startLine");break;case"diff-hunk":s(e.path,`${t}.path`,n,4096),s(e.hunkId,`${t}.hunkId`,n,512);break;case"symbol":s(e.path,`${t}.path`,n,4096),s(e.symbol,`${t}.symbol`,n,1024);break;case"dom-node":s(e.pageId,`${t}.pageId`,n,512),!e.selector&&!e.accessibilityId&&!e.snapshotArtifactId&&o(n,t,"missing_dom_locator","DOM anchors require a selector, accessibility ID, or snapshot artifact ID");break;case"timeline":s(e.recordingArtifactId,`${t}.recordingArtifactId`,n,512),(!Number.isFinite(e.startMs)||e.startMs<0)&&o(n,`${t}.startMs`,"invalid_time","startMs must be a non-negative finite number"),e.endMs!==void 0&&(!Number.isFinite(e.endMs)||e.endMs<e.startMs)&&o(n,`${t}.endMs`,"invalid_time_range","endMs must be greater than or equal to startMs");break;case"region":s(e.mediaArtifactId,`${t}.mediaArtifactId`,n,512),[e.x,e.y,e.width,e.height].every(Number.isFinite)?(e.width<=0||e.height<=0)&&o(n,t,"invalid_region_size","Region width and height must be positive"):o(n,t,"invalid_region","Region coordinates must be finite numbers");break;case"artifact":s(e.artifactId,`${t}.artifactId`,n,512);break;default:typeof e.kind!="string"||!e.kind.startsWith("custom:")?o(n,`${t}.kind`,"unknown_anchor","Anchor kind is not supported"):y(e.kind,"custom:",`${t}.kind`,n)}}function I(e,t,n,i){if(!(e===null||typeof e=="string"||typeof e=="boolean")){if(typeof e=="number"){Number.isFinite(e)||o(n,t,"non_finite_number","JSON numbers must be finite");return}if(typeof e!="object"){o(n,t,"non_json_value","Value must be JSON-serializable");return}if(i.has(e)){o(n,t,"cyclic_value","Value must not contain cycles");return}if(i.add(e),Array.isArray(e))e.forEach((r,a)=>I(r,`${t}[${a}]`,n,i));else for(let[r,a]of Object.entries(e))a===void 0?o(n,`${t}.${r}`,"undefined_value","Undefined is not valid JSON"):I(a,`${t}.${r}`,n,i);i.delete(e)}}function Re(e){let t=[];if(!e||typeof e!="object")return[{path:"$",code:"invalid_artifact",message:"Artifact must be an object"}];if(e.schemaVersion!==1&&o(t,"schemaVersion","unsupported_schema",`schemaVersion must be ${1}`),s(e.artifactId,"artifactId",t,512),(!Number.isInteger(e.revision)||e.revision<1)&&o(t,"revision","invalid_revision","revision must be a positive integer"),s(e.kind,"kind",t,160),typeof e.kind=="string"&&!_e.has(e.kind)&&!e.kind.startsWith("custom:")&&o(t,"kind","unknown_artifact_kind","Artifact kind is not supported"),y(e.kind,"custom:","kind",t),s(e.title,"title",t,1024),e.description!==void 0&&s(e.description,"description",t,32768),s(e.state,"state",t,64),Ie.has(e.state)||o(t,"state","unknown_state","Artifact state is not supported"),s(e.createdAt,"createdAt",t,128),_(e.createdAt,"createdAt",t),_(e.updatedAt,"updatedAt",t),e.updatedAt&&Number.isFinite(Date.parse(e.createdAt))&&Date.parse(e.updatedAt)<Date.parse(e.createdAt)&&o(t,"updatedAt","timestamp_order","updatedAt must not precede createdAt"),s(e.mediaType,"mediaType",t,255),s(e.sensitivity,"sensitivity",t,64),ve.has(e.sensitivity)||o(t,"sensitivity","unknown_sensitivity","Sensitivity is not supported"),e.identity)for(let[i,r]of Object.entries(e.identity))r!==void 0&&s(r,`identity.${i}`,t,512);if(!e.content||typeof e.content!="object")o(t,"content","missing_content","content descriptor is required");else{!e.content.hash||typeof e.content.hash!="object"?o(t,"content.hash","missing_hash","content hash is required"):(s(e.content.hash.algorithm,"content.hash.algorithm",t,128),y(e.content.hash.algorithm,"custom:","content.hash.algorithm",t),typeof e.content.hash.algorithm=="string"&&e.content.hash.algorithm!=="sha256"&&!e.content.hash.algorithm.startsWith("custom:")&&o(t,"content.hash.algorithm","unknown_hash_algorithm","Hash algorithm is not supported"),s(e.content.hash.value,"content.hash.value",t,512),e.content.hash.algorithm==="sha256"&&!Ae.test(e.content.hash.value)&&o(t,"content.hash.value","invalid_sha256","SHA-256 hash must be 64 lowercase hexadecimal characters")),(!Number.isSafeInteger(e.content.sizeBytes)||e.content.sizeBytes<0)&&o(t,"content.sizeBytes","invalid_size","sizeBytes must be a non-negative safe integer");let i=e.content.storage;if(!i||typeof i!="object")o(t,"content.storage","missing_storage","storage reference is required");else if(i.type==="inline")if(i.text===void 0==(i.base64===void 0))o(t,"content.storage","invalid_inline_storage","Inline storage requires exactly one of text or base64");else{let r;i.text!==void 0?r=C.Buffer.from(i.text,"utf8"):i.base64!==void 0&&(ye.test(i.base64)?r=C.Buffer.from(i.base64,"base64"):o(t,"content.storage.base64","invalid_base64","Inline base64 content is malformed")),r&&e.content.sizeBytes!==r.byteLength&&o(t,"content.sizeBytes","content_size_mismatch","sizeBytes does not match inline content"),r&&e.content.hash.algorithm==="sha256"&&A(r).value!==e.content.hash.value&&o(t,"content.hash.value","content_hash_mismatch","Hash does not match inline content")}else i.type==="file"?s(i.path,"content.storage.path",t,4096):i.type==="blob"?s(i.uri,"content.storage.uri",t,8192):i.type==="git"?(s(i.commit,"content.storage.commit",t,512),s(i.path,"content.storage.path",t,4096)):i.type==="url"?(s(i.url,"content.storage.url",t,8192),_(i.expiresAt,"content.storage.expiresAt",t)):i.type==="external"?(s(i.provider,"content.storage.provider",t,255),s(i.locator,"content.storage.locator",t,8192)):o(t,"content.storage.type","unknown_storage","Storage type is not supported");e.content.encoding!==void 0&&(typeof e.content.encoding!="string"||e.content.encoding!=="utf8"&&e.content.encoding!=="base64"&&e.content.encoding!=="binary"&&!e.content.encoding.startsWith("custom:"))&&o(t,"content.encoding","unknown_encoding","Content encoding is not supported"),y(e.content.encoding,"custom:","content.encoding",t)}!e.provenance||typeof e.provenance!="object"?o(t,"provenance","missing_provenance","provenance is required"):(Oe(e.provenance.producer,"provenance.producer",t),e.provenance.capabilityLeaseIds?.forEach((i,r)=>s(i,`provenance.capabilityLeaseIds[${r}]`,t,512)),e.provenance.sourceArtifactIds?.forEach((i,r)=>s(i,`provenance.sourceArtifactIds[${r}]`,t,512)),e.provenance.attributes&&I(e.provenance.attributes,"provenance.attributes",t,new Set));let n=new Set;return e.relationships?.forEach((i,r)=>{let a=`relationships[${r}]`;s(i.relation,`${a}.relation`,t,160),typeof i.relation=="string"&&!Ee.has(i.relation)&&!i.relation.startsWith("custom:")&&o(t,`${a}.relation`,"unknown_relationship","Relationship type is not supported"),y(i.relation,"custom:",`${a}.relation`,t),s(i.target?.type,`${a}.target.type`,t,160),typeof i.target?.type=="string"&&!be.has(i.target.type)&&!i.target.type.startsWith("custom:")&&o(t,`${a}.target.type`,"unknown_reference_type","Evidence reference type is not supported"),y(i.target?.type,"custom:",`${a}.target.type`,t),s(i.target?.id,`${a}.target.id`,t,512);let d=`${i.relation}:${i.target?.type}:${i.target?.id}:${i.target?.revision??""}`;n.has(d)&&o(t,a,"duplicate_relationship","Duplicate relationship"),n.add(d),i.attributes&&I(i.attributes,`${a}.attributes`,t,new Set)}),e.anchors?.forEach((i,r)=>we(i,`anchors[${r}]`,t)),e.revision===1&&e.predecessorRevision!==void 0&&o(t,"predecessorRevision","unexpected_predecessor","First revision cannot have a predecessor"),e.revision>1&&(!Number.isInteger(e.predecessorRevision)||(e.predecessorRevision??0)>=e.revision)&&o(t,"predecessorRevision","invalid_predecessor","Later revisions require an earlier predecessor revision"),_(e.retention?.retainUntil,"retention.retainUntil",t),e.retention?.legalHold!==void 0&&typeof e.retention.legalHold!="boolean"&&o(t,"retention.legalHold","invalid_boolean","legalHold must be a boolean"),e.extensions&&I(e.extensions,"extensions",t,new Set),t}function K(e){let t=Re(e);if(t.length>0)throw new N("XENO artifact validation failed",t)}function W(e,t={}){for(let n of e){let i=n.codePointAt(0);if(i===127)return!0;if(!(i>31)&&!(i===9&&t.allowTab===!0)&&!((i===10||i===13)&&t.allowLineBreaks===!0))return!0}return!1}var q="xeno.oracle-report.v1",u=class extends Error{constructor(n){super(`XENO Oracle report is invalid: ${n.join("; ")}`);this.issues=n;this.name="XenoOracleValidationError"}issues;code="XENO_ORACLE_INVALID"},$=class{execute;adjudicate;now;idFactory;constructor(t){if(typeof t?.execute!="function"||typeof t?.adjudicate!="function")throw new TypeError("Oracle execution and adjudication functions are required");this.execute=t.execute,this.adjudicate=t.adjudicate,this.now=t.now??(()=>new Date().toISOString()),this.idFactory=t.idFactory??(n=>`${n}_${(0,k.randomUUID)()}`)}async run(t){let n=ne(t.question,"question",128e3),i=t.runId??`oracle_run_${(0,k.randomUUID)()}`;ie(i,"runId");let r=[t.primary,...t.critics,t.adjudicator];Ce(r,t.primary,t.critics,t.adjudicator);let a=this.now(),d=await this.execute({runId:i,question:n,participant:structuredClone(t.primary)}),p=Y(d,t.primary,this.idFactory("opinion"),this.now()),w=await Promise.all(t.critics.map(async l=>{let h=await this.execute({runId:i,question:n,participant:structuredClone(l),primaryOpinion:structuredClone(p)});return Y(h,l,this.idFactory("opinion"),this.now())})),c=[p,...w],g=await this.adjudicate({runId:i,question:n,participant:structuredClone(t.adjudicator),opinions:structuredClone(c)}),X=Se(g,t.adjudicator,this.now()),re=this.now(),oe=new Set(r.map(E)),se=new Set(c.flatMap(l=>l.citations.map(h=>h.citationId))),D={schemaVersion:q,reportId:this.idFactory("oracle"),runId:i,question:n,questionHash:A(n),startedAt:a,completedAt:re,opinions:c,adjudication:X,summary:{participantCount:r.length,distinctModelCount:oe.size,totalInputTokens:c.reduce((l,h)=>l+h.usage.inputTokens,X.usage.inputTokens),totalOutputTokens:c.reduce((l,h)=>l+h.usage.outputTokens,X.usage.outputTokens),unresolvedDisagreements:X.disagreements.filter(l=>l.resolution==="unresolved").length,citationCount:se.size}};return O(D),D}};function O(e){let t=[];e?.schemaVersion!==q&&t.push("schemaVersion must be xeno.oracle-report.v1"),f(e?.reportId,"reportId",t),f(e?.runId,"runId",t),m(e?.question,"question",t,128e3),(e?.questionHash?.algorithm!=="sha256"||e.questionHash.value!==A(e.question??"").value)&&t.push("questionHash does not match question"),v(e?.startedAt,"startedAt",t),v(e?.completedAt,"completedAt",t),Date.parse(e?.completedAt)<Date.parse(e?.startedAt)&&t.push("completedAt cannot precede startedAt"),(!Array.isArray(e?.opinions)||e.opinions.length<2)&&t.push("at least two independent opinions are required");let n=new Set,i=new Set,r=new Set;for(let c of e?.opinions??[]){Z(c,t),n.has(c.participant.participantId)&&t.push(`duplicate participant ${c.participant.participantId}`),n.add(c.participant.participantId),i.add(E(c.participant));for(let g of c.citations)r.add(g.citationId)}i.size<2&&t.push("Oracle requires at least two distinct provider/model identities"),Q(e?.adjudication,r,t),e?.adjudication?.participant&&(n.add(e.adjudication.participant.participantId),i.add(E(e.adjudication.participant)));let a=[...(e?.opinions??[]).map(c=>c.usage),e?.adjudication?.usage].filter(Boolean),d=a.reduce((c,g)=>c+g.inputTokens,0),p=a.reduce((c,g)=>c+g.outputTokens,0);e?.summary?.participantCount!==n.size&&t.push("summary participantCount is inconsistent"),e?.summary?.distinctModelCount!==i.size&&t.push("summary distinctModelCount is inconsistent"),(e?.summary?.totalInputTokens!==d||e?.summary?.totalOutputTokens!==p)&&t.push("summary token usage is inconsistent"),e?.summary?.citationCount!==r.size&&t.push("summary citationCount is inconsistent");let w=e?.adjudication?.disagreements?.filter(c=>c.resolution==="unresolved").length??0;if(e?.summary?.unresolvedDisagreements!==w&&t.push("summary unresolvedDisagreements is inconsistent"),t.length>0)throw new u([...new Set(t)])}function Te(e,t){O(e);let n=e,i=x(n),r={schemaVersion:1,artifactId:t.artifactId??`oracle_${A(`${e.runId}:${e.questionHash.value}`).value.slice(0,24)}`,revision:1,kind:"custom:oracle-report",title:"Cross-model Oracle report",description:`${e.summary.distinctModelCount} distinct models; ${e.summary.unresolvedDisagreements} unresolved disagreements`,state:"pending_review",createdAt:e.completedAt,mediaType:"application/vnd.xeno.oracle-report+json",sensitivity:t.sensitivity??"internal",...t.identity?{identity:structuredClone(t.identity)}:{},content:{hash:S(n),sizeBytes:Buffer.byteLength(i,"utf8"),encoding:"utf8",storage:{type:"inline",text:i},redactedPreview:`${e.adjudication.verdict}: ${e.adjudication.conclusion.slice(0,240)}`},provenance:{producer:structuredClone(t.producer),attributes:{distinctModelCount:e.summary.distinctModelCount,participants:e.opinions.map(a=>`${a.participant.providerId}:${a.participant.model}`),adjudicator:`${e.adjudication.participant.providerId}:${e.adjudication.participant.model}`}},...t.accessPolicyId?{accessPolicyId:t.accessPolicyId}:{},extensions:{"xeno.oracle.verdict":e.adjudication.verdict,"xeno.oracle.confidence":e.adjudication.confidence,"xeno.oracle.unresolved":e.summary.unresolvedDisagreements,"xeno.oracle.questionHash":e.questionHash.value}};return K(r),r}function xe(e){if(e.kind!=="custom:oracle-report"||e.mediaType!=="application/vnd.xeno.oracle-report+json")throw new u([`Artifact ${e.artifactId} is not an Oracle report`]);if(e.content.storage.type!=="inline"||typeof e.content.storage.text!="string")throw new u(["Oracle reports require inline JSON content"]);let t;try{t=JSON.parse(e.content.storage.text)}catch{throw new u(["Oracle report content is invalid JSON"])}if(O(t),S(t).value!==e.content.hash.value)throw new u(["Oracle report content hash does not match the artifact"]);return structuredClone(t)}function Y(e,t,n,i){let r=ee(e.usage),a={...structuredClone(e.opinion),opinionId:n,participant:structuredClone(t),completedAt:i,usage:r},d=[];if(Z(a,d),d.length>0)throw new u(d);return a}function Se(e,t,n){let i={...structuredClone(e.adjudication),participant:structuredClone(t),completedAt:n,usage:ee(e.usage)},r=[];if(Q(i,void 0,r),r.length>0)throw new u(r);return i}function Ce(e,t,n,i){let r=[];(n.length<1||n.length>8)&&r.push("Oracle requires one through eight critic models"),t.role!=="primary"&&r.push("primary participant role must be primary"),n.some(p=>p.role!=="critic")&&r.push("critic participant roles must be critic"),i.role!=="adjudicator"&&r.push("adjudicator participant role must be adjudicator");let a=new Set,d=new Set;for(let p of e)H(p,r),a.has(p.participantId)&&r.push(`duplicate participant ${p.participantId}`),a.add(p.participantId),d.add(E(p));if(d.size<2&&r.push("Oracle requires at least two distinct provider/model identities"),r.length>0)throw new u([...new Set(r)])}function Z(e,t){f(e?.opinionId,"opinionId",t),H(e?.participant,t),m(e?.answer,"opinion answer",t,256e3),m(e?.publicRationale,"opinion publicRationale",t,128e3),V(e?.verdict)||t.push("opinion verdict is invalid"),j(e?.confidence,"opinion confidence",t),v(e?.completedAt,"opinion completedAt",t),te(e?.usage,"opinion usage",t);let n=new Set;for(let r of e?.citations??[])Ne(r,t),n.has(r.citationId)&&t.push(`duplicate citation ${r.citationId}`),n.add(r.citationId);let i=new Set;for(let r of e?.claims??[]){f(r?.claimId,"claimId",t),i.has(r.claimId)&&t.push(`duplicate claim ${r.claimId}`),i.add(r.claimId),m(r?.statement,`claim ${r.claimId} statement`,t,32e3),V(r?.verdict)||t.push(`claim ${r.claimId} verdict is invalid`),j(r?.confidence,`claim ${r.claimId} confidence`,t);for(let a of r?.citationIds??[])n.has(a)||t.push(`claim ${r.claimId} references unknown citation ${a}`)}}function Q(e,t,n){H(e?.participant,n),e?.participant?.role!=="adjudicator"&&n.push("adjudication participant role must be adjudicator"),m(e?.conclusion,"adjudication conclusion",n,256e3),m(e?.publicRationale,"adjudication publicRationale",n,128e3),V(e?.verdict)||n.push("adjudication verdict is invalid"),j(e?.confidence,"adjudication confidence",n),v(e?.completedAt,"adjudication completedAt",n),te(e?.usage,"adjudication usage",n);let i=new Set;for(let r of e?.disagreements??[])f(r?.disagreementId,"disagreementId",n),i.has(r.disagreementId)&&n.push(`duplicate disagreement ${r.disagreementId}`),i.add(r.disagreementId),m(r?.summary,`disagreement ${r.disagreementId} summary`,n,32e3),(!Array.isArray(r?.participantIds)||r.participantIds.length<2)&&n.push(`disagreement ${r.disagreementId} requires at least two participants`),["low","medium","high"].includes(r?.severity)||n.push(`disagreement ${r.disagreementId} severity is invalid`),r?.resolution!=="resolved"&&r?.resolution!=="unresolved"&&n.push(`disagreement ${r.disagreementId} resolution is invalid`);if(t)for(let r of e?.citationIds??[])t.has(r)||n.push(`adjudication references unknown citation ${r}`)}function H(e,t){f(e?.participantId,"participantId",t),f(e?.providerId,"providerId",t),m(e?.model,"participant model",t,512),e?.connectionId!==void 0&&f(e.connectionId,"connectionId",t),["primary","critic","adjudicator"].includes(e?.role)||t.push("participant role is invalid")}function Ne(e,t){f(e?.citationId,"citationId",t);try{let n=new URL(e?.uri);n.protocol!=="https:"&&n.protocol!=="http:"&&t.push(`citation ${e.citationId} must use HTTP(S)`),(n.username||n.password)&&t.push(`citation ${e.citationId} cannot contain credentials`)}catch{t.push(`citation ${e?.citationId??"(unknown)"} URI is invalid`)}e?.retrievedAt!==void 0&&v(e.retrievedAt,`citation ${e.citationId} retrievedAt`,t),e?.contentHash&&(e.contentHash.algorithm!=="sha256"||!/^[a-f0-9]{64}$/u.test(e.contentHash.value))&&t.push(`citation ${e.citationId} contentHash is invalid`)}function ee(e){return{inputTokens:G(e?.inputTokens),outputTokens:G(e?.outputTokens)}}function te(e,t,n){(!Number.isInteger(e?.inputTokens)||e.inputTokens<0)&&n.push(`${t} inputTokens must be a non-negative integer`),(!Number.isInteger(e?.outputTokens)||e.outputTokens<0)&&n.push(`${t} outputTokens must be a non-negative integer`)}function G(e){return Number.isInteger(e)&&(e??-1)>=0?e:0}function E(e){return`${e.providerId.trim().toLowerCase()}\0${e.model.trim().toLowerCase()}`}function ne(e,t,n){let i=typeof e=="string"?e.trim():"";if(!i||i.length>n||W(i,{allowTab:!0,allowLineBreaks:!0}))throw new u([`${t} must be non-empty bounded text`]);return i}function ie(e,t){let n=typeof e=="string"?e.trim():"";if(!/^[A-Za-z0-9][A-Za-z0-9._:@/-]{0,255}$/u.test(n))throw new u([`${t} is invalid`]);return n}function f(e,t,n){try{ie(e,t)}catch{n.push(`${t} is invalid`)}}function m(e,t,n,i){try{ne(e,t,i)}catch{n.push(`${t} must be non-empty bounded text`)}}function j(e,t,n){(typeof e!="number"||!Number.isFinite(e)||e<0||e>1)&&n.push(`${t} must be between 0 and 1`)}function v(e,t,n){(typeof e!="string"||!Number.isFinite(Date.parse(e)))&&n.push(`${t} must be an ISO timestamp`)}function V(e){return e==="supported"||e==="contested"||e==="unsupported"||e==="insufficient-evidence"}0&&(module.exports={XENO_ORACLE_REPORT_SCHEMA_VERSION,XenoOracleCoordinator,XenoOracleValidationError,assertValidXenoOracleReport,xenoArtifactToOracleReport,xenoOracleReportToArtifact});
|
package/dist/oracle/index.d.cts
CHANGED
|
@@ -4,9 +4,45 @@ type XenoJsonValue = XenoJsonPrimitive | XenoJsonObject | XenoJsonValue[];
|
|
|
4
4
|
interface XenoJsonObject {
|
|
5
5
|
[key: string]: XenoJsonValue;
|
|
6
6
|
}
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
declare const XENO_BUILTIN_ARTIFACT_KINDS: readonly [
|
|
8
|
+
"plan",
|
|
9
|
+
"requirements",
|
|
10
|
+
"design",
|
|
11
|
+
"task-graph",
|
|
12
|
+
"patch",
|
|
13
|
+
"diff",
|
|
14
|
+
"file",
|
|
15
|
+
"document",
|
|
16
|
+
"diagram",
|
|
17
|
+
"screenshot",
|
|
18
|
+
"recording",
|
|
19
|
+
"browser-snapshot",
|
|
20
|
+
"test-report",
|
|
21
|
+
"review-report",
|
|
22
|
+
"security-report",
|
|
23
|
+
"performance-report",
|
|
24
|
+
"release-report",
|
|
25
|
+
"sbom",
|
|
26
|
+
"provenance",
|
|
27
|
+
"attestation"
|
|
28
|
+
];
|
|
29
|
+
type XenoArtifactKind = (typeof XENO_BUILTIN_ARTIFACT_KINDS)[number] | `custom:${string}`;
|
|
30
|
+
declare const XENO_ARTIFACT_STATES: readonly [
|
|
31
|
+
"draft",
|
|
32
|
+
"pending_review",
|
|
33
|
+
"approved",
|
|
34
|
+
"rejected",
|
|
35
|
+
"superseded",
|
|
36
|
+
"archived"
|
|
37
|
+
];
|
|
38
|
+
type XenoArtifactState = (typeof XENO_ARTIFACT_STATES)[number];
|
|
39
|
+
declare const XENO_ARTIFACT_SENSITIVITIES: readonly [
|
|
40
|
+
"public",
|
|
41
|
+
"internal",
|
|
42
|
+
"confidential",
|
|
43
|
+
"restricted"
|
|
44
|
+
];
|
|
45
|
+
type XenoArtifactSensitivity = (typeof XENO_ARTIFACT_SENSITIVITIES)[number];
|
|
10
46
|
interface XenoContentHash {
|
|
11
47
|
algorithm: "sha256" | `custom:${string}`;
|
|
12
48
|
value: string;
|
|
@@ -51,7 +87,14 @@ interface XenoArtifactIdentity {
|
|
|
51
87
|
workspaceId?: string;
|
|
52
88
|
repositoryId?: string;
|
|
53
89
|
}
|
|
54
|
-
|
|
90
|
+
declare const XENO_ARTIFACT_ACTOR_KINDS: readonly [
|
|
91
|
+
"agent",
|
|
92
|
+
"tool",
|
|
93
|
+
"user",
|
|
94
|
+
"system",
|
|
95
|
+
"integration"
|
|
96
|
+
];
|
|
97
|
+
type XenoArtifactActorKind = (typeof XENO_ARTIFACT_ACTOR_KINDS)[number];
|
|
55
98
|
interface XenoArtifactActor {
|
|
56
99
|
kind: XenoArtifactActorKind;
|
|
57
100
|
id: string;
|
|
@@ -68,8 +111,45 @@ interface XenoArtifactProvenance {
|
|
|
68
111
|
sourceArtifactIds?: string[];
|
|
69
112
|
attributes?: XenoJsonObject;
|
|
70
113
|
}
|
|
71
|
-
|
|
72
|
-
|
|
114
|
+
declare const XENO_EVIDENCE_NODE_TYPES: readonly [
|
|
115
|
+
"requirement",
|
|
116
|
+
"design-decision",
|
|
117
|
+
"risk",
|
|
118
|
+
"task",
|
|
119
|
+
"agent",
|
|
120
|
+
"run",
|
|
121
|
+
"tool-call",
|
|
122
|
+
"edit",
|
|
123
|
+
"commit",
|
|
124
|
+
"test-case",
|
|
125
|
+
"test-run",
|
|
126
|
+
"finding",
|
|
127
|
+
"approval",
|
|
128
|
+
"artifact",
|
|
129
|
+
"release",
|
|
130
|
+
"claim"
|
|
131
|
+
];
|
|
132
|
+
type XenoEvidenceNodeType = (typeof XENO_EVIDENCE_NODE_TYPES)[number] | `custom:${string}`;
|
|
133
|
+
declare const XENO_EVIDENCE_EDGE_TYPES: readonly [
|
|
134
|
+
"decomposes",
|
|
135
|
+
"depends_on",
|
|
136
|
+
"implements",
|
|
137
|
+
"changes",
|
|
138
|
+
"tests",
|
|
139
|
+
"verifies",
|
|
140
|
+
"finds",
|
|
141
|
+
"fixes",
|
|
142
|
+
"reviews",
|
|
143
|
+
"approves",
|
|
144
|
+
"rejects",
|
|
145
|
+
"supersedes",
|
|
146
|
+
"derived_from",
|
|
147
|
+
"produced_by",
|
|
148
|
+
"supports_claim",
|
|
149
|
+
"contradicts_claim",
|
|
150
|
+
"released_as"
|
|
151
|
+
];
|
|
152
|
+
type XenoEvidenceEdgeType = (typeof XENO_EVIDENCE_EDGE_TYPES)[number] | `custom:${string}`;
|
|
73
153
|
interface XenoEvidenceReference {
|
|
74
154
|
type: XenoEvidenceNodeType;
|
|
75
155
|
id: string;
|
package/dist/oracle/index.d.ts
CHANGED
|
@@ -4,9 +4,45 @@ type XenoJsonValue = XenoJsonPrimitive | XenoJsonObject | XenoJsonValue[];
|
|
|
4
4
|
interface XenoJsonObject {
|
|
5
5
|
[key: string]: XenoJsonValue;
|
|
6
6
|
}
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
declare const XENO_BUILTIN_ARTIFACT_KINDS: readonly [
|
|
8
|
+
"plan",
|
|
9
|
+
"requirements",
|
|
10
|
+
"design",
|
|
11
|
+
"task-graph",
|
|
12
|
+
"patch",
|
|
13
|
+
"diff",
|
|
14
|
+
"file",
|
|
15
|
+
"document",
|
|
16
|
+
"diagram",
|
|
17
|
+
"screenshot",
|
|
18
|
+
"recording",
|
|
19
|
+
"browser-snapshot",
|
|
20
|
+
"test-report",
|
|
21
|
+
"review-report",
|
|
22
|
+
"security-report",
|
|
23
|
+
"performance-report",
|
|
24
|
+
"release-report",
|
|
25
|
+
"sbom",
|
|
26
|
+
"provenance",
|
|
27
|
+
"attestation"
|
|
28
|
+
];
|
|
29
|
+
type XenoArtifactKind = (typeof XENO_BUILTIN_ARTIFACT_KINDS)[number] | `custom:${string}`;
|
|
30
|
+
declare const XENO_ARTIFACT_STATES: readonly [
|
|
31
|
+
"draft",
|
|
32
|
+
"pending_review",
|
|
33
|
+
"approved",
|
|
34
|
+
"rejected",
|
|
35
|
+
"superseded",
|
|
36
|
+
"archived"
|
|
37
|
+
];
|
|
38
|
+
type XenoArtifactState = (typeof XENO_ARTIFACT_STATES)[number];
|
|
39
|
+
declare const XENO_ARTIFACT_SENSITIVITIES: readonly [
|
|
40
|
+
"public",
|
|
41
|
+
"internal",
|
|
42
|
+
"confidential",
|
|
43
|
+
"restricted"
|
|
44
|
+
];
|
|
45
|
+
type XenoArtifactSensitivity = (typeof XENO_ARTIFACT_SENSITIVITIES)[number];
|
|
10
46
|
interface XenoContentHash {
|
|
11
47
|
algorithm: "sha256" | `custom:${string}`;
|
|
12
48
|
value: string;
|
|
@@ -51,7 +87,14 @@ interface XenoArtifactIdentity {
|
|
|
51
87
|
workspaceId?: string;
|
|
52
88
|
repositoryId?: string;
|
|
53
89
|
}
|
|
54
|
-
|
|
90
|
+
declare const XENO_ARTIFACT_ACTOR_KINDS: readonly [
|
|
91
|
+
"agent",
|
|
92
|
+
"tool",
|
|
93
|
+
"user",
|
|
94
|
+
"system",
|
|
95
|
+
"integration"
|
|
96
|
+
];
|
|
97
|
+
type XenoArtifactActorKind = (typeof XENO_ARTIFACT_ACTOR_KINDS)[number];
|
|
55
98
|
interface XenoArtifactActor {
|
|
56
99
|
kind: XenoArtifactActorKind;
|
|
57
100
|
id: string;
|
|
@@ -68,8 +111,45 @@ interface XenoArtifactProvenance {
|
|
|
68
111
|
sourceArtifactIds?: string[];
|
|
69
112
|
attributes?: XenoJsonObject;
|
|
70
113
|
}
|
|
71
|
-
|
|
72
|
-
|
|
114
|
+
declare const XENO_EVIDENCE_NODE_TYPES: readonly [
|
|
115
|
+
"requirement",
|
|
116
|
+
"design-decision",
|
|
117
|
+
"risk",
|
|
118
|
+
"task",
|
|
119
|
+
"agent",
|
|
120
|
+
"run",
|
|
121
|
+
"tool-call",
|
|
122
|
+
"edit",
|
|
123
|
+
"commit",
|
|
124
|
+
"test-case",
|
|
125
|
+
"test-run",
|
|
126
|
+
"finding",
|
|
127
|
+
"approval",
|
|
128
|
+
"artifact",
|
|
129
|
+
"release",
|
|
130
|
+
"claim"
|
|
131
|
+
];
|
|
132
|
+
type XenoEvidenceNodeType = (typeof XENO_EVIDENCE_NODE_TYPES)[number] | `custom:${string}`;
|
|
133
|
+
declare const XENO_EVIDENCE_EDGE_TYPES: readonly [
|
|
134
|
+
"decomposes",
|
|
135
|
+
"depends_on",
|
|
136
|
+
"implements",
|
|
137
|
+
"changes",
|
|
138
|
+
"tests",
|
|
139
|
+
"verifies",
|
|
140
|
+
"finds",
|
|
141
|
+
"fixes",
|
|
142
|
+
"reviews",
|
|
143
|
+
"approves",
|
|
144
|
+
"rejects",
|
|
145
|
+
"supersedes",
|
|
146
|
+
"derived_from",
|
|
147
|
+
"produced_by",
|
|
148
|
+
"supports_claim",
|
|
149
|
+
"contradicts_claim",
|
|
150
|
+
"released_as"
|
|
151
|
+
];
|
|
152
|
+
type XenoEvidenceEdgeType = (typeof XENO_EVIDENCE_EDGE_TYPES)[number] | `custom:${string}`;
|
|
73
153
|
interface XenoEvidenceReference {
|
|
74
154
|
type: XenoEvidenceNodeType;
|
|
75
155
|
id: string;
|
package/dist/oracle/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{randomUUID as H}from"node:crypto";import{createHash as Y}from"node:crypto";function y(e){return{algorithm:"sha256",value:Y("sha256").update(e).digest("hex")}}function E(e){return JSON.stringify(R(e,new Set))}function x(e){return y(E(e))}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 i=e.map(r=>R(r,t));return t.delete(e),i}let n={};for(let i of Object.keys(e).sort((r,a)=>r.localeCompare(a))){let r=e[i];if(r===void 0)throw new TypeError(`Artifact JSON property ${i} is undefined`);n[i]=R(r,t)}return t.delete(e),n}import{Buffer as N}from"node:buffer";var k=class extends Error{code="ARTIFACT_INVALID";issues;constructor(t,n){super(t),this.name="XenoArtifactValidationError",this.issues=n.map(i=>({...i}))}};var Q=/^[a-z0-9][a-z0-9._/-]{0,127}$/,ee="[\\u0000-\\u001f\\u007f]",te=new RegExp(ee),ne=/^[a-f0-9]{64}$/,ie=/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/,re=new Set(["draft","pending_review","approved","rejected","superseded","archived"]),oe=new Set(["public","internal","confidential","restricted"]),se=new Set(["agent","tool","user","system","integration"]),ae=new Set(["plan","requirements","design","task-graph","patch","diff","file","document","diagram","screenshot","recording","browser-snapshot","test-report","review-report","security-report","performance-report","release-report","sbom","provenance","attestation"]),ce=new Set(["requirement","design-decision","risk","task","agent","run","tool-call","edit","commit","test-case","test-run","finding","approval","artifact","release","claim"]),de=new Set(["decomposes","depends_on","implements","changes","tests","verifies","finds","fixes","reviews","approves","rejects","supersedes","derived_from","produced_by","supports_claim","contradicts_claim","released_as"]);function o(e,t,n,i){e.push({path:t,code:n,message:i})}function s(e,t,n,i=1024){return typeof e!="string"||e.trim().length===0?(o(n,t,"required_string","Value must be a non-empty string"),!1):(e.length>i&&o(n,t,"string_too_long",`Value must not exceed ${i} characters`),te.test(e)&&o(n,t,"control_character","Value must not contain control characters"),!0)}function b(e,t,n){e!==void 0&&(!Number.isFinite(Date.parse(e))||!e.includes("T"))&&o(n,t,"invalid_timestamp","Value must be an ISO 8601 timestamp")}function v(e,t,n,i){if(typeof e!="string"||!e.startsWith(t))return;let r=e.slice(t.length);Q.test(r)||o(i,n,"invalid_custom_name",`Custom name after ${t} is invalid`)}function ue(e,t,n){if(!e||typeof e!="object"){o(n,t,"missing_actor","Actor is required");return}s(e.kind,`${t}.kind`,n,64),se.has(e.kind)||o(n,`${t}.kind`,"unknown_actor_kind","Actor kind is not supported"),s(e.id,`${t}.id`,n,512),e?.displayName!==void 0&&s(e.displayName,`${t}.displayName`,n,512),e?.profileFingerprint!==void 0&&!/^[a-f0-9]{64}$/.test(e.profileFingerprint)&&o(n,`${t}.profileFingerprint`,"invalid_fingerprint","Profile fingerprint must be 64 lowercase hexadecimal characters")}function pe(e,t,n){if(!e||typeof e!="object"){o(n,t,"invalid_anchor","Anchor must be an object");return}switch(e.kind){case"file":s(e.path,`${t}.path`,n,4096);break;case"source-line":s(e.path,`${t}.path`,n,4096),(!Number.isInteger(e.startLine)||e.startLine<1)&&o(n,`${t}.startLine`,"invalid_line","startLine must be a positive integer"),e.endLine!==void 0&&(!Number.isInteger(e.endLine)||e.endLine<e.startLine)&&o(n,`${t}.endLine`,"invalid_line_range","endLine must be greater than or equal to startLine");break;case"diff-hunk":s(e.path,`${t}.path`,n,4096),s(e.hunkId,`${t}.hunkId`,n,512);break;case"symbol":s(e.path,`${t}.path`,n,4096),s(e.symbol,`${t}.symbol`,n,1024);break;case"dom-node":s(e.pageId,`${t}.pageId`,n,512),!e.selector&&!e.accessibilityId&&!e.snapshotArtifactId&&o(n,t,"missing_dom_locator","DOM anchors require a selector, accessibility ID, or snapshot artifact ID");break;case"timeline":s(e.recordingArtifactId,`${t}.recordingArtifactId`,n,512),(!Number.isFinite(e.startMs)||e.startMs<0)&&o(n,`${t}.startMs`,"invalid_time","startMs must be a non-negative finite number"),e.endMs!==void 0&&(!Number.isFinite(e.endMs)||e.endMs<e.startMs)&&o(n,`${t}.endMs`,"invalid_time_range","endMs must be greater than or equal to startMs");break;case"region":s(e.mediaArtifactId,`${t}.mediaArtifactId`,n,512),[e.x,e.y,e.width,e.height].every(Number.isFinite)?(e.width<=0||e.height<=0)&&o(n,t,"invalid_region_size","Region width and height must be positive"):o(n,t,"invalid_region","Region coordinates must be finite numbers");break;case"artifact":s(e.artifactId,`${t}.artifactId`,n,512);break;default:typeof e.kind!="string"||!e.kind.startsWith("custom:")?o(n,`${t}.kind`,"unknown_anchor","Anchor kind is not supported"):v(e.kind,"custom:",`${t}.kind`,n)}}function A(e,t,n,i){if(!(e===null||typeof e=="string"||typeof e=="boolean")){if(typeof e=="number"){Number.isFinite(e)||o(n,t,"non_finite_number","JSON numbers must be finite");return}if(typeof e!="object"){o(n,t,"non_json_value","Value must be JSON-serializable");return}if(i.has(e)){o(n,t,"cyclic_value","Value must not contain cycles");return}if(i.add(e),Array.isArray(e))e.forEach((r,a)=>A(r,`${t}[${a}]`,n,i));else for(let[r,a]of Object.entries(e))a===void 0?o(n,`${t}.${r}`,"undefined_value","Undefined is not valid JSON"):A(a,`${t}.${r}`,n,i);i.delete(e)}}function le(e){let t=[];if(!e||typeof e!="object")return[{path:"$",code:"invalid_artifact",message:"Artifact must be an object"}];if(e.schemaVersion!==1&&o(t,"schemaVersion","unsupported_schema",`schemaVersion must be ${1}`),s(e.artifactId,"artifactId",t,512),(!Number.isInteger(e.revision)||e.revision<1)&&o(t,"revision","invalid_revision","revision must be a positive integer"),s(e.kind,"kind",t,160),typeof e.kind=="string"&&!ae.has(e.kind)&&!e.kind.startsWith("custom:")&&o(t,"kind","unknown_artifact_kind","Artifact kind is not supported"),v(e.kind,"custom:","kind",t),s(e.title,"title",t,1024),e.description!==void 0&&s(e.description,"description",t,32768),s(e.state,"state",t,64),re.has(e.state)||o(t,"state","unknown_state","Artifact state is not supported"),s(e.createdAt,"createdAt",t,128),b(e.createdAt,"createdAt",t),b(e.updatedAt,"updatedAt",t),e.updatedAt&&Number.isFinite(Date.parse(e.createdAt))&&Date.parse(e.updatedAt)<Date.parse(e.createdAt)&&o(t,"updatedAt","timestamp_order","updatedAt must not precede createdAt"),s(e.mediaType,"mediaType",t,255),s(e.sensitivity,"sensitivity",t,64),oe.has(e.sensitivity)||o(t,"sensitivity","unknown_sensitivity","Sensitivity is not supported"),e.identity)for(let[i,r]of Object.entries(e.identity))r!==void 0&&s(r,`identity.${i}`,t,512);if(!e.content||typeof e.content!="object")o(t,"content","missing_content","content descriptor is required");else{!e.content.hash||typeof e.content.hash!="object"?o(t,"content.hash","missing_hash","content hash is required"):(s(e.content.hash.algorithm,"content.hash.algorithm",t,128),v(e.content.hash.algorithm,"custom:","content.hash.algorithm",t),typeof e.content.hash.algorithm=="string"&&e.content.hash.algorithm!=="sha256"&&!e.content.hash.algorithm.startsWith("custom:")&&o(t,"content.hash.algorithm","unknown_hash_algorithm","Hash algorithm is not supported"),s(e.content.hash.value,"content.hash.value",t,512),e.content.hash.algorithm==="sha256"&&!ne.test(e.content.hash.value)&&o(t,"content.hash.value","invalid_sha256","SHA-256 hash must be 64 lowercase hexadecimal characters")),(!Number.isSafeInteger(e.content.sizeBytes)||e.content.sizeBytes<0)&&o(t,"content.sizeBytes","invalid_size","sizeBytes must be a non-negative safe integer");let i=e.content.storage;if(!i||typeof i!="object")o(t,"content.storage","missing_storage","storage reference is required");else if(i.type==="inline")if(i.text===void 0==(i.base64===void 0))o(t,"content.storage","invalid_inline_storage","Inline storage requires exactly one of text or base64");else{let r;i.text!==void 0?r=N.from(i.text,"utf8"):i.base64!==void 0&&(ie.test(i.base64)?r=N.from(i.base64,"base64"):o(t,"content.storage.base64","invalid_base64","Inline base64 content is malformed")),r&&e.content.sizeBytes!==r.byteLength&&o(t,"content.sizeBytes","content_size_mismatch","sizeBytes does not match inline content"),r&&e.content.hash.algorithm==="sha256"&&y(r).value!==e.content.hash.value&&o(t,"content.hash.value","content_hash_mismatch","Hash does not match inline content")}else i.type==="file"?s(i.path,"content.storage.path",t,4096):i.type==="blob"?s(i.uri,"content.storage.uri",t,8192):i.type==="git"?(s(i.commit,"content.storage.commit",t,512),s(i.path,"content.storage.path",t,4096)):i.type==="url"?(s(i.url,"content.storage.url",t,8192),b(i.expiresAt,"content.storage.expiresAt",t)):i.type==="external"?(s(i.provider,"content.storage.provider",t,255),s(i.locator,"content.storage.locator",t,8192)):o(t,"content.storage.type","unknown_storage","Storage type is not supported");e.content.encoding!==void 0&&(typeof e.content.encoding!="string"||e.content.encoding!=="utf8"&&e.content.encoding!=="base64"&&e.content.encoding!=="binary"&&!e.content.encoding.startsWith("custom:"))&&o(t,"content.encoding","unknown_encoding","Content encoding is not supported"),v(e.content.encoding,"custom:","content.encoding",t)}!e.provenance||typeof e.provenance!="object"?o(t,"provenance","missing_provenance","provenance is required"):(ue(e.provenance.producer,"provenance.producer",t),e.provenance.capabilityLeaseIds?.forEach((i,r)=>s(i,`provenance.capabilityLeaseIds[${r}]`,t,512)),e.provenance.sourceArtifactIds?.forEach((i,r)=>s(i,`provenance.sourceArtifactIds[${r}]`,t,512)),e.provenance.attributes&&A(e.provenance.attributes,"provenance.attributes",t,new Set));let n=new Set;return e.relationships?.forEach((i,r)=>{let a=`relationships[${r}]`;s(i.relation,`${a}.relation`,t,160),typeof i.relation=="string"&&!de.has(i.relation)&&!i.relation.startsWith("custom:")&&o(t,`${a}.relation`,"unknown_relationship","Relationship type is not supported"),v(i.relation,"custom:",`${a}.relation`,t),s(i.target?.type,`${a}.target.type`,t,160),typeof i.target?.type=="string"&&!ce.has(i.target.type)&&!i.target.type.startsWith("custom:")&&o(t,`${a}.target.type`,"unknown_reference_type","Evidence reference type is not supported"),v(i.target?.type,"custom:",`${a}.target.type`,t),s(i.target?.id,`${a}.target.id`,t,512);let d=`${i.relation}:${i.target?.type}:${i.target?.id}:${i.target?.revision??""}`;n.has(d)&&o(t,a,"duplicate_relationship","Duplicate relationship"),n.add(d),i.attributes&&A(i.attributes,`${a}.attributes`,t,new Set)}),e.anchors?.forEach((i,r)=>pe(i,`anchors[${r}]`,t)),e.revision===1&&e.predecessorRevision!==void 0&&o(t,"predecessorRevision","unexpected_predecessor","First revision cannot have a predecessor"),e.revision>1&&(!Number.isInteger(e.predecessorRevision)||(e.predecessorRevision??0)>=e.revision)&&o(t,"predecessorRevision","invalid_predecessor","Later revisions require an earlier predecessor revision"),b(e.retention?.retainUntil,"retention.retainUntil",t),e.retention?.legalHold!==void 0&&typeof e.retention.legalHold!="boolean"&&o(t,"retention.legalHold","invalid_boolean","legalHold must be a boolean"),e.extensions&&A(e.extensions,"extensions",t,new Set),t}function V(e){let t=le(e);if(t.length>0)throw new k("XENO artifact validation failed",t)}function q(e,t={}){for(let n of e){let i=n.codePointAt(0);if(i===127)return!0;if(!(i>31)&&!(i===9&&t.allowTab===!0)&&!((i===10||i===13)&&t.allowLineBreaks===!0))return!0}return!1}var L="xeno.oracle-report.v1",p=class extends Error{constructor(n){super(`XENO Oracle report is invalid: ${n.join("; ")}`);this.issues=n;this.name="XenoOracleValidationError"}issues;code="XENO_ORACLE_INVALID"},M=class{execute;adjudicate;now;idFactory;constructor(t){if(typeof t?.execute!="function"||typeof t?.adjudicate!="function")throw new TypeError("Oracle execution and adjudication functions are required");this.execute=t.execute,this.adjudicate=t.adjudicate,this.now=t.now??(()=>new Date().toISOString()),this.idFactory=t.idFactory??(n=>`${n}_${H()}`)}async run(t){let n=U(t.question,"question",128e3),i=t.runId??`oracle_run_${H()}`;K(i,"runId");let r=[t.primary,...t.critics,t.adjudicator];me(r,t.primary,t.critics,t.adjudicator);let a=this.now(),d=await this.execute({runId:i,question:n,participant:structuredClone(t.primary)}),u=D(d,t.primary,this.idFactory("opinion"),this.now()),O=await Promise.all(t.critics.map(async l=>{let h=await this.execute({runId:i,question:n,participant:structuredClone(l),primaryOpinion:structuredClone(u)});return D(h,l,this.idFactory("opinion"),this.now())})),c=[u,...O],g=await this.adjudicate({runId:i,question:n,participant:structuredClone(t.adjudicator),opinions:structuredClone(c)}),X=fe(g,t.adjudicator,this.now()),W=this.now(),Z=new Set(r.map(_)),G=new Set(c.flatMap(l=>l.citations.map(h=>h.citationId))),j={schemaVersion:L,reportId:this.idFactory("oracle"),runId:i,question:n,questionHash:y(n),startedAt:a,completedAt:W,opinions:c,adjudication:X,summary:{participantCount:r.length,distinctModelCount:Z.size,totalInputTokens:c.reduce((l,h)=>l+h.usage.inputTokens,X.usage.inputTokens),totalOutputTokens:c.reduce((l,h)=>l+h.usage.outputTokens,X.usage.outputTokens),unresolvedDisagreements:X.disagreements.filter(l=>l.resolution==="unresolved").length,citationCount:G.size}};return C(j),j}};function C(e){let t=[];e?.schemaVersion!==L&&t.push("schemaVersion must be xeno.oracle-report.v1"),f(e?.reportId,"reportId",t),f(e?.runId,"runId",t),m(e?.question,"question",t,128e3),(e?.questionHash?.algorithm!=="sha256"||e.questionHash.value!==y(e.question??"").value)&&t.push("questionHash does not match question"),I(e?.startedAt,"startedAt",t),I(e?.completedAt,"completedAt",t),Date.parse(e?.completedAt)<Date.parse(e?.startedAt)&&t.push("completedAt cannot precede startedAt"),(!Array.isArray(e?.opinions)||e.opinions.length<2)&&t.push("at least two independent opinions are required");let n=new Set,i=new Set,r=new Set;for(let c of e?.opinions??[]){P(c,t),n.has(c.participant.participantId)&&t.push(`duplicate participant ${c.participant.participantId}`),n.add(c.participant.participantId),i.add(_(c.participant));for(let g of c.citations)r.add(g.citationId)}i.size<2&&t.push("Oracle requires at least two distinct provider/model identities"),F(e?.adjudication,r,t),e?.adjudication?.participant&&(n.add(e.adjudication.participant.participantId),i.add(_(e.adjudication.participant)));let a=[...(e?.opinions??[]).map(c=>c.usage),e?.adjudication?.usage].filter(Boolean),d=a.reduce((c,g)=>c+g.inputTokens,0),u=a.reduce((c,g)=>c+g.outputTokens,0);e?.summary?.participantCount!==n.size&&t.push("summary participantCount is inconsistent"),e?.summary?.distinctModelCount!==i.size&&t.push("summary distinctModelCount is inconsistent"),(e?.summary?.totalInputTokens!==d||e?.summary?.totalOutputTokens!==u)&&t.push("summary token usage is inconsistent"),e?.summary?.citationCount!==r.size&&t.push("summary citationCount is inconsistent");let O=e?.adjudication?.disagreements?.filter(c=>c.resolution==="unresolved").length??0;if(e?.summary?.unresolvedDisagreements!==O&&t.push("summary unresolvedDisagreements is inconsistent"),t.length>0)throw new p([...new Set(t)])}function ke(e,t){C(e);let n=e,i=E(n),r={schemaVersion:1,artifactId:t.artifactId??`oracle_${y(`${e.runId}:${e.questionHash.value}`).value.slice(0,24)}`,revision:1,kind:"custom:oracle-report",title:"Cross-model Oracle report",description:`${e.summary.distinctModelCount} distinct models; ${e.summary.unresolvedDisagreements} unresolved disagreements`,state:"pending_review",createdAt:e.completedAt,mediaType:"application/vnd.xeno.oracle-report+json",sensitivity:t.sensitivity??"internal",...t.identity?{identity:structuredClone(t.identity)}:{},content:{hash:x(n),sizeBytes:Buffer.byteLength(i,"utf8"),encoding:"utf8",storage:{type:"inline",text:i},redactedPreview:`${e.adjudication.verdict}: ${e.adjudication.conclusion.slice(0,240)}`},provenance:{producer:structuredClone(t.producer),attributes:{distinctModelCount:e.summary.distinctModelCount,participants:e.opinions.map(a=>`${a.participant.providerId}:${a.participant.model}`),adjudicator:`${e.adjudication.participant.providerId}:${e.adjudication.participant.model}`}},...t.accessPolicyId?{accessPolicyId:t.accessPolicyId}:{},extensions:{"xeno.oracle.verdict":e.adjudication.verdict,"xeno.oracle.confidence":e.adjudication.confidence,"xeno.oracle.unresolved":e.summary.unresolvedDisagreements,"xeno.oracle.questionHash":e.questionHash.value}};return V(r),r}function Se(e){if(e.kind!=="custom:oracle-report"||e.mediaType!=="application/vnd.xeno.oracle-report+json")throw new p([`Artifact ${e.artifactId} is not an Oracle report`]);if(e.content.storage.type!=="inline"||typeof e.content.storage.text!="string")throw new p(["Oracle reports require inline JSON content"]);let t;try{t=JSON.parse(e.content.storage.text)}catch{throw new p(["Oracle report content is invalid JSON"])}if(C(t),x(t).value!==e.content.hash.value)throw new p(["Oracle report content hash does not match the artifact"]);return structuredClone(t)}function D(e,t,n,i){let r=z(e.usage),a={...structuredClone(e.opinion),opinionId:n,participant:structuredClone(t),completedAt:i,usage:r},d=[];if(P(a,d),d.length>0)throw new p(d);return a}function fe(e,t,n){let i={...structuredClone(e.adjudication),participant:structuredClone(t),completedAt:n,usage:z(e.usage)},r=[];if(F(i,void 0,r),r.length>0)throw new p(r);return i}function me(e,t,n,i){let r=[];(n.length<1||n.length>8)&&r.push("Oracle requires one through eight critic models"),t.role!=="primary"&&r.push("primary participant role must be primary"),n.some(u=>u.role!=="critic")&&r.push("critic participant roles must be critic"),i.role!=="adjudicator"&&r.push("adjudicator participant role must be adjudicator");let a=new Set,d=new Set;for(let u of e)$(u,r),a.has(u.participantId)&&r.push(`duplicate participant ${u.participantId}`),a.add(u.participantId),d.add(_(u));if(d.size<2&&r.push("Oracle requires at least two distinct provider/model identities"),r.length>0)throw new p([...new Set(r)])}function P(e,t){f(e?.opinionId,"opinionId",t),$(e?.participant,t),m(e?.answer,"opinion answer",t,256e3),m(e?.publicRationale,"opinion publicRationale",t,128e3),T(e?.verdict)||t.push("opinion verdict is invalid"),S(e?.confidence,"opinion confidence",t),I(e?.completedAt,"opinion completedAt",t),B(e?.usage,"opinion usage",t);let n=new Set;for(let r of e?.citations??[])ge(r,t),n.has(r.citationId)&&t.push(`duplicate citation ${r.citationId}`),n.add(r.citationId);let i=new Set;for(let r of e?.claims??[]){f(r?.claimId,"claimId",t),i.has(r.claimId)&&t.push(`duplicate claim ${r.claimId}`),i.add(r.claimId),m(r?.statement,`claim ${r.claimId} statement`,t,32e3),T(r?.verdict)||t.push(`claim ${r.claimId} verdict is invalid`),S(r?.confidence,`claim ${r.claimId} confidence`,t);for(let a of r?.citationIds??[])n.has(a)||t.push(`claim ${r.claimId} references unknown citation ${a}`)}}function F(e,t,n){$(e?.participant,n),e?.participant?.role!=="adjudicator"&&n.push("adjudication participant role must be adjudicator"),m(e?.conclusion,"adjudication conclusion",n,256e3),m(e?.publicRationale,"adjudication publicRationale",n,128e3),T(e?.verdict)||n.push("adjudication verdict is invalid"),S(e?.confidence,"adjudication confidence",n),I(e?.completedAt,"adjudication completedAt",n),B(e?.usage,"adjudication usage",n);let i=new Set;for(let r of e?.disagreements??[])f(r?.disagreementId,"disagreementId",n),i.has(r.disagreementId)&&n.push(`duplicate disagreement ${r.disagreementId}`),i.add(r.disagreementId),m(r?.summary,`disagreement ${r.disagreementId} summary`,n,32e3),(!Array.isArray(r?.participantIds)||r.participantIds.length<2)&&n.push(`disagreement ${r.disagreementId} requires at least two participants`),["low","medium","high"].includes(r?.severity)||n.push(`disagreement ${r.disagreementId} severity is invalid`),r?.resolution!=="resolved"&&r?.resolution!=="unresolved"&&n.push(`disagreement ${r.disagreementId} resolution is invalid`);if(t)for(let r of e?.citationIds??[])t.has(r)||n.push(`adjudication references unknown citation ${r}`)}function $(e,t){f(e?.participantId,"participantId",t),f(e?.providerId,"providerId",t),m(e?.model,"participant model",t,512),e?.connectionId!==void 0&&f(e.connectionId,"connectionId",t),["primary","critic","adjudicator"].includes(e?.role)||t.push("participant role is invalid")}function ge(e,t){f(e?.citationId,"citationId",t);try{let n=new URL(e?.uri);n.protocol!=="https:"&&n.protocol!=="http:"&&t.push(`citation ${e.citationId} must use HTTP(S)`),(n.username||n.password)&&t.push(`citation ${e.citationId} cannot contain credentials`)}catch{t.push(`citation ${e?.citationId??"(unknown)"} URI is invalid`)}e?.retrievedAt!==void 0&&I(e.retrievedAt,`citation ${e.citationId} retrievedAt`,t),e?.contentHash&&(e.contentHash.algorithm!=="sha256"||!/^[a-f0-9]{64}$/u.test(e.contentHash.value))&&t.push(`citation ${e.citationId} contentHash is invalid`)}function z(e){return{inputTokens:J(e?.inputTokens),outputTokens:J(e?.outputTokens)}}function B(e,t,n){(!Number.isInteger(e?.inputTokens)||e.inputTokens<0)&&n.push(`${t} inputTokens must be a non-negative integer`),(!Number.isInteger(e?.outputTokens)||e.outputTokens<0)&&n.push(`${t} outputTokens must be a non-negative integer`)}function J(e){return Number.isInteger(e)&&(e??-1)>=0?e:0}function _(e){return`${e.providerId.trim().toLowerCase()}\0${e.model.trim().toLowerCase()}`}function U(e,t,n){let i=typeof e=="string"?e.trim():"";if(!i||i.length>n||q(i,{allowTab:!0,allowLineBreaks:!0}))throw new p([`${t} must be non-empty bounded text`]);return i}function K(e,t){let n=typeof e=="string"?e.trim():"";if(!/^[A-Za-z0-9][A-Za-z0-9._:@/-]{0,255}$/u.test(n))throw new p([`${t} is invalid`]);return n}function f(e,t,n){try{K(e,t)}catch{n.push(`${t} is invalid`)}}function m(e,t,n,i){try{U(e,t,i)}catch{n.push(`${t} must be non-empty bounded text`)}}function S(e,t,n){(typeof e!="number"||!Number.isFinite(e)||e<0||e>1)&&n.push(`${t} must be between 0 and 1`)}function I(e,t,n){(typeof e!="string"||!Number.isFinite(Date.parse(e)))&&n.push(`${t} must be an ISO timestamp`)}function T(e){return e==="supported"||e==="contested"||e==="unsupported"||e==="insufficient-evidence"}export{L as XENO_ORACLE_REPORT_SCHEMA_VERSION,M as XenoOracleCoordinator,p as XenoOracleValidationError,C as assertValidXenoOracleReport,Se as xenoArtifactToOracleReport,ke as xenoOracleReportToArtifact};
|
|
1
|
+
import{randomUUID as z}from"node:crypto";import{createHash as oe}from"node:crypto";function A(e){return{algorithm:"sha256",value:oe("sha256").update(e).digest("hex")}}function R(e){return JSON.stringify(w(e,new Set))}function T(e){return A(R(e))}function w(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 i=e.map(r=>w(r,t));return t.delete(e),i}let n={};for(let i of Object.keys(e).sort((r,a)=>r.localeCompare(a))){let r=e[i];if(r===void 0)throw new TypeError(`Artifact JSON property ${i} is undefined`);n[i]=w(r,t)}return t.delete(e),n}var j=["plan","requirements","design","task-graph","patch","diff","file","document","diagram","screenshot","recording","browser-snapshot","test-report","review-report","security-report","performance-report","release-report","sbom","provenance","attestation"],V=["draft","pending_review","approved","rejected","superseded","archived"],q=["public","internal","confidential","restricted"],H=["agent","tool","user","system","integration"],D=["requirement","design-decision","risk","task","agent","run","tool-call","edit","commit","test-case","test-run","finding","approval","artifact","release","claim"],M=["decomposes","depends_on","implements","changes","tests","verifies","finds","fixes","reviews","approves","rejects","supersedes","derived_from","produced_by","supports_claim","contradicts_claim","released_as"];import{Buffer as P}from"node:buffer";var se=/^[a-z0-9][a-z0-9._/-]{0,127}$/,ae="custom:";function F(e,t=ae){return e.startsWith(t)?se.test(e.slice(t.length)):!1}var x=class extends Error{code="ARTIFACT_INVALID";issues;constructor(t,n){super(t),this.name="XenoArtifactValidationError",this.issues=n.map(i=>({...i}))}};var ce="[\\u0000-\\u001f\\u007f]",de=new RegExp(ce),ue=/^[a-f0-9]{64}$/,pe=/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/,le=new Set(V),fe=new Set(q),me=new Set(H),ge=new Set(j),he=new Set(D),Ae=new Set(M);function o(e,t,n,i){e.push({path:t,code:n,message:i})}function s(e,t,n,i=1024){return typeof e!="string"||e.trim().length===0?(o(n,t,"required_string","Value must be a non-empty string"),!1):(e.length>i&&o(n,t,"string_too_long",`Value must not exceed ${i} characters`),de.test(e)&&o(n,t,"control_character","Value must not contain control characters"),!0)}function _(e,t,n){e!==void 0&&(!Number.isFinite(Date.parse(e))||!e.includes("T"))&&o(n,t,"invalid_timestamp","Value must be an ISO 8601 timestamp")}function y(e,t,n,i){typeof e=="string"&&e.startsWith(t)&&(F(e,t)||o(i,n,"invalid_custom_name",`Custom name after ${t} is invalid`))}function ye(e,t,n){if(!e||typeof e!="object"){o(n,t,"missing_actor","Actor is required");return}s(e.kind,`${t}.kind`,n,64),me.has(e.kind)||o(n,`${t}.kind`,"unknown_actor_kind","Actor kind is not supported"),s(e.id,`${t}.id`,n,512),e?.displayName!==void 0&&s(e.displayName,`${t}.displayName`,n,512),e?.profileFingerprint!==void 0&&!/^[a-f0-9]{64}$/.test(e.profileFingerprint)&&o(n,`${t}.profileFingerprint`,"invalid_fingerprint","Profile fingerprint must be 64 lowercase hexadecimal characters")}function Ie(e,t,n){if(!e||typeof e!="object"){o(n,t,"invalid_anchor","Anchor must be an object");return}switch(e.kind){case"file":s(e.path,`${t}.path`,n,4096);break;case"source-line":s(e.path,`${t}.path`,n,4096),(!Number.isInteger(e.startLine)||e.startLine<1)&&o(n,`${t}.startLine`,"invalid_line","startLine must be a positive integer"),e.endLine!==void 0&&(!Number.isInteger(e.endLine)||e.endLine<e.startLine)&&o(n,`${t}.endLine`,"invalid_line_range","endLine must be greater than or equal to startLine");break;case"diff-hunk":s(e.path,`${t}.path`,n,4096),s(e.hunkId,`${t}.hunkId`,n,512);break;case"symbol":s(e.path,`${t}.path`,n,4096),s(e.symbol,`${t}.symbol`,n,1024);break;case"dom-node":s(e.pageId,`${t}.pageId`,n,512),!e.selector&&!e.accessibilityId&&!e.snapshotArtifactId&&o(n,t,"missing_dom_locator","DOM anchors require a selector, accessibility ID, or snapshot artifact ID");break;case"timeline":s(e.recordingArtifactId,`${t}.recordingArtifactId`,n,512),(!Number.isFinite(e.startMs)||e.startMs<0)&&o(n,`${t}.startMs`,"invalid_time","startMs must be a non-negative finite number"),e.endMs!==void 0&&(!Number.isFinite(e.endMs)||e.endMs<e.startMs)&&o(n,`${t}.endMs`,"invalid_time_range","endMs must be greater than or equal to startMs");break;case"region":s(e.mediaArtifactId,`${t}.mediaArtifactId`,n,512),[e.x,e.y,e.width,e.height].every(Number.isFinite)?(e.width<=0||e.height<=0)&&o(n,t,"invalid_region_size","Region width and height must be positive"):o(n,t,"invalid_region","Region coordinates must be finite numbers");break;case"artifact":s(e.artifactId,`${t}.artifactId`,n,512);break;default:typeof e.kind!="string"||!e.kind.startsWith("custom:")?o(n,`${t}.kind`,"unknown_anchor","Anchor kind is not supported"):y(e.kind,"custom:",`${t}.kind`,n)}}function I(e,t,n,i){if(!(e===null||typeof e=="string"||typeof e=="boolean")){if(typeof e=="number"){Number.isFinite(e)||o(n,t,"non_finite_number","JSON numbers must be finite");return}if(typeof e!="object"){o(n,t,"non_json_value","Value must be JSON-serializable");return}if(i.has(e)){o(n,t,"cyclic_value","Value must not contain cycles");return}if(i.add(e),Array.isArray(e))e.forEach((r,a)=>I(r,`${t}[${a}]`,n,i));else for(let[r,a]of Object.entries(e))a===void 0?o(n,`${t}.${r}`,"undefined_value","Undefined is not valid JSON"):I(a,`${t}.${r}`,n,i);i.delete(e)}}function ve(e){let t=[];if(!e||typeof e!="object")return[{path:"$",code:"invalid_artifact",message:"Artifact must be an object"}];if(e.schemaVersion!==1&&o(t,"schemaVersion","unsupported_schema",`schemaVersion must be ${1}`),s(e.artifactId,"artifactId",t,512),(!Number.isInteger(e.revision)||e.revision<1)&&o(t,"revision","invalid_revision","revision must be a positive integer"),s(e.kind,"kind",t,160),typeof e.kind=="string"&&!ge.has(e.kind)&&!e.kind.startsWith("custom:")&&o(t,"kind","unknown_artifact_kind","Artifact kind is not supported"),y(e.kind,"custom:","kind",t),s(e.title,"title",t,1024),e.description!==void 0&&s(e.description,"description",t,32768),s(e.state,"state",t,64),le.has(e.state)||o(t,"state","unknown_state","Artifact state is not supported"),s(e.createdAt,"createdAt",t,128),_(e.createdAt,"createdAt",t),_(e.updatedAt,"updatedAt",t),e.updatedAt&&Number.isFinite(Date.parse(e.createdAt))&&Date.parse(e.updatedAt)<Date.parse(e.createdAt)&&o(t,"updatedAt","timestamp_order","updatedAt must not precede createdAt"),s(e.mediaType,"mediaType",t,255),s(e.sensitivity,"sensitivity",t,64),fe.has(e.sensitivity)||o(t,"sensitivity","unknown_sensitivity","Sensitivity is not supported"),e.identity)for(let[i,r]of Object.entries(e.identity))r!==void 0&&s(r,`identity.${i}`,t,512);if(!e.content||typeof e.content!="object")o(t,"content","missing_content","content descriptor is required");else{!e.content.hash||typeof e.content.hash!="object"?o(t,"content.hash","missing_hash","content hash is required"):(s(e.content.hash.algorithm,"content.hash.algorithm",t,128),y(e.content.hash.algorithm,"custom:","content.hash.algorithm",t),typeof e.content.hash.algorithm=="string"&&e.content.hash.algorithm!=="sha256"&&!e.content.hash.algorithm.startsWith("custom:")&&o(t,"content.hash.algorithm","unknown_hash_algorithm","Hash algorithm is not supported"),s(e.content.hash.value,"content.hash.value",t,512),e.content.hash.algorithm==="sha256"&&!ue.test(e.content.hash.value)&&o(t,"content.hash.value","invalid_sha256","SHA-256 hash must be 64 lowercase hexadecimal characters")),(!Number.isSafeInteger(e.content.sizeBytes)||e.content.sizeBytes<0)&&o(t,"content.sizeBytes","invalid_size","sizeBytes must be a non-negative safe integer");let i=e.content.storage;if(!i||typeof i!="object")o(t,"content.storage","missing_storage","storage reference is required");else if(i.type==="inline")if(i.text===void 0==(i.base64===void 0))o(t,"content.storage","invalid_inline_storage","Inline storage requires exactly one of text or base64");else{let r;i.text!==void 0?r=P.from(i.text,"utf8"):i.base64!==void 0&&(pe.test(i.base64)?r=P.from(i.base64,"base64"):o(t,"content.storage.base64","invalid_base64","Inline base64 content is malformed")),r&&e.content.sizeBytes!==r.byteLength&&o(t,"content.sizeBytes","content_size_mismatch","sizeBytes does not match inline content"),r&&e.content.hash.algorithm==="sha256"&&A(r).value!==e.content.hash.value&&o(t,"content.hash.value","content_hash_mismatch","Hash does not match inline content")}else i.type==="file"?s(i.path,"content.storage.path",t,4096):i.type==="blob"?s(i.uri,"content.storage.uri",t,8192):i.type==="git"?(s(i.commit,"content.storage.commit",t,512),s(i.path,"content.storage.path",t,4096)):i.type==="url"?(s(i.url,"content.storage.url",t,8192),_(i.expiresAt,"content.storage.expiresAt",t)):i.type==="external"?(s(i.provider,"content.storage.provider",t,255),s(i.locator,"content.storage.locator",t,8192)):o(t,"content.storage.type","unknown_storage","Storage type is not supported");e.content.encoding!==void 0&&(typeof e.content.encoding!="string"||e.content.encoding!=="utf8"&&e.content.encoding!=="base64"&&e.content.encoding!=="binary"&&!e.content.encoding.startsWith("custom:"))&&o(t,"content.encoding","unknown_encoding","Content encoding is not supported"),y(e.content.encoding,"custom:","content.encoding",t)}!e.provenance||typeof e.provenance!="object"?o(t,"provenance","missing_provenance","provenance is required"):(ye(e.provenance.producer,"provenance.producer",t),e.provenance.capabilityLeaseIds?.forEach((i,r)=>s(i,`provenance.capabilityLeaseIds[${r}]`,t,512)),e.provenance.sourceArtifactIds?.forEach((i,r)=>s(i,`provenance.sourceArtifactIds[${r}]`,t,512)),e.provenance.attributes&&I(e.provenance.attributes,"provenance.attributes",t,new Set));let n=new Set;return e.relationships?.forEach((i,r)=>{let a=`relationships[${r}]`;s(i.relation,`${a}.relation`,t,160),typeof i.relation=="string"&&!Ae.has(i.relation)&&!i.relation.startsWith("custom:")&&o(t,`${a}.relation`,"unknown_relationship","Relationship type is not supported"),y(i.relation,"custom:",`${a}.relation`,t),s(i.target?.type,`${a}.target.type`,t,160),typeof i.target?.type=="string"&&!he.has(i.target.type)&&!i.target.type.startsWith("custom:")&&o(t,`${a}.target.type`,"unknown_reference_type","Evidence reference type is not supported"),y(i.target?.type,"custom:",`${a}.target.type`,t),s(i.target?.id,`${a}.target.id`,t,512);let d=`${i.relation}:${i.target?.type}:${i.target?.id}:${i.target?.revision??""}`;n.has(d)&&o(t,a,"duplicate_relationship","Duplicate relationship"),n.add(d),i.attributes&&I(i.attributes,`${a}.attributes`,t,new Set)}),e.anchors?.forEach((i,r)=>Ie(i,`anchors[${r}]`,t)),e.revision===1&&e.predecessorRevision!==void 0&&o(t,"predecessorRevision","unexpected_predecessor","First revision cannot have a predecessor"),e.revision>1&&(!Number.isInteger(e.predecessorRevision)||(e.predecessorRevision??0)>=e.revision)&&o(t,"predecessorRevision","invalid_predecessor","Later revisions require an earlier predecessor revision"),_(e.retention?.retainUntil,"retention.retainUntil",t),e.retention?.legalHold!==void 0&&typeof e.retention.legalHold!="boolean"&&o(t,"retention.legalHold","invalid_boolean","legalHold must be a boolean"),e.extensions&&I(e.extensions,"extensions",t,new Set),t}function L(e){let t=ve(e);if(t.length>0)throw new x("XENO artifact validation failed",t)}function J(e,t={}){for(let n of e){let i=n.codePointAt(0);if(i===127)return!0;if(!(i>31)&&!(i===9&&t.allowTab===!0)&&!((i===10||i===13)&&t.allowLineBreaks===!0))return!0}return!1}var W="xeno.oracle-report.v1",p=class extends Error{constructor(n){super(`XENO Oracle report is invalid: ${n.join("; ")}`);this.issues=n;this.name="XenoOracleValidationError"}issues;code="XENO_ORACLE_INVALID"},B=class{execute;adjudicate;now;idFactory;constructor(t){if(typeof t?.execute!="function"||typeof t?.adjudicate!="function")throw new TypeError("Oracle execution and adjudication functions are required");this.execute=t.execute,this.adjudicate=t.adjudicate,this.now=t.now??(()=>new Date().toISOString()),this.idFactory=t.idFactory??(n=>`${n}_${z()}`)}async run(t){let n=ee(t.question,"question",128e3),i=t.runId??`oracle_run_${z()}`;te(i,"runId");let r=[t.primary,...t.critics,t.adjudicator];_e(r,t.primary,t.critics,t.adjudicator);let a=this.now(),d=await this.execute({runId:i,question:n,participant:structuredClone(t.primary)}),u=U(d,t.primary,this.idFactory("opinion"),this.now()),O=await Promise.all(t.critics.map(async l=>{let h=await this.execute({runId:i,question:n,participant:structuredClone(l),primaryOpinion:structuredClone(u)});return U(h,l,this.idFactory("opinion"),this.now())})),c=[u,...O],g=await this.adjudicate({runId:i,question:n,participant:structuredClone(t.adjudicator),opinions:structuredClone(c)}),X=Xe(g,t.adjudicator,this.now()),ne=this.now(),ie=new Set(r.map(E)),re=new Set(c.flatMap(l=>l.citations.map(h=>h.citationId))),$={schemaVersion:W,reportId:this.idFactory("oracle"),runId:i,question:n,questionHash:A(n),startedAt:a,completedAt:ne,opinions:c,adjudication:X,summary:{participantCount:r.length,distinctModelCount:ie.size,totalInputTokens:c.reduce((l,h)=>l+h.usage.inputTokens,X.usage.inputTokens),totalOutputTokens:c.reduce((l,h)=>l+h.usage.outputTokens,X.usage.outputTokens),unresolvedDisagreements:X.disagreements.filter(l=>l.resolution==="unresolved").length,citationCount:re.size}};return N($),$}};function N(e){let t=[];e?.schemaVersion!==W&&t.push("schemaVersion must be xeno.oracle-report.v1"),f(e?.reportId,"reportId",t),f(e?.runId,"runId",t),m(e?.question,"question",t,128e3),(e?.questionHash?.algorithm!=="sha256"||e.questionHash.value!==A(e.question??"").value)&&t.push("questionHash does not match question"),v(e?.startedAt,"startedAt",t),v(e?.completedAt,"completedAt",t),Date.parse(e?.completedAt)<Date.parse(e?.startedAt)&&t.push("completedAt cannot precede startedAt"),(!Array.isArray(e?.opinions)||e.opinions.length<2)&&t.push("at least two independent opinions are required");let n=new Set,i=new Set,r=new Set;for(let c of e?.opinions??[]){Y(c,t),n.has(c.participant.participantId)&&t.push(`duplicate participant ${c.participant.participantId}`),n.add(c.participant.participantId),i.add(E(c.participant));for(let g of c.citations)r.add(g.citationId)}i.size<2&&t.push("Oracle requires at least two distinct provider/model identities"),G(e?.adjudication,r,t),e?.adjudication?.participant&&(n.add(e.adjudication.participant.participantId),i.add(E(e.adjudication.participant)));let a=[...(e?.opinions??[]).map(c=>c.usage),e?.adjudication?.usage].filter(Boolean),d=a.reduce((c,g)=>c+g.inputTokens,0),u=a.reduce((c,g)=>c+g.outputTokens,0);e?.summary?.participantCount!==n.size&&t.push("summary participantCount is inconsistent"),e?.summary?.distinctModelCount!==i.size&&t.push("summary distinctModelCount is inconsistent"),(e?.summary?.totalInputTokens!==d||e?.summary?.totalOutputTokens!==u)&&t.push("summary token usage is inconsistent"),e?.summary?.citationCount!==r.size&&t.push("summary citationCount is inconsistent");let O=e?.adjudication?.disagreements?.filter(c=>c.resolution==="unresolved").length??0;if(e?.summary?.unresolvedDisagreements!==O&&t.push("summary unresolvedDisagreements is inconsistent"),t.length>0)throw new p([...new Set(t)])}function Me(e,t){N(e);let n=e,i=R(n),r={schemaVersion:1,artifactId:t.artifactId??`oracle_${A(`${e.runId}:${e.questionHash.value}`).value.slice(0,24)}`,revision:1,kind:"custom:oracle-report",title:"Cross-model Oracle report",description:`${e.summary.distinctModelCount} distinct models; ${e.summary.unresolvedDisagreements} unresolved disagreements`,state:"pending_review",createdAt:e.completedAt,mediaType:"application/vnd.xeno.oracle-report+json",sensitivity:t.sensitivity??"internal",...t.identity?{identity:structuredClone(t.identity)}:{},content:{hash:T(n),sizeBytes:Buffer.byteLength(i,"utf8"),encoding:"utf8",storage:{type:"inline",text:i},redactedPreview:`${e.adjudication.verdict}: ${e.adjudication.conclusion.slice(0,240)}`},provenance:{producer:structuredClone(t.producer),attributes:{distinctModelCount:e.summary.distinctModelCount,participants:e.opinions.map(a=>`${a.participant.providerId}:${a.participant.model}`),adjudicator:`${e.adjudication.participant.providerId}:${e.adjudication.participant.model}`}},...t.accessPolicyId?{accessPolicyId:t.accessPolicyId}:{},extensions:{"xeno.oracle.verdict":e.adjudication.verdict,"xeno.oracle.confidence":e.adjudication.confidence,"xeno.oracle.unresolved":e.summary.unresolvedDisagreements,"xeno.oracle.questionHash":e.questionHash.value}};return L(r),r}function Fe(e){if(e.kind!=="custom:oracle-report"||e.mediaType!=="application/vnd.xeno.oracle-report+json")throw new p([`Artifact ${e.artifactId} is not an Oracle report`]);if(e.content.storage.type!=="inline"||typeof e.content.storage.text!="string")throw new p(["Oracle reports require inline JSON content"]);let t;try{t=JSON.parse(e.content.storage.text)}catch{throw new p(["Oracle report content is invalid JSON"])}if(N(t),T(t).value!==e.content.hash.value)throw new p(["Oracle report content hash does not match the artifact"]);return structuredClone(t)}function U(e,t,n,i){let r=Z(e.usage),a={...structuredClone(e.opinion),opinionId:n,participant:structuredClone(t),completedAt:i,usage:r},d=[];if(Y(a,d),d.length>0)throw new p(d);return a}function Xe(e,t,n){let i={...structuredClone(e.adjudication),participant:structuredClone(t),completedAt:n,usage:Z(e.usage)},r=[];if(G(i,void 0,r),r.length>0)throw new p(r);return i}function _e(e,t,n,i){let r=[];(n.length<1||n.length>8)&&r.push("Oracle requires one through eight critic models"),t.role!=="primary"&&r.push("primary participant role must be primary"),n.some(u=>u.role!=="critic")&&r.push("critic participant roles must be critic"),i.role!=="adjudicator"&&r.push("adjudicator participant role must be adjudicator");let a=new Set,d=new Set;for(let u of e)k(u,r),a.has(u.participantId)&&r.push(`duplicate participant ${u.participantId}`),a.add(u.participantId),d.add(E(u));if(d.size<2&&r.push("Oracle requires at least two distinct provider/model identities"),r.length>0)throw new p([...new Set(r)])}function Y(e,t){f(e?.opinionId,"opinionId",t),k(e?.participant,t),m(e?.answer,"opinion answer",t,256e3),m(e?.publicRationale,"opinion publicRationale",t,128e3),C(e?.verdict)||t.push("opinion verdict is invalid"),S(e?.confidence,"opinion confidence",t),v(e?.completedAt,"opinion completedAt",t),Q(e?.usage,"opinion usage",t);let n=new Set;for(let r of e?.citations??[])be(r,t),n.has(r.citationId)&&t.push(`duplicate citation ${r.citationId}`),n.add(r.citationId);let i=new Set;for(let r of e?.claims??[]){f(r?.claimId,"claimId",t),i.has(r.claimId)&&t.push(`duplicate claim ${r.claimId}`),i.add(r.claimId),m(r?.statement,`claim ${r.claimId} statement`,t,32e3),C(r?.verdict)||t.push(`claim ${r.claimId} verdict is invalid`),S(r?.confidence,`claim ${r.claimId} confidence`,t);for(let a of r?.citationIds??[])n.has(a)||t.push(`claim ${r.claimId} references unknown citation ${a}`)}}function G(e,t,n){k(e?.participant,n),e?.participant?.role!=="adjudicator"&&n.push("adjudication participant role must be adjudicator"),m(e?.conclusion,"adjudication conclusion",n,256e3),m(e?.publicRationale,"adjudication publicRationale",n,128e3),C(e?.verdict)||n.push("adjudication verdict is invalid"),S(e?.confidence,"adjudication confidence",n),v(e?.completedAt,"adjudication completedAt",n),Q(e?.usage,"adjudication usage",n);let i=new Set;for(let r of e?.disagreements??[])f(r?.disagreementId,"disagreementId",n),i.has(r.disagreementId)&&n.push(`duplicate disagreement ${r.disagreementId}`),i.add(r.disagreementId),m(r?.summary,`disagreement ${r.disagreementId} summary`,n,32e3),(!Array.isArray(r?.participantIds)||r.participantIds.length<2)&&n.push(`disagreement ${r.disagreementId} requires at least two participants`),["low","medium","high"].includes(r?.severity)||n.push(`disagreement ${r.disagreementId} severity is invalid`),r?.resolution!=="resolved"&&r?.resolution!=="unresolved"&&n.push(`disagreement ${r.disagreementId} resolution is invalid`);if(t)for(let r of e?.citationIds??[])t.has(r)||n.push(`adjudication references unknown citation ${r}`)}function k(e,t){f(e?.participantId,"participantId",t),f(e?.providerId,"providerId",t),m(e?.model,"participant model",t,512),e?.connectionId!==void 0&&f(e.connectionId,"connectionId",t),["primary","critic","adjudicator"].includes(e?.role)||t.push("participant role is invalid")}function be(e,t){f(e?.citationId,"citationId",t);try{let n=new URL(e?.uri);n.protocol!=="https:"&&n.protocol!=="http:"&&t.push(`citation ${e.citationId} must use HTTP(S)`),(n.username||n.password)&&t.push(`citation ${e.citationId} cannot contain credentials`)}catch{t.push(`citation ${e?.citationId??"(unknown)"} URI is invalid`)}e?.retrievedAt!==void 0&&v(e.retrievedAt,`citation ${e.citationId} retrievedAt`,t),e?.contentHash&&(e.contentHash.algorithm!=="sha256"||!/^[a-f0-9]{64}$/u.test(e.contentHash.value))&&t.push(`citation ${e.citationId} contentHash is invalid`)}function Z(e){return{inputTokens:K(e?.inputTokens),outputTokens:K(e?.outputTokens)}}function Q(e,t,n){(!Number.isInteger(e?.inputTokens)||e.inputTokens<0)&&n.push(`${t} inputTokens must be a non-negative integer`),(!Number.isInteger(e?.outputTokens)||e.outputTokens<0)&&n.push(`${t} outputTokens must be a non-negative integer`)}function K(e){return Number.isInteger(e)&&(e??-1)>=0?e:0}function E(e){return`${e.providerId.trim().toLowerCase()}\0${e.model.trim().toLowerCase()}`}function ee(e,t,n){let i=typeof e=="string"?e.trim():"";if(!i||i.length>n||J(i,{allowTab:!0,allowLineBreaks:!0}))throw new p([`${t} must be non-empty bounded text`]);return i}function te(e,t){let n=typeof e=="string"?e.trim():"";if(!/^[A-Za-z0-9][A-Za-z0-9._:@/-]{0,255}$/u.test(n))throw new p([`${t} is invalid`]);return n}function f(e,t,n){try{te(e,t)}catch{n.push(`${t} is invalid`)}}function m(e,t,n,i){try{ee(e,t,i)}catch{n.push(`${t} must be non-empty bounded text`)}}function S(e,t,n){(typeof e!="number"||!Number.isFinite(e)||e<0||e>1)&&n.push(`${t} must be between 0 and 1`)}function v(e,t,n){(typeof e!="string"||!Number.isFinite(Date.parse(e)))&&n.push(`${t} must be an ISO timestamp`)}function C(e){return e==="supported"||e==="contested"||e==="unsupported"||e==="insufficient-evidence"}export{W as XENO_ORACLE_REPORT_SCHEMA_VERSION,B as XenoOracleCoordinator,p as XenoOracleValidationError,N as assertValidXenoOracleReport,Fe as xenoArtifactToOracleReport,Me as xenoOracleReportToArtifact};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"inputs":{"src/artifacts/hash.ts":{"bytes":
|
|
1
|
+
{"inputs":{"src/artifacts/hash.ts":{"bytes":1489,"imports":[{"path":"node:crypto","kind":"import-statement","external":true}],"format":"esm"},"src/artifacts/types.ts":{"bytes":11224,"imports":[],"format":"esm"},"src/utils/custom-names.ts":{"bytes":2210,"imports":[],"format":"esm"},"src/artifacts/validation.ts":{"bytes":25271,"imports":[{"path":"src/artifacts/types.ts","kind":"import-statement","original":"./types.js"},{"path":"node:buffer","kind":"import-statement","external":true},{"path":"src/artifacts/hash.ts","kind":"import-statement","original":"./hash.js"},{"path":"src/utils/custom-names.ts","kind":"import-statement","original":"../utils/custom-names.js"},{"path":"src/artifacts/types.ts","kind":"import-statement","original":"./types.js"}],"format":"esm"},"src/utils/text-security.ts":{"bytes":809,"imports":[],"format":"esm"},"src/oracle/protocol.ts":{"bytes":23835,"imports":[{"path":"node:crypto","kind":"import-statement","external":true},{"path":"src/artifacts/hash.ts","kind":"import-statement","original":"../artifacts/hash.js"},{"path":"src/artifacts/types.ts","kind":"import-statement","original":"../artifacts/types.js"},{"path":"src/artifacts/validation.ts","kind":"import-statement","original":"../artifacts/validation.js"},{"path":"src/utils/text-security.ts","kind":"import-statement","original":"../utils/text-security.js"}],"format":"esm"},"src/oracle/index.ts":{"bytes":31,"imports":[{"path":"src/oracle/protocol.ts","kind":"import-statement","original":"./protocol.js"}],"format":"esm"}},"outputs":{"dist/oracle/index.cjs":{"imports":[{"path":"node:crypto","kind":"require-call","external":true},{"path":"node:crypto","kind":"require-call","external":true},{"path":"node:buffer","kind":"require-call","external":true}],"exports":[],"entryPoint":"src/oracle/index.ts","inputs":{"src/oracle/index.ts":{"bytesInOutput":243},"src/oracle/protocol.ts":{"bytesInOutput":10804},"src/artifacts/hash.ts":{"bytesInOutput":715},"src/artifacts/types.ts":{"bytesInOutput":812},"src/artifacts/validation.ts":{"bytesInOutput":9795},"src/utils/custom-names.ts":{"bytesInOutput":124},"src/utils/text-security.ts":{"bytesInOutput":179}},"bytes":23294}}}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"inputs":{"src/artifacts/hash.ts":{"bytes":
|
|
1
|
+
{"inputs":{"src/artifacts/hash.ts":{"bytes":1489,"imports":[{"path":"node:crypto","kind":"import-statement","external":true}],"format":"esm"},"src/artifacts/types.ts":{"bytes":11224,"imports":[],"format":"esm"},"src/utils/custom-names.ts":{"bytes":2210,"imports":[],"format":"esm"},"src/artifacts/validation.ts":{"bytes":25271,"imports":[{"path":"src/artifacts/types.ts","kind":"import-statement","original":"./types.js"},{"path":"node:buffer","kind":"import-statement","external":true},{"path":"src/artifacts/hash.ts","kind":"import-statement","original":"./hash.js"},{"path":"src/utils/custom-names.ts","kind":"import-statement","original":"../utils/custom-names.js"},{"path":"src/artifacts/types.ts","kind":"import-statement","original":"./types.js"}],"format":"esm"},"src/utils/text-security.ts":{"bytes":809,"imports":[],"format":"esm"},"src/oracle/protocol.ts":{"bytes":23835,"imports":[{"path":"node:crypto","kind":"import-statement","external":true},{"path":"src/artifacts/hash.ts","kind":"import-statement","original":"../artifacts/hash.js"},{"path":"src/artifacts/types.ts","kind":"import-statement","original":"../artifacts/types.js"},{"path":"src/artifacts/validation.ts","kind":"import-statement","original":"../artifacts/validation.js"},{"path":"src/utils/text-security.ts","kind":"import-statement","original":"../utils/text-security.js"}],"format":"esm"},"src/oracle/index.ts":{"bytes":31,"imports":[{"path":"src/oracle/protocol.ts","kind":"import-statement","original":"./protocol.js"}],"format":"esm"}},"outputs":{"dist/oracle/index.js":{"imports":[{"path":"node:crypto","kind":"import-statement","external":true},{"path":"node:crypto","kind":"import-statement","external":true},{"path":"node:buffer","kind":"import-statement","external":true}],"exports":["XENO_ORACLE_REPORT_SCHEMA_VERSION","XenoOracleCoordinator","XenoOracleValidationError","assertValidXenoOracleReport","xenoArtifactToOracleReport","xenoOracleReportToArtifact"],"entryPoint":"src/oracle/index.ts","inputs":{"src/oracle/protocol.ts":{"bytesInOutput":10780},"src/artifacts/hash.ts":{"bytesInOutput":714},"src/artifacts/types.ts":{"bytesInOutput":812},"src/artifacts/validation.ts":{"bytesInOutput":9789},"src/utils/custom-names.ts":{"bytesInOutput":124},"src/utils/text-security.ts":{"bytesInOutput":179},"src/oracle/index.ts":{"bytesInOutput":0}},"bytes":22603}}}
|