@privateclaw/privateclaw 0.1.3 → 0.1.6

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/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,
17
18
  } 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,
@@ -1023,6 +1023,11 @@ export class PrivateClawProvider {
1023
1023
  this.options.onLog?.(
1024
1024
  `[provider] user_message session=${sessionId} textChars=${payload.text.length} attachments=${payload.attachments?.length ?? 0}`,
1025
1025
  );
1026
+ for (const attachment of payload.attachments ?? []) {
1027
+ this.options.onLog?.(
1028
+ `[provider] attachment_in session=${sessionId} name=${JSON.stringify(attachment.name)} mimeType=${attachment.mimeType} sizeBytes=${attachment.sizeBytes} hasData=${Boolean(attachment.dataBase64?.trim())} hasUri=${Boolean(attachment.uri?.trim())}`,
1029
+ );
1030
+ }
1026
1031
 
1027
1032
  const participant =
1028
1033
  (payload.appId ? session.participants.get(payload.appId) : undefined) ??
@@ -1205,6 +1210,14 @@ export class PrivateClawProvider {
1205
1210
  });
1206
1211
 
1207
1212
  for (const message of normalizeBridgeMessages(bridgeResponse)) {
1213
+ this.options.onLog?.(
1214
+ `[provider] bridge_message_out session=${sessionId} textChars=${message.text.length} attachments=${message.attachments?.length ?? 0}`,
1215
+ );
1216
+ for (const attachment of message.attachments ?? []) {
1217
+ this.options.onLog?.(
1218
+ `[provider] attachment_out session=${sessionId} name=${JSON.stringify(attachment.name)} mimeType=${attachment.mimeType} sizeBytes=${attachment.sizeBytes} hasData=${Boolean(attachment.dataBase64?.trim())}`,
1219
+ );
1220
+ }
1208
1221
  await this.sendAssistantMessage(sessionId, {
1209
1222
  text: message.text,
1210
1223
  replyTo: payload.clientMessageId,
@@ -1311,7 +1324,11 @@ export class PrivateClawProvider {
1311
1324
  errorCorrectionLevel: PRIVATECLAW_QR_ERROR_CORRECTION_LEVEL,
1312
1325
  margin: PRIVATECLAW_QR_SVG_MARGIN,
1313
1326
  });
1314
- const qrTerminal = renderTerminalQr(inviteUri);
1327
+ const qrTerminal = await QRCode.toString(inviteUri, {
1328
+ type: "terminal",
1329
+ margin: PRIVATECLAW_QR_TERMINAL_MARGIN,
1330
+ small: true,
1331
+ });
1315
1332
 
1316
1333
  return {
1317
1334
  invite,
@@ -1,7 +0,0 @@
1
- interface QrModules {
2
- readonly size: number;
3
- get(x: number, y: number): boolean | number;
4
- }
5
- export declare function renderTerminalQr(value: string): string;
6
- export declare function renderQrModulesAsBraille(modules: QrModules, margin?: number): string;
7
- export {};
@@ -1,44 +0,0 @@
1
- import QRCode from "qrcode";
2
- import { PRIVATECLAW_QR_ERROR_CORRECTION_LEVEL, PRIVATECLAW_QR_TERMINAL_MARGIN, } from "./qr-options.js";
3
- const ANSI_QR_PREFIX = "\u001b[47m\u001b[30m";
4
- const ANSI_QR_SUFFIX = "\u001b[0m";
5
- const BRAILLE_BASE = 0x2800;
6
- export function renderTerminalQr(value) {
7
- const qr = QRCode.create(value, {
8
- errorCorrectionLevel: PRIVATECLAW_QR_ERROR_CORRECTION_LEVEL,
9
- });
10
- return renderQrModulesAsBraille(qr.modules, PRIVATECLAW_QR_TERMINAL_MARGIN);
11
- }
12
- export function renderQrModulesAsBraille(modules, margin = 0) {
13
- const width = modules.size + margin * 2;
14
- const height = modules.size + margin * 2;
15
- const lines = [];
16
- for (let y = 0; y < height; y += 4) {
17
- let line = "";
18
- for (let x = 0; x < width; x += 2) {
19
- const bits = (readModule(modules, x, y, margin) ? 0x01 : 0) |
20
- (readModule(modules, x, y + 1, margin) ? 0x02 : 0) |
21
- (readModule(modules, x, y + 2, margin) ? 0x04 : 0) |
22
- (readModule(modules, x + 1, y, margin) ? 0x08 : 0) |
23
- (readModule(modules, x + 1, y + 1, margin) ? 0x10 : 0) |
24
- (readModule(modules, x + 1, y + 2, margin) ? 0x20 : 0) |
25
- (readModule(modules, x, y + 3, margin) ? 0x40 : 0) |
26
- (readModule(modules, x + 1, y + 3, margin) ? 0x80 : 0);
27
- line += bits === 0 ? " " : String.fromCodePoint(BRAILLE_BASE + bits);
28
- }
29
- lines.push(`${ANSI_QR_PREFIX}${line}${ANSI_QR_SUFFIX}`);
30
- }
31
- return lines.join("\n");
32
- }
33
- function readModule(modules, x, y, margin) {
34
- const moduleX = x - margin;
35
- const moduleY = y - margin;
36
- if (moduleX < 0 ||
37
- moduleY < 0 ||
38
- moduleX >= modules.size ||
39
- moduleY >= modules.size) {
40
- return false;
41
- }
42
- return Boolean(modules.get(moduleX, moduleY));
43
- }
44
- //# sourceMappingURL=qr-terminal-render.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"qr-terminal-render.js","sourceRoot":"","sources":["../src/qr-terminal-render.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,EACL,qCAAqC,EACrC,8BAA8B,GAC/B,MAAM,iBAAiB,CAAC;AAEzB,MAAM,cAAc,GAAG,sBAAsB,CAAC;AAC9C,MAAM,cAAc,GAAG,WAAW,CAAC;AACnC,MAAM,YAAY,GAAG,MAAM,CAAC;AAO5B,MAAM,UAAU,gBAAgB,CAAC,KAAa;IAC5C,MAAM,EAAE,GAAG,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE;QAC9B,oBAAoB,EAAE,qCAAqC;KAC5D,CAAC,CAAC;IACH,OAAO,wBAAwB,CAAC,EAAE,CAAC,OAAO,EAAE,8BAA8B,CAAC,CAAC;AAC9E,CAAC;AAED,MAAM,UAAU,wBAAwB,CAAC,OAAkB,EAAE,MAAM,GAAG,CAAC;IACrE,MAAM,KAAK,GAAG,OAAO,CAAC,IAAI,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;gBACtD,CAAC,UAAU,CAAC,OAAO,EAAE,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;gBAClD,CAAC,UAAU,CAAC,OAAO,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;YAEzD,IAAI,IAAI,IAAI,KAAK,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,MAAM,CAAC,aAAa,CAAC,YAAY,GAAG,IAAI,CAAC,CAAC;QACvE,CAAC;QACD,KAAK,CAAC,IAAI,CAAC,GAAG,cAAc,GAAG,IAAI,GAAG,cAAc,EAAE,CAAC,CAAC;IAC1D,CAAC;IAED,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC1B,CAAC;AAED,SAAS,UAAU,CACjB,OAAkB,EAClB,CAAS,EACT,CAAS,EACT,MAAc;IAEd,MAAM,OAAO,GAAG,CAAC,GAAG,MAAM,CAAC;IAC3B,MAAM,OAAO,GAAG,CAAC,GAAG,MAAM,CAAC;IAC3B,IACE,OAAO,GAAG,CAAC;QACX,OAAO,GAAG,CAAC;QACX,OAAO,IAAI,OAAO,CAAC,IAAI;QACvB,OAAO,IAAI,OAAO,CAAC,IAAI,EACvB,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;IACD,OAAO,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC;AAChD,CAAC"}
@@ -1,26 +0,0 @@
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
- });
@@ -1,66 +0,0 @@
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
- }