page-action-cache 2026.3.3 → 2026.3.5

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.
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * Page Action Cache - OpenClaw Extension
3
- * 页面操作缓存扩展
3
+ * 页面操作缓存扩展 (最小版本)
4
4
  */
5
5
  interface OpenClawPluginApi {
6
6
  registerTool(tool: {
@@ -10,18 +10,9 @@ interface OpenClawPluginApi {
10
10
  execute: (params: unknown) => Promise<unknown>;
11
11
  }): void;
12
12
  }
13
- interface BeforeToolCallResult {
14
- params?: Record<string, unknown>;
15
- block?: boolean;
16
- blockReason?: string;
17
- }
18
13
  /**
19
14
  * 主扩展入口
20
15
  */
21
- export default function register(api: OpenClawPluginApi & {
22
- hooks?: {
23
- register: (hookName: string, handler: (event: unknown, ctx: unknown) => BeforeToolCallResult | void | Promise<BeforeToolCallResult | void>) => void;
24
- };
25
- }): void;
16
+ export default function register(_api: OpenClawPluginApi): void;
26
17
  export {};
27
18
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,UAAU,iBAAiB;IACzB,YAAY,CAAC,IAAI,EAAE;QACjB,IAAI,EAAE,MAAM,CAAC;QACb,WAAW,EAAE,MAAM,CAAC;QACpB,WAAW,EAAE,OAAO,CAAC;QACrB,OAAO,EAAE,CAAC,MAAM,EAAE,OAAO,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;KAChD,GAAG,IAAI,CAAC;CACV;AAGD,UAAU,oBAAoB;IAC5B,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACjC,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AA2DD;;GAEG;AACH,MAAM,CAAC,OAAO,UAAU,QAAQ,CAAC,GAAG,EAAE,iBAAiB,GAAG;IACxD,KAAK,CAAC,EAAE;QACN,QAAQ,EAAE,CACR,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,CAAC,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,OAAO,KAAK,oBAAoB,GAAG,IAAI,GAAG,OAAO,CAAC,oBAAoB,GAAG,IAAI,CAAC,KAC1G,IAAI,CAAC;KACX,CAAC;CACH,GAAG,IAAI,CAkOP"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,UAAU,iBAAiB;IACzB,YAAY,CAAC,IAAI,EAAE;QACjB,IAAI,EAAE,MAAM,CAAC;QACb,WAAW,EAAE,MAAM,CAAC;QACpB,WAAW,EAAE,OAAO,CAAC;QACrB,OAAO,EAAE,CAAC,MAAM,EAAE,OAAO,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;KAChD,GAAG,IAAI,CAAC;CACV;AAED;;GAEG;AACH,MAAM,CAAC,OAAO,UAAU,QAAQ,CAAC,IAAI,EAAE,iBAAiB,GAAG,IAAI,CAI9D"}
package/dist/index.js CHANGED
@@ -1,261 +1,12 @@
1
1
  /**
2
2
  * Page Action Cache - OpenClaw Extension
3
- * 页面操作缓存扩展
3
+ * 页面操作缓存扩展 (最小版本)
4
4
  */
5
- // 内存缓存(页面会话级别)
6
- const memoryCache = new Map();
7
- const MAX_CACHE_SIZE = 50;
8
- const CACHE_TTL_MS = 5 * 60 * 1000; // 5 分钟
9
- /**
10
- * 生成缓存键 (暂时禁用)
11
- */
12
- /*
13
- function getCacheKey(profile: string | undefined, targetId: string | undefined, url: string | undefined): string {
14
- const parts = [];
15
- if (profile) parts.push(profile);
16
- if (targetId) parts.push(targetId);
17
- if (url) parts.push(url);
18
- return parts.join(':');
19
- }
20
- */
21
- /**
22
- * 清理过期缓存
23
- */
24
- function cleanupExpiredCache() {
25
- const now = Date.now();
26
- let cleaned = 0;
27
- for (const [key, entry] of memoryCache.entries()) {
28
- if (now - entry.timestamp > CACHE_TTL_MS) {
29
- memoryCache.delete(key);
30
- cleaned++;
31
- }
32
- }
33
- // LRU 清理
34
- while (memoryCache.size > MAX_CACHE_SIZE) {
35
- const oldestKey = memoryCache.keys().next().value;
36
- if (oldestKey) {
37
- memoryCache.delete(oldestKey);
38
- cleaned++;
39
- }
40
- }
41
- return cleaned;
42
- }
43
5
  /**
44
6
  * 主扩展入口
45
7
  */
