dsh-vod-devkit 0.4.3 → 0.5.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.
package/lib/client.js CHANGED
@@ -3,7 +3,7 @@ window.__ModuleLoader__.load({
3
3
  factory: (require) => {
4
4
  var module = { exports: {} };
5
5
  var exports = module.exports;
6
- var B=Object.create;var v=Object.defineProperty;var M=Object.getOwnPropertyDescriptor;var U=Object.getOwnPropertyNames;var V=Object.getPrototypeOf,j=Object.prototype.hasOwnProperty;var H=(t,e)=>{for(var n in e)v(t,n,{get:e[n],enumerable:!0})},D=(t,e,n,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of U(e))!j.call(t,o)&&o!==n&&v(t,o,{get:()=>e[o],enumerable:!(r=M(e,o))||r.enumerable});return t};var N=(t,e,n)=>(n=t!=null?B(V(t)):{},D(e||!t||!t.__esModule?v(n,"default",{value:t,enumerable:!0}):n,t)),J=t=>D(v({},"__esModule",{value:!0}),t);var nt={};H(nt,{apply:()=>rt,inject:()=>et,name:()=>ot});module.exports=J(nt);var s=require("react/jsx-runtime"),d=N(require("react"),1);const w="/rest/developer/manager/hdvodmngservice/v1";let m=typeof globalThis<"u"&&globalThis.__VOD_DSH_UI_BASE__||"";const F=`${w}/external/token`,E=`${w}/external/voices`,K=`${w}/external/meta`,S="vod_dshui_token",O="vod_dshui_device",h="vod_dshui_ledger",_="vod_dshui_draft",I="vod_dshui_recovered",T=200,G=typeof globalThis<"u"&&globalThis.__VOD_DSH_UI_LEDGER_DISABLED__===!0,x=typeof globalThis<"u"&&globalThis.__VOD_DSH_UI_PRODUCT__||"",R={textarea:{width:"100%",boxSizing:"border-box",minHeight:96,borderRadius:"var(--dsw-radius-sm, 8px)",border:"1px solid var(--dsw-alias-border-l3, #ccc)",padding:"8px 10px",fontSize:13,resize:"none",background:"var(--dsw-alias-bg-layer-1, transparent)",color:"var(--dsw-alias-label-primary, #111)",outline:"none"},input:{width:"100%",boxSizing:"border-box",borderRadius:"var(--dsw-radius-sm, 8px)",border:"1px solid var(--dsw-alias-border-l3, #ccc)",padding:"7px 10px",fontSize:13,background:"var(--dsw-alias-bg-layer-1, transparent)",color:"var(--dsw-alias-label-primary, #111)",outline:"none"},hint:{fontSize:12,color:"var(--dsw-alias-label-caption, #999)",marginBottom:12},label:{fontSize:12,color:"var(--dsw-alias-label-secondary, #666)",margin:"10px 0 6px"},result:{fontSize:12,marginBottom:12,padding:"8px 10px",borderRadius:"var(--dsw-radius-sm, 8px)",background:"var(--dsw-alias-interactive-bg-hover, rgba(0,0,0,.05))",color:"var(--dsw-alias-label-primary, #111)"}};function b(){let t=localStorage.getItem(O);return t||(t=(crypto.randomUUID?crypto.randomUUID():Date.now().toString(16)+Math.random().toString(16).slice(2)+Math.random().toString(16).slice(2)).replace(/[^0-9a-f]/g,"").slice(0,32),localStorage.setItem(O,t)),t}async function A(t){if(typeof crypto<"u"&&crypto.subtle){const e=await crypto.subtle.digest("SHA-1",new TextEncoder().encode(t));return[...new Uint8Array(e)].map(n=>n.toString(16).padStart(2,"0")).join("")}return W(t)}function W(t){let r=2166136261,o=3752705916;for(let l=0;l<t.length;l++){const i=t.charCodeAt(l);r^=i,r=Math.imul(r,16777619)>>>0,o^=i<<3&65535,o=Math.imul(o,2246822507)>>>0}return r.toString(16).padStart(8,"0")+o.toString(16).padStart(8,"0")}async function X(t){return`ext_dshui_${(await A(b())).slice(0,8)}_${(await A(t)).slice(0,12)}`}function k(t){if(G)return;const e=JSON.parse(localStorage.getItem(h)||"[]");e.unshift(t),localStorage.setItem(h,JSON.stringify(e.slice(0,T)))}async function C(){let t=localStorage.getItem(S);if(t)return t;const e=await fetch(m+F,{method:"POST",headers:{"content-type":"application/json","X-Vod-Device-Id":b()},body:"{}"});if(e.status!==200&&e.status!==201)throw new Error(`token ${e.status}`);const n=await e.json().catch(()=>({}));if(t=typeof n=="string"?n:n.token||n.data?.token||"",!t)throw new Error("token empty");return localStorage.setItem(S,t),t}function q({title:t,onClose:e,children:n,footer:r}){return(0,d.useEffect)(()=>{const o=l=>l.key==="Escape"&&e();return window.addEventListener("keydown",o),()=>window.removeEventListener("keydown",o)},[e]),(0,s.jsx)("div",{style:{position:"fixed",inset:0,zIndex:9e3,background:"rgba(0,0,0,.35)",display:"flex",alignItems:"center",justifyContent:"center"},onMouseDown:o=>o.target===o.currentTarget&&e(),children:(0,s.jsxs)("div",{role:"dialog","aria-label":t,style:{width:"min(488px, 92vw)",borderRadius:"var(--dsw-radius-panel, 12px)",background:"var(--dsw-alias-bg-layer-1, #fff)",color:"var(--dsw-alias-label-primary, #111)",padding:"18px 20px",fontFamily:"inherit",boxShadow:"0 8px 40px rgba(0,0,0,.2)"},children:[(0,s.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:12},children:[(0,s.jsx)("div",{style:{fontSize:15,fontWeight:600},children:t}),(0,s.jsx)("button",{onClick:e,"aria-label":"\u5173\u95ED",style:{border:"none",background:"transparent",cursor:"pointer",fontSize:16,lineHeight:1,padding:4,borderRadius:6,color:"var(--dsw-alias-label-tertiary, #888)"},children:"\u2715"})]}),n,r&&(0,s.jsx)("div",{style:{marginTop:14},children:r})]})})}function Q({disabled:t,onClick:e,children:n}){return(0,s.jsx)("button",{disabled:t,onClick:e,style:{width:"100%",height:44,fontSize:14,fontWeight:500,border:"none",cursor:t?"not-allowed":"pointer",borderRadius:"var(--dsw-radius-lg, 10px)",background:t?"var(--dsw-alias-interactive-bg-hover, rgba(0,0,0,.06))":"var(--dsw-alias-button-primary-fill, #2563eb)",color:t?"var(--dsw-alias-label-tertiary, #999)":"var(--dsw-alias-label-primary-foreground, #fff)"},children:n})}let L=!1;async function Y(){if(L)return;L=!0;let t=0;const e=JSON.parse(localStorage.getItem(h)||"[]").filter(r=>r.status==="pending-endpoint"||r.status==="failed");for(const r of e.slice(0,5))try{const o=await C(),l=await fetch(m+E,{method:"POST",headers:{"content-type":"application/json","X-Vod-Device-Id":b(),authorization:`Bearer ${o}`},body:JSON.stringify({voices:[{title:r.title,content:r.content}],product:x})});if(l.status===200||l.status===201){r.status="accepted";try{localStorage.removeItem(_)}catch{}const i=await l.json().catch(()=>({}));r.serverVoiceId=(i.voiceIds||i.data?.voiceIds||[])[0]||"",r.retriedAt=new Date().toISOString(),t++}else l.status!==404&&(r.error=`retry ${l.status}`)}catch(o){r.error=String(o&&o.message||o)}const n=e.filter(r=>r.status!=="accepted");if(t>0){const r=e.filter(o=>o.status==="accepted"&&o.retriedAt).map(o=>`\u201C${(o.content||o.title||"").slice(0,60)}\u201D`).join("\u3001");try{localStorage.setItem(I,JSON.stringify({n:t,items:r}))}catch{}}if(n.length!==e.length||e.length){const r=JSON.parse(localStorage.getItem(h)||"[]"),o=new Map(e.map(i=>[i.voiceKey,i])),l=r.map(i=>o.get(i.voiceKey)||i);localStorage.setItem(h,JSON.stringify(l.slice(0,T)))}}function Z({onClose:t}){const e=(()=>{try{return JSON.parse(localStorage.getItem(_)||"null")||{}}catch{return{}}})(),[n,r]=(0,d.useState)(e.content||"");(0,d.useEffect)(()=>{try{localStorage.setItem(_,JSON.stringify({content:n}))}catch{}},[n]);const[o,l]=(0,d.useState)(!1),[i,g]=(0,d.useState)(null);(0,d.useEffect)(()=>{let a=null;try{a=JSON.parse(localStorage.getItem(I)||"null")}catch{}if(a&&a.n>0){try{localStorage.removeItem(I)}catch{}const c=a.items?`\uFF0C\u4EA7\u54C1\u56E2\u961F\u4F1A\u770B\u5230\uFF1A${a.items}`:"";g({ok:!0,msg:`\u4F60\u4E4B\u524D\u63D0\u4EA4\u7684 ${a.n} \u6761\u53CD\u9988\u5DF2\u81EA\u52A8\u91CD\u8BD5\u6210\u529F\uFF08\u5F53\u65F6\u63D0\u4EA4\u4E34\u65F6\u5931\u8D25\uFF09${c}`})}},[]);let y=null;async function z(a,c){if(/^\d+$/.test(a))return a;try{if(!y){const f=await fetch(m+K,{headers:{authorization:`Bearer ${c}`}});if(f.ok){const p=await f.json().catch(()=>({}));y=(p.data||p).productCatalog||[]}}const u=(y||[]).find(f=>String(f?.name||"").toLowerCase()===a.toLowerCase());if(u&&u.id!=null)return String(u.id)}catch{}return a}async function $(){const a=n.trim();if(!a){g({ok:!1,msg:"\u8BF7\u5148\u586B\u5199\u53CD\u9988\u5185\u5BB9"});return}if(a.length>2e3){g({ok:!1,msg:`\u5185\u5BB9\u8D85\u957F\uFF08${a.length}/2000\uFF09\uFF0C\u8BF7\u7CBE\u7B80`});return}l(!0),g(null);const c={title:a.slice(0,64),content:a,at:new Date().toISOString(),status:"failed",error:""};try{c.voiceKey=await X(a);try{const u=await C(),f=await fetch(m+E,{method:"POST",headers:{"content-type":"application/json","X-Vod-Device-Id":b(),authorization:`Bearer ${u}`},body:JSON.stringify({voices:[{title:a.slice(0,60),content:a}],product:await z(x,u)})});if(f.status===404){c.status="pending-endpoint",k(c),g({ok:!1,msg:"\u56E4\u79EF\u7AEF\u70B9\u5C1A\u672A\u4E0A\u7EBF\uFF08\u5F15\u64CE\u90E8\u7F72\u540E\u81EA\u52A8\u53EF\u7528\uFF09\uFF1B\u53CD\u9988\u5DF2\u6682\u5B58\u672C\u673A\uFF0C\u7A0D\u540E\u91CD\u8BD5\u63D0\u4EA4\u3002"});return}if(f.status===401&&localStorage.removeItem(S),f.status!==200&&f.status!==201)throw new Error(`submit ${f.status}`);const p=await f.json().catch(()=>({}));c.status="accepted",c.serverVoiceId=p.voiceIds?.[0]||"",c.taskId=p.taskIds?.[0]||"",k(c);const P=p.productRegistered===void 0?!0:p.productRegistered;g(P?{ok:!0,msg:"\u5DF2\u6536\u5F55\uFF0C\u4EA7\u54C1\u56E2\u961F\u4F1A\u770B\u5230\u8FD9\u6761\u53CD\u9988\u3002"}:{ok:!0,msg:"\u5DF2\u6536\u5F55\u3002\u6CE8\u610F\uFF1A\u4EA7\u54C1\u540D\u5C1A\u672A\u5728\u5E73\u53F0\u6CE8\u518C\uFF0C\u8FD9\u6761\u53CD\u9988\u6682\u4E0D\u8FDB\u4EA7\u54C1\u5206\u6790\uFF0C\u8BF7\u8054\u7CFB\u90E8\u7F72\u65B9\u6838\u5BF9\u3002"})}catch(u){c.error=String(u&&u.message||u),k(c),g({ok:!1,msg:`\u63D0\u4EA4\u5931\u8D25\uFF08${c.error}\uFF09\uFF1B\u53CD\u9988\u5DF2\u6682\u5B58\u672C\u673A\uFF0C\u7A0D\u540E\u91CD\u8BD5\u3002`})}}finally{l(!1)}}return(0,s.jsxs)(q,{title:"\u63D0\u4EA4\u53CD\u9988",onClose:t,footer:(0,s.jsx)(Q,{disabled:o||!n.trim(),onClick:$,children:o?"\u63D0\u4EA4\u4E2D\u2026":"\u63D0\u4EA4"}),children:[(0,s.jsx)("textarea",{id:"vod-fb-content",style:R.textarea,value:n,maxLength:2e3,placeholder:"\u6BD4\u5982\uFF1A\u5BF9\u8BDD\u54CD\u5E94\u6162\u3001\u67D0\u4E2A\u529F\u80FD\u627E\u4E0D\u5230\u5165\u53E3",autoFocus:!0,onChange:a=>r(a.target.value)}),i&&(0,s.jsx)("div",{style:R.result,children:i.msg})]})}function tt(){const[t,e]=(0,d.useState)(!1),n=(0,d.useRef)(null);return(0,d.useEffect)(()=>{Y();const r=()=>{const i=n.current;if(!i)return;const g=document.querySelector("[contenteditable=true][role=textbox], [contenteditable=true]");if(!g)return;const y=g.getBoundingClientRect();i.offsetWidth!==0&&(i.style.left="auto",i.style.right=Math.round(window.innerWidth-y.right+8)+"px",i.style.top=Math.round(y.top-30)+"px",i.style.height="24px")};r();const o=new ResizeObserver(r);o.observe(document.documentElement),window.addEventListener("resize",r);const l=setInterval(r,800);return()=>{o.disconnect(),window.removeEventListener("resize",r),clearInterval(l)}},[]),(0,s.jsxs)(d.default.Fragment,{children:[(0,s.jsxs)("button",{ref:n,title:"\u53CD\u9988","aria-label":"\u53CD\u9988\u5F00\u53D1\u8005\u58F0\u97F3",style:{position:"fixed",zIndex:300,border:"none",background:"transparent",cursor:"pointer",padding:0,display:"inline-flex",alignItems:"center",gap:4,borderRadius:"var(--dsw-radius-sm, 6px)",color:"var(--dsw-alias-label-tertiary, #888)",fontFamily:"inherit"},onMouseEnter:r=>r.currentTarget.style.color="var(--dsw-alias-label-primary, #111)",onMouseLeave:r=>r.currentTarget.style.color="var(--dsw-alias-label-tertiary, #888)",onClick:()=>e(!0),children:[(0,s.jsxs)("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,s.jsx)("path",{d:"M21.5 2.5 2.9 10.2c-.8.3-.8 1.5.1 1.7l4.6 1.4 1.7 5.5c.3.9 1.4 1 1.9.3l2.5-3.3 4.6 3.4c.7.5 1.7.1 1.9-.8l3.2-14.4c.2-.9-.7-1.7-1.5-1.4z"}),(0,s.jsx)("path",{d:"M7.3 13.5 21.5 2.5l-9.5 12.3"})]}),(0,s.jsx)("span",{style:{fontSize:12,lineHeight:1,whiteSpace:"nowrap"},children:"\u53CD\u9988"})]}),t&&(0,s.jsx)(Z,{onClose:()=>e(!1)})]})}const et=["slots"];function rt(t){if(!x){console.error('[vod-devkit] \u5D4C\u5165\u65B9\u672A\u6CE8\u5165 __VOD_DSH_UI_PRODUCT__\uFF0C\u53CD\u9988\u5165\u53E3\u672A\u6FC0\u6D3B\u3002\u4EA7\u54C1\u5F52\u56E0\u662F\u5FC5\u914D\u9879\uFF1A\u5D4C\u5165\u65B9\u88C5\u524D\u8BBE\u7F6E window.__VOD_DSH_UI_PRODUCT__ = "<\u4EA7\u54C1\u540D>"\uFF08\u53D6\u503C=\u751F\u6001\u770B\u677F\u4EA7\u54C1\u540D\uFF1A\u9AD8\u6821AI\u5F00\u53D1\u8005\u5E73\u53F0/\u6210\u957F\u4E2D\u5FC3/AI\u4E91\u539F\u751F\u5F00\u53D1\u5B9E\u8DF5\u4E2D\u5FC3/\u9E3F\u8499\u5F00\u53D1\u5B9E\u8DF5\u4E2D\u5FC3/AI\u529E\u516C\u5B9E\u8DF5\u4E2D\u5FC3/IaC \u5B9E\u8DF5\u4E2D\u5FC3/AI \u5F00\u53D1\u8005\u7A7A\u95F4/AI Agent \u96C6\u6210/AI \u5DE5\u5177\u96C6\u6210/AI \u8FD0\u884C\u73AF\u5883/\u5F00\u653E\u80FD\u529B/Skills\u95E8\u6237/GTD/VOD\uFF09');return}t.slots.inject("conversation.composer.dock",function*(){yield t.slots.register({name:"conversation.composer.dock",id:"vod-feedback",order:20},tt)})}const ot="vod-devkit-ui";
6
+ var U=Object.create;var b=Object.defineProperty;var V=Object.getOwnPropertyDescriptor;var N=Object.getOwnPropertyNames;var j=Object.getPrototypeOf,H=Object.prototype.hasOwnProperty;var J=(t,e)=>{for(var n in e)b(t,n,{get:e[n],enumerable:!0})},O=(t,e,n,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of N(e))!H.call(t,o)&&o!==n&&b(t,o,{get:()=>e[o],enumerable:!(r=V(e,o))||r.enumerable});return t};var K=(t,e,n)=>(n=t!=null?U(j(t)):{},O(e||!t||!t.__esModule?b(n,"default",{value:t,enumerable:!0}):n,t)),F=t=>O(b({},"__esModule",{value:!0}),t);var ct={};J(ct,{apply:()=>nt,inject:()=>ot,name:()=>lt});module.exports=F(ct);var i=require("react/jsx-runtime"),d=K(require("react"),1);const w="/rest/developer/manager/hdvodmngservice/v1";let m=typeof globalThis<"u"&&globalThis.__VOD_DSH_UI_BASE__||"";const G=`${w}/external/token`,T=`${w}/external/voices`,W=`${w}/external/meta`,_="vod_dshui_token",A="vod_dshui_device",h="vod_dshui_ledger",I="vod_dshui_draft",x="vod_dshui_recovered",R=200,X=typeof globalThis<"u"&&globalThis.__VOD_DSH_UI_LEDGER_DISABLED__===!0,k=typeof globalThis<"u"&&globalThis.__VOD_DSH_UI_PRODUCT__||"",C={textarea:{width:"100%",boxSizing:"border-box",minHeight:96,borderRadius:"var(--dsw-radius-sm, 8px)",border:"1px solid var(--dsw-alias-border-l3, #ccc)",padding:"8px 10px",fontSize:13,resize:"none",background:"var(--dsw-alias-bg-layer-1, transparent)",color:"var(--dsw-alias-label-primary, #111)",outline:"none"},input:{width:"100%",boxSizing:"border-box",borderRadius:"var(--dsw-radius-sm, 8px)",border:"1px solid var(--dsw-alias-border-l3, #ccc)",padding:"7px 10px",fontSize:13,background:"var(--dsw-alias-bg-layer-1, transparent)",color:"var(--dsw-alias-label-primary, #111)",outline:"none"},hint:{fontSize:12,color:"var(--dsw-alias-label-caption, #999)",marginBottom:12},label:{fontSize:12,color:"var(--dsw-alias-label-secondary, #666)",margin:"10px 0 6px"},result:{fontSize:12,marginBottom:12,padding:"8px 10px",borderRadius:"var(--dsw-radius-sm, 8px)",background:"var(--dsw-alias-interactive-bg-hover, rgba(0,0,0,.05))",color:"var(--dsw-alias-label-primary, #111)"}};function S(){let t=localStorage.getItem(A);return t||(t=(crypto.randomUUID?crypto.randomUUID():Date.now().toString(16)+Math.random().toString(16).slice(2)+Math.random().toString(16).slice(2)).replace(/[^0-9a-f]/g,"").slice(0,32),localStorage.setItem(A,t)),t}async function L(t){if(typeof crypto<"u"&&crypto.subtle){const e=await crypto.subtle.digest("SHA-1",new TextEncoder().encode(t));return[...new Uint8Array(e)].map(n=>n.toString(16).padStart(2,"0")).join("")}return q(t)}function q(t){let r=2166136261,o=3752705916;for(let l=0;l<t.length;l++){const s=t.charCodeAt(l);r^=s,r=Math.imul(r,16777619)>>>0,o^=s<<3&65535,o=Math.imul(o,2246822507)>>>0}return r.toString(16).padStart(8,"0")+o.toString(16).padStart(8,"0")}async function Q(t){return`ext_dshui_${(await L(S())).slice(0,8)}_${(await L(t)).slice(0,12)}`}function D(t){if(X)return;const e=JSON.parse(localStorage.getItem(h)||"[]");e.unshift(t),localStorage.setItem(h,JSON.stringify(e.slice(0,R)))}async function z(){let t=localStorage.getItem(_);if(t)return t;const e=await fetch(m+G,{method:"POST",headers:{"content-type":"application/json","X-Vod-Device-Id":S()},body:"{}"});if(e.status!==200&&e.status!==201)throw new Error(`token ${e.status}`);const n=await e.json().catch(()=>({}));if(t=typeof n=="string"?n:n.token||n.data?.token||"",!t)throw new Error("token empty");return localStorage.setItem(_,t),t}function Y({title:t,onClose:e,children:n,footer:r}){return(0,d.useEffect)(()=>{const o=l=>l.key==="Escape"&&e();return window.addEventListener("keydown",o),()=>window.removeEventListener("keydown",o)},[e]),(0,i.jsx)("div",{style:{position:"fixed",inset:0,zIndex:9e3,background:"rgba(0,0,0,.35)",display:"flex",alignItems:"center",justifyContent:"center"},onMouseDown:o=>o.target===o.currentTarget&&e(),children:(0,i.jsxs)("div",{role:"dialog","aria-label":t,style:{width:"min(488px, 92vw)",borderRadius:"var(--dsw-radius-panel, 12px)",background:"var(--dsw-alias-bg-layer-1, #fff)",color:"var(--dsw-alias-label-primary, #111)",padding:"18px 20px",fontFamily:"inherit",boxShadow:"0 8px 40px rgba(0,0,0,.2)"},children:[(0,i.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:12},children:[(0,i.jsx)("div",{style:{fontSize:15,fontWeight:600},children:t}),(0,i.jsx)("button",{onClick:e,"aria-label":"\u5173\u95ED",style:{border:"none",background:"transparent",cursor:"pointer",fontSize:16,lineHeight:1,padding:4,borderRadius:6,color:"var(--dsw-alias-label-tertiary, #888)"},children:"\u2715"})]}),n,r&&(0,i.jsx)("div",{style:{marginTop:14},children:r})]})})}function Z({disabled:t,onClick:e,children:n}){return(0,i.jsx)("button",{disabled:t,onClick:e,style:{width:"100%",height:44,fontSize:14,fontWeight:500,border:"none",cursor:t?"not-allowed":"pointer",borderRadius:"var(--dsw-radius-lg, 10px)",background:t?"var(--dsw-alias-interactive-bg-hover, rgba(0,0,0,.06))":"var(--dsw-alias-button-primary-fill, #2563eb)",color:t?"var(--dsw-alias-label-tertiary, #999)":"var(--dsw-alias-label-primary-foreground, #fff)"},children:n})}let $=!1;async function tt(){if($)return;$=!0;let t=0;const e=JSON.parse(localStorage.getItem(h)||"[]").filter(r=>r.status==="pending-endpoint"||r.status==="failed");for(const r of e.slice(0,5))try{const o=await z(),l=await fetch(m+T,{method:"POST",headers:{"content-type":"application/json","X-Vod-Device-Id":S(),authorization:`Bearer ${o}`},body:JSON.stringify({voices:[{title:r.title,content:r.content}],product:k})});if(l.status===200||l.status===201){r.status="accepted";try{localStorage.removeItem(I)}catch{}const s=await l.json().catch(()=>({}));r.serverVoiceId=(s.voiceIds||s.data?.voiceIds||[])[0]||"",r.retriedAt=new Date().toISOString(),t++}else l.status!==404&&(r.error=`retry ${l.status}`)}catch(o){r.error=String(o&&o.message||o)}const n=e.filter(r=>r.status!=="accepted");if(t>0){const r=e.filter(o=>o.status==="accepted"&&o.retriedAt).map(o=>`\u201C${(o.content||o.title||"").slice(0,60)}\u201D`).join("\u3001");try{localStorage.setItem(x,JSON.stringify({n:t,items:r}))}catch{}}if(n.length!==e.length||e.length){const r=JSON.parse(localStorage.getItem(h)||"[]"),o=new Map(e.map(s=>[s.voiceKey,s])),l=r.map(s=>o.get(s.voiceKey)||s);localStorage.setItem(h,JSON.stringify(l.slice(0,R)))}}function et({onClose:t}){const e=(()=>{try{return JSON.parse(localStorage.getItem(I)||"null")||{}}catch{return{}}})(),[n,r]=(0,d.useState)(e.content||"");(0,d.useEffect)(()=>{try{localStorage.setItem(I,JSON.stringify({content:n}))}catch{}},[n]);const[o,l]=(0,d.useState)(!1),[s,g]=(0,d.useState)(null);(0,d.useEffect)(()=>{let a=null;try{a=JSON.parse(localStorage.getItem(x)||"null")}catch{}if(a&&a.n>0){try{localStorage.removeItem(x)}catch{}const c=a.items?`\uFF0C\u4EA7\u54C1\u56E2\u961F\u4F1A\u770B\u5230\uFF1A${a.items}`:"";g({ok:!0,msg:`\u4F60\u4E4B\u524D\u63D0\u4EA4\u7684 ${a.n} \u6761\u53CD\u9988\u5DF2\u81EA\u52A8\u91CD\u8BD5\u6210\u529F\uFF08\u5F53\u65F6\u63D0\u4EA4\u4E34\u65F6\u5931\u8D25\uFF09${c}`})}},[]);let y=null;async function M(a,c){if(/^\d+$/.test(a))return a;try{if(!y){const f=await fetch(m+W,{headers:{authorization:`Bearer ${c}`}});if(f.ok){const p=await f.json().catch(()=>({}));y=(p.data||p).productCatalog||[]}}const u=(y||[]).find(f=>String(f?.name||"").toLowerCase()===a.toLowerCase());if(u&&u.id!=null)return String(u.id)}catch{}return a}async function P(){const a=n.trim();if(!a){g({ok:!1,msg:"\u8BF7\u5148\u586B\u5199\u53CD\u9988\u5185\u5BB9"});return}if(a.length>2e3){g({ok:!1,msg:`\u5185\u5BB9\u8D85\u957F\uFF08${a.length}/2000\uFF09\uFF0C\u8BF7\u7CBE\u7B80`});return}l(!0),g(null);const c={title:a.slice(0,64),content:a,at:new Date().toISOString(),status:"failed",error:""};try{c.voiceKey=await Q(a);try{const u=await z(),f=await fetch(m+T,{method:"POST",headers:{"content-type":"application/json","X-Vod-Device-Id":S(),authorization:`Bearer ${u}`},body:JSON.stringify({voices:[{title:a.slice(0,60),content:a}],product:await M(k,u)})});if(f.status===404){c.status="pending-endpoint",D(c),g({ok:!1,msg:"\u56E4\u79EF\u7AEF\u70B9\u5C1A\u672A\u4E0A\u7EBF\uFF08\u5F15\u64CE\u90E8\u7F72\u540E\u81EA\u52A8\u53EF\u7528\uFF09\uFF1B\u53CD\u9988\u5DF2\u6682\u5B58\u672C\u673A\uFF0C\u7A0D\u540E\u91CD\u8BD5\u63D0\u4EA4\u3002"});return}if(f.status===401&&localStorage.removeItem(_),f.status!==200&&f.status!==201)throw new Error(`submit ${f.status}`);const p=await f.json().catch(()=>({}));c.status="accepted",c.serverVoiceId=p.voiceIds?.[0]||"",c.taskId=p.taskIds?.[0]||"",D(c);const B=p.productRegistered===void 0?!0:p.productRegistered;g(B?{ok:!0,msg:"\u5DF2\u6536\u5F55\uFF0C\u4EA7\u54C1\u56E2\u961F\u4F1A\u770B\u5230\u8FD9\u6761\u53CD\u9988\u3002"}:{ok:!0,msg:"\u5DF2\u6536\u5F55\u3002\u6CE8\u610F\uFF1A\u4EA7\u54C1\u540D\u5C1A\u672A\u5728\u5E73\u53F0\u6CE8\u518C\uFF0C\u8FD9\u6761\u53CD\u9988\u6682\u4E0D\u8FDB\u4EA7\u54C1\u5206\u6790\uFF0C\u8BF7\u8054\u7CFB\u90E8\u7F72\u65B9\u6838\u5BF9\u3002"})}catch(u){c.error=String(u&&u.message||u),D(c),g({ok:!1,msg:`\u63D0\u4EA4\u5931\u8D25\uFF08${c.error}\uFF09\uFF1B\u53CD\u9988\u5DF2\u6682\u5B58\u672C\u673A\uFF0C\u7A0D\u540E\u91CD\u8BD5\u3002`})}}finally{l(!1)}}return(0,i.jsxs)(Y,{title:"\u63D0\u4EA4\u53CD\u9988",onClose:t,footer:(0,i.jsx)(Z,{disabled:o||!n.trim(),onClick:P,children:o?"\u63D0\u4EA4\u4E2D\u2026":"\u63D0\u4EA4"}),children:[(0,i.jsx)("textarea",{id:"vod-fb-content",style:C.textarea,value:n,maxLength:2e3,placeholder:"\u6BD4\u5982\uFF1A\u5BF9\u8BDD\u54CD\u5E94\u6162\u3001\u67D0\u4E2A\u529F\u80FD\u627E\u4E0D\u5230\u5165\u53E3",autoFocus:!0,onChange:a=>r(a.target.value)}),s&&(0,i.jsx)("div",{style:C.result,children:s.msg})]})}function rt(){const[t,e]=(0,d.useState)(!1),n=(0,d.useRef)(null);return(0,d.useEffect)(()=>{tt();const r=()=>{const s=n.current;if(!s)return;const g=document.querySelector("[contenteditable=true][role=textbox], [contenteditable=true]");if(!g)return;const y=g.getBoundingClientRect();s.offsetWidth!==0&&(s.style.left="auto",s.style.right=Math.round(window.innerWidth-y.right+8)+"px",s.style.top=Math.round(y.top-30)+"px",s.style.height="24px")};r();const o=new ResizeObserver(r);o.observe(document.documentElement),window.addEventListener("resize",r);const l=setInterval(r,800);return()=>{o.disconnect(),window.removeEventListener("resize",r),clearInterval(l)}},[]),(0,i.jsxs)(d.default.Fragment,{children:[(0,i.jsxs)("button",{ref:n,title:"\u53CD\u9988","aria-label":"\u53CD\u9988\u5F00\u53D1\u8005\u58F0\u97F3",style:{position:"fixed",zIndex:300,border:"none",background:"transparent",cursor:"pointer",padding:0,display:"inline-flex",alignItems:"center",gap:4,borderRadius:"var(--dsw-radius-sm, 6px)",color:"var(--dsw-alias-label-tertiary, #888)",fontFamily:"inherit"},onMouseEnter:r=>r.currentTarget.style.color="var(--dsw-alias-label-primary, #111)",onMouseLeave:r=>r.currentTarget.style.color="var(--dsw-alias-label-tertiary, #888)",onClick:()=>e(!0),children:[(0,i.jsxs)("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,i.jsx)("path",{d:"M21.5 2.5 2.9 10.2c-.8.3-.8 1.5.1 1.7l4.6 1.4 1.7 5.5c.3.9 1.4 1 1.9.3l2.5-3.3 4.6 3.4c.7.5 1.7.1 1.9-.8l3.2-14.4c.2-.9-.7-1.7-1.5-1.4z"}),(0,i.jsx)("path",{d:"M7.3 13.5 21.5 2.5l-9.5 12.3"})]}),(0,i.jsx)("span",{style:{fontSize:12,lineHeight:1,whiteSpace:"nowrap"},children:"\u53CD\u9988"})]}),t&&(0,i.jsx)(et,{onClose:()=>e(!1)})]})}const ot=["slots"];function nt(t){if(!k){console.error('[vod-devkit] \u5D4C\u5165\u65B9\u672A\u6CE8\u5165 __VOD_DSH_UI_PRODUCT__\uFF0C\u53CD\u9988\u5165\u53E3\u672A\u6FC0\u6D3B\u3002\u4EA7\u54C1\u5F52\u56E0\u662F\u5FC5\u914D\u9879\uFF1A\u5D4C\u5165\u65B9\u88C5\u524D\u8BBE\u7F6E window.__VOD_DSH_UI_PRODUCT__ = "<\u4EA7\u54C1\u540D>"\uFF08\u53D6\u503C=\u751F\u6001\u770B\u677F\u4EA7\u54C1\u540D\uFF1A\u9AD8\u6821AI\u5F00\u53D1\u8005\u5E73\u53F0/\u6210\u957F\u4E2D\u5FC3/AI\u4E91\u539F\u751F\u5F00\u53D1\u5B9E\u8DF5\u4E2D\u5FC3/\u9E3F\u8499\u5F00\u53D1\u5B9E\u8DF5\u4E2D\u5FC3/AI\u529E\u516C\u5B9E\u8DF5\u4E2D\u5FC3/IaC \u5B9E\u8DF5\u4E2D\u5FC3/AI \u5F00\u53D1\u8005\u7A7A\u95F4/AI Agent \u96C6\u6210/AI \u5DE5\u5177\u96C6\u6210/AI \u8FD0\u884C\u73AF\u5883/\u5F00\u653E\u80FD\u529B/Skills\u95E8\u6237/GTD/VOD\uFF09');return}for(const e of at)t.slots.inject(e,function*(){yield t.slots.register({name:e,id:"vod-feedback",order:20},st(e))})}const at=["conversation.input.dock","conversation.composer.dock"];let v=null;function it({slot:t}){return(0,d.useEffect)(()=>()=>{v===t&&(v=null)},[t]),v!==null&&v!==t?null:(v=t,(0,i.jsx)(rt,{}))}const E=new Map;function st(t){return E.has(t)||E.set(t,function(){return(0,i.jsx)(it,{slot:t})}),E.get(t)}const lt="vod-devkit-ui";
7
7
  module.exports.inject = ["slots"];
8
8
  return module.exports;
9
9
  }
package/lib/index.js CHANGED
@@ -13,19 +13,24 @@ import z from '@deepseek-ai/schemastery';
13
13
  import { createHash, randomUUID } from 'node:crypto';
14
14
  import { fileURLToPath } from 'node:url';
15
15
  import { dirname, join } from 'node:path';
16
- import { readFileSync, writeFileSync, existsSync, mkdirSync } from 'node:fs';
16
+ import { readFileSync, writeFileSync, existsSync, mkdirSync, readdirSync } from 'node:fs';
17
+ import { homedir } from 'node:os';
17
18
 
18
19
  export const name = 'vod-devkit';
19
20
  export const inject = ['tools'];
20
21
 
21
22
  const PKG_DIR = dirname(dirname(fileURLToPath(import.meta.url)));
22
23
  const DATA_DIR = join(PKG_DIR, 'data');
23
- const RUNTIME = join(DATA_DIR, 'runtime.json');
24
+ // 运行时状态路径可用 VOD_DSH_RUNTIME 覆盖(测试隔离/企业数据驻留用;
25
+ // 2026-11-11 实锤:dsh/test 直写仓内 dsh/data/runtime.json,本地账本被测试
26
+ // 灌到 128 条——测试必须能指到 tmp,不能再共用真实账本)
27
+ const RUNTIME = process.env.VOD_DSH_RUNTIME || join(DATA_DIR, 'runtime.json');
24
28
  const API_PREFIX = '/rest/developer/manager/hdvodmngservice/v1';
25
29
  const HOARD_PATH = `${API_PREFIX}/external/voices`; // V16 囤积端点(批量/不触发 LLM/结构化回执)
26
30
  const SUBMIT_PATH = `${API_PREFIX}/external/voice/submit`; // 旧单条端点:仅 404 回落使用 // V16 已切换:主路径 HOARD_PATH(囤积),本路径仅 404 回落(见 docs/decisions.md D-dsh-4)
27
31
  const TOKEN_PATH = `${API_PREFIX}/external/token`;
28
32
  const LEDGER_CAP = 200;
33
+ const PKG_VERSION = JSON.parse(readFileSync(join(PKG_DIR, 'package.json'), 'utf8')).version;
29
34
 
30
35
  export const Config = z.object({
31
36
  apiBase: z.string().default('https://vod-dev.topxtopx.com').volatile(),
@@ -294,6 +299,47 @@ export function apply(ctx, config) {
294
299
  ? readCfg(config?.receiptGuard, 'report') : 'report',
295
300
  });
296
301
 
302
+ // ── 技能披露 + 版本提醒(与 Python 侧同口径的只读面)──────────────────
303
+ // 为什么 dsh 必须有这两个:dsh 是本插件唯一没有 MCP 的宿主,规则/话术
304
+ // 全靠落盘技能;而 2026-11-11 前安装器根本没给 dsh 落技能(已修)。
305
+ // 披露让"技能文本=server data",改规则不必碰宿主拷贝。
306
+ const SKILLS_DIR = process.env.VOD_SKILLS_DIR || join(homedir(), '.dsh', 'skills');
307
+ const SKILL_RE = /^[a-z0-9][a-z0-9-]{2,63}$/;
308
+ const SKILL_CAP = 12000;
309
+ const UPDATE_TTL_MS = 24 * 3600 * 1000;
310
+ const DISMISS_DAYS = 3;
311
+
312
+ function skillDirs() {
313
+ try {
314
+ return readdirSync(SKILLS_DIR, { withFileTypes: true })
315
+ .filter((e) => e.isDirectory())
316
+ .map((e) => e.name)
317
+ .filter((n) => existsSync(join(SKILLS_DIR, n, 'SKILL.md')))
318
+ .sort();
319
+ } catch {
320
+ return [];
321
+ }
322
+ }
323
+
324
+ function skillDescription(text) {
325
+ const m = /^description:\s*(.+)$/m.exec(text || '');
326
+ return m ? m[1].trim().replace(/^['"]|['"]$/g, '') : '';
327
+ }
328
+
329
+ function versionTuple(v) {
330
+ const core = String(v || '').split('-')[0].split('+')[0];
331
+ return core.split('.').slice(0, 3).map((x) => Number.parseInt(x, 10) || 0)
332
+ .concat([0, 0]).slice(0, 3);
333
+ }
334
+
335
+ function cmpVersion(a, b) {
336
+ const x = versionTuple(a), y = versionTuple(b);
337
+ for (let i = 0; i < 3; i += 1) {
338
+ if (x[i] !== y[i]) return x[i] > y[i] ? 1 : -1;
339
+ }
340
+ return 0;
341
+ }
342
+
297
343
  const tools = [
298
344
  {
299
345
  name: 'vod_submit_voices',
@@ -514,6 +560,95 @@ export function apply(ctx, config) {
514
560
  });
515
561
  },
516
562
  },
563
+ {
564
+ name: 'vod_list_skills',
565
+ description: '[VOD-unique] Read-only: list skills available on this machine (name/pack/description). '
566
+ + 'Use before routing a rules question (分类/评分/话术) or before vod_retrieve_skill.',
567
+ parameters: buildParameters({}),
568
+ output: { schema: { type: 'object', additionalProperties: true }, render: renderText },
569
+ async execute() {
570
+ const skills = skillDirs().map((n) => {
571
+ let text = '';
572
+ try { text = readFileSync(join(SKILLS_DIR, n, 'SKILL.md'), 'utf8'); } catch { /* 忽略 */ }
573
+ const pack = ['vod-core', 'vod-feedback-collect'].includes(n) ? 'core' : 'knowledge';
574
+ return { name: n, pack, native: true, description: skillDescription(text) };
575
+ });
576
+ return textResult({ skills, skillsDir: SKILLS_DIR });
577
+ },
578
+ },
579
+ {
580
+ name: 'vod_retrieve_skill',
581
+ description: '[VOD-unique] Read-only: read one skill verbatim (SKILL.md). '
582
+ + 'Use when this machine\'s copy is missing or you need the rules text without a native skill loader. '
583
+ + 'Unknown names return the available list.',
584
+ parameters: buildParameters({
585
+ name: { type: 'string', description: 'skill name from vod_list_skills' },
586
+ }),
587
+ output: { schema: { type: 'object', additionalProperties: true }, render: renderText },
588
+ async execute(args) {
589
+ const nm = String(args.name || '').trim();
590
+ if (!SKILL_RE.test(nm)) {
591
+ return textResult({ error: 'bad-name', available: skillDirs() });
592
+ }
593
+ try {
594
+ let content = readFileSync(join(SKILLS_DIR, nm, 'SKILL.md'), 'utf8');
595
+ const truncated = content.length > SKILL_CAP;
596
+ if (truncated) content = content.slice(0, SKILL_CAP);
597
+ return textResult({ name: nm, chars: content.length, truncated, content });
598
+ } catch {
599
+ return textResult({ error: 'not-found', name: nm, available: skillDirs() });
600
+ }
601
+ },
602
+ },
603
+ {
604
+ name: 'vod_check_update',
605
+ description: '[VOD-unique] Read-only: is this plugin behind npm latest? 24h cache, silent on failure. '
606
+ + 'Reports only - never self-upgrades (upgrade = rerun the install command). '
607
+ + 'Pass dismiss=true after the user asks to stop the reminders (3-day cooldown).',
608
+ parameters: buildParameters({
609
+ dismiss: { type: 'boolean', description: 'user asked to stop reminders (3-day cooldown)' },
610
+ }),
611
+ output: { schema: { type: 'object', additionalProperties: true }, render: renderText },
612
+ async execute(args) {
613
+ const state = loadRuntime().update_check || {};
614
+ const now = Date.now();
615
+ const today = new Date(now).toISOString().slice(0, 10);
616
+ if (args.dismiss === true) {
617
+ const until = new Date(now + DISMISS_DAYS * 86400e3).toISOString().slice(0, 10);
618
+ saveRuntime({ update_check: { ...state, dismissedUntil: until } });
619
+ return textResult({ dismissedUntil: until, updateAvailable: false });
620
+ }
621
+ if (state.dismissedUntil && today < state.dismissedUntil) {
622
+ return textResult({ updateAvailable: false, dismissedUntil: state.dismissedUntil });
623
+ }
624
+ const fresh = state.checkedAt && (now - Date.parse(state.checkedAt)) < UPDATE_TTL_MS;
625
+ let latest = fresh ? state.latestVersion : null;
626
+ if (!latest) {
627
+ try {
628
+ const ctl = new AbortController();
629
+ const timer = setTimeout(() => ctl.abort(), 3000);
630
+ const res = await fetch('https://registry.npmjs.org/dsh-vod-devkit/latest',
631
+ { signal: ctl.signal });
632
+ clearTimeout(timer);
633
+ const body = await res.json();
634
+ latest = body?.version ? String(body.version) : null;
635
+ } catch { latest = null; }
636
+ if (latest) {
637
+ saveRuntime({ update_check: { ...state, checkedAt: new Date(now).toISOString(),
638
+ latestVersion: latest } });
639
+ }
640
+ }
641
+ if (!latest) {
642
+ return textResult({ currentVersion: PKG_VERSION, latestVersion: null,
643
+ updateAvailable: false, checked: false,
644
+ note: '版本检查不可达(离线/内网正常),不影响采集。' });
645
+ }
646
+ const newer = cmpVersion(latest, PKG_VERSION) > 0;
647
+ return textResult({ currentVersion: PKG_VERSION, latestVersion: latest,
648
+ updateAvailable: newer, checked: true,
649
+ ...(newer ? { upgradeCommand: '重跑 install(同一行装命令)' } : {}) });
650
+ },
651
+ },
517
652
  ];
518
653
 
519
654
  for (const t of tools) ctx.tools.register(t);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-vod-devkit",
3
- "version": "0.4.3",
3
+ "version": "0.5.0",
4
4
  "description": "VOD user-voice collection tools for DeepSeek Harness (dsh). Thin shell over the VOD external HTTP API — mirrors vod-devkit (MCP) collect semantics.",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",
@@ -42,7 +42,8 @@
42
42
  },
43
43
  "exports": {
44
44
  ".": "./lib/index.js",
45
- "./client": "./lib/client.js"
45
+ "./client": "./lib/client.js",
46
+ "./package.json": "./package.json"
46
47
  },
47
48
  "scripts": {
48
49
  "build-client": "esbuild src/client.jsx --jsx=automatic --format=cjs --minify --outfile=/tmp/client-cjs.js && python3 scripts/wrap_client.py"