dsh-vod-devkit 0.1.0 → 0.2.1
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/README.md +7 -6
- package/lib/client.js +1 -1
- package/lib/index.js +256 -16
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -16,16 +16,17 @@ VOD 用户声音采集插件 —— DeepSeek Harness (dsh) 薄壳。
|
|
|
16
16
|
## 安装
|
|
17
17
|
|
|
18
18
|
```
|
|
19
|
-
|
|
20
|
-
dsh plugin --profile <name> add
|
|
19
|
+
npx --yes vod-devkit install --target dsh --profile <name> --product <产品> # 推荐(安装期硬校验+幂等写配置)
|
|
20
|
+
dsh plugin --profile <name> add dsh-vod-devkit # 直装(装后须手工配 product,见下)
|
|
21
21
|
```
|
|
22
22
|
|
|
23
|
-
|
|
23
|
+
装后产品归因必须落到 profile 的 cordis.patch.yml(npx 包装命令自动写入):
|
|
24
24
|
|
|
25
25
|
```yaml
|
|
26
|
-
-
|
|
27
|
-
|
|
28
|
-
|
|
26
|
+
- id: vod-devkit
|
|
27
|
+
config:
|
|
28
|
+
product: codearts # 归因绑定(安装时定);无运行期传参通道
|
|
29
|
+
# apiBase: https://vod-dev.topxtopx.com # 缺省即此
|
|
29
30
|
```
|
|
30
31
|
|
|
31
32
|
## 配置(dsh 插件设置)
|
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 w=Object.defineProperty;var P=Object.getOwnPropertyDescriptor;var M=Object.getOwnPropertyNames;var U=Object.getPrototypeOf,$=Object.prototype.hasOwnProperty;var L=(t,r)=>{for(var e in r)w(t,e,{get:r[e],enumerable:!0})},D=(t,r,e,o)=>{if(r&&typeof r=="object"||typeof r=="function")for(let a of M(r))!$.call(t,a)&&a!==e&&w(t,a,{get:()=>r[a],enumerable:!(o=P(r,a))||o.enumerable});return t};var j=(t,r,e)=>(e=t!=null?B(U(t)):{},D(r||!t||!t.__esModule?w(e,"default",{value:t,enumerable:!0}):e,t)),H=t=>D(w({},"__esModule",{value:!0}),t);var et={};L(et,{apply:()=>Z,name:()=>tt});module.exports=H(et);var n=require("react/jsx-runtime"),c=j(require("react"),1);const O="/rest/developer/manager/hdvodmngservice/v1",S=typeof globalThis<"u"&&globalThis.__VOD_DSH_UI_BASE__||"https://vod-dev.topxtopx.com",V=`${O}/external/token`,x=`${O}/external/voices`,k="vod_dshui_token",R="vod_dshui_device",b="vod_dshui_ledger",T=200,v=typeof globalThis<"u"&&globalThis.__VOD_DSH_UI_PRODUCT__||"",F=[{id:"\u529F\u80FD\u5EFA\u8BAE",label:"\u529F\u80FD\u5EFA\u8BAE",hint:"\u5E0C\u671B\u65B0\u589E/\u6539\u8FDB\u80FD\u529B"},{id:"\u7528\u6237\u4F53\u9A8C",label:"\u7528\u6237\u4F53\u9A8C",hint:"\u53EF\u7528\u4F46\u4F53\u9A8C\u5DEE"},{id:"\u4EA7\u54C1\u7F3A\u9677",label:"\u4EA7\u54C1\u7F3A\u9677",hint:"Bug/\u62A5\u9519/\u529F\u80FD\u4E0D\u53EF\u7528"}],_={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:"vertical",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 N(){let t=localStorage.getItem(R);return t||(t=crypto.randomUUID?crypto.randomUUID():"dev-"+Date.now()+"-"+Math.random().toString(36).slice(2),localStorage.setItem(R,t)),t}async function z(t){if(typeof crypto<"u"&&crypto.subtle){const r=await crypto.subtle.digest("SHA-1",new TextEncoder().encode(t));return[...new Uint8Array(r)].map(e=>e.toString(16).padStart(2,"0")).join("")}return J(t)}function J(t){let o=2166136261,a=3752705916;for(let s=0;s<t.length;s++){const l=t.charCodeAt(s);o^=l,o=Math.imul(o,16777619)>>>0,a^=l<<3&65535,a=Math.imul(a,2246822507)>>>0}return o.toString(16).padStart(8,"0")+a.toString(16).padStart(8,"0")}async function K(t){return`ext_dshui_${(await z(N())).slice(0,8)}_${(await z(t)).slice(0,12)}`}function I(t){const r=JSON.parse(localStorage.getItem(b)||"[]");r.unshift(t),localStorage.setItem(b,JSON.stringify(r.slice(0,T)))}async function E(){let t=localStorage.getItem(k);if(t)return t;const r=await fetch(S+V,{method:"POST",headers:{"content-type":"application/json"},body:"{}"});if(r.status!==200&&r.status!==201)throw new Error(`token ${r.status}`);const e=await r.json().catch(()=>({}));if(t=typeof e=="string"?e:e.token||e.data?.token||"",!t)throw new Error("token empty");return localStorage.setItem(k,t),t}function W({title:t,onClose:r,children:e,footer:o}){return(0,c.useEffect)(()=>{const a=s=>s.key==="Escape"&&r();return window.addEventListener("keydown",a),()=>window.removeEventListener("keydown",a)},[r]),(0,n.jsx)("div",{style:{position:"fixed",inset:0,zIndex:9e3,background:"rgba(0,0,0,.35)",display:"flex",alignItems:"center",justifyContent:"center"},onMouseDown:a=>a.target===a.currentTarget&&r(),children:(0,n.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,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:12},children:[(0,n.jsx)("div",{style:{fontSize:15,fontWeight:600},children:t}),(0,n.jsx)("button",{onClick:r,"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"})]}),e,o&&(0,n.jsx)("div",{style:{marginTop:14},children:o})]})})}function G({disabled:t,onClick:r,children:e}){return(0,n.jsx)("button",{disabled:t,onClick:r,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:e})}async function q(t,r){try{const e=await E(),o=await fetch(S+x+"?limit=50",{headers:{authorization:`Bearer ${e}`}});if(o.status!==200)return null;const a=await o.json().catch(()=>({})),l=(a.voices||a.data?.voices||[]).find(f=>f.voiceId===t);return l&&l.issue_sync||null}catch{return null}}let C=!1;async function X(){if(C)return;C=!0;const t=JSON.parse(localStorage.getItem(b)||"[]").filter(e=>e.status==="pending-endpoint"||e.status==="failed");for(const e of t.slice(0,5))try{const o=await E(),a=await fetch(S+x,{method:"POST",headers:{"content-type":"application/json",authorization:`Bearer ${o}`},body:JSON.stringify({voices:[{title:e.title,content:e.content,...e.category?{tags:["problem_type:"+e.category]}:{}}],product:v})});if(a.status===200||a.status===201){e.status="accepted";const s=await a.json().catch(()=>({}));e.serverVoiceId=(s.voiceIds||s.data?.voiceIds||[])[0]||"",e.retriedAt=new Date().toISOString()}else a.status!==404&&(e.error=`retry ${a.status}`)}catch(o){e.error=String(o&&o.message||o)}if(t.filter(e=>e.status!=="accepted").length!==t.length||t.length){const e=JSON.parse(localStorage.getItem(b)||"[]"),o=new Map(t.map(s=>[s.voiceKey,s])),a=e.map(s=>o.get(s.voiceKey)||s);localStorage.setItem(b,JSON.stringify(a.slice(0,T)))}}function Q({onClose:t}){const[r,e]=(0,c.useState)(""),[o,a]=(0,c.useState)(""),[s,l]=(0,c.useState)(!1),[f,p]=(0,c.useState)(null);async function h(i,d){if(i)for(let g=0;g<6;g++){await new Promise(y=>setTimeout(y,1e4));const u=await q(i);if(u){if(u.status==="CREATED"&&u.issue_url){d({ok:!0,msg:`\u5DF2\u5EFA\u6210 issue\uFF1A${u.issue_url}`});return}if(u.status==="REJECTED"){d({ok:!1,msg:"\u53CD\u9988\u7ECF\u5BA1\u6838\u672A\u91C7\u7EB3\uFF0C\u611F\u8C22\u4F60\u7684\u63D0\u4EA4\u3002"});return}}}}async function m(){const i=r.trim();if(!i){p({ok:!1,msg:"\u8BF7\u5148\u586B\u5199\u53CD\u9988\u5185\u5BB9"});return}if(i.length>2e3){p({ok:!1,msg:`\u5185\u5BB9\u8D85\u957F\uFF08${i.length}/2000\uFF09\uFF0C\u8BF7\u7CBE\u7B80`});return}l(!0),p(null);const d={title:i.slice(0,60),category:o,content:i,at:new Date().toISOString(),status:"failed",error:""};try{d.voiceKey=await K(i);try{const g=await E(),u=await fetch(S+x,{method:"POST",headers:{"content-type":"application/json",authorization:`Bearer ${g}`},body:JSON.stringify({voices:[{title:i.slice(0,60),content:i,tags:o?["problem_type:"+o]:[]}],product:v})});if(u.status===404){d.status="pending-endpoint",I(d),p({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(u.status===401&&localStorage.removeItem(k),u.status!==200&&u.status!==201)throw new Error(`submit ${u.status}`);const y=await u.json().catch(()=>({}));d.status="accepted",d.serverVoiceId=y.voiceIds?.[0]||"",d.taskId=y.taskIds?.[0]||"",I(d);const A=y.productRegistered===void 0?!0:y.productRegistered;p(A?{ok:!0,msg:"\u5DF2\u6536\u5F55\uFF0C\u4EA7\u54C1\u56E2\u961F\u4F1A\u770B\u5230\u8FD9\u6761\u53CD\u9988\uFF1B\u5BA1\u6838\u540E\u5C06\u4EE5 issue \u5F62\u5F0F\u8DDF\u8FDB\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"}),h(d.serverVoiceId,p)}catch(g){d.error=String(g&&g.message||g),I(d),p({ok:!1,msg:`\u63D0\u4EA4\u5931\u8D25\uFF08${d.error}\uFF09\uFF1B\u53CD\u9988\u5DF2\u6682\u5B58\u672C\u673A\uFF0C\u7A0D\u540E\u91CD\u8BD5\u3002`})}}finally{l(!1)}}return(0,n.jsxs)(W,{title:"\u63D0\u4EA4\u53CD\u9988",onClose:t,footer:(0,n.jsx)(G,{disabled:s||!r.trim(),onClick:m,children:s?"\u63D0\u4EA4\u4E2D\u2026":"\u63D0\u4EA4"}),children:[(0,n.jsxs)("div",{style:_.hint,children:["\u4F60\u7684\u53CD\u9988\u5C06\u8FDB\u5165 VOD \u5F00\u53D1\u8005\u58F0\u97F3\u5206\u6790\u5E73\u53F0",v?`\uFF0C\u5E2E\u52A9 ${v} \u53D8\u5F97\u66F4\u597D`:"","\u3002 \u9009\u62E9\u7684\u5206\u7C7B\u4F1A\u968F\u53CD\u9988\u4E00\u5E76\u8BB0\u5F55\uFF0C\u4EA7\u54C1\u56E2\u961F\u4F1A\u7ED3\u5408\u5185\u5BB9\u590D\u6838\u3002"]}),(0,n.jsx)("div",{style:{display:"flex",flexWrap:"wrap",gap:6,marginBottom:10},children:F.map(i=>(0,n.jsxs)("button",{title:i.hint||"",style:{fontSize:12,padding:"4px 10px",cursor:"pointer",borderRadius:"var(--dsw-radius-sm, 999px)",background:o===i.id?"var(--dsw-alias-state-business-primary, #2563eb)":"transparent",color:o===i.id?"var(--dsw-alias-label-primary-foreground, #fff)":"var(--dsw-alias-label-secondary, #666)",border:"1px solid var(--dsw-alias-border-l3, #ccc)"},onClick:()=>a(o===i.id?"":i.id),children:[i.label,i.hint?"\xB7"+i.hint:""]},i.id))}),(0,n.jsx)("textarea",{style:_.textarea,value:r,maxLength:2e3,placeholder:"\u6BD4\u5982\uFF1A\u8865\u5168\u592A\u6162\uFF0C\u5E0C\u671B\u4F18\u5316\u901F\u5EA6",autoFocus:!0,onChange:i=>e(i.target.value)}),(0,n.jsxs)("div",{style:{fontSize:11,textAlign:"right",margin:"4px 0 0",color:"var(--dsw-alias-label-tertiary, #999)"},children:[r.length,"/2000"]}),f&&(0,n.jsx)("div",{style:_.result,children:f.msg})]})}function Y(){const[t,r]=(0,c.useState)(!1),e=(0,c.useRef)(null);return(0,c.useEffect)(()=>{X();const o=()=>{const l=e.current;if(!l)return;const f=document.querySelector("[contenteditable=true][role=textbox], [contenteditable=true]");if(!f)return;const p=f.getBoundingClientRect(),h=l.offsetWidth||24,m=24;l.style.left=Math.round(p.right-h-8)+"px",l.style.top=Math.round(p.top-m-6)+"px",l.style.width=h+"px",l.style.height=m+"px"};o();const a=new ResizeObserver(o);a.observe(document.documentElement),window.addEventListener("resize",o);const s=setInterval(o,800);return()=>{a.disconnect(),window.removeEventListener("resize",o),clearInterval(s)}},[]),(0,n.jsxs)(c.default.Fragment,{children:[(0,n.jsxs)("button",{ref:e,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:o=>o.currentTarget.style.color="var(--dsw-alias-label-primary, #111)",onMouseLeave:o=>o.currentTarget.style.color="var(--dsw-alias-label-tertiary, #888)",onClick:()=>r(!0),children:[(0,n.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,n.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,n.jsx)("path",{d:"M7.3 13.5 21.5 2.5l-9.5 12.3"})]}),(0,n.jsx)("span",{style:{fontSize:12,lineHeight:1,whiteSpace:"nowrap"},children:"\u53CD\u9988"})]}),t&&(0,n.jsx)(Q,{onClose:()=>r(!1)})]})}function Z(t){if(!v){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},Y)})}const tt="vod-devkit-ui";
|
|
6
|
+
var B=Object.create;var b=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)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 U(e))!j.call(t,o)&&o!==n&&b(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)):{},O(e||!t||!t.__esModule?b(n,"default",{value:t,enumerable:!0}):n,t)),J=t=>O(b({},"__esModule",{value:!0}),t);var ot={};H(ot,{apply:()=>et,name:()=>rt});module.exports=J(ot);var s=require("react/jsx-runtime"),d=N(require("react"),1);const _="/rest/developer/manager/hdvodmngservice/v1";let w=typeof globalThis<"u"&&globalThis.__VOD_DSH_UI_BASE__||"";const F=`${_}/external/token`,T=`${_}/external/voices`,K=`${_}/external/meta`,I="vod_dshui_token",R="vod_dshui_device",h="vod_dshui_ledger",x="vod_dshui_draft",k="vod_dshui_recovered",A=200,G=typeof globalThis<"u"&&globalThis.__VOD_DSH_UI_LEDGER_DISABLED__===!0,D=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(R);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(R,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 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 L(S())).slice(0,8)}_${(await L(t)).slice(0,12)}`}function E(t){if(G)return;const e=JSON.parse(localStorage.getItem(h)||"[]");e.unshift(t),localStorage.setItem(h,JSON.stringify(e.slice(0,A)))}async function z(){let t=localStorage.getItem(I);if(t)return t;const e=await fetch(w+F,{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(I,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 $=!1;async function Y(){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(w+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:D})});if(l.status===200||l.status===201){r.status="accepted";try{localStorage.removeItem(x)}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(k,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,A)))}}function Z({onClose:t}){const e=(()=>{try{return JSON.parse(localStorage.getItem(x)||"null")||{}}catch{return{}}})(),[n,r]=(0,d.useState)(e.content||"");(0,d.useEffect)(()=>{try{localStorage.setItem(x,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(k)||"null")}catch{}if(a&&a.n>0){try{localStorage.removeItem(k)}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 v(a,c){if(/^\d+$/.test(a))return a;try{if(!y){const f=await fetch(w+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 m(){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 z(),f=await fetch(w+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 v(D,u)})});if(f.status===404){c.status="pending-endpoint",E(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(I),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]||"",E(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),E(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:m,children:o?"\u63D0\u4EA4\u4E2D\u2026":"\u63D0\u4EA4"}),children:[(0,s.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)}),i&&(0,s.jsx)("div",{style:C.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(),v=i.offsetWidth||24,m=24;i.style.left=Math.round(y.right-v-8)+"px",i.style.top=Math.round(y.top-m-6)+"px",i.style.width=v+"px",i.style.height=m+"px"};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)})]})}function et(t){if(!D){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 rt="vod-devkit-ui";
|
|
7
7
|
module.exports.inject = ["slots"];
|
|
8
8
|
return module.exports;
|
|
9
9
|
}
|
package/lib/index.js
CHANGED
|
@@ -22,7 +22,8 @@ const PKG_DIR = dirname(dirname(fileURLToPath(import.meta.url)));
|
|
|
22
22
|
const DATA_DIR = join(PKG_DIR, 'data');
|
|
23
23
|
const RUNTIME = join(DATA_DIR, 'runtime.json');
|
|
24
24
|
const API_PREFIX = '/rest/developer/manager/hdvodmngservice/v1';
|
|
25
|
-
const
|
|
25
|
+
const HOARD_PATH = `${API_PREFIX}/external/voices`; // V16 囤积端点(批量/不触发 LLM/结构化回执)
|
|
26
|
+
const SUBMIT_PATH = `${API_PREFIX}/external/voice/submit`; // 旧单条端点:仅 404 回落使用 // V16 已切换:主路径 HOARD_PATH(囤积),本路径仅 404 回落(见 docs/decisions.md D-dsh-4)
|
|
26
27
|
const TOKEN_PATH = `${API_PREFIX}/external/token`;
|
|
27
28
|
const LEDGER_CAP = 200;
|
|
28
29
|
|
|
@@ -32,6 +33,7 @@ export const Config = z.object({
|
|
|
32
33
|
product: z.string().default('').volatile(),
|
|
33
34
|
confirmWrites: z.boolean().default(true).volatile(),
|
|
34
35
|
timeoutSec: z.number().default(30).volatile(),
|
|
36
|
+
receiptGuard: z.string().default('report').volatile(), // D-rguard-1:off|report|enforce,默认 report(零危害只标注)
|
|
35
37
|
});
|
|
36
38
|
|
|
37
39
|
function readCfg(v, fallback) {
|
|
@@ -79,6 +81,19 @@ function transportError(base) {
|
|
|
79
81
|
return null;
|
|
80
82
|
}
|
|
81
83
|
|
|
84
|
+
// VOD-DEVICE:设备锚点(纯 hex 32 位,引擎 [0-9a-f]{8,64} 校验;
|
|
85
|
+
// 含非 hex 字符会静默降 legacy 锚点——UI 半实锤的同类坑)
|
|
86
|
+
function i0Anon() { return true; } // 401 → 匿名令牌重试一次(保持原行为锚点)
|
|
87
|
+
|
|
88
|
+
function deviceNonce() {
|
|
89
|
+
let n = loadRuntime().device_nonce;
|
|
90
|
+
if (!n) {
|
|
91
|
+
n = (randomUUID() + randomUUID()).replace(/[^0-9a-f]/g, '').slice(0, 32);
|
|
92
|
+
saveRuntime({ device_nonce: n });
|
|
93
|
+
}
|
|
94
|
+
return n;
|
|
95
|
+
}
|
|
96
|
+
|
|
82
97
|
async function http(method, path, body, { base, key, timeoutSec, signal }) {
|
|
83
98
|
const guard = transportError(base);
|
|
84
99
|
if (guard) throw new Error(`[${guard.code}] ${guard.error}`); // backstop:守卫在工具入口已拦截,此处兜底
|
|
@@ -91,6 +106,7 @@ async function http(method, path, body, { base, key, timeoutSec, signal }) {
|
|
|
91
106
|
method,
|
|
92
107
|
headers: {
|
|
93
108
|
'content-type': 'application/json',
|
|
109
|
+
'X-Vod-Device-Id': deviceNonce(),
|
|
94
110
|
...(key ? { authorization: `Bearer ${key}` } : {}),
|
|
95
111
|
},
|
|
96
112
|
body: body === undefined ? undefined : JSON.stringify(body),
|
|
@@ -106,6 +122,27 @@ async function http(method, path, body, { base, key, timeoutSec, signal }) {
|
|
|
106
122
|
}
|
|
107
123
|
}
|
|
108
124
|
|
|
125
|
+
// T7i(方案 A,2026-11-05 拍板):产品归因主键化——meta productCatalog
|
|
126
|
+
// ([{id,name}],t_vod_product 运营预置)按名解析平台 id 后提交;
|
|
127
|
+
// ①纯数字=平台 id 透传 ②目录无此名/不可达(含老引擎 404)→ 规范名兼容通道
|
|
128
|
+
// (引擎 name 命中同样补落 product_id)——不静默丢提交。进程内缓存一次。
|
|
129
|
+
const META_PATH = `${API_PREFIX}/external/meta`;
|
|
130
|
+
let _productCatalog = null;
|
|
131
|
+
async function resolveProductId(product, cfg, signal) {
|
|
132
|
+
if (/^\d+$/.test(product)) return product;
|
|
133
|
+
try {
|
|
134
|
+
if (!_productCatalog) {
|
|
135
|
+
const out = await http('GET', META_PATH, undefined, { ...cfg, signal });
|
|
136
|
+
_productCatalog = (out.ok && out.data && out.data.data?.productCatalog)
|
|
137
|
+
|| out.data?.productCatalog || [];
|
|
138
|
+
}
|
|
139
|
+
const hit = _productCatalog.find(
|
|
140
|
+
(x) => String(x?.name || '').toLowerCase() === product.toLowerCase());
|
|
141
|
+
if (hit && hit.id != null) return String(hit.id);
|
|
142
|
+
} catch (e) { /* 目录不可用 → 名字兼容通道 */ }
|
|
143
|
+
return product;
|
|
144
|
+
}
|
|
145
|
+
|
|
109
146
|
async function fetchAnonToken(cfg) {
|
|
110
147
|
const out = await http('POST', TOKEN_PATH, {}, cfg);
|
|
111
148
|
if (out.ok && out.data && (out.data.token || out.data.data?.token)) {
|
|
@@ -128,6 +165,79 @@ function voiceId(source, content, nonce) {
|
|
|
128
165
|
return `ext_${source}_${h}`;
|
|
129
166
|
}
|
|
130
167
|
|
|
168
|
+
// ── D-rguard-1 ReceiptGuard(提交侧原文比对,2026-11-09 验证立项)──
|
|
169
|
+
// 通道实测(dsh-tools 0.2.0 类型源):exec.agent.session.deriveMessages() 的
|
|
170
|
+
// user 轮消息 = 用户逐字原文(append-only 会话日志投影,不经模型)——模型改写
|
|
171
|
+
// 只发生在 args 侧,比对 args.content 与日志原文即可抓改写(dsh headless echo
|
|
172
|
+
// 改字两次实锤均在 args 侧,正是本闸覆盖面)。模型无往日志写用户轮的通道
|
|
173
|
+
// (ToolRunContext.deferContext 是插件自铸上下文,不产生用户轮)。
|
|
174
|
+
// 三档:off=不校验;report(默认)=只标注零危害;enforce=mismatch/unavailable 拒收。
|
|
175
|
+
export function normalizeForGuard(s) {
|
|
176
|
+
return String(s ?? '').replace(/\s+/g, '').toLowerCase();
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
export function bigramSimilarity(a, b) {
|
|
180
|
+
if (!a || !b) return 0;
|
|
181
|
+
if (a === b) return 1;
|
|
182
|
+
const grams = (s) => {
|
|
183
|
+
const m = new Map();
|
|
184
|
+
for (let i = 0; i < s.length - 1; i++) {
|
|
185
|
+
const g = s.slice(i, i + 2);
|
|
186
|
+
m.set(g, (m.get(g) || 0) + 1);
|
|
187
|
+
}
|
|
188
|
+
return m;
|
|
189
|
+
};
|
|
190
|
+
const ga = grams(a), gb = grams(b);
|
|
191
|
+
let inter = 0, total = 0;
|
|
192
|
+
for (const v of ga.values()) total += v;
|
|
193
|
+
for (const [g, v] of gb) {
|
|
194
|
+
total += v;
|
|
195
|
+
if (ga.has(g)) inter += Math.min(v, ga.get(g));
|
|
196
|
+
}
|
|
197
|
+
return total ? (2 * inter) / total : 0;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/** 从会话日志取全部用户轮逐字文本(text 块;tool_result 也是 user role,按块型过滤);不可得=null */
|
|
201
|
+
export function collectUserTurns(session) {
|
|
202
|
+
if (!session || typeof session.deriveMessages !== 'function') return null;
|
|
203
|
+
const msgs = session.deriveMessages();
|
|
204
|
+
const turns = [];
|
|
205
|
+
for (const m of Array.isArray(msgs) ? msgs : []) {
|
|
206
|
+
if (!m || m.role !== 'user' || !Array.isArray(m.content)) continue;
|
|
207
|
+
const text = m.content.filter((b) => b && b.type === 'text').map((b) => b.text).join('\n');
|
|
208
|
+
if (text) turns.push(text);
|
|
209
|
+
}
|
|
210
|
+
return turns.length ? turns : null;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/** 单条 content 判定:规范化整串命中任一用户轮=verified;跨轮忠实聚合按拼接语料命中;
|
|
214
|
+
* 字符二元组相似度 ≥0.5 且规范化长度 ≥10=fuzzy(短内容必须逐字,防止相似度阈值吞掉短改写);
|
|
215
|
+
* 否则 mismatch;原文不可得=unavailable。 */
|
|
216
|
+
export function evaluateVoiceGuard(userTurns, content) {
|
|
217
|
+
if (!Array.isArray(userTurns)) return 'unavailable';
|
|
218
|
+
const c = normalizeForGuard(content);
|
|
219
|
+
if (!c) return 'mismatch';
|
|
220
|
+
const corpus = normalizeForGuard(userTurns.join('\n'));
|
|
221
|
+
if (corpus.includes(c)) return 'verified';
|
|
222
|
+
if (c.length < 10) return 'mismatch'; // 短内容不享受相似度豁免('A问题。补充B' 型胶水词改写)
|
|
223
|
+
let best = 0;
|
|
224
|
+
for (const t of userTurns) best = Math.max(best, bigramSimilarity(c, normalizeForGuard(t)));
|
|
225
|
+
return best >= 0.5 ? 'fuzzy' : 'mismatch';
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
export const RG_MODES = ['off', 'report', 'enforce'];
|
|
229
|
+
|
|
230
|
+
/** 回执汇总:mode + 逐条判定(对账主键=voiceId 顺序位;纯函数可单测) */
|
|
231
|
+
export function rgGuardSummary(verdictMap, total) {
|
|
232
|
+
const verdicts = [];
|
|
233
|
+
for (let i = 0; i < total; i++) verdicts.push(verdictMap.get(i) ?? 'unavailable');
|
|
234
|
+
return {
|
|
235
|
+
verdicts,
|
|
236
|
+
mismatch: verdicts.filter((v) => v === 'mismatch').length,
|
|
237
|
+
unavailable: verdicts.filter((v) => v === 'unavailable').length,
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
|
|
131
241
|
function buildParameters(specs) {
|
|
132
242
|
const properties = {};
|
|
133
243
|
const required = [];
|
|
@@ -143,29 +253,74 @@ function buildParameters(specs) {
|
|
|
143
253
|
const textResult = (obj) => obj; // execute 返回结构化对象;render 负责呈现
|
|
144
254
|
const renderText = (_args, value) => [{ type: 'text', text: JSON.stringify(value, null, 2) }];
|
|
145
255
|
|
|
256
|
+
/**
|
|
257
|
+
* D-anon-ui(安装时配置口径):从部署配置计算要注入页面的全局变量。
|
|
258
|
+
* 纯函数(可单测):product 恒注入;__VOD_DSH_UI_BASE__ 仅跨域部署显式配
|
|
259
|
+
* uiBase 才注入(apiBase 是 server 半自用的绝对地址,浏览器同源策略下
|
|
260
|
+
* 不能直接给页面;UI base 默认同源相对路径,宿主代理 /rest/)。
|
|
261
|
+
*/
|
|
262
|
+
export function uiGlobals(config) {
|
|
263
|
+
const globals = [{
|
|
264
|
+
kind: "global", name: "__VOD_DSH_UI_PRODUCT__",
|
|
265
|
+
value: readCfg(config?.product, '') || '',
|
|
266
|
+
}];
|
|
267
|
+
const uiBase = readCfg(config?.uiBase, '');
|
|
268
|
+
if (uiBase) {
|
|
269
|
+
globals.push({ kind: "global", name: "__VOD_DSH_UI_BASE__", value: uiBase });
|
|
270
|
+
}
|
|
271
|
+
// 企业数据驻留(--no-local-ledger):通知 client 半停写账本+隐藏历史入口
|
|
272
|
+
if (readCfg(config?.noLocalLedger, false)) {
|
|
273
|
+
globals.push({ kind: "global", name: "__VOD_DSH_UI_LEDGER_DISABLED__", value: true });
|
|
274
|
+
}
|
|
275
|
+
return globals;
|
|
276
|
+
}
|
|
277
|
+
|
|
146
278
|
export function apply(ctx, config) {
|
|
279
|
+
// D-anon-ui:部署配置经官方 index-inject 通道下发页面全局(对齐
|
|
280
|
+
// settings-account 的 __DSH_CONTACT_CONFIG__ 同款机制)。产品归因仍是
|
|
281
|
+
// 安装必配(T7d)——未配置=client 半 fail fast 不激活,但不再是
|
|
282
|
+
// "散户死插件":错误信息指向安装命令(npx vod-devkit install
|
|
283
|
+
// --target dsh --product <产品名>)
|
|
284
|
+
ctx.on("webserver/index-inject", (table) => {
|
|
285
|
+
for (const row of uiGlobals(config)) table.push(row);
|
|
286
|
+
});
|
|
147
287
|
const cfg = () => ({
|
|
148
288
|
base: (readCfg(config?.apiBase, 'https://vod-dev.topxtopx.com') || '').replace(/\/+$/, ''),
|
|
149
289
|
key: readCfg(config?.apiKey, '') || '',
|
|
150
290
|
product: readCfg(config?.product, '') || '',
|
|
151
291
|
confirmWrites: readCfg(config?.confirmWrites, true) !== false,
|
|
152
292
|
timeoutSec: readCfg(config?.timeoutSec, 30),
|
|
293
|
+
receiptGuard: RG_MODES.includes(readCfg(config?.receiptGuard, 'report'))
|
|
294
|
+
? readCfg(config?.receiptGuard, 'report') : 'report',
|
|
153
295
|
});
|
|
154
296
|
|
|
155
297
|
const tools = [
|
|
156
298
|
{
|
|
157
299
|
name: 'vod_submit_voices',
|
|
158
|
-
description: '[VOD-unique] Submit agent-product user feedback voices to VOD (write). '
|
|
159
|
-
'
|
|
160
|
-
'
|
|
161
|
-
'
|
|
300
|
+
description: '[VOD-unique] Submit agent-product user feedback voices to VOD (write). '
|
|
301
|
+
+ 'PRECONDITION (overrides everything below): obtain the user\'s explicit consent to submit THIS feedback before calling; '
|
|
302
|
+
+ 'the user merely stating a complaint is NOT consent; never pass confirmed=true without it. '
|
|
303
|
+
+ 'ON FAILURE: tell the user in plain words only (e.g. 已暂存,稍后自动重试). '
|
|
304
|
+
+ 'NEVER expose HTTP status codes, apiKeyFingerprint, tokenTier, stack traces, '
|
|
305
|
+
+ 'tool names (say 提交反馈, never vod_submit_voices) or mechanism words '
|
|
306
|
+
+ '(调用/被拒/护栏/参数) to the user - they are internal diagnostics. '
|
|
307
|
+
+ 'The agent submits on the user\'s behalf; system behavior is described as 系统/稍后自动. '
|
|
308
|
+
+ 'OUTPUT CONTRACT: when explaining results to the user, only cover 收录状态与后续跟进. '
|
|
309
|
+
+ 'NEVER explain internal mechanics to users: 声音来源/渠道字段、计数规则(入库/净新增)、配额、归因——这些是系统内部概念。 '
|
|
310
|
+
+ 'Anonymous tier has NO credentials by design. ' +
|
|
311
|
+
'Each voice = one user feedback (content ≤2000 chars). '
|
|
312
|
+
+ 'content MUST be a faithful transcription of the user\'s own words - '
|
|
313
|
+
+ 'NEVER invent sentiment (e.g. 体验不好) or fabricate content the user did not say. '
|
|
314
|
+
+ 'A bare product name or a question is NOT feedback - ask what the user wants to report. ' +
|
|
315
|
+
'Product attribution is bound at install/deploy time (config product; no runtime product argument exists). ' +
|
|
316
|
+
'Fixed one-time follow-up at confirmation, verbatim: 「方便的话,补充一下遇到这个问题时的操作步骤或期望的表现吗?不方便回复"没有",我直接提交。」' +
|
|
317
|
+
'Answer → reproSteps/expectedBehavior verbatim excerpt, never into content; "没有/跳过"=omit both. ' +
|
|
162
318
|
'Batch ≤50. Returns voiceIds (reconciliation key) + taskIds.',
|
|
163
319
|
parameters: buildParameters({
|
|
164
320
|
voices: {
|
|
165
321
|
type: 'array', required: true,
|
|
166
|
-
description: 'Array of 1-50 voices: {content (required, ≤2000),
|
|
322
|
+
description: 'Array of 1-50 voices: {content (required, ≤2000), userType (optional 企业|个人|未知), reproSteps/expectedBehavior (optional 用户追问补充, only when the fixed one-time follow-up got an answer; never merge into content)}',
|
|
167
323
|
},
|
|
168
|
-
product: { type: 'string', description: 'Target product (overrides plugin config product, e.g. codearts/aishell)' },
|
|
169
324
|
}),
|
|
170
325
|
output: { schema: { type: 'object', additionalProperties: true }, render: renderText },
|
|
171
326
|
async execute(args, exec) {
|
|
@@ -175,20 +330,100 @@ export function apply(ctx, config) {
|
|
|
175
330
|
const voices = Array.isArray(args.voices) ? args.voices : [];
|
|
176
331
|
if (!voices.length) return textResult({ error: 'voices 为空', code: -32001 });
|
|
177
332
|
if (voices.length > 50) return textResult({ error: '单批上限 50 条', code: -32001 });
|
|
178
|
-
//
|
|
179
|
-
//
|
|
180
|
-
//
|
|
181
|
-
let product = String(
|
|
333
|
+
// 归因(D-attrib-A,2026-11-06 拍板,方案 A):归因只由部署配置绑定
|
|
334
|
+
// 决定(安装时定),不读 args——宿主/模型传参自报不采信(对齐 vod_mcp
|
|
335
|
+
// effectiveBotPat 同款收紧;Python 侧实锤宽容口径被模型滥用后统一)
|
|
336
|
+
let product = String(c.product || '').trim(); // 部署配置权威(安装时定),无 args 覆盖
|
|
182
337
|
product = PRODUCT_MAP[product.toLowerCase()] || product;
|
|
338
|
+
product = await resolveProductId(product, c, exec?.signal); // T7i:主键化提交
|
|
183
339
|
const source = 'dsh';
|
|
340
|
+
// D-rguard-1:原文比对(whitelist 通道=会话日志 user 轮)。enforce 档
|
|
341
|
+
// mismatch/unavailable 拒收;report(默认)只标注;off 全跳过。
|
|
342
|
+
const rgMode = c.receiptGuard;
|
|
343
|
+
const userTurns = rgMode === 'off' ? null : collectUserTurns(exec?.agent?.session);
|
|
344
|
+
const rgVerdict = new Map(); // index → verified|fuzzy|mismatch|unavailable
|
|
184
345
|
const accepted = [], taskIds = [], rejected = [];
|
|
185
346
|
let key = c.key;
|
|
347
|
+
// V16 切换(囤积端点):批量一次 POST,title=原文截取、content=用户原话
|
|
348
|
+
// (新端点无 10 字下限,不做模板补齐——P1 数据完整性)。404=引擎未部署 → 回落旧单条
|
|
349
|
+
const hoard = [];
|
|
350
|
+
for (let i = 0; i < voices.length; i++) {
|
|
351
|
+
const v = voices[i] || {};
|
|
352
|
+
const content = String(v.content ?? '').trim();
|
|
353
|
+
if (!content) { rejected.push({ index: i, reason: 'content 为空' }); continue; }
|
|
354
|
+
if (content.length > 2000) { rejected.push({ index: i, reason: `content 超 2000 字(${content.length})` }); continue; }
|
|
355
|
+
if (rgMode !== 'off') {
|
|
356
|
+
const st = evaluateVoiceGuard(userTurns, content);
|
|
357
|
+
rgVerdict.set(i, st);
|
|
358
|
+
if (rgMode === 'enforce' && st !== 'verified' && st !== 'fuzzy') {
|
|
359
|
+
rejected.push({ index: i, reason: st === 'mismatch'
|
|
360
|
+
? 'ReceiptGuard: content 与会话用户原文不一致'
|
|
361
|
+
: 'ReceiptGuard: 会话原文不可得,无法校验' });
|
|
362
|
+
continue;
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
const hv = { title: content.slice(0, 128), content }; // R3:title=用户原文
|
|
366
|
+
// D-followup-impl-2 追问补充透传:仅 trim 非空才含键(未追问/答"没有"=键集合与旧流程一致);引擎同口径截 2000
|
|
367
|
+
// followupStatus(评审八点 #3):三态白名单归一透传,白名单外省键(desc 无预算不宣讲,行为对齐 vod_mcp 单源)
|
|
368
|
+
const DECLINES = new Set(['没有', '无', '没有。', '没了', '跳过', '不方便', '不用了', '不用', '不补充', '算了', '没有了', '没有了。', '不方便说', 'no', 'none', 'skip', 'n/a']);
|
|
369
|
+
for (const f of ['reproSteps', 'expectedBehavior']) {
|
|
370
|
+
const val = String(v[f] ?? '').trim();
|
|
371
|
+
if (val && !DECLINES.has(val.toLowerCase())) hv[f] = val.slice(0, 2000);
|
|
372
|
+
}
|
|
373
|
+
const st = String(v.followupStatus ?? '').trim().toLowerCase();
|
|
374
|
+
if (['not_asked', 'declined', 'answered'].includes(st)) hv.followupStatus = st;
|
|
375
|
+
hoard.push(hv);
|
|
376
|
+
}
|
|
377
|
+
if (hoard.length) {
|
|
378
|
+
let out = await http('POST', HOARD_PATH, { voices: hoard, product },
|
|
379
|
+
{ ...c, key, signal: exec?.signal });
|
|
380
|
+
if (out.status === 401 && i0Anon(c)) {
|
|
381
|
+
const token = await fetchAnonToken({ ...c, key: '', signal: exec?.signal });
|
|
382
|
+
if (token) {
|
|
383
|
+
key = token;
|
|
384
|
+
saveRuntime({ java_key: token, token_tier: 'anonymous' });
|
|
385
|
+
out = await http('POST', HOARD_PATH, { voices: hoard, product },
|
|
386
|
+
{ ...c, key, signal: exec?.signal });
|
|
387
|
+
} else {
|
|
388
|
+
return textResult({
|
|
389
|
+
error: '未配置接入 key 且匿名令牌端点不可用。引导:1) 首次提交时插件自动申请零字段匿名令牌;' +
|
|
390
|
+
'2) 量到上限后联系 VOD 运营升级正式 key;3) 宿主平台整体对接可获宿主 key',
|
|
391
|
+
code: -32012,
|
|
392
|
+
});
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
if (out.status !== 404) {
|
|
396
|
+
if (out.ok) {
|
|
397
|
+
const d = out.data?.data || out.data || {};
|
|
398
|
+
const ids = d.voiceIds || [];
|
|
399
|
+
const sts = d.statuses || [];
|
|
400
|
+
for (let i = 0; i < hoard.length; i++) {
|
|
401
|
+
const vid = ids[i] || '';
|
|
402
|
+
if (vid && sts[i] !== 'skipped') accepted.push(vid);
|
|
403
|
+
else if (vid) { accepted.push(vid); } // skipped=幂等,也回执
|
|
404
|
+
taskIds.push(null); // 囤积语义:无即时任务
|
|
405
|
+
}
|
|
406
|
+
const now = new Date().toISOString().replace('T', ' ').slice(0, 19);
|
|
407
|
+
ledgerAppend(hoard.map((h, i) => ({
|
|
408
|
+
voiceId: ids[i] || '', taskId: null,
|
|
409
|
+
title: h.title.slice(0, 40), product,
|
|
410
|
+
at: now, status: sts[i] === 'skipped' ? 'accepted' : 'accepted',
|
|
411
|
+
})));
|
|
412
|
+
return textResult({
|
|
413
|
+
accepted: accepted.length, voiceIds: accepted,
|
|
414
|
+
taskIds, rejected, path: 'hoarding',
|
|
415
|
+
...(rgMode !== 'off' ? { receiptGuard: rgGuardSummary(rgVerdict, hoard.length) } : {}),
|
|
416
|
+
...(d.productRegistered !== undefined ? { productRegistered: d.productRegistered } : {}),
|
|
417
|
+
});
|
|
418
|
+
}
|
|
419
|
+
// 非 404 非 2xx → 回落旧单条(如 401 已处理;此处为兼容异常响应)
|
|
420
|
+
}
|
|
421
|
+
}
|
|
186
422
|
for (let i = 0; i < voices.length; i++) {
|
|
187
423
|
const v = voices[i] || {};
|
|
188
424
|
const content = String(v.content ?? '').trim();
|
|
189
425
|
if (!content) { rejected.push({ index: i, reason: 'content 为空' }); continue; }
|
|
190
426
|
if (content.length > 2000) { rejected.push({ index: i, reason: `content 超 2000 字(${content.length})` }); continue; }
|
|
191
|
-
const scene = String(v.scene ?? '').slice(0, 128);
|
|
192
427
|
const nonce = randomUUID().replace(/-/g, '').slice(0, 8); // 调用级幂等、跨调用保声量
|
|
193
428
|
const vid = voiceId(source, content, nonce);
|
|
194
429
|
const desc = content.length >= 10 ? content : `${content} [vod-devkit]`;
|
|
@@ -199,7 +434,6 @@ export function apply(ctx, config) {
|
|
|
199
434
|
product,
|
|
200
435
|
source,
|
|
201
436
|
...(v.userType ? { customer: v.userType } : {}),
|
|
202
|
-
...(scene ? { scene } : {}),
|
|
203
437
|
};
|
|
204
438
|
const call = () => http('POST', SUBMIT_PATH, body, { ...c, key, signal: exec?.signal });
|
|
205
439
|
let out = await call();
|
|
@@ -233,7 +467,8 @@ export function apply(ctx, config) {
|
|
|
233
467
|
title: String((voices[i] || {}).content ?? '').slice(0, 40),
|
|
234
468
|
product, at: now,
|
|
235
469
|
})));
|
|
236
|
-
return textResult({ accepted: accepted.length, voiceIds: accepted, taskIds, rejected
|
|
470
|
+
return textResult({ accepted: accepted.length, voiceIds: accepted, taskIds, rejected,
|
|
471
|
+
...(rgMode !== 'off' ? { receiptGuard: rgGuardSummary(rgVerdict, voices.length) } : {}) });
|
|
237
472
|
},
|
|
238
473
|
},
|
|
239
474
|
{
|
|
@@ -264,12 +499,17 @@ export function apply(ctx, config) {
|
|
|
264
499
|
const c = cfg();
|
|
265
500
|
const rt = loadRuntime();
|
|
266
501
|
const fp = (s) => (s ? createHash('sha1').update(s).digest('hex').slice(0, 8) : null);
|
|
502
|
+
// D-anon-ui:匿名档=散户默认正常态。无 key 不是"未配置"故障,
|
|
503
|
+
// 显式标注防模型误诊(实锤:模型曾把 null 读成"凭据没配置"端给用户)
|
|
504
|
+
const authMode = c.key ? 'key-configured' : (rt.token_tier ? 'anonymous-token' : 'anonymous (auto on first submit)');
|
|
267
505
|
return textResult({
|
|
268
506
|
version: '0.1.0',
|
|
269
507
|
host: 'dsh',
|
|
270
508
|
apiBase: c.base,
|
|
271
509
|
apiKeyFingerprint: fp(c.key),
|
|
272
510
|
tokenTier: rt.token_tier || null,
|
|
511
|
+
authMode,
|
|
512
|
+
authNote: c.key ? null : 'No key configured - this is the DEFAULT anonymous tier (normal), auto token on first submit. NOT a misconfiguration.',
|
|
273
513
|
ledgerEntries: Array.isArray(rt.submissions) ? rt.submissions.length : 0,
|
|
274
514
|
});
|
|
275
515
|
},
|
|
@@ -288,8 +528,8 @@ export function apply(ctx, config) {
|
|
|
288
528
|
kind: 'ask',
|
|
289
529
|
reason: `vod-write:${exec.name}`,
|
|
290
530
|
displayReason: {
|
|
291
|
-
en: 'Submit user feedback
|
|
292
|
-
zh: '向 VOD
|
|
531
|
+
en: 'Submit this user feedback voice to VOD?',
|
|
532
|
+
zh: '向 VOD 提交这条用户反馈声音?',
|
|
293
533
|
},
|
|
294
534
|
};
|
|
295
535
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-vod-devkit",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "0.2.1",
|
|
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",
|