@workglow/util 0.0.120 → 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/node.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) {
|
|
@@ -2554,532 +2045,20 @@ async function decrypt(encrypted, iv, passphrase, keyCache) {
|
|
|
2554
2045
|
const plainBuf = await crypto.subtle.decrypt({ name: "AES-GCM", iv: base64ToBuf(iv) }, key, ciphertextBytes);
|
|
2555
2046
|
return new TextDecoder().decode(plainBuf);
|
|
2556
2047
|
}
|
|
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
|
-
}
|
|
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;
|
|
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 = {
|
|
@@ -3253,97 +2232,6 @@ async function decompress(input, algorithm = "gzip") {
|
|
|
3253
2232
|
const resultBuffer = await decompressAsyncTyped(sourceBuffer);
|
|
3254
2233
|
return resultBuffer.toString();
|
|
3255
2234
|
}
|
|
3256
|
-
// src/mcp/McpClientUtil.node.ts
|
|
3257
|
-
import { Client } from "@modelcontextprotocol/sdk/client";
|
|
3258
|
-
import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js";
|
|
3259
|
-
import { SSEClientTransport } from "@modelcontextprotocol/sdk/client/sse.js";
|
|
3260
|
-
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
|
|
3261
|
-
var mcpTransportTypes = ["stdio", "sse", "streamable-http"];
|
|
3262
|
-
var mcpServerConfigSchema = {
|
|
3263
|
-
properties: {
|
|
3264
|
-
transport: {
|
|
3265
|
-
type: "string",
|
|
3266
|
-
enum: mcpTransportTypes,
|
|
3267
|
-
title: "Transport",
|
|
3268
|
-
description: "The transport type to use for connecting to the MCP server"
|
|
3269
|
-
},
|
|
3270
|
-
server_url: {
|
|
3271
|
-
type: "string",
|
|
3272
|
-
format: "string:uri",
|
|
3273
|
-
title: "Server URL",
|
|
3274
|
-
description: "The URL of the MCP server (for sse and streamable-http transports)"
|
|
3275
|
-
},
|
|
3276
|
-
command: {
|
|
3277
|
-
type: "string",
|
|
3278
|
-
title: "Command",
|
|
3279
|
-
description: "The command to run (for stdio transport)"
|
|
3280
|
-
},
|
|
3281
|
-
args: {
|
|
3282
|
-
type: "array",
|
|
3283
|
-
items: { type: "string" },
|
|
3284
|
-
title: "Arguments",
|
|
3285
|
-
description: "Command arguments (for stdio transport)"
|
|
3286
|
-
},
|
|
3287
|
-
env: {
|
|
3288
|
-
type: "object",
|
|
3289
|
-
additionalProperties: { type: "string" },
|
|
3290
|
-
title: "Environment",
|
|
3291
|
-
description: "Environment variables (for stdio transport)"
|
|
3292
|
-
},
|
|
3293
|
-
...mcpAuthConfigSchema.properties
|
|
3294
|
-
},
|
|
3295
|
-
allOf: mcpAuthConfigSchema.allOf
|
|
3296
|
-
};
|
|
3297
|
-
async function createMcpClient(config, signal) {
|
|
3298
|
-
let transport;
|
|
3299
|
-
let auth = config.auth ?? buildAuthConfig({ ...config });
|
|
3300
|
-
if (auth && auth.type !== "none") {
|
|
3301
|
-
auth = await resolveAuthSecrets(auth, getGlobalCredentialStore());
|
|
3302
|
-
}
|
|
3303
|
-
const authProvider = config.authProvider ?? (auth && auth.type !== "none" && auth.type !== "bearer" ? createAuthProvider(auth, config.server_url ?? "", getGlobalCredentialStore()) : undefined);
|
|
3304
|
-
const headers = {
|
|
3305
|
-
...auth?.type === "bearer" ? { Authorization: `Bearer ${auth.token}` } : {}
|
|
3306
|
-
};
|
|
3307
|
-
switch (config.transport) {
|
|
3308
|
-
case "stdio":
|
|
3309
|
-
if (auth && auth.type !== "none") {
|
|
3310
|
-
getLogger().warn("MCP auth is not supported for stdio transport; auth config ignored. " + "Use env vars to pass credentials to stdio servers.");
|
|
3311
|
-
}
|
|
3312
|
-
transport = new StdioClientTransport({
|
|
3313
|
-
command: config.command,
|
|
3314
|
-
args: config.args,
|
|
3315
|
-
env: config.env
|
|
3316
|
-
});
|
|
3317
|
-
break;
|
|
3318
|
-
case "sse": {
|
|
3319
|
-
transport = new SSEClientTransport(new URL(config.server_url), {
|
|
3320
|
-
authProvider,
|
|
3321
|
-
requestInit: { headers }
|
|
3322
|
-
});
|
|
3323
|
-
break;
|
|
3324
|
-
}
|
|
3325
|
-
case "streamable-http": {
|
|
3326
|
-
transport = new StreamableHTTPClientTransport(new URL(config.server_url), {
|
|
3327
|
-
authProvider,
|
|
3328
|
-
requestInit: { headers }
|
|
3329
|
-
});
|
|
3330
|
-
break;
|
|
3331
|
-
}
|
|
3332
|
-
default:
|
|
3333
|
-
throw new Error(`Unsupported transport type: ${config.transport}`);
|
|
3334
|
-
}
|
|
3335
|
-
const client = new Client({ name: "workglow-mcp-client", version: "1.0.0" });
|
|
3336
|
-
if (signal) {
|
|
3337
|
-
signal.addEventListener("abort", () => {
|
|
3338
|
-
client.close().catch(() => {});
|
|
3339
|
-
}, { once: true });
|
|
3340
|
-
}
|
|
3341
|
-
await client.connect(transport);
|
|
3342
|
-
return { client, transport };
|
|
3343
|
-
}
|
|
3344
|
-
var mcpClientFactory = {
|
|
3345
|
-
create: createMcpClient
|
|
3346
|
-
};
|
|
3347
2235
|
// src/media/image.ts
|
|
3348
2236
|
function parseDataUri(dataUri) {
|
|
3349
2237
|
const match = dataUri.match(/^data:([^;]+);base64,(.+)$/);
|
|
@@ -3390,10 +2278,198 @@ async function convertImageDataToUseableForm(imageData, supports) {
|
|
|
3390
2278
|
throw new Error(`Unsupported image data type: ${typeof imageData}`);
|
|
3391
2279
|
}
|
|
3392
2280
|
// src/worker/Worker.node.ts
|
|
3393
|
-
import { Worker as NodeWorker, isMainThread, parentPort
|
|
2281
|
+
import { Worker as NodeWorker, isMainThread, parentPort } from "worker_threads";
|
|
3394
2282
|
import { pathToFileURL } from "url";
|
|
3395
2283
|
import { URL as NodeURL } from "url";
|
|
3396
2284
|
|
|
2285
|
+
// src/worker/WorkerServerBase.ts
|
|
2286
|
+
var WORKER_SERVER = createServiceToken("worker.server");
|
|
2287
|
+
function extractTransferables(obj) {
|
|
2288
|
+
const transferables = [];
|
|
2289
|
+
const seen = new WeakSet;
|
|
2290
|
+
function findTransferables(value) {
|
|
2291
|
+
if (value && typeof value === "object" && seen.has(value)) {
|
|
2292
|
+
return;
|
|
2293
|
+
}
|
|
2294
|
+
if (value && typeof value === "object") {
|
|
2295
|
+
seen.add(value);
|
|
2296
|
+
}
|
|
2297
|
+
if (value instanceof Float32Array || value instanceof Int16Array) {
|
|
2298
|
+
transferables.push(value.buffer);
|
|
2299
|
+
} 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) {
|
|
2300
|
+
transferables.push(value.buffer);
|
|
2301
|
+
} else if (typeof OffscreenCanvas !== "undefined" && value instanceof OffscreenCanvas) {
|
|
2302
|
+
transferables.push(value);
|
|
2303
|
+
} else if (typeof ImageBitmap !== "undefined" && value instanceof ImageBitmap) {
|
|
2304
|
+
transferables.push(value);
|
|
2305
|
+
} else if (typeof VideoFrame !== "undefined" && value instanceof VideoFrame) {
|
|
2306
|
+
transferables.push(value);
|
|
2307
|
+
} else if (typeof MessagePort !== "undefined" && value instanceof MessagePort) {
|
|
2308
|
+
transferables.push(value);
|
|
2309
|
+
} else if (value instanceof ArrayBuffer) {
|
|
2310
|
+
transferables.push(value);
|
|
2311
|
+
} else if (Array.isArray(value)) {
|
|
2312
|
+
value.forEach(findTransferables);
|
|
2313
|
+
} else if (value && typeof value === "object") {
|
|
2314
|
+
Object.values(value).forEach(findTransferables);
|
|
2315
|
+
}
|
|
2316
|
+
}
|
|
2317
|
+
findTransferables(obj);
|
|
2318
|
+
return transferables;
|
|
2319
|
+
}
|
|
2320
|
+
|
|
2321
|
+
class WorkerServerBase {
|
|
2322
|
+
constructor() {}
|
|
2323
|
+
functions = {};
|
|
2324
|
+
streamFunctions = {};
|
|
2325
|
+
reactiveFunctions = {};
|
|
2326
|
+
requestControllers = new Map;
|
|
2327
|
+
completedRequests = new Set;
|
|
2328
|
+
postResult = (id, result) => {
|
|
2329
|
+
if (this.completedRequests.has(id)) {
|
|
2330
|
+
return;
|
|
2331
|
+
}
|
|
2332
|
+
this.completedRequests.add(id);
|
|
2333
|
+
const transferables = extractTransferables(result);
|
|
2334
|
+
const uniqueTransferables = [...new Set(transferables)];
|
|
2335
|
+
postMessage({ id, type: "complete", data: result }, uniqueTransferables);
|
|
2336
|
+
};
|
|
2337
|
+
postError = (id, errorMessage) => {
|
|
2338
|
+
if (this.completedRequests.has(id)) {
|
|
2339
|
+
return;
|
|
2340
|
+
}
|
|
2341
|
+
this.completedRequests.add(id);
|
|
2342
|
+
postMessage({ id, type: "error", data: errorMessage });
|
|
2343
|
+
};
|
|
2344
|
+
postStreamChunk = (id, event) => {
|
|
2345
|
+
if (this.completedRequests.has(id)) {
|
|
2346
|
+
return;
|
|
2347
|
+
}
|
|
2348
|
+
postMessage({ id, type: "stream_chunk", data: event });
|
|
2349
|
+
};
|
|
2350
|
+
sendReady() {
|
|
2351
|
+
postMessage({
|
|
2352
|
+
type: "ready",
|
|
2353
|
+
functions: Object.keys(this.functions),
|
|
2354
|
+
streamFunctions: Object.keys(this.streamFunctions),
|
|
2355
|
+
reactiveFunctions: Object.keys(this.reactiveFunctions)
|
|
2356
|
+
});
|
|
2357
|
+
}
|
|
2358
|
+
registerFunction(name, fn) {
|
|
2359
|
+
this.functions[name] = fn;
|
|
2360
|
+
}
|
|
2361
|
+
registerReactiveFunction(name, fn) {
|
|
2362
|
+
this.reactiveFunctions[name] = fn;
|
|
2363
|
+
}
|
|
2364
|
+
registerStreamFunction(name, fn) {
|
|
2365
|
+
this.streamFunctions[name] = fn;
|
|
2366
|
+
}
|
|
2367
|
+
async handleMessage(event) {
|
|
2368
|
+
const { id, type, functionName, args, stream, reactive } = event.data;
|
|
2369
|
+
if (type === "abort") {
|
|
2370
|
+
return await this.handleAbort(id);
|
|
2371
|
+
}
|
|
2372
|
+
if (type === "call") {
|
|
2373
|
+
if (stream) {
|
|
2374
|
+
return await this.handleStreamCall(id, functionName, args);
|
|
2375
|
+
}
|
|
2376
|
+
if (reactive) {
|
|
2377
|
+
return await this.handleReactiveCall(id, functionName, args);
|
|
2378
|
+
}
|
|
2379
|
+
return await this.handleCall(id, functionName, args);
|
|
2380
|
+
}
|
|
2381
|
+
}
|
|
2382
|
+
async handleAbort(id) {
|
|
2383
|
+
if (this.requestControllers.has(id)) {
|
|
2384
|
+
const controller = this.requestControllers.get(id);
|
|
2385
|
+
controller?.abort();
|
|
2386
|
+
this.requestControllers.delete(id);
|
|
2387
|
+
this.postError(id, "Operation aborted");
|
|
2388
|
+
}
|
|
2389
|
+
}
|
|
2390
|
+
async handleReactiveCall(id, functionName, [input, output, model]) {
|
|
2391
|
+
if (!(functionName in this.reactiveFunctions)) {
|
|
2392
|
+
this.postResult(id, undefined);
|
|
2393
|
+
return;
|
|
2394
|
+
}
|
|
2395
|
+
try {
|
|
2396
|
+
const fn = this.reactiveFunctions[functionName];
|
|
2397
|
+
const result = await fn(input, output, model);
|
|
2398
|
+
this.postResult(id, result);
|
|
2399
|
+
} catch (error) {
|
|
2400
|
+
this.postError(id, error.message);
|
|
2401
|
+
}
|
|
2402
|
+
}
|
|
2403
|
+
async handleCall(id, functionName, [input, model]) {
|
|
2404
|
+
if (!(functionName in this.functions)) {
|
|
2405
|
+
this.postError(id, `Function ${functionName} not found`);
|
|
2406
|
+
return;
|
|
2407
|
+
}
|
|
2408
|
+
try {
|
|
2409
|
+
const abortController = new AbortController;
|
|
2410
|
+
this.requestControllers.set(id, abortController);
|
|
2411
|
+
const fn = this.functions[functionName];
|
|
2412
|
+
const postProgress = (progress, message, details) => {
|
|
2413
|
+
if (!this.completedRequests.has(id)) {
|
|
2414
|
+
postMessage({ id, type: "progress", data: { progress, message, details } });
|
|
2415
|
+
}
|
|
2416
|
+
};
|
|
2417
|
+
const result = await fn(input, model, postProgress, abortController.signal);
|
|
2418
|
+
this.postResult(id, result);
|
|
2419
|
+
} catch (error) {
|
|
2420
|
+
this.postError(id, error.message);
|
|
2421
|
+
} finally {
|
|
2422
|
+
this.requestControllers.delete(id);
|
|
2423
|
+
setTimeout(() => {
|
|
2424
|
+
this.completedRequests.delete(id);
|
|
2425
|
+
}, 1000);
|
|
2426
|
+
}
|
|
2427
|
+
}
|
|
2428
|
+
async handleStreamCall(id, functionName, [input, model]) {
|
|
2429
|
+
if (functionName in this.streamFunctions) {
|
|
2430
|
+
try {
|
|
2431
|
+
const abortController = new AbortController;
|
|
2432
|
+
this.requestControllers.set(id, abortController);
|
|
2433
|
+
const fn = this.streamFunctions[functionName];
|
|
2434
|
+
const iterable = fn(input, model, abortController.signal);
|
|
2435
|
+
for await (const event of iterable) {
|
|
2436
|
+
if (this.completedRequests.has(id))
|
|
2437
|
+
break;
|
|
2438
|
+
this.postStreamChunk(id, event);
|
|
2439
|
+
}
|
|
2440
|
+
this.postResult(id, undefined);
|
|
2441
|
+
} catch (error) {
|
|
2442
|
+
this.postError(id, error.message);
|
|
2443
|
+
} finally {
|
|
2444
|
+
this.requestControllers.delete(id);
|
|
2445
|
+
setTimeout(() => {
|
|
2446
|
+
this.completedRequests.delete(id);
|
|
2447
|
+
}, 1000);
|
|
2448
|
+
}
|
|
2449
|
+
} else if (functionName in this.functions) {
|
|
2450
|
+
try {
|
|
2451
|
+
const abortController = new AbortController;
|
|
2452
|
+
this.requestControllers.set(id, abortController);
|
|
2453
|
+
const fn = this.functions[functionName];
|
|
2454
|
+
const noopProgress = () => {};
|
|
2455
|
+
const result = await fn(input, model, noopProgress, abortController.signal);
|
|
2456
|
+
this.postStreamChunk(id, { type: "finish", data: result });
|
|
2457
|
+
this.postResult(id, undefined);
|
|
2458
|
+
} catch (error) {
|
|
2459
|
+
this.postError(id, error.message);
|
|
2460
|
+
} finally {
|
|
2461
|
+
this.requestControllers.delete(id);
|
|
2462
|
+
setTimeout(() => {
|
|
2463
|
+
this.completedRequests.delete(id);
|
|
2464
|
+
}, 1000);
|
|
2465
|
+
}
|
|
2466
|
+
} else {
|
|
2467
|
+
this.postError(id, `Function ${functionName} not found`);
|
|
2468
|
+
}
|
|
2469
|
+
}
|
|
2470
|
+
}
|
|
2471
|
+
|
|
2472
|
+
// src/worker/Worker.node.ts
|
|
3397
2473
|
class WorkerPolyfill extends NodeWorker {
|
|
3398
2474
|
constructor(scriptUrl, options) {
|
|
3399
2475
|
const resolved = scriptUrl instanceof NodeURL ? scriptUrl.toString() : pathToFileURL(scriptUrl).toString();
|
|
@@ -3412,7 +2488,20 @@ class WorkerPolyfill extends NodeWorker {
|
|
|
3412
2488
|
this.off("error", listener);
|
|
3413
2489
|
}
|
|
3414
2490
|
}
|
|
3415
|
-
var Worker = isMainThread ? WorkerPolyfill :
|
|
2491
|
+
var Worker = isMainThread ? WorkerPolyfill : parentPort;
|
|
2492
|
+
class WorkerServer extends WorkerServerBase {
|
|
2493
|
+
constructor() {
|
|
2494
|
+
parentPort?.addEventListener("message", async (event) => {
|
|
2495
|
+
const msg = {
|
|
2496
|
+
type: event.type,
|
|
2497
|
+
data: event.data
|
|
2498
|
+
};
|
|
2499
|
+
await this.handleMessage(msg);
|
|
2500
|
+
});
|
|
2501
|
+
super();
|
|
2502
|
+
}
|
|
2503
|
+
}
|
|
2504
|
+
globalServiceRegistry.register(WORKER_SERVER, () => new WorkerServer, true);
|
|
3416
2505
|
export {
|
|
3417
2506
|
uuid4,
|
|
3418
2507
|
toSQLiteTimestamp,
|
|
@@ -3424,19 +2513,13 @@ export {
|
|
|
3424
2513
|
setGlobalCredentialStore,
|
|
3425
2514
|
serialize,
|
|
3426
2515
|
resolveCredential,
|
|
3427
|
-
resolveAuthSecrets,
|
|
3428
2516
|
registerInputResolver,
|
|
3429
2517
|
parsePartialJson,
|
|
3430
2518
|
parseDataUri,
|
|
3431
|
-
|
|
2519
|
+
parentPort,
|
|
3432
2520
|
objectOfArraysAsArrayOfObjects,
|
|
3433
2521
|
normalizeNumberArray,
|
|
3434
2522
|
normalize,
|
|
3435
|
-
mcpTransportTypes,
|
|
3436
|
-
mcpServerConfigSchema,
|
|
3437
|
-
mcpClientFactory,
|
|
3438
|
-
mcpAuthTypes,
|
|
3439
|
-
mcpAuthConfigSchema,
|
|
3440
2523
|
makeFingerprint,
|
|
3441
2524
|
magnitude,
|
|
3442
2525
|
jaccardSimilarity,
|
|
@@ -3458,24 +2541,17 @@ export {
|
|
|
3458
2541
|
decompress,
|
|
3459
2542
|
createTypedArrayFrom,
|
|
3460
2543
|
createServiceToken,
|
|
3461
|
-
createMcpClient,
|
|
3462
|
-
createAuthProvider,
|
|
3463
2544
|
cosineSimilarity,
|
|
3464
2545
|
convertImageDataToUseableForm,
|
|
3465
2546
|
compress,
|
|
3466
|
-
compileSchema,
|
|
3467
2547
|
collectPropertyValues,
|
|
3468
|
-
buildAuthConfig,
|
|
3469
2548
|
bufToBase64,
|
|
3470
2549
|
base64ToBuf,
|
|
3471
|
-
areSemanticallyCompatible,
|
|
3472
|
-
areObjectSchemasSemanticallyCompatible,
|
|
3473
2550
|
WorkerServer,
|
|
3474
2551
|
WorkerManager,
|
|
3475
2552
|
Worker,
|
|
3476
2553
|
WORKER_SERVER,
|
|
3477
2554
|
WORKER_MANAGER,
|
|
3478
|
-
UnauthorizedError,
|
|
3479
2555
|
TypedArraySchema,
|
|
3480
2556
|
TensorType,
|
|
3481
2557
|
TensorSchema,
|
|
@@ -3497,7 +2573,6 @@ export {
|
|
|
3497
2573
|
DirectedGraph,
|
|
3498
2574
|
DirectedAcyclicGraph,
|
|
3499
2575
|
CycleError,
|
|
3500
|
-
CredentialStoreOAuthProvider,
|
|
3501
2576
|
Container,
|
|
3502
2577
|
ConsoleTelemetryProvider,
|
|
3503
2578
|
ConsoleLogger,
|
|
@@ -3506,4 +2581,4 @@ export {
|
|
|
3506
2581
|
BaseError
|
|
3507
2582
|
};
|
|
3508
2583
|
|
|
3509
|
-
//# debugId=
|
|
2584
|
+
//# debugId=7BB129A722446D6A64756E2164756E21
|