@wukazis/euphony 0.1.45 → 0.1.47

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,2 +0,0 @@
1
- (function(){"use strict";const l=new Set(["session_meta","response_item","event_msg","turn_context","compacted"]),u=new Set(["message","function_call","function_call_output","custom_tool_call","custom_tool_call_output","reasoning"]),p=new Set(["user_message","agent_message","agent_reasoning","context_compacted","turn_aborted","token_count"]),f=e=>typeof e=="object"&&e!==null,y=e=>{try{return JSON.parse(e)}catch{return null}},d=e=>{const t=[];for(const s of e){if(typeof s=="string"){const r=y(s);f(r)&&t.push(r);continue}f(s)&&t.push(s)}return t},m=e=>{if(typeof e.type!="string")return!1;if(l.has(e.type)){if(e.type==="response_item"){const t=e.payload&&typeof e.payload.type=="string"?e.payload.type:null;return t?u.has(t):!0}if(e.type==="event_msg"){const t=e.payload&&typeof e.payload.type=="string"?e.payload.type:null;return t?p.has(t):!0}return!0}return e.type.startsWith("response_")||e.type.startsWith("event_")},g=e=>{if(!Array.isArray(e)||e.length===0)return!1;const t=d(e).filter(m);return t.length===0||t.length/e.length<.6?!1:t.some(r=>r.type==="session_meta")?!0:t.filter(r=>l.has(r.type??"")).length/t.length>=.6},c=e=>typeof e!="object"||e===null?!1:"messages"in e&&Array.isArray(e.messages),_=e=>{let t=null;if(e.length>0&&typeof e[0]=="object"&&!c(e[0])&&(t=e),e.length>0&&typeof e[0]=="string"){let s=!1;try{const r=JSON.parse(e[0]);c(r)&&(s=!0)}catch{s=!0}if(!s){t=[];for(const r of e){const o=JSON.parse(r);t.push(o)}}}if(t!==null){let s=null,r=!1;for(const o in t[0])if(typeof t[0][o]=="string")try{const n=JSON.parse(t[0][o]);if(c(n)){s=o,r=!0;break}}catch{continue}else if(c(t[0][o])){s=o;break}if(s!==null){const o=[];for(const n of t){const a=r?JSON.parse(n[s]):n[s];a.metadata??={};for(const i in n)i!==s&&(a.metadata[`euphonyTransformed-${i}`]=n[i]);o.push(a)}return o}}return null},h=e=>{const t=[];for(const[s,r]of e.entries())if(typeof r=="string"){const o=JSON.parse(r);let n=r;o.conversation_id!==void 0&&o.id===void 0&&(o.id=o.conversation_id,n=JSON.stringify(o)),e[s]=n,t.push(Array.isArray(o.messages))}else{const o=r;o.conversation_id!==void 0&&o.id===void 0&&(o.id=o.conversation_id),e[s]=o,t.push(Array.isArray(o.messages))}return t.every(Boolean)},S=e=>{const t=[];try{const s=JSON.parse(e);return t.push(s),t}catch{for(const r of e.split(`
2
- `))try{t.push(JSON.parse(r))}catch{}}return t},N=e=>{let t=S(e);if(t.length===0)throw new Error("Failed to read any JSON or JSONL data.");if(g(t))return{dataType:"codex",codexSessionData:t};const s=_(t);if(s&&(t=s),!h(t))return{dataType:"json",jsonData:t};const r=[];for(const o of t)typeof o=="string"?r.push(JSON.parse(o)):r.push(o);return{dataType:"conversation",conversationData:r}};self.onmessage=async e=>{if(e.data.command!=="startParseData"){console.error("Worker: unknown message",e.data.command);return}const{requestID:t,sourceName:s,sourceText:r,sourceFile:o}=e.data.payload;try{const n=r??await o?.text();if(n===void 0)throw new Error("No source text or file was provided.");const a=N(n),i={command:"finishParseData",payload:{requestID:t,sourceName:s,...a}};postMessage(i)}catch(n){const a={command:"error",payload:{requestID:t,sourceName:s,message:n instanceof Error?n.message:String(n)}};postMessage(a)}}})();