@openclaw/diffs 2026.8.1-beta.2 → 2026.8.1-beta.3

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.
@@ -0,0 +1,118 @@
1
+ import crypto from "node:crypto";
2
+ import fs from "node:fs/promises";
3
+ import { fileURLToPath } from "node:url";
4
+ //#region extensions/diffs/src/viewer-assets.ts
5
+ const VIEWER_ASSET_PREFIX = "/plugins/diffs/assets/";
6
+ const VIEWER_LOADER_PATH = `${VIEWER_ASSET_PREFIX}viewer.js`;
7
+ const VIEWER_RUNTIME_PATH = `${VIEWER_ASSET_PREFIX}viewer-runtime.js`;
8
+ const LANGUAGE_PACK_VIEWER_ASSET_PREFIX = "/plugins/diffs-language-pack/assets/";
9
+ const LANGUAGE_PACK_VIEWER_LOADER_PATH = `${LANGUAGE_PACK_VIEWER_ASSET_PREFIX}viewer.js`;
10
+ const LANGUAGE_PACK_VIEWER_RUNTIME_PATH = `${LANGUAGE_PACK_VIEWER_ASSET_PREFIX}viewer-runtime.js`;
11
+ const VIEWER_RUNTIME_RELATIVE_IMPORT_PATH = "./viewer-runtime.js";
12
+ const VIEWER_RUNTIME_CANDIDATE_RELATIVE_PATHS = ["./assets/viewer-runtime.js", "../assets/viewer-runtime.js"];
13
+ const LANGUAGE_PACK_RUNTIME_CANDIDATE_RELATIVE_PATHS = ["../../diffs-language-pack/assets/viewer-runtime.js", "../diffs-language-pack/assets/viewer-runtime.js"];
14
+ let runtimeAssetCache = null;
15
+ let languagePackRuntimeAssetCache = null;
16
+ function isMissingFileError(error) {
17
+ return error instanceof Error && "code" in error && error.code === "ENOENT";
18
+ }
19
+ async function resolveViewerRuntimeFileUrl(params = {}) {
20
+ const baseUrl = params.baseUrl ?? import.meta.url;
21
+ const stat = params.stat ?? ((path) => fs.stat(path));
22
+ let missingFileError = null;
23
+ for (const relativePath of VIEWER_RUNTIME_CANDIDATE_RELATIVE_PATHS) {
24
+ const candidateUrl = new URL(relativePath, baseUrl);
25
+ try {
26
+ await stat(fileURLToPath(candidateUrl));
27
+ return candidateUrl;
28
+ } catch (error) {
29
+ if (isMissingFileError(error)) {
30
+ missingFileError = error;
31
+ continue;
32
+ }
33
+ throw error;
34
+ }
35
+ }
36
+ if (missingFileError) throw missingFileError;
37
+ throw new Error("viewer runtime asset candidates were not checked");
38
+ }
39
+ async function getServedViewerAsset(pathname) {
40
+ if (pathname !== VIEWER_LOADER_PATH && pathname !== VIEWER_RUNTIME_PATH) return null;
41
+ const assets = await loadViewerAssets();
42
+ if (pathname === VIEWER_LOADER_PATH) return {
43
+ body: assets.loaderBody,
44
+ contentType: "text/javascript; charset=utf-8"
45
+ };
46
+ if (pathname === VIEWER_RUNTIME_PATH) return {
47
+ body: assets.runtimeBody,
48
+ contentType: "text/javascript; charset=utf-8"
49
+ };
50
+ return null;
51
+ }
52
+ async function getServedLanguagePackViewerAsset(pathname) {
53
+ if (pathname !== LANGUAGE_PACK_VIEWER_LOADER_PATH && pathname !== LANGUAGE_PACK_VIEWER_RUNTIME_PATH) return null;
54
+ let assets;
55
+ try {
56
+ assets = await loadRuntimeAssets({
57
+ runtimeUrl: await resolveRuntimeFileUrl(LANGUAGE_PACK_RUNTIME_CANDIDATE_RELATIVE_PATHS),
58
+ cache: languagePackRuntimeAssetCache,
59
+ updateCache: (cache) => {
60
+ languagePackRuntimeAssetCache = cache;
61
+ }
62
+ });
63
+ } catch (error) {
64
+ if (isMissingFileError(error)) return null;
65
+ throw error;
66
+ }
67
+ if (pathname === LANGUAGE_PACK_VIEWER_LOADER_PATH) return {
68
+ body: assets.loaderBody,
69
+ contentType: "text/javascript; charset=utf-8"
70
+ };
71
+ return {
72
+ body: assets.runtimeBody,
73
+ contentType: "text/javascript; charset=utf-8"
74
+ };
75
+ }
76
+ async function loadViewerAssets() {
77
+ return loadRuntimeAssets({
78
+ runtimeUrl: await resolveViewerRuntimeFileUrl(),
79
+ cache: runtimeAssetCache,
80
+ updateCache: (cache) => {
81
+ runtimeAssetCache = cache;
82
+ }
83
+ });
84
+ }
85
+ async function loadRuntimeAssets(params) {
86
+ const runtimePath = fileURLToPath(params.runtimeUrl);
87
+ const runtimeStat = await fs.stat(runtimePath);
88
+ if (params.cache && params.cache.mtimeMs === runtimeStat.mtimeMs) return params.cache;
89
+ const runtimeBody = await fs.readFile(runtimePath);
90
+ const hash = crypto.createHash("sha1").update(runtimeBody).digest("hex").slice(0, 12);
91
+ const cache = {
92
+ mtimeMs: runtimeStat.mtimeMs,
93
+ runtimeBody,
94
+ loaderBody: `import "${VIEWER_RUNTIME_RELATIVE_IMPORT_PATH}?v=${hash}";\n`
95
+ };
96
+ params.updateCache(cache);
97
+ return cache;
98
+ }
99
+ async function resolveRuntimeFileUrl(relativePaths) {
100
+ let missingFileError = null;
101
+ for (const relativePath of relativePaths) {
102
+ const candidateUrl = new URL(relativePath, import.meta.url);
103
+ try {
104
+ await fs.stat(fileURLToPath(candidateUrl));
105
+ return candidateUrl;
106
+ } catch (error) {
107
+ if (isMissingFileError(error)) {
108
+ missingFileError = error;
109
+ continue;
110
+ }
111
+ throw error;
112
+ }
113
+ }
114
+ if (missingFileError) throw missingFileError;
115
+ throw new Error("viewer runtime asset candidates were not checked");
116
+ }
117
+ //#endregion
118
+ export { getServedViewerAsset as a, getServedLanguagePackViewerAsset as i, VIEWER_ASSET_PREFIX as n, VIEWER_RUNTIME_PATH as r, LANGUAGE_PACK_VIEWER_ASSET_PREFIX as t };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openclaw/diffs",
3
- "version": "2026.8.1-beta.2",
3
+ "version": "2026.8.1-beta.3",
4
4
  "description": "OpenClaw read-only diff viewer plugin and file renderer for agents.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -25,13 +25,13 @@
25
25
  "minHostVersion": ">=2026.4.30"
26
26
  },
27
27
  "compat": {
28
- "pluginApi": ">=2026.8.1-beta.2"
28
+ "pluginApi": ">=2026.8.1-beta.3"
29
29
  },
30
30
  "assetScripts": {
31
31
  "build": "node --import tsx ../../scripts/build-diffs-viewer-runtime.mts curated"
32
32
  },
33
33
  "build": {
34
- "openclawVersion": "2026.8.1-beta.2",
34
+ "openclawVersion": "2026.8.1-beta.3",
35
35
  "staticAssets": [
36
36
  {
37
37
  "source": "./assets/viewer-runtime.js",
@@ -54,7 +54,7 @@
54
54
  "skills/**"
55
55
  ],
56
56
  "peerDependencies": {
57
- "openclaw": ">=2026.8.1-beta.2"
57
+ "openclaw": ">=2026.8.1-beta.3"
58
58
  },
59
59
  "peerDependenciesMeta": {
60
60
  "openclaw": {