@tbox.cn/app-agent-sdk-client 0.1.6 → 0.2.0
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.
|
@@ -7,7 +7,7 @@ interface AuthState {
|
|
|
7
7
|
identity: AuthIdentity;
|
|
8
8
|
}
|
|
9
9
|
interface AuthClientOptions {
|
|
10
|
-
/**
|
|
10
|
+
/** 登录平台(壳内换码目标 platform,如 weapp 等换码器注册表候选键);缺省 'alipay' */
|
|
11
11
|
loginPlatform?: string;
|
|
12
12
|
/**
|
|
13
13
|
* token 缓存域键(域中性):返回值变更即失效缓存 token 并重登(如 mall 部署 () => query.mallId ?? '')。
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { TboxCardPayload, CardComponent, UiAction } from '@tbox.cn/app-contracts';
|
|
2
|
-
import { A as AuthClient } from '../auth-client-
|
|
2
|
+
import { A as AuthClient } from '../auth-client-BzOwQV_4.js';
|
|
3
3
|
import { TboxCardPreviewCard, TboxCardPreviewSample, TboxCardPreviewCatalog } from '@tbox.cn/app-sdk-core';
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -15,7 +15,7 @@ interface PreviewInstanceState {
|
|
|
15
15
|
payload: TboxCardPayload;
|
|
16
16
|
}
|
|
17
17
|
|
|
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";
|
|
18
|
+
declare const EMPTY_REGISTRY_MSG = "\u5BA2\u6237\u7AEF\u672A\u88C5\u914D\u6A21\u5757\u2014\u2014\u7ECF tbox-app-dev 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
20
|
declare const EMPTY_MODULE_MSG: (moduleId: string) => string;
|
|
21
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";
|
|
@@ -40,6 +40,7 @@ declare function PreviewRows(props: {
|
|
|
40
40
|
/** 每个卡型的一行:标题/样本切换/质量信息 + 单个 CardRenderer。 */
|
|
41
41
|
declare function PreviewSurface(props: {
|
|
42
42
|
instance: PreviewInstanceState;
|
|
43
|
+
isLast?: boolean;
|
|
43
44
|
registry: Record<string, CardComponent>;
|
|
44
45
|
historyView: boolean;
|
|
45
46
|
samples: TboxCardPreviewCatalog['cards'][number]['samples'];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{G as j}from"../chunk-FA7CKDRJ.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};
|
|
1
|
+
import{G as j}from"../chunk-FA7CKDRJ.js";import{useCallback as U,useEffect as ve,useId as re,useMemo as ie,useRef as k,useState as C}from"react";import{CaretDown as we,CaretLeft as Se,CaretRight as Te,Copy as he}from"@phosphor-icons/react";import{CardRenderer as Ce}from"@tbox.cn/app-sdk-client";var fe="preview",q="表单提交需引擎运行,预览不支持",K=e=>`预览:已发送「${e}」`,Z=e=>`宿主效果 ×${e}(预览不执行)`;function Q(e){return new URLSearchParams(e).get("history")==="true"}function ee(e){return new URLSearchParams(e).get("controls")!=="false"}var J="(未声明)";function me(e){return[...new Set(e)].sort((t,o)=>t===o?0:t===J?1:o===J?-1:t.localeCompare(o))}function G(e,t={}){let o=me(e.cards.map(d=>d.moduleId)),l=t.module!==void 0&&t.module!=="all"&&!o.includes(t.module)?[...o,t.module]:o,n=t.module??"all",i=[...n==="all"?e.cards:e.cards.filter(d=>d.moduleId===n)].sort((d,S)=>{let b=d.order??Number.POSITIVE_INFINITY,T=S.order??Number.POSITIVE_INFINITY;return b!==T?b-T:d.cardType.localeCompare(S.cardType)}),v=i.map(d=>d.cardType),g=i.find(d=>d.cardType===t.card)??i[0],w=g?.cardType??"",m=g?.samples??[],P=t.sample!==void 0&&m.some(d=>d.label===t.sample)?t.sample:"初始态";return{modules:l,moduleId:n,cardTypes:v,candidateCards:i,cardType:w,selectedCard:g,samples:m,sampleLabel:P}}function be(e,t){return`preview-${e.replace(/[^a-zA-Z0-9_-]/g,"_")}-${t}`}function X(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 $(e,t){let o={};if(!t.noTokens)for(let l of e.actions)(!l.kind||l.kind==="moduleAction")&&(o[l.actionId]=fe);return{id:t.id,cardType:e.cardType,data:t.data,status:"ready",...e.actions.length?{actions:e.actions}:{},...Object.keys(o).length?{actionTokens:o}:{},...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 te(e,t,o){return $(e,{id:be(e.cardType,o),data:t.data,isHistory:!!t.isHistory,noTokens:!!t.noTokens,...t.envelope??{}})}function xe(e,t,o,l){if(o.ok!==!0||e.payload.id!==t||!o.card)return e;if(o.kind==="card"){let n=l(o.card.cardType),i=n?.samples[0];return!n||!i?e:{card:n,sample:i,payload:$(n,{id:o.card.id,data:o.card.data,isHistory:!1,noTokens:!1,...X(o.card)})}}return o.kind!=="update"?e:{...e,payload:$(e.card,{id:t,data:o.card.data,isHistory:!!e.sample.isHistory,noTokens:!!e.sample.noTokens,...X(o.card)})}}function oe(e,t,o,l,n){let i=e[t];if(!i||i.payload.id!==o)return e;let v=xe(i,o,l,n);return v===i?e:{...e,[t]:v}}function ne(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{Fragment as nt,jsx as s,jsxs as u}from"react/jsx-runtime";var Pe="客户端未装配模块——经 tbox-app-dev dev --module <模块> 装配后可见",Ae="服务端未注册卡片(模块未装配或全部被禁用)",Ie=e=>`模块「${e}」暂无示例卡片`,Re="鉴权失败:dev 环境依赖 dev-login(浏览器态自动登录);生产构建(NODE_ENV=production)预览面不挂载",ae=e=>`卡片目录拉取失败(HTTP ${e})`,ke="tbox 卡片预览",Le="isHistory 视角",Ee="全部模块";function le(e,t,o){let l=Math.max(0,e.samples.findIndex(i=>i.label===t)),n=e.samples[l];return n?{card:e,sample:n,payload:te(e,n,o??l)}:null}function ct(e){let{registry:t,authClient:o}=e,l=Object.keys(t).length===0,[n,i]=C(null),[v,g]=C(null),[w,m]=C("all"),[P,d]=C(!1),[S,b]=C({}),[T,H]=C([]),O=k(null),I=k(new Set),x=k(S);x.current=S;let F=k(n);F.current=n;let B=k(0),D=k(0),L=ie(()=>{try{let r=window.location.search,f=new URLSearchParams(r);return{module:f.get("module")??void 0,card:f.get("card")??void 0,sample:f.get("sample")??void 0,history:Q(r),controls:ee(r)}}catch{return{}}},[]),V=L.controls!==!1,y=U(r=>{let f=++B.current;H(p=>[...p,{id:f,text:r}]),setTimeout(()=>H(p=>p.filter(c=>c.id!==f)),3200)},[]);ve(()=>{let r=!1,f=j((p,c,A)=>{a.current(p,c,A)});return(async()=>{try{let p=await o.ensureAuth();O.current=p.token;let c=await fetch("/_tbox/api/cards",{headers:p.token?{Authorization:`Bearer ${p.token}`}:{}});if(r)return;if(c.status===401||c.status===403){g(Re);return}if(!c.ok){g(ae(c.status));return}let A=await c.json();if(r)return;i(A);let _=G(A,L);m(_.moduleId);let z=Me(A.cards,_.cardType,_.sampleLabel);x.current=z,b(z),d(L.history===!0)}catch(p){r||g(`卡片目录拉取失败:${p.message}`)}})(),()=>{r=!0,f()}},[]);let E=U((r,f,p)=>{let c=ne(f);if(c.type==="openLink"){window.open(c.url,"_blank");return}if(c.type==="sendMessage"){y(K(c.value));return}if(c.type==="submitFormUnsupported"){y(q);return}if(c.type==="ignored")return;let A=Object.entries(x.current).find(([,R])=>R.payload.id===r),_=A?.[1];if(!A||!_||f.type!=="moduleAction"||I.current.has(r))return;I.current.add(r);let z=O.current;fetch("/_tbox/api/card-action",{method:"POST",headers:{"Content-Type":"application/json",...z?{Authorization:`Bearer ${z}`}:{}},body:JSON.stringify({cardType:_.card.cardType,actionId:f.actionId,surfaceId:r,...p!==void 0?{input:p}:{}})}).then(async R=>{let h=await R.json().catch(()=>null);if(!R.ok||!h||h.ok===!1){y(h?.error??ae(R.status));return}let ue=h,Y=x.current,W=oe(Y,A[0],r,ue,ge=>F.current?.cards.find(ye=>ye.cardType===ge));W!==Y&&(x.current=W,b(W)),typeof h.text=="string"&&h.text&&y(h.text),Array.isArray(h.effects)&&h.effects.length>0&&y(Z(h.effects.length))}).catch(R=>y(`动作请求失败:${R.message}`)).finally(()=>I.current.delete(r))},[y]),a=k(E);a.current=E;let M=ie(()=>n?G(n,{module:w==="all"?void 0:w}):null,[n,w]),ce=U((r,f)=>{let p=x.current[r];if(!p)return;let c=le(p.card,f,p.card.samples.length+ ++D.current);c&&(x.current={...x.current,[r]:c},b(x.current))},[]),pe=U(r=>{if(typeof navigator>"u"||!navigator.clipboard?.writeText){y("当前浏览器不支持复制");return}navigator.clipboard.writeText(r).then(()=>y(`已复制卡片 ID:${r}`)).catch(()=>y("复制失败,请手动复制"))},[y]);return u("div",{style:{minHeight:"100vh",background:"#f5f5f5",fontFamily:'-apple-system, "PingFang SC", sans-serif'},children:[V&&u("header",{style:Oe,children:[s("strong",{style:{fontSize:14,color:"#262626"},children:ke}),u("select",{"aria-label":"模块",style:ze,value:w,onChange:r=>m(r.target.value),children:[s("option",{value:"all",children:Ee}),(M?.modules??[]).map(r=>s("option",{value:r,children:r},r))]}),s("button",{type:"button",style:P?Fe:de,onClick:()=>d(r=>!r),children:Le})]}),u("main",{style:{maxWidth:1200,margin:"0 auto",padding:"12px 12px 48px"},children:[v&&s("div",{style:tt,children:v}),!v&&!n&&s("div",{style:N,children:"加载中…"}),n&&l&&s("div",{style:N,children:Pe}),n&&!l&&n.cards.length===0&&s("div",{style:N,children:Ae}),n&&!l&&n.cards.length>0&&M&&M.candidateCards.length===0&&s("div",{style:N,children:Ie(M.moduleId)}),n&&!l&&M&&s(_e,{cards:M.candidateCards,rows:S,registry:t,historyView:P,onSelectSample:ce,onCopyCardType:pe,onAction:E})]}),s("div",{style:{position:"fixed",right:16,bottom:24,display:"flex",flexDirection:"column",gap:8,zIndex:20},children:T.map(r=>s("div",{style:ot,children:r.text},r.id))})]})}function Me(e,t,o){let l={};for(let n of e){let i=le(n,n.cardType===t?o:void 0);i&&(l[n.cardType]=i)}return l}function _e(e){let{cards:t,rows:o,registry:l,historyView:n,onSelectSample:i,onCopyCardType:v,onAction:g}=e,w=t.filter(m=>o[m.cardType]);return s("div",{style:Ne,children:w.map((m,P)=>{let d=o[m.cardType];return s(He,{instance:d,isLast:P===w.length-1,registry:l,historyView:n,samples:d.card.samples,activeSampleLabel:d.sample.label,onSelectSample:S=>i(m.cardType,S),onCopyCardType:v,onAction:g},m.cardType)})})}function He(e){let{instance:t,isLast:o,registry:l,historyView:n,samples:i,activeSampleLabel:v,onSelectSample:g,onCopyCardType:w,onAction:m}=e,P=n?{...t.payload,isHistory:!0}:t.payload,d=Math.max(0,i.findIndex(a=>a.label===v)),S=i[d]??t.sample,b=i[d-1],T=i[d+1],H=re(),O=re(),[I,x]=C(null),[F,B]=C(!1),[D,L]=C(!1),[V,y]=C(!1),E=a=>{x(a.getBoundingClientRect().top<80?"bottom":"top")};return u("section",{style:o?Ue:Be,children:[u("header",{style:De,children:[s("div",{style:Ve,children:t.card.displayName}),u("span",{style:We,children:[u("button",{type:"button","aria-label":`复制卡片 ID:${t.card.cardType}`,"aria-describedby":I?H:void 0,style:$e,onMouseEnter:a=>E(a.currentTarget),onMouseLeave:()=>x(null),onFocus:a=>E(a.currentTarget),onBlur:()=>x(null),onClick:()=>w(t.card.cardType),children:[s(he,{size:14,"aria-hidden":"true"}),"复制卡片 ID"]}),I&&u("span",{id:H,role:"tooltip",style:Ge(I),children:[s("span",{style:{display:"block"},children:"复制卡片 ID"}),s("span",{style:{display:"block"},children:"用于定位卡片配置和代码"}),s("span",{style:Ye(I)})]})]})]}),i.length>0&&u("div",{style:Je,children:[u("label",{htmlFor:O,style:Xe,children:["展示状态(",u("span",{"aria-live":"polite",children:[d+1,"/",i.length]}),"):"]}),u("span",{style:qe(F),children:[s("span",{style:Ke,children:S.label}),s(we,{size:12,"aria-hidden":"true",style:Qe}),s("select",{id:O,style:Ze,value:S.label,onChange:a=>g(a.target.value),onFocus:()=>B(!0),onBlur:()=>B(!1),children:i.map(a=>u("option",{value:a.label,children:[a.issues?.length||a.envelopeError?"⚠ ":"",a.label]},a.label))})]})]}),(t.sample.issues?.length||t.sample.envelopeError)&&u("div",{style:je,children:[t.sample.issues?.length?`样本问题:${t.sample.issues.join(";")}`:null,t.sample.envelopeError&&t.sample.issues?.length?";":"",t.sample.envelopeError??""]}),u("div",{role:"group","aria-label":`${t.card.displayName}卡片预览`,tabIndex:0,style:et,onMouseEnter:()=>L(!0),onMouseLeave:()=>L(!1),onFocusCapture:()=>y(!0),onBlurCapture:a=>{a.currentTarget.contains(a.relatedTarget)||y(!1)},onKeyDown:a=>{a.target===a.currentTarget&&(a.key==="ArrowLeft"&&b?(a.preventDefault(),g(b.label)):a.key==="ArrowRight"&&T&&(a.preventDefault(),g(T.label)))},children:[s(Ce,{card:P,registry:l,onAction:a=>m(P.id,a)}),(D||V)&&i.length>1&&u(nt,{children:[s("button",{type:"button","aria-label":"卡片区域:上一个样本",title:"上一个样本",disabled:!b,onClick:()=>b&&g(b.label),style:se("left",!b),children:s(Se,{size:18,"aria-hidden":"true"})}),s("button",{type:"button","aria-label":"卡片区域:下一个样本",title:"下一个样本",disabled:!T,onClick:()=>T&&g(T.label),style:se("right",!T),children:s(Te,{size:18,"aria-hidden":"true"})})]})]})]})}var Oe={position:"sticky",top:0,zIndex:10,display:"flex",flexWrap:"wrap",alignItems:"center",gap:8,padding:"10px 16px",background:"#fff",borderBottom:"1px solid #e8e8e8"},ze={fontSize:13,padding:"4px 8px",borderRadius:8,border:"1px solid #d9d9d9",background:"#fff",color:"#262626"},de={fontSize:13,padding:"4px 12px",borderRadius:18,border:"1px solid #d9d9d9",background:"#fff",color:"#262626",cursor:"pointer"},Fe={...de,borderColor:"#1677ff",color:"#1677ff"},Be={minWidth:0,paddingBottom:16,borderBottom:"1px solid #e8e8e8"},Ue={minWidth:0},Ne={display:"flex",flexDirection:"column",gap:16},De={display:"flex",alignItems:"center",justifyContent:"space-between",gap:8,marginBottom:8},Ve={flex:"1 1 auto",minWidth:0,color:"#262626",fontSize:14,fontWeight:600,lineHeight:"22px"},We={position:"relative",display:"inline-flex",flex:"0 0 auto"},$e={display:"inline-flex",alignItems:"center",gap:4,flex:"0 0 auto",minHeight:28,padding:"4px 0",border:0,background:"transparent",color:"#222dd9",fontSize:12,lineHeight:"20px",whiteSpace:"nowrap",cursor:"pointer"},Ge=e=>({position:"absolute",right:0,...e==="top"?{bottom:"calc(100% + 8px)"}:{top:"calc(100% + 8px)"},zIndex:10,width:184,maxWidth:"calc(100vw - 24px)",padding:"6px 8px",borderRadius:4,background:"#303030",boxShadow:"0 3px 8px rgba(0, 0, 0, 0.18)",color:"#fff",fontSize:12,fontWeight:400,lineHeight:"18px",textAlign:"left",whiteSpace:"normal",pointerEvents:"none"}),Ye=e=>({position:"absolute",right:36,...e==="top"?{bottom:-4}:{top:-4},width:8,height:8,background:"#303030",transform:"rotate(45deg)"}),je={fontSize:12,lineHeight:"18px",padding:"4px 10px",borderRadius:8,background:"rgba(250,140,22,0.10)",color:"#d46b08",marginBottom:8},Je={display:"flex",alignItems:"center",gap:6,minHeight:28,marginBottom:10},Xe={flex:"0 0 auto",color:"#595959",fontSize:12,lineHeight:"20px"},qe=e=>({position:"relative",display:"inline-flex",alignItems:"center",gap:4,flex:"0 1 auto",minWidth:0,color:"#262626",fontSize:12,lineHeight:"20px",borderRadius:2,outline:e?"2px solid #222dd9":"none",outlineOffset:2}),Ke={overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},Ze={position:"absolute",inset:0,width:"100%",height:"100%",padding:0,border:0,appearance:"none",opacity:0,cursor:"pointer"},Qe={flex:"0 0 auto",color:"#8c8c8c",pointerEvents:"none"},et={position:"relative",minWidth:0},se=(e,t)=>({position:"absolute",top:"50%",[e]:8,zIndex:2,display:"grid",placeItems:"center",width:36,height:36,padding:0,border:"1px solid #e5e5e5",borderRadius:"50%",background:"#fff",boxShadow:"0 2px 8px rgba(0, 0, 0, 0.16)",color:t?"#bfbfbf":"#262626",transform:"translateY(-50%)",cursor:t?"not-allowed":"pointer"}),tt={padding:"12px 14px",borderRadius:8,background:"rgba(255,77,79,0.08)",color:"#ff4d4f",fontSize:13,lineHeight:"20px"},N={padding:"12px 14px",borderRadius:8,background:"#fff",color:"#8c8c8c",fontSize:13,lineHeight:"20px",textAlign:"center"},ot={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{Re as AUTH_ERROR_MSG,ct as CardPreviewPage,Ae as EMPTY_CATALOG_MSG,Ie as EMPTY_MODULE_MSG,Pe as EMPTY_REGISTRY_MSG,Le as HISTORY_VIEW_LABEL,ae as LOAD_ERROR_MSG,Ee as MODULE_ALL_LABEL,ke as PAGE_TITLE,_e as PreviewRows,He as PreviewSurface,Me as buildPreviewRows};
|
package/dist/client/index.d.ts
CHANGED
|
@@ -3,8 +3,8 @@ export { InferModuleCards } from '@tbox.cn/app-sdk-core';
|
|
|
3
3
|
import { TboxSessionData, HostEffect, Adapters, IASRAdapter, IFeedbackAdapter, ITTSAdapter, IUploadAdapter, HelloAckChatConfig, TboxCardPayload, UiAction, CardSnapshot, SkillRecord, PreToolRecord, HostEffectResult, UploadProgressCallback, UploadOptions, UploadResult } from '@tbox.cn/app-contracts';
|
|
4
4
|
export { Adapters, ChatUiSettings, IASRAdapter, IFeedbackAdapter, ITTSAdapter, IUploadAdapter, UploadOptions, UploadProgressCallback, UploadResult } from '@tbox.cn/app-contracts';
|
|
5
5
|
import { UseBoundStore, StoreApi } from 'zustand';
|
|
6
|
-
import { A as AuthClient } from '../auth-client-
|
|
7
|
-
export { a as AuthClientOptions, b as AuthIdentity, c as AuthState, d as createAuthClient, g as getAuthClient } from '../auth-client-
|
|
6
|
+
import { A as AuthClient } from '../auth-client-BzOwQV_4.js';
|
|
7
|
+
export { a as AuthClientOptions, b as AuthIdentity, c as AuthState, d as createAuthClient, g as getAuthClient } from '../auth-client-BzOwQV_4.js';
|
|
8
8
|
import * as react from 'react';
|
|
9
9
|
|
|
10
10
|
/** 媒体 / 消息类型(SDK 核心 chat 协议类型) */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tbox.cn/app-agent-sdk-client",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
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": {
|
|
@@ -33,7 +33,8 @@
|
|
|
33
33
|
"access": "public"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@
|
|
36
|
+
"@phosphor-icons/react": "2.1.10",
|
|
37
|
+
"@tbox.cn/app-contracts": "0.13.1",
|
|
37
38
|
"@tbox.cn/app-sdk-client": "0.21.3",
|
|
38
39
|
"@tbox.cn/app-sdk-core": "0.20.4",
|
|
39
40
|
"react": "18.3.1",
|