@doubao-dev/cli 1.0.0-rc.11 → 1.0.0-rc.12

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/session.js CHANGED
@@ -1,2 +1,2 @@
1
1
  /*! LICENSE: session.js.LICENSE.txt */
2
- import{dirname as t,join as e,relative as i,resolve as s,sep as r}from"node:path";import{EventEmitter as a}from"node:events";import{existsSync as o,stat as n,unwatchFile as l,watch as h,watchFile as d}from"node:fs";import{lstat as c,open as f,readdir as p,realpath as m,stat as u}from"node:fs/promises";import{Readable as w}from"node:stream";import{type as _}from"node:os";import{fileURLToPath as g}from"node:url";import{callHook as y,runtime as v,dist_ye as b,dist_xe as P,collectHooks as E,log as x,resolvePublicationType as k,pD as S,error_errorMessage as W,isInteractive as D,loadPackage as I}from"./691.js";import{ensureLogin as R}from"./command~1.js";import{uploadDraft as C}from"./draft.js";import*as F from"node:path";let j="files",z="directories",M="files_directories",T={root:".",fileFilter:t=>!0,directoryFilter:t=>!0,type:j,lstat:!1,depth:0x80000000,alwaysStat:!1,highWaterMark:4096};Object.freeze(T);let A="READDIRP_RECURSIVE_ERROR",$=new Set(["ENOENT","EPERM","EACCES","ELOOP",A]),N=[z,"all",M,j],O=new Set([z,"all",M]),H=new Set(["all",M,j]),U="win32"===process.platform,K=t=>!0,L=t=>{if(void 0===t)return K;if("function"==typeof t)return t;if("string"==typeof t){let e=t.trim();return t=>t.basename===e}if(Array.isArray(t)){let e=t.map(t=>t.trim());return t=>e.some(e=>t.basename===e)}return K};class G extends w{parents;reading;parent;_stat;_maxDepth;_wantsDir;_wantsFile;_wantsEverything;_root;_isDirent;_statsProp;_rdOptions;_fileFilter;_directoryFilter;constructor(t={}){super({objectMode:!0,autoDestroy:!0,highWaterMark:t.highWaterMark});let e={...T,...t},{root:i,type:r}=e;this._fileFilter=L(e.fileFilter),this._directoryFilter=L(e.directoryFilter);let a=e.lstat?c:u;U?this._stat=t=>a(t,{bigint:!0}):this._stat=a,this._maxDepth=null!=e.depth&&Number.isSafeInteger(e.depth)?e.depth:T.depth,this._wantsDir=!!r&&O.has(r),this._wantsFile=!!r&&H.has(r),this._wantsEverything="all"===r,this._root=s(i),this._isDirent=!e.alwaysStat,this._statsProp=this._isDirent?"dirent":"stats",this._rdOptions={encoding:"utf8",withFileTypes:this._isDirent},this.parents=[this._exploreDir(i,1)],this.reading=!1,this.parent=void 0}async _read(t){if(!this.reading){this.reading=!0;try{for(;!this.destroyed&&t>0;){let e=this.parent,i=e&&e.files;if(i&&i.length>0){let{path:s,depth:r}=e,a=i.splice(0,t).map(t=>this._formatEntry(t,s));for(let e of(await Promise.all(a))){if(!e)continue;if(this.destroyed)return;let i=await this._getEntryType(e);"directory"===i&&this._directoryFilter(e)?(r<=this._maxDepth&&this.parents.push(this._exploreDir(e.fullPath,r+1)),this._wantsDir&&(this.push(e),t--)):("file"===i||this._includeAsFile(e))&&this._fileFilter(e)&&this._wantsFile&&(this.push(e),t--)}}else{let t=this.parents.pop();if(!t){this.push(null);break}if(this.parent=await t,this.destroyed)return}}}catch(t){this.destroy(t)}finally{this.reading=!1}}}async _exploreDir(t,e){let i;try{i=await p(t,this._rdOptions)}catch(t){this._onError(t)}return{files:i,depth:e,path:t}}async _formatEntry(t,r){let a,o=this._isDirent?t.name:t;try{let n=s(e(r,o));(a={path:i(this._root,n),fullPath:n,basename:o})[this._statsProp]=this._isDirent?t:await this._stat(n)}catch(t){this._onError(t);return}return a}_onError(t){$.has(t.code)&&!this.destroyed?this.emit("warn",t):this.destroy(t)}async _getEntryType(t){if(!t&&this._statsProp in t)return"";let e=t[this._statsProp];if(e.isFile())return"file";if(e.isDirectory())return"directory";if(e&&e.isSymbolicLink()){let e=t.fullPath;try{let t=await m(e),i=await c(t);if(i.isFile())return"file";if(i.isDirectory()){let i=t.length;if(e.startsWith(t)&&e.substr(i,1)===r){let i=Error(`Circular symlink detected: "${e}" points to "${t}"`);return i.code=A,this._onError(i)}return"directory"}}catch(t){return this._onError(t),""}}}_includeAsFile(t){let e=t&&t[this._statsProp];return e&&this._wantsEverything&&!e.isDirectory()}}let V=()=>{},q=process.platform,B="win32"===q,J="darwin"===q,Q="linux"===q,X="freebsd"===q,Y="OS400"===_(),Z="all",tt="ready",te="add",ti="change",ts="addDir",tr="unlink",ta="unlinkDir",to="raw",tn="error",tl={lstat:c,stat:u},th="listeners",td="errHandlers",tc="rawEmitters",tf=[th,td,tc],tp=new Set(["3dm","3ds","3g2","3gp","7z","a","aac","adp","afdesign","afphoto","afpub","ai","aif","aiff","alz","ape","apk","appimage","ar","arj","asf","au","avi","bak","baml","bh","bin","bk","bmp","btif","bz2","bzip2","cab","caf","cgm","class","cmx","cpio","cr2","cur","dat","dcm","deb","dex","djvu","dll","dmg","dng","doc","docm","docx","dot","dotm","dra","DS_Store","dsk","dts","dtshd","dvb","dwg","dxf","ecelp4800","ecelp7470","ecelp9600","egg","eol","eot","epub","exe","f4v","fbs","fh","fla","flac","flatpak","fli","flv","fpx","fst","fvt","g3","gh","gif","graffle","gz","gzip","h261","h263","h264","icns","ico","ief","img","ipa","iso","jar","jpeg","jpg","jpgv","jpm","jxr","key","ktx","lha","lib","lvp","lz","lzh","lzma","lzo","m3u","m4a","m4v","mar","mdi","mht","mid","midi","mj2","mka","mkv","mmr","mng","mobi","mov","movie","mp3","mp4","mp4a","mpeg","mpg","mpga","mxu","nef","npx","numbers","nupkg","o","odp","ods","odt","oga","ogg","ogv","otf","ott","pages","pbm","pcx","pdb","pdf","pea","pgm","pic","png","pnm","pot","potm","potx","ppa","ppam","ppm","pps","ppsm","ppsx","ppt","pptm","pptx","psd","pya","pyc","pyo","pyv","qt","rar","ras","raw","resources","rgb","rip","rlc","rmf","rmvb","rpm","rtf","rz","s3m","s7z","scpt","sgi","shar","snap","sil","sketch","slk","smv","snk","so","stl","suo","sub","swf","tar","tbz","tbz2","tga","tgz","thmx","tif","tiff","tlz","ttc","ttf","txz","udf","uvh","uvi","uvm","uvp","uvs","uvu","viv","vob","war","wav","wax","wbmp","wdp","weba","webm","webp","whl","wim","wm","wma","wmv","wmx","woff","woff2","wrm","wvx","xbm","xif","xla","xlam","xls","xlsb","xlsm","xlsx","xlt","xltm","xltx","xm","xmind","xpi","xpm","xwd","xz","z","zip","zipx"]),tm=(t,e)=>{t instanceof Set?t.forEach(e):e(t)},tu=(t,e,i)=>{let s=t[e];s instanceof Set||(t[e]=s=new Set([s])),s.add(i)},tw=(t,e,i)=>{let s=t[e];s instanceof Set?s.delete(i):s===i&&delete t[e]},t_=t=>t instanceof Set?0===t.size:!t,tg=new Map;function ty(t,e,i,s,r){try{return h(t,{persistent:e.persistent},(e,s)=>{i(t),r(e,s,{watchedPath:t}),s&&t!==s&&tv(F.resolve(t,s),th,F.join(t,s))})}catch(t){s(t);return}}let tv=(t,e,i,s,r)=>{let a=tg.get(t);a&&tm(a[e],t=>{t(i,s,r)})},tb=new Map;class tP{fsw;_boundHandleError;constructor(t){this.fsw=t,this._boundHandleError=e=>t._handleError(e)}_watchWithNodeFs(t,e){let i,s=this.fsw.options,r=F.dirname(t),a=F.basename(t);this.fsw._getWatchedDir(r).add(a);let o=F.resolve(t),n={persistent:s.persistent};if(e||(e=V),s.usePolling)n.interval=s.interval!==s.binaryInterval&&tp.has(F.extname(a).slice(1).toLowerCase())?s.binaryInterval:s.interval,i=((t,e,i,s)=>{let{listener:r,rawEmitter:a}=s,o=tb.get(e),n=o&&o.options;return n&&(n.persistent<i.persistent||n.interval>i.interval)&&(l(e),o=void 0),o?(tu(o,th,r),tu(o,tc,a)):(o={listeners:r,rawEmitters:a,options:i,watcher:d(e,i,(i,s)=>{tm(o.rawEmitters,t=>{t(ti,e,{curr:i,prev:s})});let r=i.mtimeMs;(i.size!==s.size||r>s.mtimeMs||0===r)&&tm(o.listeners,e=>e(t,i))})},tb.set(e,o)),()=>{tw(o,th,r),tw(o,tc,a),t_(o.listeners)&&(tb.delete(e),l(e),o.options=o.watcher=void 0,Object.freeze(o))}})(t,o,n,{listener:e,rawEmitter:this.fsw._emitRaw});else i=((t,e,i,s)=>{let r,{listener:a,errHandler:o,rawEmitter:n}=s,l=tg.get(e);if(!i.persistent){if(!(r=ty(t,i,a,o,n)))return;return r.close.bind(r)}if(l)tu(l,th,a),tu(l,td,o),tu(l,tc,n);else{if(!(r=ty(t,i,tv.bind(null,e,th),o,tv.bind(null,e,tc))))return;r.on(tn,async i=>{let s=tv.bind(null,e,td);if(l&&(l.watcherUnusable=!0),B&&"EPERM"===i.code)try{let e=await f(t,"r");await e.close(),s(i)}catch(t){}else s(i)}),l={listeners:a,errHandlers:o,rawEmitters:n,watcher:r},tg.set(e,l)}return()=>{if(tw(l,th,a),tw(l,td,o),tw(l,tc,n),t_(l.listeners)){let t;l.watcher.close(),tg.delete(e),tf.forEach((t=l,e=>{let i=t[e];i instanceof Set?i.clear():delete t[e]})),l.watcher=void 0,Object.freeze(l)}}})(t,o,n,{listener:e,errHandler:this._boundHandleError,rawEmitter:this.fsw._emitRaw});return i}_handleFile(t,e,i){if(this.fsw.closed)return;let s=F.dirname(t),r=F.basename(t),a=this.fsw._getWatchedDir(s),o=e;if(a.has(r))return;let n=async(e,i)=>{if(this.fsw._throttle("watch",t,5))if(i&&0!==i.mtimeMs){if(a.has(r)){let e=i.atimeMs,s=i.mtimeMs;(!e||e<=s||s!==o.mtimeMs)&&this.fsw._emit(ti,t,i),o=i}}else try{let i=await u(t);if(this.fsw.closed)return;let s=i.atimeMs,r=i.mtimeMs;if((!s||s<=r||r!==o.mtimeMs)&&this.fsw._emit(ti,t,i),(J||Q||X)&&o.ino!==i.ino){this.fsw._closeFile(e),o=i;let s=this._watchWithNodeFs(t,n);s&&this.fsw._addPathCloser(e,s)}else o=i}catch(t){this.fsw._remove(s,r)}},l=this._watchWithNodeFs(t,n);if(!(i&&this.fsw.options.ignoreInitial)&&this.fsw._isntIgnored(t)){if(!this.fsw._throttle(te,t,0))return;this.fsw._emit(te,t,e)}return l}async _handleSymlink(t,e,i,s){if(this.fsw.closed)return;let r=t.fullPath,a=this.fsw._getWatchedDir(e);if(!this.fsw.options.followSymlinks){let e;this.fsw._incrReadyCount();try{e=await m(i)}catch(t){return this.fsw._emitReady(),!0}if(this.fsw.closed)return;return a.has(s)?this.fsw._symlinkPaths.get(r)!==e&&(this.fsw._symlinkPaths.set(r,e),this.fsw._emit(ti,i,t.stats)):(a.add(s),this.fsw._symlinkPaths.set(r,e),this.fsw._emit(te,i,t.stats)),this.fsw._emitReady(),!0}if(this.fsw._symlinkPaths.has(r))return!0;this.fsw._symlinkPaths.set(r,!0)}_handleRead(t,e,i,s,r,a,o){t=F.join(t,"");let n=s?`${t}:${s}`:t;if(!(o=this.fsw._throttle("readdir",n,1e3)))return;let l=this.fsw._getWatchedDir(i.path),h=new Set,d=this.fsw._readdirp(t,{fileFilter:t=>i.filterPath(t),directoryFilter:t=>i.filterDir(t)});if(d)return d.on("data",async o=>{if(this.fsw.closed){d=void 0;return}let n=o.path,c=F.join(t,n);if(h.add(n),!(o.stats.isSymbolicLink()&&await this._handleSymlink(o,t,c,n))){if(this.fsw.closed){d=void 0;return}n!==s&&(s||l.has(n))||(this.fsw._incrReadyCount(),c=F.join(r,F.relative(r,c)),this._addToNodeFs(c,e,i,a+1))}}).on(tn,this._boundHandleError),new Promise((e,n)=>{if(!d)return n();d.once("end",()=>{if(this.fsw.closed){d=void 0;return}let n=!!o&&o.clear();e(void 0),l.getChildren().filter(e=>e!==t&&!h.has(e)).forEach(e=>{this.fsw._remove(t,e)}),d=void 0,n&&this._handleRead(t,!1,i,s,r,a,o)})})}async _handleDir(t,e,i,s,r,a,o){let n,l,h=this.fsw._getWatchedDir(F.dirname(t)),d=h.has(F.basename(t));i&&this.fsw.options.ignoreInitial||r||d||this.fsw._emit(ts,t,e),h.add(F.basename(t)),this.fsw._getWatchedDir(t);let c=this.fsw.options.depth;if((null==c||s<=c)&&!this.fsw._symlinkPaths.has(o)){if(!r&&(await this._handleRead(t,i,a,r,t,s,n),this.fsw.closed))return;l=this._watchWithNodeFs(t,(e,i)=>{i&&0===i.mtimeMs||this._handleRead(e,!1,a,r,t,s,n)})}return l}async _addToNodeFs(t,e,i,s,r){let a=this.fsw._emitReady;if(this.fsw._isIgnored(t)||this.fsw.closed)return a(),!1;let o=this.fsw._getWatchHelpers(t);i&&(o.filterPath=t=>i.filterPath(t),o.filterDir=t=>i.filterDir(t));try{let i,n=await tl[o.statMethod](o.watchPath);if(this.fsw.closed)return;if(this.fsw._isIgnored(o.watchPath,n))return a(),!1;let l=this.fsw.options.followSymlinks;if(n.isDirectory()){let a=F.resolve(t),h=l?await m(t):t;if(this.fsw.closed||(i=await this._handleDir(o.watchPath,n,e,s,r,o,h),this.fsw.closed))return;a!==h&&void 0!==h&&this.fsw._symlinkPaths.set(a,h)}else if(n.isSymbolicLink()){let r=l?await m(t):t;if(this.fsw.closed)return;let a=F.dirname(o.watchPath);if(this.fsw._getWatchedDir(a).add(o.watchPath),this.fsw._emit(te,o.watchPath,n),i=await this._handleDir(a,n,e,s,t,o,r),this.fsw.closed)return;void 0!==r&&this.fsw._symlinkPaths.set(F.resolve(t),r)}else i=this._handleFile(o.watchPath,n,e);return a(),i&&this.fsw._addPathCloser(t,i),!1}catch(e){if(this.fsw._handleError(e))return a(),t}}}let tE=/\\/g,tx=/\/\//g,tk=/\..*\.(sw[px])$|~$|\.subl.*\.tmp/,tS=/^\.[/\\]/;function tW(t){return Array.isArray(t)?t:[t]}let tD=t=>"object"==typeof t&&null!==t&&!(t instanceof RegExp);function tI(t,e,i){let s=function(t){if("string"!=typeof t)throw Error("string expected");t=(t=F.normalize(t)).replace(/\\/g,"/");let e=!1;return t.startsWith("//")&&(e=!0),t=t.replace(tx,"/"),e&&(t="/"+t),t}(e);for(let e=0;e<t.length;e++)if((0,t[e])(s,i))return!0;return!1}let tR=t=>{let e=tW(t).flat();if(!e.every(t=>"string"==typeof t))throw TypeError(`Non-string provided as watch path: ${e}`);return e.map(tF)},tC=t=>{let e=t.replace(tE,"/"),i=!1;return e.startsWith("//")&&(i=!0),e=e.replace(tx,"/"),i&&(e="/"+e),e},tF=t=>tC(F.normalize(tC(t))),tj=(t="")=>e=>"string"==typeof e?tF(F.isAbsolute(e)?e:F.join(t,e)):e,tz=Object.freeze(new Set);class tM{path;_removeWatcher;items;constructor(t,e){this.path=t,this._removeWatcher=e,this.items=new Set}add(t){let{items:e}=this;e&&"."!==t&&".."!==t&&e.add(t)}async remove(t){let{items:e}=this;if(!e||(e.delete(t),e.size>0))return;let i=this.path;try{await p(i)}catch(t){this._removeWatcher&&this._removeWatcher(F.dirname(i),F.basename(i))}}has(t){let{items:e}=this;if(e)return e.has(t)}getChildren(){let{items:t}=this;return t?[...t.values()]:[]}dispose(){this.items.clear(),this.path="",this._removeWatcher=V,this.items=tz,Object.freeze(this)}}class tT{fsw;path;watchPath;fullWatchPath;dirParts;followSymlinks;statMethod;constructor(t,e,i){this.fsw=i;let s=t;this.path=t=t.replace(tS,""),this.watchPath=s,this.fullWatchPath=F.resolve(s),this.dirParts=[],this.dirParts.forEach(t=>{t.length>1&&t.pop()}),this.followSymlinks=e,this.statMethod=e?"stat":"lstat"}entryPath(t){return F.join(this.watchPath,F.relative(this.watchPath,t.fullPath))}filterPath(t){let{stats:e}=t;if(e&&e.isSymbolicLink())return this.filterDir(t);let i=this.entryPath(t);return this.fsw._isntIgnored(i,e)&&this.fsw._hasReadPermissions(e)}filterDir(t){return this.fsw._isntIgnored(this.entryPath(t),t.stats)}}class tA extends a{closed;options;_closers;_ignoredPaths;_throttled;_streams;_symlinkPaths;_watched;_pendingWrites;_pendingUnlinks;_readyCount;_emitReady;_closePromise;_userIgnored;_readyEmitted;_emitRaw;_boundRemove;_nodeFsHandler;constructor(t={}){super(),this.closed=!1,this._closers=new Map,this._ignoredPaths=new Set,this._throttled=new Map,this._streams=new Set,this._symlinkPaths=new Map,this._watched=new Map,this._pendingWrites=new Map,this._pendingUnlinks=new Map,this._readyCount=0,this._readyEmitted=!1;let e=t.awaitWriteFinish,i={stabilityThreshold:2e3,pollInterval:100},s={persistent:!0,ignoreInitial:!1,ignorePermissionErrors:!1,interval:100,binaryInterval:300,followSymlinks:!0,usePolling:!1,atomic:!0,...t,ignored:t.ignored?tW(t.ignored):tW([]),awaitWriteFinish:!0===e?i:"object"==typeof e&&{...i,...e}};Y&&(s.usePolling=!0),void 0===s.atomic&&(s.atomic=!s.usePolling);let r=process.env.CHOKIDAR_USEPOLLING;if(void 0!==r){let t=r.toLowerCase();"false"===t||"0"===t?s.usePolling=!1:"true"===t||"1"===t?s.usePolling=!0:s.usePolling=!!t}let a=process.env.CHOKIDAR_INTERVAL;a&&(s.interval=Number.parseInt(a,10));let o=0;this._emitReady=()=>{++o>=this._readyCount&&(this._emitReady=V,this._readyEmitted=!0,process.nextTick(()=>this.emit(tt)))},this._emitRaw=(...t)=>this.emit(to,...t),this._boundRemove=this._remove.bind(this),this.options=s,this._nodeFsHandler=new tP(this),Object.freeze(s)}_addIgnoredPath(t){if(tD(t)){for(let e of this._ignoredPaths)if(tD(e)&&e.path===t.path&&e.recursive===t.recursive)return}this._ignoredPaths.add(t)}_removeIgnoredPath(t){if(this._ignoredPaths.delete(t),"string"==typeof t)for(let e of this._ignoredPaths)tD(e)&&e.path===t&&this._ignoredPaths.delete(e)}add(t,e,i){let{cwd:s}=this.options;this.closed=!1,this._closePromise=void 0;let r=tR(t);return s&&(r=r.map(t=>F.isAbsolute(t)?t:F.join(s,t))),r.forEach(t=>{this._removeIgnoredPath(t)}),this._userIgnored=void 0,this._readyCount||(this._readyCount=0),this._readyCount+=r.length,Promise.all(r.map(async t=>{let s=await this._nodeFsHandler._addToNodeFs(t,!i,void 0,0,e);return s&&this._emitReady(),s})).then(t=>{this.closed||t.forEach(t=>{t&&this.add(F.dirname(t),F.basename(e||t))})}),this}unwatch(t){if(this.closed)return this;let e=tR(t),{cwd:i}=this.options;return e.forEach(t=>{F.isAbsolute(t)||this._closers.has(t)||(i&&(t=F.join(i,t)),t=F.resolve(t)),this._closePath(t),this._addIgnoredPath(t),this._watched.has(t)&&this._addIgnoredPath({path:t,recursive:!0}),this._userIgnored=void 0}),this}close(){if(this._closePromise)return this._closePromise;this.closed=!0,this.removeAllListeners();let t=[];return this._closers.forEach(e=>e.forEach(e=>{let i=e();i instanceof Promise&&t.push(i)})),this._streams.forEach(t=>t.destroy()),this._userIgnored=void 0,this._readyCount=0,this._readyEmitted=!1,this._watched.forEach(t=>t.dispose()),this._closers.clear(),this._watched.clear(),this._streams.clear(),this._symlinkPaths.clear(),this._throttled.clear(),this._closePromise=t.length?Promise.all(t).then(()=>void 0):Promise.resolve(),this._closePromise}getWatched(){let t={};return this._watched.forEach((e,i)=>{t[(this.options.cwd?F.relative(this.options.cwd,i):i)||"."]=e.getChildren().sort()}),t}emitWithAll(t,e){this.emit(t,...e),t!==tn&&this.emit(Z,t,...e)}async _emit(t,e,i){let s;if(this.closed)return;let r=this.options;B&&(e=F.normalize(e)),r.cwd&&(e=F.relative(r.cwd,e));let a=[e];null!=i&&a.push(i);let o=r.awaitWriteFinish;if(o&&(s=this._pendingWrites.get(e)))return s.lastChange=new Date,this;if(r.atomic){if(t===tr)return this._pendingUnlinks.set(e,[t,...a]),setTimeout(()=>{this._pendingUnlinks.forEach((t,e)=>{this.emit(...t),this.emit(Z,...t),this._pendingUnlinks.delete(e)})},"number"==typeof r.atomic?r.atomic:100),this;t===te&&this._pendingUnlinks.has(e)&&(t=ti,this._pendingUnlinks.delete(e))}if(o&&(t===te||t===ti)&&this._readyEmitted){let i=(e,i)=>{e?(t=tn,a[0]=e,this.emitWithAll(t,a)):i&&(a.length>1?a[1]=i:a.push(i),this.emitWithAll(t,a))};return this._awaitWriteFinish(e,o.stabilityThreshold,t,i),this}if(t===ti&&!this._throttle(ti,e,50))return this;if(r.alwaysStat&&void 0===i&&(t===te||t===ts||t===ti)){let t,i=r.cwd?F.join(r.cwd,e):e;try{t=await u(i)}catch(t){}if(!t||this.closed)return;a.push(t)}return this.emitWithAll(t,a),this}_handleError(t){let e=t&&t.code;return t&&"ENOENT"!==e&&"ENOTDIR"!==e&&(!this.options.ignorePermissionErrors||"EPERM"!==e&&"EACCES"!==e)&&this.emit(tn,t),t||this.closed}_throttle(t,e,i){let s;this._throttled.has(t)||this._throttled.set(t,new Map);let r=this._throttled.get(t);if(!r)throw Error("invalid throttle");let a=r.get(e);if(a)return a.count++,!1;let o=()=>{let t=r.get(e),i=t?t.count:0;return r.delete(e),clearTimeout(s),t&&clearTimeout(t.timeoutObject),i},n={timeoutObject:s=setTimeout(o,i),clear:o,count:0};return r.set(e,n),n}_incrReadyCount(){return this._readyCount++}_awaitWriteFinish(t,e,i,s){let r,a=this.options.awaitWriteFinish;if("object"!=typeof a)return;let o=a.pollInterval,l=t;this.options.cwd&&!F.isAbsolute(t)&&(l=F.join(this.options.cwd,t));let h=new Date,d=this._pendingWrites;d.has(t)||(d.set(t,{lastChange:h,cancelWait:()=>(d.delete(t),clearTimeout(r),i)}),r=setTimeout(function i(a){n(l,(n,l)=>{if(n||!d.has(t)){n&&"ENOENT"!==n.code&&s(n);return}let h=Number(new Date);a&&l.size!==a.size&&(d.get(t).lastChange=h),h-d.get(t).lastChange>=e?(d.delete(t),s(void 0,l)):r=setTimeout(i,o,l)})},o))}_isIgnored(t,e){if(this.options.atomic&&tk.test(t))return!0;if(!this._userIgnored){let{cwd:t}=this.options,e=(this.options.ignored||[]).map(tj(t)),i=[...[...this._ignoredPaths].map(tj(t)),...e];this._userIgnored=function(t,e){if(null==t)throw TypeError("anymatch: specify first argument");let i=tW(t).map(t=>"function"==typeof t?t:"string"==typeof t?e=>t===e:t instanceof RegExp?e=>t.test(e):"object"==typeof t&&null!==t?e=>{if(t.path===e)return!0;if(t.recursive){let i=F.relative(t.path,e);return!!i&&!i.startsWith("..")&&!F.isAbsolute(i)}return!1}:()=>!1);return null==e?(t,e)=>tI(i,t,e):tI(i,e)}(i,void 0)}return this._userIgnored(t,e)}_isntIgnored(t,e){return!this._isIgnored(t,e)}_getWatchHelpers(t){return new tT(t,this.options.followSymlinks,this)}_getWatchedDir(t){let e=F.resolve(t);return this._watched.has(e)||this._watched.set(e,new tM(e,this._boundRemove)),this._watched.get(e)}_hasReadPermissions(t){return!!this.options.ignorePermissionErrors||!!(256&Number(t.mode))}_remove(t,e,i){let s=F.join(t,e),r=F.resolve(s);if(i=null!=i?i:this._watched.has(s)||this._watched.has(r),!this._throttle("remove",s,100))return;i||1!==this._watched.size||this.add(t,e,!0),this._getWatchedDir(s).getChildren().forEach(t=>this._remove(s,t));let a=this._getWatchedDir(t),o=a.has(e);a.remove(e),this._symlinkPaths.has(r)&&this._symlinkPaths.delete(r);let n=s;if(this.options.cwd&&(n=F.relative(this.options.cwd,s)),this.options.awaitWriteFinish&&this._pendingWrites.has(n)&&this._pendingWrites.get(n).cancelWait()===te)return;this._watched.delete(s),this._watched.delete(r);let l=i?ta:tr;o&&!this._isIgnored(s)&&this._emit(l,s),this._closePath(s)}_closePath(t){this._closeFile(t);let e=F.dirname(t);this._getWatchedDir(e).remove(F.basename(t))}_closeFile(t){let e=this._closers.get(t);e&&(e.forEach(t=>t()),this._closers.delete(t))}_addPathCloser(t,e){if(!e)return;let i=this._closers.get(t);i||(i=[],this._closers.set(t,i)),i.push(e)}_readdirp(t,e){if(this.closed)return;let i=function(t,e={}){let i=e.entryType||e.type;if("both"===i&&(i=M),i&&(e.type=i),t){if("string"!=typeof t)throw TypeError("readdirp: root argument must be a string. Usage: readdirp(root, options)");else if(i&&!N.includes(i))throw Error(`readdirp: Invalid type passed. Use one of ${N.join(", ")}`)}else throw Error("readdirp: root argument is required. Usage: readdirp(root, options)");return e.root=t,new G(e)}(t,{type:Z,alwaysStat:!0,lstat:!0,...e,depth:0});return this._streams.add(i),i.once("close",()=>{i=void 0}),i.once("end",()=>{i&&(this._streams.delete(i),i=void 0)}),i}}function t$(){return{interactive:!1,addTarget(t,e){let i={status:"pending",message:"正在启动"},s="workbench"===t?`${e}:`:`[${t}] `;return{log:{info:t=>x.info(`${s}${t}`),success:t=>x.success(`${s}${t}`),warn:t=>x.warn(`${s}${t}`),error:t=>x.error(`${s}${t}`)},ui:{update(t){let s={...i};for(let[r,a]of(Object.assign(i,t),(i.message!==s.message||i.status!==s.status)&&(0,({pending:x.info,success:x.success,error:x.error})[i.status])(`${e}:${i.message}`),Object.entries(i.links??{})))s.links?.[r]!==a&&x.info(`${r}:${a}`)},select:async()=>void 0,print:t=>console.log(t)}}},close(){}}}async function tN(i){if(D())try{let{TUIManager:s,getNativePackageName:r}=await import("./dist.js"),{createRatatuiDevUI:a}=await import("./ratatui-ui.js"),n=e(t(g(import.meta.url)),"tui");if(!o(n)){let e=await I({name:r(),version:v.version,title:"交互界面"},".",i.signal,{interactive:!0,log:x});n=t(g(e))}i.signal.throwIfAborted();let l=new s({nativeDirectory:n});try{return await a(l,i)}catch(t){throw await l.close(),t}}catch(t){i.signal.aborted||x.warn(`无法启动交互界面,改用日志模式:${W(t)}`)}return t$()}async function tO(t,e,r){let a,o=new AbortController,n=Promise.withResolvers(),l=(t=!1)=>{t&&(process.exitCode=130),o.abort(),n.resolve()},h={project:t,options:e,signal:o.signal};t.assertWorkbenchModules();let d=await tU(h,r.devTargets);if(!d)return;if(e.once&&d.some(({target:t})=>!["platform","workbench"].includes(t.name)))throw Error("--once 仅支持插件或定制工作台同步,不支持 App 等持续调试目标");await R(D());let c=d.some(({target:t})=>"app"===t.name);if(t.plugin.id&&!t.hasWorkbench)await k(t);else if(!t.plugin.id&&c){x.info("未配置插件 ID,正在上传项目并创建平台草稿…");try{await C({project:t,options:{}},await E(r.exclude,{project:t},"draft"))}catch(t){throw Error(`插件初始化失败,未启动调试:${W(t)}`,{cause:t})}}let f=await E(r.exclude,{project:t},"dev"),p=()=>l(!0),m=()=>{process.exitCode=143,l()};process.on("SIGINT",p),process.on("SIGTERM",m);let u=c?await tN({signal:o.signal,onExit:l,projectName:t.plugin.name}):t$(),w=[],_=async t=>{for(let e of t.disposers.splice(0).reverse())try{await e()}catch(e){t.ctx.log.warn(`清理失败:${W(e)}`)}},g=(t,e)=>{o.signal.aborted||(t.ctx.ui.update({status:"error",message:"运行失败"}),t.ctx.log.error(W(e)))},y=t=>{t.changed.size&&t.ready&&!t.running&&!o.signal.aborted&&(t.running=(async()=>{try{for(;t.changed.size&&!o.signal.aborted;){let e=[...t.changed];t.changed.clear();try{await t.listener?.(e)}catch(e){g(t,e)}}}finally{t.running=void 0}})())};try{for(let e of d){let{name:r,title:a,label:o=a,watch:n=[]}=e.target,l={entry:e,paths:n.map(e=>i(t.root,s(t.root,e))),ready:!1,changed:new Set,disposers:[],ctx:{...h,...u.addTarget(r,o),interactive:u.interactive,packDevelopment:()=>t.pack({exclude:f}),onDispose:t=>l.disposers.push(t),onFilesChanged:t=>{l.listener=t}}};w.push(l)}if(e.once){for(let t of w)o.signal.throwIfAborted(),await t.entry.target.start(t.ctx);return}let r=w.flatMap(({paths:t})=>t),l=function(t,e={}){let i=new tA(e);return i.add(t),i}(t.root,{ignoreInitial:!0,followSymlinks:!1,ignored:e=>{let s=i(t.root,e);return!!s&&!r.some(t=>tH(s,t)||tH(t,s))}});l.on("all",(e,s)=>{if(o.signal.aborted)return;let r=i(t.root,s);for(let t of w)t.paths.some(t=>tH(r,t))&&t.changed.add(r);clearTimeout(a),a=setTimeout(()=>w.forEach(y),400)}),l.on("error",n.reject);let c=Promise.all(w.map(async t=>{try{o.signal.throwIfAborted(),await t.entry.target.start(t.ctx),o.signal.throwIfAborted(),t.ready=!0,y(t)}catch(e){t.changed.clear(),g(t,e),await _(t)}}));try{await n.promise}finally{o.abort(),clearTimeout(a);try{await l.close()}finally{await c,await Promise.all(w.map(t=>t.running))}}}catch(t){if(t!==o.signal.reason&&!(t instanceof Error&&"AbortError"===t.name))throw t}finally{for(let t of(o.abort(),w.toReversed()))await _(t);try{await u.close()}finally{process.off("SIGINT",p),process.off("SIGTERM",m)}}}function tH(t,e){return!e||t===e||t.startsWith(`${e}${r}`)}async function tU(t,e){let{options:i}=t,s=[];for(let r of e){let{pluginName:e,target:a}=r,o=!a.appliesTo||await y({pluginName:e,callback:a.appliesTo},t);if(!o&&r.attribute&&i[r.attribute]){if("workbench"===a.name)throw Error("当前项目是普通插件,请在定制工作台项目中使用 dbx dev --workbench");throw Error(`[${e}] 当前项目不支持:${a.title}`)}o&&s.push(r)}if(t.project.hasWorkbench||i.workbench){if(i.plugin)throw Error("定制工作台请使用 dbx dev --workbench 调试");return s.filter(({target:t})=>"workbench"===t.name)}let r=s.filter(({attribute:t})=>t&&"workbench"!==t),a=({attribute:t})=>!!(t&&i[t]),o=new Set;if(r.length&&!i.once&&!i.plugin&&!r.some(a)&&D())for(let{target:t}of r){let e=await b({message:`是否启动${t.title}?`,initialValue:!1});if(S(e)){P("已取消调试。"),process.exitCode=130;return}e&&o.add(t.name)}let n=s.filter(t=>!t.attribute||a(t)||o.has(t.target.name));return n.some(({target:t})=>"app"===t.name)?n.filter(({target:t})=>"platform"!==t.name):n}export{tO as runSession};
2
+ import{dirname as t,join as e,relative as i,resolve as s,sep as r}from"node:path";import{EventEmitter as a}from"node:events";import{existsSync as o,stat as n,unwatchFile as l,watch as h,watchFile as d}from"node:fs";import{lstat as c,open as f,readdir as p,realpath as m,stat as u}from"node:fs/promises";import{Readable as w}from"node:stream";import{type as _}from"node:os";import{fileURLToPath as g}from"node:url";import{callHook as y,runtime as v,dist_ye as b,dist_xe as P,collectHooks as E,log as x,resolvePublicationType as k,pD as S,error_errorMessage as W,isInteractive as D,loadPackage as I}from"./691.js";import{ensureLogin as R}from"./command~1.js";import{uploadDraft as C}from"./draft.js";import*as F from"node:path";let j="files",z="directories",M="files_directories",T={root:".",fileFilter:t=>!0,directoryFilter:t=>!0,type:j,lstat:!1,depth:0x80000000,alwaysStat:!1,highWaterMark:4096};Object.freeze(T);let A="READDIRP_RECURSIVE_ERROR",$=new Set(["ENOENT","EPERM","EACCES","ELOOP",A]),N=[z,"all",M,j],O=new Set([z,"all",M]),H=new Set(["all",M,j]),U="win32"===process.platform,K=t=>!0,L=t=>{if(void 0===t)return K;if("function"==typeof t)return t;if("string"==typeof t){let e=t.trim();return t=>t.basename===e}if(Array.isArray(t)){let e=t.map(t=>t.trim());return t=>e.some(e=>t.basename===e)}return K};class G extends w{parents;reading;parent;_stat;_maxDepth;_wantsDir;_wantsFile;_wantsEverything;_root;_isDirent;_statsProp;_rdOptions;_fileFilter;_directoryFilter;constructor(t={}){super({objectMode:!0,autoDestroy:!0,highWaterMark:t.highWaterMark});let e={...T,...t},{root:i,type:r}=e;this._fileFilter=L(e.fileFilter),this._directoryFilter=L(e.directoryFilter);let a=e.lstat?c:u;U?this._stat=t=>a(t,{bigint:!0}):this._stat=a,this._maxDepth=null!=e.depth&&Number.isSafeInteger(e.depth)?e.depth:T.depth,this._wantsDir=!!r&&O.has(r),this._wantsFile=!!r&&H.has(r),this._wantsEverything="all"===r,this._root=s(i),this._isDirent=!e.alwaysStat,this._statsProp=this._isDirent?"dirent":"stats",this._rdOptions={encoding:"utf8",withFileTypes:this._isDirent},this.parents=[this._exploreDir(i,1)],this.reading=!1,this.parent=void 0}async _read(t){if(!this.reading){this.reading=!0;try{for(;!this.destroyed&&t>0;){let e=this.parent,i=e&&e.files;if(i&&i.length>0){let{path:s,depth:r}=e,a=i.splice(0,t).map(t=>this._formatEntry(t,s));for(let e of(await Promise.all(a))){if(!e)continue;if(this.destroyed)return;let i=await this._getEntryType(e);"directory"===i&&this._directoryFilter(e)?(r<=this._maxDepth&&this.parents.push(this._exploreDir(e.fullPath,r+1)),this._wantsDir&&(this.push(e),t--)):("file"===i||this._includeAsFile(e))&&this._fileFilter(e)&&this._wantsFile&&(this.push(e),t--)}}else{let t=this.parents.pop();if(!t){this.push(null);break}if(this.parent=await t,this.destroyed)return}}}catch(t){this.destroy(t)}finally{this.reading=!1}}}async _exploreDir(t,e){let i;try{i=await p(t,this._rdOptions)}catch(t){this._onError(t)}return{files:i,depth:e,path:t}}async _formatEntry(t,r){let a,o=this._isDirent?t.name:t;try{let n=s(e(r,o));(a={path:i(this._root,n),fullPath:n,basename:o})[this._statsProp]=this._isDirent?t:await this._stat(n)}catch(t){this._onError(t);return}return a}_onError(t){$.has(t.code)&&!this.destroyed?this.emit("warn",t):this.destroy(t)}async _getEntryType(t){if(!t&&this._statsProp in t)return"";let e=t[this._statsProp];if(e.isFile())return"file";if(e.isDirectory())return"directory";if(e&&e.isSymbolicLink()){let e=t.fullPath;try{let t=await m(e),i=await c(t);if(i.isFile())return"file";if(i.isDirectory()){let i=t.length;if(e.startsWith(t)&&e.substr(i,1)===r){let i=Error(`Circular symlink detected: "${e}" points to "${t}"`);return i.code=A,this._onError(i)}return"directory"}}catch(t){return this._onError(t),""}}}_includeAsFile(t){let e=t&&t[this._statsProp];return e&&this._wantsEverything&&!e.isDirectory()}}let V=()=>{},q=process.platform,B="win32"===q,J="darwin"===q,Q="linux"===q,X="freebsd"===q,Y="OS400"===_(),Z="all",tt="ready",te="add",ti="change",ts="addDir",tr="unlink",ta="unlinkDir",to="raw",tn="error",tl={lstat:c,stat:u},th="listeners",td="errHandlers",tc="rawEmitters",tf=[th,td,tc],tp=new Set(["3dm","3ds","3g2","3gp","7z","a","aac","adp","afdesign","afphoto","afpub","ai","aif","aiff","alz","ape","apk","appimage","ar","arj","asf","au","avi","bak","baml","bh","bin","bk","bmp","btif","bz2","bzip2","cab","caf","cgm","class","cmx","cpio","cr2","cur","dat","dcm","deb","dex","djvu","dll","dmg","dng","doc","docm","docx","dot","dotm","dra","DS_Store","dsk","dts","dtshd","dvb","dwg","dxf","ecelp4800","ecelp7470","ecelp9600","egg","eol","eot","epub","exe","f4v","fbs","fh","fla","flac","flatpak","fli","flv","fpx","fst","fvt","g3","gh","gif","graffle","gz","gzip","h261","h263","h264","icns","ico","ief","img","ipa","iso","jar","jpeg","jpg","jpgv","jpm","jxr","key","ktx","lha","lib","lvp","lz","lzh","lzma","lzo","m3u","m4a","m4v","mar","mdi","mht","mid","midi","mj2","mka","mkv","mmr","mng","mobi","mov","movie","mp3","mp4","mp4a","mpeg","mpg","mpga","mxu","nef","npx","numbers","nupkg","o","odp","ods","odt","oga","ogg","ogv","otf","ott","pages","pbm","pcx","pdb","pdf","pea","pgm","pic","png","pnm","pot","potm","potx","ppa","ppam","ppm","pps","ppsm","ppsx","ppt","pptm","pptx","psd","pya","pyc","pyo","pyv","qt","rar","ras","raw","resources","rgb","rip","rlc","rmf","rmvb","rpm","rtf","rz","s3m","s7z","scpt","sgi","shar","snap","sil","sketch","slk","smv","snk","so","stl","suo","sub","swf","tar","tbz","tbz2","tga","tgz","thmx","tif","tiff","tlz","ttc","ttf","txz","udf","uvh","uvi","uvm","uvp","uvs","uvu","viv","vob","war","wav","wax","wbmp","wdp","weba","webm","webp","whl","wim","wm","wma","wmv","wmx","woff","woff2","wrm","wvx","xbm","xif","xla","xlam","xls","xlsb","xlsm","xlsx","xlt","xltm","xltx","xm","xmind","xpi","xpm","xwd","xz","z","zip","zipx"]),tm=(t,e)=>{t instanceof Set?t.forEach(e):e(t)},tu=(t,e,i)=>{let s=t[e];s instanceof Set||(t[e]=s=new Set([s])),s.add(i)},tw=(t,e,i)=>{let s=t[e];s instanceof Set?s.delete(i):s===i&&delete t[e]},t_=t=>t instanceof Set?0===t.size:!t,tg=new Map;function ty(t,e,i,s,r){try{return h(t,{persistent:e.persistent},(e,s)=>{i(t),r(e,s,{watchedPath:t}),s&&t!==s&&tv(F.resolve(t,s),th,F.join(t,s))})}catch(t){s(t);return}}let tv=(t,e,i,s,r)=>{let a=tg.get(t);a&&tm(a[e],t=>{t(i,s,r)})},tb=new Map;class tP{fsw;_boundHandleError;constructor(t){this.fsw=t,this._boundHandleError=e=>t._handleError(e)}_watchWithNodeFs(t,e){let i,s=this.fsw.options,r=F.dirname(t),a=F.basename(t);this.fsw._getWatchedDir(r).add(a);let o=F.resolve(t),n={persistent:s.persistent};if(e||(e=V),s.usePolling)n.interval=s.interval!==s.binaryInterval&&tp.has(F.extname(a).slice(1).toLowerCase())?s.binaryInterval:s.interval,i=((t,e,i,s)=>{let{listener:r,rawEmitter:a}=s,o=tb.get(e),n=o&&o.options;return n&&(n.persistent<i.persistent||n.interval>i.interval)&&(l(e),o=void 0),o?(tu(o,th,r),tu(o,tc,a)):(o={listeners:r,rawEmitters:a,options:i,watcher:d(e,i,(i,s)=>{tm(o.rawEmitters,t=>{t(ti,e,{curr:i,prev:s})});let r=i.mtimeMs;(i.size!==s.size||r>s.mtimeMs||0===r)&&tm(o.listeners,e=>e(t,i))})},tb.set(e,o)),()=>{tw(o,th,r),tw(o,tc,a),t_(o.listeners)&&(tb.delete(e),l(e),o.options=o.watcher=void 0,Object.freeze(o))}})(t,o,n,{listener:e,rawEmitter:this.fsw._emitRaw});else i=((t,e,i,s)=>{let r,{listener:a,errHandler:o,rawEmitter:n}=s,l=tg.get(e);if(!i.persistent){if(!(r=ty(t,i,a,o,n)))return;return r.close.bind(r)}if(l)tu(l,th,a),tu(l,td,o),tu(l,tc,n);else{if(!(r=ty(t,i,tv.bind(null,e,th),o,tv.bind(null,e,tc))))return;r.on(tn,async i=>{let s=tv.bind(null,e,td);if(l&&(l.watcherUnusable=!0),B&&"EPERM"===i.code)try{let e=await f(t,"r");await e.close(),s(i)}catch(t){}else s(i)}),l={listeners:a,errHandlers:o,rawEmitters:n,watcher:r},tg.set(e,l)}return()=>{if(tw(l,th,a),tw(l,td,o),tw(l,tc,n),t_(l.listeners)){let t;l.watcher.close(),tg.delete(e),tf.forEach((t=l,e=>{let i=t[e];i instanceof Set?i.clear():delete t[e]})),l.watcher=void 0,Object.freeze(l)}}})(t,o,n,{listener:e,errHandler:this._boundHandleError,rawEmitter:this.fsw._emitRaw});return i}_handleFile(t,e,i){if(this.fsw.closed)return;let s=F.dirname(t),r=F.basename(t),a=this.fsw._getWatchedDir(s),o=e;if(a.has(r))return;let n=async(e,i)=>{if(this.fsw._throttle("watch",t,5))if(i&&0!==i.mtimeMs){if(a.has(r)){let e=i.atimeMs,s=i.mtimeMs;(!e||e<=s||s!==o.mtimeMs)&&this.fsw._emit(ti,t,i),o=i}}else try{let i=await u(t);if(this.fsw.closed)return;let s=i.atimeMs,r=i.mtimeMs;if((!s||s<=r||r!==o.mtimeMs)&&this.fsw._emit(ti,t,i),(J||Q||X)&&o.ino!==i.ino){this.fsw._closeFile(e),o=i;let s=this._watchWithNodeFs(t,n);s&&this.fsw._addPathCloser(e,s)}else o=i}catch(t){this.fsw._remove(s,r)}},l=this._watchWithNodeFs(t,n);if(!(i&&this.fsw.options.ignoreInitial)&&this.fsw._isntIgnored(t)){if(!this.fsw._throttle(te,t,0))return;this.fsw._emit(te,t,e)}return l}async _handleSymlink(t,e,i,s){if(this.fsw.closed)return;let r=t.fullPath,a=this.fsw._getWatchedDir(e);if(!this.fsw.options.followSymlinks){let e;this.fsw._incrReadyCount();try{e=await m(i)}catch(t){return this.fsw._emitReady(),!0}if(this.fsw.closed)return;return a.has(s)?this.fsw._symlinkPaths.get(r)!==e&&(this.fsw._symlinkPaths.set(r,e),this.fsw._emit(ti,i,t.stats)):(a.add(s),this.fsw._symlinkPaths.set(r,e),this.fsw._emit(te,i,t.stats)),this.fsw._emitReady(),!0}if(this.fsw._symlinkPaths.has(r))return!0;this.fsw._symlinkPaths.set(r,!0)}_handleRead(t,e,i,s,r,a,o){t=F.join(t,"");let n=s?`${t}:${s}`:t;if(!(o=this.fsw._throttle("readdir",n,1e3)))return;let l=this.fsw._getWatchedDir(i.path),h=new Set,d=this.fsw._readdirp(t,{fileFilter:t=>i.filterPath(t),directoryFilter:t=>i.filterDir(t)});if(d)return d.on("data",async o=>{if(this.fsw.closed){d=void 0;return}let n=o.path,c=F.join(t,n);if(h.add(n),!(o.stats.isSymbolicLink()&&await this._handleSymlink(o,t,c,n))){if(this.fsw.closed){d=void 0;return}n!==s&&(s||l.has(n))||(this.fsw._incrReadyCount(),c=F.join(r,F.relative(r,c)),this._addToNodeFs(c,e,i,a+1))}}).on(tn,this._boundHandleError),new Promise((e,n)=>{if(!d)return n();d.once("end",()=>{if(this.fsw.closed){d=void 0;return}let n=!!o&&o.clear();e(void 0),l.getChildren().filter(e=>e!==t&&!h.has(e)).forEach(e=>{this.fsw._remove(t,e)}),d=void 0,n&&this._handleRead(t,!1,i,s,r,a,o)})})}async _handleDir(t,e,i,s,r,a,o){let n,l,h=this.fsw._getWatchedDir(F.dirname(t)),d=h.has(F.basename(t));i&&this.fsw.options.ignoreInitial||r||d||this.fsw._emit(ts,t,e),h.add(F.basename(t)),this.fsw._getWatchedDir(t);let c=this.fsw.options.depth;if((null==c||s<=c)&&!this.fsw._symlinkPaths.has(o)){if(!r&&(await this._handleRead(t,i,a,r,t,s,n),this.fsw.closed))return;l=this._watchWithNodeFs(t,(e,i)=>{i&&0===i.mtimeMs||this._handleRead(e,!1,a,r,t,s,n)})}return l}async _addToNodeFs(t,e,i,s,r){let a=this.fsw._emitReady;if(this.fsw._isIgnored(t)||this.fsw.closed)return a(),!1;let o=this.fsw._getWatchHelpers(t);i&&(o.filterPath=t=>i.filterPath(t),o.filterDir=t=>i.filterDir(t));try{let i,n=await tl[o.statMethod](o.watchPath);if(this.fsw.closed)return;if(this.fsw._isIgnored(o.watchPath,n))return a(),!1;let l=this.fsw.options.followSymlinks;if(n.isDirectory()){let a=F.resolve(t),h=l?await m(t):t;if(this.fsw.closed||(i=await this._handleDir(o.watchPath,n,e,s,r,o,h),this.fsw.closed))return;a!==h&&void 0!==h&&this.fsw._symlinkPaths.set(a,h)}else if(n.isSymbolicLink()){let r=l?await m(t):t;if(this.fsw.closed)return;let a=F.dirname(o.watchPath);if(this.fsw._getWatchedDir(a).add(o.watchPath),this.fsw._emit(te,o.watchPath,n),i=await this._handleDir(a,n,e,s,t,o,r),this.fsw.closed)return;void 0!==r&&this.fsw._symlinkPaths.set(F.resolve(t),r)}else i=this._handleFile(o.watchPath,n,e);return a(),i&&this.fsw._addPathCloser(t,i),!1}catch(e){if(this.fsw._handleError(e))return a(),t}}}let tE=/\\/g,tx=/\/\//g,tk=/\..*\.(sw[px])$|~$|\.subl.*\.tmp/,tS=/^\.[/\\]/;function tW(t){return Array.isArray(t)?t:[t]}let tD=t=>"object"==typeof t&&null!==t&&!(t instanceof RegExp);function tI(t,e,i){let s=function(t){if("string"!=typeof t)throw Error("string expected");t=(t=F.normalize(t)).replace(/\\/g,"/");let e=!1;return t.startsWith("//")&&(e=!0),t=t.replace(tx,"/"),e&&(t="/"+t),t}(e);for(let e=0;e<t.length;e++)if((0,t[e])(s,i))return!0;return!1}let tR=t=>{let e=tW(t).flat();if(!e.every(t=>"string"==typeof t))throw TypeError(`Non-string provided as watch path: ${e}`);return e.map(tF)},tC=t=>{let e=t.replace(tE,"/"),i=!1;return e.startsWith("//")&&(i=!0),e=e.replace(tx,"/"),i&&(e="/"+e),e},tF=t=>tC(F.normalize(tC(t))),tj=(t="")=>e=>"string"==typeof e?tF(F.isAbsolute(e)?e:F.join(t,e)):e,tz=Object.freeze(new Set);class tM{path;_removeWatcher;items;constructor(t,e){this.path=t,this._removeWatcher=e,this.items=new Set}add(t){let{items:e}=this;e&&"."!==t&&".."!==t&&e.add(t)}async remove(t){let{items:e}=this;if(!e||(e.delete(t),e.size>0))return;let i=this.path;try{await p(i)}catch(t){this._removeWatcher&&this._removeWatcher(F.dirname(i),F.basename(i))}}has(t){let{items:e}=this;if(e)return e.has(t)}getChildren(){let{items:t}=this;return t?[...t.values()]:[]}dispose(){this.items.clear(),this.path="",this._removeWatcher=V,this.items=tz,Object.freeze(this)}}class tT{fsw;path;watchPath;fullWatchPath;dirParts;followSymlinks;statMethod;constructor(t,e,i){this.fsw=i;let s=t;this.path=t=t.replace(tS,""),this.watchPath=s,this.fullWatchPath=F.resolve(s),this.dirParts=[],this.dirParts.forEach(t=>{t.length>1&&t.pop()}),this.followSymlinks=e,this.statMethod=e?"stat":"lstat"}entryPath(t){return F.join(this.watchPath,F.relative(this.watchPath,t.fullPath))}filterPath(t){let{stats:e}=t;if(e&&e.isSymbolicLink())return this.filterDir(t);let i=this.entryPath(t);return this.fsw._isntIgnored(i,e)&&this.fsw._hasReadPermissions(e)}filterDir(t){return this.fsw._isntIgnored(this.entryPath(t),t.stats)}}class tA extends a{closed;options;_closers;_ignoredPaths;_throttled;_streams;_symlinkPaths;_watched;_pendingWrites;_pendingUnlinks;_readyCount;_emitReady;_closePromise;_userIgnored;_readyEmitted;_emitRaw;_boundRemove;_nodeFsHandler;constructor(t={}){super(),this.closed=!1,this._closers=new Map,this._ignoredPaths=new Set,this._throttled=new Map,this._streams=new Set,this._symlinkPaths=new Map,this._watched=new Map,this._pendingWrites=new Map,this._pendingUnlinks=new Map,this._readyCount=0,this._readyEmitted=!1;let e=t.awaitWriteFinish,i={stabilityThreshold:2e3,pollInterval:100},s={persistent:!0,ignoreInitial:!1,ignorePermissionErrors:!1,interval:100,binaryInterval:300,followSymlinks:!0,usePolling:!1,atomic:!0,...t,ignored:t.ignored?tW(t.ignored):tW([]),awaitWriteFinish:!0===e?i:"object"==typeof e&&{...i,...e}};Y&&(s.usePolling=!0),void 0===s.atomic&&(s.atomic=!s.usePolling);let r=process.env.CHOKIDAR_USEPOLLING;if(void 0!==r){let t=r.toLowerCase();"false"===t||"0"===t?s.usePolling=!1:"true"===t||"1"===t?s.usePolling=!0:s.usePolling=!!t}let a=process.env.CHOKIDAR_INTERVAL;a&&(s.interval=Number.parseInt(a,10));let o=0;this._emitReady=()=>{++o>=this._readyCount&&(this._emitReady=V,this._readyEmitted=!0,process.nextTick(()=>this.emit(tt)))},this._emitRaw=(...t)=>this.emit(to,...t),this._boundRemove=this._remove.bind(this),this.options=s,this._nodeFsHandler=new tP(this),Object.freeze(s)}_addIgnoredPath(t){if(tD(t)){for(let e of this._ignoredPaths)if(tD(e)&&e.path===t.path&&e.recursive===t.recursive)return}this._ignoredPaths.add(t)}_removeIgnoredPath(t){if(this._ignoredPaths.delete(t),"string"==typeof t)for(let e of this._ignoredPaths)tD(e)&&e.path===t&&this._ignoredPaths.delete(e)}add(t,e,i){let{cwd:s}=this.options;this.closed=!1,this._closePromise=void 0;let r=tR(t);return s&&(r=r.map(t=>F.isAbsolute(t)?t:F.join(s,t))),r.forEach(t=>{this._removeIgnoredPath(t)}),this._userIgnored=void 0,this._readyCount||(this._readyCount=0),this._readyCount+=r.length,Promise.all(r.map(async t=>{let s=await this._nodeFsHandler._addToNodeFs(t,!i,void 0,0,e);return s&&this._emitReady(),s})).then(t=>{this.closed||t.forEach(t=>{t&&this.add(F.dirname(t),F.basename(e||t))})}),this}unwatch(t){if(this.closed)return this;let e=tR(t),{cwd:i}=this.options;return e.forEach(t=>{F.isAbsolute(t)||this._closers.has(t)||(i&&(t=F.join(i,t)),t=F.resolve(t)),this._closePath(t),this._addIgnoredPath(t),this._watched.has(t)&&this._addIgnoredPath({path:t,recursive:!0}),this._userIgnored=void 0}),this}close(){if(this._closePromise)return this._closePromise;this.closed=!0,this.removeAllListeners();let t=[];return this._closers.forEach(e=>e.forEach(e=>{let i=e();i instanceof Promise&&t.push(i)})),this._streams.forEach(t=>t.destroy()),this._userIgnored=void 0,this._readyCount=0,this._readyEmitted=!1,this._watched.forEach(t=>t.dispose()),this._closers.clear(),this._watched.clear(),this._streams.clear(),this._symlinkPaths.clear(),this._throttled.clear(),this._closePromise=t.length?Promise.all(t).then(()=>void 0):Promise.resolve(),this._closePromise}getWatched(){let t={};return this._watched.forEach((e,i)=>{t[(this.options.cwd?F.relative(this.options.cwd,i):i)||"."]=e.getChildren().sort()}),t}emitWithAll(t,e){this.emit(t,...e),t!==tn&&this.emit(Z,t,...e)}async _emit(t,e,i){let s;if(this.closed)return;let r=this.options;B&&(e=F.normalize(e)),r.cwd&&(e=F.relative(r.cwd,e));let a=[e];null!=i&&a.push(i);let o=r.awaitWriteFinish;if(o&&(s=this._pendingWrites.get(e)))return s.lastChange=new Date,this;if(r.atomic){if(t===tr)return this._pendingUnlinks.set(e,[t,...a]),setTimeout(()=>{this._pendingUnlinks.forEach((t,e)=>{this.emit(...t),this.emit(Z,...t),this._pendingUnlinks.delete(e)})},"number"==typeof r.atomic?r.atomic:100),this;t===te&&this._pendingUnlinks.has(e)&&(t=ti,this._pendingUnlinks.delete(e))}if(o&&(t===te||t===ti)&&this._readyEmitted){let i=(e,i)=>{e?(t=tn,a[0]=e,this.emitWithAll(t,a)):i&&(a.length>1?a[1]=i:a.push(i),this.emitWithAll(t,a))};return this._awaitWriteFinish(e,o.stabilityThreshold,t,i),this}if(t===ti&&!this._throttle(ti,e,50))return this;if(r.alwaysStat&&void 0===i&&(t===te||t===ts||t===ti)){let t,i=r.cwd?F.join(r.cwd,e):e;try{t=await u(i)}catch(t){}if(!t||this.closed)return;a.push(t)}return this.emitWithAll(t,a),this}_handleError(t){let e=t&&t.code;return t&&"ENOENT"!==e&&"ENOTDIR"!==e&&(!this.options.ignorePermissionErrors||"EPERM"!==e&&"EACCES"!==e)&&this.emit(tn,t),t||this.closed}_throttle(t,e,i){let s;this._throttled.has(t)||this._throttled.set(t,new Map);let r=this._throttled.get(t);if(!r)throw Error("invalid throttle");let a=r.get(e);if(a)return a.count++,!1;let o=()=>{let t=r.get(e),i=t?t.count:0;return r.delete(e),clearTimeout(s),t&&clearTimeout(t.timeoutObject),i},n={timeoutObject:s=setTimeout(o,i),clear:o,count:0};return r.set(e,n),n}_incrReadyCount(){return this._readyCount++}_awaitWriteFinish(t,e,i,s){let r,a=this.options.awaitWriteFinish;if("object"!=typeof a)return;let o=a.pollInterval,l=t;this.options.cwd&&!F.isAbsolute(t)&&(l=F.join(this.options.cwd,t));let h=new Date,d=this._pendingWrites;d.has(t)||(d.set(t,{lastChange:h,cancelWait:()=>(d.delete(t),clearTimeout(r),i)}),r=setTimeout(function i(a){n(l,(n,l)=>{if(n||!d.has(t)){n&&"ENOENT"!==n.code&&s(n);return}let h=Number(new Date);a&&l.size!==a.size&&(d.get(t).lastChange=h),h-d.get(t).lastChange>=e?(d.delete(t),s(void 0,l)):r=setTimeout(i,o,l)})},o))}_isIgnored(t,e){if(this.options.atomic&&tk.test(t))return!0;if(!this._userIgnored){let{cwd:t}=this.options,e=(this.options.ignored||[]).map(tj(t)),i=[...[...this._ignoredPaths].map(tj(t)),...e];this._userIgnored=function(t,e){if(null==t)throw TypeError("anymatch: specify first argument");let i=tW(t).map(t=>"function"==typeof t?t:"string"==typeof t?e=>t===e:t instanceof RegExp?e=>t.test(e):"object"==typeof t&&null!==t?e=>{if(t.path===e)return!0;if(t.recursive){let i=F.relative(t.path,e);return!!i&&!i.startsWith("..")&&!F.isAbsolute(i)}return!1}:()=>!1);return null==e?(t,e)=>tI(i,t,e):tI(i,e)}(i,void 0)}return this._userIgnored(t,e)}_isntIgnored(t,e){return!this._isIgnored(t,e)}_getWatchHelpers(t){return new tT(t,this.options.followSymlinks,this)}_getWatchedDir(t){let e=F.resolve(t);return this._watched.has(e)||this._watched.set(e,new tM(e,this._boundRemove)),this._watched.get(e)}_hasReadPermissions(t){return!!this.options.ignorePermissionErrors||!!(256&Number(t.mode))}_remove(t,e,i){let s=F.join(t,e),r=F.resolve(s);if(i=null!=i?i:this._watched.has(s)||this._watched.has(r),!this._throttle("remove",s,100))return;i||1!==this._watched.size||this.add(t,e,!0),this._getWatchedDir(s).getChildren().forEach(t=>this._remove(s,t));let a=this._getWatchedDir(t),o=a.has(e);a.remove(e),this._symlinkPaths.has(r)&&this._symlinkPaths.delete(r);let n=s;if(this.options.cwd&&(n=F.relative(this.options.cwd,s)),this.options.awaitWriteFinish&&this._pendingWrites.has(n)&&this._pendingWrites.get(n).cancelWait()===te)return;this._watched.delete(s),this._watched.delete(r);let l=i?ta:tr;o&&!this._isIgnored(s)&&this._emit(l,s),this._closePath(s)}_closePath(t){this._closeFile(t);let e=F.dirname(t);this._getWatchedDir(e).remove(F.basename(t))}_closeFile(t){let e=this._closers.get(t);e&&(e.forEach(t=>t()),this._closers.delete(t))}_addPathCloser(t,e){if(!e)return;let i=this._closers.get(t);i||(i=[],this._closers.set(t,i)),i.push(e)}_readdirp(t,e){if(this.closed)return;let i=function(t,e={}){let i=e.entryType||e.type;if("both"===i&&(i=M),i&&(e.type=i),t){if("string"!=typeof t)throw TypeError("readdirp: root argument must be a string. Usage: readdirp(root, options)");else if(i&&!N.includes(i))throw Error(`readdirp: Invalid type passed. Use one of ${N.join(", ")}`)}else throw Error("readdirp: root argument is required. Usage: readdirp(root, options)");return e.root=t,new G(e)}(t,{type:Z,alwaysStat:!0,lstat:!0,...e,depth:0});return this._streams.add(i),i.once("close",()=>{i=void 0}),i.once("end",()=>{i&&(this._streams.delete(i),i=void 0)}),i}}function t$(){return{interactive:!1,addTarget(t,e){let i={status:"pending",message:"正在启动"},s="workbench"===t?`${e}:`:`[${t}] `;return{log:{info:t=>x.info(`${s}${t}`),success:t=>x.success(`${s}${t}`),warn:t=>x.warn(`${s}${t}`),error:t=>x.error(`${s}${t}`)},ui:{update(t){let s={...i};for(let[r,a]of(Object.assign(i,t),(i.message!==s.message||i.status!==s.status)&&(0,({pending:x.info,success:x.success,error:x.error})[i.status])(`${e}:${i.message}`),Object.entries(i.links??{})))s.links?.[r]!==a&&x.info(`${r}:${a}`)},select:async()=>void 0,print:t=>console.log(t)}}},close(){}}}async function tN(i){if(D())try{let{TUIManager:s,getNativePackageName:r}=await import("./dist.js"),{createRatatuiDevUI:a}=await import("./ratatui-ui.js"),n=e(t(g(import.meta.url)),"tui");if(!o(n)){let e=await I({name:r(),version:v.version,title:"交互界面"},".",i.signal,{interactive:!0,log:x});n=t(g(e))}i.signal.throwIfAborted();let l=new s({nativeDirectory:n});try{return await a(l,i)}catch(t){throw await l.close(),t}}catch(t){i.signal.aborted||x.warn(`无法启动交互界面,改用日志模式:${W(t)}`)}return t$()}async function tO(t,e,r){let a,o=new AbortController,n=Promise.withResolvers(),l=(t=!1)=>{t&&(process.exitCode=130),o.abort(),n.resolve()},h={project:t,options:e,signal:o.signal};t.assertWorkbenchModules();let d=await tU(h,r.devTargets);if(!d)return;if(e.once&&d.some(({target:t})=>!["platform","workbench"].includes(t.name)))throw Error("--once 仅支持插件或定制工作台同步,不支持 App 等持续调试目标");await R(D());let c=d.some(({target:t})=>"app"===t.name);if(t.plugin.id&&!t.hasWorkbench)await k(t);else if(!t.plugin.id&&c){x.info("未配置插件 ID,正在上传项目并创建平台草稿…");try{await C({project:t,options:{}},await E(r.exclude,{project:t},"draft"))}catch(t){throw Error(`插件初始化失败,未启动调试:${W(t)}`,{cause:t})}}let f=await E(r.exclude,{project:t},"dev"),p=()=>l(!0),m=()=>{process.exitCode=143,l()};process.on("SIGINT",p),process.on("SIGTERM",m);let u=c?await tN({signal:o.signal,onExit:l,projectName:t.plugin.name}):t$(),w=[],_=async t=>{for(let e of t.disposers.splice(0).reverse())try{await e()}catch(e){t.ctx.log.warn(`清理失败:${W(e)}`)}},g=(t,e)=>{o.signal.aborted||(t.ctx.ui.update({status:"error",message:"运行失败"}),t.ctx.log.error(W(e)))},y=t=>{t.changed.size&&t.ready&&!t.running&&!o.signal.aborted&&(t.running=(async()=>{try{for(;t.changed.size&&!o.signal.aborted;){let e=[...t.changed];t.changed.clear();try{await t.listener?.(e)}catch(e){g(t,e)}}}finally{t.running=void 0}})())};try{for(let e of d){let{name:r,title:a,label:o=a,watch:n=[]}=e.target,l={entry:e,paths:n.map(e=>i(t.root,s(t.root,e))),ready:!1,changed:new Set,disposers:[],ctx:{...h,...u.addTarget(r,o),interactive:u.interactive,packDevelopment:()=>t.pack({exclude:f}),onDispose:t=>l.disposers.push(t),onFilesChanged:t=>{l.listener=t}}};w.push(l)}if(e.once){for(let t of w)o.signal.throwIfAborted(),await t.entry.target.start(t.ctx);return}let r=w.flatMap(({paths:t})=>t),l=function(t,e={}){let i=new tA(e);return i.add(t),i}(t.root,{ignoreInitial:!0,followSymlinks:!1,ignored:e=>{let s=i(t.root,e);return!!s&&!r.some(t=>tH(s,t)||tH(t,s))}});l.on("all",(e,s)=>{if(o.signal.aborted)return;let r=i(t.root,s);for(let t of w)t.paths.some(t=>tH(r,t))&&t.changed.add(r);clearTimeout(a),a=setTimeout(()=>w.forEach(y),400)}),l.on("error",n.reject);let c=Promise.all(w.map(async t=>{try{o.signal.throwIfAborted(),await t.entry.target.start(t.ctx),o.signal.throwIfAborted(),t.ready=!0,y(t)}catch(e){t.changed.clear(),g(t,e),await _(t)}}));try{await n.promise}finally{o.abort(),clearTimeout(a);try{await l.close()}finally{await c,await Promise.all(w.map(t=>t.running))}}}catch(t){if(t!==o.signal.reason&&!(t instanceof Error&&"AbortError"===t.name))throw t}finally{for(let t of(o.abort(),w.toReversed()))await _(t);try{await u.close()}finally{process.off("SIGINT",p),process.off("SIGTERM",m)}}}function tH(t,e){return!e||t===e||t.startsWith(`${e}${r}`)}async function tU(t,e){let{options:i}=t,s=[];for(let r of e){let{pluginName:e,target:a}=r,o=!a.appliesTo||await y({pluginName:e,callback:a.appliesTo},t);if(!o&&r.attribute&&i[r.attribute]){if("workbench"===a.name)throw Error("请在定制工作台项目中使用 dbx dev --workbench");throw Error(`[${e}] 当前项目不支持:${a.title}`)}o&&s.push(r)}if(t.project.hasWorkbench||i.workbench){if(i.plugin)throw Error("定制工作台请使用 dbx dev --workbench 调试");return s.filter(({target:t})=>"workbench"===t.name)}let r=s.filter(({attribute:t})=>t&&"workbench"!==t),a=({attribute:t})=>!!(t&&i[t]),o=new Set;if(r.length&&!i.once&&!i.plugin&&!r.some(a)&&D())for(let{target:t}of r){let e=await b({message:`是否启动${t.title}?`,initialValue:!1});if(S(e)){P("已取消调试。"),process.exitCode=130;return}e&&o.add(t.name)}let n=s.filter(t=>!t.attribute||a(t)||o.has(t.target.name));return n.some(({target:t})=>"app"===t.name)?n.filter(({target:t})=>"platform"!==t.name):n}export{tO as runSession};
@@ -1,14 +1,14 @@
1
1
  ---
