diff --git a/src/plugin-sdk/channel-entry-contract.test.ts b/src/plugin-sdk/channel-entry-contract.test.ts index 25b7137c67b..ee2faf02c7f 100644 --- a/src/plugin-sdk/channel-entry-contract.test.ts +++ b/src/plugin-sdk/channel-entry-contract.test.ts @@ -84,50 +84,4 @@ describe("loadBundledEntryExportSync", () => { platformSpy.mockRestore(); } }); - - it("falls back from src setup and secret specifiers to packaged public artifacts", () => { - const tempRoot = fs.mkdtempSync(path.join(os.tmpdir(), "openclaw-channel-entry-contract-")); - tempDirs.push(tempRoot); - - const pluginRoot = path.join(tempRoot, "dist", "extensions", "telegram"); - fs.mkdirSync(pluginRoot, { recursive: true }); - - const importerPath = path.join(pluginRoot, "setup-entry.js"); - const channelPluginApiPath = path.join(pluginRoot, "channel-plugin-api.js"); - const secretContractApiPath = path.join(pluginRoot, "secret-contract-api.js"); - fs.writeFileSync(importerPath, "export default {};\n", "utf8"); - fs.writeFileSync( - channelPluginApiPath, - "export const telegramSetupPlugin = { id: 'telegram-setup' };\n", - "utf8", - ); - fs.writeFileSync( - secretContractApiPath, - [ - "export const secretTargetRegistryEntries = ['botToken'];", - "export function collectRuntimeConfigAssignments() { return undefined; }", - ].join("\n"), - "utf8", - ); - - expect( - loadBundledEntryExportSync<{ id: string }>(pathToFileURL(importerPath).href, { - specifier: "./src/channel.setup.js", - exportName: "telegramSetupPlugin", - }), - ).toEqual({ id: "telegram-setup" }); - - expect( - loadBundledEntryExportSync<{ - secretTargetRegistryEntries: string[]; - collectRuntimeConfigAssignments: () => undefined; - }>(pathToFileURL(importerPath).href, { - specifier: "./src/secret-contract.js", - exportName: "channelSecrets", - }), - ).toMatchObject({ - secretTargetRegistryEntries: ["botToken"], - collectRuntimeConfigAssignments: expect.any(Function), - }); - }); }); diff --git a/src/plugin-sdk/channel-entry-contract.ts b/src/plugin-sdk/channel-entry-contract.ts index 4bc24713fad..8e4323f2667 100644 --- a/src/plugin-sdk/channel-entry-contract.ts +++ b/src/plugin-sdk/channel-entry-contract.ts @@ -106,30 +106,6 @@ function addBundledEntryCandidates( } } -function resolveBundledEntryFallbackSpecifiers(specifier: string): string[] { - const sourceRelativeSpecifier = specifier.replace(/^\.\/src\//u, "./"); - const fallbackSpecifiers: string[] = []; - if (sourceRelativeSpecifier !== specifier) { - fallbackSpecifiers.push(sourceRelativeSpecifier); - } - - switch (sourceRelativeSpecifier) { - case "./channel.js": - fallbackSpecifiers.push("./channel-plugin-api.js", "./api.js"); - break; - case "./channel.setup.js": - fallbackSpecifiers.push("./setup-plugin-api.js", "./channel-plugin-api.js", "./api.js"); - break; - case "./secret-contract.js": - fallbackSpecifiers.push("./secret-contract-api.js", "./contract-api.js", "./api.js"); - break; - default: - break; - } - - return [...new Set(fallbackSpecifiers)]; -} - function resolveBundledEntryModuleCandidates( importMetaUrl: string, specifier: string, @@ -141,10 +117,11 @@ function resolveBundledEntryModuleCandidates( const primaryResolved = path.resolve(importerDir, specifier); addBundledEntryCandidates(candidates, primaryResolved, boundaryRoot); - for (const fallbackSpecifier of resolveBundledEntryFallbackSpecifiers(specifier)) { + const sourceRelativeSpecifier = specifier.replace(/^\.\/src\//u, "./"); + if (sourceRelativeSpecifier !== specifier) { addBundledEntryCandidates( candidates, - path.resolve(importerDir, fallbackSpecifier), + path.resolve(importerDir, sourceRelativeSpecifier), boundaryRoot, ); } @@ -175,33 +152,16 @@ function resolveBundledEntryModuleCandidates( path.resolve(sourcePluginRoot, specifier), sourcePluginRoot, ); - for (const fallbackSpecifier of resolveBundledEntryFallbackSpecifiers(specifier)) { + if (sourceRelativeSpecifier !== specifier) { addBundledEntryCandidates( candidates, - path.resolve(sourcePluginRoot, fallbackSpecifier), + path.resolve(sourcePluginRoot, sourceRelativeSpecifier), sourcePluginRoot, ); } return candidates; } -function resolveBundledEntryCompatExport( - loaded: unknown, - reference: BundledEntryModuleRef, -): T | undefined { - if (reference.exportName !== "channelSecrets" || !loaded || typeof loaded !== "object") { - return undefined; - } - const record = loaded as Record; - if ("collectRuntimeConfigAssignments" in record && "secretTargetRegistryEntries" in record) { - return { - collectRuntimeConfigAssignments: record.collectRuntimeConfigAssignments, - secretTargetRegistryEntries: record.secretTargetRegistryEntries, - } as T; - } - return undefined; -} - function formatBundledEntryUnknownError(error: unknown): string { if (typeof error === "string") { return error; @@ -348,10 +308,6 @@ export function loadBundledEntryExportSync( } const record = (resolved ?? loaded) as Record | undefined; if (!record || !(reference.exportName in record)) { - const compatResolved = resolveBundledEntryCompatExport(record ?? loaded, reference); - if (compatResolved !== undefined) { - return compatResolved; - } throw new Error( `missing export "${reference.exportName}" from bundled entry module ${reference.specifier}`, );