@cline/cli-linux-x64 0.0.12 → 0.0.13-nightly.1778329987
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/bin/clite
CHANGED
|
Binary file
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{createRequire as n}from"node:module";var t=n(import.meta.url);import{normalizePluginManifest as GY}from"@cline/shared";import{existsSync as z,readFileSync as k}from"node:fs";import{builtinModules as r,createRequire as E}from"node:module";import{dirname as j,extname as S,isAbsolute as a,resolve as K}from"node:path";import{fileURLToPath as y}from"node:url";import{PLUGIN_FILE_EXTENSIONS as s}from"@cline/shared";var i=j(y(import.meta.url)),x=E(import.meta.url),e=K(i,"..","..","..","..",".."),N=YY(e),O=new Set(r.flatMap((Y)=>[Y,Y.replace(/^node:/,"")])),L=new Set(s);function YY(Y){let Z={},$={"@cline/agents":K(Y,"packages/agents/src/index.ts"),"@cline/core":K(Y,"packages/core/src/index.ts"),"@cline/llms":K(Y,"packages/llms/src/index.ts"),"@cline/shared":K(Y,"packages/shared/src/index.ts"),"@cline/shared/storage":K(Y,"packages/shared/src/storage/index.ts"),"@cline/shared/db":K(Y,"packages/shared/src/db/index.ts")};for(let[Q,q]of Object.entries($))if(z(q))Z[Q]=q;return Z}function f(Y){return!(Y.startsWith(".")||Y.startsWith("/")||Y.startsWith("file:")||Y.startsWith("data:")||Y.startsWith("http:")||Y.startsWith("https:"))}function b(Y){if(Y.startsWith("@")){let[Z,$]=Y.split("/",3);return $?`${Z}/${$}`:Y}return Y.split("/",1)[0]??Y}function v(Y,Z){let $=b(Z),Q=j(Y);while(!0){let q=K(Q,"node_modules",$);if(z(q)||z(K(q,"package.json")))return!0;let G=K(Q,"..");if(G===Q)return!1;Q=G}}function ZY(Y){try{return x.resolve(Y),!0}catch{return!1}}function $Y(Y){try{return x.resolve(Y)}catch{return null}}function QY(Y){let $=j(Y);for(let Q=0;Q<4;Q++){let q=K($,"package.json");if(z(q))try{let V=JSON.parse(k(q,"utf8"));return V!=null&&typeof V==="object"&&"cline"in V}catch{return!1}let G=K($,"..");if(G===$)return!1;$=G}return!1}function qY(Y,Z){let $=Z.startsWith("file:")?y(Z):a(Z)?Z:K(j(Y),Z);if(z($)&&L.has(S($)))return $;for(let Q of L){let q=`${$}${Q}`;if(z(q))return q}for(let Q of L){let q=K($,`index${Q}`);if(z(q))return q}return null}function h(Y){let Z=new Set,$=[/\bimport\s+(?:type\s+)?[^"'`]*?\bfrom\s*["'`]([^"'`]+)["'`]/g,/\bexport\s+[^"'`]*?\bfrom\s*["'`]([^"'`]+)["'`]/g,/\bimport\s*\(\s*["'`]([^"'`]+)["'`]\s*\)/g,/\brequire\s*\(\s*["'`]([^"'`]+)["'`]\s*\)/g];for(let Q of $)for(let q of Y.matchAll(Q)){let G=q[1];if(G)Z.add(G)}return[...Z]}function P(Y,Z,$=new Set){if($.has(Y)||!z(Y))return;if($.add(Y),!L.has(S(Y)))return;let Q=k(Y,"utf8");for(let q of h(Q)){if(q.startsWith("node:")||O.has(q))continue;if(f(q)){if(Object.hasOwn(N,q)||Object.hasOwn(N,b(q))||v(Y,q)||Z&&ZY(q))continue;throw Error(`Cannot find module '${b(q)}'`)}let G=qY(Y,q);if(G)P(G,Z,$)}}function wY(Y,Z){let $=E(Y),Q={};for(let[q,G]of Object.entries(N)){try{$.resolve(q);continue}catch{}Q[q]=G}if(Z){let q=k(Y,"utf8");for(let G of h(q)){if(!f(G)||G.startsWith("node:")||O.has(G)||Object.hasOwn(Q,G)||v(Y,G))continue;let V=$Y(G);if(V)Q[G]=V}}return Q}async function m(Y,Z={}){let $=!QY(Y);P(Y,$);let Q=wY(Y,$),q=await import("jiti"),G=typeof q==="function"?q:typeof q.default==="function"?q.default:void 0;if(!G)throw Error("Unable to load jiti");return await G(Y,{alias:Q,cache:Z.useCache,requireCache:Z.useCache,esmResolve:!0,interopDefault:!1,nativeModules:[...O],transformModules:Object.keys(Q)}).import(Y,{})}function d(Y,Z){if(!Y)return!0;if(Y.providerIds?.length){if(!Z?.providerId||!Y.providerIds.includes(Z.providerId))return!1}if(Y.modelIds?.length){if(!Z?.modelId||!Y.modelIds.includes(Z.modelId))return!1}return!0}function X(Y){return typeof Y==="object"&&Y!==null}function c(Y){return Array.isArray(Y)&&Y.every((Z)=>typeof Z==="string")}function JY(Y,Z){if(!X(Y))throw Error(`Invalid plugin module: ${Z}`);if(typeof Y.name!=="string"||!Y.name)throw Error(`Invalid plugin name: ${Z}`);if(!X(Y.manifest))throw Error(`Invalid plugin manifest: ${Z}`);if(Object.hasOwn(Y.manifest,"providerIds")&&!c(Y.manifest.providerIds))throw Error(`Invalid plugin manifest.providerIds: ${Z}`);if(Object.hasOwn(Y.manifest,"modelIds")&&!c(Y.manifest.modelIds))throw Error(`Invalid plugin manifest.modelIds: ${Z}`)}function KY(Y){if(!X(Y))throw Error("Plugin setup context must be an object");if(Y.session!==void 0&&!X(Y.session))throw Error("Plugin setup context session must be an object");if(Y.client!==void 0&&!X(Y.client))throw Error("Plugin setup context client must be an object");if(Y.user!==void 0&&!X(Y.user))throw Error("Plugin setup context user must be an object");if(Y.workspaceInfo!==void 0&&!X(Y.workspaceInfo))throw Error("Plugin setup context workspaceInfo must be an object");if(Y.automation!==void 0&&!X(Y.automation))throw Error("Plugin setup context automation must be an object");if(Y.automation!==void 0&&typeof Y.automation.ingestEvent!=="function")throw Error("Plugin setup context automation.ingestEvent must be a function");if(Y.logger!==void 0&&!X(Y.logger))throw Error("Plugin setup context logger must be an object")}var o=0,A=new Map,T=new Map;function VY(Y){let Z=Y instanceof Error?Y.message:String(Y),$=Y instanceof Error?Y.stack:void 0;return{message:Z,stack:$}}function R(Y,Z,$,Q){if(!process.send)return;process.send({type:"response",id:Y,ok:Z,result:$,error:Q})}function I(Y,Z){if(!process.send)return;process.send({type:"event",name:Y,payload:Z})}globalThis.__clinePluginHost={emitEvent:I};globalThis.__clineSessionEnv={cwd:void 0,workspaceInfo:void 0};function u(Y){if(!Y||typeof Y!=="object")return{};return Y}function WY(Y){if(!Y||typeof Y!=="object")return;let Z={...Y};if(Z.error instanceof Error)Z.error={name:Z.error.name,message:Z.error.message,stack:Z.error.stack};return Z}function XY(Y){let Z=($,Q,q)=>{I("plugin_log",{level:$,pluginName:Y,message:Q,metadata:WY(q)})};return{debug:($,Q)=>Z("debug",$,Q),log:($,Q)=>Z("log",$,Q),error:($,Q)=>Z("error",$,Q)}}function C(Y,Z){let $=`${Y}:${Z}`,Q=(T.get($)??0)+1;return T.set($,Q),`${Y}_${Z}_${Q}`}function FY(Y){let Z=typeof Y.eventType==="string"?Y.eventType.trim():"",$=typeof Y.source==="string"?Y.source.trim():"";if(!Z)throw Error("Automation event type contribution requires eventType");if(!$)throw Error("Automation event type contribution requires source");return{...Y,eventType:Z,source:$,examples:Y.examples?[...Y.examples]:void 0,metadata:Y.metadata?u(Y.metadata):void 0}}function _(Y){let Z=A.get(Y);if(!Z)throw Error(`Unknown sandbox plugin id: ${Y}`);return Z}async function zY(Y){if(A.clear(),o=0,T.clear(),Y.cwd)try{process.chdir(Y.cwd)}catch{}let Z=globalThis.__clineSessionEnv;if(Z)Z.cwd=Y.cwd,Z.workspaceInfo=Y.workspaceInfo;let $=[],Q=[],q=[],G=Y.exportName||"plugin",V=new Map,l={providerId:Y.providerId,modelId:Y.modelId};for(let M of Y.pluginPaths||[]){let J;try{let F=await m(M);if(J=F.default??F[G],JY(J,M),J.manifest=GY(J.manifest),!d(J.manifest,l))continue;let U=`plugin_${++o}`,B={tools:[],commands:[],messageBuilders:[],providers:[],automationEventTypes:[],shortcuts:[],flags:[]},H={tools:new Map,commands:new Map,messageBuilders:new Map},g={registerTool:(w)=>{let W=C(U,"tool");H.tools.set(W,w.execute),B.tools.push({id:W,name:w.name,description:w.description,inputSchema:w.inputSchema,timeoutMs:w.timeoutMs,retryable:w.retryable})},registerCommand:(w)=>{let W=C(U,"command");if(typeof w.handler==="function")H.commands.set(W,w.handler);B.commands.push({id:W,name:w.name,description:w.description})},registerMessageBuilder:(w)=>{let W=C(U,"builder");H.messageBuilders.set(W,w.build),B.messageBuilders.push({id:W,name:w.name})},registerProvider:(w)=>{B.providers.push({id:C(U,"provider"),name:w.name,description:w.description,metadata:u(w.metadata)})},registerAutomationEventType:(w)=>{B.automationEventTypes.push({id:C(U,"automation_event"),...FY(w)})}};if(typeof J.setup==="function")try{let w={session:Y.session,client:Y.client,user:Y.user,workspaceInfo:Y.workspaceInfo,...Y.loggerEnabled?{logger:XY(J.name)}:{},...J.manifest.capabilities.includes("automationEvents")?{automation:{ingestEvent:(W)=>{I("automation_event",W)}}}:{}};KY(w),await J.setup(g,w)}catch(w){Q.push({pluginPath:M,pluginName:J.name,phase:"setup",message:w instanceof Error?w.message:String(w),stack:w instanceof Error?w.stack:void 0});continue}let D=V.get(J.name);if(D!==void 0){let w=$[D];if(!w)V.delete(J.name);else{q.push({type:"duplicate_plugin_override",pluginName:J.name,pluginPath:M,overriddenPluginPath:w.pluginPath,message:`Plugin "${J.name}" from ${M} overrides ${w.pluginPath}`}),A.delete(w.pluginId),$.splice(D,1),V.clear();for(let[W,p]of $.entries())V.set(p.name,W)}}A.set(U,{plugin:J,handlers:H}),V.set(J.name,$.length),$.push({pluginId:U,pluginPath:M,name:J.name,manifest:J.manifest,hooks:J.hooks?Object.entries(J.hooks).filter(([,w])=>typeof w==="function").map(([w])=>w):void 0,contributions:B})}catch(F){Q.push({pluginPath:M,pluginName:J?.name,phase:"load",message:F instanceof Error?F.message:String(F),stack:F instanceof Error?F.stack:void 0})}}return{plugins:$,failures:Q,warnings:q}}async function MY(Y){let $=_(Y.pluginId).plugin.hooks?.[Y.hookName];if(typeof $!=="function")return;return await $(Y.payload)}async function UY(Y){let $=_(Y.pluginId).handlers.tools.get(Y.contributionId);if(typeof $!=="function")throw Error("Unknown sandbox tool contribution");return await $(Y.input,Y.context)}async function BY(Y){let $=_(Y.pluginId).handlers.commands.get(Y.contributionId);if(typeof $!=="function")return"";return await $(Y.input)}async function CY(Y){let $=_(Y.pluginId).handlers.messageBuilders.get(Y.contributionId);if(typeof $!=="function")return[];return await $(Y.messages)}var HY={initialize:zY,invokeHook:MY,executeTool:UY,executeCommand:BY,buildMessages:CY};process.on("message",async(Y)=>{if(!Y||Y.type!=="call")return;let Z=HY[Y.method];if(!Z){R(Y.id,!1,void 0,{message:`Unknown method: ${String(Y.method)}`});return}try{let $=await Z(Y.args||{});R(Y.id,!0,$)}catch($){R(Y.id,!1,void 0,VY($))}});
|
|
1
|
+
import{createRequire as GG}from"node:module";var QG=GG(import.meta.url);import{normalizePluginManifest as JG}from"@cline/shared";import{existsSync as L,readFileSync as B}from"node:fs";import{builtinModules as UG,createRequire as m}from"node:module";import{dirname as D,extname as y,isAbsolute as XG,resolve as K}from"node:path";import{fileURLToPath as h}from"node:url";import{PLUGIN_FILE_EXTENSIONS as YG}from"@cline/shared";var d=D(h(import.meta.url)),ZG=m(import.meta.url),$G=K(d,"..","..","..","..",".."),V=WG($G),qG=["@cline/agents","@cline/core","@cline/core/hub","@cline/core/hub/daemon-entry","@cline/core/telemetry","@cline/llms","@cline/llms/browser","@cline/shared","@cline/shared/automation","@cline/shared/browser","@cline/shared/storage","@cline/shared/db","@cline/shared/types"],R=new Set(UG.flatMap((G)=>[G,G.replace(/^node:/,"")])),j=new Set(YG),KG=["development","node","import","require","default"];function WG(G){let Q={},U={"@cline/agents":K(G,"packages/agents/src/index.ts"),"@cline/core":K(G,"packages/core/src/index.ts"),"@cline/llms":K(G,"packages/llms/src/index.ts"),"@cline/shared":K(G,"packages/shared/src/index.ts"),"@cline/shared/storage":K(G,"packages/shared/src/storage/index.ts"),"@cline/shared/db":K(G,"packages/shared/src/db/index.ts")};for(let[Y,X]of Object.entries(U))if(L(X))Q[Y]=X;for(let Y of["agents","core","llms","shared"]){let X=K(G,"packages",Y),q=K(X,"package.json");if(!L(q))continue;try{let Z=JSON.parse(B(q,"utf8"));if(typeof Z.name!=="string"||!Z.exports)continue;if(typeof Z.exports==="string"){let w=K(X,Z.exports);if(L(w))Q[Z.name]=w;continue}if(typeof Z.exports!=="object")continue;for(let[w,A]of Object.entries(Z.exports)){let W=wG(X,A);if(!W)continue;let _=w==="."?Z.name:`${Z.name}/${w.replace(/^\.\//,"")}`;Q[_]=W}}catch{}}return Q}function wG(G,Q){let U=k(Q);if(!U)return null;let Y=u(G,U);for(let X of Y)if(L(X))return X;return null}function k(G,Q=new Set){if(typeof G==="string")return G;if(!G||typeof G!=="object")return null;if(Q.has(G))return null;Q.add(G);let U=G;for(let Y of KG){let X=k(U[Y],Q);if(X)return X}return null}function u(G,Q){let U=Q.replace(/^\.\//,""),Y=[K(G,Q)];if(U.startsWith("dist/")){let X=U.replace(/^dist\//,"src/").replace(/\.(mjs|cjs|js)$/,"");return[K(G,`${X}.ts`),K(G,`${X}.tsx`),K(G,`${X}.mts`),K(G,`${X}.cts`),...Y]}return Y}function _G(G){return Object.fromEntries(Object.entries(G).sort(([Q],[U])=>U.length-Q.length))}function H(G){return!(G.startsWith(".")||G.startsWith("/")||G.startsWith("file:")||G.startsWith("data:")||G.startsWith("http:")||G.startsWith("https:"))}function C(G){if(G.startsWith("@")){let[Q,U]=G.split("/",3);return U?`${Q}/${U}`:G}return G.split("/",1)[0]??G}function LG(G){let Q=C(G);if(G===Q)return".";return`.${G.slice(Q.length)}`}function c(G){return C(G).startsWith("@cline/")}function b(G,Q){let U=C(Q),Y=D(G);while(!0){let X=K(Y,"node_modules",U);if(L(X)||L(K(X,"package.json")))return!0;let q=K(Y,"..");if(q===Y)return!1;Y=q}}function P(G){return T(G)!==null}function T(G){try{return ZG.resolve(G)}catch{}return AG(G)}function AG(G){let Q=C(G),U=MG(Q);if(!U)return null;let Y=K(U,"package.json");try{let X=JSON.parse(B(Y,"utf8")),q=LG(G),Z=q==="."&&typeof X.exports==="string"?X.exports:X.exports&&typeof X.exports==="object"&&Object.hasOwn(X.exports,q)?X.exports[q]:void 0,w=k(Z)??(q==="."&&typeof X.main==="string"?X.main:null);if(!w)return null;let A=K(U,w),W=[A,...u(U,w).filter((_)=>_!==A)];for(let _ of W)if(L(_))return _;return null}catch{return null}}function MG(G){let Q=d;while(!0){let U=K(Q,"package.json");if(L(U))try{if(JSON.parse(B(U,"utf8")).name===G)return Q}catch{}let Y=K(Q,"node_modules",G,"package.json");if(L(Y))return D(Y);let X=K(Q,"..");if(X===Q)return null;Q=X}}function zG(G){let U=D(G);for(let Y=0;Y<4;Y++){let X=K(U,"package.json");if(L(X))try{let Z=JSON.parse(B(X,"utf8"));return Z!=null&&typeof Z==="object"&&"cline"in Z}catch{return!1}let q=K(U,"..");if(q===U)return!1;U=q}return!1}function l(G,Q){let U=Q.startsWith("file:")?h(Q):XG(Q)?Q:K(D(G),Q);if(L(U)&&j.has(y(U)))return U;for(let Y of j){let X=`${U}${Y}`;if(L(X))return X}for(let Y of j){let X=K(U,`index${Y}`);if(L(X))return X}return null}function g(G){let Q=new Set,U=[/\bimport\s+(?:type\s+)?[^"'`]*?\bfrom\s*["'`]([^"'`]+)["'`]/g,/\bexport\s+[^"'`]*?\bfrom\s*["'`]([^"'`]+)["'`]/g,/\bimport\s*\(\s*["'`]([^"'`]+)["'`]\s*\)/g,/\brequire\s*\(\s*["'`]([^"'`]+)["'`]\s*\)/g];for(let Y of U)for(let X of G.matchAll(Y)){let q=X[1];if(q)Q.add(q)}return[...Q]}function o(G,Q,U=new Set){if(U.has(G)||!L(G))return;if(U.add(G),!j.has(y(G)))return;let Y=B(G,"utf8");for(let X of g(Y)){if(X.startsWith("node:")||R.has(X))continue;if(H(X)){if(Object.hasOwn(V,X)||Object.hasOwn(V,C(X))||b(G,X)||c(X)&&P(X)||Q&&P(X))continue;throw Error(`Cannot find module '${C(X)}'`)}let q=l(G,X);if(q)o(q,Q,U)}}function n(G,Q=new Set,U=new Set){if(Q.has(G)||!L(G))return U;if(Q.add(G),!j.has(y(G)))return U;let Y=B(G,"utf8");for(let X of g(Y)){if(U.add(X),H(X))continue;let q=l(G,X);if(q)n(q,Q,U)}return U}function FG(G,Q){let U=m(G),Y={},X=n(G),q=new Set(qG);for(let[Z,w]of Object.entries(V)){try{U.resolve(Z);continue}catch{}Y[Z]=w}for(let Z of X)if(H(Z)&&(c(Z)||Q))q.add(Z);for(let Z of q){if(Object.hasOwn(Y,Z)||b(G,Z))continue;let w=T(Z);if(w)Y[Z]=w}if(!Q)return Y;for(let Z of X){if(!H(Z)||Object.hasOwn(Y,Z)||b(G,Z)||Z.startsWith("node:")||R.has(Z))continue;let w=T(Z);if(w)Y[Z]=w}return Y}async function p(G,Q={}){let U=!zG(G);o(G,U);let Y=FG(G,U),X=_G(Y),q=await import("jiti"),Z=typeof q==="function"?q:typeof q.default==="function"?q.default:void 0;if(!Z)throw Error("Unable to load jiti");return await Z(G,{alias:X,cache:Q.useCache,requireCache:Q.useCache,esmResolve:!0,interopDefault:!1,nativeModules:[...R],transformModules:Object.keys(X)}).import(G,{})}function s(G,Q){if(!G)return!0;if(G.providerIds?.length){if(!Q?.providerId||!G.providerIds.includes(Q.providerId))return!1}if(G.modelIds?.length){if(!Q?.modelId||!G.modelIds.includes(Q.modelId))return!1}return!0}function z(G){return typeof G==="object"&&G!==null}function r(G){return Array.isArray(G)&&G.every((Q)=>typeof Q==="string")}function CG(G,Q){if(!z(G))throw Error(`Invalid plugin module: ${Q}`);if(typeof G.name!=="string"||!G.name)throw Error(`Invalid plugin name: ${Q}`);if(!z(G.manifest))throw Error(`Invalid plugin manifest: ${Q}`);if(Object.hasOwn(G.manifest,"providerIds")&&!r(G.manifest.providerIds))throw Error(`Invalid plugin manifest.providerIds: ${Q}`);if(Object.hasOwn(G.manifest,"modelIds")&&!r(G.manifest.modelIds))throw Error(`Invalid plugin manifest.modelIds: ${Q}`)}function BG(G){if(!z(G))throw Error("Plugin setup context must be an object");if(G.session!==void 0&&!z(G.session))throw Error("Plugin setup context session must be an object");if(G.client!==void 0&&!z(G.client))throw Error("Plugin setup context client must be an object");if(G.user!==void 0&&!z(G.user))throw Error("Plugin setup context user must be an object");if(G.workspaceInfo!==void 0&&!z(G.workspaceInfo))throw Error("Plugin setup context workspaceInfo must be an object");if(G.automation!==void 0&&!z(G.automation))throw Error("Plugin setup context automation must be an object");if(G.automation!==void 0&&typeof G.automation.ingestEvent!=="function")throw Error("Plugin setup context automation.ingestEvent must be a function");if(G.logger!==void 0&&!z(G.logger))throw Error("Plugin setup context logger must be an object")}var t=0,E=new Map,x=new Map;function jG(G){let Q=G instanceof Error?G.message:String(G),U=G instanceof Error?G.stack:void 0;return{message:Q,stack:U}}function v(G,Q,U,Y){if(!process.send)return;process.send({type:"response",id:G,ok:Q,result:U,error:Y})}function f(G,Q){if(!process.send)return;process.send({type:"event",name:G,payload:Q})}globalThis.__clinePluginHost={emitEvent:f};globalThis.__clineSessionEnv={cwd:void 0,workspaceInfo:void 0};function a(G){if(!G||typeof G!=="object")return{};return G}function DG(G){if(!G||typeof G!=="object")return;let Q={...G};if(Q.error instanceof Error)Q.error={name:Q.error.name,message:Q.error.message,stack:Q.error.stack};return Q}function OG(G){let Q=(U,Y,X)=>{f("plugin_log",{level:U,pluginName:G,message:Y,metadata:DG(X)})};return{debug:(U,Y)=>Q("debug",U,Y),log:(U,Y)=>Q("log",U,Y),error:(U,Y)=>Q("error",U,Y)}}function O(G,Q){let U=`${G}:${Q}`,Y=(x.get(U)??0)+1;return x.set(U,Y),`${G}_${Q}_${Y}`}function NG(G){let Q=typeof G.eventType==="string"?G.eventType.trim():"",U=typeof G.source==="string"?G.source.trim():"";if(!Q)throw Error("Automation event type contribution requires eventType");if(!U)throw Error("Automation event type contribution requires source");return{...G,eventType:Q,source:U,examples:G.examples?[...G.examples]:void 0,metadata:G.metadata?a(G.metadata):void 0}}function I(G){let Q=E.get(G);if(!Q)throw Error(`Unknown sandbox plugin id: ${G}`);return Q}async function HG(G){if(E.clear(),t=0,x.clear(),G.cwd)try{process.chdir(G.cwd)}catch{}let Q=globalThis.__clineSessionEnv;if(Q)Q.cwd=G.cwd,Q.workspaceInfo=G.workspaceInfo;let U=[],Y=[],X=[],q=G.exportName||"plugin",Z=new Map,w={providerId:G.providerId,modelId:G.modelId};for(let A of G.pluginPaths||[]){let W;try{let _=await p(A);if(W=_.default??_[q],CG(W,A),W.manifest=JG(W.manifest),!s(W.manifest,w))continue;let F=`plugin_${++t}`,J={tools:[],commands:[],messageBuilders:[],providers:[],automationEventTypes:[],shortcuts:[],flags:[]},N={tools:new Map,commands:new Map,messageBuilders:new Map},i={registerTool:($)=>{let M=O(F,"tool");N.tools.set(M,$.execute),J.tools.push({id:M,name:$.name,description:$.description,inputSchema:$.inputSchema,timeoutMs:$.timeoutMs,retryable:$.retryable})},registerCommand:($)=>{let M=O(F,"command");if(typeof $.handler==="function")N.commands.set(M,$.handler);J.commands.push({id:M,name:$.name,description:$.description})},registerMessageBuilder:($)=>{let M=O(F,"builder");N.messageBuilders.set(M,$.build),J.messageBuilders.push({id:M,name:$.name})},registerProvider:($)=>{J.providers.push({id:O(F,"provider"),name:$.name,description:$.description,metadata:a($.metadata)})},registerAutomationEventType:($)=>{J.automationEventTypes.push({id:O(F,"automation_event"),...NG($)})}};if(typeof W.setup==="function")try{let $={session:G.session,client:G.client,user:G.user,workspaceInfo:G.workspaceInfo,...G.loggerEnabled?{logger:OG(W.name)}:{},...W.manifest.capabilities.includes("automationEvents")?{automation:{ingestEvent:(M)=>{f("automation_event",M)}}}:{}};BG($),await W.setup(i,$)}catch($){Y.push({pluginPath:A,pluginName:W.name,phase:"setup",message:$ instanceof Error?$.message:String($),stack:$ instanceof Error?$.stack:void 0});continue}let S=Z.get(W.name);if(S!==void 0){let $=U[S];if(!$)Z.delete(W.name);else{X.push({type:"duplicate_plugin_override",pluginName:W.name,pluginPath:A,overriddenPluginPath:$.pluginPath,message:`Plugin "${W.name}" from ${A} overrides ${$.pluginPath}`}),E.delete($.pluginId),U.splice(S,1),Z.clear();for(let[M,e]of U.entries())Z.set(e.name,M)}}E.set(F,{plugin:W,handlers:N}),Z.set(W.name,U.length),U.push({pluginId:F,pluginPath:A,name:W.name,manifest:W.manifest,hooks:W.hooks?Object.entries(W.hooks).filter(([,$])=>typeof $==="function").map(([$])=>$):void 0,contributions:J})}catch(_){Y.push({pluginPath:A,pluginName:W?.name,phase:"load",message:_ instanceof Error?_.message:String(_),stack:_ instanceof Error?_.stack:void 0})}}return{plugins:U,failures:Y,warnings:X}}async function EG(G){let U=I(G.pluginId).plugin.hooks?.[G.hookName];if(typeof U!=="function")return;return await U(G.payload)}async function IG(G){let U=I(G.pluginId).handlers.tools.get(G.contributionId);if(typeof U!=="function")throw Error("Unknown sandbox tool contribution");return await U(G.input,G.context)}async function SG(G){let U=I(G.pluginId).handlers.commands.get(G.contributionId);if(typeof U!=="function")return"";return await U(G.input)}async function VG(G){let U=I(G.pluginId).handlers.messageBuilders.get(G.contributionId);if(typeof U!=="function")return[];return await U(G.messages)}var bG={initialize:HG,invokeHook:EG,executeTool:IG,executeCommand:SG,buildMessages:VG};process.on("message",async(G)=>{if(!G||G.type!=="call")return;let Q=bG[G.method];if(!Q){v(G.id,!1,void 0,{message:`Unknown method: ${String(G.method)}`});return}try{let U=await Q(G.args||{});v(G.id,!0,U)}catch(U){v(G.id,!1,void 0,jG(U))}});
|