@aipanel/dsh-plugin 1.2.4 → 1.2.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.js +75 -0
- package/package.json +2 -1
package/dist/index.js
CHANGED
|
@@ -15,6 +15,25 @@ var JS_EXTENSIONS = /* @__PURE__ */ new Set([
|
|
|
15
15
|
".vue"
|
|
16
16
|
]);
|
|
17
17
|
var MUTATING_TOOLS = /* @__PURE__ */ new Set(["write", "edit", "apply_patch"]);
|
|
18
|
+
var DEFAULT_CONTEXT_API_PATH = "/__aipanel_context__";
|
|
19
|
+
function collectNodeIds(text) {
|
|
20
|
+
const ids = [];
|
|
21
|
+
const re = new RegExp("@\u8282\u70B9\\[(n[0-9a-z]+)\\]", "g");
|
|
22
|
+
let m;
|
|
23
|
+
while ((m = re.exec(text)) !== null) ids.push(m[1]);
|
|
24
|
+
return ids;
|
|
25
|
+
}
|
|
26
|
+
function buildNodeContext(e) {
|
|
27
|
+
const lines = [`\u8282\u70B9 ID\uFF1A${e.id ?? ""}`];
|
|
28
|
+
if (e.filePath) lines.push(`\u6E90\u7801\u6587\u4EF6\u8DEF\u5F84\uFF1A${e.filePath}${e.line ? `:${e.line}` : ""}`);
|
|
29
|
+
if (e.line) lines.push(`\u4EE3\u7801\u6240\u5728\u884C\u53F7\uFF1A${e.line}`);
|
|
30
|
+
if (e.column) lines.push(`\u4EE3\u7801\u6240\u5728\u5217\u53F7\uFF1A${e.column}`);
|
|
31
|
+
if (e.description) lines.push(`DOM \u5143\u7D20\u9009\u62E9\u5668\uFF1A${e.description}`);
|
|
32
|
+
if (e.innerText) lines.push(`DOM \u5143\u7D20\u5185\u90E8\u6587\u672C\uFF1A${e.innerText.slice(0, 200)}`);
|
|
33
|
+
if (e.previewPageUrl) lines.push(`\u7528\u6237\u9009\u4E2D\u8282\u70B9\u65F6\u7684\u9875\u9762 URL\uFF1A${e.previewPageUrl}`);
|
|
34
|
+
if (e.previewPageTitle) lines.push(`\u9875\u9762\u6807\u9898\uFF1A${e.previewPageTitle}`);
|
|
35
|
+
return lines.join("\n");
|
|
36
|
+
}
|
|
18
37
|
var STDOUT_MAX_BYTES = 2e5;
|
|
19
38
|
var STDOUT_SPILL_MAX_BYTES = 2e6;
|
|
20
39
|
var STDERR_MAX_BYTES = 1e5;
|
|
@@ -22,6 +41,8 @@ var GRACE_MS = 3e4;
|
|
|
22
41
|
function apply(ctx, config = {}) {
|
|
23
42
|
const cwd = config.cwd ?? process.cwd();
|
|
24
43
|
const autoDiagnose = config.autoDiagnose ?? true;
|
|
44
|
+
const vitePort = config.vitePort ?? 0;
|
|
45
|
+
const contextApiPath = config.contextApiPath ?? DEFAULT_CONTEXT_API_PATH;
|
|
25
46
|
const tools = ctx.tools;
|
|
26
47
|
const subprocess = ctx.subprocess;
|
|
27
48
|
async function collectOutput(argv, signal) {
|
|
@@ -107,6 +128,60 @@ ${diag}`
|
|
|
107
128
|
return { kind: "accept", additionalContexts: [message] };
|
|
108
129
|
}
|
|
109
130
|
);
|
|
131
|
+
if (vitePort > 0) {
|
|
132
|
+
const contextBase = `http://127.0.0.1:${vitePort}${contextApiPath}`;
|
|
133
|
+
ctx.on(
|
|
134
|
+
"agent/pre-step",
|
|
135
|
+
async ({ signal }, next) => {
|
|
136
|
+
const decision = await next();
|
|
137
|
+
if (decision.kind === "reject") return decision;
|
|
138
|
+
const ids = /* @__PURE__ */ new Set();
|
|
139
|
+
for (const message of decision.messages) {
|
|
140
|
+
if (message.source.kind !== "user") continue;
|
|
141
|
+
for (const block of message.content) {
|
|
142
|
+
if (block.type !== "text") continue;
|
|
143
|
+
for (const id of collectNodeIds(block.text)) ids.add(id);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
if (ids.size === 0) return decision;
|
|
147
|
+
let elements = [];
|
|
148
|
+
try {
|
|
149
|
+
const res = await fetch(contextBase, { signal });
|
|
150
|
+
if (res.ok) {
|
|
151
|
+
const pc = await res.json();
|
|
152
|
+
elements = pc.selectedElements ?? [];
|
|
153
|
+
}
|
|
154
|
+
} catch {
|
|
155
|
+
}
|
|
156
|
+
const byId = /* @__PURE__ */ new Map();
|
|
157
|
+
for (const el of elements) {
|
|
158
|
+
if (el.id) byId.set(el.id, el);
|
|
159
|
+
}
|
|
160
|
+
const injected = [...ids].map((id) => byId.get(id)).filter((el) => el !== void 0);
|
|
161
|
+
if (injected.length === 0) return decision;
|
|
162
|
+
const contextText = injected.map(buildNodeContext).join("\n\n---\n\n");
|
|
163
|
+
const contextMessage = {
|
|
164
|
+
role: "user",
|
|
165
|
+
id: randomUUID(),
|
|
166
|
+
content: [
|
|
167
|
+
{
|
|
168
|
+
type: "text",
|
|
169
|
+
text: `\u4EE5\u4E0B\u662F\u7528\u6237\u5F15\u7528\u8282\u70B9\u7684\u5B8C\u6574\u4E0A\u4E0B\u6587\uFF08\u8282\u70B9 ID \u4E0E\u6D88\u606F\u4E2D\u7684 @\u8282\u70B9[id] \u6807\u8BB0\u5BF9\u5E94\uFF09\uFF1A
|
|
170
|
+
|
|
171
|
+
${contextText}`
|
|
172
|
+
}
|
|
173
|
+
],
|
|
174
|
+
source: { kind: "plugin", plugin: name }
|
|
175
|
+
};
|
|
176
|
+
try {
|
|
177
|
+
await fetch(contextBase, { method: "DELETE", signal });
|
|
178
|
+
} catch {
|
|
179
|
+
}
|
|
180
|
+
return { ...decision, messages: [...decision.messages, contextMessage] };
|
|
181
|
+
},
|
|
182
|
+
{ prepend: true }
|
|
183
|
+
);
|
|
184
|
+
}
|
|
110
185
|
}
|
|
111
186
|
export {
|
|
112
187
|
apply,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aipanel/dsh-plugin",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.5",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "AIPanel for DeepSeek Harness (dsh):注入审查工具 run_diagnostics、编辑后自动诊断。",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
},
|
|
14
14
|
"devDependencies": {
|
|
15
15
|
"@deepseek-ai/cordis": "^4.0.1",
|
|
16
|
+
"@deepseek-ai/dsh-agent": "^0.1.1-rc.2",
|
|
16
17
|
"@deepseek-ai/dsh-llm": "^0.1.1-rc.2",
|
|
17
18
|
"@deepseek-ai/dsh-subprocess": "^0.1.1-rc.2",
|
|
18
19
|
"@deepseek-ai/dsh-tools": "^0.1.1-rc.2",
|