total5 0.0.17-7 → 0.0.17-9

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.
File without changes
package/aimodel.js CHANGED
@@ -235,17 +235,167 @@ function createTool(id, name) {
235
235
  };
236
236
  }
237
237
 
238
+ function parseJSON(value) {
239
+ try {
240
+ return JSON.parse(value);
241
+ } catch (e) {
242
+ return null;
243
+ }
244
+ }
245
+
246
+ function createTool(id, name) {
247
+ return {
248
+ id: id || null,
249
+ name: name || null,
250
+ arguments: '',
251
+ input: null
252
+ };
253
+ }
254
+
255
+ function normalize(value) {
256
+
257
+ if (value == null)
258
+ return {};
259
+
260
+ if (typeof value === 'object')
261
+ return value;
262
+
263
+ if (typeof value !== 'string')
264
+ return value;
265
+
266
+ value = value.trim();
267
+
268
+ if (!value)
269
+ return {};
270
+
271
+ const json = parseJSON(value);
272
+
273
+ if (json)
274
+ return json;
275
+
276
+ return value;
277
+ }
278
+
279
+ function parseJSON(value) {
280
+ try {
281
+ return JSON.parse(value);
282
+ } catch (e) {
283
+ return null;
284
+ }
285
+ }
286
+
287
+ function createTool(id, name) {
288
+ return {
289
+ id: id || null,
290
+ name: name || null,
291
+ arguments: '',
292
+ input: null
293
+ };
294
+ }
295
+
296
+ function normalize(value) {
297
+
298
+ if (value == null)
299
+ return {};
300
+
301
+ if (typeof value === 'object')
302
+ return value;
303
+
304
+ if (typeof value !== 'string')
305
+ return value;
306
+
307
+ value = value.trim();
308
+
309
+ if (!value)
310
+ return {};
311
+
312
+ const json = parseJSON(value);
313
+
314
+ if (json)
315
+ return json;
316
+
317
+ return value;
318
+ }
319
+
238
320
  class AIStreamParser {
239
321
 
240
- constructor(provider) {
322
+ constructor(provider, ondata) {
241
323
  this.provider = provider || 'generic';
324
+
242
325
  this.content = '';
326
+ this.thinking = '';
243
327
  this.tools = [];
244
328
  this.reasoning = 'content';
329
+
245
330
  this.buffer = Buffer.alloc(0);
246
331
  this.toolmap = Object.create(null);
332
+
333
+ this.listeners = Object.create(null);
334
+ this.ondata = typeof ondata === 'function' ? ondata : null;
335
+
336
+ this.thinking_signature = null;
337
+ this.thought_signatures = [];
338
+ }
339
+
340
+ // ------------------------------------------------------------
341
+ // Events
342
+ // ------------------------------------------------------------
343
+
344
+ on(type, fn) {
345
+ if (!type || typeof fn !== 'function')
346
+ return this;
347
+
348
+ if (!this.listeners[type])
349
+ this.listeners[type] = [];
350
+
351
+ this.listeners[type].push(fn);
352
+ return this;
247
353
  }
248
354
 
355
+ off(type, fn) {
356
+ const arr = this.listeners[type];
357
+
358
+ if (!arr)
359
+ return this;
360
+
361
+ const index = arr.indexOf(fn);
362
+
363
+ if (index !== -1)
364
+ arr.splice(index, 1);
365
+
366
+ return this;
367
+ }
368
+
369
+ emit(type, data) {
370
+ const event = {
371
+ type,
372
+ ...data
373
+ };
374
+
375
+ if (this.ondata)
376
+ this.ondata(event);
377
+
378
+ const listeners = this.listeners[type];
379
+
380
+ if (listeners) {
381
+ for (const fn of listeners)
382
+ fn(event);
383
+ }
384
+
385
+ const all = this.listeners['*'];
386
+
387
+ if (all) {
388
+ for (const fn of all)
389
+ fn(event);
390
+ }
391
+
392
+ return event;
393
+ }
394
+
395
+ // ------------------------------------------------------------
396
+ // Public API
397
+ // ------------------------------------------------------------
398
+
249
399
  write(chunk) {
250
400
  if (chunk == null)
251
401
  return this.output();
@@ -265,11 +415,11 @@ class AIStreamParser {
265
415
 
266
416
  let index;
267
417
 
268
- while ((index = this.buffer.indexOf(0x0A)) !== -1) { // \n
418
+ while ((index = this.buffer.indexOf(0x0A)) !== -1) {
269
419
  let lineBuffer = this.buffer.subarray(0, index);
270
420
  this.buffer = this.buffer.subarray(index + 1);
271
421
 
272
- // CRLF support: remove \r
422
+ // CRLF support
273
423
  if (lineBuffer.length && lineBuffer[lineBuffer.length - 1] === 0x0D)
274
424
  lineBuffer = lineBuffer.subarray(0, lineBuffer.length - 1);
275
425
 
@@ -311,6 +461,7 @@ class AIStreamParser {
311
461
  return;
312
462
 
313
463
  const json = parseJSON(line);
464
+
314
465
  if (json)
315
466
  this.writeObject(json);
316
467
  }
@@ -318,9 +469,17 @@ class AIStreamParser {
318
469
  end() {
319
470
  if (this.buffer.length)
320
471
  this.processLineBuffer(this.buffer);
472
+
321
473
  this.buffer = Buffer.alloc(0);
322
474
  this.finalizeTools();
323
- return this.output();
475
+
476
+ const output = this.output();
477
+
478
+ this.emit('done', {
479
+ output
480
+ });
481
+
482
+ return output;
324
483
  }
325
484
 
326
485
  writeObject(chunk) {
@@ -328,17 +487,21 @@ class AIStreamParser {
328
487
  case 'ollama':
329
488
  this.parseOllama(chunk);
330
489
  break;
490
+
331
491
  case 'openai_chat':
332
492
  case 'openai':
333
493
  this.parseOpenAI(chunk);
334
494
  break;
495
+
335
496
  case 'openai_responses':
336
497
  this.parseOpenAIresponse(chunk);
337
498
  break;
499
+
338
500
  case 'claude':
339
501
  case 'anthropic':
340
502
  this.parseClaude(chunk);
341
503
  break;
504
+
342
505
  case 'gemini':
343
506
  case 'google':
344
507
  this.parseGemini(chunk);
@@ -348,26 +511,85 @@ class AIStreamParser {
348
511
  this.parseGeneric(chunk);
349
512
  break;
350
513
  }
514
+
351
515
  return this.output();
352
516
  }
353
517
 
518
+ // ------------------------------------------------------------
519
+ // Accumulators
520
+ // ------------------------------------------------------------
521
+
354
522
  addContent(value) {
355
523
  if (!value)
356
524
  return;
525
+
526
+ if (typeof value !== 'string')
527
+ value = String(value);
528
+
357
529
  this.content += value;
530
+
531
+ this.emit('content', {
532
+ delta: value,
533
+ content: this.content,
534
+ reasoning: 'content'
535
+ });
536
+
358
537
  if (!this.tools.length)
359
538
  this.reasoning = 'content';
360
539
  }
361
540
 
541
+ addThinking(value) {
542
+ if (!value)
543
+ return;
544
+
545
+ if (typeof value === 'object') {
546
+
547
+ if (Array.isArray(value)) {
548
+ for (const item of value)
549
+ this.addThinking(item);
550
+ return;
551
+ }
552
+
553
+ if (value.text != null)
554
+ value = value.text;
555
+ else if (value.summary != null)
556
+ value = value.summary;
557
+ else if (value.content != null)
558
+ value = value.content;
559
+ else if (value.value != null)
560
+ value = value.value;
561
+ else
562
+ value = JSON.stringify(value);
563
+ }
564
+
565
+ if (!value)
566
+ return;
567
+
568
+ if (typeof value !== 'string')
569
+ value = String(value);
570
+
571
+ this.thinking += value;
572
+ this.reasoning = 'thinking';
573
+
574
+ this.emit('thinking', {
575
+ delta: value,
576
+ thinking: this.thinking,
577
+ reasoning: 'thinking'
578
+ });
579
+ }
580
+
362
581
  getTool(key, id, name) {
363
582
 
364
583
  key = key || id || name || String(this.tools.length);
365
584
 
366
585
  let tool = this.toolmap[key];
586
+ let isnew = false;
587
+
367
588
  if (!tool) {
368
589
  tool = createTool(id, name);
369
590
  this.toolmap[key] = tool;
370
591
  this.tools.push(tool);
592
+ isnew = true;
371
593
  }
372
594
 
373
595
  if (id)
@@ -378,6 +600,11 @@ class AIStreamParser {
378
600
 
379
601
  this.reasoning = 'tool';
380
602
 
603
+ this.emit(isnew ? 'tool_start' : 'tool_update', {
604
+ tool: this.cloneTool(tool),
605
+ reasoning: 'tool'
606
+ });
607
+
381
608
  return tool;
382
609
  }
383
610
 
@@ -389,10 +616,36 @@ class AIStreamParser {
389
616
  if (typeof value === 'object') {
390
617
  tool.input = value;
391
618
  tool.arguments = JSON.stringify(value);
619
+
620
+ this.emit('tool_arguments', {
621
+ tool: this.cloneTool(tool),
622
+ delta: value,
623
+ arguments: tool.input,
624
+ reasoning: 'tool'
625
+ });
626
+
392
627
  return;
393
628
  }
394
629
 
630
+ if (typeof value !== 'string')
631
+ value = String(value);
632
+
395
633
  tool.arguments += value;
634
+
635
+ this.emit('tool_arguments', {
636
+ tool: this.cloneTool(tool),
637
+ delta: value,
638
+ arguments: tool.arguments,
639
+ reasoning: 'tool'
640
+ });
641
+ }
642
+
643
+ cloneTool(tool) {
644
+ return {
645
+ id: tool.id,
646
+ name: tool.name,
647
+ arguments: tool.input || normalize(tool.arguments)
648
+ };
396
649
  }
397
650
 
398
651
  finalizeTools() {
@@ -404,8 +657,10 @@ class AIStreamParser {
404
657
 
405
658
  output() {
406
659
  this.finalizeTools();
407
- return {
660
+
661
+ const output = {
408
662
  content: this.content,
663
+ thinking: this.thinking,
409
664
  tools: this.tools.map(tool => ({
410
665
  id: tool.id,
411
666
  name: tool.name,
@@ -413,6 +668,14 @@ class AIStreamParser {
413
668
  })),
414
669
  reasoning: this.tools.length ? 'tool' : this.reasoning
415
670
  };
671
+
672
+ if (this.thinking_signature)
673
+ output.thinking_signature = this.thinking_signature;
674
+
675
+ if (this.thought_signatures.length)
676
+ output.thought_signatures = this.thought_signatures;
677
+
678
+ return output;
416
679
  }
417
680
 
418
681
  // ------------------------------------------------------------
@@ -421,34 +684,80 @@ class AIStreamParser {
421
684
 
422
685
  parseOllama(chunk) {
423
686
 
687
+ // Ollama OpenAI-compatible endpoint fallback
688
+ if (chunk.choices) {
689
+ this.parseOpenAI(chunk);
690
+ return;
691
+ }
692
+
424
693
  const message = chunk.message || {};
425
694
 
695
+ // /api/chat thinking
696
+ if (message.thinking)
697
+ this.addThinking(message.thinking);
698
+
699
+ // /api/generate thinking
700
+ if (chunk.thinking)
701
+ this.addThinking(chunk.thinking);
702
+
703
+ // OpenAI-compatible / model-specific reasoning fields
704
+ if (message.reasoning_content)
705
+ this.addThinking(message.reasoning_content);
706
+
707
+ if (message.reasoning)
708
+ this.addThinking(message.reasoning);
709
+
710
+ if (message.reasoning_text)
711
+ this.addThinking(message.reasoning_text);
712
+
713
+ // /api/chat content
426
714
  if (message.content)
427
715
  this.addContent(message.content);
428
716
 
429
- const calls = message.tool_calls || [];
717
+ // /api/generate content
718
+ if (chunk.response)
719
+ this.addContent(chunk.response);
720
+
721
+ const calls = message.tool_calls || chunk.tool_calls || [];
430
722
 
431
723
  for (let i = 0; i < calls.length; i++) {
432
724
  const call = calls[i];
433
- const fn = call.function || {};
725
+ const fn = call.function || call;
434
726
  const key = call.id || fn.name || `ollama_${i}`;
435
727
 
436
728
  const tool = this.getTool(key, call.id, fn.name);
437
729
 
438
730
  if (fn.arguments != null)
439
731
  this.appendToolArguments(tool, fn.arguments);
732
+ else if (fn.args != null)
733
+ this.appendToolArguments(tool, fn.args);
734
+ else if (fn.input != null)
735
+ this.appendToolArguments(tool, fn.input);
440
736
  }
441
737
  }
442
738
 
443
739
  // ------------------------------------------------------------
444
740
  // OpenAI Chat Completions stream
445
741
  // ------------------------------------------------------------
742
+
446
743
  parseOpenAI(chunk) {
447
744
  const choices = chunk.choices || [];
448
745
 
449
746
  for (const choice of choices) {
450
747
  const delta = choice.delta || {};
451
748
 
749
+ if (delta.reasoning_content)
750
+ this.addThinking(delta.reasoning_content);
751
+
752
+ if (delta.reasoning)
753
+ this.addThinking(delta.reasoning);
754
+
755
+ if (delta.thinking)
756
+ this.addThinking(delta.thinking);
757
+
758
+ if (delta.reasoning_text)
759
+ this.addThinking(delta.reasoning_text);
760
+
452
761
  if (delta.content)
453
762
  this.addContent(delta.content);
454
763
 
@@ -473,11 +782,19 @@ class AIStreamParser {
473
782
 
474
783
  parseOpenAIresponse(chunk) {
475
784
  switch (chunk.type) {
785
+
476
786
  case 'response.output_text.delta':
477
787
  case 'response.refusal.delta':
478
788
  this.addContent(chunk.delta);
479
789
  break;
480
790
 
791
+ case 'response.reasoning_summary_text.delta':
792
+ case 'response.reasoning_text.delta':
793
+ case 'response.reasoning_summary.delta':
794
+ case 'response.reasoning.delta':
795
+ this.addThinking(chunk.delta);
796
+ break;
797
+
481
798
  case 'response.function_call_arguments.delta': {
482
799
  const key = chunk.item_id || chunk.call_id || `openai_response_${chunk.output_index || 0}`;
483
800
  const tool = this.getTool(key, chunk.call_id || chunk.item_id, chunk.name);
@@ -489,6 +806,17 @@ class AIStreamParser {
489
806
  case 'response.output_item.added': {
490
807
  const item = chunk.item || {};
491
808
 
809
+ if (item.type === 'reasoning') {
810
+ if (item.summary)
811
+ this.addThinking(item.summary);
812
+
813
+ if (item.content)
814
+ this.addThinking(item.content);
815
+
816
+ if (item.text)
817
+ this.addThinking(item.text);
818
+ }
819
+
492
820
  if (item.type === 'function_call') {
493
821
  const key = item.id || item.call_id;
494
822
  const tool = this.getTool(key, item.call_id || item.id, item.name);
@@ -503,6 +831,17 @@ class AIStreamParser {
503
831
  case 'response.output_item.done': {
504
832
  const item = chunk.item || {};
505
833
 
834
+ if (item.type === 'reasoning') {
835
+ if (item.summary)
836
+ this.addThinking(item.summary);
837
+
838
+ if (item.content)
839
+ this.addThinking(item.content);
840
+
841
+ if (item.text)
842
+ this.addThinking(item.text);
843
+ }
844
+
506
845
  if (item.type === 'function_call') {
507
846
  const key = item.id || item.call_id;
508
847
  const tool = this.getTool(key, item.call_id || item.id, item.name);
@@ -525,6 +864,11 @@ class AIStreamParser {
525
864
  case 'content_block_start': {
526
865
  const block = chunk.content_block || {};
527
866
 
867
+ if (block.type === 'thinking') {
868
+ if (block.thinking)
869
+ this.addThinking(block.thinking);
870
+ }
871
+
528
872
  if (block.type === 'tool_use') {
529
873
  const key = block.id || `claude_${chunk.index || 0}`;
530
874
  const tool = this.getTool(key, block.id, block.name);
@@ -539,6 +883,12 @@ class AIStreamParser {
539
883
  case 'content_block_delta': {
540
884
  const delta = chunk.delta || {};
541
885
 
886
+ if (delta.type === 'thinking_delta')
887
+ this.addThinking(delta.thinking);
888
+
889
+ if (delta.type === 'signature_delta')
890
+ this.thinking_signature = delta.signature;
891
+
542
892
  if (delta.type === 'text_delta')
543
893
  this.addContent(delta.text);
544
894
 
@@ -576,8 +926,15 @@ class AIStreamParser {
576
926
  for (let i = 0; i < parts.length; i++) {
577
927
  const part = parts[i];
578
928
 
579
- if (part.text)
580
- this.addContent(part.text);
929
+ if (part.thoughtSignature)
930
+ this.thought_signatures.push(part.thoughtSignature);
931
+
932
+ if (part.text) {
933
+ if (part.thought)
934
+ this.addThinking(part.text);
935
+ else
936
+ this.addContent(part.text);
937
+ }
581
938
 
582
939
  if (part.functionCall) {
583
940
  const fn = part.functionCall;
@@ -595,6 +952,31 @@ class AIStreamParser {
595
952
  // ------------------------------------------------------------
596
953
 
597
954
  parseGeneric(chunk) {
955
+
956
+ if (chunk.thinking)
957
+ this.addThinking(chunk.thinking);
958
+
959
+ if (chunk.reasoning)
960
+ this.addThinking(chunk.reasoning);
961
+
962
+ if (chunk.reasoning_content)
963
+ this.addThinking(chunk.reasoning_content);
964
+
965
+ if (chunk.reasoning_text)
966
+ this.addThinking(chunk.reasoning_text);
967
+
968
+ if (chunk.message?.thinking)
969
+ this.addThinking(chunk.message.thinking);
970
+
971
+ if (chunk.message?.reasoning)
972
+ this.addThinking(chunk.message.reasoning);
973
+
974
+ if (chunk.message?.reasoning_content)
975
+ this.addThinking(chunk.message.reasoning_content);
976
+
977
+ if (chunk.message?.reasoning_text)
978
+ this.addThinking(chunk.message.reasoning_text);
979
+
598
980
  if (chunk.content)
599
981
  this.addContent(chunk.content);
600
982
 
@@ -622,10 +1004,16 @@ class AIStreamParser {
622
1004
 
623
1005
  reset() {
624
1006
  this.content = '';
1007
+ this.thinking = '';
625
1008
  this.tools = [];
626
1009
  this.reasoning = 'content';
1010
+
627
1011
  this.buffer = Buffer.alloc(0);
628
1012
  this.toolmap = Object.create(null);
1013
+
1014
+ this.thinking_signature = null;
1015
+ this.thought_signatures = [];
1016
+
629
1017
  return this;
630
1018
  }
631
1019
  }
package/builders.js CHANGED
@@ -1339,6 +1339,12 @@ function ActionCaller() {
1339
1339
  setImmediate(ActionCallerExec, self);
1340
1340
  }
1341
1341
 
1342
+ ActionCaller.prototype.config = function(value) {
1343
+ this.options.config = value;
1344
+ return this;
1345
+ };
1346
+
1347
+
1342
1348
  ActionCaller.prototype.debug = function() {
1343
1349
  this.options.debug = true;
1344
1350
  return this;
@@ -1412,6 +1418,20 @@ ActionCaller.prototype.exec = function() {
1412
1418
  $.controller = self.controller;
1413
1419
  $.user = self.options.user;
1414
1420
  $.config = action.config || EMPTYOBJECT;
1421
+ if (self.options.config) {
1422
+
1423
+ if ($.config === EMPTYOBJECT)
1424
+ $.config = {};
1425
+ else {
1426
+ let tmp = $.config;
1427
+ $.config = {};
1428
+ for (let key in tmp)
1429
+ $.config[key] = tmp[key];
1430
+ }
1431
+
1432
+ for (let key in self.options.config)
1433
+ $.config[key] = self.options.config[key];
1434
+ }
1415
1435
 
1416
1436
  action.called++;
1417
1437
 
package/changelog.txt CHANGED
@@ -17,6 +17,12 @@
17
17
  - added `AIMODEL.tool(content, [merge])` method
18
18
  - added `AIPARSER(provider)` method for parsing AI responses
19
19
  - extended `String.prototype` by adding the `String.parseContext()` method to parse a specific text file format
20
+ - added `ACTION().config(obj)` method
21
+ - added a new property `flow.instance.repo = {}` for storing additional data for Flow node instances
22
+ - fixed `Utils.filestreamer()` method
23
+ - improved `Utils.filestreamer()` method by adding percentage
24
+ - fixed sending data to all outputs `$.send(null, [data])` in the FlowStream
25
+ - fixed sending data to all outputs `instance.send(null, [data])` in the FlowStream
20
26
 
21
27
  ========================
22
28
  0.0.16
@@ -9,7 +9,7 @@ if (!global.F)
9
9
 
10
10
  const W = F.Worker;
11
11
  const Fork = F.Child.fork;
12
- const VERSION = 33;
12
+ const VERSION = 34;
13
13
  const NOTIFYPATH = '/notify/';
14
14
 
15
15
  var isFLOWSTREAMWORKER = false;
@@ -1939,6 +1939,7 @@ function MAKEFLOWSTREAM(meta) {
1939
1939
  tmp.offset = com.offset;
1940
1940
  tmp.size = com.size;
1941
1941
  tmp.meta = com.meta;
1942
+ tmp.repo = com.repo;
1942
1943
  tmp.schemaid = com.schemaid;
1943
1944
  tmp.note = com.note;
1944
1945
  tmp.schema = com.schema;
@@ -1994,6 +1995,7 @@ function MAKEFLOWSTREAM(meta) {
1994
1995
  data.design = design;
1995
1996
  data.variables = variables;
1996
1997
  data.sources = sources;
1998
+ data.flowstream = VERSION;
1997
1999
  return data;
1998
2000
  };
1999
2001
 
package/flowstream.js CHANGED
@@ -77,10 +77,10 @@ MP.emit = function(name, a, b, c, d, e, f, g) {
77
77
  if (!self.$events)
78
78
  return self;
79
79
 
80
- var evt = self.$events[name];
80
+ const evt = self.$events[name];
81
81
  if (evt) {
82
82
 
83
- var clean = false;
83
+ let clean = false;
84
84
 
85
85
  for (var e of evt) {
86
86
  if (e.once)
@@ -89,7 +89,7 @@ MP.emit = function(name, a, b, c, d, e, f, g) {
89
89
  }
90
90
 
91
91
  if (clean) {
92
- var index = 0;
92
+ let index = 0;
93
93
  while (true) {
94
94
  if (!evt[index])
95
95
  break;
@@ -116,12 +116,12 @@ MP.emit2 = function(name, a, b, c, d, e, f, g) {
116
116
  if (!self.$events)
117
117
  return self;
118
118
 
119
- var evt = self.$events[name];
119
+ const evt = self.$events[name];
120
120
  if (evt) {
121
121
 
122
- var clean = false;
122
+ let clean = false;
123
123
 
124
- for (var e of evt) {
124
+ for (let e of evt) {
125
125
  if (e.cloned < self.cloned) {
126
126
  if (e.once)
127
127
  clean = true;
@@ -130,9 +130,9 @@ MP.emit2 = function(name, a, b, c, d, e, f, g) {
130
130
  }
131
131
 
132
132
  if (clean) {
133
- var index = 0;
133
+ let index = 0;
134
134
  while (true) {
135
- var e = evt[index];
135
+ let e = evt[index];
136
136
  if (!e)
137
137
  break;
138
138
  if (e.cloned < self.cloned) {
@@ -151,10 +151,10 @@ MP.emit2 = function(name, a, b, c, d, e, f, g) {
151
151
  };
152
152
 
153
153
  MP.on = function(name, fn, once) {
154
- var self = this;
154
+ const self = this;
155
155
  if (!self.$events)
156
156
  self.$events = {};
157
- var obj = { cloned: self.cloned, fn: fn, once: once };
157
+ const obj = { cloned: self.cloned, fn: fn, once: once };
158
158
  if (self.$events[name])
159
159
  self.$events[name].push(obj);
160
160
  else
@@ -167,7 +167,7 @@ MP.once = function(name, fn) {
167
167
  };
168
168
 
169
169
  MP.off = function(name, fn) {
170
- var self = this;
170
+ const self = this;
171
171
 
172
172
  if (!name) {
173
173
  delete self.$events;
@@ -175,7 +175,7 @@ MP.off = function(name, fn) {
175
175
  }
176
176
 
177
177
  if (self.$events) {
178
- var evt = self.$events[name];
178
+ let evt = self.$events[name];
179
179
  if (evt) {
180
180
  if (fn) {
181
181
  evt = evt.remove(n => n.fn === fn);
@@ -189,8 +189,9 @@ MP.off = function(name, fn) {
189
189
 
190
190
  MP.clone = function() {
191
191
 
192
- var self = this;
193
- var obj = new Message();
192
+ const self = this;
193
+ const obj = new Message();
194
+
194
195
  obj.previd = self.id;
195
196
  obj.$events = self.$events;
196
197
  obj.duration = self.duration;
@@ -218,9 +219,9 @@ MP.clone = function() {
218
219
  obj.ref = self.ref;
219
220
 
220
221
  if (obj.$events && obj.$events.timeout) {
221
- var index = 0;
222
+ let index = 0;
222
223
  while (true) {
223
- var e = obj.$events.timeout[index];
224
+ let e = obj.$events.timeout[index];
224
225
  if (e) {
225
226
  if ((e.cloned + 1) < obj.cloned)
226
227
  obj.$events.timeout.splice(index, 1);
@@ -263,9 +264,9 @@ MP.throw = function(a, b, c, d) {
263
264
  function variables(str, data, encoding) {
264
265
 
265
266
  if (typeof(str) === 'object') {
266
- var obj = {};
267
- for (var key in str) {
268
- var val = str[key];
267
+ const obj = {};
268
+ for (let key in str) {
269
+ let val = str[key];
269
270
  if (typeof(val) === 'string')
270
271
  obj[key] = variables.call(this, val, data, encoding);
271
272
  else
@@ -277,16 +278,16 @@ function variables(str, data, encoding) {
277
278
  if (typeof(str) !== 'string' || str.indexOf('{') === -1)
278
279
  return str;
279
280
 
280
- var main = this.main ? this.main : this;
281
+ const main = this.main ? this.main : this;
281
282
 
282
283
  if (data == null || data == true)
283
284
  data = this;
284
285
 
285
286
  return str.replace(REG_ARGS, function(text) {
286
287
 
287
- var l = text[1] === '{' ? 2 : 1;
288
- var key = text.substring(l, text.length - l).trim();
289
- var val = null;
288
+ const l = text[1] === '{' ? 2 : 1;
289
+ const key = text.substring(l, text.length - l).trim();
290
+ let val = null;
290
291
 
291
292
  if (main.variables)
292
293
  val = main.variables[key];
@@ -303,7 +304,7 @@ function variables(str, data, encoding) {
303
304
  val = val.substring(0, val.length - 1);
304
305
  }
305
306
 
306
- var customencoding = typeof(encoding) === 'function';
307
+ const customencoding = typeof(encoding) === 'function';
307
308
 
308
309
  if (!val && data != null && typeof(data) === 'object')
309
310
  val = key.includes('.') ? F.TUtils.get(data, key) : data[key];
@@ -369,7 +370,7 @@ MP.send = function(outputindex, data, clonedata) {
369
370
 
370
371
  if (self.instance.connections) {
371
372
  for (let key in self.instance.connections)
372
- count += self.send(key);
373
+ count += self.send(key, data, clonedata);
373
374
  }
374
375
 
375
376
  if (!count)
@@ -781,7 +782,7 @@ FP.inc = function(num) {
781
782
 
782
783
  FP.cleanforce = function() {
783
784
 
784
- var self = this;
785
+ const self = this;
785
786
 
786
787
  if (self.cleantimeout) {
787
788
  clearTimeout(self.cleantimeout);
@@ -791,21 +792,21 @@ FP.cleanforce = function() {
791
792
  if (!self.meta)
792
793
  return self;
793
794
 
794
- for (var key in self.meta.flow) {
795
+ for (let key in self.meta.flow) {
795
796
  if (!BLACKLISTID[key]) {
796
- var instance = self.meta.flow[key];
797
+ const instance = self.meta.flow[key];
797
798
  if (instance.connections) {
798
799
 
799
- for (var key2 in instance.connections) {
800
+ for (let key2 in instance.connections) {
800
801
 
801
- var conns = instance.connections[key2];
802
- var rem = {};
802
+ const conns = instance.connections[key2];
803
+ const rem = {};
803
804
 
804
- for (var conn of conns) {
805
+ for (let conn of conns) {
805
806
  if (conn) {
806
- var target = self.meta.flow[conn.id];
807
+ const target = self.meta.flow[conn.id];
807
808
  if (target) {
808
- var com = self.meta.components[target.component];
809
+ let com = self.meta.components[target.component];
809
810
  if (com) {
810
811
  if (self.strict) {
811
812
  if (target.inputs) {
@@ -821,7 +822,7 @@ FP.cleanforce = function() {
821
822
  }
822
823
  }
823
824
 
824
- var arr = conns.remove(c => c == null || rem[c.id] === 1);
825
+ const arr = conns.remove(c => c == null || rem[c.id] === 1);
825
826
  if (arr.length)
826
827
  instance.connections[key2] = arr;
827
828
  else
@@ -831,10 +832,10 @@ FP.cleanforce = function() {
831
832
  }
832
833
  }
833
834
 
834
- var paused = self.meta.flow.paused;
835
+ const paused = self.meta.flow.paused;
835
836
  if (paused) {
836
- for (var key in paused) {
837
- var arr = key.split(D);
837
+ for (let key in paused) {
838
+ const arr = key.split(D);
838
839
  // arr[0] type
839
840
  // arr[1] id
840
841
  // arr[2] index
@@ -987,7 +988,6 @@ function newmiddleware(callback) {
987
988
  return self;
988
989
  }
989
990
 
990
-
991
991
  function newmessage(data) {
992
992
  var self = this;
993
993
  var msg = new Message();
@@ -1047,40 +1047,48 @@ FP.ontrigger = function(outputindex, data, controller, events) {
1047
1047
 
1048
1048
  // this == instance
1049
1049
 
1050
- var schema = this;
1051
- var self = schema.main;
1052
- var count = 0;
1050
+ const schema = this;
1051
+ const self = schema.main;
1052
+ let count = 0;
1053
1053
 
1054
1054
  if (self.paused)
1055
1055
  return count;
1056
1056
 
1057
1057
  if (schema && schema.ready && schema.component && schema.connections) {
1058
- var instance = self.meta.components[schema.component];
1058
+
1059
+ const instance = self.meta.components[schema.component];
1060
+
1061
+ if (outputindex == null) {
1062
+ for (let key in schema.connections)
1063
+ count += schema.send(key, data, controller, events);
1064
+ return count;
1065
+ }
1066
+
1059
1067
  if (instance && instance.connected && !instance.disabled && self.$can(false, schema.id, outputindex)) {
1060
- var conn = schema.connections[outputindex];
1068
+ const conn = schema.connections[outputindex];
1061
1069
  if (conn && conn.length) {
1062
1070
 
1063
- var ts = Date.now();
1064
- for (var i = 0; i < conn.length; i++) {
1071
+ const ts = Date.now();
1072
+ for (let i = 0; i < conn.length; i++) {
1065
1073
 
1066
- var m = conn[i];
1067
- var target = self.meta.flow[m.id];
1074
+ const m = conn[i];
1075
+ const target = self.meta.flow[m.id];
1068
1076
 
1069
1077
  if (!target || (!target.message && !target['message_' + m.index]) || !self.$can(true, m.id, m.index))
1070
1078
  continue;
1071
1079
 
1072
- var com = self.meta.components[target.component];
1080
+ const com = self.meta.components[target.component];
1073
1081
  if (!com)
1074
1082
  continue;
1075
1083
 
1076
1084
  if (target.isdestroyed || (data && data.instance && data.instance.isdestroyed))
1077
1085
  continue;
1078
1086
 
1079
- var ismessage = data instanceof Message;
1087
+ const ismessage = data instanceof Message;
1080
1088
  if (ismessage && m.color && data.color && data.color !== m.color)
1081
1089
  continue;
1082
1090
 
1083
- var message = ismessage ? data.clone() : new Message();
1091
+ let message = ismessage ? data.clone() : new Message();
1084
1092
 
1085
1093
  if (ismessage) {
1086
1094
 
@@ -1396,7 +1404,7 @@ FP.use = function(schema, callback, reinit) {
1396
1404
 
1397
1405
  FP._use = function(schema, callback, reinit, insert) {
1398
1406
 
1399
- var self = this;
1407
+ let self = this;
1400
1408
 
1401
1409
  if (self.loading) {
1402
1410
  setTimeout(use, 200, self, schema, callback, reinit, insert);
@@ -1409,7 +1417,7 @@ FP._use = function(schema, callback, reinit, insert) {
1409
1417
  schema = F.TUtils.clone(schema);
1410
1418
 
1411
1419
  if (typeof(callback) === 'boolean') {
1412
- var tmp = reinit;
1420
+ let tmp = reinit;
1413
1421
  reinit = callback;
1414
1422
  callback = tmp;
1415
1423
  }
@@ -1418,12 +1426,12 @@ FP._use = function(schema, callback, reinit, insert) {
1418
1426
  // schema.COMPONENT_ID.config = {};
1419
1427
  // schema.COMPONENT_ID.connections = { '0': [{ id: 'COMPONENT_ID', index: '2' }] }
1420
1428
 
1421
- var err = new F.ErrorBuilder();
1429
+ const err = new F.ErrorBuilder();
1422
1430
 
1423
1431
  if (schema) {
1424
1432
 
1425
- var keys = Object.keys(schema);
1426
- var ts = Date.now();
1433
+ const keys = Object.keys(schema);
1434
+ const ts = Date.now();
1427
1435
 
1428
1436
  if (!insert) {
1429
1437
  if (self.meta.flow.paused)
@@ -1445,9 +1453,9 @@ FP._use = function(schema, callback, reinit, insert) {
1445
1453
  return;
1446
1454
  }
1447
1455
 
1448
- var current = self.meta.flow[key];
1449
- var instance = schema[key];
1450
- var component = instance.component ? self.meta.components[instance.component] : null;
1456
+ const current = self.meta.flow[key];
1457
+ const instance = schema[key];
1458
+ const component = instance.component ? self.meta.components[instance.component] : null;
1451
1459
 
1452
1460
  // Component not found
1453
1461
  if (!component) {
@@ -1469,11 +1477,11 @@ FP._use = function(schema, callback, reinit, insert) {
1469
1477
  return;
1470
1478
  }
1471
1479
 
1472
- var fi = self.meta.flow[key];
1480
+ const fi = self.meta.flow[key];
1473
1481
 
1474
1482
  if (!fi || reinit) {
1475
1483
  self.meta.flow[key] = instance;
1476
- var tmp = self.initcomponent(key, component);
1484
+ let tmp = self.initcomponent(key, component);
1477
1485
  if (tmp) {
1478
1486
  tmp.ts = ts;
1479
1487
  tmp.newbie = true;
@@ -1486,6 +1494,13 @@ FP._use = function(schema, callback, reinit, insert) {
1486
1494
  fi.size = instance.size;
1487
1495
  fi.tab = instance.tab;
1488
1496
  fi.ts = ts;
1497
+
1498
+ // From the view of the designer is the "repo" not visible
1499
+ if (instance.repo)
1500
+ fi.repo = instance.repo;
1501
+ else if (!fi.repo)
1502
+ fi.repo = {};
1503
+
1489
1504
  if (JSON.stringify(fi.config) !== JSON.stringify(instance.config)) {
1490
1505
  F.TUtils.extend(fi.config, instance.config);
1491
1506
  fi.configure && fi.configure(fi.config);
@@ -1499,9 +1514,9 @@ FP._use = function(schema, callback, reinit, insert) {
1499
1514
  }, function() {
1500
1515
 
1501
1516
  if (!insert) {
1502
- for (var key in self.meta.flow) {
1517
+ for (let key in self.meta.flow) {
1503
1518
  if (!BLACKLISTID[key]) {
1504
- var instance = self.meta.flow[key];
1519
+ const instance = self.meta.flow[key];
1505
1520
  if (instance.ts !== ts) {
1506
1521
  instance.ready = false;
1507
1522
  instance.isdestroyed = true;
@@ -1519,8 +1534,8 @@ FP._use = function(schema, callback, reinit, insert) {
1519
1534
  }
1520
1535
  }
1521
1536
 
1522
- for (var key in self.meta.flow) {
1523
- var instance = self.meta.flow[key];
1537
+ for (let key in self.meta.flow) {
1538
+ const instance = self.meta.flow[key];
1524
1539
  if (instance.newbie) {
1525
1540
  if (instance.init) {
1526
1541
  try {
@@ -1541,7 +1556,6 @@ FP._use = function(schema, callback, reinit, insert) {
1541
1556
  }
1542
1557
 
1543
1558
  self.inc(-1);
1544
-
1545
1559
  self.cleanforce();
1546
1560
  self.$events.schema && self.emit('schema', self.meta.flow);
1547
1561
  callback && callback(err.length ? err : null);
@@ -1559,8 +1573,8 @@ FP._use = function(schema, callback, reinit, insert) {
1559
1573
 
1560
1574
  FP.initcomponent = function(key, component) {
1561
1575
 
1562
- var self = this;
1563
- var instance = self.meta.flow[key];
1576
+ const self = this;
1577
+ const instance = self.meta.flow[key];
1564
1578
 
1565
1579
  if (instance.ready) {
1566
1580
 
@@ -1579,6 +1593,10 @@ FP.initcomponent = function(key, component) {
1579
1593
  instance.isinstance = true;
1580
1594
  instance.stats = { pending: 0, input: 0, output: 0, duration: 0, destroyed: 0 };
1581
1595
  instance.cache = {};
1596
+
1597
+ if (!instance.repo)
1598
+ instance.repo = {};
1599
+
1582
1600
  instance.id = key;
1583
1601
  instance.module = component;
1584
1602
  instance.ready = false;
@@ -1588,7 +1606,7 @@ FP.initcomponent = function(key, component) {
1588
1606
  delete instance.options;
1589
1607
  }
1590
1608
 
1591
- var tmp = component.config;
1609
+ let tmp = component.config;
1592
1610
  if (tmp)
1593
1611
  instance.config = instance.config ? F.TUtils.extend(F.TUtils.clone(tmp), instance.config) : F.TUtils.clone(tmp);
1594
1612
 
@@ -1877,10 +1895,10 @@ FP.find = function(id) {
1877
1895
  };
1878
1896
 
1879
1897
  FP.send = function(path, body) {
1880
- var self = this;
1898
+ const self = this;
1881
1899
  if (!self.paused && self.meta && self.meta.flow) {
1882
1900
  path = path.split(D);
1883
- var instance = self.meta.flow[path[0]];
1901
+ const instance = self.meta.flow[path[0]];
1884
1902
  if (instance)
1885
1903
  instance.send(path[1], body);
1886
1904
  return !!instance;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "total5",
3
- "version": "0.0.17-7",
3
+ "version": "0.0.17-9",
4
4
  "description": "Total.js framework v5",
5
5
  "main": "index.js",
6
6
  "directories": {
package/utils.js CHANGED
@@ -1627,30 +1627,49 @@ exports.aistreamer = function(online, onmessage) {
1627
1627
  };
1628
1628
  };
1629
1629
 
1630
- exports.filestreamer = function(filename, onbuffer, onend, size) {
1630
+ exports.filestreamer = function(filename, onbuffer, onend, size = 1024 * 16, offset = 0) {
1631
1631
 
1632
1632
  if (typeof(onend) === 'number') {
1633
1633
  size = onend;
1634
1634
  onend = null;
1635
1635
  }
1636
1636
 
1637
- var Fd = null;
1637
+ let Fd = null;
1638
+ let Stat = null;
1638
1639
 
1639
- var read = function(offset) {
1640
- var buffer = Buffer.alloc(size || (1024 * 16));
1640
+ const read = function(offset) {
1641
+ const buffer = Buffer.alloc(size);
1641
1642
  Total.Fs.read(Fd, buffer, 0, buffer.length, offset, function(err, bytes) {
1642
1643
  if (err || !bytes) {
1643
- onend && onend(err);
1644
1644
  Total.Fs.close(Fd, NOOP);
1645
+ onend && onend(err);
1645
1646
  } else {
1646
- onbuffer(buffer.length !== read ? buffer.slice(0, bytes) : buffer, next => read(offset + bytes));
1647
+ const buff = buffer.length !== read ? buffer.slice(0, bytes) : buffer;
1648
+ Stat.read += buff.length;
1649
+ onbuffer(buff, function(stop) {
1650
+ if (stop === true) {
1651
+ Total.Fs.close(Fd, NOOP);
1652
+ onend && onend();
1653
+ } else
1654
+ read(offset + bytes);
1655
+ }, (Stat.read * 100) / Stat.size);
1647
1656
  }
1648
1657
  });
1649
1658
  };
1650
1659
 
1651
- Total.Fs.open(filename, function(err, fd) {
1652
- Fd = fd;
1653
- read(0);
1660
+ Total.Fs.lstat(filename, function(err, stat) {
1661
+
1662
+ if (err) {
1663
+ onend && onend(err);
1664
+ return;
1665
+ }
1666
+
1667
+ Stat = stat;
1668
+ Total.Fs.open(filename, function(err, fd) {
1669
+ Fd = fd;
1670
+ Stat.read = offset;
1671
+ read(offset);
1672
+ });
1654
1673
  });
1655
1674
 
1656
1675
  };
@@ -6339,7 +6358,7 @@ function jsonschemaaitool(name) {
6339
6358
  let required = t.required;
6340
6359
  for (let key in t.properties) {
6341
6360
  let prop = t.properties[key];
6342
- properties[key] = { type: prop.type, description: t.errors[key] };
6361
+ properties[key] = { type: prop.type, description: t.errors ? (t.errors[key] || '') : '' };
6343
6362
  }
6344
6363
  return {
6345
6364
  type: 'function',