intent-hub 0.1.0
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/.claude/settings.local.json +7 -0
- package/.turbo/cache/019f5ae385027cb1-meta.json +1 -0
- package/.turbo/cache/019f5ae385027cb1.tar.zst +0 -0
- package/.turbo/cache/040af6112a552a64-meta.json +1 -0
- package/.turbo/cache/040af6112a552a64.tar.zst +0 -0
- package/.turbo/cache/11195eac3ca5c6ce-meta.json +1 -0
- package/.turbo/cache/11195eac3ca5c6ce.tar.zst +0 -0
- package/.turbo/cache/13d11166efdf11cf-meta.json +1 -0
- package/.turbo/cache/13d11166efdf11cf.tar.zst +0 -0
- package/.turbo/cache/19af1af3b136706c-meta.json +1 -0
- package/.turbo/cache/19af1af3b136706c.tar.zst +0 -0
- package/.turbo/cache/1d33efac91c05b50-meta.json +1 -0
- package/.turbo/cache/1d33efac91c05b50.tar.zst +0 -0
- package/.turbo/cache/200b85a612af2d13-meta.json +1 -0
- package/.turbo/cache/200b85a612af2d13.tar.zst +0 -0
- package/.turbo/cache/210308c9ea929858-meta.json +1 -0
- package/.turbo/cache/210308c9ea929858.tar.zst +0 -0
- package/.turbo/cache/38df8e44c617835e-meta.json +1 -0
- package/.turbo/cache/38df8e44c617835e.tar.zst +0 -0
- package/.turbo/cache/3e449de5ef60a7a0-meta.json +1 -0
- package/.turbo/cache/3e449de5ef60a7a0.tar.zst +0 -0
- package/.turbo/cache/51ff024a97c2b4f5-meta.json +1 -0
- package/.turbo/cache/51ff024a97c2b4f5.tar.zst +0 -0
- package/.turbo/cache/54bc756eeebb377a-meta.json +1 -0
- package/.turbo/cache/54bc756eeebb377a.tar.zst +0 -0
- package/.turbo/cache/5ed6a840acafc873-meta.json +1 -0
- package/.turbo/cache/5ed6a840acafc873.tar.zst +0 -0
- package/.turbo/cache/6702dc24e5ca3c2e-meta.json +1 -0
- package/.turbo/cache/6702dc24e5ca3c2e.tar.zst +0 -0
- package/.turbo/cache/725c72cf71ea854f-meta.json +1 -0
- package/.turbo/cache/725c72cf71ea854f.tar.zst +0 -0
- package/.turbo/cache/7344ca28d348037a-meta.json +1 -0
- package/.turbo/cache/7344ca28d348037a.tar.zst +0 -0
- package/.turbo/cache/748fb444cdc0b78c-meta.json +1 -0
- package/.turbo/cache/748fb444cdc0b78c.tar.zst +0 -0
- package/.turbo/cache/789677c36fe7fb98-meta.json +1 -0
- package/.turbo/cache/789677c36fe7fb98.tar.zst +0 -0
- package/.turbo/cache/89ff6c6f38dd4a18-meta.json +1 -0
- package/.turbo/cache/89ff6c6f38dd4a18.tar.zst +0 -0
- package/.turbo/cache/8dbc92d00de0c92e-meta.json +1 -0
- package/.turbo/cache/8dbc92d00de0c92e.tar.zst +0 -0
- package/.turbo/cache/8eb03f40082b9441-meta.json +1 -0
- package/.turbo/cache/8eb03f40082b9441.tar.zst +0 -0
- package/.turbo/cache/9157134d4b916017-meta.json +1 -0
- package/.turbo/cache/9157134d4b916017.tar.zst +0 -0
- package/.turbo/cache/94219ffd32b48e93-meta.json +1 -0
- package/.turbo/cache/94219ffd32b48e93.tar.zst +0 -0
- package/.turbo/cache/95c1d160b4fa84eb-meta.json +1 -0
- package/.turbo/cache/95c1d160b4fa84eb.tar.zst +0 -0
- package/.turbo/cache/998833ea02dfb225-meta.json +1 -0
- package/.turbo/cache/998833ea02dfb225.tar.zst +0 -0
- package/.turbo/cache/a5974ef6ade3eb90-meta.json +1 -0
- package/.turbo/cache/a5974ef6ade3eb90.tar.zst +0 -0
- package/.turbo/cache/aab811809257decb-meta.json +1 -0
- package/.turbo/cache/aab811809257decb.tar.zst +0 -0
- package/.turbo/cache/ab2f82a54da854fd-meta.json +1 -0
- package/.turbo/cache/ab2f82a54da854fd.tar.zst +0 -0
- package/.turbo/cache/abbf4d95d62a7303-meta.json +1 -0
- package/.turbo/cache/abbf4d95d62a7303.tar.zst +0 -0
- package/.turbo/cache/af4441f519f9ce50-meta.json +1 -0
- package/.turbo/cache/af4441f519f9ce50.tar.zst +0 -0
- package/.turbo/cache/b9b85aaaf03d00a6-meta.json +1 -0
- package/.turbo/cache/b9b85aaaf03d00a6.tar.zst +0 -0
- package/.turbo/cache/cd58ee8721bbfed7-meta.json +1 -0
- package/.turbo/cache/cd58ee8721bbfed7.tar.zst +0 -0
- package/.turbo/cache/d285e48b8afa30b5-meta.json +1 -0
- package/.turbo/cache/d285e48b8afa30b5.tar.zst +0 -0
- package/.turbo/cache/d33e90229142acce-meta.json +1 -0
- package/.turbo/cache/d33e90229142acce.tar.zst +0 -0
- package/.turbo/cache/d57839a0d3b04540-meta.json +1 -0
- package/.turbo/cache/d57839a0d3b04540.tar.zst +0 -0
- package/.turbo/cache/d8554ef2c8b6e5eb-meta.json +1 -0
- package/.turbo/cache/d8554ef2c8b6e5eb.tar.zst +0 -0
- package/.turbo/cache/dc7375b51290e102-meta.json +1 -0
- package/.turbo/cache/dc7375b51290e102.tar.zst +0 -0
- package/.turbo/cache/e5310fe547fdbf0a-meta.json +1 -0
- package/.turbo/cache/e5310fe547fdbf0a.tar.zst +0 -0
- package/.turbo/cache/f12bb5f2f188758d-meta.json +1 -0
- package/.turbo/cache/f12bb5f2f188758d.tar.zst +0 -0
- package/.turbo/cache/f2db5af0c0b4d23f-meta.json +1 -0
- package/.turbo/cache/f2db5af0c0b4d23f.tar.zst +0 -0
- package/.turbo/cache/f8935ade01a88cd7-meta.json +1 -0
- package/.turbo/cache/f8935ade01a88cd7.tar.zst +0 -0
- package/.turbo/cache/f982b8dd966f823a-meta.json +1 -0
- package/.turbo/cache/f982b8dd966f823a.tar.zst +0 -0
- package/.turbo/cache/f9d4036dd350ba1a-meta.json +1 -0
- package/.turbo/cache/f9d4036dd350ba1a.tar.zst +0 -0
- package/README.md +661 -0
- package/README_ko.md +577 -0
- package/bun.lock +135 -0
- package/package.json +26 -0
- package/packages/agent/.turbo/turbo-build.log +5 -0
- package/packages/agent/.turbo/turbo-typecheck.log +1 -0
- package/packages/agent/dist/connection/hub-client.d.ts +33 -0
- package/packages/agent/dist/connection/hub-client.d.ts.map +1 -0
- package/packages/agent/dist/connection/index.d.ts +2 -0
- package/packages/agent/dist/connection/index.d.ts.map +1 -0
- package/packages/agent/dist/hooks/index.d.ts +3 -0
- package/packages/agent/dist/hooks/index.d.ts.map +1 -0
- package/packages/agent/dist/hooks/intent-hub-hooks.d.ts +47 -0
- package/packages/agent/dist/hooks/intent-hub-hooks.d.ts.map +1 -0
- package/packages/agent/dist/index.d.ts +6 -0
- package/packages/agent/dist/index.d.ts.map +1 -0
- package/packages/agent/dist/index.js +3315 -0
- package/packages/agent/dist/plugin/index.d.ts +3 -0
- package/packages/agent/dist/plugin/index.d.ts.map +1 -0
- package/packages/agent/dist/plugin/intent-hub-plugin.d.ts +54 -0
- package/packages/agent/dist/plugin/intent-hub-plugin.d.ts.map +1 -0
- package/packages/agent/package.json +32 -0
- package/packages/agent/src/connection/hub-client.ts +152 -0
- package/packages/agent/src/connection/index.ts +1 -0
- package/packages/agent/src/hooks/index.ts +2 -0
- package/packages/agent/src/hooks/intent-hub-hooks.ts +245 -0
- package/packages/agent/src/index.ts +5 -0
- package/packages/agent/src/plugin/index.ts +2 -0
- package/packages/agent/src/plugin/intent-hub-plugin.ts +153 -0
- package/packages/agent/tsconfig.json +9 -0
- package/packages/hub/.turbo/turbo-build.log +6 -0
- package/packages/hub/.turbo/turbo-typecheck.log +1 -0
- package/packages/hub/dist/api/dashboard.d.ts +17 -0
- package/packages/hub/dist/api/dashboard.d.ts.map +1 -0
- package/packages/hub/dist/cli.d.ts +3 -0
- package/packages/hub/dist/cli.d.ts.map +1 -0
- package/packages/hub/dist/cli.js +7719 -0
- package/packages/hub/dist/core/conflict-detector.d.ts +36 -0
- package/packages/hub/dist/core/conflict-detector.d.ts.map +1 -0
- package/packages/hub/dist/core/index.d.ts +7 -0
- package/packages/hub/dist/core/index.d.ts.map +1 -0
- package/packages/hub/dist/core/intent-analyzer.d.ts +8 -0
- package/packages/hub/dist/core/intent-analyzer.d.ts.map +1 -0
- package/packages/hub/dist/core/lock-manager.d.ts +13 -0
- package/packages/hub/dist/core/lock-manager.d.ts.map +1 -0
- package/packages/hub/dist/core/orchestrator.d.ts +46 -0
- package/packages/hub/dist/core/orchestrator.d.ts.map +1 -0
- package/packages/hub/dist/index.d.ts +9 -0
- package/packages/hub/dist/index.d.ts.map +1 -0
- package/packages/hub/dist/index.js +4686 -0
- package/packages/hub/dist/llm/index.d.ts +7 -0
- package/packages/hub/dist/llm/index.d.ts.map +1 -0
- package/packages/hub/dist/llm/negotiation-engine.d.ts +40 -0
- package/packages/hub/dist/llm/negotiation-engine.d.ts.map +1 -0
- package/packages/hub/dist/llm/provider.d.ts +46 -0
- package/packages/hub/dist/llm/provider.d.ts.map +1 -0
- package/packages/hub/dist/llm/smart-analyzer.d.ts +20 -0
- package/packages/hub/dist/llm/smart-analyzer.d.ts.map +1 -0
- package/packages/hub/dist/server/hub-server.d.ts +35 -0
- package/packages/hub/dist/server/hub-server.d.ts.map +1 -0
- package/packages/hub/dist/server/index.d.ts +5 -0
- package/packages/hub/dist/server/index.d.ts.map +1 -0
- package/packages/hub/dist/server/message-handler.d.ts +18 -0
- package/packages/hub/dist/server/message-handler.d.ts.map +1 -0
- package/packages/hub/dist/server/smart-hub-server.d.ts +43 -0
- package/packages/hub/dist/server/smart-hub-server.d.ts.map +1 -0
- package/packages/hub/dist/state/index.d.ts +2 -0
- package/packages/hub/dist/state/index.d.ts.map +1 -0
- package/packages/hub/dist/state/session-manager.d.ts +19 -0
- package/packages/hub/dist/state/session-manager.d.ts.map +1 -0
- package/packages/hub/dist/tunnel/index.d.ts +14 -0
- package/packages/hub/dist/tunnel/index.d.ts.map +1 -0
- package/packages/hub/package.json +54 -0
- package/packages/hub/src/api/dashboard.ts +261 -0
- package/packages/hub/src/cli.ts +193 -0
- package/packages/hub/src/core/conflict-detector.ts +138 -0
- package/packages/hub/src/core/index.ts +6 -0
- package/packages/hub/src/core/intent-analyzer.ts +112 -0
- package/packages/hub/src/core/lock-manager.ts +95 -0
- package/packages/hub/src/core/orchestrator.ts +255 -0
- package/packages/hub/src/index.ts +8 -0
- package/packages/hub/src/llm/index.ts +17 -0
- package/packages/hub/src/llm/negotiation-engine.ts +297 -0
- package/packages/hub/src/llm/provider.ts +175 -0
- package/packages/hub/src/llm/smart-analyzer.ts +169 -0
- package/packages/hub/src/server/hub-server.ts +219 -0
- package/packages/hub/src/server/index.ts +4 -0
- package/packages/hub/src/server/message-handler.ts +111 -0
- package/packages/hub/src/server/smart-hub-server.ts +374 -0
- package/packages/hub/src/state/index.ts +1 -0
- package/packages/hub/src/state/session-manager.ts +59 -0
- package/packages/hub/src/tunnel/index.ts +153 -0
- package/packages/hub/tsconfig.json +9 -0
- package/packages/shared/.turbo/turbo-build.log +5 -0
- package/packages/shared/.turbo/turbo-typecheck.log +1 -0
- package/packages/shared/dist/index.d.ts +3 -0
- package/packages/shared/dist/index.d.ts.map +1 -0
- package/packages/shared/dist/index.js +50 -0
- package/packages/shared/dist/types/domain.d.ts +50 -0
- package/packages/shared/dist/types/domain.d.ts.map +1 -0
- package/packages/shared/dist/types/index.d.ts +4 -0
- package/packages/shared/dist/types/index.d.ts.map +1 -0
- package/packages/shared/dist/types/intent.d.ts +24 -0
- package/packages/shared/dist/types/intent.d.ts.map +1 -0
- package/packages/shared/dist/types/message.d.ts +151 -0
- package/packages/shared/dist/types/message.d.ts.map +1 -0
- package/packages/shared/dist/utils/id.d.ts +6 -0
- package/packages/shared/dist/utils/id.d.ts.map +1 -0
- package/packages/shared/dist/utils/index.d.ts +3 -0
- package/packages/shared/dist/utils/index.d.ts.map +1 -0
- package/packages/shared/dist/utils/message.d.ts +5 -0
- package/packages/shared/dist/utils/message.d.ts.map +1 -0
- package/packages/shared/package.json +33 -0
- package/packages/shared/src/index.ts +2 -0
- package/packages/shared/src/types/domain.ts +57 -0
- package/packages/shared/src/types/index.ts +3 -0
- package/packages/shared/src/types/intent.ts +34 -0
- package/packages/shared/src/types/message.ts +188 -0
- package/packages/shared/src/utils/id.ts +21 -0
- package/packages/shared/src/utils/index.ts +2 -0
- package/packages/shared/src/utils/message.ts +30 -0
- package/packages/shared/tsconfig.json +9 -0
- package/scripts/test-e2e.ts +194 -0
- package/scripts/test-mvp2.ts +167 -0
- package/scripts/test-mvp3.ts +405 -0
- package/tsconfig.json +19 -0
- package/turbo.json +22 -0
|
@@ -0,0 +1,4686 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __toESM = (mod, isNodeMode, target) => {
|
|
8
|
+
target = mod != null ? __create(__getProtoOf(mod)) : {};
|
|
9
|
+
const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
|
|
10
|
+
for (let key of __getOwnPropNames(mod))
|
|
11
|
+
if (!__hasOwnProp.call(to, key))
|
|
12
|
+
__defProp(to, key, {
|
|
13
|
+
get: () => mod[key],
|
|
14
|
+
enumerable: true
|
|
15
|
+
});
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __commonJS = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
|
|
19
|
+
var __require = /* @__PURE__ */ createRequire(import.meta.url);
|
|
20
|
+
|
|
21
|
+
// ../../node_modules/.bun/ws@8.19.0/node_modules/ws/lib/constants.js
|
|
22
|
+
var require_constants = __commonJS((exports, module) => {
|
|
23
|
+
var BINARY_TYPES = ["nodebuffer", "arraybuffer", "fragments"];
|
|
24
|
+
var hasBlob = typeof Blob !== "undefined";
|
|
25
|
+
if (hasBlob)
|
|
26
|
+
BINARY_TYPES.push("blob");
|
|
27
|
+
module.exports = {
|
|
28
|
+
BINARY_TYPES,
|
|
29
|
+
CLOSE_TIMEOUT: 30000,
|
|
30
|
+
EMPTY_BUFFER: Buffer.alloc(0),
|
|
31
|
+
GUID: "258EAFA5-E914-47DA-95CA-C5AB0DC85B11",
|
|
32
|
+
hasBlob,
|
|
33
|
+
kForOnEventAttribute: Symbol("kIsForOnEventAttribute"),
|
|
34
|
+
kListener: Symbol("kListener"),
|
|
35
|
+
kStatusCode: Symbol("status-code"),
|
|
36
|
+
kWebSocket: Symbol("websocket"),
|
|
37
|
+
NOOP: () => {}
|
|
38
|
+
};
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
// ../../node_modules/.bun/ws@8.19.0/node_modules/ws/lib/buffer-util.js
|
|
42
|
+
var require_buffer_util = __commonJS((exports, module) => {
|
|
43
|
+
var { EMPTY_BUFFER } = require_constants();
|
|
44
|
+
var FastBuffer = Buffer[Symbol.species];
|
|
45
|
+
function concat(list, totalLength) {
|
|
46
|
+
if (list.length === 0)
|
|
47
|
+
return EMPTY_BUFFER;
|
|
48
|
+
if (list.length === 1)
|
|
49
|
+
return list[0];
|
|
50
|
+
const target = Buffer.allocUnsafe(totalLength);
|
|
51
|
+
let offset = 0;
|
|
52
|
+
for (let i = 0;i < list.length; i++) {
|
|
53
|
+
const buf = list[i];
|
|
54
|
+
target.set(buf, offset);
|
|
55
|
+
offset += buf.length;
|
|
56
|
+
}
|
|
57
|
+
if (offset < totalLength) {
|
|
58
|
+
return new FastBuffer(target.buffer, target.byteOffset, offset);
|
|
59
|
+
}
|
|
60
|
+
return target;
|
|
61
|
+
}
|
|
62
|
+
function _mask(source, mask, output, offset, length) {
|
|
63
|
+
for (let i = 0;i < length; i++) {
|
|
64
|
+
output[offset + i] = source[i] ^ mask[i & 3];
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
function _unmask(buffer, mask) {
|
|
68
|
+
for (let i = 0;i < buffer.length; i++) {
|
|
69
|
+
buffer[i] ^= mask[i & 3];
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
function toArrayBuffer(buf) {
|
|
73
|
+
if (buf.length === buf.buffer.byteLength) {
|
|
74
|
+
return buf.buffer;
|
|
75
|
+
}
|
|
76
|
+
return buf.buffer.slice(buf.byteOffset, buf.byteOffset + buf.length);
|
|
77
|
+
}
|
|
78
|
+
function toBuffer(data) {
|
|
79
|
+
toBuffer.readOnly = true;
|
|
80
|
+
if (Buffer.isBuffer(data))
|
|
81
|
+
return data;
|
|
82
|
+
let buf;
|
|
83
|
+
if (data instanceof ArrayBuffer) {
|
|
84
|
+
buf = new FastBuffer(data);
|
|
85
|
+
} else if (ArrayBuffer.isView(data)) {
|
|
86
|
+
buf = new FastBuffer(data.buffer, data.byteOffset, data.byteLength);
|
|
87
|
+
} else {
|
|
88
|
+
buf = Buffer.from(data);
|
|
89
|
+
toBuffer.readOnly = false;
|
|
90
|
+
}
|
|
91
|
+
return buf;
|
|
92
|
+
}
|
|
93
|
+
module.exports = {
|
|
94
|
+
concat,
|
|
95
|
+
mask: _mask,
|
|
96
|
+
toArrayBuffer,
|
|
97
|
+
toBuffer,
|
|
98
|
+
unmask: _unmask
|
|
99
|
+
};
|
|
100
|
+
if (!process.env.WS_NO_BUFFER_UTIL) {
|
|
101
|
+
try {
|
|
102
|
+
const bufferUtil = (()=>{throw new Error("Cannot require module "+"bufferutil");})();
|
|
103
|
+
module.exports.mask = function(source, mask, output, offset, length) {
|
|
104
|
+
if (length < 48)
|
|
105
|
+
_mask(source, mask, output, offset, length);
|
|
106
|
+
else
|
|
107
|
+
bufferUtil.mask(source, mask, output, offset, length);
|
|
108
|
+
};
|
|
109
|
+
module.exports.unmask = function(buffer, mask) {
|
|
110
|
+
if (buffer.length < 32)
|
|
111
|
+
_unmask(buffer, mask);
|
|
112
|
+
else
|
|
113
|
+
bufferUtil.unmask(buffer, mask);
|
|
114
|
+
};
|
|
115
|
+
} catch (e) {}
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
// ../../node_modules/.bun/ws@8.19.0/node_modules/ws/lib/limiter.js
|
|
120
|
+
var require_limiter = __commonJS((exports, module) => {
|
|
121
|
+
var kDone = Symbol("kDone");
|
|
122
|
+
var kRun = Symbol("kRun");
|
|
123
|
+
|
|
124
|
+
class Limiter {
|
|
125
|
+
constructor(concurrency) {
|
|
126
|
+
this[kDone] = () => {
|
|
127
|
+
this.pending--;
|
|
128
|
+
this[kRun]();
|
|
129
|
+
};
|
|
130
|
+
this.concurrency = concurrency || Infinity;
|
|
131
|
+
this.jobs = [];
|
|
132
|
+
this.pending = 0;
|
|
133
|
+
}
|
|
134
|
+
add(job) {
|
|
135
|
+
this.jobs.push(job);
|
|
136
|
+
this[kRun]();
|
|
137
|
+
}
|
|
138
|
+
[kRun]() {
|
|
139
|
+
if (this.pending === this.concurrency)
|
|
140
|
+
return;
|
|
141
|
+
if (this.jobs.length) {
|
|
142
|
+
const job = this.jobs.shift();
|
|
143
|
+
this.pending++;
|
|
144
|
+
job(this[kDone]);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
module.exports = Limiter;
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
// ../../node_modules/.bun/ws@8.19.0/node_modules/ws/lib/permessage-deflate.js
|
|
152
|
+
var require_permessage_deflate = __commonJS((exports, module) => {
|
|
153
|
+
var zlib = __require("zlib");
|
|
154
|
+
var bufferUtil = require_buffer_util();
|
|
155
|
+
var Limiter = require_limiter();
|
|
156
|
+
var { kStatusCode } = require_constants();
|
|
157
|
+
var FastBuffer = Buffer[Symbol.species];
|
|
158
|
+
var TRAILER = Buffer.from([0, 0, 255, 255]);
|
|
159
|
+
var kPerMessageDeflate = Symbol("permessage-deflate");
|
|
160
|
+
var kTotalLength = Symbol("total-length");
|
|
161
|
+
var kCallback = Symbol("callback");
|
|
162
|
+
var kBuffers = Symbol("buffers");
|
|
163
|
+
var kError = Symbol("error");
|
|
164
|
+
var zlibLimiter;
|
|
165
|
+
|
|
166
|
+
class PerMessageDeflate {
|
|
167
|
+
constructor(options, isServer, maxPayload) {
|
|
168
|
+
this._maxPayload = maxPayload | 0;
|
|
169
|
+
this._options = options || {};
|
|
170
|
+
this._threshold = this._options.threshold !== undefined ? this._options.threshold : 1024;
|
|
171
|
+
this._isServer = !!isServer;
|
|
172
|
+
this._deflate = null;
|
|
173
|
+
this._inflate = null;
|
|
174
|
+
this.params = null;
|
|
175
|
+
if (!zlibLimiter) {
|
|
176
|
+
const concurrency = this._options.concurrencyLimit !== undefined ? this._options.concurrencyLimit : 10;
|
|
177
|
+
zlibLimiter = new Limiter(concurrency);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
static get extensionName() {
|
|
181
|
+
return "permessage-deflate";
|
|
182
|
+
}
|
|
183
|
+
offer() {
|
|
184
|
+
const params = {};
|
|
185
|
+
if (this._options.serverNoContextTakeover) {
|
|
186
|
+
params.server_no_context_takeover = true;
|
|
187
|
+
}
|
|
188
|
+
if (this._options.clientNoContextTakeover) {
|
|
189
|
+
params.client_no_context_takeover = true;
|
|
190
|
+
}
|
|
191
|
+
if (this._options.serverMaxWindowBits) {
|
|
192
|
+
params.server_max_window_bits = this._options.serverMaxWindowBits;
|
|
193
|
+
}
|
|
194
|
+
if (this._options.clientMaxWindowBits) {
|
|
195
|
+
params.client_max_window_bits = this._options.clientMaxWindowBits;
|
|
196
|
+
} else if (this._options.clientMaxWindowBits == null) {
|
|
197
|
+
params.client_max_window_bits = true;
|
|
198
|
+
}
|
|
199
|
+
return params;
|
|
200
|
+
}
|
|
201
|
+
accept(configurations) {
|
|
202
|
+
configurations = this.normalizeParams(configurations);
|
|
203
|
+
this.params = this._isServer ? this.acceptAsServer(configurations) : this.acceptAsClient(configurations);
|
|
204
|
+
return this.params;
|
|
205
|
+
}
|
|
206
|
+
cleanup() {
|
|
207
|
+
if (this._inflate) {
|
|
208
|
+
this._inflate.close();
|
|
209
|
+
this._inflate = null;
|
|
210
|
+
}
|
|
211
|
+
if (this._deflate) {
|
|
212
|
+
const callback = this._deflate[kCallback];
|
|
213
|
+
this._deflate.close();
|
|
214
|
+
this._deflate = null;
|
|
215
|
+
if (callback) {
|
|
216
|
+
callback(new Error("The deflate stream was closed while data was being processed"));
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
acceptAsServer(offers) {
|
|
221
|
+
const opts = this._options;
|
|
222
|
+
const accepted = offers.find((params) => {
|
|
223
|
+
if (opts.serverNoContextTakeover === false && params.server_no_context_takeover || params.server_max_window_bits && (opts.serverMaxWindowBits === false || typeof opts.serverMaxWindowBits === "number" && opts.serverMaxWindowBits > params.server_max_window_bits) || typeof opts.clientMaxWindowBits === "number" && !params.client_max_window_bits) {
|
|
224
|
+
return false;
|
|
225
|
+
}
|
|
226
|
+
return true;
|
|
227
|
+
});
|
|
228
|
+
if (!accepted) {
|
|
229
|
+
throw new Error("None of the extension offers can be accepted");
|
|
230
|
+
}
|
|
231
|
+
if (opts.serverNoContextTakeover) {
|
|
232
|
+
accepted.server_no_context_takeover = true;
|
|
233
|
+
}
|
|
234
|
+
if (opts.clientNoContextTakeover) {
|
|
235
|
+
accepted.client_no_context_takeover = true;
|
|
236
|
+
}
|
|
237
|
+
if (typeof opts.serverMaxWindowBits === "number") {
|
|
238
|
+
accepted.server_max_window_bits = opts.serverMaxWindowBits;
|
|
239
|
+
}
|
|
240
|
+
if (typeof opts.clientMaxWindowBits === "number") {
|
|
241
|
+
accepted.client_max_window_bits = opts.clientMaxWindowBits;
|
|
242
|
+
} else if (accepted.client_max_window_bits === true || opts.clientMaxWindowBits === false) {
|
|
243
|
+
delete accepted.client_max_window_bits;
|
|
244
|
+
}
|
|
245
|
+
return accepted;
|
|
246
|
+
}
|
|
247
|
+
acceptAsClient(response) {
|
|
248
|
+
const params = response[0];
|
|
249
|
+
if (this._options.clientNoContextTakeover === false && params.client_no_context_takeover) {
|
|
250
|
+
throw new Error('Unexpected parameter "client_no_context_takeover"');
|
|
251
|
+
}
|
|
252
|
+
if (!params.client_max_window_bits) {
|
|
253
|
+
if (typeof this._options.clientMaxWindowBits === "number") {
|
|
254
|
+
params.client_max_window_bits = this._options.clientMaxWindowBits;
|
|
255
|
+
}
|
|
256
|
+
} else if (this._options.clientMaxWindowBits === false || typeof this._options.clientMaxWindowBits === "number" && params.client_max_window_bits > this._options.clientMaxWindowBits) {
|
|
257
|
+
throw new Error('Unexpected or invalid parameter "client_max_window_bits"');
|
|
258
|
+
}
|
|
259
|
+
return params;
|
|
260
|
+
}
|
|
261
|
+
normalizeParams(configurations) {
|
|
262
|
+
configurations.forEach((params) => {
|
|
263
|
+
Object.keys(params).forEach((key) => {
|
|
264
|
+
let value = params[key];
|
|
265
|
+
if (value.length > 1) {
|
|
266
|
+
throw new Error(`Parameter "${key}" must have only a single value`);
|
|
267
|
+
}
|
|
268
|
+
value = value[0];
|
|
269
|
+
if (key === "client_max_window_bits") {
|
|
270
|
+
if (value !== true) {
|
|
271
|
+
const num = +value;
|
|
272
|
+
if (!Number.isInteger(num) || num < 8 || num > 15) {
|
|
273
|
+
throw new TypeError(`Invalid value for parameter "${key}": ${value}`);
|
|
274
|
+
}
|
|
275
|
+
value = num;
|
|
276
|
+
} else if (!this._isServer) {
|
|
277
|
+
throw new TypeError(`Invalid value for parameter "${key}": ${value}`);
|
|
278
|
+
}
|
|
279
|
+
} else if (key === "server_max_window_bits") {
|
|
280
|
+
const num = +value;
|
|
281
|
+
if (!Number.isInteger(num) || num < 8 || num > 15) {
|
|
282
|
+
throw new TypeError(`Invalid value for parameter "${key}": ${value}`);
|
|
283
|
+
}
|
|
284
|
+
value = num;
|
|
285
|
+
} else if (key === "client_no_context_takeover" || key === "server_no_context_takeover") {
|
|
286
|
+
if (value !== true) {
|
|
287
|
+
throw new TypeError(`Invalid value for parameter "${key}": ${value}`);
|
|
288
|
+
}
|
|
289
|
+
} else {
|
|
290
|
+
throw new Error(`Unknown parameter "${key}"`);
|
|
291
|
+
}
|
|
292
|
+
params[key] = value;
|
|
293
|
+
});
|
|
294
|
+
});
|
|
295
|
+
return configurations;
|
|
296
|
+
}
|
|
297
|
+
decompress(data, fin, callback) {
|
|
298
|
+
zlibLimiter.add((done) => {
|
|
299
|
+
this._decompress(data, fin, (err, result) => {
|
|
300
|
+
done();
|
|
301
|
+
callback(err, result);
|
|
302
|
+
});
|
|
303
|
+
});
|
|
304
|
+
}
|
|
305
|
+
compress(data, fin, callback) {
|
|
306
|
+
zlibLimiter.add((done) => {
|
|
307
|
+
this._compress(data, fin, (err, result) => {
|
|
308
|
+
done();
|
|
309
|
+
callback(err, result);
|
|
310
|
+
});
|
|
311
|
+
});
|
|
312
|
+
}
|
|
313
|
+
_decompress(data, fin, callback) {
|
|
314
|
+
const endpoint = this._isServer ? "client" : "server";
|
|
315
|
+
if (!this._inflate) {
|
|
316
|
+
const key = `${endpoint}_max_window_bits`;
|
|
317
|
+
const windowBits = typeof this.params[key] !== "number" ? zlib.Z_DEFAULT_WINDOWBITS : this.params[key];
|
|
318
|
+
this._inflate = zlib.createInflateRaw({
|
|
319
|
+
...this._options.zlibInflateOptions,
|
|
320
|
+
windowBits
|
|
321
|
+
});
|
|
322
|
+
this._inflate[kPerMessageDeflate] = this;
|
|
323
|
+
this._inflate[kTotalLength] = 0;
|
|
324
|
+
this._inflate[kBuffers] = [];
|
|
325
|
+
this._inflate.on("error", inflateOnError);
|
|
326
|
+
this._inflate.on("data", inflateOnData);
|
|
327
|
+
}
|
|
328
|
+
this._inflate[kCallback] = callback;
|
|
329
|
+
this._inflate.write(data);
|
|
330
|
+
if (fin)
|
|
331
|
+
this._inflate.write(TRAILER);
|
|
332
|
+
this._inflate.flush(() => {
|
|
333
|
+
const err = this._inflate[kError];
|
|
334
|
+
if (err) {
|
|
335
|
+
this._inflate.close();
|
|
336
|
+
this._inflate = null;
|
|
337
|
+
callback(err);
|
|
338
|
+
return;
|
|
339
|
+
}
|
|
340
|
+
const data2 = bufferUtil.concat(this._inflate[kBuffers], this._inflate[kTotalLength]);
|
|
341
|
+
if (this._inflate._readableState.endEmitted) {
|
|
342
|
+
this._inflate.close();
|
|
343
|
+
this._inflate = null;
|
|
344
|
+
} else {
|
|
345
|
+
this._inflate[kTotalLength] = 0;
|
|
346
|
+
this._inflate[kBuffers] = [];
|
|
347
|
+
if (fin && this.params[`${endpoint}_no_context_takeover`]) {
|
|
348
|
+
this._inflate.reset();
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
callback(null, data2);
|
|
352
|
+
});
|
|
353
|
+
}
|
|
354
|
+
_compress(data, fin, callback) {
|
|
355
|
+
const endpoint = this._isServer ? "server" : "client";
|
|
356
|
+
if (!this._deflate) {
|
|
357
|
+
const key = `${endpoint}_max_window_bits`;
|
|
358
|
+
const windowBits = typeof this.params[key] !== "number" ? zlib.Z_DEFAULT_WINDOWBITS : this.params[key];
|
|
359
|
+
this._deflate = zlib.createDeflateRaw({
|
|
360
|
+
...this._options.zlibDeflateOptions,
|
|
361
|
+
windowBits
|
|
362
|
+
});
|
|
363
|
+
this._deflate[kTotalLength] = 0;
|
|
364
|
+
this._deflate[kBuffers] = [];
|
|
365
|
+
this._deflate.on("data", deflateOnData);
|
|
366
|
+
}
|
|
367
|
+
this._deflate[kCallback] = callback;
|
|
368
|
+
this._deflate.write(data);
|
|
369
|
+
this._deflate.flush(zlib.Z_SYNC_FLUSH, () => {
|
|
370
|
+
if (!this._deflate) {
|
|
371
|
+
return;
|
|
372
|
+
}
|
|
373
|
+
let data2 = bufferUtil.concat(this._deflate[kBuffers], this._deflate[kTotalLength]);
|
|
374
|
+
if (fin) {
|
|
375
|
+
data2 = new FastBuffer(data2.buffer, data2.byteOffset, data2.length - 4);
|
|
376
|
+
}
|
|
377
|
+
this._deflate[kCallback] = null;
|
|
378
|
+
this._deflate[kTotalLength] = 0;
|
|
379
|
+
this._deflate[kBuffers] = [];
|
|
380
|
+
if (fin && this.params[`${endpoint}_no_context_takeover`]) {
|
|
381
|
+
this._deflate.reset();
|
|
382
|
+
}
|
|
383
|
+
callback(null, data2);
|
|
384
|
+
});
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
module.exports = PerMessageDeflate;
|
|
388
|
+
function deflateOnData(chunk) {
|
|
389
|
+
this[kBuffers].push(chunk);
|
|
390
|
+
this[kTotalLength] += chunk.length;
|
|
391
|
+
}
|
|
392
|
+
function inflateOnData(chunk) {
|
|
393
|
+
this[kTotalLength] += chunk.length;
|
|
394
|
+
if (this[kPerMessageDeflate]._maxPayload < 1 || this[kTotalLength] <= this[kPerMessageDeflate]._maxPayload) {
|
|
395
|
+
this[kBuffers].push(chunk);
|
|
396
|
+
return;
|
|
397
|
+
}
|
|
398
|
+
this[kError] = new RangeError("Max payload size exceeded");
|
|
399
|
+
this[kError].code = "WS_ERR_UNSUPPORTED_MESSAGE_LENGTH";
|
|
400
|
+
this[kError][kStatusCode] = 1009;
|
|
401
|
+
this.removeListener("data", inflateOnData);
|
|
402
|
+
this.reset();
|
|
403
|
+
}
|
|
404
|
+
function inflateOnError(err) {
|
|
405
|
+
this[kPerMessageDeflate]._inflate = null;
|
|
406
|
+
if (this[kError]) {
|
|
407
|
+
this[kCallback](this[kError]);
|
|
408
|
+
return;
|
|
409
|
+
}
|
|
410
|
+
err[kStatusCode] = 1007;
|
|
411
|
+
this[kCallback](err);
|
|
412
|
+
}
|
|
413
|
+
});
|
|
414
|
+
|
|
415
|
+
// ../../node_modules/.bun/ws@8.19.0/node_modules/ws/lib/validation.js
|
|
416
|
+
var require_validation = __commonJS((exports, module) => {
|
|
417
|
+
var { isUtf8 } = __require("buffer");
|
|
418
|
+
var { hasBlob } = require_constants();
|
|
419
|
+
var tokenChars = [
|
|
420
|
+
0,
|
|
421
|
+
0,
|
|
422
|
+
0,
|
|
423
|
+
0,
|
|
424
|
+
0,
|
|
425
|
+
0,
|
|
426
|
+
0,
|
|
427
|
+
0,
|
|
428
|
+
0,
|
|
429
|
+
0,
|
|
430
|
+
0,
|
|
431
|
+
0,
|
|
432
|
+
0,
|
|
433
|
+
0,
|
|
434
|
+
0,
|
|
435
|
+
0,
|
|
436
|
+
0,
|
|
437
|
+
0,
|
|
438
|
+
0,
|
|
439
|
+
0,
|
|
440
|
+
0,
|
|
441
|
+
0,
|
|
442
|
+
0,
|
|
443
|
+
0,
|
|
444
|
+
0,
|
|
445
|
+
0,
|
|
446
|
+
0,
|
|
447
|
+
0,
|
|
448
|
+
0,
|
|
449
|
+
0,
|
|
450
|
+
0,
|
|
451
|
+
0,
|
|
452
|
+
0,
|
|
453
|
+
1,
|
|
454
|
+
0,
|
|
455
|
+
1,
|
|
456
|
+
1,
|
|
457
|
+
1,
|
|
458
|
+
1,
|
|
459
|
+
1,
|
|
460
|
+
0,
|
|
461
|
+
0,
|
|
462
|
+
1,
|
|
463
|
+
1,
|
|
464
|
+
0,
|
|
465
|
+
1,
|
|
466
|
+
1,
|
|
467
|
+
0,
|
|
468
|
+
1,
|
|
469
|
+
1,
|
|
470
|
+
1,
|
|
471
|
+
1,
|
|
472
|
+
1,
|
|
473
|
+
1,
|
|
474
|
+
1,
|
|
475
|
+
1,
|
|
476
|
+
1,
|
|
477
|
+
1,
|
|
478
|
+
0,
|
|
479
|
+
0,
|
|
480
|
+
0,
|
|
481
|
+
0,
|
|
482
|
+
0,
|
|
483
|
+
0,
|
|
484
|
+
0,
|
|
485
|
+
1,
|
|
486
|
+
1,
|
|
487
|
+
1,
|
|
488
|
+
1,
|
|
489
|
+
1,
|
|
490
|
+
1,
|
|
491
|
+
1,
|
|
492
|
+
1,
|
|
493
|
+
1,
|
|
494
|
+
1,
|
|
495
|
+
1,
|
|
496
|
+
1,
|
|
497
|
+
1,
|
|
498
|
+
1,
|
|
499
|
+
1,
|
|
500
|
+
1,
|
|
501
|
+
1,
|
|
502
|
+
1,
|
|
503
|
+
1,
|
|
504
|
+
1,
|
|
505
|
+
1,
|
|
506
|
+
1,
|
|
507
|
+
1,
|
|
508
|
+
1,
|
|
509
|
+
1,
|
|
510
|
+
1,
|
|
511
|
+
0,
|
|
512
|
+
0,
|
|
513
|
+
0,
|
|
514
|
+
1,
|
|
515
|
+
1,
|
|
516
|
+
1,
|
|
517
|
+
1,
|
|
518
|
+
1,
|
|
519
|
+
1,
|
|
520
|
+
1,
|
|
521
|
+
1,
|
|
522
|
+
1,
|
|
523
|
+
1,
|
|
524
|
+
1,
|
|
525
|
+
1,
|
|
526
|
+
1,
|
|
527
|
+
1,
|
|
528
|
+
1,
|
|
529
|
+
1,
|
|
530
|
+
1,
|
|
531
|
+
1,
|
|
532
|
+
1,
|
|
533
|
+
1,
|
|
534
|
+
1,
|
|
535
|
+
1,
|
|
536
|
+
1,
|
|
537
|
+
1,
|
|
538
|
+
1,
|
|
539
|
+
1,
|
|
540
|
+
1,
|
|
541
|
+
1,
|
|
542
|
+
1,
|
|
543
|
+
0,
|
|
544
|
+
1,
|
|
545
|
+
0,
|
|
546
|
+
1,
|
|
547
|
+
0
|
|
548
|
+
];
|
|
549
|
+
function isValidStatusCode(code) {
|
|
550
|
+
return code >= 1000 && code <= 1014 && code !== 1004 && code !== 1005 && code !== 1006 || code >= 3000 && code <= 4999;
|
|
551
|
+
}
|
|
552
|
+
function _isValidUTF8(buf) {
|
|
553
|
+
const len = buf.length;
|
|
554
|
+
let i = 0;
|
|
555
|
+
while (i < len) {
|
|
556
|
+
if ((buf[i] & 128) === 0) {
|
|
557
|
+
i++;
|
|
558
|
+
} else if ((buf[i] & 224) === 192) {
|
|
559
|
+
if (i + 1 === len || (buf[i + 1] & 192) !== 128 || (buf[i] & 254) === 192) {
|
|
560
|
+
return false;
|
|
561
|
+
}
|
|
562
|
+
i += 2;
|
|
563
|
+
} else if ((buf[i] & 240) === 224) {
|
|
564
|
+
if (i + 2 >= len || (buf[i + 1] & 192) !== 128 || (buf[i + 2] & 192) !== 128 || buf[i] === 224 && (buf[i + 1] & 224) === 128 || buf[i] === 237 && (buf[i + 1] & 224) === 160) {
|
|
565
|
+
return false;
|
|
566
|
+
}
|
|
567
|
+
i += 3;
|
|
568
|
+
} else if ((buf[i] & 248) === 240) {
|
|
569
|
+
if (i + 3 >= len || (buf[i + 1] & 192) !== 128 || (buf[i + 2] & 192) !== 128 || (buf[i + 3] & 192) !== 128 || buf[i] === 240 && (buf[i + 1] & 240) === 128 || buf[i] === 244 && buf[i + 1] > 143 || buf[i] > 244) {
|
|
570
|
+
return false;
|
|
571
|
+
}
|
|
572
|
+
i += 4;
|
|
573
|
+
} else {
|
|
574
|
+
return false;
|
|
575
|
+
}
|
|
576
|
+
}
|
|
577
|
+
return true;
|
|
578
|
+
}
|
|
579
|
+
function isBlob(value) {
|
|
580
|
+
return hasBlob && typeof value === "object" && typeof value.arrayBuffer === "function" && typeof value.type === "string" && typeof value.stream === "function" && (value[Symbol.toStringTag] === "Blob" || value[Symbol.toStringTag] === "File");
|
|
581
|
+
}
|
|
582
|
+
module.exports = {
|
|
583
|
+
isBlob,
|
|
584
|
+
isValidStatusCode,
|
|
585
|
+
isValidUTF8: _isValidUTF8,
|
|
586
|
+
tokenChars
|
|
587
|
+
};
|
|
588
|
+
if (isUtf8) {
|
|
589
|
+
module.exports.isValidUTF8 = function(buf) {
|
|
590
|
+
return buf.length < 24 ? _isValidUTF8(buf) : isUtf8(buf);
|
|
591
|
+
};
|
|
592
|
+
} else if (!process.env.WS_NO_UTF_8_VALIDATE) {
|
|
593
|
+
try {
|
|
594
|
+
const isValidUTF8 = (()=>{throw new Error("Cannot require module "+"utf-8-validate");})();
|
|
595
|
+
module.exports.isValidUTF8 = function(buf) {
|
|
596
|
+
return buf.length < 32 ? _isValidUTF8(buf) : isValidUTF8(buf);
|
|
597
|
+
};
|
|
598
|
+
} catch (e) {}
|
|
599
|
+
}
|
|
600
|
+
});
|
|
601
|
+
|
|
602
|
+
// ../../node_modules/.bun/ws@8.19.0/node_modules/ws/lib/receiver.js
|
|
603
|
+
var require_receiver = __commonJS((exports, module) => {
|
|
604
|
+
var { Writable } = __require("stream");
|
|
605
|
+
var PerMessageDeflate = require_permessage_deflate();
|
|
606
|
+
var {
|
|
607
|
+
BINARY_TYPES,
|
|
608
|
+
EMPTY_BUFFER,
|
|
609
|
+
kStatusCode,
|
|
610
|
+
kWebSocket
|
|
611
|
+
} = require_constants();
|
|
612
|
+
var { concat, toArrayBuffer, unmask } = require_buffer_util();
|
|
613
|
+
var { isValidStatusCode, isValidUTF8 } = require_validation();
|
|
614
|
+
var FastBuffer = Buffer[Symbol.species];
|
|
615
|
+
var GET_INFO = 0;
|
|
616
|
+
var GET_PAYLOAD_LENGTH_16 = 1;
|
|
617
|
+
var GET_PAYLOAD_LENGTH_64 = 2;
|
|
618
|
+
var GET_MASK = 3;
|
|
619
|
+
var GET_DATA = 4;
|
|
620
|
+
var INFLATING = 5;
|
|
621
|
+
var DEFER_EVENT = 6;
|
|
622
|
+
|
|
623
|
+
class Receiver extends Writable {
|
|
624
|
+
constructor(options = {}) {
|
|
625
|
+
super();
|
|
626
|
+
this._allowSynchronousEvents = options.allowSynchronousEvents !== undefined ? options.allowSynchronousEvents : true;
|
|
627
|
+
this._binaryType = options.binaryType || BINARY_TYPES[0];
|
|
628
|
+
this._extensions = options.extensions || {};
|
|
629
|
+
this._isServer = !!options.isServer;
|
|
630
|
+
this._maxPayload = options.maxPayload | 0;
|
|
631
|
+
this._skipUTF8Validation = !!options.skipUTF8Validation;
|
|
632
|
+
this[kWebSocket] = undefined;
|
|
633
|
+
this._bufferedBytes = 0;
|
|
634
|
+
this._buffers = [];
|
|
635
|
+
this._compressed = false;
|
|
636
|
+
this._payloadLength = 0;
|
|
637
|
+
this._mask = undefined;
|
|
638
|
+
this._fragmented = 0;
|
|
639
|
+
this._masked = false;
|
|
640
|
+
this._fin = false;
|
|
641
|
+
this._opcode = 0;
|
|
642
|
+
this._totalPayloadLength = 0;
|
|
643
|
+
this._messageLength = 0;
|
|
644
|
+
this._fragments = [];
|
|
645
|
+
this._errored = false;
|
|
646
|
+
this._loop = false;
|
|
647
|
+
this._state = GET_INFO;
|
|
648
|
+
}
|
|
649
|
+
_write(chunk, encoding, cb) {
|
|
650
|
+
if (this._opcode === 8 && this._state == GET_INFO)
|
|
651
|
+
return cb();
|
|
652
|
+
this._bufferedBytes += chunk.length;
|
|
653
|
+
this._buffers.push(chunk);
|
|
654
|
+
this.startLoop(cb);
|
|
655
|
+
}
|
|
656
|
+
consume(n) {
|
|
657
|
+
this._bufferedBytes -= n;
|
|
658
|
+
if (n === this._buffers[0].length)
|
|
659
|
+
return this._buffers.shift();
|
|
660
|
+
if (n < this._buffers[0].length) {
|
|
661
|
+
const buf = this._buffers[0];
|
|
662
|
+
this._buffers[0] = new FastBuffer(buf.buffer, buf.byteOffset + n, buf.length - n);
|
|
663
|
+
return new FastBuffer(buf.buffer, buf.byteOffset, n);
|
|
664
|
+
}
|
|
665
|
+
const dst = Buffer.allocUnsafe(n);
|
|
666
|
+
do {
|
|
667
|
+
const buf = this._buffers[0];
|
|
668
|
+
const offset = dst.length - n;
|
|
669
|
+
if (n >= buf.length) {
|
|
670
|
+
dst.set(this._buffers.shift(), offset);
|
|
671
|
+
} else {
|
|
672
|
+
dst.set(new Uint8Array(buf.buffer, buf.byteOffset, n), offset);
|
|
673
|
+
this._buffers[0] = new FastBuffer(buf.buffer, buf.byteOffset + n, buf.length - n);
|
|
674
|
+
}
|
|
675
|
+
n -= buf.length;
|
|
676
|
+
} while (n > 0);
|
|
677
|
+
return dst;
|
|
678
|
+
}
|
|
679
|
+
startLoop(cb) {
|
|
680
|
+
this._loop = true;
|
|
681
|
+
do {
|
|
682
|
+
switch (this._state) {
|
|
683
|
+
case GET_INFO:
|
|
684
|
+
this.getInfo(cb);
|
|
685
|
+
break;
|
|
686
|
+
case GET_PAYLOAD_LENGTH_16:
|
|
687
|
+
this.getPayloadLength16(cb);
|
|
688
|
+
break;
|
|
689
|
+
case GET_PAYLOAD_LENGTH_64:
|
|
690
|
+
this.getPayloadLength64(cb);
|
|
691
|
+
break;
|
|
692
|
+
case GET_MASK:
|
|
693
|
+
this.getMask();
|
|
694
|
+
break;
|
|
695
|
+
case GET_DATA:
|
|
696
|
+
this.getData(cb);
|
|
697
|
+
break;
|
|
698
|
+
case INFLATING:
|
|
699
|
+
case DEFER_EVENT:
|
|
700
|
+
this._loop = false;
|
|
701
|
+
return;
|
|
702
|
+
}
|
|
703
|
+
} while (this._loop);
|
|
704
|
+
if (!this._errored)
|
|
705
|
+
cb();
|
|
706
|
+
}
|
|
707
|
+
getInfo(cb) {
|
|
708
|
+
if (this._bufferedBytes < 2) {
|
|
709
|
+
this._loop = false;
|
|
710
|
+
return;
|
|
711
|
+
}
|
|
712
|
+
const buf = this.consume(2);
|
|
713
|
+
if ((buf[0] & 48) !== 0) {
|
|
714
|
+
const error = this.createError(RangeError, "RSV2 and RSV3 must be clear", true, 1002, "WS_ERR_UNEXPECTED_RSV_2_3");
|
|
715
|
+
cb(error);
|
|
716
|
+
return;
|
|
717
|
+
}
|
|
718
|
+
const compressed = (buf[0] & 64) === 64;
|
|
719
|
+
if (compressed && !this._extensions[PerMessageDeflate.extensionName]) {
|
|
720
|
+
const error = this.createError(RangeError, "RSV1 must be clear", true, 1002, "WS_ERR_UNEXPECTED_RSV_1");
|
|
721
|
+
cb(error);
|
|
722
|
+
return;
|
|
723
|
+
}
|
|
724
|
+
this._fin = (buf[0] & 128) === 128;
|
|
725
|
+
this._opcode = buf[0] & 15;
|
|
726
|
+
this._payloadLength = buf[1] & 127;
|
|
727
|
+
if (this._opcode === 0) {
|
|
728
|
+
if (compressed) {
|
|
729
|
+
const error = this.createError(RangeError, "RSV1 must be clear", true, 1002, "WS_ERR_UNEXPECTED_RSV_1");
|
|
730
|
+
cb(error);
|
|
731
|
+
return;
|
|
732
|
+
}
|
|
733
|
+
if (!this._fragmented) {
|
|
734
|
+
const error = this.createError(RangeError, "invalid opcode 0", true, 1002, "WS_ERR_INVALID_OPCODE");
|
|
735
|
+
cb(error);
|
|
736
|
+
return;
|
|
737
|
+
}
|
|
738
|
+
this._opcode = this._fragmented;
|
|
739
|
+
} else if (this._opcode === 1 || this._opcode === 2) {
|
|
740
|
+
if (this._fragmented) {
|
|
741
|
+
const error = this.createError(RangeError, `invalid opcode ${this._opcode}`, true, 1002, "WS_ERR_INVALID_OPCODE");
|
|
742
|
+
cb(error);
|
|
743
|
+
return;
|
|
744
|
+
}
|
|
745
|
+
this._compressed = compressed;
|
|
746
|
+
} else if (this._opcode > 7 && this._opcode < 11) {
|
|
747
|
+
if (!this._fin) {
|
|
748
|
+
const error = this.createError(RangeError, "FIN must be set", true, 1002, "WS_ERR_EXPECTED_FIN");
|
|
749
|
+
cb(error);
|
|
750
|
+
return;
|
|
751
|
+
}
|
|
752
|
+
if (compressed) {
|
|
753
|
+
const error = this.createError(RangeError, "RSV1 must be clear", true, 1002, "WS_ERR_UNEXPECTED_RSV_1");
|
|
754
|
+
cb(error);
|
|
755
|
+
return;
|
|
756
|
+
}
|
|
757
|
+
if (this._payloadLength > 125 || this._opcode === 8 && this._payloadLength === 1) {
|
|
758
|
+
const error = this.createError(RangeError, `invalid payload length ${this._payloadLength}`, true, 1002, "WS_ERR_INVALID_CONTROL_PAYLOAD_LENGTH");
|
|
759
|
+
cb(error);
|
|
760
|
+
return;
|
|
761
|
+
}
|
|
762
|
+
} else {
|
|
763
|
+
const error = this.createError(RangeError, `invalid opcode ${this._opcode}`, true, 1002, "WS_ERR_INVALID_OPCODE");
|
|
764
|
+
cb(error);
|
|
765
|
+
return;
|
|
766
|
+
}
|
|
767
|
+
if (!this._fin && !this._fragmented)
|
|
768
|
+
this._fragmented = this._opcode;
|
|
769
|
+
this._masked = (buf[1] & 128) === 128;
|
|
770
|
+
if (this._isServer) {
|
|
771
|
+
if (!this._masked) {
|
|
772
|
+
const error = this.createError(RangeError, "MASK must be set", true, 1002, "WS_ERR_EXPECTED_MASK");
|
|
773
|
+
cb(error);
|
|
774
|
+
return;
|
|
775
|
+
}
|
|
776
|
+
} else if (this._masked) {
|
|
777
|
+
const error = this.createError(RangeError, "MASK must be clear", true, 1002, "WS_ERR_UNEXPECTED_MASK");
|
|
778
|
+
cb(error);
|
|
779
|
+
return;
|
|
780
|
+
}
|
|
781
|
+
if (this._payloadLength === 126)
|
|
782
|
+
this._state = GET_PAYLOAD_LENGTH_16;
|
|
783
|
+
else if (this._payloadLength === 127)
|
|
784
|
+
this._state = GET_PAYLOAD_LENGTH_64;
|
|
785
|
+
else
|
|
786
|
+
this.haveLength(cb);
|
|
787
|
+
}
|
|
788
|
+
getPayloadLength16(cb) {
|
|
789
|
+
if (this._bufferedBytes < 2) {
|
|
790
|
+
this._loop = false;
|
|
791
|
+
return;
|
|
792
|
+
}
|
|
793
|
+
this._payloadLength = this.consume(2).readUInt16BE(0);
|
|
794
|
+
this.haveLength(cb);
|
|
795
|
+
}
|
|
796
|
+
getPayloadLength64(cb) {
|
|
797
|
+
if (this._bufferedBytes < 8) {
|
|
798
|
+
this._loop = false;
|
|
799
|
+
return;
|
|
800
|
+
}
|
|
801
|
+
const buf = this.consume(8);
|
|
802
|
+
const num = buf.readUInt32BE(0);
|
|
803
|
+
if (num > Math.pow(2, 53 - 32) - 1) {
|
|
804
|
+
const error = this.createError(RangeError, "Unsupported WebSocket frame: payload length > 2^53 - 1", false, 1009, "WS_ERR_UNSUPPORTED_DATA_PAYLOAD_LENGTH");
|
|
805
|
+
cb(error);
|
|
806
|
+
return;
|
|
807
|
+
}
|
|
808
|
+
this._payloadLength = num * Math.pow(2, 32) + buf.readUInt32BE(4);
|
|
809
|
+
this.haveLength(cb);
|
|
810
|
+
}
|
|
811
|
+
haveLength(cb) {
|
|
812
|
+
if (this._payloadLength && this._opcode < 8) {
|
|
813
|
+
this._totalPayloadLength += this._payloadLength;
|
|
814
|
+
if (this._totalPayloadLength > this._maxPayload && this._maxPayload > 0) {
|
|
815
|
+
const error = this.createError(RangeError, "Max payload size exceeded", false, 1009, "WS_ERR_UNSUPPORTED_MESSAGE_LENGTH");
|
|
816
|
+
cb(error);
|
|
817
|
+
return;
|
|
818
|
+
}
|
|
819
|
+
}
|
|
820
|
+
if (this._masked)
|
|
821
|
+
this._state = GET_MASK;
|
|
822
|
+
else
|
|
823
|
+
this._state = GET_DATA;
|
|
824
|
+
}
|
|
825
|
+
getMask() {
|
|
826
|
+
if (this._bufferedBytes < 4) {
|
|
827
|
+
this._loop = false;
|
|
828
|
+
return;
|
|
829
|
+
}
|
|
830
|
+
this._mask = this.consume(4);
|
|
831
|
+
this._state = GET_DATA;
|
|
832
|
+
}
|
|
833
|
+
getData(cb) {
|
|
834
|
+
let data = EMPTY_BUFFER;
|
|
835
|
+
if (this._payloadLength) {
|
|
836
|
+
if (this._bufferedBytes < this._payloadLength) {
|
|
837
|
+
this._loop = false;
|
|
838
|
+
return;
|
|
839
|
+
}
|
|
840
|
+
data = this.consume(this._payloadLength);
|
|
841
|
+
if (this._masked && (this._mask[0] | this._mask[1] | this._mask[2] | this._mask[3]) !== 0) {
|
|
842
|
+
unmask(data, this._mask);
|
|
843
|
+
}
|
|
844
|
+
}
|
|
845
|
+
if (this._opcode > 7) {
|
|
846
|
+
this.controlMessage(data, cb);
|
|
847
|
+
return;
|
|
848
|
+
}
|
|
849
|
+
if (this._compressed) {
|
|
850
|
+
this._state = INFLATING;
|
|
851
|
+
this.decompress(data, cb);
|
|
852
|
+
return;
|
|
853
|
+
}
|
|
854
|
+
if (data.length) {
|
|
855
|
+
this._messageLength = this._totalPayloadLength;
|
|
856
|
+
this._fragments.push(data);
|
|
857
|
+
}
|
|
858
|
+
this.dataMessage(cb);
|
|
859
|
+
}
|
|
860
|
+
decompress(data, cb) {
|
|
861
|
+
const perMessageDeflate = this._extensions[PerMessageDeflate.extensionName];
|
|
862
|
+
perMessageDeflate.decompress(data, this._fin, (err, buf) => {
|
|
863
|
+
if (err)
|
|
864
|
+
return cb(err);
|
|
865
|
+
if (buf.length) {
|
|
866
|
+
this._messageLength += buf.length;
|
|
867
|
+
if (this._messageLength > this._maxPayload && this._maxPayload > 0) {
|
|
868
|
+
const error = this.createError(RangeError, "Max payload size exceeded", false, 1009, "WS_ERR_UNSUPPORTED_MESSAGE_LENGTH");
|
|
869
|
+
cb(error);
|
|
870
|
+
return;
|
|
871
|
+
}
|
|
872
|
+
this._fragments.push(buf);
|
|
873
|
+
}
|
|
874
|
+
this.dataMessage(cb);
|
|
875
|
+
if (this._state === GET_INFO)
|
|
876
|
+
this.startLoop(cb);
|
|
877
|
+
});
|
|
878
|
+
}
|
|
879
|
+
dataMessage(cb) {
|
|
880
|
+
if (!this._fin) {
|
|
881
|
+
this._state = GET_INFO;
|
|
882
|
+
return;
|
|
883
|
+
}
|
|
884
|
+
const messageLength = this._messageLength;
|
|
885
|
+
const fragments = this._fragments;
|
|
886
|
+
this._totalPayloadLength = 0;
|
|
887
|
+
this._messageLength = 0;
|
|
888
|
+
this._fragmented = 0;
|
|
889
|
+
this._fragments = [];
|
|
890
|
+
if (this._opcode === 2) {
|
|
891
|
+
let data;
|
|
892
|
+
if (this._binaryType === "nodebuffer") {
|
|
893
|
+
data = concat(fragments, messageLength);
|
|
894
|
+
} else if (this._binaryType === "arraybuffer") {
|
|
895
|
+
data = toArrayBuffer(concat(fragments, messageLength));
|
|
896
|
+
} else if (this._binaryType === "blob") {
|
|
897
|
+
data = new Blob(fragments);
|
|
898
|
+
} else {
|
|
899
|
+
data = fragments;
|
|
900
|
+
}
|
|
901
|
+
if (this._allowSynchronousEvents) {
|
|
902
|
+
this.emit("message", data, true);
|
|
903
|
+
this._state = GET_INFO;
|
|
904
|
+
} else {
|
|
905
|
+
this._state = DEFER_EVENT;
|
|
906
|
+
setImmediate(() => {
|
|
907
|
+
this.emit("message", data, true);
|
|
908
|
+
this._state = GET_INFO;
|
|
909
|
+
this.startLoop(cb);
|
|
910
|
+
});
|
|
911
|
+
}
|
|
912
|
+
} else {
|
|
913
|
+
const buf = concat(fragments, messageLength);
|
|
914
|
+
if (!this._skipUTF8Validation && !isValidUTF8(buf)) {
|
|
915
|
+
const error = this.createError(Error, "invalid UTF-8 sequence", true, 1007, "WS_ERR_INVALID_UTF8");
|
|
916
|
+
cb(error);
|
|
917
|
+
return;
|
|
918
|
+
}
|
|
919
|
+
if (this._state === INFLATING || this._allowSynchronousEvents) {
|
|
920
|
+
this.emit("message", buf, false);
|
|
921
|
+
this._state = GET_INFO;
|
|
922
|
+
} else {
|
|
923
|
+
this._state = DEFER_EVENT;
|
|
924
|
+
setImmediate(() => {
|
|
925
|
+
this.emit("message", buf, false);
|
|
926
|
+
this._state = GET_INFO;
|
|
927
|
+
this.startLoop(cb);
|
|
928
|
+
});
|
|
929
|
+
}
|
|
930
|
+
}
|
|
931
|
+
}
|
|
932
|
+
controlMessage(data, cb) {
|
|
933
|
+
if (this._opcode === 8) {
|
|
934
|
+
if (data.length === 0) {
|
|
935
|
+
this._loop = false;
|
|
936
|
+
this.emit("conclude", 1005, EMPTY_BUFFER);
|
|
937
|
+
this.end();
|
|
938
|
+
} else {
|
|
939
|
+
const code = data.readUInt16BE(0);
|
|
940
|
+
if (!isValidStatusCode(code)) {
|
|
941
|
+
const error = this.createError(RangeError, `invalid status code ${code}`, true, 1002, "WS_ERR_INVALID_CLOSE_CODE");
|
|
942
|
+
cb(error);
|
|
943
|
+
return;
|
|
944
|
+
}
|
|
945
|
+
const buf = new FastBuffer(data.buffer, data.byteOffset + 2, data.length - 2);
|
|
946
|
+
if (!this._skipUTF8Validation && !isValidUTF8(buf)) {
|
|
947
|
+
const error = this.createError(Error, "invalid UTF-8 sequence", true, 1007, "WS_ERR_INVALID_UTF8");
|
|
948
|
+
cb(error);
|
|
949
|
+
return;
|
|
950
|
+
}
|
|
951
|
+
this._loop = false;
|
|
952
|
+
this.emit("conclude", code, buf);
|
|
953
|
+
this.end();
|
|
954
|
+
}
|
|
955
|
+
this._state = GET_INFO;
|
|
956
|
+
return;
|
|
957
|
+
}
|
|
958
|
+
if (this._allowSynchronousEvents) {
|
|
959
|
+
this.emit(this._opcode === 9 ? "ping" : "pong", data);
|
|
960
|
+
this._state = GET_INFO;
|
|
961
|
+
} else {
|
|
962
|
+
this._state = DEFER_EVENT;
|
|
963
|
+
setImmediate(() => {
|
|
964
|
+
this.emit(this._opcode === 9 ? "ping" : "pong", data);
|
|
965
|
+
this._state = GET_INFO;
|
|
966
|
+
this.startLoop(cb);
|
|
967
|
+
});
|
|
968
|
+
}
|
|
969
|
+
}
|
|
970
|
+
createError(ErrorCtor, message, prefix, statusCode, errorCode) {
|
|
971
|
+
this._loop = false;
|
|
972
|
+
this._errored = true;
|
|
973
|
+
const err = new ErrorCtor(prefix ? `Invalid WebSocket frame: ${message}` : message);
|
|
974
|
+
Error.captureStackTrace(err, this.createError);
|
|
975
|
+
err.code = errorCode;
|
|
976
|
+
err[kStatusCode] = statusCode;
|
|
977
|
+
return err;
|
|
978
|
+
}
|
|
979
|
+
}
|
|
980
|
+
module.exports = Receiver;
|
|
981
|
+
});
|
|
982
|
+
|
|
983
|
+
// ../../node_modules/.bun/ws@8.19.0/node_modules/ws/lib/sender.js
|
|
984
|
+
var require_sender = __commonJS((exports, module) => {
|
|
985
|
+
var { Duplex } = __require("stream");
|
|
986
|
+
var { randomFillSync } = __require("crypto");
|
|
987
|
+
var PerMessageDeflate = require_permessage_deflate();
|
|
988
|
+
var { EMPTY_BUFFER, kWebSocket, NOOP } = require_constants();
|
|
989
|
+
var { isBlob, isValidStatusCode } = require_validation();
|
|
990
|
+
var { mask: applyMask, toBuffer } = require_buffer_util();
|
|
991
|
+
var kByteLength = Symbol("kByteLength");
|
|
992
|
+
var maskBuffer = Buffer.alloc(4);
|
|
993
|
+
var RANDOM_POOL_SIZE = 8 * 1024;
|
|
994
|
+
var randomPool;
|
|
995
|
+
var randomPoolPointer = RANDOM_POOL_SIZE;
|
|
996
|
+
var DEFAULT = 0;
|
|
997
|
+
var DEFLATING = 1;
|
|
998
|
+
var GET_BLOB_DATA = 2;
|
|
999
|
+
|
|
1000
|
+
class Sender {
|
|
1001
|
+
constructor(socket, extensions, generateMask) {
|
|
1002
|
+
this._extensions = extensions || {};
|
|
1003
|
+
if (generateMask) {
|
|
1004
|
+
this._generateMask = generateMask;
|
|
1005
|
+
this._maskBuffer = Buffer.alloc(4);
|
|
1006
|
+
}
|
|
1007
|
+
this._socket = socket;
|
|
1008
|
+
this._firstFragment = true;
|
|
1009
|
+
this._compress = false;
|
|
1010
|
+
this._bufferedBytes = 0;
|
|
1011
|
+
this._queue = [];
|
|
1012
|
+
this._state = DEFAULT;
|
|
1013
|
+
this.onerror = NOOP;
|
|
1014
|
+
this[kWebSocket] = undefined;
|
|
1015
|
+
}
|
|
1016
|
+
static frame(data, options) {
|
|
1017
|
+
let mask;
|
|
1018
|
+
let merge = false;
|
|
1019
|
+
let offset = 2;
|
|
1020
|
+
let skipMasking = false;
|
|
1021
|
+
if (options.mask) {
|
|
1022
|
+
mask = options.maskBuffer || maskBuffer;
|
|
1023
|
+
if (options.generateMask) {
|
|
1024
|
+
options.generateMask(mask);
|
|
1025
|
+
} else {
|
|
1026
|
+
if (randomPoolPointer === RANDOM_POOL_SIZE) {
|
|
1027
|
+
if (randomPool === undefined) {
|
|
1028
|
+
randomPool = Buffer.alloc(RANDOM_POOL_SIZE);
|
|
1029
|
+
}
|
|
1030
|
+
randomFillSync(randomPool, 0, RANDOM_POOL_SIZE);
|
|
1031
|
+
randomPoolPointer = 0;
|
|
1032
|
+
}
|
|
1033
|
+
mask[0] = randomPool[randomPoolPointer++];
|
|
1034
|
+
mask[1] = randomPool[randomPoolPointer++];
|
|
1035
|
+
mask[2] = randomPool[randomPoolPointer++];
|
|
1036
|
+
mask[3] = randomPool[randomPoolPointer++];
|
|
1037
|
+
}
|
|
1038
|
+
skipMasking = (mask[0] | mask[1] | mask[2] | mask[3]) === 0;
|
|
1039
|
+
offset = 6;
|
|
1040
|
+
}
|
|
1041
|
+
let dataLength;
|
|
1042
|
+
if (typeof data === "string") {
|
|
1043
|
+
if ((!options.mask || skipMasking) && options[kByteLength] !== undefined) {
|
|
1044
|
+
dataLength = options[kByteLength];
|
|
1045
|
+
} else {
|
|
1046
|
+
data = Buffer.from(data);
|
|
1047
|
+
dataLength = data.length;
|
|
1048
|
+
}
|
|
1049
|
+
} else {
|
|
1050
|
+
dataLength = data.length;
|
|
1051
|
+
merge = options.mask && options.readOnly && !skipMasking;
|
|
1052
|
+
}
|
|
1053
|
+
let payloadLength = dataLength;
|
|
1054
|
+
if (dataLength >= 65536) {
|
|
1055
|
+
offset += 8;
|
|
1056
|
+
payloadLength = 127;
|
|
1057
|
+
} else if (dataLength > 125) {
|
|
1058
|
+
offset += 2;
|
|
1059
|
+
payloadLength = 126;
|
|
1060
|
+
}
|
|
1061
|
+
const target = Buffer.allocUnsafe(merge ? dataLength + offset : offset);
|
|
1062
|
+
target[0] = options.fin ? options.opcode | 128 : options.opcode;
|
|
1063
|
+
if (options.rsv1)
|
|
1064
|
+
target[0] |= 64;
|
|
1065
|
+
target[1] = payloadLength;
|
|
1066
|
+
if (payloadLength === 126) {
|
|
1067
|
+
target.writeUInt16BE(dataLength, 2);
|
|
1068
|
+
} else if (payloadLength === 127) {
|
|
1069
|
+
target[2] = target[3] = 0;
|
|
1070
|
+
target.writeUIntBE(dataLength, 4, 6);
|
|
1071
|
+
}
|
|
1072
|
+
if (!options.mask)
|
|
1073
|
+
return [target, data];
|
|
1074
|
+
target[1] |= 128;
|
|
1075
|
+
target[offset - 4] = mask[0];
|
|
1076
|
+
target[offset - 3] = mask[1];
|
|
1077
|
+
target[offset - 2] = mask[2];
|
|
1078
|
+
target[offset - 1] = mask[3];
|
|
1079
|
+
if (skipMasking)
|
|
1080
|
+
return [target, data];
|
|
1081
|
+
if (merge) {
|
|
1082
|
+
applyMask(data, mask, target, offset, dataLength);
|
|
1083
|
+
return [target];
|
|
1084
|
+
}
|
|
1085
|
+
applyMask(data, mask, data, 0, dataLength);
|
|
1086
|
+
return [target, data];
|
|
1087
|
+
}
|
|
1088
|
+
close(code, data, mask, cb) {
|
|
1089
|
+
let buf;
|
|
1090
|
+
if (code === undefined) {
|
|
1091
|
+
buf = EMPTY_BUFFER;
|
|
1092
|
+
} else if (typeof code !== "number" || !isValidStatusCode(code)) {
|
|
1093
|
+
throw new TypeError("First argument must be a valid error code number");
|
|
1094
|
+
} else if (data === undefined || !data.length) {
|
|
1095
|
+
buf = Buffer.allocUnsafe(2);
|
|
1096
|
+
buf.writeUInt16BE(code, 0);
|
|
1097
|
+
} else {
|
|
1098
|
+
const length = Buffer.byteLength(data);
|
|
1099
|
+
if (length > 123) {
|
|
1100
|
+
throw new RangeError("The message must not be greater than 123 bytes");
|
|
1101
|
+
}
|
|
1102
|
+
buf = Buffer.allocUnsafe(2 + length);
|
|
1103
|
+
buf.writeUInt16BE(code, 0);
|
|
1104
|
+
if (typeof data === "string") {
|
|
1105
|
+
buf.write(data, 2);
|
|
1106
|
+
} else {
|
|
1107
|
+
buf.set(data, 2);
|
|
1108
|
+
}
|
|
1109
|
+
}
|
|
1110
|
+
const options = {
|
|
1111
|
+
[kByteLength]: buf.length,
|
|
1112
|
+
fin: true,
|
|
1113
|
+
generateMask: this._generateMask,
|
|
1114
|
+
mask,
|
|
1115
|
+
maskBuffer: this._maskBuffer,
|
|
1116
|
+
opcode: 8,
|
|
1117
|
+
readOnly: false,
|
|
1118
|
+
rsv1: false
|
|
1119
|
+
};
|
|
1120
|
+
if (this._state !== DEFAULT) {
|
|
1121
|
+
this.enqueue([this.dispatch, buf, false, options, cb]);
|
|
1122
|
+
} else {
|
|
1123
|
+
this.sendFrame(Sender.frame(buf, options), cb);
|
|
1124
|
+
}
|
|
1125
|
+
}
|
|
1126
|
+
ping(data, mask, cb) {
|
|
1127
|
+
let byteLength;
|
|
1128
|
+
let readOnly;
|
|
1129
|
+
if (typeof data === "string") {
|
|
1130
|
+
byteLength = Buffer.byteLength(data);
|
|
1131
|
+
readOnly = false;
|
|
1132
|
+
} else if (isBlob(data)) {
|
|
1133
|
+
byteLength = data.size;
|
|
1134
|
+
readOnly = false;
|
|
1135
|
+
} else {
|
|
1136
|
+
data = toBuffer(data);
|
|
1137
|
+
byteLength = data.length;
|
|
1138
|
+
readOnly = toBuffer.readOnly;
|
|
1139
|
+
}
|
|
1140
|
+
if (byteLength > 125) {
|
|
1141
|
+
throw new RangeError("The data size must not be greater than 125 bytes");
|
|
1142
|
+
}
|
|
1143
|
+
const options = {
|
|
1144
|
+
[kByteLength]: byteLength,
|
|
1145
|
+
fin: true,
|
|
1146
|
+
generateMask: this._generateMask,
|
|
1147
|
+
mask,
|
|
1148
|
+
maskBuffer: this._maskBuffer,
|
|
1149
|
+
opcode: 9,
|
|
1150
|
+
readOnly,
|
|
1151
|
+
rsv1: false
|
|
1152
|
+
};
|
|
1153
|
+
if (isBlob(data)) {
|
|
1154
|
+
if (this._state !== DEFAULT) {
|
|
1155
|
+
this.enqueue([this.getBlobData, data, false, options, cb]);
|
|
1156
|
+
} else {
|
|
1157
|
+
this.getBlobData(data, false, options, cb);
|
|
1158
|
+
}
|
|
1159
|
+
} else if (this._state !== DEFAULT) {
|
|
1160
|
+
this.enqueue([this.dispatch, data, false, options, cb]);
|
|
1161
|
+
} else {
|
|
1162
|
+
this.sendFrame(Sender.frame(data, options), cb);
|
|
1163
|
+
}
|
|
1164
|
+
}
|
|
1165
|
+
pong(data, mask, cb) {
|
|
1166
|
+
let byteLength;
|
|
1167
|
+
let readOnly;
|
|
1168
|
+
if (typeof data === "string") {
|
|
1169
|
+
byteLength = Buffer.byteLength(data);
|
|
1170
|
+
readOnly = false;
|
|
1171
|
+
} else if (isBlob(data)) {
|
|
1172
|
+
byteLength = data.size;
|
|
1173
|
+
readOnly = false;
|
|
1174
|
+
} else {
|
|
1175
|
+
data = toBuffer(data);
|
|
1176
|
+
byteLength = data.length;
|
|
1177
|
+
readOnly = toBuffer.readOnly;
|
|
1178
|
+
}
|
|
1179
|
+
if (byteLength > 125) {
|
|
1180
|
+
throw new RangeError("The data size must not be greater than 125 bytes");
|
|
1181
|
+
}
|
|
1182
|
+
const options = {
|
|
1183
|
+
[kByteLength]: byteLength,
|
|
1184
|
+
fin: true,
|
|
1185
|
+
generateMask: this._generateMask,
|
|
1186
|
+
mask,
|
|
1187
|
+
maskBuffer: this._maskBuffer,
|
|
1188
|
+
opcode: 10,
|
|
1189
|
+
readOnly,
|
|
1190
|
+
rsv1: false
|
|
1191
|
+
};
|
|
1192
|
+
if (isBlob(data)) {
|
|
1193
|
+
if (this._state !== DEFAULT) {
|
|
1194
|
+
this.enqueue([this.getBlobData, data, false, options, cb]);
|
|
1195
|
+
} else {
|
|
1196
|
+
this.getBlobData(data, false, options, cb);
|
|
1197
|
+
}
|
|
1198
|
+
} else if (this._state !== DEFAULT) {
|
|
1199
|
+
this.enqueue([this.dispatch, data, false, options, cb]);
|
|
1200
|
+
} else {
|
|
1201
|
+
this.sendFrame(Sender.frame(data, options), cb);
|
|
1202
|
+
}
|
|
1203
|
+
}
|
|
1204
|
+
send(data, options, cb) {
|
|
1205
|
+
const perMessageDeflate = this._extensions[PerMessageDeflate.extensionName];
|
|
1206
|
+
let opcode = options.binary ? 2 : 1;
|
|
1207
|
+
let rsv1 = options.compress;
|
|
1208
|
+
let byteLength;
|
|
1209
|
+
let readOnly;
|
|
1210
|
+
if (typeof data === "string") {
|
|
1211
|
+
byteLength = Buffer.byteLength(data);
|
|
1212
|
+
readOnly = false;
|
|
1213
|
+
} else if (isBlob(data)) {
|
|
1214
|
+
byteLength = data.size;
|
|
1215
|
+
readOnly = false;
|
|
1216
|
+
} else {
|
|
1217
|
+
data = toBuffer(data);
|
|
1218
|
+
byteLength = data.length;
|
|
1219
|
+
readOnly = toBuffer.readOnly;
|
|
1220
|
+
}
|
|
1221
|
+
if (this._firstFragment) {
|
|
1222
|
+
this._firstFragment = false;
|
|
1223
|
+
if (rsv1 && perMessageDeflate && perMessageDeflate.params[perMessageDeflate._isServer ? "server_no_context_takeover" : "client_no_context_takeover"]) {
|
|
1224
|
+
rsv1 = byteLength >= perMessageDeflate._threshold;
|
|
1225
|
+
}
|
|
1226
|
+
this._compress = rsv1;
|
|
1227
|
+
} else {
|
|
1228
|
+
rsv1 = false;
|
|
1229
|
+
opcode = 0;
|
|
1230
|
+
}
|
|
1231
|
+
if (options.fin)
|
|
1232
|
+
this._firstFragment = true;
|
|
1233
|
+
const opts = {
|
|
1234
|
+
[kByteLength]: byteLength,
|
|
1235
|
+
fin: options.fin,
|
|
1236
|
+
generateMask: this._generateMask,
|
|
1237
|
+
mask: options.mask,
|
|
1238
|
+
maskBuffer: this._maskBuffer,
|
|
1239
|
+
opcode,
|
|
1240
|
+
readOnly,
|
|
1241
|
+
rsv1
|
|
1242
|
+
};
|
|
1243
|
+
if (isBlob(data)) {
|
|
1244
|
+
if (this._state !== DEFAULT) {
|
|
1245
|
+
this.enqueue([this.getBlobData, data, this._compress, opts, cb]);
|
|
1246
|
+
} else {
|
|
1247
|
+
this.getBlobData(data, this._compress, opts, cb);
|
|
1248
|
+
}
|
|
1249
|
+
} else if (this._state !== DEFAULT) {
|
|
1250
|
+
this.enqueue([this.dispatch, data, this._compress, opts, cb]);
|
|
1251
|
+
} else {
|
|
1252
|
+
this.dispatch(data, this._compress, opts, cb);
|
|
1253
|
+
}
|
|
1254
|
+
}
|
|
1255
|
+
getBlobData(blob, compress, options, cb) {
|
|
1256
|
+
this._bufferedBytes += options[kByteLength];
|
|
1257
|
+
this._state = GET_BLOB_DATA;
|
|
1258
|
+
blob.arrayBuffer().then((arrayBuffer) => {
|
|
1259
|
+
if (this._socket.destroyed) {
|
|
1260
|
+
const err = new Error("The socket was closed while the blob was being read");
|
|
1261
|
+
process.nextTick(callCallbacks, this, err, cb);
|
|
1262
|
+
return;
|
|
1263
|
+
}
|
|
1264
|
+
this._bufferedBytes -= options[kByteLength];
|
|
1265
|
+
const data = toBuffer(arrayBuffer);
|
|
1266
|
+
if (!compress) {
|
|
1267
|
+
this._state = DEFAULT;
|
|
1268
|
+
this.sendFrame(Sender.frame(data, options), cb);
|
|
1269
|
+
this.dequeue();
|
|
1270
|
+
} else {
|
|
1271
|
+
this.dispatch(data, compress, options, cb);
|
|
1272
|
+
}
|
|
1273
|
+
}).catch((err) => {
|
|
1274
|
+
process.nextTick(onError, this, err, cb);
|
|
1275
|
+
});
|
|
1276
|
+
}
|
|
1277
|
+
dispatch(data, compress, options, cb) {
|
|
1278
|
+
if (!compress) {
|
|
1279
|
+
this.sendFrame(Sender.frame(data, options), cb);
|
|
1280
|
+
return;
|
|
1281
|
+
}
|
|
1282
|
+
const perMessageDeflate = this._extensions[PerMessageDeflate.extensionName];
|
|
1283
|
+
this._bufferedBytes += options[kByteLength];
|
|
1284
|
+
this._state = DEFLATING;
|
|
1285
|
+
perMessageDeflate.compress(data, options.fin, (_, buf) => {
|
|
1286
|
+
if (this._socket.destroyed) {
|
|
1287
|
+
const err = new Error("The socket was closed while data was being compressed");
|
|
1288
|
+
callCallbacks(this, err, cb);
|
|
1289
|
+
return;
|
|
1290
|
+
}
|
|
1291
|
+
this._bufferedBytes -= options[kByteLength];
|
|
1292
|
+
this._state = DEFAULT;
|
|
1293
|
+
options.readOnly = false;
|
|
1294
|
+
this.sendFrame(Sender.frame(buf, options), cb);
|
|
1295
|
+
this.dequeue();
|
|
1296
|
+
});
|
|
1297
|
+
}
|
|
1298
|
+
dequeue() {
|
|
1299
|
+
while (this._state === DEFAULT && this._queue.length) {
|
|
1300
|
+
const params = this._queue.shift();
|
|
1301
|
+
this._bufferedBytes -= params[3][kByteLength];
|
|
1302
|
+
Reflect.apply(params[0], this, params.slice(1));
|
|
1303
|
+
}
|
|
1304
|
+
}
|
|
1305
|
+
enqueue(params) {
|
|
1306
|
+
this._bufferedBytes += params[3][kByteLength];
|
|
1307
|
+
this._queue.push(params);
|
|
1308
|
+
}
|
|
1309
|
+
sendFrame(list, cb) {
|
|
1310
|
+
if (list.length === 2) {
|
|
1311
|
+
this._socket.cork();
|
|
1312
|
+
this._socket.write(list[0]);
|
|
1313
|
+
this._socket.write(list[1], cb);
|
|
1314
|
+
this._socket.uncork();
|
|
1315
|
+
} else {
|
|
1316
|
+
this._socket.write(list[0], cb);
|
|
1317
|
+
}
|
|
1318
|
+
}
|
|
1319
|
+
}
|
|
1320
|
+
module.exports = Sender;
|
|
1321
|
+
function callCallbacks(sender, err, cb) {
|
|
1322
|
+
if (typeof cb === "function")
|
|
1323
|
+
cb(err);
|
|
1324
|
+
for (let i = 0;i < sender._queue.length; i++) {
|
|
1325
|
+
const params = sender._queue[i];
|
|
1326
|
+
const callback = params[params.length - 1];
|
|
1327
|
+
if (typeof callback === "function")
|
|
1328
|
+
callback(err);
|
|
1329
|
+
}
|
|
1330
|
+
}
|
|
1331
|
+
function onError(sender, err, cb) {
|
|
1332
|
+
callCallbacks(sender, err, cb);
|
|
1333
|
+
sender.onerror(err);
|
|
1334
|
+
}
|
|
1335
|
+
});
|
|
1336
|
+
|
|
1337
|
+
// ../../node_modules/.bun/ws@8.19.0/node_modules/ws/lib/event-target.js
|
|
1338
|
+
var require_event_target = __commonJS((exports, module) => {
|
|
1339
|
+
var { kForOnEventAttribute, kListener } = require_constants();
|
|
1340
|
+
var kCode = Symbol("kCode");
|
|
1341
|
+
var kData = Symbol("kData");
|
|
1342
|
+
var kError = Symbol("kError");
|
|
1343
|
+
var kMessage = Symbol("kMessage");
|
|
1344
|
+
var kReason = Symbol("kReason");
|
|
1345
|
+
var kTarget = Symbol("kTarget");
|
|
1346
|
+
var kType = Symbol("kType");
|
|
1347
|
+
var kWasClean = Symbol("kWasClean");
|
|
1348
|
+
|
|
1349
|
+
class Event {
|
|
1350
|
+
constructor(type) {
|
|
1351
|
+
this[kTarget] = null;
|
|
1352
|
+
this[kType] = type;
|
|
1353
|
+
}
|
|
1354
|
+
get target() {
|
|
1355
|
+
return this[kTarget];
|
|
1356
|
+
}
|
|
1357
|
+
get type() {
|
|
1358
|
+
return this[kType];
|
|
1359
|
+
}
|
|
1360
|
+
}
|
|
1361
|
+
Object.defineProperty(Event.prototype, "target", { enumerable: true });
|
|
1362
|
+
Object.defineProperty(Event.prototype, "type", { enumerable: true });
|
|
1363
|
+
|
|
1364
|
+
class CloseEvent extends Event {
|
|
1365
|
+
constructor(type, options = {}) {
|
|
1366
|
+
super(type);
|
|
1367
|
+
this[kCode] = options.code === undefined ? 0 : options.code;
|
|
1368
|
+
this[kReason] = options.reason === undefined ? "" : options.reason;
|
|
1369
|
+
this[kWasClean] = options.wasClean === undefined ? false : options.wasClean;
|
|
1370
|
+
}
|
|
1371
|
+
get code() {
|
|
1372
|
+
return this[kCode];
|
|
1373
|
+
}
|
|
1374
|
+
get reason() {
|
|
1375
|
+
return this[kReason];
|
|
1376
|
+
}
|
|
1377
|
+
get wasClean() {
|
|
1378
|
+
return this[kWasClean];
|
|
1379
|
+
}
|
|
1380
|
+
}
|
|
1381
|
+
Object.defineProperty(CloseEvent.prototype, "code", { enumerable: true });
|
|
1382
|
+
Object.defineProperty(CloseEvent.prototype, "reason", { enumerable: true });
|
|
1383
|
+
Object.defineProperty(CloseEvent.prototype, "wasClean", { enumerable: true });
|
|
1384
|
+
|
|
1385
|
+
class ErrorEvent extends Event {
|
|
1386
|
+
constructor(type, options = {}) {
|
|
1387
|
+
super(type);
|
|
1388
|
+
this[kError] = options.error === undefined ? null : options.error;
|
|
1389
|
+
this[kMessage] = options.message === undefined ? "" : options.message;
|
|
1390
|
+
}
|
|
1391
|
+
get error() {
|
|
1392
|
+
return this[kError];
|
|
1393
|
+
}
|
|
1394
|
+
get message() {
|
|
1395
|
+
return this[kMessage];
|
|
1396
|
+
}
|
|
1397
|
+
}
|
|
1398
|
+
Object.defineProperty(ErrorEvent.prototype, "error", { enumerable: true });
|
|
1399
|
+
Object.defineProperty(ErrorEvent.prototype, "message", { enumerable: true });
|
|
1400
|
+
|
|
1401
|
+
class MessageEvent extends Event {
|
|
1402
|
+
constructor(type, options = {}) {
|
|
1403
|
+
super(type);
|
|
1404
|
+
this[kData] = options.data === undefined ? null : options.data;
|
|
1405
|
+
}
|
|
1406
|
+
get data() {
|
|
1407
|
+
return this[kData];
|
|
1408
|
+
}
|
|
1409
|
+
}
|
|
1410
|
+
Object.defineProperty(MessageEvent.prototype, "data", { enumerable: true });
|
|
1411
|
+
var EventTarget = {
|
|
1412
|
+
addEventListener(type, handler, options = {}) {
|
|
1413
|
+
for (const listener of this.listeners(type)) {
|
|
1414
|
+
if (!options[kForOnEventAttribute] && listener[kListener] === handler && !listener[kForOnEventAttribute]) {
|
|
1415
|
+
return;
|
|
1416
|
+
}
|
|
1417
|
+
}
|
|
1418
|
+
let wrapper;
|
|
1419
|
+
if (type === "message") {
|
|
1420
|
+
wrapper = function onMessage(data, isBinary) {
|
|
1421
|
+
const event = new MessageEvent("message", {
|
|
1422
|
+
data: isBinary ? data : data.toString()
|
|
1423
|
+
});
|
|
1424
|
+
event[kTarget] = this;
|
|
1425
|
+
callListener(handler, this, event);
|
|
1426
|
+
};
|
|
1427
|
+
} else if (type === "close") {
|
|
1428
|
+
wrapper = function onClose(code, message) {
|
|
1429
|
+
const event = new CloseEvent("close", {
|
|
1430
|
+
code,
|
|
1431
|
+
reason: message.toString(),
|
|
1432
|
+
wasClean: this._closeFrameReceived && this._closeFrameSent
|
|
1433
|
+
});
|
|
1434
|
+
event[kTarget] = this;
|
|
1435
|
+
callListener(handler, this, event);
|
|
1436
|
+
};
|
|
1437
|
+
} else if (type === "error") {
|
|
1438
|
+
wrapper = function onError(error) {
|
|
1439
|
+
const event = new ErrorEvent("error", {
|
|
1440
|
+
error,
|
|
1441
|
+
message: error.message
|
|
1442
|
+
});
|
|
1443
|
+
event[kTarget] = this;
|
|
1444
|
+
callListener(handler, this, event);
|
|
1445
|
+
};
|
|
1446
|
+
} else if (type === "open") {
|
|
1447
|
+
wrapper = function onOpen() {
|
|
1448
|
+
const event = new Event("open");
|
|
1449
|
+
event[kTarget] = this;
|
|
1450
|
+
callListener(handler, this, event);
|
|
1451
|
+
};
|
|
1452
|
+
} else {
|
|
1453
|
+
return;
|
|
1454
|
+
}
|
|
1455
|
+
wrapper[kForOnEventAttribute] = !!options[kForOnEventAttribute];
|
|
1456
|
+
wrapper[kListener] = handler;
|
|
1457
|
+
if (options.once) {
|
|
1458
|
+
this.once(type, wrapper);
|
|
1459
|
+
} else {
|
|
1460
|
+
this.on(type, wrapper);
|
|
1461
|
+
}
|
|
1462
|
+
},
|
|
1463
|
+
removeEventListener(type, handler) {
|
|
1464
|
+
for (const listener of this.listeners(type)) {
|
|
1465
|
+
if (listener[kListener] === handler && !listener[kForOnEventAttribute]) {
|
|
1466
|
+
this.removeListener(type, listener);
|
|
1467
|
+
break;
|
|
1468
|
+
}
|
|
1469
|
+
}
|
|
1470
|
+
}
|
|
1471
|
+
};
|
|
1472
|
+
module.exports = {
|
|
1473
|
+
CloseEvent,
|
|
1474
|
+
ErrorEvent,
|
|
1475
|
+
Event,
|
|
1476
|
+
EventTarget,
|
|
1477
|
+
MessageEvent
|
|
1478
|
+
};
|
|
1479
|
+
function callListener(listener, thisArg, event) {
|
|
1480
|
+
if (typeof listener === "object" && listener.handleEvent) {
|
|
1481
|
+
listener.handleEvent.call(listener, event);
|
|
1482
|
+
} else {
|
|
1483
|
+
listener.call(thisArg, event);
|
|
1484
|
+
}
|
|
1485
|
+
}
|
|
1486
|
+
});
|
|
1487
|
+
|
|
1488
|
+
// ../../node_modules/.bun/ws@8.19.0/node_modules/ws/lib/extension.js
|
|
1489
|
+
var require_extension = __commonJS((exports, module) => {
|
|
1490
|
+
var { tokenChars } = require_validation();
|
|
1491
|
+
function push(dest, name, elem) {
|
|
1492
|
+
if (dest[name] === undefined)
|
|
1493
|
+
dest[name] = [elem];
|
|
1494
|
+
else
|
|
1495
|
+
dest[name].push(elem);
|
|
1496
|
+
}
|
|
1497
|
+
function parse(header) {
|
|
1498
|
+
const offers = Object.create(null);
|
|
1499
|
+
let params = Object.create(null);
|
|
1500
|
+
let mustUnescape = false;
|
|
1501
|
+
let isEscaping = false;
|
|
1502
|
+
let inQuotes = false;
|
|
1503
|
+
let extensionName;
|
|
1504
|
+
let paramName;
|
|
1505
|
+
let start = -1;
|
|
1506
|
+
let code = -1;
|
|
1507
|
+
let end = -1;
|
|
1508
|
+
let i = 0;
|
|
1509
|
+
for (;i < header.length; i++) {
|
|
1510
|
+
code = header.charCodeAt(i);
|
|
1511
|
+
if (extensionName === undefined) {
|
|
1512
|
+
if (end === -1 && tokenChars[code] === 1) {
|
|
1513
|
+
if (start === -1)
|
|
1514
|
+
start = i;
|
|
1515
|
+
} else if (i !== 0 && (code === 32 || code === 9)) {
|
|
1516
|
+
if (end === -1 && start !== -1)
|
|
1517
|
+
end = i;
|
|
1518
|
+
} else if (code === 59 || code === 44) {
|
|
1519
|
+
if (start === -1) {
|
|
1520
|
+
throw new SyntaxError(`Unexpected character at index ${i}`);
|
|
1521
|
+
}
|
|
1522
|
+
if (end === -1)
|
|
1523
|
+
end = i;
|
|
1524
|
+
const name = header.slice(start, end);
|
|
1525
|
+
if (code === 44) {
|
|
1526
|
+
push(offers, name, params);
|
|
1527
|
+
params = Object.create(null);
|
|
1528
|
+
} else {
|
|
1529
|
+
extensionName = name;
|
|
1530
|
+
}
|
|
1531
|
+
start = end = -1;
|
|
1532
|
+
} else {
|
|
1533
|
+
throw new SyntaxError(`Unexpected character at index ${i}`);
|
|
1534
|
+
}
|
|
1535
|
+
} else if (paramName === undefined) {
|
|
1536
|
+
if (end === -1 && tokenChars[code] === 1) {
|
|
1537
|
+
if (start === -1)
|
|
1538
|
+
start = i;
|
|
1539
|
+
} else if (code === 32 || code === 9) {
|
|
1540
|
+
if (end === -1 && start !== -1)
|
|
1541
|
+
end = i;
|
|
1542
|
+
} else if (code === 59 || code === 44) {
|
|
1543
|
+
if (start === -1) {
|
|
1544
|
+
throw new SyntaxError(`Unexpected character at index ${i}`);
|
|
1545
|
+
}
|
|
1546
|
+
if (end === -1)
|
|
1547
|
+
end = i;
|
|
1548
|
+
push(params, header.slice(start, end), true);
|
|
1549
|
+
if (code === 44) {
|
|
1550
|
+
push(offers, extensionName, params);
|
|
1551
|
+
params = Object.create(null);
|
|
1552
|
+
extensionName = undefined;
|
|
1553
|
+
}
|
|
1554
|
+
start = end = -1;
|
|
1555
|
+
} else if (code === 61 && start !== -1 && end === -1) {
|
|
1556
|
+
paramName = header.slice(start, i);
|
|
1557
|
+
start = end = -1;
|
|
1558
|
+
} else {
|
|
1559
|
+
throw new SyntaxError(`Unexpected character at index ${i}`);
|
|
1560
|
+
}
|
|
1561
|
+
} else {
|
|
1562
|
+
if (isEscaping) {
|
|
1563
|
+
if (tokenChars[code] !== 1) {
|
|
1564
|
+
throw new SyntaxError(`Unexpected character at index ${i}`);
|
|
1565
|
+
}
|
|
1566
|
+
if (start === -1)
|
|
1567
|
+
start = i;
|
|
1568
|
+
else if (!mustUnescape)
|
|
1569
|
+
mustUnescape = true;
|
|
1570
|
+
isEscaping = false;
|
|
1571
|
+
} else if (inQuotes) {
|
|
1572
|
+
if (tokenChars[code] === 1) {
|
|
1573
|
+
if (start === -1)
|
|
1574
|
+
start = i;
|
|
1575
|
+
} else if (code === 34 && start !== -1) {
|
|
1576
|
+
inQuotes = false;
|
|
1577
|
+
end = i;
|
|
1578
|
+
} else if (code === 92) {
|
|
1579
|
+
isEscaping = true;
|
|
1580
|
+
} else {
|
|
1581
|
+
throw new SyntaxError(`Unexpected character at index ${i}`);
|
|
1582
|
+
}
|
|
1583
|
+
} else if (code === 34 && header.charCodeAt(i - 1) === 61) {
|
|
1584
|
+
inQuotes = true;
|
|
1585
|
+
} else if (end === -1 && tokenChars[code] === 1) {
|
|
1586
|
+
if (start === -1)
|
|
1587
|
+
start = i;
|
|
1588
|
+
} else if (start !== -1 && (code === 32 || code === 9)) {
|
|
1589
|
+
if (end === -1)
|
|
1590
|
+
end = i;
|
|
1591
|
+
} else if (code === 59 || code === 44) {
|
|
1592
|
+
if (start === -1) {
|
|
1593
|
+
throw new SyntaxError(`Unexpected character at index ${i}`);
|
|
1594
|
+
}
|
|
1595
|
+
if (end === -1)
|
|
1596
|
+
end = i;
|
|
1597
|
+
let value = header.slice(start, end);
|
|
1598
|
+
if (mustUnescape) {
|
|
1599
|
+
value = value.replace(/\\/g, "");
|
|
1600
|
+
mustUnescape = false;
|
|
1601
|
+
}
|
|
1602
|
+
push(params, paramName, value);
|
|
1603
|
+
if (code === 44) {
|
|
1604
|
+
push(offers, extensionName, params);
|
|
1605
|
+
params = Object.create(null);
|
|
1606
|
+
extensionName = undefined;
|
|
1607
|
+
}
|
|
1608
|
+
paramName = undefined;
|
|
1609
|
+
start = end = -1;
|
|
1610
|
+
} else {
|
|
1611
|
+
throw new SyntaxError(`Unexpected character at index ${i}`);
|
|
1612
|
+
}
|
|
1613
|
+
}
|
|
1614
|
+
}
|
|
1615
|
+
if (start === -1 || inQuotes || code === 32 || code === 9) {
|
|
1616
|
+
throw new SyntaxError("Unexpected end of input");
|
|
1617
|
+
}
|
|
1618
|
+
if (end === -1)
|
|
1619
|
+
end = i;
|
|
1620
|
+
const token = header.slice(start, end);
|
|
1621
|
+
if (extensionName === undefined) {
|
|
1622
|
+
push(offers, token, params);
|
|
1623
|
+
} else {
|
|
1624
|
+
if (paramName === undefined) {
|
|
1625
|
+
push(params, token, true);
|
|
1626
|
+
} else if (mustUnescape) {
|
|
1627
|
+
push(params, paramName, token.replace(/\\/g, ""));
|
|
1628
|
+
} else {
|
|
1629
|
+
push(params, paramName, token);
|
|
1630
|
+
}
|
|
1631
|
+
push(offers, extensionName, params);
|
|
1632
|
+
}
|
|
1633
|
+
return offers;
|
|
1634
|
+
}
|
|
1635
|
+
function format(extensions) {
|
|
1636
|
+
return Object.keys(extensions).map((extension) => {
|
|
1637
|
+
let configurations = extensions[extension];
|
|
1638
|
+
if (!Array.isArray(configurations))
|
|
1639
|
+
configurations = [configurations];
|
|
1640
|
+
return configurations.map((params) => {
|
|
1641
|
+
return [extension].concat(Object.keys(params).map((k) => {
|
|
1642
|
+
let values = params[k];
|
|
1643
|
+
if (!Array.isArray(values))
|
|
1644
|
+
values = [values];
|
|
1645
|
+
return values.map((v) => v === true ? k : `${k}=${v}`).join("; ");
|
|
1646
|
+
})).join("; ");
|
|
1647
|
+
}).join(", ");
|
|
1648
|
+
}).join(", ");
|
|
1649
|
+
}
|
|
1650
|
+
module.exports = { format, parse };
|
|
1651
|
+
});
|
|
1652
|
+
|
|
1653
|
+
// ../../node_modules/.bun/ws@8.19.0/node_modules/ws/lib/websocket.js
|
|
1654
|
+
var require_websocket = __commonJS((exports, module) => {
|
|
1655
|
+
var EventEmitter = __require("events");
|
|
1656
|
+
var https = __require("https");
|
|
1657
|
+
var http = __require("http");
|
|
1658
|
+
var net = __require("net");
|
|
1659
|
+
var tls = __require("tls");
|
|
1660
|
+
var { randomBytes, createHash } = __require("crypto");
|
|
1661
|
+
var { Duplex, Readable } = __require("stream");
|
|
1662
|
+
var { URL: URL2 } = __require("url");
|
|
1663
|
+
var PerMessageDeflate = require_permessage_deflate();
|
|
1664
|
+
var Receiver = require_receiver();
|
|
1665
|
+
var Sender = require_sender();
|
|
1666
|
+
var { isBlob } = require_validation();
|
|
1667
|
+
var {
|
|
1668
|
+
BINARY_TYPES,
|
|
1669
|
+
CLOSE_TIMEOUT,
|
|
1670
|
+
EMPTY_BUFFER,
|
|
1671
|
+
GUID,
|
|
1672
|
+
kForOnEventAttribute,
|
|
1673
|
+
kListener,
|
|
1674
|
+
kStatusCode,
|
|
1675
|
+
kWebSocket,
|
|
1676
|
+
NOOP
|
|
1677
|
+
} = require_constants();
|
|
1678
|
+
var {
|
|
1679
|
+
EventTarget: { addEventListener, removeEventListener }
|
|
1680
|
+
} = require_event_target();
|
|
1681
|
+
var { format, parse } = require_extension();
|
|
1682
|
+
var { toBuffer } = require_buffer_util();
|
|
1683
|
+
var kAborted = Symbol("kAborted");
|
|
1684
|
+
var protocolVersions = [8, 13];
|
|
1685
|
+
var readyStates = ["CONNECTING", "OPEN", "CLOSING", "CLOSED"];
|
|
1686
|
+
var subprotocolRegex = /^[!#$%&'*+\-.0-9A-Z^_`|a-z~]+$/;
|
|
1687
|
+
|
|
1688
|
+
class WebSocket extends EventEmitter {
|
|
1689
|
+
constructor(address, protocols, options) {
|
|
1690
|
+
super();
|
|
1691
|
+
this._binaryType = BINARY_TYPES[0];
|
|
1692
|
+
this._closeCode = 1006;
|
|
1693
|
+
this._closeFrameReceived = false;
|
|
1694
|
+
this._closeFrameSent = false;
|
|
1695
|
+
this._closeMessage = EMPTY_BUFFER;
|
|
1696
|
+
this._closeTimer = null;
|
|
1697
|
+
this._errorEmitted = false;
|
|
1698
|
+
this._extensions = {};
|
|
1699
|
+
this._paused = false;
|
|
1700
|
+
this._protocol = "";
|
|
1701
|
+
this._readyState = WebSocket.CONNECTING;
|
|
1702
|
+
this._receiver = null;
|
|
1703
|
+
this._sender = null;
|
|
1704
|
+
this._socket = null;
|
|
1705
|
+
if (address !== null) {
|
|
1706
|
+
this._bufferedAmount = 0;
|
|
1707
|
+
this._isServer = false;
|
|
1708
|
+
this._redirects = 0;
|
|
1709
|
+
if (protocols === undefined) {
|
|
1710
|
+
protocols = [];
|
|
1711
|
+
} else if (!Array.isArray(protocols)) {
|
|
1712
|
+
if (typeof protocols === "object" && protocols !== null) {
|
|
1713
|
+
options = protocols;
|
|
1714
|
+
protocols = [];
|
|
1715
|
+
} else {
|
|
1716
|
+
protocols = [protocols];
|
|
1717
|
+
}
|
|
1718
|
+
}
|
|
1719
|
+
initAsClient(this, address, protocols, options);
|
|
1720
|
+
} else {
|
|
1721
|
+
this._autoPong = options.autoPong;
|
|
1722
|
+
this._closeTimeout = options.closeTimeout;
|
|
1723
|
+
this._isServer = true;
|
|
1724
|
+
}
|
|
1725
|
+
}
|
|
1726
|
+
get binaryType() {
|
|
1727
|
+
return this._binaryType;
|
|
1728
|
+
}
|
|
1729
|
+
set binaryType(type) {
|
|
1730
|
+
if (!BINARY_TYPES.includes(type))
|
|
1731
|
+
return;
|
|
1732
|
+
this._binaryType = type;
|
|
1733
|
+
if (this._receiver)
|
|
1734
|
+
this._receiver._binaryType = type;
|
|
1735
|
+
}
|
|
1736
|
+
get bufferedAmount() {
|
|
1737
|
+
if (!this._socket)
|
|
1738
|
+
return this._bufferedAmount;
|
|
1739
|
+
return this._socket._writableState.length + this._sender._bufferedBytes;
|
|
1740
|
+
}
|
|
1741
|
+
get extensions() {
|
|
1742
|
+
return Object.keys(this._extensions).join();
|
|
1743
|
+
}
|
|
1744
|
+
get isPaused() {
|
|
1745
|
+
return this._paused;
|
|
1746
|
+
}
|
|
1747
|
+
get onclose() {
|
|
1748
|
+
return null;
|
|
1749
|
+
}
|
|
1750
|
+
get onerror() {
|
|
1751
|
+
return null;
|
|
1752
|
+
}
|
|
1753
|
+
get onopen() {
|
|
1754
|
+
return null;
|
|
1755
|
+
}
|
|
1756
|
+
get onmessage() {
|
|
1757
|
+
return null;
|
|
1758
|
+
}
|
|
1759
|
+
get protocol() {
|
|
1760
|
+
return this._protocol;
|
|
1761
|
+
}
|
|
1762
|
+
get readyState() {
|
|
1763
|
+
return this._readyState;
|
|
1764
|
+
}
|
|
1765
|
+
get url() {
|
|
1766
|
+
return this._url;
|
|
1767
|
+
}
|
|
1768
|
+
setSocket(socket, head, options) {
|
|
1769
|
+
const receiver = new Receiver({
|
|
1770
|
+
allowSynchronousEvents: options.allowSynchronousEvents,
|
|
1771
|
+
binaryType: this.binaryType,
|
|
1772
|
+
extensions: this._extensions,
|
|
1773
|
+
isServer: this._isServer,
|
|
1774
|
+
maxPayload: options.maxPayload,
|
|
1775
|
+
skipUTF8Validation: options.skipUTF8Validation
|
|
1776
|
+
});
|
|
1777
|
+
const sender = new Sender(socket, this._extensions, options.generateMask);
|
|
1778
|
+
this._receiver = receiver;
|
|
1779
|
+
this._sender = sender;
|
|
1780
|
+
this._socket = socket;
|
|
1781
|
+
receiver[kWebSocket] = this;
|
|
1782
|
+
sender[kWebSocket] = this;
|
|
1783
|
+
socket[kWebSocket] = this;
|
|
1784
|
+
receiver.on("conclude", receiverOnConclude);
|
|
1785
|
+
receiver.on("drain", receiverOnDrain);
|
|
1786
|
+
receiver.on("error", receiverOnError);
|
|
1787
|
+
receiver.on("message", receiverOnMessage);
|
|
1788
|
+
receiver.on("ping", receiverOnPing);
|
|
1789
|
+
receiver.on("pong", receiverOnPong);
|
|
1790
|
+
sender.onerror = senderOnError;
|
|
1791
|
+
if (socket.setTimeout)
|
|
1792
|
+
socket.setTimeout(0);
|
|
1793
|
+
if (socket.setNoDelay)
|
|
1794
|
+
socket.setNoDelay();
|
|
1795
|
+
if (head.length > 0)
|
|
1796
|
+
socket.unshift(head);
|
|
1797
|
+
socket.on("close", socketOnClose);
|
|
1798
|
+
socket.on("data", socketOnData);
|
|
1799
|
+
socket.on("end", socketOnEnd);
|
|
1800
|
+
socket.on("error", socketOnError);
|
|
1801
|
+
this._readyState = WebSocket.OPEN;
|
|
1802
|
+
this.emit("open");
|
|
1803
|
+
}
|
|
1804
|
+
emitClose() {
|
|
1805
|
+
if (!this._socket) {
|
|
1806
|
+
this._readyState = WebSocket.CLOSED;
|
|
1807
|
+
this.emit("close", this._closeCode, this._closeMessage);
|
|
1808
|
+
return;
|
|
1809
|
+
}
|
|
1810
|
+
if (this._extensions[PerMessageDeflate.extensionName]) {
|
|
1811
|
+
this._extensions[PerMessageDeflate.extensionName].cleanup();
|
|
1812
|
+
}
|
|
1813
|
+
this._receiver.removeAllListeners();
|
|
1814
|
+
this._readyState = WebSocket.CLOSED;
|
|
1815
|
+
this.emit("close", this._closeCode, this._closeMessage);
|
|
1816
|
+
}
|
|
1817
|
+
close(code, data) {
|
|
1818
|
+
if (this.readyState === WebSocket.CLOSED)
|
|
1819
|
+
return;
|
|
1820
|
+
if (this.readyState === WebSocket.CONNECTING) {
|
|
1821
|
+
const msg = "WebSocket was closed before the connection was established";
|
|
1822
|
+
abortHandshake(this, this._req, msg);
|
|
1823
|
+
return;
|
|
1824
|
+
}
|
|
1825
|
+
if (this.readyState === WebSocket.CLOSING) {
|
|
1826
|
+
if (this._closeFrameSent && (this._closeFrameReceived || this._receiver._writableState.errorEmitted)) {
|
|
1827
|
+
this._socket.end();
|
|
1828
|
+
}
|
|
1829
|
+
return;
|
|
1830
|
+
}
|
|
1831
|
+
this._readyState = WebSocket.CLOSING;
|
|
1832
|
+
this._sender.close(code, data, !this._isServer, (err) => {
|
|
1833
|
+
if (err)
|
|
1834
|
+
return;
|
|
1835
|
+
this._closeFrameSent = true;
|
|
1836
|
+
if (this._closeFrameReceived || this._receiver._writableState.errorEmitted) {
|
|
1837
|
+
this._socket.end();
|
|
1838
|
+
}
|
|
1839
|
+
});
|
|
1840
|
+
setCloseTimer(this);
|
|
1841
|
+
}
|
|
1842
|
+
pause() {
|
|
1843
|
+
if (this.readyState === WebSocket.CONNECTING || this.readyState === WebSocket.CLOSED) {
|
|
1844
|
+
return;
|
|
1845
|
+
}
|
|
1846
|
+
this._paused = true;
|
|
1847
|
+
this._socket.pause();
|
|
1848
|
+
}
|
|
1849
|
+
ping(data, mask, cb) {
|
|
1850
|
+
if (this.readyState === WebSocket.CONNECTING) {
|
|
1851
|
+
throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");
|
|
1852
|
+
}
|
|
1853
|
+
if (typeof data === "function") {
|
|
1854
|
+
cb = data;
|
|
1855
|
+
data = mask = undefined;
|
|
1856
|
+
} else if (typeof mask === "function") {
|
|
1857
|
+
cb = mask;
|
|
1858
|
+
mask = undefined;
|
|
1859
|
+
}
|
|
1860
|
+
if (typeof data === "number")
|
|
1861
|
+
data = data.toString();
|
|
1862
|
+
if (this.readyState !== WebSocket.OPEN) {
|
|
1863
|
+
sendAfterClose(this, data, cb);
|
|
1864
|
+
return;
|
|
1865
|
+
}
|
|
1866
|
+
if (mask === undefined)
|
|
1867
|
+
mask = !this._isServer;
|
|
1868
|
+
this._sender.ping(data || EMPTY_BUFFER, mask, cb);
|
|
1869
|
+
}
|
|
1870
|
+
pong(data, mask, cb) {
|
|
1871
|
+
if (this.readyState === WebSocket.CONNECTING) {
|
|
1872
|
+
throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");
|
|
1873
|
+
}
|
|
1874
|
+
if (typeof data === "function") {
|
|
1875
|
+
cb = data;
|
|
1876
|
+
data = mask = undefined;
|
|
1877
|
+
} else if (typeof mask === "function") {
|
|
1878
|
+
cb = mask;
|
|
1879
|
+
mask = undefined;
|
|
1880
|
+
}
|
|
1881
|
+
if (typeof data === "number")
|
|
1882
|
+
data = data.toString();
|
|
1883
|
+
if (this.readyState !== WebSocket.OPEN) {
|
|
1884
|
+
sendAfterClose(this, data, cb);
|
|
1885
|
+
return;
|
|
1886
|
+
}
|
|
1887
|
+
if (mask === undefined)
|
|
1888
|
+
mask = !this._isServer;
|
|
1889
|
+
this._sender.pong(data || EMPTY_BUFFER, mask, cb);
|
|
1890
|
+
}
|
|
1891
|
+
resume() {
|
|
1892
|
+
if (this.readyState === WebSocket.CONNECTING || this.readyState === WebSocket.CLOSED) {
|
|
1893
|
+
return;
|
|
1894
|
+
}
|
|
1895
|
+
this._paused = false;
|
|
1896
|
+
if (!this._receiver._writableState.needDrain)
|
|
1897
|
+
this._socket.resume();
|
|
1898
|
+
}
|
|
1899
|
+
send(data, options, cb) {
|
|
1900
|
+
if (this.readyState === WebSocket.CONNECTING) {
|
|
1901
|
+
throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");
|
|
1902
|
+
}
|
|
1903
|
+
if (typeof options === "function") {
|
|
1904
|
+
cb = options;
|
|
1905
|
+
options = {};
|
|
1906
|
+
}
|
|
1907
|
+
if (typeof data === "number")
|
|
1908
|
+
data = data.toString();
|
|
1909
|
+
if (this.readyState !== WebSocket.OPEN) {
|
|
1910
|
+
sendAfterClose(this, data, cb);
|
|
1911
|
+
return;
|
|
1912
|
+
}
|
|
1913
|
+
const opts = {
|
|
1914
|
+
binary: typeof data !== "string",
|
|
1915
|
+
mask: !this._isServer,
|
|
1916
|
+
compress: true,
|
|
1917
|
+
fin: true,
|
|
1918
|
+
...options
|
|
1919
|
+
};
|
|
1920
|
+
if (!this._extensions[PerMessageDeflate.extensionName]) {
|
|
1921
|
+
opts.compress = false;
|
|
1922
|
+
}
|
|
1923
|
+
this._sender.send(data || EMPTY_BUFFER, opts, cb);
|
|
1924
|
+
}
|
|
1925
|
+
terminate() {
|
|
1926
|
+
if (this.readyState === WebSocket.CLOSED)
|
|
1927
|
+
return;
|
|
1928
|
+
if (this.readyState === WebSocket.CONNECTING) {
|
|
1929
|
+
const msg = "WebSocket was closed before the connection was established";
|
|
1930
|
+
abortHandshake(this, this._req, msg);
|
|
1931
|
+
return;
|
|
1932
|
+
}
|
|
1933
|
+
if (this._socket) {
|
|
1934
|
+
this._readyState = WebSocket.CLOSING;
|
|
1935
|
+
this._socket.destroy();
|
|
1936
|
+
}
|
|
1937
|
+
}
|
|
1938
|
+
}
|
|
1939
|
+
Object.defineProperty(WebSocket, "CONNECTING", {
|
|
1940
|
+
enumerable: true,
|
|
1941
|
+
value: readyStates.indexOf("CONNECTING")
|
|
1942
|
+
});
|
|
1943
|
+
Object.defineProperty(WebSocket.prototype, "CONNECTING", {
|
|
1944
|
+
enumerable: true,
|
|
1945
|
+
value: readyStates.indexOf("CONNECTING")
|
|
1946
|
+
});
|
|
1947
|
+
Object.defineProperty(WebSocket, "OPEN", {
|
|
1948
|
+
enumerable: true,
|
|
1949
|
+
value: readyStates.indexOf("OPEN")
|
|
1950
|
+
});
|
|
1951
|
+
Object.defineProperty(WebSocket.prototype, "OPEN", {
|
|
1952
|
+
enumerable: true,
|
|
1953
|
+
value: readyStates.indexOf("OPEN")
|
|
1954
|
+
});
|
|
1955
|
+
Object.defineProperty(WebSocket, "CLOSING", {
|
|
1956
|
+
enumerable: true,
|
|
1957
|
+
value: readyStates.indexOf("CLOSING")
|
|
1958
|
+
});
|
|
1959
|
+
Object.defineProperty(WebSocket.prototype, "CLOSING", {
|
|
1960
|
+
enumerable: true,
|
|
1961
|
+
value: readyStates.indexOf("CLOSING")
|
|
1962
|
+
});
|
|
1963
|
+
Object.defineProperty(WebSocket, "CLOSED", {
|
|
1964
|
+
enumerable: true,
|
|
1965
|
+
value: readyStates.indexOf("CLOSED")
|
|
1966
|
+
});
|
|
1967
|
+
Object.defineProperty(WebSocket.prototype, "CLOSED", {
|
|
1968
|
+
enumerable: true,
|
|
1969
|
+
value: readyStates.indexOf("CLOSED")
|
|
1970
|
+
});
|
|
1971
|
+
[
|
|
1972
|
+
"binaryType",
|
|
1973
|
+
"bufferedAmount",
|
|
1974
|
+
"extensions",
|
|
1975
|
+
"isPaused",
|
|
1976
|
+
"protocol",
|
|
1977
|
+
"readyState",
|
|
1978
|
+
"url"
|
|
1979
|
+
].forEach((property) => {
|
|
1980
|
+
Object.defineProperty(WebSocket.prototype, property, { enumerable: true });
|
|
1981
|
+
});
|
|
1982
|
+
["open", "error", "close", "message"].forEach((method) => {
|
|
1983
|
+
Object.defineProperty(WebSocket.prototype, `on${method}`, {
|
|
1984
|
+
enumerable: true,
|
|
1985
|
+
get() {
|
|
1986
|
+
for (const listener of this.listeners(method)) {
|
|
1987
|
+
if (listener[kForOnEventAttribute])
|
|
1988
|
+
return listener[kListener];
|
|
1989
|
+
}
|
|
1990
|
+
return null;
|
|
1991
|
+
},
|
|
1992
|
+
set(handler) {
|
|
1993
|
+
for (const listener of this.listeners(method)) {
|
|
1994
|
+
if (listener[kForOnEventAttribute]) {
|
|
1995
|
+
this.removeListener(method, listener);
|
|
1996
|
+
break;
|
|
1997
|
+
}
|
|
1998
|
+
}
|
|
1999
|
+
if (typeof handler !== "function")
|
|
2000
|
+
return;
|
|
2001
|
+
this.addEventListener(method, handler, {
|
|
2002
|
+
[kForOnEventAttribute]: true
|
|
2003
|
+
});
|
|
2004
|
+
}
|
|
2005
|
+
});
|
|
2006
|
+
});
|
|
2007
|
+
WebSocket.prototype.addEventListener = addEventListener;
|
|
2008
|
+
WebSocket.prototype.removeEventListener = removeEventListener;
|
|
2009
|
+
module.exports = WebSocket;
|
|
2010
|
+
function initAsClient(websocket, address, protocols, options) {
|
|
2011
|
+
const opts = {
|
|
2012
|
+
allowSynchronousEvents: true,
|
|
2013
|
+
autoPong: true,
|
|
2014
|
+
closeTimeout: CLOSE_TIMEOUT,
|
|
2015
|
+
protocolVersion: protocolVersions[1],
|
|
2016
|
+
maxPayload: 100 * 1024 * 1024,
|
|
2017
|
+
skipUTF8Validation: false,
|
|
2018
|
+
perMessageDeflate: true,
|
|
2019
|
+
followRedirects: false,
|
|
2020
|
+
maxRedirects: 10,
|
|
2021
|
+
...options,
|
|
2022
|
+
socketPath: undefined,
|
|
2023
|
+
hostname: undefined,
|
|
2024
|
+
protocol: undefined,
|
|
2025
|
+
timeout: undefined,
|
|
2026
|
+
method: "GET",
|
|
2027
|
+
host: undefined,
|
|
2028
|
+
path: undefined,
|
|
2029
|
+
port: undefined
|
|
2030
|
+
};
|
|
2031
|
+
websocket._autoPong = opts.autoPong;
|
|
2032
|
+
websocket._closeTimeout = opts.closeTimeout;
|
|
2033
|
+
if (!protocolVersions.includes(opts.protocolVersion)) {
|
|
2034
|
+
throw new RangeError(`Unsupported protocol version: ${opts.protocolVersion} ` + `(supported versions: ${protocolVersions.join(", ")})`);
|
|
2035
|
+
}
|
|
2036
|
+
let parsedUrl;
|
|
2037
|
+
if (address instanceof URL2) {
|
|
2038
|
+
parsedUrl = address;
|
|
2039
|
+
} else {
|
|
2040
|
+
try {
|
|
2041
|
+
parsedUrl = new URL2(address);
|
|
2042
|
+
} catch (e) {
|
|
2043
|
+
throw new SyntaxError(`Invalid URL: ${address}`);
|
|
2044
|
+
}
|
|
2045
|
+
}
|
|
2046
|
+
if (parsedUrl.protocol === "http:") {
|
|
2047
|
+
parsedUrl.protocol = "ws:";
|
|
2048
|
+
} else if (parsedUrl.protocol === "https:") {
|
|
2049
|
+
parsedUrl.protocol = "wss:";
|
|
2050
|
+
}
|
|
2051
|
+
websocket._url = parsedUrl.href;
|
|
2052
|
+
const isSecure = parsedUrl.protocol === "wss:";
|
|
2053
|
+
const isIpcUrl = parsedUrl.protocol === "ws+unix:";
|
|
2054
|
+
let invalidUrlMessage;
|
|
2055
|
+
if (parsedUrl.protocol !== "ws:" && !isSecure && !isIpcUrl) {
|
|
2056
|
+
invalidUrlMessage = `The URL's protocol must be one of "ws:", "wss:", ` + '"http:", "https:", or "ws+unix:"';
|
|
2057
|
+
} else if (isIpcUrl && !parsedUrl.pathname) {
|
|
2058
|
+
invalidUrlMessage = "The URL's pathname is empty";
|
|
2059
|
+
} else if (parsedUrl.hash) {
|
|
2060
|
+
invalidUrlMessage = "The URL contains a fragment identifier";
|
|
2061
|
+
}
|
|
2062
|
+
if (invalidUrlMessage) {
|
|
2063
|
+
const err = new SyntaxError(invalidUrlMessage);
|
|
2064
|
+
if (websocket._redirects === 0) {
|
|
2065
|
+
throw err;
|
|
2066
|
+
} else {
|
|
2067
|
+
emitErrorAndClose(websocket, err);
|
|
2068
|
+
return;
|
|
2069
|
+
}
|
|
2070
|
+
}
|
|
2071
|
+
const defaultPort = isSecure ? 443 : 80;
|
|
2072
|
+
const key = randomBytes(16).toString("base64");
|
|
2073
|
+
const request = isSecure ? https.request : http.request;
|
|
2074
|
+
const protocolSet = new Set;
|
|
2075
|
+
let perMessageDeflate;
|
|
2076
|
+
opts.createConnection = opts.createConnection || (isSecure ? tlsConnect : netConnect);
|
|
2077
|
+
opts.defaultPort = opts.defaultPort || defaultPort;
|
|
2078
|
+
opts.port = parsedUrl.port || defaultPort;
|
|
2079
|
+
opts.host = parsedUrl.hostname.startsWith("[") ? parsedUrl.hostname.slice(1, -1) : parsedUrl.hostname;
|
|
2080
|
+
opts.headers = {
|
|
2081
|
+
...opts.headers,
|
|
2082
|
+
"Sec-WebSocket-Version": opts.protocolVersion,
|
|
2083
|
+
"Sec-WebSocket-Key": key,
|
|
2084
|
+
Connection: "Upgrade",
|
|
2085
|
+
Upgrade: "websocket"
|
|
2086
|
+
};
|
|
2087
|
+
opts.path = parsedUrl.pathname + parsedUrl.search;
|
|
2088
|
+
opts.timeout = opts.handshakeTimeout;
|
|
2089
|
+
if (opts.perMessageDeflate) {
|
|
2090
|
+
perMessageDeflate = new PerMessageDeflate(opts.perMessageDeflate !== true ? opts.perMessageDeflate : {}, false, opts.maxPayload);
|
|
2091
|
+
opts.headers["Sec-WebSocket-Extensions"] = format({
|
|
2092
|
+
[PerMessageDeflate.extensionName]: perMessageDeflate.offer()
|
|
2093
|
+
});
|
|
2094
|
+
}
|
|
2095
|
+
if (protocols.length) {
|
|
2096
|
+
for (const protocol of protocols) {
|
|
2097
|
+
if (typeof protocol !== "string" || !subprotocolRegex.test(protocol) || protocolSet.has(protocol)) {
|
|
2098
|
+
throw new SyntaxError("An invalid or duplicated subprotocol was specified");
|
|
2099
|
+
}
|
|
2100
|
+
protocolSet.add(protocol);
|
|
2101
|
+
}
|
|
2102
|
+
opts.headers["Sec-WebSocket-Protocol"] = protocols.join(",");
|
|
2103
|
+
}
|
|
2104
|
+
if (opts.origin) {
|
|
2105
|
+
if (opts.protocolVersion < 13) {
|
|
2106
|
+
opts.headers["Sec-WebSocket-Origin"] = opts.origin;
|
|
2107
|
+
} else {
|
|
2108
|
+
opts.headers.Origin = opts.origin;
|
|
2109
|
+
}
|
|
2110
|
+
}
|
|
2111
|
+
if (parsedUrl.username || parsedUrl.password) {
|
|
2112
|
+
opts.auth = `${parsedUrl.username}:${parsedUrl.password}`;
|
|
2113
|
+
}
|
|
2114
|
+
if (isIpcUrl) {
|
|
2115
|
+
const parts = opts.path.split(":");
|
|
2116
|
+
opts.socketPath = parts[0];
|
|
2117
|
+
opts.path = parts[1];
|
|
2118
|
+
}
|
|
2119
|
+
let req;
|
|
2120
|
+
if (opts.followRedirects) {
|
|
2121
|
+
if (websocket._redirects === 0) {
|
|
2122
|
+
websocket._originalIpc = isIpcUrl;
|
|
2123
|
+
websocket._originalSecure = isSecure;
|
|
2124
|
+
websocket._originalHostOrSocketPath = isIpcUrl ? opts.socketPath : parsedUrl.host;
|
|
2125
|
+
const headers = options && options.headers;
|
|
2126
|
+
options = { ...options, headers: {} };
|
|
2127
|
+
if (headers) {
|
|
2128
|
+
for (const [key2, value] of Object.entries(headers)) {
|
|
2129
|
+
options.headers[key2.toLowerCase()] = value;
|
|
2130
|
+
}
|
|
2131
|
+
}
|
|
2132
|
+
} else if (websocket.listenerCount("redirect") === 0) {
|
|
2133
|
+
const isSameHost = isIpcUrl ? websocket._originalIpc ? opts.socketPath === websocket._originalHostOrSocketPath : false : websocket._originalIpc ? false : parsedUrl.host === websocket._originalHostOrSocketPath;
|
|
2134
|
+
if (!isSameHost || websocket._originalSecure && !isSecure) {
|
|
2135
|
+
delete opts.headers.authorization;
|
|
2136
|
+
delete opts.headers.cookie;
|
|
2137
|
+
if (!isSameHost)
|
|
2138
|
+
delete opts.headers.host;
|
|
2139
|
+
opts.auth = undefined;
|
|
2140
|
+
}
|
|
2141
|
+
}
|
|
2142
|
+
if (opts.auth && !options.headers.authorization) {
|
|
2143
|
+
options.headers.authorization = "Basic " + Buffer.from(opts.auth).toString("base64");
|
|
2144
|
+
}
|
|
2145
|
+
req = websocket._req = request(opts);
|
|
2146
|
+
if (websocket._redirects) {
|
|
2147
|
+
websocket.emit("redirect", websocket.url, req);
|
|
2148
|
+
}
|
|
2149
|
+
} else {
|
|
2150
|
+
req = websocket._req = request(opts);
|
|
2151
|
+
}
|
|
2152
|
+
if (opts.timeout) {
|
|
2153
|
+
req.on("timeout", () => {
|
|
2154
|
+
abortHandshake(websocket, req, "Opening handshake has timed out");
|
|
2155
|
+
});
|
|
2156
|
+
}
|
|
2157
|
+
req.on("error", (err) => {
|
|
2158
|
+
if (req === null || req[kAborted])
|
|
2159
|
+
return;
|
|
2160
|
+
req = websocket._req = null;
|
|
2161
|
+
emitErrorAndClose(websocket, err);
|
|
2162
|
+
});
|
|
2163
|
+
req.on("response", (res) => {
|
|
2164
|
+
const location = res.headers.location;
|
|
2165
|
+
const statusCode = res.statusCode;
|
|
2166
|
+
if (location && opts.followRedirects && statusCode >= 300 && statusCode < 400) {
|
|
2167
|
+
if (++websocket._redirects > opts.maxRedirects) {
|
|
2168
|
+
abortHandshake(websocket, req, "Maximum redirects exceeded");
|
|
2169
|
+
return;
|
|
2170
|
+
}
|
|
2171
|
+
req.abort();
|
|
2172
|
+
let addr;
|
|
2173
|
+
try {
|
|
2174
|
+
addr = new URL2(location, address);
|
|
2175
|
+
} catch (e) {
|
|
2176
|
+
const err = new SyntaxError(`Invalid URL: ${location}`);
|
|
2177
|
+
emitErrorAndClose(websocket, err);
|
|
2178
|
+
return;
|
|
2179
|
+
}
|
|
2180
|
+
initAsClient(websocket, addr, protocols, options);
|
|
2181
|
+
} else if (!websocket.emit("unexpected-response", req, res)) {
|
|
2182
|
+
abortHandshake(websocket, req, `Unexpected server response: ${res.statusCode}`);
|
|
2183
|
+
}
|
|
2184
|
+
});
|
|
2185
|
+
req.on("upgrade", (res, socket, head) => {
|
|
2186
|
+
websocket.emit("upgrade", res);
|
|
2187
|
+
if (websocket.readyState !== WebSocket.CONNECTING)
|
|
2188
|
+
return;
|
|
2189
|
+
req = websocket._req = null;
|
|
2190
|
+
const upgrade = res.headers.upgrade;
|
|
2191
|
+
if (upgrade === undefined || upgrade.toLowerCase() !== "websocket") {
|
|
2192
|
+
abortHandshake(websocket, socket, "Invalid Upgrade header");
|
|
2193
|
+
return;
|
|
2194
|
+
}
|
|
2195
|
+
const digest = createHash("sha1").update(key + GUID).digest("base64");
|
|
2196
|
+
if (res.headers["sec-websocket-accept"] !== digest) {
|
|
2197
|
+
abortHandshake(websocket, socket, "Invalid Sec-WebSocket-Accept header");
|
|
2198
|
+
return;
|
|
2199
|
+
}
|
|
2200
|
+
const serverProt = res.headers["sec-websocket-protocol"];
|
|
2201
|
+
let protError;
|
|
2202
|
+
if (serverProt !== undefined) {
|
|
2203
|
+
if (!protocolSet.size) {
|
|
2204
|
+
protError = "Server sent a subprotocol but none was requested";
|
|
2205
|
+
} else if (!protocolSet.has(serverProt)) {
|
|
2206
|
+
protError = "Server sent an invalid subprotocol";
|
|
2207
|
+
}
|
|
2208
|
+
} else if (protocolSet.size) {
|
|
2209
|
+
protError = "Server sent no subprotocol";
|
|
2210
|
+
}
|
|
2211
|
+
if (protError) {
|
|
2212
|
+
abortHandshake(websocket, socket, protError);
|
|
2213
|
+
return;
|
|
2214
|
+
}
|
|
2215
|
+
if (serverProt)
|
|
2216
|
+
websocket._protocol = serverProt;
|
|
2217
|
+
const secWebSocketExtensions = res.headers["sec-websocket-extensions"];
|
|
2218
|
+
if (secWebSocketExtensions !== undefined) {
|
|
2219
|
+
if (!perMessageDeflate) {
|
|
2220
|
+
const message = "Server sent a Sec-WebSocket-Extensions header but no extension " + "was requested";
|
|
2221
|
+
abortHandshake(websocket, socket, message);
|
|
2222
|
+
return;
|
|
2223
|
+
}
|
|
2224
|
+
let extensions;
|
|
2225
|
+
try {
|
|
2226
|
+
extensions = parse(secWebSocketExtensions);
|
|
2227
|
+
} catch (err) {
|
|
2228
|
+
const message = "Invalid Sec-WebSocket-Extensions header";
|
|
2229
|
+
abortHandshake(websocket, socket, message);
|
|
2230
|
+
return;
|
|
2231
|
+
}
|
|
2232
|
+
const extensionNames = Object.keys(extensions);
|
|
2233
|
+
if (extensionNames.length !== 1 || extensionNames[0] !== PerMessageDeflate.extensionName) {
|
|
2234
|
+
const message = "Server indicated an extension that was not requested";
|
|
2235
|
+
abortHandshake(websocket, socket, message);
|
|
2236
|
+
return;
|
|
2237
|
+
}
|
|
2238
|
+
try {
|
|
2239
|
+
perMessageDeflate.accept(extensions[PerMessageDeflate.extensionName]);
|
|
2240
|
+
} catch (err) {
|
|
2241
|
+
const message = "Invalid Sec-WebSocket-Extensions header";
|
|
2242
|
+
abortHandshake(websocket, socket, message);
|
|
2243
|
+
return;
|
|
2244
|
+
}
|
|
2245
|
+
websocket._extensions[PerMessageDeflate.extensionName] = perMessageDeflate;
|
|
2246
|
+
}
|
|
2247
|
+
websocket.setSocket(socket, head, {
|
|
2248
|
+
allowSynchronousEvents: opts.allowSynchronousEvents,
|
|
2249
|
+
generateMask: opts.generateMask,
|
|
2250
|
+
maxPayload: opts.maxPayload,
|
|
2251
|
+
skipUTF8Validation: opts.skipUTF8Validation
|
|
2252
|
+
});
|
|
2253
|
+
});
|
|
2254
|
+
if (opts.finishRequest) {
|
|
2255
|
+
opts.finishRequest(req, websocket);
|
|
2256
|
+
} else {
|
|
2257
|
+
req.end();
|
|
2258
|
+
}
|
|
2259
|
+
}
|
|
2260
|
+
function emitErrorAndClose(websocket, err) {
|
|
2261
|
+
websocket._readyState = WebSocket.CLOSING;
|
|
2262
|
+
websocket._errorEmitted = true;
|
|
2263
|
+
websocket.emit("error", err);
|
|
2264
|
+
websocket.emitClose();
|
|
2265
|
+
}
|
|
2266
|
+
function netConnect(options) {
|
|
2267
|
+
options.path = options.socketPath;
|
|
2268
|
+
return net.connect(options);
|
|
2269
|
+
}
|
|
2270
|
+
function tlsConnect(options) {
|
|
2271
|
+
options.path = undefined;
|
|
2272
|
+
if (!options.servername && options.servername !== "") {
|
|
2273
|
+
options.servername = net.isIP(options.host) ? "" : options.host;
|
|
2274
|
+
}
|
|
2275
|
+
return tls.connect(options);
|
|
2276
|
+
}
|
|
2277
|
+
function abortHandshake(websocket, stream, message) {
|
|
2278
|
+
websocket._readyState = WebSocket.CLOSING;
|
|
2279
|
+
const err = new Error(message);
|
|
2280
|
+
Error.captureStackTrace(err, abortHandshake);
|
|
2281
|
+
if (stream.setHeader) {
|
|
2282
|
+
stream[kAborted] = true;
|
|
2283
|
+
stream.abort();
|
|
2284
|
+
if (stream.socket && !stream.socket.destroyed) {
|
|
2285
|
+
stream.socket.destroy();
|
|
2286
|
+
}
|
|
2287
|
+
process.nextTick(emitErrorAndClose, websocket, err);
|
|
2288
|
+
} else {
|
|
2289
|
+
stream.destroy(err);
|
|
2290
|
+
stream.once("error", websocket.emit.bind(websocket, "error"));
|
|
2291
|
+
stream.once("close", websocket.emitClose.bind(websocket));
|
|
2292
|
+
}
|
|
2293
|
+
}
|
|
2294
|
+
function sendAfterClose(websocket, data, cb) {
|
|
2295
|
+
if (data) {
|
|
2296
|
+
const length = isBlob(data) ? data.size : toBuffer(data).length;
|
|
2297
|
+
if (websocket._socket)
|
|
2298
|
+
websocket._sender._bufferedBytes += length;
|
|
2299
|
+
else
|
|
2300
|
+
websocket._bufferedAmount += length;
|
|
2301
|
+
}
|
|
2302
|
+
if (cb) {
|
|
2303
|
+
const err = new Error(`WebSocket is not open: readyState ${websocket.readyState} ` + `(${readyStates[websocket.readyState]})`);
|
|
2304
|
+
process.nextTick(cb, err);
|
|
2305
|
+
}
|
|
2306
|
+
}
|
|
2307
|
+
function receiverOnConclude(code, reason) {
|
|
2308
|
+
const websocket = this[kWebSocket];
|
|
2309
|
+
websocket._closeFrameReceived = true;
|
|
2310
|
+
websocket._closeMessage = reason;
|
|
2311
|
+
websocket._closeCode = code;
|
|
2312
|
+
if (websocket._socket[kWebSocket] === undefined)
|
|
2313
|
+
return;
|
|
2314
|
+
websocket._socket.removeListener("data", socketOnData);
|
|
2315
|
+
process.nextTick(resume, websocket._socket);
|
|
2316
|
+
if (code === 1005)
|
|
2317
|
+
websocket.close();
|
|
2318
|
+
else
|
|
2319
|
+
websocket.close(code, reason);
|
|
2320
|
+
}
|
|
2321
|
+
function receiverOnDrain() {
|
|
2322
|
+
const websocket = this[kWebSocket];
|
|
2323
|
+
if (!websocket.isPaused)
|
|
2324
|
+
websocket._socket.resume();
|
|
2325
|
+
}
|
|
2326
|
+
function receiverOnError(err) {
|
|
2327
|
+
const websocket = this[kWebSocket];
|
|
2328
|
+
if (websocket._socket[kWebSocket] !== undefined) {
|
|
2329
|
+
websocket._socket.removeListener("data", socketOnData);
|
|
2330
|
+
process.nextTick(resume, websocket._socket);
|
|
2331
|
+
websocket.close(err[kStatusCode]);
|
|
2332
|
+
}
|
|
2333
|
+
if (!websocket._errorEmitted) {
|
|
2334
|
+
websocket._errorEmitted = true;
|
|
2335
|
+
websocket.emit("error", err);
|
|
2336
|
+
}
|
|
2337
|
+
}
|
|
2338
|
+
function receiverOnFinish() {
|
|
2339
|
+
this[kWebSocket].emitClose();
|
|
2340
|
+
}
|
|
2341
|
+
function receiverOnMessage(data, isBinary) {
|
|
2342
|
+
this[kWebSocket].emit("message", data, isBinary);
|
|
2343
|
+
}
|
|
2344
|
+
function receiverOnPing(data) {
|
|
2345
|
+
const websocket = this[kWebSocket];
|
|
2346
|
+
if (websocket._autoPong)
|
|
2347
|
+
websocket.pong(data, !this._isServer, NOOP);
|
|
2348
|
+
websocket.emit("ping", data);
|
|
2349
|
+
}
|
|
2350
|
+
function receiverOnPong(data) {
|
|
2351
|
+
this[kWebSocket].emit("pong", data);
|
|
2352
|
+
}
|
|
2353
|
+
function resume(stream) {
|
|
2354
|
+
stream.resume();
|
|
2355
|
+
}
|
|
2356
|
+
function senderOnError(err) {
|
|
2357
|
+
const websocket = this[kWebSocket];
|
|
2358
|
+
if (websocket.readyState === WebSocket.CLOSED)
|
|
2359
|
+
return;
|
|
2360
|
+
if (websocket.readyState === WebSocket.OPEN) {
|
|
2361
|
+
websocket._readyState = WebSocket.CLOSING;
|
|
2362
|
+
setCloseTimer(websocket);
|
|
2363
|
+
}
|
|
2364
|
+
this._socket.end();
|
|
2365
|
+
if (!websocket._errorEmitted) {
|
|
2366
|
+
websocket._errorEmitted = true;
|
|
2367
|
+
websocket.emit("error", err);
|
|
2368
|
+
}
|
|
2369
|
+
}
|
|
2370
|
+
function setCloseTimer(websocket) {
|
|
2371
|
+
websocket._closeTimer = setTimeout(websocket._socket.destroy.bind(websocket._socket), websocket._closeTimeout);
|
|
2372
|
+
}
|
|
2373
|
+
function socketOnClose() {
|
|
2374
|
+
const websocket = this[kWebSocket];
|
|
2375
|
+
this.removeListener("close", socketOnClose);
|
|
2376
|
+
this.removeListener("data", socketOnData);
|
|
2377
|
+
this.removeListener("end", socketOnEnd);
|
|
2378
|
+
websocket._readyState = WebSocket.CLOSING;
|
|
2379
|
+
if (!this._readableState.endEmitted && !websocket._closeFrameReceived && !websocket._receiver._writableState.errorEmitted && this._readableState.length !== 0) {
|
|
2380
|
+
const chunk = this.read(this._readableState.length);
|
|
2381
|
+
websocket._receiver.write(chunk);
|
|
2382
|
+
}
|
|
2383
|
+
websocket._receiver.end();
|
|
2384
|
+
this[kWebSocket] = undefined;
|
|
2385
|
+
clearTimeout(websocket._closeTimer);
|
|
2386
|
+
if (websocket._receiver._writableState.finished || websocket._receiver._writableState.errorEmitted) {
|
|
2387
|
+
websocket.emitClose();
|
|
2388
|
+
} else {
|
|
2389
|
+
websocket._receiver.on("error", receiverOnFinish);
|
|
2390
|
+
websocket._receiver.on("finish", receiverOnFinish);
|
|
2391
|
+
}
|
|
2392
|
+
}
|
|
2393
|
+
function socketOnData(chunk) {
|
|
2394
|
+
if (!this[kWebSocket]._receiver.write(chunk)) {
|
|
2395
|
+
this.pause();
|
|
2396
|
+
}
|
|
2397
|
+
}
|
|
2398
|
+
function socketOnEnd() {
|
|
2399
|
+
const websocket = this[kWebSocket];
|
|
2400
|
+
websocket._readyState = WebSocket.CLOSING;
|
|
2401
|
+
websocket._receiver.end();
|
|
2402
|
+
this.end();
|
|
2403
|
+
}
|
|
2404
|
+
function socketOnError() {
|
|
2405
|
+
const websocket = this[kWebSocket];
|
|
2406
|
+
this.removeListener("error", socketOnError);
|
|
2407
|
+
this.on("error", NOOP);
|
|
2408
|
+
if (websocket) {
|
|
2409
|
+
websocket._readyState = WebSocket.CLOSING;
|
|
2410
|
+
this.destroy();
|
|
2411
|
+
}
|
|
2412
|
+
}
|
|
2413
|
+
});
|
|
2414
|
+
|
|
2415
|
+
// ../../node_modules/.bun/ws@8.19.0/node_modules/ws/lib/stream.js
|
|
2416
|
+
var require_stream = __commonJS((exports, module) => {
|
|
2417
|
+
var WebSocket = require_websocket();
|
|
2418
|
+
var { Duplex } = __require("stream");
|
|
2419
|
+
function emitClose(stream) {
|
|
2420
|
+
stream.emit("close");
|
|
2421
|
+
}
|
|
2422
|
+
function duplexOnEnd() {
|
|
2423
|
+
if (!this.destroyed && this._writableState.finished) {
|
|
2424
|
+
this.destroy();
|
|
2425
|
+
}
|
|
2426
|
+
}
|
|
2427
|
+
function duplexOnError(err) {
|
|
2428
|
+
this.removeListener("error", duplexOnError);
|
|
2429
|
+
this.destroy();
|
|
2430
|
+
if (this.listenerCount("error") === 0) {
|
|
2431
|
+
this.emit("error", err);
|
|
2432
|
+
}
|
|
2433
|
+
}
|
|
2434
|
+
function createWebSocketStream(ws, options) {
|
|
2435
|
+
let terminateOnDestroy = true;
|
|
2436
|
+
const duplex = new Duplex({
|
|
2437
|
+
...options,
|
|
2438
|
+
autoDestroy: false,
|
|
2439
|
+
emitClose: false,
|
|
2440
|
+
objectMode: false,
|
|
2441
|
+
writableObjectMode: false
|
|
2442
|
+
});
|
|
2443
|
+
ws.on("message", function message(msg, isBinary) {
|
|
2444
|
+
const data = !isBinary && duplex._readableState.objectMode ? msg.toString() : msg;
|
|
2445
|
+
if (!duplex.push(data))
|
|
2446
|
+
ws.pause();
|
|
2447
|
+
});
|
|
2448
|
+
ws.once("error", function error(err) {
|
|
2449
|
+
if (duplex.destroyed)
|
|
2450
|
+
return;
|
|
2451
|
+
terminateOnDestroy = false;
|
|
2452
|
+
duplex.destroy(err);
|
|
2453
|
+
});
|
|
2454
|
+
ws.once("close", function close() {
|
|
2455
|
+
if (duplex.destroyed)
|
|
2456
|
+
return;
|
|
2457
|
+
duplex.push(null);
|
|
2458
|
+
});
|
|
2459
|
+
duplex._destroy = function(err, callback) {
|
|
2460
|
+
if (ws.readyState === ws.CLOSED) {
|
|
2461
|
+
callback(err);
|
|
2462
|
+
process.nextTick(emitClose, duplex);
|
|
2463
|
+
return;
|
|
2464
|
+
}
|
|
2465
|
+
let called = false;
|
|
2466
|
+
ws.once("error", function error(err2) {
|
|
2467
|
+
called = true;
|
|
2468
|
+
callback(err2);
|
|
2469
|
+
});
|
|
2470
|
+
ws.once("close", function close() {
|
|
2471
|
+
if (!called)
|
|
2472
|
+
callback(err);
|
|
2473
|
+
process.nextTick(emitClose, duplex);
|
|
2474
|
+
});
|
|
2475
|
+
if (terminateOnDestroy)
|
|
2476
|
+
ws.terminate();
|
|
2477
|
+
};
|
|
2478
|
+
duplex._final = function(callback) {
|
|
2479
|
+
if (ws.readyState === ws.CONNECTING) {
|
|
2480
|
+
ws.once("open", function open() {
|
|
2481
|
+
duplex._final(callback);
|
|
2482
|
+
});
|
|
2483
|
+
return;
|
|
2484
|
+
}
|
|
2485
|
+
if (ws._socket === null)
|
|
2486
|
+
return;
|
|
2487
|
+
if (ws._socket._writableState.finished) {
|
|
2488
|
+
callback();
|
|
2489
|
+
if (duplex._readableState.endEmitted)
|
|
2490
|
+
duplex.destroy();
|
|
2491
|
+
} else {
|
|
2492
|
+
ws._socket.once("finish", function finish() {
|
|
2493
|
+
callback();
|
|
2494
|
+
});
|
|
2495
|
+
ws.close();
|
|
2496
|
+
}
|
|
2497
|
+
};
|
|
2498
|
+
duplex._read = function() {
|
|
2499
|
+
if (ws.isPaused)
|
|
2500
|
+
ws.resume();
|
|
2501
|
+
};
|
|
2502
|
+
duplex._write = function(chunk, encoding, callback) {
|
|
2503
|
+
if (ws.readyState === ws.CONNECTING) {
|
|
2504
|
+
ws.once("open", function open() {
|
|
2505
|
+
duplex._write(chunk, encoding, callback);
|
|
2506
|
+
});
|
|
2507
|
+
return;
|
|
2508
|
+
}
|
|
2509
|
+
ws.send(chunk, callback);
|
|
2510
|
+
};
|
|
2511
|
+
duplex.on("end", duplexOnEnd);
|
|
2512
|
+
duplex.on("error", duplexOnError);
|
|
2513
|
+
return duplex;
|
|
2514
|
+
}
|
|
2515
|
+
module.exports = createWebSocketStream;
|
|
2516
|
+
});
|
|
2517
|
+
|
|
2518
|
+
// ../../node_modules/.bun/ws@8.19.0/node_modules/ws/lib/subprotocol.js
|
|
2519
|
+
var require_subprotocol = __commonJS((exports, module) => {
|
|
2520
|
+
var { tokenChars } = require_validation();
|
|
2521
|
+
function parse(header) {
|
|
2522
|
+
const protocols = new Set;
|
|
2523
|
+
let start = -1;
|
|
2524
|
+
let end = -1;
|
|
2525
|
+
let i = 0;
|
|
2526
|
+
for (i;i < header.length; i++) {
|
|
2527
|
+
const code = header.charCodeAt(i);
|
|
2528
|
+
if (end === -1 && tokenChars[code] === 1) {
|
|
2529
|
+
if (start === -1)
|
|
2530
|
+
start = i;
|
|
2531
|
+
} else if (i !== 0 && (code === 32 || code === 9)) {
|
|
2532
|
+
if (end === -1 && start !== -1)
|
|
2533
|
+
end = i;
|
|
2534
|
+
} else if (code === 44) {
|
|
2535
|
+
if (start === -1) {
|
|
2536
|
+
throw new SyntaxError(`Unexpected character at index ${i}`);
|
|
2537
|
+
}
|
|
2538
|
+
if (end === -1)
|
|
2539
|
+
end = i;
|
|
2540
|
+
const protocol2 = header.slice(start, end);
|
|
2541
|
+
if (protocols.has(protocol2)) {
|
|
2542
|
+
throw new SyntaxError(`The "${protocol2}" subprotocol is duplicated`);
|
|
2543
|
+
}
|
|
2544
|
+
protocols.add(protocol2);
|
|
2545
|
+
start = end = -1;
|
|
2546
|
+
} else {
|
|
2547
|
+
throw new SyntaxError(`Unexpected character at index ${i}`);
|
|
2548
|
+
}
|
|
2549
|
+
}
|
|
2550
|
+
if (start === -1 || end !== -1) {
|
|
2551
|
+
throw new SyntaxError("Unexpected end of input");
|
|
2552
|
+
}
|
|
2553
|
+
const protocol = header.slice(start, i);
|
|
2554
|
+
if (protocols.has(protocol)) {
|
|
2555
|
+
throw new SyntaxError(`The "${protocol}" subprotocol is duplicated`);
|
|
2556
|
+
}
|
|
2557
|
+
protocols.add(protocol);
|
|
2558
|
+
return protocols;
|
|
2559
|
+
}
|
|
2560
|
+
module.exports = { parse };
|
|
2561
|
+
});
|
|
2562
|
+
|
|
2563
|
+
// ../../node_modules/.bun/ws@8.19.0/node_modules/ws/lib/websocket-server.js
|
|
2564
|
+
var require_websocket_server = __commonJS((exports, module) => {
|
|
2565
|
+
var EventEmitter = __require("events");
|
|
2566
|
+
var http = __require("http");
|
|
2567
|
+
var { Duplex } = __require("stream");
|
|
2568
|
+
var { createHash } = __require("crypto");
|
|
2569
|
+
var extension = require_extension();
|
|
2570
|
+
var PerMessageDeflate = require_permessage_deflate();
|
|
2571
|
+
var subprotocol = require_subprotocol();
|
|
2572
|
+
var WebSocket = require_websocket();
|
|
2573
|
+
var { CLOSE_TIMEOUT, GUID, kWebSocket } = require_constants();
|
|
2574
|
+
var keyRegex = /^[+/0-9A-Za-z]{22}==$/;
|
|
2575
|
+
var RUNNING = 0;
|
|
2576
|
+
var CLOSING = 1;
|
|
2577
|
+
var CLOSED = 2;
|
|
2578
|
+
|
|
2579
|
+
class WebSocketServer extends EventEmitter {
|
|
2580
|
+
constructor(options, callback) {
|
|
2581
|
+
super();
|
|
2582
|
+
options = {
|
|
2583
|
+
allowSynchronousEvents: true,
|
|
2584
|
+
autoPong: true,
|
|
2585
|
+
maxPayload: 100 * 1024 * 1024,
|
|
2586
|
+
skipUTF8Validation: false,
|
|
2587
|
+
perMessageDeflate: false,
|
|
2588
|
+
handleProtocols: null,
|
|
2589
|
+
clientTracking: true,
|
|
2590
|
+
closeTimeout: CLOSE_TIMEOUT,
|
|
2591
|
+
verifyClient: null,
|
|
2592
|
+
noServer: false,
|
|
2593
|
+
backlog: null,
|
|
2594
|
+
server: null,
|
|
2595
|
+
host: null,
|
|
2596
|
+
path: null,
|
|
2597
|
+
port: null,
|
|
2598
|
+
WebSocket,
|
|
2599
|
+
...options
|
|
2600
|
+
};
|
|
2601
|
+
if (options.port == null && !options.server && !options.noServer || options.port != null && (options.server || options.noServer) || options.server && options.noServer) {
|
|
2602
|
+
throw new TypeError('One and only one of the "port", "server", or "noServer" options ' + "must be specified");
|
|
2603
|
+
}
|
|
2604
|
+
if (options.port != null) {
|
|
2605
|
+
this._server = http.createServer((req, res) => {
|
|
2606
|
+
const body = http.STATUS_CODES[426];
|
|
2607
|
+
res.writeHead(426, {
|
|
2608
|
+
"Content-Length": body.length,
|
|
2609
|
+
"Content-Type": "text/plain"
|
|
2610
|
+
});
|
|
2611
|
+
res.end(body);
|
|
2612
|
+
});
|
|
2613
|
+
this._server.listen(options.port, options.host, options.backlog, callback);
|
|
2614
|
+
} else if (options.server) {
|
|
2615
|
+
this._server = options.server;
|
|
2616
|
+
}
|
|
2617
|
+
if (this._server) {
|
|
2618
|
+
const emitConnection = this.emit.bind(this, "connection");
|
|
2619
|
+
this._removeListeners = addListeners(this._server, {
|
|
2620
|
+
listening: this.emit.bind(this, "listening"),
|
|
2621
|
+
error: this.emit.bind(this, "error"),
|
|
2622
|
+
upgrade: (req, socket, head) => {
|
|
2623
|
+
this.handleUpgrade(req, socket, head, emitConnection);
|
|
2624
|
+
}
|
|
2625
|
+
});
|
|
2626
|
+
}
|
|
2627
|
+
if (options.perMessageDeflate === true)
|
|
2628
|
+
options.perMessageDeflate = {};
|
|
2629
|
+
if (options.clientTracking) {
|
|
2630
|
+
this.clients = new Set;
|
|
2631
|
+
this._shouldEmitClose = false;
|
|
2632
|
+
}
|
|
2633
|
+
this.options = options;
|
|
2634
|
+
this._state = RUNNING;
|
|
2635
|
+
}
|
|
2636
|
+
address() {
|
|
2637
|
+
if (this.options.noServer) {
|
|
2638
|
+
throw new Error('The server is operating in "noServer" mode');
|
|
2639
|
+
}
|
|
2640
|
+
if (!this._server)
|
|
2641
|
+
return null;
|
|
2642
|
+
return this._server.address();
|
|
2643
|
+
}
|
|
2644
|
+
close(cb) {
|
|
2645
|
+
if (this._state === CLOSED) {
|
|
2646
|
+
if (cb) {
|
|
2647
|
+
this.once("close", () => {
|
|
2648
|
+
cb(new Error("The server is not running"));
|
|
2649
|
+
});
|
|
2650
|
+
}
|
|
2651
|
+
process.nextTick(emitClose, this);
|
|
2652
|
+
return;
|
|
2653
|
+
}
|
|
2654
|
+
if (cb)
|
|
2655
|
+
this.once("close", cb);
|
|
2656
|
+
if (this._state === CLOSING)
|
|
2657
|
+
return;
|
|
2658
|
+
this._state = CLOSING;
|
|
2659
|
+
if (this.options.noServer || this.options.server) {
|
|
2660
|
+
if (this._server) {
|
|
2661
|
+
this._removeListeners();
|
|
2662
|
+
this._removeListeners = this._server = null;
|
|
2663
|
+
}
|
|
2664
|
+
if (this.clients) {
|
|
2665
|
+
if (!this.clients.size) {
|
|
2666
|
+
process.nextTick(emitClose, this);
|
|
2667
|
+
} else {
|
|
2668
|
+
this._shouldEmitClose = true;
|
|
2669
|
+
}
|
|
2670
|
+
} else {
|
|
2671
|
+
process.nextTick(emitClose, this);
|
|
2672
|
+
}
|
|
2673
|
+
} else {
|
|
2674
|
+
const server = this._server;
|
|
2675
|
+
this._removeListeners();
|
|
2676
|
+
this._removeListeners = this._server = null;
|
|
2677
|
+
server.close(() => {
|
|
2678
|
+
emitClose(this);
|
|
2679
|
+
});
|
|
2680
|
+
}
|
|
2681
|
+
}
|
|
2682
|
+
shouldHandle(req) {
|
|
2683
|
+
if (this.options.path) {
|
|
2684
|
+
const index = req.url.indexOf("?");
|
|
2685
|
+
const pathname = index !== -1 ? req.url.slice(0, index) : req.url;
|
|
2686
|
+
if (pathname !== this.options.path)
|
|
2687
|
+
return false;
|
|
2688
|
+
}
|
|
2689
|
+
return true;
|
|
2690
|
+
}
|
|
2691
|
+
handleUpgrade(req, socket, head, cb) {
|
|
2692
|
+
socket.on("error", socketOnError);
|
|
2693
|
+
const key = req.headers["sec-websocket-key"];
|
|
2694
|
+
const upgrade = req.headers.upgrade;
|
|
2695
|
+
const version = +req.headers["sec-websocket-version"];
|
|
2696
|
+
if (req.method !== "GET") {
|
|
2697
|
+
const message = "Invalid HTTP method";
|
|
2698
|
+
abortHandshakeOrEmitwsClientError(this, req, socket, 405, message);
|
|
2699
|
+
return;
|
|
2700
|
+
}
|
|
2701
|
+
if (upgrade === undefined || upgrade.toLowerCase() !== "websocket") {
|
|
2702
|
+
const message = "Invalid Upgrade header";
|
|
2703
|
+
abortHandshakeOrEmitwsClientError(this, req, socket, 400, message);
|
|
2704
|
+
return;
|
|
2705
|
+
}
|
|
2706
|
+
if (key === undefined || !keyRegex.test(key)) {
|
|
2707
|
+
const message = "Missing or invalid Sec-WebSocket-Key header";
|
|
2708
|
+
abortHandshakeOrEmitwsClientError(this, req, socket, 400, message);
|
|
2709
|
+
return;
|
|
2710
|
+
}
|
|
2711
|
+
if (version !== 13 && version !== 8) {
|
|
2712
|
+
const message = "Missing or invalid Sec-WebSocket-Version header";
|
|
2713
|
+
abortHandshakeOrEmitwsClientError(this, req, socket, 400, message, {
|
|
2714
|
+
"Sec-WebSocket-Version": "13, 8"
|
|
2715
|
+
});
|
|
2716
|
+
return;
|
|
2717
|
+
}
|
|
2718
|
+
if (!this.shouldHandle(req)) {
|
|
2719
|
+
abortHandshake(socket, 400);
|
|
2720
|
+
return;
|
|
2721
|
+
}
|
|
2722
|
+
const secWebSocketProtocol = req.headers["sec-websocket-protocol"];
|
|
2723
|
+
let protocols = new Set;
|
|
2724
|
+
if (secWebSocketProtocol !== undefined) {
|
|
2725
|
+
try {
|
|
2726
|
+
protocols = subprotocol.parse(secWebSocketProtocol);
|
|
2727
|
+
} catch (err) {
|
|
2728
|
+
const message = "Invalid Sec-WebSocket-Protocol header";
|
|
2729
|
+
abortHandshakeOrEmitwsClientError(this, req, socket, 400, message);
|
|
2730
|
+
return;
|
|
2731
|
+
}
|
|
2732
|
+
}
|
|
2733
|
+
const secWebSocketExtensions = req.headers["sec-websocket-extensions"];
|
|
2734
|
+
const extensions = {};
|
|
2735
|
+
if (this.options.perMessageDeflate && secWebSocketExtensions !== undefined) {
|
|
2736
|
+
const perMessageDeflate = new PerMessageDeflate(this.options.perMessageDeflate, true, this.options.maxPayload);
|
|
2737
|
+
try {
|
|
2738
|
+
const offers = extension.parse(secWebSocketExtensions);
|
|
2739
|
+
if (offers[PerMessageDeflate.extensionName]) {
|
|
2740
|
+
perMessageDeflate.accept(offers[PerMessageDeflate.extensionName]);
|
|
2741
|
+
extensions[PerMessageDeflate.extensionName] = perMessageDeflate;
|
|
2742
|
+
}
|
|
2743
|
+
} catch (err) {
|
|
2744
|
+
const message = "Invalid or unacceptable Sec-WebSocket-Extensions header";
|
|
2745
|
+
abortHandshakeOrEmitwsClientError(this, req, socket, 400, message);
|
|
2746
|
+
return;
|
|
2747
|
+
}
|
|
2748
|
+
}
|
|
2749
|
+
if (this.options.verifyClient) {
|
|
2750
|
+
const info = {
|
|
2751
|
+
origin: req.headers[`${version === 8 ? "sec-websocket-origin" : "origin"}`],
|
|
2752
|
+
secure: !!(req.socket.authorized || req.socket.encrypted),
|
|
2753
|
+
req
|
|
2754
|
+
};
|
|
2755
|
+
if (this.options.verifyClient.length === 2) {
|
|
2756
|
+
this.options.verifyClient(info, (verified, code, message, headers) => {
|
|
2757
|
+
if (!verified) {
|
|
2758
|
+
return abortHandshake(socket, code || 401, message, headers);
|
|
2759
|
+
}
|
|
2760
|
+
this.completeUpgrade(extensions, key, protocols, req, socket, head, cb);
|
|
2761
|
+
});
|
|
2762
|
+
return;
|
|
2763
|
+
}
|
|
2764
|
+
if (!this.options.verifyClient(info))
|
|
2765
|
+
return abortHandshake(socket, 401);
|
|
2766
|
+
}
|
|
2767
|
+
this.completeUpgrade(extensions, key, protocols, req, socket, head, cb);
|
|
2768
|
+
}
|
|
2769
|
+
completeUpgrade(extensions, key, protocols, req, socket, head, cb) {
|
|
2770
|
+
if (!socket.readable || !socket.writable)
|
|
2771
|
+
return socket.destroy();
|
|
2772
|
+
if (socket[kWebSocket]) {
|
|
2773
|
+
throw new Error("server.handleUpgrade() was called more than once with the same " + "socket, possibly due to a misconfiguration");
|
|
2774
|
+
}
|
|
2775
|
+
if (this._state > RUNNING)
|
|
2776
|
+
return abortHandshake(socket, 503);
|
|
2777
|
+
const digest = createHash("sha1").update(key + GUID).digest("base64");
|
|
2778
|
+
const headers = [
|
|
2779
|
+
"HTTP/1.1 101 Switching Protocols",
|
|
2780
|
+
"Upgrade: websocket",
|
|
2781
|
+
"Connection: Upgrade",
|
|
2782
|
+
`Sec-WebSocket-Accept: ${digest}`
|
|
2783
|
+
];
|
|
2784
|
+
const ws = new this.options.WebSocket(null, undefined, this.options);
|
|
2785
|
+
if (protocols.size) {
|
|
2786
|
+
const protocol = this.options.handleProtocols ? this.options.handleProtocols(protocols, req) : protocols.values().next().value;
|
|
2787
|
+
if (protocol) {
|
|
2788
|
+
headers.push(`Sec-WebSocket-Protocol: ${protocol}`);
|
|
2789
|
+
ws._protocol = protocol;
|
|
2790
|
+
}
|
|
2791
|
+
}
|
|
2792
|
+
if (extensions[PerMessageDeflate.extensionName]) {
|
|
2793
|
+
const params = extensions[PerMessageDeflate.extensionName].params;
|
|
2794
|
+
const value = extension.format({
|
|
2795
|
+
[PerMessageDeflate.extensionName]: [params]
|
|
2796
|
+
});
|
|
2797
|
+
headers.push(`Sec-WebSocket-Extensions: ${value}`);
|
|
2798
|
+
ws._extensions = extensions;
|
|
2799
|
+
}
|
|
2800
|
+
this.emit("headers", headers, req);
|
|
2801
|
+
socket.write(headers.concat(`\r
|
|
2802
|
+
`).join(`\r
|
|
2803
|
+
`));
|
|
2804
|
+
socket.removeListener("error", socketOnError);
|
|
2805
|
+
ws.setSocket(socket, head, {
|
|
2806
|
+
allowSynchronousEvents: this.options.allowSynchronousEvents,
|
|
2807
|
+
maxPayload: this.options.maxPayload,
|
|
2808
|
+
skipUTF8Validation: this.options.skipUTF8Validation
|
|
2809
|
+
});
|
|
2810
|
+
if (this.clients) {
|
|
2811
|
+
this.clients.add(ws);
|
|
2812
|
+
ws.on("close", () => {
|
|
2813
|
+
this.clients.delete(ws);
|
|
2814
|
+
if (this._shouldEmitClose && !this.clients.size) {
|
|
2815
|
+
process.nextTick(emitClose, this);
|
|
2816
|
+
}
|
|
2817
|
+
});
|
|
2818
|
+
}
|
|
2819
|
+
cb(ws, req);
|
|
2820
|
+
}
|
|
2821
|
+
}
|
|
2822
|
+
module.exports = WebSocketServer;
|
|
2823
|
+
function addListeners(server, map) {
|
|
2824
|
+
for (const event of Object.keys(map))
|
|
2825
|
+
server.on(event, map[event]);
|
|
2826
|
+
return function removeListeners() {
|
|
2827
|
+
for (const event of Object.keys(map)) {
|
|
2828
|
+
server.removeListener(event, map[event]);
|
|
2829
|
+
}
|
|
2830
|
+
};
|
|
2831
|
+
}
|
|
2832
|
+
function emitClose(server) {
|
|
2833
|
+
server._state = CLOSED;
|
|
2834
|
+
server.emit("close");
|
|
2835
|
+
}
|
|
2836
|
+
function socketOnError() {
|
|
2837
|
+
this.destroy();
|
|
2838
|
+
}
|
|
2839
|
+
function abortHandshake(socket, code, message, headers) {
|
|
2840
|
+
message = message || http.STATUS_CODES[code];
|
|
2841
|
+
headers = {
|
|
2842
|
+
Connection: "close",
|
|
2843
|
+
"Content-Type": "text/html",
|
|
2844
|
+
"Content-Length": Buffer.byteLength(message),
|
|
2845
|
+
...headers
|
|
2846
|
+
};
|
|
2847
|
+
socket.once("finish", socket.destroy);
|
|
2848
|
+
socket.end(`HTTP/1.1 ${code} ${http.STATUS_CODES[code]}\r
|
|
2849
|
+
` + Object.keys(headers).map((h) => `${h}: ${headers[h]}`).join(`\r
|
|
2850
|
+
`) + `\r
|
|
2851
|
+
\r
|
|
2852
|
+
` + message);
|
|
2853
|
+
}
|
|
2854
|
+
function abortHandshakeOrEmitwsClientError(server, req, socket, code, message, headers) {
|
|
2855
|
+
if (server.listenerCount("wsClientError")) {
|
|
2856
|
+
const err = new Error(message);
|
|
2857
|
+
Error.captureStackTrace(err, abortHandshakeOrEmitwsClientError);
|
|
2858
|
+
server.emit("wsClientError", err, socket, req);
|
|
2859
|
+
} else {
|
|
2860
|
+
abortHandshake(socket, code, message, headers);
|
|
2861
|
+
}
|
|
2862
|
+
}
|
|
2863
|
+
});
|
|
2864
|
+
|
|
2865
|
+
// ../../node_modules/.bun/ws@8.19.0/node_modules/ws/wrapper.mjs
|
|
2866
|
+
var import_stream = __toESM(require_stream(), 1);
|
|
2867
|
+
var import_receiver = __toESM(require_receiver(), 1);
|
|
2868
|
+
var import_sender = __toESM(require_sender(), 1);
|
|
2869
|
+
var import_websocket = __toESM(require_websocket(), 1);
|
|
2870
|
+
var import_websocket_server = __toESM(require_websocket_server(), 1);
|
|
2871
|
+
|
|
2872
|
+
// ../shared/dist/index.js
|
|
2873
|
+
import { randomUUID } from "crypto";
|
|
2874
|
+
function generateMessageId() {
|
|
2875
|
+
return `msg_${randomUUID()}`;
|
|
2876
|
+
}
|
|
2877
|
+
function generateIntentId() {
|
|
2878
|
+
return `int_${randomUUID()}`;
|
|
2879
|
+
}
|
|
2880
|
+
function generateConflictId() {
|
|
2881
|
+
return `cnf_${randomUUID()}`;
|
|
2882
|
+
}
|
|
2883
|
+
function generateSessionId() {
|
|
2884
|
+
return `ses_${randomUUID()}`;
|
|
2885
|
+
}
|
|
2886
|
+
function createMessage(type, payload) {
|
|
2887
|
+
return {
|
|
2888
|
+
type,
|
|
2889
|
+
timestamp: Date.now(),
|
|
2890
|
+
messageId: generateMessageId(),
|
|
2891
|
+
...payload
|
|
2892
|
+
};
|
|
2893
|
+
}
|
|
2894
|
+
function parseMessage(data) {
|
|
2895
|
+
try {
|
|
2896
|
+
const parsed = JSON.parse(data);
|
|
2897
|
+
if (typeof parsed.type === "string" && typeof parsed.timestamp === "number") {
|
|
2898
|
+
return parsed;
|
|
2899
|
+
}
|
|
2900
|
+
return null;
|
|
2901
|
+
} catch {
|
|
2902
|
+
return null;
|
|
2903
|
+
}
|
|
2904
|
+
}
|
|
2905
|
+
function serializeMessage(message2) {
|
|
2906
|
+
return JSON.stringify(message2);
|
|
2907
|
+
}
|
|
2908
|
+
|
|
2909
|
+
// src/state/session-manager.ts
|
|
2910
|
+
class SessionManager {
|
|
2911
|
+
sessions = new Map;
|
|
2912
|
+
addSession(sessionId, userId, username) {
|
|
2913
|
+
const session = {
|
|
2914
|
+
sessionId,
|
|
2915
|
+
userId,
|
|
2916
|
+
username,
|
|
2917
|
+
connectedAt: Date.now(),
|
|
2918
|
+
lastActiveAt: Date.now()
|
|
2919
|
+
};
|
|
2920
|
+
this.sessions.set(sessionId, session);
|
|
2921
|
+
return session;
|
|
2922
|
+
}
|
|
2923
|
+
removeSession(sessionId) {
|
|
2924
|
+
return this.sessions.delete(sessionId);
|
|
2925
|
+
}
|
|
2926
|
+
getSession(sessionId) {
|
|
2927
|
+
return this.sessions.get(sessionId);
|
|
2928
|
+
}
|
|
2929
|
+
getSessionByUserId(userId) {
|
|
2930
|
+
for (const session of this.sessions.values()) {
|
|
2931
|
+
if (session.userId === userId) {
|
|
2932
|
+
return session;
|
|
2933
|
+
}
|
|
2934
|
+
}
|
|
2935
|
+
return;
|
|
2936
|
+
}
|
|
2937
|
+
getAllSessions() {
|
|
2938
|
+
return Array.from(this.sessions.values());
|
|
2939
|
+
}
|
|
2940
|
+
updateLastActive(sessionId) {
|
|
2941
|
+
const session = this.sessions.get(sessionId);
|
|
2942
|
+
if (session) {
|
|
2943
|
+
session.lastActiveAt = Date.now();
|
|
2944
|
+
}
|
|
2945
|
+
}
|
|
2946
|
+
getActiveUserCount() {
|
|
2947
|
+
return this.sessions.size;
|
|
2948
|
+
}
|
|
2949
|
+
getActiveUsernames() {
|
|
2950
|
+
return Array.from(this.sessions.values()).map((s) => s.username);
|
|
2951
|
+
}
|
|
2952
|
+
}
|
|
2953
|
+
|
|
2954
|
+
// src/core/lock-manager.ts
|
|
2955
|
+
class LockManager {
|
|
2956
|
+
locks = new Map;
|
|
2957
|
+
acquireLock(domainId, intentId, userId, username, expiresInMs) {
|
|
2958
|
+
const existing = this.locks.get(domainId);
|
|
2959
|
+
if (existing && existing.status === "active" && existing.userId !== userId) {
|
|
2960
|
+
return null;
|
|
2961
|
+
}
|
|
2962
|
+
const lock = {
|
|
2963
|
+
domainId,
|
|
2964
|
+
intentId,
|
|
2965
|
+
userId,
|
|
2966
|
+
username,
|
|
2967
|
+
acquiredAt: Date.now(),
|
|
2968
|
+
expiresAt: expiresInMs ? Date.now() + expiresInMs : undefined,
|
|
2969
|
+
status: "active"
|
|
2970
|
+
};
|
|
2971
|
+
this.locks.set(domainId, lock);
|
|
2972
|
+
return lock;
|
|
2973
|
+
}
|
|
2974
|
+
releaseLock(domainId, userId) {
|
|
2975
|
+
const lock = this.locks.get(domainId);
|
|
2976
|
+
if (!lock || lock.userId !== userId) {
|
|
2977
|
+
return false;
|
|
2978
|
+
}
|
|
2979
|
+
lock.status = "released";
|
|
2980
|
+
this.locks.delete(domainId);
|
|
2981
|
+
return true;
|
|
2982
|
+
}
|
|
2983
|
+
releaseAllForUser(userId) {
|
|
2984
|
+
let count = 0;
|
|
2985
|
+
for (const [domainId, lock] of this.locks) {
|
|
2986
|
+
if (lock.userId === userId) {
|
|
2987
|
+
this.locks.delete(domainId);
|
|
2988
|
+
count++;
|
|
2989
|
+
}
|
|
2990
|
+
}
|
|
2991
|
+
return count;
|
|
2992
|
+
}
|
|
2993
|
+
getLockForDomain(domainId) {
|
|
2994
|
+
const lock = this.locks.get(domainId);
|
|
2995
|
+
if (lock && lock.status === "active") {
|
|
2996
|
+
if (lock.expiresAt && Date.now() > lock.expiresAt) {
|
|
2997
|
+
this.locks.delete(domainId);
|
|
2998
|
+
return;
|
|
2999
|
+
}
|
|
3000
|
+
return lock;
|
|
3001
|
+
}
|
|
3002
|
+
return;
|
|
3003
|
+
}
|
|
3004
|
+
getActiveLocks() {
|
|
3005
|
+
const now = Date.now();
|
|
3006
|
+
const active = [];
|
|
3007
|
+
for (const [domainId, lock] of this.locks) {
|
|
3008
|
+
if (lock.status === "active") {
|
|
3009
|
+
if (lock.expiresAt && now > lock.expiresAt) {
|
|
3010
|
+
this.locks.delete(domainId);
|
|
3011
|
+
} else {
|
|
3012
|
+
active.push(lock);
|
|
3013
|
+
}
|
|
3014
|
+
}
|
|
3015
|
+
}
|
|
3016
|
+
return active;
|
|
3017
|
+
}
|
|
3018
|
+
getLocksForUser(userId) {
|
|
3019
|
+
return this.getActiveLocks().filter((lock) => lock.userId === userId);
|
|
3020
|
+
}
|
|
3021
|
+
hasConflict(domainId, userId) {
|
|
3022
|
+
const lock = this.getLockForDomain(domainId);
|
|
3023
|
+
return lock !== undefined && lock.userId !== userId;
|
|
3024
|
+
}
|
|
3025
|
+
findOverlappingDomains(domains, userId) {
|
|
3026
|
+
return domains.filter((d) => this.hasConflict(d, userId));
|
|
3027
|
+
}
|
|
3028
|
+
}
|
|
3029
|
+
|
|
3030
|
+
// src/core/intent-analyzer.ts
|
|
3031
|
+
var DOMAIN_KEYWORDS = {
|
|
3032
|
+
auth: ["login", "logout", "auth", "authentication", "oauth", "session", "token", "jwt", "password", "로그인", "인증"],
|
|
3033
|
+
user: ["user", "profile", "account", "member", "사용자", "회원", "프로필"],
|
|
3034
|
+
payment: ["payment", "pay", "billing", "invoice", "checkout", "cart", "결제", "장바구니"],
|
|
3035
|
+
database: ["database", "db", "migration", "schema", "model", "entity", "데이터베이스"],
|
|
3036
|
+
api: ["api", "endpoint", "route", "controller", "rest", "graphql"],
|
|
3037
|
+
ui: ["ui", "component", "button", "form", "modal", "layout", "style", "css", "버튼", "컴포넌트"],
|
|
3038
|
+
test: ["test", "spec", "jest", "vitest", "e2e", "unit", "테스트"],
|
|
3039
|
+
config: ["config", "setting", "env", "environment", "설정"],
|
|
3040
|
+
docs: ["doc", "readme", "documentation", "문서"]
|
|
3041
|
+
};
|
|
3042
|
+
var SUBDOMAIN_KEYWORDS = {
|
|
3043
|
+
auth: {
|
|
3044
|
+
oauth: ["oauth", "google", "github", "facebook", "social"],
|
|
3045
|
+
session: ["session", "cookie"],
|
|
3046
|
+
jwt: ["jwt", "token", "refresh"]
|
|
3047
|
+
},
|
|
3048
|
+
payment: {
|
|
3049
|
+
checkout: ["checkout", "order"],
|
|
3050
|
+
subscription: ["subscription", "recurring"]
|
|
3051
|
+
}
|
|
3052
|
+
};
|
|
3053
|
+
|
|
3054
|
+
class IntentAnalyzer {
|
|
3055
|
+
analyze(prompt) {
|
|
3056
|
+
const lowerPrompt = prompt.toLowerCase();
|
|
3057
|
+
let domain = "general";
|
|
3058
|
+
let maxScore = 0;
|
|
3059
|
+
for (const [d, keywords] of Object.entries(DOMAIN_KEYWORDS)) {
|
|
3060
|
+
const score = keywords.filter((kw) => lowerPrompt.includes(kw)).length;
|
|
3061
|
+
if (score > maxScore) {
|
|
3062
|
+
maxScore = score;
|
|
3063
|
+
domain = d;
|
|
3064
|
+
}
|
|
3065
|
+
}
|
|
3066
|
+
let subdomain;
|
|
3067
|
+
const subdomains = SUBDOMAIN_KEYWORDS[domain];
|
|
3068
|
+
if (subdomains) {
|
|
3069
|
+
let subMaxScore = 0;
|
|
3070
|
+
for (const [sd, keywords] of Object.entries(subdomains)) {
|
|
3071
|
+
const score = keywords.filter((kw) => lowerPrompt.includes(kw)).length;
|
|
3072
|
+
if (score > subMaxScore) {
|
|
3073
|
+
subMaxScore = score;
|
|
3074
|
+
subdomain = sd;
|
|
3075
|
+
}
|
|
3076
|
+
}
|
|
3077
|
+
}
|
|
3078
|
+
const affectedFiles = this.extractAffectedFiles(prompt);
|
|
3079
|
+
const semanticTags = this.extractSemanticTags(lowerPrompt);
|
|
3080
|
+
const estimatedScope = this.estimateScope(prompt);
|
|
3081
|
+
return {
|
|
3082
|
+
domain,
|
|
3083
|
+
subdomain,
|
|
3084
|
+
affectedFiles,
|
|
3085
|
+
semanticTags,
|
|
3086
|
+
estimatedScope,
|
|
3087
|
+
dependencies: []
|
|
3088
|
+
};
|
|
3089
|
+
}
|
|
3090
|
+
extractAffectedFiles(prompt) {
|
|
3091
|
+
const filePatterns = [
|
|
3092
|
+
/[\w\-\/]+\.(ts|tsx|js|jsx|json|css|scss|html|md)/gi,
|
|
3093
|
+
/src\/[\w\-\/]+/gi,
|
|
3094
|
+
/pages\/[\w\-\/]+/gi,
|
|
3095
|
+
/components\/[\w\-\/]+/gi
|
|
3096
|
+
];
|
|
3097
|
+
const files = new Set;
|
|
3098
|
+
for (const pattern of filePatterns) {
|
|
3099
|
+
const matches = prompt.match(pattern);
|
|
3100
|
+
if (matches) {
|
|
3101
|
+
for (const match of matches) {
|
|
3102
|
+
files.add(match);
|
|
3103
|
+
}
|
|
3104
|
+
}
|
|
3105
|
+
}
|
|
3106
|
+
return Array.from(files);
|
|
3107
|
+
}
|
|
3108
|
+
extractSemanticTags(lowerPrompt) {
|
|
3109
|
+
const tags = [];
|
|
3110
|
+
for (const [domain, keywords] of Object.entries(DOMAIN_KEYWORDS)) {
|
|
3111
|
+
for (const kw of keywords) {
|
|
3112
|
+
if (lowerPrompt.includes(kw)) {
|
|
3113
|
+
tags.push(kw);
|
|
3114
|
+
}
|
|
3115
|
+
}
|
|
3116
|
+
}
|
|
3117
|
+
return [...new Set(tags)].slice(0, 10);
|
|
3118
|
+
}
|
|
3119
|
+
estimateScope(prompt) {
|
|
3120
|
+
const length = prompt.length;
|
|
3121
|
+
const fileCount = (prompt.match(/\.(ts|tsx|js|jsx|json|css)/gi) ?? []).length;
|
|
3122
|
+
if (length < 100 && fileCount <= 1)
|
|
3123
|
+
return "small";
|
|
3124
|
+
if (length < 300 && fileCount <= 3)
|
|
3125
|
+
return "medium";
|
|
3126
|
+
return "large";
|
|
3127
|
+
}
|
|
3128
|
+
}
|
|
3129
|
+
|
|
3130
|
+
// src/server/message-handler.ts
|
|
3131
|
+
class MessageHandler {
|
|
3132
|
+
sessionManager;
|
|
3133
|
+
lockManager;
|
|
3134
|
+
send;
|
|
3135
|
+
broadcast;
|
|
3136
|
+
intentAnalyzer;
|
|
3137
|
+
constructor(sessionManager, lockManager, send, broadcast) {
|
|
3138
|
+
this.sessionManager = sessionManager;
|
|
3139
|
+
this.lockManager = lockManager;
|
|
3140
|
+
this.send = send;
|
|
3141
|
+
this.broadcast = broadcast;
|
|
3142
|
+
this.intentAnalyzer = new IntentAnalyzer;
|
|
3143
|
+
}
|
|
3144
|
+
handle(sessionId, message) {
|
|
3145
|
+
switch (message.type) {
|
|
3146
|
+
case "agent:intent:submit":
|
|
3147
|
+
this.handleIntentSubmit(sessionId, message);
|
|
3148
|
+
break;
|
|
3149
|
+
case "agent:decision":
|
|
3150
|
+
this.handleDecision(sessionId, message);
|
|
3151
|
+
break;
|
|
3152
|
+
case "agent:heartbeat":
|
|
3153
|
+
break;
|
|
3154
|
+
default:
|
|
3155
|
+
console.warn(`[MessageHandler] Unknown message type: ${message.type}`);
|
|
3156
|
+
}
|
|
3157
|
+
}
|
|
3158
|
+
handleIntentSubmit(sessionId, message) {
|
|
3159
|
+
const session = this.sessionManager.getSession(sessionId);
|
|
3160
|
+
if (!session) {
|
|
3161
|
+
console.warn(`[MessageHandler] Session not found: ${sessionId}`);
|
|
3162
|
+
return;
|
|
3163
|
+
}
|
|
3164
|
+
const intentId = generateIntentId();
|
|
3165
|
+
const { prompt } = message.payload;
|
|
3166
|
+
const receivedMsg = createMessage("hub:intent:received", {
|
|
3167
|
+
payload: { intentId }
|
|
3168
|
+
});
|
|
3169
|
+
this.send(sessionId, receivedMsg);
|
|
3170
|
+
const analysis = this.intentAnalyzer.analyze(prompt);
|
|
3171
|
+
const domainId = `${analysis.domain}${analysis.subdomain ? ":" + analysis.subdomain : ""}`;
|
|
3172
|
+
const existingLock = this.lockManager.getLockForDomain(domainId);
|
|
3173
|
+
if (existingLock && existingLock.userId !== session.userId) {
|
|
3174
|
+
const blockedMsg = createMessage("hub:lock:blocked", {
|
|
3175
|
+
payload: {
|
|
3176
|
+
intentId,
|
|
3177
|
+
blockedBy: [{
|
|
3178
|
+
domain: domainId,
|
|
3179
|
+
username: existingLock.username,
|
|
3180
|
+
intentSummary: "Currently working on this domain"
|
|
3181
|
+
}]
|
|
3182
|
+
}
|
|
3183
|
+
});
|
|
3184
|
+
this.send(sessionId, blockedMsg);
|
|
3185
|
+
console.log(`[MessageHandler] Intent blocked: ${session.username} blocked by ${existingLock.username} on ${domainId}`);
|
|
3186
|
+
return;
|
|
3187
|
+
}
|
|
3188
|
+
this.lockManager.acquireLock(domainId, intentId, session.userId, session.username);
|
|
3189
|
+
const acquiredMsg = createMessage("hub:lock:acquired", {
|
|
3190
|
+
payload: {
|
|
3191
|
+
intentId,
|
|
3192
|
+
domains: [domainId]
|
|
3193
|
+
}
|
|
3194
|
+
});
|
|
3195
|
+
this.send(sessionId, acquiredMsg);
|
|
3196
|
+
const lockUpdateMsg = createMessage("broadcast:lock:update", {
|
|
3197
|
+
payload: {
|
|
3198
|
+
locks: this.lockManager.getActiveLocks().map((lock) => ({
|
|
3199
|
+
domainId: lock.domainId,
|
|
3200
|
+
username: lock.username,
|
|
3201
|
+
intentSummary: prompt.slice(0, 50)
|
|
3202
|
+
}))
|
|
3203
|
+
}
|
|
3204
|
+
});
|
|
3205
|
+
this.broadcast(lockUpdateMsg);
|
|
3206
|
+
console.log(`[MessageHandler] Lock acquired: ${session.username} on ${domainId}`);
|
|
3207
|
+
}
|
|
3208
|
+
handleDecision(sessionId, message) {
|
|
3209
|
+
const { conflictId, choice } = message.payload;
|
|
3210
|
+
console.log(`[MessageHandler] Decision received for conflict ${conflictId}: ${choice}`);
|
|
3211
|
+
}
|
|
3212
|
+
}
|
|
3213
|
+
|
|
3214
|
+
// src/server/hub-server.ts
|
|
3215
|
+
class HubServer {
|
|
3216
|
+
options;
|
|
3217
|
+
wss = null;
|
|
3218
|
+
clients = new Map;
|
|
3219
|
+
sessionManager;
|
|
3220
|
+
lockManager;
|
|
3221
|
+
messageHandler;
|
|
3222
|
+
constructor(options) {
|
|
3223
|
+
this.options = options;
|
|
3224
|
+
this.sessionManager = new SessionManager;
|
|
3225
|
+
this.lockManager = new LockManager;
|
|
3226
|
+
this.messageHandler = new MessageHandler(this.sessionManager, this.lockManager, this.sendToClient.bind(this), this.broadcast.bind(this));
|
|
3227
|
+
}
|
|
3228
|
+
start() {
|
|
3229
|
+
this.wss = new import_websocket_server.default({
|
|
3230
|
+
port: this.options.port,
|
|
3231
|
+
host: this.options.host ?? "0.0.0.0"
|
|
3232
|
+
});
|
|
3233
|
+
this.wss.on("connection", (socket) => {
|
|
3234
|
+
this.handleConnection(socket);
|
|
3235
|
+
});
|
|
3236
|
+
this.wss.on("error", (error) => {
|
|
3237
|
+
console.error("[Hub] Server error:", error);
|
|
3238
|
+
});
|
|
3239
|
+
console.log(`[Hub] Server started on ${this.options.host ?? "0.0.0.0"}:${this.options.port}`);
|
|
3240
|
+
}
|
|
3241
|
+
stop() {
|
|
3242
|
+
if (this.wss) {
|
|
3243
|
+
for (const client of this.clients.values()) {
|
|
3244
|
+
client.socket.close();
|
|
3245
|
+
}
|
|
3246
|
+
this.clients.clear();
|
|
3247
|
+
this.wss.close();
|
|
3248
|
+
this.wss = null;
|
|
3249
|
+
console.log("[Hub] Server stopped");
|
|
3250
|
+
}
|
|
3251
|
+
}
|
|
3252
|
+
handleConnection(socket) {
|
|
3253
|
+
const tempSessionId = generateSessionId();
|
|
3254
|
+
socket.on("message", (data) => {
|
|
3255
|
+
const message = parseMessage(data.toString());
|
|
3256
|
+
if (!message) {
|
|
3257
|
+
console.warn("[Hub] Invalid message received");
|
|
3258
|
+
return;
|
|
3259
|
+
}
|
|
3260
|
+
this.handleMessage(socket, tempSessionId, message);
|
|
3261
|
+
});
|
|
3262
|
+
socket.on("close", () => {
|
|
3263
|
+
this.handleDisconnection(tempSessionId);
|
|
3264
|
+
});
|
|
3265
|
+
socket.on("error", (error) => {
|
|
3266
|
+
console.error(`[Hub] Socket error for session ${tempSessionId}:`, error);
|
|
3267
|
+
});
|
|
3268
|
+
}
|
|
3269
|
+
handleMessage(socket, tempSessionId, message) {
|
|
3270
|
+
if (message.type === "agent:connect") {
|
|
3271
|
+
const sessionId = generateSessionId();
|
|
3272
|
+
const client2 = {
|
|
3273
|
+
socket,
|
|
3274
|
+
sessionId,
|
|
3275
|
+
userId: message.payload.userId,
|
|
3276
|
+
username: message.payload.username,
|
|
3277
|
+
projectPath: message.payload.projectPath,
|
|
3278
|
+
connectedAt: Date.now()
|
|
3279
|
+
};
|
|
3280
|
+
this.clients.set(sessionId, client2);
|
|
3281
|
+
this.sessionManager.addSession(sessionId, client2.userId, client2.username);
|
|
3282
|
+
const response = createMessage("hub:connected", {
|
|
3283
|
+
payload: {
|
|
3284
|
+
sessionId,
|
|
3285
|
+
activeLocks: this.lockManager.getActiveLocks().map((lock) => ({
|
|
3286
|
+
domainId: lock.domainId,
|
|
3287
|
+
username: lock.username
|
|
3288
|
+
}))
|
|
3289
|
+
}
|
|
3290
|
+
});
|
|
3291
|
+
this.sendToClient(sessionId, response);
|
|
3292
|
+
const joinBroadcast = createMessage("broadcast:user:joined", {
|
|
3293
|
+
payload: {
|
|
3294
|
+
userId: client2.userId,
|
|
3295
|
+
username: client2.username
|
|
3296
|
+
}
|
|
3297
|
+
});
|
|
3298
|
+
this.broadcastExcept(sessionId, joinBroadcast);
|
|
3299
|
+
console.log(`[Hub] Client connected: ${client2.username} (${sessionId})`);
|
|
3300
|
+
return;
|
|
3301
|
+
}
|
|
3302
|
+
const client = this.findClientBySocket(socket);
|
|
3303
|
+
if (!client) {
|
|
3304
|
+
console.warn("[Hub] Message from unknown client");
|
|
3305
|
+
return;
|
|
3306
|
+
}
|
|
3307
|
+
this.messageHandler.handle(client.sessionId, message);
|
|
3308
|
+
}
|
|
3309
|
+
handleDisconnection(sessionId) {
|
|
3310
|
+
const client = this.clients.get(sessionId);
|
|
3311
|
+
if (!client) {
|
|
3312
|
+
for (const [sid, c] of this.clients) {
|
|
3313
|
+
if (c.socket.readyState === import_websocket.default.CLOSED) {
|
|
3314
|
+
this.performDisconnection(sid, c);
|
|
3315
|
+
}
|
|
3316
|
+
}
|
|
3317
|
+
return;
|
|
3318
|
+
}
|
|
3319
|
+
this.performDisconnection(sessionId, client);
|
|
3320
|
+
}
|
|
3321
|
+
performDisconnection(sessionId, client) {
|
|
3322
|
+
this.lockManager.releaseAllForUser(client.userId);
|
|
3323
|
+
this.sessionManager.removeSession(sessionId);
|
|
3324
|
+
this.clients.delete(sessionId);
|
|
3325
|
+
const leaveBroadcast = createMessage("broadcast:user:left", {
|
|
3326
|
+
payload: {
|
|
3327
|
+
userId: client.userId,
|
|
3328
|
+
username: client.username
|
|
3329
|
+
}
|
|
3330
|
+
});
|
|
3331
|
+
this.broadcast(leaveBroadcast);
|
|
3332
|
+
console.log(`[Hub] Client disconnected: ${client.username} (${sessionId})`);
|
|
3333
|
+
}
|
|
3334
|
+
findClientBySocket(socket) {
|
|
3335
|
+
for (const client of this.clients.values()) {
|
|
3336
|
+
if (client.socket === socket) {
|
|
3337
|
+
return client;
|
|
3338
|
+
}
|
|
3339
|
+
}
|
|
3340
|
+
return;
|
|
3341
|
+
}
|
|
3342
|
+
sendToClient(sessionId, message) {
|
|
3343
|
+
const client = this.clients.get(sessionId);
|
|
3344
|
+
if (client && client.socket.readyState === import_websocket.default.OPEN) {
|
|
3345
|
+
client.socket.send(serializeMessage(message));
|
|
3346
|
+
}
|
|
3347
|
+
}
|
|
3348
|
+
broadcast(message) {
|
|
3349
|
+
const serialized = serializeMessage(message);
|
|
3350
|
+
for (const client of this.clients.values()) {
|
|
3351
|
+
if (client.socket.readyState === import_websocket.default.OPEN) {
|
|
3352
|
+
client.socket.send(serialized);
|
|
3353
|
+
}
|
|
3354
|
+
}
|
|
3355
|
+
}
|
|
3356
|
+
broadcastExcept(excludeSessionId, message) {
|
|
3357
|
+
const serialized = serializeMessage(message);
|
|
3358
|
+
for (const [sessionId, client] of this.clients) {
|
|
3359
|
+
if (sessionId !== excludeSessionId && client.socket.readyState === import_websocket.default.OPEN) {
|
|
3360
|
+
client.socket.send(serialized);
|
|
3361
|
+
}
|
|
3362
|
+
}
|
|
3363
|
+
}
|
|
3364
|
+
getConnectedClients() {
|
|
3365
|
+
return Array.from(this.clients.values());
|
|
3366
|
+
}
|
|
3367
|
+
getClientCount() {
|
|
3368
|
+
return this.clients.size;
|
|
3369
|
+
}
|
|
3370
|
+
}
|
|
3371
|
+
// src/llm/smart-analyzer.ts
|
|
3372
|
+
var INTENT_ANALYSIS_PROMPT = `You are an intent analyzer for a team collaboration system.
|
|
3373
|
+
Analyze the user's request and extract structured information about what they want to do.
|
|
3374
|
+
|
|
3375
|
+
Respond in JSON format with the following structure:
|
|
3376
|
+
{
|
|
3377
|
+
"domain": "main domain (e.g., auth, user, payment, database, api, ui, test, config, docs)",
|
|
3378
|
+
"subdomain": "specific subdomain if applicable (e.g., oauth, session, profile)",
|
|
3379
|
+
"affectedFiles": ["list of likely affected file paths"],
|
|
3380
|
+
"semanticTags": ["relevant keywords and concepts"],
|
|
3381
|
+
"estimatedScope": "small | medium | large",
|
|
3382
|
+
"dependencies": ["other domains this might depend on or affect"],
|
|
3383
|
+
"summary": "brief one-line summary of the intent"
|
|
3384
|
+
}
|
|
3385
|
+
|
|
3386
|
+
Consider:
|
|
3387
|
+
- What part of the system does this affect?
|
|
3388
|
+
- What files would likely be modified?
|
|
3389
|
+
- How complex is this task?
|
|
3390
|
+
- What other parts of the system might be affected?`;
|
|
3391
|
+
|
|
3392
|
+
class SmartIntentAnalyzer {
|
|
3393
|
+
provider;
|
|
3394
|
+
constructor(provider) {
|
|
3395
|
+
this.provider = provider;
|
|
3396
|
+
}
|
|
3397
|
+
async analyze(prompt, projectContext) {
|
|
3398
|
+
const messages = [
|
|
3399
|
+
{ role: "system", content: INTENT_ANALYSIS_PROMPT }
|
|
3400
|
+
];
|
|
3401
|
+
if (projectContext) {
|
|
3402
|
+
messages.push({
|
|
3403
|
+
role: "user",
|
|
3404
|
+
content: `Project context:
|
|
3405
|
+
${projectContext}
|
|
3406
|
+
|
|
3407
|
+
Now analyze this request:`
|
|
3408
|
+
});
|
|
3409
|
+
}
|
|
3410
|
+
messages.push({
|
|
3411
|
+
role: "user",
|
|
3412
|
+
content: prompt
|
|
3413
|
+
});
|
|
3414
|
+
try {
|
|
3415
|
+
const result = await this.provider.completeJSON(messages, { temperature: 0.3 });
|
|
3416
|
+
return {
|
|
3417
|
+
domain: result.domain || "general",
|
|
3418
|
+
subdomain: result.subdomain,
|
|
3419
|
+
affectedFiles: result.affectedFiles || [],
|
|
3420
|
+
semanticTags: result.semanticTags || [],
|
|
3421
|
+
estimatedScope: result.estimatedScope || "medium",
|
|
3422
|
+
dependencies: result.dependencies || [],
|
|
3423
|
+
summary: result.summary || prompt.slice(0, 50),
|
|
3424
|
+
confidence: 0.9
|
|
3425
|
+
};
|
|
3426
|
+
} catch (error) {
|
|
3427
|
+
console.error("[SmartIntentAnalyzer] LLM analysis failed, using fallback:", error);
|
|
3428
|
+
return this.fallbackAnalysis(prompt);
|
|
3429
|
+
}
|
|
3430
|
+
}
|
|
3431
|
+
fallbackAnalysis(prompt) {
|
|
3432
|
+
const lowerPrompt = prompt.toLowerCase();
|
|
3433
|
+
const domainKeywords = {
|
|
3434
|
+
auth: ["login", "logout", "auth", "oauth", "session", "token", "password", "로그인", "인증"],
|
|
3435
|
+
user: ["user", "profile", "account", "사용자", "회원", "프로필"],
|
|
3436
|
+
payment: ["payment", "pay", "billing", "checkout", "cart", "결제", "장바구니"],
|
|
3437
|
+
database: ["database", "db", "migration", "schema", "model"],
|
|
3438
|
+
api: ["api", "endpoint", "route", "controller"],
|
|
3439
|
+
ui: ["ui", "component", "button", "form", "modal", "버튼", "컴포넌트"]
|
|
3440
|
+
};
|
|
3441
|
+
let domain = "general";
|
|
3442
|
+
let maxScore = 0;
|
|
3443
|
+
for (const [d, keywords] of Object.entries(domainKeywords)) {
|
|
3444
|
+
const score = keywords.filter((kw) => lowerPrompt.includes(kw)).length;
|
|
3445
|
+
if (score > maxScore) {
|
|
3446
|
+
maxScore = score;
|
|
3447
|
+
domain = d;
|
|
3448
|
+
}
|
|
3449
|
+
}
|
|
3450
|
+
return {
|
|
3451
|
+
domain,
|
|
3452
|
+
subdomain: undefined,
|
|
3453
|
+
affectedFiles: [],
|
|
3454
|
+
semanticTags: [],
|
|
3455
|
+
estimatedScope: "medium",
|
|
3456
|
+
dependencies: [],
|
|
3457
|
+
summary: prompt.slice(0, 50),
|
|
3458
|
+
confidence: 0.5
|
|
3459
|
+
};
|
|
3460
|
+
}
|
|
3461
|
+
async checkOverlap(intent1, intent2) {
|
|
3462
|
+
const messages = [
|
|
3463
|
+
{
|
|
3464
|
+
role: "system",
|
|
3465
|
+
content: `You analyze whether two development intents might conflict with each other.
|
|
3466
|
+
Consider: shared files, shared domains, logical dependencies, potential merge conflicts.
|
|
3467
|
+
|
|
3468
|
+
Respond in JSON:
|
|
3469
|
+
{
|
|
3470
|
+
"hasOverlap": boolean,
|
|
3471
|
+
"overlapDomains": ["shared domains"],
|
|
3472
|
+
"overlapFiles": ["potentially conflicting files"],
|
|
3473
|
+
"severity": "none" | "low" | "medium" | "high",
|
|
3474
|
+
"reason": "brief explanation"
|
|
3475
|
+
}`
|
|
3476
|
+
},
|
|
3477
|
+
{
|
|
3478
|
+
role: "user",
|
|
3479
|
+
content: `Intent 1:
|
|
3480
|
+
- Domain: ${intent1.domain}${intent1.subdomain ? "/" + intent1.subdomain : ""}
|
|
3481
|
+
- Summary: ${intent1.summary}
|
|
3482
|
+
- Files: ${intent1.affectedFiles.join(", ") || "unknown"}
|
|
3483
|
+
- Tags: ${intent1.semanticTags.join(", ")}
|
|
3484
|
+
|
|
3485
|
+
Intent 2:
|
|
3486
|
+
- Domain: ${intent2.domain}${intent2.subdomain ? "/" + intent2.subdomain : ""}
|
|
3487
|
+
- Summary: ${intent2.summary}
|
|
3488
|
+
- Files: ${intent2.affectedFiles.join(", ") || "unknown"}
|
|
3489
|
+
- Tags: ${intent2.semanticTags.join(", ")}
|
|
3490
|
+
|
|
3491
|
+
Do these intents potentially conflict?`
|
|
3492
|
+
}
|
|
3493
|
+
];
|
|
3494
|
+
try {
|
|
3495
|
+
return await this.provider.completeJSON(messages, { temperature: 0.2 });
|
|
3496
|
+
} catch {
|
|
3497
|
+
const sameDomain = intent1.domain === intent2.domain;
|
|
3498
|
+
const sharedFiles = intent1.affectedFiles.filter((f) => intent2.affectedFiles.includes(f));
|
|
3499
|
+
return {
|
|
3500
|
+
hasOverlap: sameDomain || sharedFiles.length > 0,
|
|
3501
|
+
overlapDomains: sameDomain ? [intent1.domain] : [],
|
|
3502
|
+
overlapFiles: sharedFiles,
|
|
3503
|
+
severity: sameDomain ? "medium" : sharedFiles.length > 0 ? "low" : "none",
|
|
3504
|
+
reason: sameDomain ? "Same domain" : sharedFiles.length > 0 ? "Shared files" : "No overlap detected"
|
|
3505
|
+
};
|
|
3506
|
+
}
|
|
3507
|
+
}
|
|
3508
|
+
}
|
|
3509
|
+
|
|
3510
|
+
// src/llm/negotiation-engine.ts
|
|
3511
|
+
var NEGOTIATION_SYSTEM_PROMPT = `You are an AI agent helping coordinate work between team members.
|
|
3512
|
+
Two developers want to work on potentially overlapping parts of the codebase.
|
|
3513
|
+
Your job is to propose a plan that minimizes conflicts and maximizes parallel work.
|
|
3514
|
+
|
|
3515
|
+
Consider:
|
|
3516
|
+
1. Which work can be done in parallel without conflicts?
|
|
3517
|
+
2. Which work has dependencies and should be sequenced?
|
|
3518
|
+
3. Can one person define interfaces/contracts first that the other can use?
|
|
3519
|
+
4. Is there a natural order (e.g., backend before frontend)?
|
|
3520
|
+
|
|
3521
|
+
Respond in JSON:
|
|
3522
|
+
{
|
|
3523
|
+
"proposal": "brief description of your proposed approach",
|
|
3524
|
+
"suggestedOrder": ["userId who should go first", "userId who should go second"],
|
|
3525
|
+
"reasoning": "why this order makes sense",
|
|
3526
|
+
"canWorkInParallel": boolean,
|
|
3527
|
+
"parallelStrategy": "if parallel is possible, how to divide the work",
|
|
3528
|
+
"sharedInterface": "any interface/contract that should be agreed upon first"
|
|
3529
|
+
}`;
|
|
3530
|
+
|
|
3531
|
+
class NegotiationEngine {
|
|
3532
|
+
provider;
|
|
3533
|
+
activeNegotiations = new Map;
|
|
3534
|
+
constructor(provider) {
|
|
3535
|
+
this.provider = provider;
|
|
3536
|
+
}
|
|
3537
|
+
async startNegotiation(participant1, participant2) {
|
|
3538
|
+
const conflictId = generateConflictId();
|
|
3539
|
+
this.activeNegotiations.set(conflictId, {
|
|
3540
|
+
participants: [participant1, participant2],
|
|
3541
|
+
proposals: [],
|
|
3542
|
+
startedAt: Date.now()
|
|
3543
|
+
});
|
|
3544
|
+
const proposal1 = await this.getProposal(participant1, participant2);
|
|
3545
|
+
const proposal2 = await this.getProposal(participant2, participant1);
|
|
3546
|
+
const negotiation = this.activeNegotiations.get(conflictId);
|
|
3547
|
+
negotiation.proposals.push(proposal1, proposal2);
|
|
3548
|
+
const consensus = await this.findConsensus(proposal1, proposal2, participant1, participant2);
|
|
3549
|
+
this.activeNegotiations.delete(conflictId);
|
|
3550
|
+
return {
|
|
3551
|
+
conflictId,
|
|
3552
|
+
...consensus,
|
|
3553
|
+
proposals: [proposal1, proposal2]
|
|
3554
|
+
};
|
|
3555
|
+
}
|
|
3556
|
+
async getProposal(self, other) {
|
|
3557
|
+
const messages = [
|
|
3558
|
+
{ role: "system", content: NEGOTIATION_SYSTEM_PROMPT },
|
|
3559
|
+
{
|
|
3560
|
+
role: "user",
|
|
3561
|
+
content: `You are representing ${self.username} (userId: ${self.userId}).
|
|
3562
|
+
|
|
3563
|
+
Your task:
|
|
3564
|
+
- Domain: ${self.intent.domain}${self.intent.subdomain ? "/" + self.intent.subdomain : ""}
|
|
3565
|
+
- Description: ${self.prompt}
|
|
3566
|
+
- Affected files: ${self.intent.affectedFiles.join(", ") || "to be determined"}
|
|
3567
|
+
- Tags: ${self.intent.semanticTags.join(", ")}
|
|
3568
|
+
|
|
3569
|
+
Other developer's task (${other.username}, userId: ${other.userId}):
|
|
3570
|
+
- Domain: ${other.intent.domain}${other.intent.subdomain ? "/" + other.intent.subdomain : ""}
|
|
3571
|
+
- Description: ${other.prompt}
|
|
3572
|
+
- Affected files: ${other.intent.affectedFiles.join(", ") || "to be determined"}
|
|
3573
|
+
- Tags: ${other.intent.semanticTags.join(", ")}
|
|
3574
|
+
|
|
3575
|
+
Propose a plan that works best for both parties.`
|
|
3576
|
+
}
|
|
3577
|
+
];
|
|
3578
|
+
try {
|
|
3579
|
+
const result = await this.provider.completeJSON(messages, { temperature: 0.4 });
|
|
3580
|
+
return {
|
|
3581
|
+
fromUserId: self.userId,
|
|
3582
|
+
fromUsername: self.username,
|
|
3583
|
+
proposal: result.proposal,
|
|
3584
|
+
suggestedOrder: result.suggestedOrder,
|
|
3585
|
+
reasoning: result.reasoning
|
|
3586
|
+
};
|
|
3587
|
+
} catch (error) {
|
|
3588
|
+
return {
|
|
3589
|
+
fromUserId: self.userId,
|
|
3590
|
+
fromUsername: self.username,
|
|
3591
|
+
proposal: `${self.username} should complete their task first`,
|
|
3592
|
+
suggestedOrder: [self.userId, other.userId],
|
|
3593
|
+
reasoning: "Default proposal due to analysis failure"
|
|
3594
|
+
};
|
|
3595
|
+
}
|
|
3596
|
+
}
|
|
3597
|
+
async findConsensus(proposal1, proposal2, participant1, participant2) {
|
|
3598
|
+
const sameOrder = proposal1.suggestedOrder[0] === proposal2.suggestedOrder[0] && proposal1.suggestedOrder[1] === proposal2.suggestedOrder[1];
|
|
3599
|
+
if (sameOrder) {
|
|
3600
|
+
const firstUserId = proposal1.suggestedOrder[0];
|
|
3601
|
+
const secondUserId = proposal1.suggestedOrder[1];
|
|
3602
|
+
const first = firstUserId === participant1.userId ? participant1 : participant2;
|
|
3603
|
+
const second = secondUserId === participant1.userId ? participant1 : participant2;
|
|
3604
|
+
const plan = {
|
|
3605
|
+
phases: [
|
|
3606
|
+
{
|
|
3607
|
+
order: 1,
|
|
3608
|
+
intentId: `int_${first.userId}`,
|
|
3609
|
+
userId: first.userId,
|
|
3610
|
+
domains: [first.intent.domain]
|
|
3611
|
+
},
|
|
3612
|
+
{
|
|
3613
|
+
order: 2,
|
|
3614
|
+
intentId: `int_${second.userId}`,
|
|
3615
|
+
userId: second.userId,
|
|
3616
|
+
domains: [second.intent.domain],
|
|
3617
|
+
dependsOn: [`int_${first.userId}`]
|
|
3618
|
+
}
|
|
3619
|
+
]
|
|
3620
|
+
};
|
|
3621
|
+
return {
|
|
3622
|
+
status: "agreed",
|
|
3623
|
+
plan,
|
|
3624
|
+
requiresUserDecision: false
|
|
3625
|
+
};
|
|
3626
|
+
}
|
|
3627
|
+
const messages = [
|
|
3628
|
+
{
|
|
3629
|
+
role: "system",
|
|
3630
|
+
content: `Two AI agents proposed different plans for coordinating work.
|
|
3631
|
+
Determine if a compromise is possible or if human decision is needed.
|
|
3632
|
+
|
|
3633
|
+
Respond in JSON:
|
|
3634
|
+
{
|
|
3635
|
+
"canResolve": boolean,
|
|
3636
|
+
"resolution": "if can resolve, the agreed plan",
|
|
3637
|
+
"reasoning": "explanation",
|
|
3638
|
+
"firstUserId": "who should go first if resolved",
|
|
3639
|
+
"secondUserId": "who should go second if resolved"
|
|
3640
|
+
}`
|
|
3641
|
+
},
|
|
3642
|
+
{
|
|
3643
|
+
role: "user",
|
|
3644
|
+
content: `Proposal 1 from ${proposal1.fromUsername}:
|
|
3645
|
+
${proposal1.proposal}
|
|
3646
|
+
Order: ${proposal1.suggestedOrder.join(" → ")}
|
|
3647
|
+
Reasoning: ${proposal1.reasoning}
|
|
3648
|
+
|
|
3649
|
+
Proposal 2 from ${proposal2.fromUsername}:
|
|
3650
|
+
${proposal2.proposal}
|
|
3651
|
+
Order: ${proposal2.suggestedOrder.join(" → ")}
|
|
3652
|
+
Reasoning: ${proposal2.reasoning}
|
|
3653
|
+
|
|
3654
|
+
Can these be reconciled?`
|
|
3655
|
+
}
|
|
3656
|
+
];
|
|
3657
|
+
try {
|
|
3658
|
+
const result = await this.provider.completeJSON(messages, { temperature: 0.3 });
|
|
3659
|
+
if (result.canResolve && result.firstUserId && result.secondUserId) {
|
|
3660
|
+
const first = result.firstUserId === participant1.userId ? participant1 : participant2;
|
|
3661
|
+
const second = result.secondUserId === participant1.userId ? participant1 : participant2;
|
|
3662
|
+
const plan = {
|
|
3663
|
+
phases: [
|
|
3664
|
+
{
|
|
3665
|
+
order: 1,
|
|
3666
|
+
intentId: `int_${first.userId}`,
|
|
3667
|
+
userId: first.userId,
|
|
3668
|
+
domains: [first.intent.domain]
|
|
3669
|
+
},
|
|
3670
|
+
{
|
|
3671
|
+
order: 2,
|
|
3672
|
+
intentId: `int_${second.userId}`,
|
|
3673
|
+
userId: second.userId,
|
|
3674
|
+
domains: [second.intent.domain],
|
|
3675
|
+
dependsOn: [`int_${first.userId}`]
|
|
3676
|
+
}
|
|
3677
|
+
]
|
|
3678
|
+
};
|
|
3679
|
+
return {
|
|
3680
|
+
status: "agreed",
|
|
3681
|
+
plan,
|
|
3682
|
+
requiresUserDecision: false
|
|
3683
|
+
};
|
|
3684
|
+
}
|
|
3685
|
+
return {
|
|
3686
|
+
status: "disagreed",
|
|
3687
|
+
requiresUserDecision: true,
|
|
3688
|
+
disagreementReason: result.reasoning,
|
|
3689
|
+
options: [
|
|
3690
|
+
{
|
|
3691
|
+
id: "option_1",
|
|
3692
|
+
description: `${proposal1.fromUsername}'s plan: ${proposal1.proposal}`,
|
|
3693
|
+
proposedBy: proposal1.fromUsername
|
|
3694
|
+
},
|
|
3695
|
+
{
|
|
3696
|
+
id: "option_2",
|
|
3697
|
+
description: `${proposal2.fromUsername}'s plan: ${proposal2.proposal}`,
|
|
3698
|
+
proposedBy: proposal2.fromUsername
|
|
3699
|
+
}
|
|
3700
|
+
]
|
|
3701
|
+
};
|
|
3702
|
+
} catch {
|
|
3703
|
+
return {
|
|
3704
|
+
status: "disagreed",
|
|
3705
|
+
requiresUserDecision: true,
|
|
3706
|
+
disagreementReason: "Failed to reach automated consensus",
|
|
3707
|
+
options: [
|
|
3708
|
+
{
|
|
3709
|
+
id: "option_1",
|
|
3710
|
+
description: `${proposal1.fromUsername} goes first`,
|
|
3711
|
+
proposedBy: proposal1.fromUsername
|
|
3712
|
+
},
|
|
3713
|
+
{
|
|
3714
|
+
id: "option_2",
|
|
3715
|
+
description: `${proposal2.fromUsername} goes first`,
|
|
3716
|
+
proposedBy: proposal2.fromUsername
|
|
3717
|
+
}
|
|
3718
|
+
]
|
|
3719
|
+
};
|
|
3720
|
+
}
|
|
3721
|
+
}
|
|
3722
|
+
getActiveNegotiations() {
|
|
3723
|
+
return Array.from(this.activeNegotiations.keys());
|
|
3724
|
+
}
|
|
3725
|
+
}
|
|
3726
|
+
|
|
3727
|
+
// src/core/conflict-detector.ts
|
|
3728
|
+
class ConflictDetector {
|
|
3729
|
+
analyzer;
|
|
3730
|
+
activeIntents = new Map;
|
|
3731
|
+
constructor(analyzer) {
|
|
3732
|
+
this.analyzer = analyzer;
|
|
3733
|
+
}
|
|
3734
|
+
addIntent(intent) {
|
|
3735
|
+
this.activeIntents.set(intent.intentId, intent);
|
|
3736
|
+
}
|
|
3737
|
+
removeIntent(intentId) {
|
|
3738
|
+
this.activeIntents.delete(intentId);
|
|
3739
|
+
}
|
|
3740
|
+
getActiveIntents() {
|
|
3741
|
+
return Array.from(this.activeIntents.values()).filter((i) => i.status === "active");
|
|
3742
|
+
}
|
|
3743
|
+
async detectConflicts(newIntent) {
|
|
3744
|
+
const conflicts = [];
|
|
3745
|
+
const activeIntents = this.getActiveIntents();
|
|
3746
|
+
for (const existing of activeIntents) {
|
|
3747
|
+
if (existing.userId === newIntent.userId)
|
|
3748
|
+
continue;
|
|
3749
|
+
const overlap = await this.analyzer.checkOverlap(existing.analysis, newIntent.analysis);
|
|
3750
|
+
if (overlap.hasOverlap && overlap.severity !== "none") {
|
|
3751
|
+
conflicts.push({
|
|
3752
|
+
intentId1: existing.intentId,
|
|
3753
|
+
intentId2: newIntent.intentId,
|
|
3754
|
+
userId1: existing.userId,
|
|
3755
|
+
userId2: newIntent.userId,
|
|
3756
|
+
username1: existing.username,
|
|
3757
|
+
username2: newIntent.username,
|
|
3758
|
+
overlapDomains: overlap.overlapDomains,
|
|
3759
|
+
overlapFiles: overlap.overlapFiles,
|
|
3760
|
+
severity: overlap.severity,
|
|
3761
|
+
reason: overlap.reason
|
|
3762
|
+
});
|
|
3763
|
+
}
|
|
3764
|
+
}
|
|
3765
|
+
return conflicts;
|
|
3766
|
+
}
|
|
3767
|
+
quickConflictCheck(newIntent) {
|
|
3768
|
+
const conflicts = [];
|
|
3769
|
+
const activeIntents = this.getActiveIntents();
|
|
3770
|
+
for (const existing of activeIntents) {
|
|
3771
|
+
if (existing.userId === newIntent.userId)
|
|
3772
|
+
continue;
|
|
3773
|
+
const domainMatch = existing.analysis.domain === newIntent.analysis.domain;
|
|
3774
|
+
const subdomainMatch = existing.analysis.subdomain && newIntent.analysis.subdomain && existing.analysis.subdomain === newIntent.analysis.subdomain;
|
|
3775
|
+
const fileOverlap = existing.analysis.affectedFiles.filter((f) => newIntent.analysis.affectedFiles.includes(f));
|
|
3776
|
+
const tagOverlap = existing.analysis.semanticTags.filter((t) => newIntent.analysis.semanticTags.includes(t));
|
|
3777
|
+
let severity = "low";
|
|
3778
|
+
let hasConflict = false;
|
|
3779
|
+
if (subdomainMatch || fileOverlap.length > 0) {
|
|
3780
|
+
severity = "high";
|
|
3781
|
+
hasConflict = true;
|
|
3782
|
+
} else if (domainMatch) {
|
|
3783
|
+
severity = "medium";
|
|
3784
|
+
hasConflict = true;
|
|
3785
|
+
} else if (tagOverlap.length >= 3) {
|
|
3786
|
+
severity = "low";
|
|
3787
|
+
hasConflict = true;
|
|
3788
|
+
}
|
|
3789
|
+
if (hasConflict) {
|
|
3790
|
+
conflicts.push({
|
|
3791
|
+
intentId1: existing.intentId,
|
|
3792
|
+
intentId2: newIntent.intentId,
|
|
3793
|
+
userId1: existing.userId,
|
|
3794
|
+
userId2: newIntent.userId,
|
|
3795
|
+
username1: existing.username,
|
|
3796
|
+
username2: newIntent.username,
|
|
3797
|
+
overlapDomains: domainMatch ? [existing.analysis.domain] : [],
|
|
3798
|
+
overlapFiles: fileOverlap,
|
|
3799
|
+
severity,
|
|
3800
|
+
reason: subdomainMatch ? "Same subdomain" : fileOverlap.length > 0 ? "Shared files" : domainMatch ? "Same domain" : "Related tags"
|
|
3801
|
+
});
|
|
3802
|
+
}
|
|
3803
|
+
}
|
|
3804
|
+
return conflicts;
|
|
3805
|
+
}
|
|
3806
|
+
getIntentsByDomain(domain) {
|
|
3807
|
+
return this.getActiveIntents().filter((i) => i.analysis.domain === domain);
|
|
3808
|
+
}
|
|
3809
|
+
getIntentByUser(userId) {
|
|
3810
|
+
return this.getActiveIntents().find((i) => i.userId === userId);
|
|
3811
|
+
}
|
|
3812
|
+
}
|
|
3813
|
+
|
|
3814
|
+
// src/core/orchestrator.ts
|
|
3815
|
+
class Orchestrator {
|
|
3816
|
+
config;
|
|
3817
|
+
analyzer;
|
|
3818
|
+
negotiationEngine;
|
|
3819
|
+
conflictDetector;
|
|
3820
|
+
lockManager;
|
|
3821
|
+
pendingIntents = new Map;
|
|
3822
|
+
notify;
|
|
3823
|
+
constructor(provider, config, notify) {
|
|
3824
|
+
this.config = config;
|
|
3825
|
+
this.analyzer = new SmartIntentAnalyzer(provider);
|
|
3826
|
+
this.negotiationEngine = new NegotiationEngine(provider);
|
|
3827
|
+
this.conflictDetector = new ConflictDetector(this.analyzer);
|
|
3828
|
+
this.lockManager = new LockManager;
|
|
3829
|
+
this.notify = notify;
|
|
3830
|
+
}
|
|
3831
|
+
async processIntent(request) {
|
|
3832
|
+
const intentId = generateIntentId();
|
|
3833
|
+
let analysis;
|
|
3834
|
+
if (this.config.useLLMAnalysis) {
|
|
3835
|
+
analysis = await this.analyzer.analyze(request.prompt);
|
|
3836
|
+
} else {
|
|
3837
|
+
analysis = this.analyzer["fallbackAnalysis"](request.prompt);
|
|
3838
|
+
}
|
|
3839
|
+
const domainId = `${analysis.domain}${analysis.subdomain ? ":" + analysis.subdomain : ""}`;
|
|
3840
|
+
const activeIntent = {
|
|
3841
|
+
intentId,
|
|
3842
|
+
sessionId: request.sessionId,
|
|
3843
|
+
userId: request.userId,
|
|
3844
|
+
username: request.username,
|
|
3845
|
+
prompt: request.prompt,
|
|
3846
|
+
analysis,
|
|
3847
|
+
status: "active",
|
|
3848
|
+
startedAt: Date.now()
|
|
3849
|
+
};
|
|
3850
|
+
const conflicts = this.conflictDetector.quickConflictCheck(activeIntent);
|
|
3851
|
+
const significantConflicts = conflicts.filter((c) => this.config.conflictThreshold === "low" ? true : this.config.conflictThreshold === "medium" ? c.severity !== "low" : c.severity === "high");
|
|
3852
|
+
if (significantConflicts.length === 0) {
|
|
3853
|
+
this.lockManager.acquireLock(domainId, intentId, request.userId, request.username);
|
|
3854
|
+
this.conflictDetector.addIntent(activeIntent);
|
|
3855
|
+
return {
|
|
3856
|
+
intentId,
|
|
3857
|
+
status: "approved",
|
|
3858
|
+
analysis,
|
|
3859
|
+
domains: [domainId]
|
|
3860
|
+
};
|
|
3861
|
+
}
|
|
3862
|
+
const conflict = significantConflicts[0];
|
|
3863
|
+
const existingIntent = this.conflictDetector.getIntentByUser(conflict.userId1);
|
|
3864
|
+
if (!existingIntent) {
|
|
3865
|
+
this.lockManager.acquireLock(domainId, intentId, request.userId, request.username);
|
|
3866
|
+
this.conflictDetector.addIntent(activeIntent);
|
|
3867
|
+
return {
|
|
3868
|
+
intentId,
|
|
3869
|
+
status: "approved",
|
|
3870
|
+
analysis,
|
|
3871
|
+
domains: [domainId]
|
|
3872
|
+
};
|
|
3873
|
+
}
|
|
3874
|
+
if (!this.config.autoNegotiate) {
|
|
3875
|
+
return {
|
|
3876
|
+
intentId,
|
|
3877
|
+
status: "blocked",
|
|
3878
|
+
analysis,
|
|
3879
|
+
domains: [domainId],
|
|
3880
|
+
blockedBy: [{
|
|
3881
|
+
username: existingIntent.username,
|
|
3882
|
+
domain: conflict.overlapDomains[0] || domainId,
|
|
3883
|
+
reason: conflict.reason
|
|
3884
|
+
}]
|
|
3885
|
+
};
|
|
3886
|
+
}
|
|
3887
|
+
this.pendingIntents.set(intentId, activeIntent);
|
|
3888
|
+
const participant1 = {
|
|
3889
|
+
sessionId: existingIntent.sessionId,
|
|
3890
|
+
userId: existingIntent.userId,
|
|
3891
|
+
username: existingIntent.username,
|
|
3892
|
+
intent: existingIntent.analysis,
|
|
3893
|
+
prompt: existingIntent.prompt
|
|
3894
|
+
};
|
|
3895
|
+
const participant2 = {
|
|
3896
|
+
sessionId: request.sessionId,
|
|
3897
|
+
userId: request.userId,
|
|
3898
|
+
username: request.username,
|
|
3899
|
+
intent: analysis,
|
|
3900
|
+
prompt: request.prompt
|
|
3901
|
+
};
|
|
3902
|
+
this.notify(existingIntent.sessionId, "negotiation:start", {
|
|
3903
|
+
conflictId: intentId,
|
|
3904
|
+
withUser: request.username,
|
|
3905
|
+
reason: conflict.reason
|
|
3906
|
+
});
|
|
3907
|
+
const negotiationResult = await this.negotiationEngine.startNegotiation(participant1, participant2);
|
|
3908
|
+
this.pendingIntents.delete(intentId);
|
|
3909
|
+
if (negotiationResult.status === "agreed" && negotiationResult.plan) {
|
|
3910
|
+
const firstPhase = negotiationResult.plan.phases[0];
|
|
3911
|
+
const secondPhase = negotiationResult.plan.phases[1];
|
|
3912
|
+
if (firstPhase.userId === request.userId) {
|
|
3913
|
+
this.lockManager.acquireLock(domainId, intentId, request.userId, request.username);
|
|
3914
|
+
this.conflictDetector.addIntent(activeIntent);
|
|
3915
|
+
this.notify(existingIntent.sessionId, "negotiation:resolved", {
|
|
3916
|
+
conflictId: negotiationResult.conflictId,
|
|
3917
|
+
result: "wait",
|
|
3918
|
+
message: `${request.username} will go first. You'll be notified when it's your turn.`
|
|
3919
|
+
});
|
|
3920
|
+
return {
|
|
3921
|
+
intentId,
|
|
3922
|
+
status: "approved",
|
|
3923
|
+
analysis,
|
|
3924
|
+
domains: [domainId],
|
|
3925
|
+
negotiation: negotiationResult
|
|
3926
|
+
};
|
|
3927
|
+
} else {
|
|
3928
|
+
this.notify(existingIntent.sessionId, "negotiation:resolved", {
|
|
3929
|
+
conflictId: negotiationResult.conflictId,
|
|
3930
|
+
result: "proceed",
|
|
3931
|
+
message: `You can proceed first. ${request.username} will wait.`
|
|
3932
|
+
});
|
|
3933
|
+
return {
|
|
3934
|
+
intentId,
|
|
3935
|
+
status: "negotiating",
|
|
3936
|
+
analysis,
|
|
3937
|
+
domains: [domainId],
|
|
3938
|
+
negotiation: negotiationResult,
|
|
3939
|
+
blockedBy: [{
|
|
3940
|
+
username: existingIntent.username,
|
|
3941
|
+
domain: conflict.overlapDomains[0] || domainId,
|
|
3942
|
+
reason: `Negotiation resolved: ${existingIntent.username} goes first`
|
|
3943
|
+
}]
|
|
3944
|
+
};
|
|
3945
|
+
}
|
|
3946
|
+
}
|
|
3947
|
+
if (negotiationResult.requiresUserDecision) {
|
|
3948
|
+
this.notify(existingIntent.sessionId, "decision:required", {
|
|
3949
|
+
conflictId: negotiationResult.conflictId,
|
|
3950
|
+
options: negotiationResult.options,
|
|
3951
|
+
reason: negotiationResult.disagreementReason
|
|
3952
|
+
});
|
|
3953
|
+
return {
|
|
3954
|
+
intentId,
|
|
3955
|
+
status: "pending_decision",
|
|
3956
|
+
analysis,
|
|
3957
|
+
domains: [domainId],
|
|
3958
|
+
negotiation: negotiationResult
|
|
3959
|
+
};
|
|
3960
|
+
}
|
|
3961
|
+
return {
|
|
3962
|
+
intentId,
|
|
3963
|
+
status: "blocked",
|
|
3964
|
+
analysis,
|
|
3965
|
+
domains: [domainId],
|
|
3966
|
+
blockedBy: [{
|
|
3967
|
+
username: existingIntent.username,
|
|
3968
|
+
domain: conflict.overlapDomains[0] || domainId,
|
|
3969
|
+
reason: negotiationResult.disagreementReason || "Negotiation failed"
|
|
3970
|
+
}],
|
|
3971
|
+
negotiation: negotiationResult
|
|
3972
|
+
};
|
|
3973
|
+
}
|
|
3974
|
+
completeIntent(intentId, userId) {
|
|
3975
|
+
const intent = Array.from(this.conflictDetector["activeIntents"].values()).find((i) => i.intentId === intentId && i.userId === userId);
|
|
3976
|
+
if (intent) {
|
|
3977
|
+
intent.status = "completed";
|
|
3978
|
+
this.conflictDetector.removeIntent(intentId);
|
|
3979
|
+
const domainId = `${intent.analysis.domain}${intent.analysis.subdomain ? ":" + intent.analysis.subdomain : ""}`;
|
|
3980
|
+
this.lockManager.releaseLock(domainId, userId);
|
|
3981
|
+
}
|
|
3982
|
+
}
|
|
3983
|
+
getStatus() {
|
|
3984
|
+
return {
|
|
3985
|
+
activeIntents: this.conflictDetector.getActiveIntents().length,
|
|
3986
|
+
pendingNegotiations: this.pendingIntents.size,
|
|
3987
|
+
activeLocks: this.lockManager.getActiveLocks().length
|
|
3988
|
+
};
|
|
3989
|
+
}
|
|
3990
|
+
}
|
|
3991
|
+
|
|
3992
|
+
// src/server/smart-hub-server.ts
|
|
3993
|
+
class SmartHubServer {
|
|
3994
|
+
options;
|
|
3995
|
+
wss = null;
|
|
3996
|
+
clients = new Map;
|
|
3997
|
+
sessionManager;
|
|
3998
|
+
orchestrator;
|
|
3999
|
+
constructor(options) {
|
|
4000
|
+
this.options = options;
|
|
4001
|
+
this.sessionManager = new SessionManager;
|
|
4002
|
+
const orchestratorConfig = {
|
|
4003
|
+
useLLMAnalysis: options.orchestratorConfig?.useLLMAnalysis ?? true,
|
|
4004
|
+
autoNegotiate: options.orchestratorConfig?.autoNegotiate ?? true,
|
|
4005
|
+
conflictThreshold: options.orchestratorConfig?.conflictThreshold ?? "medium"
|
|
4006
|
+
};
|
|
4007
|
+
this.orchestrator = new Orchestrator(options.llmProvider, orchestratorConfig, this.sendNotification.bind(this));
|
|
4008
|
+
}
|
|
4009
|
+
start() {
|
|
4010
|
+
this.wss = new import_websocket_server.default({
|
|
4011
|
+
port: this.options.port,
|
|
4012
|
+
host: this.options.host ?? "0.0.0.0"
|
|
4013
|
+
});
|
|
4014
|
+
this.wss.on("connection", (socket) => {
|
|
4015
|
+
this.handleConnection(socket);
|
|
4016
|
+
});
|
|
4017
|
+
this.wss.on("error", (error) => {
|
|
4018
|
+
console.error("[SmartHub] Server error:", error);
|
|
4019
|
+
});
|
|
4020
|
+
console.log(`[SmartHub] Server started on ${this.options.host ?? "0.0.0.0"}:${this.options.port}`);
|
|
4021
|
+
}
|
|
4022
|
+
stop() {
|
|
4023
|
+
if (this.wss) {
|
|
4024
|
+
for (const client of this.clients.values()) {
|
|
4025
|
+
client.socket.close();
|
|
4026
|
+
}
|
|
4027
|
+
this.clients.clear();
|
|
4028
|
+
this.wss.close();
|
|
4029
|
+
this.wss = null;
|
|
4030
|
+
console.log("[SmartHub] Server stopped");
|
|
4031
|
+
}
|
|
4032
|
+
}
|
|
4033
|
+
handleConnection(socket) {
|
|
4034
|
+
const tempSessionId = generateSessionId();
|
|
4035
|
+
socket.on("message", async (data) => {
|
|
4036
|
+
const message = parseMessage(data.toString());
|
|
4037
|
+
if (!message) {
|
|
4038
|
+
console.warn("[SmartHub] Invalid message received");
|
|
4039
|
+
return;
|
|
4040
|
+
}
|
|
4041
|
+
await this.handleMessage(socket, tempSessionId, message);
|
|
4042
|
+
});
|
|
4043
|
+
socket.on("close", () => {
|
|
4044
|
+
this.handleDisconnection(socket);
|
|
4045
|
+
});
|
|
4046
|
+
socket.on("error", (error) => {
|
|
4047
|
+
console.error(`[SmartHub] Socket error:`, error);
|
|
4048
|
+
});
|
|
4049
|
+
}
|
|
4050
|
+
async handleMessage(socket, tempSessionId, message) {
|
|
4051
|
+
if (message.type === "agent:connect") {
|
|
4052
|
+
const sessionId = generateSessionId();
|
|
4053
|
+
const client2 = {
|
|
4054
|
+
socket,
|
|
4055
|
+
sessionId,
|
|
4056
|
+
userId: message.payload.userId,
|
|
4057
|
+
username: message.payload.username,
|
|
4058
|
+
projectPath: message.payload.projectPath,
|
|
4059
|
+
connectedAt: Date.now()
|
|
4060
|
+
};
|
|
4061
|
+
this.clients.set(sessionId, client2);
|
|
4062
|
+
this.sessionManager.addSession(sessionId, client2.userId, client2.username);
|
|
4063
|
+
const status = this.orchestrator.getStatus();
|
|
4064
|
+
const response = createMessage("hub:connected", {
|
|
4065
|
+
payload: {
|
|
4066
|
+
sessionId,
|
|
4067
|
+
activeLocks: []
|
|
4068
|
+
}
|
|
4069
|
+
});
|
|
4070
|
+
this.sendToClient(sessionId, response);
|
|
4071
|
+
const joinBroadcast = createMessage("broadcast:user:joined", {
|
|
4072
|
+
payload: {
|
|
4073
|
+
userId: client2.userId,
|
|
4074
|
+
username: client2.username
|
|
4075
|
+
}
|
|
4076
|
+
});
|
|
4077
|
+
this.broadcastExcept(sessionId, joinBroadcast);
|
|
4078
|
+
console.log(`[SmartHub] Client connected: ${client2.username} (${sessionId})`);
|
|
4079
|
+
return;
|
|
4080
|
+
}
|
|
4081
|
+
const client = this.findClientBySocket(socket);
|
|
4082
|
+
if (!client) {
|
|
4083
|
+
console.warn("[SmartHub] Message from unknown client");
|
|
4084
|
+
return;
|
|
4085
|
+
}
|
|
4086
|
+
if (message.type === "agent:intent:submit") {
|
|
4087
|
+
await this.handleIntentSubmit(client, message.payload.prompt);
|
|
4088
|
+
} else if (message.type === "agent:decision") {
|
|
4089
|
+
console.log(`[SmartHub] Decision from ${client.username}: ${message.payload.choice}`);
|
|
4090
|
+
}
|
|
4091
|
+
}
|
|
4092
|
+
async handleIntentSubmit(client, prompt) {
|
|
4093
|
+
const receivedMsg = createMessage("hub:intent:received", {
|
|
4094
|
+
payload: { intentId: "pending" }
|
|
4095
|
+
});
|
|
4096
|
+
this.sendToClient(client.sessionId, receivedMsg);
|
|
4097
|
+
try {
|
|
4098
|
+
const response = await this.orchestrator.processIntent({
|
|
4099
|
+
sessionId: client.sessionId,
|
|
4100
|
+
userId: client.userId,
|
|
4101
|
+
username: client.username,
|
|
4102
|
+
prompt
|
|
4103
|
+
});
|
|
4104
|
+
this.sendIntentResponse(client, response);
|
|
4105
|
+
this.broadcastLockUpdate();
|
|
4106
|
+
} catch (error) {
|
|
4107
|
+
console.error("[SmartHub] Error processing intent:", error);
|
|
4108
|
+
}
|
|
4109
|
+
}
|
|
4110
|
+
sendIntentResponse(client, response) {
|
|
4111
|
+
const analyzedMsg = createMessage("hub:intent:analyzed", {
|
|
4112
|
+
payload: {
|
|
4113
|
+
intentId: response.intentId,
|
|
4114
|
+
analysis: {
|
|
4115
|
+
domain: response.analysis.domain,
|
|
4116
|
+
subdomain: response.analysis.subdomain,
|
|
4117
|
+
affectedFiles: response.analysis.affectedFiles,
|
|
4118
|
+
semanticTags: response.analysis.semanticTags
|
|
4119
|
+
}
|
|
4120
|
+
}
|
|
4121
|
+
});
|
|
4122
|
+
this.sendToClient(client.sessionId, analyzedMsg);
|
|
4123
|
+
if (response.status === "approved") {
|
|
4124
|
+
const acquiredMsg = createMessage("hub:lock:acquired", {
|
|
4125
|
+
payload: {
|
|
4126
|
+
intentId: response.intentId,
|
|
4127
|
+
domains: response.domains
|
|
4128
|
+
}
|
|
4129
|
+
});
|
|
4130
|
+
this.sendToClient(client.sessionId, acquiredMsg);
|
|
4131
|
+
console.log(`[SmartHub] ${client.username} acquired lock on ${response.domains.join(", ")}`);
|
|
4132
|
+
} else if (response.status === "blocked") {
|
|
4133
|
+
const blockedMsg = createMessage("hub:lock:blocked", {
|
|
4134
|
+
payload: {
|
|
4135
|
+
intentId: response.intentId,
|
|
4136
|
+
blockedBy: (response.blockedBy || []).map((b) => ({
|
|
4137
|
+
domain: b.domain,
|
|
4138
|
+
username: b.username,
|
|
4139
|
+
intentSummary: b.reason
|
|
4140
|
+
}))
|
|
4141
|
+
}
|
|
4142
|
+
});
|
|
4143
|
+
this.sendToClient(client.sessionId, blockedMsg);
|
|
4144
|
+
console.log(`[SmartHub] ${client.username} blocked: ${response.blockedBy?.map((b) => b.reason).join(", ")}`);
|
|
4145
|
+
} else if (response.status === "negotiating" && response.negotiation) {
|
|
4146
|
+
if (response.negotiation.status === "agreed") {
|
|
4147
|
+
const resolvedMsg = createMessage("hub:negotiation:resolved", {
|
|
4148
|
+
payload: {
|
|
4149
|
+
conflictId: response.negotiation.conflictId,
|
|
4150
|
+
resolution: {
|
|
4151
|
+
type: "auto",
|
|
4152
|
+
summary: response.negotiation.proposals.map((p) => p.proposal).join(" / "),
|
|
4153
|
+
yourPhase: response.negotiation.plan?.phases.findIndex((p) => p.userId === client.userId) ?? 0
|
|
4154
|
+
}
|
|
4155
|
+
}
|
|
4156
|
+
});
|
|
4157
|
+
this.sendToClient(client.sessionId, resolvedMsg);
|
|
4158
|
+
}
|
|
4159
|
+
} else if (response.status === "pending_decision" && response.negotiation) {
|
|
4160
|
+
const decisionMsg = createMessage("hub:decision:required", {
|
|
4161
|
+
payload: {
|
|
4162
|
+
conflictId: response.negotiation.conflictId,
|
|
4163
|
+
question: response.negotiation.disagreementReason || "How should this conflict be resolved?",
|
|
4164
|
+
options: response.negotiation.options || []
|
|
4165
|
+
}
|
|
4166
|
+
});
|
|
4167
|
+
this.sendToClient(client.sessionId, decisionMsg);
|
|
4168
|
+
}
|
|
4169
|
+
}
|
|
4170
|
+
sendNotification(sessionId, event, data) {
|
|
4171
|
+
const client = this.clients.get(sessionId);
|
|
4172
|
+
if (!client) {
|
|
4173
|
+
for (const [sid, c] of this.clients) {
|
|
4174
|
+
if (c.sessionId === sessionId || c.userId === sessionId) {
|
|
4175
|
+
this.sendNotificationToClient(c, event, data);
|
|
4176
|
+
return;
|
|
4177
|
+
}
|
|
4178
|
+
}
|
|
4179
|
+
return;
|
|
4180
|
+
}
|
|
4181
|
+
this.sendNotificationToClient(client, event, data);
|
|
4182
|
+
}
|
|
4183
|
+
sendNotificationToClient(client, event, data) {
|
|
4184
|
+
if (event === "negotiation:start") {
|
|
4185
|
+
const msg = createMessage("hub:negotiation:start", {
|
|
4186
|
+
payload: {
|
|
4187
|
+
conflictId: data.conflictId,
|
|
4188
|
+
participants: [data.withUser],
|
|
4189
|
+
domains: []
|
|
4190
|
+
}
|
|
4191
|
+
});
|
|
4192
|
+
this.sendToClient(client.sessionId, msg);
|
|
4193
|
+
} else if (event === "negotiation:resolved") {
|
|
4194
|
+
const msg = createMessage("hub:negotiation:resolved", {
|
|
4195
|
+
payload: {
|
|
4196
|
+
conflictId: data.conflictId,
|
|
4197
|
+
resolution: {
|
|
4198
|
+
type: "auto",
|
|
4199
|
+
summary: data.message,
|
|
4200
|
+
yourPhase: data.result === "proceed" ? 1 : 2
|
|
4201
|
+
}
|
|
4202
|
+
}
|
|
4203
|
+
});
|
|
4204
|
+
this.sendToClient(client.sessionId, msg);
|
|
4205
|
+
} else if (event === "decision:required") {
|
|
4206
|
+
const msg = createMessage("hub:decision:required", {
|
|
4207
|
+
payload: {
|
|
4208
|
+
conflictId: data.conflictId,
|
|
4209
|
+
question: data.reason,
|
|
4210
|
+
options: data.options
|
|
4211
|
+
}
|
|
4212
|
+
});
|
|
4213
|
+
this.sendToClient(client.sessionId, msg);
|
|
4214
|
+
}
|
|
4215
|
+
}
|
|
4216
|
+
broadcastLockUpdate() {
|
|
4217
|
+
const status = this.orchestrator.getStatus();
|
|
4218
|
+
const msg = createMessage("broadcast:lock:update", {
|
|
4219
|
+
payload: {
|
|
4220
|
+
locks: []
|
|
4221
|
+
}
|
|
4222
|
+
});
|
|
4223
|
+
this.broadcast(msg);
|
|
4224
|
+
}
|
|
4225
|
+
handleDisconnection(socket) {
|
|
4226
|
+
for (const [sessionId, client] of this.clients) {
|
|
4227
|
+
if (client.socket === socket) {
|
|
4228
|
+
this.sessionManager.removeSession(sessionId);
|
|
4229
|
+
this.clients.delete(sessionId);
|
|
4230
|
+
const leaveBroadcast = createMessage("broadcast:user:left", {
|
|
4231
|
+
payload: {
|
|
4232
|
+
userId: client.userId,
|
|
4233
|
+
username: client.username
|
|
4234
|
+
}
|
|
4235
|
+
});
|
|
4236
|
+
this.broadcast(leaveBroadcast);
|
|
4237
|
+
console.log(`[SmartHub] Client disconnected: ${client.username} (${sessionId})`);
|
|
4238
|
+
return;
|
|
4239
|
+
}
|
|
4240
|
+
}
|
|
4241
|
+
}
|
|
4242
|
+
findClientBySocket(socket) {
|
|
4243
|
+
for (const client of this.clients.values()) {
|
|
4244
|
+
if (client.socket === socket) {
|
|
4245
|
+
return client;
|
|
4246
|
+
}
|
|
4247
|
+
}
|
|
4248
|
+
return;
|
|
4249
|
+
}
|
|
4250
|
+
sendToClient(sessionId, message) {
|
|
4251
|
+
const client = this.clients.get(sessionId);
|
|
4252
|
+
if (client && client.socket.readyState === import_websocket.default.OPEN) {
|
|
4253
|
+
client.socket.send(serializeMessage(message));
|
|
4254
|
+
}
|
|
4255
|
+
}
|
|
4256
|
+
broadcast(message) {
|
|
4257
|
+
const serialized = serializeMessage(message);
|
|
4258
|
+
for (const client of this.clients.values()) {
|
|
4259
|
+
if (client.socket.readyState === import_websocket.default.OPEN) {
|
|
4260
|
+
client.socket.send(serialized);
|
|
4261
|
+
}
|
|
4262
|
+
}
|
|
4263
|
+
}
|
|
4264
|
+
broadcastExcept(excludeSessionId, message) {
|
|
4265
|
+
const serialized = serializeMessage(message);
|
|
4266
|
+
for (const [sessionId, client] of this.clients) {
|
|
4267
|
+
if (sessionId !== excludeSessionId && client.socket.readyState === import_websocket.default.OPEN) {
|
|
4268
|
+
client.socket.send(serialized);
|
|
4269
|
+
}
|
|
4270
|
+
}
|
|
4271
|
+
}
|
|
4272
|
+
getConnectedClients() {
|
|
4273
|
+
return Array.from(this.clients.values());
|
|
4274
|
+
}
|
|
4275
|
+
getClientCount() {
|
|
4276
|
+
return this.clients.size;
|
|
4277
|
+
}
|
|
4278
|
+
getOrchestratorStatus() {
|
|
4279
|
+
return this.orchestrator.getStatus();
|
|
4280
|
+
}
|
|
4281
|
+
}
|
|
4282
|
+
// src/llm/provider.ts
|
|
4283
|
+
class OpenAIProvider {
|
|
4284
|
+
apiKey;
|
|
4285
|
+
defaultModel;
|
|
4286
|
+
name = "openai";
|
|
4287
|
+
constructor(apiKey, defaultModel = "gpt-4o-mini") {
|
|
4288
|
+
this.apiKey = apiKey;
|
|
4289
|
+
this.defaultModel = defaultModel;
|
|
4290
|
+
}
|
|
4291
|
+
async complete(messages, options) {
|
|
4292
|
+
const response = await fetch("https://api.openai.com/v1/chat/completions", {
|
|
4293
|
+
method: "POST",
|
|
4294
|
+
headers: {
|
|
4295
|
+
"Content-Type": "application/json",
|
|
4296
|
+
Authorization: `Bearer ${this.apiKey}`
|
|
4297
|
+
},
|
|
4298
|
+
body: JSON.stringify({
|
|
4299
|
+
model: options?.model ?? this.defaultModel,
|
|
4300
|
+
messages,
|
|
4301
|
+
temperature: options?.temperature ?? 0.7,
|
|
4302
|
+
max_tokens: options?.maxTokens ?? 2048
|
|
4303
|
+
})
|
|
4304
|
+
});
|
|
4305
|
+
if (!response.ok) {
|
|
4306
|
+
const error = await response.text();
|
|
4307
|
+
throw new Error(`OpenAI API error: ${response.status} - ${error}`);
|
|
4308
|
+
}
|
|
4309
|
+
const data = await response.json();
|
|
4310
|
+
return {
|
|
4311
|
+
content: data.choices[0].message.content,
|
|
4312
|
+
model: data.model,
|
|
4313
|
+
usage: data.usage ? {
|
|
4314
|
+
promptTokens: data.usage.prompt_tokens,
|
|
4315
|
+
completionTokens: data.usage.completion_tokens,
|
|
4316
|
+
totalTokens: data.usage.total_tokens
|
|
4317
|
+
} : undefined
|
|
4318
|
+
};
|
|
4319
|
+
}
|
|
4320
|
+
async completeJSON(messages, options) {
|
|
4321
|
+
const response = await fetch("https://api.openai.com/v1/chat/completions", {
|
|
4322
|
+
method: "POST",
|
|
4323
|
+
headers: {
|
|
4324
|
+
"Content-Type": "application/json",
|
|
4325
|
+
Authorization: `Bearer ${this.apiKey}`
|
|
4326
|
+
},
|
|
4327
|
+
body: JSON.stringify({
|
|
4328
|
+
model: options?.model ?? this.defaultModel,
|
|
4329
|
+
messages,
|
|
4330
|
+
temperature: options?.temperature ?? 0.3,
|
|
4331
|
+
max_tokens: options?.maxTokens ?? 2048,
|
|
4332
|
+
response_format: { type: "json_object" }
|
|
4333
|
+
})
|
|
4334
|
+
});
|
|
4335
|
+
if (!response.ok) {
|
|
4336
|
+
const error = await response.text();
|
|
4337
|
+
throw new Error(`OpenAI API error: ${response.status} - ${error}`);
|
|
4338
|
+
}
|
|
4339
|
+
const data = await response.json();
|
|
4340
|
+
return JSON.parse(data.choices[0].message.content);
|
|
4341
|
+
}
|
|
4342
|
+
}
|
|
4343
|
+
|
|
4344
|
+
class AnthropicProvider {
|
|
4345
|
+
apiKey;
|
|
4346
|
+
defaultModel;
|
|
4347
|
+
name = "anthropic";
|
|
4348
|
+
constructor(apiKey, defaultModel = "claude-3-5-sonnet-20241022") {
|
|
4349
|
+
this.apiKey = apiKey;
|
|
4350
|
+
this.defaultModel = defaultModel;
|
|
4351
|
+
}
|
|
4352
|
+
async complete(messages, options) {
|
|
4353
|
+
const systemMessage = messages.find((m) => m.role === "system");
|
|
4354
|
+
const otherMessages = messages.filter((m) => m.role !== "system");
|
|
4355
|
+
const response = await fetch("https://api.anthropic.com/v1/messages", {
|
|
4356
|
+
method: "POST",
|
|
4357
|
+
headers: {
|
|
4358
|
+
"Content-Type": "application/json",
|
|
4359
|
+
"x-api-key": this.apiKey,
|
|
4360
|
+
"anthropic-version": "2023-06-01"
|
|
4361
|
+
},
|
|
4362
|
+
body: JSON.stringify({
|
|
4363
|
+
model: options?.model ?? this.defaultModel,
|
|
4364
|
+
max_tokens: options?.maxTokens ?? 2048,
|
|
4365
|
+
system: systemMessage?.content,
|
|
4366
|
+
messages: otherMessages.map((m) => ({
|
|
4367
|
+
role: m.role,
|
|
4368
|
+
content: m.content
|
|
4369
|
+
}))
|
|
4370
|
+
})
|
|
4371
|
+
});
|
|
4372
|
+
if (!response.ok) {
|
|
4373
|
+
const error = await response.text();
|
|
4374
|
+
throw new Error(`Anthropic API error: ${response.status} - ${error}`);
|
|
4375
|
+
}
|
|
4376
|
+
const data = await response.json();
|
|
4377
|
+
return {
|
|
4378
|
+
content: data.content[0].text,
|
|
4379
|
+
model: data.model,
|
|
4380
|
+
usage: data.usage ? {
|
|
4381
|
+
promptTokens: data.usage.input_tokens,
|
|
4382
|
+
completionTokens: data.usage.output_tokens,
|
|
4383
|
+
totalTokens: data.usage.input_tokens + data.usage.output_tokens
|
|
4384
|
+
} : undefined
|
|
4385
|
+
};
|
|
4386
|
+
}
|
|
4387
|
+
async completeJSON(messages, options) {
|
|
4388
|
+
const result = await this.complete([
|
|
4389
|
+
...messages,
|
|
4390
|
+
{ role: "assistant", content: "{" }
|
|
4391
|
+
], options);
|
|
4392
|
+
const jsonStr = "{" + result.content;
|
|
4393
|
+
return JSON.parse(jsonStr);
|
|
4394
|
+
}
|
|
4395
|
+
}
|
|
4396
|
+
|
|
4397
|
+
class MockProvider {
|
|
4398
|
+
name = "mock";
|
|
4399
|
+
async complete(messages) {
|
|
4400
|
+
const lastMessage = messages[messages.length - 1];
|
|
4401
|
+
return {
|
|
4402
|
+
content: `Mock response to: ${lastMessage?.content.slice(0, 50)}...`,
|
|
4403
|
+
model: "mock-model"
|
|
4404
|
+
};
|
|
4405
|
+
}
|
|
4406
|
+
async completeJSON() {
|
|
4407
|
+
return {};
|
|
4408
|
+
}
|
|
4409
|
+
}
|
|
4410
|
+
function createProvider(type, apiKey) {
|
|
4411
|
+
switch (type) {
|
|
4412
|
+
case "openai":
|
|
4413
|
+
if (!apiKey)
|
|
4414
|
+
throw new Error("OpenAI API key required");
|
|
4415
|
+
return new OpenAIProvider(apiKey);
|
|
4416
|
+
case "anthropic":
|
|
4417
|
+
if (!apiKey)
|
|
4418
|
+
throw new Error("Anthropic API key required");
|
|
4419
|
+
return new AnthropicProvider(apiKey);
|
|
4420
|
+
case "mock":
|
|
4421
|
+
return new MockProvider;
|
|
4422
|
+
default:
|
|
4423
|
+
throw new Error(`Unknown provider type: ${type}`);
|
|
4424
|
+
}
|
|
4425
|
+
}
|
|
4426
|
+
// src/api/dashboard.ts
|
|
4427
|
+
import { createServer } from "http";
|
|
4428
|
+
|
|
4429
|
+
class DashboardApi {
|
|
4430
|
+
options;
|
|
4431
|
+
server = null;
|
|
4432
|
+
constructor(options) {
|
|
4433
|
+
this.options = options;
|
|
4434
|
+
}
|
|
4435
|
+
start() {
|
|
4436
|
+
this.server = createServer((req, res) => {
|
|
4437
|
+
this.handleRequest(req, res);
|
|
4438
|
+
});
|
|
4439
|
+
this.server.listen(this.options.port, () => {
|
|
4440
|
+
console.log(`[Dashboard] API running on http://localhost:${this.options.port}`);
|
|
4441
|
+
});
|
|
4442
|
+
}
|
|
4443
|
+
stop() {
|
|
4444
|
+
if (this.server) {
|
|
4445
|
+
this.server.close();
|
|
4446
|
+
this.server = null;
|
|
4447
|
+
}
|
|
4448
|
+
}
|
|
4449
|
+
handleRequest(req, res) {
|
|
4450
|
+
res.setHeader("Access-Control-Allow-Origin", "*");
|
|
4451
|
+
res.setHeader("Access-Control-Allow-Methods", "GET, OPTIONS");
|
|
4452
|
+
res.setHeader("Access-Control-Allow-Headers", "Content-Type");
|
|
4453
|
+
if (req.method === "OPTIONS") {
|
|
4454
|
+
res.writeHead(204);
|
|
4455
|
+
res.end();
|
|
4456
|
+
return;
|
|
4457
|
+
}
|
|
4458
|
+
const url = new URL(req.url ?? "/", `http://localhost:${this.options.port}`);
|
|
4459
|
+
if (url.pathname === "/api/status") {
|
|
4460
|
+
this.handleStatus(res);
|
|
4461
|
+
} else if (url.pathname === "/api/clients") {
|
|
4462
|
+
this.handleClients(res);
|
|
4463
|
+
} else if (url.pathname === "/") {
|
|
4464
|
+
this.handleDashboard(res);
|
|
4465
|
+
} else {
|
|
4466
|
+
res.writeHead(404, { "Content-Type": "application/json" });
|
|
4467
|
+
res.end(JSON.stringify({ error: "Not found" }));
|
|
4468
|
+
}
|
|
4469
|
+
}
|
|
4470
|
+
handleStatus(res) {
|
|
4471
|
+
const status = this.options.hubServer.getOrchestratorStatus();
|
|
4472
|
+
const clients = this.options.hubServer.getConnectedClients();
|
|
4473
|
+
res.writeHead(200, { "Content-Type": "application/json" });
|
|
4474
|
+
res.end(JSON.stringify({
|
|
4475
|
+
status: "running",
|
|
4476
|
+
orchestrator: status,
|
|
4477
|
+
connectedUsers: clients.length,
|
|
4478
|
+
users: clients.map((c) => ({
|
|
4479
|
+
username: c.username,
|
|
4480
|
+
connectedAt: c.connectedAt
|
|
4481
|
+
}))
|
|
4482
|
+
}));
|
|
4483
|
+
}
|
|
4484
|
+
handleClients(res) {
|
|
4485
|
+
const clients = this.options.hubServer.getConnectedClients();
|
|
4486
|
+
res.writeHead(200, { "Content-Type": "application/json" });
|
|
4487
|
+
res.end(JSON.stringify({
|
|
4488
|
+
count: clients.length,
|
|
4489
|
+
clients: clients.map((c) => ({
|
|
4490
|
+
sessionId: c.sessionId,
|
|
4491
|
+
userId: c.userId,
|
|
4492
|
+
username: c.username,
|
|
4493
|
+
projectPath: c.projectPath,
|
|
4494
|
+
connectedAt: c.connectedAt,
|
|
4495
|
+
connectedFor: Math.round((Date.now() - c.connectedAt) / 1000)
|
|
4496
|
+
}))
|
|
4497
|
+
}));
|
|
4498
|
+
}
|
|
4499
|
+
handleDashboard(res) {
|
|
4500
|
+
res.writeHead(200, { "Content-Type": "text/html" });
|
|
4501
|
+
res.end(DASHBOARD_HTML);
|
|
4502
|
+
}
|
|
4503
|
+
}
|
|
4504
|
+
var DASHBOARD_HTML = `<!DOCTYPE html>
|
|
4505
|
+
<html lang="en">
|
|
4506
|
+
<head>
|
|
4507
|
+
<meta charset="UTF-8">
|
|
4508
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
4509
|
+
<title>Intent Hub Dashboard</title>
|
|
4510
|
+
<style>
|
|
4511
|
+
* { margin: 0; padding: 0; box-sizing: border-box; }
|
|
4512
|
+
body {
|
|
4513
|
+
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
|
|
4514
|
+
background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
|
|
4515
|
+
color: #e4e4e4;
|
|
4516
|
+
min-height: 100vh;
|
|
4517
|
+
padding: 2rem;
|
|
4518
|
+
}
|
|
4519
|
+
.container { max-width: 1200px; margin: 0 auto; }
|
|
4520
|
+
h1 {
|
|
4521
|
+
font-size: 2.5rem;
|
|
4522
|
+
margin-bottom: 0.5rem;
|
|
4523
|
+
background: linear-gradient(90deg, #00d9ff, #00ff88);
|
|
4524
|
+
-webkit-background-clip: text;
|
|
4525
|
+
-webkit-text-fill-color: transparent;
|
|
4526
|
+
}
|
|
4527
|
+
.subtitle { color: #888; margin-bottom: 2rem; }
|
|
4528
|
+
.grid {
|
|
4529
|
+
display: grid;
|
|
4530
|
+
grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
|
|
4531
|
+
gap: 1.5rem;
|
|
4532
|
+
margin-bottom: 2rem;
|
|
4533
|
+
}
|
|
4534
|
+
.card {
|
|
4535
|
+
background: rgba(255,255,255,0.05);
|
|
4536
|
+
border: 1px solid rgba(255,255,255,0.1);
|
|
4537
|
+
border-radius: 12px;
|
|
4538
|
+
padding: 1.5rem;
|
|
4539
|
+
}
|
|
4540
|
+
.card h2 {
|
|
4541
|
+
font-size: 1rem;
|
|
4542
|
+
color: #888;
|
|
4543
|
+
margin-bottom: 1rem;
|
|
4544
|
+
text-transform: uppercase;
|
|
4545
|
+
letter-spacing: 1px;
|
|
4546
|
+
}
|
|
4547
|
+
.stat {
|
|
4548
|
+
font-size: 3rem;
|
|
4549
|
+
font-weight: bold;
|
|
4550
|
+
color: #00ff88;
|
|
4551
|
+
}
|
|
4552
|
+
.stat.warn { color: #ffaa00; }
|
|
4553
|
+
.stat.error { color: #ff4444; }
|
|
4554
|
+
.user-list { list-style: none; }
|
|
4555
|
+
.user-item {
|
|
4556
|
+
display: flex;
|
|
4557
|
+
align-items: center;
|
|
4558
|
+
padding: 0.75rem;
|
|
4559
|
+
background: rgba(255,255,255,0.03);
|
|
4560
|
+
border-radius: 8px;
|
|
4561
|
+
margin-bottom: 0.5rem;
|
|
4562
|
+
}
|
|
4563
|
+
.user-avatar {
|
|
4564
|
+
width: 40px;
|
|
4565
|
+
height: 40px;
|
|
4566
|
+
border-radius: 50%;
|
|
4567
|
+
background: linear-gradient(135deg, #00d9ff, #00ff88);
|
|
4568
|
+
display: flex;
|
|
4569
|
+
align-items: center;
|
|
4570
|
+
justify-content: center;
|
|
4571
|
+
font-weight: bold;
|
|
4572
|
+
margin-right: 1rem;
|
|
4573
|
+
}
|
|
4574
|
+
.user-info { flex: 1; }
|
|
4575
|
+
.user-name { font-weight: 500; }
|
|
4576
|
+
.user-time { font-size: 0.85rem; color: #888; }
|
|
4577
|
+
.status-badge {
|
|
4578
|
+
padding: 0.25rem 0.75rem;
|
|
4579
|
+
border-radius: 20px;
|
|
4580
|
+
font-size: 0.75rem;
|
|
4581
|
+
text-transform: uppercase;
|
|
4582
|
+
}
|
|
4583
|
+
.status-active {
|
|
4584
|
+
background: rgba(0,255,136,0.2);
|
|
4585
|
+
color: #00ff88;
|
|
4586
|
+
}
|
|
4587
|
+
.refresh-btn {
|
|
4588
|
+
background: rgba(0,217,255,0.2);
|
|
4589
|
+
color: #00d9ff;
|
|
4590
|
+
border: 1px solid rgba(0,217,255,0.3);
|
|
4591
|
+
padding: 0.5rem 1rem;
|
|
4592
|
+
border-radius: 6px;
|
|
4593
|
+
cursor: pointer;
|
|
4594
|
+
font-size: 0.9rem;
|
|
4595
|
+
}
|
|
4596
|
+
.refresh-btn:hover { background: rgba(0,217,255,0.3); }
|
|
4597
|
+
.empty { color: #666; font-style: italic; padding: 1rem; }
|
|
4598
|
+
</style>
|
|
4599
|
+
</head>
|
|
4600
|
+
<body>
|
|
4601
|
+
<div class="container">
|
|
4602
|
+
<h1>Intent Hub</h1>
|
|
4603
|
+
<p class="subtitle">Team-based LLM Coordination Platform</p>
|
|
4604
|
+
|
|
4605
|
+
<div class="grid">
|
|
4606
|
+
<div class="card">
|
|
4607
|
+
<h2>Connected Users</h2>
|
|
4608
|
+
<div class="stat" id="userCount">-</div>
|
|
4609
|
+
</div>
|
|
4610
|
+
<div class="card">
|
|
4611
|
+
<h2>Active Intents</h2>
|
|
4612
|
+
<div class="stat" id="intentCount">-</div>
|
|
4613
|
+
</div>
|
|
4614
|
+
<div class="card">
|
|
4615
|
+
<h2>Active Locks</h2>
|
|
4616
|
+
<div class="stat" id="lockCount">-</div>
|
|
4617
|
+
</div>
|
|
4618
|
+
</div>
|
|
4619
|
+
|
|
4620
|
+
<div class="card">
|
|
4621
|
+
<h2>Team Members</h2>
|
|
4622
|
+
<button class="refresh-btn" onclick="refresh()">Refresh</button>
|
|
4623
|
+
<ul class="user-list" id="userList">
|
|
4624
|
+
<li class="empty">No users connected</li>
|
|
4625
|
+
</ul>
|
|
4626
|
+
</div>
|
|
4627
|
+
</div>
|
|
4628
|
+
|
|
4629
|
+
<script>
|
|
4630
|
+
async function refresh() {
|
|
4631
|
+
try {
|
|
4632
|
+
const res = await fetch('/api/status');
|
|
4633
|
+
const data = await res.json();
|
|
4634
|
+
|
|
4635
|
+
document.getElementById('userCount').textContent = data.connectedUsers;
|
|
4636
|
+
document.getElementById('intentCount').textContent = data.orchestrator.activeIntents;
|
|
4637
|
+
document.getElementById('lockCount').textContent = data.orchestrator.activeLocks;
|
|
4638
|
+
|
|
4639
|
+
const list = document.getElementById('userList');
|
|
4640
|
+
if (data.users.length === 0) {
|
|
4641
|
+
list.innerHTML = '<li class="empty">No users connected</li>';
|
|
4642
|
+
} else {
|
|
4643
|
+
list.innerHTML = data.users.map(u => \`
|
|
4644
|
+
<li class="user-item">
|
|
4645
|
+
<div class="user-avatar">\${u.username[0].toUpperCase()}</div>
|
|
4646
|
+
<div class="user-info">
|
|
4647
|
+
<div class="user-name">\${u.username}</div>
|
|
4648
|
+
<div class="user-time">Connected \${formatTime(u.connectedAt)}</div>
|
|
4649
|
+
</div>
|
|
4650
|
+
<span class="status-badge status-active">Active</span>
|
|
4651
|
+
</li>
|
|
4652
|
+
\`).join('');
|
|
4653
|
+
}
|
|
4654
|
+
} catch (e) {
|
|
4655
|
+
console.error('Failed to fetch status:', e);
|
|
4656
|
+
}
|
|
4657
|
+
}
|
|
4658
|
+
|
|
4659
|
+
function formatTime(ts) {
|
|
4660
|
+
const diff = Math.round((Date.now() - ts) / 1000);
|
|
4661
|
+
if (diff < 60) return diff + 's ago';
|
|
4662
|
+
if (diff < 3600) return Math.round(diff/60) + 'm ago';
|
|
4663
|
+
return Math.round(diff/3600) + 'h ago';
|
|
4664
|
+
}
|
|
4665
|
+
|
|
4666
|
+
refresh();
|
|
4667
|
+
setInterval(refresh, 5000);
|
|
4668
|
+
</script>
|
|
4669
|
+
</body>
|
|
4670
|
+
</html>`;
|
|
4671
|
+
export {
|
|
4672
|
+
createProvider,
|
|
4673
|
+
SmartIntentAnalyzer,
|
|
4674
|
+
SmartHubServer,
|
|
4675
|
+
SessionManager,
|
|
4676
|
+
Orchestrator,
|
|
4677
|
+
OpenAIProvider,
|
|
4678
|
+
NegotiationEngine,
|
|
4679
|
+
MockProvider,
|
|
4680
|
+
LockManager,
|
|
4681
|
+
IntentAnalyzer,
|
|
4682
|
+
HubServer,
|
|
4683
|
+
DashboardApi,
|
|
4684
|
+
ConflictDetector,
|
|
4685
|
+
AnthropicProvider
|
|
4686
|
+
};
|