@urun-sh/react 0.1.43 → 0.1.46
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.css +1 -0
- package/dist/index.js +9 -1
- package/dist/index.mjs +9 -1
- package/dist/styles.css +28 -0
- package/package.json +21 -15
package/dist/index.css
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
:root{--urun-bg: #ffffff;--urun-text: #1a1a2e;--urun-border: #e2e8f0;--urun-radius: 8px;--urun-font: system-ui, -apple-system, sans-serif;--urun-progress-bg: #e2e8f0;--urun-progress-fill: #3b82f6;--urun-progress-success: #22c55e;--urun-progress-error: #ef4444;--urun-progress-height: 8px;--urun-status-thinking: #f59e0b;--urun-status-generating: #3b82f6;--urun-status-idle: #94a3b8;--urun-status-error: #ef4444;--urun-status-indicator-size: 8px;--urun-cursor-color: #3b82f6;--urun-cursor-width: 2px;--urun-metric-bg: #f8fafc;--urun-metric-label-color: #64748b;--urun-metric-value-color: #1a1a2e}.urun-progress-card{font-family:var(--urun-font);color:var(--urun-text);border:1px solid var(--urun-border);border-radius:var(--urun-radius);padding:12px 16px;background:var(--urun-bg)}.urun-progress-label{font-size:.875rem;font-weight:500;margin-bottom:8px}.urun-progress-bar{height:var(--urun-progress-height);background:var(--urun-progress-bg);border-radius:calc(var(--urun-progress-height) / 2);overflow:hidden}.urun-progress-fill{height:100%;background:var(--urun-progress-fill);border-radius:inherit;transition:width .3s ease}.urun-progress-card[data-variant=success] .urun-progress-fill{background:var(--urun-progress-success)}.urun-progress-card[data-variant=error] .urun-progress-fill{background:var(--urun-progress-error)}.urun-progress-text{font-size:.75rem;color:var(--urun-metric-label-color);margin-top:4px;text-align:right}.urun-status-badge{display:inline-flex;align-items:center;gap:6px;font-family:var(--urun-font);font-size:.875rem;color:var(--urun-text)}.urun-status-indicator{display:inline-block;width:var(--urun-status-indicator-size);height:var(--urun-status-indicator-size);border-radius:50%;background:var(--urun-status-idle);flex-shrink:0}.urun-status-badge[data-state=thinking] .urun-status-indicator{background:var(--urun-status-thinking)}.urun-status-badge[data-state=generating] .urun-status-indicator{background:var(--urun-status-generating)}.urun-status-badge[data-state=error] .urun-status-indicator{background:var(--urun-status-error)}.urun-status-pulse{animation:urun-pulse 1.5s ease-in-out infinite}.urun-text-stream{font-family:var(--urun-font);color:var(--urun-text);white-space:pre-wrap;word-break:break-word}.urun-text-cursor{display:inline-block;width:var(--urun-cursor-width);height:1em;background:var(--urun-cursor-color);vertical-align:text-bottom;animation:urun-blink 1s step-end infinite}.urun-image-frame{margin:0;border:1px solid var(--urun-border);border-radius:var(--urun-radius);overflow:hidden;background:var(--urun-bg)}.urun-image{display:block;width:100%;height:auto}.urun-image-caption{padding:8px 12px;font-family:var(--urun-font);font-size:.875rem;color:var(--urun-metric-label-color);text-align:center}.urun-metrics-panel{display:grid;grid-template-columns:repeat(auto-fit,minmax(120px,1fr));gap:12px;font-family:var(--urun-font)}.urun-metric-card{background:var(--urun-metric-bg);border:1px solid var(--urun-border);border-radius:var(--urun-radius);padding:12px;text-align:center}.urun-metric-label{font-size:.75rem;color:var(--urun-metric-label-color);margin-bottom:4px}.urun-metric-value{font-size:1.25rem;font-weight:600;color:var(--urun-metric-value-color)}.urun-component-error{font-family:var(--urun-font);padding:8px 12px;border:1px solid var(--urun-status-error);border-radius:var(--urun-radius);background:#fef2f2;color:var(--urun-status-error);font-size:.875rem}@keyframes urun-pulse{0%,to{opacity:1}50%{opacity:.4}}@keyframes urun-blink{0%,to{opacity:1}50%{opacity:0}}[data-urun-video],[data-urun-video] .video-js,[data-urun-video] .vjs-tech{width:100%;height:100%}[data-urun-video] .vjs-tech{object-fit:contain}.urun-video-live.vjs-has-started .vjs-poster,.urun-video-live.vjs-has-started .vjs-loading-spinner,.urun-video-live.vjs-has-started .vjs-big-play-button{display:none!important}.urun-video-live .vjs-poster{background-color:transparent}
|
package/dist/index.js
CHANGED
|
@@ -1 +1,9 @@
|
|
|
1
|
-
"use strict";var ct=Object.create;var oe=Object.defineProperty;var pt=Object.getOwnPropertyDescriptor;var dt=Object.getOwnPropertyNames;var lt=Object.getPrototypeOf,mt=Object.prototype.hasOwnProperty;var ft=(t,e)=>{for(var r in e)oe(t,r,{get:e[r],enumerable:!0})},ke=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of dt(e))!mt.call(t,s)&&s!==r&&oe(t,s,{get:()=>e[s],enumerable:!(n=pt(e,s))||n.enumerable});return t};var gt=(t,e,r)=>(r=t!=null?ct(lt(t)):{},ke(e||!t||!t.__esModule?oe(r,"default",{value:t,enumerable:!0}):r,t)),ht=t=>ke(oe({},"__esModule",{value:!0}),t);var xt={};ft(xt,{ComponentRenderer:()=>Fe,ImageFrame:()=>Ge,ImageFrameSchema:()=>Ze,MetricsPanel:()=>Ye,MetricsPanelSchema:()=>Qe,ProgressCard:()=>Xe,ProgressCardSchema:()=>ze,StatusBadge:()=>Je,StatusBadgeSchema:()=>$e,TextStream:()=>Ke,TextStreamSchema:()=>We,UrunAuthProvider:()=>fe,UrunErrorBoundary:()=>H,UrunJwtProvider:()=>Ue,UrunProvider:()=>Ae,UrunVideo:()=>ot,authMode:()=>G,registerComponent:()=>je,urunPublicEnv:()=>M,useApp:()=>Ie,useChat:()=>Be,useCompletion:()=>Oe,useImageFrame:()=>Pe,useMetricsPanel:()=>Te,useProgressCard:()=>ve,useRequest:()=>qe,useStatusBadge:()=>Re,useTextStream:()=>Ce,useUrunAuth:()=>ae,usesWorkOSAuth:()=>xe});module.exports=ht(xt);var z=require("react");var be=require("react"),Z=require("react/jsx-runtime"),H=class extends be.Component{constructor(e){super(e),this.state={error:null}}static getDerivedStateFromError(e){return{error:e}}componentDidCatch(e,r){console.error("[urun] Error caught by UrunErrorBoundary:",e,r)}render(){if(this.state.error){let{fallback:e}=this.props;return typeof e=="function"?e(this.state.error):e||(0,Z.jsxs)("div",{role:"status","aria-live":"polite",style:{padding:"16px",border:"1px solid rgba(17, 24, 39, 0.12)",borderRadius:"8px",background:"#ffffff",color:"#111827",fontFamily:'system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif',maxWidth:"360px"},children:[(0,Z.jsx)("p",{style:{margin:0,fontWeight:600},children:"Connection interrupted"}),(0,Z.jsx)("p",{style:{margin:"6px 0 0",color:"#4b5563"},children:"Reconnecting automatically."})]})}return this.props.children}};var Ee=require("react"),ie=(0,Ee.createContext)(null);function B(t){return t&&t.trim()?t.trim():void 0}function M(t){switch(t){case"NEXT_PUBLIC_AUTH_MODE":return B(typeof process<"u"?process.env?.NEXT_PUBLIC_AUTH_MODE:void 0);case"NEXT_PUBLIC_AUTH_ENABLED":return B(typeof process<"u"?process.env?.NEXT_PUBLIC_AUTH_ENABLED:void 0);case"NEXT_PUBLIC_SESSION_AUTH_PROVIDER":return B(typeof process<"u"?process.env?.NEXT_PUBLIC_SESSION_AUTH_PROVIDER:void 0);case"NEXT_PUBLIC_SESSION_TOKEN":return B(typeof process<"u"?process.env?.NEXT_PUBLIC_SESSION_TOKEN:void 0);case"NEXT_PUBLIC_URUN_JWT":return B(typeof process<"u"?process.env?.NEXT_PUBLIC_URUN_JWT:void 0);case"VERCEL_ENV":return B(typeof process<"u"?process.env?.VERCEL_ENV:void 0);default:return B(typeof process<"u"?process.env?.[t]:void 0)}}function G(){let t=M("NEXT_PUBLIC_AUTH_MODE")?.toLowerCase();return t==="jwt"||t==="customer-jwt"||t==="test-jwt"?"jwt":t==="workos"||M("VERCEL_ENV")==="production"?"workos":M("NEXT_PUBLIC_AUTH_ENABLED")==="false"?"jwt":"workos"}function xe(){return G()==="workos"}var F=require("react"),we=require("react/jsx-runtime"),_e=(0,F.createContext)(null);function fe({getAccessToken:t,children:e}){let r=(0,F.useMemo)(()=>({getAccessToken:t}),[t]);return(0,we.jsx)(_e.Provider,{value:r,children:e})}var Ue=fe;function ae(){return(0,F.useContext)(_e)}var ue=require("react/jsx-runtime");function Ae({baseUrl:t,orgId:e,appId:r,jwt:n,authProvider:s,fallback:i,children:a}){let[_,u]=(0,z.useState)(),m=ae(),P=M("NEXT_PUBLIC_SESSION_TOKEN")??M("NEXT_PUBLIC_URUN_JWT"),c=G(),d=c==="workos"&&!n,E=n??(c==="jwt"?P:void 0)??_,U=s??M("NEXT_PUBLIC_SESSION_AUTH_PROVIDER"),T=d&&!E,v=(0,z.useMemo)(()=>({appId:r,baseUrl:t,orgId:e,jwt:E,getAccessToken:d?m?.getAccessToken:void 0,authProvider:U}),[r,m,t,U,E,e,d]);return(0,z.useEffect)(()=>{if(!d||!m)return;let f=!1,S=m;async function g(){try{let x=await S.getAccessToken();f||u(x??void 0)}catch{f||u(void 0)}}g();let w=window.setInterval(()=>{g()},6e4);return()=>{f=!0,window.clearInterval(w)}},[m,d]),(0,ue.jsx)(H,{fallback:i,children:T?(0,ue.jsx)("div",{role:"status","aria-live":"polite",children:"Signing in..."}):(0,ue.jsx)(ie.Provider,{value:v,children:a})})}var O=require("react"),Ne=require("@urun-sh/core");function St(t,e){return`${t}:${JSON.stringify(e??{})}`}var ge=class{constructor(e,r){this._doc=e;this._notify=r;this._unsubscribeChange=this._doc.on("change",()=>this._notify())}_doc;_notify;_unsubscribeChange;get(e,r){return this._doc.get(e,r)}set(e){this._doc.set(e),this._notify()}on(e,r){return this._doc.on(e,n=>r(n))}get synced(){return this._doc.synced}onSynced(e){return this._doc.onSynced(()=>{e(),this._notify()})}text(e){let r=this._doc.text(e),n=this._notify;return{append(s){r.append(s),n()},toString:()=>r.toString(),get length(){return r.length},on:(s,i)=>r.on(s,a=>{i(a),n()})}}dispose(){this._unsubscribeChange()}},he=class{constructor(e,r){this._stream=e;this._notify=r;this._unsubscribeTrack=this._stream.on("track",()=>this._notify())}_stream;_notify;_unsubscribeTrack;get track(){return this._stream.track}attach(e){return this._stream.attach(e)}attachVideo(e){return this._stream.attachVideo(e)}detach(){return this._stream.detach()}detachVideo(){return this._stream.detachVideo()}seek(e){return this._stream.seek(e)}on(e,r){return this._stream.on(e,r)}messages(){return this._stream.messages()}emit(e,r){return this._stream.emit(e,r)}dispose(){this._unsubscribeTrack()}},Se=class{constructor(e,r){this._session=e;this._notify=r;this._unsubscribePhase=this._session.onPhase(()=>this._notify())}_session;_notify;_docs=new Map;_streams=new Map;_unsubscribePhase;get id(){return this._session.id}get phase(){return this._session.phase}onPhase(e){return this._session.onPhase(e)}request(e,r){return this._session.request(e,r)}requestStream(e,r){return this._session.requestStream(e,r)}complete(e,r){return this._session.complete(e,r)}doc(e){let r=this._docs.get(e);return r||(r=new ge(this._session.doc(e),this._notify),this._docs.set(e,r)),r}stream(e){let r=this._streams.get(e);return r||(r=new he(this._session.stream(e),this._notify),this._streams.set(e,r)),r}disconnect(){for(let e of this._docs.values())e.dispose();for(let e of this._streams.values())e.dispose();this._docs.clear(),this._streams.clear(),this._unsubscribePhase(),this._session.disconnect(),this._notify()}};function Ie(){let t=(0,O.useContext)(ie);if(!t)throw new Error("useApp must be used within <UrunProvider>");if(!t.appId)throw new Error('useApp requires <UrunProvider appId="...">');let[,e]=(0,O.useReducer)(s=>s+1,0),r=(0,O.useRef)(new Map),n=(0,O.useMemo)(()=>(0,Ne.App)(t.appId,{baseUrl:t.baseUrl,orgId:t.orgId,jwt:t.jwt,getAccessToken:t.getAccessToken,authProvider:t.authProvider}),[t.appId,t.baseUrl,t.orgId,t.jwt,t.getAccessToken,t.authProvider]);return(0,O.useMemo)(()=>new Proxy({},{get(s,i){if(typeof i=="string")return a=>{let _=St(i,a),u=r.current.get(_);if(u)return u;let m=new Se(n[i](a),e);return r.current.set(_,m),m}}}),[n])}var C=require("react");function X(t){let e=t;if(!e||typeof e.request!="function"||typeof e.requestStream!="function")throw new Error("This session does not support request/requestStream. Upgrade @urun-sh/core to a version that ships the request/response primitive.");return e}function yt(t){return t instanceof Error?t:new Error(String(t))}function qe(t,e){let r=(0,C.useMemo)(()=>X(t),[t]),[n,s]=(0,C.useState)(void 0),[i,a]=(0,C.useState)(null),[_,u]=(0,C.useState)(!1),m=(0,C.useRef)(e);m.current=e;let P=(0,C.useRef)(0),c=(0,C.useRef)(null),d=(0,C.useRef)(!0);(0,C.useEffect)(()=>(d.current=!0,()=>{d.current=!1,c.current?.abort()}),[]);let E=(0,C.useCallback)(async v=>{c.current?.abort();let f=new AbortController;c.current=f;let S=++P.current,g=()=>d.current&&P.current===S;g()&&(u(!0),a(null));try{let w=await r.request(v,{...m.current,signal:f.signal});return g()&&(s(w),u(!1),m.current?.onSuccess?.(w)),w}catch(w){let x=yt(w);throw g()&&(a(x),u(!1),m.current?.onError?.(x)),x}},[r]),U=(0,C.useCallback)(v=>{E(v).catch(()=>{})},[E]),T=(0,C.useCallback)(()=>{P.current++,c.current?.abort(),c.current=null,s(void 0),a(null),u(!1)},[]);return{mutate:U,mutateAsync:E,data:n,error:i,isPending:_,reset:T}}var b=require("react");function Me(t){return t instanceof Error?t:new Error(String(t))}var vt=t=>typeof t=="string"?t:String(t);function Oe(t,e){let r=(0,b.useMemo)(()=>X(t),[t]),[n,s]=(0,b.useState)(""),[i,a]=(0,b.useState)(!1),[_,u]=(0,b.useState)(null),m=(0,b.useRef)(e);m.current=e;let P=(0,b.useRef)(0),c=(0,b.useRef)(null),d=(0,b.useRef)(!0);(0,b.useEffect)(()=>(d.current=!0,()=>{d.current=!1,c.current?.cancel(),c.current=null}),[]);let E=(0,b.useCallback)(()=>{P.current++,c.current?.cancel(),c.current=null,d.current&&a(!1)},[]),U=(0,b.useCallback)(async T=>{c.current?.cancel();let v=++P.current,f=()=>d.current&&P.current===v,S=m.current,g=S?.parseChunk??vt,w=S?.buildPayload??(l=>({prompt:l}));f()&&(s(""),u(null),a(!0));let{parseChunk:x,buildPayload:de,onFinish:N,onError:o,...p}=S??{},R="",k;try{k=r.requestStream(w(T),p),c.current=k}catch(l){let I=Me(l);f()&&(u(I),a(!1),S?.onError?.(I));return}try{for await(let l of k){if(P.current!==v)break;R+=g(l),f()&&s(R)}f()&&(a(!1),S?.onFinish?.(R))}catch(l){let I=Me(l);f()&&(u(I),a(!1),S?.onError?.(I))}finally{c.current===k&&(c.current=null)}},[r]);return{completion:n,complete:U,stop:E,isStreaming:i,error:_}}var h=require("react");function Le(t){return t instanceof Error?t:new Error(String(t))}var Rt=t=>typeof t=="string"?t:String(t),Ve=0;function ye(t){return Ve+=1,`${t}-${Ve}`}function Be(t,e){let r=(0,h.useMemo)(()=>X(t),[t]),[n,s]=(0,h.useState)(()=>(e?.initialMessages??[]).map(g=>({id:g.id??ye("msg"),role:g.role,content:g.content}))),[i,a]=(0,h.useState)(""),[_,u]=(0,h.useState)(!1),[m,P]=(0,h.useState)(null),c=(0,h.useRef)(e);c.current=e;let d=(0,h.useRef)(n);d.current=n;let E=(0,h.useRef)(i);E.current=i;let U=(0,h.useRef)(0),T=(0,h.useRef)(null),v=(0,h.useRef)(!0);(0,h.useEffect)(()=>(v.current=!0,()=>{v.current=!1,T.current?.cancel(),T.current=null}),[]);let f=(0,h.useCallback)(()=>{U.current++,T.current?.cancel(),T.current=null,v.current&&u(!1)},[]),S=(0,h.useCallback)(async g=>{let w=g===void 0,x=(w?E.current:g)??"";if(!x.trim())return;T.current?.cancel();let N=++U.current,o=()=>v.current&&U.current===N,p=c.current,R=p?.parseChunk??Rt,k={id:ye("msg"),role:"user",content:x},l={id:ye("msg"),role:"assistant",content:""},I=[...d.current,k].map(A=>({role:A.role,content:A.content})),K=[...d.current,k,l];d.current=K,s(K),w&&a(""),P(null),u(!0);let it=p?.buildPayload??(A=>({messages:A})),{initialMessages:_t,parseChunk:Ut,buildPayload:wt,onFinish:At,onError:Nt,...at}=p??{},ut=A=>{s(V=>V.map(me=>me.id===l.id?{...me,content:A}:me))},le="",se;try{se=r.requestStream(it(I),at),T.current=se}catch(A){let V=Le(A);o()&&(P(V),u(!1),p?.onError?.(V));return}try{for await(let A of se){if(U.current!==N)break;le+=R(A),o()&&ut(le)}o()&&(u(!1),p?.onFinish?.({...l,content:le}))}catch(A){let V=Le(A);o()&&(P(V),u(!1),p?.onError?.(V))}finally{T.current===se&&(T.current=null)}},[r]);return{messages:n,input:i,setInput:a,sendMessage:S,stop:f,isStreaming:_,error:m}}var De=new Map;function je(t,e,r){if(!r||typeof r.safeParse!="function")throw new Error(`registerComponent("${t}"): schema must be a valid Zod schema`);De.set(t,{component:e,schema:r})}function He(t,e){let r=De.get(t);if(!r)return{error:`Unknown component: "${t}"`};let n=r.schema.safeParse(e);return n.success?{Component:r.component,validatedProps:n.data}:{error:`Validation failed for "${t}": ${n.error.message}`}}var D=require("react/jsx-runtime");function Fe({name:t,props:e,fallback:r}){let n=He(t,e);if(n.error)return console.warn(`[urun] ComponentRenderer: ${n.error}`),r?(0,D.jsx)(D.Fragment,{children:r}):(0,D.jsx)("div",{className:"urun-component-error",role:"alert",children:(0,D.jsx)("span",{className:"urun-component-error-text",children:n.error})});let s=n.Component;return(0,D.jsx)(s,{...n.validatedProps})}var $=require("zod"),j=require("react/jsx-runtime"),ze=$.z.object({step:$.z.number().min(0),total:$.z.number().min(1),label:$.z.string().optional(),variant:$.z.enum(["default","success","error"]).default("default")});function ve(t){let{step:e,total:r,label:n,variant:s="default"}=t,i=Math.min(e/r*100,100),a=e>=r;return{step:e,total:r,label:n,variant:s,percentage:i,isComplete:a}}function Xe(t){let{step:e,total:r,label:n,variant:s,percentage:i}=ve(t);return(0,j.jsxs)("div",{className:"urun-progress-card","data-variant":s,children:[n&&(0,j.jsx)("div",{className:"urun-progress-label",children:n}),(0,j.jsx)("div",{className:"urun-progress-bar",children:(0,j.jsx)("div",{className:"urun-progress-fill",style:{width:`${i}%`}})}),(0,j.jsxs)("div",{className:"urun-progress-text",children:[e,"/",r]})]})}var ce=require("zod"),Q=require("react/jsx-runtime"),$e=ce.z.object({state:ce.z.enum(["thinking","generating","idle","error"]),message:ce.z.string().optional()}),Ct={thinking:"Thinking...",generating:"Generating...",idle:"Idle",error:"Error"};function Re(t){let{state:e,message:r}=t,n=e==="thinking"||e==="generating",s=r??Ct[e]??e;return{state:e,message:s,isActive:n}}function Je(t){let{state:e,message:r,isActive:n}=Re(t);return(0,Q.jsxs)("span",{className:"urun-status-badge","data-state":e,children:[(0,Q.jsx)("span",{className:`urun-status-indicator${n?" urun-status-pulse":""}`}),(0,Q.jsx)("span",{className:"urun-status-message",children:r})]})}var Y=require("react"),pe=require("zod"),ee=require("react/jsx-runtime"),We=pe.z.object({text:pe.z.string(),streaming:pe.z.boolean().default(!1)});function Ce(t){let{text:e,streaming:r=!1}=t,n=e.length===0;return{text:e,streaming:r,isEmpty:n}}function Ke(t){let{text:e,streaming:r}=Ce(t),n=(0,Y.useRef)(null),s=(0,Y.useRef)(0);return(0,Y.useEffect)(()=>{let i=n.current;i&&e.length!==s.current&&(i.textContent=e,s.current=e.length)},[e]),(0,ee.jsxs)("div",{className:"urun-text-stream",children:[(0,ee.jsx)("span",{ref:n,className:"urun-text-content"}),r&&(0,ee.jsx)("span",{className:"urun-text-cursor"})]})}var te=require("zod"),re=require("react/jsx-runtime"),Ze=te.z.object({src:te.z.string().url(),alt:te.z.string().optional(),caption:te.z.string().optional()});function Pe(t){let{src:e,alt:r,caption:n}=t;return{src:e,alt:r??"",caption:n}}function Ge(t){let{src:e,alt:r,caption:n}=Pe(t);return(0,re.jsxs)("figure",{className:"urun-image-frame",children:[(0,re.jsx)("img",{className:"urun-image",src:e,alt:r}),n&&(0,re.jsx)("figcaption",{className:"urun-image-caption",children:n})]})}var L=require("zod"),J=require("react/jsx-runtime"),Qe=L.z.object({metrics:L.z.array(L.z.object({label:L.z.string(),value:L.z.union([L.z.string(),L.z.number()]),unit:L.z.string().optional()}))});function Te(t){return{metrics:t.metrics.map(r=>({...r,displayValue:r.unit?`${r.value} ${r.unit}`:String(r.value)}))}}function Ye(t){let{metrics:e}=Te(t);return(0,J.jsx)("div",{className:"urun-metrics-panel",children:e.map((r,n)=>(0,J.jsxs)("div",{className:"urun-metric-card",children:[(0,J.jsx)("div",{className:"urun-metric-label",children:r.label}),(0,J.jsx)("div",{className:"urun-metric-value",children:r.displayValue})]},n))})}var y=require("react"),nt=gt(require("video.js")),cr=require("video.js/dist/video-js.css");var W=require("react");var ne=require("react"),Pt=require("@urun-sh/core/internal");var Tt=require("react/jsx-runtime"),et=(0,ne.createContext)(null);function tt(t){let e=(0,W.useContext)(et);if(!e)throw new Error("useTrack must be used within <SessionProvider> or <UrunProvider>");let[r,n]=(0,W.useState)(null);return(0,W.useEffect)(()=>{let s=e.getState()._transport;if(!s)return;let i=s.getTrackByName?.bind(s),a=i?.(t);a&&a.readyState!=="ended"&&n(a);let _=s.on("track",u=>{let m=i?.(t);m&&m.id!==u.id||(n(u),u.addEventListener("ended",()=>{n(null)}))});return()=>{_()}},[t,e]),r}var q=require("react/jsx-runtime");function rt(t){t.posterImage?.hide?.()}var kt=["playToggle","volumePanel","fullscreenToggle"],bt=["playToggle","volumePanel","currentTimeDisplay","timeDivider","durationDisplay","progressControl","remainingTimeDisplay","fullscreenToggle"],st=(0,y.forwardRef)(function(e,r){let{track:n,stream:s,src:i,type:a="video/mp4",className:_,videoClassName:u,poster:m,controls:P=!0,autoPlay:c=!0,muted:d=!0,onVideoElement:E,onPlayerReady:U,children:T}=e,v=typeof i=="string"&&i.length>0,f=!v,S=(0,y.useRef)(null),g=(0,y.useRef)(null),[w,x]=(0,y.useState)(!1),de=(0,y.useCallback)(o=>{S.current=o,typeof r=="function"?r(o):r&&(r.current=o),E?.(o)},[r,E]);(0,y.useImperativeHandle)(r,()=>S.current,[]);let N=(0,y.useCallback)(()=>{let o=S.current;if(!o||!o.srcObject&&!o.src)return;d&&(o.muted=!0,o.defaultMuted=!0),o.setAttribute("playsinline",""),o.setAttribute("webkit-playsinline","");let p=o.play();p&&typeof p.then=="function"&&p.then(()=>x(!1)).catch(R=>{(R instanceof Error?R.name:String(R))!=="AbortError"&&x(!0)})},[d]);return(0,y.useEffect)(()=>{if(typeof document>"u")return;let o=S.current;if(!o)return;d&&(o.muted=!0,o.defaultMuted=!0,o.setAttribute("muted","")),o.autoplay=c,o.setAttribute("playsinline",""),o.setAttribute("webkit-playsinline","");let p=(0,nt.default)(o,{controls:P,autoplay:c,muted:d,playsinline:!0,preload:"auto",fluid:!1,bigPlayButton:!0,poster:m,userActions:{click:!0,doubleClick:!1,hotkeys:!1},controlBar:{children:f?kt:bt}});f&&p.addClass("urun-video-live");let R=()=>x(!1),k=()=>{p.hasStarted(!0),rt(p),R()},l=()=>{f&&N()};return o.addEventListener("playing",k),o.addEventListener("loadedmetadata",l),f&&o.addEventListener("pause",l),g.current=p,U?.(p),()=>{o.removeEventListener("playing",k),o.removeEventListener("loadedmetadata",l),o.removeEventListener("pause",l),U?.(null),g.current&&(g.current.dispose(),g.current=null)}},[f]),(0,y.useEffect)(()=>{if(!v)return;let o=g.current;if(!o)return;let p=o.tech?.(!0)?.el?.();p&&(p.srcObject=null),o.src({src:i,type:a}),c&&N()},[v,i,a,c,N]),(0,y.useEffect)(()=>{if(!f)return;let o=g.current;if(!o)return;let p=n??null,R=s??null;!R&&p&&(R=new MediaStream([p]));let k=o.tech?.(!0)?.el?.()??S.current;if(!k)return;if(!R){k.srcObject=null,x(!1);return}k.srcObject=R,N();let l=R.getVideoTracks()[0]??p??null,I=()=>{o.hasStarted(!0),rt(o),N()},K=()=>{k.srcObject=null,x(!1)};return l&&(l.addEventListener("unmute",I),l.addEventListener("ended",K),l.muted||I()),()=>{l&&(l.removeEventListener("unmute",I),l.removeEventListener("ended",K))}},[f,n,s,N]),(0,q.jsxs)("div",{className:_,style:{position:"relative"},"data-urun-video-mode":f?"live":"vod",children:[(0,q.jsx)("video",{ref:de,className:["video-js","vjs-default-skin",u].filter(Boolean).join(" "),playsInline:!0}),w&&(0,q.jsx)("button",{type:"button",onClick:N,"aria-label":"Tap to play",style:{position:"absolute",inset:0,zIndex:30,display:"flex",alignItems:"center",justifyContent:"center",background:"rgba(0,0,0,0.6)",border:0,cursor:"pointer",color:"#fff"},children:(0,q.jsxs)("span",{style:{display:"inline-flex",alignItems:"center",gap:8,borderRadius:999,border:"1px solid rgba(255,255,255,0.2)",background:"rgba(255,255,255,0.1)",padding:"10px 20px",fontSize:14,fontWeight:500},children:[(0,q.jsx)("svg",{viewBox:"0 0 24 24",fill:"currentColor",width:16,height:16,"aria-hidden":!0,children:(0,q.jsx)("path",{d:"M8 5v14l11-7z"})}),"Tap to play"]})}),T]})}),Et=(0,y.forwardRef)(function({name:e,...r},n){let s=tt(e);return(0,q.jsx)(st,{ref:n,...r,track:s})}),ot=(0,y.forwardRef)(function(e,r){return!!e.name&&!e.track&&!e.stream&&!(typeof e.src=="string"&&e.src)?(0,q.jsx)(Et,{ref:r,...e,name:e.name}):(0,q.jsx)(st,{ref:r,...e})});0&&(module.exports={ComponentRenderer,ImageFrame,ImageFrameSchema,MetricsPanel,MetricsPanelSchema,ProgressCard,ProgressCardSchema,StatusBadge,StatusBadgeSchema,TextStream,TextStreamSchema,UrunAuthProvider,UrunErrorBoundary,UrunJwtProvider,UrunProvider,UrunVideo,authMode,registerComponent,urunPublicEnv,useApp,useChat,useCompletion,useImageFrame,useMetricsPanel,useProgressCard,useRequest,useStatusBadge,useTextStream,useUrunAuth,usesWorkOSAuth});
|
|
1
|
+
"use strict";var dr=Object.create;var oe=Object.defineProperty;var lr=Object.getOwnPropertyDescriptor;var pr=Object.getOwnPropertyNames;var mr=Object.getPrototypeOf,fr=Object.prototype.hasOwnProperty;var gr=(r,e)=>{for(var t in e)oe(r,t,{get:e[t],enumerable:!0})},xe=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of pr(e))!fr.call(r,s)&&s!==t&&oe(r,s,{get:()=>e[s],enumerable:!(n=lr(e,s))||n.enumerable});return r};var hr=(r,e,t)=>(t=r!=null?dr(mr(r)):{},xe(e||!r||!r.__esModule?oe(t,"default",{value:r,enumerable:!0}):t,r)),vr=r=>xe(oe({},"__esModule",{value:!0}),r);var Ur={};gr(Ur,{ComponentRenderer:()=>He,ImageFrame:()=>Ge,ImageFrameSchema:()=>Ze,MetricsPanel:()=>Qe,MetricsPanelSchema:()=>Ye,ProgressCard:()=>Xe,ProgressCardSchema:()=>Fe,StatusBadge:()=>Je,StatusBadgeSchema:()=>$e,TextStream:()=>Ke,TextStreamSchema:()=>We,UrunAuthProvider:()=>fe,UrunErrorBoundary:()=>z,UrunJwtProvider:()=>_e,UrunProvider:()=>Ae,UrunVideo:()=>ir,authMode:()=>G,registerComponent:()=>De,urunPublicEnv:()=>M,useApp:()=>Ne,useChat:()=>Ve,useCompletion:()=>Oe,useImageFrame:()=>Ce,useMetricsPanel:()=>Re,useProgressCard:()=>be,useRequest:()=>qe,useStatusBadge:()=>Se,useTextStream:()=>ke,useUrunAuth:()=>ae,usesWorkOSAuth:()=>Ee});module.exports=vr(Ur);var F=require("react");var Te=require("react"),Z=require("react/jsx-runtime"),z=class extends Te.Component{constructor(e){super(e),this.state={error:null}}static getDerivedStateFromError(e){return{error:e}}componentDidCatch(e,t){console.error("[urun] Error caught by UrunErrorBoundary:",e,t)}render(){if(this.state.error){let{fallback:e}=this.props;return typeof e=="function"?e(this.state.error):e||(0,Z.jsxs)("div",{role:"status","aria-live":"polite",style:{padding:"16px",border:"1px solid rgba(17, 24, 39, 0.12)",borderRadius:"8px",background:"#ffffff",color:"#111827",fontFamily:'system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif',maxWidth:"360px"},children:[(0,Z.jsx)("p",{style:{margin:0,fontWeight:600},children:"Connection interrupted"}),(0,Z.jsx)("p",{style:{margin:"6px 0 0",color:"#4b5563"},children:"Reconnecting automatically."})]})}return this.props.children}};var Pe=require("react"),ie=(0,Pe.createContext)(null);function V(r){return r&&r.trim()?r.trim():void 0}function M(r){switch(r){case"NEXT_PUBLIC_AUTH_MODE":return V(typeof process<"u"?process.env?.NEXT_PUBLIC_AUTH_MODE:void 0);case"NEXT_PUBLIC_AUTH_ENABLED":return V(typeof process<"u"?process.env?.NEXT_PUBLIC_AUTH_ENABLED:void 0);case"NEXT_PUBLIC_SESSION_AUTH_PROVIDER":return V(typeof process<"u"?process.env?.NEXT_PUBLIC_SESSION_AUTH_PROVIDER:void 0);case"NEXT_PUBLIC_SESSION_TOKEN":return V(typeof process<"u"?process.env?.NEXT_PUBLIC_SESSION_TOKEN:void 0);case"NEXT_PUBLIC_URUN_JWT":return V(typeof process<"u"?process.env?.NEXT_PUBLIC_URUN_JWT:void 0);case"VERCEL_ENV":return V(typeof process<"u"?process.env?.VERCEL_ENV:void 0);default:return V(typeof process<"u"?process.env?.[r]:void 0)}}function G(){let r=M("NEXT_PUBLIC_AUTH_MODE")?.toLowerCase();return r==="jwt"||r==="customer-jwt"||r==="test-jwt"?"jwt":r==="workos"||M("VERCEL_ENV")==="production"?"workos":M("NEXT_PUBLIC_AUTH_ENABLED")==="false"?"jwt":"workos"}function Ee(){return G()==="workos"}var H=require("react"),Ue=require("react/jsx-runtime"),we=(0,H.createContext)(null);function fe({getAccessToken:r,children:e}){let t=(0,H.useMemo)(()=>({getAccessToken:r}),[r]);return(0,Ue.jsx)(we.Provider,{value:t,children:e})}var _e=fe;function ae(){return(0,H.useContext)(we)}var ue=require("react/jsx-runtime");function Ae({baseUrl:r,orgId:e,appId:t,jwt:n,authProvider:s,fallback:i,children:a}){let[w,u]=(0,F.useState)(),m=ae(),C=M("NEXT_PUBLIC_SESSION_TOKEN")??M("NEXT_PUBLIC_URUN_JWT"),c=G(),l=c==="workos"&&!n,P=n??(c==="jwt"?C:void 0)??w,_=s??M("NEXT_PUBLIC_SESSION_AUTH_PROVIDER"),R=l&&!P,b=(0,F.useMemo)(()=>({appId:t,baseUrl:r,orgId:e,jwt:P,getAccessToken:l?m?.getAccessToken:void 0,authProvider:_}),[t,m,r,_,P,e,l]);return(0,F.useEffect)(()=>{if(!l||!m)return;let f=!1,v=m;async function g(){try{let E=await v.getAccessToken();f||u(E??void 0)}catch{f||u(void 0)}}g();let U=window.setInterval(()=>{g()},6e4);return()=>{f=!0,window.clearInterval(U)}},[m,l]),(0,ue.jsx)(z,{fallback:i,children:R?(0,ue.jsx)("div",{role:"status","aria-live":"polite",children:"Signing in..."}):(0,ue.jsx)(ie.Provider,{value:b,children:a})})}var O=require("react"),Ie=require("@urun-sh/core");function yr(r,e){return`${r}:${JSON.stringify(e??{})}`}var ge=class{constructor(e,t){this._doc=e;this._notify=t;this._unsubscribeChange=this._doc.on("change",()=>this._notify())}_doc;_notify;_unsubscribeChange;get(e,t){return this._doc.get(e,t)}set(e){this._doc.set(e),this._notify()}on(e,t){return this._doc.on(e,n=>t(n))}get synced(){return this._doc.synced}onSynced(e){return this._doc.onSynced(()=>{e(),this._notify()})}text(e){let t=this._doc.text(e),n=this._notify;return{append(s){t.append(s),n()},toString:()=>t.toString(),get length(){return t.length},on:(s,i)=>t.on(s,a=>{i(a),n()})}}dispose(){this._unsubscribeChange()}},he=class{constructor(e,t){this._stream=e;this._notify=t;this._unsubscribeTrack=this._stream.on("track",()=>this._notify())}_stream;_notify;_unsubscribeTrack;get track(){return this._stream.track}attach(e){return this._stream.attach(e)}attachVideo(e){return this._stream.attachVideo(e)}detach(){return this._stream.detach()}detachVideo(){return this._stream.detachVideo()}seek(e){return this._stream.seek(e)}on(e,t){return this._stream.on(e,t)}messages(){return this._stream.messages()}emit(e,t){return this._stream.emit(e,t)}dispose(){this._unsubscribeTrack()}},ve=class{constructor(e,t){this._session=e;this._notify=t;this._unsubscribePhase=this._session.onPhase(()=>this._notify())}_session;_notify;_docs=new Map;_streams=new Map;_unsubscribePhase;get id(){return this._session.id}get phase(){return this._session.phase}onPhase(e){return this._session.onPhase(e)}request(e,t){return this._session.request(e,t)}requestStream(e,t){return this._session.requestStream(e,t)}complete(e,t){return this._session.complete(e,t)}doc(e){let t=this._docs.get(e);return t||(t=new ge(this._session.doc(e),this._notify),this._docs.set(e,t)),t}stream(e){let t=this._streams.get(e);return t||(t=new he(this._session.stream(e),this._notify),this._streams.set(e,t)),t}disconnect(){for(let e of this._docs.values())e.dispose();for(let e of this._streams.values())e.dispose();this._docs.clear(),this._streams.clear(),this._unsubscribePhase(),this._session.disconnect(),this._notify()}};function Ne(){let r=(0,O.useContext)(ie);if(!r)throw new Error("useApp must be used within <UrunProvider>");if(!r.appId)throw new Error('useApp requires <UrunProvider appId="...">');let[,e]=(0,O.useReducer)(s=>s+1,0),t=(0,O.useRef)(new Map),n=(0,O.useMemo)(()=>(0,Ie.App)(r.appId,{baseUrl:r.baseUrl,orgId:r.orgId,jwt:r.jwt,getAccessToken:r.getAccessToken,authProvider:r.authProvider}),[r.appId,r.baseUrl,r.orgId,r.jwt,r.getAccessToken,r.authProvider]);return(0,O.useMemo)(()=>new Proxy({},{get(s,i){if(typeof i=="string")return a=>{let w=yr(i,a),u=t.current.get(w);if(u)return u;let m=new ve(n[i](a),e);return t.current.set(w,m),m}}}),[n])}var k=require("react");function X(r){let e=r;if(!e||typeof e.request!="function"||typeof e.requestStream!="function")throw new Error("This session does not support request/requestStream. Upgrade @urun-sh/core to a version that ships the request/response primitive.");return e}function br(r){return r instanceof Error?r:new Error(String(r))}function qe(r,e){let t=(0,k.useMemo)(()=>X(r),[r]),[n,s]=(0,k.useState)(void 0),[i,a]=(0,k.useState)(null),[w,u]=(0,k.useState)(!1),m=(0,k.useRef)(e);m.current=e;let C=(0,k.useRef)(0),c=(0,k.useRef)(null),l=(0,k.useRef)(!0);(0,k.useEffect)(()=>(l.current=!0,()=>{l.current=!1,c.current?.abort()}),[]);let P=(0,k.useCallback)(async b=>{c.current?.abort();let f=new AbortController;c.current=f;let v=++C.current,g=()=>l.current&&C.current===v;g()&&(u(!0),a(null));try{let U=await t.request(b,{...m.current,signal:f.signal});return g()&&(s(U),u(!1),m.current?.onSuccess?.(U)),U}catch(U){let E=br(U);throw g()&&(a(E),u(!1),m.current?.onError?.(E)),E}},[t]),_=(0,k.useCallback)(b=>{P(b).catch(()=>{})},[P]),R=(0,k.useCallback)(()=>{C.current++,c.current?.abort(),c.current=null,s(void 0),a(null),u(!1)},[]);return{mutate:_,mutateAsync:P,data:n,error:i,isPending:w,reset:R}}var T=require("react");function Me(r){return r instanceof Error?r:new Error(String(r))}var Sr=r=>typeof r=="string"?r:String(r);function Oe(r,e){let t=(0,T.useMemo)(()=>X(r),[r]),[n,s]=(0,T.useState)(""),[i,a]=(0,T.useState)(!1),[w,u]=(0,T.useState)(null),m=(0,T.useRef)(e);m.current=e;let C=(0,T.useRef)(0),c=(0,T.useRef)(null),l=(0,T.useRef)(!0);(0,T.useEffect)(()=>(l.current=!0,()=>{l.current=!1,c.current?.cancel(),c.current=null}),[]);let P=(0,T.useCallback)(()=>{C.current++,c.current?.cancel(),c.current=null,l.current&&a(!1)},[]),_=(0,T.useCallback)(async R=>{c.current?.cancel();let b=++C.current,f=()=>l.current&&C.current===b,v=m.current,g=v?.parseChunk??Sr,U=v?.buildPayload??(p=>({prompt:p}));f()&&(s(""),u(null),a(!0));let{parseChunk:E,buildPayload:le,onFinish:I,onError:o,...d}=v??{},S="",x;try{x=t.requestStream(U(R),d),c.current=x}catch(p){let N=Me(p);f()&&(u(N),a(!1),v?.onError?.(N));return}try{for await(let p of x){if(C.current!==b)break;S+=g(p),f()&&s(S)}f()&&(a(!1),v?.onFinish?.(S))}catch(p){let N=Me(p);f()&&(u(N),a(!1),v?.onError?.(N))}finally{c.current===x&&(c.current=null)}},[t]);return{completion:n,complete:_,stop:P,isStreaming:i,error:w}}var h=require("react");function Le(r){return r instanceof Error?r:new Error(String(r))}var kr=r=>typeof r=="string"?r:String(r),je=0;function ye(r){return je+=1,`${r}-${je}`}function Ve(r,e){let t=(0,h.useMemo)(()=>X(r),[r]),[n,s]=(0,h.useState)(()=>(e?.initialMessages??[]).map(g=>({id:g.id??ye("msg"),role:g.role,content:g.content}))),[i,a]=(0,h.useState)(""),[w,u]=(0,h.useState)(!1),[m,C]=(0,h.useState)(null),c=(0,h.useRef)(e);c.current=e;let l=(0,h.useRef)(n);l.current=n;let P=(0,h.useRef)(i);P.current=i;let _=(0,h.useRef)(0),R=(0,h.useRef)(null),b=(0,h.useRef)(!0);(0,h.useEffect)(()=>(b.current=!0,()=>{b.current=!1,R.current?.cancel(),R.current=null}),[]);let f=(0,h.useCallback)(()=>{_.current++,R.current?.cancel(),R.current=null,b.current&&u(!1)},[]),v=(0,h.useCallback)(async g=>{let U=g===void 0,E=(U?P.current:g)??"";if(!E.trim())return;R.current?.cancel();let I=++_.current,o=()=>b.current&&_.current===I,d=c.current,S=d?.parseChunk??kr,x={id:ye("msg"),role:"user",content:E},p={id:ye("msg"),role:"assistant",content:""},N=[...l.current,x].map(A=>({role:A.role,content:A.content})),K=[...l.current,x,p];l.current=K,s(K),U&&a(""),C(null),u(!0);let ar=d?.buildPayload??(A=>({messages:A})),{initialMessages:Ar,parseChunk:Ir,buildPayload:Nr,onFinish:qr,onError:Mr,...ur}=d??{},cr=A=>{s(j=>j.map(me=>me.id===p.id?{...me,content:A}:me))},pe="",se;try{se=t.requestStream(ar(N),ur),R.current=se}catch(A){let j=Le(A);o()&&(C(j),u(!1),d?.onError?.(j));return}try{for await(let A of se){if(_.current!==I)break;pe+=S(A),o()&&cr(pe)}o()&&(u(!1),d?.onFinish?.({...p,content:pe}))}catch(A){let j=Le(A);o()&&(C(j),u(!1),d?.onError?.(j))}finally{R.current===se&&(R.current=null)}},[t]);return{messages:n,input:i,setInput:a,sendMessage:v,stop:f,isStreaming:w,error:m}}var Be=new Map;function De(r,e,t){if(!t||typeof t.safeParse!="function")throw new Error(`registerComponent("${r}"): schema must be a valid Zod schema`);Be.set(r,{component:e,schema:t})}function ze(r,e){let t=Be.get(r);if(!t)return{error:`Unknown component: "${r}"`};let n=t.schema.safeParse(e);return n.success?{Component:t.component,validatedProps:n.data}:{error:`Validation failed for "${r}": ${n.error.message}`}}var B=require("react/jsx-runtime");function He({name:r,props:e,fallback:t}){let n=ze(r,e);if(n.error)return console.warn(`[urun] ComponentRenderer: ${n.error}`),t?(0,B.jsx)(B.Fragment,{children:t}):(0,B.jsx)("div",{className:"urun-component-error",role:"alert",children:(0,B.jsx)("span",{className:"urun-component-error-text",children:n.error})});let s=n.Component;return(0,B.jsx)(s,{...n.validatedProps})}var $=require("zod"),D=require("react/jsx-runtime"),Fe=$.z.object({step:$.z.number().min(0),total:$.z.number().min(1),label:$.z.string().optional(),variant:$.z.enum(["default","success","error"]).default("default")});function be(r){let{step:e,total:t,label:n,variant:s="default"}=r,i=Math.min(e/t*100,100),a=e>=t;return{step:e,total:t,label:n,variant:s,percentage:i,isComplete:a}}function Xe(r){let{step:e,total:t,label:n,variant:s,percentage:i}=be(r);return(0,D.jsxs)("div",{className:"urun-progress-card","data-variant":s,children:[n&&(0,D.jsx)("div",{className:"urun-progress-label",children:n}),(0,D.jsx)("div",{className:"urun-progress-bar",children:(0,D.jsx)("div",{className:"urun-progress-fill",style:{width:`${i}%`}})}),(0,D.jsxs)("div",{className:"urun-progress-text",children:[e,"/",t]})]})}var ce=require("zod"),Y=require("react/jsx-runtime"),$e=ce.z.object({state:ce.z.enum(["thinking","generating","idle","error"]),message:ce.z.string().optional()}),Cr={thinking:"Thinking...",generating:"Generating...",idle:"Idle",error:"Error"};function Se(r){let{state:e,message:t}=r,n=e==="thinking"||e==="generating",s=t??Cr[e]??e;return{state:e,message:s,isActive:n}}function Je(r){let{state:e,message:t,isActive:n}=Se(r);return(0,Y.jsxs)("span",{className:"urun-status-badge","data-state":e,children:[(0,Y.jsx)("span",{className:`urun-status-indicator${n?" urun-status-pulse":""}`}),(0,Y.jsx)("span",{className:"urun-status-message",children:t})]})}var Q=require("react"),de=require("zod"),ee=require("react/jsx-runtime"),We=de.z.object({text:de.z.string(),streaming:de.z.boolean().default(!1)});function ke(r){let{text:e,streaming:t=!1}=r,n=e.length===0;return{text:e,streaming:t,isEmpty:n}}function Ke(r){let{text:e,streaming:t}=ke(r),n=(0,Q.useRef)(null),s=(0,Q.useRef)(0);return(0,Q.useEffect)(()=>{let i=n.current;i&&e.length!==s.current&&(i.textContent=e,s.current=e.length)},[e]),(0,ee.jsxs)("div",{className:"urun-text-stream",children:[(0,ee.jsx)("span",{ref:n,className:"urun-text-content"}),t&&(0,ee.jsx)("span",{className:"urun-text-cursor"})]})}var re=require("zod"),te=require("react/jsx-runtime"),Ze=re.z.object({src:re.z.string().url(),alt:re.z.string().optional(),caption:re.z.string().optional()});function Ce(r){let{src:e,alt:t,caption:n}=r;return{src:e,alt:t??"",caption:n}}function Ge(r){let{src:e,alt:t,caption:n}=Ce(r);return(0,te.jsxs)("figure",{className:"urun-image-frame",children:[(0,te.jsx)("img",{className:"urun-image",src:e,alt:t}),n&&(0,te.jsx)("figcaption",{className:"urun-image-caption",children:n})]})}var L=require("zod"),J=require("react/jsx-runtime"),Ye=L.z.object({metrics:L.z.array(L.z.object({label:L.z.string(),value:L.z.union([L.z.string(),L.z.number()]),unit:L.z.string().optional()}))});function Re(r){return{metrics:r.metrics.map(t=>({...t,displayValue:t.unit?`${t.value} ${t.unit}`:String(t.value)}))}}function Qe(r){let{metrics:e}=Re(r);return(0,J.jsx)("div",{className:"urun-metrics-panel",children:e.map((t,n)=>(0,J.jsxs)("div",{className:"urun-metric-card",children:[(0,J.jsx)("div",{className:"urun-metric-label",children:t.label}),(0,J.jsx)("div",{className:"urun-metric-value",children:t.displayValue})]},n))})}var y=require("react"),sr=hr(require("video.js")),ft=require("video.js/dist/video-js.css");var W=require("react");var ne=require("react"),Rr=require("@urun-sh/core/internal");var xr=require("react/jsx-runtime"),er=(0,ne.createContext)(null);function rr(r){let e=(0,W.useContext)(er);if(!e)throw new Error("useTrack must be used within <SessionProvider> or <UrunProvider>");let[t,n]=(0,W.useState)(null);return(0,W.useEffect)(()=>{let s=e.getState()._transport;if(!s)return;let i=s.getTrackByName?.bind(s),a=i?.(r);a&&a.readyState!=="ended"&&n(a);let w=s.on("track",u=>{let m=i?.(r);m&&m.id!==u.id||(n(u),u.addEventListener("ended",()=>{n(null)}))});return()=>{w()}},[r,e]),t}var q=require("react/jsx-runtime");function tr(r){r.posterImage?.hide?.()}var Tr=`
|
|
2
|
+
[data-urun-video]{width:100%;height:100%}
|
|
3
|
+
[data-urun-video] .video-js,[data-urun-video] .vjs-tech{width:100%;height:100%}
|
|
4
|
+
[data-urun-video] .vjs-tech{object-fit:contain}
|
|
5
|
+
.urun-video-live.vjs-has-started .vjs-poster,
|
|
6
|
+
.urun-video-live.vjs-has-started .vjs-loading-spinner,
|
|
7
|
+
.urun-video-live.vjs-has-started .vjs-big-play-button{display:none !important}
|
|
8
|
+
.urun-video-live .vjs-poster{background-color:transparent}
|
|
9
|
+
`,nr="urun-video-critical-css";function Pr(){if(typeof document>"u"||document.getElementById(nr))return;let r=document.createElement("style");r.id=nr,r.textContent=Tr,document.head.appendChild(r)}var Er=["playToggle","volumePanel","fullscreenToggle"],wr=["playToggle","volumePanel","currentTimeDisplay","timeDivider","durationDisplay","progressControl","remainingTimeDisplay","fullscreenToggle"],or=(0,y.forwardRef)(function(e,t){let{track:n,stream:s,src:i,type:a="video/mp4",className:w,videoClassName:u,poster:m,controls:C=!0,autoPlay:c=!0,muted:l=!0,onVideoElement:P,onPlayerReady:_,children:R}=e,b=typeof i=="string"&&i.length>0,f=!b,v=(0,y.useRef)(null),g=(0,y.useRef)(null),[U,E]=(0,y.useState)(!1),le=(0,y.useCallback)(o=>{v.current=o,typeof t=="function"?t(o):t&&(t.current=o),P?.(o)},[t,P]);(0,y.useImperativeHandle)(t,()=>v.current,[]);let I=(0,y.useCallback)(()=>{let o=v.current;if(!o||!o.srcObject&&!o.src)return;l&&(o.muted=!0,o.defaultMuted=!0),o.setAttribute("playsinline",""),o.setAttribute("webkit-playsinline","");let d=o.play();d&&typeof d.then=="function"&&d.then(()=>E(!1)).catch(S=>{(S instanceof Error?S.name:String(S))!=="AbortError"&&E(!0)})},[l]);return(0,y.useEffect)(()=>{if(typeof document>"u")return;let o=v.current;if(!o)return;Pr(),l&&(o.muted=!0,o.defaultMuted=!0,o.setAttribute("muted","")),o.autoplay=c,o.setAttribute("playsinline",""),o.setAttribute("webkit-playsinline","");let d=(0,sr.default)(o,{controls:C,autoplay:c,muted:l,playsinline:!0,preload:"auto",fluid:!1,bigPlayButton:!0,poster:m,userActions:{click:!0,doubleClick:!1,hotkeys:!1},controlBar:{children:f?Er:wr}});f&&d.addClass("urun-video-live");let S=()=>E(!1),x=()=>{d.hasStarted(!0),tr(d),S()},p=()=>{f&&I()};return o.addEventListener("playing",x),o.addEventListener("loadedmetadata",p),f&&o.addEventListener("pause",p),g.current=d,_?.(d),()=>{o.removeEventListener("playing",x),o.removeEventListener("loadedmetadata",p),o.removeEventListener("pause",p),_?.(null),g.current&&(g.current.dispose(),g.current=null)}},[f]),(0,y.useEffect)(()=>{if(!b)return;let o=g.current;if(!o)return;let d=o.tech?.(!0)?.el?.();d&&(d.srcObject=null),o.src({src:i,type:a}),c&&I()},[b,i,a,c,I]),(0,y.useEffect)(()=>{if(!f)return;let o=g.current;if(!o)return;let d=n??null,S=s??null;!S&&d&&(S=new MediaStream([d]));let x=o.tech?.(!0)?.el?.()??v.current;if(!x)return;if(!S){x.srcObject=null,E(!1);return}x.srcObject=S,I();let p=S.getVideoTracks()[0]??d??null,N=()=>{o.hasStarted(!0),tr(o),I()},K=()=>{x.srcObject=null,E(!1)};return p&&(p.addEventListener("unmute",N),p.addEventListener("ended",K),p.muted||N()),()=>{p&&(p.removeEventListener("unmute",N),p.removeEventListener("ended",K))}},[f,n,s,I]),(0,q.jsxs)("div",{className:w,style:{position:"relative",width:"100%",height:"100%"},"data-urun-video":"","data-urun-video-mode":f?"live":"vod",children:[(0,q.jsx)("video",{ref:le,className:["video-js","vjs-default-skin",u].filter(Boolean).join(" "),playsInline:!0}),U&&(0,q.jsx)("button",{type:"button",onClick:I,"aria-label":"Tap to play",style:{position:"absolute",inset:0,zIndex:30,display:"flex",alignItems:"center",justifyContent:"center",background:"rgba(0,0,0,0.6)",border:0,cursor:"pointer",color:"#fff"},children:(0,q.jsxs)("span",{style:{display:"inline-flex",alignItems:"center",gap:8,borderRadius:999,border:"1px solid rgba(255,255,255,0.2)",background:"rgba(255,255,255,0.1)",padding:"10px 20px",fontSize:14,fontWeight:500},children:[(0,q.jsx)("svg",{viewBox:"0 0 24 24",fill:"currentColor",width:16,height:16,"aria-hidden":!0,children:(0,q.jsx)("path",{d:"M8 5v14l11-7z"})}),"Tap to play"]})}),R]})}),_r=(0,y.forwardRef)(function({name:e,...t},n){let s=rr(e);return(0,q.jsx)(or,{ref:n,...t,track:s})}),ir=(0,y.forwardRef)(function(e,t){return!!e.name&&!e.track&&!e.stream&&!(typeof e.src=="string"&&e.src)?(0,q.jsx)(_r,{ref:t,...e,name:e.name}):(0,q.jsx)(or,{ref:t,...e})});0&&(module.exports={ComponentRenderer,ImageFrame,ImageFrameSchema,MetricsPanel,MetricsPanelSchema,ProgressCard,ProgressCardSchema,StatusBadge,StatusBadgeSchema,TextStream,TextStreamSchema,UrunAuthProvider,UrunErrorBoundary,UrunJwtProvider,UrunProvider,UrunVideo,authMode,registerComponent,urunPublicEnv,useApp,useChat,useCompletion,useImageFrame,useMetricsPanel,useProgressCard,useRequest,useStatusBadge,useTextStream,useUrunAuth,usesWorkOSAuth});
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1,9 @@
|
|
|
1
|
-
import{a as je,b as He,c as G}from"./chunk-QAEWAWV4.mjs";import{useEffect as Je,useMemo as We,useState as Ke}from"react";import{Component as Fe}from"react";import{jsx as le,jsxs as ze}from"react/jsx-runtime";var V=class extends Fe{constructor(e){super(e),this.state={error:null}}static getDerivedStateFromError(e){return{error:e}}componentDidCatch(e,r){console.error("[urun] Error caught by UrunErrorBoundary:",e,r)}render(){if(this.state.error){let{fallback:e}=this.props;return typeof e=="function"?e(this.state.error):e||ze("div",{role:"status","aria-live":"polite",style:{padding:"16px",border:"1px solid rgba(17, 24, 39, 0.12)",borderRadius:"8px",background:"#ffffff",color:"#111827",fontFamily:'system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif',maxWidth:"360px"},children:[le("p",{style:{margin:0,fontWeight:600},children:"Connection interrupted"}),le("p",{style:{margin:"6px 0 0",color:"#4b5563"},children:"Reconnecting automatically."})]})}return this.props.children}};import{createContext as Xe}from"react";var j=Xe(null);function A(t){return t&&t.trim()?t.trim():void 0}function U(t){switch(t){case"NEXT_PUBLIC_AUTH_MODE":return A(typeof process<"u"?process.env?.NEXT_PUBLIC_AUTH_MODE:void 0);case"NEXT_PUBLIC_AUTH_ENABLED":return A(typeof process<"u"?process.env?.NEXT_PUBLIC_AUTH_ENABLED:void 0);case"NEXT_PUBLIC_SESSION_AUTH_PROVIDER":return A(typeof process<"u"?process.env?.NEXT_PUBLIC_SESSION_AUTH_PROVIDER:void 0);case"NEXT_PUBLIC_SESSION_TOKEN":return A(typeof process<"u"?process.env?.NEXT_PUBLIC_SESSION_TOKEN:void 0);case"NEXT_PUBLIC_URUN_JWT":return A(typeof process<"u"?process.env?.NEXT_PUBLIC_URUN_JWT:void 0);case"VERCEL_ENV":return A(typeof process<"u"?process.env?.VERCEL_ENV:void 0);default:return A(typeof process<"u"?process.env?.[t]:void 0)}}function H(){let t=U("NEXT_PUBLIC_AUTH_MODE")?.toLowerCase();return t==="jwt"||t==="customer-jwt"||t==="test-jwt"?"jwt":t==="workos"||U("VERCEL_ENV")==="production"?"workos":U("NEXT_PUBLIC_AUTH_ENABLED")==="false"?"jwt":"workos"}function $e(){return H()==="workos"}import{jsx as Q}from"react/jsx-runtime";function Ze({baseUrl:t,orgId:e,appId:r,jwt:n,authProvider:o,fallback:i,children:a}){let[k,u]=Ke(),m=G(),v=U("NEXT_PUBLIC_SESSION_TOKEN")??U("NEXT_PUBLIC_URUN_JWT"),c=H(),d=c==="workos"&&!n,P=n??(c==="jwt"?v:void 0)??k,b=o??U("NEXT_PUBLIC_SESSION_AUTH_PROVIDER"),R=d&&!P,S=We(()=>({appId:r,baseUrl:t,orgId:e,jwt:P,getAccessToken:d?m?.getAccessToken:void 0,authProvider:b}),[r,m,t,b,P,e,d]);return Je(()=>{if(!d||!m)return;let f=!1,h=m;async function g(){try{let T=await h.getAccessToken();f||u(T??void 0)}catch{f||u(void 0)}}g();let E=window.setInterval(()=>{g()},6e4);return()=>{f=!0,window.clearInterval(E)}},[m,d]),Q(V,{fallback:i,children:R?Q("div",{role:"status","aria-live":"polite",children:"Signing in..."}):Q(j.Provider,{value:S,children:a})})}import{useContext as Ge,useMemo as me,useReducer as Qe,useRef as Ye}from"react";import{App as et}from"@urun-sh/core";function tt(t,e){return`${t}:${JSON.stringify(e??{})}`}var Y=class{constructor(e,r){this._doc=e;this._notify=r;this._unsubscribeChange=this._doc.on("change",()=>this._notify())}_doc;_notify;_unsubscribeChange;get(e,r){return this._doc.get(e,r)}set(e){this._doc.set(e),this._notify()}on(e,r){return this._doc.on(e,n=>r(n))}get synced(){return this._doc.synced}onSynced(e){return this._doc.onSynced(()=>{e(),this._notify()})}text(e){let r=this._doc.text(e),n=this._notify;return{append(o){r.append(o),n()},toString:()=>r.toString(),get length(){return r.length},on:(o,i)=>r.on(o,a=>{i(a),n()})}}dispose(){this._unsubscribeChange()}},ee=class{constructor(e,r){this._stream=e;this._notify=r;this._unsubscribeTrack=this._stream.on("track",()=>this._notify())}_stream;_notify;_unsubscribeTrack;get track(){return this._stream.track}attach(e){return this._stream.attach(e)}attachVideo(e){return this._stream.attachVideo(e)}detach(){return this._stream.detach()}detachVideo(){return this._stream.detachVideo()}seek(e){return this._stream.seek(e)}on(e,r){return this._stream.on(e,r)}messages(){return this._stream.messages()}emit(e,r){return this._stream.emit(e,r)}dispose(){this._unsubscribeTrack()}},te=class{constructor(e,r){this._session=e;this._notify=r;this._unsubscribePhase=this._session.onPhase(()=>this._notify())}_session;_notify;_docs=new Map;_streams=new Map;_unsubscribePhase;get id(){return this._session.id}get phase(){return this._session.phase}onPhase(e){return this._session.onPhase(e)}request(e,r){return this._session.request(e,r)}requestStream(e,r){return this._session.requestStream(e,r)}complete(e,r){return this._session.complete(e,r)}doc(e){let r=this._docs.get(e);return r||(r=new Y(this._session.doc(e),this._notify),this._docs.set(e,r)),r}stream(e){let r=this._streams.get(e);return r||(r=new ee(this._session.stream(e),this._notify),this._streams.set(e,r)),r}disconnect(){for(let e of this._docs.values())e.dispose();for(let e of this._streams.values())e.dispose();this._docs.clear(),this._streams.clear(),this._unsubscribePhase(),this._session.disconnect(),this._notify()}};function rt(){let t=Ge(j);if(!t)throw new Error("useApp must be used within <UrunProvider>");if(!t.appId)throw new Error('useApp requires <UrunProvider appId="...">');let[,e]=Qe(o=>o+1,0),r=Ye(new Map),n=me(()=>et(t.appId,{baseUrl:t.baseUrl,orgId:t.orgId,jwt:t.jwt,getAccessToken:t.getAccessToken,authProvider:t.authProvider}),[t.appId,t.baseUrl,t.orgId,t.jwt,t.getAccessToken,t.authProvider]);return me(()=>new Proxy({},{get(o,i){if(typeof i=="string")return a=>{let k=tt(i,a),u=r.current.get(k);if(u)return u;let m=new te(n[i](a),e);return r.current.set(k,m),m}}}),[n])}import{useCallback as re,useEffect as nt,useMemo as st,useRef as F,useState as ne}from"react";function M(t){let e=t;if(!e||typeof e.request!="function"||typeof e.requestStream!="function")throw new Error("This session does not support request/requestStream. Upgrade @urun-sh/core to a version that ships the request/response primitive.");return e}function ot(t){return t instanceof Error?t:new Error(String(t))}function it(t,e){let r=st(()=>M(t),[t]),[n,o]=ne(void 0),[i,a]=ne(null),[k,u]=ne(!1),m=F(e);m.current=e;let v=F(0),c=F(null),d=F(!0);nt(()=>(d.current=!0,()=>{d.current=!1,c.current?.abort()}),[]);let P=re(async S=>{c.current?.abort();let f=new AbortController;c.current=f;let h=++v.current,g=()=>d.current&&v.current===h;g()&&(u(!0),a(null));try{let E=await r.request(S,{...m.current,signal:f.signal});return g()&&(o(E),u(!1),m.current?.onSuccess?.(E)),E}catch(E){let T=ot(E);throw g()&&(a(T),u(!1),m.current?.onError?.(T)),T}},[r]),b=re(S=>{P(S).catch(()=>{})},[P]),R=re(()=>{v.current++,c.current?.abort(),c.current=null,o(void 0),a(null),u(!1)},[]);return{mutate:b,mutateAsync:P,data:n,error:i,isPending:k,reset:R}}import{useCallback as fe,useEffect as at,useMemo as ut,useRef as z,useState as se}from"react";function ge(t){return t instanceof Error?t:new Error(String(t))}var ct=t=>typeof t=="string"?t:String(t);function pt(t,e){let r=ut(()=>M(t),[t]),[n,o]=se(""),[i,a]=se(!1),[k,u]=se(null),m=z(e);m.current=e;let v=z(0),c=z(null),d=z(!0);at(()=>(d.current=!0,()=>{d.current=!1,c.current?.cancel(),c.current=null}),[]);let P=fe(()=>{v.current++,c.current?.cancel(),c.current=null,d.current&&a(!1)},[]),b=fe(async R=>{c.current?.cancel();let S=++v.current,f=()=>d.current&&v.current===S,h=m.current,g=h?.parseChunk??ct,E=h?.buildPayload??(l=>({prompt:l}));f()&&(o(""),u(null),a(!0));let{parseChunk:T,buildPayload:W,onFinish:_,onError:s,...p}=h??{},y="",C;try{C=r.requestStream(E(R),p),c.current=C}catch(l){let w=ge(l);f()&&(u(w),a(!1),h?.onError?.(w));return}try{for await(let l of C){if(v.current!==S)break;y+=g(l),f()&&o(y)}f()&&(a(!1),h?.onFinish?.(y))}catch(l){let w=ge(l);f()&&(u(w),a(!1),h?.onError?.(w))}finally{c.current===C&&(c.current=null)}},[r]);return{completion:n,complete:b,stop:P,isStreaming:i,error:k}}import{useCallback as he,useEffect as dt,useMemo as lt,useRef as O,useState as X}from"react";function Se(t){return t instanceof Error?t:new Error(String(t))}var mt=t=>typeof t=="string"?t:String(t),ye=0;function oe(t){return ye+=1,`${t}-${ye}`}function ft(t,e){let r=lt(()=>M(t),[t]),[n,o]=X(()=>(e?.initialMessages??[]).map(g=>({id:g.id??oe("msg"),role:g.role,content:g.content}))),[i,a]=X(""),[k,u]=X(!1),[m,v]=X(null),c=O(e);c.current=e;let d=O(n);d.current=n;let P=O(i);P.current=i;let b=O(0),R=O(null),S=O(!0);dt(()=>(S.current=!0,()=>{S.current=!1,R.current?.cancel(),R.current=null}),[]);let f=he(()=>{b.current++,R.current?.cancel(),R.current=null,S.current&&u(!1)},[]),h=he(async g=>{let E=g===void 0,T=(E?P.current:g)??"";if(!T.trim())return;R.current?.cancel();let _=++b.current,s=()=>S.current&&b.current===_,p=c.current,y=p?.parseChunk??mt,C={id:oe("msg"),role:"user",content:T},l={id:oe("msg"),role:"assistant",content:""},w=[...d.current,C].map(x=>({role:x.role,content:x.content})),L=[...d.current,C,l];d.current=L,o(L),E&&a(""),v(null),u(!0);let Ve=p?.buildPayload??(x=>({messages:x})),{initialMessages:Xt,parseChunk:$t,buildPayload:Jt,onFinish:Wt,onError:Kt,...Be}=p??{},De=x=>{o(I=>I.map(Z=>Z.id===l.id?{...Z,content:x}:Z))},K="",D;try{D=r.requestStream(Ve(w),Be),R.current=D}catch(x){let I=Se(x);s()&&(v(I),u(!1),p?.onError?.(I));return}try{for await(let x of D){if(b.current!==_)break;K+=y(x),s()&&De(K)}s()&&(u(!1),p?.onFinish?.({...l,content:K}))}catch(x){let I=Se(x);s()&&(v(I),u(!1),p?.onError?.(I))}finally{R.current===D&&(R.current=null)}},[r]);return{messages:n,input:i,setInput:a,sendMessage:h,stop:f,isStreaming:k,error:m}}var ve=new Map;function gt(t,e,r){if(!r||typeof r.safeParse!="function")throw new Error(`registerComponent("${t}"): schema must be a valid Zod schema`);ve.set(t,{component:e,schema:r})}function Re(t,e){let r=ve.get(t);if(!r)return{error:`Unknown component: "${t}"`};let n=r.schema.safeParse(e);return n.success?{Component:r.component,validatedProps:n.data}:{error:`Validation failed for "${t}": ${n.error.message}`}}import{Fragment as St,jsx as $}from"react/jsx-runtime";function ht({name:t,props:e,fallback:r}){let n=Re(t,e);if(n.error)return console.warn(`[urun] ComponentRenderer: ${n.error}`),r?$(St,{children:r}):$("div",{className:"urun-component-error",role:"alert",children:$("span",{className:"urun-component-error-text",children:n.error})});let o=n.Component;return $(o,{...n.validatedProps})}import{z as B}from"zod";import{jsx as ie,jsxs as Ce}from"react/jsx-runtime";var yt=B.object({step:B.number().min(0),total:B.number().min(1),label:B.string().optional(),variant:B.enum(["default","success","error"]).default("default")});function Pe(t){let{step:e,total:r,label:n,variant:o="default"}=t,i=Math.min(e/r*100,100),a=e>=r;return{step:e,total:r,label:n,variant:o,percentage:i,isComplete:a}}function vt(t){let{step:e,total:r,label:n,variant:o,percentage:i}=Pe(t);return Ce("div",{className:"urun-progress-card","data-variant":o,children:[n&&ie("div",{className:"urun-progress-label",children:n}),ie("div",{className:"urun-progress-bar",children:ie("div",{className:"urun-progress-fill",style:{width:`${i}%`}})}),Ce("div",{className:"urun-progress-text",children:[e,"/",r]})]})}import{z as ae}from"zod";import{jsx as Te,jsxs as Tt}from"react/jsx-runtime";var Rt=ae.object({state:ae.enum(["thinking","generating","idle","error"]),message:ae.string().optional()}),Ct={thinking:"Thinking...",generating:"Generating...",idle:"Idle",error:"Error"};function ke(t){let{state:e,message:r}=t,n=e==="thinking"||e==="generating",o=r??Ct[e]??e;return{state:e,message:o,isActive:n}}function Pt(t){let{state:e,message:r,isActive:n}=ke(t);return Tt("span",{className:"urun-status-badge","data-state":e,children:[Te("span",{className:`urun-status-indicator${n?" urun-status-pulse":""}`}),Te("span",{className:"urun-status-message",children:r})]})}import{useRef as be,useEffect as kt}from"react";import{z as ue}from"zod";import{jsx as Ee,jsxs as xt}from"react/jsx-runtime";var bt=ue.object({text:ue.string(),streaming:ue.boolean().default(!1)});function xe(t){let{text:e,streaming:r=!1}=t,n=e.length===0;return{text:e,streaming:r,isEmpty:n}}function Et(t){let{text:e,streaming:r}=xe(t),n=be(null),o=be(0);return kt(()=>{let i=n.current;i&&e.length!==o.current&&(i.textContent=e,o.current=e.length)},[e]),xt("div",{className:"urun-text-stream",children:[Ee("span",{ref:n,className:"urun-text-content"}),r&&Ee("span",{className:"urun-text-cursor"})]})}import{z as J}from"zod";import{jsx as _e,jsxs as Ut}from"react/jsx-runtime";var _t=J.object({src:J.string().url(),alt:J.string().optional(),caption:J.string().optional()});function we(t){let{src:e,alt:r,caption:n}=t;return{src:e,alt:r??"",caption:n}}function wt(t){let{src:e,alt:r,caption:n}=we(t);return Ut("figure",{className:"urun-image-frame",children:[_e("img",{className:"urun-image",src:e,alt:r}),n&&_e("figcaption",{className:"urun-image-caption",children:n})]})}import{z as N}from"zod";import{jsx as ce,jsxs as At}from"react/jsx-runtime";var Nt=N.object({metrics:N.array(N.object({label:N.string(),value:N.union([N.string(),N.number()]),unit:N.string().optional()}))});function Ue(t){return{metrics:t.metrics.map(r=>({...r,displayValue:r.unit?`${r.value} ${r.unit}`:String(r.value)}))}}function It(t){let{metrics:e}=Ue(t);return ce("div",{className:"urun-metrics-panel",children:e.map((r,n)=>At("div",{className:"urun-metric-card",children:[ce("div",{className:"urun-metric-label",children:r.label}),ce("div",{className:"urun-metric-value",children:r.displayValue})]},n))})}import{forwardRef as de,useCallback as Ae,useEffect as pe,useImperativeHandle as Vt,useRef as qe,useState as Bt}from"react";import Dt from"video.js";import"video.js/dist/video-js.css";import{useContext as Mt,useState as Ot,useEffect as Lt}from"react";import{createContext as qt,useState as zr,useEffect as Xr,useRef as $r}from"react";import{TransportSession as Wr}from"@urun-sh/core/internal";import{jsx as Zr}from"react/jsx-runtime";var Ne=qt(null);function Ie(t){let e=Mt(Ne);if(!e)throw new Error("useTrack must be used within <SessionProvider> or <UrunProvider>");let[r,n]=Ot(null);return Lt(()=>{let o=e.getState()._transport;if(!o)return;let i=o.getTrackByName?.bind(o),a=i?.(t);a&&a.readyState!=="ended"&&n(a);let k=o.on("track",u=>{let m=i?.(t);m&&m.id!==u.id||(n(u),u.addEventListener("ended",()=>{n(null)}))});return()=>{k()}},[t,e]),r}import{jsx as q,jsxs as Oe}from"react/jsx-runtime";function Me(t){t.posterImage?.hide?.()}var jt=["playToggle","volumePanel","fullscreenToggle"],Ht=["playToggle","volumePanel","currentTimeDisplay","timeDivider","durationDisplay","progressControl","remainingTimeDisplay","fullscreenToggle"],Le=de(function(e,r){let{track:n,stream:o,src:i,type:a="video/mp4",className:k,videoClassName:u,poster:m,controls:v=!0,autoPlay:c=!0,muted:d=!0,onVideoElement:P,onPlayerReady:b,children:R}=e,S=typeof i=="string"&&i.length>0,f=!S,h=qe(null),g=qe(null),[E,T]=Bt(!1),W=Ae(s=>{h.current=s,typeof r=="function"?r(s):r&&(r.current=s),P?.(s)},[r,P]);Vt(r,()=>h.current,[]);let _=Ae(()=>{let s=h.current;if(!s||!s.srcObject&&!s.src)return;d&&(s.muted=!0,s.defaultMuted=!0),s.setAttribute("playsinline",""),s.setAttribute("webkit-playsinline","");let p=s.play();p&&typeof p.then=="function"&&p.then(()=>T(!1)).catch(y=>{(y instanceof Error?y.name:String(y))!=="AbortError"&&T(!0)})},[d]);return pe(()=>{if(typeof document>"u")return;let s=h.current;if(!s)return;d&&(s.muted=!0,s.defaultMuted=!0,s.setAttribute("muted","")),s.autoplay=c,s.setAttribute("playsinline",""),s.setAttribute("webkit-playsinline","");let p=Dt(s,{controls:v,autoplay:c,muted:d,playsinline:!0,preload:"auto",fluid:!1,bigPlayButton:!0,poster:m,userActions:{click:!0,doubleClick:!1,hotkeys:!1},controlBar:{children:f?jt:Ht}});f&&p.addClass("urun-video-live");let y=()=>T(!1),C=()=>{p.hasStarted(!0),Me(p),y()},l=()=>{f&&_()};return s.addEventListener("playing",C),s.addEventListener("loadedmetadata",l),f&&s.addEventListener("pause",l),g.current=p,b?.(p),()=>{s.removeEventListener("playing",C),s.removeEventListener("loadedmetadata",l),s.removeEventListener("pause",l),b?.(null),g.current&&(g.current.dispose(),g.current=null)}},[f]),pe(()=>{if(!S)return;let s=g.current;if(!s)return;let p=s.tech?.(!0)?.el?.();p&&(p.srcObject=null),s.src({src:i,type:a}),c&&_()},[S,i,a,c,_]),pe(()=>{if(!f)return;let s=g.current;if(!s)return;let p=n??null,y=o??null;!y&&p&&(y=new MediaStream([p]));let C=s.tech?.(!0)?.el?.()??h.current;if(!C)return;if(!y){C.srcObject=null,T(!1);return}C.srcObject=y,_();let l=y.getVideoTracks()[0]??p??null,w=()=>{s.hasStarted(!0),Me(s),_()},L=()=>{C.srcObject=null,T(!1)};return l&&(l.addEventListener("unmute",w),l.addEventListener("ended",L),l.muted||w()),()=>{l&&(l.removeEventListener("unmute",w),l.removeEventListener("ended",L))}},[f,n,o,_]),Oe("div",{className:k,style:{position:"relative"},"data-urun-video-mode":f?"live":"vod",children:[q("video",{ref:W,className:["video-js","vjs-default-skin",u].filter(Boolean).join(" "),playsInline:!0}),E&&q("button",{type:"button",onClick:_,"aria-label":"Tap to play",style:{position:"absolute",inset:0,zIndex:30,display:"flex",alignItems:"center",justifyContent:"center",background:"rgba(0,0,0,0.6)",border:0,cursor:"pointer",color:"#fff"},children:Oe("span",{style:{display:"inline-flex",alignItems:"center",gap:8,borderRadius:999,border:"1px solid rgba(255,255,255,0.2)",background:"rgba(255,255,255,0.1)",padding:"10px 20px",fontSize:14,fontWeight:500},children:[q("svg",{viewBox:"0 0 24 24",fill:"currentColor",width:16,height:16,"aria-hidden":!0,children:q("path",{d:"M8 5v14l11-7z"})}),"Tap to play"]})}),R]})}),Ft=de(function({name:e,...r},n){let o=Ie(e);return q(Le,{ref:n,...r,track:o})}),zt=de(function(e,r){return!!e.name&&!e.track&&!e.stream&&!(typeof e.src=="string"&&e.src)?q(Ft,{ref:r,...e,name:e.name}):q(Le,{ref:r,...e})});export{ht as ComponentRenderer,wt as ImageFrame,_t as ImageFrameSchema,It as MetricsPanel,Nt as MetricsPanelSchema,vt as ProgressCard,yt as ProgressCardSchema,Pt as StatusBadge,Rt as StatusBadgeSchema,Et as TextStream,bt as TextStreamSchema,je as UrunAuthProvider,V as UrunErrorBoundary,He as UrunJwtProvider,Ze as UrunProvider,zt as UrunVideo,H as authMode,gt as registerComponent,U as urunPublicEnv,rt as useApp,ft as useChat,pt as useCompletion,we as useImageFrame,Ue as useMetricsPanel,Pe as useProgressCard,it as useRequest,ke as useStatusBadge,xe as useTextStream,G as useUrunAuth,$e as usesWorkOSAuth};
|
|
1
|
+
import{a as ze,b as He,c as G}from"./chunk-QAEWAWV4.mjs";import{useEffect as We,useMemo as Ke,useState as Ze}from"react";import{Component as Fe}from"react";import{jsx as pe,jsxs as Xe}from"react/jsx-runtime";var L=class extends Fe{constructor(e){super(e),this.state={error:null}}static getDerivedStateFromError(e){return{error:e}}componentDidCatch(e,t){console.error("[urun] Error caught by UrunErrorBoundary:",e,t)}render(){if(this.state.error){let{fallback:e}=this.props;return typeof e=="function"?e(this.state.error):e||Xe("div",{role:"status","aria-live":"polite",style:{padding:"16px",border:"1px solid rgba(17, 24, 39, 0.12)",borderRadius:"8px",background:"#ffffff",color:"#111827",fontFamily:'system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif',maxWidth:"360px"},children:[pe("p",{style:{margin:0,fontWeight:600},children:"Connection interrupted"}),pe("p",{style:{margin:"6px 0 0",color:"#4b5563"},children:"Reconnecting automatically."})]})}return this.props.children}};import{createContext as $e}from"react";var D=$e(null);function A(r){return r&&r.trim()?r.trim():void 0}function U(r){switch(r){case"NEXT_PUBLIC_AUTH_MODE":return A(typeof process<"u"?process.env?.NEXT_PUBLIC_AUTH_MODE:void 0);case"NEXT_PUBLIC_AUTH_ENABLED":return A(typeof process<"u"?process.env?.NEXT_PUBLIC_AUTH_ENABLED:void 0);case"NEXT_PUBLIC_SESSION_AUTH_PROVIDER":return A(typeof process<"u"?process.env?.NEXT_PUBLIC_SESSION_AUTH_PROVIDER:void 0);case"NEXT_PUBLIC_SESSION_TOKEN":return A(typeof process<"u"?process.env?.NEXT_PUBLIC_SESSION_TOKEN:void 0);case"NEXT_PUBLIC_URUN_JWT":return A(typeof process<"u"?process.env?.NEXT_PUBLIC_URUN_JWT:void 0);case"VERCEL_ENV":return A(typeof process<"u"?process.env?.VERCEL_ENV:void 0);default:return A(typeof process<"u"?process.env?.[r]:void 0)}}function z(){let r=U("NEXT_PUBLIC_AUTH_MODE")?.toLowerCase();return r==="jwt"||r==="customer-jwt"||r==="test-jwt"?"jwt":r==="workos"||U("VERCEL_ENV")==="production"?"workos":U("NEXT_PUBLIC_AUTH_ENABLED")==="false"?"jwt":"workos"}function Je(){return z()==="workos"}import{jsx as Y}from"react/jsx-runtime";function Ge({baseUrl:r,orgId:e,appId:t,jwt:n,authProvider:o,fallback:i,children:a}){let[x,u]=Ze(),m=G(),b=U("NEXT_PUBLIC_SESSION_TOKEN")??U("NEXT_PUBLIC_URUN_JWT"),c=z(),l=c==="workos"&&!n,R=n??(c==="jwt"?b:void 0)??x,T=o??U("NEXT_PUBLIC_SESSION_AUTH_PROVIDER"),S=l&&!R,v=Ke(()=>({appId:t,baseUrl:r,orgId:e,jwt:R,getAccessToken:l?m?.getAccessToken:void 0,authProvider:T}),[t,m,r,T,R,e,l]);return We(()=>{if(!l||!m)return;let f=!1,h=m;async function g(){try{let C=await h.getAccessToken();f||u(C??void 0)}catch{f||u(void 0)}}g();let P=window.setInterval(()=>{g()},6e4);return()=>{f=!0,window.clearInterval(P)}},[m,l]),Y(L,{fallback:i,children:S?Y("div",{role:"status","aria-live":"polite",children:"Signing in..."}):Y(D.Provider,{value:v,children:a})})}import{useContext as Ye,useMemo as me,useReducer as Qe,useRef as er}from"react";import{App as rr}from"@urun-sh/core";function tr(r,e){return`${r}:${JSON.stringify(e??{})}`}var Q=class{constructor(e,t){this._doc=e;this._notify=t;this._unsubscribeChange=this._doc.on("change",()=>this._notify())}_doc;_notify;_unsubscribeChange;get(e,t){return this._doc.get(e,t)}set(e){this._doc.set(e),this._notify()}on(e,t){return this._doc.on(e,n=>t(n))}get synced(){return this._doc.synced}onSynced(e){return this._doc.onSynced(()=>{e(),this._notify()})}text(e){let t=this._doc.text(e),n=this._notify;return{append(o){t.append(o),n()},toString:()=>t.toString(),get length(){return t.length},on:(o,i)=>t.on(o,a=>{i(a),n()})}}dispose(){this._unsubscribeChange()}},ee=class{constructor(e,t){this._stream=e;this._notify=t;this._unsubscribeTrack=this._stream.on("track",()=>this._notify())}_stream;_notify;_unsubscribeTrack;get track(){return this._stream.track}attach(e){return this._stream.attach(e)}attachVideo(e){return this._stream.attachVideo(e)}detach(){return this._stream.detach()}detachVideo(){return this._stream.detachVideo()}seek(e){return this._stream.seek(e)}on(e,t){return this._stream.on(e,t)}messages(){return this._stream.messages()}emit(e,t){return this._stream.emit(e,t)}dispose(){this._unsubscribeTrack()}},re=class{constructor(e,t){this._session=e;this._notify=t;this._unsubscribePhase=this._session.onPhase(()=>this._notify())}_session;_notify;_docs=new Map;_streams=new Map;_unsubscribePhase;get id(){return this._session.id}get phase(){return this._session.phase}onPhase(e){return this._session.onPhase(e)}request(e,t){return this._session.request(e,t)}requestStream(e,t){return this._session.requestStream(e,t)}complete(e,t){return this._session.complete(e,t)}doc(e){let t=this._docs.get(e);return t||(t=new Q(this._session.doc(e),this._notify),this._docs.set(e,t)),t}stream(e){let t=this._streams.get(e);return t||(t=new ee(this._session.stream(e),this._notify),this._streams.set(e,t)),t}disconnect(){for(let e of this._docs.values())e.dispose();for(let e of this._streams.values())e.dispose();this._docs.clear(),this._streams.clear(),this._unsubscribePhase(),this._session.disconnect(),this._notify()}};function nr(){let r=Ye(D);if(!r)throw new Error("useApp must be used within <UrunProvider>");if(!r.appId)throw new Error('useApp requires <UrunProvider appId="...">');let[,e]=Qe(o=>o+1,0),t=er(new Map),n=me(()=>rr(r.appId,{baseUrl:r.baseUrl,orgId:r.orgId,jwt:r.jwt,getAccessToken:r.getAccessToken,authProvider:r.authProvider}),[r.appId,r.baseUrl,r.orgId,r.jwt,r.getAccessToken,r.authProvider]);return me(()=>new Proxy({},{get(o,i){if(typeof i=="string")return a=>{let x=tr(i,a),u=t.current.get(x);if(u)return u;let m=new re(n[i](a),e);return t.current.set(x,m),m}}}),[n])}import{useCallback as te,useEffect as sr,useMemo as or,useRef as H,useState as ne}from"react";function M(r){let e=r;if(!e||typeof e.request!="function"||typeof e.requestStream!="function")throw new Error("This session does not support request/requestStream. Upgrade @urun-sh/core to a version that ships the request/response primitive.");return e}function ir(r){return r instanceof Error?r:new Error(String(r))}function ar(r,e){let t=or(()=>M(r),[r]),[n,o]=ne(void 0),[i,a]=ne(null),[x,u]=ne(!1),m=H(e);m.current=e;let b=H(0),c=H(null),l=H(!0);sr(()=>(l.current=!0,()=>{l.current=!1,c.current?.abort()}),[]);let R=te(async v=>{c.current?.abort();let f=new AbortController;c.current=f;let h=++b.current,g=()=>l.current&&b.current===h;g()&&(u(!0),a(null));try{let P=await t.request(v,{...m.current,signal:f.signal});return g()&&(o(P),u(!1),m.current?.onSuccess?.(P)),P}catch(P){let C=ir(P);throw g()&&(a(C),u(!1),m.current?.onError?.(C)),C}},[t]),T=te(v=>{R(v).catch(()=>{})},[R]),S=te(()=>{b.current++,c.current?.abort(),c.current=null,o(void 0),a(null),u(!1)},[]);return{mutate:T,mutateAsync:R,data:n,error:i,isPending:x,reset:S}}import{useCallback as fe,useEffect as ur,useMemo as cr,useRef as F,useState as se}from"react";function ge(r){return r instanceof Error?r:new Error(String(r))}var dr=r=>typeof r=="string"?r:String(r);function lr(r,e){let t=cr(()=>M(r),[r]),[n,o]=se(""),[i,a]=se(!1),[x,u]=se(null),m=F(e);m.current=e;let b=F(0),c=F(null),l=F(!0);ur(()=>(l.current=!0,()=>{l.current=!1,c.current?.cancel(),c.current=null}),[]);let R=fe(()=>{b.current++,c.current?.cancel(),c.current=null,l.current&&a(!1)},[]),T=fe(async S=>{c.current?.cancel();let v=++b.current,f=()=>l.current&&b.current===v,h=m.current,g=h?.parseChunk??dr,P=h?.buildPayload??(p=>({prompt:p}));f()&&(o(""),u(null),a(!0));let{parseChunk:C,buildPayload:W,onFinish:w,onError:s,...d}=h??{},y="",k;try{k=t.requestStream(P(S),d),c.current=k}catch(p){let _=ge(p);f()&&(u(_),a(!1),h?.onError?.(_));return}try{for await(let p of k){if(b.current!==v)break;y+=g(p),f()&&o(y)}f()&&(a(!1),h?.onFinish?.(y))}catch(p){let _=ge(p);f()&&(u(_),a(!1),h?.onError?.(_))}finally{c.current===k&&(c.current=null)}},[t]);return{completion:n,complete:T,stop:R,isStreaming:i,error:x}}import{useCallback as he,useEffect as pr,useMemo as mr,useRef as O,useState as X}from"react";function ve(r){return r instanceof Error?r:new Error(String(r))}var fr=r=>typeof r=="string"?r:String(r),ye=0;function oe(r){return ye+=1,`${r}-${ye}`}function gr(r,e){let t=mr(()=>M(r),[r]),[n,o]=X(()=>(e?.initialMessages??[]).map(g=>({id:g.id??oe("msg"),role:g.role,content:g.content}))),[i,a]=X(""),[x,u]=X(!1),[m,b]=X(null),c=O(e);c.current=e;let l=O(n);l.current=n;let R=O(i);R.current=i;let T=O(0),S=O(null),v=O(!0);pr(()=>(v.current=!0,()=>{v.current=!1,S.current?.cancel(),S.current=null}),[]);let f=he(()=>{T.current++,S.current?.cancel(),S.current=null,v.current&&u(!1)},[]),h=he(async g=>{let P=g===void 0,C=(P?R.current:g)??"";if(!C.trim())return;S.current?.cancel();let w=++T.current,s=()=>v.current&&T.current===w,d=c.current,y=d?.parseChunk??fr,k={id:oe("msg"),role:"user",content:C},p={id:oe("msg"),role:"assistant",content:""},_=[...l.current,k].map(E=>({role:E.role,content:E.content})),j=[...l.current,k,p];l.current=j,o(j),P&&a(""),b(null),u(!0);let Ve=d?.buildPayload??(E=>({messages:E})),{initialMessages:Wr,parseChunk:Kr,buildPayload:Zr,onFinish:Gr,onError:Yr,...Be}=d??{},De=E=>{o(N=>N.map(Z=>Z.id===p.id?{...Z,content:E}:Z))},K="",B;try{B=t.requestStream(Ve(_),Be),S.current=B}catch(E){let N=ve(E);s()&&(b(N),u(!1),d?.onError?.(N));return}try{for await(let E of B){if(T.current!==w)break;K+=y(E),s()&&De(K)}s()&&(u(!1),d?.onFinish?.({...p,content:K}))}catch(E){let N=ve(E);s()&&(b(N),u(!1),d?.onError?.(N))}finally{S.current===B&&(S.current=null)}},[t]);return{messages:n,input:i,setInput:a,sendMessage:h,stop:f,isStreaming:x,error:m}}var be=new Map;function hr(r,e,t){if(!t||typeof t.safeParse!="function")throw new Error(`registerComponent("${r}"): schema must be a valid Zod schema`);be.set(r,{component:e,schema:t})}function Se(r,e){let t=be.get(r);if(!t)return{error:`Unknown component: "${r}"`};let n=t.schema.safeParse(e);return n.success?{Component:t.component,validatedProps:n.data}:{error:`Validation failed for "${r}": ${n.error.message}`}}import{Fragment as yr,jsx as $}from"react/jsx-runtime";function vr({name:r,props:e,fallback:t}){let n=Se(r,e);if(n.error)return console.warn(`[urun] ComponentRenderer: ${n.error}`),t?$(yr,{children:t}):$("div",{className:"urun-component-error",role:"alert",children:$("span",{className:"urun-component-error-text",children:n.error})});let o=n.Component;return $(o,{...n.validatedProps})}import{z as V}from"zod";import{jsx as ie,jsxs as ke}from"react/jsx-runtime";var br=V.object({step:V.number().min(0),total:V.number().min(1),label:V.string().optional(),variant:V.enum(["default","success","error"]).default("default")});function Re(r){let{step:e,total:t,label:n,variant:o="default"}=r,i=Math.min(e/t*100,100),a=e>=t;return{step:e,total:t,label:n,variant:o,percentage:i,isComplete:a}}function Sr(r){let{step:e,total:t,label:n,variant:o,percentage:i}=Re(r);return ke("div",{className:"urun-progress-card","data-variant":o,children:[n&&ie("div",{className:"urun-progress-label",children:n}),ie("div",{className:"urun-progress-bar",children:ie("div",{className:"urun-progress-fill",style:{width:`${i}%`}})}),ke("div",{className:"urun-progress-text",children:[e,"/",t]})]})}import{z as ae}from"zod";import{jsx as Ce,jsxs as xr}from"react/jsx-runtime";var kr=ae.object({state:ae.enum(["thinking","generating","idle","error"]),message:ae.string().optional()}),Rr={thinking:"Thinking...",generating:"Generating...",idle:"Idle",error:"Error"};function xe(r){let{state:e,message:t}=r,n=e==="thinking"||e==="generating",o=t??Rr[e]??e;return{state:e,message:o,isActive:n}}function Cr(r){let{state:e,message:t,isActive:n}=xe(r);return xr("span",{className:"urun-status-badge","data-state":e,children:[Ce("span",{className:`urun-status-indicator${n?" urun-status-pulse":""}`}),Ce("span",{className:"urun-status-message",children:t})]})}import{useRef as Te,useEffect as Tr}from"react";import{z as ue}from"zod";import{jsx as Pe,jsxs as wr}from"react/jsx-runtime";var Pr=ue.object({text:ue.string(),streaming:ue.boolean().default(!1)});function Ee(r){let{text:e,streaming:t=!1}=r,n=e.length===0;return{text:e,streaming:t,isEmpty:n}}function Er(r){let{text:e,streaming:t}=Ee(r),n=Te(null),o=Te(0);return Tr(()=>{let i=n.current;i&&e.length!==o.current&&(i.textContent=e,o.current=e.length)},[e]),wr("div",{className:"urun-text-stream",children:[Pe("span",{ref:n,className:"urun-text-content"}),t&&Pe("span",{className:"urun-text-cursor"})]})}import{z as J}from"zod";import{jsx as we,jsxs as Ir}from"react/jsx-runtime";var _r=J.object({src:J.string().url(),alt:J.string().optional(),caption:J.string().optional()});function _e(r){let{src:e,alt:t,caption:n}=r;return{src:e,alt:t??"",caption:n}}function Ur(r){let{src:e,alt:t,caption:n}=_e(r);return Ir("figure",{className:"urun-image-frame",children:[we("img",{className:"urun-image",src:e,alt:t}),n&&we("figcaption",{className:"urun-image-caption",children:n})]})}import{z as I}from"zod";import{jsx as ce,jsxs as qr}from"react/jsx-runtime";var Nr=I.object({metrics:I.array(I.object({label:I.string(),value:I.union([I.string(),I.number()]),unit:I.string().optional()}))});function Ue(r){return{metrics:r.metrics.map(t=>({...t,displayValue:t.unit?`${t.value} ${t.unit}`:String(t.value)}))}}function Ar(r){let{metrics:e}=Ue(r);return ce("div",{className:"urun-metrics-panel",children:e.map((t,n)=>qr("div",{className:"urun-metric-card",children:[ce("div",{className:"urun-metric-label",children:t.label}),ce("div",{className:"urun-metric-value",children:t.displayValue})]},n))})}import{forwardRef as le,useCallback as Ae,useEffect as de,useImperativeHandle as Vr,useRef as qe,useState as Br}from"react";import Dr from"video.js";import"video.js/dist/video-js.css";import{useContext as Or,useState as jr,useEffect as Lr}from"react";import{createContext as Mr,useState as Kt,useEffect as Zt,useRef as Gt}from"react";import{TransportSession as Qt}from"@urun-sh/core/internal";import{jsx as rn}from"react/jsx-runtime";var Ie=Mr(null);function Ne(r){let e=Or(Ie);if(!e)throw new Error("useTrack must be used within <SessionProvider> or <UrunProvider>");let[t,n]=jr(null);return Lr(()=>{let o=e.getState()._transport;if(!o)return;let i=o.getTrackByName?.bind(o),a=i?.(r);a&&a.readyState!=="ended"&&n(a);let x=o.on("track",u=>{let m=i?.(r);m&&m.id!==u.id||(n(u),u.addEventListener("ended",()=>{n(null)}))});return()=>{x()}},[r,e]),t}import{jsx as q,jsxs as je}from"react/jsx-runtime";function Me(r){r.posterImage?.hide?.()}var zr=`
|
|
2
|
+
[data-urun-video]{width:100%;height:100%}
|
|
3
|
+
[data-urun-video] .video-js,[data-urun-video] .vjs-tech{width:100%;height:100%}
|
|
4
|
+
[data-urun-video] .vjs-tech{object-fit:contain}
|
|
5
|
+
.urun-video-live.vjs-has-started .vjs-poster,
|
|
6
|
+
.urun-video-live.vjs-has-started .vjs-loading-spinner,
|
|
7
|
+
.urun-video-live.vjs-has-started .vjs-big-play-button{display:none !important}
|
|
8
|
+
.urun-video-live .vjs-poster{background-color:transparent}
|
|
9
|
+
`,Oe="urun-video-critical-css";function Hr(){if(typeof document>"u"||document.getElementById(Oe))return;let r=document.createElement("style");r.id=Oe,r.textContent=zr,document.head.appendChild(r)}var Fr=["playToggle","volumePanel","fullscreenToggle"],Xr=["playToggle","volumePanel","currentTimeDisplay","timeDivider","durationDisplay","progressControl","remainingTimeDisplay","fullscreenToggle"],Le=le(function(e,t){let{track:n,stream:o,src:i,type:a="video/mp4",className:x,videoClassName:u,poster:m,controls:b=!0,autoPlay:c=!0,muted:l=!0,onVideoElement:R,onPlayerReady:T,children:S}=e,v=typeof i=="string"&&i.length>0,f=!v,h=qe(null),g=qe(null),[P,C]=Br(!1),W=Ae(s=>{h.current=s,typeof t=="function"?t(s):t&&(t.current=s),R?.(s)},[t,R]);Vr(t,()=>h.current,[]);let w=Ae(()=>{let s=h.current;if(!s||!s.srcObject&&!s.src)return;l&&(s.muted=!0,s.defaultMuted=!0),s.setAttribute("playsinline",""),s.setAttribute("webkit-playsinline","");let d=s.play();d&&typeof d.then=="function"&&d.then(()=>C(!1)).catch(y=>{(y instanceof Error?y.name:String(y))!=="AbortError"&&C(!0)})},[l]);return de(()=>{if(typeof document>"u")return;let s=h.current;if(!s)return;Hr(),l&&(s.muted=!0,s.defaultMuted=!0,s.setAttribute("muted","")),s.autoplay=c,s.setAttribute("playsinline",""),s.setAttribute("webkit-playsinline","");let d=Dr(s,{controls:b,autoplay:c,muted:l,playsinline:!0,preload:"auto",fluid:!1,bigPlayButton:!0,poster:m,userActions:{click:!0,doubleClick:!1,hotkeys:!1},controlBar:{children:f?Fr:Xr}});f&&d.addClass("urun-video-live");let y=()=>C(!1),k=()=>{d.hasStarted(!0),Me(d),y()},p=()=>{f&&w()};return s.addEventListener("playing",k),s.addEventListener("loadedmetadata",p),f&&s.addEventListener("pause",p),g.current=d,T?.(d),()=>{s.removeEventListener("playing",k),s.removeEventListener("loadedmetadata",p),s.removeEventListener("pause",p),T?.(null),g.current&&(g.current.dispose(),g.current=null)}},[f]),de(()=>{if(!v)return;let s=g.current;if(!s)return;let d=s.tech?.(!0)?.el?.();d&&(d.srcObject=null),s.src({src:i,type:a}),c&&w()},[v,i,a,c,w]),de(()=>{if(!f)return;let s=g.current;if(!s)return;let d=n??null,y=o??null;!y&&d&&(y=new MediaStream([d]));let k=s.tech?.(!0)?.el?.()??h.current;if(!k)return;if(!y){k.srcObject=null,C(!1);return}k.srcObject=y,w();let p=y.getVideoTracks()[0]??d??null,_=()=>{s.hasStarted(!0),Me(s),w()},j=()=>{k.srcObject=null,C(!1)};return p&&(p.addEventListener("unmute",_),p.addEventListener("ended",j),p.muted||_()),()=>{p&&(p.removeEventListener("unmute",_),p.removeEventListener("ended",j))}},[f,n,o,w]),je("div",{className:x,style:{position:"relative",width:"100%",height:"100%"},"data-urun-video":"","data-urun-video-mode":f?"live":"vod",children:[q("video",{ref:W,className:["video-js","vjs-default-skin",u].filter(Boolean).join(" "),playsInline:!0}),P&&q("button",{type:"button",onClick:w,"aria-label":"Tap to play",style:{position:"absolute",inset:0,zIndex:30,display:"flex",alignItems:"center",justifyContent:"center",background:"rgba(0,0,0,0.6)",border:0,cursor:"pointer",color:"#fff"},children:je("span",{style:{display:"inline-flex",alignItems:"center",gap:8,borderRadius:999,border:"1px solid rgba(255,255,255,0.2)",background:"rgba(255,255,255,0.1)",padding:"10px 20px",fontSize:14,fontWeight:500},children:[q("svg",{viewBox:"0 0 24 24",fill:"currentColor",width:16,height:16,"aria-hidden":!0,children:q("path",{d:"M8 5v14l11-7z"})}),"Tap to play"]})}),S]})}),$r=le(function({name:e,...t},n){let o=Ne(e);return q(Le,{ref:n,...t,track:o})}),Jr=le(function(e,t){return!!e.name&&!e.track&&!e.stream&&!(typeof e.src=="string"&&e.src)?q($r,{ref:t,...e,name:e.name}):q(Le,{ref:t,...e})});export{vr as ComponentRenderer,Ur as ImageFrame,_r as ImageFrameSchema,Ar as MetricsPanel,Nr as MetricsPanelSchema,Sr as ProgressCard,br as ProgressCardSchema,Cr as StatusBadge,kr as StatusBadgeSchema,Er as TextStream,Pr as TextStreamSchema,ze as UrunAuthProvider,L as UrunErrorBoundary,He as UrunJwtProvider,Ge as UrunProvider,Jr as UrunVideo,z as authMode,hr as registerComponent,U as urunPublicEnv,nr as useApp,gr as useChat,lr as useCompletion,_e as useImageFrame,Ue as useMetricsPanel,Re as useProgressCard,ar as useRequest,xe as useStatusBadge,Ee as useTextStream,G as useUrunAuth,Je as usesWorkOSAuth};
|
package/dist/styles.css
CHANGED
|
@@ -209,6 +209,34 @@
|
|
|
209
209
|
}
|
|
210
210
|
}
|
|
211
211
|
|
|
212
|
+
/* UrunVideo — default sizing.
|
|
213
|
+
*
|
|
214
|
+
* video.js wraps the <video> in a `.video-js` div which becomes the rendered
|
|
215
|
+
* box; the component's own props/classes land on the inner <video>, NOT that
|
|
216
|
+
* wrapper. Without explicit sizing the `.video-js` wrapper collapses to a
|
|
217
|
+
* default/zero size inside a flex/relative container, so nothing is visible
|
|
218
|
+
* even though the decoder is fine (this was the prod "black video" bug).
|
|
219
|
+
*
|
|
220
|
+
* Make the whole stack fill its parent so a consumer only has to size the OUTER
|
|
221
|
+
* container (as helios does with an aspect-ratio box) — no per-consumer
|
|
222
|
+
* `videoClassName` required. `data-urun-video` is the component's own wrapper. */
|
|
223
|
+
[data-urun-video] {
|
|
224
|
+
width: 100%;
|
|
225
|
+
height: 100%;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
[data-urun-video] .video-js,
|
|
229
|
+
[data-urun-video] .vjs-tech {
|
|
230
|
+
width: 100%;
|
|
231
|
+
height: 100%;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/* Letterbox rather than crop/stretch by default; consumers can override the
|
|
235
|
+
* <video> via `videoClassName` (e.g. object-fit: cover). */
|
|
236
|
+
[data-urun-video] .vjs-tech {
|
|
237
|
+
object-fit: contain;
|
|
238
|
+
}
|
|
239
|
+
|
|
212
240
|
/* UrunVideo — live mode: keep the video.js poster / loading spinner / big-play
|
|
213
241
|
* layer from staying composited OVER the <video>. On iOS Safari/Chrome that
|
|
214
242
|
* layer stays opaque (black) when srcObject is attached and video.js never
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@urun-sh/react",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.46",
|
|
4
4
|
"description": "React bindings for the urun TypeScript SDK",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -42,37 +42,43 @@
|
|
|
42
42
|
"build": "tsup && node -e \"require('fs').copyFileSync('src/components/styles.css','dist/styles.css')\" && node ../../scripts/sanitize-dist.mjs .",
|
|
43
43
|
"prepack": "pnpm build",
|
|
44
44
|
"test": "vitest run",
|
|
45
|
+
"test:e2e": "playwright test",
|
|
46
|
+
"test:e2e:install": "playwright install --with-deps chromium webkit",
|
|
45
47
|
"typecheck": "tsc --noEmit",
|
|
46
48
|
"dev": "tsup --watch"
|
|
47
49
|
},
|
|
48
50
|
"peerDependencies": {
|
|
49
|
-
"
|
|
50
|
-
"@urun-sh/core": "^0.1.43",
|
|
51
|
-
"@workos-inc/authkit-react": "^0.15.0 || ^0.16.0",
|
|
51
|
+
"@urun-sh/core": "^0.1.46",
|
|
52
52
|
"@workos-inc/authkit-nextjs": "^3.0.0",
|
|
53
|
+
"@workos-inc/authkit-react": "^0.15.0 || ^0.16.0",
|
|
53
54
|
"next": "^15.0.0 || ^16.0.0",
|
|
55
|
+
"react": "^18.2.0 || ^19.0.0",
|
|
54
56
|
"video.js": "^8.0.0"
|
|
55
57
|
},
|
|
56
58
|
"dependencies": {
|
|
57
|
-
"zustand": "^5.0.0",
|
|
58
59
|
"yjs": "^13.6.0",
|
|
59
|
-
"zod": "^3.24.0"
|
|
60
|
+
"zod": "^3.24.0",
|
|
61
|
+
"zustand": "^5.0.0"
|
|
60
62
|
},
|
|
61
63
|
"devDependencies": {
|
|
62
|
-
"
|
|
63
|
-
"vitest": "^3.0.0",
|
|
64
|
-
"happy-dom": "^20.9.0",
|
|
65
|
-
"typescript": "^5.3.0",
|
|
66
|
-
"@testing-library/react": "^16.0.0",
|
|
64
|
+
"@playwright/test": "^1.61.1",
|
|
67
65
|
"@testing-library/dom": "^10.0.0",
|
|
66
|
+
"@testing-library/react": "^16.0.0",
|
|
67
|
+
"@types/pngjs": "^6.0.5",
|
|
68
68
|
"@types/react": "^19.2.15",
|
|
69
|
-
"react": "^19.2.6",
|
|
70
|
-
"react-dom": "^19.2.6",
|
|
71
69
|
"@urun-sh/core": "workspace:*",
|
|
72
|
-
"@workos-inc/authkit-react": "^0.16.1",
|
|
73
70
|
"@workos-inc/authkit-nextjs": "^3.0.0",
|
|
71
|
+
"@workos-inc/authkit-react": "^0.16.1",
|
|
72
|
+
"esbuild": "0.28.1",
|
|
73
|
+
"happy-dom": "^20.9.0",
|
|
74
74
|
"next": "16.2.6",
|
|
75
|
-
"
|
|
75
|
+
"pngjs": "^7.0.0",
|
|
76
|
+
"react": "^19.2.6",
|
|
77
|
+
"react-dom": "^19.2.6",
|
|
78
|
+
"tsup": "^8.5.0",
|
|
79
|
+
"typescript": "^5.3.0",
|
|
80
|
+
"video.js": "^8.23.7",
|
|
81
|
+
"vitest": "^3.0.0"
|
|
76
82
|
},
|
|
77
83
|
"files": [
|
|
78
84
|
"dist",
|