@workglow/util 0.0.121 → 0.0.122
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser.js +337 -1250
- package/dist/browser.js.map +6 -11
- package/dist/bun.js +334 -1260
- package/dist/bun.js.map +6 -11
- package/dist/common.d.ts +0 -5
- package/dist/common.d.ts.map +1 -1
- package/dist/credentials/ChainedCredentialStore.d.ts.map +1 -1
- package/dist/credentials/EnvCredentialStore.d.ts.map +1 -1
- package/dist/credentials/InMemoryCredentialStore.d.ts.map +1 -1
- package/dist/di/Container.d.ts.map +1 -1
- package/dist/di/ServiceRegistry.d.ts.map +1 -1
- package/dist/events/EventEmitter.d.ts.map +1 -1
- package/dist/graph/directedAcyclicGraph.d.ts.map +1 -1
- package/dist/graph/directedGraph.d.ts.map +1 -1
- package/dist/graph/errors.d.ts.map +1 -1
- package/dist/graph/graph.d.ts.map +1 -1
- package/dist/logging/ConsoleLogger.d.ts.map +1 -1
- package/dist/logging/NullLogger.d.ts.map +1 -1
- package/dist/node.js +335 -1260
- package/dist/node.js.map +6 -11
- package/dist/telemetry/ConsoleTelemetryProvider.d.ts.map +1 -1
- package/dist/telemetry/NoopTelemetryProvider.d.ts.map +1 -1
- package/dist/telemetry/OTelTelemetryProvider.d.ts.map +1 -1
- package/dist/types.d.ts +0 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/utilities/BaseError.d.ts.map +1 -1
- package/dist/vector/Tensor.d.ts +1 -1
- package/dist/vector/Tensor.d.ts.map +1 -1
- package/dist/vector/TypedArray.d.ts +4 -4
- package/dist/vector/TypedArray.d.ts.map +1 -1
- package/dist/worker/Worker.browser.d.ts +6 -1
- package/dist/worker/Worker.browser.d.ts.map +1 -1
- package/dist/worker/Worker.bun.d.ts +6 -1
- package/dist/worker/Worker.bun.d.ts.map +1 -1
- package/dist/worker/Worker.node.d.ts +6 -1
- package/dist/worker/Worker.node.d.ts.map +1 -1
- package/dist/worker/WorkerManager.d.ts +7 -1
- package/dist/worker/WorkerManager.d.ts.map +1 -1
- package/dist/worker/{WorkerServer.d.ts → WorkerServerBase.d.ts} +5 -4
- package/dist/worker/WorkerServerBase.d.ts.map +1 -0
- package/dist/worker-browser.js +894 -0
- package/dist/worker-browser.js.map +19 -0
- package/dist/worker-bun.js +895 -0
- package/dist/worker-bun.js.map +19 -0
- package/dist/worker-entry.d.ts +25 -0
- package/dist/worker-entry.d.ts.map +1 -0
- package/dist/worker-node.js +914 -0
- package/dist/worker-node.js.map +19 -0
- package/package.json +23 -20
- package/dist/json-schema/SchemaUtils.d.ts +0 -58
- package/dist/json-schema/SchemaUtils.d.ts.map +0 -1
- package/dist/json-schema/SchemaValidation.d.ts +0 -8
- package/dist/json-schema/SchemaValidation.d.ts.map +0 -1
- package/dist/mcp/McpAuthProvider.d.ts +0 -70
- package/dist/mcp/McpAuthProvider.d.ts.map +0 -1
- package/dist/mcp/McpAuthTypes.d.ts +0 -218
- package/dist/mcp/McpAuthTypes.d.ts.map +0 -1
- package/dist/mcp/McpClientUtil.browser.d.ts +0 -198
- package/dist/mcp/McpClientUtil.browser.d.ts.map +0 -1
- package/dist/mcp/McpClientUtil.node.d.ts +0 -222
- package/dist/mcp/McpClientUtil.node.d.ts.map +0 -1
- package/dist/worker/WorkerServer.d.ts.map +0 -1
package/dist/browser.js
CHANGED
|
@@ -885,357 +885,6 @@ var FromSchemaDefaultOptions = {
|
|
|
885
885
|
references: false,
|
|
886
886
|
deserialize: false
|
|
887
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
888
|
// src/json-schema/parsePartialJson.ts
|
|
1240
889
|
function parsePartialJson(text) {
|
|
1241
890
|
const trimmed = text.trim();
|
|
@@ -1942,10 +1591,22 @@ class WorkerManager {
|
|
|
1942
1591
|
workerFunctions = new Map;
|
|
1943
1592
|
workerStreamFunctions = new Map;
|
|
1944
1593
|
workerReactiveFunctions = new Map;
|
|
1945
|
-
|
|
1946
|
-
|
|
1594
|
+
lazyFactories = new Map;
|
|
1595
|
+
lazyInitPromises = new Map;
|
|
1596
|
+
registerWorker(name, workerOrFactory) {
|
|
1597
|
+
if (this.workers.has(name)) {
|
|
1947
1598
|
throw new Error(`Worker ${name} is already registered.`);
|
|
1948
|
-
|
|
1599
|
+
}
|
|
1600
|
+
if (this.lazyFactories.has(name)) {
|
|
1601
|
+
throw new Error(`Worker ${name} is already registered.`);
|
|
1602
|
+
}
|
|
1603
|
+
if (typeof workerOrFactory === "function") {
|
|
1604
|
+
this.lazyFactories.set(name, workerOrFactory);
|
|
1605
|
+
} else {
|
|
1606
|
+
this.attachWorkerInstance(name, workerOrFactory);
|
|
1607
|
+
}
|
|
1608
|
+
}
|
|
1609
|
+
attachWorkerInstance(name, worker) {
|
|
1949
1610
|
this.workers.set(name, worker);
|
|
1950
1611
|
worker.addEventListener("error", (event) => {
|
|
1951
1612
|
console.error("Worker Error:", event.message, "at", event.filename, "line:", event.lineno);
|
|
@@ -1967,6 +1628,29 @@ class WorkerManager {
|
|
|
1967
1628
|
});
|
|
1968
1629
|
this.readyWorkers.set(name, readyPromise);
|
|
1969
1630
|
}
|
|
1631
|
+
async ensureWorkerReady(name) {
|
|
1632
|
+
if (this.workers.has(name)) {
|
|
1633
|
+
await this.readyWorkers.get(name);
|
|
1634
|
+
return;
|
|
1635
|
+
}
|
|
1636
|
+
const factory = this.lazyFactories.get(name);
|
|
1637
|
+
if (!factory) {
|
|
1638
|
+
throw new Error(`Worker ${name} not found.`);
|
|
1639
|
+
}
|
|
1640
|
+
let init = this.lazyInitPromises.get(name);
|
|
1641
|
+
if (!init) {
|
|
1642
|
+
init = (async () => {
|
|
1643
|
+
const f = this.lazyFactories.get(name);
|
|
1644
|
+
this.lazyFactories.delete(name);
|
|
1645
|
+
const worker = f();
|
|
1646
|
+
this.attachWorkerInstance(name, worker);
|
|
1647
|
+
})();
|
|
1648
|
+
this.lazyInitPromises.set(name, init);
|
|
1649
|
+
}
|
|
1650
|
+
await init;
|
|
1651
|
+
await this.readyWorkers.get(name);
|
|
1652
|
+
this.lazyInitPromises.delete(name);
|
|
1653
|
+
}
|
|
1970
1654
|
getWorker(name) {
|
|
1971
1655
|
const worker = this.workers.get(name);
|
|
1972
1656
|
if (!worker)
|
|
@@ -1974,6 +1658,7 @@ class WorkerManager {
|
|
|
1974
1658
|
return worker;
|
|
1975
1659
|
}
|
|
1976
1660
|
async callWorkerFunction(workerName, functionName, args, options) {
|
|
1661
|
+
await this.ensureWorkerReady(workerName);
|
|
1977
1662
|
const worker = this.workers.get(workerName);
|
|
1978
1663
|
if (!worker)
|
|
1979
1664
|
throw new Error(`Worker ${workerName} not found.`);
|
|
@@ -2019,6 +1704,7 @@ class WorkerManager {
|
|
|
2019
1704
|
});
|
|
2020
1705
|
}
|
|
2021
1706
|
async callWorkerReactiveFunction(workerName, functionName, args) {
|
|
1707
|
+
await this.ensureWorkerReady(workerName);
|
|
2022
1708
|
const worker = this.workers.get(workerName);
|
|
2023
1709
|
if (!worker)
|
|
2024
1710
|
return;
|
|
@@ -2050,6 +1736,7 @@ class WorkerManager {
|
|
|
2050
1736
|
});
|
|
2051
1737
|
}
|
|
2052
1738
|
async* callWorkerStreamFunction(workerName, functionName, args, options) {
|
|
1739
|
+
await this.ensureWorkerReady(workerName);
|
|
2053
1740
|
const worker = this.workers.get(workerName);
|
|
2054
1741
|
if (!worker)
|
|
2055
1742
|
throw new Error(`Worker ${workerName} not found.`);
|
|
@@ -2133,292 +1820,96 @@ class WorkerManager {
|
|
|
2133
1820
|
}
|
|
2134
1821
|
var WORKER_MANAGER = createServiceToken("worker.manager");
|
|
2135
1822
|
globalServiceRegistry.register(WORKER_MANAGER, () => new WorkerManager, true);
|
|
2136
|
-
// src/
|
|
2137
|
-
|
|
2138
|
-
|
|
2139
|
-
|
|
2140
|
-
|
|
2141
|
-
|
|
2142
|
-
|
|
1823
|
+
// src/credentials/ICredentialStore.ts
|
|
1824
|
+
var CREDENTIAL_STORE = createServiceToken("credential.store");
|
|
1825
|
+
// src/credentials/InMemoryCredentialStore.ts
|
|
1826
|
+
class InMemoryCredentialStore {
|
|
1827
|
+
store = new Map;
|
|
1828
|
+
async get(key) {
|
|
1829
|
+
const entry = this.store.get(key);
|
|
1830
|
+
if (!entry)
|
|
1831
|
+
return;
|
|
1832
|
+
if (entry.metadata.expiresAt && entry.metadata.expiresAt <= new Date) {
|
|
1833
|
+
this.store.delete(key);
|
|
2143
1834
|
return;
|
|
2144
1835
|
}
|
|
2145
|
-
|
|
2146
|
-
|
|
1836
|
+
return entry.value;
|
|
1837
|
+
}
|
|
1838
|
+
async put(key, value, options) {
|
|
1839
|
+
const now = new Date;
|
|
1840
|
+
const existing = this.store.get(key);
|
|
1841
|
+
const metadata = {
|
|
1842
|
+
label: options?.label ?? existing?.metadata.label,
|
|
1843
|
+
provider: options?.provider ?? existing?.metadata.provider,
|
|
1844
|
+
createdAt: existing?.metadata.createdAt ?? now,
|
|
1845
|
+
updatedAt: now,
|
|
1846
|
+
expiresAt: options?.expiresAt ?? existing?.metadata.expiresAt
|
|
1847
|
+
};
|
|
1848
|
+
this.store.set(key, { key, value, metadata });
|
|
1849
|
+
}
|
|
1850
|
+
async delete(key) {
|
|
1851
|
+
return this.store.delete(key);
|
|
1852
|
+
}
|
|
1853
|
+
async has(key) {
|
|
1854
|
+
const entry = this.store.get(key);
|
|
1855
|
+
if (!entry)
|
|
1856
|
+
return false;
|
|
1857
|
+
if (entry.metadata.expiresAt && entry.metadata.expiresAt <= new Date) {
|
|
1858
|
+
this.store.delete(key);
|
|
1859
|
+
return false;
|
|
2147
1860
|
}
|
|
2148
|
-
|
|
2149
|
-
|
|
2150
|
-
|
|
2151
|
-
|
|
2152
|
-
|
|
2153
|
-
|
|
2154
|
-
|
|
2155
|
-
|
|
2156
|
-
|
|
2157
|
-
|
|
2158
|
-
|
|
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);
|
|
1861
|
+
return true;
|
|
1862
|
+
}
|
|
1863
|
+
async keys() {
|
|
1864
|
+
const now = new Date;
|
|
1865
|
+
const result = [];
|
|
1866
|
+
for (const [key, entry] of this.store) {
|
|
1867
|
+
if (entry.metadata.expiresAt && entry.metadata.expiresAt <= now) {
|
|
1868
|
+
this.store.delete(key);
|
|
1869
|
+
continue;
|
|
1870
|
+
}
|
|
1871
|
+
result.push(key);
|
|
2166
1872
|
}
|
|
1873
|
+
return result;
|
|
1874
|
+
}
|
|
1875
|
+
async deleteAll() {
|
|
1876
|
+
this.store.clear();
|
|
2167
1877
|
}
|
|
2168
|
-
findTransferables(obj);
|
|
2169
|
-
return transferables;
|
|
2170
1878
|
}
|
|
2171
|
-
|
|
2172
|
-
class
|
|
2173
|
-
|
|
2174
|
-
|
|
2175
|
-
|
|
2176
|
-
|
|
2177
|
-
|
|
2178
|
-
};
|
|
2179
|
-
await this.handleMessage(msg);
|
|
2180
|
-
});
|
|
1879
|
+
// src/credentials/EnvCredentialStore.ts
|
|
1880
|
+
class EnvCredentialStore {
|
|
1881
|
+
keyToEnvVar;
|
|
1882
|
+
prefix;
|
|
1883
|
+
constructor(mapping = {}, prefix) {
|
|
1884
|
+
this.keyToEnvVar = new Map(Object.entries(mapping));
|
|
1885
|
+
this.prefix = prefix;
|
|
2181
1886
|
}
|
|
2182
|
-
|
|
2183
|
-
|
|
2184
|
-
|
|
2185
|
-
|
|
2186
|
-
|
|
2187
|
-
|
|
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;
|
|
1887
|
+
resolveEnvVar(key) {
|
|
1888
|
+
const explicit = this.keyToEnvVar.get(key);
|
|
1889
|
+
if (explicit)
|
|
1890
|
+
return explicit;
|
|
1891
|
+
if (this.prefix) {
|
|
1892
|
+
return `${this.prefix}_${key.toUpperCase().replace(/-/g, "_")}`;
|
|
2206
1893
|
}
|
|
2207
|
-
|
|
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;
|
|
1894
|
+
return key.toUpperCase().replace(/-/g, "_");
|
|
2219
1895
|
}
|
|
2220
|
-
|
|
2221
|
-
|
|
1896
|
+
getEnv(envVar) {
|
|
1897
|
+
if (typeof process !== "undefined" && process.env) {
|
|
1898
|
+
return process.env[envVar];
|
|
1899
|
+
}
|
|
1900
|
+
return;
|
|
2222
1901
|
}
|
|
2223
|
-
|
|
2224
|
-
|
|
1902
|
+
async get(key) {
|
|
1903
|
+
const envVar = this.resolveEnvVar(key);
|
|
1904
|
+
return this.getEnv(envVar);
|
|
2225
1905
|
}
|
|
2226
|
-
async
|
|
2227
|
-
const
|
|
2228
|
-
if (
|
|
2229
|
-
|
|
1906
|
+
async put(key, value, _options) {
|
|
1907
|
+
const envVar = this.resolveEnvVar(key);
|
|
1908
|
+
if (typeof process !== "undefined" && process.env) {
|
|
1909
|
+
process.env[envVar] = value;
|
|
2230
1910
|
}
|
|
2231
|
-
if (
|
|
2232
|
-
|
|
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
|
-
// src/credentials/ICredentialStore.ts
|
|
2333
|
-
var CREDENTIAL_STORE = createServiceToken("credential.store");
|
|
2334
|
-
// src/credentials/InMemoryCredentialStore.ts
|
|
2335
|
-
class InMemoryCredentialStore {
|
|
2336
|
-
store = new Map;
|
|
2337
|
-
async get(key) {
|
|
2338
|
-
const entry = this.store.get(key);
|
|
2339
|
-
if (!entry)
|
|
2340
|
-
return;
|
|
2341
|
-
if (entry.metadata.expiresAt && entry.metadata.expiresAt <= new Date) {
|
|
2342
|
-
this.store.delete(key);
|
|
2343
|
-
return;
|
|
2344
|
-
}
|
|
2345
|
-
return entry.value;
|
|
2346
|
-
}
|
|
2347
|
-
async put(key, value, options) {
|
|
2348
|
-
const now = new Date;
|
|
2349
|
-
const existing = this.store.get(key);
|
|
2350
|
-
const metadata = {
|
|
2351
|
-
label: options?.label ?? existing?.metadata.label,
|
|
2352
|
-
provider: options?.provider ?? existing?.metadata.provider,
|
|
2353
|
-
createdAt: existing?.metadata.createdAt ?? now,
|
|
2354
|
-
updatedAt: now,
|
|
2355
|
-
expiresAt: options?.expiresAt ?? existing?.metadata.expiresAt
|
|
2356
|
-
};
|
|
2357
|
-
this.store.set(key, { key, value, metadata });
|
|
2358
|
-
}
|
|
2359
|
-
async delete(key) {
|
|
2360
|
-
return this.store.delete(key);
|
|
2361
|
-
}
|
|
2362
|
-
async has(key) {
|
|
2363
|
-
const entry = this.store.get(key);
|
|
2364
|
-
if (!entry)
|
|
2365
|
-
return false;
|
|
2366
|
-
if (entry.metadata.expiresAt && entry.metadata.expiresAt <= new Date) {
|
|
2367
|
-
this.store.delete(key);
|
|
2368
|
-
return false;
|
|
2369
|
-
}
|
|
2370
|
-
return true;
|
|
2371
|
-
}
|
|
2372
|
-
async keys() {
|
|
2373
|
-
const now = new Date;
|
|
2374
|
-
const result = [];
|
|
2375
|
-
for (const [key, entry] of this.store) {
|
|
2376
|
-
if (entry.metadata.expiresAt && entry.metadata.expiresAt <= now) {
|
|
2377
|
-
this.store.delete(key);
|
|
2378
|
-
continue;
|
|
2379
|
-
}
|
|
2380
|
-
result.push(key);
|
|
2381
|
-
}
|
|
2382
|
-
return result;
|
|
2383
|
-
}
|
|
2384
|
-
async deleteAll() {
|
|
2385
|
-
this.store.clear();
|
|
2386
|
-
}
|
|
2387
|
-
}
|
|
2388
|
-
// src/credentials/EnvCredentialStore.ts
|
|
2389
|
-
class EnvCredentialStore {
|
|
2390
|
-
keyToEnvVar;
|
|
2391
|
-
prefix;
|
|
2392
|
-
constructor(mapping = {}, prefix) {
|
|
2393
|
-
this.keyToEnvVar = new Map(Object.entries(mapping));
|
|
2394
|
-
this.prefix = prefix;
|
|
2395
|
-
}
|
|
2396
|
-
resolveEnvVar(key) {
|
|
2397
|
-
const explicit = this.keyToEnvVar.get(key);
|
|
2398
|
-
if (explicit)
|
|
2399
|
-
return explicit;
|
|
2400
|
-
if (this.prefix) {
|
|
2401
|
-
return `${this.prefix}_${key.toUpperCase().replace(/-/g, "_")}`;
|
|
2402
|
-
}
|
|
2403
|
-
return key.toUpperCase().replace(/-/g, "_");
|
|
2404
|
-
}
|
|
2405
|
-
getEnv(envVar) {
|
|
2406
|
-
if (typeof process !== "undefined" && process.env) {
|
|
2407
|
-
return process.env[envVar];
|
|
2408
|
-
}
|
|
2409
|
-
return;
|
|
2410
|
-
}
|
|
2411
|
-
async get(key) {
|
|
2412
|
-
const envVar = this.resolveEnvVar(key);
|
|
2413
|
-
return this.getEnv(envVar);
|
|
2414
|
-
}
|
|
2415
|
-
async put(key, value, _options) {
|
|
2416
|
-
const envVar = this.resolveEnvVar(key);
|
|
2417
|
-
if (typeof process !== "undefined" && process.env) {
|
|
2418
|
-
process.env[envVar] = value;
|
|
2419
|
-
}
|
|
2420
|
-
if (!this.keyToEnvVar.has(key)) {
|
|
2421
|
-
this.keyToEnvVar.set(key, envVar);
|
|
1911
|
+
if (!this.keyToEnvVar.has(key)) {
|
|
1912
|
+
this.keyToEnvVar.set(key, envVar);
|
|
2422
1913
|
}
|
|
2423
1914
|
}
|
|
2424
1915
|
async delete(key) {
|
|
@@ -2548,538 +2039,26 @@ async function decrypt(encrypted, iv, passphrase, keyCache) {
|
|
|
2548
2039
|
const saltB64 = bufToBase64(salt);
|
|
2549
2040
|
let key = keyCache.get(saltB64);
|
|
2550
2041
|
if (!key) {
|
|
2551
|
-
key = await deriveKey(passphrase, salt);
|
|
2552
|
-
keyCache.set(saltB64, key);
|
|
2553
|
-
}
|
|
2554
|
-
const plainBuf = await crypto.subtle.decrypt({ name: "AES-GCM", iv: base64ToBuf(iv) }, key, ciphertextBytes);
|
|
2555
|
-
return new TextDecoder().decode(plainBuf);
|
|
2556
|
-
}
|
|
2557
|
-
function bufToBase64(buf) {
|
|
2558
|
-
let binary = "";
|
|
2559
|
-
for (let i = 0;i < buf.length; i++) {
|
|
2560
|
-
binary += String.fromCharCode(buf[i]);
|
|
2561
|
-
}
|
|
2562
|
-
return btoa(binary);
|
|
2563
|
-
}
|
|
2564
|
-
function base64ToBuf(b64) {
|
|
2565
|
-
const binary = atob(b64);
|
|
2566
|
-
const buf = new Uint8Array(binary.length);
|
|
2567
|
-
for (let i = 0;i < binary.length; i++) {
|
|
2568
|
-
buf[i] = binary.charCodeAt(i);
|
|
2569
|
-
}
|
|
2570
|
-
return buf;
|
|
2571
|
-
}
|
|
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
|
-
}
|
|
2042
|
+
key = await deriveKey(passphrase, salt);
|
|
2043
|
+
keyCache.set(saltB64, key);
|
|
2910
2044
|
}
|
|
2045
|
+
const plainBuf = await crypto.subtle.decrypt({ name: "AES-GCM", iv: base64ToBuf(iv) }, key, ciphertextBytes);
|
|
2046
|
+
return new TextDecoder().decode(plainBuf);
|
|
2911
2047
|
}
|
|
2912
|
-
function
|
|
2913
|
-
|
|
2914
|
-
|
|
2915
|
-
|
|
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;
|
|
2048
|
+
function bufToBase64(buf) {
|
|
2049
|
+
let binary = "";
|
|
2050
|
+
for (let i = 0;i < buf.length; i++) {
|
|
2051
|
+
binary += String.fromCharCode(buf[i]);
|
|
3045
2052
|
}
|
|
2053
|
+
return btoa(binary);
|
|
3046
2054
|
}
|
|
3047
|
-
|
|
3048
|
-
|
|
3049
|
-
|
|
3050
|
-
|
|
3051
|
-
|
|
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;
|
|
2055
|
+
function base64ToBuf(b64) {
|
|
2056
|
+
const binary = atob(b64);
|
|
2057
|
+
const buf = new Uint8Array(binary.length);
|
|
2058
|
+
for (let i = 0;i < binary.length; i++) {
|
|
2059
|
+
buf[i] = binary.charCodeAt(i);
|
|
3082
2060
|
}
|
|
2061
|
+
return buf;
|
|
3083
2062
|
}
|
|
3084
2063
|
// src/telemetry/ITelemetryProvider.ts
|
|
3085
2064
|
var SpanStatusCode = {
|
|
@@ -3246,84 +2225,6 @@ async function decompress(input, algorithm = "gzip") {
|
|
|
3246
2225
|
const decompressedStream = sourceBlob.stream().pipeThrough(new DecompressionStream(algorithm));
|
|
3247
2226
|
return await new Response(decompressedStream).text();
|
|
3248
2227
|
}
|
|
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;
|
|
3297
|
-
}
|
|
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 });
|
|
3315
|
-
}
|
|
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 });
|
|
3319
|
-
}
|
|
3320
|
-
throw err;
|
|
3321
|
-
}
|
|
3322
|
-
return { client, transport };
|
|
3323
|
-
}
|
|
3324
|
-
var mcpClientFactory = {
|
|
3325
|
-
create: createMcpClient
|
|
3326
|
-
};
|
|
3327
2228
|
// src/media/image.ts
|
|
3328
2229
|
function parseDataUri(dataUri) {
|
|
3329
2230
|
const match = dataUri.match(/^data:([^;]+);base64,(.+)$/);
|
|
@@ -3392,9 +2293,209 @@ async function convertImageDataToUseableForm(imageData, supports) {
|
|
|
3392
2293
|
}
|
|
3393
2294
|
throw new Error(`Unsupported image data type: ${typeof imageData} `);
|
|
3394
2295
|
}
|
|
2296
|
+
// src/worker/WorkerServerBase.ts
|
|
2297
|
+
var WORKER_SERVER = createServiceToken("worker.server");
|
|
2298
|
+
function extractTransferables(obj) {
|
|
2299
|
+
const transferables = [];
|
|
2300
|
+
const seen = new WeakSet;
|
|
2301
|
+
function findTransferables(value) {
|
|
2302
|
+
if (value && typeof value === "object" && seen.has(value)) {
|
|
2303
|
+
return;
|
|
2304
|
+
}
|
|
2305
|
+
if (value && typeof value === "object") {
|
|
2306
|
+
seen.add(value);
|
|
2307
|
+
}
|
|
2308
|
+
if (value instanceof Float32Array || value instanceof Int16Array) {
|
|
2309
|
+
transferables.push(value.buffer);
|
|
2310
|
+
} 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) {
|
|
2311
|
+
transferables.push(value.buffer);
|
|
2312
|
+
} else if (typeof OffscreenCanvas !== "undefined" && value instanceof OffscreenCanvas) {
|
|
2313
|
+
transferables.push(value);
|
|
2314
|
+
} else if (typeof ImageBitmap !== "undefined" && value instanceof ImageBitmap) {
|
|
2315
|
+
transferables.push(value);
|
|
2316
|
+
} else if (typeof VideoFrame !== "undefined" && value instanceof VideoFrame) {
|
|
2317
|
+
transferables.push(value);
|
|
2318
|
+
} else if (typeof MessagePort !== "undefined" && value instanceof MessagePort) {
|
|
2319
|
+
transferables.push(value);
|
|
2320
|
+
} else if (value instanceof ArrayBuffer) {
|
|
2321
|
+
transferables.push(value);
|
|
2322
|
+
} else if (Array.isArray(value)) {
|
|
2323
|
+
value.forEach(findTransferables);
|
|
2324
|
+
} else if (value && typeof value === "object") {
|
|
2325
|
+
Object.values(value).forEach(findTransferables);
|
|
2326
|
+
}
|
|
2327
|
+
}
|
|
2328
|
+
findTransferables(obj);
|
|
2329
|
+
return transferables;
|
|
2330
|
+
}
|
|
2331
|
+
|
|
2332
|
+
class WorkerServerBase {
|
|
2333
|
+
constructor() {}
|
|
2334
|
+
functions = {};
|
|
2335
|
+
streamFunctions = {};
|
|
2336
|
+
reactiveFunctions = {};
|
|
2337
|
+
requestControllers = new Map;
|
|
2338
|
+
completedRequests = new Set;
|
|
2339
|
+
postResult = (id, result) => {
|
|
2340
|
+
if (this.completedRequests.has(id)) {
|
|
2341
|
+
return;
|
|
2342
|
+
}
|
|
2343
|
+
this.completedRequests.add(id);
|
|
2344
|
+
const transferables = extractTransferables(result);
|
|
2345
|
+
const uniqueTransferables = [...new Set(transferables)];
|
|
2346
|
+
postMessage({ id, type: "complete", data: result }, uniqueTransferables);
|
|
2347
|
+
};
|
|
2348
|
+
postError = (id, errorMessage) => {
|
|
2349
|
+
if (this.completedRequests.has(id)) {
|
|
2350
|
+
return;
|
|
2351
|
+
}
|
|
2352
|
+
this.completedRequests.add(id);
|
|
2353
|
+
postMessage({ id, type: "error", data: errorMessage });
|
|
2354
|
+
};
|
|
2355
|
+
postStreamChunk = (id, event) => {
|
|
2356
|
+
if (this.completedRequests.has(id)) {
|
|
2357
|
+
return;
|
|
2358
|
+
}
|
|
2359
|
+
postMessage({ id, type: "stream_chunk", data: event });
|
|
2360
|
+
};
|
|
2361
|
+
sendReady() {
|
|
2362
|
+
postMessage({
|
|
2363
|
+
type: "ready",
|
|
2364
|
+
functions: Object.keys(this.functions),
|
|
2365
|
+
streamFunctions: Object.keys(this.streamFunctions),
|
|
2366
|
+
reactiveFunctions: Object.keys(this.reactiveFunctions)
|
|
2367
|
+
});
|
|
2368
|
+
}
|
|
2369
|
+
registerFunction(name, fn) {
|
|
2370
|
+
this.functions[name] = fn;
|
|
2371
|
+
}
|
|
2372
|
+
registerReactiveFunction(name, fn) {
|
|
2373
|
+
this.reactiveFunctions[name] = fn;
|
|
2374
|
+
}
|
|
2375
|
+
registerStreamFunction(name, fn) {
|
|
2376
|
+
this.streamFunctions[name] = fn;
|
|
2377
|
+
}
|
|
2378
|
+
async handleMessage(event) {
|
|
2379
|
+
const { id, type, functionName, args, stream, reactive } = event.data;
|
|
2380
|
+
if (type === "abort") {
|
|
2381
|
+
return await this.handleAbort(id);
|
|
2382
|
+
}
|
|
2383
|
+
if (type === "call") {
|
|
2384
|
+
if (stream) {
|
|
2385
|
+
return await this.handleStreamCall(id, functionName, args);
|
|
2386
|
+
}
|
|
2387
|
+
if (reactive) {
|
|
2388
|
+
return await this.handleReactiveCall(id, functionName, args);
|
|
2389
|
+
}
|
|
2390
|
+
return await this.handleCall(id, functionName, args);
|
|
2391
|
+
}
|
|
2392
|
+
}
|
|
2393
|
+
async handleAbort(id) {
|
|
2394
|
+
if (this.requestControllers.has(id)) {
|
|
2395
|
+
const controller = this.requestControllers.get(id);
|
|
2396
|
+
controller?.abort();
|
|
2397
|
+
this.requestControllers.delete(id);
|
|
2398
|
+
this.postError(id, "Operation aborted");
|
|
2399
|
+
}
|
|
2400
|
+
}
|
|
2401
|
+
async handleReactiveCall(id, functionName, [input, output, model]) {
|
|
2402
|
+
if (!(functionName in this.reactiveFunctions)) {
|
|
2403
|
+
this.postResult(id, undefined);
|
|
2404
|
+
return;
|
|
2405
|
+
}
|
|
2406
|
+
try {
|
|
2407
|
+
const fn = this.reactiveFunctions[functionName];
|
|
2408
|
+
const result = await fn(input, output, model);
|
|
2409
|
+
this.postResult(id, result);
|
|
2410
|
+
} catch (error) {
|
|
2411
|
+
this.postError(id, error.message);
|
|
2412
|
+
}
|
|
2413
|
+
}
|
|
2414
|
+
async handleCall(id, functionName, [input, model]) {
|
|
2415
|
+
if (!(functionName in this.functions)) {
|
|
2416
|
+
this.postError(id, `Function ${functionName} not found`);
|
|
2417
|
+
return;
|
|
2418
|
+
}
|
|
2419
|
+
try {
|
|
2420
|
+
const abortController = new AbortController;
|
|
2421
|
+
this.requestControllers.set(id, abortController);
|
|
2422
|
+
const fn = this.functions[functionName];
|
|
2423
|
+
const postProgress = (progress, message, details) => {
|
|
2424
|
+
if (!this.completedRequests.has(id)) {
|
|
2425
|
+
postMessage({ id, type: "progress", data: { progress, message, details } });
|
|
2426
|
+
}
|
|
2427
|
+
};
|
|
2428
|
+
const result = await fn(input, model, postProgress, abortController.signal);
|
|
2429
|
+
this.postResult(id, result);
|
|
2430
|
+
} catch (error) {
|
|
2431
|
+
this.postError(id, error.message);
|
|
2432
|
+
} finally {
|
|
2433
|
+
this.requestControllers.delete(id);
|
|
2434
|
+
setTimeout(() => {
|
|
2435
|
+
this.completedRequests.delete(id);
|
|
2436
|
+
}, 1000);
|
|
2437
|
+
}
|
|
2438
|
+
}
|
|
2439
|
+
async handleStreamCall(id, functionName, [input, model]) {
|
|
2440
|
+
if (functionName in this.streamFunctions) {
|
|
2441
|
+
try {
|
|
2442
|
+
const abortController = new AbortController;
|
|
2443
|
+
this.requestControllers.set(id, abortController);
|
|
2444
|
+
const fn = this.streamFunctions[functionName];
|
|
2445
|
+
const iterable = fn(input, model, abortController.signal);
|
|
2446
|
+
for await (const event of iterable) {
|
|
2447
|
+
if (this.completedRequests.has(id))
|
|
2448
|
+
break;
|
|
2449
|
+
this.postStreamChunk(id, event);
|
|
2450
|
+
}
|
|
2451
|
+
this.postResult(id, undefined);
|
|
2452
|
+
} catch (error) {
|
|
2453
|
+
this.postError(id, error.message);
|
|
2454
|
+
} finally {
|
|
2455
|
+
this.requestControllers.delete(id);
|
|
2456
|
+
setTimeout(() => {
|
|
2457
|
+
this.completedRequests.delete(id);
|
|
2458
|
+
}, 1000);
|
|
2459
|
+
}
|
|
2460
|
+
} else if (functionName in this.functions) {
|
|
2461
|
+
try {
|
|
2462
|
+
const abortController = new AbortController;
|
|
2463
|
+
this.requestControllers.set(id, abortController);
|
|
2464
|
+
const fn = this.functions[functionName];
|
|
2465
|
+
const noopProgress = () => {};
|
|
2466
|
+
const result = await fn(input, model, noopProgress, abortController.signal);
|
|
2467
|
+
this.postStreamChunk(id, { type: "finish", data: result });
|
|
2468
|
+
this.postResult(id, undefined);
|
|
2469
|
+
} catch (error) {
|
|
2470
|
+
this.postError(id, error.message);
|
|
2471
|
+
} finally {
|
|
2472
|
+
this.requestControllers.delete(id);
|
|
2473
|
+
setTimeout(() => {
|
|
2474
|
+
this.completedRequests.delete(id);
|
|
2475
|
+
}, 1000);
|
|
2476
|
+
}
|
|
2477
|
+
} else {
|
|
2478
|
+
this.postError(id, `Function ${functionName} not found`);
|
|
2479
|
+
}
|
|
2480
|
+
}
|
|
2481
|
+
}
|
|
2482
|
+
|
|
3395
2483
|
// src/worker/Worker.browser.ts
|
|
3396
2484
|
var Worker = globalThis.Worker;
|
|
3397
|
-
var
|
|
2485
|
+
var parentPort = self;
|
|
2486
|
+
class WorkerServer extends WorkerServerBase {
|
|
2487
|
+
constructor() {
|
|
2488
|
+
parentPort?.addEventListener("message", async (event) => {
|
|
2489
|
+
const msg = {
|
|
2490
|
+
type: event.type,
|
|
2491
|
+
data: event.data
|
|
2492
|
+
};
|
|
2493
|
+
await this.handleMessage(msg);
|
|
2494
|
+
});
|
|
2495
|
+
super();
|
|
2496
|
+
}
|
|
2497
|
+
}
|
|
2498
|
+
globalServiceRegistry.register(WORKER_SERVER, () => new WorkerServer, true);
|
|
3398
2499
|
export {
|
|
3399
2500
|
uuid4,
|
|
3400
2501
|
toSQLiteTimestamp,
|
|
@@ -3406,19 +2507,13 @@ export {
|
|
|
3406
2507
|
setGlobalCredentialStore,
|
|
3407
2508
|
serialize,
|
|
3408
2509
|
resolveCredential,
|
|
3409
|
-
resolveAuthSecrets,
|
|
3410
2510
|
registerInputResolver,
|
|
3411
2511
|
parsePartialJson,
|
|
3412
2512
|
parseDataUri,
|
|
3413
|
-
|
|
2513
|
+
parentPort,
|
|
3414
2514
|
objectOfArraysAsArrayOfObjects,
|
|
3415
2515
|
normalizeNumberArray,
|
|
3416
2516
|
normalize,
|
|
3417
|
-
mcpTransportTypes,
|
|
3418
|
-
mcpServerConfigSchema,
|
|
3419
|
-
mcpClientFactory,
|
|
3420
|
-
mcpAuthTypes,
|
|
3421
|
-
mcpAuthConfigSchema,
|
|
3422
2517
|
makeFingerprint,
|
|
3423
2518
|
magnitude,
|
|
3424
2519
|
jaccardSimilarity,
|
|
@@ -3440,24 +2535,17 @@ export {
|
|
|
3440
2535
|
decompress,
|
|
3441
2536
|
createTypedArrayFrom,
|
|
3442
2537
|
createServiceToken,
|
|
3443
|
-
createMcpClient,
|
|
3444
|
-
createAuthProvider,
|
|
3445
2538
|
cosineSimilarity,
|
|
3446
2539
|
convertImageDataToUseableForm,
|
|
3447
2540
|
compress,
|
|
3448
|
-
compileSchema,
|
|
3449
2541
|
collectPropertyValues,
|
|
3450
|
-
buildAuthConfig,
|
|
3451
2542
|
bufToBase64,
|
|
3452
2543
|
base64ToBuf,
|
|
3453
|
-
areSemanticallyCompatible,
|
|
3454
|
-
areObjectSchemasSemanticallyCompatible,
|
|
3455
2544
|
WorkerServer,
|
|
3456
2545
|
WorkerManager,
|
|
3457
2546
|
Worker,
|
|
3458
2547
|
WORKER_SERVER,
|
|
3459
2548
|
WORKER_MANAGER,
|
|
3460
|
-
UnauthorizedError,
|
|
3461
2549
|
TypedArraySchema,
|
|
3462
2550
|
TensorType,
|
|
3463
2551
|
TensorSchema,
|
|
@@ -3479,7 +2567,6 @@ export {
|
|
|
3479
2567
|
DirectedGraph,
|
|
3480
2568
|
DirectedAcyclicGraph,
|
|
3481
2569
|
CycleError,
|
|
3482
|
-
CredentialStoreOAuthProvider,
|
|
3483
2570
|
Container,
|
|
3484
2571
|
ConsoleTelemetryProvider,
|
|
3485
2572
|
ConsoleLogger,
|
|
@@ -3488,4 +2575,4 @@ export {
|
|
|
3488
2575
|
BaseError
|
|
3489
2576
|
};
|
|
3490
2577
|
|
|
3491
|
-
//# debugId=
|
|
2578
|
+
//# debugId=547A5F14C3BF7B1564756E2164756E21
|