@@ -154,6 +154,32 @@ function writeWorkspacePackageEntry(params: {
154154 return { srcFile, distFile } ;
155155}
156156
157+ function writeWorkspacePackageExports (
158+ root : string ,
159+ packageDir : string ,
160+ subpaths : readonly string [ ] ,
161+ ) {
162+ mkdirSafeDir ( path . join ( root , "packages" , packageDir ) ) ;
163+ fs . writeFileSync (
164+ path . join ( root , "packages" , packageDir , "package.json" ) ,
165+ JSON . stringify (
166+ {
167+ name : `@openclaw/${ packageDir } ` ,
168+ exports : Object . fromEntries (
169+ subpaths . map ( ( subpath ) => {
170+ const exportKey = subpath ? `./${ subpath } ` : "." ;
171+ const distFile = `./dist/${ subpath || "index" } .mjs` ;
172+ return [ exportKey , { import : distFile , default : distFile } ] ;
173+ } ) ,
174+ ) ,
175+ } ,
176+ null ,
177+ 2 ,
178+ ) ,
179+ "utf-8" ,
180+ ) ;
181+ }
182+
157183type WorkspaceAliasFixture = readonly [
158184 alias : `@openclaw/${string } `,
159185 packageDir : string ,
@@ -1148,6 +1174,15 @@ describe("plugin sdk alias helpers", () => {
11481174
11491175 it ( "aliases workspace packages to source when dist artifacts are missing" , ( ) => {
11501176 const fixture = createPluginSdkAliasFixture ( ) ;
1177+ writeWorkspacePackageExports ( fixture . root , "media-core" , [ "" , "attachment-classify" , "mime" ] ) ;
1178+ writeWorkspacePackageExports ( fixture . root , "acp-core" , [ "" , "runtime/types" ] ) ;
1179+ writeWorkspacePackageExports ( fixture . root , "normalization-core" , [
1180+ "" ,
1181+ "agent-id" ,
1182+ "boolean-coercion" ,
1183+ "result" ,
1184+ "string-coerce" ,
1185+ ] ) ;
11511186 const workspaceAliases = writeWorkspaceAliasFixtures ( fixture . root , [
11521187 [ "@openclaw/gateway-client" , "gateway-client" , "index" ] ,
11531188 [ "@openclaw/gateway-client/timeouts" , "gateway-client" , "timeouts" ] ,
@@ -1160,6 +1195,7 @@ describe("plugin sdk alias helpers", () => {
11601195 [ "@openclaw/media-generation-core" , "media-generation-core" , "index" ] ,
11611196 [ "@openclaw/media-generation-core/model-ref" , "media-generation-core" , "model-ref" ] ,
11621197 [ "@openclaw/media-core" , "media-core" , "index" ] ,
1198+ [ "@openclaw/media-core/attachment-classify" , "media-core" , "attachment-classify" ] ,
11631199 [ "@openclaw/media-core/mime" , "media-core" , "mime" ] ,
11641200 [ "@openclaw/acp-core" , "acp-core" , "index" ] ,
11651201 [ "@openclaw/acp-core/runtime/types" , "acp-core" , "runtime/types" ] ,
@@ -1193,6 +1229,9 @@ describe("plugin sdk alias helpers", () => {
11931229
11941230 it ( "aliases workspace package subpaths to dist when available" , ( ) => {
11951231 const fixture = createPluginSdkAliasFixture ( ) ;
1232+ writeWorkspacePackageExports ( fixture . root , "media-core" , [ "attachment-classify" ] ) ;
1233+ writeWorkspacePackageExports ( fixture . root , "acp-core" , [ "normalize-text" ] ) ;
1234+ writeWorkspacePackageExports ( fixture . root , "normalization-core" , [ "record-coerce" ] ) ;
11961235 const workspaceAliases = writeWorkspaceAliasFixtures ( fixture . root , [
11971236 [ "@openclaw/gateway-client/readiness" , "gateway-client" , "readiness" ] ,
11981237 [
@@ -1203,6 +1242,7 @@ describe("plugin sdk alias helpers", () => {
12031242 [ "@openclaw/gateway-protocol/frame-guards" , "gateway-protocol" , "frame-guards" ] ,
12041243 [ "@openclaw/markdown-core/render" , "markdown-core" , "render" ] ,
12051244 [ "@openclaw/media-generation-core/catalog" , "media-generation-core" , "catalog" ] ,
1245+ [ "@openclaw/media-core/attachment-classify" , "media-core" , "attachment-classify" ] ,
12061246 [
12071247 "@openclaw/acp-core/normalize-text" ,
12081248 "acp-core" ,
@@ -1254,9 +1294,18 @@ describe("plugin sdk alias helpers", () => {
12541294 ) ;
12551295 mkdirSafeDir ( path . dirname ( normalizationAgentId ) ) ;
12561296 fs . writeFileSync ( normalizationAgentId , "export {};\n" , "utf-8" ) ;
1257- const cwdWithoutOpenClawPackage = makeTempDir ( ) ;
1297+ const mediaAttachmentClassify = path . join (
1298+ fixture . root ,
1299+ "dist" ,
1300+ "media-core" ,
1301+ "attachment-classify.js" ,
1302+ ) ;
1303+ mkdirSafeDir ( path . dirname ( mediaAttachmentClassify ) ) ;
1304+ fs . writeFileSync ( mediaAttachmentClassify , "export {};\n" , "utf-8" ) ;
1305+ const staleCheckout = createPluginSdkAliasFixture ( ) ;
1306+ writeWorkspacePackageExports ( staleCheckout . root , "media-core" , [ "mime" ] ) ;
12581307
1259- const aliases = withCwd ( cwdWithoutOpenClawPackage , ( ) =>
1308+ const aliases = withCwd ( staleCheckout . root , ( ) =>
12601309 withEnv ( { NODE_ENV : undefined } , ( ) =>
12611310 buildPluginLoaderAliasMap ( sourcePluginEntry , undefined , undefined , "dist" ) ,
12621311 ) ,
@@ -1268,6 +1317,9 @@ describe("plugin sdk alias helpers", () => {
12681317 expect ( fs . realpathSync ( aliases [ "@openclaw/normalization-core/agent-id" ] ?? "" ) ) . toBe (
12691318 fs . realpathSync ( normalizationAgentId ) ,
12701319 ) ;
1320+ expect ( fs . realpathSync ( aliases [ "@openclaw/media-core/attachment-classify" ] ?? "" ) ) . toBe (
1321+ fs . realpathSync ( mediaAttachmentClassify ) ,
1322+ ) ;
12711323 } ) ;
12721324
12731325 it ( "aliases bundled plugin package public surfaces for source plugin transforms" , ( ) => {
0 commit comments