46
- export default function register(api) {
8
+ export default function register(_api) {
47
9
  console.log('[PageActionCache] Starting...');
48
- // 注册 hooks (暂时禁用以诊断问题)
49
- /*
50
- if (api.hooks) {
51
- // after_tool_call hook - cache snapshot metadata
52
- api.hooks.register('after_tool_call', async (event: unknown, _ctx: unknown) => {
53
- try {
54
- const hookEvent = event as { toolName: string; params: Record<string, unknown>; result?: unknown; error?: string };
55
-
56
- // Only process browser snapshot actions
57
- if (hookEvent.toolName !== 'browser') {
58
- return;
59
- }
60
-
61
- const params = hookEvent.params as { action?: string; profile?: string; targetId?: string; url?: string; refs?: "role" | "aria" };
62
- if (params.action !== 'snapshot') {
63
- return;
64
- }
65
-
66
- // Skip if there was an error
67
- if (hookEvent.error) {
68
- return;
69
- }
70
-
71
- // Extract metadata from result
72
- const result = hookEvent.result as { details?: { targetId?: string; url?: string; refs?: number } };
73
- if (!result?.details) {
74
- return;
75
- }
76
-
77
- const targetId = result.details.targetId || params.targetId;
78
- const url = result.details.url || params.url;
79
- const refsCount = result.details.refs;
80
-
81
- if (!targetId || !url) {
82
- return;
83
- }
84
-
85
- // Check if refs were collected
86
- const refs: "role" | "aria" | undefined = (params.refs === "role" || params.refs === "aria") ? params.refs : undefined;
87
-
88
- // Store in cache
89
- const cacheKey = getCacheKey(params.profile, targetId, url);
90
- const existingEntry = memoryCache.get(cacheKey);
91
-
92
- const entry: CacheEntry = {
93
- url,
94
- targetId,
95
- profile: params.profile,
96
- refs,
97
- refsData: refsCount && refsCount > 0 ? {} : undefined, // Would store actual refs if accessible
98
- timestamp: Date.now(),
99
- hitCount: existingEntry?.hitCount || 0
100
- };
101
-
102
- // Refresh insertion order for LRU
103
- if (existingEntry) {
104
- memoryCache.delete(cacheKey);
105
- }
106
- memoryCache.set(cacheKey, entry);
107
-
108
- // Cleanup if over limit
109
- if (memoryCache.size > MAX_CACHE_SIZE) {
110
- const oldestKey = memoryCache.keys().next().value;
111
- if (oldestKey) {
112
- memoryCache.delete(oldestKey);
113
- }
114
- }
115
-
116
- console.log('[PageActionCache] Cached snapshot:', cacheKey, 'refs:', refs, 'count:', refsCount);
117
- } catch (err) {
118
- console.error('[PageActionCache] Error in after_tool_call:', err);
119
- }
120
- });
121
-
122
- // before_tool_call hook - restore cached params
123
- api.hooks.register('before_tool_call', async (event: unknown, _ctx: unknown) => {
124
- try {
125
- const hookEvent = event as { toolName: string; params: Record<string, unknown> };
126
-
127
- // Only process browser actions
128
- if (hookEvent.toolName !== 'browser') {
129
- return undefined;
130
- }
131
-
132
- const params = hookEvent.params as { action?: string; profile?: string; targetId?: string; url?: string; refs?: "role" | "aria" };
133
- if (!params.action) {
134
- return undefined;
135
- }
136
-
137
- // Generate cache key
138
- const cacheKey = getCacheKey(params.profile, params.targetId, params.url);
139
- if (!cacheKey) {
140
- return undefined;
141
- }
142
-
143
- // Check cache
144
- const entry = memoryCache.get(cacheKey);
145
- if (!entry) {
146
- return undefined;
147
- }
148
-
149
- // Check if expired
150
- if (Date.now() - entry.timestamp > CACHE_TTL_MS) {
151
- memoryCache.delete(cacheKey);
152
- return undefined;
153
- }
154
-
155
- // Increment hit count and refresh LRU
156
- entry.hitCount++;
157
- memoryCache.delete(cacheKey);
158
- memoryCache.set(cacheKey, entry);
159
-
160
- // Build modified params
161
- const modifiedParams: Record<string, unknown> = {};
162
-
163
- // Add profile if cached and not in params
164
- if (entry.profile && !params.profile) {
165
- modifiedParams.profile = entry.profile;
166
- }
167
-
168
- // Add targetId if cached and not in params
169
- if (entry.targetId && !params.targetId) {
170
- modifiedParams.targetId = entry.targetId;
171
- }
172
-
173
- // Add refs if this is a snapshot action and we have cached refs
174
- if (params.action === 'snapshot' && entry.refs && !params.refs) {
175
- modifiedParams.refs = entry.refs;
176
- }
177
-
178
- // Only return if we have something to add
179
- if (Object.keys(modifiedParams).length > 0) {
180
- console.log('[PageActionCache] Cache hit:', cacheKey, 'modified params:', Object.keys(modifiedParams));
181
- return { params: modifiedParams };
182
- }
183
- } catch (err) {
184
- console.error('[PageActionCache] Error in before_tool_call:', err);
185
- }
186
- return undefined;
187
- });
188
-
189
- console.log('[PageActionCache] Hooks registered');
190
- } else {
191
- console.log('[PageActionCache] No hooks API available');
192
- }
193
- */
194
- // 注册缓存统计工具
195
- api.registerTool({
196
- name: 'page_cache_stats',
197
- description: 'View page snapshot cache statistics',
198
- inputSchema: {
199
- type: 'object',
200
- properties: {},
201
- required: []
202
- },
203
- async execute() {
204
- cleanupExpiredCache();
205
- const entries = Array.from(memoryCache.values());
206
- const profiles = new Set(entries.filter(e => e.profile).map(e => e.profile));
207
- const urls = new Set(entries.map(e => e.url));
208
- const stats = {
209
- totalEntries: memoryCache.size,
210
- uniqueProfiles: profiles.size,
211
- uniqueUrls: urls.size,
212
- hits: entries.reduce((sum, e) => sum + e.hitCount, 0),
213
- avgHitCount: memoryCache.size > 0
214
- ? entries.reduce((sum, e) => sum + e.hitCount, 0) / memoryCache.size
215
- : 0,
216
- oldestEntry: memoryCache.size > 0
217
- ? Math.min(...entries.map(e => e.timestamp))
218
- : null,
219
- newestEntry: memoryCache.size > 0
220
- ? Math.max(...entries.map(e => e.timestamp))
221
- : null
222
- };
223
- console.log('[PageActionCache] Stats:', JSON.stringify(stats));
224
- let report = `## Page Snapshot Cache Statistics\n\n`;
225
- report += `- Total Entries: ${stats.totalEntries}\n`;
226
- report += `- Unique Profiles: ${stats.uniqueProfiles}\n`;
227
- report += `- Unique URLs: ${stats.uniqueUrls}\n`;
228
- report += `- Total Hits: ${stats.hits}\n`;
229
- report += `- Avg Hits per Entry: ${stats.avgHitCount.toFixed(2)}\n`;
230
- report += `- Hit Rate: ${(stats.totalEntries > 0 ? (stats.hits / stats.totalEntries * 100).toFixed(2) : '0.00')}%\n`;
231
- if (profiles.size > 0) {
232
- report += `\n**Profiles:** ${Array.from(profiles).join(', ')}\n`;
233
- }
234
- return {
235
- text: report,
236
- stats
237
- };
238
- }
239
- });
240
- // 注册缓存清空工具
241
- api.registerTool({
242
- name: 'page_cache_clear',
243
- description: 'Clear page snapshot cache',
244
- inputSchema: {
245
- type: 'object',
246
- properties: {},
247
- required: []
248
- },
249
- async execute() {
250
- const count = memoryCache.size;
251
- memoryCache.clear();
252
- console.log('[PageActionCache] Cleared', count);
253
- return {
254
- text: `Cleared ${count} cache entries`,
255
- cleared: count
256
- };
257
- }
258
- });
259
10
  console.log('[PageActionCache] Registration complete');
260
11
  }
261
12
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAgCH,eAAe;AACf,MAAM,WAAW,GAAG,IAAI,GAAG,EAAsB,CAAC;AAClD,MAAM,cAAc,GAAG,EAAE,CAAC;AAC1B,MAAM,YAAY,GAAG,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC,OAAO;AAE3C;;GAEG;AACH;;;;;;;;EAQE;AAEF;;GAEG;AACH,SAAS,mBAAmB;IAC1B,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;IACvB,IAAI,OAAO,GAAG,CAAC,CAAC;IAEhB,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,WAAW,CAAC,OAAO,EAAE,EAAE,CAAC;QACjD,IAAI,GAAG,GAAG,KAAK,CAAC,SAAS,GAAG,YAAY,EAAE,CAAC;YACzC,WAAW,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;YACxB,OAAO,EAAE,C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"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAYH;;GAEG;AACH,MAAM,CAAC,OAAO,UAAU,QAAQ,CAAC,IAAuB;IACtD,OAAO,CAAC,GAAG,CAAC,+BAA+B,CAAC,CAAC;IAE7C,OAAO,CAAC,GAAG,CAAC,yCAAyC,CAAC,CAAC;AACzD,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "page-action-cache",
3
- "version": "2026.3.3",
3
+ "version": "2026.3.5",
4
4
  "description": "Page Action Cache - OpenClaw extension",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",