@sleep2agi/dsh-anet 0.1.0-preview.32 → 0.1.0-preview.33
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 +1 -1
- package/README.zh.md +1 -1
- package/package.json +1 -1
- package/src/plugin.mjs +10 -45
- package/src/ocr.swift +0 -17
package/README.md
CHANGED
|
@@ -53,7 +53,7 @@ The user token is never printed or persisted; `--no-verify` skips the round-trip
|
|
|
53
53
|
- If the plugin process dies mid-turn, the task is answered `failed` with "please resend" on the next start rather than being re-run silently.
|
|
54
54
|
- Replies over the hub's 10 000-character limit are truncated with a visible note.
|
|
55
55
|
- Informational (non-task) inbox messages are acknowledged but not shown to the agent in this version.
|
|
56
|
-
- Image attachments on tasks are downloaded with the node token (up to 5 images, 10 MB each)
|
|
56
|
+
- Image attachments on tasks are downloaded with the node token and passed as image blocks (up to 5 images, 10 MB each); the selected model must support image input. Other attachment types are not processed yet.
|
|
57
57
|
|
|
58
58
|
## Tests
|
|
59
59
|
|
package/README.zh.md
CHANGED
|
@@ -51,7 +51,7 @@ ANET_USER_TOKEN=utok_... node scripts/connect.mjs \
|
|
|
51
51
|
- 插件进程在一轮中途死掉,下次启动时对该任务回 `failed` 并提示「请重发」,而不是悄悄重跑。
|
|
52
52
|
- 超过 hub 1 万字上限的回件会截断并附说明。
|
|
53
53
|
- 本版对「消息」类(非任务)收件只确认,不交给 agent。
|
|
54
|
-
- 任务里的图片附件会用节点 token
|
|
54
|
+
- 任务里的图片附件会用节点 token 下载并作为 image block 交给 agent(最多 5 张、单张 ≤10MB);需要模型支持图片输入。其他类型附件暂不处理。
|
|
55
55
|
|
|
56
56
|
## 测试
|
|
57
57
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sleep2agi/dsh-anet",
|
|
3
|
-
"version": "0.1.0-preview.
|
|
3
|
+
"version": "0.1.0-preview.33",
|
|
4
4
|
"description": "DSH (DeepSeek Harness) plugin: expose one or more DSH sessions as Agent Network (anet.sh / CommHub) nodes.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/plugin.mjs",
|
package/src/plugin.mjs
CHANGED
|
@@ -2,11 +2,8 @@
|
|
|
2
2
|
// Each node has its own name, hub, token, project directory and dedicated
|
|
3
3
|
// session; tasks for a node run in that node's session so context is preserved.
|
|
4
4
|
import { randomUUID } from "node:crypto";
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import { fileURLToPath } from "node:url";
|
|
8
|
-
import { accessSync, chmodSync, mkdirSync, readFileSync, unlinkSync, writeFileSync } from "node:fs";
|
|
9
|
-
import { homedir, tmpdir } from "node:os";
|
|
5
|
+
import { chmodSync, mkdirSync, readFileSync, unlinkSync, writeFileSync } from "node:fs";
|
|
6
|
+
import { homedir } from "node:os";
|
|
10
7
|
import { basename, dirname, join } from "node:path";
|
|
11
8
|
import { installModelSelection } from "@deepseek-ai/dsh-agent";
|
|
12
9
|
import { createUserMessage } from "@deepseek-ai/dsh-llm";
|
|
@@ -25,7 +22,7 @@ export { attachmentCandidates, collectAttachments };
|
|
|
25
22
|
export const name = "anet";
|
|
26
23
|
export const inject = ["agents", "agentDefaultModel", "sessions", "tools", "attachments"];
|
|
27
24
|
|
|
28
|
-
const VERSION = "dsh-anet@0.1.0-preview.
|
|
25
|
+
const VERSION = "dsh-anet@0.1.0-preview.33";
|
|
29
26
|
|
|
30
27
|
function agentSetup(ctx) {
|
|
31
28
|
const selection = ctx.agentDefaultModel.currentSelection();
|
|
@@ -56,26 +53,6 @@ const IMAGE_MAX_BYTES = 10 * 1024 * 1024;
|
|
|
56
53
|
const MAX_IMAGES = 5;
|
|
57
54
|
const MIME_BY_EXT = { jpg: "image/jpeg", jpeg: "image/jpeg", png: "image/png", gif: "image/gif", webp: "image/webp" };
|
|
58
55
|
|
|
59
|
-
const runFile = promisify(execFile);
|
|
60
|
-
const ocrSource = fileURLToPath(new URL("./ocr.swift", import.meta.url));
|
|
61
|
-
|
|
62
|
-
async function ocrImage(path) {
|
|
63
|
-
const bin = join(homedir(), ".anet", "dsh", "anet-ocr");
|
|
64
|
-
try { accessSync(bin); } catch {
|
|
65
|
-
mkdirSync(dirname(bin), { recursive: true, mode: 0o700 });
|
|
66
|
-
await runFile("swiftc", ["-O", ocrSource, "-o", bin], { timeout: 120_000 });
|
|
67
|
-
chmodSync(bin, 0o700);
|
|
68
|
-
}
|
|
69
|
-
const { stdout } = await runFile(bin, [path], { timeout: 60_000, maxBuffer: 2 * 1024 * 1024 });
|
|
70
|
-
return String(stdout).trim();
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
function modelReadsImages(selection) {
|
|
74
|
-
const id = `${selection?.provider ?? ""} ${selection?.model ?? ""}`.toLowerCase();
|
|
75
|
-
if (id.includes("deepseek")) return /vl|vision|multimodal/.test(id);
|
|
76
|
-
return true;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
56
|
function attachmentCandidates(task) {
|
|
80
57
|
const candidates = [];
|
|
81
58
|
for (const item of task?.meta?.attachments ?? task?.attachments ?? []) {
|
|
@@ -87,10 +64,8 @@ function attachmentCandidates(task) {
|
|
|
87
64
|
return candidates;
|
|
88
65
|
}
|
|
89
66
|
|
|
90
|
-
async function collectAttachments(ctx, node, task
|
|
91
|
-
const blocks = []; const notes = [];
|
|
92
|
-
const inline = options.inlineImages !== false;
|
|
93
|
-
const read = options.ocr ?? ocrImage;
|
|
67
|
+
async function collectAttachments(ctx, node, task) {
|
|
68
|
+
const blocks = []; const notes = [];
|
|
94
69
|
let count = 0;
|
|
95
70
|
for (const candidate of attachmentCandidates(task)) {
|
|
96
71
|
if (count >= MAX_IMAGES) break;
|
|
@@ -106,32 +81,22 @@ async function collectAttachments(ctx, node, task, options = {}) {
|
|
|
106
81
|
const data = new Uint8Array(await res.arrayBuffer());
|
|
107
82
|
if (data.byteLength === 0) throw new Error("empty file");
|
|
108
83
|
if (data.byteLength > IMAGE_MAX_BYTES) throw new Error("image larger than 10 MB");
|
|
109
|
-
const
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
try { recognized = await read(tmp); } catch { /* OCR unavailable */ }
|
|
113
|
-
try { unlinkSync(tmp); } catch { /* best effort */ }
|
|
114
|
-
if (inline) {
|
|
115
|
-
const attachment = await ctx.attachments.saveImage({ data, mediaType: mime, ...(candidate.name ? { name: candidate.name } : {}) });
|
|
116
|
-
blocks.push({ type: "image", attachment });
|
|
117
|
-
}
|
|
118
|
-
if (recognized) text += `${text ? "\n" : ""}[图片文字 ${candidate.name ?? "image"}]\n${recognized}`;
|
|
119
|
-
notes.push(recognized ? `[附件 ${candidate.name ?? "image"}:已提取文字]` : `[附件 ${candidate.name ?? "image"}${inline ? "" : ":模型不支持图片,未提取到文字"}]`);
|
|
84
|
+
const attachment = await ctx.attachments.saveImage({ data, mediaType: mime, ...(candidate.name ? { name: candidate.name } : {}) });
|
|
85
|
+
blocks.push({ type: "image", attachment });
|
|
86
|
+
notes.push(`[附件 ${candidate.name ?? "image"}]`);
|
|
120
87
|
count++;
|
|
121
88
|
} catch (error) {
|
|
122
89
|
notes.push(`[附件 ${candidate.name ?? candidate.id ?? url} 下载失败: ${error?.message ?? error}]`);
|
|
123
90
|
}
|
|
124
91
|
}
|
|
125
|
-
return { blocks, notes
|
|
92
|
+
return { blocks, notes };
|
|
126
93
|
}
|
|
127
94
|
|
|
128
95
|
async function runNodeTurn(ctx, node, prompt, task) {
|
|
129
|
-
const
|
|
130
|
-
const attachments = await collectAttachments(ctx, node, task, { inlineImages: modelReadsImages(selection) });
|
|
96
|
+
const attachments = await collectAttachments(ctx, node, task);
|
|
131
97
|
const agent = await ensureAgent(ctx, node);
|
|
132
98
|
const firstSeq = agent.session.seq;
|
|
133
99
|
const content = [{ type: "text", text: prompt }, ...attachments.blocks];
|
|
134
|
-
if (attachments.text) content.push({ type: "text", text: attachments.text });
|
|
135
100
|
if (attachments.notes.length > 0) content.push({ type: "text", text: attachments.notes.join("\n") });
|
|
136
101
|
agent.followup(createUserMessage({ content, source: { kind: "user" } }));
|
|
137
102
|
await agent.whenIdle();
|
package/src/ocr.swift
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import Foundation
|
|
2
|
-
import Vision
|
|
3
|
-
import AppKit
|
|
4
|
-
|
|
5
|
-
let path = CommandLine.arguments[1]
|
|
6
|
-
guard let image = NSImage(contentsOfFile: path),
|
|
7
|
-
let cg = image.cgImage(forProposedRect: nil, context: nil, hints: nil) else {
|
|
8
|
-
exit(2)
|
|
9
|
-
}
|
|
10
|
-
let request = VNRecognizeTextRequest()
|
|
11
|
-
request.recognitionLevel = .accurate
|
|
12
|
-
request.usesLanguageCorrection = true
|
|
13
|
-
request.recognitionLanguages = ["zh-Hans", "en-US"]
|
|
14
|
-
let handler = VNImageRequestHandler(cgImage: cg, options: [:])
|
|
15
|
-
try handler.perform([request])
|
|
16
|
-
let lines = (request.results ?? []).compactMap { $0.topCandidates(1).first?.string }
|
|
17
|
-
print(lines.joined(separator: "\n"))
|