@fastgpt-plugin/sdk-client 0.0.1-alpha.7 → 0.0.1-alpha.8
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/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -16,5 +16,6 @@ import e,{z as t,z as n}from"zod";import{createHash as r}from"node:crypto";impor
|
|
|
16
16
|
`+t+`}`}}return i.pop(),a=t,s}function p(e){if(e.length===0)return d(e,!0);let t=String.fromCodePoint(e.codePointAt(0));if(!n.isIdStartChar(t))return d(e,!0);for(let r=t.length;r<e.length;r++)if(!n.isIdContinueChar(String.fromCodePoint(e.codePointAt(r))))return d(e,!0);return e}function m(e){if(i.indexOf(e)>=0)throw TypeError(`Converting circular structure to JSON5`);i.push(e);let t=a;a+=c;let n=[];for(let t=0;t<e.length;t++){let r=u(String(t),e);n.push(r===void 0?`null`:r)}let r;if(n.length===0)r=`[]`;else if(c===``)r=`[`+n.join(`,`)+`]`;else{let e=`,
|
|
17
17
|
`+a,i=n.join(e);r=`[
|
|
18
18
|
`+a+i+`,
|
|
19
|
-
`+t+`]`}return i.pop(),a=t,r}}})),Si=m(f(((e,t)=>{t.exports={parse:bi(),stringify:xi()}}))(),1);const Ci=e.object({...E.omit({etag:!0,readmeUrl:!0}).shape}),wi=e.object({...Ci.shape,type:e.literal(T.tool),toolDescription:e.string(),inputSchema:e.any().optional(),outputSchema:e.any().optional(),secretSchema:e.any(),children:e.array(e.object({id:e.string(),description:g,name:g,toolDescription:e.string(),icon:e.string(),inputSchema:e.any(),outputSchema:e.any()})).min(1).optional()}),Ti=Si.default.parse,Ei=async({getAccessURL:e,pluginId:t,version:n,filePath:r})=>e?e({pluginId:t,version:n,filePath:r}):z({en:`Missing access url resolver`,"zh-CN":`缺少访问地址解析器`}),Di=async({manifest:e,etag:t,availableFiles:n,getAccessURL:r})=>{try{let i=new Set(n),a=e.icon;if(r&&i.has(e.icon)){let[t,n]=await Ei({getAccessURL:r,pluginId:e.pluginId,version:e.version,filePath:[e.icon]});if(n)return z({en:`resolve plugin icon failed`,"zh-CN":`解析插件图标失败`},n);a=t}let o;if(r&&i.has(`README.md`)){let[t]=await Ei({getAccessURL:r,pluginId:e.pluginId,version:e.version,filePath:[`README.md`]});o=t??void 0}let s;if(e.children){s=[];for(let t of e.children){let n=t.icon;if(r&&i.has(t.icon)){let[i,a]=await Ei({getAccessURL:r,pluginId:e.pluginId,version:e.version,filePath:[t.icon]});if(a)return z({en:`resolve child icon failed: ${t.id}`,"zh-CN":`解析子工具图标失败: ${t.id}`},a);n=i}s.push({...t,icon:n})}}let c={...e,etag:t,icon:a,...o?{readmeUrl:o}:{},children:s,toolDescription:e.toolDescription,inputSchema:e.inputSchema,outputSchema:e.outputSchema,secretSchema:e.secretSchema};return _t(O.parse(c))}catch(e){return z({en:`parse tool failed`,"zh-CN":`解析工具失败`},e)}},Oi=async e=>{try{let t=Ti(e.manifest),{success:n,data:r}=Ci.pick({type:!0}).safeParse(t);if(!n)return z({en:`parse manifest.json failed: can not find type field`,"zh-CN":`解析 manifest.json 失败: 找不到 type 字段`});switch(r.type){case`tool`:return await Di({...e,manifest:wi.parse(t)});default:return z({en:`unsupported plugin type: ${r.type}`,"zh-CN":`不支持的插件类型: ${r.type}`})}}catch{return z({en:`parse manifest.json failed`,"zh-CN":`解析 manifest.json 失败`})}},ki=new Set([`image/svg+xml`,`image/png`,`image/jpeg`,`image/gif`,`image/webp`]),Ai=async e=>Buffer.isBuffer(e)?_t(e):gi(e),ji=(e,t)=>gt(t,ht(e)??`application/octet-stream`),Mi=(e,t)=>({filename:e,contentType:ji(e,t),size:t.length,stream:hi(t)}),Ni=e=>r(`md5`).update(e).digest(`hex`)
|
|
19
|
+
`+t+`]`}return i.pop(),a=t,r}}})),Si=m(f(((e,t)=>{t.exports={parse:bi(),stringify:xi()}}))(),1);const Ci=e.object({...E.omit({etag:!0,readmeUrl:!0}).shape}),wi=e.object({...Ci.shape,type:e.literal(T.tool),toolDescription:e.string(),inputSchema:e.any().optional(),outputSchema:e.any().optional(),secretSchema:e.any(),children:e.array(e.object({id:e.string(),description:g,name:g,toolDescription:e.string(),icon:e.string(),inputSchema:e.any(),outputSchema:e.any()})).min(1).optional()}),Ti=Si.default.parse,Ei=async({getAccessURL:e,pluginId:t,version:n,filePath:r})=>e?e({pluginId:t,version:n,filePath:r}):z({en:`Missing access url resolver`,"zh-CN":`缺少访问地址解析器`}),Di=async({manifest:e,etag:t,availableFiles:n,getAccessURL:r})=>{try{let i=new Set(n),a=e.icon;if(r&&i.has(e.icon)){let[t,n]=await Ei({getAccessURL:r,pluginId:e.pluginId,version:e.version,filePath:[e.icon]});if(n)return z({en:`resolve plugin icon failed`,"zh-CN":`解析插件图标失败`},n);a=t}let o;if(r&&i.has(`README.md`)){let[t]=await Ei({getAccessURL:r,pluginId:e.pluginId,version:e.version,filePath:[`README.md`]});o=t??void 0}let s;if(e.children){s=[];for(let t of e.children){let n=t.icon;if(r&&i.has(t.icon)){let[i,a]=await Ei({getAccessURL:r,pluginId:e.pluginId,version:e.version,filePath:[t.icon]});if(a)return z({en:`resolve child icon failed: ${t.id}`,"zh-CN":`解析子工具图标失败: ${t.id}`},a);n=i}s.push({...t,icon:n})}}let c={...e,etag:t,icon:a,...o?{readmeUrl:o}:{},children:s,toolDescription:e.toolDescription,inputSchema:e.inputSchema,outputSchema:e.outputSchema,secretSchema:e.secretSchema};return _t(O.parse(c))}catch(e){return z({en:`parse tool failed`,"zh-CN":`解析工具失败`},e)}},Oi=async e=>{try{let t=Ti(e.manifest),{success:n,data:r}=Ci.pick({type:!0}).safeParse(t);if(!n)return z({en:`parse manifest.json failed: can not find type field`,"zh-CN":`解析 manifest.json 失败: 找不到 type 字段`});switch(r.type){case`tool`:return await Di({...e,manifest:wi.parse(t)});default:return z({en:`unsupported plugin type: ${r.type}`,"zh-CN":`不支持的插件类型: ${r.type}`})}}catch{return z({en:`parse manifest.json failed`,"zh-CN":`解析 manifest.json 失败`})}},ki=new Set([`image/svg+xml`,`image/png`,`image/jpeg`,`image/gif`,`image/webp`]),Ai=async e=>Buffer.isBuffer(e)?_t(e):gi(e),ji=(e,t)=>gt(t,ht(e)??`application/octet-stream`),Mi=(e,t)=>({filename:e,contentType:ji(e,t),size:t.length,stream:hi(t)}),Ni=e=>r(`md5`).update(e).digest(`hex`),Pi=e=>{let t=r(`md5`),n=[...e].sort((e,t)=>e.filename<t.filename?-1:+(e.filename>t.filename));for(let e of n)t.update(e.filename),t.update(`\0`),t.update(Ni(e.buffer)),t.update(`\0`),t.update(String(e.buffer.length)),t.update(`
|
|
20
|
+
`);return t.digest(`hex`).slice(0,8)},Fi=async({input:e,getAccessURL:t})=>{let[n,r]=await Ai(e);if(r)return z({en:`Failed to read plugin package`,"zh-CN":`读取插件包失败`},r);let a=await _i(hi(n)),o=[];for(let e of a){if(e.directory||!e.stream)continue;let[t,n]=await gi(e.stream);if(n)return z({en:`Failed to read extracted file: ${e.filename}`,"zh-CN":`读取解压文件失败: ${e.filename}`},n);o.push({filename:e.filename,buffer:t})}let s=Pi(o),c=o.map(e=>e.filename),l,u,d,f,p=[],m=[];for(let e of o){let t=Mi(e.filename,e.buffer);if(e.filename===`index.js`){l=t;continue}if(e.filename===`manifest.json`){u=t,d=e.buffer.toString();continue}if(e.filename===`README.md`){f=t;continue}if(i.dirname(e.filename)===`assets`&&ki.has(t.contentType)){p.push(t);continue}i.dirname(e.filename)===`.`&&/^([^.]+\.|)logo\./i.test(i.basename(e.filename))&&ki.has(t.contentType)&&m.push(t)}if(!l)return z({en:`Missing index.js in plugin package`,"zh-CN":`插件包缺少 index.js`});if(!u)return z({en:`Missing manifest.json in plugin package`,"zh-CN":`插件包缺少 manifest.json`});let[h,g]=await Oi({manifest:d??``,etag:s,availableFiles:c,getAccessURL:t?async({filePath:e,pluginId:n,version:r})=>t({filePath:e,pluginId:n,version:r,etag:s}):void 0});return g?z({en:`Can not load plugin`,"zh-CN":`无法加载插件`},g):_t({info:h,files:{index:l,manifest:u,...f?{readme:f}:{},...p.length?{assets:p}:{},...m.length?{logos:m}:{}}})};export{ft as FastGPTPluginClient,y as PluginPermissionEnum,v as PluginPermissionEnumSchema,lt as RunToolWithStream,Fi as parsePkg,dt as pluginTagList};
|
|
20
21
|
//# sourceMappingURL=index.js.map
|