2
2
  name: doubao-plugin-cli
3
- description: 用于选择豆包插件的能力组合,并通过 dbx 创建、配置、调试、上传和提审;覆盖通用插件、含 App 的应用插件、定制工作台,以及 MCP 服务准备与接入。
3
+ description: 用于选择豆包插件的能力组合,并通过 dbx 创建、配置、调试、上传和提审;覆盖通用插件、应用插件、豆包工作台(定制工作台),以及 MCP 服务准备与接入。用户简称“工作台”,且涉及豆包首页、导航、推荐或预装插件/Skill 时也适用。
4
4
  metadata:
5
5
  display_name: 豆包插件 CLI 开发
6
- display_description: 使用 dbx 开发通用插件或含 App 的应用插件,并处理调试、上传与审核。
6
+ display_description: 使用 dbx 开发通用插件或应用插件,并处理调试、上传与审核。
7
7
  ---
8
8
 
9
9
  # 豆包插件 CLI
10
10
 
11
- 使用 `@doubao-dev/cli` 提供的 `dbx`,命令选项以当前版本的 `dbx <命令> --help` 为准。
11
+ 命令选项以当前版本的 `dbx <命令> --help` 为准。
12
12
 
13
13
  - 项目命令从当前目录或 `--cwd <项目内目录>` 向上查找最近的 `plugin.json`。核对目标项目并保留已有 `id` 和 `publicationType`。
