2026-03-27 20:16:07 +00:00
import fs from "node:fs" ;
import path from "node:path" ;
import ts from "typescript" ;
2026-03-29 14:32:46 +01:00
import { bundledPluginFile } from "./bundled-plugin-paths.mjs" ;
2026-03-29 09:08:06 +01:00
function pluginSource ( dirName , artifactBasename = "api.js" ) {
2026-03-29 14:32:46 +01:00
return ` @openclaw/ ${ dirName } / ${ artifactBasename } ` ;
2026-03-29 09:08:06 +01:00
}
function runtimeApiSourcePath ( dirName ) {
return bundledPluginFile ( dirName , "runtime-api.ts" ) ;
}
2026-03-27 20:16:07 +00:00
export const GENERATED _PLUGIN _SDK _FACADES = [
2026-03-27 23:24:36 +00:00
{
subpath : "amazon-bedrock" ,
2026-03-29 09:08:06 +01:00
source : pluginSource ( "amazon-bedrock" , "api.js" ) ,
2026-03-27 23:24:36 +00:00
exports : [
"discoverBedrockModels" ,
"mergeImplicitBedrockProvider" ,
"resetBedrockDiscoveryCacheForTest" ,
"resolveBedrockConfigApiKey" ,
"resolveImplicitBedrockProvider" ,
] ,
} ,
2026-03-27 20:16:07 +00:00
{
subpath : "anthropic-vertex" ,
2026-03-29 09:08:06 +01:00
source : pluginSource ( "anthropic-vertex" , "api.js" ) ,
2026-03-27 20:16:07 +00:00
exports : [
"ANTHROPIC_VERTEX_DEFAULT_MODEL_ID" ,
"buildAnthropicVertexProvider" ,
2026-03-27 23:24:36 +00:00
"hasAnthropicVertexAvailableAuth" ,
"hasAnthropicVertexCredentials" ,
"mergeImplicitAnthropicVertexProvider" ,
"resolveAnthropicVertexClientRegion" ,
"resolveAnthropicVertexConfigApiKey" ,
"resolveImplicitAnthropicVertexProvider" ,
"resolveAnthropicVertexProjectId" ,
2026-03-27 20:16:07 +00:00
"resolveAnthropicVertexRegion" ,
2026-03-27 23:24:36 +00:00
"resolveAnthropicVertexRegionFromBaseUrl" ,
2026-03-27 20:16:07 +00:00
] ,
} ,
{
subpath : "anthropic-cli" ,
2026-03-29 09:08:06 +01:00
source : pluginSource ( "anthropic" , "api.js" ) ,
2026-03-27 20:16:07 +00:00
exports : [ "CLAUDE_CLI_BACKEND_ID" , "isClaudeCliProvider" ] ,
} ,
{
subpath : "bluebubbles-policy" ,
2026-03-29 09:08:06 +01:00
source : pluginSource ( "bluebubbles" , "api.js" ) ,
2026-03-27 20:16:07 +00:00
exports : [
"isAllowedBlueBubblesSender" ,
"resolveBlueBubblesGroupRequireMention" ,
"resolveBlueBubblesGroupToolPolicy" ,
] ,
} ,
{
subpath : "browser" ,
2026-03-29 09:08:06 +01:00
source : pluginSource ( "browser" , "runtime-api.js" ) ,
2026-04-02 14:37:12 +09:00
loadPolicy : "activated" ,
2026-03-27 20:16:07 +00:00
exports : [
"browserHandlers" ,
"createBrowserPluginService" ,
"createBrowserTool" ,
"handleBrowserGatewayRequest" ,
"registerBrowserCli" ,
] ,
} ,
{
subpath : "browser-runtime" ,
2026-03-29 09:08:06 +01:00
source : pluginSource ( "browser" , "runtime-api.js" ) ,
2026-04-02 14:37:12 +09:00
loadPolicy : "activated" ,
2026-04-02 11:43:02 +09:00
directExports : {
DEFAULT _AI _SNAPSHOT _MAX _CHARS : "./browser-config.js" ,
DEFAULT _BROWSER _EVALUATE _ENABLED : "./browser-config.js" ,
DEFAULT _OPENCLAW _BROWSER _COLOR : "./browser-config.js" ,
DEFAULT _OPENCLAW _BROWSER _PROFILE _NAME : "./browser-config.js" ,
DEFAULT _UPLOAD _DIR : "./browser-config.js" ,
2026-04-02 14:37:12 +09:00
closeTrackedBrowserTabsForSessions : "./browser-maintenance.js" ,
movePathToTrash : "./browser-maintenance.js" ,
2026-04-02 17:12:32 +09:00
parseBrowserMajorVersion : "./browser-host-inspection.js" ,
2026-04-02 11:43:02 +09:00
redactCdpUrl : "./browser-config.js" ,
2026-04-02 17:12:32 +09:00
readBrowserVersion : "./browser-host-inspection.js" ,
2026-04-02 11:43:02 +09:00
resolveBrowserConfig : "./browser-config.js" ,
resolveBrowserControlAuth : "./browser-config.js" ,
2026-04-02 17:12:32 +09:00
resolveGoogleChromeExecutableForPlatform : "./browser-host-inspection.js" ,
2026-04-02 11:43:02 +09:00
resolveProfile : "./browser-config.js" ,
} ,
2026-03-29 09:08:06 +01:00
exports : [
"BrowserBridge" ,
"BrowserCreateProfileResult" ,
"BrowserDeleteProfileResult" ,
"BrowserExecutable" ,
"BrowserFormField" ,
"BrowserResetProfileResult" ,
"BrowserRouteRegistrar" ,
"BrowserServerState" ,
"BrowserStatus" ,
"BrowserTab" ,
"BrowserTransport" ,
"DEFAULT_AI_SNAPSHOT_MAX_CHARS" ,
"DEFAULT_BROWSER_EVALUATE_ENABLED" ,
"DEFAULT_OPENCLAW_BROWSER_COLOR" ,
"DEFAULT_OPENCLAW_BROWSER_PROFILE_NAME" ,
"DEFAULT_UPLOAD_DIR" ,
"OpenClawPluginApi" ,
"OpenClawPluginToolContext" ,
"OpenClawPluginToolFactory" ,
"ProfileStatus" ,
"ResolvedBrowserConfig" ,
"ResolvedBrowserProfile" ,
"SnapshotResult" ,
"applyBrowserProxyPaths" ,
"browserAct" ,
"browserArmDialog" ,
"browserArmFileChooser" ,
"browserCloseTab" ,
"browserConsoleMessages" ,
"browserCreateProfile" ,
"browserDeleteProfile" ,
"browserFocusTab" ,
"browserHandlers" ,
"browserNavigate" ,
"browserOpenTab" ,
"browserPdfSave" ,
"browserProfiles" ,
"browserResetProfile" ,
"browserScreenshotAction" ,
"browserSnapshot" ,
"browserStart" ,
"browserStatus" ,
"browserStop" ,
"browserTabAction" ,
"browserTabs" ,
"closeTrackedBrowserTabsForSessions" ,
"createBrowserControlContext" ,
"createBrowserPluginService" ,
"createBrowserRouteContext" ,
"createBrowserRouteDispatcher" ,
"createBrowserRuntimeState" ,
"createBrowserTool" ,
"definePluginEntry" ,
"ensureBrowserControlAuth" ,
"getBrowserControlState" ,
"getBrowserProfileCapabilities" ,
"handleBrowserGatewayRequest" ,
"installBrowserAuthMiddleware" ,
"installBrowserCommonMiddleware" ,
"isPersistentBrowserProfileMutation" ,
"movePathToTrash" ,
"normalizeBrowserFormField" ,
"normalizeBrowserFormFieldValue" ,
"normalizeBrowserRequestPath" ,
"parseBrowserMajorVersion" ,
"persistBrowserProxyFiles" ,
"readBrowserVersion" ,
"redactCdpUrl" ,
"registerBrowserCli" ,
"registerBrowserRoutes" ,
"resolveBrowserConfig" ,
"resolveBrowserControlAuth" ,
"resolveExistingPathsWithinRoot" ,
"resolveGoogleChromeExecutableForPlatform" ,
"resolveProfile" ,
"resolveRequestedBrowserProfile" ,
"runBrowserProxyCommand" ,
"startBrowserBridgeServer" ,
"startBrowserControlServiceFromConfig" ,
"stopBrowserBridgeServer" ,
"stopBrowserControlService" ,
"stopBrowserRuntime" ,
"trackSessionBrowserTab" ,
"untrackSessionBrowserTab" ,
] ,
typeExports : [
"BrowserBridge" ,
"BrowserCreateProfileResult" ,
"BrowserDeleteProfileResult" ,
"BrowserExecutable" ,
"BrowserFormField" ,
"BrowserResetProfileResult" ,
"BrowserRouteRegistrar" ,
"BrowserServerState" ,
"BrowserStatus" ,
"BrowserTab" ,
"BrowserTransport" ,
"OpenClawPluginApi" ,
"OpenClawPluginToolContext" ,
"OpenClawPluginToolFactory" ,
"ProfileStatus" ,
"ResolvedBrowserConfig" ,
"ResolvedBrowserProfile" ,
"SnapshotResult" ,
] ,
2026-03-27 20:16:07 +00:00
} ,
{
subpath : "cloudflare-ai-gateway" ,
2026-03-29 09:08:06 +01:00
source : pluginSource ( "cloudflare-ai-gateway" , "api.js" ) ,
2026-03-27 20:16:07 +00:00
exports : [
"applyCloudflareAiGatewayConfig" ,
"applyCloudflareAiGatewayProviderConfig" ,
"buildCloudflareAiGatewayConfigPatch" ,
"buildCloudflareAiGatewayModelDefinition" ,
"CLOUDFLARE_AI_GATEWAY_DEFAULT_MODEL_ID" ,
"CLOUDFLARE_AI_GATEWAY_DEFAULT_MODEL_REF" ,
"CLOUDFLARE_AI_GATEWAY_PROVIDER_ID" ,
"resolveCloudflareAiGatewayBaseUrl" ,
] ,
} ,
{
subpath : "byteplus" ,
2026-03-29 09:08:06 +01:00
source : pluginSource ( "byteplus" , "api.js" ) ,
2026-03-27 20:16:07 +00:00
exports : [
"buildBytePlusCodingProvider" ,
"buildBytePlusModelDefinition" ,
"buildBytePlusProvider" ,
"BYTEPLUS_BASE_URL" ,
"BYTEPLUS_CODING_BASE_URL" ,
"BYTEPLUS_CODING_MODEL_CATALOG" ,
"BYTEPLUS_MODEL_CATALOG" ,
] ,
} ,
{
subpath : "chutes" ,
2026-03-29 09:08:06 +01:00
source : pluginSource ( "chutes" , "api.js" ) ,
2026-03-27 20:16:07 +00:00
exports : [
"applyChutesApiKeyConfig" ,
"applyChutesConfig" ,
"applyChutesProviderConfig" ,
"buildChutesModelDefinition" ,
"buildChutesProvider" ,
"CHUTES_BASE_URL" ,
"CHUTES_DEFAULT_MODEL_ID" ,
"CHUTES_DEFAULT_MODEL_REF" ,
"CHUTES_MODEL_CATALOG" ,
"discoverChutesModels" ,
] ,
} ,
{
subpath : "deepseek" ,
2026-03-29 09:08:06 +01:00
source : pluginSource ( "deepseek" , "api.js" ) ,
2026-03-27 20:16:07 +00:00
exports : [
"buildDeepSeekModelDefinition" ,
"buildDeepSeekProvider" ,
"DEEPSEEK_BASE_URL" ,
"DEEPSEEK_MODEL_CATALOG" ,
] ,
} ,
{
subpath : "feishu-conversation" ,
2026-03-29 09:08:06 +01:00
source : pluginSource ( "feishu" , "api.js" ) ,
2026-03-27 20:16:07 +00:00
exports : [
"buildFeishuConversationId" ,
"createFeishuThreadBindingManager" ,
2026-03-27 23:24:36 +00:00
"feishuSessionBindingAdapterChannels" ,
"feishuThreadBindingTesting" ,
2026-03-27 20:16:07 +00:00
"parseFeishuDirectConversationId" ,
"parseFeishuConversationId" ,
"parseFeishuTargetId" ,
] ,
} ,
{
subpath : "google" ,
2026-03-29 09:08:06 +01:00
source : pluginSource ( "google" , "api.js" ) ,
2026-03-27 20:16:07 +00:00
exports : [
"applyGoogleGeminiModelDefault" ,
"DEFAULT_GOOGLE_API_BASE_URL" ,
"GOOGLE_GEMINI_DEFAULT_MODEL" ,
2026-03-27 23:24:36 +00:00
"isGoogleGenerativeAiApi" ,
"normalizeAntigravityModelId" ,
2026-03-27 20:16:07 +00:00
"normalizeGoogleApiBaseUrl" ,
2026-03-27 23:24:36 +00:00
"normalizeGoogleGenerativeAiBaseUrl" ,
2026-03-27 20:16:07 +00:00
"normalizeGoogleModelId" ,
2026-03-27 23:24:36 +00:00
"normalizeGoogleProviderConfig" ,
2026-03-27 20:16:07 +00:00
"parseGeminiAuth" ,
2026-03-27 23:24:36 +00:00
"resolveGoogleGenerativeAiApiOrigin" ,
"resolveGoogleGenerativeAiTransport" ,
"shouldNormalizeGoogleProviderConfig" ,
"shouldNormalizeGoogleGenerativeAiProviderConfig" ,
2026-03-27 20:16:07 +00:00
] ,
} ,
{
subpath : "feishu-setup" ,
2026-03-29 09:08:06 +01:00
source : pluginSource ( "feishu" , "api.js" ) ,
2026-03-27 20:16:07 +00:00
exports : [ "feishuSetupAdapter" , "feishuSetupWizard" ] ,
} ,
{
subpath : "github-copilot-login" ,
2026-03-29 09:08:06 +01:00
source : pluginSource ( "github-copilot" , "api.js" ) ,
2026-03-27 20:16:07 +00:00
exports : [ "githubCopilotLoginCommand" ] ,
} ,
{
subpath : "huggingface" ,
2026-03-29 09:08:06 +01:00
source : pluginSource ( "huggingface" , "api.js" ) ,
2026-03-27 20:16:07 +00:00
exports : [
"buildHuggingfaceModelDefinition" ,
"buildHuggingfaceProvider" ,
"discoverHuggingfaceModels" ,
"HUGGINGFACE_BASE_URL" ,
"HUGGINGFACE_DEFAULT_MODEL_REF" ,
"HUGGINGFACE_MODEL_CATALOG" ,
"HUGGINGFACE_POLICY_SUFFIXES" ,
"isHuggingfacePolicyLocked" ,
] ,
} ,
{
subpath : "image-generation-runtime" ,
2026-03-29 09:08:06 +01:00
source : pluginSource ( "image-generation-core" , "runtime-api.js" ) ,
2026-04-02 14:37:12 +09:00
loadPolicy : "activated" ,
2026-03-29 09:08:06 +01:00
exports : [
"generateImage" ,
"listRuntimeImageGenerationProviders" ,
"GenerateImageParams" ,
"GenerateImageRuntimeResult" ,
] ,
typeExports : [ "GenerateImageParams" , "GenerateImageRuntimeResult" ] ,
2026-03-27 20:16:07 +00:00
} ,
{
subpath : "kimi-coding" ,
2026-03-29 09:08:06 +01:00
source : pluginSource ( "kimi-coding" , "api.js" ) ,
2026-03-27 20:16:07 +00:00
exports : [ "buildKimiCodingProvider" ] ,
} ,
{
subpath : "kilocode" ,
2026-03-29 09:08:06 +01:00
source : pluginSource ( "kilocode" , "api.js" ) ,
2026-03-27 20:16:07 +00:00
exports : [
"buildKilocodeProvider" ,
"buildKilocodeProviderWithDiscovery" ,
"buildKilocodeModelDefinition" ,
"discoverKilocodeModels" ,
"KILOCODE_BASE_URL" ,
"KILOCODE_DEFAULT_CONTEXT_WINDOW" ,
"KILOCODE_DEFAULT_COST" ,
"KILOCODE_DEFAULT_MAX_TOKENS" ,
"KILOCODE_DEFAULT_MODEL_ID" ,
"KILOCODE_DEFAULT_MODEL_NAME" ,
"KILOCODE_DEFAULT_MODEL_REF" ,
"KILOCODE_MODELS_URL" ,
"KILOCODE_MODEL_CATALOG" ,
] ,
} ,
{
subpath : "irc-surface" ,
2026-03-29 09:08:06 +01:00
source : pluginSource ( "irc" , "api.js" ) ,
2026-03-27 20:16:07 +00:00
exports : [
"ircSetupAdapter" ,
"ircSetupWizard" ,
"listIrcAccountIds" ,
"resolveDefaultIrcAccountId" ,
"resolveIrcAccount" ,
] ,
} ,
{
subpath : "media-understanding-runtime" ,
2026-03-29 09:08:06 +01:00
source : pluginSource ( "media-understanding-core" , "runtime-api.js" ) ,
2026-04-02 14:37:12 +09:00
loadPolicy : "activated" ,
2026-03-29 09:08:06 +01:00
exports : [
"describeImageFile" ,
"describeImageFileWithModel" ,
"describeVideoFile" ,
"runMediaUnderstandingFile" ,
"transcribeAudioFile" ,
"RunMediaUnderstandingFileParams" ,
"RunMediaUnderstandingFileResult" ,
] ,
typeExports : [ "RunMediaUnderstandingFileParams" , "RunMediaUnderstandingFileResult" ] ,
2026-03-27 20:16:07 +00:00
} ,
{
subpath : "memory-core-engine-runtime" ,
2026-03-29 09:08:06 +01:00
source : pluginSource ( "memory-core" , "runtime-api.js" ) ,
2026-04-02 14:37:12 +09:00
loadPolicy : "activated" ,
2026-03-29 09:08:06 +01:00
exports : [
"BuiltinMemoryEmbeddingProviderDoctorMetadata" ,
"getBuiltinMemoryEmbeddingProviderDoctorMetadata" ,
"getMemorySearchManager" ,
"listBuiltinAutoSelectMemoryEmbeddingProviderDoctorMetadata" ,
"MemoryIndexManager" ,
] ,
typeExports : [ "BuiltinMemoryEmbeddingProviderDoctorMetadata" ] ,
2026-03-27 20:16:07 +00:00
} ,
{
subpath : "mattermost-policy" ,
2026-03-29 09:08:06 +01:00
source : pluginSource ( "mattermost" , "api.js" ) ,
2026-03-27 20:16:07 +00:00
exports : [ "isMattermostSenderAllowed" ] ,
} ,
{
subpath : "litellm" ,
2026-03-29 09:08:06 +01:00
source : pluginSource ( "litellm" , "api.js" ) ,
2026-03-27 20:16:07 +00:00
exports : [
"applyLitellmConfig" ,
"applyLitellmProviderConfig" ,
"buildLitellmModelDefinition" ,
"LITELLM_BASE_URL" ,
"LITELLM_DEFAULT_MODEL_ID" ,
"LITELLM_DEFAULT_MODEL_REF" ,
] ,
} ,
{
subpath : "line-runtime" ,
2026-03-29 09:08:06 +01:00
source : pluginSource ( "line" , "runtime-api.js" ) ,
2026-04-02 14:37:12 +09:00
loadPolicy : "activated" ,
2026-03-29 09:08:06 +01:00
runtimeApiPreExportsPath : runtimeApiSourcePath ( "line" ) ,
2026-03-27 20:16:07 +00:00
typeExports : [
"Action" ,
"CardAction" ,
"CreateRichMenuParams" ,
"FlexBox" ,
"FlexBubble" ,
"FlexButton" ,
"FlexCarousel" ,
"FlexComponent" ,
"FlexContainer" ,
"FlexImage" ,
"FlexText" ,
"LineChannelData" ,
"LineConfig" ,
"LineProbeResult" ,
"ListItem" ,
"ResolvedLineAccount" ,
"RichMenuArea" ,
"RichMenuAreaRequest" ,
"RichMenuRequest" ,
"RichMenuResponse" ,
"RichMenuSize" ,
] ,
} ,
{
subpath : "line-surface" ,
2026-03-29 09:08:06 +01:00
source : pluginSource ( "line" , "runtime-api.js" ) ,
2026-04-02 14:37:12 +09:00
// This surface is also used by passive reply normalization helpers.
// Keep it loadable without requiring the LINE plugin to be activated.
2026-03-27 20:16:07 +00:00
exports : [
"CardAction" ,
"createActionCard" ,
"createAgendaCard" ,
"createAppleTvRemoteCard" ,
"createDeviceControlCard" ,
"createEventCard" ,
"createImageCard" ,
"createInfoCard" ,
"createListCard" ,
"createMediaPlayerCard" ,
"createReceiptCard" ,
"LineChannelData" ,
"LineConfig" ,
"LineConfigSchema" ,
"LineProbeResult" ,
"listLineAccountIds" ,
"ListItem" ,
"normalizeAccountId" ,
"processLineMessage" ,
"ResolvedLineAccount" ,
"resolveDefaultLineAccountId" ,
"resolveExactLineGroupConfigKey" ,
"resolveLineAccount" ,
] ,
typeExports : [
"CardAction" ,
"LineChannelData" ,
"LineConfig" ,
"LineProbeResult" ,
"ListItem" ,
"ResolvedLineAccount" ,
] ,
} ,
{
subpath : "matrix-helper" ,
2026-03-29 09:08:06 +01:00
source : pluginSource ( "matrix" , "api.js" ) ,
2026-03-27 20:16:07 +00:00
exports : [
"findMatrixAccountEntry" ,
"getMatrixScopedEnvVarNames" ,
"requiresExplicitMatrixDefaultAccount" ,
"resolveConfiguredMatrixAccountIds" ,
"resolveMatrixAccountStorageRoot" ,
"resolveMatrixChannelConfig" ,
"resolveMatrixCredentialsDir" ,
"resolveMatrixCredentialsPath" ,
"resolveMatrixDefaultOrOnlyAccountId" ,
"resolveMatrixLegacyFlatStoragePaths" ,
] ,
} ,
{
subpath : "matrix-runtime-surface" ,
2026-03-29 09:08:06 +01:00
source : pluginSource ( "matrix" , "runtime-api.js" ) ,
2026-04-02 14:37:12 +09:00
loadPolicy : "activated" ,
2026-03-27 20:16:07 +00:00
exports : [ "resolveMatrixAccountStringValues" , "setMatrixRuntime" ] ,
} ,
{
subpath : "matrix-surface" ,
2026-03-29 09:08:06 +01:00
source : pluginSource ( "matrix" , "api.js" ) ,
2026-03-27 23:24:36 +00:00
exports : [
"createMatrixThreadBindingManager" ,
"matrixSessionBindingAdapterChannels" ,
"resetMatrixThreadBindingsForTests" ,
] ,
2026-03-27 20:16:07 +00:00
} ,
{
subpath : "matrix-thread-bindings" ,
2026-03-29 09:08:06 +01:00
source : pluginSource ( "matrix" , "api.js" ) ,
2026-03-27 20:16:07 +00:00
exports : [
"setMatrixThreadBindingIdleTimeoutBySessionKey" ,
"setMatrixThreadBindingMaxAgeBySessionKey" ,
] ,
} ,
{
subpath : "openrouter" ,
2026-03-29 09:08:06 +01:00
source : pluginSource ( "openrouter" , "api.js" ) ,
2026-03-28 20:58:54 +00:00
exports : [
"applyOpenrouterConfig" ,
"applyOpenrouterProviderConfig" ,
"buildOpenrouterProvider" ,
"OPENROUTER_DEFAULT_MODEL_REF" ,
] ,
2026-03-27 20:16:07 +00:00
} ,
{
subpath : "minimax" ,
2026-03-29 09:08:06 +01:00
source : pluginSource ( "minimax" , "api.js" ) ,
2026-03-27 20:16:07 +00:00
exports : [
2026-03-28 20:58:54 +00:00
"applyMinimaxApiConfig" ,
"applyMinimaxApiConfigCn" ,
"applyMinimaxApiProviderConfig" ,
"applyMinimaxApiProviderConfigCn" ,
2026-03-27 20:16:07 +00:00
"buildMinimaxPortalProvider" ,
"buildMinimaxProvider" ,
"isMiniMaxModernModelId" ,
2026-03-27 23:24:36 +00:00
"MINIMAX_API_BASE_URL" ,
"MINIMAX_CN_API_BASE_URL" ,
2026-03-27 20:16:07 +00:00
"MINIMAX_DEFAULT_MODEL_ID" ,
"MINIMAX_DEFAULT_MODEL_REF" ,
"MINIMAX_TEXT_MODEL_CATALOG" ,
"MINIMAX_TEXT_MODEL_ORDER" ,
"MINIMAX_TEXT_MODEL_REFS" ,
] ,
} ,
{
subpath : "modelstudio" ,
2026-03-29 09:08:06 +01:00
source : pluginSource ( "modelstudio" , "api.js" ) ,
2026-03-27 20:45:43 +00:00
exports : [
2026-03-27 23:24:36 +00:00
"applyModelStudioNativeStreamingUsageCompat" ,
2026-03-27 20:45:43 +00:00
"buildModelStudioDefaultModelDefinition" ,
"buildModelStudioModelDefinition" ,
"MODELSTUDIO_BASE_URL" ,
"MODELSTUDIO_CN_BASE_URL" ,
"MODELSTUDIO_DEFAULT_COST" ,
"MODELSTUDIO_DEFAULT_MODEL_ID" ,
"MODELSTUDIO_DEFAULT_MODEL_REF" ,
"MODELSTUDIO_GLOBAL_BASE_URL" ,
2026-03-27 16:33:44 -05:00
"MODELSTUDIO_STANDARD_CN_BASE_URL" ,
"MODELSTUDIO_STANDARD_GLOBAL_BASE_URL" ,
"MODELSTUDIO_MODEL_CATALOG" ,
2026-03-27 23:24:36 +00:00
"isNativeModelStudioBaseUrl" ,
2026-03-27 20:45:43 +00:00
"buildModelStudioProvider" ,
] ,
2026-03-27 20:16:07 +00:00
} ,
{
subpath : "modelstudio-definitions" ,
2026-03-29 09:08:06 +01:00
source : pluginSource ( "modelstudio" , "api.js" ) ,
2026-03-27 20:16:07 +00:00
exports : [
"buildModelStudioDefaultModelDefinition" ,
"buildModelStudioModelDefinition" ,
"MODELSTUDIO_CN_BASE_URL" ,
"MODELSTUDIO_DEFAULT_COST" ,
"MODELSTUDIO_DEFAULT_MODEL_ID" ,
"MODELSTUDIO_DEFAULT_MODEL_REF" ,
"MODELSTUDIO_GLOBAL_BASE_URL" ,
2026-03-27 16:10:42 -05:00
"MODELSTUDIO_STANDARD_CN_BASE_URL" ,
"MODELSTUDIO_STANDARD_GLOBAL_BASE_URL" ,
2026-03-27 20:16:07 +00:00
] ,
} ,
{
subpath : "moonshot" ,
2026-03-29 09:08:06 +01:00
source : pluginSource ( "moonshot" , "api.js" ) ,
2026-03-27 23:24:36 +00:00
exports : [
"applyMoonshotNativeStreamingUsageCompat" ,
"buildMoonshotProvider" ,
"isNativeMoonshotBaseUrl" ,
"MOONSHOT_BASE_URL" ,
"MOONSHOT_CN_BASE_URL" ,
"MOONSHOT_DEFAULT_MODEL_ID" ,
"MOONSHOT_DEFAULT_MODEL_REF" ,
] ,
} ,
{
subpath : "mistral" ,
2026-03-29 09:08:06 +01:00
source : pluginSource ( "mistral" , "api.js" ) ,
2026-03-28 20:58:54 +00:00
exports : [
"applyMistralConfig" ,
"applyMistralProviderConfig" ,
"buildMistralModelDefinition" ,
"buildMistralProvider" ,
"MISTRAL_BASE_URL" ,
"MISTRAL_DEFAULT_MODEL_ID" ,
"MISTRAL_DEFAULT_MODEL_REF" ,
] ,
2026-03-27 20:16:07 +00:00
} ,
{
subpath : "nvidia" ,
2026-03-29 09:08:06 +01:00
source : pluginSource ( "nvidia" , "api.js" ) ,
2026-03-27 20:16:07 +00:00
exports : [ "buildNvidiaProvider" ] ,
} ,
{
subpath : "ollama" ,
2026-03-29 09:08:06 +01:00
source : pluginSource ( "ollama" , "runtime-api.js" ) ,
exports : [
"buildAssistantMessage" ,
"buildOllamaChatRequest" ,
"convertToOllamaMessages" ,
"createOllamaEmbeddingProvider" ,
"createConfiguredOllamaCompatNumCtxWrapper" ,
"createConfiguredOllamaCompatStreamWrapper" ,
"createConfiguredOllamaStreamFn" ,
"createOllamaStreamFn" ,
"DEFAULT_OLLAMA_EMBEDDING_MODEL" ,
"isOllamaCompatProvider" ,
"OLLAMA_NATIVE_BASE_URL" ,
"parseNdjsonStream" ,
"resolveOllamaBaseUrlForRun" ,
"resolveOllamaCompatNumCtxEnabled" ,
"shouldInjectOllamaCompatNumCtx" ,
"wrapOllamaCompatNumCtx" ,
] ,
typeExports : [ "OllamaEmbeddingClient" , "OllamaEmbeddingProvider" ] ,
2026-03-27 20:16:07 +00:00
} ,
{
subpath : "ollama-surface" ,
2026-03-29 09:08:06 +01:00
source : pluginSource ( "ollama" , "api.js" ) ,
2026-03-27 20:16:07 +00:00
exports : [
"buildOllamaModelDefinition" ,
"buildOllamaProvider" ,
"configureOllamaNonInteractive" ,
"ensureOllamaModelPulled" ,
"enrichOllamaModelsWithContext" ,
"fetchOllamaModels" ,
"OLLAMA_DEFAULT_BASE_URL" ,
"OLLAMA_DEFAULT_CONTEXT_WINDOW" ,
"OLLAMA_DEFAULT_COST" ,
"OLLAMA_DEFAULT_MAX_TOKENS" ,
"OLLAMA_DEFAULT_MODEL" ,
"OllamaModelWithContext" ,
"OllamaTagModel" ,
"OllamaTagsResponse" ,
"promptAndConfigureOllama" ,
"queryOllamaContextWindow" ,
"resolveOllamaApiBase" ,
] ,
typeExports : [ "OllamaModelWithContext" , "OllamaTagModel" , "OllamaTagsResponse" ] ,
} ,
{
subpath : "openai" ,
2026-03-29 09:08:06 +01:00
source : pluginSource ( "openai" , "api.js" ) ,
2026-03-27 20:16:07 +00:00
exports : [
"applyOpenAIConfig" ,
"applyOpenAIProviderConfig" ,
"buildOpenAICodexProvider" ,
"buildOpenAIProvider" ,
"OPENAI_CODEX_DEFAULT_MODEL" ,
"OPENAI_DEFAULT_AUDIO_TRANSCRIPTION_MODEL" ,
"OPENAI_DEFAULT_EMBEDDING_MODEL" ,
"OPENAI_DEFAULT_IMAGE_MODEL" ,
"OPENAI_DEFAULT_MODEL" ,
"OPENAI_DEFAULT_TTS_MODEL" ,
"OPENAI_DEFAULT_TTS_VOICE" ,
] ,
} ,
{
subpath : "opencode" ,
2026-03-29 09:08:06 +01:00
source : pluginSource ( "opencode" , "api.js" ) ,
2026-03-27 20:16:07 +00:00
exports : [
"applyOpencodeZenConfig" ,
"applyOpencodeZenModelDefault" ,
"applyOpencodeZenProviderConfig" ,
"OPENCODE_ZEN_DEFAULT_MODEL" ,
"OPENCODE_ZEN_DEFAULT_MODEL_REF" ,
] ,
} ,
{
subpath : "opencode-go" ,
2026-03-29 09:08:06 +01:00
source : pluginSource ( "opencode-go" , "api.js" ) ,
2026-03-27 20:16:07 +00:00
exports : [
"applyOpencodeGoConfig" ,
"applyOpencodeGoModelDefault" ,
"applyOpencodeGoProviderConfig" ,
"OPENCODE_GO_DEFAULT_MODEL_REF" ,
] ,
} ,
{
subpath : "qianfan" ,
2026-03-29 09:08:06 +01:00
source : pluginSource ( "qianfan" , "api.js" ) ,
2026-03-27 20:16:07 +00:00
exports : [ "QIANFAN_BASE_URL" , "QIANFAN_DEFAULT_MODEL_ID" , "buildQianfanProvider" ] ,
} ,
{
subpath : "provider-reasoning" ,
2026-03-29 09:08:06 +01:00
source : pluginSource ( "ollama" , "api.js" ) ,
2026-03-27 20:16:07 +00:00
exports : [ "isReasoningModelHeuristic" ] ,
} ,
{
subpath : "speech-runtime" ,
2026-03-29 09:08:06 +01:00
source : pluginSource ( "speech-core" , "runtime-api.js" ) ,
2026-04-02 14:37:12 +09:00
loadPolicy : "activated" ,
2026-03-29 09:08:06 +01:00
exports : [
"_test" ,
"buildTtsSystemPromptHint" ,
"getLastTtsAttempt" ,
"getResolvedSpeechProviderConfig" ,
"getTtsMaxLength" ,
"getTtsProvider" ,
"isSummarizationEnabled" ,
"isTtsEnabled" ,
"isTtsProviderConfigured" ,
"listSpeechVoices" ,
"maybeApplyTtsToPayload" ,
"ResolvedTtsConfig" ,
"ResolvedTtsModelOverrides" ,
"resolveTtsAutoMode" ,
"resolveTtsConfig" ,
"resolveTtsPrefsPath" ,
"resolveTtsProviderOrder" ,
"setLastTtsAttempt" ,
"setSummarizationEnabled" ,
"setTtsAutoMode" ,
"setTtsEnabled" ,
"setTtsMaxLength" ,
"setTtsProvider" ,
"synthesizeSpeech" ,
"textToSpeech" ,
"textToSpeechTelephony" ,
"TtsDirectiveOverrides" ,
"TtsDirectiveParseResult" ,
"TtsResult" ,
"TtsSynthesisResult" ,
"TtsTelephonyResult" ,
] ,
typeExports : [
"ResolvedTtsConfig" ,
"ResolvedTtsModelOverrides" ,
"TtsDirectiveOverrides" ,
"TtsDirectiveParseResult" ,
"TtsResult" ,
"TtsSynthesisResult" ,
"TtsTelephonyResult" ,
] ,
2026-03-27 20:16:07 +00:00
} ,
{
subpath : "sglang" ,
2026-03-29 09:08:06 +01:00
source : pluginSource ( "sglang" , "api.js" ) ,
2026-03-27 20:16:07 +00:00
exports : [
2026-03-27 23:24:36 +00:00
"buildSglangProvider" ,
2026-03-27 20:16:07 +00:00
"SGLANG_DEFAULT_API_KEY_ENV_VAR" ,
"SGLANG_DEFAULT_BASE_URL" ,
"SGLANG_MODEL_PLACEHOLDER" ,
"SGLANG_PROVIDER_LABEL" ,
] ,
} ,
{
subpath : "synthetic" ,
2026-03-29 09:08:06 +01:00
source : pluginSource ( "synthetic" , "api.js" ) ,
2026-03-27 20:16:07 +00:00
exports : [
2026-03-28 20:58:54 +00:00
"applySyntheticConfig" ,
"applySyntheticProviderConfig" ,
2026-03-27 20:16:07 +00:00
"buildSyntheticModelDefinition" ,
"buildSyntheticProvider" ,
"SYNTHETIC_BASE_URL" ,
"SYNTHETIC_DEFAULT_MODEL_REF" ,
"SYNTHETIC_MODEL_CATALOG" ,
] ,
} ,
{
subpath : "together" ,
2026-03-29 09:08:06 +01:00
source : pluginSource ( "together" , "api.js" ) ,
2026-03-27 20:16:07 +00:00
exports : [
"applyTogetherConfig" ,
"buildTogetherModelDefinition" ,
"buildTogetherProvider" ,
"TOGETHER_BASE_URL" ,
"TOGETHER_DEFAULT_MODEL_REF" ,
"TOGETHER_MODEL_CATALOG" ,
] ,
} ,
{
subpath : "venice" ,
2026-03-29 09:08:06 +01:00
source : pluginSource ( "venice" , "api.js" ) ,
2026-03-27 20:16:07 +00:00
exports : [
"buildVeniceModelDefinition" ,
"buildVeniceProvider" ,
"discoverVeniceModels" ,
"VENICE_BASE_URL" ,
"VENICE_DEFAULT_MODEL_REF" ,
"VENICE_MODEL_CATALOG" ,
] ,
} ,
{
subpath : "vercel-ai-gateway" ,
2026-03-29 09:08:06 +01:00
source : pluginSource ( "vercel-ai-gateway" , "api.js" ) ,
2026-03-27 20:16:07 +00:00
exports : [
"buildVercelAiGatewayProvider" ,
"discoverVercelAiGatewayModels" ,
"getStaticVercelAiGatewayModelCatalog" ,
"VERCEL_AI_GATEWAY_BASE_URL" ,
2026-03-27 20:45:43 +00:00
"VERCEL_AI_GATEWAY_DEFAULT_CONTEXT_WINDOW" ,
"VERCEL_AI_GATEWAY_DEFAULT_COST" ,
"VERCEL_AI_GATEWAY_DEFAULT_MAX_TOKENS" ,
"VERCEL_AI_GATEWAY_DEFAULT_MODEL_ID" ,
2026-03-27 20:16:07 +00:00
"VERCEL_AI_GATEWAY_DEFAULT_MODEL_REF" ,
2026-03-27 20:45:43 +00:00
"VERCEL_AI_GATEWAY_PROVIDER_ID" ,
2026-03-27 20:16:07 +00:00
] ,
} ,
{
subpath : "volcengine" ,
2026-03-29 09:08:06 +01:00
source : pluginSource ( "volcengine" , "api.js" ) ,
2026-03-27 20:16:07 +00:00
exports : [
"buildDoubaoCodingProvider" ,
"buildDoubaoModelDefinition" ,
"buildDoubaoProvider" ,
"DOUBAO_BASE_URL" ,
"DOUBAO_CODING_BASE_URL" ,
"DOUBAO_CODING_MODEL_CATALOG" ,
"DOUBAO_MODEL_CATALOG" ,
] ,
} ,
{
subpath : "vllm" ,
2026-03-29 09:08:06 +01:00
source : pluginSource ( "vllm" , "api.js" ) ,
2026-03-27 20:16:07 +00:00
exports : [
2026-03-27 23:24:36 +00:00
"buildVllmProvider" ,
2026-03-27 20:16:07 +00:00
"VLLM_DEFAULT_API_KEY_ENV_VAR" ,
"VLLM_DEFAULT_BASE_URL" ,
"VLLM_MODEL_PLACEHOLDER" ,
"VLLM_PROVIDER_LABEL" ,
] ,
} ,
{
subpath : "xai" ,
2026-03-29 09:08:06 +01:00
source : pluginSource ( "xai" , "api.js" ) ,
2026-03-27 20:16:07 +00:00
exports : [
2026-03-28 20:58:54 +00:00
"applyXaiConfig" ,
"applyXaiProviderConfig" ,
2026-03-27 20:16:07 +00:00
"applyXaiModelCompat" ,
"buildXaiCatalogModels" ,
"buildXaiModelDefinition" ,
"buildXaiProvider" ,
"HTML_ENTITY_TOOL_CALL_ARGUMENTS_ENCODING" ,
"isModernXaiModel" ,
"normalizeXaiModelId" ,
"resolveXaiCatalogEntry" ,
"resolveXaiForwardCompatModel" ,
"XAI_BASE_URL" ,
"XAI_DEFAULT_CONTEXT_WINDOW" ,
"XAI_DEFAULT_MODEL_ID" ,
"XAI_DEFAULT_MODEL_REF" ,
"XAI_DEFAULT_MAX_TOKENS" ,
"XAI_TOOL_SCHEMA_PROFILE" ,
] ,
} ,
{
subpath : "xiaomi" ,
2026-03-29 09:08:06 +01:00
source : pluginSource ( "xiaomi" , "api.js" ) ,
2026-03-27 20:16:07 +00:00
exports : [
"applyXiaomiConfig" ,
2026-03-28 20:58:54 +00:00
"applyXiaomiProviderConfig" ,
2026-03-27 20:16:07 +00:00
"buildXiaomiProvider" ,
"XIAOMI_DEFAULT_MODEL_ID" ,
"XIAOMI_DEFAULT_MODEL_REF" ,
] ,
} ,
{
subpath : "zai" ,
2026-03-29 09:08:06 +01:00
source : pluginSource ( "zai" , "api.js" ) ,
2026-03-27 20:16:07 +00:00
exports : [
"applyZaiConfig" ,
"applyZaiProviderConfig" ,
"ZAI_CN_BASE_URL" ,
"ZAI_CODING_CN_BASE_URL" ,
"ZAI_CODING_GLOBAL_BASE_URL" ,
"ZAI_DEFAULT_MODEL_ID" ,
"ZAI_DEFAULT_MODEL_REF" ,
"ZAI_GLOBAL_BASE_URL" ,
] ,
} ,
2026-04-02 09:01:44 +01:00
{
subpath : "whatsapp-surface" ,
source : pluginSource ( "whatsapp" , "api.js" ) ,
exportSources : {
DEFAULT _WEB _MEDIA _BYTES : pluginSource ( "whatsapp" , "constants.js" ) ,
} ,
exports : [
"DEFAULT_WEB_MEDIA_BYTES" ,
"hasAnyWhatsAppAuth" ,
"listEnabledWhatsAppAccounts" ,
"listWhatsAppDirectoryGroupsFromConfig" ,
"listWhatsAppDirectoryPeersFromConfig" ,
"resolveWhatsAppAccount" ,
"resolveWhatsAppGroupRequireMention" ,
"resolveWhatsAppGroupToolPolicy" ,
"resolveWhatsAppOutboundTarget" ,
"whatsappAccessControlTesting" ,
] ,
typeExports : [
"WebChannelStatus" ,
"WebInboundMessage" ,
"WebListenerCloseReason" ,
"WebMonitorTuning" ,
] ,
} ,
2026-03-27 20:16:07 +00:00
{
subpath : "zalo-setup" ,
2026-03-29 09:08:06 +01:00
source : pluginSource ( "zalo" , "api.js" ) ,
2026-03-27 23:24:36 +00:00
exports : [
"evaluateZaloGroupAccess" ,
"resolveZaloRuntimeGroupPolicy" ,
"zaloSetupAdapter" ,
"zaloSetupWizard" ,
] ,
2026-03-27 20:16:07 +00:00
} ,
] ;
export const GENERATED _PLUGIN _SDK _FACADES _BY _SUBPATH = Object . fromEntries (
GENERATED _PLUGIN _SDK _FACADES . map ( ( entry ) => [ entry . subpath , entry ] ) ,
) ;
2026-04-02 14:37:12 +09:00
function resolveFacadeLoadPolicy ( entry , sourcePath ) {
// Keep loader policy next to the facade entry itself so additions stay local
// and mixed-source facades can opt into per-source behavior later if needed.
const sourcePolicy = entry . sourceLoadPolicy ? . [ sourcePath ] ;
if ( sourcePolicy ) {
return sourcePolicy ;
}
return entry . loadPolicy ? ? "plain" ;
}
2026-03-27 20:16:07 +00:00
export const GENERATED _PLUGIN _SDK _FACADES _LABEL = "plugin-sdk-facades" ;
export const GENERATED _PLUGIN _SDK _FACADES _SCRIPT = "scripts/generate-plugin-sdk-facades.mjs" ;
2026-03-29 09:08:06 +01:00
export const GENERATED _PLUGIN _SDK _FACADE _TYPES _OUTPUT =
"src/generated/plugin-sdk-facade-type-map.generated.ts" ;
function rewriteFacadeTypeImportSpecifier ( sourcePath ) {
return sourcePath ;
}
2026-03-27 20:16:07 +00:00
const MODULE _RESOLUTION _OPTIONS = {
allowJs : true ,
checkJs : false ,
jsx : ts . JsxEmit . Preserve ,
module : ts . ModuleKind . ESNext ,
moduleResolution : ts . ModuleResolutionKind . Bundler ,
skipLibCheck : true ,
target : ts . ScriptTarget . ESNext ,
} ;
const MODULE _RESOLUTION _HOST = ts . createCompilerHost ( MODULE _RESOLUTION _OPTIONS , true ) ;
2026-03-31 20:59:54 +01:00
const moduleResolutionContextCache = new Map ( ) ;
2026-03-27 20:16:07 +00:00
const sourceExportKindsCache = new Map ( ) ;
2026-03-29 09:08:06 +01:00
function listFacadeEntrySourcePaths ( entry ) {
return Array . from ( new Set ( [ entry . source , ... Object . values ( entry . exportSources ? ? { } ) ] ) ) ;
}
function buildFacadeSourceModuleKey ( sourceIndex ) {
return ` source ${ sourceIndex + 1 } ` ;
}
function isPrimitiveTypeLike ( type ) {
if ( type . isUnion ( ) ) {
return type . types . every ( ( member ) => isPrimitiveTypeLike ( member ) ) ;
}
const primitiveFlags =
ts . TypeFlags . StringLike |
ts . TypeFlags . NumberLike |
ts . TypeFlags . BooleanLike |
ts . TypeFlags . BigIntLike |
ts . TypeFlags . ESSymbolLike |
ts . TypeFlags . Null |
ts . TypeFlags . Undefined |
ts . TypeFlags . Void ;
return Boolean ( type . flags & primitiveFlags ) ;
}
function isArrayTypeLike ( checker , type ) {
if ( type . isUnion ( ) ) {
return type . types . every ( ( member ) => isArrayTypeLike ( checker , member ) ) ;
}
return checker . isArrayType ( type ) || checker . isTupleType ( type ) ;
}
function normalizeFacadeSourceParts ( sourcePath ) {
2026-03-29 14:32:46 +01:00
const packageSourceMatch = /^@openclaw\/([^/]+)\/([^/]+)$/u . exec ( sourcePath ) ;
if ( packageSourceMatch ) {
2026-03-29 09:08:06 +01:00
return {
2026-03-29 14:32:46 +01:00
dirName : packageSourceMatch [ 1 ] ,
artifactBasename : packageSourceMatch [ 2 ] ,
2026-03-29 09:08:06 +01:00
} ;
}
const match = /^\.\.\/\.\.\/extensions\/([^/]+)\/([^/]+)$/u . exec ( sourcePath ) ;
if ( ! match ) {
throw new Error ( ` Unsupported plugin-sdk facade source: ${ sourcePath } ` ) ;
}
return {
dirName : match [ 1 ] ,
artifactBasename : match [ 2 ] ,
} ;
}
2026-03-27 20:16:07 +00:00
function collectRuntimeApiPreExports ( repoRoot , runtimeApiPath ) {
const absolutePath = path . join ( repoRoot , runtimeApiPath ) ;
const sourceText = fs . readFileSync ( absolutePath , "utf8" ) ;
const sourceFile = ts . createSourceFile ( absolutePath , sourceText , ts . ScriptTarget . Latest , true ) ;
const exportNames = new Set ( ) ;
for ( const statement of sourceFile . statements ) {
if ( ! ts . isExportDeclaration ( statement ) ) {
continue ;
}
const moduleSpecifier =
statement . moduleSpecifier && ts . isStringLiteral ( statement . moduleSpecifier )
? statement . moduleSpecifier . text
: undefined ;
if ( ! moduleSpecifier ) {
continue ;
}
if ( statement . isTypeOnly ) {
continue ;
}
if ( moduleSpecifier === "openclaw/plugin-sdk/line-runtime" ) {
break ;
}
if ( ! moduleSpecifier . startsWith ( "./src/" ) ) {
continue ;
}
if ( ! statement . exportClause || ! ts . isNamedExports ( statement . exportClause ) ) {
continue ;
}
for ( const element of statement . exportClause . elements ) {
if ( ! element . isTypeOnly ) {
exportNames . add ( element . name . text ) ;
}
}
}
return Array . from ( exportNames ) . toSorted ( ( left , right ) => left . localeCompare ( right ) ) ;
}
function resolveFacadeSourceTypescriptPath ( repoRoot , sourcePath ) {
2026-03-29 14:32:46 +01:00
const packageSourceMatch = /^@openclaw\/([^/]+)\/(.+)$/u . exec ( sourcePath ) ;
const absolutePath = packageSourceMatch
? path . resolve ( repoRoot , "extensions" , packageSourceMatch [ 1 ] , packageSourceMatch [ 2 ] )
2026-03-29 09:08:06 +01:00
: path . resolve ( repoRoot , "src/plugin-sdk" , sourcePath ) ;
2026-03-27 20:16:07 +00:00
const candidates = [ absolutePath . replace ( /\.js$/ , ".ts" ) , absolutePath . replace ( /\.js$/ , ".tsx" ) ] ;
return candidates . find ( ( candidate ) => fs . existsSync ( candidate ) ) ;
}
2026-03-31 20:59:54 +01:00
function resolveFacadeModuleResolutionContext ( repoRoot ) {
const cacheKey = repoRoot || "__default__" ;
const cached = moduleResolutionContextCache . get ( cacheKey ) ;
if ( cached ) {
return cached ;
}
let context = {
options : MODULE _RESOLUTION _OPTIONS ,
host : MODULE _RESOLUTION _HOST ,
} ;
if ( repoRoot ) {
const fileExists = ( filePath ) => ts . sys . fileExists ( filePath ) ;
const readFile = ( filePath ) => ts . sys . readFile ( filePath ) ;
const configPath = ts . findConfigFile ( repoRoot , fileExists , "tsconfig.json" ) ;
if ( configPath ) {
const configFile = ts . readConfigFile ( configPath , readFile ) ;
if ( ! configFile . error ) {
const parsedConfig = ts . parseJsonConfigFileContent (
configFile . config ,
ts . sys ,
path . dirname ( configPath ) ,
MODULE _RESOLUTION _OPTIONS ,
configPath ,
) ;
const options = {
... MODULE _RESOLUTION _OPTIONS ,
... parsedConfig . options ,
} ;
context = {
options ,
host : ts . createCompilerHost ( options , true ) ,
} ;
}
}
}
moduleResolutionContextCache . set ( cacheKey , context ) ;
return context ;
}
2026-03-27 20:16:07 +00:00
function resolveFacadeSourceExportKinds ( repoRoot , sourcePath ) {
const cacheKey = ` ${ repoRoot } :: ${ sourcePath } ` ;
const cached = sourceExportKindsCache . get ( cacheKey ) ;
if ( cached ) {
return cached ;
}
const sourceTsPath = resolveFacadeSourceTypescriptPath ( repoRoot , sourcePath ) ;
if ( ! sourceTsPath ) {
const empty = new Map ( ) ;
sourceExportKindsCache . set ( cacheKey , empty ) ;
return empty ;
}
2026-03-31 20:59:54 +01:00
const moduleResolutionContext = resolveFacadeModuleResolutionContext ( repoRoot ) ;
2026-03-27 20:16:07 +00:00
const program = ts . createProgram (
[ sourceTsPath ] ,
2026-03-31 20:59:54 +01:00
moduleResolutionContext . options ,
moduleResolutionContext . host ,
2026-03-27 20:16:07 +00:00
) ;
const sourceFile = program . getSourceFile ( sourceTsPath ) ;
if ( ! sourceFile ) {
const empty = new Map ( ) ;
sourceExportKindsCache . set ( cacheKey , empty ) ;
return empty ;
}
const checker = program . getTypeChecker ( ) ;
const moduleSymbol = checker . getSymbolAtLocation ( sourceFile ) ? ? sourceFile . symbol ;
const exportKinds = new Map ( ) ;
if ( moduleSymbol ) {
for ( const exported of checker . getExportsOfModule ( moduleSymbol ) ) {
const symbol =
exported . flags & ts . SymbolFlags . Alias ? checker . getAliasedSymbol ( exported ) : exported ;
const flags = symbol . flags ;
2026-03-29 09:08:06 +01:00
const declaration =
symbol . valueDeclaration ? ? exported . valueDeclaration ? ? exported . declarations ? . [ 0 ] ;
const typeAtLocation = declaration
? checker . getTypeOfSymbolAtLocation ( symbol , declaration )
: checker . getDeclaredTypeOfSymbol ( symbol ) ;
2026-03-27 20:16:07 +00:00
exportKinds . set ( exported . getName ( ) , {
type : Boolean ( flags & ts . SymbolFlags . Type ) ,
value : Boolean ( flags & ts . SymbolFlags . Value ) ,
2026-03-29 09:08:06 +01:00
functionLike : Boolean ( flags & ( ts . SymbolFlags . Function | ts . SymbolFlags . Method ) ) ,
callable : typeAtLocation . getCallSignatures ( ) . length > 0 ,
arrayLike : isArrayTypeLike ( checker , typeAtLocation ) ,
primitiveLike : isPrimitiveTypeLike ( typeAtLocation ) ,
2026-03-27 20:16:07 +00:00
} ) ;
}
}
sourceExportKindsCache . set ( cacheKey , exportKinds ) ;
return exportKinds ;
}
export function buildPluginSdkFacadeModule ( entry , params = { } ) {
2026-03-29 09:08:06 +01:00
const sourceExportKinds = params . repoRoot
? resolveFacadeSourceExportKinds ( params . repoRoot , entry . source )
: new Map ( ) ;
2026-04-01 04:51:36 +09:00
const explicitFunctionExports = new Set ( entry . functionExports ? ? [ ] ) ;
2026-04-02 11:43:02 +09:00
const directExportSources = entry . directExports ? ? { } ;
2026-03-29 09:08:06 +01:00
const exportNames = entry . exportAll
? Array . from ( sourceExportKinds . keys ( ) ) . toSorted ( ( left , right ) => left . localeCompare ( right ) )
: entry . runtimeApiPreExportsPath
? collectRuntimeApiPreExports ( params . repoRoot , entry . runtimeApiPreExportsPath )
: entry . exports ;
2026-03-27 20:16:07 +00:00
const explicitTypeExports = new Set ( entry . typeExports ? ? [ ] ) ;
const valueExports = [ ] ;
const typeExports = [ ] ;
2026-03-29 09:08:06 +01:00
const valueExportsBySource = new Map ( ) ;
let needsLazyArrayHelper = false ;
let needsLazyObjectHelper = false ;
2026-03-27 20:16:07 +00:00
for ( const exportName of exportNames ? ? [ ] ) {
if ( explicitTypeExports . has ( exportName ) ) {
continue ;
}
2026-04-02 11:43:02 +09:00
if ( directExportSources [ exportName ] ) {
valueExports . push ( exportName ) ;
continue ;
}
2026-03-29 09:08:06 +01:00
const kind = sourceExportKinds . get ( exportName ) ;
2026-03-27 20:16:07 +00:00
if ( kind ? . type && ! kind . value ) {
typeExports . push ( exportName ) ;
continue ;
}
valueExports . push ( exportName ) ;
2026-03-29 09:08:06 +01:00
if ( kind ? . arrayLike ) {
needsLazyArrayHelper = true ;
} else if ( ! kind ? . functionLike && ! kind ? . callable && ! kind ? . primitiveLike ) {
needsLazyObjectHelper = true ;
}
const sourcePath = entry . exportSources ? . [ exportName ] ? ? entry . source ;
const exportsForSource = valueExportsBySource . get ( sourcePath ) ? ? [ ] ;
exportsForSource . push ( exportName ) ;
valueExportsBySource . set ( sourcePath , exportsForSource ) ;
2026-03-27 20:16:07 +00:00
}
for ( const typeExport of entry . typeExports ? ? [ ] ) {
if ( ! typeExports . includes ( typeExport ) ) {
typeExports . push ( typeExport ) ;
}
}
2026-04-02 09:31:47 +01:00
const nonDirectValueExports = valueExports . filter (
( exportName ) => ! directExportSources [ exportName ] ,
) ;
2026-03-27 20:16:07 +00:00
const lines = [ ` // Generated by ${ GENERATED _PLUGIN _SDK _FACADES _SCRIPT } . Do not edit manually. ` ] ;
2026-04-02 09:31:47 +01:00
if ( nonDirectValueExports . length || typeExports . length ) {
2026-03-29 09:08:06 +01:00
lines . push (
'import type { PluginSdkFacadeTypeMap } from "../generated/plugin-sdk-facade-type-map.generated.js";' ,
) ;
lines . push ( ` type FacadeEntry = PluginSdkFacadeTypeMap[ ${ JSON . stringify ( entry . subpath ) } ]; ` ) ;
lines . push ( 'type FacadeModule = FacadeEntry["module"];' ) ;
for ( const [ sourceIndex ] of listFacadeEntrySourcePaths ( entry ) . entries ( ) ) {
if ( sourceIndex === 0 ) {
continue ;
}
lines . push (
` type FacadeModule ${ sourceIndex + 1 } = FacadeEntry["sourceModules"][ ${ JSON . stringify ( buildFacadeSourceModuleKey ( sourceIndex ) ) } ]["module"]; ` ,
) ;
}
}
2026-04-02 11:43:02 +09:00
const directExportsBySource = new Map ( ) ;
for ( const exportName of valueExports ) {
const sourcePath = directExportSources [ exportName ] ;
if ( ! sourcePath ) {
continue ;
}
const exportsForSource = directExportsBySource . get ( sourcePath ) ? ? [ ] ;
exportsForSource . push ( exportName ) ;
directExportsBySource . set ( sourcePath , exportsForSource ) ;
}
if ( directExportsBySource . size > 0 ) {
for ( const [ sourcePath , exportNamesForSource ] of [ ... directExportsBySource . entries ( ) ] . toSorted (
( [ left ] , [ right ] ) => left . localeCompare ( right ) ,
) ) {
lines . push (
` export { ${ exportNamesForSource . toSorted ( ( left , right ) => left . localeCompare ( right ) ) . join ( ", " ) } } from ${ JSON . stringify ( sourcePath ) } ; ` ,
) ;
}
}
2026-04-02 09:31:47 +01:00
if ( nonDirectValueExports . length ) {
2026-04-02 14:37:12 +09:00
const runtimeImports = new Set ( ) ;
2026-03-29 09:08:06 +01:00
if ( needsLazyArrayHelper ) {
2026-04-02 14:37:12 +09:00
runtimeImports . add ( "createLazyFacadeArrayValue" ) ;
2026-03-29 09:08:06 +01:00
}
if ( needsLazyObjectHelper ) {
2026-04-02 14:37:12 +09:00
runtimeImports . add ( "createLazyFacadeObjectValue" ) ;
2026-03-29 09:08:06 +01:00
}
2026-04-02 14:37:12 +09:00
for ( const sourcePath of listFacadeEntrySourcePaths ( entry ) ) {
const loadPolicy = resolveFacadeLoadPolicy ( entry , sourcePath ) ;
runtimeImports . add (
loadPolicy === "activated"
? "loadActivatedBundledPluginPublicSurfaceModuleSync"
: "loadBundledPluginPublicSurfaceModuleSync" ,
) ;
}
lines . push (
` import { ${ [ ... runtimeImports ] . toSorted ( ( left , right ) => left . localeCompare ( right ) ) . join ( ", " ) } } from "./facade-runtime.js"; ` ,
) ;
2026-03-29 09:08:06 +01:00
for ( const [ sourceIndex , sourcePath ] of listFacadeEntrySourcePaths ( entry ) . entries ( ) ) {
if ( ! valueExportsBySource . has ( sourcePath ) ) {
continue ;
}
const { dirName : sourceDirName , artifactBasename : sourceArtifactBasename } =
normalizeFacadeSourceParts ( sourcePath ) ;
2026-04-02 14:37:12 +09:00
const loadPolicy = resolveFacadeLoadPolicy ( entry , sourcePath ) ;
const loaderName =
loadPolicy === "activated"
? "loadActivatedBundledPluginPublicSurfaceModuleSync"
: "loadBundledPluginPublicSurfaceModuleSync" ;
2026-03-29 09:08:06 +01:00
const loaderSuffix = sourceIndex === 0 ? "" : String ( sourceIndex + 1 ) ;
const moduleTypeName = sourceIndex === 0 ? "FacadeModule" : ` FacadeModule ${ sourceIndex + 1 } ` ;
lines . push ( "" ) ;
lines . push ( ` function loadFacadeModule ${ loaderSuffix } (): ${ moduleTypeName } { ` ) ;
2026-04-02 14:37:12 +09:00
lines . push ( ` return ${ loaderName } < ${ moduleTypeName } >({ ` ) ;
2026-03-29 09:08:06 +01:00
lines . push ( ` dirName: ${ JSON . stringify ( sourceDirName ) } , ` ) ;
lines . push ( ` artifactBasename: ${ JSON . stringify ( sourceArtifactBasename ) } , ` ) ;
lines . push ( " });" ) ;
lines . push ( "}" ) ;
}
}
2026-04-02 09:31:47 +01:00
if ( nonDirectValueExports . length ) {
2026-03-29 09:08:06 +01:00
const sourceIndexByPath = new Map (
listFacadeEntrySourcePaths ( entry ) . map ( ( sourcePath , index ) => [ sourcePath , index ] ) ,
) ;
2026-04-02 09:31:47 +01:00
for ( const exportName of nonDirectValueExports ) {
2026-04-02 11:43:02 +09:00
if ( directExportSources [ exportName ] ) {
continue ;
}
2026-03-29 09:08:06 +01:00
const kind = sourceExportKinds . get ( exportName ) ;
2026-04-01 04:51:36 +09:00
const isExplicitFunctionExport = explicitFunctionExports . has ( exportName ) ;
2026-03-29 09:08:06 +01:00
const sourcePath = entry . exportSources ? . [ exportName ] ? ? entry . source ;
const sourceIndex = sourceIndexByPath . get ( sourcePath ) ? ? 0 ;
const loaderSuffix = sourceIndex === 0 ? "" : String ( sourceIndex + 1 ) ;
const moduleTypeName = sourceIndex === 0 ? "FacadeModule" : ` FacadeModule ${ sourceIndex + 1 } ` ;
2026-04-01 04:51:36 +09:00
if ( isExplicitFunctionExport || kind ? . functionLike || kind ? . callable ) {
2026-03-29 09:08:06 +01:00
lines . push (
` export const ${ exportName } : ${ moduleTypeName } [ ${ JSON . stringify ( exportName ) } ] = ((...args) => ` ,
) ;
lines . push (
` loadFacadeModule ${ loaderSuffix } ()[ ${ JSON . stringify ( exportName ) } ](...args)) as ${ moduleTypeName } [ ${ JSON . stringify ( exportName ) } ]; ` ,
) ;
continue ;
}
if ( kind ? . arrayLike ) {
lines . push (
` export const ${ exportName } : ${ moduleTypeName } [ ${ JSON . stringify ( exportName ) } ] = createLazyFacadeArrayValue(() => loadFacadeModule ${ loaderSuffix } ()[ ${ JSON . stringify ( exportName ) } ] as unknown as readonly unknown[]) as ${ moduleTypeName } [ ${ JSON . stringify ( exportName ) } ]; ` ,
) ;
continue ;
}
if ( ! kind ? . primitiveLike ) {
lines . push (
` export const ${ exportName } : ${ moduleTypeName } [ ${ JSON . stringify ( exportName ) } ] = createLazyFacadeObjectValue(() => loadFacadeModule ${ loaderSuffix } ()[ ${ JSON . stringify ( exportName ) } ] as object) as ${ moduleTypeName } [ ${ JSON . stringify ( exportName ) } ]; ` ,
) ;
continue ;
}
lines . push (
` export const ${ exportName } : ${ moduleTypeName } [ ${ JSON . stringify ( exportName ) } ] = loadFacadeModule ${ loaderSuffix } ()[ ${ JSON . stringify ( exportName ) } ]; ` ,
) ;
}
2026-03-27 20:16:07 +00:00
}
if ( typeExports . length ) {
2026-03-29 09:08:06 +01:00
for ( const exportedType of typeExports ) {
lines . push (
` export type ${ exportedType } = FacadeEntry["types"][ ${ JSON . stringify ( exportedType ) } ]; ` ,
) ;
}
}
lines . push ( "" ) ;
return lines . join ( "\n" ) ;
}
export function buildPluginSdkFacadeTypeMapModule ( entries ) {
const lines = [ ` // Generated by ${ GENERATED _PLUGIN _SDK _FACADES _SCRIPT } . Do not edit manually. ` ] ;
lines . push ( "export interface PluginSdkFacadeTypeMap {" ) ;
for ( const entry of entries ) {
const moduleImportPath = rewriteFacadeTypeImportSpecifier ( entry . source ) ;
lines . push ( ` ${ JSON . stringify ( entry . subpath ) } : { ` ) ;
lines . push ( ` module: typeof import( ${ JSON . stringify ( moduleImportPath ) } ); ` ) ;
lines . push ( " sourceModules: {" ) ;
for ( const [ sourceIndex , sourcePath ] of listFacadeEntrySourcePaths ( entry ) . entries ( ) ) {
const rewrittenSourcePath = rewriteFacadeTypeImportSpecifier ( sourcePath ) ;
lines . push ( ` ${ JSON . stringify ( buildFacadeSourceModuleKey ( sourceIndex ) ) } : { ` ) ;
lines . push ( ` module: typeof import( ${ JSON . stringify ( rewrittenSourcePath ) } ); ` ) ;
lines . push ( " };" ) ;
}
lines . push ( " };" ) ;
lines . push ( " types: {" ) ;
for ( const exportedType of entry . typeExports ? ? [ ] ) {
const typeImportPath = rewriteFacadeTypeImportSpecifier ( entry . source ) ;
lines . push (
` ${ JSON . stringify ( exportedType ) } : import( ${ JSON . stringify ( typeImportPath ) } ). ${ exportedType } ; ` ,
) ;
}
lines . push ( " };" ) ;
lines . push ( " };" ) ;
2026-03-27 20:16:07 +00:00
}
2026-03-29 09:08:06 +01:00
lines . push ( "}" ) ;
2026-03-27 20:16:07 +00:00
lines . push ( "" ) ;
return lines . join ( "\n" ) ;
}