@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/bun.js
CHANGED
|
@@ -886,357 +886,6 @@ var FromSchemaDefaultOptions = {
|
|
|
886
886
|
references: false,
|
|
887
887
|
deserialize: false
|
|
888
888
|
};
|
|
889
|
-
// src/json-schema/SchemaUtils.ts
|
|
890
|
-
function areFormatStringsCompatible(sourceFormat, targetFormat) {
|
|
891
|
-
const formatPattern = /^[a-zA-Z][a-zA-Z0-9_-]*(?::[a-zA-Z][a-zA-Z0-9_-]*)?$/;
|
|
892
|
-
if (!formatPattern.test(sourceFormat) || !formatPattern.test(targetFormat)) {
|
|
893
|
-
return "incompatible";
|
|
894
|
-
}
|
|
895
|
-
const [sourceName, sourceNarrow] = sourceFormat.split(":");
|
|
896
|
-
const [targetName, targetNarrow] = targetFormat.split(":");
|
|
897
|
-
if (sourceName !== targetName) {
|
|
898
|
-
return "incompatible";
|
|
899
|
-
}
|
|
900
|
-
if (!sourceNarrow && !targetNarrow) {
|
|
901
|
-
return "static";
|
|
902
|
-
}
|
|
903
|
-
if (sourceNarrow && !targetNarrow) {
|
|
904
|
-
return "static";
|
|
905
|
-
}
|
|
906
|
-
if (!sourceNarrow && targetNarrow) {
|
|
907
|
-
return "runtime";
|
|
908
|
-
}
|
|
909
|
-
if (sourceNarrow === targetNarrow) {
|
|
910
|
-
return "static";
|
|
911
|
-
}
|
|
912
|
-
return "incompatible";
|
|
913
|
-
}
|
|
914
|
-
function isTypeStaticallyCompatible(sourceType, targetType) {
|
|
915
|
-
if (!targetType) {
|
|
916
|
-
return true;
|
|
917
|
-
}
|
|
918
|
-
if (!sourceType) {
|
|
919
|
-
return false;
|
|
920
|
-
}
|
|
921
|
-
const sourceTypes = Array.isArray(sourceType) ? sourceType : [sourceType];
|
|
922
|
-
const targetTypes = Array.isArray(targetType) ? targetType : [targetType];
|
|
923
|
-
return sourceTypes.some((st) => targetTypes.includes(st));
|
|
924
|
-
}
|
|
925
|
-
function mergeAllOfSchemas(schemas) {
|
|
926
|
-
if (schemas.length === 0)
|
|
927
|
-
return null;
|
|
928
|
-
if (schemas.length === 1)
|
|
929
|
-
return schemas[0];
|
|
930
|
-
let merged = {};
|
|
931
|
-
for (const schema of schemas) {
|
|
932
|
-
if (typeof schema === "boolean") {
|
|
933
|
-
if (schema === false)
|
|
934
|
-
return false;
|
|
935
|
-
continue;
|
|
936
|
-
}
|
|
937
|
-
const schemaObj = schema;
|
|
938
|
-
if (schemaObj.type !== undefined) {
|
|
939
|
-
if (merged.type === undefined) {
|
|
940
|
-
merged.type = schemaObj.type;
|
|
941
|
-
} else if (merged.type !== schemaObj.type) {
|
|
942
|
-
const mergedTypes = Array.isArray(merged.type) ? merged.type : [merged.type];
|
|
943
|
-
const schemaTypes = Array.isArray(schemaObj.type) ? schemaObj.type : [schemaObj.type];
|
|
944
|
-
const commonTypes = mergedTypes.filter((t) => schemaTypes.includes(t));
|
|
945
|
-
if (commonTypes.length === 0) {
|
|
946
|
-
return false;
|
|
947
|
-
}
|
|
948
|
-
merged.type = commonTypes.length === 1 ? commonTypes[0] : commonTypes;
|
|
949
|
-
}
|
|
950
|
-
}
|
|
951
|
-
const schemaFormat = schemaObj.format;
|
|
952
|
-
const mergedFormat = merged.format;
|
|
953
|
-
if (schemaFormat) {
|
|
954
|
-
if (!mergedFormat) {
|
|
955
|
-
merged.format = schemaFormat;
|
|
956
|
-
} else {
|
|
957
|
-
const formatCompat = areFormatStringsCompatible(mergedFormat, schemaFormat);
|
|
958
|
-
if (formatCompat === "incompatible") {
|
|
959
|
-
return false;
|
|
960
|
-
}
|
|
961
|
-
const mergedHasNarrow = mergedFormat.includes(":");
|
|
962
|
-
const schemaHasNarrow = schemaFormat.includes(":");
|
|
963
|
-
if (schemaHasNarrow && !mergedHasNarrow) {
|
|
964
|
-
merged.format = schemaFormat;
|
|
965
|
-
} else if (!schemaHasNarrow && mergedHasNarrow) {} else if (mergedFormat !== schemaFormat) {
|
|
966
|
-
return false;
|
|
967
|
-
}
|
|
968
|
-
}
|
|
969
|
-
}
|
|
970
|
-
if (schemaObj.properties && typeof schemaObj.properties === "object") {
|
|
971
|
-
if (!merged.properties) {
|
|
972
|
-
merged.properties = {};
|
|
973
|
-
}
|
|
974
|
-
const mergedProps = merged.properties;
|
|
975
|
-
const schemaProps = schemaObj.properties;
|
|
976
|
-
for (const [key, value] of Object.entries(schemaProps)) {
|
|
977
|
-
if (mergedProps[key]) {
|
|
978
|
-
const nestedMerged = mergeAllOfSchemas([mergedProps[key], value]);
|
|
979
|
-
if (nestedMerged === null || nestedMerged === false) {
|
|
980
|
-
return false;
|
|
981
|
-
}
|
|
982
|
-
mergedProps[key] = nestedMerged;
|
|
983
|
-
} else {
|
|
984
|
-
mergedProps[key] = value;
|
|
985
|
-
}
|
|
986
|
-
}
|
|
987
|
-
}
|
|
988
|
-
if (schemaObj.required && Array.isArray(schemaObj.required)) {
|
|
989
|
-
if (!merged.required) {
|
|
990
|
-
merged.required = [];
|
|
991
|
-
}
|
|
992
|
-
const mergedRequired = merged.required;
|
|
993
|
-
const schemaRequired = schemaObj.required;
|
|
994
|
-
merged.required = mergedRequired.filter((r) => schemaRequired.includes(r));
|
|
995
|
-
}
|
|
996
|
-
if (schemaObj.additionalProperties !== undefined) {
|
|
997
|
-
if (merged.additionalProperties === undefined) {
|
|
998
|
-
merged.additionalProperties = schemaObj.additionalProperties;
|
|
999
|
-
} else if (merged.additionalProperties === true && schemaObj.additionalProperties === false) {
|
|
1000
|
-
merged.additionalProperties = false;
|
|
1001
|
-
}
|
|
1002
|
-
}
|
|
1003
|
-
if (schemaObj.items !== undefined) {
|
|
1004
|
-
if (merged.items === undefined) {
|
|
1005
|
-
merged.items = schemaObj.items;
|
|
1006
|
-
} else {
|
|
1007
|
-
const mergedItems = mergeAllOfSchemas([
|
|
1008
|
-
merged.items,
|
|
1009
|
-
schemaObj.items
|
|
1010
|
-
]);
|
|
1011
|
-
if (mergedItems === null || mergedItems === false) {
|
|
1012
|
-
return false;
|
|
1013
|
-
}
|
|
1014
|
-
merged.items = mergedItems;
|
|
1015
|
-
}
|
|
1016
|
-
}
|
|
1017
|
-
}
|
|
1018
|
-
return merged;
|
|
1019
|
-
}
|
|
1020
|
-
function isCompatibleWithUnion(sourceSchema, unionSchemas) {
|
|
1021
|
-
let hasStatic = false;
|
|
1022
|
-
let hasRuntime = false;
|
|
1023
|
-
for (const unionSchema of unionSchemas) {
|
|
1024
|
-
const compatibility = areSemanticallyCompatible(sourceSchema, unionSchema);
|
|
1025
|
-
if (compatibility === "static") {
|
|
1026
|
-
hasStatic = true;
|
|
1027
|
-
} else if (compatibility === "runtime") {
|
|
1028
|
-
hasRuntime = true;
|
|
1029
|
-
}
|
|
1030
|
-
}
|
|
1031
|
-
if (hasStatic)
|
|
1032
|
-
return "static";
|
|
1033
|
-
if (hasRuntime)
|
|
1034
|
-
return "runtime";
|
|
1035
|
-
return "incompatible";
|
|
1036
|
-
}
|
|
1037
|
-
function areSemanticallyCompatible(sourceSchema, targetSchema) {
|
|
1038
|
-
if (sourceSchema === undefined || targetSchema === undefined) {
|
|
1039
|
-
return "incompatible";
|
|
1040
|
-
}
|
|
1041
|
-
if (typeof targetSchema === "boolean") {
|
|
1042
|
-
if (targetSchema === false)
|
|
1043
|
-
return "incompatible";
|
|
1044
|
-
if (targetSchema === true)
|
|
1045
|
-
return "static";
|
|
1046
|
-
return "incompatible";
|
|
1047
|
-
}
|
|
1048
|
-
if (typeof sourceSchema === "boolean") {
|
|
1049
|
-
if (sourceSchema === false)
|
|
1050
|
-
return "incompatible";
|
|
1051
|
-
if (sourceSchema === true)
|
|
1052
|
-
return "runtime";
|
|
1053
|
-
}
|
|
1054
|
-
if (sourceSchema.allOf && Array.isArray(sourceSchema.allOf)) {
|
|
1055
|
-
const mergedSchema = mergeAllOfSchemas(sourceSchema.allOf);
|
|
1056
|
-
if (mergedSchema === null || mergedSchema === false) {
|
|
1057
|
-
return "incompatible";
|
|
1058
|
-
}
|
|
1059
|
-
return areSemanticallyCompatible(mergedSchema, targetSchema);
|
|
1060
|
-
}
|
|
1061
|
-
const sourceType = sourceSchema.type;
|
|
1062
|
-
const targetType = targetSchema.type;
|
|
1063
|
-
if (sourceSchema.oneOf && Array.isArray(sourceSchema.oneOf)) {
|
|
1064
|
-
let hasStatic = false;
|
|
1065
|
-
let hasRuntime = false;
|
|
1066
|
-
for (const sourceOption of sourceSchema.oneOf) {
|
|
1067
|
-
const compatibility = areSemanticallyCompatible(sourceOption, targetSchema);
|
|
1068
|
-
if (compatibility === "static") {
|
|
1069
|
-
hasStatic = true;
|
|
1070
|
-
} else if (compatibility === "runtime") {
|
|
1071
|
-
hasRuntime = true;
|
|
1072
|
-
}
|
|
1073
|
-
}
|
|
1074
|
-
if (hasRuntime)
|
|
1075
|
-
return "runtime";
|
|
1076
|
-
if (hasStatic)
|
|
1077
|
-
return "static";
|
|
1078
|
-
return "incompatible";
|
|
1079
|
-
}
|
|
1080
|
-
if (sourceSchema.anyOf && Array.isArray(sourceSchema.anyOf)) {
|
|
1081
|
-
let hasStatic = false;
|
|
1082
|
-
let hasRuntime = false;
|
|
1083
|
-
for (const sourceOption of sourceSchema.anyOf) {
|
|
1084
|
-
const compatibility = areSemanticallyCompatible(sourceOption, targetSchema);
|
|
1085
|
-
if (compatibility === "static") {
|
|
1086
|
-
hasStatic = true;
|
|
1087
|
-
} else if (compatibility === "runtime") {
|
|
1088
|
-
hasRuntime = true;
|
|
1089
|
-
}
|
|
1090
|
-
}
|
|
1091
|
-
if (hasRuntime)
|
|
1092
|
-
return "runtime";
|
|
1093
|
-
if (hasStatic)
|
|
1094
|
-
return "static";
|
|
1095
|
-
return "incompatible";
|
|
1096
|
-
}
|
|
1097
|
-
if (targetSchema.oneOf && Array.isArray(targetSchema.oneOf)) {
|
|
1098
|
-
return isCompatibleWithUnion(sourceSchema, targetSchema.oneOf);
|
|
1099
|
-
}
|
|
1100
|
-
if (targetSchema.anyOf && Array.isArray(targetSchema.anyOf)) {
|
|
1101
|
-
return isCompatibleWithUnion(sourceSchema, targetSchema.anyOf);
|
|
1102
|
-
}
|
|
1103
|
-
if (targetSchema.allOf && Array.isArray(targetSchema.allOf)) {
|
|
1104
|
-
let hasStatic = false;
|
|
1105
|
-
let hasRuntime = false;
|
|
1106
|
-
for (const allOfSchema of targetSchema.allOf) {
|
|
1107
|
-
const compatibility = areSemanticallyCompatible(sourceSchema, allOfSchema);
|
|
1108
|
-
if (compatibility === "incompatible") {
|
|
1109
|
-
return "incompatible";
|
|
1110
|
-
} else if (compatibility === "static") {
|
|
1111
|
-
hasStatic = true;
|
|
1112
|
-
} else if (compatibility === "runtime") {
|
|
1113
|
-
hasRuntime = true;
|
|
1114
|
-
}
|
|
1115
|
-
}
|
|
1116
|
-
if (hasRuntime)
|
|
1117
|
-
return "runtime";
|
|
1118
|
-
if (hasStatic)
|
|
1119
|
-
return "static";
|
|
1120
|
-
return "incompatible";
|
|
1121
|
-
}
|
|
1122
|
-
if (sourceType === "object" && targetType === "object") {
|
|
1123
|
-
const sourceProperties = sourceSchema.properties;
|
|
1124
|
-
const targetProperties = targetSchema.properties;
|
|
1125
|
-
if (!targetProperties) {
|
|
1126
|
-
return "static";
|
|
1127
|
-
}
|
|
1128
|
-
if (!sourceProperties) {
|
|
1129
|
-
if (targetSchema.additionalProperties === false) {
|
|
1130
|
-
return "incompatible";
|
|
1131
|
-
}
|
|
1132
|
-
return "static";
|
|
1133
|
-
}
|
|
1134
|
-
const targetRequired = targetSchema.required || [];
|
|
1135
|
-
let hasStatic = true;
|
|
1136
|
-
let hasRuntime = false;
|
|
1137
|
-
for (const propName of targetRequired) {
|
|
1138
|
-
const targetProp = targetProperties?.[propName];
|
|
1139
|
-
const sourceProp = sourceProperties?.[propName];
|
|
1140
|
-
if (!sourceProp) {
|
|
1141
|
-
return "incompatible";
|
|
1142
|
-
}
|
|
1143
|
-
if (targetProp) {
|
|
1144
|
-
const propCompatibility = areSemanticallyCompatible(sourceProp, targetProp);
|
|
1145
|
-
if (propCompatibility === "incompatible") {
|
|
1146
|
-
return "incompatible";
|
|
1147
|
-
} else if (propCompatibility === "runtime") {
|
|
1148
|
-
hasRuntime = true;
|
|
1149
|
-
hasStatic = false;
|
|
1150
|
-
}
|
|
1151
|
-
}
|
|
1152
|
-
}
|
|
1153
|
-
if (targetSchema.additionalProperties === false) {
|
|
1154
|
-
const sourcePropNames = Object.keys(sourceProperties);
|
|
1155
|
-
const targetPropNames = Object.keys(targetProperties);
|
|
1156
|
-
const extraProps = sourcePropNames.filter((name) => !targetPropNames.includes(name));
|
|
1157
|
-
if (extraProps.length > 0) {
|
|
1158
|
-
return "incompatible";
|
|
1159
|
-
}
|
|
1160
|
-
}
|
|
1161
|
-
if (hasRuntime)
|
|
1162
|
-
return "runtime";
|
|
1163
|
-
return "static";
|
|
1164
|
-
}
|
|
1165
|
-
if (sourceType === "array" && targetType === "array") {
|
|
1166
|
-
const sourceFormat2 = sourceSchema?.format;
|
|
1167
|
-
const targetFormat2 = targetSchema?.format;
|
|
1168
|
-
let formatCompatibility = null;
|
|
1169
|
-
if (sourceFormat2 && targetFormat2) {
|
|
1170
|
-
formatCompatibility = areFormatStringsCompatible(sourceFormat2, targetFormat2);
|
|
1171
|
-
if (formatCompatibility === "incompatible") {
|
|
1172
|
-
return "incompatible";
|
|
1173
|
-
}
|
|
1174
|
-
}
|
|
1175
|
-
if (sourceFormat2 && !targetFormat2) {
|
|
1176
|
-
return "static";
|
|
1177
|
-
}
|
|
1178
|
-
if (!sourceFormat2 && targetFormat2) {
|
|
1179
|
-
return "incompatible";
|
|
1180
|
-
}
|
|
1181
|
-
const sourceItems = sourceSchema.items;
|
|
1182
|
-
const targetItems = targetSchema.items;
|
|
1183
|
-
if (sourceItems && typeof sourceItems === "object" && !Array.isArray(sourceItems) && targetItems && typeof targetItems === "object" && !Array.isArray(targetItems)) {
|
|
1184
|
-
const itemsCompatibility = areSemanticallyCompatible(sourceItems, targetItems);
|
|
1185
|
-
if (formatCompatibility === "runtime") {
|
|
1186
|
-
return "runtime";
|
|
1187
|
-
}
|
|
1188
|
-
return itemsCompatibility;
|
|
1189
|
-
}
|
|
1190
|
-
if (!targetItems) {
|
|
1191
|
-
return "static";
|
|
1192
|
-
}
|
|
1193
|
-
if (!sourceItems) {
|
|
1194
|
-
return "incompatible";
|
|
1195
|
-
}
|
|
1196
|
-
if (Array.isArray(targetItems)) {
|
|
1197
|
-
return isCompatibleWithUnion(sourceItems, targetItems);
|
|
1198
|
-
}
|
|
1199
|
-
return "static";
|
|
1200
|
-
}
|
|
1201
|
-
if (!sourceType) {
|
|
1202
|
-
const targetFormat2 = targetSchema?.format;
|
|
1203
|
-
if (targetFormat2) {
|
|
1204
|
-
return "runtime";
|
|
1205
|
-
}
|
|
1206
|
-
return "static";
|
|
1207
|
-
}
|
|
1208
|
-
if (!targetType) {
|
|
1209
|
-
const targetFormat2 = targetSchema?.format;
|
|
1210
|
-
if (targetFormat2) {
|
|
1211
|
-
const sourceFormat2 = sourceSchema?.format;
|
|
1212
|
-
if (!sourceFormat2) {
|
|
1213
|
-
return "incompatible";
|
|
1214
|
-
}
|
|
1215
|
-
return areFormatStringsCompatible(sourceFormat2, targetFormat2);
|
|
1216
|
-
}
|
|
1217
|
-
return "static";
|
|
1218
|
-
}
|
|
1219
|
-
if (!isTypeStaticallyCompatible(sourceType, targetType)) {
|
|
1220
|
-
return "incompatible";
|
|
1221
|
-
}
|
|
1222
|
-
const sourceFormat = sourceSchema?.format;
|
|
1223
|
-
const targetFormat = targetSchema?.format;
|
|
1224
|
-
if (sourceFormat && targetFormat) {
|
|
1225
|
-
return areFormatStringsCompatible(sourceFormat, targetFormat);
|
|
1226
|
-
}
|
|
1227
|
-
if (sourceFormat && !targetFormat) {
|
|
1228
|
-
return "static";
|
|
1229
|
-
}
|
|
1230
|
-
if (!sourceFormat && targetFormat) {
|
|
1231
|
-
return "incompatible";
|
|
1232
|
-
}
|
|
1233
|
-
return "static";
|
|
1234
|
-
}
|
|
1235
|
-
function areObjectSchemasSemanticallyCompatible(sourceSchema, targetSchema) {
|
|
1236
|
-
return areSemanticallyCompatible(sourceSchema, targetSchema);
|
|
1237
|
-
}
|
|
1238
|
-
// src/json-schema/SchemaValidation.ts
|
|
1239
|
-
import { compileSchema } from "@sroussey/json-schema-library";
|
|
1240
889
|
// src/json-schema/parsePartialJson.ts
|
|
1241
890
|
function parsePartialJson(text) {
|
|
1242
891
|
const trimmed = text.trim();
|
|
@@ -1943,10 +1592,22 @@ class WorkerManager {
|
|
|
1943
1592
|
workerFunctions = new Map;
|
|
1944
1593
|
workerStreamFunctions = new Map;
|
|
1945
1594
|
workerReactiveFunctions = new Map;
|
|
1946
|
-
|
|
1947
|
-
|
|
1595
|
+
lazyFactories = new Map;
|
|
1596
|
+
lazyInitPromises = new Map;
|
|
1597
|
+
registerWorker(name, workerOrFactory) {
|
|
1598
|
+
if (this.workers.has(name)) {
|
|
1948
1599
|
throw new Error(`Worker ${name} is already registered.`);
|
|
1949
|
-
|
|
1600
|
+
}
|
|
1601
|
+
if (this.lazyFactories.has(name)) {
|
|
1602
|
+
throw new Error(`Worker ${name} is already registered.`);
|
|
1603
|
+
}
|
|
1604
|
+
if (typeof workerOrFactory === "function") {
|
|
1605
|
+
this.lazyFactories.set(name, workerOrFactory);
|
|
1606
|
+
} else {
|
|
1607
|
+
this.attachWorkerInstance(name, workerOrFactory);
|
|
1608
|
+
}
|
|
1609
|
+
}
|
|
1610
|
+
attachWorkerInstance(name, worker) {
|
|
1950
1611
|
this.workers.set(name, worker);
|
|
1951
1612
|
worker.addEventListener("error", (event) => {
|
|
1952
1613
|
console.error("Worker Error:", event.message, "at", event.filename, "line:", event.lineno);
|
|
@@ -1968,6 +1629,29 @@ class WorkerManager {
|
|
|
1968
1629
|
});
|
|
1969
1630
|
this.readyWorkers.set(name, readyPromise);
|
|
1970
1631
|
}
|
|
1632
|
+
async ensureWorkerReady(name) {
|
|
1633
|
+
if (this.workers.has(name)) {
|
|
1634
|
+
await this.readyWorkers.get(name);
|
|
1635
|
+
return;
|
|
1636
|
+
}
|
|
1637
|
+
const factory = this.lazyFactories.get(name);
|
|
1638
|
+
if (!factory) {
|
|
1639
|
+
throw new Error(`Worker ${name} not found.`);
|
|
1640
|
+
}
|
|
1641
|
+
let init = this.lazyInitPromises.get(name);
|
|
1642
|
+
if (!init) {
|
|
1643
|
+
init = (async () => {
|
|
1644
|
+
const f = this.lazyFactories.get(name);
|
|
1645
|
+
this.lazyFactories.delete(name);
|
|
1646
|
+
const worker = f();
|
|
1647
|
+
this.attachWorkerInstance(name, worker);
|
|
1648
|
+
})();
|
|
1649
|
+
this.lazyInitPromises.set(name, init);
|
|
1650
|
+
}
|
|
1651
|
+
await init;
|
|
1652
|
+
await this.readyWorkers.get(name);
|
|
1653
|
+
this.lazyInitPromises.delete(name);
|
|
1654
|
+
}
|
|
1971
1655
|
getWorker(name) {
|
|
1972
1656
|
const worker = this.workers.get(name);
|
|
1973
1657
|
if (!worker)
|
|
@@ -1975,6 +1659,7 @@ class WorkerManager {
|
|
|
1975
1659
|
return worker;
|
|
1976
1660
|
}
|
|
1977
1661
|
async callWorkerFunction(workerName, functionName, args, options) {
|
|
1662
|
+
await this.ensureWorkerReady(workerName);
|
|
1978
1663
|
const worker = this.workers.get(workerName);
|
|
1979
1664
|
if (!worker)
|
|
1980
1665
|
throw new Error(`Worker ${workerName} not found.`);
|
|
@@ -2020,6 +1705,7 @@ class WorkerManager {
|
|
|
2020
1705
|
});
|
|
2021
1706
|
}
|
|
2022
1707
|
async callWorkerReactiveFunction(workerName, functionName, args) {
|
|
1708
|
+
await this.ensureWorkerReady(workerName);
|
|
2023
1709
|
const worker = this.workers.get(workerName);
|
|
2024
1710
|
if (!worker)
|
|
2025
1711
|
return;
|
|
@@ -2051,6 +1737,7 @@ class WorkerManager {
|
|
|
2051
1737
|
});
|
|
2052
1738
|
}
|
|
2053
1739
|
async* callWorkerStreamFunction(workerName, functionName, args, options) {
|
|
1740
|
+
await this.ensureWorkerReady(workerName);
|
|
2054
1741
|
const worker = this.workers.get(workerName);
|
|
2055
1742
|
if (!worker)
|
|
2056
1743
|
throw new Error(`Worker ${workerName} not found.`);
|
|
@@ -2134,292 +1821,96 @@ class WorkerManager {
|
|
|
2134
1821
|
}
|
|
2135
1822
|
var WORKER_MANAGER = createServiceToken("worker.manager");
|
|
2136
1823
|
globalServiceRegistry.register(WORKER_MANAGER, () => new WorkerManager, true);
|
|
2137
|
-
// src/
|
|
2138
|
-
|
|
2139
|
-
|
|
2140
|
-
|
|
2141
|
-
|
|
2142
|
-
|
|
2143
|
-
|
|
1824
|
+
// src/credentials/ICredentialStore.ts
|
|
1825
|
+
var CREDENTIAL_STORE = createServiceToken("credential.store");
|
|
1826
|
+
// src/credentials/InMemoryCredentialStore.ts
|
|
1827
|
+
class InMemoryCredentialStore {
|
|
1828
|
+
store = new Map;
|
|
1829
|
+
async get(key) {
|
|
1830
|
+
const entry = this.store.get(key);
|
|
1831
|
+
if (!entry)
|
|
1832
|
+
return;
|
|
1833
|
+
if (entry.metadata.expiresAt && entry.metadata.expiresAt <= new Date) {
|
|
1834
|
+
this.store.delete(key);
|
|
2144
1835
|
return;
|
|
2145
1836
|
}
|
|
2146
|
-
|
|
2147
|
-
|
|
1837
|
+
return entry.value;
|
|
1838
|
+
}
|
|
1839
|
+
async put(key, value, options) {
|
|
1840
|
+
const now = new Date;
|
|
1841
|
+
const existing = this.store.get(key);
|
|
1842
|
+
const metadata = {
|
|
1843
|
+
label: options?.label ?? existing?.metadata.label,
|
|
1844
|
+
provider: options?.provider ?? existing?.metadata.provider,
|
|
1845
|
+
createdAt: existing?.metadata.createdAt ?? now,
|
|
1846
|
+
updatedAt: now,
|
|
1847
|
+
expiresAt: options?.expiresAt ?? existing?.metadata.expiresAt
|
|
1848
|
+
};
|
|
1849
|
+
this.store.set(key, { key, value, metadata });
|
|
1850
|
+
}
|
|
1851
|
+
async delete(key) {
|
|
1852
|
+
return this.store.delete(key);
|
|
1853
|
+
}
|
|
1854
|
+
async has(key) {
|
|
1855
|
+
const entry = this.store.get(key);
|
|
1856
|
+
if (!entry)
|
|
1857
|
+
return false;
|
|
1858
|
+
if (entry.metadata.expiresAt && entry.metadata.expiresAt <= new Date) {
|
|
1859
|
+
this.store.delete(key);
|
|
1860
|
+
return false;
|
|
2148
1861
|
}
|
|
2149
|
-
|
|
2150
|
-
|
|
2151
|
-
|
|
2152
|
-
|
|
2153
|
-
|
|
2154
|
-
|
|
2155
|
-
|
|
2156
|
-
|
|
2157
|
-
|
|
2158
|
-
|
|
2159
|
-
|
|
2160
|
-
transferables.push(value);
|
|
2161
|
-
} else if (value instanceof ArrayBuffer) {
|
|
2162
|
-
transferables.push(value);
|
|
2163
|
-
} else if (Array.isArray(value)) {
|
|
2164
|
-
value.forEach(findTransferables);
|
|
2165
|
-
} else if (value && typeof value === "object") {
|
|
2166
|
-
Object.values(value).forEach(findTransferables);
|
|
1862
|
+
return true;
|
|
1863
|
+
}
|
|
1864
|
+
async keys() {
|
|
1865
|
+
const now = new Date;
|
|
1866
|
+
const result = [];
|
|
1867
|
+
for (const [key, entry] of this.store) {
|
|
1868
|
+
if (entry.metadata.expiresAt && entry.metadata.expiresAt <= now) {
|
|
1869
|
+
this.store.delete(key);
|
|
1870
|
+
continue;
|
|
1871
|
+
}
|
|
1872
|
+
result.push(key);
|
|
2167
1873
|
}
|
|
1874
|
+
return result;
|
|
1875
|
+
}
|
|
1876
|
+
async deleteAll() {
|
|
1877
|
+
this.store.clear();
|
|
2168
1878
|
}
|
|
2169
|
-
findTransferables(obj);
|
|
2170
|
-
return transferables;
|
|
2171
1879
|
}
|
|
2172
|
-
|
|
2173
|
-
class
|
|
2174
|
-
|
|
2175
|
-
|
|
2176
|
-
|
|
2177
|
-
|
|
2178
|
-
|
|
2179
|
-
};
|
|
2180
|
-
await this.handleMessage(msg);
|
|
2181
|
-
});
|
|
1880
|
+
// src/credentials/EnvCredentialStore.ts
|
|
1881
|
+
class EnvCredentialStore {
|
|
1882
|
+
keyToEnvVar;
|
|
1883
|
+
prefix;
|
|
1884
|
+
constructor(mapping = {}, prefix) {
|
|
1885
|
+
this.keyToEnvVar = new Map(Object.entries(mapping));
|
|
1886
|
+
this.prefix = prefix;
|
|
2182
1887
|
}
|
|
2183
|
-
|
|
2184
|
-
|
|
2185
|
-
|
|
2186
|
-
|
|
2187
|
-
|
|
2188
|
-
|
|
2189
|
-
if (this.completedRequests.has(id)) {
|
|
2190
|
-
return;
|
|
2191
|
-
}
|
|
2192
|
-
this.completedRequests.add(id);
|
|
2193
|
-
const transferables = extractTransferables(result);
|
|
2194
|
-
const uniqueTransferables = [...new Set(transferables)];
|
|
2195
|
-
postMessage({ id, type: "complete", data: result }, uniqueTransferables);
|
|
2196
|
-
};
|
|
2197
|
-
postError = (id, errorMessage) => {
|
|
2198
|
-
if (this.completedRequests.has(id)) {
|
|
2199
|
-
return;
|
|
2200
|
-
}
|
|
2201
|
-
this.completedRequests.add(id);
|
|
2202
|
-
postMessage({ id, type: "error", data: errorMessage });
|
|
2203
|
-
};
|
|
2204
|
-
postStreamChunk = (id, event) => {
|
|
2205
|
-
if (this.completedRequests.has(id)) {
|
|
2206
|
-
return;
|
|
1888
|
+
resolveEnvVar(key) {
|
|
1889
|
+
const explicit = this.keyToEnvVar.get(key);
|
|
1890
|
+
if (explicit)
|
|
1891
|
+
return explicit;
|
|
1892
|
+
if (this.prefix) {
|
|
1893
|
+
return `${this.prefix}_${key.toUpperCase().replace(/-/g, "_")}`;
|
|
2207
1894
|
}
|
|
2208
|
-
|
|
2209
|
-
};
|
|
2210
|
-
sendReady() {
|
|
2211
|
-
postMessage({
|
|
2212
|
-
type: "ready",
|
|
2213
|
-
functions: Object.keys(this.functions),
|
|
2214
|
-
streamFunctions: Object.keys(this.streamFunctions),
|
|
2215
|
-
reactiveFunctions: Object.keys(this.reactiveFunctions)
|
|
2216
|
-
});
|
|
2217
|
-
}
|
|
2218
|
-
registerFunction(name, fn) {
|
|
2219
|
-
this.functions[name] = fn;
|
|
1895
|
+
return key.toUpperCase().replace(/-/g, "_");
|
|
2220
1896
|
}
|
|
2221
|
-
|
|
2222
|
-
|
|
1897
|
+
getEnv(envVar) {
|
|
1898
|
+
if (typeof process !== "undefined" && process.env) {
|
|
1899
|
+
return process.env[envVar];
|
|
1900
|
+
}
|
|
1901
|
+
return;
|
|
2223
1902
|
}
|
|
2224
|
-
|
|
2225
|
-
|
|
1903
|
+
async get(key) {
|
|
1904
|
+
const envVar = this.resolveEnvVar(key);
|
|
1905
|
+
return this.getEnv(envVar);
|
|
2226
1906
|
}
|
|
2227
|
-
async
|
|
2228
|
-
const
|
|
2229
|
-
if (
|
|
2230
|
-
|
|
1907
|
+
async put(key, value, _options) {
|
|
1908
|
+
const envVar = this.resolveEnvVar(key);
|
|
1909
|
+
if (typeof process !== "undefined" && process.env) {
|
|
1910
|
+
process.env[envVar] = value;
|
|
2231
1911
|
}
|
|
2232
|
-
if (
|
|
2233
|
-
|
|
2234
|
-
return await this.handleStreamCall(id, functionName, args);
|
|
2235
|
-
}
|
|
2236
|
-
if (reactive) {
|
|
2237
|
-
return await this.handleReactiveCall(id, functionName, args);
|
|
2238
|
-
}
|
|
2239
|
-
return await this.handleCall(id, functionName, args);
|
|
2240
|
-
}
|
|
2241
|
-
}
|
|
2242
|
-
async handleAbort(id) {
|
|
2243
|
-
if (this.requestControllers.has(id)) {
|
|
2244
|
-
const controller = this.requestControllers.get(id);
|
|
2245
|
-
controller?.abort();
|
|
2246
|
-
this.requestControllers.delete(id);
|
|
2247
|
-
this.postError(id, "Operation aborted");
|
|
2248
|
-
}
|
|
2249
|
-
}
|
|
2250
|
-
async handleReactiveCall(id, functionName, [input, output, model]) {
|
|
2251
|
-
if (!(functionName in this.reactiveFunctions)) {
|
|
2252
|
-
this.postResult(id, undefined);
|
|
2253
|
-
return;
|
|
2254
|
-
}
|
|
2255
|
-
try {
|
|
2256
|
-
const fn = this.reactiveFunctions[functionName];
|
|
2257
|
-
const result = await fn(input, output, model);
|
|
2258
|
-
this.postResult(id, result);
|
|
2259
|
-
} catch (error) {
|
|
2260
|
-
this.postError(id, error.message);
|
|
2261
|
-
}
|
|
2262
|
-
}
|
|
2263
|
-
async handleCall(id, functionName, [input, model]) {
|
|
2264
|
-
if (!(functionName in this.functions)) {
|
|
2265
|
-
this.postError(id, `Function ${functionName} not found`);
|
|
2266
|
-
return;
|
|
2267
|
-
}
|
|
2268
|
-
try {
|
|
2269
|
-
const abortController = new AbortController;
|
|
2270
|
-
this.requestControllers.set(id, abortController);
|
|
2271
|
-
const fn = this.functions[functionName];
|
|
2272
|
-
const postProgress = (progress, message, details) => {
|
|
2273
|
-
if (!this.completedRequests.has(id)) {
|
|
2274
|
-
postMessage({ id, type: "progress", data: { progress, message, details } });
|
|
2275
|
-
}
|
|
2276
|
-
};
|
|
2277
|
-
const result = await fn(input, model, postProgress, abortController.signal);
|
|
2278
|
-
this.postResult(id, result);
|
|
2279
|
-
} catch (error) {
|
|
2280
|
-
this.postError(id, error.message);
|
|
2281
|
-
} finally {
|
|
2282
|
-
this.requestControllers.delete(id);
|
|
2283
|
-
setTimeout(() => {
|
|
2284
|
-
this.completedRequests.delete(id);
|
|
2285
|
-
}, 1000);
|
|
2286
|
-
}
|
|
2287
|
-
}
|
|
2288
|
-
async handleStreamCall(id, functionName, [input, model]) {
|
|
2289
|
-
if (functionName in this.streamFunctions) {
|
|
2290
|
-
try {
|
|
2291
|
-
const abortController = new AbortController;
|
|
2292
|
-
this.requestControllers.set(id, abortController);
|
|
2293
|
-
const fn = this.streamFunctions[functionName];
|
|
2294
|
-
const iterable = fn(input, model, abortController.signal);
|
|
2295
|
-
for await (const event of iterable) {
|
|
2296
|
-
if (this.completedRequests.has(id))
|
|
2297
|
-
break;
|
|
2298
|
-
this.postStreamChunk(id, event);
|
|
2299
|
-
}
|
|
2300
|
-
this.postResult(id, undefined);
|
|
2301
|
-
} catch (error) {
|
|
2302
|
-
this.postError(id, error.message);
|
|
2303
|
-
} finally {
|
|
2304
|
-
this.requestControllers.delete(id);
|
|
2305
|
-
setTimeout(() => {
|
|
2306
|
-
this.completedRequests.delete(id);
|
|
2307
|
-
}, 1000);
|
|
2308
|
-
}
|
|
2309
|
-
} else if (functionName in this.functions) {
|
|
2310
|
-
try {
|
|
2311
|
-
const abortController = new AbortController;
|
|
2312
|
-
this.requestControllers.set(id, abortController);
|
|
2313
|
-
const fn = this.functions[functionName];
|
|
2314
|
-
const noopProgress = () => {};
|
|
2315
|
-
const result = await fn(input, model, noopProgress, abortController.signal);
|
|
2316
|
-
this.postStreamChunk(id, { type: "finish", data: result });
|
|
2317
|
-
this.postResult(id, undefined);
|
|
2318
|
-
} catch (error) {
|
|
2319
|
-
this.postError(id, error.message);
|
|
2320
|
-
} finally {
|
|
2321
|
-
this.requestControllers.delete(id);
|
|
2322
|
-
setTimeout(() => {
|
|
2323
|
-
this.completedRequests.delete(id);
|
|
2324
|
-
}, 1000);
|
|
2325
|
-
}
|
|
2326
|
-
} else {
|
|
2327
|
-
this.postError(id, `Function ${functionName} not found`);
|
|
2328
|
-
}
|
|
2329
|
-
}
|
|
2330
|
-
}
|
|
2331
|
-
var WORKER_SERVER = createServiceToken("worker.server");
|
|
2332
|
-
globalServiceRegistry.register(WORKER_SERVER, () => new WorkerServer, true);
|
|
2333
|
-
// src/credentials/ICredentialStore.ts
|
|
2334
|
-
var CREDENTIAL_STORE = createServiceToken("credential.store");
|
|
2335
|
-
// src/credentials/InMemoryCredentialStore.ts
|
|
2336
|
-
class InMemoryCredentialStore {
|
|
2337
|
-
store = new Map;
|
|
2338
|
-
async get(key) {
|
|
2339
|
-
const entry = this.store.get(key);
|
|
2340
|
-
if (!entry)
|
|
2341
|
-
return;
|
|
2342
|
-
if (entry.metadata.expiresAt && entry.metadata.expiresAt <= new Date) {
|
|
2343
|
-
this.store.delete(key);
|
|
2344
|
-
return;
|
|
2345
|
-
}
|
|
2346
|
-
return entry.value;
|
|
2347
|
-
}
|
|
2348
|
-
async put(key, value, options) {
|
|
2349
|
-
const now = new Date;
|
|
2350
|
-
const existing = this.store.get(key);
|
|
2351
|
-
const metadata = {
|
|
2352
|
-
label: options?.label ?? existing?.metadata.label,
|
|
2353
|
-
provider: options?.provider ?? existing?.metadata.provider,
|
|
2354
|
-
createdAt: existing?.metadata.createdAt ?? now,
|
|
2355
|
-
updatedAt: now,
|
|
2356
|
-
expiresAt: options?.expiresAt ?? existing?.metadata.expiresAt
|
|
2357
|
-
};
|
|
2358
|
-
this.store.set(key, { key, value, metadata });
|
|
2359
|
-
}
|
|
2360
|
-
async delete(key) {
|
|
2361
|
-
return this.store.delete(key);
|
|
2362
|
-
}
|
|
2363
|
-
async has(key) {
|
|
2364
|
-
const entry = this.store.get(key);
|
|
2365
|
-
if (!entry)
|
|
2366
|
-
return false;
|
|
2367
|
-
if (entry.metadata.expiresAt && entry.metadata.expiresAt <= new Date) {
|
|
2368
|
-
this.store.delete(key);
|
|
2369
|
-
return false;
|
|
2370
|
-
}
|
|
2371
|
-
return true;
|
|
2372
|
-
}
|
|
2373
|
-
async keys() {
|
|
2374
|
-
const now = new Date;
|
|
2375
|
-
const result = [];
|
|
2376
|
-
for (const [key, entry] of this.store) {
|
|
2377
|
-
if (entry.metadata.expiresAt && entry.metadata.expiresAt <= now) {
|
|
2378
|
-
this.store.delete(key);
|
|
2379
|
-
continue;
|
|
2380
|
-
}
|
|
2381
|
-
result.push(key);
|
|
2382
|
-
}
|
|
2383
|
-
return result;
|
|
2384
|
-
}
|
|
2385
|
-
async deleteAll() {
|
|
2386
|
-
this.store.clear();
|
|
2387
|
-
}
|
|
2388
|
-
}
|
|
2389
|
-
// src/credentials/EnvCredentialStore.ts
|
|
2390
|
-
class EnvCredentialStore {
|
|
2391
|
-
keyToEnvVar;
|
|
2392
|
-
prefix;
|
|
2393
|
-
constructor(mapping = {}, prefix) {
|
|
2394
|
-
this.keyToEnvVar = new Map(Object.entries(mapping));
|
|
2395
|
-
this.prefix = prefix;
|
|
2396
|
-
}
|
|
2397
|
-
resolveEnvVar(key) {
|
|
2398
|
-
const explicit = this.keyToEnvVar.get(key);
|
|
2399
|
-
if (explicit)
|
|
2400
|
-
return explicit;
|
|
2401
|
-
if (this.prefix) {
|
|
2402
|
-
return `${this.prefix}_${key.toUpperCase().replace(/-/g, "_")}`;
|
|
2403
|
-
}
|
|
2404
|
-
return key.toUpperCase().replace(/-/g, "_");
|
|
2405
|
-
}
|
|
2406
|
-
getEnv(envVar) {
|
|
2407
|
-
if (typeof process !== "undefined" && process.env) {
|
|
2408
|
-
return process.env[envVar];
|
|
2409
|
-
}
|
|
2410
|
-
return;
|
|
2411
|
-
}
|
|
2412
|
-
async get(key) {
|
|
2413
|
-
const envVar = this.resolveEnvVar(key);
|
|
2414
|
-
return this.getEnv(envVar);
|
|
2415
|
-
}
|
|
2416
|
-
async put(key, value, _options) {
|
|
2417
|
-
const envVar = this.resolveEnvVar(key);
|
|
2418
|
-
if (typeof process !== "undefined" && process.env) {
|
|
2419
|
-
process.env[envVar] = value;
|
|
2420
|
-
}
|
|
2421
|
-
if (!this.keyToEnvVar.has(key)) {
|
|
2422
|
-
this.keyToEnvVar.set(key, envVar);
|
|
1912
|
+
if (!this.keyToEnvVar.has(key)) {
|
|
1913
|
+
this.keyToEnvVar.set(key, envVar);
|
|
2423
1914
|
}
|
|
2424
1915
|
}
|
|
2425
1916
|
async delete(key) {
|
|
@@ -2553,534 +2044,22 @@ async function decrypt(encrypted, iv, passphrase, keyCache) {
|
|
|
2553
2044
|
keyCache.set(saltB64, key);
|
|
2554
2045
|
}
|
|
2555
2046
|
const plainBuf = await crypto.subtle.decrypt({ name: "AES-GCM", iv: base64ToBuf(iv) }, key, ciphertextBytes);
|
|
2556
|
-
return new TextDecoder().decode(plainBuf);
|
|
2557
|
-
}
|
|
2558
|
-
function bufToBase64(buf) {
|
|
2559
|
-
let binary = "";
|
|
2560
|
-
for (let i = 0;i < buf.length; i++) {
|
|
2561
|
-
binary += String.fromCharCode(buf[i]);
|
|
2562
|
-
}
|
|
2563
|
-
return btoa(binary);
|
|
2564
|
-
}
|
|
2565
|
-
function base64ToBuf(b64) {
|
|
2566
|
-
const binary = atob(b64);
|
|
2567
|
-
const buf = new Uint8Array(binary.length);
|
|
2568
|
-
for (let i = 0;i < binary.length; i++) {
|
|
2569
|
-
buf[i] = binary.charCodeAt(i);
|
|
2570
|
-
}
|
|
2571
|
-
return buf;
|
|
2572
|
-
}
|
|
2573
|
-
// src/mcp/McpAuthTypes.ts
|
|
2574
|
-
var mcpAuthTypes = [
|
|
2575
|
-
"none",
|
|
2576
|
-
"bearer",
|
|
2577
|
-
"client_credentials",
|
|
2578
|
-
"private_key_jwt",
|
|
2579
|
-
"static_private_key_jwt",
|
|
2580
|
-
"authorization_code"
|
|
2581
|
-
];
|
|
2582
|
-
var mcpAuthConfigSchema = {
|
|
2583
|
-
properties: {
|
|
2584
|
-
auth_type: {
|
|
2585
|
-
type: "string",
|
|
2586
|
-
enum: mcpAuthTypes,
|
|
2587
|
-
title: "Auth Type",
|
|
2588
|
-
description: "Authentication method for connecting to the MCP server",
|
|
2589
|
-
default: "none"
|
|
2590
|
-
},
|
|
2591
|
-
auth_token: {
|
|
2592
|
-
type: "string",
|
|
2593
|
-
format: "credential",
|
|
2594
|
-
title: "Bearer Token",
|
|
2595
|
-
description: "Static bearer token or API key (for bearer auth)"
|
|
2596
|
-
},
|
|
2597
|
-
auth_client_id: {
|
|
2598
|
-
type: "string",
|
|
2599
|
-
title: "Client ID",
|
|
2600
|
-
description: "OAuth client ID (for OAuth auth types)"
|
|
2601
|
-
},
|
|
2602
|
-
auth_client_secret: {
|
|
2603
|
-
type: "string",
|
|
2604
|
-
format: "credential",
|
|
2605
|
-
title: "Client Secret",
|
|
2606
|
-
description: "OAuth client secret (for client_credentials auth)"
|
|
2607
|
-
},
|
|
2608
|
-
auth_private_key: {
|
|
2609
|
-
type: "string",
|
|
2610
|
-
format: "credential",
|
|
2611
|
-
title: "Private Key",
|
|
2612
|
-
description: "PEM or JWK private key (for private_key_jwt auth)"
|
|
2613
|
-
},
|
|
2614
|
-
auth_algorithm: {
|
|
2615
|
-
type: "string",
|
|
2616
|
-
title: "Algorithm",
|
|
2617
|
-
description: "JWT signing algorithm, e.g. RS256, ES256 (for private_key_jwt auth)"
|
|
2618
|
-
},
|
|
2619
|
-
auth_jwt_bearer_assertion: {
|
|
2620
|
-
type: "string",
|
|
2621
|
-
format: "credential",
|
|
2622
|
-
title: "JWT Assertion",
|
|
2623
|
-
description: "Pre-built JWT assertion (for static_private_key_jwt auth)"
|
|
2624
|
-
},
|
|
2625
|
-
auth_redirect_url: {
|
|
2626
|
-
type: "string",
|
|
2627
|
-
format: "uri",
|
|
2628
|
-
title: "Redirect URL",
|
|
2629
|
-
description: "OAuth redirect URL (for authorization_code auth)"
|
|
2630
|
-
},
|
|
2631
|
-
auth_scope: {
|
|
2632
|
-
type: "string",
|
|
2633
|
-
title: "Scope",
|
|
2634
|
-
description: "OAuth scope (space-separated)"
|
|
2635
|
-
},
|
|
2636
|
-
auth_client_name: {
|
|
2637
|
-
type: "string",
|
|
2638
|
-
title: "Client Name",
|
|
2639
|
-
description: "Optional OAuth client display name"
|
|
2640
|
-
},
|
|
2641
|
-
auth_jwt_lifetime_seconds: {
|
|
2642
|
-
type: "number",
|
|
2643
|
-
title: "JWT Lifetime",
|
|
2644
|
-
description: "JWT lifetime in seconds (default: 300)",
|
|
2645
|
-
minimum: 1
|
|
2646
|
-
}
|
|
2647
|
-
},
|
|
2648
|
-
allOf: [
|
|
2649
|
-
{
|
|
2650
|
-
if: { properties: { auth_type: { const: "bearer" } }, required: ["auth_type"] },
|
|
2651
|
-
then: {
|
|
2652
|
-
required: ["auth_token"],
|
|
2653
|
-
properties: { auth_token: true }
|
|
2654
|
-
}
|
|
2655
|
-
},
|
|
2656
|
-
{
|
|
2657
|
-
if: {
|
|
2658
|
-
properties: { auth_type: { const: "client_credentials" } },
|
|
2659
|
-
required: ["auth_type"]
|
|
2660
|
-
},
|
|
2661
|
-
then: {
|
|
2662
|
-
required: ["auth_client_id", "auth_client_secret"],
|
|
2663
|
-
properties: {
|
|
2664
|
-
auth_client_id: true,
|
|
2665
|
-
auth_client_secret: true,
|
|
2666
|
-
auth_client_name: true,
|
|
2667
|
-
auth_scope: true
|
|
2668
|
-
}
|
|
2669
|
-
}
|
|
2670
|
-
},
|
|
2671
|
-
{
|
|
2672
|
-
if: { properties: { auth_type: { const: "private_key_jwt" } }, required: ["auth_type"] },
|
|
2673
|
-
then: {
|
|
2674
|
-
required: ["auth_client_id", "auth_private_key", "auth_algorithm"],
|
|
2675
|
-
properties: {
|
|
2676
|
-
auth_client_id: true,
|
|
2677
|
-
auth_private_key: true,
|
|
2678
|
-
auth_algorithm: true,
|
|
2679
|
-
auth_client_name: true,
|
|
2680
|
-
auth_jwt_lifetime_seconds: true,
|
|
2681
|
-
auth_scope: true
|
|
2682
|
-
}
|
|
2683
|
-
}
|
|
2684
|
-
},
|
|
2685
|
-
{
|
|
2686
|
-
if: {
|
|
2687
|
-
properties: { auth_type: { const: "static_private_key_jwt" } },
|
|
2688
|
-
required: ["auth_type"]
|
|
2689
|
-
},
|
|
2690
|
-
then: {
|
|
2691
|
-
required: ["auth_client_id", "auth_jwt_bearer_assertion"],
|
|
2692
|
-
properties: {
|
|
2693
|
-
auth_client_id: true,
|
|
2694
|
-
auth_jwt_bearer_assertion: true,
|
|
2695
|
-
auth_client_name: true,
|
|
2696
|
-
auth_scope: true
|
|
2697
|
-
}
|
|
2698
|
-
}
|
|
2699
|
-
},
|
|
2700
|
-
{
|
|
2701
|
-
if: { properties: { auth_type: { const: "authorization_code" } }, required: ["auth_type"] },
|
|
2702
|
-
then: {
|
|
2703
|
-
required: ["auth_client_id", "auth_redirect_url"],
|
|
2704
|
-
properties: {
|
|
2705
|
-
auth_client_id: true,
|
|
2706
|
-
auth_client_secret: true,
|
|
2707
|
-
auth_redirect_url: true,
|
|
2708
|
-
auth_scope: true
|
|
2709
|
-
}
|
|
2710
|
-
}
|
|
2711
|
-
}
|
|
2712
|
-
]
|
|
2713
|
-
};
|
|
2714
|
-
function isMcpAuthType(value) {
|
|
2715
|
-
return typeof value === "string" && mcpAuthTypes.includes(value);
|
|
2716
|
-
}
|
|
2717
|
-
function asNonEmptyString(value) {
|
|
2718
|
-
if (typeof value !== "string")
|
|
2719
|
-
return;
|
|
2720
|
-
const trimmed = value.trim();
|
|
2721
|
-
return trimmed === "" ? undefined : trimmed;
|
|
2722
|
-
}
|
|
2723
|
-
function asNumber(value) {
|
|
2724
|
-
return typeof value === "number" ? value : undefined;
|
|
2725
|
-
}
|
|
2726
|
-
function buildAuthConfig(flat) {
|
|
2727
|
-
const rawAuthType = flat.auth_type;
|
|
2728
|
-
if (!isMcpAuthType(rawAuthType) || rawAuthType === "none") {
|
|
2729
|
-
return;
|
|
2730
|
-
}
|
|
2731
|
-
const authType = rawAuthType;
|
|
2732
|
-
switch (authType) {
|
|
2733
|
-
case "bearer": {
|
|
2734
|
-
const token = asNonEmptyString(flat.auth_token);
|
|
2735
|
-
if (!token)
|
|
2736
|
-
return;
|
|
2737
|
-
return { type: "bearer", token };
|
|
2738
|
-
}
|
|
2739
|
-
case "client_credentials": {
|
|
2740
|
-
const client_id = asNonEmptyString(flat.auth_client_id);
|
|
2741
|
-
const client_secret = asNonEmptyString(flat.auth_client_secret);
|
|
2742
|
-
if (!client_id || !client_secret)
|
|
2743
|
-
return;
|
|
2744
|
-
return {
|
|
2745
|
-
type: "client_credentials",
|
|
2746
|
-
client_id,
|
|
2747
|
-
client_secret,
|
|
2748
|
-
client_name: asNonEmptyString(flat.auth_client_name),
|
|
2749
|
-
scope: asNonEmptyString(flat.auth_scope)
|
|
2750
|
-
};
|
|
2751
|
-
}
|
|
2752
|
-
case "private_key_jwt": {
|
|
2753
|
-
const client_id = asNonEmptyString(flat.auth_client_id);
|
|
2754
|
-
const private_key = asNonEmptyString(flat.auth_private_key);
|
|
2755
|
-
const algorithm = asNonEmptyString(flat.auth_algorithm);
|
|
2756
|
-
if (!client_id || !private_key || !algorithm)
|
|
2757
|
-
return;
|
|
2758
|
-
return {
|
|
2759
|
-
type: "private_key_jwt",
|
|
2760
|
-
client_id,
|
|
2761
|
-
private_key,
|
|
2762
|
-
algorithm,
|
|
2763
|
-
client_name: asNonEmptyString(flat.auth_client_name),
|
|
2764
|
-
jwt_lifetime_seconds: asNumber(flat.auth_jwt_lifetime_seconds),
|
|
2765
|
-
scope: asNonEmptyString(flat.auth_scope)
|
|
2766
|
-
};
|
|
2767
|
-
}
|
|
2768
|
-
case "static_private_key_jwt": {
|
|
2769
|
-
const client_id = asNonEmptyString(flat.auth_client_id);
|
|
2770
|
-
const jwt_bearer_assertion = asNonEmptyString(flat.auth_jwt_bearer_assertion);
|
|
2771
|
-
if (!client_id || !jwt_bearer_assertion)
|
|
2772
|
-
return;
|
|
2773
|
-
return {
|
|
2774
|
-
type: "static_private_key_jwt",
|
|
2775
|
-
client_id,
|
|
2776
|
-
jwt_bearer_assertion,
|
|
2777
|
-
client_name: asNonEmptyString(flat.auth_client_name),
|
|
2778
|
-
scope: asNonEmptyString(flat.auth_scope)
|
|
2779
|
-
};
|
|
2780
|
-
}
|
|
2781
|
-
case "authorization_code": {
|
|
2782
|
-
const client_id = asNonEmptyString(flat.auth_client_id);
|
|
2783
|
-
const redirect_url = asNonEmptyString(flat.auth_redirect_url);
|
|
2784
|
-
if (!client_id || !redirect_url)
|
|
2785
|
-
return;
|
|
2786
|
-
return {
|
|
2787
|
-
type: "authorization_code",
|
|
2788
|
-
client_id,
|
|
2789
|
-
client_secret: asNonEmptyString(flat.auth_client_secret),
|
|
2790
|
-
redirect_url,
|
|
2791
|
-
scope: asNonEmptyString(flat.auth_scope)
|
|
2792
|
-
};
|
|
2793
|
-
}
|
|
2794
|
-
default:
|
|
2795
|
-
return;
|
|
2796
|
-
}
|
|
2797
|
-
}
|
|
2798
|
-
// src/mcp/McpAuthProvider.ts
|
|
2799
|
-
import {
|
|
2800
|
-
ClientCredentialsProvider,
|
|
2801
|
-
PrivateKeyJwtProvider,
|
|
2802
|
-
StaticPrivateKeyJwtProvider,
|
|
2803
|
-
createPrivateKeyJwtAuth
|
|
2804
|
-
} from "@modelcontextprotocol/sdk/client/auth-extensions.js";
|
|
2805
|
-
import { UnauthorizedError } from "@modelcontextprotocol/sdk/client/auth.js";
|
|
2806
|
-
function normalizeServerUrl(serverUrl) {
|
|
2807
|
-
try {
|
|
2808
|
-
const u = new URL(serverUrl);
|
|
2809
|
-
return u.origin + u.pathname.replace(/\/+$/, "");
|
|
2810
|
-
} catch {
|
|
2811
|
-
return serverUrl;
|
|
2812
|
-
}
|
|
2813
|
-
}
|
|
2814
|
-
function storeKey(serverUrl, suffix) {
|
|
2815
|
-
return `mcp:oauth:${normalizeServerUrl(serverUrl)}:${suffix}`;
|
|
2816
|
-
}
|
|
2817
|
-
|
|
2818
|
-
class CredentialStoreOAuthProvider {
|
|
2819
|
-
store;
|
|
2820
|
-
serverUrl;
|
|
2821
|
-
_clientMetadata;
|
|
2822
|
-
_redirectUrl;
|
|
2823
|
-
_initialClientInfo;
|
|
2824
|
-
prepareTokenRequest;
|
|
2825
|
-
addClientAuthentication;
|
|
2826
|
-
constructor(options) {
|
|
2827
|
-
this.store = options.store;
|
|
2828
|
-
this.serverUrl = options.serverUrl;
|
|
2829
|
-
this._clientMetadata = options.clientMetadata;
|
|
2830
|
-
this._redirectUrl = options.redirectUrl;
|
|
2831
|
-
this._initialClientInfo = options.initialClientInfo;
|
|
2832
|
-
if (options.prepareTokenRequest) {
|
|
2833
|
-
this.prepareTokenRequest = options.prepareTokenRequest;
|
|
2834
|
-
}
|
|
2835
|
-
if (options.addClientAuthentication) {
|
|
2836
|
-
this.addClientAuthentication = options.addClientAuthentication;
|
|
2837
|
-
}
|
|
2838
|
-
}
|
|
2839
|
-
get redirectUrl() {
|
|
2840
|
-
return this._redirectUrl;
|
|
2841
|
-
}
|
|
2842
|
-
get clientMetadata() {
|
|
2843
|
-
return this._clientMetadata;
|
|
2844
|
-
}
|
|
2845
|
-
async clientInformation() {
|
|
2846
|
-
const raw = await this.store.get(storeKey(this.serverUrl, "client_info"));
|
|
2847
|
-
if (!raw)
|
|
2848
|
-
return this._initialClientInfo;
|
|
2849
|
-
return JSON.parse(raw);
|
|
2850
|
-
}
|
|
2851
|
-
async saveClientInformation(info) {
|
|
2852
|
-
await this.store.put(storeKey(this.serverUrl, "client_info"), JSON.stringify(info));
|
|
2853
|
-
}
|
|
2854
|
-
async tokens() {
|
|
2855
|
-
const raw = await this.store.get(storeKey(this.serverUrl, "tokens"));
|
|
2856
|
-
if (!raw)
|
|
2857
|
-
return;
|
|
2858
|
-
return JSON.parse(raw);
|
|
2859
|
-
}
|
|
2860
|
-
async saveTokens(tokens) {
|
|
2861
|
-
const expiresAt = tokens.expires_in != null ? new Date(Date.now() + tokens.expires_in * 1000) : undefined;
|
|
2862
|
-
await this.store.put(storeKey(this.serverUrl, "tokens"), JSON.stringify(tokens), {
|
|
2863
|
-
expiresAt
|
|
2864
|
-
});
|
|
2865
|
-
}
|
|
2866
|
-
async redirectToAuthorization(authorizationUrl) {
|
|
2867
|
-
throw new Error(`MCP OAuth authorization required. ` + `Open this URL to authorize: ${authorizationUrl.toString()}`);
|
|
2868
|
-
}
|
|
2869
|
-
async saveCodeVerifier(codeVerifier) {
|
|
2870
|
-
await this.store.put(storeKey(this.serverUrl, "code_verifier"), codeVerifier);
|
|
2871
|
-
}
|
|
2872
|
-
async codeVerifier() {
|
|
2873
|
-
const v = await this.store.get(storeKey(this.serverUrl, "code_verifier"));
|
|
2874
|
-
if (!v)
|
|
2875
|
-
throw new Error("No code verifier saved for this session");
|
|
2876
|
-
return v;
|
|
2877
|
-
}
|
|
2878
|
-
async saveDiscoveryState(state) {
|
|
2879
|
-
await this.store.put(storeKey(this.serverUrl, "discovery"), JSON.stringify(state));
|
|
2880
|
-
}
|
|
2881
|
-
async discoveryState() {
|
|
2882
|
-
const raw = await this.store.get(storeKey(this.serverUrl, "discovery"));
|
|
2883
|
-
if (!raw)
|
|
2884
|
-
return;
|
|
2885
|
-
return JSON.parse(raw);
|
|
2886
|
-
}
|
|
2887
|
-
async invalidateCredentials(scope) {
|
|
2888
|
-
const deleteKey = async (suffix) => {
|
|
2889
|
-
await this.store.delete(storeKey(this.serverUrl, suffix));
|
|
2890
|
-
};
|
|
2891
|
-
switch (scope) {
|
|
2892
|
-
case "all":
|
|
2893
|
-
await deleteKey("tokens");
|
|
2894
|
-
await deleteKey("client_info");
|
|
2895
|
-
await deleteKey("code_verifier");
|
|
2896
|
-
await deleteKey("discovery");
|
|
2897
|
-
break;
|
|
2898
|
-
case "client":
|
|
2899
|
-
await deleteKey("client_info");
|
|
2900
|
-
break;
|
|
2901
|
-
case "tokens":
|
|
2902
|
-
await deleteKey("tokens");
|
|
2903
|
-
break;
|
|
2904
|
-
case "verifier":
|
|
2905
|
-
await deleteKey("code_verifier");
|
|
2906
|
-
break;
|
|
2907
|
-
case "discovery":
|
|
2908
|
-
await deleteKey("discovery");
|
|
2909
|
-
break;
|
|
2910
|
-
}
|
|
2911
|
-
}
|
|
2047
|
+
return new TextDecoder().decode(plainBuf);
|
|
2912
2048
|
}
|
|
2913
|
-
function
|
|
2914
|
-
|
|
2915
|
-
|
|
2916
|
-
|
|
2917
|
-
return;
|
|
2918
|
-
case "client_credentials": {
|
|
2919
|
-
if (!credentialStore) {
|
|
2920
|
-
return new ClientCredentialsProvider({
|
|
2921
|
-
clientId: auth.client_id,
|
|
2922
|
-
clientSecret: auth.client_secret,
|
|
2923
|
-
clientName: auth.client_name,
|
|
2924
|
-
scope: auth.scope
|
|
2925
|
-
});
|
|
2926
|
-
}
|
|
2927
|
-
const prepareTokenRequest = (scope) => {
|
|
2928
|
-
const params = new URLSearchParams({ grant_type: "client_credentials" });
|
|
2929
|
-
const effectiveScope = scope ?? auth.scope;
|
|
2930
|
-
if (effectiveScope)
|
|
2931
|
-
params.set("scope", effectiveScope);
|
|
2932
|
-
return params;
|
|
2933
|
-
};
|
|
2934
|
-
return new CredentialStoreOAuthProvider({
|
|
2935
|
-
store: credentialStore,
|
|
2936
|
-
serverUrl,
|
|
2937
|
-
clientMetadata: {
|
|
2938
|
-
redirect_uris: [],
|
|
2939
|
-
grant_types: ["client_credentials"],
|
|
2940
|
-
token_endpoint_auth_method: "client_secret_basic",
|
|
2941
|
-
client_name: auth.client_name
|
|
2942
|
-
},
|
|
2943
|
-
initialClientInfo: {
|
|
2944
|
-
client_id: auth.client_id,
|
|
2945
|
-
client_secret: auth.client_secret
|
|
2946
|
-
},
|
|
2947
|
-
prepareTokenRequest
|
|
2948
|
-
});
|
|
2949
|
-
}
|
|
2950
|
-
case "private_key_jwt": {
|
|
2951
|
-
if (!credentialStore) {
|
|
2952
|
-
return new PrivateKeyJwtProvider({
|
|
2953
|
-
clientId: auth.client_id,
|
|
2954
|
-
privateKey: auth.private_key,
|
|
2955
|
-
algorithm: auth.algorithm,
|
|
2956
|
-
clientName: auth.client_name,
|
|
2957
|
-
jwtLifetimeSeconds: auth.jwt_lifetime_seconds,
|
|
2958
|
-
scope: auth.scope
|
|
2959
|
-
});
|
|
2960
|
-
}
|
|
2961
|
-
const addClientAuth = createPrivateKeyJwtAuth({
|
|
2962
|
-
issuer: auth.client_id,
|
|
2963
|
-
subject: auth.client_id,
|
|
2964
|
-
privateKey: auth.private_key,
|
|
2965
|
-
alg: auth.algorithm,
|
|
2966
|
-
lifetimeSeconds: auth.jwt_lifetime_seconds
|
|
2967
|
-
});
|
|
2968
|
-
const prepareTokenRequest = (scope) => {
|
|
2969
|
-
const params = new URLSearchParams({ grant_type: "client_credentials" });
|
|
2970
|
-
const effectiveScope = scope ?? auth.scope;
|
|
2971
|
-
if (effectiveScope)
|
|
2972
|
-
params.set("scope", effectiveScope);
|
|
2973
|
-
return params;
|
|
2974
|
-
};
|
|
2975
|
-
return new CredentialStoreOAuthProvider({
|
|
2976
|
-
store: credentialStore,
|
|
2977
|
-
serverUrl,
|
|
2978
|
-
clientMetadata: {
|
|
2979
|
-
redirect_uris: [],
|
|
2980
|
-
grant_types: ["client_credentials"],
|
|
2981
|
-
token_endpoint_auth_method: "private_key_jwt",
|
|
2982
|
-
client_name: auth.client_name
|
|
2983
|
-
},
|
|
2984
|
-
initialClientInfo: { client_id: auth.client_id },
|
|
2985
|
-
prepareTokenRequest,
|
|
2986
|
-
addClientAuthentication: addClientAuth
|
|
2987
|
-
});
|
|
2988
|
-
}
|
|
2989
|
-
case "static_private_key_jwt": {
|
|
2990
|
-
if (!credentialStore) {
|
|
2991
|
-
return new StaticPrivateKeyJwtProvider({
|
|
2992
|
-
clientId: auth.client_id,
|
|
2993
|
-
jwtBearerAssertion: auth.jwt_bearer_assertion,
|
|
2994
|
-
clientName: auth.client_name,
|
|
2995
|
-
scope: auth.scope
|
|
2996
|
-
});
|
|
2997
|
-
}
|
|
2998
|
-
const assertion = auth.jwt_bearer_assertion;
|
|
2999
|
-
const addClientAuth = (_headers, params) => {
|
|
3000
|
-
params.set("client_assertion_type", "urn:ietf:params:oauth:client-assertion-type:jwt-bearer");
|
|
3001
|
-
params.set("client_assertion", assertion);
|
|
3002
|
-
};
|
|
3003
|
-
const prepareTokenRequest = (scope) => {
|
|
3004
|
-
const params = new URLSearchParams({ grant_type: "client_credentials" });
|
|
3005
|
-
const effectiveScope = scope ?? auth.scope;
|
|
3006
|
-
if (effectiveScope)
|
|
3007
|
-
params.set("scope", effectiveScope);
|
|
3008
|
-
return params;
|
|
3009
|
-
};
|
|
3010
|
-
return new CredentialStoreOAuthProvider({
|
|
3011
|
-
store: credentialStore,
|
|
3012
|
-
serverUrl,
|
|
3013
|
-
clientMetadata: {
|
|
3014
|
-
redirect_uris: [],
|
|
3015
|
-
grant_types: ["client_credentials"],
|
|
3016
|
-
token_endpoint_auth_method: "private_key_jwt",
|
|
3017
|
-
client_name: auth.client_name
|
|
3018
|
-
},
|
|
3019
|
-
initialClientInfo: { client_id: auth.client_id },
|
|
3020
|
-
prepareTokenRequest,
|
|
3021
|
-
addClientAuthentication: addClientAuth
|
|
3022
|
-
});
|
|
3023
|
-
}
|
|
3024
|
-
case "authorization_code": {
|
|
3025
|
-
if (!credentialStore) {
|
|
3026
|
-
throw new Error("authorization_code auth requires a credential store for token persistence");
|
|
3027
|
-
}
|
|
3028
|
-
return new CredentialStoreOAuthProvider({
|
|
3029
|
-
store: credentialStore,
|
|
3030
|
-
serverUrl,
|
|
3031
|
-
clientMetadata: {
|
|
3032
|
-
redirect_uris: [auth.redirect_url],
|
|
3033
|
-
grant_types: ["authorization_code", "refresh_token"],
|
|
3034
|
-
token_endpoint_auth_method: auth.client_secret ? "client_secret_basic" : "none",
|
|
3035
|
-
scope: auth.scope
|
|
3036
|
-
},
|
|
3037
|
-
initialClientInfo: {
|
|
3038
|
-
client_id: auth.client_id,
|
|
3039
|
-
...auth.client_secret ? { client_secret: auth.client_secret } : {}
|
|
3040
|
-
},
|
|
3041
|
-
redirectUrl: auth.redirect_url
|
|
3042
|
-
});
|
|
3043
|
-
}
|
|
3044
|
-
default:
|
|
3045
|
-
return;
|
|
2049
|
+
function bufToBase64(buf) {
|
|
2050
|
+
let binary = "";
|
|
2051
|
+
for (let i = 0;i < buf.length; i++) {
|
|
2052
|
+
binary += String.fromCharCode(buf[i]);
|
|
3046
2053
|
}
|
|
2054
|
+
return btoa(binary);
|
|
3047
2055
|
}
|
|
3048
|
-
|
|
3049
|
-
|
|
3050
|
-
|
|
3051
|
-
|
|
3052
|
-
|
|
3053
|
-
if (!value)
|
|
3054
|
-
return value;
|
|
3055
|
-
const resolved = await store.get(value);
|
|
3056
|
-
return resolved ?? value;
|
|
3057
|
-
}
|
|
3058
|
-
switch (auth.type) {
|
|
3059
|
-
case "bearer":
|
|
3060
|
-
return { ...auth, token: await resolve(auth.token) ?? auth.token };
|
|
3061
|
-
case "client_credentials":
|
|
3062
|
-
return {
|
|
3063
|
-
...auth,
|
|
3064
|
-
client_secret: await resolve(auth.client_secret) ?? auth.client_secret
|
|
3065
|
-
};
|
|
3066
|
-
case "private_key_jwt":
|
|
3067
|
-
return {
|
|
3068
|
-
...auth,
|
|
3069
|
-
private_key: await resolve(auth.private_key) ?? auth.private_key
|
|
3070
|
-
};
|
|
3071
|
-
case "static_private_key_jwt":
|
|
3072
|
-
return {
|
|
3073
|
-
...auth,
|
|
3074
|
-
jwt_bearer_assertion: await resolve(auth.jwt_bearer_assertion) ?? auth.jwt_bearer_assertion
|
|
3075
|
-
};
|
|
3076
|
-
case "authorization_code":
|
|
3077
|
-
return {
|
|
3078
|
-
...auth,
|
|
3079
|
-
client_secret: await resolve(auth.client_secret)
|
|
3080
|
-
};
|
|
3081
|
-
default:
|
|
3082
|
-
return auth;
|
|
2056
|
+
function base64ToBuf(b64) {
|
|
2057
|
+
const binary = atob(b64);
|
|
2058
|
+
const buf = new Uint8Array(binary.length);
|
|
2059
|
+
for (let i = 0;i < binary.length; i++) {
|
|
2060
|
+
buf[i] = binary.charCodeAt(i);
|
|
3083
2061
|
}
|
|
2062
|
+
return buf;
|
|
3084
2063
|
}
|
|
3085
2064
|
// src/telemetry/ITelemetryProvider.ts
|
|
3086
2065
|
var SpanStatusCode = {
|
|
@@ -3254,97 +2233,6 @@ async function decompress(input, algorithm = "gzip") {
|
|
|
3254
2233
|
const resultBuffer = await decompressAsyncTyped(sourceBuffer);
|
|
3255
2234
|
return resultBuffer.toString();
|
|
3256
2235
|
}
|
|
3257
|
-
// src/mcp/McpClientUtil.node.ts
|
|
3258
|
-
import { Client } from "@modelcontextprotocol/sdk/client";
|
|
3259
|
-
import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js";
|
|
3260
|
-
import { SSEClientTransport } from "@modelcontextprotocol/sdk/client/sse.js";
|
|
3261
|
-
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
|
|
3262
|
-
var mcpTransportTypes = ["stdio", "sse", "streamable-http"];
|
|
3263
|
-
var mcpServerConfigSchema = {
|
|
3264
|
-
properties: {
|
|
3265
|
-
transport: {
|
|
3266
|
-
type: "string",
|
|
3267
|
-
enum: mcpTransportTypes,
|
|
3268
|
-
title: "Transport",
|
|
3269
|
-
description: "The transport type to use for connecting to the MCP server"
|
|
3270
|
-
},
|
|
3271
|
-
server_url: {
|
|
3272
|
-
type: "string",
|
|
3273
|
-
format: "string:uri",
|
|
3274
|
-
title: "Server URL",
|
|
3275
|
-
description: "The URL of the MCP server (for sse and streamable-http transports)"
|
|
3276
|
-
},
|
|
3277
|
-
command: {
|
|
3278
|
-
type: "string",
|
|
3279
|
-
title: "Command",
|
|
3280
|
-
description: "The command to run (for stdio transport)"
|
|
3281
|
-
},
|
|
3282
|
-
args: {
|
|
3283
|
-
type: "array",
|
|
3284
|
-
items: { type: "string" },
|
|
3285
|
-
title: "Arguments",
|
|
3286
|
-
description: "Command arguments (for stdio transport)"
|
|
3287
|
-
},
|
|
3288
|
-
env: {
|
|
3289
|
-
type: "object",
|
|
3290
|
-
additionalProperties: { type: "string" },
|
|
3291
|
-
title: "Environment",
|
|
3292
|
-
description: "Environment variables (for stdio transport)"
|
|
3293
|
-
},
|
|
3294
|
-
...mcpAuthConfigSchema.properties
|
|
3295
|
-
},
|
|
3296
|
-
allOf: mcpAuthConfigSchema.allOf
|
|
3297
|
-
};
|
|
3298
|
-
async function createMcpClient(config, signal) {
|
|
3299
|
-
let transport;
|
|
3300
|
-
let auth = config.auth ?? buildAuthConfig({ ...config });
|
|
3301
|
-
if (auth && auth.type !== "none") {
|
|
3302
|
-
auth = await resolveAuthSecrets(auth, getGlobalCredentialStore());
|
|
3303
|
-
}
|
|
3304
|
-
const authProvider = config.authProvider ?? (auth && auth.type !== "none" && auth.type !== "bearer" ? createAuthProvider(auth, config.server_url ?? "", getGlobalCredentialStore()) : undefined);
|
|
3305
|
-
const headers = {
|
|
3306
|
-
...auth?.type === "bearer" ? { Authorization: `Bearer ${auth.token}` } : {}
|
|
3307
|
-
};
|
|
3308
|
-
switch (config.transport) {
|
|
3309
|
-
case "stdio":
|
|
3310
|
-
if (auth && auth.type !== "none") {
|
|
3311
|
-
getLogger().warn("MCP auth is not supported for stdio transport; auth config ignored. " + "Use env vars to pass credentials to stdio servers.");
|
|
3312
|
-
}
|
|
3313
|
-
transport = new StdioClientTransport({
|
|
3314
|
-
command: config.command,
|
|
3315
|
-
args: config.args,
|
|
3316
|
-
env: config.env
|
|
3317
|
-
});
|
|
3318
|
-
break;
|
|
3319
|
-
case "sse": {
|
|
3320
|
-
transport = new SSEClientTransport(new URL(config.server_url), {
|
|
3321
|
-
authProvider,
|
|
3322
|
-
requestInit: { headers }
|
|
3323
|
-
});
|
|
3324
|
-
break;
|
|
3325
|
-
}
|
|
3326
|
-
case "streamable-http": {
|
|
3327
|
-
transport = new StreamableHTTPClientTransport(new URL(config.server_url), {
|
|
3328
|
-
authProvider,
|
|
3329
|
-
requestInit: { headers }
|
|
3330
|
-
});
|
|
3331
|
-
break;
|
|
3332
|
-
}
|
|
3333
|
-
default:
|
|
3334
|
-
throw new Error(`Unsupported transport type: ${config.transport}`);
|
|
3335
|
-
}
|
|
3336
|
-
const client = new Client({ name: "workglow-mcp-client", version: "1.0.0" });
|
|
3337
|
-
if (signal) {
|
|
3338
|
-
signal.addEventListener("abort", () => {
|
|
3339
|
-
client.close().catch(() => {});
|
|
3340
|
-
}, { once: true });
|
|
3341
|
-
}
|
|
3342
|
-
await client.connect(transport);
|
|
3343
|
-
return { client, transport };
|
|
3344
|
-
}
|
|
3345
|
-
var mcpClientFactory = {
|
|
3346
|
-
create: createMcpClient
|
|
3347
|
-
};
|
|
3348
2236
|
// src/media/image.ts
|
|
3349
2237
|
function parseDataUri(dataUri) {
|
|
3350
2238
|
const match = dataUri.match(/^data:([^;]+);base64,(.+)$/);
|
|
@@ -3390,9 +2278,209 @@ async function convertImageDataToUseableForm(imageData, supports) {
|
|
|
3390
2278
|
}
|
|
3391
2279
|
throw new Error(`Unsupported image data type: ${typeof imageData}`);
|
|
3392
2280
|
}
|
|
2281
|
+
// src/worker/WorkerServerBase.ts
|
|
2282
|
+
var WORKER_SERVER = createServiceToken("worker.server");
|
|
2283
|
+
function extractTransferables(obj) {
|
|
2284
|
+
const transferables = [];
|
|
2285
|
+
const seen = new WeakSet;
|
|
2286
|
+
function findTransferables(value) {
|
|
2287
|
+
if (value && typeof value === "object" && seen.has(value)) {
|
|
2288
|
+
return;
|
|
2289
|
+
}
|
|
2290
|
+
if (value && typeof value === "object") {
|
|
2291
|
+
seen.add(value);
|
|
2292
|
+
}
|
|
2293
|
+
if (value instanceof Float32Array || value instanceof Int16Array) {
|
|
2294
|
+
transferables.push(value.buffer);
|
|
2295
|
+
} 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) {
|
|
2296
|
+
transferables.push(value.buffer);
|
|
2297
|
+
} else if (typeof OffscreenCanvas !== "undefined" && value instanceof OffscreenCanvas) {
|
|
2298
|
+
transferables.push(value);
|
|
2299
|
+
} else if (typeof ImageBitmap !== "undefined" && value instanceof ImageBitmap) {
|
|
2300
|
+
transferables.push(value);
|
|
2301
|
+
} else if (typeof VideoFrame !== "undefined" && value instanceof VideoFrame) {
|
|
2302
|
+
transferables.push(value);
|
|
2303
|
+
} else if (typeof MessagePort !== "undefined" && value instanceof MessagePort) {
|
|
2304
|
+
transferables.push(value);
|
|
2305
|
+
} else if (value instanceof ArrayBuffer) {
|
|
2306
|
+
transferables.push(value);
|
|
2307
|
+
} else if (Array.isArray(value)) {
|
|
2308
|
+
value.forEach(findTransferables);
|
|
2309
|
+
} else if (value && typeof value === "object") {
|
|
2310
|
+
Object.values(value).forEach(findTransferables);
|
|
2311
|
+
}
|
|
2312
|
+
}
|
|
2313
|
+
findTransferables(obj);
|
|
2314
|
+
return transferables;
|
|
2315
|
+
}
|
|
2316
|
+
|
|
2317
|
+
class WorkerServerBase {
|
|
2318
|
+
constructor() {}
|
|
2319
|
+
functions = {};
|
|
2320
|
+
streamFunctions = {};
|
|
2321
|
+
reactiveFunctions = {};
|
|
2322
|
+
requestControllers = new Map;
|
|
2323
|
+
completedRequests = new Set;
|
|
2324
|
+
postResult = (id, result) => {
|
|
2325
|
+
if (this.completedRequests.has(id)) {
|
|
2326
|
+
return;
|
|
2327
|
+
}
|
|
2328
|
+
this.completedRequests.add(id);
|
|
2329
|
+
const transferables = extractTransferables(result);
|
|
2330
|
+
const uniqueTransferables = [...new Set(transferables)];
|
|
2331
|
+
postMessage({ id, type: "complete", data: result }, uniqueTransferables);
|
|
2332
|
+
};
|
|
2333
|
+
postError = (id, errorMessage) => {
|
|
2334
|
+
if (this.completedRequests.has(id)) {
|
|
2335
|
+
return;
|
|
2336
|
+
}
|
|
2337
|
+
this.completedRequests.add(id);
|
|
2338
|
+
postMessage({ id, type: "error", data: errorMessage });
|
|
2339
|
+
};
|
|
2340
|
+
postStreamChunk = (id, event) => {
|
|
2341
|
+
if (this.completedRequests.has(id)) {
|
|
2342
|
+
return;
|
|
2343
|
+
}
|
|
2344
|
+
postMessage({ id, type: "stream_chunk", data: event });
|
|
2345
|
+
};
|
|
2346
|
+
sendReady() {
|
|
2347
|
+
postMessage({
|
|
2348
|
+
type: "ready",
|
|
2349
|
+
functions: Object.keys(this.functions),
|
|
2350
|
+
streamFunctions: Object.keys(this.streamFunctions),
|
|
2351
|
+
reactiveFunctions: Object.keys(this.reactiveFunctions)
|
|
2352
|
+
});
|
|
2353
|
+
}
|
|
2354
|
+
registerFunction(name, fn) {
|
|
2355
|
+
this.functions[name] = fn;
|
|
2356
|
+
}
|
|
2357
|
+
registerReactiveFunction(name, fn) {
|
|
2358
|
+
this.reactiveFunctions[name] = fn;
|
|
2359
|
+
}
|
|
2360
|
+
registerStreamFunction(name, fn) {
|
|
2361
|
+
this.streamFunctions[name] = fn;
|
|
2362
|
+
}
|
|
2363
|
+
async handleMessage(event) {
|
|
2364
|
+
const { id, type, functionName, args, stream, reactive } = event.data;
|
|
2365
|
+
if (type === "abort") {
|
|
2366
|
+
return await this.handleAbort(id);
|
|
2367
|
+
}
|
|
2368
|
+
if (type === "call") {
|
|
2369
|
+
if (stream) {
|
|
2370
|
+
return await this.handleStreamCall(id, functionName, args);
|
|
2371
|
+
}
|
|
2372
|
+
if (reactive) {
|
|
2373
|
+
return await this.handleReactiveCall(id, functionName, args);
|
|
2374
|
+
}
|
|
2375
|
+
return await this.handleCall(id, functionName, args);
|
|
2376
|
+
}
|
|
2377
|
+
}
|
|
2378
|
+
async handleAbort(id) {
|
|
2379
|
+
if (this.requestControllers.has(id)) {
|
|
2380
|
+
const controller = this.requestControllers.get(id);
|
|
2381
|
+
controller?.abort();
|
|
2382
|
+
this.requestControllers.delete(id);
|
|
2383
|
+
this.postError(id, "Operation aborted");
|
|
2384
|
+
}
|
|
2385
|
+
}
|
|
2386
|
+
async handleReactiveCall(id, functionName, [input, output, model]) {
|
|
2387
|
+
if (!(functionName in this.reactiveFunctions)) {
|
|
2388
|
+
this.postResult(id, undefined);
|
|
2389
|
+
return;
|
|
2390
|
+
}
|
|
2391
|
+
try {
|
|
2392
|
+
const fn = this.reactiveFunctions[functionName];
|
|
2393
|
+
const result = await fn(input, output, model);
|
|
2394
|
+
this.postResult(id, result);
|
|
2395
|
+
} catch (error) {
|
|
2396
|
+
this.postError(id, error.message);
|
|
2397
|
+
}
|
|
2398
|
+
}
|
|
2399
|
+
async handleCall(id, functionName, [input, model]) {
|
|
2400
|
+
if (!(functionName in this.functions)) {
|
|
2401
|
+
this.postError(id, `Function ${functionName} not found`);
|
|
2402
|
+
return;
|
|
2403
|
+
}
|
|
2404
|
+
try {
|
|
2405
|
+
const abortController = new AbortController;
|
|
2406
|
+
this.requestControllers.set(id, abortController);
|
|
2407
|
+
const fn = this.functions[functionName];
|
|
2408
|
+
const postProgress = (progress, message, details) => {
|
|
2409
|
+
if (!this.completedRequests.has(id)) {
|
|
2410
|
+
postMessage({ id, type: "progress", data: { progress, message, details } });
|
|
2411
|
+
}
|
|
2412
|
+
};
|
|
2413
|
+
const result = await fn(input, model, postProgress, abortController.signal);
|
|
2414
|
+
this.postResult(id, result);
|
|
2415
|
+
} catch (error) {
|
|
2416
|
+
this.postError(id, error.message);
|
|
2417
|
+
} finally {
|
|
2418
|
+
this.requestControllers.delete(id);
|
|
2419
|
+
setTimeout(() => {
|
|
2420
|
+
this.completedRequests.delete(id);
|
|
2421
|
+
}, 1000);
|
|
2422
|
+
}
|
|
2423
|
+
}
|
|
2424
|
+
async handleStreamCall(id, functionName, [input, model]) {
|
|
2425
|
+
if (functionName in this.streamFunctions) {
|
|
2426
|
+
try {
|
|
2427
|
+
const abortController = new AbortController;
|
|
2428
|
+
this.requestControllers.set(id, abortController);
|
|
2429
|
+
const fn = this.streamFunctions[functionName];
|
|
2430
|
+
const iterable = fn(input, model, abortController.signal);
|
|
2431
|
+
for await (const event of iterable) {
|
|
2432
|
+
if (this.completedRequests.has(id))
|
|
2433
|
+
break;
|
|
2434
|
+
this.postStreamChunk(id, event);
|
|
2435
|
+
}
|
|
2436
|
+
this.postResult(id, undefined);
|
|
2437
|
+
} catch (error) {
|
|
2438
|
+
this.postError(id, error.message);
|
|
2439
|
+
} finally {
|
|
2440
|
+
this.requestControllers.delete(id);
|
|
2441
|
+
setTimeout(() => {
|
|
2442
|
+
this.completedRequests.delete(id);
|
|
2443
|
+
}, 1000);
|
|
2444
|
+
}
|
|
2445
|
+
} else if (functionName in this.functions) {
|
|
2446
|
+
try {
|
|
2447
|
+
const abortController = new AbortController;
|
|
2448
|
+
this.requestControllers.set(id, abortController);
|
|
2449
|
+
const fn = this.functions[functionName];
|
|
2450
|
+
const noopProgress = () => {};
|
|
2451
|
+
const result = await fn(input, model, noopProgress, abortController.signal);
|
|
2452
|
+
this.postStreamChunk(id, { type: "finish", data: result });
|
|
2453
|
+
this.postResult(id, undefined);
|
|
2454
|
+
} catch (error) {
|
|
2455
|
+
this.postError(id, error.message);
|
|
2456
|
+
} finally {
|
|
2457
|
+
this.requestControllers.delete(id);
|
|
2458
|
+
setTimeout(() => {
|
|
2459
|
+
this.completedRequests.delete(id);
|
|
2460
|
+
}, 1000);
|
|
2461
|
+
}
|
|
2462
|
+
} else {
|
|
2463
|
+
this.postError(id, `Function ${functionName} not found`);
|
|
2464
|
+
}
|
|
2465
|
+
}
|
|
2466
|
+
}
|
|
2467
|
+
|
|
3393
2468
|
// src/worker/Worker.bun.ts
|
|
3394
2469
|
var Worker = globalThis.Worker;
|
|
3395
|
-
var
|
|
2470
|
+
var parentPort = self;
|
|
2471
|
+
class WorkerServer extends WorkerServerBase {
|
|
2472
|
+
constructor() {
|
|
2473
|
+
parentPort?.addEventListener("message", async (event) => {
|
|
2474
|
+
const msg = {
|
|
2475
|
+
type: event.type,
|
|
2476
|
+
data: event.data
|
|
2477
|
+
};
|
|
2478
|
+
await this.handleMessage(msg);
|
|
2479
|
+
});
|
|
2480
|
+
super();
|
|
2481
|
+
}
|
|
2482
|
+
}
|
|
2483
|
+
globalServiceRegistry.register(WORKER_SERVER, () => new WorkerServer, true);
|
|
3396
2484
|
export {
|
|
3397
2485
|
uuid4,
|
|
3398
2486
|
toSQLiteTimestamp,
|
|
@@ -3404,19 +2492,13 @@ export {
|
|
|
3404
2492
|
setGlobalCredentialStore,
|
|
3405
2493
|
serialize,
|
|
3406
2494
|
resolveCredential,
|
|
3407
|
-
resolveAuthSecrets,
|
|
3408
2495
|
registerInputResolver,
|
|
3409
2496
|
parsePartialJson,
|
|
3410
2497
|
parseDataUri,
|
|
3411
|
-
|
|
2498
|
+
parentPort,
|
|
3412
2499
|
objectOfArraysAsArrayOfObjects,
|
|
3413
2500
|
normalizeNumberArray,
|
|
3414
2501
|
normalize,
|
|
3415
|
-
mcpTransportTypes,
|
|
3416
|
-
mcpServerConfigSchema,
|
|
3417
|
-
mcpClientFactory,
|
|
3418
|
-
mcpAuthTypes,
|
|
3419
|
-
mcpAuthConfigSchema,
|
|
3420
2502
|
makeFingerprint,
|
|
3421
2503
|
magnitude,
|
|
3422
2504
|
jaccardSimilarity,
|
|
@@ -3438,24 +2520,17 @@ export {
|
|
|
3438
2520
|
decompress,
|
|
3439
2521
|
createTypedArrayFrom,
|
|
3440
2522
|
createServiceToken,
|
|
3441
|
-
createMcpClient,
|
|
3442
|
-
createAuthProvider,
|
|
3443
2523
|
cosineSimilarity,
|
|
3444
2524
|
convertImageDataToUseableForm,
|
|
3445
2525
|
compress,
|
|
3446
|
-
compileSchema,
|
|
3447
2526
|
collectPropertyValues,
|
|
3448
|
-
buildAuthConfig,
|
|
3449
2527
|
bufToBase64,
|
|
3450
2528
|
base64ToBuf,
|
|
3451
|
-
areSemanticallyCompatible,
|
|
3452
|
-
areObjectSchemasSemanticallyCompatible,
|
|
3453
2529
|
WorkerServer,
|
|
3454
2530
|
WorkerManager,
|
|
3455
2531
|
Worker,
|
|
3456
2532
|
WORKER_SERVER,
|
|
3457
2533
|
WORKER_MANAGER,
|
|
3458
|
-
UnauthorizedError,
|
|
3459
2534
|
TypedArraySchema,
|
|
3460
2535
|
TensorType,
|
|
3461
2536
|
TensorSchema,
|
|
@@ -3477,7 +2552,6 @@ export {
|
|
|
3477
2552
|
DirectedGraph,
|
|
3478
2553
|
DirectedAcyclicGraph,
|
|
3479
2554
|
CycleError,
|
|
3480
|
-
CredentialStoreOAuthProvider,
|
|
3481
2555
|
Container,
|
|
3482
2556
|
ConsoleTelemetryProvider,
|
|
3483
2557
|
ConsoleLogger,
|
|
@@ -3486,4 +2560,4 @@ export {
|
|
|
3486
2560
|
BaseError
|
|
3487
2561
|
};
|
|
3488
2562
|
|
|
3489
|
-
//# debugId=
|
|
2563
|
+
//# debugId=6926AF3541A03FA164756E2164756E21
|