page-action-cache 2.0.8 → 2026.2.0
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/README.md +100 -306
- package/openclaw.plugin.json +23 -14
- package/package.json +28 -21
- package/dist/browser-action-executor.d.ts +0 -87
- package/dist/browser-action-executor.d.ts.map +0 -1
- package/dist/browser-action-executor.js +0 -283
- package/dist/browser-action-executor.js.map +0 -1
- package/dist/cache-invalidation.d.ts +0 -128
- package/dist/cache-invalidation.d.ts.map +0 -1
- package/dist/cache-invalidation.js +0 -262
- package/dist/cache-invalidation.js.map +0 -1
- package/dist/cache-manager.d.ts +0 -83
- package/dist/cache-manager.d.ts.map +0 -1
- package/dist/cache-manager.js +0 -184
- package/dist/cache-manager.js.map +0 -1
- package/dist/index.d.ts +0 -10
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -48
- package/dist/index.js.map +0 -1
- package/dist/multi-level-cache.d.ts +0 -127
- package/dist/multi-level-cache.d.ts.map +0 -1
- package/dist/multi-level-cache.js +0 -362
- package/dist/multi-level-cache.js.map +0 -1
- package/dist/scenario-recognizer.d.ts +0 -35
- package/dist/scenario-recognizer.d.ts.map +0 -1
- package/dist/scenario-recognizer.js +0 -93
- package/dist/scenario-recognizer.js.map +0 -1
- package/dist/types.d.ts +0 -62
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js +0 -6
- package/dist/types.js.map +0 -1
- package/dist/variable-extractor.d.ts +0 -56
- package/dist/variable-extractor.d.ts.map +0 -1
- package/dist/variable-extractor.js +0 -159
- package/dist/variable-extractor.js.map +0 -1
- package/src/browser-action-executor.ts +0 -337
- package/src/cache-invalidation.ts +0 -338
- package/src/cache-manager.ts +0 -211
- package/src/index.ts +0 -58
- package/src/multi-level-cache.ts +0 -478
- package/src/scenario-recognizer.ts +0 -121
- package/src/types-mock.d.ts +0 -18
- package/src/types.ts +0 -66
- package/src/variable-extractor.ts +0 -204
|
@@ -1,204 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Variable Extractor - Page Action Cache
|
|
3
|
-
* 变量提取器 - 从用户输入中提取动态变量
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* 变量匹配规则
|
|
8
|
-
*/
|
|
9
|
-
interface VariableRule {
|
|
10
|
-
name: string;
|
|
11
|
-
pattern: RegExp;
|
|
12
|
-
description: string;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* 常见变量规则
|
|
17
|
-
*/
|
|
18
|
-
const VARIABLE_RULES: VariableRule[] = [
|
|
19
|
-
{
|
|
20
|
-
name: 'email',
|
|
21
|
-
pattern: /([a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,})/g,
|
|
22
|
-
description: '电子邮件地址'
|
|
23
|
-
},
|
|
24
|
-
{
|
|
25
|
-
name: 'phone',
|
|
26
|
-
pattern: /(\d{11}|\d{3}[-.\s]?\d{4}[-.\s]?\d{4}|\+?[\d\s-]{10,})/g,
|
|
27
|
-
description: '电话号码'
|
|
28
|
-
},
|
|
29
|
-
{
|
|
30
|
-
name: 'date',
|
|
31
|
-
pattern: /(\d{4}[-/年]\d{1,2}[-/月]\d{1,2}日?|\d{1,2}[-/]\d{1,2}[-/]\d{4})/g,
|
|
32
|
-
description: '日期'
|
|
33
|
-
},
|
|
34
|
-
{
|
|
35
|
-
name: 'time',
|
|
36
|
-
pattern: /(\d{1,2}:\d{2}(:\d{2})?)/g,
|
|
37
|
-
description: '时间'
|
|
38
|
-
},
|
|
39
|
-
{
|
|
40
|
-
name: 'number',
|
|
41
|
-
pattern: /(\d+(?:,\d{3})*(?:\.\d+)?)/g,
|
|
42
|
-
description: '数字'
|
|
43
|
-
},
|
|
44
|
-
{
|
|
45
|
-
name: 'url',
|
|
46
|
-
pattern: /(https?:\/\/[^\s<>"]+|www\.[^\s<>"]+)/g,
|
|
47
|
-
description: '网址'
|
|
48
|
-
},
|
|
49
|
-
{
|
|
50
|
-
name: 'amount',
|
|
51
|
-
pattern: /(?:¥|\$|¥|€|£)?\s*(\d+(?:,\d{3})*(?:\.\d{2})?)\s*(?:元|dollars?|euros?|pounds?)?/gi,
|
|
52
|
-
description: '金额'
|
|
53
|
-
},
|
|
54
|
-
{
|
|
55
|
-
name: 'username',
|
|
56
|
-
pattern: /(?:用户名|username|user|account)\s*[::]?\s*([^\s,,]+)/gi,
|
|
57
|
-
description: '用户名'
|
|
58
|
-
},
|
|
59
|
-
{
|
|
60
|
-
name: 'password',
|
|
61
|
-
pattern: /(?:密码|password|pwd)\s*[::]?\s*([^\s,,]+)/gi,
|
|
62
|
-
description: '密码'
|
|
63
|
-
},
|
|
64
|
-
{
|
|
65
|
-
name: 'product_name',
|
|
66
|
-
pattern: /(?:商品|产品|product|item)\s*[::]?\s*([^\n,,]+)/gi,
|
|
67
|
-
description: '商品名称'
|
|
68
|
-
}
|
|
69
|
-
];
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* 提取的变量
|
|
73
|
-
*/
|
|
74
|
-
export interface ExtractedVariable {
|
|
75
|
-
name: string;
|
|
76
|
-
value: string;
|
|
77
|
-
description: string;
|
|
78
|
-
confidence: number;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* 变量提取结果
|
|
83
|
-
*/
|
|
84
|
-
export interface ExtractionResult {
|
|
85
|
-
variables: ExtractedVariable[];
|
|
86
|
-
rawText: string;
|
|
87
|
-
confidence: number;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* 变量提取器
|
|
92
|
-
*/
|
|
93
|
-
export class VariableExtractor {
|
|
94
|
-
private customRules: VariableRule[] = [];
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
* 从文本中提取变量
|
|
98
|
-
*/
|
|
99
|
-
extract(text: string): ExtractionResult {
|
|
100
|
-
const variables: ExtractedVariable[] = [];
|
|
101
|
-
const seenValues = new Set<string>();
|
|
102
|
-
|
|
103
|
-
// 应用内置规则
|
|
104
|
-
for (const rule of [...VARIABLE_RULES, ...this.customRules]) {
|
|
105
|
-
const matches = text.matchAll(rule.pattern);
|
|
106
|
-
|
|
107
|
-
for (const match of matches) {
|
|
108
|
-
const value = match[1] || match[0];
|
|
109
|
-
|
|
110
|
-
// 避免重复提取相同值
|
|
111
|
-
const key = `${rule.name}:${value}`;
|
|
112
|
-
if (seenValues.has(key)) {
|
|
113
|
-
continue;
|
|
114
|
-
}
|
|
115
|
-
seenValues.add(key);
|
|
116
|
-
|
|
117
|
-
variables.push({
|
|
118
|
-
name: rule.name,
|
|
119
|
-
value: value.trim(),
|
|
120
|
-
description: rule.description,
|
|
121
|
-
confidence: this.calculateConfidence(text, rule.pattern)
|
|
122
|
-
});
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
return {
|
|
127
|
-
variables,
|
|
128
|
-
rawText: text,
|
|
129
|
-
confidence: this.calculateOverallConfidence(variables)
|
|
130
|
-
};
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
/**
|
|
134
|
-
* 计算单个变量的置信度
|
|
135
|
-
*/
|
|
136
|
-
private calculateConfidence(text: string, pattern: RegExp): number {
|
|
137
|
-
const matches = text.match(pattern);
|
|
138
|
-
if (!matches) return 0;
|
|
139
|
-
|
|
140
|
-
// 匹配次数越多,置信度越高
|
|
141
|
-
const matchCount = matches.length;
|
|
142
|
-
let confidence = Math.min(matchCount * 0.3, 1.0);
|
|
143
|
-
|
|
144
|
-
// 如果匹配的值周围有特定关键词,提高置信度
|
|
145
|
-
const contextKeywords = ['填写', '输入', '请输入', 'enter', 'fill in', 'please'];
|
|
146
|
-
for (const keyword of contextKeywords) {
|
|
147
|
-
if (text.toLowerCase().includes(keyword.toLowerCase())) {
|
|
148
|
-
confidence = Math.min(confidence + 0.2, 1.0);
|
|
149
|
-
break;
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
return confidence;
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
/**
|
|
157
|
-
* 计算整体置信度
|
|
158
|
-
*/
|
|
159
|
-
private calculateOverallConfidence(variables: ExtractedVariable[]): number {
|
|
160
|
-
if (variables.length === 0) return 0;
|
|
161
|
-
|
|
162
|
-
const avgConfidence = variables.reduce((sum, v) => sum + v.confidence, 0) / variables.length;
|
|
163
|
-
|
|
164
|
-
// 变量数量适中时置信度更高(避免过多或过少)
|
|
165
|
-
const countFactor = variables.length >= 2 && variables.length <= 5 ? 1.0 : 0.8;
|
|
166
|
-
|
|
167
|
-
return Math.min(avgConfidence * countFactor, 1.0);
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
/**
|
|
171
|
-
* 添加自定义变量规则
|
|
172
|
-
*/
|
|
173
|
-
addCustomRule(name: string, pattern: RegExp, description: string): void {
|
|
174
|
-
this.customRules.push({ name, pattern, description });
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
/**
|
|
178
|
-
* 获取变量替换模板
|
|
179
|
-
*/
|
|
180
|
-
getTemplate(variables: ExtractedVariable[]): string {
|
|
181
|
-
if (variables.length === 0) return '';
|
|
182
|
-
|
|
183
|
-
let template = '';
|
|
184
|
-
for (const v of variables) {
|
|
185
|
-
template += `${v.description}: {{${v.name}}}\n`;
|
|
186
|
-
}
|
|
187
|
-
return template.trim();
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
/**
|
|
191
|
-
* 验证变量值
|
|
192
|
-
*/
|
|
193
|
-
validate(variableName: string, value: string): boolean {
|
|
194
|
-
const rule = [...VARIABLE_RULES, ...this.customRules].find(r => r.name === variableName);
|
|
195
|
-
if (!rule) return false;
|
|
196
|
-
|
|
197
|
-
return rule.pattern.test(value);
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
/**
|
|
202
|
-
* 单例导出
|
|
203
|
-
*/
|
|
204
|
-
export const variableExtractor = new VariableExtractor();
|