@workglow/util 0.0.121 → 0.0.123

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.
Files changed (82) hide show
  1. package/dist/browser.js +232 -2098
  2. package/dist/browser.js.map +6 -25
  3. package/dist/bun.js +236 -2099
  4. package/dist/bun.js.map +6 -25
  5. package/dist/common.d.ts +0 -15
  6. package/dist/common.d.ts.map +1 -1
  7. package/dist/compress-browser.d.ts +7 -0
  8. package/dist/compress-browser.d.ts.map +1 -0
  9. package/dist/compress-browser.js +18 -0
  10. package/dist/compress-browser.js.map +10 -0
  11. package/dist/compress-node.d.ts +7 -0
  12. package/dist/compress-node.d.ts.map +1 -0
  13. package/dist/compress-node.js +25 -0
  14. package/dist/compress-node.js.map +10 -0
  15. package/dist/credentials/ChainedCredentialStore.d.ts.map +1 -1
  16. package/dist/credentials/EnvCredentialStore.d.ts.map +1 -1
  17. package/dist/credentials/InMemoryCredentialStore.d.ts.map +1 -1
  18. package/dist/di/Container.d.ts.map +1 -1
  19. package/dist/di/ServiceRegistry.d.ts.map +1 -1
  20. package/dist/events/EventEmitter.d.ts.map +1 -1
  21. package/dist/graph/directedAcyclicGraph.d.ts.map +1 -1
  22. package/dist/graph/directedGraph.d.ts.map +1 -1
  23. package/dist/graph/errors.d.ts.map +1 -1
  24. package/dist/graph/graph.d.ts.map +1 -1
  25. package/dist/graph-entry.d.ts +7 -0
  26. package/dist/graph-entry.d.ts.map +1 -0
  27. package/dist/graph-entry.js +539 -0
  28. package/dist/graph-entry.js.map +15 -0
  29. package/dist/logging/ConsoleLogger.d.ts.map +1 -1
  30. package/dist/logging/NullLogger.d.ts.map +1 -1
  31. package/dist/media-browser.d.ts +8 -0
  32. package/dist/media-browser.d.ts.map +1 -0
  33. package/dist/media-browser.js +73 -0
  34. package/dist/media-browser.js.map +11 -0
  35. package/dist/media-node.d.ts +8 -0
  36. package/dist/media-node.d.ts.map +1 -0
  37. package/dist/media-node.js +50 -0
  38. package/dist/media-node.js.map +11 -0
  39. package/dist/node.js +246 -2108
  40. package/dist/node.js.map +6 -25
  41. package/dist/schema-entry.d.ts +17 -0
  42. package/dist/schema-entry.d.ts.map +1 -0
  43. package/dist/schema-entry.js +774 -0
  44. package/dist/schema-entry.js.map +18 -0
  45. package/dist/telemetry/ConsoleTelemetryProvider.d.ts.map +1 -1
  46. package/dist/telemetry/NoopTelemetryProvider.d.ts.map +1 -1
  47. package/dist/telemetry/OTelTelemetryProvider.d.ts.map +1 -1
  48. package/dist/types.d.ts +0 -3
  49. package/dist/types.d.ts.map +1 -1
  50. package/dist/utilities/BaseError.d.ts.map +1 -1
  51. package/dist/vector/Tensor.d.ts +1 -1
  52. package/dist/vector/Tensor.d.ts.map +1 -1
  53. package/dist/vector/TypedArray.d.ts +4 -4
  54. package/dist/vector/TypedArray.d.ts.map +1 -1
  55. package/dist/worker/Worker.browser.d.ts +6 -1
  56. package/dist/worker/Worker.browser.d.ts.map +1 -1
  57. package/dist/worker/Worker.bun.d.ts +6 -1
  58. package/dist/worker/Worker.bun.d.ts.map +1 -1
  59. package/dist/worker/Worker.node.d.ts +6 -1
  60. package/dist/worker/Worker.node.d.ts.map +1 -1
  61. package/dist/worker/WorkerManager.d.ts +7 -1
  62. package/dist/worker/WorkerManager.d.ts.map +1 -1
  63. package/dist/worker/{WorkerServer.d.ts → WorkerServerBase.d.ts} +5 -4
  64. package/dist/worker/WorkerServerBase.d.ts.map +1 -0
  65. package/dist/worker-browser.js +894 -0
  66. package/dist/worker-browser.js.map +19 -0
  67. package/dist/worker-bun.js +895 -0
  68. package/dist/worker-bun.js.map +19 -0
  69. package/dist/worker-entry.d.ts +25 -0
  70. package/dist/worker-entry.d.ts.map +1 -0
  71. package/dist/worker-node.js +914 -0
  72. package/dist/worker-node.js.map +19 -0
  73. package/package.json +59 -19
  74. package/dist/mcp/McpAuthProvider.d.ts +0 -70
  75. package/dist/mcp/McpAuthProvider.d.ts.map +0 -1
  76. package/dist/mcp/McpAuthTypes.d.ts +0 -218
  77. package/dist/mcp/McpAuthTypes.d.ts.map +0 -1
  78. package/dist/mcp/McpClientUtil.browser.d.ts +0 -198
  79. package/dist/mcp/McpClientUtil.browser.d.ts.map +0 -1
  80. package/dist/mcp/McpClientUtil.node.d.ts +0 -222
  81. package/dist/mcp/McpClientUtil.node.d.ts.map +0 -1
  82. package/dist/worker/WorkerServer.d.ts.map +0 -1
package/dist/browser.js CHANGED
@@ -430,975 +430,6 @@ class BaseError {
430
430
  return `${this.name}: ${this.message}`;
431
431
  }
432
432
  }
