@urun-sh/react 0.1.7 → 0.1.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var ie=Object.create;var
|
|
1
|
+
"use strict";var ie=Object.create;var C=Object.defineProperty;var ce=Object.getOwnPropertyDescriptor;var ue=Object.getOwnPropertyNames;var pe=Object.getPrototypeOf,de=Object.prototype.hasOwnProperty;var me=(t,e)=>{for(var r in e)C(t,r,{get:e[r],enumerable:!0})},W=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of ue(e))!de.call(t,o)&&o!==r&&C(t,o,{get:()=>e[o],enumerable:!(n=ce(e,o))||n.enumerable});return t};var le=(t,e,r)=>(r=t!=null?ie(pe(t)):{},W(e||!t||!t.__esModule?C(r,"default",{value:t,enumerable:!0}):r,t)),ge=t=>W(C({},"__esModule",{value:!0}),t);var Se={};me(Se,{ComponentRenderer:()=>H,ImageFrame:()=>ne,ImageFrameSchema:()=>te,MetricsPanel:()=>se,MetricsPanelSchema:()=>oe,ProgressCard:()=>Q,ProgressCardSchema:()=>K,StatusBadge:()=>Y,StatusBadgeSchema:()=>X,TextStream:()=>re,TextStreamSchema:()=>ee,UrunErrorBoundary:()=>d,UrunProvider:()=>V,registerComponent:()=>q,useApp:()=>J,useImageFrame:()=>O,useMetricsPanel:()=>D,useProgressCard:()=>N,useStatusBadge:()=>U,useTextStream:()=>B});module.exports=ge(Se);var T=require("react");var F=require("react"),f=require("react/jsx-runtime"),d=class extends F.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,f.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,f.jsx)("p",{style:{margin:0,fontWeight:600},children:"Connection interrupted"}),(0,f.jsx)("p",{style:{margin:"6px 0 0",color:"#4b5563"},children:"Reconnecting automatically."})]})}return this.props.children}};var z=require("react"),w=(0,z.createContext)(null);var h=require("react"),L=require("react/jsx-runtime");function fe({module:t,onToken:e}){let r=t.useAuth();return(0,h.useEffect)(()=>{let n=!1;async function o(){if(!(r.loading||r.isLoading))try{let c=r.getAccessToken?await r.getAccessToken():r.accessToken;n||e(c??void 0)}catch{n||e(void 0)}}o();let s=window.setInterval(()=>{o()},6e4);return()=>{n=!0,window.clearInterval(s)}},[r,r.accessToken,r.getAccessToken,r.isAuthenticated,r.isLoading,r.loading,r.user,e]),null}function $({onToken:t}){let[e,r]=(0,h.useState)(null);return(0,h.useEffect)(()=>{let n=!1;return import("@workos-inc/authkit-react").then(o=>{!n&&typeof o.useAuth=="function"&&r({useAuth:o.useAuth})}).catch(()=>{n||r(null)}),()=>{n=!0}},[]),e?(0,L.jsx)(fe,{module:e,onToken:t}):null}var v=require("react/jsx-runtime");function V({baseUrl:t,orgId:e,appId:r,jwt:n,authProvider:o,fallback:s,children:c}){let[b,R]=(0,T.useState)(),g=n??b,ae=(0,T.useMemo)(()=>({appId:r,baseUrl:t,orgId:e,jwt:g,authProvider:o}),[r,o,t,g,e]);return(0,v.jsxs)(d,{fallback:s,children:[o==="workos"&&!n?(0,v.jsx)($,{onToken:R}):null,(0,v.jsx)(w.Provider,{value:ae,children:c})]})}var a=require("react"),j=require("@urun-sh/core");function he(t,e){return`${t}:${JSON.stringify(e??{})}`}var M=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))}dispose(){this._unsubscribeChange()}},E=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)}detach(){return this._stream.detach()}seek(e){return this._stream.seek(e)}on(e,r){return this._stream.on(e,r)}dispose(){this._unsubscribeTrack()}},I=class{constructor(e,r){this._session=e;this._notify=r}_session;_notify;_docs=new Map;_streams=new Map;get id(){return this._session.id}doc(e){let r=this._docs.get(e);return r||(r=new M(this._session.doc(e),this._notify),this._docs.set(e,r)),r}stream(e){let r=this._streams.get(e);return r||(r=new E(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._session.disconnect(),this._notify()}};function J(){let t=(0,a.useContext)(w);if(!t)throw new Error("useApp must be used within <UrunProvider>");if(!t.appId)throw new Error('useApp requires <UrunProvider appId="...">');let[,e]=(0,a.useReducer)(o=>o+1,0),r=(0,a.useRef)(new Map),n=(0,a.useMemo)(()=>(0,j.App)(t.appId,{baseUrl:t.baseUrl,orgId:t.orgId,jwt:t.jwt,authProvider:t.authProvider}),[t.appId,t.baseUrl,t.orgId,t.jwt,t.authProvider]);return(0,a.useMemo)(()=>new Proxy({},{get(o,s){if(typeof s=="string")return c=>{let b=he(s,c),R=r.current.get(b);if(R)return R;let g=new I(n[s](c),e);return r.current.set(b,g),g}}}),[n])}var Z=new Map;function q(t,e,r){if(!r||typeof r.safeParse!="function")throw new Error(`registerComponent("${t}"): schema must be a valid Zod schema`);Z.set(t,{component:e,schema:r})}function G(t,e){let r=Z.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 u=require("react/jsx-runtime");function H({name:t,props:e,fallback:r}){let n=G(t,e);if(n.error)return console.warn(`[urun] ComponentRenderer: ${n.error}`),r?(0,u.jsx)(u.Fragment,{children:r}):(0,u.jsx)("div",{className:"urun-component-error",role:"alert",children:(0,u.jsx)("span",{className:"urun-component-error-text",children:n.error})});let o=n.Component;return(0,u.jsx)(o,{...n.validatedProps})}var m=require("zod"),p=require("react/jsx-runtime"),K=m.z.object({step:m.z.number().min(0),total:m.z.number().min(1),label:m.z.string().optional(),variant:m.z.enum(["default","success","error"]).default("default")});function N(t){let{step:e,total:r,label:n,variant:o="default"}=t,s=Math.min(e/r*100,100),c=e>=r;return{step:e,total:r,label:n,variant:o,percentage:s,isComplete:c}}function Q(t){let{step:e,total:r,label:n,variant:o,percentage:s}=N(t);return(0,p.jsxs)("div",{className:"urun-progress-card","data-variant":o,children:[n&&(0,p.jsx)("div",{className:"urun-progress-label",children:n}),(0,p.jsx)("div",{className:"urun-progress-bar",children:(0,p.jsx)("div",{className:"urun-progress-fill",style:{width:`${s}%`}})}),(0,p.jsxs)("div",{className:"urun-progress-text",children:[e,"/",r]})]})}var _=require("zod"),S=require("react/jsx-runtime"),X=_.z.object({state:_.z.enum(["thinking","generating","idle","error"]),message:_.z.string().optional()}),ve={thinking:"Thinking...",generating:"Generating...",idle:"Idle",error:"Error"};function U(t){let{state:e,message:r}=t,n=e==="thinking"||e==="generating",o=r??ve[e]??e;return{state:e,message:o,isActive:n}}function Y(t){let{state:e,message:r,isActive:n}=U(t);return(0,S.jsxs)("span",{className:"urun-status-badge","data-state":e,children:[(0,S.jsx)("span",{className:`urun-status-indicator${n?" urun-status-pulse":""}`}),(0,S.jsx)("span",{className:"urun-status-message",children:r})]})}var y=require("react"),A=require("zod"),k=require("react/jsx-runtime"),ee=A.z.object({text:A.z.string(),streaming:A.z.boolean().default(!1)});function B(t){let{text:e,streaming:r=!1}=t,n=e.length===0;return{text:e,streaming:r,isEmpty:n}}function re(t){let{text:e,streaming:r}=B(t),n=(0,y.useRef)(null),o=(0,y.useRef)(0);return(0,y.useEffect)(()=>{let s=n.current;s&&e.length!==o.current&&(s.textContent=e,o.current=e.length)},[e]),(0,k.jsxs)("div",{className:"urun-text-stream",children:[(0,k.jsx)("span",{ref:n,className:"urun-text-content"}),r&&(0,k.jsx)("span",{className:"urun-text-cursor"})]})}var x=require("zod"),P=require("react/jsx-runtime"),te=x.z.object({src:x.z.string().url(),alt:x.z.string().optional(),caption:x.z.string().optional()});function O(t){let{src:e,alt:r,caption:n}=t;return{src:e,alt:r??"",caption:n}}function ne(t){let{src:e,alt:r,caption:n}=O(t);return(0,P.jsxs)("figure",{className:"urun-image-frame",children:[(0,P.jsx)("img",{className:"urun-image",src:e,alt:r}),n&&(0,P.jsx)("figcaption",{className:"urun-image-caption",children:n})]})}var i=require("zod"),l=require("react/jsx-runtime"),oe=i.z.object({metrics:i.z.array(i.z.object({label:i.z.string(),value:i.z.union([i.z.string(),i.z.number()]),unit:i.z.string().optional()}))});function D(t){return{metrics:t.metrics.map(r=>({...r,displayValue:r.unit?`${r.value} ${r.unit}`:String(r.value)}))}}function se(t){let{metrics:e}=D(t);return(0,l.jsx)("div",{className:"urun-metrics-panel",children:e.map((r,n)=>(0,l.jsxs)("div",{className:"urun-metric-card",children:[(0,l.jsx)("div",{className:"urun-metric-label",children:r.label}),(0,l.jsx)("div",{className:"urun-metric-value",children:r.displayValue})]},n))})}0&&(module.exports={ComponentRenderer,ImageFrame,ImageFrameSchema,MetricsPanel,MetricsPanelSchema,ProgressCard,ProgressCardSchema,StatusBadge,StatusBadgeSchema,TextStream,TextStreamSchema,UrunErrorBoundary,UrunProvider,registerComponent,useApp,useImageFrame,useMetricsPanel,useProgressCard,useStatusBadge,useTextStream});
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{useMemo as q,useState as G}from"react";import{Component as
|
|
1
|
+
import{useMemo as q,useState as G}from"react";import{Component as $}from"react";import{jsx as b,jsxs as L}from"react/jsx-runtime";var u=class extends ${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||L("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:[b("p",{style:{margin:0,fontWeight:600},children:"Connection interrupted"}),b("p",{style:{margin:"6px 0 0",color:"#4b5563"},children:"Reconnecting automatically."})]})}return this.props.children}};import{createContext as V}from"react";var l=V(null);import{useEffect as R,useState as j}from"react";import{jsx as Z}from"react/jsx-runtime";function J({module:t,onToken:e}){let r=t.useAuth();return R(()=>{let n=!1;async function o(){if(!(r.loading||r.isLoading))try{let a=r.getAccessToken?await r.getAccessToken():r.accessToken;n||e(a??void 0)}catch{n||e(void 0)}}o();let s=window.setInterval(()=>{o()},6e4);return()=>{n=!0,window.clearInterval(s)}},[r,r.accessToken,r.getAccessToken,r.isAuthenticated,r.isLoading,r.loading,r.user,e]),null}function C({onToken:t}){let[e,r]=j(null);return R(()=>{let n=!1;return import("@workos-inc/authkit-react").then(o=>{!n&&typeof o.useAuth=="function"&&r({useAuth:o.useAuth})}).catch(()=>{n||r(null)}),()=>{n=!0}},[]),e?Z(J,{module:e,onToken:t}):null}import{jsx as w,jsxs as K}from"react/jsx-runtime";function H({baseUrl:t,orgId:e,appId:r,jwt:n,authProvider:o,fallback:s,children:a}){let[d,m]=G(),c=n??d,z=q(()=>({appId:r,baseUrl:t,orgId:e,jwt:c,authProvider:o}),[r,o,t,c,e]);return K(u,{fallback:s,children:[o==="workos"&&!n?w(C,{onToken:m}):null,w(l.Provider,{value:z,children:a})]})}import{useContext as Q,useMemo as T,useReducer as X,useRef as Y}from"react";import{App as ee}from"@urun-sh/core";function re(t,e){return`${t}:${JSON.stringify(e??{})}`}var h=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))}dispose(){this._unsubscribeChange()}},v=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)}detach(){return this._stream.detach()}seek(e){return this._stream.seek(e)}on(e,r){return this._stream.on(e,r)}dispose(){this._unsubscribeTrack()}},S=class{constructor(e,r){this._session=e;this._notify=r}_session;_notify;_docs=new Map;_streams=new Map;get id(){return this._session.id}doc(e){let r=this._docs.get(e);return r||(r=new h(this._session.doc(e),this._notify),this._docs.set(e,r)),r}stream(e){let r=this._streams.get(e);return r||(r=new v(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._session.disconnect(),this._notify()}};function te(){let t=Q(l);if(!t)throw new Error("useApp must be used within <UrunProvider>");if(!t.appId)throw new Error('useApp requires <UrunProvider appId="...">');let[,e]=X(o=>o+1,0),r=Y(new Map),n=T(()=>ee(t.appId,{baseUrl:t.baseUrl,orgId:t.orgId,jwt:t.jwt,authProvider:t.authProvider}),[t.appId,t.baseUrl,t.orgId,t.jwt,t.authProvider]);return T(()=>new Proxy({},{get(o,s){if(typeof s=="string")return a=>{let d=re(s,a),m=r.current.get(d);if(m)return m;let c=new S(n[s](a),e);return r.current.set(d,c),c}}}),[n])}var _=new Map;function ne(t,e,r){if(!r||typeof r.safeParse!="function")throw new Error(`registerComponent("${t}"): schema must be a valid Zod schema`);_.set(t,{component:e,schema:r})}function A(t,e){let r=_.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 se,jsx as g}from"react/jsx-runtime";function oe({name:t,props:e,fallback:r}){let n=A(t,e);if(n.error)return console.warn(`[urun] ComponentRenderer: ${n.error}`),r?g(se,{children:r}):g("div",{className:"urun-component-error",role:"alert",children:g("span",{className:"urun-component-error-text",children:n.error})});let o=n.Component;return g(o,{...n.validatedProps})}import{z as p}from"zod";import{jsx as y,jsxs as M}from"react/jsx-runtime";var ae=p.object({step:p.number().min(0),total:p.number().min(1),label:p.string().optional(),variant:p.enum(["default","success","error"]).default("default")});function E(t){let{step:e,total:r,label:n,variant:o="default"}=t,s=Math.min(e/r*100,100),a=e>=r;return{step:e,total:r,label:n,variant:o,percentage:s,isComplete:a}}function ie(t){let{step:e,total:r,label:n,variant:o,percentage:s}=E(t);return M("div",{className:"urun-progress-card","data-variant":o,children:[n&&y("div",{className:"urun-progress-label",children:n}),y("div",{className:"urun-progress-bar",children:y("div",{className:"urun-progress-fill",style:{width:`${s}%`}})}),M("div",{className:"urun-progress-text",children:[e,"/",r]})]})}import{z as k}from"zod";import{jsx as I,jsxs as de}from"react/jsx-runtime";var ce=k.object({state:k.enum(["thinking","generating","idle","error"]),message:k.string().optional()}),ue={thinking:"Thinking...",generating:"Generating...",idle:"Idle",error:"Error"};function N(t){let{state:e,message:r}=t,n=e==="thinking"||e==="generating",o=r??ue[e]??e;return{state:e,message:o,isActive:n}}function pe(t){let{state:e,message:r,isActive:n}=N(t);return de("span",{className:"urun-status-badge","data-state":e,children:[I("span",{className:`urun-status-indicator${n?" urun-status-pulse":""}`}),I("span",{className:"urun-status-message",children:r})]})}import{useRef as U,useEffect as me}from"react";import{z as x}from"zod";import{jsx as B,jsxs as fe}from"react/jsx-runtime";var le=x.object({text:x.string(),streaming:x.boolean().default(!1)});function O(t){let{text:e,streaming:r=!1}=t,n=e.length===0;return{text:e,streaming:r,isEmpty:n}}function ge(t){let{text:e,streaming:r}=O(t),n=U(null),o=U(0);return me(()=>{let s=n.current;s&&e.length!==o.current&&(s.textContent=e,o.current=e.length)},[e]),fe("div",{className:"urun-text-stream",children:[B("span",{ref:n,className:"urun-text-content"}),r&&B("span",{className:"urun-text-cursor"})]})}import{z as f}from"zod";import{jsx as D,jsxs as Se}from"react/jsx-runtime";var he=f.object({src:f.string().url(),alt:f.string().optional(),caption:f.string().optional()});function W(t){let{src:e,alt:r,caption:n}=t;return{src:e,alt:r??"",caption:n}}function ve(t){let{src:e,alt:r,caption:n}=W(t);return Se("figure",{className:"urun-image-frame",children:[D("img",{className:"urun-image",src:e,alt:r}),n&&D("figcaption",{className:"urun-image-caption",children:n})]})}import{z as i}from"zod";import{jsx as P,jsxs as xe}from"react/jsx-runtime";var ye=i.object({metrics:i.array(i.object({label:i.string(),value:i.union([i.string(),i.number()]),unit:i.string().optional()}))});function F(t){return{metrics:t.metrics.map(r=>({...r,displayValue:r.unit?`${r.value} ${r.unit}`:String(r.value)}))}}function ke(t){let{metrics:e}=F(t);return P("div",{className:"urun-metrics-panel",children:e.map((r,n)=>xe("div",{className:"urun-metric-card",children:[P("div",{className:"urun-metric-label",children:r.label}),P("div",{className:"urun-metric-value",children:r.displayValue})]},n))})}export{oe as ComponentRenderer,ve as ImageFrame,he as ImageFrameSchema,ke as MetricsPanel,ye as MetricsPanelSchema,ie as ProgressCard,ae as ProgressCardSchema,pe as StatusBadge,ce as StatusBadgeSchema,ge as TextStream,le as TextStreamSchema,u as UrunErrorBoundary,H as UrunProvider,ne as registerComponent,te as useApp,W as useImageFrame,F as useMetricsPanel,E as useProgressCard,N as useStatusBadge,O as useTextStream};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@urun-sh/react",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.9",
|
|
4
4
|
"description": "React bindings for the urun TypeScript SDK",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
},
|
|
32
32
|
"peerDependencies": {
|
|
33
33
|
"react": "^18.2.0 || ^19.0.0",
|
|
34
|
-
"@urun-sh/core": "^0.1.
|
|
34
|
+
"@urun-sh/core": "^0.1.9",
|
|
35
35
|
"@workos-inc/authkit-react": "^0.15.0"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|