piclaw 0.0.19 → 0.0.21
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/.output/nitro.json +1 -1
- package/.output/public/assets/defult-D5RLDUrI.js +1 -0
- package/.output/public/assets/{dist-CMBqBOCp.js → dist-BH_oa-kv.js} +1 -1
- package/.output/public/assets/index-7JvURuHy.js +204 -0
- package/.output/public/assets/index-K43slwjJ.css +1 -0
- package/.output/public/index.html +11 -2
- package/.output/server/_...path_.get.mjs +16 -0
- package/.output/server/_chunks/app.mjs +261 -181
- package/.output/server/_chunks/browser.mjs +4 -1
- package/.output/server/_chunks/config.mjs +4 -0
- package/.output/server/_chunks/db.mjs +32 -28
- package/.output/server/_chunks/device-bus.mjs +123 -0
- package/.output/server/_chunks/dummy.mjs +1 -1
- package/.output/server/_chunks/logger.mjs +23 -0
- package/.output/server/_chunks/login.mjs +1 -1
- package/.output/server/_chunks/notes.mjs +1 -3
- package/.output/server/_chunks/renderer-template.mjs +1 -1
- package/.output/server/_chunks/sandbox.mjs +217 -0
- package/.output/server/_chunks/server.mjs +2302 -122
- package/.output/server/_chunks/terminal.mjs +63 -8
- package/.output/server/_chunks/uploads.mjs +60 -0
- package/.output/server/_chunks/virtual.mjs +192 -54
- package/.output/server/_id_.delete.mjs +5 -2
- package/.output/server/_id_.patch.mjs +2 -0
- package/.output/server/_id_2.delete.mjs +8 -0
- package/.output/server/_jid_.delete.mjs +5 -2
- package/.output/server/_jid_.patch.mjs +37 -4
- package/.output/server/_jid_2.delete.mjs +5 -2
- package/.output/server/_libs/@acemir/cssom+[...].mjs +2269 -1137
- package/.output/server/_libs/@google/genai.mjs +337 -273
- package/.output/server/_libs/@mariozechner/pi-agent-core+[...].mjs +381 -2073
- package/.output/server/_libs/@mariozechner/pi-coding-agent+[...].mjs +231 -131
- package/.output/server/_libs/_.mjs +3 -2
- package/.output/server/_libs/_10.mjs +2 -4
- package/.output/server/_libs/_11.mjs +2 -4
- package/.output/server/_libs/_12.mjs +2 -3
- package/.output/server/_libs/_13.mjs +2 -3
- package/.output/server/_libs/_14.mjs +2 -4
- package/.output/server/_libs/_15.mjs +2 -4
- package/.output/server/_libs/_16.mjs +2 -3
- package/.output/server/_libs/_17.mjs +2 -4
- package/.output/server/_libs/_18.mjs +2 -2
- package/.output/server/_libs/_19.mjs +2 -2
- package/.output/server/_libs/_2.mjs +3 -3
- package/.output/server/_libs/_20.mjs +2 -2
- package/.output/server/_libs/_21.mjs +2 -2
- package/.output/server/_libs/_22.mjs +2 -2
- package/.output/server/_libs/_23.mjs +2 -2
- package/.output/server/_libs/_24.mjs +2 -2
- package/.output/server/_libs/_25.mjs +2 -2
- package/.output/server/_libs/_26.mjs +2 -2
- package/.output/server/_libs/_27.mjs +2 -2
- package/.output/server/_libs/_28.mjs +2 -2
- package/.output/server/_libs/_29.mjs +2 -2
- package/.output/server/_libs/_3.mjs +3 -3
- package/.output/server/_libs/_30.mjs +2 -2
- package/.output/server/_libs/_31.mjs +2 -2
- package/.output/server/_libs/_32.mjs +2 -2
- package/.output/server/_libs/_33.mjs +2 -2
- package/.output/server/_libs/_34.mjs +2 -2
- package/.output/server/_libs/_35.mjs +2 -2
- package/.output/server/_libs/_36.mjs +2 -2
- package/.output/server/_libs/_37.mjs +2 -2
- package/.output/server/_libs/_38.mjs +2 -2
- package/.output/server/_libs/_39.mjs +2 -2
- package/.output/server/_libs/_4.mjs +4 -3
- package/.output/server/_libs/_40.mjs +2 -2
- package/.output/server/_libs/_41.mjs +2 -2
- package/.output/server/_libs/_42.mjs +2 -2
- package/.output/server/_libs/_43.mjs +2 -2
- package/.output/server/_libs/_44.mjs +2 -2
- package/.output/server/_libs/_45.mjs +2 -2
- package/.output/server/_libs/_46.mjs +2 -2
- package/.output/server/_libs/_47.mjs +2 -2
- package/.output/server/_libs/_48.mjs +2 -2
- package/.output/server/_libs/_49.mjs +2 -2
- package/.output/server/_libs/_5.mjs +2 -3
- package/.output/server/_libs/_50.mjs +2 -2
- package/.output/server/_libs/_51.mjs +2 -2
- package/.output/server/_libs/_52.mjs +2 -2
- package/.output/server/_libs/_53.mjs +2 -2
- package/.output/server/_libs/_54.mjs +2 -2
- package/.output/server/_libs/_55.mjs +2 -2
- package/.output/server/_libs/_56.mjs +2 -2
- package/.output/server/_libs/_57.mjs +2 -2
- package/.output/server/_libs/_58.mjs +2 -2
- package/.output/server/_libs/_59.mjs +2 -2
- package/.output/server/_libs/_6.mjs +2 -3
- package/.output/server/_libs/_60.mjs +2 -2
- package/.output/server/_libs/_61.mjs +2 -2
- package/.output/server/_libs/_62.mjs +2 -2
- package/.output/server/_libs/_63.mjs +2 -2
- package/.output/server/_libs/_64.mjs +2 -2
- package/.output/server/_libs/_65.mjs +2 -2
- package/.output/server/_libs/_66.mjs +2 -2
- package/.output/server/_libs/_67.mjs +2 -2
- package/.output/server/_libs/_68.mjs +2 -2
- package/.output/server/_libs/_69.mjs +2 -2
- package/.output/server/_libs/_7.mjs +2 -5
- package/.output/server/_libs/_70.mjs +2 -2
- package/.output/server/_libs/_71.mjs +2 -2
- package/.output/server/_libs/_72.mjs +2 -2
- package/.output/server/_libs/_73.mjs +2 -2
- package/.output/server/_libs/_74.mjs +2 -2
- package/.output/server/_libs/_75.mjs +2 -2
- package/.output/server/_libs/_76.mjs +2 -2
- package/.output/server/_libs/_77.mjs +2 -2
- package/.output/server/_libs/_78.mjs +2 -2
- package/.output/server/_libs/_79.mjs +2 -2
- package/.output/server/_libs/_8.mjs +2 -3
- package/.output/server/_libs/_80.mjs +2 -2
- package/.output/server/_libs/_81.mjs +2 -2
- package/.output/server/_libs/_82.mjs +2 -2
- package/.output/server/_libs/_83.mjs +2 -2
- package/.output/server/_libs/_84.mjs +2 -2
- package/.output/server/_libs/_85.mjs +2 -2
- package/.output/server/_libs/_86.mjs +2 -2
- package/.output/server/_libs/_87.mjs +2 -2
- package/.output/server/_libs/_88.mjs +2 -2
- package/.output/server/_libs/_89.mjs +2 -2
- package/.output/server/_libs/_9.mjs +2 -4
- package/.output/server/_libs/_90.mjs +5 -2
- package/.output/server/_libs/_91.mjs +3 -2
- package/.output/server/_libs/_92.mjs +2 -2
- package/.output/server/_libs/_93.mjs +2 -2
- package/.output/server/_libs/_94.mjs +2 -2
- package/.output/server/_libs/agent-base.mjs +1 -1
- package/.output/server/_libs/cheerio+[...].mjs +1 -1
- package/.output/server/_libs/data-uri-to-buffer.mjs +2 -67
- package/.output/server/_libs/data-urls+[...].mjs +1 -1
- package/.output/server/_libs/diff.mjs +1 -1
- package/.output/server/_libs/exodus__bytes.mjs +99 -81
- package/.output/server/_libs/fetch-blob+node-domexception.mjs +1 -1
- package/.output/server/_libs/h3+rou3+srvx.mjs +34 -4
- package/.output/server/_libs/html-encoding-sniffer.mjs +1 -1
- package/.output/server/_libs/https-proxy-agent.mjs +2 -2
- package/.output/server/_libs/jsdom.mjs +1 -1
- package/.output/server/_libs/just-bash+[...].mjs +4676 -3916
- package/.output/server/_libs/mariozechner__jiti.mjs +1 -1
- package/.output/server/_libs/mariozechner__pi-ai.mjs +1472 -0
- package/.output/server/_libs/md4x.mjs +1 -1
- package/.output/server/_libs/mime.mjs +838 -1
- package/.output/server/_libs/node-fetch.mjs +4 -4
- package/.output/server/_libs/node-liblzma.mjs +1 -1
- package/.output/server/_libs/silvia-odwyer__photon-node.mjs +1 -1
- package/.output/server/_routes/api/auth/approve.mjs +2 -0
- package/.output/server/_routes/api/auth/revoke.mjs +2 -0
- package/.output/server/_routes/api/auth/status.mjs +25 -6
- package/.output/server/_routes/api/browser2.mjs +1 -1
- package/.output/server/_routes/api/config2.mjs +2 -0
- package/.output/server/_routes/api/device_events.mjs +36 -0
- package/.output/server/_routes/api/files/groups.mjs +1 -2
- package/.output/server/_routes/api/files/raw.mjs +1 -1
- package/.output/server/_routes/api/groups.mjs +5 -3
- package/.output/server/_routes/api/groups2.mjs +18 -6
- package/.output/server/_routes/api/health.mjs +1 -2
- package/.output/server/_routes/api/messages.mjs +7 -1
- package/.output/server/_routes/api/notes/delete.mjs +4 -1
- package/.output/server/_routes/api/notes/write.mjs +2 -0
- package/.output/server/_routes/api/ntfy/setup.mjs +8 -0
- package/.output/server/_routes/api/pi/apikey.mjs +3 -2
- package/.output/server/_routes/api/pi/apikey_providers.mjs +1 -2
- package/.output/server/_routes/api/pi/commands.mjs +13 -3
- package/.output/server/_routes/api/pi/login/events.mjs +0 -1
- package/.output/server/_routes/api/pi/login/respond.mjs +2 -1
- package/.output/server/_routes/api/pi/login.mjs +1 -2
- package/.output/server/_routes/api/pi/logout.mjs +2 -1
- package/.output/server/_routes/api/pi/models.mjs +1 -2
- package/.output/server/_routes/api/pi/models_config2.mjs +2 -0
- package/.output/server/_routes/api/pi/settings2.mjs +2 -0
- package/.output/server/_routes/api/pi/status.mjs +1 -2
- package/.output/server/_routes/api/proxy.mjs +19 -1
- package/.output/server/_routes/api/sandbox.mjs +26 -0
- package/.output/server/_routes/api/sandbox2.mjs +17 -0
- package/.output/server/_routes/api/send.mjs +26 -18
- package/.output/server/_routes/api/status.mjs +1 -3
- package/.output/server/_routes/api/stop.mjs +11 -0
- package/.output/server/_routes/api/store/plugins.mjs +75 -0
- package/.output/server/_routes/api/store/skills.mjs +11 -0
- package/.output/server/_routes/api/tasks2.mjs +3 -2
- package/.output/server/_routes/api/telegram/setup.mjs +5 -2
- package/.output/server/_routes/api/telegram/status.mjs +1 -2
- package/.output/server/_routes/api/terminal2.mjs +2 -1
- package/.output/server/_routes/api/tunnel/setup.mjs +4 -2
- package/.output/server/_runtime.mjs +1 -2
- package/.output/server/_utils.mjs +10 -2
- package/.output/server/index.mjs +1 -1
- package/.output/server/node_modules/amdefine/amdefine.js +301 -0
- package/.output/server/node_modules/amdefine/package.json +16 -0
- package/.output/server/node_modules/compressjs/lib/BWT.js +420 -0
- package/.output/server/node_modules/compressjs/lib/BWTC.js +234 -0
- package/.output/server/node_modules/compressjs/lib/BitStream.js +108 -0
- package/.output/server/node_modules/compressjs/lib/Bzip2.js +936 -0
- package/.output/server/node_modules/compressjs/lib/CRC32.js +105 -0
- package/.output/server/node_modules/compressjs/lib/Context1Model.js +56 -0
- package/.output/server/node_modules/compressjs/lib/DefSumModel.js +152 -0
- package/.output/server/node_modules/compressjs/lib/DeflateDistanceModel.js +55 -0
- package/.output/server/node_modules/compressjs/lib/Dmc.js +197 -0
- package/.output/server/node_modules/compressjs/lib/DummyRangeCoder.js +81 -0
- package/.output/server/node_modules/compressjs/lib/FenwickModel.js +194 -0
- package/.output/server/node_modules/compressjs/lib/Huffman.js +514 -0
- package/.output/server/node_modules/compressjs/lib/HuffmanAllocator.js +227 -0
- package/.output/server/node_modules/compressjs/lib/LogDistanceModel.js +46 -0
- package/.output/server/node_modules/compressjs/lib/Lzjb.js +300 -0
- package/.output/server/node_modules/compressjs/lib/LzjbR.js +241 -0
- package/.output/server/node_modules/compressjs/lib/Lzp3.js +273 -0
- package/.output/server/node_modules/compressjs/lib/MTFModel.js +208 -0
- package/.output/server/node_modules/compressjs/lib/NoModel.js +46 -0
- package/.output/server/node_modules/compressjs/lib/PPM.js +343 -0
- package/.output/server/node_modules/compressjs/lib/RangeCoder.js +238 -0
- package/.output/server/node_modules/compressjs/lib/Simple.js +111 -0
- package/.output/server/node_modules/compressjs/lib/Stream.js +53 -0
- package/.output/server/node_modules/compressjs/lib/Util.js +324 -0
- package/.output/server/node_modules/compressjs/lib/freeze.js +14 -0
- package/.output/server/node_modules/compressjs/main.js +29 -0
- package/.output/server/node_modules/compressjs/package.json +35 -0
- package/.output/server/package.json +2 -1
- package/README.md +10 -1
- package/lib/index.d.mts +1 -0
- package/lib/index.mjs +1 -0
- package/lib/piclaw.mjs +100 -0
- package/lib/utils.mjs +96 -0
- package/package.json +16 -11
- package/.output/public/assets/defult-CMO6TZ5a.js +0 -1
- package/.output/public/assets/index-jdnbJw-M.js +0 -204
- package/.output/public/assets/index-ooXrRwgl.css +0 -1
- package/.output/server/_chunks/commands.mjs +0 -282
- package/.output/server/_chunks/pi.mjs +0 -202
- package/.output/server/_chunks/session.mjs +0 -1114
- package/.output/server/_libs/@aws-crypto/crc32+[...].mjs +0 -299
- package/.output/server/_libs/@aws-sdk/client-bedrock-runtime+[...].mjs +0 -17828
- package/.output/server/_libs/@aws-sdk/credential-provider-http+[...].mjs +0 -122
- package/.output/server/_libs/@aws-sdk/credential-provider-ini+[...].mjs +0 -417
- package/.output/server/_libs/@aws-sdk/credential-provider-process+[...].mjs +0 -54
- package/.output/server/_libs/@aws-sdk/credential-provider-sso+[...].mjs +0 -1151
- package/.output/server/_libs/@aws-sdk/credential-provider-web-identity+[...].mjs +0 -50
- package/.output/server/_libs/@smithy/credential-provider-imds+[...].mjs +0 -369
- package/.output/server/_libs/@tootallnate/quickjs-emscripten+[...].mjs +0 -3011
- package/.output/server/_libs/_100.mjs +0 -2
- package/.output/server/_libs/_101.mjs +0 -2
- package/.output/server/_libs/_102.mjs +0 -5
- package/.output/server/_libs/_103.mjs +0 -3
- package/.output/server/_libs/_104.mjs +0 -2
- package/.output/server/_libs/_105.mjs +0 -3
- package/.output/server/_libs/_106.mjs +0 -2
- package/.output/server/_libs/_107.mjs +0 -2
- package/.output/server/_libs/_95.mjs +0 -2
- package/.output/server/_libs/_96.mjs +0 -2
- package/.output/server/_libs/_97.mjs +0 -2
- package/.output/server/_libs/_98.mjs +0 -2
- package/.output/server/_libs/_99.mjs +0 -2
- package/.output/server/_libs/amdefine.mjs +0 -188
- package/.output/server/_libs/ast-types.mjs +0 -2270
- package/.output/server/_libs/aws-sdk__nested-clients.mjs +0 -3141
- package/.output/server/_libs/basic-ftp.mjs +0 -1906
- package/.output/server/_libs/compressjs.mjs +0 -50
- package/.output/server/_libs/degenerator+[...].mjs +0 -9964
- package/.output/server/_libs/get-uri.mjs +0 -413
- package/.output/server/_libs/http-proxy-agent.mjs +0 -123
- package/.output/server/_libs/ip-address.mjs +0 -1423
- package/.output/server/_libs/lru-cache.mjs +0 -732
- package/.output/server/_libs/netmask.mjs +0 -139
- package/.output/server/_libs/pac-proxy-agent+[...].mjs +0 -3104
- package/.output/server/_libs/proxy-agent+proxy-from-env.mjs +0 -204
- package/.output/server/_libs/smithy__core.mjs +0 -192
- package/.output/server/node_modules/tslib/modules/index.js +0 -70
- package/.output/server/node_modules/tslib/modules/package.json +0 -3
- package/.output/server/node_modules/tslib/package.json +0 -47
- package/.output/server/node_modules/tslib/tslib.js +0 -484
- package/bin/piclaw.mjs +0 -195
|
@@ -0,0 +1,324 @@
|
|
|
1
|
+
/* Some basic utilities, used in a number of places. */
|
|
2
|
+
if (typeof define !== 'function') { var define = require('amdefine')(module); }
|
|
3
|
+
define(['./freeze','./Stream'],function(freeze, Stream) {
|
|
4
|
+
var Util = Object.create(null);
|
|
5
|
+
|
|
6
|
+
var EOF = Stream.EOF;
|
|
7
|
+
|
|
8
|
+
/* Take a buffer, array, or stream, and return an input stream. */
|
|
9
|
+
Util.coerceInputStream = function(input, forceRead) {
|
|
10
|
+
if (!('readByte' in input)) {
|
|
11
|
+
var buffer = input;
|
|
12
|
+
input = new Stream();
|
|
13
|
+
input.size = buffer.length;
|
|
14
|
+
input.pos = 0;
|
|
15
|
+
input.readByte = function() {
|
|
16
|
+
if (this.pos >= this.size) { return EOF; }
|
|
17
|
+
return buffer[this.pos++];
|
|
18
|
+
};
|
|
19
|
+
input.read = function(buf, bufOffset, length) {
|
|
20
|
+
var bytesRead = 0;
|
|
21
|
+
while (bytesRead < length && this.pos < buffer.length) {
|
|
22
|
+
buf[bufOffset++] = buffer[this.pos++];
|
|
23
|
+
bytesRead++;
|
|
24
|
+
}
|
|
25
|
+
return bytesRead;
|
|
26
|
+
};
|
|
27
|
+
input.seek = function(pos) { this.pos = pos; };
|
|
28
|
+
input.tell = function() { return this.pos; };
|
|
29
|
+
input.eof = function() { return this.pos >= buffer.length; };
|
|
30
|
+
} else if (forceRead && !('read' in input)) {
|
|
31
|
+
// wrap input if it doesn't implement read
|
|
32
|
+
var s = input;
|
|
33
|
+
input = new Stream();
|
|
34
|
+
input.readByte = function() {
|
|
35
|
+
var ch = s.readByte();
|
|
36
|
+
if (ch === EOF) { this._eof = true; }
|
|
37
|
+
return ch;
|
|
38
|
+
};
|
|
39
|
+
if ('size' in s) { input.size = s.size; }
|
|
40
|
+
if ('seek' in s) {
|
|
41
|
+
input.seek = function(pos) {
|
|
42
|
+
s.seek(pos); // may throw if s doesn't implement seek
|
|
43
|
+
this._eof = false;
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
if ('tell' in s) {
|
|
47
|
+
input.tell = s.tell.bind(s);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return input;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
var BufferStream = function(buffer, resizeOk) {
|
|
54
|
+
this.buffer = buffer;
|
|
55
|
+
this.resizeOk = resizeOk;
|
|
56
|
+
this.pos = 0;
|
|
57
|
+
};
|
|
58
|
+
BufferStream.prototype = Object.create(Stream.prototype);
|
|
59
|
+
BufferStream.prototype.writeByte = function(_byte) {
|
|
60
|
+
if (this.resizeOk && this.pos >= this.buffer.length) {
|
|
61
|
+
var newBuffer = Util.makeU8Buffer(this.buffer.length * 2);
|
|
62
|
+
newBuffer.set(this.buffer);
|
|
63
|
+
this.buffer = newBuffer;
|
|
64
|
+
}
|
|
65
|
+
this.buffer[this.pos++] = _byte;
|
|
66
|
+
};
|
|
67
|
+
BufferStream.prototype.getBuffer = function() {
|
|
68
|
+
// trim buffer if needed
|
|
69
|
+
if (this.pos !== this.buffer.length) {
|
|
70
|
+
if (!this.resizeOk)
|
|
71
|
+
throw new TypeError('outputsize does not match decoded input');
|
|
72
|
+
var newBuffer = Util.makeU8Buffer(this.pos);
|
|
73
|
+
newBuffer.set(this.buffer.subarray(0, this.pos));
|
|
74
|
+
this.buffer = newBuffer;
|
|
75
|
+
}
|
|
76
|
+
return this.buffer;
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
/* Take a stream (or not) and an (optional) size, and return an
|
|
80
|
+
* output stream. Return an object with a 'retval' field equal to
|
|
81
|
+
* the output stream (if that was given) or else a pointer at the
|
|
82
|
+
* internal Uint8Array/buffer/array; and a 'stream' field equal to
|
|
83
|
+
* an output stream to use.
|
|
84
|
+
*/
|
|
85
|
+
Util.coerceOutputStream = function(output, size) {
|
|
86
|
+
var r = { stream: output, retval: output };
|
|
87
|
+
if (output) {
|
|
88
|
+
if (typeof(output)==='object' && 'writeByte' in output) {
|
|
89
|
+
return r; /* leave output alone */
|
|
90
|
+
} else if (typeof(size) === 'number') {
|
|
91
|
+
console.assert(size >= 0);
|
|
92
|
+
r.stream = new BufferStream(Util.makeU8Buffer(size), false);
|
|
93
|
+
} else { // output is a buffer
|
|
94
|
+
r.stream = new BufferStream(output, false);
|
|
95
|
+
}
|
|
96
|
+
} else {
|
|
97
|
+
r.stream = new BufferStream(Util.makeU8Buffer(16384), true);
|
|
98
|
+
}
|
|
99
|
+
Object.defineProperty(r, 'retval', {
|
|
100
|
+
get: r.stream.getBuffer.bind(r.stream)
|
|
101
|
+
});
|
|
102
|
+
return r;
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
Util.compressFileHelper = function(magic, guts, suppressFinalByte) {
|
|
106
|
+
return function(inStream, outStream, props) {
|
|
107
|
+
inStream = Util.coerceInputStream(inStream);
|
|
108
|
+
var o = Util.coerceOutputStream(outStream, outStream);
|
|
109
|
+
outStream = o.stream;
|
|
110
|
+
|
|
111
|
+
// write the magic number to identify this file type
|
|
112
|
+
// (it better be ASCII, we're not doing utf-8 conversion)
|
|
113
|
+
var i;
|
|
114
|
+
for (i=0; i<magic.length; i++) {
|
|
115
|
+
outStream.writeByte(magic.charCodeAt(i));
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// if we know the size, write it
|
|
119
|
+
var fileSize;
|
|
120
|
+
if ('size' in inStream && inStream.size >= 0) {
|
|
121
|
+
fileSize = inStream.size;
|
|
122
|
+
} else {
|
|
123
|
+
fileSize = -1; // size unknown
|
|
124
|
+
}
|
|
125
|
+
if (suppressFinalByte) {
|
|
126
|
+
var tmpOutput = Util.coerceOutputStream([]);
|
|
127
|
+
Util.writeUnsignedNumber(tmpOutput.stream, fileSize + 1);
|
|
128
|
+
tmpOutput = tmpOutput.retval;
|
|
129
|
+
for (i=0; i<tmpOutput.length-1; i++) {
|
|
130
|
+
outStream.writeByte(tmpOutput[i]);
|
|
131
|
+
}
|
|
132
|
+
suppressFinalByte = tmpOutput[tmpOutput.length-1];
|
|
133
|
+
} else {
|
|
134
|
+
Util.writeUnsignedNumber(outStream, fileSize + 1);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// call the guts to do the real compression
|
|
138
|
+
guts(inStream, outStream, fileSize, props, suppressFinalByte);
|
|
139
|
+
|
|
140
|
+
return o.retval;
|
|
141
|
+
};
|
|
142
|
+
};
|
|
143
|
+
Util.decompressFileHelper = function(magic, guts) {
|
|
144
|
+
return function(inStream, outStream) {
|
|
145
|
+
inStream = Util.coerceInputStream(inStream);
|
|
146
|
+
|
|
147
|
+
// read the magic number to confirm this file type
|
|
148
|
+
// (it better be ASCII, we're not doing utf-8 conversion)
|
|
149
|
+
var i;
|
|
150
|
+
for (i=0; i<magic.length; i++) {
|
|
151
|
+
if (magic.charCodeAt(i) !== inStream.readByte()) {
|
|
152
|
+
throw new Error("Bad magic");
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// read the file size & create an appropriate output stream/buffer
|
|
157
|
+
var fileSize = Util.readUnsignedNumber(inStream) - 1;
|
|
158
|
+
var o = Util.coerceOutputStream(outStream, fileSize);
|
|
159
|
+
outStream = o.stream;
|
|
160
|
+
|
|
161
|
+
// call the guts to do the real decompression
|
|
162
|
+
guts(inStream, outStream, fileSize);
|
|
163
|
+
|
|
164
|
+
return o.retval;
|
|
165
|
+
};
|
|
166
|
+
};
|
|
167
|
+
// a helper for simple self-test of model encode
|
|
168
|
+
Util.compressWithModel = function(inStream, fileSize, model) {
|
|
169
|
+
var inSize = 0;
|
|
170
|
+
while (inSize !== fileSize) {
|
|
171
|
+
var ch = inStream.readByte();
|
|
172
|
+
if (ch === EOF) {
|
|
173
|
+
model.encode(256); // end of stream;
|
|
174
|
+
break;
|
|
175
|
+
}
|
|
176
|
+
model.encode(ch);
|
|
177
|
+
inSize++;
|
|
178
|
+
}
|
|
179
|
+
};
|
|
180
|
+
// a helper for simple self-test of model decode
|
|
181
|
+
Util.decompressWithModel = function(outStream, fileSize, model) {
|
|
182
|
+
var outSize = 0;
|
|
183
|
+
while (outSize !== fileSize) {
|
|
184
|
+
var ch = model.decode();
|
|
185
|
+
if (ch === 256) {
|
|
186
|
+
break; // end of stream;
|
|
187
|
+
}
|
|
188
|
+
outStream.writeByte(ch);
|
|
189
|
+
outSize++;
|
|
190
|
+
}
|
|
191
|
+
};
|
|
192
|
+
|
|
193
|
+
/** Write a number using a self-delimiting big-endian encoding. */
|
|
194
|
+
Util.writeUnsignedNumber = function(output, n) {
|
|
195
|
+
console.assert(n >= 0);
|
|
196
|
+
var bytes = [], i;
|
|
197
|
+
do {
|
|
198
|
+
bytes.push(n & 0x7F);
|
|
199
|
+
// use division instead of shift to allow encoding numbers up to
|
|
200
|
+
// 2^53
|
|
201
|
+
n = Math.floor( n / 128 );
|
|
202
|
+
} while (n !== 0);
|
|
203
|
+
bytes[0] |= 0x80; // mark end of encoding.
|
|
204
|
+
for (i=bytes.length-1; i>=0; i--) {
|
|
205
|
+
output.writeByte(bytes[i]); // write in big-endian order
|
|
206
|
+
}
|
|
207
|
+
return output;
|
|
208
|
+
};
|
|
209
|
+
|
|
210
|
+
/** Read a number using a self-delimiting big-endian encoding. */
|
|
211
|
+
Util.readUnsignedNumber = function(input) {
|
|
212
|
+
var n = 0, c;
|
|
213
|
+
while (true) {
|
|
214
|
+
c = input.readByte();
|
|
215
|
+
if (c&0x80) { n += (c&0x7F); break; }
|
|
216
|
+
// using + and * instead of << allows decoding numbers up to 2^53
|
|
217
|
+
n = (n + c) * 128;
|
|
218
|
+
}
|
|
219
|
+
return n;
|
|
220
|
+
};
|
|
221
|
+
|
|
222
|
+
// Compatibility thunks for Buffer/TypedArray constructors.
|
|
223
|
+
|
|
224
|
+
var zerofill = function(a) {
|
|
225
|
+
for (var i = 0, len = a.length; i < len; i++) {
|
|
226
|
+
a[i] = 0;
|
|
227
|
+
}
|
|
228
|
+
return a;
|
|
229
|
+
};
|
|
230
|
+
|
|
231
|
+
var fallbackarray = function(size) {
|
|
232
|
+
return zerofill(new Array(size));
|
|
233
|
+
};
|
|
234
|
+
|
|
235
|
+
// Node 0.11.6 - 0.11.10ish don't properly zero fill typed arrays.
|
|
236
|
+
// See https://github.com/joyent/node/issues/6664
|
|
237
|
+
// Try to detect and workaround the bug.
|
|
238
|
+
var ensureZeroed = function id(a) { return a; };
|
|
239
|
+
if ((typeof(process) !== 'undefined') &&
|
|
240
|
+
Array.prototype.some.call(new Uint32Array(128), function(x) {
|
|
241
|
+
return x !== 0;
|
|
242
|
+
})) {
|
|
243
|
+
//console.warn('Working around broken TypedArray');
|
|
244
|
+
ensureZeroed = zerofill;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
/** Portable 8-bit unsigned buffer. */
|
|
248
|
+
Util.makeU8Buffer = (typeof(Uint8Array) !== 'undefined') ? function(size) {
|
|
249
|
+
// Uint8Array ought to be automatically zero-filled
|
|
250
|
+
return ensureZeroed(new Uint8Array(size));
|
|
251
|
+
} : (typeof(Buffer) !== 'undefined') ? function(size) {
|
|
252
|
+
var b = new Buffer(size);
|
|
253
|
+
b.fill(0);
|
|
254
|
+
return b;
|
|
255
|
+
} : fallbackarray;
|
|
256
|
+
|
|
257
|
+
/** Portable 16-bit unsigned buffer. */
|
|
258
|
+
Util.makeU16Buffer = (typeof(Uint16Array) !== 'undefined') ? function(size) {
|
|
259
|
+
// Uint16Array ought to be automatically zero-filled
|
|
260
|
+
return ensureZeroed(new Uint16Array(size));
|
|
261
|
+
} : fallbackarray;
|
|
262
|
+
|
|
263
|
+
/** Portable 32-bit unsigned buffer. */
|
|
264
|
+
Util.makeU32Buffer = (typeof(Uint32Array) !== 'undefined') ? function(size) {
|
|
265
|
+
// Uint32Array ought to be automatically zero-filled
|
|
266
|
+
return ensureZeroed(new Uint32Array(size));
|
|
267
|
+
} : fallbackarray;
|
|
268
|
+
|
|
269
|
+
/** Portable 32-bit signed buffer. */
|
|
270
|
+
Util.makeS32Buffer = (typeof(Int32Array) !== 'undefined') ? function(size) {
|
|
271
|
+
// Int32Array ought to be automatically zero-filled
|
|
272
|
+
return ensureZeroed(new Int32Array(size));
|
|
273
|
+
} : fallbackarray;
|
|
274
|
+
|
|
275
|
+
Util.arraycopy = function(dst, src) {
|
|
276
|
+
console.assert(dst.length >= src.length);
|
|
277
|
+
for (var i = 0, len = src.length; i < len ; i++) {
|
|
278
|
+
dst[i] = src[i];
|
|
279
|
+
}
|
|
280
|
+
return dst;
|
|
281
|
+
};
|
|
282
|
+
|
|
283
|
+
/** Highest bit set in a byte. */
|
|
284
|
+
var bytemsb = [
|
|
285
|
+
0, 1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5,
|
|
286
|
+
5, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
|
|
287
|
+
6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7,
|
|
288
|
+
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
|
|
289
|
+
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
|
|
290
|
+
7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
|
|
291
|
+
8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
|
|
292
|
+
8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
|
|
293
|
+
8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
|
|
294
|
+
8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
|
|
295
|
+
8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8 /* 256 */
|
|
296
|
+
];
|
|
297
|
+
console.assert(bytemsb.length===0x100);
|
|
298
|
+
/** Find last set (most significant bit).
|
|
299
|
+
* @return the last bit set in the argument.
|
|
300
|
+
* <code>fls(0)==0</code> and <code>fls(1)==1</code>. */
|
|
301
|
+
var fls = Util.fls = function(v) {
|
|
302
|
+
console.assert(v>=0);
|
|
303
|
+
if (v > 0xFFFFFFFF) { // use floating-point mojo
|
|
304
|
+
return 32 + fls(Math.floor(v / 0x100000000));
|
|
305
|
+
}
|
|
306
|
+
if ( (v & 0xFFFF0000) !== 0) {
|
|
307
|
+
if ( (v & 0xFF000000) !== 0) {
|
|
308
|
+
return 24 + bytemsb[(v>>>24) & 0xFF];
|
|
309
|
+
} else {
|
|
310
|
+
return 16 + bytemsb[v>>>16];
|
|
311
|
+
}
|
|
312
|
+
} else if ( (v & 0x0000FF00) !== 0) {
|
|
313
|
+
return 8 + bytemsb[v>>>8];
|
|
314
|
+
} else {
|
|
315
|
+
return bytemsb[v];
|
|
316
|
+
}
|
|
317
|
+
};
|
|
318
|
+
/** Returns ceil(log2(n)) */
|
|
319
|
+
Util.log2c = function(v) {
|
|
320
|
+
return (v===0)?-1:fls(v-1);
|
|
321
|
+
};
|
|
322
|
+
|
|
323
|
+
return freeze(Util); // ensure constants are recognized as such.
|
|
324
|
+
});
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
if (typeof define !== 'function') { var define = require('amdefine')(module); }
|
|
2
|
+
define([],function(){
|
|
3
|
+
'use strict';
|
|
4
|
+
|
|
5
|
+
// Object.freeze(), or a thunk if that method is not present in this
|
|
6
|
+
// JavaScript environment.
|
|
7
|
+
|
|
8
|
+
if (Object.freeze) {
|
|
9
|
+
return Object.freeze;
|
|
10
|
+
} else {
|
|
11
|
+
return function(o) { return o; };
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
});
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
if (typeof define !== 'function') { var define = require('amdefine')(module); }
|
|
2
|
+
define(['./lib/freeze','./lib/BitStream','./lib/Stream','./lib/BWT','./lib/Context1Model','./lib/DefSumModel','./lib/FenwickModel','./lib/MTFModel','./lib/NoModel','./lib/Huffman','./lib/RangeCoder','./lib/BWTC','./lib/Bzip2','./lib/Dmc','./lib/Lzjb','./lib/LzjbR','./lib/Lzp3','./lib/PPM','./lib/Simple'], function(freeze,BitStream,Stream,BWT,Context1Model,DefSumModel,FenwickModel,MTFModel,NoModel,Huffman,RangeCoder,BWTC,Bzip2,Dmc,Lzjb,LzjbR,Lzp3,PPM,Simple) {
|
|
3
|
+
'use strict';
|
|
4
|
+
return freeze({
|
|
5
|
+
version: "0.0.1",
|
|
6
|
+
// APIs
|
|
7
|
+
BitStream: BitStream,
|
|
8
|
+
Stream: Stream,
|
|
9
|
+
// transforms
|
|
10
|
+
BWT: BWT,
|
|
11
|
+
// models and coder
|
|
12
|
+
Context1Model: Context1Model,
|
|
13
|
+
DefSumModel: DefSumModel,
|
|
14
|
+
FenwickModel: FenwickModel,
|
|
15
|
+
MTFModel: MTFModel,
|
|
16
|
+
NoModel: NoModel,
|
|
17
|
+
Huffman: Huffman,
|
|
18
|
+
RangeCoder: RangeCoder,
|
|
19
|
+
// compression methods
|
|
20
|
+
BWTC: BWTC,
|
|
21
|
+
Bzip2: Bzip2,
|
|
22
|
+
Dmc: Dmc,
|
|
23
|
+
Lzjb: Lzjb,
|
|
24
|
+
LzjbR: LzjbR,
|
|
25
|
+
Lzp3: Lzp3,
|
|
26
|
+
PPM: PPM,
|
|
27
|
+
Simple: Simple
|
|
28
|
+
});
|
|
29
|
+
});
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "compressjs",
|
|
3
|
+
"version": "1.0.3",
|
|
4
|
+
"author": "C. Scott Ananian",
|
|
5
|
+
"description": "pure JavaScript de/compression (bzip2, etc) for node.js, volo, and the browser.",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"bzip2",
|
|
8
|
+
"compression",
|
|
9
|
+
"decompression"
|
|
10
|
+
],
|
|
11
|
+
"main": "main",
|
|
12
|
+
"repository": {
|
|
13
|
+
"type": "git",
|
|
14
|
+
"url": "https://github.com/cscott/compressjs.git"
|
|
15
|
+
},
|
|
16
|
+
"license": "GPL",
|
|
17
|
+
"bin": {
|
|
18
|
+
"compressjs": "./bin/compressjs"
|
|
19
|
+
},
|
|
20
|
+
"directories": {
|
|
21
|
+
"test": "test"
|
|
22
|
+
},
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"amdefine": "~1.0.0",
|
|
25
|
+
"commander": "~2.8.1"
|
|
26
|
+
},
|
|
27
|
+
"devDependencies": {
|
|
28
|
+
"mocha": "~2.2.5"
|
|
29
|
+
},
|
|
30
|
+
"scripts": {
|
|
31
|
+
"test": "mocha"
|
|
32
|
+
},
|
|
33
|
+
"amd": {},
|
|
34
|
+
"volo": {}
|
|
35
|
+
}
|
package/README.md
CHANGED
|
@@ -81,6 +81,7 @@ Each group/chat has its own:
|
|
|
81
81
|
- workspace folder
|
|
82
82
|
- persisted memory + session state
|
|
83
83
|
- model + thinking settings
|
|
84
|
+
- optional persona/soul (custom role injected into system prompt)
|
|
84
85
|
|
|
85
86
|
Trigger behavior is configurable:
|
|
86
87
|
|
|
@@ -97,6 +98,7 @@ Every agent session comes with built-in tools:
|
|
|
97
98
|
- **Browser** — open, navigate, and manage browser tabs in the admin UI
|
|
98
99
|
- **Notes** — markdown notes organized by category for persistent knowledge
|
|
99
100
|
- **Notify** — send push notifications (ntfy.sh) with priority, tags, and actions
|
|
101
|
+
- **Message** — inter-group messaging lets agents communicate across groups
|
|
100
102
|
|
|
101
103
|
### 🤖 Serious agent controls
|
|
102
104
|
|
|
@@ -133,7 +135,7 @@ Per-chat command controls include:
|
|
|
133
135
|
- Real PTY terminal sessions in the dashboard
|
|
134
136
|
- Sessions survive window close/reopen
|
|
135
137
|
- Label sync + reconnect across views
|
|
136
|
-
-
|
|
138
|
+
- Sandboxed virtual terminal mode (powered by [just-bash](https://justbash.dev/))
|
|
137
139
|
|
|
138
140
|
### ⏰ Scheduler + automation hooks
|
|
139
141
|
|
|
@@ -141,6 +143,12 @@ Per-chat command controls include:
|
|
|
141
143
|
- Attach tasks to specific chat groups
|
|
142
144
|
- Automated prompts executed by the right agent context
|
|
143
145
|
|
|
146
|
+
### 🖼️ Image attachments
|
|
147
|
+
|
|
148
|
+
- Send images in chat via file picker, clipboard paste, or drag-and-drop
|
|
149
|
+
- Thumbnail previews in compose area
|
|
150
|
+
- Telegram inbound photo/document support
|
|
151
|
+
|
|
144
152
|
### 📲 External channels + notifications
|
|
145
153
|
|
|
146
154
|
- Telegram bot integration (DMs + groups)
|
|
@@ -188,6 +196,7 @@ Per-chat command controls include:
|
|
|
188
196
|
- [Modern Monaco](https://github.com/esm-dev/modern-monaco) — code editor
|
|
189
197
|
- [Visual JSON](https://github.com/vercel-labs/visual-json) — schema-aware JSON editor
|
|
190
198
|
- [Xterm.js](https://github.com/xtermjs/xterm.js) and [node-pty](https://github.com/microsoft/node-pty) — terminal
|
|
199
|
+
- [just-bash](https://justbash.dev/) — sandboxed bash for virtual terminal
|
|
191
200
|
- [Geist](https://vercel.com/font) — typography (Sans, Mono, Pixel)
|
|
192
201
|
- [Iconify](https://github.com/iconify/iconify) — icons
|
|
193
202
|
|
package/lib/index.d.mts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "../src/server/entry.ts";
|
package/lib/index.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "../.output/server/index.mjs";
|
package/lib/piclaw.mjs
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { parseArgs } from "node:util";
|
|
3
|
+
import { ansi, isPortOpen, checkSqlite, printBanner, openBrowser } from "./utils.mjs";
|
|
4
|
+
|
|
5
|
+
process.removeAllListeners("warning");
|
|
6
|
+
process.on("warning", (warning) => {
|
|
7
|
+
if (warning.name === "ExperimentalWarning") return;
|
|
8
|
+
console.warn(warning);
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
const { values } = parseArgs({
|
|
12
|
+
options: {
|
|
13
|
+
help: { type: "boolean", short: "h", default: false },
|
|
14
|
+
"no-open": { type: "boolean", default: false },
|
|
15
|
+
"no-kiosk": { type: "boolean", default: false },
|
|
16
|
+
port: { type: "string", short: "p" },
|
|
17
|
+
},
|
|
18
|
+
strict: false,
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
if (values.help) {
|
|
22
|
+
_printHelp();
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const [subCmd, ...args] = process.argv.slice(2).filter((a) => !a.startsWith("-"));
|
|
26
|
+
if (subCmd === "device") {
|
|
27
|
+
await _handleDeviceCommand(...args);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const port = Number(values.port || process.env.PORT || 3737);
|
|
31
|
+
const isWebContainer = process.env.SHELL === "/bin/jsh" || !!process.versions?.webcontainer;
|
|
32
|
+
|
|
33
|
+
let serverUrl;
|
|
34
|
+
if (!isWebContainer && (await isPortOpen(port))) {
|
|
35
|
+
serverUrl = `http://localhost:${port}`;
|
|
36
|
+
console.log(`\x1b[32m✔ PiClaw already running on ${serverUrl}\x1b[0m\n`);
|
|
37
|
+
} else {
|
|
38
|
+
serverUrl = await _startServer(port, isWebContainer);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if (serverUrl && !values["no-open"] && !isWebContainer) {
|
|
42
|
+
openBrowser(serverUrl, { kiosk: !values["no-kiosk"] });
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// --- internal helpers ---
|
|
46
|
+
|
|
47
|
+
function _printHelp() {
|
|
48
|
+
const { bold, dim, cyan } = ansi;
|
|
49
|
+
console.log(`${bold("piclaw")} ${dim("— multi-channel chat bot orchestrator")}
|
|
50
|
+
|
|
51
|
+
${bold("Usage:")} ${cyan("piclaw")} [options]
|
|
52
|
+
${cyan("piclaw")} device approve|revoke <device-id>
|
|
53
|
+
|
|
54
|
+
${bold("Options:")}
|
|
55
|
+
${cyan("-p, --port")} Port to listen on ${dim("(default: 3737, env: PORT)")}
|
|
56
|
+
${cyan("--no-open")} Do not open the browser on start
|
|
57
|
+
${cyan("--no-kiosk")} Disable kiosk mode ${dim("(fullscreen chromeless)")}
|
|
58
|
+
${cyan("-h, --help")} Show this help message
|
|
59
|
+
|
|
60
|
+
${bold("Commands:")}
|
|
61
|
+
${cyan("device approve <id>")} Approve a pending device
|
|
62
|
+
${cyan("device revoke <id>")} Revoke an approved device`);
|
|
63
|
+
process.exit(0);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
async function _handleDeviceCommand(action, deviceId) {
|
|
67
|
+
if (!["approve", "revoke"].includes(action) || !deviceId) {
|
|
68
|
+
console.error("Usage: piclaw device approve|revoke <device-id>");
|
|
69
|
+
process.exit(1);
|
|
70
|
+
}
|
|
71
|
+
const { approveDevice, revokeDevice } = await import("../.output/server/index.mjs");
|
|
72
|
+
const fn = action === "approve" ? approveDevice : revokeDevice;
|
|
73
|
+
const result = await fn(deviceId);
|
|
74
|
+
if (!result) {
|
|
75
|
+
console.error(`\x1b[31m✖ Device ${deviceId} not found or already ${action}d.\x1b[0m`);
|
|
76
|
+
process.exit(1);
|
|
77
|
+
}
|
|
78
|
+
console.log(`\x1b[32m✔ Device ${action}d: ${deviceId}\x1b[0m`);
|
|
79
|
+
process.exit(0);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
async function _startServer(port, isWebContainer) {
|
|
83
|
+
const startTime = performance.now();
|
|
84
|
+
|
|
85
|
+
console.log(
|
|
86
|
+
"\x1b[33m⚠ This project is in private beta. Use at your own risk.\n Feedback → https://pi0.io\x1b[0m\n",
|
|
87
|
+
);
|
|
88
|
+
|
|
89
|
+
if (!("Bun" in globalThis) && !isWebContainer) {
|
|
90
|
+
checkSqlite();
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
process.env.PORT = String(port);
|
|
94
|
+
|
|
95
|
+
const { startServer } = await import("./index.mjs");
|
|
96
|
+
const server = await startServer();
|
|
97
|
+
|
|
98
|
+
printBanner(server.url, startTime);
|
|
99
|
+
return server.url;
|
|
100
|
+
}
|
package/lib/utils.mjs
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { createConnection } from "node:net";
|
|
2
|
+
|
|
3
|
+
export const ansi = {
|
|
4
|
+
bold: (s) => `\x1b[1m${s}\x1b[0m`,
|
|
5
|
+
dim: (s) => `\x1b[2m${s}\x1b[0m`,
|
|
6
|
+
cyan: (s) => `\x1b[36m${s}\x1b[0m`,
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export function isPortOpen(port) {
|
|
10
|
+
return new Promise((resolve) => {
|
|
11
|
+
const conn = createConnection({ port });
|
|
12
|
+
conn.once("connect", () => {
|
|
13
|
+
conn.destroy();
|
|
14
|
+
resolve(true);
|
|
15
|
+
});
|
|
16
|
+
conn.once("error", () => resolve(false));
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export async function checkSqlite() {
|
|
21
|
+
let hasSqlite = false;
|
|
22
|
+
try {
|
|
23
|
+
await import("node:sqlite");
|
|
24
|
+
hasSqlite = true;
|
|
25
|
+
} catch {}
|
|
26
|
+
if (!hasSqlite) {
|
|
27
|
+
try {
|
|
28
|
+
(await import("node:module")).createRequire(import.meta.url)("sqlite3");
|
|
29
|
+
hasSqlite = true;
|
|
30
|
+
} catch {}
|
|
31
|
+
}
|
|
32
|
+
if (!hasSqlite) {
|
|
33
|
+
console.error(
|
|
34
|
+
`\x1b[31m✖ No SQLite backend available.\x1b[0m\n\n` +
|
|
35
|
+
` PiClaw requires \x1b[1m\x1b[36mnode:sqlite\x1b[0m (Node.js ≥ v22.5.0) or \x1b[1m\x1b[36msqlite3\x1b[0m.\n\n` +
|
|
36
|
+
` Current Node.js: \x1b[33m${process.version}\x1b[0m\n` +
|
|
37
|
+
` Fix: upgrade Node.js.`,
|
|
38
|
+
);
|
|
39
|
+
process.exit(1);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export async function printBanner(serverUrl, startTime) {
|
|
44
|
+
const { bold, dim, cyan } = ansi;
|
|
45
|
+
const elapsed = ((performance.now() - startTime) / 1000).toFixed(1);
|
|
46
|
+
|
|
47
|
+
const parsed = new URL(serverUrl);
|
|
48
|
+
const isWildcard = parsed.hostname === "0.0.0.0" || parsed.hostname === "::";
|
|
49
|
+
|
|
50
|
+
let lines = `\n ${bold("PiClaw")} ${dim(`ready in ${elapsed}s`)}\n\n`;
|
|
51
|
+
if (isWildcard) {
|
|
52
|
+
parsed.hostname = "localhost";
|
|
53
|
+
lines += ` ${cyan("➜")} ${bold("Local:")} ${cyan(parsed.href)}\n`;
|
|
54
|
+
const { hostname, networkInterfaces } = await import("node:os");
|
|
55
|
+
const host = hostname();
|
|
56
|
+
if (host) {
|
|
57
|
+
parsed.hostname = host;
|
|
58
|
+
lines += ` ${cyan("➜")} ${bold("Network:")} ${cyan(parsed.href)}\n`;
|
|
59
|
+
}
|
|
60
|
+
for (const addrs of Object.values(networkInterfaces())) {
|
|
61
|
+
for (const addr of addrs) {
|
|
62
|
+
if (addr.internal || addr.family !== "IPv4") continue;
|
|
63
|
+
parsed.hostname = addr.address;
|
|
64
|
+
lines += ` ${cyan("➜")} ${bold("Network:")} ${cyan(parsed.href)}\n`;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
} else {
|
|
68
|
+
lines += ` ${cyan("➜")} ${bold("Local:")} ${cyan(serverUrl)}\n`;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
console.log(lines);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export async function openBrowser(serverUrl, { kiosk = true } = {}) {
|
|
75
|
+
const { exec } = await import("node:child_process");
|
|
76
|
+
const url = new URL(serverUrl);
|
|
77
|
+
if (["::", "127.0.0.1", "localhost"].includes(url.hostname)) {
|
|
78
|
+
url.hostname = "piclaw.localhost";
|
|
79
|
+
}
|
|
80
|
+
const href = url.href;
|
|
81
|
+
const kioskFlag = kiosk ? " --kiosk" : "";
|
|
82
|
+
const platform = process.platform;
|
|
83
|
+
if (platform === "darwin") {
|
|
84
|
+
exec(
|
|
85
|
+
`open -na "Google Chrome" --args --app="${href}"${kioskFlag} || open -na "Safari" "${href}"`,
|
|
86
|
+
);
|
|
87
|
+
} else if (platform === "win32") {
|
|
88
|
+
exec(`start chrome --app="${href}"${kioskFlag} || start msedge --app="${href}"${kioskFlag}`);
|
|
89
|
+
} else {
|
|
90
|
+
const tmpDir = `\${XDG_RUNTIME_DIR:-/tmp}/piclaw-chrome`;
|
|
91
|
+
const chromeFlags = `--user-data-dir="${tmpDir}" --no-first-run --no-default-browser-check${kioskFlag} --app="${href}"`;
|
|
92
|
+
exec(
|
|
93
|
+
`google-chrome-stable ${chromeFlags} 2>/dev/null || google-chrome ${chromeFlags} 2>/dev/null || chromium ${chromeFlags} 2>/dev/null || xdg-open "${href}"`,
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
}
|