惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

小众软件
小众软件
博客园_首页
M
MIT News - Artificial intelligence
雷峰网
雷峰网
GbyAI
GbyAI
博客园 - 叶小钗
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
V
V2EX
S
SegmentFault 最新的问题
H
Help Net Security
Apple Machine Learning Research
Apple Machine Learning Research
H
Hackread – Cybersecurity News, Data Breaches, AI and More
博客园 - 【当耐特】
V
Visual Studio Blog
月光博客
月光博客
G
Google Developers Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
腾讯CDC
云风的 BLOG
云风的 BLOG
美团技术团队
Microsoft Azure Blog
Microsoft Azure Blog
A
About on SuperTechFans
有赞技术团队
有赞技术团队

Recent Commits to openclaw:main

test: merge chat side-result checks · openclaw/openclaw@ddd2c2a test: merge cron history checks · openclaw/openclaw@f7eb746 test: merge responsive navigation shell checks · openclaw/openclaw@c2e4b47 docs(changelog): add codex oauth fixes · openclaw/openclaw@628e6cd test: merge navigation routing cases · openclaw/openclaw@5d8cecb Tests: mock channel registry bundled fallback · openclaw/openclaw@2b08233 Secrets: avoid broad web search discovery for single plugin config · openclaw/openclaw@a464f59 test: merge config view browser checks · openclaw/openclaw@20cf511 fix(status): align oauth health with runtime · openclaw/openclaw@eed7116 feat: add macOS screen snapshots for monitor preview (#67954) thanks … · openclaw/openclaw@f377db1 fix: report shared auth scopes in hello-ok (#67810) thanks @BunsDev · openclaw/openclaw@0b6c39b Auto-reply: avoid eager bundled route fallback · openclaw/openclaw@3ea1bf4 Tests: narrow session binding contract setup · openclaw/openclaw@54e4e16 fix(macOS): enable undo/redo in webchat composer text input (#34962) · openclaw/openclaw@00951dc Tests: speed up channel setup promotion · openclaw/openclaw@82b529a Docs: refresh agent instructions · openclaw/openclaw@5775fe2 fix(auth): serialize OAuth refresh across agents to fix #26322 (#67876) · openclaw/openclaw@8e79080 test: allow ollama public surface boundary test · openclaw/openclaw@7d4f1a6 Docs: add test performance guardrails · openclaw/openclaw@89706d3 Tests: restore context-engine usage proof · openclaw/openclaw@e4c4f95 Tests: slim context engine runtime coverage · openclaw/openclaw@74c198f ci: retry failed custom checkouts · openclaw/openclaw@0ee5baf test: trim duplicate provider auth onboarding cases · openclaw/openclaw@1ffc02e matrix: fix sessions_spawn --thread subagent session spawning (#67643) · openclaw/openclaw@1ce2596 test: reduce auth choice fixture churn · openclaw/openclaw@857b9cd test: mock health status config boundaries · openclaw/openclaw@9d5ab4a test: mock onboard config io boundary · openclaw/openclaw@299694d test: mock legacy state plugin boundaries · openclaw/openclaw@2713089 test: mock channel install boundaries · openclaw/openclaw@b945248 test: mock doctor preview channel boundaries · openclaw/openclaw@b1a3ad4
perf: resolve native esm plugin sdk imports · openclaw/op...
steipete · 2026-05-30 · via Recent Commits to openclaw:main
1+

import { spawnSync } from "node:child_process";

12

import fs from "node:fs";

23

import { createRequire } from "node:module";

34

import os from "node:os";

45

import path from "node:path";

6+

import { pathToFileURL } from "node:url";

57

import { afterEach, describe, expect, it } from "vitest";

68

import {

79

installOpenClawPluginSdkNativeResolver,

@@ -122,6 +124,80 @@ describe("installOpenClawPluginSdkNativeResolver", () => {

122124

}

123125

});

124126127+

it("keeps SDK aliases available for native ESM lazy imports", () => {

128+

const root = fs.mkdtempSync(path.join(os.tmpdir(), "openclaw-sdk-native-esm-resolver-"));

129+

const probePath = path.join(root, "probe.mjs");

130+

const resolverModuleUrl = pathToFileURL(

131+

path.join(process.cwd(), "src", "plugins", "plugin-sdk-native-resolver.ts"),

132+

).href;

133+

fs.writeFileSync(

134+

probePath,

135+

[

136+

'import fs from "node:fs";',

137+

'import path from "node:path";',

138+

'import { pathToFileURL } from "node:url";',

139+

`import { installOpenClawPluginSdkNativeResolver, resetOpenClawPluginSdkNativeResolverForTest } from ${JSON.stringify(resolverModuleUrl)};`,

140+

`const root = ${JSON.stringify(root)};`,

141+

"const writeJson = (targetPath, value) => {",

142+

" fs.mkdirSync(path.dirname(targetPath), { recursive: true });",

143+

' fs.writeFileSync(targetPath, `${JSON.stringify(value, null, 2)}\\n`, "utf8");',

144+

"};",

145+

'writeJson(path.join(root, "package.json"), {',

146+

' name: "openclaw",',

147+

' type: "module",',

148+

' bin: { openclaw: "./openclaw.mjs" },',

149+

" exports: {",

150+

' "./plugin-sdk": "./dist/plugin-sdk/root-alias.cjs",',

151+

' "./plugin-sdk/channel-outbound": "./dist/plugin-sdk/channel-outbound.js",',

152+

" },",

153+

"});",

154+

'fs.writeFileSync(path.join(root, "openclaw.mjs"), "#!/usr/bin/env node\\n", "utf8");',

155+

'fs.mkdirSync(path.join(root, "dist", "plugin-sdk"), { recursive: true });',

156+

'fs.writeFileSync(path.join(root, "dist", "plugin-sdk", "root-alias.cjs"), "module.exports = {};\\n", "utf8");',

157+

'fs.writeFileSync(path.join(root, "dist", "plugin-sdk", "channel-outbound.js"), "export const defineChannelMessageAdapter = () => \\"adapter\\";\\n", "utf8");',

158+

'const loaderModulePath = path.join(root, "dist", "plugins", "loader.js");',

159+

"fs.mkdirSync(path.dirname(loaderModulePath), { recursive: true });",

160+

'fs.writeFileSync(loaderModulePath, "export default {};\\n", "utf8");',

161+

'const pluginRoot = path.join(root, "external-plugin");',

162+

'writeJson(path.join(pluginRoot, "package.json"), { name: "external-plugin", type: "module" });',

163+

'const entryPath = path.join(pluginRoot, "dist", "runtime-api.js");',

164+

'const lazyPath = path.join(pluginRoot, "dist", "lazy.js");',

165+

"fs.mkdirSync(path.dirname(entryPath), { recursive: true });",

166+

"fs.writeFileSync(",

167+

" entryPath,",

168+

' "import { defineChannelMessageAdapter } from \\"openclaw/plugin-sdk/channel-outbound\\"; export const eager = defineChannelMessageAdapter(); export const loadLazy = () => import(\\"./lazy.js\\");\\n",',

169+

' "utf8",',

170+

");",

171+

"fs.writeFileSync(",

172+

" lazyPath,",

173+

' "import { defineChannelMessageAdapter } from \\"openclaw/plugin-sdk/channel-outbound\\"; export const lazy = defineChannelMessageAdapter();\\n",',

174+

' "utf8",',

175+

");",

176+

"installOpenClawPluginSdkNativeResolver({",

177+

" modulePath: loaderModulePath,",

178+

" pluginModulePath: entryPath,",

179+

' pluginSdkResolution: "dist",',

180+

"});",

181+

"const module = await import(pathToFileURL(entryPath).href);",

182+

"const lazy = await module.loadLazy();",

183+

"resetOpenClawPluginSdkNativeResolverForTest();",

184+

"console.log(`${module.eager}:${lazy.lazy}`);",

185+

"",

186+

].join("\n"),

187+

"utf8",

188+

);

189+190+

const result = spawnSync(process.execPath, ["--import", "tsx", probePath], {

191+

cwd: process.cwd(),

192+

encoding: "utf8",

193+

});

194+

fs.rmSync(root, { recursive: true, force: true });

195+196+

expect(result.stderr).toBe("");

197+

expect(result.status).toBe(0);

198+

expect(result.stdout.trim()).toBe("adapter:adapter");

199+

});

200+125201

it("does not resolve SDK aliases for parents outside registered plugin roots", () => {

126202

const root = fs.mkdtempSync(path.join(os.tmpdir(), "openclaw-sdk-native-guard-"));

127203

const { loaderModulePath } = writeFakeOpenClawPackage(root);