433
-
434
- // src/graph/errors.ts
435
- class NodeAlreadyExistsError extends BaseError {
436
- static type = "NodeAlreadyExistsError";
437
- newNode;
438
- oldNode;
439
- identity;
440
- constructor(newNode, oldNode, identity) {
441
- super(`${JSON.stringify(newNode)} shares an identity (${String(identity)}) with ${JSON.stringify(oldNode)}`);
442
- this.newNode = newNode;
443
- this.oldNode = oldNode;
444
- this.identity = identity;
445
- this.name = "NodeAlreadyExistsError";
446
- Object.setPrototypeOf(this, NodeAlreadyExistsError.prototype);
447
- }
448
- }
449
-
450
- class NodeDoesntExistError extends BaseError {
451
- static type = "NodeDoesntExistError";
452
- identity;
453
- constructor(identity) {
454
- super(`A node with identity ${String(identity)} doesn't exist in the graph`);
455
- this.identity = identity;
456
- this.name = "NodeDoesntExistError";
457
- Object.setPrototypeOf(this, NodeDoesntExistError.prototype);
458
- }
459
- }
460
-
461
- class CycleError extends BaseError {
462
- static type = "CycleError";
463
- constructor(message) {
464
- super(message);
465
- this.name = "CycleError";
466
- Object.setPrototypeOf(this, CycleError.prototype);
467
- }
468
- }
469
-
470
- // src/graph/graph.ts
471
- class Graph {
472
- nodes;
473
- adjacency;
474
- nodeIdentity;
475
- edgeIdentity;
476
- constructor(nodeIdentity, edgeIdentity) {
477
- this.nodes = new Map;
478
- this.adjacency = [];
479
- this.nodeIdentity = nodeIdentity;
480
- this.edgeIdentity = edgeIdentity;
481
- }
482
- events = new EventEmitter;
483
- on(name, fn) {
484
- this.events.on.call(this.events, name, fn);
485
- }
486
- off(name, fn) {
487
- this.events.off.call(this.events, name, fn);
488
- }
489
- emit(name, ...args) {
490
- this.events.emit(name, ...args);
491
- }
492
- insert(node) {
493
- const id = this.nodeIdentity(node);
494
- const isOverwrite = this.nodes.has(id);
495
- if (isOverwrite) {
496
- throw new NodeAlreadyExistsError(node, this.nodes.get(id), id);
497
- }
498
- this.nodes.set(id, node);
499
- this.adjacency.map((adj) => adj.push(null));
500
- this.adjacency.push(new Array(this.adjacency.length + 1).fill(null));
501
- this.emit("node-added", id);
502
- return id;
503
- }
504
- replace(node) {
505
- const id = this.nodeIdentity(node);
506
- const isOverwrite = this.nodes.has(id);
507
- if (!isOverwrite) {
508
- throw new NodeDoesntExistError(id);
509
- }
510
- this.nodes.set(id, node);
511
- this.emit("node-replaced", id);
512
- }
513
- upsert(node) {
514
- const id = this.nodeIdentity(node);
515
- const isOverwrite = this.nodes.has(id);
516
- this.nodes.set(id, node);
517
- if (!isOverwrite) {
518
- this.adjacency.map((adj) => adj.push(null));
519
- this.adjacency.push(new Array(this.adjacency.length + 1).fill(null));
520
- this.emit("node-added", id);
521
- } else {
522
- this.emit("node-replaced", id);
523
- }
524
- return id;
525
- }
526
- addEdge(node1Identity, node2Identity, edge) {
527
- if (edge === undefined) {
528
- edge = true;
529
- }
530
- const node1Exists = this.nodes.has(node1Identity);
531
- const node2Exists = this.nodes.has(node2Identity);
532
- if (!node1Exists) {
533
- throw new NodeDoesntExistError(node1Identity);
534
- }
535
- if (!node2Exists) {
536
- throw new NodeDoesntExistError(node2Identity);
537
- }
538
- const node1Index = Array.from(this.nodes.keys()).indexOf(node1Identity);
539
- const node2Index = Array.from(this.nodes.keys()).indexOf(node2Identity);
540
- if (this.adjacency[node1Index][node2Index] === null) {
541
- this.adjacency[node1Index][node2Index] = [edge];
542
- } else {
543
- if (!this.adjacency[node1Index][node2Index].includes(edge)) {
544
- this.adjacency[node1Index][node2Index].push(edge);
545
- }
546
- }
547
- const id = this.edgeIdentity(edge, node1Identity, node2Identity);
548
- this.emit("edge-added", id);
549
- return id;
550
- }
551
- getNodes(compareFunc) {
552
- const temp = Array.from(this.nodes.values());
553
- if (compareFunc !== undefined) {
554
- return temp.sort(compareFunc);
555
- }
556
- return temp;
557
- }
558
- getNode(nodeIdentity) {
559
- return this.nodes.get(nodeIdentity);
560
- }
561
- hasNode(nodeIdentity) {
562
- return this.nodes.has(nodeIdentity);
563
- }
564
- getEdges() {
565
- const toReturn = [];
566
- const nodeKeys = Array.from(this.nodes.keys());
567
- this.adjacency.forEach((row, rowIndex) => {
568
- const node1Identity = nodeKeys[rowIndex];
569
- if (node1Identity != null) {
570
- row.forEach((edges, colIndex) => {
571
- if (edges !== null) {
572
- const node2Identity = nodeKeys[colIndex];
573
- if (node2Identity != null) {
574
- for (const edge of edges) {
575
- toReturn.push([node1Identity, node2Identity, edge]);
576
- }
577
- }
578
- }
579
- });
580
- }
581
- });
582
- return toReturn;
583
- }
584
- outEdges(node1Identity) {
585
- const nodeKeys = Array.from(this.nodes.keys());
586
- const nodeIndex = nodeKeys.indexOf(node1Identity);
587
- const toReturn = [];
588
- this.adjacency[nodeIndex].forEach((edges, colIndex) => {
589
- if (edges !== null) {
590
- const node2Identity = nodeKeys[colIndex];
591
- if (node2Identity != null) {
592
- for (const edge of edges) {
593
- toReturn.push([node1Identity, node2Identity, edge]);
594
- }
595
- }
596
- }
597
- });
598
- return toReturn;
599
- }
600
- inEdges(node2Identity) {
601
- const nodeKeys = Array.from(this.nodes.keys());
602
- const node2Index = nodeKeys.indexOf(node2Identity);
603
- const toReturn = [];
604
- this.adjacency.forEach((row, rowIndex) => {
605
- const node1Identity = nodeKeys[rowIndex];
606
- const edges = row[node2Index];
607
- if (edges !== null) {
608
- for (const edge of edges) {
609
- toReturn.push([node1Identity, node2Identity, edge]);
610
- }
611
- }
612
- });
613
- return toReturn;
614
- }
615
- nodeEdges(nodeIdentity) {
616
- return [...this.outEdges(nodeIdentity), ...this.inEdges(nodeIdentity)];
617
- }
618
- removeEdge(node1Identity, node2Identity, edgeIdentity) {
619
- const node1Exists = this.nodes.has(node1Identity);
620
- const node2Exists = this.nodes.has(node2Identity);
621
- if (!node1Exists) {
622
- throw new NodeDoesntExistError(node1Identity);
623
- }
624
- if (!node2Exists) {
625
- throw new NodeDoesntExistError(node2Identity);
626
- }
627
- const node1Index = Array.from(this.nodes.keys()).indexOf(node1Identity);
628
- const node2Index = Array.from(this.nodes.keys()).indexOf(node2Identity);
629
- if (edgeIdentity === undefined) {
630
- this.adjacency[node1Index][node2Index] = null;
631
- } else {
632
- for (const row of this.adjacency) {
633
- for (const edgelist of row) {
634
- if (edgelist !== null) {
635
- for (let edgeIndex = 0;edgeIndex < edgelist.length; edgeIndex++) {
636
- if (this.edgeIdentity(edgelist[edgeIndex], node1Identity, node2Identity) === edgeIdentity) {
637
- edgelist.splice(edgeIndex, 1);
638
- }
639
- }
640
- }
641
- }
642
- }
643
- }
644
- this.emit("edge-removed", edgeIdentity);
645
- }
646
- remove(nodeIdentity) {
647
- if (!this.nodes.has(nodeIdentity)) {
648
- throw new NodeDoesntExistError(nodeIdentity);
649
- }
650
- this.nodes.delete(nodeIdentity);
651
- const nodeIndex = Array.from(this.nodes.keys()).indexOf(nodeIdentity);
652
- this.adjacency.splice(nodeIndex, 1);
653
- this.adjacency.forEach((row) => row.splice(nodeIndex, 1));
654
- this.emit("node-removed", nodeIdentity);
655
- }
656
- removeNode(nodeIdentity) {
657
- return this.remove(nodeIdentity);
658
- }
659
- addNode(node) {
660
- return this.insert(node);
661
- }
662
- addNodes(nodes) {
663
- return nodes.map((node) => this.insert(node));
664
- }
665
- addEdges(edges) {
666
- return edges.map(([node1Identity, node2Identity, edge]) => this.addEdge(node1Identity, node2Identity, edge));
667
- }
668
- }
669
-
670
- // src/graph/directedGraph.ts
671
- class DirectedGraph extends Graph {
672
- hasCycle = false;
673
- isAcyclic() {
674
- if (this.hasCycle !== undefined) {
675
- return !this.hasCycle;
676
- }
677
- const nodeIndices = Array.from(this.nodes.keys());
678
- const nodeInDegrees = new Map(Array.from(this.nodes.keys()).map((n) => [n, this.indegreeOfNode(n)]));
679
- const toSearch = Array.from(nodeInDegrees).filter((pair) => pair[1] === 0);
680
- let visitedNodes = 0;
681
- while (toSearch.length > 0) {
682
- const cur = toSearch.pop();
683
- if (cur === undefined) {
684
- continue;
685
- }
686
- const nodeIndex = nodeIndices.indexOf(cur[0]);
687
- this.adjacency[nodeIndex].forEach((hasAdj, index) => {
688
- if (hasAdj !== null) {
689
- const currentInDegree = nodeInDegrees.get(nodeIndices[index]);
690
- if (currentInDegree !== undefined) {
691
- nodeInDegrees.set(nodeIndices[index], currentInDegree - 1);
692
- if (currentInDegree - 1 === 0) {
693
- toSearch.push([nodeIndices[index], currentInDegree - 1]);
694
- }
695
- }
696
- }
697
- });
698
- visitedNodes++;
699
- }
700
- this.hasCycle = !(visitedNodes === this.nodes.size);
701
- return visitedNodes === this.nodes.size;
702
- }
703
- indegreeOfNode(nodeID) {
704
- const nodeIdentities = Array.from(this.nodes.keys());
705
- const indexOfNode = nodeIdentities.indexOf(nodeID);
706
- if (indexOfNode === -1) {
707
- throw new NodeDoesntExistError(nodeID);
708
- }
709
- return this.adjacency.reduce((carry, row) => {
710
- return carry + (row[indexOfNode] == null ? 0 : 1);
711
- }, 0);
712
- }
713
- addEdge(sourceNodeIdentity, targetNodeIdentity, edge, skipUpdatingCyclicality = false) {
714
- if (edge === undefined) {
715
- edge = true;
716
- }
717
- if (this.hasCycle === false && !skipUpdatingCyclicality) {
718
- this.hasCycle = this.wouldAddingEdgeCreateCycle(sourceNodeIdentity, targetNodeIdentity);
719
- } else if (skipUpdatingCyclicality) {
720
- this.hasCycle = undefined;
721
- }
722
- return super.addEdge(sourceNodeIdentity, targetNodeIdentity, edge);
723
- }
724
- canReachFrom(startNode, endNode) {
725
- const nodeIdentities = Array.from(this.nodes.keys());
726
- const startNodeIndex = nodeIdentities.indexOf(startNode);
727
- const endNodeIndex = nodeIdentities.indexOf(endNode);
728
- if (this.adjacency[startNodeIndex][endNodeIndex] != null) {
729
- return true;
730
- }
731
- return this.adjacency[startNodeIndex].reduce((carry, edge, index) => {
732
- if (carry || edge === null) {
733
- return carry;
734
- }
735
- return this.canReachFrom(nodeIdentities[index], endNode);
736
- }, false);
737
- }
738
- wouldAddingEdgeCreateCycle(sourceNodeIdentity, targetNodeIdentity) {
739
- return this.hasCycle || sourceNodeIdentity === targetNodeIdentity || this.canReachFrom(targetNodeIdentity, sourceNodeIdentity);
740
- }
741
- getSubGraphStartingFrom(startNodeIdentity) {
742
- const nodeIndices = Array.from(this.nodes.keys());
743
- const initalNode = this.nodes.get(startNodeIdentity);
744
- if (initalNode == null) {
745
- throw new NodeDoesntExistError(startNodeIdentity);
746
- }
747
- const recur = (startNodeIdentity2, nodesToInclude) => {
748
- let toReturn = [...nodesToInclude];
749
- const nodeIndex = nodeIndices.indexOf(startNodeIdentity2);
750
- this.adjacency[nodeIndex].forEach((hasAdj, index) => {
751
- if (hasAdj !== null && nodesToInclude.find((n) => this.nodeIdentity(n) === nodeIndices[index]) == null) {
752
- const newNode = this.nodes.get(nodeIndices[index]);
753
- if (newNode != null) {
754
- toReturn = [...recur(nodeIndices[index], toReturn), newNode];
755
- }
756
- }
757
- });
758
- return toReturn;
759
- };
760
- const newGraph = new DirectedGraph(this.nodeIdentity, this.edgeIdentity);
761
- const nodeList = recur(startNodeIdentity, [initalNode]);
762
- const includeIdents = nodeList.map((t) => this.nodeIdentity(t));
763
- Array.from(this.nodes.values()).forEach((n) => {
764
- if (includeIdents.includes(this.nodeIdentity(n))) {
765
- newGraph.insert(n);
766
- }
767
- });
768
- newGraph.adjacency = this.subAdj(nodeList);
769
- return newGraph;
770
- }
771
- subAdj(include) {
772
- const includeIdents = include.map((t) => this.nodeIdentity(t));
773
- const nodeIndices = Array.from(this.nodes.keys());
774
- return this.adjacency.reduce((carry, cur, index) => {
775
- if (includeIdents.includes(nodeIndices[index])) {
776
- return [...carry, cur.filter((_, index2) => includeIdents.includes(nodeIndices[index2]))];
777
- } else {
778
- return carry;
779
- }
780
- }, []);
781
- }
782
- getEdges() {
783
- return super.getEdges();
784
- }
785
- removeEdge(sourceNodeIdentity, targetNodeIdentity, edgeIdentity) {
786
- super.removeEdge(sourceNodeIdentity, targetNodeIdentity, edgeIdentity);
787
- this.hasCycle = undefined;
788
- }
789
- remove(nodeIdentity) {
790
- super.remove(nodeIdentity);
791
- this.hasCycle = undefined;
792
- }
793
- addEdges(edges) {
794
- return super.addEdges(edges);
795
- }
796
- }
797
-
798
- // src/graph/directedAcyclicGraph.ts
799
- class DirectedAcyclicGraph extends DirectedGraph {
800
- _topologicallySortedNodes;
801
- static fromDirectedGraph(graph) {
802
- if (!graph.isAcyclic()) {
803
- throw new CycleError("Can't convert that graph to a DAG because it contains a cycle");
804
- }
805
- const toRet = new DirectedAcyclicGraph(graph.nodeIdentity, graph.edgeIdentity);
806
- toRet.nodes = graph.nodes;
807
- toRet.adjacency = graph.adjacency;
808
- return toRet;
809
- }
810
- addEdge(sourceNodeIdentity, targetNodeIdentity, edge) {
811
- if (edge === undefined) {
812
- edge = true;
813
- }
814
- if (this.wouldAddingEdgeCreateCycle(sourceNodeIdentity, targetNodeIdentity)) {
815
- throw new CycleError(`Can't add edge from ${String(sourceNodeIdentity)} to ${String(targetNodeIdentity)} it would create a cycle`);
816
- }
817
- this._topologicallySortedNodes = undefined;
818
- return super.addEdge(sourceNodeIdentity, targetNodeIdentity, edge, true);
819
- }
820
- insert(node) {
821
- if (this._topologicallySortedNodes !== undefined) {
822
- this._topologicallySortedNodes = [node, ...this._topologicallySortedNodes];
823
- }
824
- return super.insert(node);
825
- }
826
- topologicallySortedNodes() {
827
- if (this._topologicallySortedNodes !== undefined) {
828
- return this._topologicallySortedNodes;
829
- }
830
- const nodeIndices = Array.from(this.nodes.keys());
831
- const nodeInDegrees = new Map(Array.from(this.nodes.keys()).map((n) => [n, this.indegreeOfNode(n)]));
832
- const adjCopy = this.adjacency.map((a) => [...a]);
833
- const toSearch = Array.from(nodeInDegrees).filter((pair) => pair[1] === 0);
834
- if (toSearch.length === this.nodes.size) {
835
- const arrayOfNodes = Array.from(this.nodes.values());
836
- this._topologicallySortedNodes = arrayOfNodes;
837
- return arrayOfNodes;
838
- }
839
- const toReturn = [];
840
- while (toSearch.length > 0) {
841
- const n = toSearch.pop();
842
- if (n === undefined) {
843
- throw new Error("Unexpected empty array");
844
- }
845
- const curNode = this.nodes.get(n[0]);
846
- if (curNode == null) {
847
- throw new Error("This should never happen");
848
- }
849
- toReturn.push(curNode);
850
- adjCopy[nodeIndices.indexOf(n[0])]?.forEach((edge, index) => {
851
- if (edge !== null) {
852
- adjCopy[nodeIndices.indexOf(n[0])][index] = null;
853
- const target = nodeInDegrees.get(nodeIndices[index]);
854
- if (target !== undefined) {
855
- nodeInDegrees.set(nodeIndices[index], target - 1);
856
- if (target - 1 === 0) {
857
- toSearch.push([nodeIndices[index], 0]);
858
- }
859
- } else {
860
- throw new Error("This should never happen");
861
- }
862
- }
863
- });
864
- }
865
- this._topologicallySortedNodes = toReturn;
866
- return toReturn;
867
- }
868
- getSubGraphStartingFrom(startNodeIdentity) {
869
- return DirectedAcyclicGraph.fromDirectedGraph(super.getSubGraphStartingFrom(startNodeIdentity));
870
- }
871
- removeEdge(sourceNodeIdentity, targetNodeIdentity, edgeIdentity) {
872
- super.removeEdge(sourceNodeIdentity, targetNodeIdentity, edgeIdentity);
873
- this._topologicallySortedNodes = undefined;
874
- }
875
- remove(nodeIdentity) {
876
- super.remove(nodeIdentity);
877
- this._topologicallySortedNodes = undefined;
878
- }
879
- }
880
- // src/json-schema/FromSchema.ts
881
- var FromSchemaDefaultOptions = {
882
- parseNotKeyword: true,
883
- parseIfThenElseKeywords: true,
884
- keepDefaultedPropertiesOptional: true,
885
- references: false,
886
- deserialize: false
887
- };
888
- // src/json-schema/SchemaUtils.ts
889
- function areFormatStringsCompatible(sourceFormat, targetFormat) {
890
- const formatPattern = /^[a-zA-Z][a-zA-Z0-9_-]*(?::[a-zA-Z][a-zA-Z0-9_-]*)?$/;
891
- if (!formatPattern.test(sourceFormat) || !formatPattern.test(targetFormat)) {
892
- return "incompatible";
893
- }
894
- const [sourceName, sourceNarrow] = sourceFormat.split(":");
895
- const [targetName, targetNarrow] = targetFormat.split(":");
896
- if (sourceName !== targetName) {
897
- return "incompatible";
898
- }
899
- if (!sourceNarrow && !targetNarrow) {
900
- return "static";
901
- }
902
- if (sourceNarrow && !targetNarrow) {
903
- return "static";
904
- }
905
- if (!sourceNarrow && targetNarrow) {
906
- return "runtime";
907
- }
908
- if (sourceNarrow === targetNarrow) {
909
- return "static";
910
- }
911
- return "incompatible";
912
- }
913
- function isTypeStaticallyCompatible(sourceType, targetType) {
914
- if (!targetType) {
915
- return true;
916
- }
917
- if (!sourceType) {
918
- return false;
919
- }
920
- const sourceTypes = Array.isArray(sourceType) ? sourceType : [sourceType];
921
- const targetTypes = Array.isArray(targetType) ? targetType : [targetType];
922
- return sourceTypes.some((st) => targetTypes.includes(st));
923
- }
924
- function mergeAllOfSchemas(schemas) {
925
- if (schemas.length === 0)
926
- return null;
927
- if (schemas.length === 1)
928
- return schemas[0];
929
- let merged = {};
930
- for (const schema of schemas) {
931
- if (typeof schema === "boolean") {
932
- if (schema === false)
933
- return false;
934
- continue;
935
- }
936
- const schemaObj = schema;
937
- if (schemaObj.type !== undefined) {
938
- if (merged.type === undefined) {
939
- merged.type = schemaObj.type;
940
- } else if (merged.type !== schemaObj.type) {
941
- const mergedTypes = Array.isArray(merged.type) ? merged.type : [merged.type];
942
- const schemaTypes = Array.isArray(schemaObj.type) ? schemaObj.type : [schemaObj.type];
943
- const commonTypes = mergedTypes.filter((t) => schemaTypes.includes(t));
944
- if (commonTypes.length === 0) {
945
- return false;
946
- }
947
- merged.type = commonTypes.length === 1 ? commonTypes[0] : commonTypes;
948
- }
949
- }
950
- const schemaFormat = schemaObj.format;
951
- const mergedFormat = merged.format;
952
- if (schemaFormat) {
953
- if (!mergedFormat) {
954
- merged.format = schemaFormat;
955
- } else {
956
- const formatCompat = areFormatStringsCompatible(mergedFormat, schemaFormat);
957
- if (formatCompat === "incompatible") {
958
- return false;
959
- }
960
- const mergedHasNarrow = mergedFormat.includes(":");
961
- const schemaHasNarrow = schemaFormat.includes(":");
962
- if (schemaHasNarrow && !mergedHasNarrow) {
963
- merged.format = schemaFormat;
964
- } else if (!schemaHasNarrow && mergedHasNarrow) {} else if (mergedFormat !== schemaFormat) {
965
- return false;
966
- }
967
- }
968
- }
969
- if (schemaObj.properties && typeof schemaObj.properties === "object") {
970
- if (!merged.properties) {
971
- merged.properties = {};
972
- }
973
- const mergedProps = merged.properties;
974
- const schemaProps = schemaObj.properties;
975
- for (const [key, value] of Object.entries(schemaProps)) {
976
- if (mergedProps[key]) {
977
- const nestedMerged = mergeAllOfSchemas([mergedProps[key], value]);
978
- if (nestedMerged === null || nestedMerged === false) {
979
- return false;
980
- }
981
- mergedProps[key] = nestedMerged;
982
- } else {
983
- mergedProps[key] = value;
984
- }
985
- }
986
- }
987
- if (schemaObj.required && Array.isArray(schemaObj.required)) {
988
- if (!merged.required) {
989
- merged.required = [];
990
- }
991
- const mergedRequired = merged.required;
992
- const schemaRequired = schemaObj.required;
993
- merged.required = mergedRequired.filter((r) => schemaRequired.includes(r));
994
- }
995
- if (schemaObj.additionalProperties !== undefined) {
996
- if (merged.additionalProperties === undefined) {
997
- merged.additionalProperties = schemaObj.additionalProperties;
998
- } else if (merged.additionalProperties === true && schemaObj.additionalProperties === false) {
999
- merged.additionalProperties = false;
1000
- }
1001
- }
1002
- if (schemaObj.items !== undefined) {
1003
- if (merged.items === undefined) {
1004
- merged.items = schemaObj.items;
1005
- } else {
1006
- const mergedItems = mergeAllOfSchemas([
1007
- merged.items,
1008
- schemaObj.items
1009
- ]);
1010
- if (mergedItems === null || mergedItems === false) {
1011
- return false;
1012
- }
1013
- merged.items = mergedItems;
1014
- }
1015
- }
1016
- }
1017
- return merged;
1018
- }
1019
- function isCompatibleWithUnion(sourceSchema, unionSchemas) {
1020
- let hasStatic = false;
1021
- let hasRuntime = false;
1022
- for (const unionSchema of unionSchemas) {
1023
- const compatibility = areSemanticallyCompatible(sourceSchema, unionSchema);
1024
- if (compatibility === "static") {
1025
- hasStatic = true;
1026
- } else if (compatibility === "runtime") {
1027
- hasRuntime = true;
1028
- }
1029
- }
1030
- if (hasStatic)
1031
- return "static";
1032
- if (hasRuntime)
1033
- return "runtime";
1034
- return "incompatible";
1035
- }
1036
- function areSemanticallyCompatible(sourceSchema, targetSchema) {
1037
- if (sourceSchema === undefined || targetSchema === undefined) {
1038
- return "incompatible";
1039
- }
1040
- if (typeof targetSchema === "boolean") {
1041
- if (targetSchema === false)
1042
- return "incompatible";
1043
- if (targetSchema === true)
1044
- return "static";
1045
- return "incompatible";
1046
- }
1047
- if (typeof sourceSchema === "boolean") {
1048
- if (sourceSchema === false)
1049
- return "incompatible";
1050
- if (sourceSchema === true)
1051
- return "runtime";
1052
- }
1053
- if (sourceSchema.allOf && Array.isArray(sourceSchema.allOf)) {
1054
- const mergedSchema = mergeAllOfSchemas(sourceSchema.allOf);
1055
- if (mergedSchema === null || mergedSchema === false) {
1056
- return "incompatible";
1057
- }
1058
- return areSemanticallyCompatible(mergedSchema, targetSchema);
1059
- }
1060
- const sourceType = sourceSchema.type;
1061
- const targetType = targetSchema.type;
1062
- if (sourceSchema.oneOf && Array.isArray(sourceSchema.oneOf)) {
1063
- let hasStatic = false;
1064
- let hasRuntime = false;
1065
- for (const sourceOption of sourceSchema.oneOf) {
1066
- const compatibility = areSemanticallyCompatible(sourceOption, targetSchema);
1067
- if (compatibility === "static") {
1068
- hasStatic = true;
1069
- } else if (compatibility === "runtime") {
1070
- hasRuntime = true;
1071
- }
1072
- }
1073
- if (hasRuntime)
1074
- return "runtime";
1075
- if (hasStatic)
1076
- return "static";
1077
- return "incompatible";
1078
- }
1079
- if (sourceSchema.anyOf && Array.isArray(sourceSchema.anyOf)) {
1080
- let hasStatic = false;
1081
- let hasRuntime = false;
1082
- for (const sourceOption of sourceSchema.anyOf) {
1083
- const compatibility = areSemanticallyCompatible(sourceOption, targetSchema);
1084
- if (compatibility === "static") {
1085
- hasStatic = true;
1086
- } else if (compatibility === "runtime") {
1087
- hasRuntime = true;
1088
- }
1089
- }
1090
- if (hasRuntime)
1091
- return "runtime";
1092
- if (hasStatic)
1093
- return "static";
1094
- return "incompatible";
1095
- }
1096
- if (targetSchema.oneOf && Array.isArray(targetSchema.oneOf)) {
1097
- return isCompatibleWithUnion(sourceSchema, targetSchema.oneOf);
1098
- }
1099
- if (targetSchema.anyOf && Array.isArray(targetSchema.anyOf)) {
1100
- return isCompatibleWithUnion(sourceSchema, targetSchema.anyOf);
1101
- }
1102
- if (targetSchema.allOf && Array.isArray(targetSchema.allOf)) {
1103
- let hasStatic = false;
1104
- let hasRuntime = false;
1105
- for (const allOfSchema of targetSchema.allOf) {
1106
- const compatibility = areSemanticallyCompatible(sourceSchema, allOfSchema);
1107
- if (compatibility === "incompatible") {
1108
- return "incompatible";
1109
- } else if (compatibility === "static") {
1110
- hasStatic = true;
1111
- } else if (compatibility === "runtime") {
1112
- hasRuntime = true;
1113
- }
1114
- }
1115
- if (hasRuntime)
1116
- return "runtime";
1117
- if (hasStatic)
1118
- return "static";
1119
- return "incompatible";
1120
- }
1121
- if (sourceType === "object" && targetType === "object") {
1122
- const sourceProperties = sourceSchema.properties;
1123
- const targetProperties = targetSchema.properties;
1124
- if (!targetProperties) {
1125
- return "static";
1126
- }
1127
- if (!sourceProperties) {
1128
- if (targetSchema.additionalProperties === false) {
1129
- return "incompatible";
1130
- }
1131
- return "static";
1132
- }
1133
- const targetRequired = targetSchema.required || [];
1134
- let hasStatic = true;
1135
- let hasRuntime = false;
1136
- for (const propName of targetRequired) {
1137
- const targetProp = targetProperties?.[propName];
1138
- const sourceProp = sourceProperties?.[propName];
1139
- if (!sourceProp) {
1140
- return "incompatible";
1141
- }
1142
- if (targetProp) {
1143
- const propCompatibility = areSemanticallyCompatible(sourceProp, targetProp);
1144
- if (propCompatibility === "incompatible") {
1145
- return "incompatible";
1146
- } else if (propCompatibility === "runtime") {
1147
- hasRuntime = true;
1148
- hasStatic = false;
1149
- }
1150
- }
1151
- }
1152
- if (targetSchema.additionalProperties === false) {
1153
- const sourcePropNames = Object.keys(sourceProperties);
1154
- const targetPropNames = Object.keys(targetProperties);
1155
- const extraProps = sourcePropNames.filter((name) => !targetPropNames.includes(name));
1156
- if (extraProps.length > 0) {
1157
- return "incompatible";
1158
- }
1159
- }
1160
- if (hasRuntime)
1161
- return "runtime";
1162
- return "static";
1163
- }
1164
- if (sourceType === "array" && targetType === "array") {
1165
- const sourceFormat2 = sourceSchema?.format;
1166
- const targetFormat2 = targetSchema?.format;
1167
- let formatCompatibility = null;
1168
- if (sourceFormat2 && targetFormat2) {
1169
- formatCompatibility = areFormatStringsCompatible(sourceFormat2, targetFormat2);
1170
- if (formatCompatibility === "incompatible") {
1171
- return "incompatible";
1172
- }
1173
- }
1174
- if (sourceFormat2 && !targetFormat2) {
1175
- return "static";
1176
- }
1177
- if (!sourceFormat2 && targetFormat2) {
1178
- return "incompatible";
1179
- }
1180
- const sourceItems = sourceSchema.items;
1181
- const targetItems = targetSchema.items;
1182
- if (sourceItems && typeof sourceItems === "object" && !Array.isArray(sourceItems) && targetItems && typeof targetItems === "object" && !Array.isArray(targetItems)) {
1183
- const itemsCompatibility = areSemanticallyCompatible(sourceItems, targetItems);
1184
- if (formatCompatibility === "runtime") {
1185
- return "runtime";
1186
- }
1187
- return itemsCompatibility;
1188
- }
1189
- if (!targetItems) {
1190
- return "static";
1191
- }
1192
- if (!sourceItems) {
1193
- return "incompatible";
1194
- }
1195
- if (Array.isArray(targetItems)) {
1196
- return isCompatibleWithUnion(sourceItems, targetItems);
1197
- }
1198
- return "static";
1199
- }
1200
- if (!sourceType) {
1201
- const targetFormat2 = targetSchema?.format;
1202
- if (targetFormat2) {
1203
- return "runtime";
1204
- }
1205
- return "static";
1206
- }
1207
- if (!targetType) {
1208
- const targetFormat2 = targetSchema?.format;
1209
- if (targetFormat2) {
1210
- const sourceFormat2 = sourceSchema?.format;
1211
- if (!sourceFormat2) {
1212
- return "incompatible";
1213
- }
1214
- return areFormatStringsCompatible(sourceFormat2, targetFormat2);
1215
- }
1216
- return "static";
1217
- }
1218
- if (!isTypeStaticallyCompatible(sourceType, targetType)) {
1219
- return "incompatible";
1220
- }
1221
- const sourceFormat = sourceSchema?.format;
1222
- const targetFormat = targetSchema?.format;
1223
- if (sourceFormat && targetFormat) {
1224
- return areFormatStringsCompatible(sourceFormat, targetFormat);
1225
- }
1226
- if (sourceFormat && !targetFormat) {
1227
- return "static";
1228
- }
1229
- if (!sourceFormat && targetFormat) {
1230
- return "incompatible";
1231
- }
1232
- return "static";
1233
- }
1234
- function areObjectSchemasSemanticallyCompatible(sourceSchema, targetSchema) {
1235
- return areSemanticallyCompatible(sourceSchema, targetSchema);
1236
- }
1237
- // src/json-schema/SchemaValidation.ts
1238
- import { compileSchema } from "@sroussey/json-schema-library";
1239
- // src/json-schema/parsePartialJson.ts
1240
- function parsePartialJson(text) {
1241
- const trimmed = text.trim();
1242
- if (!trimmed)
1243
- return;
1244
- try {
1245
- const result = JSON.parse(trimmed);
1246
- if (typeof result === "object" && result !== null && !Array.isArray(result)) {
1247
- return result;
1248
- }
1249
- return;
1250
- } catch {}
1251
- if (trimmed[0] !== "{")
1252
- return;
1253
- const repaired = repairJson(trimmed);
1254
- if (repaired === undefined)
1255
- return;
1256
- try {
1257
- const result = JSON.parse(repaired);
1258
- if (typeof result === "object" && result !== null && !Array.isArray(result)) {
1259
- return result;
1260
- }
1261
- return;
1262
- } catch {
1263
- return;
1264
- }
1265
- }
1266
- function repairJson(text) {
1267
- let result = "";
1268
- let i = 0;
1269
- const len = text.length;
1270
- const stack = [];
1271
- let inString = false;
1272
- let escaped = false;
1273
- let lastSafeEnd = 0;
1274
- while (i < len) {
1275
- const ch = text[i];
1276
- if (escaped) {
1277
- escaped = false;
1278
- result += ch;
1279
- i++;
1280
- continue;
1281
- }
1282
- if (ch === "\\") {
1283
- escaped = true;
1284
- result += ch;
1285
- i++;
1286
- continue;
1287
- }
1288
- if (inString) {
1289
- if (ch === '"') {
1290
- inString = false;
1291
- result += ch;
1292
- i++;
1293
- lastSafeEnd = result.length;
1294
- continue;
1295
- }
1296
- result += ch;
1297
- i++;
1298
- continue;
1299
- }
1300
- switch (ch) {
1301
- case '"':
1302
- inString = true;
1303
- result += ch;
1304
- i++;
1305
- break;
1306
- case "{":
1307
- stack.push("}");
1308
- result += ch;
1309
- i++;
1310
- break;
1311
- case "[":
1312
- stack.push("]");
1313
- result += ch;
1314
- i++;
1315
- break;
1316
- case "}":
1317
- if (stack.length > 0 && stack[stack.length - 1] === "}") {
1318
- stack.pop();
1319
- result += ch;
1320
- i++;
1321
- lastSafeEnd = result.length;
1322
- } else {
1323
- return closeStack(result, stack);
1324
- }
1325
- break;
1326
- case "]":
1327
- if (stack.length > 0 && stack[stack.length - 1] === "]") {
1328
- stack.pop();
1329
- result += ch;
1330
- i++;
1331
- lastSafeEnd = result.length;
1332
- } else {
1333
- return closeStack(result, stack);
1334
- }
1335
- break;
1336
- default:
1337
- result += ch;
1338
- i++;
1339
- break;
1340
- }
1341
- }
1342
- if (inString) {
1343
- result += '"';
1344
- }
1345
- if (stack.length === 0) {
1346
- return result;
1347
- }
1348
- return closeStack(cleanTrailing(result), stack);
1349
- }
1350
- function cleanTrailing(text) {
1351
- let s = text.trimEnd();
1352
- let changed = true;
1353
- while (changed) {
1354
- changed = false;
1355
- const trimmed = s.trimEnd();
1356
- if (trimmed.endsWith(",")) {
1357
- s = trimmed.slice(0, -1);
1358
- changed = true;
1359
- continue;
1360
- }
1361
- if (trimmed.endsWith(":")) {
1362
- const withoutColon = trimmed.slice(0, -1).trimEnd();
1363
- if (withoutColon.endsWith('"')) {
1364
- const keyStart = withoutColon.lastIndexOf('"', withoutColon.length - 2);
1365
- if (keyStart >= 0) {
1366
- let before = withoutColon.slice(0, keyStart).trimEnd();
1367
- if (before.endsWith(",")) {
1368
- before = before.slice(0, -1);
1369
- }
1370
- s = before;
1371
- changed = true;
1372
- continue;
1373
- }
1374
- }
1375
- s = withoutColon;
1376
- changed = true;
1377
- continue;
1378
- }
1379
- const bareTokenMatch = trimmed.match(/,\s*"[^"]*"\s*:\s*(?:tru|fal|nul|true|false|null|[\d.eE+-]+)$/);
1380
- if (bareTokenMatch) {
1381
- const valueStr = trimmed.slice(trimmed.lastIndexOf(":") + 1).trim();
1382
- try {
1383
- JSON.parse(valueStr);
1384
- } catch {
1385
- s = trimmed.slice(0, bareTokenMatch.index).trimEnd();
1386
- if (s.endsWith(","))
1387
- s = s.slice(0, -1);
1388
- changed = true;
1389
- continue;
1390
- }
1391
- }
1392
- }
1393
- return s;
1394
- }
1395
- function closeStack(text, stack) {
1396
- let result = text;
1397
- for (let i = stack.length - 1;i >= 0; i--) {
1398
- result += stack[i];
1399
- }
1400
- return result;
1401
- }
1402
433
  // src/utilities/objectOfArraysAsArrayOfObjects.ts
