@privateclaw/privateclaw 0.1.2 → 0.1.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.
- package/README.md +1 -1
- package/dist/bridges/openclaw-agent-bridge.d.ts +15 -0
- package/dist/bridges/openclaw-agent-bridge.js +113 -4
- package/dist/bridges/openclaw-agent-bridge.js.map +1 -1
- package/dist/cli.js +2 -0
- package/dist/cli.js.map +1 -1
- package/dist/invite-qr-files.d.ts +12 -0
- package/dist/invite-qr-files.js +124 -0
- package/dist/invite-qr-files.js.map +1 -0
- package/dist/openclaw-plugin.js +14 -21
- package/dist/openclaw-plugin.js.map +1 -1
- package/dist/pair-session.d.ts +3 -1
- package/dist/pair-session.js +39 -3
- package/dist/pair-session.js.map +1 -1
- package/dist/provider.js +3 -6
- package/dist/provider.js.map +1 -1
- package/dist/qr-terminal-render.d.ts +7 -0
- package/dist/qr-terminal-render.js +44 -0
- package/dist/qr-terminal-render.js.map +1 -0
- package/dist/text.d.ts +2 -0
- package/dist/text.js +2 -0
- package/dist/text.js.map +1 -1
- package/dist/types.d.ts +1 -0
- package/package.json +1 -1
- package/src/bridges/openclaw-agent-bridge.test.ts +46 -0
- package/src/bridges/openclaw-agent-bridge.ts +155 -5
- package/src/cli.ts +2 -0
- package/src/invite-qr-files.ts +156 -0
- package/src/openclaw-plugin.test.ts +25 -3
- package/src/openclaw-plugin.ts +19 -32
- package/src/pair-session.ts +65 -1
- package/src/provider.ts +2 -6
- package/src/qr-terminal-render.test.ts +26 -0
- package/src/qr-terminal-render.ts +66 -0
- package/src/text.ts +10 -0
- package/src/types.ts +1 -0
package/src/provider.ts
CHANGED
|
@@ -14,8 +14,8 @@ import QRCode from "qrcode";
|
|
|
14
14
|
import {
|
|
15
15
|
PRIVATECLAW_QR_ERROR_CORRECTION_LEVEL,
|
|
16
16
|
PRIVATECLAW_QR_SVG_MARGIN,
|
|
17
|
-
PRIVATECLAW_QR_TERMINAL_MARGIN,
|
|
18
17
|
} from "./qr-options.js";
|
|
18
|
+
import { renderTerminalQr } from "./qr-terminal-render.js";
|
|
19
19
|
import { RelayProviderClient } from "./relay-provider-client.js";
|
|
20
20
|
import {
|
|
21
21
|
buildInviteAnnouncementText,
|
|
@@ -1311,11 +1311,7 @@ export class PrivateClawProvider {
|
|
|
1311
1311
|
errorCorrectionLevel: PRIVATECLAW_QR_ERROR_CORRECTION_LEVEL,
|
|
1312
1312
|
margin: PRIVATECLAW_QR_SVG_MARGIN,
|
|
1313
1313
|
});
|
|
1314
|
-
const qrTerminal =
|
|
1315
|
-
type: "terminal",
|
|
1316
|
-
margin: PRIVATECLAW_QR_TERMINAL_MARGIN,
|
|
1317
|
-
small: true,
|
|
1318
|
-
});
|
|
1314
|
+
const qrTerminal = renderTerminalQr(inviteUri);
|
|
1319
1315
|
|
|
1320
1316
|
return {
|
|
1321
1317
|
invite,
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import test from "node:test";
|
|
3
|
+
import { renderQrModulesAsBraille } from "./qr-terminal-render.js";
|
|
4
|
+
|
|
5
|
+
test("renderQrModulesAsBraille packs QR modules into dense braille cells", () => {
|
|
6
|
+
const modules = {
|
|
7
|
+
size: 4,
|
|
8
|
+
get(x: number, y: number): boolean {
|
|
9
|
+
const pattern = [
|
|
10
|
+
[true, false, true, false],
|
|
11
|
+
[false, true, false, true],
|
|
12
|
+
[true, false, true, false],
|
|
13
|
+
[false, true, false, true],
|
|
14
|
+
];
|
|
15
|
+
return pattern[y]?.[x] ?? false;
|
|
16
|
+
},
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
const rendered = renderQrModulesAsBraille(modules, 0);
|
|
20
|
+
const lines = rendered.split("\n");
|
|
21
|
+
|
|
22
|
+
assert.equal(lines.length, 1);
|
|
23
|
+
assert.match(lines[0], /\u001b\[47m\u001b\[30m/u);
|
|
24
|
+
assert.match(lines[0], /[⢕⡪]/u);
|
|
25
|
+
assert.ok(lines[0].length < 20, "braille rendering should stay compact");
|
|
26
|
+
});
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import QRCode from "qrcode";
|
|
2
|
+
import {
|
|
3
|
+
PRIVATECLAW_QR_ERROR_CORRECTION_LEVEL,
|
|
4
|
+
PRIVATECLAW_QR_TERMINAL_MARGIN,
|
|
5
|
+
} from "./qr-options.js";
|
|
6
|
+
|
|
7
|
+
const ANSI_QR_PREFIX = "\u001b[47m\u001b[30m";
|
|
8
|
+
const ANSI_QR_SUFFIX = "\u001b[0m";
|
|
9
|
+
const BRAILLE_BASE = 0x2800;
|
|
10
|
+
|
|
11
|
+
interface QrModules {
|
|
12
|
+
readonly size: number;
|
|
13
|
+
get(x: number, y: number): boolean | number;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function renderTerminalQr(value: string): string {
|
|
17
|
+
const qr = QRCode.create(value, {
|
|
18
|
+
errorCorrectionLevel: PRIVATECLAW_QR_ERROR_CORRECTION_LEVEL,
|
|
19
|
+
});
|
|
20
|
+
return renderQrModulesAsBraille(qr.modules, PRIVATECLAW_QR_TERMINAL_MARGIN);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function renderQrModulesAsBraille(modules: QrModules, margin = 0): string {
|
|
24
|
+
const width = modules.size + margin * 2;
|
|
25
|
+
const height = modules.size + margin * 2;
|
|
26
|
+
const lines: string[] = [];
|
|
27
|
+
|
|
28
|
+
for (let y = 0; y < height; y += 4) {
|
|
29
|
+
let line = "";
|
|
30
|
+
for (let x = 0; x < width; x += 2) {
|
|
31
|
+
const bits =
|
|
32
|
+
(readModule(modules, x, y, margin) ? 0x01 : 0) |
|
|
33
|
+
(readModule(modules, x, y + 1, margin) ? 0x02 : 0) |
|
|
34
|
+
(readModule(modules, x, y + 2, margin) ? 0x04 : 0) |
|
|
35
|
+
(readModule(modules, x + 1, y, margin) ? 0x08 : 0) |
|
|
36
|
+
(readModule(modules, x + 1, y + 1, margin) ? 0x10 : 0) |
|
|
37
|
+
(readModule(modules, x + 1, y + 2, margin) ? 0x20 : 0) |
|
|
38
|
+
(readModule(modules, x, y + 3, margin) ? 0x40 : 0) |
|
|
39
|
+
(readModule(modules, x + 1, y + 3, margin) ? 0x80 : 0);
|
|
40
|
+
|
|
41
|
+
line += bits === 0 ? " " : String.fromCodePoint(BRAILLE_BASE + bits);
|
|
42
|
+
}
|
|
43
|
+
lines.push(`${ANSI_QR_PREFIX}${line}${ANSI_QR_SUFFIX}`);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return lines.join("\n");
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function readModule(
|
|
50
|
+
modules: QrModules,
|
|
51
|
+
x: number,
|
|
52
|
+
y: number,
|
|
53
|
+
margin: number,
|
|
54
|
+
): boolean {
|
|
55
|
+
const moduleX = x - margin;
|
|
56
|
+
const moduleY = y - margin;
|
|
57
|
+
if (
|
|
58
|
+
moduleX < 0 ||
|
|
59
|
+
moduleY < 0 ||
|
|
60
|
+
moduleX >= modules.size ||
|
|
61
|
+
moduleY >= modules.size
|
|
62
|
+
) {
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
return Boolean(modules.get(moduleX, moduleY));
|
|
66
|
+
}
|
package/src/text.ts
CHANGED
|
@@ -68,11 +68,21 @@ export const PRIVATECLAW_CLI_PRINT_ONLY_OPTION_DESCRIPTION =
|
|
|
68
68
|
"Print the invite and QR code, then exit immediately.",
|
|
69
69
|
);
|
|
70
70
|
|
|
71
|
+
export const PRIVATECLAW_CLI_OPEN_OPTION_DESCRIPTION = formatBilingualInline(
|
|
72
|
+
"生成二维码后在浏览器中打开本地预览页。",
|
|
73
|
+
"Open a local browser preview after generating the QR code.",
|
|
74
|
+
);
|
|
75
|
+
|
|
71
76
|
export const PRIVATECLAW_INVITE_URI_LABEL = formatBilingualInline(
|
|
72
77
|
"邀请链接",
|
|
73
78
|
"Invite URI",
|
|
74
79
|
);
|
|
75
80
|
|
|
81
|
+
export const PRIVATECLAW_QR_PNG_PATH_LABEL = formatBilingualInline(
|
|
82
|
+
"二维码 PNG 路径",
|
|
83
|
+
"QR PNG path",
|
|
84
|
+
);
|
|
85
|
+
|
|
76
86
|
export const PRIVATECLAW_WAITING_FOR_APP_MESSAGE = formatBilingualInline(
|
|
77
87
|
"等待 PrivateClaw App 连接,按 Ctrl+C 停止。",
|
|
78
88
|
"Waiting for the PrivateClaw app to connect. Press Ctrl+C to stop.",
|