@workglow/util 0.0.101 → 0.0.103
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 +335 -48
- package/dist/browser.js.map +10 -6
- package/dist/bun.js +320 -58
- package/dist/bun.js.map +10 -6
- package/dist/common.d.ts +2 -0
- package/dist/common.d.ts.map +1 -1
- package/dist/json-schema/JsonSchema.d.ts +2 -1
- package/dist/json-schema/JsonSchema.d.ts.map +1 -1
- package/dist/json-schema/parsePartialJson.d.ts +21 -0
- package/dist/json-schema/parsePartialJson.d.ts.map +1 -0
- package/dist/logging/ConsoleLogger.d.ts +27 -0
- package/dist/logging/ConsoleLogger.d.ts.map +1 -0
- package/dist/logging/ILogger.d.ts +22 -0
- package/dist/logging/ILogger.d.ts.map +1 -0
- package/dist/logging/LoggerRegistry.d.ts +19 -0
- package/dist/logging/LoggerRegistry.d.ts.map +1 -0
- package/dist/logging/NullLogger.d.ts +23 -0
- package/dist/logging/NullLogger.d.ts.map +1 -0
- package/dist/logging/index.d.ts +10 -0
- package/dist/logging/index.d.ts.map +1 -0
- package/dist/mcp/McpClientUtil.browser.d.ts.map +1 -1
- package/dist/mcp/McpClientUtil.node.d.ts +1 -1
- package/dist/mcp/McpClientUtil.node.d.ts.map +1 -1
- package/dist/node.js +320 -58
- package/dist/node.js.map +10 -6
- package/dist/worker/Worker.node.d.ts +1 -1
- package/dist/worker/Worker.node.d.ts.map +1 -1
- package/dist/worker/WorkerManager.d.ts +4 -0
- package/dist/worker/WorkerManager.d.ts.map +1 -1
- package/dist/worker/WorkerServer.d.ts +6 -0
- package/dist/worker/WorkerServer.d.ts.map +1 -1
- package/package.json +2 -2
package/dist/node.js
CHANGED
|
@@ -143,6 +143,117 @@ class EventEmitter {
|
|
|
143
143
|
return () => this.off(event, listener);
|
|
144
144
|
}
|
|
145
145
|
}
|
|
146
|
+
// src/logging/ConsoleLogger.ts
|
|
147
|
+
class ConsoleLogger {
|
|
148
|
+
bindings;
|
|
149
|
+
constructor(bindings = {}) {
|
|
150
|
+
this.bindings = bindings;
|
|
151
|
+
}
|
|
152
|
+
info(message, meta) {
|
|
153
|
+
const merged = this.merge(meta);
|
|
154
|
+
if (merged) {
|
|
155
|
+
console.info(message, merged);
|
|
156
|
+
} else {
|
|
157
|
+
console.info(message);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
warn(message, meta) {
|
|
161
|
+
const merged = this.merge(meta);
|
|
162
|
+
if (merged) {
|
|
163
|
+
console.warn(message, merged);
|
|
164
|
+
} else {
|
|
165
|
+
console.warn(message);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
error(message, meta) {
|
|
169
|
+
const merged = this.merge(meta);
|
|
170
|
+
if (merged) {
|
|
171
|
+
console.error(message, merged);
|
|
172
|
+
} else {
|
|
173
|
+
console.error(message);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
debug(message, meta) {
|
|
177
|
+
const merged = this.merge(meta);
|
|
178
|
+
if (merged) {
|
|
179
|
+
console.debug(message, merged);
|
|
180
|
+
} else {
|
|
181
|
+
console.debug(message);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
fatal(err, message, meta) {
|
|
185
|
+
const merged = this.merge(meta);
|
|
186
|
+
if (merged) {
|
|
187
|
+
console.error(message, { ...merged, error: err });
|
|
188
|
+
} else {
|
|
189
|
+
console.error(message, { error: err });
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
time(label, meta) {
|
|
193
|
+
const merged = this.merge(meta);
|
|
194
|
+
if (merged) {
|
|
195
|
+
console.info(`[time] ${label}`, merged);
|
|
196
|
+
}
|
|
197
|
+
console.time(label);
|
|
198
|
+
}
|
|
199
|
+
timeEnd(label, meta) {
|
|
200
|
+
console.timeEnd(label);
|
|
201
|
+
const merged = this.merge(meta);
|
|
202
|
+
if (merged) {
|
|
203
|
+
console.info(`[timeEnd] ${label}`, merged);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
group(label, meta) {
|
|
207
|
+
const merged = this.merge(meta);
|
|
208
|
+
if (merged) {
|
|
209
|
+
console.group(label, merged);
|
|
210
|
+
} else {
|
|
211
|
+
console.group(label);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
groupEnd() {
|
|
215
|
+
console.groupEnd();
|
|
216
|
+
}
|
|
217
|
+
child(bindings) {
|
|
218
|
+
return new ConsoleLogger({ ...this.bindings, ...bindings });
|
|
219
|
+
}
|
|
220
|
+
merge(meta) {
|
|
221
|
+
const hasBindings = Object.keys(this.bindings).length > 0;
|
|
222
|
+
if (!hasBindings && !meta)
|
|
223
|
+
return;
|
|
224
|
+
if (!hasBindings)
|
|
225
|
+
return meta;
|
|
226
|
+
if (!meta)
|
|
227
|
+
return this.bindings;
|
|
228
|
+
return { ...this.bindings, ...meta };
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
// src/logging/NullLogger.ts
|
|
232
|
+
class NullLogger {
|
|
233
|
+
info(_message, _meta) {}
|
|
234
|
+
error(_message, _meta) {}
|
|
235
|
+
warn(_message, _meta) {}
|
|
236
|
+
debug(_message, _meta) {}
|
|
237
|
+
fatal(_err, _message, _meta) {}
|
|
238
|
+
time(_label, _meta) {}
|
|
239
|
+
timeEnd(_label, _meta) {}
|
|
240
|
+
group(_label, _meta) {}
|
|
241
|
+
groupEnd() {}
|
|
242
|
+
child(_bindings) {
|
|
243
|
+
return this;
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
// src/logging/LoggerRegistry.ts
|
|
247
|
+
var LOGGER = createServiceToken("logger");
|
|
248
|
+
if (!globalServiceRegistry.has(LOGGER)) {
|
|
249
|
+
globalServiceRegistry.register(LOGGER, () => new ConsoleLogger, true);
|
|
250
|
+
}
|
|
251
|
+
function getLogger() {
|
|
252
|
+
return globalServiceRegistry.get(LOGGER);
|
|
253
|
+
}
|
|
254
|
+
function setLogger(logger) {
|
|
255
|
+
globalServiceRegistry.registerInstance(LOGGER, logger);
|
|
256
|
+
}
|
|
146
257
|
// src/utilities/BaseError.ts
|
|
147
258
|
class BaseError {
|
|
148
259
|
static type = "BaseError";
|
|
@@ -977,6 +1088,169 @@ function areObjectSchemasSemanticallyCompatible(sourceSchema, targetSchema) {
|
|
|
977
1088
|
}
|
|
978
1089
|
// src/json-schema/SchemaValidation.ts
|
|
979
1090
|
import { compileSchema } from "@sroussey/json-schema-library";
|
|
1091
|
+
// src/json-schema/parsePartialJson.ts
|
|
1092
|
+
function parsePartialJson(text) {
|
|
1093
|
+
const trimmed = text.trim();
|
|
1094
|
+
if (!trimmed)
|
|
1095
|
+
return;
|
|
1096
|
+
try {
|
|
1097
|
+
const result = JSON.parse(trimmed);
|
|
1098
|
+
if (typeof result === "object" && result !== null && !Array.isArray(result)) {
|
|
1099
|
+
return result;
|
|
1100
|
+
}
|
|
1101
|
+
return;
|
|
1102
|
+
} catch {}
|
|
1103
|
+
if (trimmed[0] !== "{")
|
|
1104
|
+
return;
|
|
1105
|
+
const repaired = repairJson(trimmed);
|
|
1106
|
+
if (repaired === undefined)
|
|
1107
|
+
return;
|
|
1108
|
+
try {
|
|
1109
|
+
const result = JSON.parse(repaired);
|
|
1110
|
+
if (typeof result === "object" && result !== null && !Array.isArray(result)) {
|
|
1111
|
+
return result;
|
|
1112
|
+
}
|
|
1113
|
+
return;
|
|
1114
|
+
} catch {
|
|
1115
|
+
return;
|
|
1116
|
+
}
|
|
1117
|
+
}
|
|
1118
|
+
function repairJson(text) {
|
|
1119
|
+
let result = "";
|
|
1120
|
+
let i = 0;
|
|
1121
|
+
const len = text.length;
|
|
1122
|
+
const stack = [];
|
|
1123
|
+
let inString = false;
|
|
1124
|
+
let escaped = false;
|
|
1125
|
+
let lastSafeEnd = 0;
|
|
1126
|
+
while (i < len) {
|
|
1127
|
+
const ch = text[i];
|
|
1128
|
+
if (escaped) {
|
|
1129
|
+
escaped = false;
|
|
1130
|
+
result += ch;
|
|
1131
|
+
i++;
|
|
1132
|
+
continue;
|
|
1133
|
+
}
|
|
1134
|
+
if (ch === "\\") {
|
|
1135
|
+
escaped = true;
|
|
1136
|
+
result += ch;
|
|
1137
|
+
i++;
|
|
1138
|
+
continue;
|
|
1139
|
+
}
|
|
1140
|
+
if (inString) {
|
|
1141
|
+
if (ch === '"') {
|
|
1142
|
+
inString = false;
|
|
1143
|
+
result += ch;
|
|
1144
|
+
i++;
|
|
1145
|
+
lastSafeEnd = result.length;
|
|
1146
|
+
continue;
|
|
1147
|
+
}
|
|
1148
|
+
result += ch;
|
|
1149
|
+
i++;
|
|
1150
|
+
continue;
|
|
1151
|
+
}
|
|
1152
|
+
switch (ch) {
|
|
1153
|
+
case '"':
|
|
1154
|
+
inString = true;
|
|
1155
|
+
result += ch;
|
|
1156
|
+
i++;
|
|
1157
|
+
break;
|
|
1158
|
+
case "{":
|
|
1159
|
+
stack.push("}");
|
|
1160
|
+
result += ch;
|
|
1161
|
+
i++;
|
|
1162
|
+
break;
|
|
1163
|
+
case "[":
|
|
1164
|
+
stack.push("]");
|
|
1165
|
+
result += ch;
|
|
1166
|
+
i++;
|
|
1167
|
+
break;
|
|
1168
|
+
case "}":
|
|
1169
|
+
if (stack.length > 0 && stack[stack.length - 1] === "}") {
|
|
1170
|
+
stack.pop();
|
|
1171
|
+
result += ch;
|
|
1172
|
+
i++;
|
|
1173
|
+
lastSafeEnd = result.length;
|
|
1174
|
+
} else {
|
|
1175
|
+
return closeStack(result, stack);
|
|
1176
|
+
}
|
|
1177
|
+
break;
|
|
1178
|
+
case "]":
|
|
1179
|
+
if (stack.length > 0 && stack[stack.length - 1] === "]") {
|
|
1180
|
+
stack.pop();
|
|
1181
|
+
result += ch;
|
|
1182
|
+
i++;
|
|
1183
|
+
lastSafeEnd = result.length;
|
|
1184
|
+
} else {
|
|
1185
|
+
return closeStack(result, stack);
|
|
1186
|
+
}
|
|
1187
|
+
break;
|
|
1188
|
+
default:
|
|
1189
|
+
result += ch;
|
|
1190
|
+
i++;
|
|
1191
|
+
break;
|
|
1192
|
+
}
|
|
1193
|
+
}
|
|
1194
|
+
if (inString) {
|
|
1195
|
+
result += '"';
|
|
1196
|
+
}
|
|
1197
|
+
if (stack.length === 0) {
|
|
1198
|
+
return result;
|
|
1199
|
+
}
|
|
1200
|
+
return closeStack(cleanTrailing(result), stack);
|
|
1201
|
+
}
|
|
1202
|
+
function cleanTrailing(text) {
|
|
1203
|
+
let s = text.trimEnd();
|
|
1204
|
+
let changed = true;
|
|
1205
|
+
while (changed) {
|
|
1206
|
+
changed = false;
|
|
1207
|
+
const trimmed = s.trimEnd();
|
|
1208
|
+
if (trimmed.endsWith(",")) {
|
|
1209
|
+
s = trimmed.slice(0, -1);
|
|
1210
|
+
changed = true;
|
|
1211
|
+
continue;
|
|
1212
|
+
}
|
|
1213
|
+
if (trimmed.endsWith(":")) {
|
|
1214
|
+
const withoutColon = trimmed.slice(0, -1).trimEnd();
|
|
1215
|
+
if (withoutColon.endsWith('"')) {
|
|
1216
|
+
const keyStart = withoutColon.lastIndexOf('"', withoutColon.length - 2);
|
|
1217
|
+
if (keyStart >= 0) {
|
|
1218
|
+
let before = withoutColon.slice(0, keyStart).trimEnd();
|
|
1219
|
+
if (before.endsWith(",")) {
|
|
1220
|
+
before = before.slice(0, -1);
|
|
1221
|
+
}
|
|
1222
|
+
s = before;
|
|
1223
|
+
changed = true;
|
|
1224
|
+
continue;
|
|
1225
|
+
}
|
|
1226
|
+
}
|
|
1227
|
+
s = withoutColon;
|
|
1228
|
+
changed = true;
|
|
1229
|
+
continue;
|
|
1230
|
+
}
|
|
1231
|
+
const bareTokenMatch = trimmed.match(/,\s*"[^"]*"\s*:\s*(?:tru|fal|nul|true|false|null|[\d.eE+-]+)$/);
|
|
1232
|
+
if (bareTokenMatch) {
|
|
1233
|
+
const valueStr = trimmed.slice(trimmed.lastIndexOf(":") + 1).trim();
|
|
1234
|
+
try {
|
|
1235
|
+
JSON.parse(valueStr);
|
|
1236
|
+
} catch {
|
|
1237
|
+
s = trimmed.slice(0, bareTokenMatch.index).trimEnd();
|
|
1238
|
+
if (s.endsWith(","))
|
|
1239
|
+
s = s.slice(0, -1);
|
|
1240
|
+
changed = true;
|
|
1241
|
+
continue;
|
|
1242
|
+
}
|
|
1243
|
+
}
|
|
1244
|
+
}
|
|
1245
|
+
return s;
|
|
1246
|
+
}
|
|
1247
|
+
function closeStack(text, stack) {
|
|
1248
|
+
let result = text;
|
|
1249
|
+
for (let i = stack.length - 1;i >= 0; i--) {
|
|
1250
|
+
result += stack[i];
|
|
1251
|
+
}
|
|
1252
|
+
return result;
|
|
1253
|
+
}
|
|
980
1254
|
// src/utilities/Misc.ts
|
|
981
1255
|
function forceArray(input) {
|
|
982
1256
|
if (Array.isArray(input))
|
|
@@ -1581,43 +1855,12 @@ function normalizeNumberArray(values, throwOnZero = false) {
|
|
|
1581
1855
|
return values.map((v) => v / norm);
|
|
1582
1856
|
}
|
|
1583
1857
|
// src/worker/WorkerManager.ts
|
|
1584
|
-
function extractTransferables(obj) {
|
|
1585
|
-
const transferables = [];
|
|
1586
|
-
const seen = new WeakSet;
|
|
1587
|
-
function findTransferables(value) {
|
|
1588
|
-
if (value && typeof value === "object" && seen.has(value)) {
|
|
1589
|
-
return;
|
|
1590
|
-
}
|
|
1591
|
-
if (value && typeof value === "object") {
|
|
1592
|
-
seen.add(value);
|
|
1593
|
-
}
|
|
1594
|
-
if (value instanceof Float32Array || value instanceof Int16Array) {
|
|
1595
|
-
transferables.push(value.buffer);
|
|
1596
|
-
} 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) {
|
|
1597
|
-
transferables.push(value.buffer);
|
|
1598
|
-
} else if (typeof OffscreenCanvas !== "undefined" && value instanceof OffscreenCanvas) {
|
|
1599
|
-
transferables.push(value);
|
|
1600
|
-
} else if (typeof ImageBitmap !== "undefined" && value instanceof ImageBitmap) {
|
|
1601
|
-
transferables.push(value);
|
|
1602
|
-
} else if (typeof VideoFrame !== "undefined" && value instanceof VideoFrame) {
|
|
1603
|
-
transferables.push(value);
|
|
1604
|
-
} else if (typeof MessagePort !== "undefined" && value instanceof MessagePort) {
|
|
1605
|
-
transferables.push(value);
|
|
1606
|
-
} else if (value instanceof ArrayBuffer) {
|
|
1607
|
-
transferables.push(value);
|
|
1608
|
-
} else if (Array.isArray(value)) {
|
|
1609
|
-
value.forEach(findTransferables);
|
|
1610
|
-
} else if (value && typeof value === "object") {
|
|
1611
|
-
Object.values(value).forEach(findTransferables);
|
|
1612
|
-
}
|
|
1613
|
-
}
|
|
1614
|
-
findTransferables(obj);
|
|
1615
|
-
return transferables;
|
|
1616
|
-
}
|
|
1617
|
-
|
|
1618
1858
|
class WorkerManager {
|
|
1619
1859
|
workers = new Map;
|
|
1620
1860
|
readyWorkers = new Map;
|
|
1861
|
+
workerFunctions = new Map;
|
|
1862
|
+
workerStreamFunctions = new Map;
|
|
1863
|
+
workerReactiveFunctions = new Map;
|
|
1621
1864
|
registerWorker(name, worker) {
|
|
1622
1865
|
if (this.workers.has(name))
|
|
1623
1866
|
throw new Error(`Worker ${name} is already registered.`);
|
|
@@ -1633,6 +1876,9 @@ class WorkerManager {
|
|
|
1633
1876
|
const handleReady = (event) => {
|
|
1634
1877
|
if (event.data?.type === "ready") {
|
|
1635
1878
|
worker.removeEventListener("message", handleReady);
|
|
1879
|
+
this.workerFunctions.set(name, new Set(event.data.functions ?? []));
|
|
1880
|
+
this.workerStreamFunctions.set(name, new Set(event.data.streamFunctions ?? []));
|
|
1881
|
+
this.workerReactiveFunctions.set(name, new Set(event.data.reactiveFunctions ?? []));
|
|
1636
1882
|
resolve();
|
|
1637
1883
|
}
|
|
1638
1884
|
};
|
|
@@ -1651,6 +1897,10 @@ class WorkerManager {
|
|
|
1651
1897
|
if (!worker)
|
|
1652
1898
|
throw new Error(`Worker ${workerName} not found.`);
|
|
1653
1899
|
await this.readyWorkers.get(workerName);
|
|
1900
|
+
const knownFunctions = this.workerFunctions.get(workerName);
|
|
1901
|
+
if (knownFunctions && !knownFunctions.has(functionName)) {
|
|
1902
|
+
throw new Error(`Function "${functionName}" is not registered on worker "${workerName}".`);
|
|
1903
|
+
}
|
|
1654
1904
|
return new Promise((resolve, reject) => {
|
|
1655
1905
|
const requestId = crypto.randomUUID();
|
|
1656
1906
|
const handleMessage = (event) => {
|
|
@@ -1679,8 +1929,7 @@ class WorkerManager {
|
|
|
1679
1929
|
options.signal.addEventListener("abort", handleAbort, { once: true });
|
|
1680
1930
|
}
|
|
1681
1931
|
const message = { id: requestId, type: "call", functionName, args };
|
|
1682
|
-
|
|
1683
|
-
worker.postMessage(message, transferables);
|
|
1932
|
+
worker.postMessage(message);
|
|
1684
1933
|
});
|
|
1685
1934
|
}
|
|
1686
1935
|
async callWorkerReactiveFunction(workerName, functionName, args) {
|
|
@@ -1688,6 +1937,9 @@ class WorkerManager {
|
|
|
1688
1937
|
if (!worker)
|
|
1689
1938
|
return;
|
|
1690
1939
|
await this.readyWorkers.get(workerName);
|
|
1940
|
+
const knownReactive = this.workerReactiveFunctions.get(workerName);
|
|
1941
|
+
if (knownReactive && !knownReactive.has(functionName))
|
|
1942
|
+
return;
|
|
1691
1943
|
return new Promise((resolve) => {
|
|
1692
1944
|
const requestId = crypto.randomUUID();
|
|
1693
1945
|
const handleMessage = (event) => {
|
|
@@ -1707,8 +1959,7 @@ class WorkerManager {
|
|
|
1707
1959
|
};
|
|
1708
1960
|
worker.addEventListener("message", handleMessage);
|
|
1709
1961
|
const message = { id: requestId, type: "call", functionName, args, reactive: true };
|
|
1710
|
-
|
|
1711
|
-
worker.postMessage(message, transferables);
|
|
1962
|
+
worker.postMessage(message);
|
|
1712
1963
|
});
|
|
1713
1964
|
}
|
|
1714
1965
|
async* callWorkerStreamFunction(workerName, functionName, args, options) {
|
|
@@ -1716,6 +1967,11 @@ class WorkerManager {
|
|
|
1716
1967
|
if (!worker)
|
|
1717
1968
|
throw new Error(`Worker ${workerName} not found.`);
|
|
1718
1969
|
await this.readyWorkers.get(workerName);
|
|
1970
|
+
const knownStream = this.workerStreamFunctions.get(workerName);
|
|
1971
|
+
const knownFns = this.workerFunctions.get(workerName);
|
|
1972
|
+
if (knownStream && knownFns && !knownStream.has(functionName) && !knownFns.has(functionName)) {
|
|
1973
|
+
throw new Error(`Function "${functionName}" is not registered on worker "${workerName}".`);
|
|
1974
|
+
}
|
|
1719
1975
|
const requestId = crypto.randomUUID();
|
|
1720
1976
|
const queue = [];
|
|
1721
1977
|
let waiting = null;
|
|
@@ -1757,8 +2013,7 @@ class WorkerManager {
|
|
|
1757
2013
|
options.signal.addEventListener("abort", handleAbort, { once: true });
|
|
1758
2014
|
}
|
|
1759
2015
|
const message = { id: requestId, type: "call", functionName, args, stream: true };
|
|
1760
|
-
|
|
1761
|
-
worker.postMessage(message, transferables);
|
|
2016
|
+
worker.postMessage(message);
|
|
1762
2017
|
let completedNormally = false;
|
|
1763
2018
|
try {
|
|
1764
2019
|
while (true) {
|
|
@@ -1790,7 +2045,7 @@ var WORKER_MANAGER = createServiceToken("worker.manager");
|
|
|
1790
2045
|
globalServiceRegistry.register(WORKER_MANAGER, () => new WorkerManager, true);
|
|
1791
2046
|
// src/worker/WorkerServer.ts
|
|
1792
2047
|
import { parentPort } from "@workglow/util";
|
|
1793
|
-
function
|
|
2048
|
+
function extractTransferables(obj) {
|
|
1794
2049
|
const transferables = [];
|
|
1795
2050
|
const seen = new WeakSet;
|
|
1796
2051
|
function findTransferables(value) {
|
|
@@ -1844,8 +2099,9 @@ class WorkerServer {
|
|
|
1844
2099
|
return;
|
|
1845
2100
|
}
|
|
1846
2101
|
this.completedRequests.add(id);
|
|
1847
|
-
const transferables =
|
|
1848
|
-
|
|
2102
|
+
const transferables = extractTransferables(result);
|
|
2103
|
+
const uniqueTransferables = [...new Set(transferables)];
|
|
2104
|
+
postMessage({ id, type: "complete", data: result }, uniqueTransferables);
|
|
1849
2105
|
};
|
|
1850
2106
|
postError = (id, errorMessage) => {
|
|
1851
2107
|
if (this.completedRequests.has(id)) {
|
|
@@ -1860,6 +2116,14 @@ class WorkerServer {
|
|
|
1860
2116
|
}
|
|
1861
2117
|
postMessage({ id, type: "stream_chunk", data: event });
|
|
1862
2118
|
};
|
|
2119
|
+
sendReady() {
|
|
2120
|
+
postMessage({
|
|
2121
|
+
type: "ready",
|
|
2122
|
+
functions: Object.keys(this.functions),
|
|
2123
|
+
streamFunctions: Object.keys(this.streamFunctions),
|
|
2124
|
+
reactiveFunctions: Object.keys(this.reactiveFunctions)
|
|
2125
|
+
});
|
|
2126
|
+
}
|
|
1863
2127
|
registerFunction(name, fn) {
|
|
1864
2128
|
this.functions[name] = fn;
|
|
1865
2129
|
}
|
|
@@ -2022,7 +2286,7 @@ var mcpServerConfigSchema = {
|
|
|
2022
2286
|
},
|
|
2023
2287
|
server_url: {
|
|
2024
2288
|
type: "string",
|
|
2025
|
-
format: "uri",
|
|
2289
|
+
format: "string:uri",
|
|
2026
2290
|
title: "Server URL",
|
|
2027
2291
|
description: "The URL of the MCP server (for sse and streamable-http transports)"
|
|
2028
2292
|
},
|
|
@@ -2054,12 +2318,14 @@ async function createMcpClient(config, signal) {
|
|
|
2054
2318
|
env: config.env
|
|
2055
2319
|
});
|
|
2056
2320
|
break;
|
|
2057
|
-
case "sse":
|
|
2321
|
+
case "sse": {
|
|
2058
2322
|
transport = new SSEClientTransport(new URL(config.server_url));
|
|
2059
2323
|
break;
|
|
2060
|
-
|
|
2324
|
+
}
|
|
2325
|
+
case "streamable-http": {
|
|
2061
2326
|
transport = new StreamableHTTPClientTransport(new URL(config.server_url));
|
|
2062
2327
|
break;
|
|
2328
|
+
}
|
|
2063
2329
|
default:
|
|
2064
2330
|
throw new Error(`Unsupported transport type: ${config.transport}`);
|
|
2065
2331
|
}
|
|
@@ -2069,17 +2335,7 @@ async function createMcpClient(config, signal) {
|
|
|
2069
2335
|
client.close().catch(() => {});
|
|
2070
2336
|
}, { once: true });
|
|
2071
2337
|
}
|
|
2072
|
-
|
|
2073
|
-
await client.connect(transport);
|
|
2074
|
-
} catch (err) {
|
|
2075
|
-
const message = err instanceof Error ? err.message : String(err);
|
|
2076
|
-
const url = config.server_url ?? "";
|
|
2077
|
-
const is405 = message.includes("405") || message.includes("Method Not Allowed") || typeof err === "object" && err !== null && "status" in err && err.status === 405;
|
|
2078
|
-
if (is405) {
|
|
2079
|
-
throw new Error(`MCP connection failed with 405 Method Not Allowed for ${url}. ` + `This usually means the server does not accept GET requests. `, { cause: err });
|
|
2080
|
-
}
|
|
2081
|
-
throw err;
|
|
2082
|
-
}
|
|
2338
|
+
await client.connect(transport);
|
|
2083
2339
|
return { client, transport };
|
|
2084
2340
|
}
|
|
2085
2341
|
var mcpClientFactory = {
|
|
@@ -2160,8 +2416,10 @@ export {
|
|
|
2160
2416
|
sortObject,
|
|
2161
2417
|
sleep,
|
|
2162
2418
|
sha256,
|
|
2419
|
+
setLogger,
|
|
2163
2420
|
serialize,
|
|
2164
2421
|
registerInputResolver,
|
|
2422
|
+
parsePartialJson,
|
|
2165
2423
|
parseDataUri,
|
|
2166
2424
|
parentPort2 as parentPort,
|
|
2167
2425
|
objectOfArraysAsArrayOfObjects,
|
|
@@ -2179,6 +2437,7 @@ export {
|
|
|
2179
2437
|
hammingDistance,
|
|
2180
2438
|
globalServiceRegistry,
|
|
2181
2439
|
globalContainer,
|
|
2440
|
+
getLogger,
|
|
2182
2441
|
getInputResolvers,
|
|
2183
2442
|
forceArray,
|
|
2184
2443
|
deepEqual,
|
|
@@ -2202,8 +2461,10 @@ export {
|
|
|
2202
2461
|
TensorType,
|
|
2203
2462
|
TensorSchema,
|
|
2204
2463
|
ServiceRegistry,
|
|
2464
|
+
NullLogger,
|
|
2205
2465
|
NodeDoesntExistError,
|
|
2206
2466
|
NodeAlreadyExistsError,
|
|
2467
|
+
LOGGER,
|
|
2207
2468
|
INPUT_RESOLVERS,
|
|
2208
2469
|
Graph,
|
|
2209
2470
|
FromSchemaDefaultOptions,
|
|
@@ -2212,7 +2473,8 @@ export {
|
|
|
2212
2473
|
DirectedAcyclicGraph,
|
|
2213
2474
|
CycleError,
|
|
2214
2475
|
Container,
|
|
2476
|
+
ConsoleLogger,
|
|
2215
2477
|
BaseError
|
|
2216
2478
|
};
|
|
2217
2479
|
|
|
2218
|
-
//# debugId=
|
|
2480
|
+
//# debugId=B4EF66B1A6B9B24664756E2164756E21
|