dsh-vod-devkit 0.0.0-stage → 0.1.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/README.md +43 -2
- package/cordis.patch.yml +10 -0
- package/lib/client.js +10 -0
- package/lib/index.js +304 -0
- package/package.json +47 -3
package/README.md
CHANGED
|
@@ -1,3 +1,44 @@
|
|
|
1
|
-
#
|
|
1
|
+
# dsh-vod-devkit
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
VOD 用户声音采集插件 —— DeepSeek Harness (dsh) 薄壳。
|
|
4
|
+
|
|
5
|
+
## 形态
|
|
6
|
+
|
|
7
|
+
- 纯采集:3 工具(`vod_submit_voices` / `vod_list_submitted` / `vod_devkit_info`)
|
|
8
|
+
- 插件=引擎客户端,只走 HTTPS(VOD external API),不 import 任何引擎模块
|
|
9
|
+
- 与 vod-devkit(MCP 形态,同仓 `../vod_mcp`)语义对齐:
|
|
10
|
+
- voiceId = f(source, content, 调用级 nonce):同调用幂等、跨调用保声量
|
|
11
|
+
- product 归一映射(小写 codearts → CodeArts;引擎实测小写 400)
|
|
12
|
+
- 归因三层:配置绑定 → 显式传参 → 报错引导(绝不静默默认)
|
|
13
|
+
- 无 key/401 → POST /external/token 零字段匿名令牌 → 本地落盘 → 重试一次
|
|
14
|
+
- 本地账本 data/runtime.json(cap 200 环形,读改写只动目标键)
|
|
15
|
+
|
|
16
|
+
## 安装
|
|
17
|
+
|
|
18
|
+
```
|
|
19
|
+
dsh plugin --profile <name> add dsh-vod-devkit # npm 发布后
|
|
20
|
+
dsh plugin --profile <name> add github:yangaiwu/vod-devkit#dsh # 亦可
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
装后在 profile 的 cordis.patch.yml 激活(与包内 cordis.patch.yml 同语义):
|
|
24
|
+
|
|
25
|
+
```yaml
|
|
26
|
+
- insert:
|
|
27
|
+
- id: vod-devkit
|
|
28
|
+
name: 'dsh-vod-devkit'
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## 配置(dsh 插件设置)
|
|
32
|
+
|
|
33
|
+
| 字段 | 默认 | 说明 |
|
|
34
|
+
|---|---|---|
|
|
35
|
+
| apiBase | https://vod-dev.topxtopx.com | VOD external API 基址 |
|
|
36
|
+
| apiKey | (空) | 缺省走零字段匿名令牌;灰度期可用运营签发 key |
|
|
37
|
+
| product | (空) | 本机产品归因绑定(如 codearts);空且调用未传参时报错引导 |
|
|
38
|
+
| confirmWrites | true | 写操作走 dsh 审批通道(tools/pre-execute → ask) |
|
|
39
|
+
| timeoutSec | 30 | HTTP 超时 |
|
|
40
|
+
|
|
41
|
+
## 安全
|
|
42
|
+
|
|
43
|
+
- apiKey 标记 `.role('secret')`:不跨 wire 回传,展示一律 sha1[:8] 指纹
|
|
44
|
+
- 写操作默认弹确认;单批 ≤50;content ≤2000 逐条校验
|
package/cordis.patch.yml
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
# dsh-vod-devkit bundle patch — applied when this plugin is installed.
|
|
2
|
+
# Registers 3 VOD user-voice collection tools on ctx.tools:
|
|
3
|
+
# vod_submit_voices / vod_list_submitted / vod_devkit_info
|
|
4
|
+
#
|
|
5
|
+
# Transport: HTTPS to the VOD external API (no local CLI subprocess needed).
|
|
6
|
+
# Config (dsh settings): apiBase / apiKey(secret) / product / confirmWrites.
|
|
7
|
+
# No key → automatic zero-field anonymous token on first submit (VOD-KEY).
|
|
8
|
+
- insert:
|
|
9
|
+
- id: vod-devkit
|
|
10
|
+
name: 'dsh-vod-devkit'
|
package/lib/client.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
window.__ModuleLoader__.load({
|
|
2
|
+
id: "dsh-vod-devkit",
|
|
3
|
+
factory: (require) => {
|
|
4
|
+
var module = { exports: {} };
|
|
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";
|
|
7
|
+
module.exports.inject = ["slots"];
|
|
8
|
+
return module.exports;
|
|
9
|
+
}
|
|
10
|
+
});
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,304 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* dsh-vod-devkit — VOD 用户声音采集插件(dsh 薄壳)。
|
|
3
|
+
*
|
|
4
|
+
* 形态纪律(与 vod-devkit MCP 侧一致):
|
|
5
|
+
* - 插件=引擎的客户端,只走 HTTPS,不 import 任何引擎模块
|
|
6
|
+
* - 纯采集形态:submit / 本地账本查询 / 自述,共 3 工具
|
|
7
|
+
* - 写操作默认走 dsh 审批通道(tools/pre-execute → kind:'ask')
|
|
8
|
+
* - voiceId = f(source, content, 调用级nonce):同调用幂等、跨调用保声量
|
|
9
|
+
* - key 缺失/401 → 自动 POST /external/token 零字段令牌 → 落本地 → 重试一次
|
|
10
|
+
* - 本地账本(data/runtime.json,cap 200 环形)只动目标键,读改写
|
|
11
|
+
*/
|
|
12
|
+
import z from '@deepseek-ai/schemastery';
|
|
13
|
+
import { createHash, randomUUID } from 'node:crypto';
|
|
14
|
+
import { fileURLToPath } from 'node:url';
|
|
15
|
+
import { dirname, join } from 'node:path';
|
|
16
|
+
import { readFileSync, writeFileSync, existsSync, mkdirSync } from 'node:fs';
|
|
17
|
+
|
|
18
|
+
export const name = 'vod-devkit';
|
|
19
|
+
export const inject = ['tools'];
|
|
20
|
+
|
|
21
|
+
const PKG_DIR = dirname(dirname(fileURLToPath(import.meta.url)));
|
|
22
|
+
const DATA_DIR = join(PKG_DIR, 'data');
|
|
23
|
+
const RUNTIME = join(DATA_DIR, 'runtime.json');
|
|
24
|
+
const API_PREFIX = '/rest/developer/manager/hdvodmngservice/v1';
|
|
25
|
+
const SUBMIT_PATH = `${API_PREFIX}/external/voice/submit`; // TODO(引擎VOD-VOI上线):切换为 `${API_PREFIX}/external/voices`(囤积入库、批量、不触发LLM分析、逐条结构化回执)——切换点仅此一行+body 字段核对,见 docs/decisions.md D-dsh-4
|
|
26
|
+
const TOKEN_PATH = `${API_PREFIX}/external/token`;
|
|
27
|
+
const LEDGER_CAP = 200;
|
|
28
|
+
|
|
29
|
+
export const Config = z.object({
|
|
30
|
+
apiBase: z.string().default('https://vod-dev.topxtopx.com').volatile(),
|
|
31
|
+
apiKey: z.string().default('').volatile().role('secret'),
|
|
32
|
+
product: z.string().default('').volatile(),
|
|
33
|
+
confirmWrites: z.boolean().default(true).volatile(),
|
|
34
|
+
timeoutSec: z.number().default(30).volatile(),
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
function readCfg(v, fallback) {
|
|
38
|
+
if (v === undefined || v === null) return fallback;
|
|
39
|
+
if (typeof v === 'object' && typeof v.get === 'function') {
|
|
40
|
+
const got = v.get();
|
|
41
|
+
return got === undefined || got === null ? fallback : got;
|
|
42
|
+
}
|
|
43
|
+
return v;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// ── 本地账本:每次文件读改写,只动目标键(防内存合并回写陈旧配置) ──
|
|
47
|
+
function loadRuntime() {
|
|
48
|
+
try { return JSON.parse(readFileSync(RUNTIME, 'utf8')); } catch { return {}; }
|
|
49
|
+
}
|
|
50
|
+
function saveRuntime(patch) {
|
|
51
|
+
const rt = loadRuntime();
|
|
52
|
+
const next = { ...rt, ...patch };
|
|
53
|
+
if (Array.isArray(next.submissions) && next.submissions.length > LEDGER_CAP) {
|
|
54
|
+
next.submissions = next.submissions.slice(-LEDGER_CAP);
|
|
55
|
+
}
|
|
56
|
+
mkdirSync(DATA_DIR, { recursive: true });
|
|
57
|
+
writeFileSync(RUNTIME, JSON.stringify(next, null, 2));
|
|
58
|
+
}
|
|
59
|
+
function ledgerAppend(entries) {
|
|
60
|
+
const rt = loadRuntime();
|
|
61
|
+
const subs = Array.isArray(rt.submissions) ? rt.submissions : [];
|
|
62
|
+
saveRuntime({ submissions: [...subs, ...entries].slice(-LEDGER_CAP) });
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// ── HTTP ──
|
|
66
|
+
// ── 传输守卫(与 vod_mcp tools.py -32014 同构):Bearer key/匿名令牌不得明文过公网 ──
|
|
67
|
+
function transportError(base) {
|
|
68
|
+
if (!base) return null;
|
|
69
|
+
let u; try { u = new URL(base); } catch { return { error: `apiBase 非法 URL: ${base}`, code: -32014 }; }
|
|
70
|
+
const host = u.hostname;
|
|
71
|
+
const loopback = host === 'localhost' || host === '127.0.0.1' || host === '::1' || host === '[::1]';
|
|
72
|
+
if (u.protocol !== 'https:' && !loopback) {
|
|
73
|
+
return {
|
|
74
|
+
error: `上游 ${u.protocol}//${host} 非 https 且非本机回环——Bearer key 明文外发被拒` +
|
|
75
|
+
'(插件配置 apiBase 改为 https:// 地址)',
|
|
76
|
+
code: -32014,
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
return null;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
async function http(method, path, body, { base, key, timeoutSec, signal }) {
|
|
83
|
+
const guard = transportError(base);
|
|
84
|
+
if (guard) throw new Error(`[${guard.code}] ${guard.error}`); // backstop:守卫在工具入口已拦截,此处兜底
|
|
85
|
+
const ctrl = new AbortController();
|
|
86
|
+
const timer = setTimeout(() => ctrl.abort(), (timeoutSec || 30) * 1000);
|
|
87
|
+
const onOuterAbort = () => ctrl.abort();
|
|
88
|
+
signal?.addEventListener('abort', onOuterAbort);
|
|
89
|
+
try {
|
|
90
|
+
const res = await fetch(`${base}${path}`, {
|
|
91
|
+
method,
|
|
92
|
+
headers: {
|
|
93
|
+
'content-type': 'application/json',
|
|
94
|
+
...(key ? { authorization: `Bearer ${key}` } : {}),
|
|
95
|
+
},
|
|
96
|
+
body: body === undefined ? undefined : JSON.stringify(body),
|
|
97
|
+
signal: ctrl.signal,
|
|
98
|
+
});
|
|
99
|
+
const text = await res.text();
|
|
100
|
+
let data = null;
|
|
101
|
+
try { data = text ? JSON.parse(text) : null; } catch { data = { raw: text }; }
|
|
102
|
+
return { status: res.status, ok: res.ok, data };
|
|
103
|
+
} finally {
|
|
104
|
+
clearTimeout(timer);
|
|
105
|
+
signal?.removeEventListener('abort', onOuterAbort);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
async function fetchAnonToken(cfg) {
|
|
110
|
+
const out = await http('POST', TOKEN_PATH, {}, cfg);
|
|
111
|
+
if (out.ok && out.data && (out.data.token || out.data.data?.token)) {
|
|
112
|
+
return out.data.token || out.data.data.token;
|
|
113
|
+
}
|
|
114
|
+
return null;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
const PRODUCT_MAP = { // 引擎枚举归一(实测:小写 codearts → 400 空响应;Python 侧同款映射)
|
|
118
|
+
// 已知差距(M2/M3 不适用于 dsh 形态):本表硬编码,不拉 GET /external/meta——
|
|
119
|
+
// 引擎 VodExternalProducts 变更时需同步此表(含 kb-query-auth 合入后的 AISHELL/nameAliases)。
|
|
120
|
+
// 详见 docs/decisions.md D-dsh-3。
|
|
121
|
+
agentarts: 'AgentArts', codearts: 'CodeArts', dataarts: 'DataArts',
|
|
122
|
+
maas: 'MaaS', obs: 'OBS', officeclaw: 'OfficeClaw',
|
|
123
|
+
modelarts: 'MaaS',
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
function voiceId(source, content, nonce) {
|
|
127
|
+
const h = createHash('sha1').update(content + nonce).digest('hex').slice(0, 12);
|
|
128
|
+
return `ext_${source}_${h}`;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function buildParameters(specs) {
|
|
132
|
+
const properties = {};
|
|
133
|
+
const required = [];
|
|
134
|
+
for (const [k, spec] of Object.entries(specs)) {
|
|
135
|
+
properties[k] = { type: spec.type, description: spec.description || k };
|
|
136
|
+
if (spec.required) required.push(k);
|
|
137
|
+
}
|
|
138
|
+
const r = { type: 'object', properties, additionalProperties: false };
|
|
139
|
+
if (required.length) r.required = required;
|
|
140
|
+
return r;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
const textResult = (obj) => obj; // execute 返回结构化对象;render 负责呈现
|
|
144
|
+
const renderText = (_args, value) => [{ type: 'text', text: JSON.stringify(value, null, 2) }];
|
|
145
|
+
|
|
146
|
+
export function apply(ctx, config) {
|
|
147
|
+
const cfg = () => ({
|
|
148
|
+
base: (readCfg(config?.apiBase, 'https://vod-dev.topxtopx.com') || '').replace(/\/+$/, ''),
|
|
149
|
+
key: readCfg(config?.apiKey, '') || '',
|
|
150
|
+
product: readCfg(config?.product, '') || '',
|
|
151
|
+
confirmWrites: readCfg(config?.confirmWrites, true) !== false,
|
|
152
|
+
timeoutSec: readCfg(config?.timeoutSec, 30),
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
const tools = [
|
|
156
|
+
{
|
|
157
|
+
name: 'vod_submit_voices',
|
|
158
|
+
description: '[VOD-unique] Submit agent-product user feedback voices to VOD (write). ' +
|
|
159
|
+
'Each voice = one user feedback (content ≤2000 chars, scene optional). ' +
|
|
160
|
+
'Product attribution ("host-is-product", no whitelist): explicit arg → config product → ' +
|
|
161
|
+
'host identity (DSH). Host-reported products pass through as-is. ' +
|
|
162
|
+
'Batch ≤50. Returns voiceIds (reconciliation key) + taskIds.',
|
|
163
|
+
parameters: buildParameters({
|
|
164
|
+
voices: {
|
|
165
|
+
type: 'array', required: true,
|
|
166
|
+
description: 'Array of 1-50 voices: {content (required, ≤2000), scene (optional ≤128), userType (optional 企业|个人|未知)}',
|
|
167
|
+
},
|
|
168
|
+
product: { type: 'string', description: 'Target product (overrides plugin config product, e.g. codearts/aishell)' },
|
|
169
|
+
}),
|
|
170
|
+
output: { schema: { type: 'object', additionalProperties: true }, render: renderText },
|
|
171
|
+
async execute(args, exec) {
|
|
172
|
+
const c = cfg();
|
|
173
|
+
const guard = transportError(c.base); // 传输守卫:非 https 且非回环 → 拒绝(-32014,对齐 vod_mcp)
|
|
174
|
+
if (guard) return textResult(guard);
|
|
175
|
+
const voices = Array.isArray(args.voices) ? args.voices : [];
|
|
176
|
+
if (!voices.length) return textResult({ error: 'voices 为空', code: -32001 });
|
|
177
|
+
if (voices.length > 50) return textResult({ error: '单批上限 50 条', code: -32001 });
|
|
178
|
+
// 归因(「宿主即产品」口径,2026-11-03 拍板·不设白名单):显式传参 > 配置绑定
|
|
179
|
+
// (安装时默认=宿主名)> 缺省 DSH(本插件就装在 dsh 里);白名单废除,
|
|
180
|
+
// 宿主自报产品原样上送(引擎宽松归一),不再 -32013 本地拦截
|
|
181
|
+
let product = String(args.product || c.product || 'DSH').trim();
|
|
182
|
+
product = PRODUCT_MAP[product.toLowerCase()] || product;
|
|
183
|
+
const source = 'dsh';
|
|
184
|
+
const accepted = [], taskIds = [], rejected = [];
|
|
185
|
+
let key = c.key;
|
|
186
|
+
for (let i = 0; i < voices.length; i++) {
|
|
187
|
+
const v = voices[i] || {};
|
|
188
|
+
const content = String(v.content ?? '').trim();
|
|
189
|
+
if (!content) { rejected.push({ index: i, reason: 'content 为空' }); continue; }
|
|
190
|
+
if (content.length > 2000) { rejected.push({ index: i, reason: `content 超 2000 字(${content.length})` }); continue; }
|
|
191
|
+
const scene = String(v.scene ?? '').slice(0, 128);
|
|
192
|
+
const nonce = randomUUID().replace(/-/g, '').slice(0, 8); // 调用级幂等、跨调用保声量
|
|
193
|
+
const vid = voiceId(source, content, nonce);
|
|
194
|
+
const desc = content.length >= 10 ? content : `${content} [vod-devkit]`;
|
|
195
|
+
const body = {
|
|
196
|
+
voiceId: vid,
|
|
197
|
+
title: content.slice(0, 128), // R3:title=用户原文(分析消费),模板只允许出现在 description
|
|
198
|
+
description: desc,
|
|
199
|
+
product,
|
|
200
|
+
source,
|
|
201
|
+
...(v.userType ? { customer: v.userType } : {}),
|
|
202
|
+
...(scene ? { scene } : {}),
|
|
203
|
+
};
|
|
204
|
+
const call = () => http('POST', SUBMIT_PATH, body, { ...c, key, signal: exec?.signal });
|
|
205
|
+
let out = await call();
|
|
206
|
+
if (out.status === 401 && i === 0) {
|
|
207
|
+
// 零字段匿名令牌:401 → 自动取令牌 → 落本地 → 重试一次
|
|
208
|
+
const token = await fetchAnonToken({ ...c, key: '', signal: exec?.signal });
|
|
209
|
+
if (token) {
|
|
210
|
+
key = token;
|
|
211
|
+
saveRuntime({ java_key: token, token_tier: 'anonymous' });
|
|
212
|
+
out = await call();
|
|
213
|
+
} else {
|
|
214
|
+
return textResult({
|
|
215
|
+
error: '未配置接入 key 且匿名令牌端点不可用。引导:1) 首次提交时插件自动申请零字段匿名令牌;' +
|
|
216
|
+
'2) 量到上限后联系 VOD 运营升级正式 key;3) 宿主平台整体对接可获宿主 key',
|
|
217
|
+
code: -32012,
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
if (out.ok) {
|
|
222
|
+
accepted.push(vid);
|
|
223
|
+
taskIds.push(out.data?.data?.taskId ?? null);
|
|
224
|
+
} else {
|
|
225
|
+
const msg = JSON.stringify(out.data || {}).slice(0, 160);
|
|
226
|
+
if (msg.includes('Duplicate entry')) { accepted.push(vid); taskIds.push(null); }
|
|
227
|
+
else rejected.push({ index: i, reason: msg && msg !== '{}' ? msg : `HTTP ${out.status}` });
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
const now = new Date().toISOString().replace('T', ' ').slice(0, 19);
|
|
231
|
+
ledgerAppend(accepted.map((vid, i) => ({
|
|
232
|
+
voiceId: vid, taskId: taskIds[i],
|
|
233
|
+
title: String((voices[i] || {}).content ?? '').slice(0, 40),
|
|
234
|
+
product, at: now,
|
|
235
|
+
})));
|
|
236
|
+
return textResult({ accepted: accepted.length, voiceIds: accepted, taskIds, rejected });
|
|
237
|
+
},
|
|
238
|
+
},
|
|
239
|
+
{
|
|
240
|
+
name: 'vod_list_submitted',
|
|
241
|
+
description: '[VOD-unique] Read-only: list voices submitted from THIS machine (local ledger, cap 200, newest first). ' +
|
|
242
|
+
'Scope: local machine only — authoritative cross-machine query arrives with the engine-side endpoint (VOD-VOI layer 2).',
|
|
243
|
+
parameters: buildParameters({
|
|
244
|
+
limit: { type: 'number', description: '1-100, default 20, newest first' },
|
|
245
|
+
}),
|
|
246
|
+
output: { schema: { type: 'object', additionalProperties: true }, render: renderText },
|
|
247
|
+
async execute(args) {
|
|
248
|
+
const rt = loadRuntime();
|
|
249
|
+
const subs = Array.isArray(rt.submissions) ? rt.submissions : [];
|
|
250
|
+
const limit = Math.max(1, Math.min(100, Number(args.limit) || 20));
|
|
251
|
+
return textResult({
|
|
252
|
+
scope: 'local-machine',
|
|
253
|
+
total: subs.length,
|
|
254
|
+
voices: subs.slice(-limit).reverse(),
|
|
255
|
+
});
|
|
256
|
+
},
|
|
257
|
+
},
|
|
258
|
+
{
|
|
259
|
+
name: 'vod_devkit_info',
|
|
260
|
+
description: '[VOD-unique] Read-only plugin self-description: version, api endpoint (fingerprinted), auth state (fingerprinted, never plaintext), local ledger size.',
|
|
261
|
+
parameters: buildParameters({}),
|
|
262
|
+
output: { schema: { type: 'object', additionalProperties: true }, render: renderText },
|
|
263
|
+
async execute() {
|
|
264
|
+
const c = cfg();
|
|
265
|
+
const rt = loadRuntime();
|
|
266
|
+
const fp = (s) => (s ? createHash('sha1').update(s).digest('hex').slice(0, 8) : null);
|
|
267
|
+
return textResult({
|
|
268
|
+
version: '0.1.0',
|
|
269
|
+
host: 'dsh',
|
|
270
|
+
apiBase: c.base,
|
|
271
|
+
apiKeyFingerprint: fp(c.key),
|
|
272
|
+
tokenTier: rt.token_tier || null,
|
|
273
|
+
ledgerEntries: Array.isArray(rt.submissions) ? rt.submissions.length : 0,
|
|
274
|
+
});
|
|
275
|
+
},
|
|
276
|
+
},
|
|
277
|
+
];
|
|
278
|
+
|
|
279
|
+
for (const t of tools) ctx.tools.register(t);
|
|
280
|
+
|
|
281
|
+
// 写操作确认:dsh 审批通道(web 端弹确认框),拒绝则不执行
|
|
282
|
+
if (typeof ctx.on === 'function') {
|
|
283
|
+
try {
|
|
284
|
+
ctx.on('tools/pre-execute', (exec, next) => {
|
|
285
|
+
if (exec.name !== 'vod_submit_voices') return next();
|
|
286
|
+
if (!cfg().confirmWrites) return next();
|
|
287
|
+
return {
|
|
288
|
+
kind: 'ask',
|
|
289
|
+
reason: `vod-write:${exec.name}`,
|
|
290
|
+
displayReason: {
|
|
291
|
+
en: 'Submit user feedback voices to VOD?',
|
|
292
|
+
zh: '向 VOD 提交用户反馈声音(入库即触发分析)?',
|
|
293
|
+
},
|
|
294
|
+
};
|
|
295
|
+
});
|
|
296
|
+
} catch (err) {
|
|
297
|
+
console.warn(`[dsh-vod-devkit] pre-execute registration failed: ${String(err)}`);
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
console.log(`[dsh-vod-devkit] Registered ${tools.length} tools, apiBase=${cfg().base}` +
|
|
302
|
+
(cfg().key ? ', key=set' : ', key=none (auto anonymous-token on first submit)') +
|
|
303
|
+
(cfg().product ? `, product=${cfg().product}` : ', product=unset (must be set or passed per call)'));
|
|
304
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,50 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-vod-devkit",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.1.0",
|
|
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
|
+
"type": "module",
|
|
6
|
+
"main": "lib/index.js",
|
|
7
|
+
"files": [
|
|
8
|
+
"lib/**/*.js",
|
|
9
|
+
"cordis.patch.yml",
|
|
10
|
+
"README.md"
|
|
11
|
+
],
|
|
12
|
+
"license": "MIT",
|
|
13
|
+
"dsh": {
|
|
14
|
+
"bundle": {
|
|
15
|
+
"patch": "./cordis.patch.yml"
|
|
16
|
+
},
|
|
17
|
+
"client": {
|
|
18
|
+
"platform": "web",
|
|
19
|
+
"inject": [
|
|
20
|
+
"@deepseek-ai/dsh-client-ui-chat"
|
|
21
|
+
]
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"engines": {
|
|
25
|
+
"node": ">=18"
|
|
26
|
+
},
|
|
27
|
+
"peerDependencies": {
|
|
28
|
+
"@deepseek-ai/cordis": ">=4.0.0",
|
|
29
|
+
"@deepseek-ai/dsh-tools": ">=0.0.1-0",
|
|
30
|
+
"@deepseek-ai/schemastery": ">=3.18.0"
|
|
31
|
+
},
|
|
32
|
+
"keywords": [
|
|
33
|
+
"dsh",
|
|
34
|
+
"deepseek-harness",
|
|
35
|
+
"dsh-plugin",
|
|
36
|
+
"vod",
|
|
37
|
+
"feedback"
|
|
38
|
+
],
|
|
39
|
+
"devDependencies": {
|
|
40
|
+
"esbuild": "^0.28.2",
|
|
41
|
+
"react": "^19.3.1"
|
|
42
|
+
},
|
|
43
|
+
"exports": {
|
|
44
|
+
".": "./lib/index.js",
|
|
45
|
+
"./client": "./lib/client.js"
|
|
46
|
+
},
|
|
47
|
+
"scripts": {
|
|
48
|
+
"build-client": "esbuild src/client.jsx --jsx=automatic --format=cjs --minify --outfile=/tmp/client-cjs.js && python3 scripts/wrap_client.py"
|
|
49
|
+
}
|
|
6
50
|
}
|