total5 0.0.16-4 → 0.0.16-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/changelog.txt +3 -0
- package/cms.js +1 -0
- package/flow-flowstream.js +15 -0
- package/package.json +1 -1
- package/utils.js +59 -0
package/changelog.txt
CHANGED
|
@@ -18,6 +18,9 @@
|
|
|
18
18
|
- added new action methods `$.progress(percentage)` and `ACTION().progress(console.log)` to measure percentage
|
|
19
19
|
- fixed Total error handling
|
|
20
20
|
- improved compiling navigation in the CMS compiler
|
|
21
|
+
- fixed filling of the `template` property in the CMS compiler
|
|
22
|
+
- added a new method `U.aistreamer(on_line, on_message)`
|
|
23
|
+
- added `Flow.edit(proxy_socket_url)` method for the remote editing of the FlowStream
|
|
21
24
|
|
|
22
25
|
========================
|
|
23
26
|
0.0.15
|
package/cms.js
CHANGED
|
@@ -548,6 +548,7 @@ exports.compile = function(html, widgets, used) {
|
|
|
548
548
|
opt.html = body.substring(body.lastIndexOf('~BEG~') + 5, body.lastIndexOf('~END~'));
|
|
549
549
|
opt.config = config || EMPTYOBJECT;
|
|
550
550
|
opt.render = widget.render;
|
|
551
|
+
opt.template = widget.ui ? widget.ui.template : '';
|
|
551
552
|
opt.beg = opt.body.substring(0, opt.body.indexOf('>') + 1);
|
|
552
553
|
opt.end = opt.body.substring(opt.body.lastIndexOf('<'));
|
|
553
554
|
|
package/flow-flowstream.js
CHANGED
|
@@ -96,6 +96,21 @@ Instance.prototype = {
|
|
|
96
96
|
}
|
|
97
97
|
};
|
|
98
98
|
|
|
99
|
+
Instance.prototype.edit = function(proxy_socket_url = 'wss://flow.totaljs.com/{0}/') {
|
|
100
|
+
|
|
101
|
+
let instance = this;
|
|
102
|
+
|
|
103
|
+
if (instance.$remoteclient)
|
|
104
|
+
instance.$remoteclient.destroy();
|
|
105
|
+
|
|
106
|
+
return WEBSOCKETCLIENT(function(client) {
|
|
107
|
+
instance.$remoteclient = client;
|
|
108
|
+
client.connect(proxy_socket_url.format(instance.id));
|
|
109
|
+
Flow.client(instance.flow, client);
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
};
|
|
113
|
+
|
|
99
114
|
Instance.prototype.postMessage = function(msg) {
|
|
100
115
|
if (this.flow.postMessage) {
|
|
101
116
|
// Try & Catch handles unexpected problems with the main process becoming disconnected.
|
package/package.json
CHANGED
package/utils.js
CHANGED
|
@@ -1565,6 +1565,65 @@ exports.streamer2 = function(beg, end, callback, skip, stream) {
|
|
|
1565
1565
|
return exports.streamer(beg, end, callback, skip, stream, true);
|
|
1566
1566
|
};
|
|
1567
1567
|
|
|
1568
|
+
exports.aistreamer = function(online, onmessage) {
|
|
1569
|
+
|
|
1570
|
+
let buffer = Buffer.alloc(0);
|
|
1571
|
+
let date = onmessage != null;
|
|
1572
|
+
let chunks = [null, null];
|
|
1573
|
+
let newline = Buffer.from('\n', 'utf8');
|
|
1574
|
+
let print = '';
|
|
1575
|
+
let obj = null;
|
|
1576
|
+
|
|
1577
|
+
let onmsg = function(msg) {
|
|
1578
|
+
|
|
1579
|
+
// Completions (OpenAI)
|
|
1580
|
+
if (msg.startsWith('data:')) {
|
|
1581
|
+
msg = msg.substring(6);
|
|
1582
|
+
if (msg === '[DONE]')
|
|
1583
|
+
print += '\n';
|
|
1584
|
+
else {
|
|
1585
|
+
obj = msg.parseJSON(date);
|
|
1586
|
+
print += obj.choices?.[0]?.delta?.content || '';
|
|
1587
|
+
}
|
|
1588
|
+
} else {
|
|
1589
|
+
// OLLAMA
|
|
1590
|
+
obj = msg.parseJSON(date);
|
|
1591
|
+
print += obj.message?.content || '';
|
|
1592
|
+
if (obj.done)
|
|
1593
|
+
print += '\n';
|
|
1594
|
+
}
|
|
1595
|
+
|
|
1596
|
+
while (true) {
|
|
1597
|
+
const index = print.indexOf('\n');
|
|
1598
|
+
if (index === -1)
|
|
1599
|
+
break;
|
|
1600
|
+
online(print.substring(0, index));
|
|
1601
|
+
print = print.substring(index + 1);
|
|
1602
|
+
}
|
|
1603
|
+
if (obj && onmessage)
|
|
1604
|
+
onmessage(obj);
|
|
1605
|
+
};
|
|
1606
|
+
|
|
1607
|
+
return function(chunk) {
|
|
1608
|
+
|
|
1609
|
+
chunks[0] = buffer;
|
|
1610
|
+
chunks[1] = chunk;
|
|
1611
|
+
buffer = Buffer.concat(chunks);
|
|
1612
|
+
|
|
1613
|
+
while (true) {
|
|
1614
|
+
let index = buffer.indexOf(newline);
|
|
1615
|
+
if (index === -1)
|
|
1616
|
+
break;
|
|
1617
|
+
let msg = buffer.toString('utf8', 0, index);
|
|
1618
|
+
buffer = buffer.slice(index + 1)
|
|
1619
|
+
if (msg)
|
|
1620
|
+
onmsg(msg);
|
|
1621
|
+
}
|
|
1622
|
+
|
|
1623
|
+
return;
|
|
1624
|
+
};
|
|
1625
|
+
};
|
|
1626
|
+
|
|
1568
1627
|
exports.filestreamer = function(filename, onbuffer, onend, size) {
|
|
1569
1628
|
|
|
1570
1629
|
if (typeof(onend) === 'number') {
|