1403
434
  function objectOfArraysAsArrayOfObjects(data) {
1404
435
  const keys = Object.keys(data);
@@ -1705,236 +736,6 @@ function objectOfArraysAsArrayOfObjects(data) {
1705
736
  }
1706
737
  });
1707
738
  }
1708
- // src/vector/TypedArray.ts
1709
- function isTypedArray(value) {
1710
- return ArrayBuffer.isView(value) && !(value instanceof DataView);
1711
- }
1712
- var TypedArrayType = null;
1713
- var TypedArraySchemaOptions = {
1714
- ...FromSchemaDefaultOptions,
1715
- deserialize: [
1716
- {
1717
- pattern: { type: "array", format: "TypedArray:Float64Array" },
1718
- output: Float64Array
1719
- },
1720
- {
1721
- pattern: { type: "array", format: "TypedArray:Float32Array" },
1722
- output: Float32Array
1723
- },
1724
- {
1725
- pattern: { type: "array", format: "TypedArray:Float16Array" },
1726
- output: Float16Array
1727
- },
1728
- {
1729
- pattern: { type: "array", format: "TypedArray:Int16Array" },
1730
- output: Int16Array
1731
- },
1732
- {
1733
- pattern: { type: "array", format: "TypedArray:Int8Array" },
1734
- output: Int8Array
1735
- },
1736
- {
1737
- pattern: { type: "array", format: "TypedArray:Uint8Array" },
1738
- output: Uint8Array
1739
- },
1740
- {
1741
- pattern: { type: "array", format: "TypedArray:Uint16Array" },
1742
- output: Uint16Array
1743
- },
1744
- {
1745
- pattern: { type: "array", format: "TypedArray" },
1746
- output: TypedArrayType
1747
- }
1748
- ]
1749
- };
1750
- var TypedArraySchema = (annotations = {}) => {
1751
- return {
1752
- type: "array",
1753
- format: "TypedArray",
1754
- title: "Typed Array",
1755
- description: "A typed array (Float32Array, Int8Array, etc.)",
1756
- ...annotations
1757
- };
1758
- };
1759
-
1760
- // src/vector/Tensor.ts
1761
- var TensorType = {
1762
- FLOAT16: "float16",
1763
- FLOAT32: "float32",
1764
- FLOAT64: "float64",
1765
- INT8: "int8",
1766
- UINT8: "uint8",
1767
- INT16: "int16",
1768
- UINT16: "uint16"
1769
- };
1770
- var TensorSchema = (annotations = {}) => ({
1771
- type: "object",
1772
- properties: {
1773
- type: {
1774
- type: "string",
1775
- enum: Object.values(TensorType),
1776
- title: "Type",
1777
- description: "The type of the tensor"
1778
- },
1779
- data: TypedArraySchema({
1780
- title: "Data",
1781
- description: "The data of the tensor"
1782
- }),
1783
- shape: {
1784
- type: "array",
1785
- items: { type: "number" },
1786
- title: "Shape",
1787
- description: "The shape of the tensor (dimensions)",
1788
- minItems: 1,
1789
- default: [1]
1790
- },
1791
- normalized: {
1792
- type: "boolean",
1793
- title: "Normalized",
1794
- description: "Whether the tensor data is normalized",
1795
- default: false
1796
- }
1797
- },
1798
- required: ["data"],
1799
- additionalProperties: false,
1800
- ...annotations
1801
- });
1802
- // src/vector/TypedArrayUtils.ts
1803
- var WIDTH_RANK = {
1804
- Float64Array: 6,
1805
- Float32Array: 5,
1806
- Float16Array: 4,
1807
- Int16Array: 3,
1808
- Uint16Array: 3,
1809
- Int8Array: 2,
1810
- Uint8Array: 2
1811
- };
1812
- function getWidthRank(arr) {
1813
- return WIDTH_RANK[arr.constructor.name] ?? 0;
1814
- }
1815
- function widestConstructor(sources) {
1816
- let best = sources[0];
1817
- for (let i = 1;i < sources.length; i++) {
1818
- if (getWidthRank(sources[i]) > getWidthRank(best))
1819
- best = sources[i];
1820
- }
1821
- return best.constructor;
1822
- }
1823
- function createTypedArrayFrom(sources, values) {
1824
- const Ctor = widestConstructor(sources);
1825
- const result = new Ctor(values.length);
1826
- for (let i = 0;i < values.length; i++)
1827
- result[i] = values[i];
1828
- return result;
1829
- }
1830
- // src/vector/VectorSimilarityUtils.ts
1831
- function cosineSimilarity(a, b) {
1832
- if (a.length !== b.length) {
1833
- throw new Error("Vectors must have the same length");
1834
- }
1835
- let dotProduct = 0;
1836
- let normA = 0;
1837
- let normB = 0;
1838
- for (let i = 0;i < a.length; i++) {
1839
- dotProduct += a[i] * b[i];
1840
- normA += a[i] * a[i];
1841
- normB += b[i] * b[i];
1842
- }
1843
- const denominator = Math.sqrt(normA) * Math.sqrt(normB);
1844
- if (denominator === 0) {
1845
- return 0;
1846
- }
1847
- return dotProduct / denominator;
1848
- }
1849
- function jaccardSimilarity(a, b) {
1850
- if (a.length !== b.length) {
1851
- throw new Error("Vectors must have the same length");
1852
- }
1853
- let globalMin = a[0];
1854
- for (let i = 0;i < a.length; i++) {
1855
- globalMin = Math.min(globalMin, a[i], b[i]);
1856
- }
1857
- const shift = globalMin < 0 ? -globalMin : 0;
1858
- let minSum = 0;
1859
- let maxSum = 0;
1860
- for (let i = 0;i < a.length; i++) {
1861
- const shiftedA = a[i] + shift;
1862
- const shiftedB = b[i] + shift;
1863
- minSum += Math.min(shiftedA, shiftedB);
1864
- maxSum += Math.max(shiftedA, shiftedB);
1865
- }
1866
- return maxSum === 0 ? 0 : minSum / maxSum;
1867
- }
1868
- function hammingDistance(a, b) {
1869
- if (a.length !== b.length) {
1870
- throw new Error("Vectors must have the same length");
1871
- }
1872
- let differences = 0;
1873
- for (let i = 0;i < a.length; i++) {
1874
- if (a[i] !== b[i]) {
1875
- differences++;
1876
- }
1877
- }
1878
- return differences / a.length;
1879
- }
1880
- function hammingSimilarity(a, b) {
1881
- return 1 - hammingDistance(a, b);
1882
- }
1883
- // src/vector/VectorUtils.ts
1884
- function magnitude(arr) {
1885
- return Math.sqrt(arr.reduce((acc, val) => acc + val * val, 0));
1886
- }
1887
- function inner(arr1, arr2) {
1888
- if (arr1.length !== arr2.length) {
1889
- throw new Error("Vectors must have the same length to compute inner product.");
1890
- }
1891
- return arr1.reduce((acc, val, i) => acc + val * arr2[i], 0);
1892
- }
1893
- function normalize(vector, throwOnZero = true, float32 = false) {
1894
- const mag = magnitude(vector);
1895
- if (mag === 0) {
1896
- if (throwOnZero) {
1897
- throw new Error("Cannot normalize a zero vector.");
1898
- }
1899
- return vector;
1900
- }
1901
- const normalized = Array.from(vector).map((val) => Number(val) / mag);
1902
- if (float32) {
1903
- return new Float32Array(normalized);
1904
- }
1905
- if (vector instanceof Float64Array) {
1906
- return new Float64Array(normalized);
1907
- }
1908
- if (vector instanceof Float16Array) {
1909
- return new Float16Array(normalized);
1910
- }
1911
- if (vector instanceof Float32Array) {
1912
- return new Float32Array(normalized);
1913
- }
1914
- if (vector instanceof Int8Array) {
1915
- return new Int8Array(normalized);
1916
- }
1917
- if (vector instanceof Uint8Array) {
1918
- return new Uint8Array(normalized);
1919
- }
1920
- if (vector instanceof Int16Array) {
1921
- return new Int16Array(normalized);
1922
- }
1923
- if (vector instanceof Uint16Array) {
1924
- return new Uint16Array(normalized);
1925
- }
1926
- return new Float32Array(normalized);
1927
- }
1928
- function normalizeNumberArray(values, throwOnZero = false) {
1929
- const norm = magnitude(values);
1930
- if (norm === 0) {
1931
- if (throwOnZero) {
1932
- throw new Error("Cannot normalize a zero vector.");
1933
- }
1934
- return values;
1935
- }
1936
- return values.map((v) => v / norm);
1937
- }
1938
739
  // src/worker/WorkerManager.ts
