@tbox.cn/app-agent-sdk-client 0.1.2 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1 +1 @@
|
|
|
1
|
-
import{G as j}from"../chunk-RQWCUVXR.js";import{useCallback as E,useEffect as xe,useMemo as te,useRef as P,useState as k}from"react";import{CardRenderer as ve}from"@tbox.cn/app-sdk-client";var ge="preview",Y="表单提交需引擎运行,预览不支持",J=e=>`预览:已发送「${e}」`,X=e=>`宿主效果 ×${e}(预览不执行)`;function q(e){return new URLSearchParams(e).get("history")==="true"}function K(e){return new URLSearchParams(e).get("controls")!=="false"}var G="(未声明)";function fe(e){return[...new Set(e)].sort((t,n)=>t===n?0:t===G?1:n===G?-1:t.localeCompare(n))}function B(e,t={}){let n=fe(e.cards.map(d=>d.moduleId)),i=t.module!==void 0&&t.module!=="all"&&!n.includes(t.module)?[...n,t.module]:n,r=t.module??"all",a=[...r==="all"?e.cards:e.cards.filter(d=>d.moduleId===r)].sort((d,v)=>d.cardType.localeCompare(v.cardType)),y=a.map(d=>d.cardType),m=a.find(d=>d.cardType===t.card)??a[0],f=m?.cardType??"",g=m?.samples??[],b=t.sample!==void 0&&g.some(d=>d.label===t.sample)?t.sample:"初始态";return{modules:i,moduleId:r,cardTypes:y,candidateCards:a,cardType:f,selectedCard:m,samples:g,sampleLabel:b}}function me(e,t){return`preview-${e.replace(/[^a-zA-Z0-9_-]/g,"_")}-${t}`}function W(e){return{...e.title!==void 0?{title:e.title}:{},...e.subtitle!==void 0?{subtitle:e.subtitle}:{},...e.notices!==void 0?{notices:e.notices}:{},...e.expiresAt!==void 0?{expiresAt:e.expiresAt}:{}}}function z(e,t){let n={};if(!t.noTokens)for(let i of e.actions)(!i.kind||i.kind==="moduleAction")&&(n[i.actionId]=ge);return{id:t.id,cardType:e.cardType,data:t.data,status:"ready",...e.actions.length?{actions:e.actions}:{},...Object.keys(n).length?{actionTokens:n}:{},...t.isHistory?{isHistory:!0}:{},...t.title!==void 0?{title:t.title}:{},...t.subtitle!==void 0?{subtitle:t.subtitle}:{},...t.notices!==void 0?{notices:t.notices}:{},...t.expiresAt!==void 0?{expiresAt:t.expiresAt}:{}}}function Z(e,t,n){return z(e,{id:me(e.cardType,n),data:t.data,isHistory:!!t.isHistory,noTokens:!!t.noTokens,...t.envelope??{}})}function be(e,t,n,i){if(n.ok!==!0||e.payload.id!==t||!n.card)return e;if(n.kind==="card"){let r=i(n.card.cardType),a=r?.samples[0];return!r||!a?e:{card:r,sample:a,payload:z(r,{id:n.card.id,data:n.card.data,isHistory:!1,noTokens:!1,...W(n.card)})}}return n.kind!=="update"?e:{...e,payload:z(e.card,{id:t,data:n.card.data,isHistory:!!e.sample.isHistory,noTokens:!!e.sample.noTokens,...W(n.card)})}}function Q(e,t,n,i,r){let a=e[t];if(!a||a.payload.id!==n)return e;let y=be(a,n,i,r);return y===a?e:{...e,[t]:y}}function ee(e){switch(e.type){case"moduleAction":return{type:"server"};case"openLink":return{type:"openLink",url:e.url};case"sendMessage":return{type:"sendMessage",value:e.value};case"submitForm":return{type:"submitFormUnsupported"};default:return{type:"ignored"}}}import{jsx as s,jsxs as u}from"react/jsx-runtime";var we="客户端未装配模块——经 tbox-app dev --module <模块> 装配后可见",he="服务端未注册卡片(模块未装配或全部被禁用)",Te=e=>`模块「${e}」暂无示例卡片`,Ce="鉴权失败:dev 环境依赖 dev-login(浏览器态自动登录);生产构建(NODE_ENV=production)预览面不挂载",re=e=>`卡片目录拉取失败(HTTP ${e})`,Se="tbox 卡片预览",Pe="isHistory 视角",Ae="全部模块";function oe(e,t,n){let i=Math.max(0,e.samples.findIndex(a=>a.label===t)),r=e.samples[i];return r?{card:e,sample:r,payload:Z(e,r,n??i)}:null}function Qe(e){let{registry:t,authClient:n}=e,i=Object.keys(t).length===0,[r,a]=k(null),[y,m]=k(null),[f,g]=k("all"),[b,d]=k(!1),[v,C]=k({}),[I,N]=k([]),F=P(null),M=P(new Set),h=P(v);h.current=v;let V=P(r);V.current=r;let ae=P(0),se=P(0),H=te(()=>{try{let o=window.location.search,p=new URLSearchParams(o);return{module:p.get("module")??void 0,card:p.get("card")??void 0,sample:p.get("sample")??void 0,history:q(o),controls:K(o)}}catch{return{}}},[]),de=H.controls!==!1,x=E(o=>{let p=++ae.current;N(l=>[...l,{id:p,text:o}]),setTimeout(()=>N(l=>l.filter(c=>c.id!==p)),3200)},[]);xe(()=>{let o=!1,p=j((l,c,T)=>{$.current(l,c,T)});return(async()=>{try{let l=await n.ensureAuth();F.current=l.token;let c=await fetch("/_tbox/api/cards",{headers:l.token?{Authorization:`Bearer ${l.token}`}:{}});if(o)return;if(c.status===401||c.status===403){m(Ce);return}if(!c.ok){m(re(c.status));return}let T=await c.json();if(o)return;a(T);let R=B(T,H);g(R.moduleId);let L=Re(T.cards,R.cardType,R.sampleLabel);h.current=L,C(L),d(H.history===!0)}catch(l){o||m(`卡片目录拉取失败:${l.message}`)}})(),()=>{o=!0,p()}},[]);let O=E((o,p,l)=>{let c=ee(p);if(c.type==="openLink"){window.open(c.url,"_blank");return}if(c.type==="sendMessage"){x(J(c.value));return}if(c.type==="submitFormUnsupported"){x(Y);return}if(c.type==="ignored")return;let T=Object.entries(h.current).find(([,S])=>S.payload.id===o),R=T?.[1];if(!T||!R||p.type!=="moduleAction"||M.current.has(o))return;M.current.add(o);let L=F.current;fetch("/_tbox/api/card-action",{method:"POST",headers:{"Content-Type":"application/json",...L?{Authorization:`Bearer ${L}`}:{}},body:JSON.stringify({cardType:R.card.cardType,actionId:p.actionId,surfaceId:o,...l!==void 0?{input:l}:{}})}).then(async S=>{let w=await S.json().catch(()=>null);if(!S.ok||!w||w.ok===!1){x(w?.error??re(S.status));return}let pe=w,D=h.current,U=Q(D,T[0],o,pe,ue=>V.current?.cards.find(ye=>ye.cardType===ue));U!==D&&(h.current=U,C(U)),typeof w.text=="string"&&w.text&&x(w.text),Array.isArray(w.effects)&&w.effects.length>0&&x(X(w.effects.length))}).catch(S=>x(`动作请求失败:${S.message}`)).finally(()=>M.current.delete(o))},[x]),$=P(O);$.current=O;let A=te(()=>r?B(r,{module:f==="all"?void 0:f}):null,[r,f]),ce=E((o,p)=>{let l=h.current[o];if(!l)return;let c=oe(l.card,p,l.card.samples.length+ ++se.current);c&&(h.current={...h.current,[o]:c},C(h.current))},[]),le=E(o=>{if(typeof navigator>"u"||!navigator.clipboard?.writeText){x("当前浏览器不支持复制");return}navigator.clipboard.writeText(o).then(()=>x(`已复制卡型 ID:${o}`)).catch(()=>x("复制失败,请手动复制"))},[x]);return u("div",{style:{minHeight:"100vh",background:"#f5f5f5",fontFamily:'-apple-system, "PingFang SC", sans-serif'},children:[de&&u("header",{style:Le,children:[s("strong",{style:{fontSize:14,color:"#262626"},children:Se}),u("select",{"aria-label":"模块",style:Ee,value:f,onChange:o=>g(o.target.value),children:[s("option",{value:"all",children:Ae}),(A?.modules??[]).map(o=>s("option",{value:o,children:o},o))]}),s("button",{type:"button",style:b?_e:ie,onClick:()=>d(o=>!o),children:Pe})]}),u("main",{style:{maxWidth:1200,margin:"0 auto",padding:"12px 12px 48px"},children:[y&&s("div",{style:We,children:y}),!y&&!r&&s("div",{style:_,children:"加载中…"}),r&&i&&s("div",{style:_,children:we}),r&&!i&&r.cards.length===0&&s("div",{style:_,children:he}),r&&!i&&r.cards.length>0&&A&&A.candidateCards.length===0&&s("div",{style:_,children:Te(A.moduleId)}),r&&!i&&A&&s(ke,{cards:A.candidateCards,rows:v,registry:t,historyView:b,onSelectSample:ce,onCopyCardType:le,onAction:O})]}),s("div",{style:{position:"fixed",right:16,bottom:24,display:"flex",flexDirection:"column",gap:8,zIndex:20},children:I.map(o=>s("div",{style:Ye,children:o.text},o.id))})]})}function Re(e,t,n){let i={};for(let r of e){let a=oe(r,r.cardType===t?n:void 0);a&&(i[r.cardType]=a)}return i}function ke(e){let{cards:t,rows:n,registry:i,historyView:r,onSelectSample:a,onCopyCardType:y,onAction:m}=e;return s("div",{style:He,children:t.map(f=>{let g=n[f.cardType];return g?s(Ie,{instance:g,registry:i,historyView:r,samples:g.card.samples,activeSampleLabel:g.sample.label,onSelectSample:b=>a(f.cardType,b),onCopyCardType:y,onAction:m},f.cardType):null})})}function Ie(e){let{instance:t,registry:n,historyView:i,samples:r,activeSampleLabel:a,onSelectSample:y,onCopyCardType:m,onAction:f}=e,g=i?{...t.payload,isHistory:!0}:t.payload,b=Math.max(0,r.findIndex(I=>I.label===a)),d=r[b]??t.sample,v=r[b-1],C=r[b+1];return u("section",{style:Me,children:[u("header",{style:{marginBottom:8},children:[s("div",{style:{fontSize:14,fontWeight:600,color:"#262626",lineHeight:"22px"},children:t.card.displayName}),u("div",{style:Oe,children:[u("span",{style:Ue,title:t.card.cardType,children:["卡片id:",t.card.cardType]}),s("button",{type:"button","aria-label":`复制卡型 ID:${t.card.cardType}`,title:"复制卡型 ID",style:ze,onClick:()=>m(t.card.cardType),children:u("span",{"aria-hidden":"true",style:Be,children:[s("span",{style:Ne}),s("span",{style:Fe})]})})]})]}),r.length>0&&u("div",{style:$e,children:[u("div",{style:Ge,title:d.label,"aria-live":"polite",children:[d.issues?.length||d.envelopeError?"⚠ ":"",d.label]}),u("div",{style:De,children:[s("button",{type:"button","aria-label":"上一个样本",title:"上一个样本",disabled:!v,onClick:()=>v&&y(v.label),style:ne(!v),children:"‹"}),u("span",{style:je,children:[b+1," / ",r.length]}),s("button",{type:"button","aria-label":"下一个样本",title:"下一个样本",disabled:!C,onClick:()=>C&&y(C.label),style:ne(!C),children:"›"})]})]}),(t.sample.issues?.length||t.sample.envelopeError)&&u("div",{style:Ve,children:[t.sample.issues?.length?`样本问题:${t.sample.issues.join(";")}`:null,t.sample.envelopeError&&t.sample.issues?.length?";":"",t.sample.envelopeError??""]}),s(ve,{card:g,registry:n,onAction:I=>f(g.id,I)})]})}var Le={position:"sticky",top:0,zIndex:10,display:"flex",flexWrap:"wrap",alignItems:"center",gap:8,padding:"10px 16px",background:"#fff",borderBottom:"1px solid #e8e8e8"},Ee={fontSize:13,padding:"4px 8px",borderRadius:8,border:"1px solid #d9d9d9",background:"#fff",color:"#262626"},ie={fontSize:13,padding:"4px 12px",borderRadius:18,border:"1px solid #d9d9d9",background:"#fff",color:"#262626",cursor:"pointer"},_e={...ie,borderColor:"#1677ff",color:"#1677ff"},Me={background:"#fff",borderRadius:8,padding:14,boxShadow:"0 1px 4px rgba(0,0,0,0.06)"},He={display:"flex",flexDirection:"column",gap:12},Oe={display:"flex",alignItems:"center",justifyContent:"space-between",gap:"var(--spacing.4, 4px)",minHeight:20,color:"var(--color.text.tertiary, #8c8c8c)",fontSize:11,lineHeight:"16px"},Ue={flex:"1 1 auto",minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},ze={display:"inline-flex",alignItems:"center",justifyContent:"center",flex:"0 0 auto",width:20,height:20,padding:0,border:0,borderRadius:"var(--radius.4, 4px)",background:"transparent",color:"var(--color.text.tertiary, #8c8c8c)",cursor:"pointer"},Be={position:"relative",display:"inline-block",width:13,height:13},Ne={position:"absolute",top:1,left:1,width:8,height:8,border:"1px solid currentColor",borderRadius:2,boxSizing:"border-box"},Fe={position:"absolute",right:1,bottom:1,width:8,height:8,border:"1px solid currentColor",borderRadius:2,background:"#fff",boxSizing:"border-box"},Ve={fontSize:12,lineHeight:"18px",padding:"4px 10px",borderRadius:8,background:"rgba(250,140,22,0.10)",color:"#d46b08",marginBottom:8},$e={display:"flex",alignItems:"center",justifyContent:"space-between",gap:"var(--spacing.12, 12px)",minHeight:24,marginBottom:10},De={display:"flex",alignItems:"center",gap:"var(--spacing.2, 2px)",flex:"0 0 auto",height:24},ne=e=>({width:24,height:24,padding:0,border:0,borderRadius:"var(--radius.4, 4px)",background:"transparent",color:e?"var(--color.text.disabled, #bfbfbf)":"var(--color.text.secondary, #404040)",fontSize:18,lineHeight:"22px",cursor:e?"not-allowed":"pointer"}),je={display:"flex",alignItems:"center",justifyContent:"center",minWidth:42,color:"var(--color.text.tertiary, #8c8c8c)",fontSize:"var(--font.size.12, 12px)",fontVariantNumeric:"tabular-nums",whiteSpace:"nowrap"},Ge={flex:"1 1 auto",minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:"var(--color.text.primary, #1f1f1f)",fontSize:"var(--font.size.14, 14px)",fontWeight:"var(--font.weight.medium, 500)"},We={padding:"12px 14px",borderRadius:8,background:"rgba(255,77,79,0.08)",color:"#ff4d4f",fontSize:13,lineHeight:"20px"},_={padding:"12px 14px",borderRadius:8,background:"#fff",color:"#8c8c8c",fontSize:13,lineHeight:"20px",textAlign:"center"},Ye={maxWidth:320,padding:"8px 12px",borderRadius:8,background:"rgba(38,38,38,0.88)",color:"#fff",fontSize:13,lineHeight:"18px",boxShadow:"0 4px 12px rgba(0,0,0,0.18)"};export{Ce as AUTH_ERROR_MSG,Qe as CardPreviewPage,he as EMPTY_CATALOG_MSG,Te as EMPTY_MODULE_MSG,we as EMPTY_REGISTRY_MSG,Pe as HISTORY_VIEW_LABEL,re as LOAD_ERROR_MSG,Ae as MODULE_ALL_LABEL,Se as PAGE_TITLE,ke as PreviewRows,Ie as PreviewSurface,Re as buildPreviewRows};
|
|
1
|
+
import{G as j}from"../chunk-RQWCUVXR.js";import{useCallback as L,useEffect as xe,useMemo as te,useRef as A,useState as I}from"react";import{CardRenderer as ve}from"@tbox.cn/app-sdk-client";var ge="preview",Y="表单提交需引擎运行,预览不支持",J=e=>`预览:已发送「${e}」`,X=e=>`宿主效果 ×${e}(预览不执行)`;function q(e){return new URLSearchParams(e).get("history")==="true"}function K(e){return new URLSearchParams(e).get("controls")!=="false"}var G="(未声明)";function fe(e){return[...new Set(e)].sort((t,n)=>t===n?0:t===G?1:n===G?-1:t.localeCompare(n))}function z(e,t={}){let n=fe(e.cards.map(d=>d.moduleId)),i=t.module!==void 0&&t.module!=="all"&&!n.includes(t.module)?[...n,t.module]:n,r=t.module??"all",a=[...r==="all"?e.cards:e.cards.filter(d=>d.moduleId===r)].sort((d,x)=>{let v=d.order??Number.POSITIVE_INFINITY,C=x.order??Number.POSITIVE_INFINITY;return v!==C?v-C:d.cardType.localeCompare(x.cardType)}),y=a.map(d=>d.cardType),m=a.find(d=>d.cardType===t.card)??a[0],f=m?.cardType??"",g=m?.samples??[],b=t.sample!==void 0&&g.some(d=>d.label===t.sample)?t.sample:"初始态";return{modules:i,moduleId:r,cardTypes:y,candidateCards:a,cardType:f,selectedCard:m,samples:g,sampleLabel:b}}function me(e,t){return`preview-${e.replace(/[^a-zA-Z0-9_-]/g,"_")}-${t}`}function W(e){return{...e.title!==void 0?{title:e.title}:{},...e.subtitle!==void 0?{subtitle:e.subtitle}:{},...e.notices!==void 0?{notices:e.notices}:{},...e.expiresAt!==void 0?{expiresAt:e.expiresAt}:{}}}function N(e,t){let n={};if(!t.noTokens)for(let i of e.actions)(!i.kind||i.kind==="moduleAction")&&(n[i.actionId]=ge);return{id:t.id,cardType:e.cardType,data:t.data,status:"ready",...e.actions.length?{actions:e.actions}:{},...Object.keys(n).length?{actionTokens:n}:{},...t.isHistory?{isHistory:!0}:{},...t.title!==void 0?{title:t.title}:{},...t.subtitle!==void 0?{subtitle:t.subtitle}:{},...t.notices!==void 0?{notices:t.notices}:{},...t.expiresAt!==void 0?{expiresAt:t.expiresAt}:{}}}function Z(e,t,n){return N(e,{id:me(e.cardType,n),data:t.data,isHistory:!!t.isHistory,noTokens:!!t.noTokens,...t.envelope??{}})}function be(e,t,n,i){if(n.ok!==!0||e.payload.id!==t||!n.card)return e;if(n.kind==="card"){let r=i(n.card.cardType),a=r?.samples[0];return!r||!a?e:{card:r,sample:a,payload:N(r,{id:n.card.id,data:n.card.data,isHistory:!1,noTokens:!1,...W(n.card)})}}return n.kind!=="update"?e:{...e,payload:N(e.card,{id:t,data:n.card.data,isHistory:!!e.sample.isHistory,noTokens:!!e.sample.noTokens,...W(n.card)})}}function Q(e,t,n,i,r){let a=e[t];if(!a||a.payload.id!==n)return e;let y=be(a,n,i,r);return y===a?e:{...e,[t]:y}}function ee(e){switch(e.type){case"moduleAction":return{type:"server"};case"openLink":return{type:"openLink",url:e.url};case"sendMessage":return{type:"sendMessage",value:e.value};case"submitForm":return{type:"submitFormUnsupported"};default:return{type:"ignored"}}}import{jsx as s,jsxs as u}from"react/jsx-runtime";var we="客户端未装配模块——经 tbox-app dev --module <模块> 装配后可见",Te="服务端未注册卡片(模块未装配或全部被禁用)",Se=e=>`模块「${e}」暂无示例卡片`,he="鉴权失败:dev 环境依赖 dev-login(浏览器态自动登录);生产构建(NODE_ENV=production)预览面不挂载",re=e=>`卡片目录拉取失败(HTTP ${e})`,Ce="tbox 卡片预览",Pe="isHistory 视角",Ae="全部模块";function oe(e,t,n){let i=Math.max(0,e.samples.findIndex(a=>a.label===t)),r=e.samples[i];return r?{card:e,sample:r,payload:Z(e,r,n??i)}:null}function Qe(e){let{registry:t,authClient:n}=e,i=Object.keys(t).length===0,[r,a]=I(null),[y,m]=I(null),[f,g]=I("all"),[b,d]=I(!1),[x,v]=I({}),[C,B]=I([]),F=A(null),M=A(new Set),S=A(x);S.current=x;let V=A(r);V.current=r;let ae=A(0),se=A(0),H=te(()=>{try{let o=window.location.search,p=new URLSearchParams(o);return{module:p.get("module")??void 0,card:p.get("card")??void 0,sample:p.get("sample")??void 0,history:q(o),controls:K(o)}}catch{return{}}},[]),de=H.controls!==!1,w=L(o=>{let p=++ae.current;B(l=>[...l,{id:p,text:o}]),setTimeout(()=>B(l=>l.filter(c=>c.id!==p)),3200)},[]);xe(()=>{let o=!1,p=j((l,c,h)=>{$.current(l,c,h)});return(async()=>{try{let l=await n.ensureAuth();F.current=l.token;let c=await fetch("/_tbox/api/cards",{headers:l.token?{Authorization:`Bearer ${l.token}`}:{}});if(o)return;if(c.status===401||c.status===403){m(he);return}if(!c.ok){m(re(c.status));return}let h=await c.json();if(o)return;a(h);let k=z(h,H);g(k.moduleId);let E=Re(h.cards,k.cardType,k.sampleLabel);S.current=E,v(E),d(H.history===!0)}catch(l){o||m(`卡片目录拉取失败:${l.message}`)}})(),()=>{o=!0,p()}},[]);let O=L((o,p,l)=>{let c=ee(p);if(c.type==="openLink"){window.open(c.url,"_blank");return}if(c.type==="sendMessage"){w(J(c.value));return}if(c.type==="submitFormUnsupported"){w(Y);return}if(c.type==="ignored")return;let h=Object.entries(S.current).find(([,P])=>P.payload.id===o),k=h?.[1];if(!h||!k||p.type!=="moduleAction"||M.current.has(o))return;M.current.add(o);let E=F.current;fetch("/_tbox/api/card-action",{method:"POST",headers:{"Content-Type":"application/json",...E?{Authorization:`Bearer ${E}`}:{}},body:JSON.stringify({cardType:k.card.cardType,actionId:p.actionId,surfaceId:o,...l!==void 0?{input:l}:{}})}).then(async P=>{let T=await P.json().catch(()=>null);if(!P.ok||!T||T.ok===!1){w(T?.error??re(P.status));return}let pe=T,D=S.current,U=Q(D,h[0],o,pe,ue=>V.current?.cards.find(ye=>ye.cardType===ue));U!==D&&(S.current=U,v(U)),typeof T.text=="string"&&T.text&&w(T.text),Array.isArray(T.effects)&&T.effects.length>0&&w(X(T.effects.length))}).catch(P=>w(`动作请求失败:${P.message}`)).finally(()=>M.current.delete(o))},[w]),$=A(O);$.current=O;let R=te(()=>r?z(r,{module:f==="all"?void 0:f}):null,[r,f]),ce=L((o,p)=>{let l=S.current[o];if(!l)return;let c=oe(l.card,p,l.card.samples.length+ ++se.current);c&&(S.current={...S.current,[o]:c},v(S.current))},[]),le=L(o=>{if(typeof navigator>"u"||!navigator.clipboard?.writeText){w("当前浏览器不支持复制");return}navigator.clipboard.writeText(o).then(()=>w(`已复制卡型 ID:${o}`)).catch(()=>w("复制失败,请手动复制"))},[w]);return u("div",{style:{minHeight:"100vh",background:"#f5f5f5",fontFamily:'-apple-system, "PingFang SC", sans-serif'},children:[de&&u("header",{style:Ee,children:[s("strong",{style:{fontSize:14,color:"#262626"},children:Ce}),u("select",{"aria-label":"模块",style:Le,value:f,onChange:o=>g(o.target.value),children:[s("option",{value:"all",children:Ae}),(R?.modules??[]).map(o=>s("option",{value:o,children:o},o))]}),s("button",{type:"button",style:b?_e:ie,onClick:()=>d(o=>!o),children:Pe})]}),u("main",{style:{maxWidth:1200,margin:"0 auto",padding:"12px 12px 48px"},children:[y&&s("div",{style:We,children:y}),!y&&!r&&s("div",{style:_,children:"加载中…"}),r&&i&&s("div",{style:_,children:we}),r&&!i&&r.cards.length===0&&s("div",{style:_,children:Te}),r&&!i&&r.cards.length>0&&R&&R.candidateCards.length===0&&s("div",{style:_,children:Se(R.moduleId)}),r&&!i&&R&&s(ke,{cards:R.candidateCards,rows:x,registry:t,historyView:b,onSelectSample:ce,onCopyCardType:le,onAction:O})]}),s("div",{style:{position:"fixed",right:16,bottom:24,display:"flex",flexDirection:"column",gap:8,zIndex:20},children:C.map(o=>s("div",{style:Ye,children:o.text},o.id))})]})}function Re(e,t,n){let i={};for(let r of e){let a=oe(r,r.cardType===t?n:void 0);a&&(i[r.cardType]=a)}return i}function ke(e){let{cards:t,rows:n,registry:i,historyView:r,onSelectSample:a,onCopyCardType:y,onAction:m}=e;return s("div",{style:He,children:t.map(f=>{let g=n[f.cardType];return g?s(Ie,{instance:g,registry:i,historyView:r,samples:g.card.samples,activeSampleLabel:g.sample.label,onSelectSample:b=>a(f.cardType,b),onCopyCardType:y,onAction:m},f.cardType):null})})}function Ie(e){let{instance:t,registry:n,historyView:i,samples:r,activeSampleLabel:a,onSelectSample:y,onCopyCardType:m,onAction:f}=e,g=i?{...t.payload,isHistory:!0}:t.payload,b=Math.max(0,r.findIndex(C=>C.label===a)),d=r[b]??t.sample,x=r[b-1],v=r[b+1];return u("section",{style:Me,children:[u("header",{style:{marginBottom:8},children:[s("div",{style:{fontSize:14,fontWeight:600,color:"#262626",lineHeight:"22px"},children:t.card.displayName}),u("div",{style:Oe,children:[u("span",{style:Ue,title:t.card.cardType,children:["卡片id:",t.card.cardType]}),s("button",{type:"button","aria-label":`复制卡型 ID:${t.card.cardType}`,title:"复制卡型 ID",style:Ne,onClick:()=>m(t.card.cardType),children:u("span",{"aria-hidden":"true",style:ze,children:[s("span",{style:Be}),s("span",{style:Fe})]})})]})]}),r.length>0&&u("div",{style:$e,children:[u("div",{style:Ge,title:d.label,"aria-live":"polite",children:[d.issues?.length||d.envelopeError?"⚠ ":"",d.label]}),u("div",{style:De,children:[s("button",{type:"button","aria-label":"上一个样本",title:"上一个样本",disabled:!x,onClick:()=>x&&y(x.label),style:ne(!x),children:"‹"}),u("span",{style:je,children:[b+1," / ",r.length]}),s("button",{type:"button","aria-label":"下一个样本",title:"下一个样本",disabled:!v,onClick:()=>v&&y(v.label),style:ne(!v),children:"›"})]})]}),(t.sample.issues?.length||t.sample.envelopeError)&&u("div",{style:Ve,children:[t.sample.issues?.length?`样本问题:${t.sample.issues.join(";")}`:null,t.sample.envelopeError&&t.sample.issues?.length?";":"",t.sample.envelopeError??""]}),s(ve,{card:g,registry:n,onAction:C=>f(g.id,C)})]})}var Ee={position:"sticky",top:0,zIndex:10,display:"flex",flexWrap:"wrap",alignItems:"center",gap:8,padding:"10px 16px",background:"#fff",borderBottom:"1px solid #e8e8e8"},Le={fontSize:13,padding:"4px 8px",borderRadius:8,border:"1px solid #d9d9d9",background:"#fff",color:"#262626"},ie={fontSize:13,padding:"4px 12px",borderRadius:18,border:"1px solid #d9d9d9",background:"#fff",color:"#262626",cursor:"pointer"},_e={...ie,borderColor:"#1677ff",color:"#1677ff"},Me={background:"#fff",borderRadius:8,padding:14,boxShadow:"0 1px 4px rgba(0,0,0,0.06)"},He={display:"flex",flexDirection:"column",gap:12},Oe={display:"flex",alignItems:"center",justifyContent:"space-between",gap:"var(--spacing.4, 4px)",minHeight:20,color:"var(--color.text.tertiary, #8c8c8c)",fontSize:12,lineHeight:"16px"},Ue={flex:"1 1 auto",minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},Ne={display:"inline-flex",alignItems:"center",justifyContent:"center",flex:"0 0 auto",width:20,height:20,padding:0,border:0,borderRadius:"var(--radius.4, 4px)",background:"transparent",color:"var(--color.text.tertiary, #8c8c8c)",cursor:"pointer"},ze={position:"relative",display:"inline-block",width:13,height:13},Be={position:"absolute",top:1,left:1,width:8,height:8,border:"1px solid currentColor",borderRadius:2,boxSizing:"border-box"},Fe={position:"absolute",right:1,bottom:1,width:8,height:8,border:"1px solid currentColor",borderRadius:2,background:"#fff",boxSizing:"border-box"},Ve={fontSize:12,lineHeight:"18px",padding:"4px 10px",borderRadius:8,background:"rgba(250,140,22,0.10)",color:"#d46b08",marginBottom:8},$e={display:"flex",alignItems:"center",justifyContent:"space-between",gap:"var(--spacing.12, 12px)",minHeight:24,marginBottom:10},De={display:"flex",alignItems:"center",gap:"var(--spacing.2, 2px)",flex:"0 0 auto",height:24},ne=e=>({width:24,height:24,padding:0,border:0,borderRadius:"var(--radius.4, 4px)",background:"transparent",color:e?"var(--color.text.disabled, #bfbfbf)":"var(--color.text.secondary, #404040)",fontSize:18,lineHeight:"22px",cursor:e?"not-allowed":"pointer"}),je={display:"flex",alignItems:"center",justifyContent:"center",minWidth:42,color:"var(--color.text.tertiary, #8c8c8c)",fontSize:12,fontVariantNumeric:"tabular-nums",whiteSpace:"nowrap"},Ge={flex:"1 1 auto",minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:"var(--color.text.primary, #1f1f1f)",fontSize:12,fontWeight:"var(--font.weight.medium, 500)"},We={padding:"12px 14px",borderRadius:8,background:"rgba(255,77,79,0.08)",color:"#ff4d4f",fontSize:13,lineHeight:"20px"},_={padding:"12px 14px",borderRadius:8,background:"#fff",color:"#8c8c8c",fontSize:13,lineHeight:"20px",textAlign:"center"},Ye={maxWidth:320,padding:"8px 12px",borderRadius:8,background:"rgba(38,38,38,0.88)",color:"#fff",fontSize:13,lineHeight:"18px",boxShadow:"0 4px 12px rgba(0,0,0,0.18)"};export{he as AUTH_ERROR_MSG,Qe as CardPreviewPage,Te as EMPTY_CATALOG_MSG,Se as EMPTY_MODULE_MSG,we as EMPTY_REGISTRY_MSG,Pe as HISTORY_VIEW_LABEL,re as LOAD_ERROR_MSG,Ae as MODULE_ALL_LABEL,Ce as PAGE_TITLE,ke as PreviewRows,Ie as PreviewSurface,Re as buildPreviewRows};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tbox.cn/app-agent-sdk-client",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "tbox agent 应用框架 client 轴:chat-store 状态域、WS、卡片运行时、能力适配器(asr/tts/upload/feedback)、历史/深链自动发送。通用底座(runtime/http/logger/bridge/卡片渲染基元)在 @tbox.cn/app-sdk-client。",
|
|
6
6
|
"exports": {
|
|
@@ -34,9 +34,9 @@
|
|
|
34
34
|
"access": "public"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@tbox.cn/app-contracts": "0.12.
|
|
37
|
+
"@tbox.cn/app-contracts": "0.12.3",
|
|
38
38
|
"@tbox.cn/app-sdk-client": "0.21.1",
|
|
39
|
-
"@tbox.cn/app-sdk-core": "0.20.
|
|
39
|
+
"@tbox.cn/app-sdk-core": "0.20.2",
|
|
40
40
|
"react": "18.3.1",
|
|
41
41
|
"react-dom": "18.3.1",
|
|
42
42
|
"zustand": "4.5.7"
|