total5 0.0.16-3 → 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/builders.js +20 -5
- package/changelog.txt +6 -0
- package/cms.js +22 -5
- package/flow-flowstream.js +15 -0
- package/index.js +1 -1
- package/package.json +1 -1
- package/utils.js +59 -0
package/builders.js
CHANGED
|
@@ -153,7 +153,13 @@ Options.prototype.promisify = function(fn, a, b, c) {
|
|
|
153
153
|
});
|
|
154
154
|
};
|
|
155
155
|
|
|
156
|
-
Options.prototype.status = function() {
|
|
156
|
+
Options.prototype.status = function(a, b, c, d) {
|
|
157
|
+
this.status2?.call(this, a, b, c, d);
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
Options.prototype.progress = function(a, b, c, d) {
|
|
161
|
+
this.progress2?.call(this, a, b, c, d);
|
|
162
|
+
};
|
|
157
163
|
|
|
158
164
|
Options.prototype.publish = function(value) {
|
|
159
165
|
var self = this;
|
|
@@ -252,7 +258,7 @@ Options.prototype.callback = Options.prototype.pipe = function(value) {
|
|
|
252
258
|
};
|
|
253
259
|
}
|
|
254
260
|
|
|
255
|
-
self.$callback(self.error.items.length ? self.error : null, value);
|
|
261
|
+
self.$callback.call(self, self.error.items.length ? self.error : null, value);
|
|
256
262
|
};
|
|
257
263
|
|
|
258
264
|
Options.prototype.done = function(arg) {
|
|
@@ -1348,6 +1354,11 @@ ActionCaller.prototype.status = function(fn) {
|
|
|
1348
1354
|
return this;
|
|
1349
1355
|
};
|
|
1350
1356
|
|
|
1357
|
+
ActionCaller.prototype.progress = function(fn) {
|
|
1358
|
+
this.options.progress = fn;
|
|
1359
|
+
return this;
|
|
1360
|
+
};
|
|
1361
|
+
|
|
1351
1362
|
ActionCaller.prototype.exec = function() {
|
|
1352
1363
|
|
|
1353
1364
|
let self = this;
|
|
@@ -1394,6 +1405,7 @@ ActionCaller.prototype.exec = function() {
|
|
|
1394
1405
|
let type = meta.payload || (action.input ? '+' : '-');
|
|
1395
1406
|
let $ = self.$;
|
|
1396
1407
|
|
|
1408
|
+
$.name = action.name;
|
|
1397
1409
|
$.id = action.id;
|
|
1398
1410
|
$.error = self.error;
|
|
1399
1411
|
$.controller = self.controller;
|
|
@@ -1497,7 +1509,10 @@ ActionCaller.prototype.exec = function() {
|
|
|
1497
1509
|
$.payload = payload;
|
|
1498
1510
|
|
|
1499
1511
|
if (self.options.status)
|
|
1500
|
-
$.
|
|
1512
|
+
$.status2 = self.options.status;
|
|
1513
|
+
|
|
1514
|
+
if (self.options.progress)
|
|
1515
|
+
$.progress2 = self.options.progress;
|
|
1501
1516
|
|
|
1502
1517
|
if (action.middleware) {
|
|
1503
1518
|
action.middleware.wait(function(name, next) {
|
|
@@ -1523,9 +1538,9 @@ ActionCaller.prototype.finish = function(value) {
|
|
|
1523
1538
|
if (self.error.length)
|
|
1524
1539
|
$.invalid(self.error);
|
|
1525
1540
|
else
|
|
1526
|
-
$.callback(value === undefined ? self.$.response : value);
|
|
1541
|
+
$.callback.call(self.$, value === undefined ? self.$.response : value);
|
|
1527
1542
|
} else
|
|
1528
|
-
self.options.callback(self.error.length ? self.error : null, value === undefined ? self.$.response : value);
|
|
1543
|
+
self.options.callback.call(self.$, self.error.length ? self.error : null, value === undefined ? self.$.response : value);
|
|
1529
1544
|
|
|
1530
1545
|
self.options.callback = null;
|
|
1531
1546
|
}
|
package/changelog.txt
CHANGED
|
@@ -15,6 +15,12 @@
|
|
|
15
15
|
- exended `Total.download()` by adding `size {Number}` property to the response
|
|
16
16
|
- extended FlowStream by adding the ability to execute Total.js actions
|
|
17
17
|
- added a new global event `ON('flowstream', function(instance) {`
|
|
18
|
+
- added new action methods `$.progress(percentage)` and `ACTION().progress(console.log)` to measure percentage
|
|
19
|
+
- fixed Total error handling
|
|
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
|
|
18
24
|
|
|
19
25
|
========================
|
|
20
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
|
|
|
@@ -575,14 +576,30 @@ exports.compile = function(html, widgets, used) {
|
|
|
575
576
|
let endindex = html.indexOf('</script>', index);
|
|
576
577
|
let endhead = html.indexOf('>', index);
|
|
577
578
|
let head = html.substring(begindex, endhead);
|
|
578
|
-
let
|
|
579
|
+
let uid = head.match(/id=".*?"/i);
|
|
579
580
|
let template = html.substring(html.indexOf('>', endhead) + 1, endindex);
|
|
581
|
+
let name = '';
|
|
580
582
|
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
583
|
+
if (uid && uid[0]) {
|
|
584
|
+
uid = uid[0];
|
|
585
|
+
uid = uid.substring(4, uid.length - 1);
|
|
586
|
+
name = uid.capitalize();
|
|
587
|
+
} else {
|
|
588
|
+
uid = head.match(/name=".*?"/i);
|
|
589
|
+
if (uid && uid[0]) {
|
|
590
|
+
uid = uid[0];
|
|
591
|
+
uid = uid.substring(6, uid.length - 1);
|
|
592
|
+
name = uid.capitalize();
|
|
593
|
+
uid = HASH(uid).toString(36); // Backward compatibility with old CMS
|
|
594
|
+
}
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
if (name) {
|
|
598
|
+
html = html.replace(html.substring(begindex, endindex + 9), '~WIDGET#' + response.tangular.length + '~');
|
|
599
|
+
response.tangular.push({ id: uid, name: name, type: 'nav', template: Tangular.compile(template) });
|
|
600
|
+
}
|
|
585
601
|
|
|
602
|
+
index = begindex;
|
|
586
603
|
}
|
|
587
604
|
|
|
588
605
|
index = 0;
|
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/index.js
CHANGED
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') {
|