1939
740
  class WorkerManager {
1940
741
  workers = new Map;
@@ -1942,14 +743,26 @@ class WorkerManager {
1942
743
  workerFunctions = new Map;
1943
744
  workerStreamFunctions = new Map;
1944
745
  workerReactiveFunctions = new Map;
1945
- registerWorker(name, worker) {
1946
- if (this.workers.has(name))
746
+ lazyFactories = new Map;
747
+ lazyInitPromises = new Map;
748
+ registerWorker(name, workerOrFactory) {
749
+ if (this.workers.has(name)) {
1947
750
  throw new Error(`Worker ${name} is already registered.`);
1948
- this.workers.set(name, worker);
1949
- this.workers.set(name, worker);
1950
- worker.addEventListener("error", (event) => {
1951
- console.error("Worker Error:", event.message, "at", event.filename, "line:", event.lineno);
1952
- });
751
+ }
752
+ if (this.lazyFactories.has(name)) {
753
+ throw new Error(`Worker ${name} is already registered.`);
754
+ }
755
+ if (typeof workerOrFactory === "function") {
756
+ this.lazyFactories.set(name, workerOrFactory);
757
+ } else {
758
+ this.attachWorkerInstance(name, workerOrFactory);
759
+ }
760
+ }
761
+ attachWorkerInstance(name, worker) {
762
+ this.workers.set(name, worker);
763
+ worker.addEventListener("error", (event) => {
764
+ console.error("Worker Error:", event.message, "at", event.filename, "line:", event.lineno);
765
+ });
1953
766
  worker.addEventListener("messageerror", (event) => {
1954
767
  console.error("Worker message error:", event);
1955
768
  });
@@ -1967,6 +780,29 @@ class WorkerManager {
1967
780
  });
1968
781
  this.readyWorkers.set(name, readyPromise);
1969
782
  }
783
+ async ensureWorkerReady(name) {
784
+ if (this.workers.has(name)) {
785
+ await this.readyWorkers.get(name);
786
+ return;
787
+ }
788
+ const factory = this.lazyFactories.get(name);
789
+ if (!factory) {
790
+ throw new Error(`Worker ${name} not found.`);
791
+ }
792
+ let init = this.lazyInitPromises.get(name);
793
+ if (!init) {
794
+ init = (async () => {
795
+ const f = this.lazyFactories.get(name);
796
+ this.lazyFactories.delete(name);
797
+ const worker = f();
798
+ this.attachWorkerInstance(name, worker);
799
+ })();
800
+ this.lazyInitPromises.set(name, init);
801
+ }
802
+ await init;
803
+ await this.readyWorkers.get(name);
804
+ this.lazyInitPromises.delete(name);
805
+ }
1970
806
  getWorker(name) {
1971
807
  const worker = this.workers.get(name);
1972
808
  if (!worker)
@@ -1974,6 +810,7 @@ class WorkerManager {
1974
810
  return worker;
1975
811
  }
1976
812
  async callWorkerFunction(workerName, functionName, args, options) {
813
+ await this.ensureWorkerReady(workerName);
1977
814
  const worker = this.workers.get(workerName);
1978
815
  if (!worker)
1979
816
  throw new Error(`Worker ${workerName} not found.`);
@@ -2019,6 +856,7 @@ class WorkerManager {
2019
856
  });
2020
857
  }
2021
858
  async callWorkerReactiveFunction(workerName, functionName, args) {
859
+ await this.ensureWorkerReady(workerName);
2022
860
  const worker = this.workers.get(workerName);
2023
861
  if (!worker)
2024
862
  return;
@@ -2050,6 +888,7 @@ class WorkerManager {
2050
888
  });
2051
889
  }
2052
890
  async* callWorkerStreamFunction(workerName, functionName, args, options) {
891
+ await this.ensureWorkerReady(workerName);
2053
892
  const worker = this.workers.get(workerName);
2054
893
  if (!worker)
2055
894
  throw new Error(`Worker ${workerName} not found.`);
@@ -2133,202 +972,6 @@ class WorkerManager {
2133
972
  }
2134
973
  var WORKER_MANAGER = createServiceToken("worker.manager");
2135
974
  globalServiceRegistry.register(WORKER_MANAGER, () => new WorkerManager, true);
2136
- // src/worker/WorkerServer.ts
2137
- import { parentPort } from "@workglow/util";
2138
- function extractTransferables(obj) {
2139
- const transferables = [];
2140
- const seen = new WeakSet;
2141
- function findTransferables(value) {
2142
- if (value && typeof value === "object" && seen.has(value)) {
2143
- return;
2144
- }
2145
- if (value && typeof value === "object") {
2146
- seen.add(value);
2147
- }
2148
- if (value instanceof Float32Array || value instanceof Int16Array) {
2149
- transferables.push(value.buffer);
2150
- } else if (value instanceof Uint8Array || value instanceof Uint8ClampedArray || value instanceof Int8Array || value instanceof Uint16Array || value instanceof Int32Array || value instanceof Uint32Array || value instanceof Float64Array || value instanceof BigInt64Array || value instanceof BigUint64Array) {
2151
- transferables.push(value.buffer);
2152
- } else if (typeof OffscreenCanvas !== "undefined" && value instanceof OffscreenCanvas) {
2153
- transferables.push(value);
2154
- } else if (typeof ImageBitmap !== "undefined" && value instanceof ImageBitmap) {
2155
- transferables.push(value);
2156
- } else if (typeof VideoFrame !== "undefined" && value instanceof VideoFrame) {
2157
- transferables.push(value);
2158
- } else if (typeof MessagePort !== "undefined" && value instanceof MessagePort) {
2159
- transferables.push(value);
2160
- } else if (value instanceof ArrayBuffer) {
2161
- transferables.push(value);
2162
- } else if (Array.isArray(value)) {
2163
- value.forEach(findTransferables);
2164
- } else if (value && typeof value === "object") {
2165
- Object.values(value).forEach(findTransferables);
2166
- }
2167
- }
2168
- findTransferables(obj);
2169
- return transferables;
2170
- }
2171
-
2172
- class WorkerServer {
2173
- constructor() {
2174
- parentPort?.addEventListener("message", async (event) => {
2175
- const msg = {
2176
- type: event.type,
2177
- data: event.data
2178
- };
2179
- await this.handleMessage(msg);
2180
- });
2181
- }
2182
- functions = {};
2183
- streamFunctions = {};
2184
- reactiveFunctions = {};
2185
- requestControllers = new Map;
2186
- completedRequests = new Set;
2187
- postResult = (id, result) => {
2188
- if (this.completedRequests.has(id)) {
2189
- return;
2190
- }
2191
- this.completedRequests.add(id);
2192
- const transferables = extractTransferables(result);
2193
- const uniqueTransferables = [...new Set(transferables)];
2194
- postMessage({ id, type: "complete", data: result }, uniqueTransferables);
2195
- };
2196
- postError = (id, errorMessage) => {
2197
- if (this.completedRequests.has(id)) {
2198
- return;
2199
- }
2200
- this.completedRequests.add(id);
2201
- postMessage({ id, type: "error", data: errorMessage });
2202
- };
2203
- postStreamChunk = (id, event) => {
2204
- if (this.completedRequests.has(id)) {
2205
- return;
2206
- }
2207
- postMessage({ id, type: "stream_chunk", data: event });
2208
- };
2209
- sendReady() {
2210
- postMessage({
2211
- type: "ready",
2212
- functions: Object.keys(this.functions),
2213
- streamFunctions: Object.keys(this.streamFunctions),
2214
- reactiveFunctions: Object.keys(this.reactiveFunctions)
2215
- });
2216
- }
2217
- registerFunction(name, fn) {
2218
- this.functions[name] = fn;
2219
- }
2220
- registerReactiveFunction(name, fn) {
2221
- this.reactiveFunctions[name] = fn;
2222
- }
2223
- registerStreamFunction(name, fn) {
2224
- this.streamFunctions[name] = fn;
2225
- }
2226
- async handleMessage(event) {
2227
- const { id, type, functionName, args, stream, reactive } = event.data;
2228
- if (type === "abort") {
2229
- return await this.handleAbort(id);
2230
- }
2231
- if (type === "call") {
2232
- if (stream) {
2233
- return await this.handleStreamCall(id, functionName, args);
2234
- }
2235
- if (reactive) {
2236
- return await this.handleReactiveCall(id, functionName, args);
2237
- }
2238
- return await this.handleCall(id, functionName, args);
2239
- }
2240
- }
2241
- async handleAbort(id) {
2242
- if (this.requestControllers.has(id)) {
2243
- const controller = this.requestControllers.get(id);
2244
- controller?.abort();
2245
- this.requestControllers.delete(id);
2246
- this.postError(id, "Operation aborted");
2247
- }
2248
- }
2249
- async handleReactiveCall(id, functionName, [input, output, model]) {
2250
- if (!(functionName in this.reactiveFunctions)) {
2251
- this.postResult(id, undefined);
2252
- return;
2253
- }
2254
- try {
2255
- const fn = this.reactiveFunctions[functionName];
2256
- const result = await fn(input, output, model);
2257
- this.postResult(id, result);
2258
- } catch (error) {
2259
- this.postError(id, error.message);
2260
- }
2261
- }
2262
- async handleCall(id, functionName, [input, model]) {
2263
- if (!(functionName in this.functions)) {
2264
- this.postError(id, `Function ${functionName} not found`);
2265
- return;
2266
- }
2267
- try {
2268
- const abortController = new AbortController;
2269
- this.requestControllers.set(id, abortController);
2270
- const fn = this.functions[functionName];
2271
- const postProgress = (progress, message, details) => {
2272
- if (!this.completedRequests.has(id)) {
2273
- postMessage({ id, type: "progress", data: { progress, message, details } });
2274
- }
2275
- };
2276
- const result = await fn(input, model, postProgress, abortController.signal);
2277
- this.postResult(id, result);
2278
- } catch (error) {
2279
- this.postError(id, error.message);
2280
- } finally {
2281
- this.requestControllers.delete(id);
2282
- setTimeout(() => {
2283
- this.completedRequests.delete(id);
2284
- }, 1000);
2285
- }
2286
- }
2287
- async handleStreamCall(id, functionName, [input, model]) {
2288
- if (functionName in this.streamFunctions) {
2289
- try {
2290
- const abortController = new AbortController;
2291
- this.requestControllers.set(id, abortController);
2292
- const fn = this.streamFunctions[functionName];
2293
- const iterable = fn(input, model, abortController.signal);
2294
- for await (const event of iterable) {
2295
- if (this.completedRequests.has(id))
2296
- break;
2297
- this.postStreamChunk(id, event);
2298
- }
2299
- this.postResult(id, undefined);
2300
- } catch (error) {
2301
- this.postError(id, error.message);
2302
- } finally {
2303
- this.requestControllers.delete(id);
2304
- setTimeout(() => {
2305
- this.completedRequests.delete(id);
2306
- }, 1000);
2307
- }
2308
- } else if (functionName in this.functions) {
2309
- try {
2310
- const abortController = new AbortController;
2311
- this.requestControllers.set(id, abortController);
2312
- const fn = this.functions[functionName];
2313
- const noopProgress = () => {};
2314
- const result = await fn(input, model, noopProgress, abortController.signal);
2315
- this.postStreamChunk(id, { type: "finish", data: result });
2316
- this.postResult(id, undefined);
2317
- } catch (error) {
2318
- this.postError(id, error.message);
2319
- } finally {
2320
- this.requestControllers.delete(id);
2321
- setTimeout(() => {
2322
- this.completedRequests.delete(id);
2323
- }, 1000);
2324
- }
2325
- } else {
2326
- this.postError(id, `Function ${functionName} not found`);
2327
- }
2328
- }
2329
- }
2330
- var WORKER_SERVER = createServiceToken("worker.server");
2331
- globalServiceRegistry.register(WORKER_SERVER, () => new WorkerServer, true);
2332
975
  // src/credentials/ICredentialStore.ts
2333
976
  var CREDENTIAL_STORE = createServiceToken("credential.store");
2334
977
  // src/credentials/InMemoryCredentialStore.ts
@@ -2569,518 +1212,6 @@ function base64ToBuf(b64) {
2569
1212
  }
2570
1213
  return buf;
2571
1214
  }
2572
- // src/mcp/McpAuthTypes.ts
2573
- var mcpAuthTypes = [
2574
- "none",
2575
- "bearer",
2576
- "client_credentials",
2577
- "private_key_jwt",
2578
- "static_private_key_jwt",
2579
- "authorization_code"
2580
- ];
2581
- var mcpAuthConfigSchema = {
2582
- properties: {
2583
- auth_type: {
2584
- type: "string",
2585
- enum: mcpAuthTypes,
2586
- title: "Auth Type",
2587
- description: "Authentication method for connecting to the MCP server",
2588
- default: "none"
2589
- },
2590
- auth_token: {
2591
- type: "string",
2592
- format: "credential",
2593
- title: "Bearer Token",
2594
- description: "Static bearer token or API key (for bearer auth)"
2595
- },
2596
- auth_client_id: {
2597
- type: "string",
2598
- title: "Client ID",
2599
- description: "OAuth client ID (for OAuth auth types)"
2600
- },
2601
- auth_client_secret: {
2602
- type: "string",
2603
- format: "credential",
2604
- title: "Client Secret",
2605
- description: "OAuth client secret (for client_credentials auth)"
2606
- },
2607
- auth_private_key: {
2608
- type: "string",
2609
- format: "credential",
2610
- title: "Private Key",
2611
- description: "PEM or JWK private key (for private_key_jwt auth)"
2612
- },
2613
- auth_algorithm: {
2614
- type: "string",
2615
- title: "Algorithm",
2616
- description: "JWT signing algorithm, e.g. RS256, ES256 (for private_key_jwt auth)"
2617
- },
2618
- auth_jwt_bearer_assertion: {
2619
- type: "string",
2620
- format: "credential",
2621
- title: "JWT Assertion",
2622
- description: "Pre-built JWT assertion (for static_private_key_jwt auth)"
2623
- },
2624
- auth_redirect_url: {
2625
- type: "string",
2626
- format: "uri",
2627
- title: "Redirect URL",
2628
- description: "OAuth redirect URL (for authorization_code auth)"
2629
- },
2630
- auth_scope: {
2631
- type: "string",
2632
- title: "Scope",
2633
- description: "OAuth scope (space-separated)"
2634
- },
2635
- auth_client_name: {
2636
- type: "string",
2637
- title: "Client Name",
2638
- description: "Optional OAuth client display name"
2639
- },
2640
- auth_jwt_lifetime_seconds: {
2641
- type: "number",
2642
- title: "JWT Lifetime",
2643
- description: "JWT lifetime in seconds (default: 300)",
2644
- minimum: 1
2645
- }
2646
- },
2647
- allOf: [
2648
- {
2649
- if: { properties: { auth_type: { const: "bearer" } }, required: ["auth_type"] },
2650
- then: {
2651
- required: ["auth_token"],
2652
- properties: { auth_token: true }
2653
- }
2654
- },
2655
- {
2656
- if: {
2657
- properties: { auth_type: { const: "client_credentials" } },
2658
- required: ["auth_type"]
2659
- },
2660
- then: {
2661
- required: ["auth_client_id", "auth_client_secret"],
2662
- properties: {
2663
- auth_client_id: true,
2664
- auth_client_secret: true,
2665
- auth_client_name: true,
2666
- auth_scope: true
2667
- }
2668
- }
2669
- },
2670
- {
2671
- if: { properties: { auth_type: { const: "private_key_jwt" } }, required: ["auth_type"] },
2672
- then: {
2673
- required: ["auth_client_id", "auth_private_key", "auth_algorithm"],
2674
- properties: {
2675
- auth_client_id: true,
2676
- auth_private_key: true,
2677
- auth_algorithm: true,
2678
- auth_client_name: true,
2679
- auth_jwt_lifetime_seconds: true,
2680
- auth_scope: true
2681
- }
2682
- }
2683
- },
2684
- {
2685
- if: {
2686
- properties: { auth_type: { const: "static_private_key_jwt" } },
2687
- required: ["auth_type"]
2688
- },
2689
- then: {
2690
- required: ["auth_client_id", "auth_jwt_bearer_assertion"],
2691
- properties: {
2692
- auth_client_id: true,
2693
- auth_jwt_bearer_assertion: true,
2694
- auth_client_name: true,
2695
- auth_scope: true
2696
- }
2697
- }
2698
- },
2699
- {
2700
- if: { properties: { auth_type: { const: "authorization_code" } }, required: ["auth_type"] },
2701
- then: {
2702
- required: ["auth_client_id", "auth_redirect_url"],
2703
- properties: {
2704
- auth_client_id: true,
2705
- auth_client_secret: true,
2706
- auth_redirect_url: true,
2707
- auth_scope: true
2708
- }
2709
- }
2710
- }
2711
- ]
2712
- };
2713
- function isMcpAuthType(value) {
2714
- return typeof value === "string" && mcpAuthTypes.includes(value);
2715
- }
2716
- function asNonEmptyString(value) {
2717
- if (typeof value !== "string")
2718
- return;
2719
- const trimmed = value.trim();
2720
- return trimmed === "" ? undefined : trimmed;
2721
- }
2722
- function asNumber(value) {
2723
- return typeof value === "number" ? value : undefined;
2724
- }
2725
- function buildAuthConfig(flat) {
2726
- const rawAuthType = flat.auth_type;
2727
- if (!isMcpAuthType(rawAuthType) || rawAuthType === "none") {
2728
- return;
2729
- }
2730
- const authType = rawAuthType;
2731
- switch (authType) {
2732
- case "bearer": {
2733
- const token = asNonEmptyString(flat.auth_token);
2734
- if (!token)
2735
- return;
2736
- return { type: "bearer", token };
2737
- }
2738
- case "client_credentials": {
2739
- const client_id = asNonEmptyString(flat.auth_client_id);
2740
- const client_secret = asNonEmptyString(flat.auth_client_secret);
2741
- if (!client_id || !client_secret)
2742
- return;
2743
- return {
2744
- type: "client_credentials",
2745
- client_id,
2746
- client_secret,
2747
- client_name: asNonEmptyString(flat.auth_client_name),
2748
- scope: asNonEmptyString(flat.auth_scope)
2749
- };
2750
- }
2751
- case "private_key_jwt": {
2752
- const client_id = asNonEmptyString(flat.auth_client_id);
2753
- const private_key = asNonEmptyString(flat.auth_private_key);
2754
- const algorithm = asNonEmptyString(flat.auth_algorithm);
2755
- if (!client_id || !private_key || !algorithm)
2756
- return;
2757
- return {
2758
- type: "private_key_jwt",
2759
- client_id,
2760
- private_key,
2761
- algorithm,
2762
- client_name: asNonEmptyString(flat.auth_client_name),
2763
- jwt_lifetime_seconds: asNumber(flat.auth_jwt_lifetime_seconds),
2764
- scope: asNonEmptyString(flat.auth_scope)
2765
- };
2766
- }
2767
- case "static_private_key_jwt": {
2768
- const client_id = asNonEmptyString(flat.auth_client_id);
2769
- const jwt_bearer_assertion = asNonEmptyString(flat.auth_jwt_bearer_assertion);
2770
- if (!client_id || !jwt_bearer_assertion)
2771
- return;
2772
- return {
2773
- type: "static_private_key_jwt",
2774
- client_id,
2775
- jwt_bearer_assertion,
2776
- client_name: asNonEmptyString(flat.auth_client_name),
2777
- scope: asNonEmptyString(flat.auth_scope)
2778
- };
2779
- }
2780
- case "authorization_code": {
2781
- const client_id = asNonEmptyString(flat.auth_client_id);
2782
- const redirect_url = asNonEmptyString(flat.auth_redirect_url);
2783
- if (!client_id || !redirect_url)
2784
- return;
2785
- return {
2786
- type: "authorization_code",
2787
- client_id,
2788
- client_secret: asNonEmptyString(flat.auth_client_secret),
2789
- redirect_url,
2790
- scope: asNonEmptyString(flat.auth_scope)
2791
- };
2792
- }
2793
- default:
2794
- return;
2795
- }
2796
- }
2797
- // src/mcp/McpAuthProvider.ts
2798
- import {
2799
- ClientCredentialsProvider,
2800
- PrivateKeyJwtProvider,
2801
- StaticPrivateKeyJwtProvider,
2802
- createPrivateKeyJwtAuth
2803
- } from "@modelcontextprotocol/sdk/client/auth-extensions.js";
2804
- import { UnauthorizedError } from "@modelcontextprotocol/sdk/client/auth.js";
2805
- function normalizeServerUrl(serverUrl) {
2806
- try {
2807
- const u = new URL(serverUrl);
2808
- return u.origin + u.pathname.replace(/\/+$/, "");
2809
- } catch {
2810
- return serverUrl;
2811
- }
2812
- }
2813
- function storeKey(serverUrl, suffix) {
2814
- return `mcp:oauth:${normalizeServerUrl(serverUrl)}:${suffix}`;
2815
- }
2816
-
2817
- class CredentialStoreOAuthProvider {
2818
- store;
2819
- serverUrl;
2820
- _clientMetadata;
2821
- _redirectUrl;
2822
- _initialClientInfo;
2823
- prepareTokenRequest;
2824
- addClientAuthentication;
2825
- constructor(options) {
2826
- this.store = options.store;
2827
- this.serverUrl = options.serverUrl;
2828
- this._clientMetadata = options.clientMetadata;
2829
- this._redirectUrl = options.redirectUrl;
2830
- this._initialClientInfo = options.initialClientInfo;
2831
- if (options.prepareTokenRequest) {
2832
- this.prepareTokenRequest = options.prepareTokenRequest;
2833
- }
2834
- if (options.addClientAuthentication) {
2835
- this.addClientAuthentication = options.addClientAuthentication;
2836
- }
2837
- }
2838
- get redirectUrl() {
2839
- return this._redirectUrl;
2840
- }
2841
- get clientMetadata() {
2842
- return this._clientMetadata;
2843
- }
2844
- async clientInformation() {
2845
- const raw = await this.store.get(storeKey(this.serverUrl, "client_info"));
2846
- if (!raw)
2847
- return this._initialClientInfo;
2848
- return JSON.parse(raw);
2849
- }
2850
- async saveClientInformation(info) {
2851
- await this.store.put(storeKey(this.serverUrl, "client_info"), JSON.stringify(info));
2852
- }
2853
- async tokens() {
2854
- const raw = await this.store.get(storeKey(this.serverUrl, "tokens"));
2855
- if (!raw)
2856
- return;
2857
- return JSON.parse(raw);
2858
- }
2859
- async saveTokens(tokens) {
2860
- const expiresAt = tokens.expires_in != null ? new Date(Date.now() + tokens.expires_in * 1000) : undefined;
2861
- await this.store.put(storeKey(this.serverUrl, "tokens"), JSON.stringify(tokens), {
2862
- expiresAt
2863
- });
2864
- }
2865
- async redirectToAuthorization(authorizationUrl) {
2866
- throw new Error(`MCP OAuth authorization required. ` + `Open this URL to authorize: ${authorizationUrl.toString()}`);
2867
- }
2868
- async saveCodeVerifier(codeVerifier) {
2869
- await this.store.put(storeKey(this.serverUrl, "code_verifier"), codeVerifier);
2870
- }
2871
- async codeVerifier() {
2872
- const v = await this.store.get(storeKey(this.serverUrl, "code_verifier"));
2873
- if (!v)
2874
- throw new Error("No code verifier saved for this session");
2875
- return v;
2876
- }
2877
- async saveDiscoveryState(state) {
2878
- await this.store.put(storeKey(this.serverUrl, "discovery"), JSON.stringify(state));
2879
- }
2880
- async discoveryState() {
2881
- const raw = await this.store.get(storeKey(this.serverUrl, "discovery"));
2882
- if (!raw)
2883
- return;
2884
- return JSON.parse(raw);
2885
- }
2886
- async invalidateCredentials(scope) {
2887
- const deleteKey = async (suffix) => {
2888
- await this.store.delete(storeKey(this.serverUrl, suffix));
2889
- };
2890
- switch (scope) {
2891
- case "all":
2892
- await deleteKey("tokens");
2893
- await deleteKey("client_info");
2894
- await deleteKey("code_verifier");
2895
- await deleteKey("discovery");
2896
- break;
2897
- case "client":
2898
- await deleteKey("client_info");
2899
- break;
2900
- case "tokens":
2901
- await deleteKey("tokens");
2902
- break;
2903
- case "verifier":
2904
- await deleteKey("code_verifier");
2905
- break;
2906
- case "discovery":
2907
- await deleteKey("discovery");
2908
- break;
2909
- }
2910
- }
2911
- }
2912
- function createAuthProvider(auth, serverUrl, credentialStore) {
2913
- switch (auth.type) {
2914
- case "none":
2915
- case "bearer":
2916
- return;
2917
- case "client_credentials": {
2918
- if (!credentialStore) {
2919
- return new ClientCredentialsProvider({
2920
- clientId: auth.client_id,
2921
- clientSecret: auth.client_secret,
2922
- clientName: auth.client_name,
2923
- scope: auth.scope
2924
- });
2925
- }
2926
- const prepareTokenRequest = (scope) => {
2927
- const params = new URLSearchParams({ grant_type: "client_credentials" });
2928
- const effectiveScope = scope ?? auth.scope;
2929
- if (effectiveScope)
2930
- params.set("scope", effectiveScope);
2931
- return params;
2932
- };
2933
- return new CredentialStoreOAuthProvider({
2934
- store: credentialStore,
2935
- serverUrl,
2936
- clientMetadata: {
2937
- redirect_uris: [],
2938
- grant_types: ["client_credentials"],
2939
- token_endpoint_auth_method: "client_secret_basic",
2940
- client_name: auth.client_name
2941
- },
2942
- initialClientInfo: {
2943
- client_id: auth.client_id,
2944
- client_secret: auth.client_secret
2945
- },
2946
- prepareTokenRequest
2947
- });
2948
- }
2949
- case "private_key_jwt": {
2950
- if (!credentialStore) {
2951
- return new PrivateKeyJwtProvider({
2952
- clientId: auth.client_id,
2953
- privateKey: auth.private_key,
2954
- algorithm: auth.algorithm,
2955
- clientName: auth.client_name,
2956
- jwtLifetimeSeconds: auth.jwt_lifetime_seconds,
2957
- scope: auth.scope
2958
- });
2959
- }
2960
- const addClientAuth = createPrivateKeyJwtAuth({
2961
- issuer: auth.client_id,
2962
- subject: auth.client_id,
2963
- privateKey: auth.private_key,
2964
- alg: auth.algorithm,
2965
- lifetimeSeconds: auth.jwt_lifetime_seconds
2966
- });
2967
- const prepareTokenRequest = (scope) => {
2968
- const params = new URLSearchParams({ grant_type: "client_credentials" });
2969
- const effectiveScope = scope ?? auth.scope;
2970
- if (effectiveScope)
2971
- params.set("scope", effectiveScope);
2972
- return params;
2973
- };
2974
- return new CredentialStoreOAuthProvider({
2975
- store: credentialStore,
2976
- serverUrl,
2977
- clientMetadata: {
2978
- redirect_uris: [],
2979
- grant_types: ["client_credentials"],
2980
- token_endpoint_auth_method: "private_key_jwt",
2981
- client_name: auth.client_name
2982
- },
2983
- initialClientInfo: { client_id: auth.client_id },
2984
- prepareTokenRequest,
2985
- addClientAuthentication: addClientAuth
2986
- });
2987
- }
2988
- case "static_private_key_jwt": {
2989
- if (!credentialStore) {
2990
- return new StaticPrivateKeyJwtProvider({
2991
- clientId: auth.client_id,
2992
- jwtBearerAssertion: auth.jwt_bearer_assertion,
2993
- clientName: auth.client_name,
2994
- scope: auth.scope
2995
- });
2996
- }
2997
- const assertion = auth.jwt_bearer_assertion;
2998
- const addClientAuth = (_headers, params) => {
2999
- params.set("client_assertion_type", "urn:ietf:params:oauth:client-assertion-type:jwt-bearer");
3000
- params.set("client_assertion", assertion);
3001
- };
3002
- const prepareTokenRequest = (scope) => {
3003
- const params = new URLSearchParams({ grant_type: "client_credentials" });
3004
- const effectiveScope = scope ?? auth.scope;
3005
- if (effectiveScope)
3006
- params.set("scope", effectiveScope);
3007
- return params;
3008
- };
3009
- return new CredentialStoreOAuthProvider({
3010
- store: credentialStore,
3011
- serverUrl,
3012
- clientMetadata: {
3013
- redirect_uris: [],
3014
- grant_types: ["client_credentials"],
3015
- token_endpoint_auth_method: "private_key_jwt",
3016
- client_name: auth.client_name
3017
- },
3018
- initialClientInfo: { client_id: auth.client_id },
3019
- prepareTokenRequest,
3020
- addClientAuthentication: addClientAuth
3021
- });
3022
- }
3023
- case "authorization_code": {
3024
- if (!credentialStore) {
3025
- throw new Error("authorization_code auth requires a credential store for token persistence");
3026
- }
3027
- return new CredentialStoreOAuthProvider({
3028
- store: credentialStore,
3029
- serverUrl,
3030
- clientMetadata: {
3031
- redirect_uris: [auth.redirect_url],
3032
- grant_types: ["authorization_code", "refresh_token"],
3033
- token_endpoint_auth_method: auth.client_secret ? "client_secret_basic" : "none",
3034
- scope: auth.scope
3035
- },
3036
- initialClientInfo: {
3037
- client_id: auth.client_id,
3038
- ...auth.client_secret ? { client_secret: auth.client_secret } : {}
3039
- },
3040
- redirectUrl: auth.redirect_url
3041
- });
3042
- }
3043
- default:
3044
- return;
3045
- }
3046
- }
3047
- async function resolveAuthSecrets(auth, credentialStore) {
3048
- if (auth.type === "none")
3049
- return auth;
3050
- const store = credentialStore ?? getGlobalCredentialStore();
3051
- async function resolve(value) {
3052
- if (!value)
3053
- return value;
3054
- const resolved = await store.get(value);
3055
- return resolved ?? value;
3056
- }
3057
- switch (auth.type) {
3058
- case "bearer":
3059
- return { ...auth, token: await resolve(auth.token) ?? auth.token };
3060
- case "client_credentials":
3061
- return {
3062
- ...auth,
3063
- client_secret: await resolve(auth.client_secret) ?? auth.client_secret
3064
- };
3065
- case "private_key_jwt":
3066
- return {
3067
- ...auth,
3068
- private_key: await resolve(auth.private_key) ?? auth.private_key
3069
- };
3070
- case "static_private_key_jwt":
3071
- return {
3072
- ...auth,
3073
- jwt_bearer_assertion: await resolve(auth.jwt_bearer_assertion) ?? auth.jwt_bearer_assertion
3074
- };
3075
- case "authorization_code":
3076
- return {
3077
- ...auth,
3078
- client_secret: await resolve(auth.client_secret)
3079
- };
3080
- default:
3081
- return auth;
3082
- }
3083
- }
3084
1215
  // src/telemetry/ITelemetryProvider.ts
3085
1216
  var SpanStatusCode = {
3086
1217
  UNSET: 0,
@@ -3234,167 +1365,209 @@ function getTelemetryProvider() {
3234
1365
  function setTelemetryProvider(provider) {
3235
1366
  globalServiceRegistry.registerInstance(TELEMETRY_PROVIDER, provider);
3236
1367
  }
3237
- // src/compress/compress.browser.ts
3238
- async function compress(input, algorithm = "gzip") {
3239
- const sourceBlob = new Blob([typeof input === "string" ? input : new Uint8Array(input)]);
3240
- const compressedStream = sourceBlob.stream().pipeThrough(new CompressionStream(algorithm));
3241
- const compressedBuffer = await new Response(compressedStream).arrayBuffer();
3242
- return new Uint8Array(compressedBuffer);
3243
- }
3244
- async function decompress(input, algorithm = "gzip") {
3245
- const sourceBlob = new Blob([new Uint8Array(input)]);
3246
- const decompressedStream = sourceBlob.stream().pipeThrough(new DecompressionStream(algorithm));
3247
- return await new Response(decompressedStream).text();
3248
- }
3249
- // src/mcp/McpClientUtil.browser.ts
3250
- import { Client } from "@modelcontextprotocol/sdk/client";
3251
- import { SSEClientTransport } from "@modelcontextprotocol/sdk/client/sse.js";
3252
- import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
3253
- var mcpTransportTypes = ["streamable-http", "sse"];
3254
- var mcpServerConfigSchema = {
3255
- properties: {
3256
- transport: {
3257
- type: "string",
3258
- enum: mcpTransportTypes,
3259
- title: "Transport",
3260
- description: "The transport type to use for connecting to the MCP server"
3261
- },
3262
- server_url: {
3263
- type: "string",
3264
- format: "uri",
3265
- title: "Server URL",
3266
- description: "The URL of the MCP server (for streamable-http transport)"
3267
- },
3268
- ...mcpAuthConfigSchema.properties
3269
- },
3270
- allOf: mcpAuthConfigSchema.allOf
3271
- };
3272
- async function createMcpClient(config, signal) {
3273
- let transport;
3274
- let auth = config.auth ?? buildAuthConfig({ ...config });
3275
- if (auth && auth.type !== "none") {
3276
- auth = await resolveAuthSecrets(auth, getGlobalCredentialStore());
3277
- }
3278
- const authProvider = config.authProvider ?? (auth && auth.type !== "none" && auth.type !== "bearer" ? createAuthProvider(auth, config.server_url ?? "", getGlobalCredentialStore()) : undefined);
3279
- const headers = {
3280
- ...auth?.type === "bearer" ? { Authorization: `Bearer ${auth.token}` } : {}
3281
- };
3282
- const requestInit = { headers };
3283
- switch (config.transport) {
3284
- case "sse": {
3285
- transport = new SSEClientTransport(new URL(config.server_url), {
3286
- authProvider,
3287
- requestInit
3288
- });
3289
- break;
3290
- }
3291
- case "streamable-http": {
3292
- transport = new StreamableHTTPClientTransport(new URL(config.server_url), {
3293
- authProvider,
3294
- requestInit
3295
- });
3296
- break;
1368
+ // src/worker/WorkerServerBase.ts
1369
+ var WORKER_SERVER = createServiceToken("worker.server");
1370
+ function extractTransferables(obj) {
1371
+ const transferables = [];
1372
+ const seen = new WeakSet;
1373
+ function findTransferables(value) {
1374
+ if (value && typeof value === "object" && seen.has(value)) {
1375
+ return;
3297
1376
  }
3298
- default:
3299
- throw new Error(`Unsupported transport type: ${config.transport}`);
3300
- }
3301
- const client = new Client({ name: "workglow-mcp-client", version: "1.0.0" });
3302
- if (signal) {
3303
- signal.addEventListener("abort", () => {
3304
- client.close().catch(() => {});
3305
- }, { once: true });
3306
- }
3307
- try {
3308
- await client.connect(transport);
3309
- } catch (err) {
3310
- const message = err instanceof Error ? err.message : String(err);
3311
- const url = config.server_url ?? "";
3312
- const is405 = message.includes("405") || message.includes("Method Not Allowed") || typeof err === "object" && err !== null && "status" in err && err.status === 405;
3313
- if (is405) {
3314
- throw new Error(`MCP connection failed with 405 Method Not Allowed for ${url}. ` + `This usually means the server does not accept GET requests. `, { cause: err });
1377
+ if (value && typeof value === "object") {
1378
+ seen.add(value);
3315
1379
  }
3316
- const is406 = message.includes("406") || message.includes("Not Acceptable") || typeof err === "object" && err !== null && "code" in err && err.code === 406;
3317
- if (is406) {
3318
- throw new Error(`MCP connection failed with 406 Not Acceptable for ${url}. ` + `Try using transport "sse" instead of "streamable-http", or ensure the server accepts the request format (Accept: application/json, text/event-stream and MCP-Protocol-Version).`, { cause: err });
1380
+ if (value instanceof Float32Array || value instanceof Int16Array) {
1381
+ transferables.push(value.buffer);
1382
+ } else if (value instanceof Uint8Array || value instanceof Uint8ClampedArray || value instanceof Int8Array || value instanceof Uint16Array || value instanceof Int32Array || value instanceof Uint32Array || value instanceof Float64Array || value instanceof BigInt64Array || value instanceof BigUint64Array) {
1383
+ transferables.push(value.buffer);
1384
+ } else if (typeof OffscreenCanvas !== "undefined" && value instanceof OffscreenCanvas) {
1385
+ transferables.push(value);
1386
+ } else if (typeof ImageBitmap !== "undefined" && value instanceof ImageBitmap) {
1387
+ transferables.push(value);
1388
+ } else if (typeof VideoFrame !== "undefined" && value instanceof VideoFrame) {
1389
+ transferables.push(value);
1390
+ } else if (typeof MessagePort !== "undefined" && value instanceof MessagePort) {
1391
+ transferables.push(value);
1392
+ } else if (value instanceof ArrayBuffer) {
1393
+ transferables.push(value);
1394
+ } else if (Array.isArray(value)) {
1395
+ value.forEach(findTransferables);
1396
+ } else if (value && typeof value === "object") {
1397
+ Object.values(value).forEach(findTransferables);
3319
1398
  }
3320
- throw err;
3321
1399
  }
3322
- return { client, transport };
3323
- }
3324
- var mcpClientFactory = {
3325
- create: createMcpClient
3326
- };
3327
- // src/media/image.ts
3328
- function parseDataUri(dataUri) {
3329
- const match = dataUri.match(/^data:([^;]+);base64,(.+)$/);
3330
- if (!match) {
3331
- throw new Error("Invalid base64 data URI");
3332
- }
3333
- return {
3334
- mimeType: match[1],
3335
- base64: match[2]
3336
- };
1400
+ findTransferables(obj);
1401
+ return transferables;
3337
1402
  }
3338
1403
 
3339
- // src/media/image.browser.ts
3340
- var convertBlobToOffscreenCanvas = async (blob) => {
3341
- const img = await createImageBitmap(blob);
3342
- const ctx = new OffscreenCanvas(img.width, img.height).getContext("2d");
3343
- if (!ctx) {
3344
- throw new Error("Failed to get context.");
3345
- }
3346
- ctx.drawImage(img, 0, 0);
3347
- return ctx.canvas;
3348
- };
3349
- function dataUriToBlob(dataUri) {
3350
- const { mimeType, base64 } = parseDataUri(dataUri);
3351
- const binary = atob(base64);
3352
- const bytes = Uint8Array.from(binary, (char) => char.charCodeAt(0));
3353
- const blob = new Blob([bytes], { type: mimeType });
3354
- return blob;
3355
- }
3356
- async function convertImageDataToUseableForm(imageData, supports) {
3357
- if (imageData === null || imageData === undefined) {
3358
- throw new Error("Image data is null or undefined");
3359
- }
3360
- if (supports.includes("ImageBitmap") && imageData instanceof ImageBitmap) {
3361
- return imageData;
3362
- }
3363
- if (supports.includes("VideoFrame") && imageData instanceof VideoFrame) {
3364
- return imageData;
3365
- }
3366
- if (supports.includes("Blob") && imageData instanceof Blob) {
3367
- return imageData;
1404
+ class WorkerServerBase {
1405
+ constructor() {}
1406
+ functions = {};
1407
+ streamFunctions = {};
1408
+ reactiveFunctions = {};
1409
+ requestControllers = new Map;
1410
+ completedRequests = new Set;
1411
+ postResult = (id, result) => {
1412
+ if (this.completedRequests.has(id)) {
1413
+ return;
1414
+ }
1415
+ this.completedRequests.add(id);
1416
+ const transferables = extractTransferables(result);
1417
+ const uniqueTransferables = [...new Set(transferables)];
1418
+ postMessage({ id, type: "complete", data: result }, uniqueTransferables);
1419
+ };
1420
+ postError = (id, errorMessage) => {
1421
+ if (this.completedRequests.has(id)) {
1422
+ return;
1423
+ }
1424
+ this.completedRequests.add(id);
1425
+ postMessage({ id, type: "error", data: errorMessage });
1426
+ };
1427
+ postStreamChunk = (id, event) => {
1428
+ if (this.completedRequests.has(id)) {
1429
+ return;
1430
+ }
1431
+ postMessage({ id, type: "stream_chunk", data: event });
1432
+ };
1433
+ sendReady() {
1434
+ postMessage({
1435
+ type: "ready",
1436
+ functions: Object.keys(this.functions),
1437
+ streamFunctions: Object.keys(this.streamFunctions),
1438
+ reactiveFunctions: Object.keys(this.reactiveFunctions)
1439
+ });
3368
1440
  }
3369
- if (supports.includes("ImageBinary") && typeof imageData === "object" && "data" in imageData && "width" in imageData && "height" in imageData && "channels" in imageData) {
3370
- return imageData;
1441
+ registerFunction(name, fn) {
1442
+ this.functions[name] = fn;
3371
1443
  }
3372
- if (supports.includes("ImageBitmap") && imageData instanceof Blob) {
3373
- return createImageBitmap(imageData);
1444
+ registerReactiveFunction(name, fn) {
1445
+ this.reactiveFunctions[name] = fn;
3374
1446
  }
3375
- if (supports.includes("OffscreenCanvas") && imageData instanceof Blob) {
3376
- return await convertBlobToOffscreenCanvas(imageData);
1447
+ registerStreamFunction(name, fn) {
1448
+ this.streamFunctions[name] = fn;
3377
1449
  }
3378
- if (supports.includes("ImageBitmap") && imageData instanceof OffscreenCanvas) {
3379
- return imageData.transferToImageBitmap();
1450
+ async handleMessage(event) {
1451
+ const { id, type, functionName, args, stream, reactive } = event.data;
1452
+ if (type === "abort") {
1453
+ return await this.handleAbort(id);
1454
+ }
1455
+ if (type === "call") {
1456
+ if (stream) {
1457
+ return await this.handleStreamCall(id, functionName, args);
1458
+ }
1459
+ if (reactive) {
1460
+ return await this.handleReactiveCall(id, functionName, args);
1461
+ }
1462
+ return await this.handleCall(id, functionName, args);
1463
+ }
3380
1464
  }
3381
- if (supports.includes("ImageBitmap") && typeof imageData === "string") {
3382
- return createImageBitmap(dataUriToBlob(imageData));
1465
+ async handleAbort(id) {
1466
+ if (this.requestControllers.has(id)) {
1467
+ const controller = this.requestControllers.get(id);
1468
+ controller?.abort();
1469
+ this.requestControllers.delete(id);
1470
+ this.postError(id, "Operation aborted");
1471
+ }
3383
1472
  }
3384
- if (supports.includes("OffscreenCanvas") && typeof imageData === "string") {
3385
- return convertBlobToOffscreenCanvas(dataUriToBlob(imageData));
1473
+ async handleReactiveCall(id, functionName, [input, output, model]) {
1474
+ if (!(functionName in this.reactiveFunctions)) {
1475
+ this.postResult(id, undefined);
1476
+ return;
1477
+ }
1478
+ try {
1479
+ const fn = this.reactiveFunctions[functionName];
1480
+ const result = await fn(input, output, model);
1481
+ this.postResult(id, result);
1482
+ } catch (error) {
1483
+ this.postError(id, error.message);
1484
+ }
3386
1485
  }
3387
- if (supports.includes("Blob") && typeof imageData === "string") {
3388
- return dataUriToBlob(imageData);
1486
+ async handleCall(id, functionName, [input, model]) {
1487
+ if (!(functionName in this.functions)) {
1488
+ this.postError(id, `Function ${functionName} not found`);
1489
+ return;
1490
+ }
1491
+ try {
1492
+ const abortController = new AbortController;
1493
+ this.requestControllers.set(id, abortController);
1494
+ const fn = this.functions[functionName];
1495
+ const postProgress = (progress, message, details) => {
1496
+ if (!this.completedRequests.has(id)) {
1497
+ postMessage({ id, type: "progress", data: { progress, message, details } });
1498
+ }
1499
+ };
1500
+ const result = await fn(input, model, postProgress, abortController.signal);
1501
+ this.postResult(id, result);
1502
+ } catch (error) {
1503
+ this.postError(id, error.message);
1504
+ } finally {
1505
+ this.requestControllers.delete(id);
1506
+ setTimeout(() => {
1507
+ this.completedRequests.delete(id);
1508
+ }, 1000);
1509
+ }
3389
1510
  }
3390
- if (supports.includes("DataUri") && typeof imageData === "string" && imageData.startsWith("data:")) {
3391
- return imageData;
1511
+ async handleStreamCall(id, functionName, [input, model]) {
1512
+ if (functionName in this.streamFunctions) {
1513
+ try {
1514
+ const abortController = new AbortController;
1515
+ this.requestControllers.set(id, abortController);
1516
+ const fn = this.streamFunctions[functionName];
1517
+ const iterable = fn(input, model, abortController.signal);
1518
+ for await (const event of iterable) {
1519
+ if (this.completedRequests.has(id))
1520
+ break;
1521
+ this.postStreamChunk(id, event);
1522
+ }
1523
+ this.postResult(id, undefined);
1524
+ } catch (error) {
1525
+ this.postError(id, error.message);
1526
+ } finally {
1527
+ this.requestControllers.delete(id);
1528
+ setTimeout(() => {
1529
+ this.completedRequests.delete(id);
1530
+ }, 1000);
1531
+ }
1532
+ } else if (functionName in this.functions) {
1533
+ try {
1534
+ const abortController = new AbortController;
1535
+ this.requestControllers.set(id, abortController);
1536
+ const fn = this.functions[functionName];
1537
+ const noopProgress = () => {};
1538
+ const result = await fn(input, model, noopProgress, abortController.signal);
1539
+ this.postStreamChunk(id, { type: "finish", data: result });
1540
+ this.postResult(id, undefined);
1541
+ } catch (error) {
1542
+ this.postError(id, error.message);
1543
+ } finally {
1544
+ this.requestControllers.delete(id);
1545
+ setTimeout(() => {
1546
+ this.completedRequests.delete(id);
1547
+ }, 1000);
1548
+ }
1549
+ } else {
1550
+ this.postError(id, `Function ${functionName} not found`);
1551
+ }
3392
1552
  }
3393
- throw new Error(`Unsupported image data type: ${typeof imageData} `);
3394
1553
  }
1554
+
3395
1555
  // src/worker/Worker.browser.ts
3396
1556
  var Worker = globalThis.Worker;
3397
- var parentPort2 = self;
1557
+ var parentPort = self;
1558
+ class WorkerServer extends WorkerServerBase {
1559
+ constructor() {
1560
+ parentPort?.addEventListener("message", async (event) => {
1561
+ const msg = {
1562
+ type: event.type,
1563
+ data: event.data
1564
+ };
1565
+ await this.handleMessage(msg);
1566
+ });
1567
+ super();
1568
+ }
1569
+ }
1570
+ globalServiceRegistry.register(WORKER_SERVER, () => new WorkerServer, true);
3398
1571
  export {
3399
1572
  uuid4,
3400
1573
  toSQLiteTimestamp,
@@ -3406,26 +1579,10 @@ export {
3406
1579
  setGlobalCredentialStore,
3407
1580
  serialize,
3408
1581
  resolveCredential,
3409
- resolveAuthSecrets,
3410
1582
  registerInputResolver,
3411
- parsePartialJson,
3412
- parseDataUri,
3413
- parentPort2 as parentPort,
1583
+ parentPort,
3414
1584
  objectOfArraysAsArrayOfObjects,
3415
- normalizeNumberArray,
3416
- normalize,
3417
- mcpTransportTypes,
3418
- mcpServerConfigSchema,
3419
- mcpClientFactory,
3420
- mcpAuthTypes,
3421
- mcpAuthConfigSchema,
3422
1585
  makeFingerprint,
3423
- magnitude,
3424
- jaccardSimilarity,
3425
- isTypedArray,
3426
- inner,
3427
- hammingSimilarity,
3428
- hammingDistance,
3429
1586
  globalServiceRegistry,
3430
1587
  globalContainer,
3431
1588
  getTelemetryProvider,
@@ -3437,49 +1594,26 @@ export {
3437
1594
  deriveKey,
3438
1595
  deepEqual,
3439
1596
  decrypt,
3440
- decompress,
3441
- createTypedArrayFrom,
3442
1597
  createServiceToken,
3443
- createMcpClient,
3444
- createAuthProvider,
3445
- cosineSimilarity,
3446
- convertImageDataToUseableForm,
3447
- compress,
3448
- compileSchema,
3449
1598
  collectPropertyValues,
3450
- buildAuthConfig,
3451
1599
  bufToBase64,
3452
1600
  base64ToBuf,
3453
- areSemanticallyCompatible,
3454
- areObjectSchemasSemanticallyCompatible,
3455
1601
  WorkerServer,
3456
1602
  WorkerManager,
3457
1603
  Worker,
3458
1604
  WORKER_SERVER,
3459
1605
  WORKER_MANAGER,
3460
- UnauthorizedError,
3461
- TypedArraySchema,
3462
- TensorType,
3463
- TensorSchema,
3464
1606
  TELEMETRY_PROVIDER,
3465
1607
  SpanStatusCode,
3466
1608
  ServiceRegistry,
3467
1609
  OTelTelemetryProvider,
3468
1610
  NullLogger,
3469
1611
  NoopTelemetryProvider,
3470
- NodeDoesntExistError,
3471
- NodeAlreadyExistsError,
3472
1612
  LOGGER,
3473
1613
  InMemoryCredentialStore,
3474
1614
  INPUT_RESOLVERS,
3475
- Graph,
3476
- FromSchemaDefaultOptions,
3477
1615
  EventEmitter,
3478
1616
  EnvCredentialStore,
3479
- DirectedGraph,
3480
- DirectedAcyclicGraph,
3481
- CycleError,
3482
- CredentialStoreOAuthProvider,
3483
1617
  Container,
3484
1618
  ConsoleTelemetryProvider,
3485
1619
  ConsoleLogger,
@@ -3488,4 +1622,4 @@ export {
3488
1622
  BaseError
3489
1623
  };
3490
1624
 
3491
- //# debugId=F92FC9473BBE2EE764756E2164756E21
1625
+ //# debugId=C665251EA27E791364756E2164756E21