@kingsoftcloud/agentkit-harness-node 0.0.23 → 0.0.25
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/dist/engine-view.html +1 -1
- package/dist/index.mjs +87 -3
- package/dist/rpc-entry.mjs +87 -3
- package/package.json +2 -2
- package/src/native/model-deepseek-dsml.mjs +86 -0
- package/src/native/model-openai-chat.mjs +10 -3
package/dist/engine-view.html
CHANGED
|
@@ -670,5 +670,5 @@ button.harness-tool-summary { border: 0; background: none; color: inherit; font:
|
|
|
670
670
|
.harness-activity-children { border-left: 1px solid var(--harness-border); margin: 8px 0 8px 7px; padding-left: 16px; display: flex; flex-direction: column; gap: 8px; }
|
|
671
671
|
`;var La=8,Po=24,Oo=1;function Ma({clientHeight:e,scrollHeight:t,scrollTop:n},r){let i=Math.max(0,t-e),o={showTop:i>Oo&&n>Oo,showBottom:i>Oo&&n<i-Oo};return r?.showTop===o.showTop&&r?.showBottom===o.showBottom?r:o}function py({showTop:e,showBottom:t}){if(!e&&!t)return;let n=e?`transparent 0px, black ${Po}px`:`black 0px, black ${Po}px`,r=t?`black calc(100% - ${Po}px), transparent 100%`:`black calc(100% - ${Po}px), black 100%`,i=`linear-gradient(to bottom, ${n}, ${r})`;return{WebkitMaskImage:i,maskImage:i,WebkitMaskRepeat:"no-repeat",maskRepeat:"no-repeat",WebkitMaskSize:"100% 100%",maskSize:"100% 100%"}}function hy(e){if(!e)return;let t="linear-gradient(to right, transparent 0, black 16px, black calc(100% - 16px), transparent 100%)";return{WebkitMaskImage:t,maskImage:t,WebkitMaskRepeat:"no-repeat",maskRepeat:"no-repeat",WebkitMaskSize:"100% 100%",maskSize:"100% 100%"}}function hp(e){let{createElement:t,useState:n,useCallback:r,useRef:i,useEffect:o,useMemo:l,Fragment:a}=e;function s(c){let{state:f,className:y,workspaceRoot:v,labels:k,locale:x,showPlanDock:C,theme:M="system",renderText:E,initiallyExpandedThoughts:F,initiallyExpandedTools:B,autoFollow:K,styleSheet:V,onJumpLatest:j,onOpenFile:O,onCopy:U,onOpenTerminal:N,onRetrieveFullDiff:W,onInspectTool:we,onOpenSubagent:Oe,loadImage:Q}=c||{},[$,he]=n(()=>new Map((F||[]).map(Z=>[Z,!0]))),[xt,Sp]=n(()=>new Map((B||[]).map(Z=>[Z,!0]))),[_p,Ep]=n(()=>new Map),[Ao,Pa]=n(!0),[Fo,Ip]=n(!1),St=i(null),Oa=i(new Set),Aa=i(new Map);o(()=>{if(typeof window!="object"||typeof window.matchMedia!="function")return;let Z=window.matchMedia("(prefers-reduced-motion: reduce)"),ue=()=>Ip(!!Z.matches);return ue(),typeof Z.addEventListener=="function"?(Z.addEventListener("change",ue),()=>Z.removeEventListener("change",ue)):(Z.addListener(ue),()=>Z.removeListener(ue))},[]),o(()=>{if(!K)return;let Z=St.current;if(!Z||typeof Z.addEventListener!="function")return;let ue=()=>{let me=Z.scrollHeight-Z.scrollTop-Z.clientHeight<La;Pa(me)};return Z.addEventListener("scroll",ue,{passive:!0}),()=>Z.removeEventListener("scroll",ue)},[K]),o(()=>{K&&Ao&&St.current&&(St.current.scrollTop=St.current.scrollHeight)},[f,Ao,K]),o(()=>{let Z=Ur(f),ue=new Map($),me=!1;for(let rt of Z){if(rt.kind!=="thought")continue;let Gr=Aa.current.get(rt.id)??!1,ce=!!rt.streaming;Gr&&!ce&&!Oa.current.has(rt.id)&&ue.get(rt.id)!==!1&&(ue.set(rt.id,!1),me=!0),Aa.current.set(rt.id,ce)}me&&he(ue)},[f,$]);let Cp=r(Z=>{let ue=Z.target;if(!ue||!ue.closest)return;let me=ue.closest("[data-action]");if(me){let ce=me.getAttribute("data-action");if(ce==="jump-latest"){j?j():St.current&&(St.current.scrollTop=St.current.scrollHeight,Pa(!0));return}if(ce==="open-file"&&O){O({path:me.getAttribute("data-path")||"",kind:me.getAttribute("data-kind")||"file",callId:me.getAttribute("data-call-id")||void 0});return}if(ce==="copy"&&U){U(me.getAttribute("data-copy-text")||"");return}if(ce==="open-terminal"&&N){N({callId:me.getAttribute("data-call-id")||"",cwd:me.getAttribute("data-cwd")||void 0});return}if(ce==="retrieve-diff"&&W){W({callId:me.getAttribute("data-call-id")||"",path:me.getAttribute("data-path")||""});return}if(ce==="open-subagent"&&Oe){let _t=me.getAttribute("data-call-id"),Qt=f.items.find(Gn=>Gn.callId===_t)?.child;Qt&&Oe({callId:_t,...Qt});return}if(ce==="inspect-tool"&&we){we({callId:me.getAttribute("data-call-id")||""});return}}let rt=ue.closest('summary[data-testid="work-history-toggle"]');if(rt){Z.preventDefault();let ce=rt.parentElement,_t=ce.getAttribute("data-item-id");Ep(Qt=>new Map(Qt).set(_t,!ce.open));return}let Gr=ue.closest('summary[data-testid="thought-toggle"], summary[data-testid="tool-toggle"]');if(Gr){let ce=Gr.parentElement,_t=ce.getAttribute("data-item-id"),Qt=ce.getAttribute("data-call-id");Z.preventDefault(),_t?(Oa.current.add(_t),he(Gn=>{let Yn=new Map(Gn);return Yn.set(_t,!ce.open),Yn})):Qt&&Sp(Gn=>{let Yn=new Map(Gn);return Yn.set(Qt,!ce.open),Yn})}},[f,j,O,U,N,W,we,Oe]),Np={ref:St,onClick:Cp,className:y?`harness-timeline-shell ${y}`:"harness-timeline-shell","data-reduced-motion":Fo?"true":"false","data-theme":M},Fa=l(()=>({onOpenFile:O,onCopy:U,onOpenTerminal:N,onRetrieveFullDiff:W,onInspectTool:we,onOpenSubagent:Oe,loadImage:Q}),[O,U,N,W,we,Oe,Q]),Da=l(()=>new WeakMap,[xt,k,x,v,!!O,!!U,!!N,!!W,!!we,!!Oe]),Tp=l(()=>new WeakMap,[Da,Fo]),Lp=dp(f,{thoughtOpen:$,toolOpen:xt,historyOpen:_p,labels:k,locale:x,showPlanDock:C,workspaceRoot:v,following:Ao,rootProps:Np,toolViewCache:Da,...Fa}),ja=u(Lp,E,Fa,e,Fo,Tp);return V===null?ja:t(a,null,t("style",{"data-harness-ui":!0},V===void 0?pp:V),ja)}function u(c,f,y,v,k,x){if(c==null||c===!1)return null;if(typeof c!="object")return c;let{createElement:C}=v,M=c.props?.["data-testid"],E=c.props||{};if(M==="user-image")return C(d,{key:E["data-item-id"],image:E.image,loadImage:y.loadImage,id:E["data-item-id"]});if(M==="tool-block"&&x?.has(c))return x.get(c);if(M==="execute-command")return C(g,{key:E["data-call-id"],type:c.type,props:E,renderChildren:(c.children||[]).map(j=>u(j,f,y,v,k,x))});if(M==="thought-body")return C(m,{key:E["data-item-id"],streaming:E["data-streaming"]==="true",axis:"vertical",mask:"vertical",reducedMotion:k,renderChildren:(c.children||[]).map(j=>u(j,f,y,v,k,x)),type:c.type,props:c.props});if(M==="bash-output-preview-full"||M==="bash-result-output")return C(m,{key:E["data-call-id"]||M,streaming:E["data-streaming"]==="true",axis:"vertical",freezeWhileReading:!0,mask:"vertical",renderChildren:(c.children||[]).map(j=>u(j,f,y,v,k,x)),type:c.type,props:c.props});if(M==="thought-preview")return C(w,{key:E["data-item-id"]||M,reducedMotion:k,renderChildren:(c.children||[]).map(j=>u(j,f,y,v,k,x)),type:c.type,props:c.props});let F=M==="text-block"&&E["data-role"]!=="user",B=c.children?.[0]?.children?.[0],K=F&&f?[f(String(B??""),{streaming:E["data-streaming"]==="true"})]:(c.children||[]).map(j=>u(j,f,y,v,k,x)),V=C(c.type,{key:E["data-item-id"]??E["data-call-id"],...E},...K);return M==="tool-block"&&x?.set(c,V),V}function d({image:c,loadImage:f,id:y}){let{attachment:v,previewUrl:k}=c,[x,C]=n(()=>ko(k??f?.peek?.(v))),[M,E]=n(!1),[F,B]=n(0),[K,V]=n(!1),j=i(null),O=JSON.stringify(v??k);o(()=>{let N=!0;return E(!1),C(ko(k??(v&&f?.peek?.(v)))),v&&f?Promise.resolve().then(()=>f(v)).then(W=>{if(N){let we=ko(W);C(we),E(!we)}}).catch(()=>{N&&E(!0)}):k||E(!0),()=>{N=!1}},[O,f,F]),o(()=>{K?j.current?.showModal?.():j.current?.close?.()},[K]);let U=v?.name||c.name||"\u56FE\u7247";return t("span",{className:"harness-user-image","data-testid":"user-image","data-item-id":y},x?t("button",{type:"button",className:"harness-image-preview","aria-label":`\u67E5\u770B\u56FE\u7247\uFF1A${U}`,onClick:()=>V(!0)},t("img",{src:x,alt:U,onError:()=>{C(null),E(!0)}})):t("button",{type:"button",disabled:!M,onClick:()=>B(N=>N+1)},M?`${U} \xB7 \u70B9\u51FB\u91CD\u65B0\u52A0\u8F7D`:`${U} \xB7 \u52A0\u8F7D\u4E2D\u2026`),K?t("dialog",{ref:j,className:"harness-image-dialog","aria-label":`\u56FE\u7247\u9884\u89C8\uFF1A${U}`,onClose:()=>V(!1)},t("button",{type:"button",onClick:()=>V(!1)},"\u5173\u95ED"),t("img",{src:x,alt:U})):null)}function g({renderChildren:c,type:f,props:y}){let v=i(null),[k,x]=n(!1),[C,M]=n(!1);return o(()=>{let E=v.current;if(!E||k)return;let F=()=>M(E.scrollHeight>E.clientHeight+1);if(F(),typeof ResizeObserver>"u")return;let B=new ResizeObserver(F);return B.observe(E),()=>B.disconnect()},[c,k]),e.createElement(f,y,e.createElement("div",{ref:v,className:"harness-command-viewport","data-expanded":String(k),tabIndex:k?0:void 0},c[0]),C||k?e.createElement("button",{type:"button",className:"harness-command-toggle","aria-expanded":k,onClick:()=>{v.current&&(v.current.scrollTop=0),x(E=>!E)}},y[k?"data-collapse-label":"data-expand-label"]):null,...c.slice(1))}function m({streaming:c,axis:f,mask:y,freezeWhileReading:v=!1,reducedMotion:k,renderChildren:x,type:C,props:M}){let E=i(null),F=i(!0),B=i(0),K=i(c),[V,j]=n(null),[O,U]=n({showTop:!1,showBottom:!1}),N=v?V===null:F.current,W=V??x;o(()=>{let Q=E.current;Q&&(c&&(K.current=!0),(v?K.current:c)&&N&&(f==="vertical"?Q.scrollTop=Q.scrollHeight:Q.scrollLeft=Q.scrollWidth,B.current=Q.scrollTop),y==="vertical"&&U($=>Ma({clientHeight:Q.clientHeight,scrollHeight:Q.scrollHeight,scrollTop:Q.scrollTop},$)))}),o(()=>{let Q=E.current;if(!Q||y!=="vertical"||typeof ResizeObserver>"u")return;let $=()=>{U(xt=>Ma({clientHeight:Q.clientHeight,scrollHeight:Q.scrollHeight,scrollTop:Q.scrollTop},xt))};$();let he=new ResizeObserver($);return he.observe(Q),()=>he.disconnect()},[y]);let we=Q=>{let $=Q.currentTarget,he=f==="vertical"?$.scrollHeight-$.scrollTop-$.clientHeight<=La:$.scrollWidth-$.scrollLeft-$.clientWidth<=La;v&&K.current&&N&&$.scrollTop<B.current&&!he?j(W):v&&!N&&he?j(null):!v&&F.current&&$.scrollTop<B.current&&!he?F.current=!1:!v&&!F.current&&he&&(F.current=!0),B.current=$.scrollTop,y==="vertical"&&U(xt=>Ma({clientHeight:$.clientHeight,scrollHeight:$.scrollHeight,scrollTop:$.scrollTop},xt))};o(()=>{c&&(F.current=!0)},[c]);let Oe={ref:E,onScroll:we,"data-following":N?"true":"false"};if(y==="vertical"){let Q=O.showTop&&O.showBottom?"both":O.showTop?"top":O.showBottom?"bottom":"none";Oe["data-reasoning-scroll-mask"]=Q;let $=py(O);$&&(Oe.style={...M.style||{},...$})}return e.createElement(C,{...M,...Oe},...W)}function w({reducedMotion:c,renderChildren:f,type:y,props:v}){let k={key:v["data-line-key"],text:v["data-line-text"]},[x,C]=n(()=>({current:k,previous:null,animate:!1})),M=i(null);o(()=>(M.current=Sf(k,O=>C(U=>O.refresh?{...U,current:O.current}:O)),()=>{M.current.dispose(),M.current=null}),[]),o(()=>{M.current?.update(k,!c)},[k.key,k.text,c]);let E=i(null),[F,B]=n(!1);o(()=>{let O=E.current;if(!O)return;O.scrollLeft=O.scrollWidth;let U=O.scrollWidth>O.clientWidth+1;if(B(we=>we===U?we:U),typeof ResizeObserver>"u")return;let N=()=>{O.scrollLeft=O.scrollWidth,B(O.scrollWidth>O.clientWidth+1)},W=new ResizeObserver(N);return W.observe(O),()=>W.disconnect()});let K=F?"both":"none",V=hy(F),j={ref:E,"data-reasoning-streaming-mask":K};return V&&(j.style={...v.style||{},...V}),e.createElement(y,{...v,...j},e.createElement("span",{className:"harness-summary-roll","data-animated":String(x.animate)},x.animate&&x.previous?e.createElement("span",{key:"out:"+x.previous.key,className:"harness-summary-out","aria-hidden":!0},x.previous.text):null,e.createElement("span",{key:x.current.key,className:x.animate?"harness-summary-in":""},x.current.text)))}function _({path:c,seq:f,resolve:y,zh:v,application:k=!1}){let[x,C]=n(null),[M,E]=n(!1),[F,B]=n(!1),K=i(null);if(o(()=>{let N=new AbortController;return K.current=N,y({path:c,seq:f,application:k},N.signal).then(W=>{N.signal.aborted||C(W)}).catch(()=>{}),()=>N.abort()},[c,f,y,k]),!x?.href)return null;let V=k?v?"\u8FD0\u884C\u4E2D\u7684\u5E94\u7528":"Running application":c.split("/").at(-1),j=v?`\u6253\u5F00 ${V}`:`Open ${V}`,O=async()=>{let N=K.current.signal;B(!1),E(!0);try{await x.openInSidebar(N)}catch{N.aborted||B(!0)}finally{N.aborted||E(!1)}},U=(N,W)=>t("a",{href:x.href,target:"_blank",rel:"noopener noreferrer","aria-label":W},N);return t("div",{className:"harness-delivery","data-testid":"web-delivery"},t("span",{className:"harness-delivery-icon"},t("svg",{viewBox:"0 0 24 24",width:20,height:20,fill:"none",stroke:"currentColor",strokeWidth:1.5,"aria-hidden":!0},t("circle",{cx:12,cy:12,r:9}),t("ellipse",{cx:12,cy:12,rx:4,ry:9}),t("path",{d:"M3 12h18"}))),t("span",{className:"harness-delivery-name"},t("strong",{title:c},V),t("small",null,k?c:v?"\u7F51\u7AD9 \xB7 HTML":"Website \xB7 HTML")),x.openInSidebar?t("div",{className:"harness-delivery-actions"},t("button",{type:"button",disabled:M,onClick:O,"aria-label":j},M?v?"\u6B63\u5728\u6253\u5F00\u2026":"Opening\u2026":v?"\u6253\u5F00":"Open"),t("details",{className:"harness-delivery-menu"},t("summary",{"aria-label":v?"\u66F4\u591A\u6253\u5F00\u65B9\u5F0F":"More ways to open"},t("svg",{width:14,height:14,viewBox:"0 0 24 24","aria-hidden":!0,fill:"none",stroke:"currentColor"},t("path",{d:"m6 9 6 6 6-6",strokeWidth:2}))),U(v?"\u5728\u65B0\u6807\u7B7E\u9875\u6253\u5F00":"Open in a new tab")),F?t("span",{role:"status"},v?"\u65E0\u6CD5\u6253\u5F00\u4FA7\u680F\u9884\u89C8":"Could not open the sidebar preview"):null):U(v?"\u6253\u5F00":"Open",j))}function I({seq:c,load:f,openFile:y,resolveWebDelivery:v,deliveries:k,zh:x}){let[C,M]=n(null);o(()=>{let N=new AbortController;if(!(!f||c===void 0))return f(c,N.signal).then(W=>{N.signal.aborted||M(W)}).catch(()=>{}),()=>N.abort()},[c,f]);let{files:E=[],screenshots:F=[],truncated:B,application:K}=C??{},V=N=>Number.isSafeInteger(N.added)&&N.added>=0&&Number.isSafeInteger(N.removed)&&N.removed>=0,j=(N,W)=>t("span",{className:"harness-delivery-delta"},t("span",null,`+${N}`),t("span",null,`\u2212${W}`)),O=E.length&&!B&&E.every(V)?j(E.reduce((N,W)=>N+W.added,0),E.reduce((N,W)=>N+W.removed,0)):null,U=x?`${E.length}${B?"+":""} \u4E2A\u6587\u4EF6\u5DF2\u66F4\u6539`:`${E.length}${B?"+":""} ${E.length===1?"file":"files"} changed`;return t(e.Fragment,null,...v?[...K?[{path:K.path,seq:c,application:!0}]:[],...(k??[]).filter(N=>N.path!==K?.path)].map(N=>t(_,{key:N.path,...N,resolve:v,zh:x})):[],E.length?t("details",{className:"harness-delivery-changes","data-testid":"delivery-changes"},t("summary",null,U,O),t("ul",null,...E.map(N=>t("li",{key:N.path},N.deleted||!y?t("span",null,N.path):t("button",{type:"button",onClick:()=>y({path:N.path,kind:"file"})},N.path),V(N)?j(N.added,N.removed):null)))):null,...F.map(({path:N,href:W})=>t("a",{key:N,className:"harness-delivery-image","data-testid":"delivery-screenshot",href:W,target:"_blank",rel:"noopener noreferrer"},t("img",{src:W,alt:N.split("/").at(-1),loading:"lazy"}))))}function P({state:c,reply:f,onCopy:y,onBranch:v,assistantActions:k,containerProps:x,deliveries:C,resolveWebDelivery:M,deliverySeq:E,loadDeliveryEvidence:F,locale:B="zh-CN",...K}){let[V,j]=n(null),O=c.items.find($=>$.id===c.finalAnswerId),U=async()=>{try{let $=O.sourceMessageId?c.items.filter(he=>he.kind==="text"&&he.sourceMessageId===O.sourceMessageId).map(he=>he.text).join(`
|
|
672
672
|
|
|
673
|
-
`):O.text;await(y?y($):navigator.clipboard.writeText($)),j("copied")}catch{j("failed")}},N=B.startsWith("zh"),W=V==="copied"?N?"\u5DF2\u590D\u5236":"Copied":N?"\u590D\u5236\u56DE\u590D":"Copy reply",we=N?"\u4ECE\u8FD9\u91CC\u65B0\u5EFA\u5206\u652F":"Branch from here",Oe=($,he,xt)=>t("button",{type:"button",title:$,"aria-label":$,onClick:he},t("svg",{viewBox:"0 0 24 24",width:16,height:16,fill:"none",stroke:"currentColor",strokeWidth:1.5,strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0},t("path",{d:xt}))),Q=f?.time??c.taskEndedAt;return t("article",{...x,className:"harness-turn","data-testid":"harness-turn"},t(s,{state:c,onCopy:y,locale:B,...K}),c.taskState==="failed"&&c.taskError?t("details",{className:"harness-turn-error"},t("summary",null,N?"\u672C\u8F6E\u672A\u5B8C\u6210\uFF0C\u67E5\u770B\u539F\u56E0":"This turn did not complete. View reason"),t("p",null,c.taskError)):c.taskState==="paused"&&c.taskReason==="provider_unavailable"&&c.taskMessage?t("p",{className:"harness-turn-model-pause",role:"status"},c.taskMessage):null,O?.kind==="text"&&!O.streaming&&(M||F)?t(I,{key:E,seq:E,load:F,deliveries:C,openFile:K.onOpenFile,resolveWebDelivery:M,zh:N}):null,O?.kind==="text"&&!O.streaming?t("div",{className:"harness-reply-actions",role:"group","aria-label":N?"\u56DE\u590D\u64CD\u4F5C":"Reply actions"},Oe(W,U,V==="copied"?"m5 12 4 4L19 6":"M8 8h11v12H8zM5 16H4V4h11v1"),k,f?.branchable&&v?Oe(we,()=>v(f.seq),"M5 19 19 5m-6 0h6v6M5 10v9h9"):null,typeof Q=="number"&&Number.isFinite(Q)?t("time",{dateTime:new Date(Q).toISOString()},new Intl.DateTimeFormat(B,{hour:"2-digit",minute:"2-digit",hour12:!1}).format(Q)):null,V==="failed"?t("span",{role:"status"},N?"\u65E0\u6CD5\u590D\u5236":"Unable to copy"):null):null)}function p({state:c,loading:f,error:y,omittedRows:v=0,omittedChars:k=0,labels:x={},...C}){return e.createElement("section",{className:"harness-subagent-pane","data-testid":"subagent-pane","aria-readonly":!0},y?e.createElement("p",{role:"alert"},y):f?e.createElement("p",{role:"status"},x.childSyncing||"Syncing"):null,v||k?e.createElement("p",{className:"harness-subagent-window-notice"},x.childOmitted||"Earlier rows or long fields are omitted in this observation window."):null,c?e.createElement(s,{state:c,labels:x,...C}):null)}return{HarnessTimeline:s,HarnessTurn:P,SubagentPane:p}}function Kn(){return{protocolVersion:1,taskId:null,taskTitle:null,runId:null,taskState:L.Idle,taskReason:null,taskMessage:null,taskOutcome:null,taskSummary:null,taskError:null,taskStartedAt:null,taskEndedAt:null,finalAnswerId:null,verificationRequired:null,modelRequestActive:!1,modelRequestRetry:!1,modelRequestPurpose:null,modelWait:null,modelThinkingId:null,contextMarkers:[],subagents:new Map,items:[],seen:new Set,pendingThinking:new Set,plan:null,planSummary:null,lastSeq:null}}function my(e,t){e||(e=Kn());let n;try{n=Tf(t)}catch{return e}if(e.seen.has(n.id))return e;let r=Ey(e);return r.seen=new Set(e.seen),r.seen.add(n.id),r.items=e.items.slice(),r.pendingThinking=new Set(e.pendingThinking),n.seq!=null&&(r.lastSeq==null||n.seq>r.lastSeq)&&(r.lastSeq=n.seq),gy(r,n),r}function gp(e,t){let n=e||Kn();for(let r of Array.isArray(t)?t:[])n=my(n,r);return n}function gy(e,t){switch(t.type){case R.TaskStarted:return yy(e,t);case R.TaskState:return mp(e,t);case R.TaskFinished:return vy(e,t);case R.ModelWait:e.taskState===L.Running&&(e.modelWait={retryAt:t.retryAt,httpStatus:t.httpStatus});return;case R.ModelRequest:t.active&&(e.modelWait=null),t.active&&e.taskState===L.Paused&&e.taskReason==="provider_unavailable"&&mp(e,{state:L.Running,reason:null,message:null}),(!t.active||e.modelThinkingId!==t.itemId)&&Ra(e),e.modelRequestActive=t.active,e.modelRequestRetry=t.active&&t.retry===!0,e.modelRequestPurpose=t.active?t.purpose??null:null,e.modelThinkingId=t.active?t.itemId:null;return;case R.TextPreview:{if(!e.modelRequestActive||!t.responseId||t.responseId!==e.modelThinkingId||!t.itemId||!t.text)return;let n=qr(e,t.itemId);if(n>=0&&!e.items[n].preview)return;Kr(e,t);let r={kind:"text",id:t.itemId,text:t.text,responseId:t.responseId,streaming:!0,preview:!0,receivedChars:t.receivedChars};n>=0?e.items[n]=r:e.items.push(r);return}case R.TextDelta:return wy(e,t);case R.TextDone:return ky(e,t);case R.ThinkingStart:return xy(e,t);case R.ThinkingDelta:return Sy(e,t);case R.ThinkingDone:return yp(e,t);case R.SubagentBound:{if(!t.callId)return;e.subagents=new Map(e.subagents??[]),e.subagents.set(t.callId,t.child);let n=vp(e,t.callId);n>=0&&(fn(e,n).child=t.child);return}case R.ToolPreview:{if(!t.previewId)return;Kr(e,t);let n=e.items.findIndex(i=>i.kind==="tool-preview"&&i.id===t.previewId),r={kind:"tool-preview",id:t.previewId,name:t.name,input:t.input,receivedChars:t.receivedChars,streaming:!0,...t.responseId?{responseId:t.responseId}:{}};n>=0?e.items[n]=r:e.items.push(r);return}case R.ToolScheduled:return Qn(e,t,b.Scheduled);case R.ToolStarted:return Qn(e,t,b.Running);case R.ToolState:return Qn(e,t,t.status,t);case R.ToolProgress:return Qn(e,t,b.Running,t);case R.ToolResult:return Qn(e,t,b.Completed,t);case R.ToolError:return Qn(e,t,b.Failed,t);case R.ContextMarker:{let n=[...e.contextMarkers??[]],r=n.findIndex(i=>i.id===t.marker.id);r<0?n.push(t.marker):n[r]=t.marker,e.contextMarkers=n;return}case R.PlanUpdated:return _y(e,t);default:return e}}function yy(e,t){if(e.taskId=t.taskId||e.taskId,e.taskTitle=t.title||e.taskTitle,e.runId=t.runId||e.runId,oa(e.taskState,L.Running)||e.taskState===L.Idle)e.taskState=L.Running;else return;e.taskOutcome=null,e.taskSummary=null,e.taskError=null,e.taskReason=null,e.taskMessage=null,t.startedAt!==void 0&&(e.taskStartedAt=t.startedAt),e.taskEndedAt=null,e.finalAnswerId=null}function Ra(e){e.modelThinkingId&&(yp(e,{itemId:e.modelThinkingId}),e.items=e.items.filter(t=>!(t.kind==="tool-preview"||t.preview===!0)||t.responseId!==e.modelThinkingId))}function mp(e,t){oa(e.taskState,t.state)&&(e.taskState=t.state,t.state!==L.Running&&(Ra(e),e.modelWait=null,e.modelRequestActive=!1,e.modelRequestRetry=!1,e.modelRequestPurpose=null,e.modelThinkingId=null),e.taskReason=t.reason,e.taskMessage=t.message,(t.state===L.Running||t.state===L.Recovered)&&(e.taskOutcome=null,e.taskError=null))}function vy(e,t){Ra(e),e.modelWait=null,e.modelRequestActive=!1,e.modelRequestRetry=!1,e.modelRequestPurpose=null,e.modelThinkingId=null,e.verificationRequired=t.verificationRequired,e.taskOutcome=t.outcome,e.taskSummary=t.summary,e.taskError=t.error||null,e.taskReason=t.reason||null,e.taskEndedAt=t.endedAt??null,e.finalAnswerId=["completed","unverified"].includes(t.outcome)&&!t.error&&t.executionState!=="interrupted"?t.finalAnswerId??null:null,t.outcome===Vt.Completed?e.taskState=L.Completed:t.outcome===Vt.Cancelled?e.taskState=L.Cancelled:t.outcome===Vt.Failed?e.taskState=L.Failed:t.outcome===Vt.Blocked?e.taskState=L.Blocked:t.outcome===Vt.Unverified&&(e.taskState=L.Unverified),t.executionState===L.Interrupted&&(e.taskState=L.Interrupted);for(let n=0;n<e.items.length;n+=1){let r=e.items[n],i=r.streaming,o=r.kind==="tool"&&(r.status===b.Scheduled||r.status===b.Running);(i||o)&&(e.items[n]={...r,streaming:!1,...o?{status:b.Interrupted}:{}})}e.pendingThinking=new Set}function wy(e,t){if(!t.itemId)return;t.delta&&Kr(e,t);let n=qr(e,t.itemId);if(n>=0){let r=fn(e,n);r.text=(r.text||"")+t.delta,r.streaming=!0,t.responseId&&(r.responseId=t.responseId);return}e.items.push({kind:"text",id:t.itemId,text:t.delta,streaming:!0,...t.responseId?{responseId:t.responseId}:{}})}function ky(e,t){t.text&&Kr(e,t);let n=qr(e,t.itemId);if(n>=0&&e.items[n].kind==="text"){let r=fn(e,n);t.text!==void 0&&(r.text=t.text),r.streaming=!1,t.sourceMessageId&&(r.sourceMessageId=t.sourceMessageId),t.responseId&&(r.responseId=t.responseId),t.role==="user"&&t.images&&(r.images=t.images)}else t.itemId&&(t.text||t.images?.length)&&e.items.push({kind:"text",id:t.itemId,text:t.text??"",role:t.role??"assistant",streaming:!1,...t.images?.length?{images:t.images}:{},...t.responseId?{responseId:t.responseId}:{},...t.sourceMessageId?{sourceMessageId:t.sourceMessageId}:{}})}function xy(e,t){t.itemId&&e.pendingThinking.add(t.itemId)}function Sy(e,t){if(!t.itemId||!t.delta&&e.pendingThinking.has(t.itemId))return;let n=qr(e,t.itemId);if(n>=0){let r=fn(e,n);r.text=(r.text||"")+t.delta,r.streaming=!0,t.responseId&&(r.responseId=t.responseId);return}t.delta&&(e.pendingThinking.delete(t.itemId),e.items.push({kind:"thought",id:t.itemId,text:t.delta,streaming:!0,provider:!0,...t.responseId?{responseId:t.responseId}:{}}))}function yp(e,t){e.pendingThinking.delete(t.itemId);let n=qr(e,t.itemId);if(n>=0&&e.items[n].kind==="thought"){let r=fn(e,n);t.text!==void 0&&(r.text=t.text),r.streaming=!1,t.sourceMessageId&&(r.sourceMessageId=t.sourceMessageId),t.responseId&&(r.responseId=t.responseId),t.duration!=null&&(r.duration=t.duration)}else t.itemId&&t.text&&e.items.push({kind:"thought",id:t.itemId,text:t.text,streaming:!1,provider:!0,...t.responseId?{responseId:t.responseId}:{},...t.sourceMessageId?{sourceMessageId:t.sourceMessageId}:{},...t.duration!=null?{duration:t.duration}:{}})}function Qn(e,t,n,r){if(!t.callId)return;n===b.Scheduled&&Kr(e,t);let i=vp(e,t.callId);if(i>=0){let l=fn(e,i);if([b.Completed,b.Failed,b.NotDispatched].includes(l.status)&&![b.Completed,b.Failed,b.NotDispatched].includes(n)){t.type===R.ToolScheduled&&(l.name=t.name||l.name,l.input=t.input,t.responseId&&(l.responseId=t.responseId));return}t.type===R.ToolScheduled&&(l.name=t.name||l.name,l.input=t.input,t.responseId&&(l.responseId=t.responseId)),e.subagents?.has(t.callId)&&(l.child=e.subagents.get(t.callId)),r&&t.type===R.ToolProgress&&(l.progress=r.progress||r.message||null,r.display&&r.display.kind&&(l.display=r.display)),r&&t.type===R.ToolResult&&(l.result=r.result,l.display=r.display),r&&t.type===R.ToolError&&(l.error=r.error),t.type===R.ToolState&&(l.progress=t.message),l.status=n;return}let o={kind:"tool",callId:t.callId,...t.responseId?{responseId:t.responseId}:{},...e.subagents?.has(t.callId)?{child:e.subagents.get(t.callId)}:{},name:t.name||"tool",input:t.input||{},status:n};r&&t.type===R.ToolResult&&(o.result=r.result,o.display=r.display),r&&t.type===R.ToolError&&(o.error=r.error),r&&t.type===R.ToolProgress&&(o.progress=r.progress||r.message||null,r.display&&r.display.kind&&(o.display=r.display)),e.items.push(o)}function Kr(e,t){if(t.responseId)for(let n=0;n<e.items.length;n++){let r=e.items[n];r.kind==="thought"&&r.streaming&&r.responseId===t.responseId&&(fn(e,n).streaming=!1)}}function _y(e,t){e.plan=t.items.length?t.items:null;let n=t.items.filter(l=>l.status==="completed").length,r=Number.isSafeInteger(t.totalCount)&&t.totalCount>=t.items.length?t.totalCount:t.items.length,i=r-t.items.length,o=Number.isSafeInteger(t.completedCount)&&t.completedCount>=n&&t.completedCount<=n+i?t.completedCount:n;e.planSummary={totalCount:r,completedCount:o,omittedItems:i}}function qr(e,t){for(let n=0;n<e.items.length;n+=1)if(e.items[n].id===t)return n;return-1}function vp(e,t){for(let n=0;n<e.items.length;n+=1){let r=e.items[n];if(r.kind==="tool"&&r.callId===t)return n}return-1}function fn(e,t){let n={...e.items[t]};return e.items[t]=n,n}function Ey(e){return Object.assign({},e,{items:e.items,seen:e.seen,pendingThinking:e.pendingThinking,plan:e.plan})}var Iy="agentkit.engine-event/v1",za="agentkit.engine-view/v1",Cy="submit_final_output",Ny=new Set(["completed","unverified","blocked","failed","cancelled"]),be=e=>typeof e=="string"&&e.trim().length>0,Ty=e=>e==null?{}:typeof e=="object"?e:{value:e};function Ly(e){let t=le(e.title)?.family,{ok:n,path:r,diff_additions:i,diff_deletions:o}=e.result??{};if(!(!["edit","write"].includes(t)||n!==!0||!be(r)||![i,o].every(l=>Number.isSafeInteger(l)&&l>=0)))return{kind:"file_edit",files:[{path:r,changeStat:{added:i,removed:o},operationKind:t==="write"?"write":"edit"}]}}function My(e){return e.title==="failed"||e.status==="failed"?"failed":["canceled","cancelled"].includes(e.title)||["canceled","cancelled"].includes(e.status)?"cancelled":e.status==="verified"?"completed":Ny.has(e.status)?e.status:e.title==="completed"?"completed":"unverified"}function Ry(e,t){let n=e?.error_type??e?.code??e?.error_code,r=e?.error_message??e?.message;if(!be(n))return{message:be(r)?r:`\u5DE5\u5177 ${t??""} \u672A\u6210\u529F`.trim()};let i=n==="command_policy_blocked"&&e?.executed===!1?e.finding?.detail:void 0;return{code:n,...be(i)?{message:i}:be(r)?{message:r}:{},...Number.isSafeInteger(e.failed_edit_index)&&e.failed_edit_index>=0?{failed_edit_index:e.failed_edit_index}:{}}}function zy(e,{runId:t="run",time:n,startedAt:r=n}={}){if(!e||e.schema!==Iy||!Number.isSafeInteger(e.seq))return[];let i=So,o=a=>`${t}:${e.seq}:${a}`,l=typeof e.requestId=="string"&&/^[a-f0-9]{64}$/.test(e.requestId)?`${t}:thought:${e.requestId}`:o("thought");switch(e.kind){case"run.started":return[{v:i,id:o("start"),type:"task.started",taskId:t,runId:t,startedAt:r}];case"todo.initialized":case"todo.updated":return Object.hasOwn(e,"plan")?[{v:i,id:o("todo"),type:"plan.updated",items:e.plan?.items??[],completedCount:e.plan?.completedCount,totalCount:e.plan?.totalCount}]:[];case"effect.prepared":case"effect.settled":return e.category==="model"&&e.title==="request"?[{v:i,id:o("model-request"),type:"model.request",active:e.kind==="effect.prepared",retry:e.kind==="effect.prepared"&&e.retry===!0,...e.purpose==="compaction"?{purpose:"compaction"}:{},itemId:l}]:[];case"model.completed":{let a=[];if(be(e.thinking)&&a.push({v:i,id:o("thought-done"),type:"thinking.done",itemId:l,text:e.thinking}),be(e.detail)&&(e.title==="initial_plan"||Array.isArray(e.calls)&&e.calls.length)){let s=`${t}:note:${e.seq}`;a.push({v:i,id:o("note"),type:"text.delta",itemId:s,delta:e.detail},{v:i,id:o("note-done"),type:"text.done",itemId:s})}for(let s of Array.isArray(e.calls)?e.calls:[])!be(s?.callId)||!be(s?.name)||s.name===Cy||a.push({v:i,id:o(`call:${s.callId}`),type:"tool.scheduled",callId:s.callId,name:s.name,input:Ty(s.arguments)},{v:i,id:o(`run:${s.callId}`),type:"tool.started",callId:s.callId});return a}case"model.stream_interrupted":return be(e.thinking)?[{v:i,id:o("thought-done"),type:"thinking.done",itemId:l,text:e.thinking}]:[];case"tool.completed":{if(!be(e.callId))return[];if(e.status==="uncertain")return[{v:i,id:o("uncertain"),type:"tool.state",callId:e.callId,status:"uncertain"}];let a=e.status==="ok"?Ly(e):void 0;if(e.status!=="ok")return[{v:i,id:o("error"),type:"tool.error",callId:e.callId,error:Ry(e.result,e.title)}];let s=[{v:i,id:o("result"),type:"tool.result",callId:e.callId,result:e.result??null,...a?{display:a}:{}}];return e.title==="TodoWrite"&&Array.isArray(e.result?.todos)&&s.push({v:i,id:o("todo-receipt"),type:"plan.updated",items:e.result.todos.map((u,d)=>({...u,id:`todo:${d}`}))}),s}case"model.retry_scheduled":return Number.isSafeInteger(e.retryAt)&&e.retryAt>0?[{v:i,id:o("model-wait"),type:"model.wait",retryAt:e.retryAt,httpStatus:e.httpStatus}]:[];case"model.retry_exhausted":return[{v:i,id:o("paused"),type:"task.state",state:"paused",reason:"provider_unavailable",message:e.modelError}];case"run.terminal":{let a=[],s=`${t}:final`;return be(e.detail)&&a.push({v:i,id:o("final"),type:"text.delta",itemId:s,delta:e.detail},{v:i,id:o("final-done"),type:"text.done",itemId:s}),e.title==="paused"?[...a,{v:i,id:o("paused"),type:"task.state",state:"paused",reason:e.reason??null}]:e.title==="interrupted"?[{v:i,id:o("finished"),type:"task.finished",outcome:"unverified",executionState:"interrupted",endedAt:n,reason:e.reason}]:[...a,{v:i,id:o("finished"),type:"task.finished",outcome:My(e),endedAt:n,...a.length?{finalAnswerId:s}:{},...e.reason?{reason:e.reason}:{},...be(e.modelError)?{error:e.modelError}:{}}]}default:return[]}}function wp(e,t){return(Array.isArray(e)?e:[]).flatMap(n=>zy(n,t))}var Py="0.0.23",{HarnessTurn:Oy}=hp(qn.default),kp=e=>{try{window.parent.postMessage({contract:za,...e},"*")}catch{}};function Ay(){let[e,t]=qn.default.useState({runId:"run",state:Kn(),theme:"system"});return qn.default.useEffect(()=>{let n=o=>{if(o.source!==window.parent)return;let l=o.data;!l||l.contract!==za||(l.type==="theme"&&["light","dark","system"].includes(l.theme)?(document.documentElement.style.colorScheme=l.theme==="system"?"light dark":l.theme,t(a=>({...a,theme:l.theme}))):l.type==="reset"?t(a=>({...a,runId:String(l.runId||"run"),state:Kn()})):l.type==="events"&&Array.isArray(l.events)&&t(a=>{let s=String(l.runId||a.runId),u=s===a.runId?a.state:Kn();return{...a,runId:s,state:gp(u,wp(l.events,{runId:s}))}}))};window.addEventListener("message",n),kp({type:"ready",version:Py});let r=document.getElementById("root"),i=new ResizeObserver(()=>kp({type:"height",height:Math.ceil(r.getBoundingClientRect().height)}));return i.observe(r),()=>{window.removeEventListener("message",n),i.disconnect()}},[]),qn.default.createElement(Oy,{state:e.state,theme:e.theme,autoFollow:!1,styleSheet:null})}(0,xp.createRoot)(document.getElementById("root")).render(qn.default.createElement(Ay));})();
|
|
673
|
+
`):O.text;await(y?y($):navigator.clipboard.writeText($)),j("copied")}catch{j("failed")}},N=B.startsWith("zh"),W=V==="copied"?N?"\u5DF2\u590D\u5236":"Copied":N?"\u590D\u5236\u56DE\u590D":"Copy reply",we=N?"\u4ECE\u8FD9\u91CC\u65B0\u5EFA\u5206\u652F":"Branch from here",Oe=($,he,xt)=>t("button",{type:"button",title:$,"aria-label":$,onClick:he},t("svg",{viewBox:"0 0 24 24",width:16,height:16,fill:"none",stroke:"currentColor",strokeWidth:1.5,strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0},t("path",{d:xt}))),Q=f?.time??c.taskEndedAt;return t("article",{...x,className:"harness-turn","data-testid":"harness-turn"},t(s,{state:c,onCopy:y,locale:B,...K}),c.taskState==="failed"&&c.taskError?t("details",{className:"harness-turn-error"},t("summary",null,N?"\u672C\u8F6E\u672A\u5B8C\u6210\uFF0C\u67E5\u770B\u539F\u56E0":"This turn did not complete. View reason"),t("p",null,c.taskError)):c.taskState==="paused"&&c.taskReason==="provider_unavailable"&&c.taskMessage?t("p",{className:"harness-turn-model-pause",role:"status"},c.taskMessage):null,O?.kind==="text"&&!O.streaming&&(M||F)?t(I,{key:E,seq:E,load:F,deliveries:C,openFile:K.onOpenFile,resolveWebDelivery:M,zh:N}):null,O?.kind==="text"&&!O.streaming?t("div",{className:"harness-reply-actions",role:"group","aria-label":N?"\u56DE\u590D\u64CD\u4F5C":"Reply actions"},Oe(W,U,V==="copied"?"m5 12 4 4L19 6":"M8 8h11v12H8zM5 16H4V4h11v1"),k,f?.branchable&&v?Oe(we,()=>v(f.seq),"M5 19 19 5m-6 0h6v6M5 10v9h9"):null,typeof Q=="number"&&Number.isFinite(Q)?t("time",{dateTime:new Date(Q).toISOString()},new Intl.DateTimeFormat(B,{hour:"2-digit",minute:"2-digit",hour12:!1}).format(Q)):null,V==="failed"?t("span",{role:"status"},N?"\u65E0\u6CD5\u590D\u5236":"Unable to copy"):null):null)}function p({state:c,loading:f,error:y,omittedRows:v=0,omittedChars:k=0,labels:x={},...C}){return e.createElement("section",{className:"harness-subagent-pane","data-testid":"subagent-pane","aria-readonly":!0},y?e.createElement("p",{role:"alert"},y):f?e.createElement("p",{role:"status"},x.childSyncing||"Syncing"):null,v||k?e.createElement("p",{className:"harness-subagent-window-notice"},x.childOmitted||"Earlier rows or long fields are omitted in this observation window."):null,c?e.createElement(s,{state:c,labels:x,...C}):null)}return{HarnessTimeline:s,HarnessTurn:P,SubagentPane:p}}function Kn(){return{protocolVersion:1,taskId:null,taskTitle:null,runId:null,taskState:L.Idle,taskReason:null,taskMessage:null,taskOutcome:null,taskSummary:null,taskError:null,taskStartedAt:null,taskEndedAt:null,finalAnswerId:null,verificationRequired:null,modelRequestActive:!1,modelRequestRetry:!1,modelRequestPurpose:null,modelWait:null,modelThinkingId:null,contextMarkers:[],subagents:new Map,items:[],seen:new Set,pendingThinking:new Set,plan:null,planSummary:null,lastSeq:null}}function my(e,t){e||(e=Kn());let n;try{n=Tf(t)}catch{return e}if(e.seen.has(n.id))return e;let r=Ey(e);return r.seen=new Set(e.seen),r.seen.add(n.id),r.items=e.items.slice(),r.pendingThinking=new Set(e.pendingThinking),n.seq!=null&&(r.lastSeq==null||n.seq>r.lastSeq)&&(r.lastSeq=n.seq),gy(r,n),r}function gp(e,t){let n=e||Kn();for(let r of Array.isArray(t)?t:[])n=my(n,r);return n}function gy(e,t){switch(t.type){case R.TaskStarted:return yy(e,t);case R.TaskState:return mp(e,t);case R.TaskFinished:return vy(e,t);case R.ModelWait:e.taskState===L.Running&&(e.modelWait={retryAt:t.retryAt,httpStatus:t.httpStatus});return;case R.ModelRequest:t.active&&(e.modelWait=null),t.active&&e.taskState===L.Paused&&e.taskReason==="provider_unavailable"&&mp(e,{state:L.Running,reason:null,message:null}),(!t.active||e.modelThinkingId!==t.itemId)&&Ra(e),e.modelRequestActive=t.active,e.modelRequestRetry=t.active&&t.retry===!0,e.modelRequestPurpose=t.active?t.purpose??null:null,e.modelThinkingId=t.active?t.itemId:null;return;case R.TextPreview:{if(!e.modelRequestActive||!t.responseId||t.responseId!==e.modelThinkingId||!t.itemId||!t.text)return;let n=qr(e,t.itemId);if(n>=0&&!e.items[n].preview)return;Kr(e,t);let r={kind:"text",id:t.itemId,text:t.text,responseId:t.responseId,streaming:!0,preview:!0,receivedChars:t.receivedChars};n>=0?e.items[n]=r:e.items.push(r);return}case R.TextDelta:return wy(e,t);case R.TextDone:return ky(e,t);case R.ThinkingStart:return xy(e,t);case R.ThinkingDelta:return Sy(e,t);case R.ThinkingDone:return yp(e,t);case R.SubagentBound:{if(!t.callId)return;e.subagents=new Map(e.subagents??[]),e.subagents.set(t.callId,t.child);let n=vp(e,t.callId);n>=0&&(fn(e,n).child=t.child);return}case R.ToolPreview:{if(!t.previewId)return;Kr(e,t);let n=e.items.findIndex(i=>i.kind==="tool-preview"&&i.id===t.previewId),r={kind:"tool-preview",id:t.previewId,name:t.name,input:t.input,receivedChars:t.receivedChars,streaming:!0,...t.responseId?{responseId:t.responseId}:{}};n>=0?e.items[n]=r:e.items.push(r);return}case R.ToolScheduled:return Qn(e,t,b.Scheduled);case R.ToolStarted:return Qn(e,t,b.Running);case R.ToolState:return Qn(e,t,t.status,t);case R.ToolProgress:return Qn(e,t,b.Running,t);case R.ToolResult:return Qn(e,t,b.Completed,t);case R.ToolError:return Qn(e,t,b.Failed,t);case R.ContextMarker:{let n=[...e.contextMarkers??[]],r=n.findIndex(i=>i.id===t.marker.id);r<0?n.push(t.marker):n[r]=t.marker,e.contextMarkers=n;return}case R.PlanUpdated:return _y(e,t);default:return e}}function yy(e,t){if(e.taskId=t.taskId||e.taskId,e.taskTitle=t.title||e.taskTitle,e.runId=t.runId||e.runId,oa(e.taskState,L.Running)||e.taskState===L.Idle)e.taskState=L.Running;else return;e.taskOutcome=null,e.taskSummary=null,e.taskError=null,e.taskReason=null,e.taskMessage=null,t.startedAt!==void 0&&(e.taskStartedAt=t.startedAt),e.taskEndedAt=null,e.finalAnswerId=null}function Ra(e){e.modelThinkingId&&(yp(e,{itemId:e.modelThinkingId}),e.items=e.items.filter(t=>!(t.kind==="tool-preview"||t.preview===!0)||t.responseId!==e.modelThinkingId))}function mp(e,t){oa(e.taskState,t.state)&&(e.taskState=t.state,t.state!==L.Running&&(Ra(e),e.modelWait=null,e.modelRequestActive=!1,e.modelRequestRetry=!1,e.modelRequestPurpose=null,e.modelThinkingId=null),e.taskReason=t.reason,e.taskMessage=t.message,(t.state===L.Running||t.state===L.Recovered)&&(e.taskOutcome=null,e.taskError=null))}function vy(e,t){Ra(e),e.modelWait=null,e.modelRequestActive=!1,e.modelRequestRetry=!1,e.modelRequestPurpose=null,e.modelThinkingId=null,e.verificationRequired=t.verificationRequired,e.taskOutcome=t.outcome,e.taskSummary=t.summary,e.taskError=t.error||null,e.taskReason=t.reason||null,e.taskEndedAt=t.endedAt??null,e.finalAnswerId=["completed","unverified"].includes(t.outcome)&&!t.error&&t.executionState!=="interrupted"?t.finalAnswerId??null:null,t.outcome===Vt.Completed?e.taskState=L.Completed:t.outcome===Vt.Cancelled?e.taskState=L.Cancelled:t.outcome===Vt.Failed?e.taskState=L.Failed:t.outcome===Vt.Blocked?e.taskState=L.Blocked:t.outcome===Vt.Unverified&&(e.taskState=L.Unverified),t.executionState===L.Interrupted&&(e.taskState=L.Interrupted);for(let n=0;n<e.items.length;n+=1){let r=e.items[n],i=r.streaming,o=r.kind==="tool"&&(r.status===b.Scheduled||r.status===b.Running);(i||o)&&(e.items[n]={...r,streaming:!1,...o?{status:b.Interrupted}:{}})}e.pendingThinking=new Set}function wy(e,t){if(!t.itemId)return;t.delta&&Kr(e,t);let n=qr(e,t.itemId);if(n>=0){let r=fn(e,n);r.text=(r.text||"")+t.delta,r.streaming=!0,t.responseId&&(r.responseId=t.responseId);return}e.items.push({kind:"text",id:t.itemId,text:t.delta,streaming:!0,...t.responseId?{responseId:t.responseId}:{}})}function ky(e,t){t.text&&Kr(e,t);let n=qr(e,t.itemId);if(n>=0&&e.items[n].kind==="text"){let r=fn(e,n);t.text!==void 0&&(r.text=t.text),r.streaming=!1,t.sourceMessageId&&(r.sourceMessageId=t.sourceMessageId),t.responseId&&(r.responseId=t.responseId),t.role==="user"&&t.images&&(r.images=t.images)}else t.itemId&&(t.text||t.images?.length)&&e.items.push({kind:"text",id:t.itemId,text:t.text??"",role:t.role??"assistant",streaming:!1,...t.images?.length?{images:t.images}:{},...t.responseId?{responseId:t.responseId}:{},...t.sourceMessageId?{sourceMessageId:t.sourceMessageId}:{}})}function xy(e,t){t.itemId&&e.pendingThinking.add(t.itemId)}function Sy(e,t){if(!t.itemId||!t.delta&&e.pendingThinking.has(t.itemId))return;let n=qr(e,t.itemId);if(n>=0){let r=fn(e,n);r.text=(r.text||"")+t.delta,r.streaming=!0,t.responseId&&(r.responseId=t.responseId);return}t.delta&&(e.pendingThinking.delete(t.itemId),e.items.push({kind:"thought",id:t.itemId,text:t.delta,streaming:!0,provider:!0,...t.responseId?{responseId:t.responseId}:{}}))}function yp(e,t){e.pendingThinking.delete(t.itemId);let n=qr(e,t.itemId);if(n>=0&&e.items[n].kind==="thought"){let r=fn(e,n);t.text!==void 0&&(r.text=t.text),r.streaming=!1,t.sourceMessageId&&(r.sourceMessageId=t.sourceMessageId),t.responseId&&(r.responseId=t.responseId),t.duration!=null&&(r.duration=t.duration)}else t.itemId&&t.text&&e.items.push({kind:"thought",id:t.itemId,text:t.text,streaming:!1,provider:!0,...t.responseId?{responseId:t.responseId}:{},...t.sourceMessageId?{sourceMessageId:t.sourceMessageId}:{},...t.duration!=null?{duration:t.duration}:{}})}function Qn(e,t,n,r){if(!t.callId)return;n===b.Scheduled&&Kr(e,t);let i=vp(e,t.callId);if(i>=0){let l=fn(e,i);if([b.Completed,b.Failed,b.NotDispatched].includes(l.status)&&![b.Completed,b.Failed,b.NotDispatched].includes(n)){t.type===R.ToolScheduled&&(l.name=t.name||l.name,l.input=t.input,t.responseId&&(l.responseId=t.responseId));return}t.type===R.ToolScheduled&&(l.name=t.name||l.name,l.input=t.input,t.responseId&&(l.responseId=t.responseId)),e.subagents?.has(t.callId)&&(l.child=e.subagents.get(t.callId)),r&&t.type===R.ToolProgress&&(l.progress=r.progress||r.message||null,r.display&&r.display.kind&&(l.display=r.display)),r&&t.type===R.ToolResult&&(l.result=r.result,l.display=r.display),r&&t.type===R.ToolError&&(l.error=r.error),t.type===R.ToolState&&(l.progress=t.message),l.status=n;return}let o={kind:"tool",callId:t.callId,...t.responseId?{responseId:t.responseId}:{},...e.subagents?.has(t.callId)?{child:e.subagents.get(t.callId)}:{},name:t.name||"tool",input:t.input||{},status:n};r&&t.type===R.ToolResult&&(o.result=r.result,o.display=r.display),r&&t.type===R.ToolError&&(o.error=r.error),r&&t.type===R.ToolProgress&&(o.progress=r.progress||r.message||null,r.display&&r.display.kind&&(o.display=r.display)),e.items.push(o)}function Kr(e,t){if(t.responseId)for(let n=0;n<e.items.length;n++){let r=e.items[n];r.kind==="thought"&&r.streaming&&r.responseId===t.responseId&&(fn(e,n).streaming=!1)}}function _y(e,t){e.plan=t.items.length?t.items:null;let n=t.items.filter(l=>l.status==="completed").length,r=Number.isSafeInteger(t.totalCount)&&t.totalCount>=t.items.length?t.totalCount:t.items.length,i=r-t.items.length,o=Number.isSafeInteger(t.completedCount)&&t.completedCount>=n&&t.completedCount<=n+i?t.completedCount:n;e.planSummary={totalCount:r,completedCount:o,omittedItems:i}}function qr(e,t){for(let n=0;n<e.items.length;n+=1)if(e.items[n].id===t)return n;return-1}function vp(e,t){for(let n=0;n<e.items.length;n+=1){let r=e.items[n];if(r.kind==="tool"&&r.callId===t)return n}return-1}function fn(e,t){let n={...e.items[t]};return e.items[t]=n,n}function Ey(e){return Object.assign({},e,{items:e.items,seen:e.seen,pendingThinking:e.pendingThinking,plan:e.plan})}var Iy="agentkit.engine-event/v1",za="agentkit.engine-view/v1",Cy="submit_final_output",Ny=new Set(["completed","unverified","blocked","failed","cancelled"]),be=e=>typeof e=="string"&&e.trim().length>0,Ty=e=>e==null?{}:typeof e=="object"?e:{value:e};function Ly(e){let t=le(e.title)?.family,{ok:n,path:r,diff_additions:i,diff_deletions:o}=e.result??{};if(!(!["edit","write"].includes(t)||n!==!0||!be(r)||![i,o].every(l=>Number.isSafeInteger(l)&&l>=0)))return{kind:"file_edit",files:[{path:r,changeStat:{added:i,removed:o},operationKind:t==="write"?"write":"edit"}]}}function My(e){return e.title==="failed"||e.status==="failed"?"failed":["canceled","cancelled"].includes(e.title)||["canceled","cancelled"].includes(e.status)?"cancelled":e.status==="verified"?"completed":Ny.has(e.status)?e.status:e.title==="completed"?"completed":"unverified"}function Ry(e,t){let n=e?.error_type??e?.code??e?.error_code,r=e?.error_message??e?.message;if(!be(n))return{message:be(r)?r:`\u5DE5\u5177 ${t??""} \u672A\u6210\u529F`.trim()};let i=n==="command_policy_blocked"&&e?.executed===!1?e.finding?.detail:void 0;return{code:n,...be(i)?{message:i}:be(r)?{message:r}:{},...Number.isSafeInteger(e.failed_edit_index)&&e.failed_edit_index>=0?{failed_edit_index:e.failed_edit_index}:{}}}function zy(e,{runId:t="run",time:n,startedAt:r=n}={}){if(!e||e.schema!==Iy||!Number.isSafeInteger(e.seq))return[];let i=So,o=a=>`${t}:${e.seq}:${a}`,l=typeof e.requestId=="string"&&/^[a-f0-9]{64}$/.test(e.requestId)?`${t}:thought:${e.requestId}`:o("thought");switch(e.kind){case"run.started":return[{v:i,id:o("start"),type:"task.started",taskId:t,runId:t,startedAt:r}];case"todo.initialized":case"todo.updated":return Object.hasOwn(e,"plan")?[{v:i,id:o("todo"),type:"plan.updated",items:e.plan?.items??[],completedCount:e.plan?.completedCount,totalCount:e.plan?.totalCount}]:[];case"effect.prepared":case"effect.settled":return e.category==="model"&&e.title==="request"?[{v:i,id:o("model-request"),type:"model.request",active:e.kind==="effect.prepared",retry:e.kind==="effect.prepared"&&e.retry===!0,...e.purpose==="compaction"?{purpose:"compaction"}:{},itemId:l}]:[];case"model.completed":{let a=[];if(be(e.thinking)&&a.push({v:i,id:o("thought-done"),type:"thinking.done",itemId:l,text:e.thinking}),be(e.detail)&&(e.title==="initial_plan"||Array.isArray(e.calls)&&e.calls.length)){let s=`${t}:note:${e.seq}`;a.push({v:i,id:o("note"),type:"text.delta",itemId:s,delta:e.detail},{v:i,id:o("note-done"),type:"text.done",itemId:s})}for(let s of Array.isArray(e.calls)?e.calls:[])!be(s?.callId)||!be(s?.name)||s.name===Cy||a.push({v:i,id:o(`call:${s.callId}`),type:"tool.scheduled",callId:s.callId,name:s.name,input:Ty(s.arguments)},{v:i,id:o(`run:${s.callId}`),type:"tool.started",callId:s.callId});return a}case"model.stream_interrupted":return be(e.thinking)?[{v:i,id:o("thought-done"),type:"thinking.done",itemId:l,text:e.thinking}]:[];case"tool.completed":{if(!be(e.callId))return[];if(e.status==="uncertain")return[{v:i,id:o("uncertain"),type:"tool.state",callId:e.callId,status:"uncertain"}];let a=e.status==="ok"?Ly(e):void 0;if(e.status!=="ok")return[{v:i,id:o("error"),type:"tool.error",callId:e.callId,error:Ry(e.result,e.title)}];let s=[{v:i,id:o("result"),type:"tool.result",callId:e.callId,result:e.result??null,...a?{display:a}:{}}];return e.title==="TodoWrite"&&Array.isArray(e.result?.todos)&&s.push({v:i,id:o("todo-receipt"),type:"plan.updated",items:e.result.todos.map((u,d)=>({...u,id:`todo:${d}`}))}),s}case"model.retry_scheduled":return Number.isSafeInteger(e.retryAt)&&e.retryAt>0?[{v:i,id:o("model-wait"),type:"model.wait",retryAt:e.retryAt,httpStatus:e.httpStatus}]:[];case"model.retry_exhausted":return[{v:i,id:o("paused"),type:"task.state",state:"paused",reason:"provider_unavailable",message:e.modelError}];case"run.terminal":{let a=[],s=`${t}:final`;return be(e.detail)&&a.push({v:i,id:o("final"),type:"text.delta",itemId:s,delta:e.detail},{v:i,id:o("final-done"),type:"text.done",itemId:s}),e.title==="paused"?[...a,{v:i,id:o("paused"),type:"task.state",state:"paused",reason:e.reason??null}]:e.title==="interrupted"?[{v:i,id:o("finished"),type:"task.finished",outcome:"unverified",executionState:"interrupted",endedAt:n,reason:e.reason}]:[...a,{v:i,id:o("finished"),type:"task.finished",outcome:My(e),endedAt:n,...a.length?{finalAnswerId:s}:{},...e.reason?{reason:e.reason}:{},...be(e.modelError)?{error:e.modelError}:{}}]}default:return[]}}function wp(e,t){return(Array.isArray(e)?e:[]).flatMap(n=>zy(n,t))}var Py="0.0.25",{HarnessTurn:Oy}=hp(qn.default),kp=e=>{try{window.parent.postMessage({contract:za,...e},"*")}catch{}};function Ay(){let[e,t]=qn.default.useState({runId:"run",state:Kn(),theme:"system"});return qn.default.useEffect(()=>{let n=o=>{if(o.source!==window.parent)return;let l=o.data;!l||l.contract!==za||(l.type==="theme"&&["light","dark","system"].includes(l.theme)?(document.documentElement.style.colorScheme=l.theme==="system"?"light dark":l.theme,t(a=>({...a,theme:l.theme}))):l.type==="reset"?t(a=>({...a,runId:String(l.runId||"run"),state:Kn()})):l.type==="events"&&Array.isArray(l.events)&&t(a=>{let s=String(l.runId||a.runId),u=s===a.runId?a.state:Kn();return{...a,runId:s,state:gp(u,wp(l.events,{runId:s}))}}))};window.addEventListener("message",n),kp({type:"ready",version:Py});let r=document.getElementById("root"),i=new ResizeObserver(()=>kp({type:"height",height:Math.ceil(r.getBoundingClientRect().height)}));return i.observe(r),()=>{window.removeEventListener("message",n),i.disconnect()}},[]),qn.default.createElement(Oy,{state:e.state,theme:e.theme,autoFollow:!1,styleSheet:null})}(0,xp.createRoot)(document.getElementById("root")).render(qn.default.createElement(Ay));})();
|
|
674
674
|
</script></body></html>
|
package/dist/index.mjs
CHANGED
|
@@ -2260,6 +2260,84 @@ function mergeChatUsage(previous, reported, policy, finalized = false) {
|
|
|
2260
2260
|
return { ...previous, ...reported };
|
|
2261
2261
|
}
|
|
2262
2262
|
|
|
2263
|
+
// packages/agentkit-harness-node/src/native/model-deepseek-dsml.mjs
|
|
2264
|
+
var markerHeads = ["<", "</"].flatMap((start) => ["|", "||"].flatMap((left) => ["||", "|"].map((right) => `${start}${left}DSML${right}`)));
|
|
2265
|
+
var maxHeadLength = Math.max(...markerHeads.map((head) => head.length));
|
|
2266
|
+
var tagNames = ["calls", "tool_calls", "function_calls", "invoke", "parameter"];
|
|
2267
|
+
var tagPrefix = new RegExp(`^(${tagNames.join("|")})(?=[\\t />])`, "u");
|
|
2268
|
+
var deepSeekModelId = /(?:^|[-/.:_@])deepseek[-/._](?:v(?:3[._-]2|4)|chat|reasoner)(?=$|[-/.:_@])/iu;
|
|
2269
|
+
function createDeepSeekContentProjector(binding) {
|
|
2270
|
+
if (!deepSeekModelId.test(binding?.model ?? "")) {
|
|
2271
|
+
return { push: (text) => text, seal: () => "" };
|
|
2272
|
+
}
|
|
2273
|
+
let pending = "";
|
|
2274
|
+
let hiddenBlock = null;
|
|
2275
|
+
let codeDelimiter = "";
|
|
2276
|
+
function read(text, sealed) {
|
|
2277
|
+
pending += text;
|
|
2278
|
+
let visible = "";
|
|
2279
|
+
while (pending) {
|
|
2280
|
+
const special = pending.search(/[<`~]/u);
|
|
2281
|
+
const length = special < 0 ? pending.length : special;
|
|
2282
|
+
if (length) {
|
|
2283
|
+
if (!hiddenBlock) visible += pending.slice(0, length);
|
|
2284
|
+
pending = pending.slice(length);
|
|
2285
|
+
continue;
|
|
2286
|
+
}
|
|
2287
|
+
if (pending[0] !== "<") {
|
|
2288
|
+
const delimiter = pending.match(/^(?:`+|~+)/u)[0];
|
|
2289
|
+
if (!sealed && delimiter.length === pending.length) break;
|
|
2290
|
+
if (!hiddenBlock) {
|
|
2291
|
+
if (codeDelimiter) {
|
|
2292
|
+
if (delimiter === codeDelimiter || codeDelimiter.length >= 3 && delimiter[0] === codeDelimiter[0] && delimiter.length > codeDelimiter.length) {
|
|
2293
|
+
codeDelimiter = "";
|
|
2294
|
+
}
|
|
2295
|
+
} else if (delimiter[0] === "`" || delimiter.length >= 3) {
|
|
2296
|
+
codeDelimiter = delimiter;
|
|
2297
|
+
}
|
|
2298
|
+
visible += delimiter;
|
|
2299
|
+
}
|
|
2300
|
+
pending = pending.slice(delimiter.length);
|
|
2301
|
+
continue;
|
|
2302
|
+
}
|
|
2303
|
+
if (!codeDelimiter) {
|
|
2304
|
+
const prefix = pending.slice(0, maxHeadLength).replaceAll("\uFF5C", "|");
|
|
2305
|
+
if (markerHeads.some((head2) => head2.length > prefix.length && head2.startsWith(prefix))) {
|
|
2306
|
+
if (!sealed) break;
|
|
2307
|
+
if (prefix.endsWith("DSML")) {
|
|
2308
|
+
pending = "";
|
|
2309
|
+
break;
|
|
2310
|
+
}
|
|
2311
|
+
}
|
|
2312
|
+
const head = markerHeads.find((candidate) => prefix.startsWith(candidate));
|
|
2313
|
+
if (head) {
|
|
2314
|
+
const afterHead = pending.slice(head.length);
|
|
2315
|
+
const rest = afterHead.replace(/^[\t ]+/u, "");
|
|
2316
|
+
const tag = rest.match(tagPrefix)?.[1];
|
|
2317
|
+
if (tag) {
|
|
2318
|
+
const end = pending.indexOf(">", head.length);
|
|
2319
|
+
if (end < 0 && !sealed) break;
|
|
2320
|
+
const closing = head.startsWith("</");
|
|
2321
|
+
if (closing && tag === hiddenBlock) hiddenBlock = null;
|
|
2322
|
+
if (!closing && !hiddenBlock && end >= 0 && pending[end - 1] !== "/") hiddenBlock = tag;
|
|
2323
|
+
pending = end < 0 ? "" : pending.slice(end + 1);
|
|
2324
|
+
continue;
|
|
2325
|
+
}
|
|
2326
|
+
if (tagNames.some((name) => name.startsWith(rest))) {
|
|
2327
|
+
if (!sealed) break;
|
|
2328
|
+
pending = "";
|
|
2329
|
+
continue;
|
|
2330
|
+
}
|
|
2331
|
+
}
|
|
2332
|
+
}
|
|
2333
|
+
if (!hiddenBlock) visible += "<";
|
|
2334
|
+
pending = pending.slice(1);
|
|
2335
|
+
}
|
|
2336
|
+
return visible;
|
|
2337
|
+
}
|
|
2338
|
+
return { push: (text) => read(text, false), seal: () => read("", true) };
|
|
2339
|
+
}
|
|
2340
|
+
|
|
2263
2341
|
// packages/agentkit-harness-node/src/native/model-openai-chat.mjs
|
|
2264
2342
|
import { parseModelJson, stringifyModelJson, modelWireToolCall as modelWireToolCall2, FINAL_SUBMISSION_TOOL as FINAL_SUBMISSION_TOOL3 } from "@kingsoftcloud/agentkit-harness-core";
|
|
2265
2343
|
function strictParseJson(text) {
|
|
@@ -2462,6 +2540,8 @@ function parseOpenAIBuffered(bodyText, request, { captureReplay = false, binding
|
|
|
2462
2540
|
let text = message.content;
|
|
2463
2541
|
if (text == null) text = "";
|
|
2464
2542
|
if (typeof text !== "string") throw new ProtocolError("unsupported assistant content");
|
|
2543
|
+
const dsml = createDeepSeekContentProjector(binding);
|
|
2544
|
+
text = dsml.push(text) + dsml.seal();
|
|
2465
2545
|
text = projectInlineReasoning(text, inlineReasoningMarker(request.profile.inlineReasoningPolicy, binding), request.profile.inlineReasoningPolicy);
|
|
2466
2546
|
let calls;
|
|
2467
2547
|
const rawCalls = Array.isArray(message.tool_calls) && message.tool_calls.length > 0;
|
|
@@ -2585,6 +2665,7 @@ function createOpenAIStreamTurn(profile, binding) {
|
|
|
2585
2665
|
const emitThinking = profile.providerThinkingDisplay ?? profile.providerReplayMode !== "none";
|
|
2586
2666
|
const marker = inlineReasoningMarker(profile.inlineReasoningPolicy, binding);
|
|
2587
2667
|
const projector = createInlineReasoningProjector(marker, profile.inlineReasoningPolicy);
|
|
2668
|
+
const dsml = createDeepSeekContentProjector(binding);
|
|
2588
2669
|
let emitContent;
|
|
2589
2670
|
return {
|
|
2590
2671
|
text: "",
|
|
@@ -2688,8 +2769,9 @@ function createOpenAIStreamTurn(profile, binding) {
|
|
|
2688
2769
|
this.finish = finish;
|
|
2689
2770
|
if (reported) this.usageAtFinish = true;
|
|
2690
2771
|
}
|
|
2691
|
-
|
|
2692
|
-
|
|
2772
|
+
const visibleText = dsml.push(content);
|
|
2773
|
+
this.text += visibleText;
|
|
2774
|
+
const publicContent = projector.push(visibleText);
|
|
2693
2775
|
if (publicContent) emit({ kind: "text", text: publicContent });
|
|
2694
2776
|
if (reasoning && emitThinking) emit({ kind: "thinking", text: reasoning });
|
|
2695
2777
|
try {
|
|
@@ -2739,9 +2821,11 @@ function createOpenAIStreamTurn(profile, binding) {
|
|
|
2739
2821
|
}
|
|
2740
2822
|
},
|
|
2741
2823
|
finalize({ errorKind = null, failureKind = null } = {}) {
|
|
2824
|
+
const wireTail = dsml.seal();
|
|
2825
|
+
this.text += wireTail;
|
|
2742
2826
|
const result = this.rawResult({ errorKind, failureKind });
|
|
2743
2827
|
if (!["provider_retryable_error", "provider_terminal_error"].includes(result.kind)) {
|
|
2744
|
-
const tail = projector.seal();
|
|
2828
|
+
const tail = projector.push(wireTail) + projector.seal();
|
|
2745
2829
|
if (tail) emitContent?.({ kind: "text", text: tail });
|
|
2746
2830
|
}
|
|
2747
2831
|
const text = projectInlineReasoning(result.text, marker, profile.inlineReasoningPolicy);
|
package/dist/rpc-entry.mjs
CHANGED
|
@@ -2271,6 +2271,84 @@ function mergeChatUsage(previous, reported, policy, finalized = false) {
|
|
|
2271
2271
|
return { ...previous, ...reported };
|
|
2272
2272
|
}
|
|
2273
2273
|
|
|
2274
|
+
// packages/agentkit-harness-node/src/native/model-deepseek-dsml.mjs
|
|
2275
|
+
var markerHeads = ["<", "</"].flatMap((start) => ["|", "||"].flatMap((left) => ["||", "|"].map((right) => `${start}${left}DSML${right}`)));
|
|
2276
|
+
var maxHeadLength = Math.max(...markerHeads.map((head) => head.length));
|
|
2277
|
+
var tagNames = ["calls", "tool_calls", "function_calls", "invoke", "parameter"];
|
|
2278
|
+
var tagPrefix = new RegExp(`^(${tagNames.join("|")})(?=[\\t />])`, "u");
|
|
2279
|
+
var deepSeekModelId = /(?:^|[-/.:_@])deepseek[-/._](?:v(?:3[._-]2|4)|chat|reasoner)(?=$|[-/.:_@])/iu;
|
|
2280
|
+
function createDeepSeekContentProjector(binding) {
|
|
2281
|
+
if (!deepSeekModelId.test(binding?.model ?? "")) {
|
|
2282
|
+
return { push: (text) => text, seal: () => "" };
|
|
2283
|
+
}
|
|
2284
|
+
let pending = "";
|
|
2285
|
+
let hiddenBlock = null;
|
|
2286
|
+
let codeDelimiter = "";
|
|
2287
|
+
function read(text, sealed) {
|
|
2288
|
+
pending += text;
|
|
2289
|
+
let visible = "";
|
|
2290
|
+
while (pending) {
|
|
2291
|
+
const special = pending.search(/[<`~]/u);
|
|
2292
|
+
const length = special < 0 ? pending.length : special;
|
|
2293
|
+
if (length) {
|
|
2294
|
+
if (!hiddenBlock) visible += pending.slice(0, length);
|
|
2295
|
+
pending = pending.slice(length);
|
|
2296
|
+
continue;
|
|
2297
|
+
}
|
|
2298
|
+
if (pending[0] !== "<") {
|
|
2299
|
+
const delimiter = pending.match(/^(?:`+|~+)/u)[0];
|
|
2300
|
+
if (!sealed && delimiter.length === pending.length) break;
|
|
2301
|
+
if (!hiddenBlock) {
|
|
2302
|
+
if (codeDelimiter) {
|
|
2303
|
+
if (delimiter === codeDelimiter || codeDelimiter.length >= 3 && delimiter[0] === codeDelimiter[0] && delimiter.length > codeDelimiter.length) {
|
|
2304
|
+
codeDelimiter = "";
|
|
2305
|
+
}
|
|
2306
|
+
} else if (delimiter[0] === "`" || delimiter.length >= 3) {
|
|
2307
|
+
codeDelimiter = delimiter;
|
|
2308
|
+
}
|
|
2309
|
+
visible += delimiter;
|
|
2310
|
+
}
|
|
2311
|
+
pending = pending.slice(delimiter.length);
|
|
2312
|
+
continue;
|
|
2313
|
+
}
|
|
2314
|
+
if (!codeDelimiter) {
|
|
2315
|
+
const prefix = pending.slice(0, maxHeadLength).replaceAll("\uFF5C", "|");
|
|
2316
|
+
if (markerHeads.some((head2) => head2.length > prefix.length && head2.startsWith(prefix))) {
|
|
2317
|
+
if (!sealed) break;
|
|
2318
|
+
if (prefix.endsWith("DSML")) {
|
|
2319
|
+
pending = "";
|
|
2320
|
+
break;
|
|
2321
|
+
}
|
|
2322
|
+
}
|
|
2323
|
+
const head = markerHeads.find((candidate) => prefix.startsWith(candidate));
|
|
2324
|
+
if (head) {
|
|
2325
|
+
const afterHead = pending.slice(head.length);
|
|
2326
|
+
const rest = afterHead.replace(/^[\t ]+/u, "");
|
|
2327
|
+
const tag = rest.match(tagPrefix)?.[1];
|
|
2328
|
+
if (tag) {
|
|
2329
|
+
const end = pending.indexOf(">", head.length);
|
|
2330
|
+
if (end < 0 && !sealed) break;
|
|
2331
|
+
const closing = head.startsWith("</");
|
|
2332
|
+
if (closing && tag === hiddenBlock) hiddenBlock = null;
|
|
2333
|
+
if (!closing && !hiddenBlock && end >= 0 && pending[end - 1] !== "/") hiddenBlock = tag;
|
|
2334
|
+
pending = end < 0 ? "" : pending.slice(end + 1);
|
|
2335
|
+
continue;
|
|
2336
|
+
}
|
|
2337
|
+
if (tagNames.some((name) => name.startsWith(rest))) {
|
|
2338
|
+
if (!sealed) break;
|
|
2339
|
+
pending = "";
|
|
2340
|
+
continue;
|
|
2341
|
+
}
|
|
2342
|
+
}
|
|
2343
|
+
}
|
|
2344
|
+
if (!hiddenBlock) visible += "<";
|
|
2345
|
+
pending = pending.slice(1);
|
|
2346
|
+
}
|
|
2347
|
+
return visible;
|
|
2348
|
+
}
|
|
2349
|
+
return { push: (text) => read(text, false), seal: () => read("", true) };
|
|
2350
|
+
}
|
|
2351
|
+
|
|
2274
2352
|
// packages/agentkit-harness-node/src/native/model-openai-chat.mjs
|
|
2275
2353
|
import { parseModelJson, stringifyModelJson, modelWireToolCall as modelWireToolCall2, FINAL_SUBMISSION_TOOL as FINAL_SUBMISSION_TOOL3 } from "@kingsoftcloud/agentkit-harness-core";
|
|
2276
2354
|
function strictParseJson(text) {
|
|
@@ -2473,6 +2551,8 @@ function parseOpenAIBuffered(bodyText, request, { captureReplay = false, binding
|
|
|
2473
2551
|
let text = message.content;
|
|
2474
2552
|
if (text == null) text = "";
|
|
2475
2553
|
if (typeof text !== "string") throw new ProtocolError("unsupported assistant content");
|
|
2554
|
+
const dsml = createDeepSeekContentProjector(binding);
|
|
2555
|
+
text = dsml.push(text) + dsml.seal();
|
|
2476
2556
|
text = projectInlineReasoning(text, inlineReasoningMarker(request.profile.inlineReasoningPolicy, binding), request.profile.inlineReasoningPolicy);
|
|
2477
2557
|
let calls;
|
|
2478
2558
|
const rawCalls = Array.isArray(message.tool_calls) && message.tool_calls.length > 0;
|
|
@@ -2596,6 +2676,7 @@ function createOpenAIStreamTurn(profile, binding) {
|
|
|
2596
2676
|
const emitThinking = profile.providerThinkingDisplay ?? profile.providerReplayMode !== "none";
|
|
2597
2677
|
const marker = inlineReasoningMarker(profile.inlineReasoningPolicy, binding);
|
|
2598
2678
|
const projector = createInlineReasoningProjector(marker, profile.inlineReasoningPolicy);
|
|
2679
|
+
const dsml = createDeepSeekContentProjector(binding);
|
|
2599
2680
|
let emitContent;
|
|
2600
2681
|
return {
|
|
2601
2682
|
text: "",
|
|
@@ -2699,8 +2780,9 @@ function createOpenAIStreamTurn(profile, binding) {
|
|
|
2699
2780
|
this.finish = finish;
|
|
2700
2781
|
if (reported) this.usageAtFinish = true;
|
|
2701
2782
|
}
|
|
2702
|
-
|
|
2703
|
-
|
|
2783
|
+
const visibleText = dsml.push(content);
|
|
2784
|
+
this.text += visibleText;
|
|
2785
|
+
const publicContent = projector.push(visibleText);
|
|
2704
2786
|
if (publicContent) emit({ kind: "text", text: publicContent });
|
|
2705
2787
|
if (reasoning && emitThinking) emit({ kind: "thinking", text: reasoning });
|
|
2706
2788
|
try {
|
|
@@ -2750,9 +2832,11 @@ function createOpenAIStreamTurn(profile, binding) {
|
|
|
2750
2832
|
}
|
|
2751
2833
|
},
|
|
2752
2834
|
finalize({ errorKind = null, failureKind = null } = {}) {
|
|
2835
|
+
const wireTail = dsml.seal();
|
|
2836
|
+
this.text += wireTail;
|
|
2753
2837
|
const result = this.rawResult({ errorKind, failureKind });
|
|
2754
2838
|
if (!["provider_retryable_error", "provider_terminal_error"].includes(result.kind)) {
|
|
2755
|
-
const tail = projector.seal();
|
|
2839
|
+
const tail = projector.push(wireTail) + projector.seal();
|
|
2756
2840
|
if (tail) emitContent?.({ kind: "text", text: tail });
|
|
2757
2841
|
}
|
|
2758
2842
|
const text = projectInlineReasoning(result.text, marker, profile.inlineReasoningPolicy);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kingsoftcloud/agentkit-harness-node",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.25",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "Standalone Native Harness Node adapters: a durable SQLite run store, a one-request model HTTP port, and a minimal versioned JSON-RPC 2.0 over NDJSON process entry. Reuses the shared Native adapter implementations and externalizes @kingsoftcloud/agentkit-harness-core; depends on no Studio/DSH code at runtime.",
|
|
@@ -154,7 +154,7 @@
|
|
|
154
154
|
"src/package-integrity.mjs"
|
|
155
155
|
],
|
|
156
156
|
"dependencies": {
|
|
157
|
-
"@kingsoftcloud/agentkit-harness-core": "0.0.
|
|
157
|
+
"@kingsoftcloud/agentkit-harness-core": "0.0.25",
|
|
158
158
|
"@astral-sh/ruff-wasm-nodejs": "0.16.8",
|
|
159
159
|
"parse5": "7.3.0",
|
|
160
160
|
"playwright-core": "1.58.2",
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
const markerHeads = ['<', '</'].flatMap(start => ['|', '||'].flatMap(left =>
|
|
2
|
+
['||', '|'].map(right => `${start}${left}DSML${right}`)));
|
|
3
|
+
const maxHeadLength = Math.max(...markerHeads.map(head => head.length));
|
|
4
|
+
const tagNames = ['calls', 'tool_calls', 'function_calls', 'invoke', 'parameter'];
|
|
5
|
+
const tagPrefix = new RegExp(`^(${tagNames.join('|')})(?=[\\t />])`, 'u');
|
|
6
|
+
const deepSeekModelId = /(?:^|[-/.:_@])deepseek[-/._](?:v(?:3[._-]2|4)|chat|reasoner)(?=$|[-/.:_@])/iu;
|
|
7
|
+
|
|
8
|
+
export function createDeepSeekContentProjector(binding) {
|
|
9
|
+
// Recognize versioned and standard DeepSeek IDs inside proxy model aliases.
|
|
10
|
+
if (!deepSeekModelId.test(binding?.model ?? '')) {
|
|
11
|
+
return { push: text => text, seal: () => '' };
|
|
12
|
+
}
|
|
13
|
+
let pending = '';
|
|
14
|
+
let hiddenBlock = null;
|
|
15
|
+
let codeDelimiter = '';
|
|
16
|
+
|
|
17
|
+
function read(text, sealed) {
|
|
18
|
+
pending += text;
|
|
19
|
+
let visible = '';
|
|
20
|
+
while (pending) {
|
|
21
|
+
const special = pending.search(/[<`~]/u);
|
|
22
|
+
const length = special < 0 ? pending.length : special;
|
|
23
|
+
if (length) {
|
|
24
|
+
if (!hiddenBlock) visible += pending.slice(0, length);
|
|
25
|
+
pending = pending.slice(length);
|
|
26
|
+
continue;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if (pending[0] !== '<') {
|
|
30
|
+
const delimiter = pending.match(/^(?:`+|~+)/u)[0];
|
|
31
|
+
if (!sealed && delimiter.length === pending.length) break;
|
|
32
|
+
if (!hiddenBlock) {
|
|
33
|
+
if (codeDelimiter) {
|
|
34
|
+
if (delimiter === codeDelimiter || codeDelimiter.length >= 3 &&
|
|
35
|
+
delimiter[0] === codeDelimiter[0] && delimiter.length > codeDelimiter.length) {
|
|
36
|
+
codeDelimiter = '';
|
|
37
|
+
}
|
|
38
|
+
} else if (delimiter[0] === '`' || delimiter.length >= 3) {
|
|
39
|
+
codeDelimiter = delimiter;
|
|
40
|
+
}
|
|
41
|
+
visible += delimiter;
|
|
42
|
+
}
|
|
43
|
+
pending = pending.slice(delimiter.length);
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (!codeDelimiter) {
|
|
48
|
+
const prefix = pending.slice(0, maxHeadLength).replaceAll('|', '|');
|
|
49
|
+
if (markerHeads.some(head => head.length > prefix.length && head.startsWith(prefix))) {
|
|
50
|
+
if (!sealed) break;
|
|
51
|
+
if (prefix.endsWith('DSML')) {
|
|
52
|
+
pending = '';
|
|
53
|
+
break;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
const head = markerHeads.find(candidate => prefix.startsWith(candidate));
|
|
57
|
+
if (head) {
|
|
58
|
+
const afterHead = pending.slice(head.length);
|
|
59
|
+
const rest = afterHead.replace(/^[\t ]+/u, '');
|
|
60
|
+
const tag = rest.match(tagPrefix)?.[1];
|
|
61
|
+
if (tag) {
|
|
62
|
+
const end = pending.indexOf('>', head.length);
|
|
63
|
+
if (end < 0 && !sealed) break;
|
|
64
|
+
const closing = head.startsWith('</');
|
|
65
|
+
if (closing && tag === hiddenBlock) hiddenBlock = null;
|
|
66
|
+
if (!closing && !hiddenBlock && end >= 0 && pending[end - 1] !== '/') hiddenBlock = tag;
|
|
67
|
+
pending = end < 0 ? '' : pending.slice(end + 1);
|
|
68
|
+
continue;
|
|
69
|
+
}
|
|
70
|
+
if (tagNames.some(name => name.startsWith(rest))) {
|
|
71
|
+
if (!sealed) break;
|
|
72
|
+
pending = '';
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
if (!hiddenBlock) visible += '<';
|
|
78
|
+
pending = pending.slice(1);
|
|
79
|
+
}
|
|
80
|
+
return visible;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// Only transport markup is suppressed. Executable calls still come from the
|
|
84
|
+
// provider's structured tool_calls channel and its existing validation path.
|
|
85
|
+
return { push: text => read(text, false), seal: () => read('', true) };
|
|
86
|
+
}
|
|
@@ -17,6 +17,7 @@ import { inlineReasoningMarker, projectInlineReasoning, createInlineReasoningPro
|
|
|
17
17
|
import { applyProviderChatCompatibility, resolveProviderCompatibility } from './model-provider-compat.mjs';
|
|
18
18
|
import { classifyOpenAIProviderError } from './model-provider-error.mjs';
|
|
19
19
|
import { mergeChatUsage } from './model-chat-usage.mjs';
|
|
20
|
+
import { createDeepSeekContentProjector } from './model-deepseek-dsml.mjs';
|
|
20
21
|
// parseModelJson is the kernel's strict finite JSON parser: it rejects
|
|
21
22
|
// duplicate object keys and non-finite numbers (e.g. 1e400). Using it here keeps
|
|
22
23
|
// provider-envelope and tool-argument decoding consistent with the kernel's
|
|
@@ -240,6 +241,8 @@ export function parseOpenAIBuffered(bodyText, request, { captureReplay = false,
|
|
|
240
241
|
let text = message.content;
|
|
241
242
|
if (text == null) text = '';
|
|
242
243
|
if (typeof text !== 'string') throw new ProtocolError('unsupported assistant content');
|
|
244
|
+
const dsml = createDeepSeekContentProjector(binding);
|
|
245
|
+
text = dsml.push(text) + dsml.seal();
|
|
243
246
|
text = projectInlineReasoning(text, inlineReasoningMarker(request.profile.inlineReasoningPolicy, binding), request.profile.inlineReasoningPolicy);
|
|
244
247
|
let calls;
|
|
245
248
|
// tool_calls truthiness mirrors Python: an empty array carries no calls.
|
|
@@ -354,6 +357,7 @@ export function createOpenAIStreamTurn(profile, binding) {
|
|
|
354
357
|
const emitThinking = profile.providerThinkingDisplay ?? profile.providerReplayMode !== 'none';
|
|
355
358
|
const marker = inlineReasoningMarker(profile.inlineReasoningPolicy, binding);
|
|
356
359
|
const projector = createInlineReasoningProjector(marker, profile.inlineReasoningPolicy);
|
|
360
|
+
const dsml = createDeepSeekContentProjector(binding);
|
|
357
361
|
let emitContent;
|
|
358
362
|
return {
|
|
359
363
|
text: '',
|
|
@@ -444,8 +448,9 @@ export function createOpenAIStreamTurn(profile, binding) {
|
|
|
444
448
|
this.finish = finish;
|
|
445
449
|
if (reported) this.usageAtFinish = true;
|
|
446
450
|
}
|
|
447
|
-
|
|
448
|
-
|
|
451
|
+
const visibleText = dsml.push(content);
|
|
452
|
+
this.text += visibleText;
|
|
453
|
+
const publicContent = projector.push(visibleText);
|
|
449
454
|
if (publicContent) emit({ kind: 'text', text: publicContent });
|
|
450
455
|
if (reasoning && emitThinking) emit({ kind: 'thinking', text: reasoning });
|
|
451
456
|
try {
|
|
@@ -499,9 +504,11 @@ export function createOpenAIStreamTurn(profile, binding) {
|
|
|
499
504
|
},
|
|
500
505
|
|
|
501
506
|
finalize({ errorKind = null, failureKind = null } = {}) {
|
|
507
|
+
const wireTail = dsml.seal();
|
|
508
|
+
this.text += wireTail;
|
|
502
509
|
const result = this.rawResult({ errorKind, failureKind });
|
|
503
510
|
if (!['provider_retryable_error', 'provider_terminal_error'].includes(result.kind)) {
|
|
504
|
-
const tail = projector.seal();
|
|
511
|
+
const tail = projector.push(wireTail) + projector.seal();
|
|
505
512
|
if (tail) emitContent?.({ kind: 'text', text: tail });
|
|
506
513
|
}
|
|
507
514
|
const text = projectInlineReasoning(result.text, marker, profile.inlineReasoningPolicy);
|