@tbox.cn/app-agent-sdk-client 0.1.1 → 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.
@@ -17,6 +17,7 @@ interface PreviewInstanceState {
17
17
 
18
18
  declare const EMPTY_REGISTRY_MSG = "\u5BA2\u6237\u7AEF\u672A\u88C5\u914D\u6A21\u5757\u2014\u2014\u7ECF tbox-app dev --module <\u6A21\u5757> \u88C5\u914D\u540E\u53EF\u89C1";
19
19
  declare const EMPTY_CATALOG_MSG = "\u670D\u52A1\u7AEF\u672A\u6CE8\u518C\u5361\u7247\uFF08\u6A21\u5757\u672A\u88C5\u914D\u6216\u5168\u90E8\u88AB\u7981\u7528\uFF09";
20
+ declare const EMPTY_MODULE_MSG: (moduleId: string) => string;
20
21
  declare const AUTH_ERROR_MSG = "\u9274\u6743\u5931\u8D25\uFF1Adev \u73AF\u5883\u4F9D\u8D56 dev-login\uFF08\u6D4F\u89C8\u5668\u6001\u81EA\u52A8\u767B\u5F55\uFF09\uFF1B\u751F\u4EA7\u6784\u5EFA\uFF08NODE_ENV=production\uFF09\u9884\u89C8\u9762\u4E0D\u6302\u8F7D";
21
22
  declare const LOAD_ERROR_MSG: (status: number) => string;
22
23
  declare const PAGE_TITLE = "tbox \u5361\u7247\u9884\u89C8";
@@ -48,4 +49,4 @@ declare function PreviewSurface(props: {
48
49
  onAction: (surfaceId: string, action: UiAction) => void;
49
50
  }): JSX.Element;
50
51
 
51
- export { AUTH_ERROR_MSG, CardPreviewPage, EMPTY_CATALOG_MSG, EMPTY_REGISTRY_MSG, HISTORY_VIEW_LABEL, LOAD_ERROR_MSG, MODULE_ALL_LABEL, PAGE_TITLE, PreviewRows, PreviewSurface, buildPreviewRows };
52
+ export { AUTH_ERROR_MSG, CardPreviewPage, EMPTY_CATALOG_MSG, EMPTY_MODULE_MSG, EMPTY_REGISTRY_MSG, HISTORY_VIEW_LABEL, LOAD_ERROR_MSG, MODULE_ALL_LABEL, PAGE_TITLE, PreviewRows, PreviewSurface, buildPreviewRows };
@@ -1 +1 @@
1
- import{G as j}from"../chunk-RQWCUVXR.js";import{useCallback as L,useEffect as xe,useMemo as te,useRef as P,useState as R}from"react";import{CardRenderer as ve}from"@tbox.cn/app-sdk-client";var ge="preview",J="表单提交需引擎运行,预览不支持",Y=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 W="(未声明)";function fe(e){return[...new Set(e)].sort((t,n)=>t===n?0:t===W?1:n===W?-1:t.localeCompare(n))}function U(e,t={}){let n=fe(e.cards.map(a=>a.moduleId)),i=t.module!==void 0&&n.includes(t.module)?t.module:"all",r=[...i==="all"?e.cards:e.cards.filter(a=>a.moduleId===i)].sort((a,v)=>a.cardType.localeCompare(v.cardType)),s=r.map(a=>a.cardType),p=r.find(a=>a.cardType===t.card)??r[0],x=p?.cardType??"",g=p?.samples??[],f=t.sample!==void 0&&g.some(a=>a.label===t.sample)?t.sample:"初始态";return{modules:n,moduleId:i,cardTypes:s,candidateCards:r,cardType:x,selectedCard:p,samples:g,sampleLabel:f}}function me(e,t){return`preview-${e.replace(/[^a-zA-Z0-9_-]/g,"_")}-${t}`}function G(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),s=r?.samples[0];return!r||!s?e:{card:r,sample:s,payload:z(r,{id:n.card.id,data:n.card.data,isHistory:!1,noTokens:!1,...G(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,...G(n.card)})}}function Q(e,t,n,i,r){let s=e[t];if(!s||s.payload.id!==n)return e;let p=be(s,n,i,r);return p===s?e:{...e,[t]:p}}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 c,jsxs as y}from"react/jsx-runtime";var we="客户端未装配模块——经 tbox-app dev --module <模块> 装配后可见",Te="服务端未注册卡片(模块未装配或全部被禁用)",he="鉴权失败:dev 环境依赖 dev-login(浏览器态自动登录);生产构建(NODE_ENV=production)预览面不挂载",re=e=>`卡片目录拉取失败(HTTP ${e})`,Ce="tbox 卡片预览",Se="isHistory 视角",Pe="全部模块";function oe(e,t,n){let i=Math.max(0,e.samples.findIndex(s=>s.label===t)),r=e.samples[i];return r?{card:e,sample:r,payload:Z(e,r,n??i)}:null}function Ze(e){let{registry:t,authClient:n}=e,i=Object.keys(t).length===0,[r,s]=R(null),[p,x]=R(null),[g,f]=R("all"),[a,v]=R(!1),[h,C]=R({}),[k,N]=R([]),F=P(null),E=P(new Set),w=P(h);w.current=h;let V=P(r);V.current=r;let ae=P(0),se=P(0),_=te(()=>{try{let o=window.location.search,u=new URLSearchParams(o);return{module:u.get("module")??void 0,card:u.get("card")??void 0,sample:u.get("sample")??void 0,history:q(o),controls:K(o)}}catch{return{}}},[]),ce=_.controls!==!1,m=L(o=>{let u=++ae.current;N(l=>[...l,{id:u,text:o}]),setTimeout(()=>N(l=>l.filter(d=>d.id!==u)),3200)},[]);xe(()=>{let o=!1,u=j((l,d,T)=>{$.current(l,d,T)});return(async()=>{try{let l=await n.ensureAuth();F.current=l.token;let d=await fetch("/_tbox/api/cards",{headers:l.token?{Authorization:`Bearer ${l.token}`}:{}});if(o)return;if(d.status===401||d.status===403){x(he);return}if(!d.ok){x(re(d.status));return}let T=await d.json();if(o)return;s(T);let A=U(T,_);f(A.moduleId);let I=Ae(T.cards,A.cardType,A.sampleLabel);w.current=I,C(I),v(_.history===!0)}catch(l){o||x(`卡片目录拉取失败:${l.message}`)}})(),()=>{o=!0,u()}},[]);let H=L((o,u,l)=>{let d=ee(u);if(d.type==="openLink"){window.open(d.url,"_blank");return}if(d.type==="sendMessage"){m(Y(d.value));return}if(d.type==="submitFormUnsupported"){m(J);return}if(d.type==="ignored")return;let T=Object.entries(w.current).find(([,S])=>S.payload.id===o),A=T?.[1];if(!T||!A||u.type!=="moduleAction"||E.current.has(o))return;E.current.add(o);let I=F.current;fetch("/_tbox/api/card-action",{method:"POST",headers:{"Content-Type":"application/json",...I?{Authorization:`Bearer ${I}`}:{}},body:JSON.stringify({cardType:A.card.cardType,actionId:u.actionId,surfaceId:o,...l!==void 0?{input:l}:{}})}).then(async S=>{let b=await S.json().catch(()=>null);if(!S.ok||!b||b.ok===!1){m(b?.error??re(S.status));return}let pe=b,D=w.current,O=Q(D,T[0],o,pe,ue=>V.current?.cards.find(ye=>ye.cardType===ue));O!==D&&(w.current=O,C(O)),typeof b.text=="string"&&b.text&&m(b.text),Array.isArray(b.effects)&&b.effects.length>0&&m(X(b.effects.length))}).catch(S=>m(`动作请求失败:${S.message}`)).finally(()=>E.current.delete(o))},[m]),$=P(H);$.current=H;let M=te(()=>r?U(r,{module:g==="all"?void 0:g}):null,[r,g]),de=L((o,u)=>{let l=w.current[o];if(!l)return;let d=oe(l.card,u,l.card.samples.length+ ++se.current);d&&(w.current={...w.current,[o]:d},C(w.current))},[]),le=L(o=>{if(typeof navigator>"u"||!navigator.clipboard?.writeText){m("当前浏览器不支持复制");return}navigator.clipboard.writeText(o).then(()=>m(`已复制卡型 ID:${o}`)).catch(()=>m("复制失败,请手动复制"))},[m]);return y("div",{style:{minHeight:"100vh",background:"#f5f5f5",fontFamily:'-apple-system, "PingFang SC", sans-serif'},children:[ce&&y("header",{style:Ie,children:[c("strong",{style:{fontSize:14,color:"#262626"},children:Ce}),y("select",{"aria-label":"模块",style:Le,value:g,onChange:o=>f(o.target.value),children:[c("option",{value:"all",children:Pe}),(M?.modules??[]).map(o=>c("option",{value:o,children:o},o))]}),c("button",{type:"button",style:a?Ee:ie,onClick:()=>v(o=>!o),children:Se})]}),y("main",{style:{maxWidth:1200,margin:"0 auto",padding:"12px 12px 48px"},children:[p&&c("div",{style:We,children:p}),!p&&!r&&c("div",{style:B,children:"加载中…"}),r&&i&&c("div",{style:B,children:we}),r&&!i&&r.cards.length===0&&c("div",{style:B,children:Te}),r&&!i&&M&&c(Re,{cards:M.candidateCards,rows:h,registry:t,historyView:a,onSelectSample:de,onCopyCardType:le,onAction:H})]}),c("div",{style:{position:"fixed",right:16,bottom:24,display:"flex",flexDirection:"column",gap:8,zIndex:20},children:k.map(o=>c("div",{style:Ge,children:o.text},o.id))})]})}function Ae(e,t,n){let i={};for(let r of e){let s=oe(r,r.cardType===t?n:void 0);s&&(i[r.cardType]=s)}return i}function Re(e){let{cards:t,rows:n,registry:i,historyView:r,onSelectSample:s,onCopyCardType:p,onAction:x}=e;return c("div",{style:He,children:t.map(g=>{let f=n[g.cardType];return f?c(ke,{instance:f,registry:i,historyView:r,samples:f.card.samples,activeSampleLabel:f.sample.label,onSelectSample:a=>s(g.cardType,a),onCopyCardType:p,onAction:x},g.cardType):null})})}function ke(e){let{instance:t,registry:n,historyView:i,samples:r,activeSampleLabel:s,onSelectSample:p,onCopyCardType:x,onAction:g}=e,f=i?{...t.payload,isHistory:!0}:t.payload,a=Math.max(0,r.findIndex(k=>k.label===s)),v=r[a]??t.sample,h=r[a-1],C=r[a+1];return y("section",{style:_e,children:[y("header",{style:{marginBottom:8},children:[c("div",{style:{fontSize:14,fontWeight:600,color:"#262626",lineHeight:"22px"},children:t.card.displayName}),y("div",{style:Me,children:[y("span",{style:Oe,title:t.card.cardType,children:["卡片id:",t.card.cardType]}),c("button",{type:"button","aria-label":`复制卡型 ID:${t.card.cardType}`,title:"复制卡型 ID",style:ze,onClick:()=>x(t.card.cardType),children:y("span",{"aria-hidden":"true",style:Ue,children:[c("span",{style:Be}),c("span",{style:Ne})]})})]})]}),r.length>0&&y("div",{style:Ve,children:[y("div",{style:je,title:v.label,"aria-live":"polite",children:[v.issues?.length||v.envelopeError?"⚠ ":"",v.label]}),y("div",{style:$e,children:[c("button",{type:"button","aria-label":"上一个样本",title:"上一个样本",disabled:!h,onClick:()=>h&&p(h.label),style:ne(!h),children:"‹"}),y("span",{style:De,children:[a+1," / ",r.length]}),c("button",{type:"button","aria-label":"下一个样本",title:"下一个样本",disabled:!C,onClick:()=>C&&p(C.label),style:ne(!C),children:"›"})]})]}),(t.sample.issues?.length||t.sample.envelopeError)&&y("div",{style:Fe,children:[t.sample.issues?.length?`样本问题:${t.sample.issues.join(";")}`:null,t.sample.envelopeError&&t.sample.issues?.length?";":"",t.sample.envelopeError??""]}),c(ve,{card:f,registry:n,onAction:k=>g(f.id,k)})]})}var Ie={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"},Ee={...ie,borderColor:"#1677ff",color:"#1677ff"},_e={background:"#fff",borderRadius:8,padding:14,boxShadow:"0 1px 4px rgba(0,0,0,0.06)"},He={display:"flex",flexDirection:"column",gap:12},Me={display:"flex",alignItems:"center",justifyContent:"space-between",gap:"var(--spacing.4, 4px)",minHeight:20,color:"var(--color.text.tertiary, #8c8c8c)",fontSize:11,lineHeight:"16px"},Oe={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"},Ue={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"},Ne={position:"absolute",right:1,bottom:1,width:8,height:8,border:"1px solid currentColor",borderRadius:2,background:"#fff",boxSizing:"border-box"},Fe={fontSize:12,lineHeight:"18px",padding:"4px 10px",borderRadius:8,background:"rgba(250,140,22,0.10)",color:"#d46b08",marginBottom:8},Ve={display:"flex",alignItems:"center",justifyContent:"space-between",gap:"var(--spacing.12, 12px)",minHeight:24,marginBottom:10},$e={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"}),De={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"},je={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"},B={padding:"12px 14px",borderRadius:8,background:"#fff",color:"#8c8c8c",fontSize:13,lineHeight:"20px",textAlign:"center"},Ge={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,Ze as CardPreviewPage,Te as EMPTY_CATALOG_MSG,we as EMPTY_REGISTRY_MSG,Se as HISTORY_VIEW_LABEL,re as LOAD_ERROR_MSG,Pe as MODULE_ALL_LABEL,Ce as PAGE_TITLE,Re as PreviewRows,ke as PreviewSurface,Ae 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.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.0",
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.0",
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"