14
14
  - 字段定义中的字符串长度按 Unicode 码点计数,“非空”不包含纯空白字符串。
@@ -27,6 +27,7 @@ metadata:
27
27
  | --- | --- |
28
28
  | 创建项目、查看完整目录结构、选择能力 | [项目配置](references/cli/project.md);[TODO 示例](references/examples/todo-example.md) |
29
29
  | 新建或扩展 MCP、选择托管路线、回收生成结果 | [MCP 服务准备](references/cli/development.md#mcp-服务准备) |
30
+ | 已选妙搭开发或部署 MCP / MCP Apps | `miaoda-mcp-dev` Skill |
30
31
  | 验证业务效果、排查失败或继续已有任务 | [业务验证](references/cli/development.md#业务验证);[续做与恢复](references/cli/development.md#续做与恢复) |
31
32
  | 定制工作台配置、预装资源与完整示例 | [工作台包协议](references/protocols/workbench.md);[资源搜索](references/cli/project.md#配置工作台预装资源);[合同工作台示例](references/examples/workbench-example.md) |
32
33
  | `dbx dev` 调试、个人安装或卸载,`dbx inspect` 单独调试 MCP | [开发调试](references/cli/development.md) |
@@ -4,7 +4,7 @@
4
4
 
5
5
  | 命令 | 行为 |
6
6
  | --- | --- |
7
- | `dbx dev` | 工作台工程默认调试工作台,普通插件默认同步并个人安装 Skill / MCP 开发包。含 App 的项目在交互终端可切换到 App 调试 |
7
+ | `dbx dev` | 工作台工程默认调试工作台,普通插件默认同步并个人安装 Skill / MCP 开发包。应用插件在交互终端可切换到 App 调试 |
8
8
  | `dbx dev --plugin` | 显式选择 Skill / MCP 调试,上传开发包并安装到当前登录账号 |
9
9
  | `dbx dev --app` | App 本地编译和 Web 模拟器,不同步个人开发包;缺少插件 ID 时,会上传完整项目并保存平台草稿 |
10
10
  | `dbx dev --workbench` | 上传工作台配置、资源及同工程的 MCP,并安装到当前登录账号 |
@@ -24,7 +24,9 @@
24
24
 
25
25
  新增或移除 App 后重启并选择调试目标。要保存版本或生成 App 预览,按 [版本交付与审核](release.md) 操作。
26
26
 
27
- ### 确认首次同步结果
27
+ ### 同步安装与修改后的更新
28
+
29
+ 本次目标包含普通插件或工作台的账号安装、更新时,完成制作或修改及本地验证后,执行对应的 `dbx dev --plugin --once` 或 `dbx dev --workbench --once`,确认本次内容同步成功,再继续宿主验证与交接。已有监听进程完成本次变更同步时,复用该结果,无需重复执行。
28
30
 
29
31
  单次模式等待命令结束并核对退出码;失败后按错误修复并重新执行。
30
32
 
@@ -85,7 +85,7 @@ CLI 通过 `com.doubao/workbench/manifest.json` 识别工作台,初始化骨
85
85
  | `dbx init <name> --workbench` | 定制工作台骨架,目录见 [定制工作台](#定制工作台) |
86
86
  | `dbx init <name> --app` | 应用插件骨架:增加 App、本地商品搜索端工具、业务 Skill、页面和卡片 |
87
87
 
88
- 目标目录须不存在或为空。用 `--type public|enterprise` 明确发布类型;未指定时,`--app` 或非 TTY 默认使用 PUBLIC,其他交互场景按 CLI 提示选择。企业专属插件需要发布权限,暂不支持 App。交互模式可选择普通插件、含 App 的插件或定制工作台。`--app` 和 `--workbench` 互斥。
88
+ 目标目录须不存在或为空。用 `--type public|enterprise` 明确发布类型;未指定时,`--app` 或非 TTY 默认使用 PUBLIC,其他交互场景按 CLI 提示选择。企业专属插件需要发布权限,暂不支持 App。交互模式可选择普通插件、应用插件或定制工作台。`--app` 和 `--workbench` 互斥。
89
89
 
90
90
  ### 确定发布类型
91
91
 
@@ -134,6 +134,8 @@ dbx workbench search "合同" --source official store enterprise --json
134
134
  ]
135
135
  ```
136
136
 
137
+ 资源 `id` **必须使用 `dbx workbench search` 对目标资源返回的值**,字段语义见 [预装资源声明](../protocols/workbench.md#预装资源声明)。未搜到目标资源时,先确认资源发布及账号可见范围。
138
+
137
139
  选中资源后按以下方式填写配置,完整文件见 [预装文件示例](../examples/workbench-example.md#声明预装资源)。
138
140
 
139
141
  | 搜索结果 | 配置位置 |
@@ -21,13 +21,13 @@
21
21
 
22
22
  从 CLI 输出取得实际版本号与平台链接。部分步骤失败可能已有草稿或版本保存,按错误说明和平台入口核实后恢复。
23
23
 
24
- 含 App 的工程在非 TTY 模式生成预览后输出文本二维码和预览链接。上传成功不能替代 App 构建或预览成功。内容未变且预览链接仍对应目标版本时复用;内容变更或链接失效后按已有授权重新上传。预览状态未知时先查询,不自行改写链接。
24
+ 应用插件在非 TTY 模式生成预览后输出文本二维码和预览链接。上传成功不能替代 App 构建或预览成功。内容未变且预览链接仍对应目标版本时复用;内容变更或链接失效后按已有授权重新上传。预览状态未知时先查询,不自行改写链接。
25
25
 
26
26
  审核中服务端锁定当前草稿,`upload --version` 也受限制。等待审核结束后再上传,或在用户要求时撤回审核。
27
27
 
28
28
  ## 上传物料与图标
29
29
 
30
- 包目录与相对路径规则见 [项目配置](project.md#路径与打包)。基础上传限额如下;含 App 的差异要求以平台校验为准:
30
+ 包目录与相对路径规则见 [项目配置](project.md#路径与打包)。基础上传限额如下;应用插件的额外要求以平台校验为准:
31
31
 
32
32
  | 检查项 | 上限 |
33
33
  | --- | --- |
@@ -40,7 +40,7 @@
40
40
  | 图标 | 要求 |
41
41
  | --- | --- |
42
42
  | 普通 Plugin 主图标、`chatIcon`、Skill 和 MCP 图标 | 可选;PNG / JPEG,512×512,单张 ≤500 KB |
43
- | 含 App 的 Plugin 主图标 | 首次创建关联 App 时必填;GIF / JPEG / PNG / WebP,512×512,≤10 MiB,四角像素均不能完全透明 |
43
+ | 应用插件主图标 | 首次创建关联 App 时必填;GIF / JPEG / PNG / WebP,512×512,≤10 MiB,四角像素均不能完全透明 |
44
44
 
45
45
  新增或替换图标时按上表准备文件;已有有效配置无需重复检查。字段位置和回退规则见 [根清单](../protocols/plugin-json.md#展示字段)、[业务 Skill](../protocols/business-skills.md#frontmatter-字段);主图标和 `chatIcon` 可引用同一文件。
46
46
 
@@ -1,6 +1,29 @@
1
- # TODO 应用插件示例
1
+ # TODO 插件与 MCP Apps 示例
2
2
 
3
- 假设已有提供查看、新增、完成待办三个工具的远程 MCP 服务,以下最小配置串起根清单、MCP 连接和业务 Skill。鉴权按服务要求补充;需要交互界面时再读取 [MCP Apps](../protocols/mcp-apps/integration.md)。
3
+ 本例统一待办服务的业务契约、MCP Apps 交互与插件接入。已有服务按真实 schema 调整配置,不将平台 SDK 写法当作 MCP 协议。
4
+
5
+ 使用妙搭时,读取 `miaoda-mcp-dev` Skill 的 `references/todo-example.md`。
6
+
7
+ ## 业务契约
8
+
9
+ 个人待办包含 `id`、`title`、`completed`;ID 由服务生成,标题去空白后长度为 1–200 个字符。持久化记录另存所属用户,身份由已验证的请求上下文提供,不从工具入参接受用户 ID。查询和写入都限制当前用户,业务结果不返回内部身份或审计字段。
10
+
11
+ | 工具 | 输入 | structuredContent | 行为 |
12
+ | --- | --- | --- | --- |
13
+ | `todo_list` | 可选 `completed`;`offset=0`、`limit=20`,上限 50 | `{ items: [{ id, title, completed }], nextOffset }` | 按稳定顺序分页,末页 `nextOffset=null` |
14
+ | `todo_create` | `title` | `{ todo: { id, title, completed } }` | 新建未完成待办;重复调用会新增 |
15
+ | `todo_complete` | `id`、可选 `completed=true` | `{ todo: { id, title, completed } }` | 设置目标状态,重复设置不改变结果;不可访问返回 `TODO_NOT_FOUND` |
16
+ | `todo_delete` | `id` | `{ deleted: boolean }` | 删除本人待办,未找到可删除项时返回 false |
17
+
18
+ 每个工具声明对应的输入、输出 schema,并提供独立可读的 `content`。查询工具标注只读;创建工具非幂等,设置状态和删除工具幂等;删除工具标注破坏性。业务失败使用 `isError: true` 及解释性结果,协议字段按 [MCP 配置](../protocols/mcp-config.md) 与上游标准维护。
19
+
20
+ ## 可选 MCP Apps 界面
21
+
22
+ 通过 `todo_list` 的 `_meta.ui.resourceUri` 关联 `ui://todo/list`,资源返回已构建的 HTML。具体字段、资源媒体类型、权限与生命周期见 [MCP Apps 接入](../protocols/mcp-apps/integration.md#接通工具与界面)。
23
+
24
+ 界面接收工具结果中的 `items` 并渲染列表;新增、勾选和删除分别调用上表工具,成功后调用 `todo_list` 刷新列表。分页沿用返回的 `nextOffset`。初次工具结果可能早于 UI 就绪,按 SDK 生命周期先注册处理器再连接;从静态入口打开且尚无结果时主动查询。空列表、未授权及业务失败在界面中给出对应反馈。
25
+
26
+ 平台 SDK 可封装注册与连接,工具契约和验收目标保持相同。
4
27
 
5
28
  ## 目录与完整配置
6
29
 
@@ -23,14 +46,14 @@ todo-demo/
23
46
  {
24
47
  "name": "todo-demo",
25
48
  "publicationType": "PUBLIC",
26
- "description": "查看、新增和完成待办",
49
+ "description": "查看、新增、完成和删除待办",
27
50
  "extensions": {
28
51
  "com.doubao": {
29
52
  "displayName": { "zh": "待办清单" },
30
53
  "mcpServers": {
31
54
  "todo": {
32
55
  "displayName": { "zh": "待办服务" },
33
- "displayDescription": { "zh": "查看、新增和完成待办" }
56
+ "displayDescription": { "zh": "查看、新增、完成和删除待办" }
34
57
  }
35
58
  }
36
59
  }
@@ -53,7 +76,7 @@ todo-demo/
53
76
  }
54
77
  ```
55
78
 
56
- 两个 JSON 文件中的服务键统一为 `todo`:连接配置使用 `mcpServers.todo`,展示配置使用 `extensions["com.doubao"].mcpServers.todo`。Skill 正文中的三个工具名须与服务实际返回的 `tools/list` 一致。
79
+ 两个 JSON 文件中的服务键统一为 `todo`:连接配置使用 `mcpServers.todo`,展示配置使用 `extensions["com.doubao"].mcpServers.todo`。Skill 正文中的工具名须与服务实际返回的 `tools/list` 一致。
57
80
 
58
81
  ### skills/todo-list/SKILL.md
59
82
 
@@ -62,7 +85,7 @@ todo-demo/
62
85
  ```markdown
63
86
  ---
64
87
  name: todo-list
65
- description: 当用户需要查看、新增或完成待办时使用。
88
+ description: 当用户需要查看、新增、完成或删除待办时使用。
66
89
  metadata:
67
90
  display_name: 待办清单
68
91
  display_description: 查看、新增待办,并将已完成的任务标记为完成。
@@ -73,8 +96,9 @@ metadata:
73
96
  - 查看待办:调用 `todo_list({})`,空列表为 `items: []`。
74
97
  - 新增待办:调用 `todo_create({ "title": "用户提供的标题" })`,标题去除首尾空白后不能为空,ID 由服务生成。
75
98
  - 完成待办:从 `todo_list` 的真实结果取得 ID,再调用 `todo_complete({ "id": "实际 ID" })`;同名多项且目标不明时先澄清,重复完成不改变状态。
99
+ - 删除待办:用户要求删除时,从实际列表确认目标 ID,再调用 `todo_delete({ "id": "实际 ID" })`。
76
100
 
77
- 成功结果包含可读 `content` 和 `structuredContent.items`,每项含 `id`、`title`、`completed`。只在返回成功后报告新增或完成,不虚构待办或 ID。
101
+ 成功结果包含可读 `content` 和 `structuredContent`:查询返回 `items` 和 `nextOffset`,创建或设置状态返回 `todo`,删除返回 `deleted`。待办记录包含 `id`、`title`、`completed`。只按真实结果报告操作状态,不虚构待办或 ID。
78
102
 
79
103
  工具业务失败返回 `isError: true` 和原因;连接、协议或授权失败按实际报错处理。未知 ID 时重新读取列表;新增请求超时或断线时先读取并核对结果,不能直接重试造成重复。
80
104
  ```
@@ -82,7 +106,9 @@ metadata:
82
106
  ## 调试与验证
83
107
 
84
108
  1. 替换占位地址,按实际服务配置 [鉴权](../protocols/mcp-auth.md)。Streamable HTTP 服务可用 `dbx inspect --mcp-server <实际地址>` 检查工具、输入 schema 和结果,并直接调用验证空标题、未知 ID 等错误边界。
85
- 2. 按 [开发调试](../cli/development.md) 登录并运行 `dbx dev --plugin`,确认首次同步和当前账号安装成功。
86
- 3. 在目标宿主依次请求“新增待办:整理本周计划”“查看待办”“完成整理本周计划”,核对同一 ID 的状态变化。
109
+ 2. 按 [开发调试](../cli/development.md) 登录并运行 `dbx dev --plugin --once`,确认同步和当前账号安装成功。
110
+ 3. 在目标宿主依次请求“新增待办:整理本周计划”“查看待办”“完成整理本周计划”,核对同一 ID 的状态变化;新会话查询仍保持状态。
111
+ 4. 已选 MCP Apps 时,按 [CSP 域名清单](../protocols/mcp-apps/integration.md#csp-域名清单)核对构建产物和声明;实际打开列表,在界面新增并勾选待办,再通过工具查询确认相同变更。读取到 HTML 或独立网页可访问不能代替宿主界面验收。
112
+ 5. 验证空列表、未知 ID 和缺少授权的反馈;有多用户隔离要求时以另一身份确认无法读取或修改前一用户的待办。按本次授权删除测试数据并读回确认。
87
113
 
88
114
  保存版本时按 [版本交付与审核](../cli/release.md) 执行。
@@ -121,7 +121,7 @@ cd contract-workbench
121
121
 
122
122
  ## 同步与试用
123
123
 
124
- 按 [开发调试](../cli/development.md#启动调试) 运行 `dbx dev --workbench`,同步并切换到本次工作台开发版,然后逐项验证:
124
+ 按 [开发调试](../cli/development.md#启动调试) 运行 `dbx dev --workbench --once`,同步并切换到本次工作台开发版,然后逐项验证:
125
125
 
126
126
  1. 首页显示欢迎语。点「查询待签合同」后,输入框预填请求并选中对应的推荐插件。发送后核对结果依赖的是本次选择的插件和授权。
127
127
  2. 点左侧「合同管理」打开 MCP 页面。若页面需要访问合同数据,用当前账号验证一条只读查询。
@@ -92,7 +92,7 @@ UI HTML 非空,豆包扩展的总上限为 10 MiB,inline 上限为 5 MiB。
92
92
 
93
93
  | 资源元数据位置 | 契约 |
94
94
  | --- | --- |
95
- | `contents[i]._meta.ui.csp` | `connectDomains`、`resourceDomains`、`frameDomains`、`baseUriDomains`;每组最多 32 项。网络连接允许 HTTPS/WSS,其余三组限 HTTPS |
95
+ | `contents[i]._meta.ui.csp` | 按下文 [CSP 域名清单](#csp-域名清单)声明完整依赖;豆包每组最多 32 项,网络连接允许 HTTPS/WSS,其余三组限 HTTPS |
96
96
  | `contents[i]._meta.ui.permissions` | `camera`、`microphone`、`geolocation`、`clipboardWrite` 以 `{}` 申请;当前默认策略只允许 clipboardWrite,实际权限取申请与 Host 策略的交集 |
97
97
  | `contents[i]._meta.ui.domain` / `prefersBorder` | 专用来源标识和边框偏好;最终按容器策略渲染 |
98
98
  | `contents[i]._meta["openai/ui"]` 或 `doubao/ui` | `availableDisplayModes`、`preferredDisplayMode`;支持的模式为 `inline` / `fullscreen`,最终取 App、资源与 Host 支持的交集 |
@@ -103,13 +103,34 @@ inline 高度使用官方 `ui/notifications/size-changed` 或 SDK 默认 autoRes
103
103
 
104
104
  显示模式请求以返回的 `mode` 为准。豆包扩展不提供 PiP;sidebar、page、rightSidebar 是其他层次的容器概念,不新增对应 wire displayMode。
105
105
 
106
+ ### CSP 域名清单
107
+
108
+ CSP 的四组字段来自 [MCP Apps 标准](../../upstream/mcp-apps.mdx#ui-resource-format)。开发或修改 UI 时,必须从**实际构建并托管的 HTML 及其依赖**收集来源,按用途填写;不能只填 MCP 服务地址或 HTML 入口域名。
109
+
110
+ | 字段 | 需要覆盖的来源 | 示例 |
111
+ | --- | --- | --- |
112
+ | `connectDomains` | 页面直接发起的 fetch、XHR、WebSocket 等网络连接 | `https://api.example.com`、`wss://events.example.com` |
113
+ | `resourceDomains` | 外链 JS、CSS、图片、字体、音视频,以及模块加载、CSS `@import` / `url()` 等间接加载的静态资源 | `https://cdn.example.com` |
114
+ | `frameDomains` | 页面内 iframe 加载的目标来源 | `https://embed.example.com` |
115
+ | `baseUriDomains` | `<base href>` 指定的来源;资源和请求仍按用途声明到上述字段 | `https://cdn.example.com` |
116
+
117
+ 填写 origin(协议、域名和必要的端口),同一 origin 用于多种用途时分别填入对应字段。检查相对路径最终解析的地址、重定向后的来源及交互时才加载的依赖。托管 HTML 与 JS/CSS 在同一域名,也不能假定该域名已被沙箱允许;打包后的外链仍需声明。通过 `app.callServerTool` 由宿主访问 MCP 不属于页面直接联网,无需因此添加服务域名。
118
+
119
+ **建议直接在 MCP Apps 资源中实现界面,避免再用 iframe 嵌套业务网页,尤其是多层嵌套。** 确需嵌套时,逐层检查子页面及其潜在嵌套页面的网络、静态资源和 iframe 来源,并配置到各层适用的 CSP。顶层 `frameDomains` 只允许加载子页面,不会自动放行子页面的所有依赖;跨源子页面还受自身 CSP 和嵌入策略约束。
120
+
121
+ 资源模式将 CSP 写入 `resources/read` 返回的 `contents[i]._meta.ui.csp`,不能只写在工具元数据或 `registerAppResource` 注册配置上。URL source 使用上文的 `doubao/ui.csp`,工作台 HTML 使用[包协议](../workbench.md)中的 `html.csp`。平台 SDK 封装了声明时,检查最终响应是否带上这些字段。
122
+
123
+ 交付前核对构建产物和实际响应,并在目标宿主打开页面、触发主要交互,结合 Console 的 CSP 错误与 Network 中被拦截的 URL 补齐相应来源;每次新增外部依赖都更新清单并复验。未使用的字段可省略或为空,不能复制空数组来代替依赖检查,也不要用宽泛通配符消除报错。CSP 放行后仍须满足 CORS 和目标页面的嵌入策略;若无法执行宿主验证,明确记录未验证项。
124
+
125
+ 官方实践:[CSP 字段说明](https://apps.extensions.modelcontextprotocol.io/api/interfaces/app.McpUiResourceCsp.html)、[CSP 与 CORS 配置](https://apps.extensions.modelcontextprotocol.io/api/documents/Patterns.html#configuring-csp-and-cors)。
126
+
106
127
  ## 接通工具与界面
107
128
 
108
129
  普通接入先按本页步骤实施;需要核对标准字段或报文时,按[协议章节索引](#按需核对标准协议)读取对应章节。SDK 用法以工程已安装的 `@modelcontextprotocol/ext-apps` 导出与类型为准,保留已有 MCP 和 Web 工程。
109
130
 
110
131
  1. 确认真正使用的工具、输入及结果 schema、样例数据和前端入口。工具须返回独立可读的文字或结构化结果,包含核心数据和状态,不能只返回“请看卡片”、空结果或 UI URI。
111
132
  2. 用 `registerAppTool` 注册工具;资源模式通过 `_meta.ui.resourceUri` 绑定 `ui://` 资源,URL 模式按[静态入口与 UI 来源](#静态入口与-ui-来源)声明,两者互斥。
112
- 3. 资源模式用 `registerAppResource` 注册同一 URI,contents 返回实际 HTML 和 `text/html;profile=mcp-app`;URL 模式验证实际页面与 Host Proxy 通信。两种模式均只申请实际需要的域名和权限。
133
+ 3. 资源模式用 `registerAppResource` 注册同一 URI,contents 返回实际 HTML 和 `text/html;profile=mcp-app`;URL 模式验证实际页面与 Host Proxy 通信。两种模式均按 [CSP 域名清单](#csp-域名清单)覆盖实际依赖,并申请所需权限。
113
134
  4. 前端创建 SDK `App`,先注册处理器再 `app.connect()`;用 `app.ontoolresult` 接收数据,交互通过 `app.callServerTool({ name, arguments })` 调用工具。服务端保留参数校验、授权和业务错误处理。
114
135
  5. 按工程实际命令构建,在目标宿主验证 `io.modelcontextprotocol/ui` 扩展协商、资源加载与交互。读取 `hostContext.availableDisplayModes` 后,按[显示模式约束](#资源安全与显示模式)请求支持的模式。
115
136
 
@@ -166,7 +187,7 @@ inline 高度使用官方 `ui/notifications/size-changed` 或 SDK 默认 autoRes
166
187
 
167
188
  ## 调试与验收
168
189
 
169
- 按 MCP / Web 工程自身命令启动服务。使用 [Inspector](../../cli/development.md#单独调试-mcp-server) 单独检查工具、资源和 HTML 界面。需要验收应用插件整体效果时,通过 `dbx dev --plugin` 将开发包安装到当前账号,再在支持 MCP Apps 的目标宿主验证。
190
+ 按 MCP / Web 工程自身命令启动服务。使用 [Inspector](../../cli/development.md#单独调试-mcp-server) 单独检查工具、资源和 HTML 界面。需要验收插件在目标宿主中的整体效果时,通过 `dbx dev --plugin --once` 将开发包安装到当前账号,再在支持 MCP Apps 的目标宿主验证。
170
191
 
171
192
  - 工具:真实调用成功,文字或结构化结果独立可读;业务 Skill 中的参数与 tools/list schema 一致。
172
193
  - 界面:读取到关联 URI 的 HTML,工具结果进入 UI;筛选、详情或修改操作调用真实工具并更新界面。
@@ -181,6 +202,6 @@ inline 高度使用官方 `ui/notifications/size-changed` 或 SDK 默认 autoRes
181
202
  | 连接或工具枚举 | 地址、传输、运行态服务、授权;见 [MCP 鉴权](../mcp-auth.md#按失败环节排查) |
182
203
  | 工具调用 | 输入 schema、业务权限、`isError` 与原始结果;有数据再查 UI |
183
204
  | 工具成功但没有界面 | 宿主支持及扩展协商、工具定义中的默认 URI;不把结果缺少重复 URI 当作故障 |
184
- | 资源加载失败或白屏 | 同一服务的 `resources/read`、URI、媒体类型、实际 HTML、CSP 与浏览器错误 |
205
+ | 资源加载失败或白屏 | 同一服务的 `resources/read`、URI、媒体类型、实际 HTML;按 [CSP 域名清单](#csp-域名清单)核对被拦截的请求与资源 |
185
206
  | HTML 已加载但一直等待 | `App` 处理器是否先于 `connect()` 注册,宿主是否送达结果,字段是否符合 UI 读取逻辑 |
186
207
  | 首屏正常但操作失败 | `callServerTool` 的工具名、参数、授权及真实返回;错误后是否保留数据并给出恢复入口 |
@@ -57,7 +57,7 @@ Manifest 的 `entrypoint.type` 枚举:
57
57
  | 字段 | 类型 | 必填 | 约束 |
58
58
  | --- | --- | --- | --- |
59
59
  | `type` | string | 是 | `skill` 或 `plugin` |
60
- | `id` | string | 是 | 来源下稳定的非空资源 ID,按搜索返回的字符串保存 |
60
+ | `id` | string | 是 | 被引用插件或 Skill 在对应来源下的稳定、非空资源 ID;不是本地 `plugin.json.id`,二者不得替换 |
61
61
  | `source` | string | 是 | 见 [资源来源枚举](#资源来源枚举),区分大小写;按工作台发布类型选择可预装来源 |
62
62
 
63
63
  ### 资源来源枚举
@@ -108,7 +108,7 @@ Manifest 的 `entrypoint.type` 枚举:
108
108
  | --- | --- |
109
109
  | `path` | 相对 `com.doubao/workbench/`,指向 `web/` 下实际存在的 HTML 文件;不得越出目录或包含查询参数、片段 |
110
110
  | `startupCalls` | 可省略,最多 32 项;使用包内声明的服务和只读工具,`arguments` 符合工具输入 schema,省略时为 `{}` |
111
- | `csp` | 按需声明 `connectDomains`、`resourceDomains`、`frameDomains`、`baseUriDomains` |
111
+ | `csp` | 使用 MCP Apps 标准字段,按 [CSP 域名清单](mcp-apps/integration.md#csp-域名清单)覆盖托管 HTML 的直接与间接依赖 |
112
112
  | `permissions` | 按需声明权限,键及对应取值见下表 |
113
113
 
114
114
  `permissions` 的权限枚举:
@@ -1,10 +1,10 @@
1
1
  # 协议快照来源
2
2
 
3
- 本目录保存上游协议原文与许可证,按接入指引选择需要的章节。原文中的背景资料与外部链接仅供补充查阅。
3
+ 本目录保存上游协议快照与许可证,按接入指引选择需要的章节。原文中的背景资料与外部链接仅供补充查阅。
4
4
 
5
5
  ## 上游标准快照
6
6
 
7
- 快照日期:2026-11-13。固定到下列提交,更新时核对协议变化后再替换。文档仅在有相对链接时增加页首说明,并将相对链接解析为对应固定提交的上游地址;其余正文及许可证保持原样。
7
+ 快照日期为 2026-11-13。更新时核对协议变化以及下方记录的本地修正。随包副本可加页首说明、解析相对链接或包含下方记录的修正。
8
8
 
9
9
  | 本地文件 | 上游原文 | 固定提交 | 许可证 |
10
10
  | --- | --- | --- | --- |
@@ -12,13 +12,21 @@
12
12
  | [standard-webhooks.md](standard-webhooks.md) | [standard-webhooks/standard-webhooks: spec/standard-webhooks.md](https://github.com/standard-webhooks/standard-webhooks/blob/f72db81617ce7c285e99d7734ff2480303328377/spec/standard-webhooks.md) | `f72db81617ce7c285e99d7734ff2480303328377` | [Apache-2.0](standard-webhooks.LICENSE) |
13
13
  | [mcp-apps.mdx](mcp-apps.mdx) | [modelcontextprotocol/ext-apps: specification/2026-01-26/apps.mdx](https://github.com/modelcontextprotocol/ext-apps/blob/ea3e9d0e624a20bc1c51310292f09d9b8ed17161/specification/2026-01-26/apps.mdx) | `ea3e9d0e624a20bc1c51310292f09d9b8ed17161` | [上游 Apache-2.0 / MIT 过渡声明](mcp-apps.LICENSE) |
14
14
 
15
+ ## 本地修正
16
+
17
+ `mcp-apps.mdx` 的随包示例以 `@modelcontextprotocol/ext-apps@^1.7.5` 和 `@modelcontextprotocol/sdk@^1.29.0` 为基准。Host 通过实际返回的能力声明表明支持范围。
18
+
19
+ - View 握手使用 `ui/initialize`、`appInfo` 和 `appCapabilities`。手写传输示例按请求 ID 匹配响应。Host → MCP Server 的 `initialize` 示例使用 Core 的 `clientInfo` 和 `capabilities`。 [ext-apps 握手实现](https://github.com/modelcontextprotocol/ext-apps/blob/v1.7.5/src/app.ts#L1881-L1915) · [Core 请求类型](https://github.com/modelcontextprotocol/typescript-sdk/blob/v1.29.0/src/types.ts#L489-L503)
20
+ - 消息、通知和销毁示例按 SDK 类型修正。补充 SDK 中的下载、主动请求关闭以及相关 Host 能力。 [ext-apps 消息与能力类型](https://github.com/modelcontextprotocol/ext-apps/blob/v1.7.5/src/spec.types.ts)
21
+ - 工具注册示例补全输入 schema 和 handler。连接前注册工具,初始化后按客户端能力更新 UI 元数据。 [ext-apps 能力查询](https://github.com/modelcontextprotocol/ext-apps/blob/v1.7.5/src/server/index.ts#L445-L458) · [Core 注册签名](https://github.com/modelcontextprotocol/typescript-sdk/blob/v1.29.0/src/server/mcp.ts#L963)
22
+
15
23
  ## SHA-256
16
24
 
17
25
  | 文件 | 下载原文 | 随包副本 |
18
26
  | --- | --- | --- |
19
27
  | `mcp-events.md` | `03b454b6c877cd93dded5827c6b8bf315cde0e839bd2e51ce1b752bd5f04e87b` | `804f008c54f32a15434acfc5581ceffcb715e81a6158d611b0199a66681a1432` |
20
28
  | `standard-webhooks.md` | `c9a80952a2a6a34fb456ae9614483b7d9b8563fe5eb8f328f3d138f1e765ac31` | `fc0f69754c9c09369edc08acfc3c52ae10094f2113f824cd49512e6862b16a60` |
21
- | `mcp-apps.mdx` | `ee452a7d1b9b7fb900acfeb4d6932d3963375b0f3f37d196a4b93eb80312af0e` | `ee452a7d1b9b7fb900acfeb4d6932d3963375b0f3f37d196a4b93eb80312af0e` |
29
+ | `mcp-apps.mdx` | `ee452a7d1b9b7fb900acfeb4d6932d3963375b0f3f37d196a4b93eb80312af0e` | `8c1b5b98b4951cc81023ded68116747636e0bf2ee1f7966516c62e623561a892` |
22
30
  | `mcp-events.LICENSE` | `0382b0057770ca05e9c350a50aa3b1c1fea84da0bc81d723bf00b9aa841be58a` | `0382b0057770ca05e9c350a50aa3b1c1fea84da0bc81d723bf00b9aa841be58a` |
23
31
  | `standard-webhooks.LICENSE` | `c71d239df91726fc519c6eb72d318ec65820627232b2f796219e87dcf35d0ab4` | `c71d239df91726fc519c6eb72d318ec65820627232b2f796219e87dcf35d0ab4` |
24
32
  | `mcp-apps.LICENSE` | `0382b0057770ca05e9c350a50aa3b1c1fea84da0bc81d723bf00b9aa841be58a` | `0382b0057770ca05e9c350a50aa3b1c1fea84da0bc81d723bf00b9aa841be58a` |