Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- .gitattributes +2 -0
- platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/wrap-ansi-cjs/node_modules/ansi-regex/package.json +55 -0
- platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/wrap-ansi-cjs/node_modules/ansi-regex/readme.md +78 -0
- platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/wrap-ansi-cjs/node_modules/ansi-styles/index.d.ts +345 -0
- platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/wrap-ansi-cjs/node_modules/ansi-styles/index.js +163 -0
- platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/wrap-ansi-cjs/node_modules/ansi-styles/license +9 -0
- platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/wrap-ansi-cjs/node_modules/ansi-styles/package.json +56 -0
- platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/wrap-ansi-cjs/node_modules/ansi-styles/readme.md +152 -0
- platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/wrap-ansi-cjs/node_modules/emoji-regex/LICENSE-MIT.txt +20 -0
- platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/wrap-ansi-cjs/node_modules/emoji-regex/README.md +73 -0
- platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/wrap-ansi-cjs/node_modules/emoji-regex/es2015/index.js +6 -0
- platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/wrap-ansi-cjs/node_modules/emoji-regex/es2015/text.js +6 -0
- platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/wrap-ansi-cjs/node_modules/emoji-regex/index.d.ts +23 -0
- platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/wrap-ansi-cjs/node_modules/emoji-regex/index.js +6 -0
- platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/wrap-ansi-cjs/node_modules/emoji-regex/package.json +50 -0
- platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/wrap-ansi-cjs/node_modules/emoji-regex/text.js +6 -0
- platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/wrap-ansi-cjs/node_modules/string-width/index.d.ts +29 -0
- platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/wrap-ansi-cjs/node_modules/string-width/index.js +47 -0
- platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/wrap-ansi-cjs/node_modules/string-width/license +9 -0
- platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/wrap-ansi-cjs/node_modules/string-width/package.json +56 -0
- platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/wrap-ansi-cjs/node_modules/string-width/readme.md +50 -0
- platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/wrap-ansi-cjs/node_modules/strip-ansi/index.d.ts +17 -0
- platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/wrap-ansi-cjs/node_modules/strip-ansi/index.js +4 -0
- platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/wrap-ansi-cjs/node_modules/strip-ansi/license +9 -0
- platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/wrap-ansi-cjs/node_modules/strip-ansi/package.json +54 -0
- platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/wrap-ansi-cjs/node_modules/strip-ansi/readme.md +46 -0
- platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/ws/lib/buffer-util.js +131 -0
- platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/ws/lib/constants.js +18 -0
- platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/ws/lib/event-target.js +292 -0
- platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/ws/lib/extension.js +203 -0
- platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/ws/lib/limiter.js +55 -0
- platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/ws/lib/permessage-deflate.js +528 -0
- platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/ws/lib/receiver.js +706 -0
- platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/ws/lib/sender.js +602 -0
- platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/ws/lib/stream.js +161 -0
- platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/ws/lib/subprotocol.js +62 -0
- platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/ws/lib/validation.js +152 -0
- platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/ws/lib/websocket-server.js +550 -0
- platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/ws/lib/websocket.js +1388 -0
- platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/src/middleware/auth.ts +92 -0
- platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/src/utils/cache.ts +47 -0
- platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/src/utils/close.ts +27 -0
- platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/src/utils/codeCommand.ts +96 -0
- platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/src/utils/index.ts +167 -0
- platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/src/utils/log.ts +45 -0
- platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/src/utils/logCleanup.ts +44 -0
- platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/src/utils/processCheck.ts +88 -0
- platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/src/utils/router.ts +178 -0
- platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/src/utils/status.ts +27 -0
- platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/src/utils/statusline.ts +813 -0
.gitattributes
CHANGED
|
@@ -1942,3 +1942,5 @@ platform/dbops/archive/databases_old/data/home/x/.npm/_cacache/content-v2/sha512
|
|
| 1942 |
platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/elizabeth_chroma/chroma.sqlite3 filter=lfs diff=lfs merge=lfs -text
|
| 1943 |
platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/@esbuild/linux-x64/bin/esbuild filter=lfs diff=lfs merge=lfs -text
|
| 1944 |
platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/esbuild/bin/esbuild filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
| 1942 |
platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/elizabeth_chroma/chroma.sqlite3 filter=lfs diff=lfs merge=lfs -text
|
| 1943 |
platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/@esbuild/linux-x64/bin/esbuild filter=lfs diff=lfs merge=lfs -text
|
| 1944 |
platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/esbuild/bin/esbuild filter=lfs diff=lfs merge=lfs -text
|
| 1945 |
+
platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/ui/node_modules/lightningcss-linux-x64-gnu/lightningcss.linux-x64-gnu.node filter=lfs diff=lfs merge=lfs -text
|
| 1946 |
+
platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/ui/node_modules/lightningcss-linux-x64-musl/lightningcss.linux-x64-musl.node filter=lfs diff=lfs merge=lfs -text
|
platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/wrap-ansi-cjs/node_modules/ansi-regex/package.json
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "ansi-regex",
|
| 3 |
+
"version": "5.0.1",
|
| 4 |
+
"description": "Regular expression for matching ANSI escape codes",
|
| 5 |
+
"license": "MIT",
|
| 6 |
+
"repository": "chalk/ansi-regex",
|
| 7 |
+
"author": {
|
| 8 |
+
"name": "Sindre Sorhus",
|
| 9 |
+
"email": "sindresorhus@gmail.com",
|
| 10 |
+
"url": "sindresorhus.com"
|
| 11 |
+
},
|
| 12 |
+
"engines": {
|
| 13 |
+
"node": ">=8"
|
| 14 |
+
},
|
| 15 |
+
"scripts": {
|
| 16 |
+
"test": "xo && ava && tsd",
|
| 17 |
+
"view-supported": "node fixtures/view-codes.js"
|
| 18 |
+
},
|
| 19 |
+
"files": [
|
| 20 |
+
"index.js",
|
| 21 |
+
"index.d.ts"
|
| 22 |
+
],
|
| 23 |
+
"keywords": [
|
| 24 |
+
"ansi",
|
| 25 |
+
"styles",
|
| 26 |
+
"color",
|
| 27 |
+
"colour",
|
| 28 |
+
"colors",
|
| 29 |
+
"terminal",
|
| 30 |
+
"console",
|
| 31 |
+
"cli",
|
| 32 |
+
"string",
|
| 33 |
+
"tty",
|
| 34 |
+
"escape",
|
| 35 |
+
"formatting",
|
| 36 |
+
"rgb",
|
| 37 |
+
"256",
|
| 38 |
+
"shell",
|
| 39 |
+
"xterm",
|
| 40 |
+
"command-line",
|
| 41 |
+
"text",
|
| 42 |
+
"regex",
|
| 43 |
+
"regexp",
|
| 44 |
+
"re",
|
| 45 |
+
"match",
|
| 46 |
+
"test",
|
| 47 |
+
"find",
|
| 48 |
+
"pattern"
|
| 49 |
+
],
|
| 50 |
+
"devDependencies": {
|
| 51 |
+
"ava": "^2.4.0",
|
| 52 |
+
"tsd": "^0.9.0",
|
| 53 |
+
"xo": "^0.25.3"
|
| 54 |
+
}
|
| 55 |
+
}
|
platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/wrap-ansi-cjs/node_modules/ansi-regex/readme.md
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# ansi-regex
|
| 2 |
+
|
| 3 |
+
> Regular expression for matching [ANSI escape codes](https://en.wikipedia.org/wiki/ANSI_escape_code)
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
## Install
|
| 7 |
+
|
| 8 |
+
```
|
| 9 |
+
$ npm install ansi-regex
|
| 10 |
+
```
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
## Usage
|
| 14 |
+
|
| 15 |
+
```js
|
| 16 |
+
const ansiRegex = require('ansi-regex');
|
| 17 |
+
|
| 18 |
+
ansiRegex().test('\u001B[4mcake\u001B[0m');
|
| 19 |
+
//=> true
|
| 20 |
+
|
| 21 |
+
ansiRegex().test('cake');
|
| 22 |
+
//=> false
|
| 23 |
+
|
| 24 |
+
'\u001B[4mcake\u001B[0m'.match(ansiRegex());
|
| 25 |
+
//=> ['\u001B[4m', '\u001B[0m']
|
| 26 |
+
|
| 27 |
+
'\u001B[4mcake\u001B[0m'.match(ansiRegex({onlyFirst: true}));
|
| 28 |
+
//=> ['\u001B[4m']
|
| 29 |
+
|
| 30 |
+
'\u001B]8;;https://github.com\u0007click\u001B]8;;\u0007'.match(ansiRegex());
|
| 31 |
+
//=> ['\u001B]8;;https://github.com\u0007', '\u001B]8;;\u0007']
|
| 32 |
+
```
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
## API
|
| 36 |
+
|
| 37 |
+
### ansiRegex(options?)
|
| 38 |
+
|
| 39 |
+
Returns a regex for matching ANSI escape codes.
|
| 40 |
+
|
| 41 |
+
#### options
|
| 42 |
+
|
| 43 |
+
Type: `object`
|
| 44 |
+
|
| 45 |
+
##### onlyFirst
|
| 46 |
+
|
| 47 |
+
Type: `boolean`<br>
|
| 48 |
+
Default: `false` *(Matches any ANSI escape codes in a string)*
|
| 49 |
+
|
| 50 |
+
Match only the first ANSI escape.
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
## FAQ
|
| 54 |
+
|
| 55 |
+
### Why do you test for codes not in the ECMA 48 standard?
|
| 56 |
+
|
| 57 |
+
Some of the codes we run as a test are codes that we acquired finding various lists of non-standard or manufacturer specific codes. We test for both standard and non-standard codes, as most of them follow the same or similar format and can be safely matched in strings without the risk of removing actual string content. There are a few non-standard control codes that do not follow the traditional format (i.e. they end in numbers) thus forcing us to exclude them from the test because we cannot reliably match them.
|
| 58 |
+
|
| 59 |
+
On the historical side, those ECMA standards were established in the early 90's whereas the VT100, for example, was designed in the mid/late 70's. At that point in time, control codes were still pretty ungoverned and engineers used them for a multitude of things, namely to activate hardware ports that may have been proprietary. Somewhere else you see a similar 'anarchy' of codes is in the x86 architecture for processors; there are a ton of "interrupts" that can mean different things on certain brands of processors, most of which have been phased out.
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
## Maintainers
|
| 63 |
+
|
| 64 |
+
- [Sindre Sorhus](https://github.com/sindresorhus)
|
| 65 |
+
- [Josh Junon](https://github.com/qix-)
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
---
|
| 69 |
+
|
| 70 |
+
<div align="center">
|
| 71 |
+
<b>
|
| 72 |
+
<a href="https://tidelift.com/subscription/pkg/npm-ansi-regex?utm_source=npm-ansi-regex&utm_medium=referral&utm_campaign=readme">Get professional support for this package with a Tidelift subscription</a>
|
| 73 |
+
</b>
|
| 74 |
+
<br>
|
| 75 |
+
<sub>
|
| 76 |
+
Tidelift helps make open source sustainable for maintainers while giving companies<br>assurances about security, maintenance, and licensing for their dependencies.
|
| 77 |
+
</sub>
|
| 78 |
+
</div>
|
platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/wrap-ansi-cjs/node_modules/ansi-styles/index.d.ts
ADDED
|
@@ -0,0 +1,345 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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aliceblue'
|
| 3 |
+
| 'antiquewhite'
|
| 4 |
+
| 'aqua'
|
| 5 |
+
| 'aquamarine'
|
| 6 |
+
| 'azure'
|
| 7 |
+
| 'beige'
|
| 8 |
+
| 'bisque'
|
| 9 |
+
| 'black'
|
| 10 |
+
| 'blanchedalmond'
|
| 11 |
+
| 'blue'
|
| 12 |
+
| 'blueviolet'
|
| 13 |
+
| 'brown'
|
| 14 |
+
| 'burlywood'
|
| 15 |
+
| 'cadetblue'
|
| 16 |
+
| 'chartreuse'
|
| 17 |
+
| 'chocolate'
|
| 18 |
+
| 'coral'
|
| 19 |
+
| 'cornflowerblue'
|
| 20 |
+
| 'cornsilk'
|
| 21 |
+
| 'crimson'
|
| 22 |
+
| 'cyan'
|
| 23 |
+
| 'darkblue'
|
| 24 |
+
| 'darkcyan'
|
| 25 |
+
| 'darkgoldenrod'
|
| 26 |
+
| 'darkgray'
|
| 27 |
+
| 'darkgreen'
|
| 28 |
+
| 'darkgrey'
|
| 29 |
+
| 'darkkhaki'
|
| 30 |
+
| 'darkmagenta'
|
| 31 |
+
| 'darkolivegreen'
|
| 32 |
+
| 'darkorange'
|
| 33 |
+
| 'darkorchid'
|
| 34 |
+
| 'darkred'
|
| 35 |
+
| 'darksalmon'
|
| 36 |
+
| 'darkseagreen'
|
| 37 |
+
| 'darkslateblue'
|
| 38 |
+
| 'darkslategray'
|
| 39 |
+
| 'darkslategrey'
|
| 40 |
+
| 'darkturquoise'
|
| 41 |
+
| 'darkviolet'
|
| 42 |
+
| 'deeppink'
|
| 43 |
+
| 'deepskyblue'
|
| 44 |
+
| 'dimgray'
|
| 45 |
+
| 'dimgrey'
|
| 46 |
+
| 'dodgerblue'
|
| 47 |
+
| 'firebrick'
|
| 48 |
+
| 'floralwhite'
|
| 49 |
+
| 'forestgreen'
|
| 50 |
+
| 'fuchsia'
|
| 51 |
+
| 'gainsboro'
|
| 52 |
+
| 'ghostwhite'
|
| 53 |
+
| 'gold'
|
| 54 |
+
| 'goldenrod'
|
| 55 |
+
| 'gray'
|
| 56 |
+
| 'green'
|
| 57 |
+
| 'greenyellow'
|
| 58 |
+
| 'grey'
|
| 59 |
+
| 'honeydew'
|
| 60 |
+
| 'hotpink'
|
| 61 |
+
| 'indianred'
|
| 62 |
+
| 'indigo'
|
| 63 |
+
| 'ivory'
|
| 64 |
+
| 'khaki'
|
| 65 |
+
| 'lavender'
|
| 66 |
+
| 'lavenderblush'
|
| 67 |
+
| 'lawngreen'
|
| 68 |
+
| 'lemonchiffon'
|
| 69 |
+
| 'lightblue'
|
| 70 |
+
| 'lightcoral'
|
| 71 |
+
| 'lightcyan'
|
| 72 |
+
| 'lightgoldenrodyellow'
|
| 73 |
+
| 'lightgray'
|
| 74 |
+
| 'lightgreen'
|
| 75 |
+
| 'lightgrey'
|
| 76 |
+
| 'lightpink'
|
| 77 |
+
| 'lightsalmon'
|
| 78 |
+
| 'lightseagreen'
|
| 79 |
+
| 'lightskyblue'
|
| 80 |
+
| 'lightslategray'
|
| 81 |
+
| 'lightslategrey'
|
| 82 |
+
| 'lightsteelblue'
|
| 83 |
+
| 'lightyellow'
|
| 84 |
+
| 'lime'
|
| 85 |
+
| 'limegreen'
|
| 86 |
+
| 'linen'
|
| 87 |
+
| 'magenta'
|
| 88 |
+
| 'maroon'
|
| 89 |
+
| 'mediumaquamarine'
|
| 90 |
+
| 'mediumblue'
|
| 91 |
+
| 'mediumorchid'
|
| 92 |
+
| 'mediumpurple'
|
| 93 |
+
| 'mediumseagreen'
|
| 94 |
+
| 'mediumslateblue'
|
| 95 |
+
| 'mediumspringgreen'
|
| 96 |
+
| 'mediumturquoise'
|
| 97 |
+
| 'mediumvioletred'
|
| 98 |
+
| 'midnightblue'
|
| 99 |
+
| 'mintcream'
|
| 100 |
+
| 'mistyrose'
|
| 101 |
+
| 'moccasin'
|
| 102 |
+
| 'navajowhite'
|
| 103 |
+
| 'navy'
|
| 104 |
+
| 'oldlace'
|
| 105 |
+
| 'olive'
|
| 106 |
+
| 'olivedrab'
|
| 107 |
+
| 'orange'
|
| 108 |
+
| 'orangered'
|
| 109 |
+
| 'orchid'
|
| 110 |
+
| 'palegoldenrod'
|
| 111 |
+
| 'palegreen'
|
| 112 |
+
| 'paleturquoise'
|
| 113 |
+
| 'palevioletred'
|
| 114 |
+
| 'papayawhip'
|
| 115 |
+
| 'peachpuff'
|
| 116 |
+
| 'peru'
|
| 117 |
+
| 'pink'
|
| 118 |
+
| 'plum'
|
| 119 |
+
| 'powderblue'
|
| 120 |
+
| 'purple'
|
| 121 |
+
| 'rebeccapurple'
|
| 122 |
+
| 'red'
|
| 123 |
+
| 'rosybrown'
|
| 124 |
+
| 'royalblue'
|
| 125 |
+
| 'saddlebrown'
|
| 126 |
+
| 'salmon'
|
| 127 |
+
| 'sandybrown'
|
| 128 |
+
| 'seagreen'
|
| 129 |
+
| 'seashell'
|
| 130 |
+
| 'sienna'
|
| 131 |
+
| 'silver'
|
| 132 |
+
| 'skyblue'
|
| 133 |
+
| 'slateblue'
|
| 134 |
+
| 'slategray'
|
| 135 |
+
| 'slategrey'
|
| 136 |
+
| 'snow'
|
| 137 |
+
| 'springgreen'
|
| 138 |
+
| 'steelblue'
|
| 139 |
+
| 'tan'
|
| 140 |
+
| 'teal'
|
| 141 |
+
| 'thistle'
|
| 142 |
+
| 'tomato'
|
| 143 |
+
| 'turquoise'
|
| 144 |
+
| 'violet'
|
| 145 |
+
| 'wheat'
|
| 146 |
+
| 'white'
|
| 147 |
+
| 'whitesmoke'
|
| 148 |
+
| 'yellow'
|
| 149 |
+
| 'yellowgreen';
|
| 150 |
+
|
| 151 |
+
declare namespace ansiStyles {
|
| 152 |
+
interface ColorConvert {
|
| 153 |
+
/**
|
| 154 |
+
The RGB color space.
|
| 155 |
+
|
| 156 |
+
@param red - (`0`-`255`)
|
| 157 |
+
@param green - (`0`-`255`)
|
| 158 |
+
@param blue - (`0`-`255`)
|
| 159 |
+
*/
|
| 160 |
+
rgb(red: number, green: number, blue: number): string;
|
| 161 |
+
|
| 162 |
+
/**
|
| 163 |
+
The RGB HEX color space.
|
| 164 |
+
|
| 165 |
+
@param hex - A hexadecimal string containing RGB data.
|
| 166 |
+
*/
|
| 167 |
+
hex(hex: string): string;
|
| 168 |
+
|
| 169 |
+
/**
|
| 170 |
+
@param keyword - A CSS color name.
|
| 171 |
+
*/
|
| 172 |
+
keyword(keyword: CSSColor): string;
|
| 173 |
+
|
| 174 |
+
/**
|
| 175 |
+
The HSL color space.
|
| 176 |
+
|
| 177 |
+
@param hue - (`0`-`360`)
|
| 178 |
+
@param saturation - (`0`-`100`)
|
| 179 |
+
@param lightness - (`0`-`100`)
|
| 180 |
+
*/
|
| 181 |
+
hsl(hue: number, saturation: number, lightness: number): string;
|
| 182 |
+
|
| 183 |
+
/**
|
| 184 |
+
The HSV color space.
|
| 185 |
+
|
| 186 |
+
@param hue - (`0`-`360`)
|
| 187 |
+
@param saturation - (`0`-`100`)
|
| 188 |
+
@param value - (`0`-`100`)
|
| 189 |
+
*/
|
| 190 |
+
hsv(hue: number, saturation: number, value: number): string;
|
| 191 |
+
|
| 192 |
+
/**
|
| 193 |
+
The HSV color space.
|
| 194 |
+
|
| 195 |
+
@param hue - (`0`-`360`)
|
| 196 |
+
@param whiteness - (`0`-`100`)
|
| 197 |
+
@param blackness - (`0`-`100`)
|
| 198 |
+
*/
|
| 199 |
+
hwb(hue: number, whiteness: number, blackness: number): string;
|
| 200 |
+
|
| 201 |
+
/**
|
| 202 |
+
Use a [4-bit unsigned number](https://en.wikipedia.org/wiki/ANSI_escape_code#3/4-bit) to set text color.
|
| 203 |
+
*/
|
| 204 |
+
ansi(ansi: number): string;
|
| 205 |
+
|
| 206 |
+
/**
|
| 207 |
+
Use an [8-bit unsigned number](https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit) to set text color.
|
| 208 |
+
*/
|
| 209 |
+
ansi256(ansi: number): string;
|
| 210 |
+
}
|
| 211 |
+
|
| 212 |
+
interface CSPair {
|
| 213 |
+
/**
|
| 214 |
+
The ANSI terminal control sequence for starting this style.
|
| 215 |
+
*/
|
| 216 |
+
readonly open: string;
|
| 217 |
+
|
| 218 |
+
/**
|
| 219 |
+
The ANSI terminal control sequence for ending this style.
|
| 220 |
+
*/
|
| 221 |
+
readonly close: string;
|
| 222 |
+
}
|
| 223 |
+
|
| 224 |
+
interface ColorBase {
|
| 225 |
+
readonly ansi: ColorConvert;
|
| 226 |
+
readonly ansi256: ColorConvert;
|
| 227 |
+
readonly ansi16m: ColorConvert;
|
| 228 |
+
|
| 229 |
+
/**
|
| 230 |
+
The ANSI terminal control sequence for ending this color.
|
| 231 |
+
*/
|
| 232 |
+
readonly close: string;
|
| 233 |
+
}
|
| 234 |
+
|
| 235 |
+
interface Modifier {
|
| 236 |
+
/**
|
| 237 |
+
Resets the current color chain.
|
| 238 |
+
*/
|
| 239 |
+
readonly reset: CSPair;
|
| 240 |
+
|
| 241 |
+
/**
|
| 242 |
+
Make text bold.
|
| 243 |
+
*/
|
| 244 |
+
readonly bold: CSPair;
|
| 245 |
+
|
| 246 |
+
/**
|
| 247 |
+
Emitting only a small amount of light.
|
| 248 |
+
*/
|
| 249 |
+
readonly dim: CSPair;
|
| 250 |
+
|
| 251 |
+
/**
|
| 252 |
+
Make text italic. (Not widely supported)
|
| 253 |
+
*/
|
| 254 |
+
readonly italic: CSPair;
|
| 255 |
+
|
| 256 |
+
/**
|
| 257 |
+
Make text underline. (Not widely supported)
|
| 258 |
+
*/
|
| 259 |
+
readonly underline: CSPair;
|
| 260 |
+
|
| 261 |
+
/**
|
| 262 |
+
Inverse background and foreground colors.
|
| 263 |
+
*/
|
| 264 |
+
readonly inverse: CSPair;
|
| 265 |
+
|
| 266 |
+
/**
|
| 267 |
+
Prints the text, but makes it invisible.
|
| 268 |
+
*/
|
| 269 |
+
readonly hidden: CSPair;
|
| 270 |
+
|
| 271 |
+
/**
|
| 272 |
+
Puts a horizontal line through the center of the text. (Not widely supported)
|
| 273 |
+
*/
|
| 274 |
+
readonly strikethrough: CSPair;
|
| 275 |
+
}
|
| 276 |
+
|
| 277 |
+
interface ForegroundColor {
|
| 278 |
+
readonly black: CSPair;
|
| 279 |
+
readonly red: CSPair;
|
| 280 |
+
readonly green: CSPair;
|
| 281 |
+
readonly yellow: CSPair;
|
| 282 |
+
readonly blue: CSPair;
|
| 283 |
+
readonly cyan: CSPair;
|
| 284 |
+
readonly magenta: CSPair;
|
| 285 |
+
readonly white: CSPair;
|
| 286 |
+
|
| 287 |
+
/**
|
| 288 |
+
Alias for `blackBright`.
|
| 289 |
+
*/
|
| 290 |
+
readonly gray: CSPair;
|
| 291 |
+
|
| 292 |
+
/**
|
| 293 |
+
Alias for `blackBright`.
|
| 294 |
+
*/
|
| 295 |
+
readonly grey: CSPair;
|
| 296 |
+
|
| 297 |
+
readonly blackBright: CSPair;
|
| 298 |
+
readonly redBright: CSPair;
|
| 299 |
+
readonly greenBright: CSPair;
|
| 300 |
+
readonly yellowBright: CSPair;
|
| 301 |
+
readonly blueBright: CSPair;
|
| 302 |
+
readonly cyanBright: CSPair;
|
| 303 |
+
readonly magentaBright: CSPair;
|
| 304 |
+
readonly whiteBright: CSPair;
|
| 305 |
+
}
|
| 306 |
+
|
| 307 |
+
interface BackgroundColor {
|
| 308 |
+
readonly bgBlack: CSPair;
|
| 309 |
+
readonly bgRed: CSPair;
|
| 310 |
+
readonly bgGreen: CSPair;
|
| 311 |
+
readonly bgYellow: CSPair;
|
| 312 |
+
readonly bgBlue: CSPair;
|
| 313 |
+
readonly bgCyan: CSPair;
|
| 314 |
+
readonly bgMagenta: CSPair;
|
| 315 |
+
readonly bgWhite: CSPair;
|
| 316 |
+
|
| 317 |
+
/**
|
| 318 |
+
Alias for `bgBlackBright`.
|
| 319 |
+
*/
|
| 320 |
+
readonly bgGray: CSPair;
|
| 321 |
+
|
| 322 |
+
/**
|
| 323 |
+
Alias for `bgBlackBright`.
|
| 324 |
+
*/
|
| 325 |
+
readonly bgGrey: CSPair;
|
| 326 |
+
|
| 327 |
+
readonly bgBlackBright: CSPair;
|
| 328 |
+
readonly bgRedBright: CSPair;
|
| 329 |
+
readonly bgGreenBright: CSPair;
|
| 330 |
+
readonly bgYellowBright: CSPair;
|
| 331 |
+
readonly bgBlueBright: CSPair;
|
| 332 |
+
readonly bgCyanBright: CSPair;
|
| 333 |
+
readonly bgMagentaBright: CSPair;
|
| 334 |
+
readonly bgWhiteBright: CSPair;
|
| 335 |
+
}
|
| 336 |
+
}
|
| 337 |
+
|
| 338 |
+
declare const ansiStyles: {
|
| 339 |
+
readonly modifier: ansiStyles.Modifier;
|
| 340 |
+
readonly color: ansiStyles.ForegroundColor & ansiStyles.ColorBase;
|
| 341 |
+
readonly bgColor: ansiStyles.BackgroundColor & ansiStyles.ColorBase;
|
| 342 |
+
readonly codes: ReadonlyMap<number, number>;
|
| 343 |
+
} & ansiStyles.BackgroundColor & ansiStyles.ForegroundColor & ansiStyles.Modifier;
|
| 344 |
+
|
| 345 |
+
export = ansiStyles;
|
platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/wrap-ansi-cjs/node_modules/ansi-styles/index.js
ADDED
|
@@ -0,0 +1,163 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
'use strict';
|
| 2 |
+
|
| 3 |
+
const wrapAnsi16 = (fn, offset) => (...args) => {
|
| 4 |
+
const code = fn(...args);
|
| 5 |
+
return `\u001B[${code + offset}m`;
|
| 6 |
+
};
|
| 7 |
+
|
| 8 |
+
const wrapAnsi256 = (fn, offset) => (...args) => {
|
| 9 |
+
const code = fn(...args);
|
| 10 |
+
return `\u001B[${38 + offset};5;${code}m`;
|
| 11 |
+
};
|
| 12 |
+
|
| 13 |
+
const wrapAnsi16m = (fn, offset) => (...args) => {
|
| 14 |
+
const rgb = fn(...args);
|
| 15 |
+
return `\u001B[${38 + offset};2;${rgb[0]};${rgb[1]};${rgb[2]}m`;
|
| 16 |
+
};
|
| 17 |
+
|
| 18 |
+
const ansi2ansi = n => n;
|
| 19 |
+
const rgb2rgb = (r, g, b) => [r, g, b];
|
| 20 |
+
|
| 21 |
+
const setLazyProperty = (object, property, get) => {
|
| 22 |
+
Object.defineProperty(object, property, {
|
| 23 |
+
get: () => {
|
| 24 |
+
const value = get();
|
| 25 |
+
|
| 26 |
+
Object.defineProperty(object, property, {
|
| 27 |
+
value,
|
| 28 |
+
enumerable: true,
|
| 29 |
+
configurable: true
|
| 30 |
+
});
|
| 31 |
+
|
| 32 |
+
return value;
|
| 33 |
+
},
|
| 34 |
+
enumerable: true,
|
| 35 |
+
configurable: true
|
| 36 |
+
});
|
| 37 |
+
};
|
| 38 |
+
|
| 39 |
+
/** @type {typeof import('color-convert')} */
|
| 40 |
+
let colorConvert;
|
| 41 |
+
const makeDynamicStyles = (wrap, targetSpace, identity, isBackground) => {
|
| 42 |
+
if (colorConvert === undefined) {
|
| 43 |
+
colorConvert = require('color-convert');
|
| 44 |
+
}
|
| 45 |
+
|
| 46 |
+
const offset = isBackground ? 10 : 0;
|
| 47 |
+
const styles = {};
|
| 48 |
+
|
| 49 |
+
for (const [sourceSpace, suite] of Object.entries(colorConvert)) {
|
| 50 |
+
const name = sourceSpace === 'ansi16' ? 'ansi' : sourceSpace;
|
| 51 |
+
if (sourceSpace === targetSpace) {
|
| 52 |
+
styles[name] = wrap(identity, offset);
|
| 53 |
+
} else if (typeof suite === 'object') {
|
| 54 |
+
styles[name] = wrap(suite[targetSpace], offset);
|
| 55 |
+
}
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
return styles;
|
| 59 |
+
};
|
| 60 |
+
|
| 61 |
+
function assembleStyles() {
|
| 62 |
+
const codes = new Map();
|
| 63 |
+
const styles = {
|
| 64 |
+
modifier: {
|
| 65 |
+
reset: [0, 0],
|
| 66 |
+
// 21 isn't widely supported and 22 does the same thing
|
| 67 |
+
bold: [1, 22],
|
| 68 |
+
dim: [2, 22],
|
| 69 |
+
italic: [3, 23],
|
| 70 |
+
underline: [4, 24],
|
| 71 |
+
inverse: [7, 27],
|
| 72 |
+
hidden: [8, 28],
|
| 73 |
+
strikethrough: [9, 29]
|
| 74 |
+
},
|
| 75 |
+
color: {
|
| 76 |
+
black: [30, 39],
|
| 77 |
+
red: [31, 39],
|
| 78 |
+
green: [32, 39],
|
| 79 |
+
yellow: [33, 39],
|
| 80 |
+
blue: [34, 39],
|
| 81 |
+
magenta: [35, 39],
|
| 82 |
+
cyan: [36, 39],
|
| 83 |
+
white: [37, 39],
|
| 84 |
+
|
| 85 |
+
// Bright color
|
| 86 |
+
blackBright: [90, 39],
|
| 87 |
+
redBright: [91, 39],
|
| 88 |
+
greenBright: [92, 39],
|
| 89 |
+
yellowBright: [93, 39],
|
| 90 |
+
blueBright: [94, 39],
|
| 91 |
+
magentaBright: [95, 39],
|
| 92 |
+
cyanBright: [96, 39],
|
| 93 |
+
whiteBright: [97, 39]
|
| 94 |
+
},
|
| 95 |
+
bgColor: {
|
| 96 |
+
bgBlack: [40, 49],
|
| 97 |
+
bgRed: [41, 49],
|
| 98 |
+
bgGreen: [42, 49],
|
| 99 |
+
bgYellow: [43, 49],
|
| 100 |
+
bgBlue: [44, 49],
|
| 101 |
+
bgMagenta: [45, 49],
|
| 102 |
+
bgCyan: [46, 49],
|
| 103 |
+
bgWhite: [47, 49],
|
| 104 |
+
|
| 105 |
+
// Bright color
|
| 106 |
+
bgBlackBright: [100, 49],
|
| 107 |
+
bgRedBright: [101, 49],
|
| 108 |
+
bgGreenBright: [102, 49],
|
| 109 |
+
bgYellowBright: [103, 49],
|
| 110 |
+
bgBlueBright: [104, 49],
|
| 111 |
+
bgMagentaBright: [105, 49],
|
| 112 |
+
bgCyanBright: [106, 49],
|
| 113 |
+
bgWhiteBright: [107, 49]
|
| 114 |
+
}
|
| 115 |
+
};
|
| 116 |
+
|
| 117 |
+
// Alias bright black as gray (and grey)
|
| 118 |
+
styles.color.gray = styles.color.blackBright;
|
| 119 |
+
styles.bgColor.bgGray = styles.bgColor.bgBlackBright;
|
| 120 |
+
styles.color.grey = styles.color.blackBright;
|
| 121 |
+
styles.bgColor.bgGrey = styles.bgColor.bgBlackBright;
|
| 122 |
+
|
| 123 |
+
for (const [groupName, group] of Object.entries(styles)) {
|
| 124 |
+
for (const [styleName, style] of Object.entries(group)) {
|
| 125 |
+
styles[styleName] = {
|
| 126 |
+
open: `\u001B[${style[0]}m`,
|
| 127 |
+
close: `\u001B[${style[1]}m`
|
| 128 |
+
};
|
| 129 |
+
|
| 130 |
+
group[styleName] = styles[styleName];
|
| 131 |
+
|
| 132 |
+
codes.set(style[0], style[1]);
|
| 133 |
+
}
|
| 134 |
+
|
| 135 |
+
Object.defineProperty(styles, groupName, {
|
| 136 |
+
value: group,
|
| 137 |
+
enumerable: false
|
| 138 |
+
});
|
| 139 |
+
}
|
| 140 |
+
|
| 141 |
+
Object.defineProperty(styles, 'codes', {
|
| 142 |
+
value: codes,
|
| 143 |
+
enumerable: false
|
| 144 |
+
});
|
| 145 |
+
|
| 146 |
+
styles.color.close = '\u001B[39m';
|
| 147 |
+
styles.bgColor.close = '\u001B[49m';
|
| 148 |
+
|
| 149 |
+
setLazyProperty(styles.color, 'ansi', () => makeDynamicStyles(wrapAnsi16, 'ansi16', ansi2ansi, false));
|
| 150 |
+
setLazyProperty(styles.color, 'ansi256', () => makeDynamicStyles(wrapAnsi256, 'ansi256', ansi2ansi, false));
|
| 151 |
+
setLazyProperty(styles.color, 'ansi16m', () => makeDynamicStyles(wrapAnsi16m, 'rgb', rgb2rgb, false));
|
| 152 |
+
setLazyProperty(styles.bgColor, 'ansi', () => makeDynamicStyles(wrapAnsi16, 'ansi16', ansi2ansi, true));
|
| 153 |
+
setLazyProperty(styles.bgColor, 'ansi256', () => makeDynamicStyles(wrapAnsi256, 'ansi256', ansi2ansi, true));
|
| 154 |
+
setLazyProperty(styles.bgColor, 'ansi16m', () => makeDynamicStyles(wrapAnsi16m, 'rgb', rgb2rgb, true));
|
| 155 |
+
|
| 156 |
+
return styles;
|
| 157 |
+
}
|
| 158 |
+
|
| 159 |
+
// Make the export immutable
|
| 160 |
+
Object.defineProperty(module, 'exports', {
|
| 161 |
+
enumerable: true,
|
| 162 |
+
get: assembleStyles
|
| 163 |
+
});
|
platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/wrap-ansi-cjs/node_modules/ansi-styles/license
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
MIT License
|
| 2 |
+
|
| 3 |
+
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
|
| 4 |
+
|
| 5 |
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
| 6 |
+
|
| 7 |
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
| 8 |
+
|
| 9 |
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/wrap-ansi-cjs/node_modules/ansi-styles/package.json
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "ansi-styles",
|
| 3 |
+
"version": "4.3.0",
|
| 4 |
+
"description": "ANSI escape codes for styling strings in the terminal",
|
| 5 |
+
"license": "MIT",
|
| 6 |
+
"repository": "chalk/ansi-styles",
|
| 7 |
+
"funding": "https://github.com/chalk/ansi-styles?sponsor=1",
|
| 8 |
+
"author": {
|
| 9 |
+
"name": "Sindre Sorhus",
|
| 10 |
+
"email": "sindresorhus@gmail.com",
|
| 11 |
+
"url": "sindresorhus.com"
|
| 12 |
+
},
|
| 13 |
+
"engines": {
|
| 14 |
+
"node": ">=8"
|
| 15 |
+
},
|
| 16 |
+
"scripts": {
|
| 17 |
+
"test": "xo && ava && tsd",
|
| 18 |
+
"screenshot": "svg-term --command='node screenshot' --out=screenshot.svg --padding=3 --width=55 --height=3 --at=1000 --no-cursor"
|
| 19 |
+
},
|
| 20 |
+
"files": [
|
| 21 |
+
"index.js",
|
| 22 |
+
"index.d.ts"
|
| 23 |
+
],
|
| 24 |
+
"keywords": [
|
| 25 |
+
"ansi",
|
| 26 |
+
"styles",
|
| 27 |
+
"color",
|
| 28 |
+
"colour",
|
| 29 |
+
"colors",
|
| 30 |
+
"terminal",
|
| 31 |
+
"console",
|
| 32 |
+
"cli",
|
| 33 |
+
"string",
|
| 34 |
+
"tty",
|
| 35 |
+
"escape",
|
| 36 |
+
"formatting",
|
| 37 |
+
"rgb",
|
| 38 |
+
"256",
|
| 39 |
+
"shell",
|
| 40 |
+
"xterm",
|
| 41 |
+
"log",
|
| 42 |
+
"logging",
|
| 43 |
+
"command-line",
|
| 44 |
+
"text"
|
| 45 |
+
],
|
| 46 |
+
"dependencies": {
|
| 47 |
+
"color-convert": "^2.0.1"
|
| 48 |
+
},
|
| 49 |
+
"devDependencies": {
|
| 50 |
+
"@types/color-convert": "^1.9.0",
|
| 51 |
+
"ava": "^2.3.0",
|
| 52 |
+
"svg-term-cli": "^2.1.1",
|
| 53 |
+
"tsd": "^0.11.0",
|
| 54 |
+
"xo": "^0.25.3"
|
| 55 |
+
}
|
| 56 |
+
}
|
platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/wrap-ansi-cjs/node_modules/ansi-styles/readme.md
ADDED
|
@@ -0,0 +1,152 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# ansi-styles [](https://travis-ci.org/chalk/ansi-styles)
|
| 2 |
+
|
| 3 |
+
> [ANSI escape codes](https://en.wikipedia.org/wiki/ANSI_escape_code#Colors_and_Styles) for styling strings in the terminal
|
| 4 |
+
|
| 5 |
+
You probably want the higher-level [chalk](https://github.com/chalk/chalk) module for styling your strings.
|
| 6 |
+
|
| 7 |
+
<img src="screenshot.svg" width="900">
|
| 8 |
+
|
| 9 |
+
## Install
|
| 10 |
+
|
| 11 |
+
```
|
| 12 |
+
$ npm install ansi-styles
|
| 13 |
+
```
|
| 14 |
+
|
| 15 |
+
## Usage
|
| 16 |
+
|
| 17 |
+
```js
|
| 18 |
+
const style = require('ansi-styles');
|
| 19 |
+
|
| 20 |
+
console.log(`${style.green.open}Hello world!${style.green.close}`);
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
// Color conversion between 16/256/truecolor
|
| 24 |
+
// NOTE: If conversion goes to 16 colors or 256 colors, the original color
|
| 25 |
+
// may be degraded to fit that color palette. This means terminals
|
| 26 |
+
// that do not support 16 million colors will best-match the
|
| 27 |
+
// original color.
|
| 28 |
+
console.log(style.bgColor.ansi.hsl(120, 80, 72) + 'Hello world!' + style.bgColor.close);
|
| 29 |
+
console.log(style.color.ansi256.rgb(199, 20, 250) + 'Hello world!' + style.color.close);
|
| 30 |
+
console.log(style.color.ansi16m.hex('#abcdef') + 'Hello world!' + style.color.close);
|
| 31 |
+
```
|
| 32 |
+
|
| 33 |
+
## API
|
| 34 |
+
|
| 35 |
+
Each style has an `open` and `close` property.
|
| 36 |
+
|
| 37 |
+
## Styles
|
| 38 |
+
|
| 39 |
+
### Modifiers
|
| 40 |
+
|
| 41 |
+
- `reset`
|
| 42 |
+
- `bold`
|
| 43 |
+
- `dim`
|
| 44 |
+
- `italic` *(Not widely supported)*
|
| 45 |
+
- `underline`
|
| 46 |
+
- `inverse`
|
| 47 |
+
- `hidden`
|
| 48 |
+
- `strikethrough` *(Not widely supported)*
|
| 49 |
+
|
| 50 |
+
### Colors
|
| 51 |
+
|
| 52 |
+
- `black`
|
| 53 |
+
- `red`
|
| 54 |
+
- `green`
|
| 55 |
+
- `yellow`
|
| 56 |
+
- `blue`
|
| 57 |
+
- `magenta`
|
| 58 |
+
- `cyan`
|
| 59 |
+
- `white`
|
| 60 |
+
- `blackBright` (alias: `gray`, `grey`)
|
| 61 |
+
- `redBright`
|
| 62 |
+
- `greenBright`
|
| 63 |
+
- `yellowBright`
|
| 64 |
+
- `blueBright`
|
| 65 |
+
- `magentaBright`
|
| 66 |
+
- `cyanBright`
|
| 67 |
+
- `whiteBright`
|
| 68 |
+
|
| 69 |
+
### Background colors
|
| 70 |
+
|
| 71 |
+
- `bgBlack`
|
| 72 |
+
- `bgRed`
|
| 73 |
+
- `bgGreen`
|
| 74 |
+
- `bgYellow`
|
| 75 |
+
- `bgBlue`
|
| 76 |
+
- `bgMagenta`
|
| 77 |
+
- `bgCyan`
|
| 78 |
+
- `bgWhite`
|
| 79 |
+
- `bgBlackBright` (alias: `bgGray`, `bgGrey`)
|
| 80 |
+
- `bgRedBright`
|
| 81 |
+
- `bgGreenBright`
|
| 82 |
+
- `bgYellowBright`
|
| 83 |
+
- `bgBlueBright`
|
| 84 |
+
- `bgMagentaBright`
|
| 85 |
+
- `bgCyanBright`
|
| 86 |
+
- `bgWhiteBright`
|
| 87 |
+
|
| 88 |
+
## Advanced usage
|
| 89 |
+
|
| 90 |
+
By default, you get a map of styles, but the styles are also available as groups. They are non-enumerable so they don't show up unless you access them explicitly. This makes it easier to expose only a subset in a higher-level module.
|
| 91 |
+
|
| 92 |
+
- `style.modifier`
|
| 93 |
+
- `style.color`
|
| 94 |
+
- `style.bgColor`
|
| 95 |
+
|
| 96 |
+
###### Example
|
| 97 |
+
|
| 98 |
+
```js
|
| 99 |
+
console.log(style.color.green.open);
|
| 100 |
+
```
|
| 101 |
+
|
| 102 |
+
Raw escape codes (i.e. without the CSI escape prefix `\u001B[` and render mode postfix `m`) are available under `style.codes`, which returns a `Map` with the open codes as keys and close codes as values.
|
| 103 |
+
|
| 104 |
+
###### Example
|
| 105 |
+
|
| 106 |
+
```js
|
| 107 |
+
console.log(style.codes.get(36));
|
| 108 |
+
//=> 39
|
| 109 |
+
```
|
| 110 |
+
|
| 111 |
+
## [256 / 16 million (TrueColor) support](https://gist.github.com/XVilka/8346728)
|
| 112 |
+
|
| 113 |
+
`ansi-styles` uses the [`color-convert`](https://github.com/Qix-/color-convert) package to allow for converting between various colors and ANSI escapes, with support for 256 and 16 million colors.
|
| 114 |
+
|
| 115 |
+
The following color spaces from `color-convert` are supported:
|
| 116 |
+
|
| 117 |
+
- `rgb`
|
| 118 |
+
- `hex`
|
| 119 |
+
- `keyword`
|
| 120 |
+
- `hsl`
|
| 121 |
+
- `hsv`
|
| 122 |
+
- `hwb`
|
| 123 |
+
- `ansi`
|
| 124 |
+
- `ansi256`
|
| 125 |
+
|
| 126 |
+
To use these, call the associated conversion function with the intended output, for example:
|
| 127 |
+
|
| 128 |
+
```js
|
| 129 |
+
style.color.ansi.rgb(100, 200, 15); // RGB to 16 color ansi foreground code
|
| 130 |
+
style.bgColor.ansi.rgb(100, 200, 15); // RGB to 16 color ansi background code
|
| 131 |
+
|
| 132 |
+
style.color.ansi256.hsl(120, 100, 60); // HSL to 256 color ansi foreground code
|
| 133 |
+
style.bgColor.ansi256.hsl(120, 100, 60); // HSL to 256 color ansi foreground code
|
| 134 |
+
|
| 135 |
+
style.color.ansi16m.hex('#C0FFEE'); // Hex (RGB) to 16 million color foreground code
|
| 136 |
+
style.bgColor.ansi16m.hex('#C0FFEE'); // Hex (RGB) to 16 million color background code
|
| 137 |
+
```
|
| 138 |
+
|
| 139 |
+
## Related
|
| 140 |
+
|
| 141 |
+
- [ansi-escapes](https://github.com/sindresorhus/ansi-escapes) - ANSI escape codes for manipulating the terminal
|
| 142 |
+
|
| 143 |
+
## Maintainers
|
| 144 |
+
|
| 145 |
+
- [Sindre Sorhus](https://github.com/sindresorhus)
|
| 146 |
+
- [Josh Junon](https://github.com/qix-)
|
| 147 |
+
|
| 148 |
+
## For enterprise
|
| 149 |
+
|
| 150 |
+
Available as part of the Tidelift Subscription.
|
| 151 |
+
|
| 152 |
+
The maintainers of `ansi-styles` and thousands of other packages are working with Tidelift to deliver commercial support and maintenance for the open source dependencies you use to build your applications. Save time, reduce risk, and improve code health, while paying the maintainers of the exact dependencies you use. [Learn more.](https://tidelift.com/subscription/pkg/npm-ansi-styles?utm_source=npm-ansi-styles&utm_medium=referral&utm_campaign=enterprise&utm_term=repo)
|
platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/wrap-ansi-cjs/node_modules/emoji-regex/LICENSE-MIT.txt
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Copyright Mathias Bynens <https://mathiasbynens.be/>
|
| 2 |
+
|
| 3 |
+
Permission is hereby granted, free of charge, to any person obtaining
|
| 4 |
+
a copy of this software and associated documentation files (the
|
| 5 |
+
"Software"), to deal in the Software without restriction, including
|
| 6 |
+
without limitation the rights to use, copy, modify, merge, publish,
|
| 7 |
+
distribute, sublicense, and/or sell copies of the Software, and to
|
| 8 |
+
permit persons to whom the Software is furnished to do so, subject to
|
| 9 |
+
the following conditions:
|
| 10 |
+
|
| 11 |
+
The above copyright notice and this permission notice shall be
|
| 12 |
+
included in all copies or substantial portions of the Software.
|
| 13 |
+
|
| 14 |
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
| 15 |
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
| 16 |
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
| 17 |
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
| 18 |
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
| 19 |
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
| 20 |
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/wrap-ansi-cjs/node_modules/emoji-regex/README.md
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# emoji-regex [](https://travis-ci.org/mathiasbynens/emoji-regex)
|
| 2 |
+
|
| 3 |
+
_emoji-regex_ offers a regular expression to match all emoji symbols (including textual representations of emoji) as per the Unicode Standard.
|
| 4 |
+
|
| 5 |
+
This repository contains a script that generates this regular expression based on [the data from Unicode v12](https://github.com/mathiasbynens/unicode-12.0.0). Because of this, the regular expression can easily be updated whenever new emoji are added to the Unicode standard.
|
| 6 |
+
|
| 7 |
+
## Installation
|
| 8 |
+
|
| 9 |
+
Via [npm](https://www.npmjs.com/):
|
| 10 |
+
|
| 11 |
+
```bash
|
| 12 |
+
npm install emoji-regex
|
| 13 |
+
```
|
| 14 |
+
|
| 15 |
+
In [Node.js](https://nodejs.org/):
|
| 16 |
+
|
| 17 |
+
```js
|
| 18 |
+
const emojiRegex = require('emoji-regex');
|
| 19 |
+
// Note: because the regular expression has the global flag set, this module
|
| 20 |
+
// exports a function that returns the regex rather than exporting the regular
|
| 21 |
+
// expression itself, to make it impossible to (accidentally) mutate the
|
| 22 |
+
// original regular expression.
|
| 23 |
+
|
| 24 |
+
const text = `
|
| 25 |
+
\u{231A}: ⌚ default emoji presentation character (Emoji_Presentation)
|
| 26 |
+
\u{2194}\u{FE0F}: ↔️ default text presentation character rendered as emoji
|
| 27 |
+
\u{1F469}: 👩 emoji modifier base (Emoji_Modifier_Base)
|
| 28 |
+
\u{1F469}\u{1F3FF}: 👩🏿 emoji modifier base followed by a modifier
|
| 29 |
+
`;
|
| 30 |
+
|
| 31 |
+
const regex = emojiRegex();
|
| 32 |
+
let match;
|
| 33 |
+
while (match = regex.exec(text)) {
|
| 34 |
+
const emoji = match[0];
|
| 35 |
+
console.log(`Matched sequence ${ emoji } — code points: ${ [...emoji].length }`);
|
| 36 |
+
}
|
| 37 |
+
```
|
| 38 |
+
|
| 39 |
+
Console output:
|
| 40 |
+
|
| 41 |
+
```
|
| 42 |
+
Matched sequence ⌚ — code points: 1
|
| 43 |
+
Matched sequence ⌚ — code points: 1
|
| 44 |
+
Matched sequence ↔️ — code points: 2
|
| 45 |
+
Matched sequence ↔️ — code points: 2
|
| 46 |
+
Matched sequence 👩 — code points: 1
|
| 47 |
+
Matched sequence 👩 — code points: 1
|
| 48 |
+
Matched sequence 👩🏿 — code points: 2
|
| 49 |
+
Matched sequence 👩🏿 — code points: 2
|
| 50 |
+
```
|
| 51 |
+
|
| 52 |
+
To match emoji in their textual representation as well (i.e. emoji that are not `Emoji_Presentation` symbols and that aren’t forced to render as emoji by a variation selector), `require` the other regex:
|
| 53 |
+
|
| 54 |
+
```js
|
| 55 |
+
const emojiRegex = require('emoji-regex/text.js');
|
| 56 |
+
```
|
| 57 |
+
|
| 58 |
+
Additionally, in environments which support ES2015 Unicode escapes, you may `require` ES2015-style versions of the regexes:
|
| 59 |
+
|
| 60 |
+
```js
|
| 61 |
+
const emojiRegex = require('emoji-regex/es2015/index.js');
|
| 62 |
+
const emojiRegexText = require('emoji-regex/es2015/text.js');
|
| 63 |
+
```
|
| 64 |
+
|
| 65 |
+
## Author
|
| 66 |
+
|
| 67 |
+
| [](https://twitter.com/mathias "Follow @mathias on Twitter") |
|
| 68 |
+
|---|
|
| 69 |
+
| [Mathias Bynens](https://mathiasbynens.be/) |
|
| 70 |
+
|
| 71 |
+
## License
|
| 72 |
+
|
| 73 |
+
_emoji-regex_ is available under the [MIT](https://mths.be/mit) license.
|
platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/wrap-ansi-cjs/node_modules/emoji-regex/es2015/index.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"use strict";
|
| 2 |
+
|
| 3 |
+
module.exports = () => {
|
| 4 |
+
// https://mths.be/emoji
|
| 5 |
+
return /\u{1F3F4}\u{E0067}\u{E0062}(?:\u{E0065}\u{E006E}\u{E0067}|\u{E0073}\u{E0063}\u{E0074}|\u{E0077}\u{E006C}\u{E0073})\u{E007F}|\u{1F468}(?:\u{1F3FC}\u200D(?:\u{1F91D}\u200D\u{1F468}\u{1F3FB}|[\u{1F33E}\u{1F373}\u{1F393}\u{1F3A4}\u{1F3A8}\u{1F3EB}\u{1F3ED}\u{1F4BB}\u{1F4BC}\u{1F527}\u{1F52C}\u{1F680}\u{1F692}\u{1F9AF}-\u{1F9B3}\u{1F9BC}\u{1F9BD}])|\u{1F3FF}\u200D(?:\u{1F91D}\u200D\u{1F468}[\u{1F3FB}-\u{1F3FE}]|[\u{1F33E}\u{1F373}\u{1F393}\u{1F3A4}\u{1F3A8}\u{1F3EB}\u{1F3ED}\u{1F4BB}\u{1F4BC}\u{1F527}\u{1F52C}\u{1F680}\u{1F692}\u{1F9AF}-\u{1F9B3}\u{1F9BC}\u{1F9BD}])|\u{1F3FE}\u200D(?:\u{1F91D}\u200D\u{1F468}[\u{1F3FB}-\u{1F3FD}]|[\u{1F33E}\u{1F373}\u{1F393}\u{1F3A4}\u{1F3A8}\u{1F3EB}\u{1F3ED}\u{1F4BB}\u{1F4BC}\u{1F527}\u{1F52C}\u{1F680}\u{1F692}\u{1F9AF}-\u{1F9B3}\u{1F9BC}\u{1F9BD}])|\u{1F3FD}\u200D(?:\u{1F91D}\u200D\u{1F468}[\u{1F3FB}\u{1F3FC}]|[\u{1F33E}\u{1F373}\u{1F393}\u{1F3A4}\u{1F3A8}\u{1F3EB}\u{1F3ED}\u{1F4BB}\u{1F4BC}\u{1F527}\u{1F52C}\u{1F680}\u{1F692}\u{1F9AF}-\u{1F9B3}\u{1F9BC}\u{1F9BD}])|\u200D(?:\u2764\uFE0F\u200D(?:\u{1F48B}\u200D)?\u{1F468}|[\u{1F468}\u{1F469}]\u200D(?:\u{1F466}\u200D\u{1F466}|\u{1F467}\u200D[\u{1F466}\u{1F467}])|\u{1F466}\u200D\u{1F466}|\u{1F467}\u200D[\u{1F466}\u{1F467}]|[\u{1F468}\u{1F469}]\u200D[\u{1F466}\u{1F467}]|[\u2695\u2696\u2708]\uFE0F|[\u{1F466}\u{1F467}]|[\u{1F33E}\u{1F373}\u{1F393}\u{1F3A4}\u{1F3A8}\u{1F3EB}\u{1F3ED}\u{1F4BB}\u{1F4BC}\u{1F527}\u{1F52C}\u{1F680}\u{1F692}\u{1F9AF}-\u{1F9B3}\u{1F9BC}\u{1F9BD}])|(?:\u{1F3FB}\u200D[\u2695\u2696\u2708]|\u{1F3FF}\u200D[\u2695\u2696\u2708]|\u{1F3FE}\u200D[\u2695\u2696\u2708]|\u{1F3FD}\u200D[\u2695\u2696\u2708]|\u{1F3FC}\u200D[\u2695\u2696\u2708])\uFE0F|\u{1F3FB}\u200D[\u{1F33E}\u{1F373}\u{1F393}\u{1F3A4}\u{1F3A8}\u{1F3EB}\u{1F3ED}\u{1F4BB}\u{1F4BC}\u{1F527}\u{1F52C}\u{1F680}\u{1F692}\u{1F9AF}-\u{1F9B3}\u{1F9BC}\u{1F9BD}]|[\u{1F3FB}-\u{1F3FF}])|(?:\u{1F9D1}\u{1F3FB}\u200D\u{1F91D}\u200D\u{1F9D1}|\u{1F469}\u{1F3FC}\u200D\u{1F91D}\u200D\u{1F469})\u{1F3FB}|\u{1F9D1}(?:\u{1F3FF}\u200D\u{1F91D}\u200D\u{1F9D1}[\u{1F3FB}-\u{1F3FF}]|\u200D\u{1F91D}\u200D\u{1F9D1})|(?:\u{1F9D1}\u{1F3FE}\u200D\u{1F91D}\u200D\u{1F9D1}|\u{1F469}\u{1F3FF}\u200D\u{1F91D}\u200D[\u{1F468}\u{1F469}])[\u{1F3FB}-\u{1F3FE}]|(?:\u{1F9D1}\u{1F3FC}\u200D\u{1F91D}\u200D\u{1F9D1}|\u{1F469}\u{1F3FD}\u200D\u{1F91D}\u200D\u{1F469})[\u{1F3FB}\u{1F3FC}]|\u{1F469}(?:\u{1F3FE}\u200D(?:\u{1F91D}\u200D\u{1F468}[\u{1F3FB}-\u{1F3FD}\u{1F3FF}]|[\u{1F33E}\u{1F373}\u{1F393}\u{1F3A4}\u{1F3A8}\u{1F3EB}\u{1F3ED}\u{1F4BB}\u{1F4BC}\u{1F527}\u{1F52C}\u{1F680}\u{1F692}\u{1F9AF}-\u{1F9B3}\u{1F9BC}\u{1F9BD}])|\u{1F3FC}\u200D(?:\u{1F91D}\u200D\u{1F468}[\u{1F3FB}\u{1F3FD}-\u{1F3FF}]|[\u{1F33E}\u{1F373}\u{1F393}\u{1F3A4}\u{1F3A8}\u{1F3EB}\u{1F3ED}\u{1F4BB}\u{1F4BC}\u{1F527}\u{1F52C}\u{1F680}\u{1F692}\u{1F9AF}-\u{1F9B3}\u{1F9BC}\u{1F9BD}])|\u{1F3FB}\u200D(?:\u{1F91D}\u200D\u{1F468}[\u{1F3FC}-\u{1F3FF}]|[\u{1F33E}\u{1F373}\u{1F393}\u{1F3A4}\u{1F3A8}\u{1F3EB}\u{1F3ED}\u{1F4BB}\u{1F4BC}\u{1F527}\u{1F52C}\u{1F680}\u{1F692}\u{1F9AF}-\u{1F9B3}\u{1F9BC}\u{1F9BD}])|\u{1F3FD}\u200D(?:\u{1F91D}\u200D\u{1F468}[\u{1F3FB}\u{1F3FC}\u{1F3FE}\u{1F3FF}]|[\u{1F33E}\u{1F373}\u{1F393}\u{1F3A4}\u{1F3A8}\u{1F3EB}\u{1F3ED}\u{1F4BB}\u{1F4BC}\u{1F527}\u{1F52C}\u{1F680}\u{1F692}\u{1F9AF}-\u{1F9B3}\u{1F9BC}\u{1F9BD}])|\u200D(?:\u2764\uFE0F\u200D(?:\u{1F48B}\u200D[\u{1F468}\u{1F469}]|[\u{1F468}\u{1F469}])|[\u{1F33E}\u{1F373}\u{1F393}\u{1F3A4}\u{1F3A8}\u{1F3EB}\u{1F3ED}\u{1F4BB}\u{1F4BC}\u{1F527}\u{1F52C}\u{1F680}\u{1F692}\u{1F9AF}-\u{1F9B3}\u{1F9BC}\u{1F9BD}])|\u{1F3FF}\u200D[\u{1F33E}\u{1F373}\u{1F393}\u{1F3A4}\u{1F3A8}\u{1F3EB}\u{1F3ED}\u{1F4BB}\u{1F4BC}\u{1F527}\u{1F52C}\u{1F680}\u{1F692}\u{1F9AF}-\u{1F9B3}\u{1F9BC}\u{1F9BD}])|\u{1F469}\u200D\u{1F469}\u200D(?:\u{1F466}\u200D\u{1F466}|\u{1F467}\u200D[\u{1F466}\u{1F467}])|(?:\u{1F9D1}\u{1F3FD}\u200D\u{1F91D}\u200D\u{1F9D1}|\u{1F469}\u{1F3FE}\u200D\u{1F91D}\u200D\u{1F469})[\u{1F3FB}-\u{1F3FD}]|\u{1F469}\u200D\u{1F466}\u200D\u{1F466}|\u{1F469}\u200D\u{1F469}\u200D[\u{1F466}\u{1F467}]|(?:\u{1F441}\uFE0F\u200D\u{1F5E8}|\u{1F469}(?:\u{1F3FF}\u200D[\u2695\u2696\u2708]|\u{1F3FE}\u200D[\u2695\u2696\u2708]|\u{1F3FC}\u200D[\u2695\u2696\u2708]|\u{1F3FB}\u200D[\u2695\u2696\u2708]|\u{1F3FD}\u200D[\u2695\u2696\u2708]|\u200D[\u2695\u2696\u2708])|(?:[\u26F9\u{1F3CB}\u{1F3CC}\u{1F575}]\uFE0F|[\u{1F46F}\u{1F93C}\u{1F9DE}\u{1F9DF}])\u200D[\u2640\u2642]|[\u26F9\u{1F3CB}\u{1F3CC}\u{1F575}][\u{1F3FB}-\u{1F3FF}]\u200D[\u2640\u2642]|[\u{1F3C3}\u{1F3C4}\u{1F3CA}\u{1F46E}\u{1F471}\u{1F473}\u{1F477}\u{1F481}\u{1F482}\u{1F486}\u{1F487}\u{1F645}-\u{1F647}\u{1F64B}\u{1F64D}\u{1F64E}\u{1F6A3}\u{1F6B4}-\u{1F6B6}\u{1F926}\u{1F937}-\u{1F939}\u{1F93D}\u{1F93E}\u{1F9B8}\u{1F9B9}\u{1F9CD}-\u{1F9CF}\u{1F9D6}-\u{1F9DD}](?:[\u{1F3FB}-\u{1F3FF}]\u200D[\u2640\u2642]|\u200D[\u2640\u2642])|\u{1F3F4}\u200D\u2620)\uFE0F|\u{1F469}\u200D\u{1F467}\u200D[\u{1F466}\u{1F467}]|\u{1F3F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1F3CA}\u{1F46E}\u{1F471}\u{1F473}\u{1F477}\u{1F481}\u{1F482}\u{1F486}\u{1F487}\u{1F645}-\u{1F647}\u{1F64B}\u{1F64D}\u{1F64E}\u{1F6A3}\u{1F6B4}-\u{1F6B6}\u{1F926}\u{1F937}-\u{1F939}\u{1F93D}\u{1F93E}\u{1F9B8}\u{1F9B9}\u{1F9CD}-\u{1F9CF}\u{1F9D6}-\u{1F9DD}][\u{1F3FB}-\u{1F3FF}]|[\u26F9\u{1F3CB}\u{1F3CC}\u{1F575}][\u{1F3FB}-\u{1F3FF}]|[\u261D\u270A-\u270D\u{1F385}\u{1F3C2}\u{1F3C7}\u{1F442}\u{1F443}\u{1F446}-\u{1F450}\u{1F466}\u{1F467}\u{1F46B}-\u{1F46D}\u{1F470}\u{1F472}\u{1F474}-\u{1F476}\u{1F478}\u{1F47C}\u{1F483}\u{1F485}\u{1F4AA}\u{1F574}\u{1F57A}\u{1F590}\u{1F595}\u{1F596}\u{1F64C}\u{1F64F}\u{1F6C0}\u{1F6CC}\u{1F90F}\u{1F918}-\u{1F91C}\u{1F91E}\u{1F91F}\u{1F930}-\u{1F936}\u{1F9B5}\u{1F9B6}\u{1F9BB}\u{1F9D2}-\u{1F9D5}][\u{1F3FB}-\u{1F3FF}]|[\u231A\u231B\u23E9-\u23EC\u23F0\u23F3\u25FD\u25FE\u2614\u2615\u2648-\u2653\u267F\u2693\u26A1\u26AA\u26AB\u26BD\u26BE\u26C4\u26C5\u26CE\u26D4\u26EA\u26F2\u26F3\u26F5\u26FA\u26FD\u2705\u270A\u270B\u2728\u274C\u274E\u2753-\u2755\u2757\u2795-\u2797\u27B0\u27BF\u2B1B\u2B1C\u2B50\u2B55\u{1F004}\u{1F0CF}\u{1F18E}\u{1F191}-\u{1F19A}\u{1F1E6}-\u{1F1FF}\u{1F201}\u{1F21A}\u{1F22F}\u{1F232}-\u{1F236}\u{1F238}-\u{1F23A}\u{1F250}\u{1F251}\u{1F300}-\u{1F320}\u{1F32D}-\u{1F335}\u{1F337}-\u{1F37C}\u{1F37E}-\u{1F393}\u{1F3A0}-\u{1F3CA}\u{1F3CF}-\u{1F3D3}\u{1F3E0}-\u{1F3F0}\u{1F3F4}\u{1F3F8}-\u{1F43E}\u{1F440}\u{1F442}-\u{1F4FC}\u{1F4FF}-\u{1F53D}\u{1F54B}-\u{1F54E}\u{1F550}-\u{1F567}\u{1F57A}\u{1F595}\u{1F596}\u{1F5A4}\u{1F5FB}-\u{1F64F}\u{1F680}-\u{1F6C5}\u{1F6CC}\u{1F6D0}-\u{1F6D2}\u{1F6D5}\u{1F6EB}\u{1F6EC}\u{1F6F4}-\u{1F6FA}\u{1F7E0}-\u{1F7EB}\u{1F90D}-\u{1F93A}\u{1F93C}-\u{1F945}\u{1F947}-\u{1F971}\u{1F973}-\u{1F976}\u{1F97A}-\u{1F9A2}\u{1F9A5}-\u{1F9AA}\u{1F9AE}-\u{1F9CA}\u{1F9CD}-\u{1F9FF}\u{1FA70}-\u{1FA73}\u{1FA78}-\u{1FA7A}\u{1FA80}-\u{1FA82}\u{1FA90}-\u{1FA95}]|[#\*0-9\xA9\xAE\u203C\u2049\u2122\u2139\u2194-\u2199\u21A9\u21AA\u231A\u231B\u2328\u23CF\u23E9-\u23F3\u23F8-\u23FA\u24C2\u25AA\u25AB\u25B6\u25C0\u25FB-\u25FE\u2600-\u2604\u260E\u2611\u2614\u2615\u2618\u261D\u2620\u2622\u2623\u2626\u262A\u262E\u262F\u2638-\u263A\u2640\u2642\u2648-\u2653\u265F\u2660\u2663\u2665\u2666\u2668\u267B\u267E\u267F\u2692-\u2697\u2699\u269B\u269C\u26A0\u26A1\u26AA\u26AB\u26B0\u26B1\u26BD\u26BE\u26C4\u26C5\u26C8\u26CE\u26CF\u26D1\u26D3\u26D4\u26E9\u26EA\u26F0-\u26F5\u26F7-\u26FA\u26FD\u2702\u2705\u2708-\u270D\u270F\u2712\u2714\u2716\u271D\u2721\u2728\u2733\u2734\u2744\u2747\u274C\u274E\u2753-\u2755\u2757\u2763\u2764\u2795-\u2797\u27A1\u27B0\u27BF\u2934\u2935\u2B05-\u2B07\u2B1B\u2B1C\u2B50\u2B55\u3030\u303D\u3297\u3299\u{1F004}\u{1F0CF}\u{1F170}\u{1F171}\u{1F17E}\u{1F17F}\u{1F18E}\u{1F191}-\u{1F19A}\u{1F1E6}-\u{1F1FF}\u{1F201}\u{1F202}\u{1F21A}\u{1F22F}\u{1F232}-\u{1F23A}\u{1F250}\u{1F251}\u{1F300}-\u{1F321}\u{1F324}-\u{1F393}\u{1F396}\u{1F397}\u{1F399}-\u{1F39B}\u{1F39E}-\u{1F3F0}\u{1F3F3}-\u{1F3F5}\u{1F3F7}-\u{1F4FD}\u{1F4FF}-\u{1F53D}\u{1F549}-\u{1F54E}\u{1F550}-\u{1F567}\u{1F56F}\u{1F570}\u{1F573}-\u{1F57A}\u{1F587}\u{1F58A}-\u{1F58D}\u{1F590}\u{1F595}\u{1F596}\u{1F5A4}\u{1F5A5}\u{1F5A8}\u{1F5B1}\u{1F5B2}\u{1F5BC}\u{1F5C2}-\u{1F5C4}\u{1F5D1}-\u{1F5D3}\u{1F5DC}-\u{1F5DE}\u{1F5E1}\u{1F5E3}\u{1F5E8}\u{1F5EF}\u{1F5F3}\u{1F5FA}-\u{1F64F}\u{1F680}-\u{1F6C5}\u{1F6CB}-\u{1F6D2}\u{1F6D5}\u{1F6E0}-\u{1F6E5}\u{1F6E9}\u{1F6EB}\u{1F6EC}\u{1F6F0}\u{1F6F3}-\u{1F6FA}\u{1F7E0}-\u{1F7EB}\u{1F90D}-\u{1F93A}\u{1F93C}-\u{1F945}\u{1F947}-\u{1F971}\u{1F973}-\u{1F976}\u{1F97A}-\u{1F9A2}\u{1F9A5}-\u{1F9AA}\u{1F9AE}-\u{1F9CA}\u{1F9CD}-\u{1F9FF}\u{1FA70}-\u{1FA73}\u{1FA78}-\u{1FA7A}\u{1FA80}-\u{1FA82}\u{1FA90}-\u{1FA95}]\uFE0F|[\u261D\u26F9\u270A-\u270D\u{1F385}\u{1F3C2}-\u{1F3C4}\u{1F3C7}\u{1F3CA}-\u{1F3CC}\u{1F442}\u{1F443}\u{1F446}-\u{1F450}\u{1F466}-\u{1F478}\u{1F47C}\u{1F481}-\u{1F483}\u{1F485}-\u{1F487}\u{1F48F}\u{1F491}\u{1F4AA}\u{1F574}\u{1F575}\u{1F57A}\u{1F590}\u{1F595}\u{1F596}\u{1F645}-\u{1F647}\u{1F64B}-\u{1F64F}\u{1F6A3}\u{1F6B4}-\u{1F6B6}\u{1F6C0}\u{1F6CC}\u{1F90F}\u{1F918}-\u{1F91F}\u{1F926}\u{1F930}-\u{1F939}\u{1F93C}-\u{1F93E}\u{1F9B5}\u{1F9B6}\u{1F9B8}\u{1F9B9}\u{1F9BB}\u{1F9CD}-\u{1F9CF}\u{1F9D1}-\u{1F9DD}]/gu;
|
| 6 |
+
};
|
platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/wrap-ansi-cjs/node_modules/emoji-regex/es2015/text.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"use strict";
|
| 2 |
+
|
| 3 |
+
module.exports = () => {
|
| 4 |
+
// https://mths.be/emoji
|
| 5 |
+
return /\u{1F3F4}\u{E0067}\u{E0062}(?:\u{E0065}\u{E006E}\u{E0067}|\u{E0073}\u{E0063}\u{E0074}|\u{E0077}\u{E006C}\u{E0073})\u{E007F}|\u{1F468}(?:\u{1F3FC}\u200D(?:\u{1F91D}\u200D\u{1F468}\u{1F3FB}|[\u{1F33E}\u{1F373}\u{1F393}\u{1F3A4}\u{1F3A8}\u{1F3EB}\u{1F3ED}\u{1F4BB}\u{1F4BC}\u{1F527}\u{1F52C}\u{1F680}\u{1F692}\u{1F9AF}-\u{1F9B3}\u{1F9BC}\u{1F9BD}])|\u{1F3FF}\u200D(?:\u{1F91D}\u200D\u{1F468}[\u{1F3FB}-\u{1F3FE}]|[\u{1F33E}\u{1F373}\u{1F393}\u{1F3A4}\u{1F3A8}\u{1F3EB}\u{1F3ED}\u{1F4BB}\u{1F4BC}\u{1F527}\u{1F52C}\u{1F680}\u{1F692}\u{1F9AF}-\u{1F9B3}\u{1F9BC}\u{1F9BD}])|\u{1F3FE}\u200D(?:\u{1F91D}\u200D\u{1F468}[\u{1F3FB}-\u{1F3FD}]|[\u{1F33E}\u{1F373}\u{1F393}\u{1F3A4}\u{1F3A8}\u{1F3EB}\u{1F3ED}\u{1F4BB}\u{1F4BC}\u{1F527}\u{1F52C}\u{1F680}\u{1F692}\u{1F9AF}-\u{1F9B3}\u{1F9BC}\u{1F9BD}])|\u{1F3FD}\u200D(?:\u{1F91D}\u200D\u{1F468}[\u{1F3FB}\u{1F3FC}]|[\u{1F33E}\u{1F373}\u{1F393}\u{1F3A4}\u{1F3A8}\u{1F3EB}\u{1F3ED}\u{1F4BB}\u{1F4BC}\u{1F527}\u{1F52C}\u{1F680}\u{1F692}\u{1F9AF}-\u{1F9B3}\u{1F9BC}\u{1F9BD}])|\u200D(?:\u2764\uFE0F\u200D(?:\u{1F48B}\u200D)?\u{1F468}|[\u{1F468}\u{1F469}]\u200D(?:\u{1F466}\u200D\u{1F466}|\u{1F467}\u200D[\u{1F466}\u{1F467}])|\u{1F466}\u200D\u{1F466}|\u{1F467}\u200D[\u{1F466}\u{1F467}]|[\u{1F468}\u{1F469}]\u200D[\u{1F466}\u{1F467}]|[\u2695\u2696\u2708]\uFE0F|[\u{1F466}\u{1F467}]|[\u{1F33E}\u{1F373}\u{1F393}\u{1F3A4}\u{1F3A8}\u{1F3EB}\u{1F3ED}\u{1F4BB}\u{1F4BC}\u{1F527}\u{1F52C}\u{1F680}\u{1F692}\u{1F9AF}-\u{1F9B3}\u{1F9BC}\u{1F9BD}])|(?:\u{1F3FB}\u200D[\u2695\u2696\u2708]|\u{1F3FF}\u200D[\u2695\u2696\u2708]|\u{1F3FE}\u200D[\u2695\u2696\u2708]|\u{1F3FD}\u200D[\u2695\u2696\u2708]|\u{1F3FC}\u200D[\u2695\u2696\u2708])\uFE0F|\u{1F3FB}\u200D[\u{1F33E}\u{1F373}\u{1F393}\u{1F3A4}\u{1F3A8}\u{1F3EB}\u{1F3ED}\u{1F4BB}\u{1F4BC}\u{1F527}\u{1F52C}\u{1F680}\u{1F692}\u{1F9AF}-\u{1F9B3}\u{1F9BC}\u{1F9BD}]|[\u{1F3FB}-\u{1F3FF}])|(?:\u{1F9D1}\u{1F3FB}\u200D\u{1F91D}\u200D\u{1F9D1}|\u{1F469}\u{1F3FC}\u200D\u{1F91D}\u200D\u{1F469})\u{1F3FB}|\u{1F9D1}(?:\u{1F3FF}\u200D\u{1F91D}\u200D\u{1F9D1}[\u{1F3FB}-\u{1F3FF}]|\u200D\u{1F91D}\u200D\u{1F9D1})|(?:\u{1F9D1}\u{1F3FE}\u200D\u{1F91D}\u200D\u{1F9D1}|\u{1F469}\u{1F3FF}\u200D\u{1F91D}\u200D[\u{1F468}\u{1F469}])[\u{1F3FB}-\u{1F3FE}]|(?:\u{1F9D1}\u{1F3FC}\u200D\u{1F91D}\u200D\u{1F9D1}|\u{1F469}\u{1F3FD}\u200D\u{1F91D}\u200D\u{1F469})[\u{1F3FB}\u{1F3FC}]|\u{1F469}(?:\u{1F3FE}\u200D(?:\u{1F91D}\u200D\u{1F468}[\u{1F3FB}-\u{1F3FD}\u{1F3FF}]|[\u{1F33E}\u{1F373}\u{1F393}\u{1F3A4}\u{1F3A8}\u{1F3EB}\u{1F3ED}\u{1F4BB}\u{1F4BC}\u{1F527}\u{1F52C}\u{1F680}\u{1F692}\u{1F9AF}-\u{1F9B3}\u{1F9BC}\u{1F9BD}])|\u{1F3FC}\u200D(?:\u{1F91D}\u200D\u{1F468}[\u{1F3FB}\u{1F3FD}-\u{1F3FF}]|[\u{1F33E}\u{1F373}\u{1F393}\u{1F3A4}\u{1F3A8}\u{1F3EB}\u{1F3ED}\u{1F4BB}\u{1F4BC}\u{1F527}\u{1F52C}\u{1F680}\u{1F692}\u{1F9AF}-\u{1F9B3}\u{1F9BC}\u{1F9BD}])|\u{1F3FB}\u200D(?:\u{1F91D}\u200D\u{1F468}[\u{1F3FC}-\u{1F3FF}]|[\u{1F33E}\u{1F373}\u{1F393}\u{1F3A4}\u{1F3A8}\u{1F3EB}\u{1F3ED}\u{1F4BB}\u{1F4BC}\u{1F527}\u{1F52C}\u{1F680}\u{1F692}\u{1F9AF}-\u{1F9B3}\u{1F9BC}\u{1F9BD}])|\u{1F3FD}\u200D(?:\u{1F91D}\u200D\u{1F468}[\u{1F3FB}\u{1F3FC}\u{1F3FE}\u{1F3FF}]|[\u{1F33E}\u{1F373}\u{1F393}\u{1F3A4}\u{1F3A8}\u{1F3EB}\u{1F3ED}\u{1F4BB}\u{1F4BC}\u{1F527}\u{1F52C}\u{1F680}\u{1F692}\u{1F9AF}-\u{1F9B3}\u{1F9BC}\u{1F9BD}])|\u200D(?:\u2764\uFE0F\u200D(?:\u{1F48B}\u200D[\u{1F468}\u{1F469}]|[\u{1F468}\u{1F469}])|[\u{1F33E}\u{1F373}\u{1F393}\u{1F3A4}\u{1F3A8}\u{1F3EB}\u{1F3ED}\u{1F4BB}\u{1F4BC}\u{1F527}\u{1F52C}\u{1F680}\u{1F692}\u{1F9AF}-\u{1F9B3}\u{1F9BC}\u{1F9BD}])|\u{1F3FF}\u200D[\u{1F33E}\u{1F373}\u{1F393}\u{1F3A4}\u{1F3A8}\u{1F3EB}\u{1F3ED}\u{1F4BB}\u{1F4BC}\u{1F527}\u{1F52C}\u{1F680}\u{1F692}\u{1F9AF}-\u{1F9B3}\u{1F9BC}\u{1F9BD}])|\u{1F469}\u200D\u{1F469}\u200D(?:\u{1F466}\u200D\u{1F466}|\u{1F467}\u200D[\u{1F466}\u{1F467}])|(?:\u{1F9D1}\u{1F3FD}\u200D\u{1F91D}\u200D\u{1F9D1}|\u{1F469}\u{1F3FE}\u200D\u{1F91D}\u200D\u{1F469})[\u{1F3FB}-\u{1F3FD}]|\u{1F469}\u200D\u{1F466}\u200D\u{1F466}|\u{1F469}\u200D\u{1F469}\u200D[\u{1F466}\u{1F467}]|(?:\u{1F441}\uFE0F\u200D\u{1F5E8}|\u{1F469}(?:\u{1F3FF}\u200D[\u2695\u2696\u2708]|\u{1F3FE}\u200D[\u2695\u2696\u2708]|\u{1F3FC}\u200D[\u2695\u2696\u2708]|\u{1F3FB}\u200D[\u2695\u2696\u2708]|\u{1F3FD}\u200D[\u2695\u2696\u2708]|\u200D[\u2695\u2696\u2708])|(?:[\u26F9\u{1F3CB}\u{1F3CC}\u{1F575}]\uFE0F|[\u{1F46F}\u{1F93C}\u{1F9DE}\u{1F9DF}])\u200D[\u2640\u2642]|[\u26F9\u{1F3CB}\u{1F3CC}\u{1F575}][\u{1F3FB}-\u{1F3FF}]\u200D[\u2640\u2642]|[\u{1F3C3}\u{1F3C4}\u{1F3CA}\u{1F46E}\u{1F471}\u{1F473}\u{1F477}\u{1F481}\u{1F482}\u{1F486}\u{1F487}\u{1F645}-\u{1F647}\u{1F64B}\u{1F64D}\u{1F64E}\u{1F6A3}\u{1F6B4}-\u{1F6B6}\u{1F926}\u{1F937}-\u{1F939}\u{1F93D}\u{1F93E}\u{1F9B8}\u{1F9B9}\u{1F9CD}-\u{1F9CF}\u{1F9D6}-\u{1F9DD}](?:[\u{1F3FB}-\u{1F3FF}]\u200D[\u2640\u2642]|\u200D[\u2640\u2642])|\u{1F3F4}\u200D\u2620)\uFE0F|\u{1F469}\u200D\u{1F467}\u200D[\u{1F466}\u{1F467}]|\u{1F3F3}\uFE0F\u200D\u{1F308}|\u{1F415}\u200D\u{1F9BA}|\u{1F469}\u200D\u{1F466}|\u{1F469}\u200D\u{1F467}|\u{1F1FD}\u{1F1F0}|\u{1F1F4}\u{1F1F2}|\u{1F1F6}\u{1F1E6}|[#\*0-9]\uFE0F\u20E3|\u{1F1E7}[\u{1F1E6}\u{1F1E7}\u{1F1E9}-\u{1F1EF}\u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\u{1F9D6}-\u{1F9DD}][\u{1F3FB}-\u{1F3FF}]|[\u26F9\u{1F3CB}\u{1F3CC}\u{1F575}][\u{1F3FB}-\u{1F3FF}]|[\u261D\u270A-\u270D\u{1F385}\u{1F3C2}\u{1F3C7}\u{1F442}\u{1F443}\u{1F446}-\u{1F450}\u{1F466}\u{1F467}\u{1F46B}-\u{1F46D}\u{1F470}\u{1F472}\u{1F474}-\u{1F476}\u{1F478}\u{1F47C}\u{1F483}\u{1F485}\u{1F4AA}\u{1F574}\u{1F57A}\u{1F590}\u{1F595}\u{1F596}\u{1F64C}\u{1F64F}\u{1F6C0}\u{1F6CC}\u{1F90F}\u{1F918}-\u{1F91C}\u{1F91E}\u{1F91F}\u{1F930}-\u{1F936}\u{1F9B5}\u{1F9B6}\u{1F9BB}\u{1F9D2}-\u{1F9D5}][\u{1F3FB}-\u{1F3FF}]|[\u231A\u231B\u23E9-\u23EC\u23F0\u23F3\u25FD\u25FE\u2614\u2615\u2648-\u2653\u267F\u2693\u26A1\u26AA\u26AB\u26BD\u26BE\u26C4\u26C5\u26CE\u26D4\u26EA\u26F2\u26F3\u26F5\u26FA\u26FD\u2705\u270A\u270B\u2728\u274C\u274E\u2753-\u2755\u2757\u2795-\u2797\u27B0\u27BF\u2B1B\u2B1C\u2B50\u2B55\u{1F004}\u{1F0CF}\u{1F18E}\u{1F191}-\u{1F19A}\u{1F1E6}-\u{1F1FF}\u{1F201}\u{1F21A}\u{1F22F}\u{1F232}-\u{1F236}\u{1F238}-\u{1F23A}\u{1F250}\u{1F251}\u{1F300}-\u{1F320}\u{1F32D}-\u{1F335}\u{1F337}-\u{1F37C}\u{1F37E}-\u{1F393}\u{1F3A0}-\u{1F3CA}\u{1F3CF}-\u{1F3D3}\u{1F3E0}-\u{1F3F0}\u{1F3F4}\u{1F3F8}-\u{1F43E}\u{1F440}\u{1F442}-\u{1F4FC}\u{1F4FF}-\u{1F53D}\u{1F54B}-\u{1F54E}\u{1F550}-\u{1F567}\u{1F57A}\u{1F595}\u{1F596}\u{1F5A4}\u{1F5FB}-\u{1F64F}\u{1F680}-\u{1F6C5}\u{1F6CC}\u{1F6D0}-\u{1F6D2}\u{1F6D5}\u{1F6EB}\u{1F6EC}\u{1F6F4}-\u{1F6FA}\u{1F7E0}-\u{1F7EB}\u{1F90D}-\u{1F93A}\u{1F93C}-\u{1F945}\u{1F947}-\u{1F971}\u{1F973}-\u{1F976}\u{1F97A}-\u{1F9A2}\u{1F9A5}-\u{1F9AA}\u{1F9AE}-\u{1F9CA}\u{1F9CD}-\u{1F9FF}\u{1FA70}-\u{1FA73}\u{1FA78}-\u{1FA7A}\u{1FA80}-\u{1FA82}\u{1FA90}-\u{1FA95}]|[#\*0-9\xA9\xAE\u203C\u2049\u2122\u2139\u2194-\u2199\u21A9\u21AA\u231A\u231B\u2328\u23CF\u23E9-\u23F3\u23F8-\u23FA\u24C2\u25AA\u25AB\u25B6\u25C0\u25FB-\u25FE\u2600-\u2604\u260E\u2611\u2614\u2615\u2618\u261D\u2620\u2622\u2623\u2626\u262A\u262E\u262F\u2638-\u263A\u2640\u2642\u2648-\u2653\u265F\u2660\u2663\u2665\u2666\u2668\u267B\u267E\u267F\u2692-\u2697\u2699\u269B\u269C\u26A0\u26A1\u26AA\u26AB\u26B0\u26B1\u26BD\u26BE\u26C4\u26C5\u26C8\u26CE\u26CF\u26D1\u26D3\u26D4\u26E9\u26EA\u26F0-\u26F5\u26F7-\u26FA\u26FD\u2702\u2705\u2708-\u270D\u270F\u2712\u2714\u2716\u271D\u2721\u2728\u2733\u2734\u2744\u2747\u274C\u274E\u2753-\u2755\u2757\u2763\u2764\u2795-\u2797\u27A1\u27B0\u27BF\u2934\u2935\u2B05-\u2B07\u2B1B\u2B1C\u2B50\u2B55\u3030\u303D\u3297\u3299\u{1F004}\u{1F0CF}\u{1F170}\u{1F171}\u{1F17E}\u{1F17F}\u{1F18E}\u{1F191}-\u{1F19A}\u{1F1E6}-\u{1F1FF}\u{1F201}\u{1F202}\u{1F21A}\u{1F22F}\u{1F232}-\u{1F23A}\u{1F250}\u{1F251}\u{1F300}-\u{1F321}\u{1F324}-\u{1F393}\u{1F396}\u{1F397}\u{1F399}-\u{1F39B}\u{1F39E}-\u{1F3F0}\u{1F3F3}-\u{1F3F5}\u{1F3F7}-\u{1F4FD}\u{1F4FF}-\u{1F53D}\u{1F549}-\u{1F54E}\u{1F550}-\u{1F567}\u{1F56F}\u{1F570}\u{1F573}-\u{1F57A}\u{1F587}\u{1F58A}-\u{1F58D}\u{1F590}\u{1F595}\u{1F596}\u{1F5A4}\u{1F5A5}\u{1F5A8}\u{1F5B1}\u{1F5B2}\u{1F5BC}\u{1F5C2}-\u{1F5C4}\u{1F5D1}-\u{1F5D3}\u{1F5DC}-\u{1F5DE}\u{1F5E1}\u{1F5E3}\u{1F5E8}\u{1F5EF}\u{1F5F3}\u{1F5FA}-\u{1F64F}\u{1F680}-\u{1F6C5}\u{1F6CB}-\u{1F6D2}\u{1F6D5}\u{1F6E0}-\u{1F6E5}\u{1F6E9}\u{1F6EB}\u{1F6EC}\u{1F6F0}\u{1F6F3}-\u{1F6FA}\u{1F7E0}-\u{1F7EB}\u{1F90D}-\u{1F93A}\u{1F93C}-\u{1F945}\u{1F947}-\u{1F971}\u{1F973}-\u{1F976}\u{1F97A}-\u{1F9A2}\u{1F9A5}-\u{1F9AA}\u{1F9AE}-\u{1F9CA}\u{1F9CD}-\u{1F9FF}\u{1FA70}-\u{1FA73}\u{1FA78}-\u{1FA7A}\u{1FA80}-\u{1FA82}\u{1FA90}-\u{1FA95}]\uFE0F?|[\u261D\u26F9\u270A-\u270D\u{1F385}\u{1F3C2}-\u{1F3C4}\u{1F3C7}\u{1F3CA}-\u{1F3CC}\u{1F442}\u{1F443}\u{1F446}-\u{1F450}\u{1F466}-\u{1F478}\u{1F47C}\u{1F481}-\u{1F483}\u{1F485}-\u{1F487}\u{1F48F}\u{1F491}\u{1F4AA}\u{1F574}\u{1F575}\u{1F57A}\u{1F590}\u{1F595}\u{1F596}\u{1F645}-\u{1F647}\u{1F64B}-\u{1F64F}\u{1F6A3}\u{1F6B4}-\u{1F6B6}\u{1F6C0}\u{1F6CC}\u{1F90F}\u{1F918}-\u{1F91F}\u{1F926}\u{1F930}-\u{1F939}\u{1F93C}-\u{1F93E}\u{1F9B5}\u{1F9B6}\u{1F9B8}\u{1F9B9}\u{1F9BB}\u{1F9CD}-\u{1F9CF}\u{1F9D1}-\u{1F9DD}]/gu;
|
| 6 |
+
};
|
platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/wrap-ansi-cjs/node_modules/emoji-regex/index.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
declare module 'emoji-regex' {
|
| 2 |
+
function emojiRegex(): RegExp;
|
| 3 |
+
|
| 4 |
+
export default emojiRegex;
|
| 5 |
+
}
|
| 6 |
+
|
| 7 |
+
declare module 'emoji-regex/text' {
|
| 8 |
+
function emojiRegex(): RegExp;
|
| 9 |
+
|
| 10 |
+
export default emojiRegex;
|
| 11 |
+
}
|
| 12 |
+
|
| 13 |
+
declare module 'emoji-regex/es2015' {
|
| 14 |
+
function emojiRegex(): RegExp;
|
| 15 |
+
|
| 16 |
+
export default emojiRegex;
|
| 17 |
+
}
|
| 18 |
+
|
| 19 |
+
declare module 'emoji-regex/es2015/text' {
|
| 20 |
+
function emojiRegex(): RegExp;
|
| 21 |
+
|
| 22 |
+
export default emojiRegex;
|
| 23 |
+
}
|
platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/wrap-ansi-cjs/node_modules/emoji-regex/index.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"use strict";
|
| 2 |
+
|
| 3 |
+
module.exports = function () {
|
| 4 |
+
// https://mths.be/emoji
|
| 5 |
+
return /\uD83C\uDFF4\uDB40\uDC67\uDB40\uDC62(?:\uDB40\uDC65\uDB40\uDC6E\uDB40\uDC67|\uDB40\uDC73\uDB40\uDC63\uDB40\uDC74|\uDB40\uDC77\uDB40\uDC6C\uDB40\uDC73)\uDB40\uDC7F|\uD83D\uDC68(?:\uD83C\uDFFC\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68\uD83C\uDFFB|\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFF\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB-\uDFFE])|\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFE\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB-\uDFFD])|\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFD\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB\uDFFC])|\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\u200D(?:\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D)?\uD83D\uDC68|(?:\uD83D[\uDC68\uDC69])\u200D(?:\uD83D\uDC66\u200D\uD83D\uDC66|\uD83D\uDC67\u200D(?:\uD83D[\uDC66\uDC67]))|\uD83D\uDC66\u200D\uD83D\uDC66|\uD83D\uDC67\u200D(?:\uD83D[\uDC66\uDC67])|(?:\uD83D[\uDC68\uDC69])\u200D(?:\uD83D[\uDC66\uDC67])|[\u2695\u2696\u2708]\uFE0F|\uD83D[\uDC66\uDC67]|\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|(?:\uD83C\uDFFB\u200D[\u2695\u2696\u2708]|\uD83C\uDFFF\u200D[\u2695\u2696\u2708]|\uD83C\uDFFE\u200D[\u2695\u2696\u2708]|\uD83C\uDFFD\u200D[\u2695\u2696\u2708]|\uD83C\uDFFC\u200D[\u2695\u2696\u2708])\uFE0F|\uD83C\uDFFB\u200D(?:\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C[\uDFFB-\uDFFF])|(?:\uD83E\uDDD1\uD83C\uDFFB\u200D\uD83E\uDD1D\u200D\uD83E\uDDD1|\uD83D\uDC69\uD83C\uDFFC\u200D\uD83E\uDD1D\u200D\uD83D\uDC69)\uD83C\uDFFB|\uD83E\uDDD1(?:\uD83C\uDFFF\u200D\uD83E\uDD1D\u200D\uD83E\uDDD1(?:\uD83C[\uDFFB-\uDFFF])|\u200D\uD83E\uDD1D\u200D\uD83E\uDDD1)|(?:\uD83E\uDDD1\uD83C\uDFFE\u200D\uD83E\uDD1D\u200D\uD83E\uDDD1|\uD83D\uDC69\uD83C\uDFFF\u200D\uD83E\uDD1D\u200D(?:\uD83D[\uDC68\uDC69]))(?:\uD83C[\uDFFB-\uDFFE])|(?:\uD83E\uDDD1\uD83C\uDFFC\u200D\uD83E\uDD1D\u200D\uD83E\uDDD1|\uD83D\uDC69\uD83C\uDFFD\u200D\uD83E\uDD1D\u200D\uD83D\uDC69)(?:\uD83C[\uDFFB\uDFFC])|\uD83D\uDC69(?:\uD83C\uDFFE\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB-\uDFFD\uDFFF])|\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFC\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB\uDFFD-\uDFFF])|\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFB\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFC-\uDFFF])|\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFD\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF])|\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\u200D(?:\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D(?:\uD83D[\uDC68\uDC69])|\uD83D[\uDC68\uDC69])|\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFF\u200D(?:\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD]))|\uD83D\uDC69\u200D\uD83D\uDC69\u200D(?:\uD83D\uDC66\u200D\uD83D\uDC66|\uD83D\uDC67\u200D(?:\uD83D[\uDC66\uDC67]))|(?:\uD83E\uDDD1\uD83C\uDFFD\u200D\uD83E\uDD1D\u200D\uD83E\uDDD1|\uD83D\uDC69\uD83C\uDFFE\u200D\uD83E\uDD1D\u200D\uD83D\uDC69)(?:\uD83C[\uDFFB-\uDFFD])|\uD83D\uDC69\u200D\uD83D\uDC66\u200D\uD83D\uDC66|\uD83D\uDC69\u200D\uD83D\uDC69\u200D(?:\uD83D[\uDC66\uDC67])|(?:\uD83D\uDC41\uFE0F\u200D\uD83D\uDDE8|\uD83D\uDC69(?:\uD83C\uDFFF\u200D[\u2695\u2696\u2708]|\uD83C\uDFFE\u200D[\u2695\u2696\u2708]|\uD83C\uDFFC\u200D[\u2695\u2696\u2708]|\uD83C\uDFFB\u200D[\u2695\u2696\u2708]|\uD83C\uDFFD\u200D[\u2695\u2696\u2708]|\u200D[\u2695\u2696\u2708])|(?:(?:\u26F9|\uD83C[\uDFCB\uDFCC]|\uD83D\uDD75)\uFE0F|\uD83D\uDC6F|\uD83E[\uDD3C\uDDDE\uDDDF])\u200D[\u2640\u2642]|(?:\u26F9|\uD83C[\uDFCB\uDFCC]|\uD83D\uDD75)(?:\uD83C[\uDFFB-\uDFFF])\u200D[\u2640\u2642]|(?:\uD83C[\uDFC3\uDFC4\uDFCA]|\uD83D[\uDC6E\uDC71\uDC73\uDC77\uDC81\uDC82\uDC86\uDC87\uDE45-\uDE47\uDE4B\uDE4D\uDE4E\uDEA3\uDEB4-\uDEB6]|\uD83E[\uDD26\uDD37-\uDD39\uDD3D\uDD3E\uDDB8\uDDB9\uDDCD-\uDDCF\uDDD6-\uDDDD])(?:(?:\uD83C[\uDFFB-\uDFFF])\u200D[\u2640\u2642]|\u200D[\u2640\u2642])|\uD83C\uDFF4\u200D\u2620)\uFE0F|\uD83D\uDC69\u200D\uD83D\uDC67\u200D(?:\uD83D[\uDC66\uDC67])|\uD83C\uDFF3\uFE0F\u200D\uD83C\uDF08|\uD83D\uDC15\u200D\uD83E\uDDBA|\uD83D\uDC69\u200D\uD83D\uDC66|\uD83D\uDC69\u200D\uD83D\uDC67|\uD83C\uDDFD\uD83C\uDDF0|\uD83C\uDDF4\uD83C\uDDF2|\uD83C\uDDF6\uD83C\uDDE6|[#\*0-9]\uFE0F\u20E3|\uD83C\uDDE7(?:\uD83C[\uDDE6\uDDE7\uDDE9-\uDDEF\uDDF1-\uDDF4\uDDF6-\uDDF9\uDDFB\uDDFC\uDDFE\uDDFF])|\uD83C\uDDF9(?:\uD83C[\uDDE6\uDDE8\uDDE9\uDDEB-\uDDED\uDDEF-\uDDF4\uDDF7\uDDF9\uDDFB\uDDFC\uDDFF])|\uD83C\uDDEA(?:\uD83C[\uDDE6\uDDE8\uDDEA\uDDEC\uDDED\uDDF7-\uDDFA])|\uD83E\uDDD1(?:\uD83C[\uDFFB-\uDFFF])|\uD83C\uDDF7(?:\uD83C[\uDDEA\uDDF4\uDDF8\uDDFA\uDDFC])|\uD83D\uDC69(?:\uD83C[\uDFFB-\uDFFF])|\uD83C\uDDF2(?:\uD83C[\uDDE6\uDDE8-\uDDED\uDDF0-\uDDFF])|\uD83C\uDDE6(?:\uD83C[\uDDE8-\uDDEC\uDDEE\uDDF1\uDDF2\uDDF4\uDDF6-\uDDFA\uDDFC\uDDFD\uDDFF])|\uD83C\uDDF0(?:\uD83C[\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DEF(?:\uD83C[\uDDEA\uDDF2\uDDF4\uDDF5])|(?:\uD83C[\uDFC3\uDFC4\uDFCA]|\uD83D[\uDC6E\uDC71\uDC73\uDC77\uDC81\uDC82\uDC86\uDC87\uDE45-\uDE47\uDE4B\uDE4D\uDE4E\uDEA3\uDEB4-\uDEB6]|\uD83E[\uDD26\uDD37-\uDD39\uDD3D\uDD3E\uDDB8\uDDB9\uDDCD-\uDDCF\uDDD6-\uDDDD])(?:\uD83C[\uDFFB-\uDFFF])|(?:\u26F9|\uD83C[\uDFCB\uDFCC]|\uD83D\uDD75)(?:\uD83C[\uDFFB-\uDFFF])|(?:[\u261D\u270A-\u270D]|\uD83C[\uDF85\uDFC2\uDFC7]|\uD83D[\uDC42\uDC43\uDC46-\uDC50\uDC66\uDC67\uDC6B-\uDC6D\uDC70\uDC72\uDC74-\uDC76\uDC78\uDC7C\uDC83\uDC85\uDCAA\uDD74\uDD7A\uDD90\uDD95\uDD96\uDE4C\uDE4F\uDEC0\uDECC]|\uD83E[\uDD0F\uDD18-\uDD1C\uDD1E\uDD1F\uDD30-\uDD36\uDDB5\uDDB6\uDDBB\uDDD2-\uDDD5])(?:\uD83C[\uDFFB-\uDFFF])|(?:[\u231A\u231B\u23E9-\u23EC\u23F0\u23F3\u25FD\u25FE\u2614\u2615\u2648-\u2653\u267F\u2693\u26A1\u26AA\u26AB\u26BD\u26BE\u26C4\u26C5\u26CE\u26D4\u26EA\u26F2\u26F3\u26F5\u26FA\u26FD\u2705\u270A\u270B\u2728\u274C\u274E\u2753-\u2755\u2757\u2795-\u2797\u27B0\u27BF\u2B1B\u2B1C\u2B50\u2B55]|\uD83C[\uDC04\uDCCF\uDD8E\uDD91-\uDD9A\uDDE6-\uDDFF\uDE01\uDE1A\uDE2F\uDE32-\uDE36\uDE38-\uDE3A\uDE50\uDE51\uDF00-\uDF20\uDF2D-\uDF35\uDF37-\uDF7C\uDF7E-\uDF93\uDFA0-\uDFCA\uDFCF-\uDFD3\uDFE0-\uDFF0\uDFF4\uDFF8-\uDFFF]|\uD83D[\uDC00-\uDC3E\uDC40\uDC42-\uDCFC\uDCFF-\uDD3D\uDD4B-\uDD4E\uDD50-\uDD67\uDD7A\uDD95\uDD96\uDDA4\uDDFB-\uDE4F\uDE80-\uDEC5\uDECC\uDED0-\uDED2\uDED5\uDEEB\uDEEC\uDEF4-\uDEFA\uDFE0-\uDFEB]|\uD83E[\uDD0D-\uDD3A\uDD3C-\uDD45\uDD47-\uDD71\uDD73-\uDD76\uDD7A-\uDDA2\uDDA5-\uDDAA\uDDAE-\uDDCA\uDDCD-\uDDFF\uDE70-\uDE73\uDE78-\uDE7A\uDE80-\uDE82\uDE90-\uDE95])|(?:[#\*0-9\xA9\xAE\u203C\u2049\u2122\u2139\u2194-\u2199\u21A9\u21AA\u231A\u231B\u2328\u23CF\u23E9-\u23F3\u23F8-\u23FA\u24C2\u25AA\u25AB\u25B6\u25C0\u25FB-\u25FE\u2600-\u2604\u260E\u2611\u2614\u2615\u2618\u261D\u2620\u2622\u2623\u2626\u262A\u262E\u262F\u2638-\u263A\u2640\u2642\u2648-\u2653\u265F\u2660\u2663\u2665\u2666\u2668\u267B\u267E\u267F\u2692-\u2697\u2699\u269B\u269C\u26A0\u26A1\u26AA\u26AB\u26B0\u26B1\u26BD\u26BE\u26C4\u26C5\u26C8\u26CE\u26CF\u26D1\u26D3\u26D4\u26E9\u26EA\u26F0-\u26F5\u26F7-\u26FA\u26FD\u2702\u2705\u2708-\u270D\u270F\u2712\u2714\u2716\u271D\u2721\u2728\u2733\u2734\u2744\u2747\u274C\u274E\u2753-\u2755\u2757\u2763\u2764\u2795-\u2797\u27A1\u27B0\u27BF\u2934\u2935\u2B05-\u2B07\u2B1B\u2B1C\u2B50\u2B55\u3030\u303D\u3297\u3299]|\uD83C[\uDC04\uDCCF\uDD70\uDD71\uDD7E\uDD7F\uDD8E\uDD91-\uDD9A\uDDE6-\uDDFF\uDE01\uDE02\uDE1A\uDE2F\uDE32-\uDE3A\uDE50\uDE51\uDF00-\uDF21\uDF24-\uDF93\uDF96\uDF97\uDF99-\uDF9B\uDF9E-\uDFF0\uDFF3-\uDFF5\uDFF7-\uDFFF]|\uD83D[\uDC00-\uDCFD\uDCFF-\uDD3D\uDD49-\uDD4E\uDD50-\uDD67\uDD6F\uDD70\uDD73-\uDD7A\uDD87\uDD8A-\uDD8D\uDD90\uDD95\uDD96\uDDA4\uDDA5\uDDA8\uDDB1\uDDB2\uDDBC\uDDC2-\uDDC4\uDDD1-\uDDD3\uDDDC-\uDDDE\uDDE1\uDDE3\uDDE8\uDDEF\uDDF3\uDDFA-\uDE4F\uDE80-\uDEC5\uDECB-\uDED2\uDED5\uDEE0-\uDEE5\uDEE9\uDEEB\uDEEC\uDEF0\uDEF3-\uDEFA\uDFE0-\uDFEB]|\uD83E[\uDD0D-\uDD3A\uDD3C-\uDD45\uDD47-\uDD71\uDD73-\uDD76\uDD7A-\uDDA2\uDDA5-\uDDAA\uDDAE-\uDDCA\uDDCD-\uDDFF\uDE70-\uDE73\uDE78-\uDE7A\uDE80-\uDE82\uDE90-\uDE95])\uFE0F|(?:[\u261D\u26F9\u270A-\u270D]|\uD83C[\uDF85\uDFC2-\uDFC4\uDFC7\uDFCA-\uDFCC]|\uD83D[\uDC42\uDC43\uDC46-\uDC50\uDC66-\uDC78\uDC7C\uDC81-\uDC83\uDC85-\uDC87\uDC8F\uDC91\uDCAA\uDD74\uDD75\uDD7A\uDD90\uDD95\uDD96\uDE45-\uDE47\uDE4B-\uDE4F\uDEA3\uDEB4-\uDEB6\uDEC0\uDECC]|\uD83E[\uDD0F\uDD18-\uDD1F\uDD26\uDD30-\uDD39\uDD3C-\uDD3E\uDDB5\uDDB6\uDDB8\uDDB9\uDDBB\uDDCD-\uDDCF\uDDD1-\uDDDD])/g;
|
| 6 |
+
};
|
platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/wrap-ansi-cjs/node_modules/emoji-regex/package.json
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "emoji-regex",
|
| 3 |
+
"version": "8.0.0",
|
| 4 |
+
"description": "A regular expression to match all Emoji-only symbols as per the Unicode Standard.",
|
| 5 |
+
"homepage": "https://mths.be/emoji-regex",
|
| 6 |
+
"main": "index.js",
|
| 7 |
+
"types": "index.d.ts",
|
| 8 |
+
"keywords": [
|
| 9 |
+
"unicode",
|
| 10 |
+
"regex",
|
| 11 |
+
"regexp",
|
| 12 |
+
"regular expressions",
|
| 13 |
+
"code points",
|
| 14 |
+
"symbols",
|
| 15 |
+
"characters",
|
| 16 |
+
"emoji"
|
| 17 |
+
],
|
| 18 |
+
"license": "MIT",
|
| 19 |
+
"author": {
|
| 20 |
+
"name": "Mathias Bynens",
|
| 21 |
+
"url": "https://mathiasbynens.be/"
|
| 22 |
+
},
|
| 23 |
+
"repository": {
|
| 24 |
+
"type": "git",
|
| 25 |
+
"url": "https://github.com/mathiasbynens/emoji-regex.git"
|
| 26 |
+
},
|
| 27 |
+
"bugs": "https://github.com/mathiasbynens/emoji-regex/issues",
|
| 28 |
+
"files": [
|
| 29 |
+
"LICENSE-MIT.txt",
|
| 30 |
+
"index.js",
|
| 31 |
+
"index.d.ts",
|
| 32 |
+
"text.js",
|
| 33 |
+
"es2015/index.js",
|
| 34 |
+
"es2015/text.js"
|
| 35 |
+
],
|
| 36 |
+
"scripts": {
|
| 37 |
+
"build": "rm -rf -- es2015; babel src -d .; NODE_ENV=es2015 babel src -d ./es2015; node script/inject-sequences.js",
|
| 38 |
+
"test": "mocha",
|
| 39 |
+
"test:watch": "npm run test -- --watch"
|
| 40 |
+
},
|
| 41 |
+
"devDependencies": {
|
| 42 |
+
"@babel/cli": "^7.2.3",
|
| 43 |
+
"@babel/core": "^7.3.4",
|
| 44 |
+
"@babel/plugin-proposal-unicode-property-regex": "^7.2.0",
|
| 45 |
+
"@babel/preset-env": "^7.3.4",
|
| 46 |
+
"mocha": "^6.0.2",
|
| 47 |
+
"regexgen": "^1.3.0",
|
| 48 |
+
"unicode-12.0.0": "^0.7.9"
|
| 49 |
+
}
|
| 50 |
+
}
|
platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/wrap-ansi-cjs/node_modules/emoji-regex/text.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"use strict";
|
| 2 |
+
|
| 3 |
+
module.exports = function () {
|
| 4 |
+
// https://mths.be/emoji
|
| 5 |
+
return /\uD83C\uDFF4\uDB40\uDC67\uDB40\uDC62(?:\uDB40\uDC65\uDB40\uDC6E\uDB40\uDC67|\uDB40\uDC73\uDB40\uDC63\uDB40\uDC74|\uDB40\uDC77\uDB40\uDC6C\uDB40\uDC73)\uDB40\uDC7F|\uD83D\uDC68(?:\uD83C\uDFFC\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68\uD83C\uDFFB|\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFF\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB-\uDFFE])|\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFE\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB-\uDFFD])|\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFD\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB\uDFFC])|\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\u200D(?:\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D)?\uD83D\uDC68|(?:\uD83D[\uDC68\uDC69])\u200D(?:\uD83D\uDC66\u200D\uD83D\uDC66|\uD83D\uDC67\u200D(?:\uD83D[\uDC66\uDC67]))|\uD83D\uDC66\u200D\uD83D\uDC66|\uD83D\uDC67\u200D(?:\uD83D[\uDC66\uDC67])|(?:\uD83D[\uDC68\uDC69])\u200D(?:\uD83D[\uDC66\uDC67])|[\u2695\u2696\u2708]\uFE0F|\uD83D[\uDC66\uDC67]|\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|(?:\uD83C\uDFFB\u200D[\u2695\u2696\u2708]|\uD83C\uDFFF\u200D[\u2695\u2696\u2708]|\uD83C\uDFFE\u200D[\u2695\u2696\u2708]|\uD83C\uDFFD\u200D[\u2695\u2696\u2708]|\uD83C\uDFFC\u200D[\u2695\u2696\u2708])\uFE0F|\uD83C\uDFFB\u200D(?:\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C[\uDFFB-\uDFFF])|(?:\uD83E\uDDD1\uD83C\uDFFB\u200D\uD83E\uDD1D\u200D\uD83E\uDDD1|\uD83D\uDC69\uD83C\uDFFC\u200D\uD83E\uDD1D\u200D\uD83D\uDC69)\uD83C\uDFFB|\uD83E\uDDD1(?:\uD83C\uDFFF\u200D\uD83E\uDD1D\u200D\uD83E\uDDD1(?:\uD83C[\uDFFB-\uDFFF])|\u200D\uD83E\uDD1D\u200D\uD83E\uDDD1)|(?:\uD83E\uDDD1\uD83C\uDFFE\u200D\uD83E\uDD1D\u200D\uD83E\uDDD1|\uD83D\uDC69\uD83C\uDFFF\u200D\uD83E\uDD1D\u200D(?:\uD83D[\uDC68\uDC69]))(?:\uD83C[\uDFFB-\uDFFE])|(?:\uD83E\uDDD1\uD83C\uDFFC\u200D\uD83E\uDD1D\u200D\uD83E\uDDD1|\uD83D\uDC69\uD83C\uDFFD\u200D\uD83E\uDD1D\u200D\uD83D\uDC69)(?:\uD83C[\uDFFB\uDFFC])|\uD83D\uDC69(?:\uD83C\uDFFE\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB-\uDFFD\uDFFF])|\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFC\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB\uDFFD-\uDFFF])|\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFB\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFC-\uDFFF])|\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFD\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF])|\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\u200D(?:\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D(?:\uD83D[\uDC68\uDC69])|\uD83D[\uDC68\uDC69])|\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFF\u200D(?:\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD]))|\uD83D\uDC69\u200D\uD83D\uDC69\u200D(?:\uD83D\uDC66\u200D\uD83D\uDC66|\uD83D\uDC67\u200D(?:\uD83D[\uDC66\uDC67]))|(?:\uD83E\uDDD1\uD83C\uDFFD\u200D\uD83E\uDD1D\u200D\uD83E\uDDD1|\uD83D\uDC69\uD83C\uDFFE\u200D\uD83E\uDD1D\u200D\uD83D\uDC69)(?:\uD83C[\uDFFB-\uDFFD])|\uD83D\uDC69\u200D\uD83D\uDC66\u200D\uD83D\uDC66|\uD83D\uDC69\u200D\uD83D\uDC69\u200D(?:\uD83D[\uDC66\uDC67])|(?:\uD83D\uDC41\uFE0F\u200D\uD83D\uDDE8|\uD83D\uDC69(?:\uD83C\uDFFF\u200D[\u2695\u2696\u2708]|\uD83C\uDFFE\u200D[\u2695\u2696\u2708]|\uD83C\uDFFC\u200D[\u2695\u2696\u2708]|\uD83C\uDFFB\u200D[\u2695\u2696\u2708]|\uD83C\uDFFD\u200D[\u2695\u2696\u2708]|\u200D[\u2695\u2696\u2708])|(?:(?:\u26F9|\uD83C[\uDFCB\uDFCC]|\uD83D\uDD75)\uFE0F|\uD83D\uDC6F|\uD83E[\uDD3C\uDDDE\uDDDF])\u200D[\u2640\u2642]|(?:\u26F9|\uD83C[\uDFCB\uDFCC]|\uD83D\uDD75)(?:\uD83C[\uDFFB-\uDFFF])\u200D[\u2640\u2642]|(?:\uD83C[\uDFC3\uDFC4\uDFCA]|\uD83D[\uDC6E\uDC71\uDC73\uDC77\uDC81\uDC82\uDC86\uDC87\uDE45-\uDE47\uDE4B\uDE4D\uDE4E\uDEA3\uDEB4-\uDEB6]|\uD83E[\uDD26\uDD37-\uDD39\uDD3D\uDD3E\uDDB8\uDDB9\uDDCD-\uDDCF\uDDD6-\uDDDD])(?:(?:\uD83C[\uDFFB-\uDFFF])\u200D[\u2640\u2642]|\u200D[\u2640\u2642])|\uD83C\uDFF4\u200D\u2620)\uFE0F|\uD83D\uDC69\u200D\uD83D\uDC67\u200D(?:\uD83D[\uDC66\uDC67])|\uD83C\uDFF3\uFE0F\u200D\uD83C\uDF08|\uD83D\uDC15\u200D\uD83E\uDDBA|\uD83D\uDC69\u200D\uD83D\uDC66|\uD83D\uDC69\u200D\uD83D\uDC67|\uD83C\uDDFD\uD83C\uDDF0|\uD83C\uDDF4\uD83C\uDDF2|\uD83C\uDDF6\uD83C\uDDE6|[#\*0-9]\uFE0F\u20E3|\uD83C\uDDE7(?:\uD83C[\uDDE6\uDDE7\uDDE9-\uDDEF\u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\uDD18-\uDD1C\uDD1E\uDD1F\uDD30-\uDD36\uDDB5\uDDB6\uDDBB\uDDD2-\uDDD5])(?:\uD83C[\uDFFB-\uDFFF])|(?:[\u231A\u231B\u23E9-\u23EC\u23F0\u23F3\u25FD\u25FE\u2614\u2615\u2648-\u2653\u267F\u2693\u26A1\u26AA\u26AB\u26BD\u26BE\u26C4\u26C5\u26CE\u26D4\u26EA\u26F2\u26F3\u26F5\u26FA\u26FD\u2705\u270A\u270B\u2728\u274C\u274E\u2753-\u2755\u2757\u2795-\u2797\u27B0\u27BF\u2B1B\u2B1C\u2B50\u2B55]|\uD83C[\uDC04\uDCCF\uDD8E\uDD91-\uDD9A\uDDE6-\uDDFF\uDE01\uDE1A\uDE2F\uDE32-\uDE36\uDE38-\uDE3A\uDE50\uDE51\uDF00-\uDF20\uDF2D-\uDF35\uDF37-\uDF7C\uDF7E-\uDF93\uDFA0-\uDFCA\uDFCF-\uDFD3\uDFE0-\uDFF0\uDFF4\uDFF8-\uDFFF]|\uD83D[\uDC00-\uDC3E\uDC40\uDC42-\uDCFC\uDCFF-\uDD3D\uDD4B-\uDD4E\uDD50-\uDD67\uDD7A\uDD95\uDD96\uDDA4\uDDFB-\uDE4F\uDE80-\uDEC5\uDECC\uDED0-\uDED2\uDED5\uDEEB\uDEEC\uDEF4-\uDEFA\uDFE0-\uDFEB]|\uD83E[\uDD0D-\uDD3A\uDD3C-\uDD45\uDD47-\uDD71\uDD73-\uDD76\uDD7A-\uDDA2\uDDA5-\uDDAA\uDDAE-\uDDCA\uDDCD-\uDDFF\uDE70-\uDE73\uDE78-\uDE7A\uDE80-\uDE82\uDE90-\uDE95])|(?:[#\*0-9\xA9\xAE\u203C\u2049\u2122\u2139\u2194-\u2199\u21A9\u21AA\u231A\u231B\u2328\u23CF\u23E9-\u23F3\u23F8-\u23FA\u24C2\u25AA\u25AB\u25B6\u25C0\u25FB-\u25FE\u2600-\u2604\u260E\u2611\u2614\u2615\u2618\u261D\u2620\u2622\u2623\u2626\u262A\u262E\u262F\u2638-\u263A\u2640\u2642\u2648-\u2653\u265F\u2660\u2663\u2665\u2666\u2668\u267B\u267E\u267F\u2692-\u2697\u2699\u269B\u269C\u26A0\u26A1\u26AA\u26AB\u26B0\u26B1\u26BD\u26BE\u26C4\u26C5\u26C8\u26CE\u26CF\u26D1\u26D3\u26D4\u26E9\u26EA\u26F0-\u26F5\u26F7-\u26FA\u26FD\u2702\u2705\u2708-\u270D\u270F\u2712\u2714\u2716\u271D\u2721\u2728\u2733\u2734\u2744\u2747\u274C\u274E\u2753-\u2755\u2757\u2763\u2764\u2795-\u2797\u27A1\u27B0\u27BF\u2934\u2935\u2B05-\u2B07\u2B1B\u2B1C\u2B50\u2B55\u3030\u303D\u3297\u3299]|\uD83C[\uDC04\uDCCF\uDD70\uDD71\uDD7E\uDD7F\uDD8E\uDD91-\uDD9A\uDDE6-\uDDFF\uDE01\uDE02\uDE1A\uDE2F\uDE32-\uDE3A\uDE50\uDE51\uDF00-\uDF21\uDF24-\uDF93\uDF96\uDF97\uDF99-\uDF9B\uDF9E-\uDFF0\uDFF3-\uDFF5\uDFF7-\uDFFF]|\uD83D[\uDC00-\uDCFD\uDCFF-\uDD3D\uDD49-\uDD4E\uDD50-\uDD67\uDD6F\uDD70\uDD73-\uDD7A\uDD87\uDD8A-\uDD8D\uDD90\uDD95\uDD96\uDDA4\uDDA5\uDDA8\uDDB1\uDDB2\uDDBC\uDDC2-\uDDC4\uDDD1-\uDDD3\uDDDC-\uDDDE\uDDE1\uDDE3\uDDE8\uDDEF\uDDF3\uDDFA-\uDE4F\uDE80-\uDEC5\uDECB-\uDED2\uDED5\uDEE0-\uDEE5\uDEE9\uDEEB\uDEEC\uDEF0\uDEF3-\uDEFA\uDFE0-\uDFEB]|\uD83E[\uDD0D-\uDD3A\uDD3C-\uDD45\uDD47-\uDD71\uDD73-\uDD76\uDD7A-\uDDA2\uDDA5-\uDDAA\uDDAE-\uDDCA\uDDCD-\uDDFF\uDE70-\uDE73\uDE78-\uDE7A\uDE80-\uDE82\uDE90-\uDE95])\uFE0F?|(?:[\u261D\u26F9\u270A-\u270D]|\uD83C[\uDF85\uDFC2-\uDFC4\uDFC7\uDFCA-\uDFCC]|\uD83D[\uDC42\uDC43\uDC46-\uDC50\uDC66-\uDC78\uDC7C\uDC81-\uDC83\uDC85-\uDC87\uDC8F\uDC91\uDCAA\uDD74\uDD75\uDD7A\uDD90\uDD95\uDD96\uDE45-\uDE47\uDE4B-\uDE4F\uDEA3\uDEB4-\uDEB6\uDEC0\uDECC]|\uD83E[\uDD0F\uDD18-\uDD1F\uDD26\uDD30-\uDD39\uDD3C-\uDD3E\uDDB5\uDDB6\uDDB8\uDDB9\uDDBB\uDDCD-\uDDCF\uDDD1-\uDDDD])/g;
|
| 6 |
+
};
|
platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/wrap-ansi-cjs/node_modules/string-width/index.d.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
declare const stringWidth: {
|
| 2 |
+
/**
|
| 3 |
+
Get the visual width of a string - the number of columns required to display it.
|
| 4 |
+
|
| 5 |
+
Some Unicode characters are [fullwidth](https://en.wikipedia.org/wiki/Halfwidth_and_fullwidth_forms) and use double the normal width. [ANSI escape codes](https://en.wikipedia.org/wiki/ANSI_escape_code) are stripped and doesn't affect the width.
|
| 6 |
+
|
| 7 |
+
@example
|
| 8 |
+
```
|
| 9 |
+
import stringWidth = require('string-width');
|
| 10 |
+
|
| 11 |
+
stringWidth('a');
|
| 12 |
+
//=> 1
|
| 13 |
+
|
| 14 |
+
stringWidth('古');
|
| 15 |
+
//=> 2
|
| 16 |
+
|
| 17 |
+
stringWidth('\u001B[1m古\u001B[22m');
|
| 18 |
+
//=> 2
|
| 19 |
+
```
|
| 20 |
+
*/
|
| 21 |
+
(string: string): number;
|
| 22 |
+
|
| 23 |
+
// TODO: remove this in the next major version, refactor the whole definition to:
|
| 24 |
+
// declare function stringWidth(string: string): number;
|
| 25 |
+
// export = stringWidth;
|
| 26 |
+
default: typeof stringWidth;
|
| 27 |
+
}
|
| 28 |
+
|
| 29 |
+
export = stringWidth;
|
platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/wrap-ansi-cjs/node_modules/string-width/index.js
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
'use strict';
|
| 2 |
+
const stripAnsi = require('strip-ansi');
|
| 3 |
+
const isFullwidthCodePoint = require('is-fullwidth-code-point');
|
| 4 |
+
const emojiRegex = require('emoji-regex');
|
| 5 |
+
|
| 6 |
+
const stringWidth = string => {
|
| 7 |
+
if (typeof string !== 'string' || string.length === 0) {
|
| 8 |
+
return 0;
|
| 9 |
+
}
|
| 10 |
+
|
| 11 |
+
string = stripAnsi(string);
|
| 12 |
+
|
| 13 |
+
if (string.length === 0) {
|
| 14 |
+
return 0;
|
| 15 |
+
}
|
| 16 |
+
|
| 17 |
+
string = string.replace(emojiRegex(), ' ');
|
| 18 |
+
|
| 19 |
+
let width = 0;
|
| 20 |
+
|
| 21 |
+
for (let i = 0; i < string.length; i++) {
|
| 22 |
+
const code = string.codePointAt(i);
|
| 23 |
+
|
| 24 |
+
// Ignore control characters
|
| 25 |
+
if (code <= 0x1F || (code >= 0x7F && code <= 0x9F)) {
|
| 26 |
+
continue;
|
| 27 |
+
}
|
| 28 |
+
|
| 29 |
+
// Ignore combining characters
|
| 30 |
+
if (code >= 0x300 && code <= 0x36F) {
|
| 31 |
+
continue;
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
// Surrogates
|
| 35 |
+
if (code > 0xFFFF) {
|
| 36 |
+
i++;
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
width += isFullwidthCodePoint(code) ? 2 : 1;
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
return width;
|
| 43 |
+
};
|
| 44 |
+
|
| 45 |
+
module.exports = stringWidth;
|
| 46 |
+
// TODO: remove this in the next major version
|
| 47 |
+
module.exports.default = stringWidth;
|
platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/wrap-ansi-cjs/node_modules/string-width/license
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
MIT License
|
| 2 |
+
|
| 3 |
+
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
|
| 4 |
+
|
| 5 |
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
| 6 |
+
|
| 7 |
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
| 8 |
+
|
| 9 |
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/wrap-ansi-cjs/node_modules/string-width/package.json
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "string-width",
|
| 3 |
+
"version": "4.2.3",
|
| 4 |
+
"description": "Get the visual width of a string - the number of columns required to display it",
|
| 5 |
+
"license": "MIT",
|
| 6 |
+
"repository": "sindresorhus/string-width",
|
| 7 |
+
"author": {
|
| 8 |
+
"name": "Sindre Sorhus",
|
| 9 |
+
"email": "sindresorhus@gmail.com",
|
| 10 |
+
"url": "sindresorhus.com"
|
| 11 |
+
},
|
| 12 |
+
"engines": {
|
| 13 |
+
"node": ">=8"
|
| 14 |
+
},
|
| 15 |
+
"scripts": {
|
| 16 |
+
"test": "xo && ava && tsd"
|
| 17 |
+
},
|
| 18 |
+
"files": [
|
| 19 |
+
"index.js",
|
| 20 |
+
"index.d.ts"
|
| 21 |
+
],
|
| 22 |
+
"keywords": [
|
| 23 |
+
"string",
|
| 24 |
+
"character",
|
| 25 |
+
"unicode",
|
| 26 |
+
"width",
|
| 27 |
+
"visual",
|
| 28 |
+
"column",
|
| 29 |
+
"columns",
|
| 30 |
+
"fullwidth",
|
| 31 |
+
"full-width",
|
| 32 |
+
"full",
|
| 33 |
+
"ansi",
|
| 34 |
+
"escape",
|
| 35 |
+
"codes",
|
| 36 |
+
"cli",
|
| 37 |
+
"command-line",
|
| 38 |
+
"terminal",
|
| 39 |
+
"console",
|
| 40 |
+
"cjk",
|
| 41 |
+
"chinese",
|
| 42 |
+
"japanese",
|
| 43 |
+
"korean",
|
| 44 |
+
"fixed-width"
|
| 45 |
+
],
|
| 46 |
+
"dependencies": {
|
| 47 |
+
"emoji-regex": "^8.0.0",
|
| 48 |
+
"is-fullwidth-code-point": "^3.0.0",
|
| 49 |
+
"strip-ansi": "^6.0.1"
|
| 50 |
+
},
|
| 51 |
+
"devDependencies": {
|
| 52 |
+
"ava": "^1.4.1",
|
| 53 |
+
"tsd": "^0.7.1",
|
| 54 |
+
"xo": "^0.24.0"
|
| 55 |
+
}
|
| 56 |
+
}
|
platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/wrap-ansi-cjs/node_modules/string-width/readme.md
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# string-width
|
| 2 |
+
|
| 3 |
+
> Get the visual width of a string - the number of columns required to display it
|
| 4 |
+
|
| 5 |
+
Some Unicode characters are [fullwidth](https://en.wikipedia.org/wiki/Halfwidth_and_fullwidth_forms) and use double the normal width. [ANSI escape codes](https://en.wikipedia.org/wiki/ANSI_escape_code) are stripped and doesn't affect the width.
|
| 6 |
+
|
| 7 |
+
Useful to be able to measure the actual width of command-line output.
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
## Install
|
| 11 |
+
|
| 12 |
+
```
|
| 13 |
+
$ npm install string-width
|
| 14 |
+
```
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
## Usage
|
| 18 |
+
|
| 19 |
+
```js
|
| 20 |
+
const stringWidth = require('string-width');
|
| 21 |
+
|
| 22 |
+
stringWidth('a');
|
| 23 |
+
//=> 1
|
| 24 |
+
|
| 25 |
+
stringWidth('古');
|
| 26 |
+
//=> 2
|
| 27 |
+
|
| 28 |
+
stringWidth('\u001B[1m古\u001B[22m');
|
| 29 |
+
//=> 2
|
| 30 |
+
```
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
## Related
|
| 34 |
+
|
| 35 |
+
- [string-width-cli](https://github.com/sindresorhus/string-width-cli) - CLI for this module
|
| 36 |
+
- [string-length](https://github.com/sindresorhus/string-length) - Get the real length of a string
|
| 37 |
+
- [widest-line](https://github.com/sindresorhus/widest-line) - Get the visual width of the widest line in a string
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
---
|
| 41 |
+
|
| 42 |
+
<div align="center">
|
| 43 |
+
<b>
|
| 44 |
+
<a href="https://tidelift.com/subscription/pkg/npm-string-width?utm_source=npm-string-width&utm_medium=referral&utm_campaign=readme">Get professional support for this package with a Tidelift subscription</a>
|
| 45 |
+
</b>
|
| 46 |
+
<br>
|
| 47 |
+
<sub>
|
| 48 |
+
Tidelift helps make open source sustainable for maintainers while giving companies<br>assurances about security, maintenance, and licensing for their dependencies.
|
| 49 |
+
</sub>
|
| 50 |
+
</div>
|
platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/wrap-ansi-cjs/node_modules/strip-ansi/index.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
Strip [ANSI escape codes](https://en.wikipedia.org/wiki/ANSI_escape_code) from a string.
|
| 3 |
+
|
| 4 |
+
@example
|
| 5 |
+
```
|
| 6 |
+
import stripAnsi = require('strip-ansi');
|
| 7 |
+
|
| 8 |
+
stripAnsi('\u001B[4mUnicorn\u001B[0m');
|
| 9 |
+
//=> 'Unicorn'
|
| 10 |
+
|
| 11 |
+
stripAnsi('\u001B]8;;https://github.com\u0007Click\u001B]8;;\u0007');
|
| 12 |
+
//=> 'Click'
|
| 13 |
+
```
|
| 14 |
+
*/
|
| 15 |
+
declare function stripAnsi(string: string): string;
|
| 16 |
+
|
| 17 |
+
export = stripAnsi;
|
platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/wrap-ansi-cjs/node_modules/strip-ansi/index.js
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
'use strict';
|
| 2 |
+
const ansiRegex = require('ansi-regex');
|
| 3 |
+
|
| 4 |
+
module.exports = string => typeof string === 'string' ? string.replace(ansiRegex(), '') : string;
|
platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/wrap-ansi-cjs/node_modules/strip-ansi/license
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
MIT License
|
| 2 |
+
|
| 3 |
+
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
|
| 4 |
+
|
| 5 |
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
| 6 |
+
|
| 7 |
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
| 8 |
+
|
| 9 |
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/wrap-ansi-cjs/node_modules/strip-ansi/package.json
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "strip-ansi",
|
| 3 |
+
"version": "6.0.1",
|
| 4 |
+
"description": "Strip ANSI escape codes from a string",
|
| 5 |
+
"license": "MIT",
|
| 6 |
+
"repository": "chalk/strip-ansi",
|
| 7 |
+
"author": {
|
| 8 |
+
"name": "Sindre Sorhus",
|
| 9 |
+
"email": "sindresorhus@gmail.com",
|
| 10 |
+
"url": "sindresorhus.com"
|
| 11 |
+
},
|
| 12 |
+
"engines": {
|
| 13 |
+
"node": ">=8"
|
| 14 |
+
},
|
| 15 |
+
"scripts": {
|
| 16 |
+
"test": "xo && ava && tsd"
|
| 17 |
+
},
|
| 18 |
+
"files": [
|
| 19 |
+
"index.js",
|
| 20 |
+
"index.d.ts"
|
| 21 |
+
],
|
| 22 |
+
"keywords": [
|
| 23 |
+
"strip",
|
| 24 |
+
"trim",
|
| 25 |
+
"remove",
|
| 26 |
+
"ansi",
|
| 27 |
+
"styles",
|
| 28 |
+
"color",
|
| 29 |
+
"colour",
|
| 30 |
+
"colors",
|
| 31 |
+
"terminal",
|
| 32 |
+
"console",
|
| 33 |
+
"string",
|
| 34 |
+
"tty",
|
| 35 |
+
"escape",
|
| 36 |
+
"formatting",
|
| 37 |
+
"rgb",
|
| 38 |
+
"256",
|
| 39 |
+
"shell",
|
| 40 |
+
"xterm",
|
| 41 |
+
"log",
|
| 42 |
+
"logging",
|
| 43 |
+
"command-line",
|
| 44 |
+
"text"
|
| 45 |
+
],
|
| 46 |
+
"dependencies": {
|
| 47 |
+
"ansi-regex": "^5.0.1"
|
| 48 |
+
},
|
| 49 |
+
"devDependencies": {
|
| 50 |
+
"ava": "^2.4.0",
|
| 51 |
+
"tsd": "^0.10.0",
|
| 52 |
+
"xo": "^0.25.3"
|
| 53 |
+
}
|
| 54 |
+
}
|
platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/wrap-ansi-cjs/node_modules/strip-ansi/readme.md
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# strip-ansi [](https://travis-ci.org/chalk/strip-ansi)
|
| 2 |
+
|
| 3 |
+
> Strip [ANSI escape codes](https://en.wikipedia.org/wiki/ANSI_escape_code) from a string
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
## Install
|
| 7 |
+
|
| 8 |
+
```
|
| 9 |
+
$ npm install strip-ansi
|
| 10 |
+
```
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
## Usage
|
| 14 |
+
|
| 15 |
+
```js
|
| 16 |
+
const stripAnsi = require('strip-ansi');
|
| 17 |
+
|
| 18 |
+
stripAnsi('\u001B[4mUnicorn\u001B[0m');
|
| 19 |
+
//=> 'Unicorn'
|
| 20 |
+
|
| 21 |
+
stripAnsi('\u001B]8;;https://github.com\u0007Click\u001B]8;;\u0007');
|
| 22 |
+
//=> 'Click'
|
| 23 |
+
```
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
## strip-ansi for enterprise
|
| 27 |
+
|
| 28 |
+
Available as part of the Tidelift Subscription.
|
| 29 |
+
|
| 30 |
+
The maintainers of strip-ansi and thousands of other packages are working with Tidelift to deliver commercial support and maintenance for the open source dependencies you use to build your applications. Save time, reduce risk, and improve code health, while paying the maintainers of the exact dependencies you use. [Learn more.](https://tidelift.com/subscription/pkg/npm-strip-ansi?utm_source=npm-strip-ansi&utm_medium=referral&utm_campaign=enterprise&utm_term=repo)
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
## Related
|
| 34 |
+
|
| 35 |
+
- [strip-ansi-cli](https://github.com/chalk/strip-ansi-cli) - CLI for this module
|
| 36 |
+
- [strip-ansi-stream](https://github.com/chalk/strip-ansi-stream) - Streaming version of this module
|
| 37 |
+
- [has-ansi](https://github.com/chalk/has-ansi) - Check if a string has ANSI escape codes
|
| 38 |
+
- [ansi-regex](https://github.com/chalk/ansi-regex) - Regular expression for matching ANSI escape codes
|
| 39 |
+
- [chalk](https://github.com/chalk/chalk) - Terminal string styling done right
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
## Maintainers
|
| 43 |
+
|
| 44 |
+
- [Sindre Sorhus](https://github.com/sindresorhus)
|
| 45 |
+
- [Josh Junon](https://github.com/qix-)
|
| 46 |
+
|
platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/ws/lib/buffer-util.js
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
'use strict';
|
| 2 |
+
|
| 3 |
+
const { EMPTY_BUFFER } = require('./constants');
|
| 4 |
+
|
| 5 |
+
const FastBuffer = Buffer[Symbol.species];
|
| 6 |
+
|
| 7 |
+
/**
|
| 8 |
+
* Merges an array of buffers into a new buffer.
|
| 9 |
+
*
|
| 10 |
+
* @param {Buffer[]} list The array of buffers to concat
|
| 11 |
+
* @param {Number} totalLength The total length of buffers in the list
|
| 12 |
+
* @return {Buffer} The resulting buffer
|
| 13 |
+
* @public
|
| 14 |
+
*/
|
| 15 |
+
function concat(list, totalLength) {
|
| 16 |
+
if (list.length === 0) return EMPTY_BUFFER;
|
| 17 |
+
if (list.length === 1) return list[0];
|
| 18 |
+
|
| 19 |
+
const target = Buffer.allocUnsafe(totalLength);
|
| 20 |
+
let offset = 0;
|
| 21 |
+
|
| 22 |
+
for (let i = 0; i < list.length; i++) {
|
| 23 |
+
const buf = list[i];
|
| 24 |
+
target.set(buf, offset);
|
| 25 |
+
offset += buf.length;
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
if (offset < totalLength) {
|
| 29 |
+
return new FastBuffer(target.buffer, target.byteOffset, offset);
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
return target;
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
/**
|
| 36 |
+
* Masks a buffer using the given mask.
|
| 37 |
+
*
|
| 38 |
+
* @param {Buffer} source The buffer to mask
|
| 39 |
+
* @param {Buffer} mask The mask to use
|
| 40 |
+
* @param {Buffer} output The buffer where to store the result
|
| 41 |
+
* @param {Number} offset The offset at which to start writing
|
| 42 |
+
* @param {Number} length The number of bytes to mask.
|
| 43 |
+
* @public
|
| 44 |
+
*/
|
| 45 |
+
function _mask(source, mask, output, offset, length) {
|
| 46 |
+
for (let i = 0; i < length; i++) {
|
| 47 |
+
output[offset + i] = source[i] ^ mask[i & 3];
|
| 48 |
+
}
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
/**
|
| 52 |
+
* Unmasks a buffer using the given mask.
|
| 53 |
+
*
|
| 54 |
+
* @param {Buffer} buffer The buffer to unmask
|
| 55 |
+
* @param {Buffer} mask The mask to use
|
| 56 |
+
* @public
|
| 57 |
+
*/
|
| 58 |
+
function _unmask(buffer, mask) {
|
| 59 |
+
for (let i = 0; i < buffer.length; i++) {
|
| 60 |
+
buffer[i] ^= mask[i & 3];
|
| 61 |
+
}
|
| 62 |
+
}
|
| 63 |
+
|
| 64 |
+
/**
|
| 65 |
+
* Converts a buffer to an `ArrayBuffer`.
|
| 66 |
+
*
|
| 67 |
+
* @param {Buffer} buf The buffer to convert
|
| 68 |
+
* @return {ArrayBuffer} Converted buffer
|
| 69 |
+
* @public
|
| 70 |
+
*/
|
| 71 |
+
function toArrayBuffer(buf) {
|
| 72 |
+
if (buf.length === buf.buffer.byteLength) {
|
| 73 |
+
return buf.buffer;
|
| 74 |
+
}
|
| 75 |
+
|
| 76 |
+
return buf.buffer.slice(buf.byteOffset, buf.byteOffset + buf.length);
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
/**
|
| 80 |
+
* Converts `data` to a `Buffer`.
|
| 81 |
+
*
|
| 82 |
+
* @param {*} data The data to convert
|
| 83 |
+
* @return {Buffer} The buffer
|
| 84 |
+
* @throws {TypeError}
|
| 85 |
+
* @public
|
| 86 |
+
*/
|
| 87 |
+
function toBuffer(data) {
|
| 88 |
+
toBuffer.readOnly = true;
|
| 89 |
+
|
| 90 |
+
if (Buffer.isBuffer(data)) return data;
|
| 91 |
+
|
| 92 |
+
let buf;
|
| 93 |
+
|
| 94 |
+
if (data instanceof ArrayBuffer) {
|
| 95 |
+
buf = new FastBuffer(data);
|
| 96 |
+
} else if (ArrayBuffer.isView(data)) {
|
| 97 |
+
buf = new FastBuffer(data.buffer, data.byteOffset, data.byteLength);
|
| 98 |
+
} else {
|
| 99 |
+
buf = Buffer.from(data);
|
| 100 |
+
toBuffer.readOnly = false;
|
| 101 |
+
}
|
| 102 |
+
|
| 103 |
+
return buf;
|
| 104 |
+
}
|
| 105 |
+
|
| 106 |
+
module.exports = {
|
| 107 |
+
concat,
|
| 108 |
+
mask: _mask,
|
| 109 |
+
toArrayBuffer,
|
| 110 |
+
toBuffer,
|
| 111 |
+
unmask: _unmask
|
| 112 |
+
};
|
| 113 |
+
|
| 114 |
+
/* istanbul ignore else */
|
| 115 |
+
if (!process.env.WS_NO_BUFFER_UTIL) {
|
| 116 |
+
try {
|
| 117 |
+
const bufferUtil = require('bufferutil');
|
| 118 |
+
|
| 119 |
+
module.exports.mask = function (source, mask, output, offset, length) {
|
| 120 |
+
if (length < 48) _mask(source, mask, output, offset, length);
|
| 121 |
+
else bufferUtil.mask(source, mask, output, offset, length);
|
| 122 |
+
};
|
| 123 |
+
|
| 124 |
+
module.exports.unmask = function (buffer, mask) {
|
| 125 |
+
if (buffer.length < 32) _unmask(buffer, mask);
|
| 126 |
+
else bufferUtil.unmask(buffer, mask);
|
| 127 |
+
};
|
| 128 |
+
} catch (e) {
|
| 129 |
+
// Continue regardless of the error.
|
| 130 |
+
}
|
| 131 |
+
}
|
platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/ws/lib/constants.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
'use strict';
|
| 2 |
+
|
| 3 |
+
const BINARY_TYPES = ['nodebuffer', 'arraybuffer', 'fragments'];
|
| 4 |
+
const hasBlob = typeof Blob !== 'undefined';
|
| 5 |
+
|
| 6 |
+
if (hasBlob) BINARY_TYPES.push('blob');
|
| 7 |
+
|
| 8 |
+
module.exports = {
|
| 9 |
+
BINARY_TYPES,
|
| 10 |
+
EMPTY_BUFFER: Buffer.alloc(0),
|
| 11 |
+
GUID: '258EAFA5-E914-47DA-95CA-C5AB0DC85B11',
|
| 12 |
+
hasBlob,
|
| 13 |
+
kForOnEventAttribute: Symbol('kIsForOnEventAttribute'),
|
| 14 |
+
kListener: Symbol('kListener'),
|
| 15 |
+
kStatusCode: Symbol('status-code'),
|
| 16 |
+
kWebSocket: Symbol('websocket'),
|
| 17 |
+
NOOP: () => {}
|
| 18 |
+
};
|
platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/ws/lib/event-target.js
ADDED
|
@@ -0,0 +1,292 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
'use strict';
|
| 2 |
+
|
| 3 |
+
const { kForOnEventAttribute, kListener } = require('./constants');
|
| 4 |
+
|
| 5 |
+
const kCode = Symbol('kCode');
|
| 6 |
+
const kData = Symbol('kData');
|
| 7 |
+
const kError = Symbol('kError');
|
| 8 |
+
const kMessage = Symbol('kMessage');
|
| 9 |
+
const kReason = Symbol('kReason');
|
| 10 |
+
const kTarget = Symbol('kTarget');
|
| 11 |
+
const kType = Symbol('kType');
|
| 12 |
+
const kWasClean = Symbol('kWasClean');
|
| 13 |
+
|
| 14 |
+
/**
|
| 15 |
+
* Class representing an event.
|
| 16 |
+
*/
|
| 17 |
+
class Event {
|
| 18 |
+
/**
|
| 19 |
+
* Create a new `Event`.
|
| 20 |
+
*
|
| 21 |
+
* @param {String} type The name of the event
|
| 22 |
+
* @throws {TypeError} If the `type` argument is not specified
|
| 23 |
+
*/
|
| 24 |
+
constructor(type) {
|
| 25 |
+
this[kTarget] = null;
|
| 26 |
+
this[kType] = type;
|
| 27 |
+
}
|
| 28 |
+
|
| 29 |
+
/**
|
| 30 |
+
* @type {*}
|
| 31 |
+
*/
|
| 32 |
+
get target() {
|
| 33 |
+
return this[kTarget];
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
/**
|
| 37 |
+
* @type {String}
|
| 38 |
+
*/
|
| 39 |
+
get type() {
|
| 40 |
+
return this[kType];
|
| 41 |
+
}
|
| 42 |
+
}
|
| 43 |
+
|
| 44 |
+
Object.defineProperty(Event.prototype, 'target', { enumerable: true });
|
| 45 |
+
Object.defineProperty(Event.prototype, 'type', { enumerable: true });
|
| 46 |
+
|
| 47 |
+
/**
|
| 48 |
+
* Class representing a close event.
|
| 49 |
+
*
|
| 50 |
+
* @extends Event
|
| 51 |
+
*/
|
| 52 |
+
class CloseEvent extends Event {
|
| 53 |
+
/**
|
| 54 |
+
* Create a new `CloseEvent`.
|
| 55 |
+
*
|
| 56 |
+
* @param {String} type The name of the event
|
| 57 |
+
* @param {Object} [options] A dictionary object that allows for setting
|
| 58 |
+
* attributes via object members of the same name
|
| 59 |
+
* @param {Number} [options.code=0] The status code explaining why the
|
| 60 |
+
* connection was closed
|
| 61 |
+
* @param {String} [options.reason=''] A human-readable string explaining why
|
| 62 |
+
* the connection was closed
|
| 63 |
+
* @param {Boolean} [options.wasClean=false] Indicates whether or not the
|
| 64 |
+
* connection was cleanly closed
|
| 65 |
+
*/
|
| 66 |
+
constructor(type, options = {}) {
|
| 67 |
+
super(type);
|
| 68 |
+
|
| 69 |
+
this[kCode] = options.code === undefined ? 0 : options.code;
|
| 70 |
+
this[kReason] = options.reason === undefined ? '' : options.reason;
|
| 71 |
+
this[kWasClean] = options.wasClean === undefined ? false : options.wasClean;
|
| 72 |
+
}
|
| 73 |
+
|
| 74 |
+
/**
|
| 75 |
+
* @type {Number}
|
| 76 |
+
*/
|
| 77 |
+
get code() {
|
| 78 |
+
return this[kCode];
|
| 79 |
+
}
|
| 80 |
+
|
| 81 |
+
/**
|
| 82 |
+
* @type {String}
|
| 83 |
+
*/
|
| 84 |
+
get reason() {
|
| 85 |
+
return this[kReason];
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
/**
|
| 89 |
+
* @type {Boolean}
|
| 90 |
+
*/
|
| 91 |
+
get wasClean() {
|
| 92 |
+
return this[kWasClean];
|
| 93 |
+
}
|
| 94 |
+
}
|
| 95 |
+
|
| 96 |
+
Object.defineProperty(CloseEvent.prototype, 'code', { enumerable: true });
|
| 97 |
+
Object.defineProperty(CloseEvent.prototype, 'reason', { enumerable: true });
|
| 98 |
+
Object.defineProperty(CloseEvent.prototype, 'wasClean', { enumerable: true });
|
| 99 |
+
|
| 100 |
+
/**
|
| 101 |
+
* Class representing an error event.
|
| 102 |
+
*
|
| 103 |
+
* @extends Event
|
| 104 |
+
*/
|
| 105 |
+
class ErrorEvent extends Event {
|
| 106 |
+
/**
|
| 107 |
+
* Create a new `ErrorEvent`.
|
| 108 |
+
*
|
| 109 |
+
* @param {String} type The name of the event
|
| 110 |
+
* @param {Object} [options] A dictionary object that allows for setting
|
| 111 |
+
* attributes via object members of the same name
|
| 112 |
+
* @param {*} [options.error=null] The error that generated this event
|
| 113 |
+
* @param {String} [options.message=''] The error message
|
| 114 |
+
*/
|
| 115 |
+
constructor(type, options = {}) {
|
| 116 |
+
super(type);
|
| 117 |
+
|
| 118 |
+
this[kError] = options.error === undefined ? null : options.error;
|
| 119 |
+
this[kMessage] = options.message === undefined ? '' : options.message;
|
| 120 |
+
}
|
| 121 |
+
|
| 122 |
+
/**
|
| 123 |
+
* @type {*}
|
| 124 |
+
*/
|
| 125 |
+
get error() {
|
| 126 |
+
return this[kError];
|
| 127 |
+
}
|
| 128 |
+
|
| 129 |
+
/**
|
| 130 |
+
* @type {String}
|
| 131 |
+
*/
|
| 132 |
+
get message() {
|
| 133 |
+
return this[kMessage];
|
| 134 |
+
}
|
| 135 |
+
}
|
| 136 |
+
|
| 137 |
+
Object.defineProperty(ErrorEvent.prototype, 'error', { enumerable: true });
|
| 138 |
+
Object.defineProperty(ErrorEvent.prototype, 'message', { enumerable: true });
|
| 139 |
+
|
| 140 |
+
/**
|
| 141 |
+
* Class representing a message event.
|
| 142 |
+
*
|
| 143 |
+
* @extends Event
|
| 144 |
+
*/
|
| 145 |
+
class MessageEvent extends Event {
|
| 146 |
+
/**
|
| 147 |
+
* Create a new `MessageEvent`.
|
| 148 |
+
*
|
| 149 |
+
* @param {String} type The name of the event
|
| 150 |
+
* @param {Object} [options] A dictionary object that allows for setting
|
| 151 |
+
* attributes via object members of the same name
|
| 152 |
+
* @param {*} [options.data=null] The message content
|
| 153 |
+
*/
|
| 154 |
+
constructor(type, options = {}) {
|
| 155 |
+
super(type);
|
| 156 |
+
|
| 157 |
+
this[kData] = options.data === undefined ? null : options.data;
|
| 158 |
+
}
|
| 159 |
+
|
| 160 |
+
/**
|
| 161 |
+
* @type {*}
|
| 162 |
+
*/
|
| 163 |
+
get data() {
|
| 164 |
+
return this[kData];
|
| 165 |
+
}
|
| 166 |
+
}
|
| 167 |
+
|
| 168 |
+
Object.defineProperty(MessageEvent.prototype, 'data', { enumerable: true });
|
| 169 |
+
|
| 170 |
+
/**
|
| 171 |
+
* This provides methods for emulating the `EventTarget` interface. It's not
|
| 172 |
+
* meant to be used directly.
|
| 173 |
+
*
|
| 174 |
+
* @mixin
|
| 175 |
+
*/
|
| 176 |
+
const EventTarget = {
|
| 177 |
+
/**
|
| 178 |
+
* Register an event listener.
|
| 179 |
+
*
|
| 180 |
+
* @param {String} type A string representing the event type to listen for
|
| 181 |
+
* @param {(Function|Object)} handler The listener to add
|
| 182 |
+
* @param {Object} [options] An options object specifies characteristics about
|
| 183 |
+
* the event listener
|
| 184 |
+
* @param {Boolean} [options.once=false] A `Boolean` indicating that the
|
| 185 |
+
* listener should be invoked at most once after being added. If `true`,
|
| 186 |
+
* the listener would be automatically removed when invoked.
|
| 187 |
+
* @public
|
| 188 |
+
*/
|
| 189 |
+
addEventListener(type, handler, options = {}) {
|
| 190 |
+
for (const listener of this.listeners(type)) {
|
| 191 |
+
if (
|
| 192 |
+
!options[kForOnEventAttribute] &&
|
| 193 |
+
listener[kListener] === handler &&
|
| 194 |
+
!listener[kForOnEventAttribute]
|
| 195 |
+
) {
|
| 196 |
+
return;
|
| 197 |
+
}
|
| 198 |
+
}
|
| 199 |
+
|
| 200 |
+
let wrapper;
|
| 201 |
+
|
| 202 |
+
if (type === 'message') {
|
| 203 |
+
wrapper = function onMessage(data, isBinary) {
|
| 204 |
+
const event = new MessageEvent('message', {
|
| 205 |
+
data: isBinary ? data : data.toString()
|
| 206 |
+
});
|
| 207 |
+
|
| 208 |
+
event[kTarget] = this;
|
| 209 |
+
callListener(handler, this, event);
|
| 210 |
+
};
|
| 211 |
+
} else if (type === 'close') {
|
| 212 |
+
wrapper = function onClose(code, message) {
|
| 213 |
+
const event = new CloseEvent('close', {
|
| 214 |
+
code,
|
| 215 |
+
reason: message.toString(),
|
| 216 |
+
wasClean: this._closeFrameReceived && this._closeFrameSent
|
| 217 |
+
});
|
| 218 |
+
|
| 219 |
+
event[kTarget] = this;
|
| 220 |
+
callListener(handler, this, event);
|
| 221 |
+
};
|
| 222 |
+
} else if (type === 'error') {
|
| 223 |
+
wrapper = function onError(error) {
|
| 224 |
+
const event = new ErrorEvent('error', {
|
| 225 |
+
error,
|
| 226 |
+
message: error.message
|
| 227 |
+
});
|
| 228 |
+
|
| 229 |
+
event[kTarget] = this;
|
| 230 |
+
callListener(handler, this, event);
|
| 231 |
+
};
|
| 232 |
+
} else if (type === 'open') {
|
| 233 |
+
wrapper = function onOpen() {
|
| 234 |
+
const event = new Event('open');
|
| 235 |
+
|
| 236 |
+
event[kTarget] = this;
|
| 237 |
+
callListener(handler, this, event);
|
| 238 |
+
};
|
| 239 |
+
} else {
|
| 240 |
+
return;
|
| 241 |
+
}
|
| 242 |
+
|
| 243 |
+
wrapper[kForOnEventAttribute] = !!options[kForOnEventAttribute];
|
| 244 |
+
wrapper[kListener] = handler;
|
| 245 |
+
|
| 246 |
+
if (options.once) {
|
| 247 |
+
this.once(type, wrapper);
|
| 248 |
+
} else {
|
| 249 |
+
this.on(type, wrapper);
|
| 250 |
+
}
|
| 251 |
+
},
|
| 252 |
+
|
| 253 |
+
/**
|
| 254 |
+
* Remove an event listener.
|
| 255 |
+
*
|
| 256 |
+
* @param {String} type A string representing the event type to remove
|
| 257 |
+
* @param {(Function|Object)} handler The listener to remove
|
| 258 |
+
* @public
|
| 259 |
+
*/
|
| 260 |
+
removeEventListener(type, handler) {
|
| 261 |
+
for (const listener of this.listeners(type)) {
|
| 262 |
+
if (listener[kListener] === handler && !listener[kForOnEventAttribute]) {
|
| 263 |
+
this.removeListener(type, listener);
|
| 264 |
+
break;
|
| 265 |
+
}
|
| 266 |
+
}
|
| 267 |
+
}
|
| 268 |
+
};
|
| 269 |
+
|
| 270 |
+
module.exports = {
|
| 271 |
+
CloseEvent,
|
| 272 |
+
ErrorEvent,
|
| 273 |
+
Event,
|
| 274 |
+
EventTarget,
|
| 275 |
+
MessageEvent
|
| 276 |
+
};
|
| 277 |
+
|
| 278 |
+
/**
|
| 279 |
+
* Call an event listener
|
| 280 |
+
*
|
| 281 |
+
* @param {(Function|Object)} listener The listener to call
|
| 282 |
+
* @param {*} thisArg The value to use as `this`` when calling the listener
|
| 283 |
+
* @param {Event} event The event to pass to the listener
|
| 284 |
+
* @private
|
| 285 |
+
*/
|
| 286 |
+
function callListener(listener, thisArg, event) {
|
| 287 |
+
if (typeof listener === 'object' && listener.handleEvent) {
|
| 288 |
+
listener.handleEvent.call(listener, event);
|
| 289 |
+
} else {
|
| 290 |
+
listener.call(thisArg, event);
|
| 291 |
+
}
|
| 292 |
+
}
|
platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/ws/lib/extension.js
ADDED
|
@@ -0,0 +1,203 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
'use strict';
|
| 2 |
+
|
| 3 |
+
const { tokenChars } = require('./validation');
|
| 4 |
+
|
| 5 |
+
/**
|
| 6 |
+
* Adds an offer to the map of extension offers or a parameter to the map of
|
| 7 |
+
* parameters.
|
| 8 |
+
*
|
| 9 |
+
* @param {Object} dest The map of extension offers or parameters
|
| 10 |
+
* @param {String} name The extension or parameter name
|
| 11 |
+
* @param {(Object|Boolean|String)} elem The extension parameters or the
|
| 12 |
+
* parameter value
|
| 13 |
+
* @private
|
| 14 |
+
*/
|
| 15 |
+
function push(dest, name, elem) {
|
| 16 |
+
if (dest[name] === undefined) dest[name] = [elem];
|
| 17 |
+
else dest[name].push(elem);
|
| 18 |
+
}
|
| 19 |
+
|
| 20 |
+
/**
|
| 21 |
+
* Parses the `Sec-WebSocket-Extensions` header into an object.
|
| 22 |
+
*
|
| 23 |
+
* @param {String} header The field value of the header
|
| 24 |
+
* @return {Object} The parsed object
|
| 25 |
+
* @public
|
| 26 |
+
*/
|
| 27 |
+
function parse(header) {
|
| 28 |
+
const offers = Object.create(null);
|
| 29 |
+
let params = Object.create(null);
|
| 30 |
+
let mustUnescape = false;
|
| 31 |
+
let isEscaping = false;
|
| 32 |
+
let inQuotes = false;
|
| 33 |
+
let extensionName;
|
| 34 |
+
let paramName;
|
| 35 |
+
let start = -1;
|
| 36 |
+
let code = -1;
|
| 37 |
+
let end = -1;
|
| 38 |
+
let i = 0;
|
| 39 |
+
|
| 40 |
+
for (; i < header.length; i++) {
|
| 41 |
+
code = header.charCodeAt(i);
|
| 42 |
+
|
| 43 |
+
if (extensionName === undefined) {
|
| 44 |
+
if (end === -1 && tokenChars[code] === 1) {
|
| 45 |
+
if (start === -1) start = i;
|
| 46 |
+
} else if (
|
| 47 |
+
i !== 0 &&
|
| 48 |
+
(code === 0x20 /* ' ' */ || code === 0x09) /* '\t' */
|
| 49 |
+
) {
|
| 50 |
+
if (end === -1 && start !== -1) end = i;
|
| 51 |
+
} else if (code === 0x3b /* ';' */ || code === 0x2c /* ',' */) {
|
| 52 |
+
if (start === -1) {
|
| 53 |
+
throw new SyntaxError(`Unexpected character at index ${i}`);
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
if (end === -1) end = i;
|
| 57 |
+
const name = header.slice(start, end);
|
| 58 |
+
if (code === 0x2c) {
|
| 59 |
+
push(offers, name, params);
|
| 60 |
+
params = Object.create(null);
|
| 61 |
+
} else {
|
| 62 |
+
extensionName = name;
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
start = end = -1;
|
| 66 |
+
} else {
|
| 67 |
+
throw new SyntaxError(`Unexpected character at index ${i}`);
|
| 68 |
+
}
|
| 69 |
+
} else if (paramName === undefined) {
|
| 70 |
+
if (end === -1 && tokenChars[code] === 1) {
|
| 71 |
+
if (start === -1) start = i;
|
| 72 |
+
} else if (code === 0x20 || code === 0x09) {
|
| 73 |
+
if (end === -1 && start !== -1) end = i;
|
| 74 |
+
} else if (code === 0x3b || code === 0x2c) {
|
| 75 |
+
if (start === -1) {
|
| 76 |
+
throw new SyntaxError(`Unexpected character at index ${i}`);
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
if (end === -1) end = i;
|
| 80 |
+
push(params, header.slice(start, end), true);
|
| 81 |
+
if (code === 0x2c) {
|
| 82 |
+
push(offers, extensionName, params);
|
| 83 |
+
params = Object.create(null);
|
| 84 |
+
extensionName = undefined;
|
| 85 |
+
}
|
| 86 |
+
|
| 87 |
+
start = end = -1;
|
| 88 |
+
} else if (code === 0x3d /* '=' */ && start !== -1 && end === -1) {
|
| 89 |
+
paramName = header.slice(start, i);
|
| 90 |
+
start = end = -1;
|
| 91 |
+
} else {
|
| 92 |
+
throw new SyntaxError(`Unexpected character at index ${i}`);
|
| 93 |
+
}
|
| 94 |
+
} else {
|
| 95 |
+
//
|
| 96 |
+
// The value of a quoted-string after unescaping must conform to the
|
| 97 |
+
// token ABNF, so only token characters are valid.
|
| 98 |
+
// Ref: https://tools.ietf.org/html/rfc6455#section-9.1
|
| 99 |
+
//
|
| 100 |
+
if (isEscaping) {
|
| 101 |
+
if (tokenChars[code] !== 1) {
|
| 102 |
+
throw new SyntaxError(`Unexpected character at index ${i}`);
|
| 103 |
+
}
|
| 104 |
+
if (start === -1) start = i;
|
| 105 |
+
else if (!mustUnescape) mustUnescape = true;
|
| 106 |
+
isEscaping = false;
|
| 107 |
+
} else if (inQuotes) {
|
| 108 |
+
if (tokenChars[code] === 1) {
|
| 109 |
+
if (start === -1) start = i;
|
| 110 |
+
} else if (code === 0x22 /* '"' */ && start !== -1) {
|
| 111 |
+
inQuotes = false;
|
| 112 |
+
end = i;
|
| 113 |
+
} else if (code === 0x5c /* '\' */) {
|
| 114 |
+
isEscaping = true;
|
| 115 |
+
} else {
|
| 116 |
+
throw new SyntaxError(`Unexpected character at index ${i}`);
|
| 117 |
+
}
|
| 118 |
+
} else if (code === 0x22 && header.charCodeAt(i - 1) === 0x3d) {
|
| 119 |
+
inQuotes = true;
|
| 120 |
+
} else if (end === -1 && tokenChars[code] === 1) {
|
| 121 |
+
if (start === -1) start = i;
|
| 122 |
+
} else if (start !== -1 && (code === 0x20 || code === 0x09)) {
|
| 123 |
+
if (end === -1) end = i;
|
| 124 |
+
} else if (code === 0x3b || code === 0x2c) {
|
| 125 |
+
if (start === -1) {
|
| 126 |
+
throw new SyntaxError(`Unexpected character at index ${i}`);
|
| 127 |
+
}
|
| 128 |
+
|
| 129 |
+
if (end === -1) end = i;
|
| 130 |
+
let value = header.slice(start, end);
|
| 131 |
+
if (mustUnescape) {
|
| 132 |
+
value = value.replace(/\\/g, '');
|
| 133 |
+
mustUnescape = false;
|
| 134 |
+
}
|
| 135 |
+
push(params, paramName, value);
|
| 136 |
+
if (code === 0x2c) {
|
| 137 |
+
push(offers, extensionName, params);
|
| 138 |
+
params = Object.create(null);
|
| 139 |
+
extensionName = undefined;
|
| 140 |
+
}
|
| 141 |
+
|
| 142 |
+
paramName = undefined;
|
| 143 |
+
start = end = -1;
|
| 144 |
+
} else {
|
| 145 |
+
throw new SyntaxError(`Unexpected character at index ${i}`);
|
| 146 |
+
}
|
| 147 |
+
}
|
| 148 |
+
}
|
| 149 |
+
|
| 150 |
+
if (start === -1 || inQuotes || code === 0x20 || code === 0x09) {
|
| 151 |
+
throw new SyntaxError('Unexpected end of input');
|
| 152 |
+
}
|
| 153 |
+
|
| 154 |
+
if (end === -1) end = i;
|
| 155 |
+
const token = header.slice(start, end);
|
| 156 |
+
if (extensionName === undefined) {
|
| 157 |
+
push(offers, token, params);
|
| 158 |
+
} else {
|
| 159 |
+
if (paramName === undefined) {
|
| 160 |
+
push(params, token, true);
|
| 161 |
+
} else if (mustUnescape) {
|
| 162 |
+
push(params, paramName, token.replace(/\\/g, ''));
|
| 163 |
+
} else {
|
| 164 |
+
push(params, paramName, token);
|
| 165 |
+
}
|
| 166 |
+
push(offers, extensionName, params);
|
| 167 |
+
}
|
| 168 |
+
|
| 169 |
+
return offers;
|
| 170 |
+
}
|
| 171 |
+
|
| 172 |
+
/**
|
| 173 |
+
* Builds the `Sec-WebSocket-Extensions` header field value.
|
| 174 |
+
*
|
| 175 |
+
* @param {Object} extensions The map of extensions and parameters to format
|
| 176 |
+
* @return {String} A string representing the given object
|
| 177 |
+
* @public
|
| 178 |
+
*/
|
| 179 |
+
function format(extensions) {
|
| 180 |
+
return Object.keys(extensions)
|
| 181 |
+
.map((extension) => {
|
| 182 |
+
let configurations = extensions[extension];
|
| 183 |
+
if (!Array.isArray(configurations)) configurations = [configurations];
|
| 184 |
+
return configurations
|
| 185 |
+
.map((params) => {
|
| 186 |
+
return [extension]
|
| 187 |
+
.concat(
|
| 188 |
+
Object.keys(params).map((k) => {
|
| 189 |
+
let values = params[k];
|
| 190 |
+
if (!Array.isArray(values)) values = [values];
|
| 191 |
+
return values
|
| 192 |
+
.map((v) => (v === true ? k : `${k}=${v}`))
|
| 193 |
+
.join('; ');
|
| 194 |
+
})
|
| 195 |
+
)
|
| 196 |
+
.join('; ');
|
| 197 |
+
})
|
| 198 |
+
.join(', ');
|
| 199 |
+
})
|
| 200 |
+
.join(', ');
|
| 201 |
+
}
|
| 202 |
+
|
| 203 |
+
module.exports = { format, parse };
|
platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/ws/lib/limiter.js
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
'use strict';
|
| 2 |
+
|
| 3 |
+
const kDone = Symbol('kDone');
|
| 4 |
+
const kRun = Symbol('kRun');
|
| 5 |
+
|
| 6 |
+
/**
|
| 7 |
+
* A very simple job queue with adjustable concurrency. Adapted from
|
| 8 |
+
* https://github.com/STRML/async-limiter
|
| 9 |
+
*/
|
| 10 |
+
class Limiter {
|
| 11 |
+
/**
|
| 12 |
+
* Creates a new `Limiter`.
|
| 13 |
+
*
|
| 14 |
+
* @param {Number} [concurrency=Infinity] The maximum number of jobs allowed
|
| 15 |
+
* to run concurrently
|
| 16 |
+
*/
|
| 17 |
+
constructor(concurrency) {
|
| 18 |
+
this[kDone] = () => {
|
| 19 |
+
this.pending--;
|
| 20 |
+
this[kRun]();
|
| 21 |
+
};
|
| 22 |
+
this.concurrency = concurrency || Infinity;
|
| 23 |
+
this.jobs = [];
|
| 24 |
+
this.pending = 0;
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
/**
|
| 28 |
+
* Adds a job to the queue.
|
| 29 |
+
*
|
| 30 |
+
* @param {Function} job The job to run
|
| 31 |
+
* @public
|
| 32 |
+
*/
|
| 33 |
+
add(job) {
|
| 34 |
+
this.jobs.push(job);
|
| 35 |
+
this[kRun]();
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
/**
|
| 39 |
+
* Removes a job from the queue and runs it if possible.
|
| 40 |
+
*
|
| 41 |
+
* @private
|
| 42 |
+
*/
|
| 43 |
+
[kRun]() {
|
| 44 |
+
if (this.pending === this.concurrency) return;
|
| 45 |
+
|
| 46 |
+
if (this.jobs.length) {
|
| 47 |
+
const job = this.jobs.shift();
|
| 48 |
+
|
| 49 |
+
this.pending++;
|
| 50 |
+
job(this[kDone]);
|
| 51 |
+
}
|
| 52 |
+
}
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
module.exports = Limiter;
|
platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/ws/lib/permessage-deflate.js
ADDED
|
@@ -0,0 +1,528 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
'use strict';
|
| 2 |
+
|
| 3 |
+
const zlib = require('zlib');
|
| 4 |
+
|
| 5 |
+
const bufferUtil = require('./buffer-util');
|
| 6 |
+
const Limiter = require('./limiter');
|
| 7 |
+
const { kStatusCode } = require('./constants');
|
| 8 |
+
|
| 9 |
+
const FastBuffer = Buffer[Symbol.species];
|
| 10 |
+
const TRAILER = Buffer.from([0x00, 0x00, 0xff, 0xff]);
|
| 11 |
+
const kPerMessageDeflate = Symbol('permessage-deflate');
|
| 12 |
+
const kTotalLength = Symbol('total-length');
|
| 13 |
+
const kCallback = Symbol('callback');
|
| 14 |
+
const kBuffers = Symbol('buffers');
|
| 15 |
+
const kError = Symbol('error');
|
| 16 |
+
|
| 17 |
+
//
|
| 18 |
+
// We limit zlib concurrency, which prevents severe memory fragmentation
|
| 19 |
+
// as documented in https://github.com/nodejs/node/issues/8871#issuecomment-250915913
|
| 20 |
+
// and https://github.com/websockets/ws/issues/1202
|
| 21 |
+
//
|
| 22 |
+
// Intentionally global; it's the global thread pool that's an issue.
|
| 23 |
+
//
|
| 24 |
+
let zlibLimiter;
|
| 25 |
+
|
| 26 |
+
/**
|
| 27 |
+
* permessage-deflate implementation.
|
| 28 |
+
*/
|
| 29 |
+
class PerMessageDeflate {
|
| 30 |
+
/**
|
| 31 |
+
* Creates a PerMessageDeflate instance.
|
| 32 |
+
*
|
| 33 |
+
* @param {Object} [options] Configuration options
|
| 34 |
+
* @param {(Boolean|Number)} [options.clientMaxWindowBits] Advertise support
|
| 35 |
+
* for, or request, a custom client window size
|
| 36 |
+
* @param {Boolean} [options.clientNoContextTakeover=false] Advertise/
|
| 37 |
+
* acknowledge disabling of client context takeover
|
| 38 |
+
* @param {Number} [options.concurrencyLimit=10] The number of concurrent
|
| 39 |
+
* calls to zlib
|
| 40 |
+
* @param {(Boolean|Number)} [options.serverMaxWindowBits] Request/confirm the
|
| 41 |
+
* use of a custom server window size
|
| 42 |
+
* @param {Boolean} [options.serverNoContextTakeover=false] Request/accept
|
| 43 |
+
* disabling of server context takeover
|
| 44 |
+
* @param {Number} [options.threshold=1024] Size (in bytes) below which
|
| 45 |
+
* messages should not be compressed if context takeover is disabled
|
| 46 |
+
* @param {Object} [options.zlibDeflateOptions] Options to pass to zlib on
|
| 47 |
+
* deflate
|
| 48 |
+
* @param {Object} [options.zlibInflateOptions] Options to pass to zlib on
|
| 49 |
+
* inflate
|
| 50 |
+
* @param {Boolean} [isServer=false] Create the instance in either server or
|
| 51 |
+
* client mode
|
| 52 |
+
* @param {Number} [maxPayload=0] The maximum allowed message length
|
| 53 |
+
*/
|
| 54 |
+
constructor(options, isServer, maxPayload) {
|
| 55 |
+
this._maxPayload = maxPayload | 0;
|
| 56 |
+
this._options = options || {};
|
| 57 |
+
this._threshold =
|
| 58 |
+
this._options.threshold !== undefined ? this._options.threshold : 1024;
|
| 59 |
+
this._isServer = !!isServer;
|
| 60 |
+
this._deflate = null;
|
| 61 |
+
this._inflate = null;
|
| 62 |
+
|
| 63 |
+
this.params = null;
|
| 64 |
+
|
| 65 |
+
if (!zlibLimiter) {
|
| 66 |
+
const concurrency =
|
| 67 |
+
this._options.concurrencyLimit !== undefined
|
| 68 |
+
? this._options.concurrencyLimit
|
| 69 |
+
: 10;
|
| 70 |
+
zlibLimiter = new Limiter(concurrency);
|
| 71 |
+
}
|
| 72 |
+
}
|
| 73 |
+
|
| 74 |
+
/**
|
| 75 |
+
* @type {String}
|
| 76 |
+
*/
|
| 77 |
+
static get extensionName() {
|
| 78 |
+
return 'permessage-deflate';
|
| 79 |
+
}
|
| 80 |
+
|
| 81 |
+
/**
|
| 82 |
+
* Create an extension negotiation offer.
|
| 83 |
+
*
|
| 84 |
+
* @return {Object} Extension parameters
|
| 85 |
+
* @public
|
| 86 |
+
*/
|
| 87 |
+
offer() {
|
| 88 |
+
const params = {};
|
| 89 |
+
|
| 90 |
+
if (this._options.serverNoContextTakeover) {
|
| 91 |
+
params.server_no_context_takeover = true;
|
| 92 |
+
}
|
| 93 |
+
if (this._options.clientNoContextTakeover) {
|
| 94 |
+
params.client_no_context_takeover = true;
|
| 95 |
+
}
|
| 96 |
+
if (this._options.serverMaxWindowBits) {
|
| 97 |
+
params.server_max_window_bits = this._options.serverMaxWindowBits;
|
| 98 |
+
}
|
| 99 |
+
if (this._options.clientMaxWindowBits) {
|
| 100 |
+
params.client_max_window_bits = this._options.clientMaxWindowBits;
|
| 101 |
+
} else if (this._options.clientMaxWindowBits == null) {
|
| 102 |
+
params.client_max_window_bits = true;
|
| 103 |
+
}
|
| 104 |
+
|
| 105 |
+
return params;
|
| 106 |
+
}
|
| 107 |
+
|
| 108 |
+
/**
|
| 109 |
+
* Accept an extension negotiation offer/response.
|
| 110 |
+
*
|
| 111 |
+
* @param {Array} configurations The extension negotiation offers/reponse
|
| 112 |
+
* @return {Object} Accepted configuration
|
| 113 |
+
* @public
|
| 114 |
+
*/
|
| 115 |
+
accept(configurations) {
|
| 116 |
+
configurations = this.normalizeParams(configurations);
|
| 117 |
+
|
| 118 |
+
this.params = this._isServer
|
| 119 |
+
? this.acceptAsServer(configurations)
|
| 120 |
+
: this.acceptAsClient(configurations);
|
| 121 |
+
|
| 122 |
+
return this.params;
|
| 123 |
+
}
|
| 124 |
+
|
| 125 |
+
/**
|
| 126 |
+
* Releases all resources used by the extension.
|
| 127 |
+
*
|
| 128 |
+
* @public
|
| 129 |
+
*/
|
| 130 |
+
cleanup() {
|
| 131 |
+
if (this._inflate) {
|
| 132 |
+
this._inflate.close();
|
| 133 |
+
this._inflate = null;
|
| 134 |
+
}
|
| 135 |
+
|
| 136 |
+
if (this._deflate) {
|
| 137 |
+
const callback = this._deflate[kCallback];
|
| 138 |
+
|
| 139 |
+
this._deflate.close();
|
| 140 |
+
this._deflate = null;
|
| 141 |
+
|
| 142 |
+
if (callback) {
|
| 143 |
+
callback(
|
| 144 |
+
new Error(
|
| 145 |
+
'The deflate stream was closed while data was being processed'
|
| 146 |
+
)
|
| 147 |
+
);
|
| 148 |
+
}
|
| 149 |
+
}
|
| 150 |
+
}
|
| 151 |
+
|
| 152 |
+
/**
|
| 153 |
+
* Accept an extension negotiation offer.
|
| 154 |
+
*
|
| 155 |
+
* @param {Array} offers The extension negotiation offers
|
| 156 |
+
* @return {Object} Accepted configuration
|
| 157 |
+
* @private
|
| 158 |
+
*/
|
| 159 |
+
acceptAsServer(offers) {
|
| 160 |
+
const opts = this._options;
|
| 161 |
+
const accepted = offers.find((params) => {
|
| 162 |
+
if (
|
| 163 |
+
(opts.serverNoContextTakeover === false &&
|
| 164 |
+
params.server_no_context_takeover) ||
|
| 165 |
+
(params.server_max_window_bits &&
|
| 166 |
+
(opts.serverMaxWindowBits === false ||
|
| 167 |
+
(typeof opts.serverMaxWindowBits === 'number' &&
|
| 168 |
+
opts.serverMaxWindowBits > params.server_max_window_bits))) ||
|
| 169 |
+
(typeof opts.clientMaxWindowBits === 'number' &&
|
| 170 |
+
!params.client_max_window_bits)
|
| 171 |
+
) {
|
| 172 |
+
return false;
|
| 173 |
+
}
|
| 174 |
+
|
| 175 |
+
return true;
|
| 176 |
+
});
|
| 177 |
+
|
| 178 |
+
if (!accepted) {
|
| 179 |
+
throw new Error('None of the extension offers can be accepted');
|
| 180 |
+
}
|
| 181 |
+
|
| 182 |
+
if (opts.serverNoContextTakeover) {
|
| 183 |
+
accepted.server_no_context_takeover = true;
|
| 184 |
+
}
|
| 185 |
+
if (opts.clientNoContextTakeover) {
|
| 186 |
+
accepted.client_no_context_takeover = true;
|
| 187 |
+
}
|
| 188 |
+
if (typeof opts.serverMaxWindowBits === 'number') {
|
| 189 |
+
accepted.server_max_window_bits = opts.serverMaxWindowBits;
|
| 190 |
+
}
|
| 191 |
+
if (typeof opts.clientMaxWindowBits === 'number') {
|
| 192 |
+
accepted.client_max_window_bits = opts.clientMaxWindowBits;
|
| 193 |
+
} else if (
|
| 194 |
+
accepted.client_max_window_bits === true ||
|
| 195 |
+
opts.clientMaxWindowBits === false
|
| 196 |
+
) {
|
| 197 |
+
delete accepted.client_max_window_bits;
|
| 198 |
+
}
|
| 199 |
+
|
| 200 |
+
return accepted;
|
| 201 |
+
}
|
| 202 |
+
|
| 203 |
+
/**
|
| 204 |
+
* Accept the extension negotiation response.
|
| 205 |
+
*
|
| 206 |
+
* @param {Array} response The extension negotiation response
|
| 207 |
+
* @return {Object} Accepted configuration
|
| 208 |
+
* @private
|
| 209 |
+
*/
|
| 210 |
+
acceptAsClient(response) {
|
| 211 |
+
const params = response[0];
|
| 212 |
+
|
| 213 |
+
if (
|
| 214 |
+
this._options.clientNoContextTakeover === false &&
|
| 215 |
+
params.client_no_context_takeover
|
| 216 |
+
) {
|
| 217 |
+
throw new Error('Unexpected parameter "client_no_context_takeover"');
|
| 218 |
+
}
|
| 219 |
+
|
| 220 |
+
if (!params.client_max_window_bits) {
|
| 221 |
+
if (typeof this._options.clientMaxWindowBits === 'number') {
|
| 222 |
+
params.client_max_window_bits = this._options.clientMaxWindowBits;
|
| 223 |
+
}
|
| 224 |
+
} else if (
|
| 225 |
+
this._options.clientMaxWindowBits === false ||
|
| 226 |
+
(typeof this._options.clientMaxWindowBits === 'number' &&
|
| 227 |
+
params.client_max_window_bits > this._options.clientMaxWindowBits)
|
| 228 |
+
) {
|
| 229 |
+
throw new Error(
|
| 230 |
+
'Unexpected or invalid parameter "client_max_window_bits"'
|
| 231 |
+
);
|
| 232 |
+
}
|
| 233 |
+
|
| 234 |
+
return params;
|
| 235 |
+
}
|
| 236 |
+
|
| 237 |
+
/**
|
| 238 |
+
* Normalize parameters.
|
| 239 |
+
*
|
| 240 |
+
* @param {Array} configurations The extension negotiation offers/reponse
|
| 241 |
+
* @return {Array} The offers/response with normalized parameters
|
| 242 |
+
* @private
|
| 243 |
+
*/
|
| 244 |
+
normalizeParams(configurations) {
|
| 245 |
+
configurations.forEach((params) => {
|
| 246 |
+
Object.keys(params).forEach((key) => {
|
| 247 |
+
let value = params[key];
|
| 248 |
+
|
| 249 |
+
if (value.length > 1) {
|
| 250 |
+
throw new Error(`Parameter "${key}" must have only a single value`);
|
| 251 |
+
}
|
| 252 |
+
|
| 253 |
+
value = value[0];
|
| 254 |
+
|
| 255 |
+
if (key === 'client_max_window_bits') {
|
| 256 |
+
if (value !== true) {
|
| 257 |
+
const num = +value;
|
| 258 |
+
if (!Number.isInteger(num) || num < 8 || num > 15) {
|
| 259 |
+
throw new TypeError(
|
| 260 |
+
`Invalid value for parameter "${key}": ${value}`
|
| 261 |
+
);
|
| 262 |
+
}
|
| 263 |
+
value = num;
|
| 264 |
+
} else if (!this._isServer) {
|
| 265 |
+
throw new TypeError(
|
| 266 |
+
`Invalid value for parameter "${key}": ${value}`
|
| 267 |
+
);
|
| 268 |
+
}
|
| 269 |
+
} else if (key === 'server_max_window_bits') {
|
| 270 |
+
const num = +value;
|
| 271 |
+
if (!Number.isInteger(num) || num < 8 || num > 15) {
|
| 272 |
+
throw new TypeError(
|
| 273 |
+
`Invalid value for parameter "${key}": ${value}`
|
| 274 |
+
);
|
| 275 |
+
}
|
| 276 |
+
value = num;
|
| 277 |
+
} else if (
|
| 278 |
+
key === 'client_no_context_takeover' ||
|
| 279 |
+
key === 'server_no_context_takeover'
|
| 280 |
+
) {
|
| 281 |
+
if (value !== true) {
|
| 282 |
+
throw new TypeError(
|
| 283 |
+
`Invalid value for parameter "${key}": ${value}`
|
| 284 |
+
);
|
| 285 |
+
}
|
| 286 |
+
} else {
|
| 287 |
+
throw new Error(`Unknown parameter "${key}"`);
|
| 288 |
+
}
|
| 289 |
+
|
| 290 |
+
params[key] = value;
|
| 291 |
+
});
|
| 292 |
+
});
|
| 293 |
+
|
| 294 |
+
return configurations;
|
| 295 |
+
}
|
| 296 |
+
|
| 297 |
+
/**
|
| 298 |
+
* Decompress data. Concurrency limited.
|
| 299 |
+
*
|
| 300 |
+
* @param {Buffer} data Compressed data
|
| 301 |
+
* @param {Boolean} fin Specifies whether or not this is the last fragment
|
| 302 |
+
* @param {Function} callback Callback
|
| 303 |
+
* @public
|
| 304 |
+
*/
|
| 305 |
+
decompress(data, fin, callback) {
|
| 306 |
+
zlibLimiter.add((done) => {
|
| 307 |
+
this._decompress(data, fin, (err, result) => {
|
| 308 |
+
done();
|
| 309 |
+
callback(err, result);
|
| 310 |
+
});
|
| 311 |
+
});
|
| 312 |
+
}
|
| 313 |
+
|
| 314 |
+
/**
|
| 315 |
+
* Compress data. Concurrency limited.
|
| 316 |
+
*
|
| 317 |
+
* @param {(Buffer|String)} data Data to compress
|
| 318 |
+
* @param {Boolean} fin Specifies whether or not this is the last fragment
|
| 319 |
+
* @param {Function} callback Callback
|
| 320 |
+
* @public
|
| 321 |
+
*/
|
| 322 |
+
compress(data, fin, callback) {
|
| 323 |
+
zlibLimiter.add((done) => {
|
| 324 |
+
this._compress(data, fin, (err, result) => {
|
| 325 |
+
done();
|
| 326 |
+
callback(err, result);
|
| 327 |
+
});
|
| 328 |
+
});
|
| 329 |
+
}
|
| 330 |
+
|
| 331 |
+
/**
|
| 332 |
+
* Decompress data.
|
| 333 |
+
*
|
| 334 |
+
* @param {Buffer} data Compressed data
|
| 335 |
+
* @param {Boolean} fin Specifies whether or not this is the last fragment
|
| 336 |
+
* @param {Function} callback Callback
|
| 337 |
+
* @private
|
| 338 |
+
*/
|
| 339 |
+
_decompress(data, fin, callback) {
|
| 340 |
+
const endpoint = this._isServer ? 'client' : 'server';
|
| 341 |
+
|
| 342 |
+
if (!this._inflate) {
|
| 343 |
+
const key = `${endpoint}_max_window_bits`;
|
| 344 |
+
const windowBits =
|
| 345 |
+
typeof this.params[key] !== 'number'
|
| 346 |
+
? zlib.Z_DEFAULT_WINDOWBITS
|
| 347 |
+
: this.params[key];
|
| 348 |
+
|
| 349 |
+
this._inflate = zlib.createInflateRaw({
|
| 350 |
+
...this._options.zlibInflateOptions,
|
| 351 |
+
windowBits
|
| 352 |
+
});
|
| 353 |
+
this._inflate[kPerMessageDeflate] = this;
|
| 354 |
+
this._inflate[kTotalLength] = 0;
|
| 355 |
+
this._inflate[kBuffers] = [];
|
| 356 |
+
this._inflate.on('error', inflateOnError);
|
| 357 |
+
this._inflate.on('data', inflateOnData);
|
| 358 |
+
}
|
| 359 |
+
|
| 360 |
+
this._inflate[kCallback] = callback;
|
| 361 |
+
|
| 362 |
+
this._inflate.write(data);
|
| 363 |
+
if (fin) this._inflate.write(TRAILER);
|
| 364 |
+
|
| 365 |
+
this._inflate.flush(() => {
|
| 366 |
+
const err = this._inflate[kError];
|
| 367 |
+
|
| 368 |
+
if (err) {
|
| 369 |
+
this._inflate.close();
|
| 370 |
+
this._inflate = null;
|
| 371 |
+
callback(err);
|
| 372 |
+
return;
|
| 373 |
+
}
|
| 374 |
+
|
| 375 |
+
const data = bufferUtil.concat(
|
| 376 |
+
this._inflate[kBuffers],
|
| 377 |
+
this._inflate[kTotalLength]
|
| 378 |
+
);
|
| 379 |
+
|
| 380 |
+
if (this._inflate._readableState.endEmitted) {
|
| 381 |
+
this._inflate.close();
|
| 382 |
+
this._inflate = null;
|
| 383 |
+
} else {
|
| 384 |
+
this._inflate[kTotalLength] = 0;
|
| 385 |
+
this._inflate[kBuffers] = [];
|
| 386 |
+
|
| 387 |
+
if (fin && this.params[`${endpoint}_no_context_takeover`]) {
|
| 388 |
+
this._inflate.reset();
|
| 389 |
+
}
|
| 390 |
+
}
|
| 391 |
+
|
| 392 |
+
callback(null, data);
|
| 393 |
+
});
|
| 394 |
+
}
|
| 395 |
+
|
| 396 |
+
/**
|
| 397 |
+
* Compress data.
|
| 398 |
+
*
|
| 399 |
+
* @param {(Buffer|String)} data Data to compress
|
| 400 |
+
* @param {Boolean} fin Specifies whether or not this is the last fragment
|
| 401 |
+
* @param {Function} callback Callback
|
| 402 |
+
* @private
|
| 403 |
+
*/
|
| 404 |
+
_compress(data, fin, callback) {
|
| 405 |
+
const endpoint = this._isServer ? 'server' : 'client';
|
| 406 |
+
|
| 407 |
+
if (!this._deflate) {
|
| 408 |
+
const key = `${endpoint}_max_window_bits`;
|
| 409 |
+
const windowBits =
|
| 410 |
+
typeof this.params[key] !== 'number'
|
| 411 |
+
? zlib.Z_DEFAULT_WINDOWBITS
|
| 412 |
+
: this.params[key];
|
| 413 |
+
|
| 414 |
+
this._deflate = zlib.createDeflateRaw({
|
| 415 |
+
...this._options.zlibDeflateOptions,
|
| 416 |
+
windowBits
|
| 417 |
+
});
|
| 418 |
+
|
| 419 |
+
this._deflate[kTotalLength] = 0;
|
| 420 |
+
this._deflate[kBuffers] = [];
|
| 421 |
+
|
| 422 |
+
this._deflate.on('data', deflateOnData);
|
| 423 |
+
}
|
| 424 |
+
|
| 425 |
+
this._deflate[kCallback] = callback;
|
| 426 |
+
|
| 427 |
+
this._deflate.write(data);
|
| 428 |
+
this._deflate.flush(zlib.Z_SYNC_FLUSH, () => {
|
| 429 |
+
if (!this._deflate) {
|
| 430 |
+
//
|
| 431 |
+
// The deflate stream was closed while data was being processed.
|
| 432 |
+
//
|
| 433 |
+
return;
|
| 434 |
+
}
|
| 435 |
+
|
| 436 |
+
let data = bufferUtil.concat(
|
| 437 |
+
this._deflate[kBuffers],
|
| 438 |
+
this._deflate[kTotalLength]
|
| 439 |
+
);
|
| 440 |
+
|
| 441 |
+
if (fin) {
|
| 442 |
+
data = new FastBuffer(data.buffer, data.byteOffset, data.length - 4);
|
| 443 |
+
}
|
| 444 |
+
|
| 445 |
+
//
|
| 446 |
+
// Ensure that the callback will not be called again in
|
| 447 |
+
// `PerMessageDeflate#cleanup()`.
|
| 448 |
+
//
|
| 449 |
+
this._deflate[kCallback] = null;
|
| 450 |
+
|
| 451 |
+
this._deflate[kTotalLength] = 0;
|
| 452 |
+
this._deflate[kBuffers] = [];
|
| 453 |
+
|
| 454 |
+
if (fin && this.params[`${endpoint}_no_context_takeover`]) {
|
| 455 |
+
this._deflate.reset();
|
| 456 |
+
}
|
| 457 |
+
|
| 458 |
+
callback(null, data);
|
| 459 |
+
});
|
| 460 |
+
}
|
| 461 |
+
}
|
| 462 |
+
|
| 463 |
+
module.exports = PerMessageDeflate;
|
| 464 |
+
|
| 465 |
+
/**
|
| 466 |
+
* The listener of the `zlib.DeflateRaw` stream `'data'` event.
|
| 467 |
+
*
|
| 468 |
+
* @param {Buffer} chunk A chunk of data
|
| 469 |
+
* @private
|
| 470 |
+
*/
|
| 471 |
+
function deflateOnData(chunk) {
|
| 472 |
+
this[kBuffers].push(chunk);
|
| 473 |
+
this[kTotalLength] += chunk.length;
|
| 474 |
+
}
|
| 475 |
+
|
| 476 |
+
/**
|
| 477 |
+
* The listener of the `zlib.InflateRaw` stream `'data'` event.
|
| 478 |
+
*
|
| 479 |
+
* @param {Buffer} chunk A chunk of data
|
| 480 |
+
* @private
|
| 481 |
+
*/
|
| 482 |
+
function inflateOnData(chunk) {
|
| 483 |
+
this[kTotalLength] += chunk.length;
|
| 484 |
+
|
| 485 |
+
if (
|
| 486 |
+
this[kPerMessageDeflate]._maxPayload < 1 ||
|
| 487 |
+
this[kTotalLength] <= this[kPerMessageDeflate]._maxPayload
|
| 488 |
+
) {
|
| 489 |
+
this[kBuffers].push(chunk);
|
| 490 |
+
return;
|
| 491 |
+
}
|
| 492 |
+
|
| 493 |
+
this[kError] = new RangeError('Max payload size exceeded');
|
| 494 |
+
this[kError].code = 'WS_ERR_UNSUPPORTED_MESSAGE_LENGTH';
|
| 495 |
+
this[kError][kStatusCode] = 1009;
|
| 496 |
+
this.removeListener('data', inflateOnData);
|
| 497 |
+
|
| 498 |
+
//
|
| 499 |
+
// The choice to employ `zlib.reset()` over `zlib.close()` is dictated by the
|
| 500 |
+
// fact that in Node.js versions prior to 13.10.0, the callback for
|
| 501 |
+
// `zlib.flush()` is not called if `zlib.close()` is used. Utilizing
|
| 502 |
+
// `zlib.reset()` ensures that either the callback is invoked or an error is
|
| 503 |
+
// emitted.
|
| 504 |
+
//
|
| 505 |
+
this.reset();
|
| 506 |
+
}
|
| 507 |
+
|
| 508 |
+
/**
|
| 509 |
+
* The listener of the `zlib.InflateRaw` stream `'error'` event.
|
| 510 |
+
*
|
| 511 |
+
* @param {Error} err The emitted error
|
| 512 |
+
* @private
|
| 513 |
+
*/
|
| 514 |
+
function inflateOnError(err) {
|
| 515 |
+
//
|
| 516 |
+
// There is no need to call `Zlib#close()` as the handle is automatically
|
| 517 |
+
// closed when an error is emitted.
|
| 518 |
+
//
|
| 519 |
+
this[kPerMessageDeflate]._inflate = null;
|
| 520 |
+
|
| 521 |
+
if (this[kError]) {
|
| 522 |
+
this[kCallback](this[kError]);
|
| 523 |
+
return;
|
| 524 |
+
}
|
| 525 |
+
|
| 526 |
+
err[kStatusCode] = 1007;
|
| 527 |
+
this[kCallback](err);
|
| 528 |
+
}
|
platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/ws/lib/receiver.js
ADDED
|
@@ -0,0 +1,706 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
+
const {
|
| 7 |
+
BINARY_TYPES,
|
| 8 |
+
EMPTY_BUFFER,
|
| 9 |
+
kStatusCode,
|
| 10 |
+
kWebSocket
|
| 11 |
+
} = require('./constants');
|
| 12 |
+
const { concat, toArrayBuffer, unmask } = require('./buffer-util');
|
| 13 |
+
const { isValidStatusCode, isValidUTF8 } = require('./validation');
|
| 14 |
+
|
| 15 |
+
const FastBuffer = Buffer[Symbol.species];
|
| 16 |
+
|
| 17 |
+
const GET_INFO = 0;
|
| 18 |
+
const GET_PAYLOAD_LENGTH_16 = 1;
|
| 19 |
+
const GET_PAYLOAD_LENGTH_64 = 2;
|
| 20 |
+
const GET_MASK = 3;
|
| 21 |
+
const GET_DATA = 4;
|
| 22 |
+
const INFLATING = 5;
|
| 23 |
+
const DEFER_EVENT = 6;
|
| 24 |
+
|
| 25 |
+
/**
|
| 26 |
+
* HyBi Receiver implementation.
|
| 27 |
+
*
|
| 28 |
+
* @extends Writable
|
| 29 |
+
*/
|
| 30 |
+
class Receiver extends Writable {
|
| 31 |
+
/**
|
| 32 |
+
* Creates a Receiver instance.
|
| 33 |
+
*
|
| 34 |
+
* @param {Object} [options] Options object
|
| 35 |
+
* @param {Boolean} [options.allowSynchronousEvents=true] Specifies whether
|
| 36 |
+
* any of the `'message'`, `'ping'`, and `'pong'` events can be emitted
|
| 37 |
+
* multiple times in the same tick
|
| 38 |
+
* @param {String} [options.binaryType=nodebuffer] The type for binary data
|
| 39 |
+
* @param {Object} [options.extensions] An object containing the negotiated
|
| 40 |
+
* extensions
|
| 41 |
+
* @param {Boolean} [options.isServer=false] Specifies whether to operate in
|
| 42 |
+
* client or server mode
|
| 43 |
+
* @param {Number} [options.maxPayload=0] The maximum allowed message length
|
| 44 |
+
* @param {Boolean} [options.skipUTF8Validation=false] Specifies whether or
|
| 45 |
+
* not to skip UTF-8 validation for text and close messages
|
| 46 |
+
*/
|
| 47 |
+
constructor(options = {}) {
|
| 48 |
+
super();
|
| 49 |
+
|
| 50 |
+
this._allowSynchronousEvents =
|
| 51 |
+
options.allowSynchronousEvents !== undefined
|
| 52 |
+
? options.allowSynchronousEvents
|
| 53 |
+
: true;
|
| 54 |
+
this._binaryType = options.binaryType || BINARY_TYPES[0];
|
| 55 |
+
this._extensions = options.extensions || {};
|
| 56 |
+
this._isServer = !!options.isServer;
|
| 57 |
+
this._maxPayload = options.maxPayload | 0;
|
| 58 |
+
this._skipUTF8Validation = !!options.skipUTF8Validation;
|
| 59 |
+
this[kWebSocket] = undefined;
|
| 60 |
+
|
| 61 |
+
this._bufferedBytes = 0;
|
| 62 |
+
this._buffers = [];
|
| 63 |
+
|
| 64 |
+
this._compressed = false;
|
| 65 |
+
this._payloadLength = 0;
|
| 66 |
+
this._mask = undefined;
|
| 67 |
+
this._fragmented = 0;
|
| 68 |
+
this._masked = false;
|
| 69 |
+
this._fin = false;
|
| 70 |
+
this._opcode = 0;
|
| 71 |
+
|
| 72 |
+
this._totalPayloadLength = 0;
|
| 73 |
+
this._messageLength = 0;
|
| 74 |
+
this._fragments = [];
|
| 75 |
+
|
| 76 |
+
this._errored = false;
|
| 77 |
+
this._loop = false;
|
| 78 |
+
this._state = GET_INFO;
|
| 79 |
+
}
|
| 80 |
+
|
| 81 |
+
/**
|
| 82 |
+
* Implements `Writable.prototype._write()`.
|
| 83 |
+
*
|
| 84 |
+
* @param {Buffer} chunk The chunk of data to write
|
| 85 |
+
* @param {String} encoding The character encoding of `chunk`
|
| 86 |
+
* @param {Function} cb Callback
|
| 87 |
+
* @private
|
| 88 |
+
*/
|
| 89 |
+
_write(chunk, encoding, cb) {
|
| 90 |
+
if (this._opcode === 0x08 && this._state == GET_INFO) return cb();
|
| 91 |
+
|
| 92 |
+
this._bufferedBytes += chunk.length;
|
| 93 |
+
this._buffers.push(chunk);
|
| 94 |
+
this.startLoop(cb);
|
| 95 |
+
}
|
| 96 |
+
|
| 97 |
+
/**
|
| 98 |
+
* Consumes `n` bytes from the buffered data.
|
| 99 |
+
*
|
| 100 |
+
* @param {Number} n The number of bytes to consume
|
| 101 |
+
* @return {Buffer} The consumed bytes
|
| 102 |
+
* @private
|
| 103 |
+
*/
|
| 104 |
+
consume(n) {
|
| 105 |
+
this._bufferedBytes -= n;
|
| 106 |
+
|
| 107 |
+
if (n === this._buffers[0].length) return this._buffers.shift();
|
| 108 |
+
|
| 109 |
+
if (n < this._buffers[0].length) {
|
| 110 |
+
const buf = this._buffers[0];
|
| 111 |
+
this._buffers[0] = new FastBuffer(
|
| 112 |
+
buf.buffer,
|
| 113 |
+
buf.byteOffset + n,
|
| 114 |
+
buf.length - n
|
| 115 |
+
);
|
| 116 |
+
|
| 117 |
+
return new FastBuffer(buf.buffer, buf.byteOffset, n);
|
| 118 |
+
}
|
| 119 |
+
|
| 120 |
+
const dst = Buffer.allocUnsafe(n);
|
| 121 |
+
|
| 122 |
+
do {
|
| 123 |
+
const buf = this._buffers[0];
|
| 124 |
+
const offset = dst.length - n;
|
| 125 |
+
|
| 126 |
+
if (n >= buf.length) {
|
| 127 |
+
dst.set(this._buffers.shift(), offset);
|
| 128 |
+
} else {
|
| 129 |
+
dst.set(new Uint8Array(buf.buffer, buf.byteOffset, n), offset);
|
| 130 |
+
this._buffers[0] = new FastBuffer(
|
| 131 |
+
buf.buffer,
|
| 132 |
+
buf.byteOffset + n,
|
| 133 |
+
buf.length - n
|
| 134 |
+
);
|
| 135 |
+
}
|
| 136 |
+
|
| 137 |
+
n -= buf.length;
|
| 138 |
+
} while (n > 0);
|
| 139 |
+
|
| 140 |
+
return dst;
|
| 141 |
+
}
|
| 142 |
+
|
| 143 |
+
/**
|
| 144 |
+
* Starts the parsing loop.
|
| 145 |
+
*
|
| 146 |
+
* @param {Function} cb Callback
|
| 147 |
+
* @private
|
| 148 |
+
*/
|
| 149 |
+
startLoop(cb) {
|
| 150 |
+
this._loop = true;
|
| 151 |
+
|
| 152 |
+
do {
|
| 153 |
+
switch (this._state) {
|
| 154 |
+
case GET_INFO:
|
| 155 |
+
this.getInfo(cb);
|
| 156 |
+
break;
|
| 157 |
+
case GET_PAYLOAD_LENGTH_16:
|
| 158 |
+
this.getPayloadLength16(cb);
|
| 159 |
+
break;
|
| 160 |
+
case GET_PAYLOAD_LENGTH_64:
|
| 161 |
+
this.getPayloadLength64(cb);
|
| 162 |
+
break;
|
| 163 |
+
case GET_MASK:
|
| 164 |
+
this.getMask();
|
| 165 |
+
break;
|
| 166 |
+
case GET_DATA:
|
| 167 |
+
this.getData(cb);
|
| 168 |
+
break;
|
| 169 |
+
case INFLATING:
|
| 170 |
+
case DEFER_EVENT:
|
| 171 |
+
this._loop = false;
|
| 172 |
+
return;
|
| 173 |
+
}
|
| 174 |
+
} while (this._loop);
|
| 175 |
+
|
| 176 |
+
if (!this._errored) cb();
|
| 177 |
+
}
|
| 178 |
+
|
| 179 |
+
/**
|
| 180 |
+
* Reads the first two bytes of a frame.
|
| 181 |
+
*
|
| 182 |
+
* @param {Function} cb Callback
|
| 183 |
+
* @private
|
| 184 |
+
*/
|
| 185 |
+
getInfo(cb) {
|
| 186 |
+
if (this._bufferedBytes < 2) {
|
| 187 |
+
this._loop = false;
|
| 188 |
+
return;
|
| 189 |
+
}
|
| 190 |
+
|
| 191 |
+
const buf = this.consume(2);
|
| 192 |
+
|
| 193 |
+
if ((buf[0] & 0x30) !== 0x00) {
|
| 194 |
+
const error = this.createError(
|
| 195 |
+
RangeError,
|
| 196 |
+
'RSV2 and RSV3 must be clear',
|
| 197 |
+
true,
|
| 198 |
+
1002,
|
| 199 |
+
'WS_ERR_UNEXPECTED_RSV_2_3'
|
| 200 |
+
);
|
| 201 |
+
|
| 202 |
+
cb(error);
|
| 203 |
+
return;
|
| 204 |
+
}
|
| 205 |
+
|
| 206 |
+
const compressed = (buf[0] & 0x40) === 0x40;
|
| 207 |
+
|
| 208 |
+
if (compressed && !this._extensions[PerMessageDeflate.extensionName]) {
|
| 209 |
+
const error = this.createError(
|
| 210 |
+
RangeError,
|
| 211 |
+
'RSV1 must be clear',
|
| 212 |
+
true,
|
| 213 |
+
1002,
|
| 214 |
+
'WS_ERR_UNEXPECTED_RSV_1'
|
| 215 |
+
);
|
| 216 |
+
|
| 217 |
+
cb(error);
|
| 218 |
+
return;
|
| 219 |
+
}
|
| 220 |
+
|
| 221 |
+
this._fin = (buf[0] & 0x80) === 0x80;
|
| 222 |
+
this._opcode = buf[0] & 0x0f;
|
| 223 |
+
this._payloadLength = buf[1] & 0x7f;
|
| 224 |
+
|
| 225 |
+
if (this._opcode === 0x00) {
|
| 226 |
+
if (compressed) {
|
| 227 |
+
const error = this.createError(
|
| 228 |
+
RangeError,
|
| 229 |
+
'RSV1 must be clear',
|
| 230 |
+
true,
|
| 231 |
+
1002,
|
| 232 |
+
'WS_ERR_UNEXPECTED_RSV_1'
|
| 233 |
+
);
|
| 234 |
+
|
| 235 |
+
cb(error);
|
| 236 |
+
return;
|
| 237 |
+
}
|
| 238 |
+
|
| 239 |
+
if (!this._fragmented) {
|
| 240 |
+
const error = this.createError(
|
| 241 |
+
RangeError,
|
| 242 |
+
'invalid opcode 0',
|
| 243 |
+
true,
|
| 244 |
+
1002,
|
| 245 |
+
'WS_ERR_INVALID_OPCODE'
|
| 246 |
+
);
|
| 247 |
+
|
| 248 |
+
cb(error);
|
| 249 |
+
return;
|
| 250 |
+
}
|
| 251 |
+
|
| 252 |
+
this._opcode = this._fragmented;
|
| 253 |
+
} else if (this._opcode === 0x01 || this._opcode === 0x02) {
|
| 254 |
+
if (this._fragmented) {
|
| 255 |
+
const error = this.createError(
|
| 256 |
+
RangeError,
|
| 257 |
+
`invalid opcode ${this._opcode}`,
|
| 258 |
+
true,
|
| 259 |
+
1002,
|
| 260 |
+
'WS_ERR_INVALID_OPCODE'
|
| 261 |
+
);
|
| 262 |
+
|
| 263 |
+
cb(error);
|
| 264 |
+
return;
|
| 265 |
+
}
|
| 266 |
+
|
| 267 |
+
this._compressed = compressed;
|
| 268 |
+
} else if (this._opcode > 0x07 && this._opcode < 0x0b) {
|
| 269 |
+
if (!this._fin) {
|
| 270 |
+
const error = this.createError(
|
| 271 |
+
RangeError,
|
| 272 |
+
'FIN must be set',
|
| 273 |
+
true,
|
| 274 |
+
1002,
|
| 275 |
+
'WS_ERR_EXPECTED_FIN'
|
| 276 |
+
);
|
| 277 |
+
|
| 278 |
+
cb(error);
|
| 279 |
+
return;
|
| 280 |
+
}
|
| 281 |
+
|
| 282 |
+
if (compressed) {
|
| 283 |
+
const error = this.createError(
|
| 284 |
+
RangeError,
|
| 285 |
+
'RSV1 must be clear',
|
| 286 |
+
true,
|
| 287 |
+
1002,
|
| 288 |
+
'WS_ERR_UNEXPECTED_RSV_1'
|
| 289 |
+
);
|
| 290 |
+
|
| 291 |
+
cb(error);
|
| 292 |
+
return;
|
| 293 |
+
}
|
| 294 |
+
|
| 295 |
+
if (
|
| 296 |
+
this._payloadLength > 0x7d ||
|
| 297 |
+
(this._opcode === 0x08 && this._payloadLength === 1)
|
| 298 |
+
) {
|
| 299 |
+
const error = this.createError(
|
| 300 |
+
RangeError,
|
| 301 |
+
`invalid payload length ${this._payloadLength}`,
|
| 302 |
+
true,
|
| 303 |
+
1002,
|
| 304 |
+
'WS_ERR_INVALID_CONTROL_PAYLOAD_LENGTH'
|
| 305 |
+
);
|
| 306 |
+
|
| 307 |
+
cb(error);
|
| 308 |
+
return;
|
| 309 |
+
}
|
| 310 |
+
} else {
|
| 311 |
+
const error = this.createError(
|
| 312 |
+
RangeError,
|
| 313 |
+
`invalid opcode ${this._opcode}`,
|
| 314 |
+
true,
|
| 315 |
+
1002,
|
| 316 |
+
'WS_ERR_INVALID_OPCODE'
|
| 317 |
+
);
|
| 318 |
+
|
| 319 |
+
cb(error);
|
| 320 |
+
return;
|
| 321 |
+
}
|
| 322 |
+
|
| 323 |
+
if (!this._fin && !this._fragmented) this._fragmented = this._opcode;
|
| 324 |
+
this._masked = (buf[1] & 0x80) === 0x80;
|
| 325 |
+
|
| 326 |
+
if (this._isServer) {
|
| 327 |
+
if (!this._masked) {
|
| 328 |
+
const error = this.createError(
|
| 329 |
+
RangeError,
|
| 330 |
+
'MASK must be set',
|
| 331 |
+
true,
|
| 332 |
+
1002,
|
| 333 |
+
'WS_ERR_EXPECTED_MASK'
|
| 334 |
+
);
|
| 335 |
+
|
| 336 |
+
cb(error);
|
| 337 |
+
return;
|
| 338 |
+
}
|
| 339 |
+
} else if (this._masked) {
|
| 340 |
+
const error = this.createError(
|
| 341 |
+
RangeError,
|
| 342 |
+
'MASK must be clear',
|
| 343 |
+
true,
|
| 344 |
+
1002,
|
| 345 |
+
'WS_ERR_UNEXPECTED_MASK'
|
| 346 |
+
);
|
| 347 |
+
|
| 348 |
+
cb(error);
|
| 349 |
+
return;
|
| 350 |
+
}
|
| 351 |
+
|
| 352 |
+
if (this._payloadLength === 126) this._state = GET_PAYLOAD_LENGTH_16;
|
| 353 |
+
else if (this._payloadLength === 127) this._state = GET_PAYLOAD_LENGTH_64;
|
| 354 |
+
else this.haveLength(cb);
|
| 355 |
+
}
|
| 356 |
+
|
| 357 |
+
/**
|
| 358 |
+
* Gets extended payload length (7+16).
|
| 359 |
+
*
|
| 360 |
+
* @param {Function} cb Callback
|
| 361 |
+
* @private
|
| 362 |
+
*/
|
| 363 |
+
getPayloadLength16(cb) {
|
| 364 |
+
if (this._bufferedBytes < 2) {
|
| 365 |
+
this._loop = false;
|
| 366 |
+
return;
|
| 367 |
+
}
|
| 368 |
+
|
| 369 |
+
this._payloadLength = this.consume(2).readUInt16BE(0);
|
| 370 |
+
this.haveLength(cb);
|
| 371 |
+
}
|
| 372 |
+
|
| 373 |
+
/**
|
| 374 |
+
* Gets extended payload length (7+64).
|
| 375 |
+
*
|
| 376 |
+
* @param {Function} cb Callback
|
| 377 |
+
* @private
|
| 378 |
+
*/
|
| 379 |
+
getPayloadLength64(cb) {
|
| 380 |
+
if (this._bufferedBytes < 8) {
|
| 381 |
+
this._loop = false;
|
| 382 |
+
return;
|
| 383 |
+
}
|
| 384 |
+
|
| 385 |
+
const buf = this.consume(8);
|
| 386 |
+
const num = buf.readUInt32BE(0);
|
| 387 |
+
|
| 388 |
+
//
|
| 389 |
+
// The maximum safe integer in JavaScript is 2^53 - 1. An error is returned
|
| 390 |
+
// if payload length is greater than this number.
|
| 391 |
+
//
|
| 392 |
+
if (num > Math.pow(2, 53 - 32) - 1) {
|
| 393 |
+
const error = this.createError(
|
| 394 |
+
RangeError,
|
| 395 |
+
'Unsupported WebSocket frame: payload length > 2^53 - 1',
|
| 396 |
+
false,
|
| 397 |
+
1009,
|
| 398 |
+
'WS_ERR_UNSUPPORTED_DATA_PAYLOAD_LENGTH'
|
| 399 |
+
);
|
| 400 |
+
|
| 401 |
+
cb(error);
|
| 402 |
+
return;
|
| 403 |
+
}
|
| 404 |
+
|
| 405 |
+
this._payloadLength = num * Math.pow(2, 32) + buf.readUInt32BE(4);
|
| 406 |
+
this.haveLength(cb);
|
| 407 |
+
}
|
| 408 |
+
|
| 409 |
+
/**
|
| 410 |
+
* Payload length has been read.
|
| 411 |
+
*
|
| 412 |
+
* @param {Function} cb Callback
|
| 413 |
+
* @private
|
| 414 |
+
*/
|
| 415 |
+
haveLength(cb) {
|
| 416 |
+
if (this._payloadLength && this._opcode < 0x08) {
|
| 417 |
+
this._totalPayloadLength += this._payloadLength;
|
| 418 |
+
if (this._totalPayloadLength > this._maxPayload && this._maxPayload > 0) {
|
| 419 |
+
const error = this.createError(
|
| 420 |
+
RangeError,
|
| 421 |
+
'Max payload size exceeded',
|
| 422 |
+
false,
|
| 423 |
+
1009,
|
| 424 |
+
'WS_ERR_UNSUPPORTED_MESSAGE_LENGTH'
|
| 425 |
+
);
|
| 426 |
+
|
| 427 |
+
cb(error);
|
| 428 |
+
return;
|
| 429 |
+
}
|
| 430 |
+
}
|
| 431 |
+
|
| 432 |
+
if (this._masked) this._state = GET_MASK;
|
| 433 |
+
else this._state = GET_DATA;
|
| 434 |
+
}
|
| 435 |
+
|
| 436 |
+
/**
|
| 437 |
+
* Reads mask bytes.
|
| 438 |
+
*
|
| 439 |
+
* @private
|
| 440 |
+
*/
|
| 441 |
+
getMask() {
|
| 442 |
+
if (this._bufferedBytes < 4) {
|
| 443 |
+
this._loop = false;
|
| 444 |
+
return;
|
| 445 |
+
}
|
| 446 |
+
|
| 447 |
+
this._mask = this.consume(4);
|
| 448 |
+
this._state = GET_DATA;
|
| 449 |
+
}
|
| 450 |
+
|
| 451 |
+
/**
|
| 452 |
+
* Reads data bytes.
|
| 453 |
+
*
|
| 454 |
+
* @param {Function} cb Callback
|
| 455 |
+
* @private
|
| 456 |
+
*/
|
| 457 |
+
getData(cb) {
|
| 458 |
+
let data = EMPTY_BUFFER;
|
| 459 |
+
|
| 460 |
+
if (this._payloadLength) {
|
| 461 |
+
if (this._bufferedBytes < this._payloadLength) {
|
| 462 |
+
this._loop = false;
|
| 463 |
+
return;
|
| 464 |
+
}
|
| 465 |
+
|
| 466 |
+
data = this.consume(this._payloadLength);
|
| 467 |
+
|
| 468 |
+
if (
|
| 469 |
+
this._masked &&
|
| 470 |
+
(this._mask[0] | this._mask[1] | this._mask[2] | this._mask[3]) !== 0
|
| 471 |
+
) {
|
| 472 |
+
unmask(data, this._mask);
|
| 473 |
+
}
|
| 474 |
+
}
|
| 475 |
+
|
| 476 |
+
if (this._opcode > 0x07) {
|
| 477 |
+
this.controlMessage(data, cb);
|
| 478 |
+
return;
|
| 479 |
+
}
|
| 480 |
+
|
| 481 |
+
if (this._compressed) {
|
| 482 |
+
this._state = INFLATING;
|
| 483 |
+
this.decompress(data, cb);
|
| 484 |
+
return;
|
| 485 |
+
}
|
| 486 |
+
|
| 487 |
+
if (data.length) {
|
| 488 |
+
//
|
| 489 |
+
// This message is not compressed so its length is the sum of the payload
|
| 490 |
+
// length of all fragments.
|
| 491 |
+
//
|
| 492 |
+
this._messageLength = this._totalPayloadLength;
|
| 493 |
+
this._fragments.push(data);
|
| 494 |
+
}
|
| 495 |
+
|
| 496 |
+
this.dataMessage(cb);
|
| 497 |
+
}
|
| 498 |
+
|
| 499 |
+
/**
|
| 500 |
+
* Decompresses data.
|
| 501 |
+
*
|
| 502 |
+
* @param {Buffer} data Compressed data
|
| 503 |
+
* @param {Function} cb Callback
|
| 504 |
+
* @private
|
| 505 |
+
*/
|
| 506 |
+
decompress(data, cb) {
|
| 507 |
+
const perMessageDeflate = this._extensions[PerMessageDeflate.extensionName];
|
| 508 |
+
|
| 509 |
+
perMessageDeflate.decompress(data, this._fin, (err, buf) => {
|
| 510 |
+
if (err) return cb(err);
|
| 511 |
+
|
| 512 |
+
if (buf.length) {
|
| 513 |
+
this._messageLength += buf.length;
|
| 514 |
+
if (this._messageLength > this._maxPayload && this._maxPayload > 0) {
|
| 515 |
+
const error = this.createError(
|
| 516 |
+
RangeError,
|
| 517 |
+
'Max payload size exceeded',
|
| 518 |
+
false,
|
| 519 |
+
1009,
|
| 520 |
+
'WS_ERR_UNSUPPORTED_MESSAGE_LENGTH'
|
| 521 |
+
);
|
| 522 |
+
|
| 523 |
+
cb(error);
|
| 524 |
+
return;
|
| 525 |
+
}
|
| 526 |
+
|
| 527 |
+
this._fragments.push(buf);
|
| 528 |
+
}
|
| 529 |
+
|
| 530 |
+
this.dataMessage(cb);
|
| 531 |
+
if (this._state === GET_INFO) this.startLoop(cb);
|
| 532 |
+
});
|
| 533 |
+
}
|
| 534 |
+
|
| 535 |
+
/**
|
| 536 |
+
* Handles a data message.
|
| 537 |
+
*
|
| 538 |
+
* @param {Function} cb Callback
|
| 539 |
+
* @private
|
| 540 |
+
*/
|
| 541 |
+
dataMessage(cb) {
|
| 542 |
+
if (!this._fin) {
|
| 543 |
+
this._state = GET_INFO;
|
| 544 |
+
return;
|
| 545 |
+
}
|
| 546 |
+
|
| 547 |
+
const messageLength = this._messageLength;
|
| 548 |
+
const fragments = this._fragments;
|
| 549 |
+
|
| 550 |
+
this._totalPayloadLength = 0;
|
| 551 |
+
this._messageLength = 0;
|
| 552 |
+
this._fragmented = 0;
|
| 553 |
+
this._fragments = [];
|
| 554 |
+
|
| 555 |
+
if (this._opcode === 2) {
|
| 556 |
+
let data;
|
| 557 |
+
|
| 558 |
+
if (this._binaryType === 'nodebuffer') {
|
| 559 |
+
data = concat(fragments, messageLength);
|
| 560 |
+
} else if (this._binaryType === 'arraybuffer') {
|
| 561 |
+
data = toArrayBuffer(concat(fragments, messageLength));
|
| 562 |
+
} else if (this._binaryType === 'blob') {
|
| 563 |
+
data = new Blob(fragments);
|
| 564 |
+
} else {
|
| 565 |
+
data = fragments;
|
| 566 |
+
}
|
| 567 |
+
|
| 568 |
+
if (this._allowSynchronousEvents) {
|
| 569 |
+
this.emit('message', data, true);
|
| 570 |
+
this._state = GET_INFO;
|
| 571 |
+
} else {
|
| 572 |
+
this._state = DEFER_EVENT;
|
| 573 |
+
setImmediate(() => {
|
| 574 |
+
this.emit('message', data, true);
|
| 575 |
+
this._state = GET_INFO;
|
| 576 |
+
this.startLoop(cb);
|
| 577 |
+
});
|
| 578 |
+
}
|
| 579 |
+
} else {
|
| 580 |
+
const buf = concat(fragments, messageLength);
|
| 581 |
+
|
| 582 |
+
if (!this._skipUTF8Validation && !isValidUTF8(buf)) {
|
| 583 |
+
const error = this.createError(
|
| 584 |
+
Error,
|
| 585 |
+
'invalid UTF-8 sequence',
|
| 586 |
+
true,
|
| 587 |
+
1007,
|
| 588 |
+
'WS_ERR_INVALID_UTF8'
|
| 589 |
+
);
|
| 590 |
+
|
| 591 |
+
cb(error);
|
| 592 |
+
return;
|
| 593 |
+
}
|
| 594 |
+
|
| 595 |
+
if (this._state === INFLATING || this._allowSynchronousEvents) {
|
| 596 |
+
this.emit('message', buf, false);
|
| 597 |
+
this._state = GET_INFO;
|
| 598 |
+
} else {
|
| 599 |
+
this._state = DEFER_EVENT;
|
| 600 |
+
setImmediate(() => {
|
| 601 |
+
this.emit('message', buf, false);
|
| 602 |
+
this._state = GET_INFO;
|
| 603 |
+
this.startLoop(cb);
|
| 604 |
+
});
|
| 605 |
+
}
|
| 606 |
+
}
|
| 607 |
+
}
|
| 608 |
+
|
| 609 |
+
/**
|
| 610 |
+
* Handles a control message.
|
| 611 |
+
*
|
| 612 |
+
* @param {Buffer} data Data to handle
|
| 613 |
+
* @return {(Error|RangeError|undefined)} A possible error
|
| 614 |
+
* @private
|
| 615 |
+
*/
|
| 616 |
+
controlMessage(data, cb) {
|
| 617 |
+
if (this._opcode === 0x08) {
|
| 618 |
+
if (data.length === 0) {
|
| 619 |
+
this._loop = false;
|
| 620 |
+
this.emit('conclude', 1005, EMPTY_BUFFER);
|
| 621 |
+
this.end();
|
| 622 |
+
} else {
|
| 623 |
+
const code = data.readUInt16BE(0);
|
| 624 |
+
|
| 625 |
+
if (!isValidStatusCode(code)) {
|
| 626 |
+
const error = this.createError(
|
| 627 |
+
RangeError,
|
| 628 |
+
`invalid status code ${code}`,
|
| 629 |
+
true,
|
| 630 |
+
1002,
|
| 631 |
+
'WS_ERR_INVALID_CLOSE_CODE'
|
| 632 |
+
);
|
| 633 |
+
|
| 634 |
+
cb(error);
|
| 635 |
+
return;
|
| 636 |
+
}
|
| 637 |
+
|
| 638 |
+
const buf = new FastBuffer(
|
| 639 |
+
data.buffer,
|
| 640 |
+
data.byteOffset + 2,
|
| 641 |
+
data.length - 2
|
| 642 |
+
);
|
| 643 |
+
|
| 644 |
+
if (!this._skipUTF8Validation && !isValidUTF8(buf)) {
|
| 645 |
+
const error = this.createError(
|
| 646 |
+
Error,
|
| 647 |
+
'invalid UTF-8 sequence',
|
| 648 |
+
true,
|
| 649 |
+
1007,
|
| 650 |
+
'WS_ERR_INVALID_UTF8'
|
| 651 |
+
);
|
| 652 |
+
|
| 653 |
+
cb(error);
|
| 654 |
+
return;
|
| 655 |
+
}
|
| 656 |
+
|
| 657 |
+
this._loop = false;
|
| 658 |
+
this.emit('conclude', code, buf);
|
| 659 |
+
this.end();
|
| 660 |
+
}
|
| 661 |
+
|
| 662 |
+
this._state = GET_INFO;
|
| 663 |
+
return;
|
| 664 |
+
}
|
| 665 |
+
|
| 666 |
+
if (this._allowSynchronousEvents) {
|
| 667 |
+
this.emit(this._opcode === 0x09 ? 'ping' : 'pong', data);
|
| 668 |
+
this._state = GET_INFO;
|
| 669 |
+
} else {
|
| 670 |
+
this._state = DEFER_EVENT;
|
| 671 |
+
setImmediate(() => {
|
| 672 |
+
this.emit(this._opcode === 0x09 ? 'ping' : 'pong', data);
|
| 673 |
+
this._state = GET_INFO;
|
| 674 |
+
this.startLoop(cb);
|
| 675 |
+
});
|
| 676 |
+
}
|
| 677 |
+
}
|
| 678 |
+
|
| 679 |
+
/**
|
| 680 |
+
* Builds an error object.
|
| 681 |
+
*
|
| 682 |
+
* @param {function(new:Error|RangeError)} ErrorCtor The error constructor
|
| 683 |
+
* @param {String} message The error message
|
| 684 |
+
* @param {Boolean} prefix Specifies whether or not to add a default prefix to
|
| 685 |
+
* `message`
|
| 686 |
+
* @param {Number} statusCode The status code
|
| 687 |
+
* @param {String} errorCode The exposed error code
|
| 688 |
+
* @return {(Error|RangeError)} The error
|
| 689 |
+
* @private
|
| 690 |
+
*/
|
| 691 |
+
createError(ErrorCtor, message, prefix, statusCode, errorCode) {
|
| 692 |
+
this._loop = false;
|
| 693 |
+
this._errored = true;
|
| 694 |
+
|
| 695 |
+
const err = new ErrorCtor(
|
| 696 |
+
prefix ? `Invalid WebSocket frame: ${message}` : message
|
| 697 |
+
);
|
| 698 |
+
|
| 699 |
+
Error.captureStackTrace(err, this.createError);
|
| 700 |
+
err.code = errorCode;
|
| 701 |
+
err[kStatusCode] = statusCode;
|
| 702 |
+
return err;
|
| 703 |
+
}
|
| 704 |
+
}
|
| 705 |
+
|
| 706 |
+
module.exports = Receiver;
|
platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/ws/lib/sender.js
ADDED
|
@@ -0,0 +1,602 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* eslint no-unused-vars: ["error", { "varsIgnorePattern": "^Duplex" }] */
|
| 2 |
+
|
| 3 |
+
'use strict';
|
| 4 |
+
|
| 5 |
+
const { Duplex } = require('stream');
|
| 6 |
+
const { randomFillSync } = require('crypto');
|
| 7 |
+
|
| 8 |
+
const PerMessageDeflate = require('./permessage-deflate');
|
| 9 |
+
const { EMPTY_BUFFER, kWebSocket, NOOP } = require('./constants');
|
| 10 |
+
const { isBlob, isValidStatusCode } = require('./validation');
|
| 11 |
+
const { mask: applyMask, toBuffer } = require('./buffer-util');
|
| 12 |
+
|
| 13 |
+
const kByteLength = Symbol('kByteLength');
|
| 14 |
+
const maskBuffer = Buffer.alloc(4);
|
| 15 |
+
const RANDOM_POOL_SIZE = 8 * 1024;
|
| 16 |
+
let randomPool;
|
| 17 |
+
let randomPoolPointer = RANDOM_POOL_SIZE;
|
| 18 |
+
|
| 19 |
+
const DEFAULT = 0;
|
| 20 |
+
const DEFLATING = 1;
|
| 21 |
+
const GET_BLOB_DATA = 2;
|
| 22 |
+
|
| 23 |
+
/**
|
| 24 |
+
* HyBi Sender implementation.
|
| 25 |
+
*/
|
| 26 |
+
class Sender {
|
| 27 |
+
/**
|
| 28 |
+
* Creates a Sender instance.
|
| 29 |
+
*
|
| 30 |
+
* @param {Duplex} socket The connection socket
|
| 31 |
+
* @param {Object} [extensions] An object containing the negotiated extensions
|
| 32 |
+
* @param {Function} [generateMask] The function used to generate the masking
|
| 33 |
+
* key
|
| 34 |
+
*/
|
| 35 |
+
constructor(socket, extensions, generateMask) {
|
| 36 |
+
this._extensions = extensions || {};
|
| 37 |
+
|
| 38 |
+
if (generateMask) {
|
| 39 |
+
this._generateMask = generateMask;
|
| 40 |
+
this._maskBuffer = Buffer.alloc(4);
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
this._socket = socket;
|
| 44 |
+
|
| 45 |
+
this._firstFragment = true;
|
| 46 |
+
this._compress = false;
|
| 47 |
+
|
| 48 |
+
this._bufferedBytes = 0;
|
| 49 |
+
this._queue = [];
|
| 50 |
+
this._state = DEFAULT;
|
| 51 |
+
this.onerror = NOOP;
|
| 52 |
+
this[kWebSocket] = undefined;
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
/**
|
| 56 |
+
* Frames a piece of data according to the HyBi WebSocket protocol.
|
| 57 |
+
*
|
| 58 |
+
* @param {(Buffer|String)} data The data to frame
|
| 59 |
+
* @param {Object} options Options object
|
| 60 |
+
* @param {Boolean} [options.fin=false] Specifies whether or not to set the
|
| 61 |
+
* FIN bit
|
| 62 |
+
* @param {Function} [options.generateMask] The function used to generate the
|
| 63 |
+
* masking key
|
| 64 |
+
* @param {Boolean} [options.mask=false] Specifies whether or not to mask
|
| 65 |
+
* `data`
|
| 66 |
+
* @param {Buffer} [options.maskBuffer] The buffer used to store the masking
|
| 67 |
+
* key
|
| 68 |
+
* @param {Number} options.opcode The opcode
|
| 69 |
+
* @param {Boolean} [options.readOnly=false] Specifies whether `data` can be
|
| 70 |
+
* modified
|
| 71 |
+
* @param {Boolean} [options.rsv1=false] Specifies whether or not to set the
|
| 72 |
+
* RSV1 bit
|
| 73 |
+
* @return {(Buffer|String)[]} The framed data
|
| 74 |
+
* @public
|
| 75 |
+
*/
|
| 76 |
+
static frame(data, options) {
|
| 77 |
+
let mask;
|
| 78 |
+
let merge = false;
|
| 79 |
+
let offset = 2;
|
| 80 |
+
let skipMasking = false;
|
| 81 |
+
|
| 82 |
+
if (options.mask) {
|
| 83 |
+
mask = options.maskBuffer || maskBuffer;
|
| 84 |
+
|
| 85 |
+
if (options.generateMask) {
|
| 86 |
+
options.generateMask(mask);
|
| 87 |
+
} else {
|
| 88 |
+
if (randomPoolPointer === RANDOM_POOL_SIZE) {
|
| 89 |
+
/* istanbul ignore else */
|
| 90 |
+
if (randomPool === undefined) {
|
| 91 |
+
//
|
| 92 |
+
// This is lazily initialized because server-sent frames must not
|
| 93 |
+
// be masked so it may never be used.
|
| 94 |
+
//
|
| 95 |
+
randomPool = Buffer.alloc(RANDOM_POOL_SIZE);
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
randomFillSync(randomPool, 0, RANDOM_POOL_SIZE);
|
| 99 |
+
randomPoolPointer = 0;
|
| 100 |
+
}
|
| 101 |
+
|
| 102 |
+
mask[0] = randomPool[randomPoolPointer++];
|
| 103 |
+
mask[1] = randomPool[randomPoolPointer++];
|
| 104 |
+
mask[2] = randomPool[randomPoolPointer++];
|
| 105 |
+
mask[3] = randomPool[randomPoolPointer++];
|
| 106 |
+
}
|
| 107 |
+
|
| 108 |
+
skipMasking = (mask[0] | mask[1] | mask[2] | mask[3]) === 0;
|
| 109 |
+
offset = 6;
|
| 110 |
+
}
|
| 111 |
+
|
| 112 |
+
let dataLength;
|
| 113 |
+
|
| 114 |
+
if (typeof data === 'string') {
|
| 115 |
+
if (
|
| 116 |
+
(!options.mask || skipMasking) &&
|
| 117 |
+
options[kByteLength] !== undefined
|
| 118 |
+
) {
|
| 119 |
+
dataLength = options[kByteLength];
|
| 120 |
+
} else {
|
| 121 |
+
data = Buffer.from(data);
|
| 122 |
+
dataLength = data.length;
|
| 123 |
+
}
|
| 124 |
+
} else {
|
| 125 |
+
dataLength = data.length;
|
| 126 |
+
merge = options.mask && options.readOnly && !skipMasking;
|
| 127 |
+
}
|
| 128 |
+
|
| 129 |
+
let payloadLength = dataLength;
|
| 130 |
+
|
| 131 |
+
if (dataLength >= 65536) {
|
| 132 |
+
offset += 8;
|
| 133 |
+
payloadLength = 127;
|
| 134 |
+
} else if (dataLength > 125) {
|
| 135 |
+
offset += 2;
|
| 136 |
+
payloadLength = 126;
|
| 137 |
+
}
|
| 138 |
+
|
| 139 |
+
const target = Buffer.allocUnsafe(merge ? dataLength + offset : offset);
|
| 140 |
+
|
| 141 |
+
target[0] = options.fin ? options.opcode | 0x80 : options.opcode;
|
| 142 |
+
if (options.rsv1) target[0] |= 0x40;
|
| 143 |
+
|
| 144 |
+
target[1] = payloadLength;
|
| 145 |
+
|
| 146 |
+
if (payloadLength === 126) {
|
| 147 |
+
target.writeUInt16BE(dataLength, 2);
|
| 148 |
+
} else if (payloadLength === 127) {
|
| 149 |
+
target[2] = target[3] = 0;
|
| 150 |
+
target.writeUIntBE(dataLength, 4, 6);
|
| 151 |
+
}
|
| 152 |
+
|
| 153 |
+
if (!options.mask) return [target, data];
|
| 154 |
+
|
| 155 |
+
target[1] |= 0x80;
|
| 156 |
+
target[offset - 4] = mask[0];
|
| 157 |
+
target[offset - 3] = mask[1];
|
| 158 |
+
target[offset - 2] = mask[2];
|
| 159 |
+
target[offset - 1] = mask[3];
|
| 160 |
+
|
| 161 |
+
if (skipMasking) return [target, data];
|
| 162 |
+
|
| 163 |
+
if (merge) {
|
| 164 |
+
applyMask(data, mask, target, offset, dataLength);
|
| 165 |
+
return [target];
|
| 166 |
+
}
|
| 167 |
+
|
| 168 |
+
applyMask(data, mask, data, 0, dataLength);
|
| 169 |
+
return [target, data];
|
| 170 |
+
}
|
| 171 |
+
|
| 172 |
+
/**
|
| 173 |
+
* Sends a close message to the other peer.
|
| 174 |
+
*
|
| 175 |
+
* @param {Number} [code] The status code component of the body
|
| 176 |
+
* @param {(String|Buffer)} [data] The message component of the body
|
| 177 |
+
* @param {Boolean} [mask=false] Specifies whether or not to mask the message
|
| 178 |
+
* @param {Function} [cb] Callback
|
| 179 |
+
* @public
|
| 180 |
+
*/
|
| 181 |
+
close(code, data, mask, cb) {
|
| 182 |
+
let buf;
|
| 183 |
+
|
| 184 |
+
if (code === undefined) {
|
| 185 |
+
buf = EMPTY_BUFFER;
|
| 186 |
+
} else if (typeof code !== 'number' || !isValidStatusCode(code)) {
|
| 187 |
+
throw new TypeError('First argument must be a valid error code number');
|
| 188 |
+
} else if (data === undefined || !data.length) {
|
| 189 |
+
buf = Buffer.allocUnsafe(2);
|
| 190 |
+
buf.writeUInt16BE(code, 0);
|
| 191 |
+
} else {
|
| 192 |
+
const length = Buffer.byteLength(data);
|
| 193 |
+
|
| 194 |
+
if (length > 123) {
|
| 195 |
+
throw new RangeError('The message must not be greater than 123 bytes');
|
| 196 |
+
}
|
| 197 |
+
|
| 198 |
+
buf = Buffer.allocUnsafe(2 + length);
|
| 199 |
+
buf.writeUInt16BE(code, 0);
|
| 200 |
+
|
| 201 |
+
if (typeof data === 'string') {
|
| 202 |
+
buf.write(data, 2);
|
| 203 |
+
} else {
|
| 204 |
+
buf.set(data, 2);
|
| 205 |
+
}
|
| 206 |
+
}
|
| 207 |
+
|
| 208 |
+
const options = {
|
| 209 |
+
[kByteLength]: buf.length,
|
| 210 |
+
fin: true,
|
| 211 |
+
generateMask: this._generateMask,
|
| 212 |
+
mask,
|
| 213 |
+
maskBuffer: this._maskBuffer,
|
| 214 |
+
opcode: 0x08,
|
| 215 |
+
readOnly: false,
|
| 216 |
+
rsv1: false
|
| 217 |
+
};
|
| 218 |
+
|
| 219 |
+
if (this._state !== DEFAULT) {
|
| 220 |
+
this.enqueue([this.dispatch, buf, false, options, cb]);
|
| 221 |
+
} else {
|
| 222 |
+
this.sendFrame(Sender.frame(buf, options), cb);
|
| 223 |
+
}
|
| 224 |
+
}
|
| 225 |
+
|
| 226 |
+
/**
|
| 227 |
+
* Sends a ping message to the other peer.
|
| 228 |
+
*
|
| 229 |
+
* @param {*} data The message to send
|
| 230 |
+
* @param {Boolean} [mask=false] Specifies whether or not to mask `data`
|
| 231 |
+
* @param {Function} [cb] Callback
|
| 232 |
+
* @public
|
| 233 |
+
*/
|
| 234 |
+
ping(data, mask, cb) {
|
| 235 |
+
let byteLength;
|
| 236 |
+
let readOnly;
|
| 237 |
+
|
| 238 |
+
if (typeof data === 'string') {
|
| 239 |
+
byteLength = Buffer.byteLength(data);
|
| 240 |
+
readOnly = false;
|
| 241 |
+
} else if (isBlob(data)) {
|
| 242 |
+
byteLength = data.size;
|
| 243 |
+
readOnly = false;
|
| 244 |
+
} else {
|
| 245 |
+
data = toBuffer(data);
|
| 246 |
+
byteLength = data.length;
|
| 247 |
+
readOnly = toBuffer.readOnly;
|
| 248 |
+
}
|
| 249 |
+
|
| 250 |
+
if (byteLength > 125) {
|
| 251 |
+
throw new RangeError('The data size must not be greater than 125 bytes');
|
| 252 |
+
}
|
| 253 |
+
|
| 254 |
+
const options = {
|
| 255 |
+
[kByteLength]: byteLength,
|
| 256 |
+
fin: true,
|
| 257 |
+
generateMask: this._generateMask,
|
| 258 |
+
mask,
|
| 259 |
+
maskBuffer: this._maskBuffer,
|
| 260 |
+
opcode: 0x09,
|
| 261 |
+
readOnly,
|
| 262 |
+
rsv1: false
|
| 263 |
+
};
|
| 264 |
+
|
| 265 |
+
if (isBlob(data)) {
|
| 266 |
+
if (this._state !== DEFAULT) {
|
| 267 |
+
this.enqueue([this.getBlobData, data, false, options, cb]);
|
| 268 |
+
} else {
|
| 269 |
+
this.getBlobData(data, false, options, cb);
|
| 270 |
+
}
|
| 271 |
+
} else if (this._state !== DEFAULT) {
|
| 272 |
+
this.enqueue([this.dispatch, data, false, options, cb]);
|
| 273 |
+
} else {
|
| 274 |
+
this.sendFrame(Sender.frame(data, options), cb);
|
| 275 |
+
}
|
| 276 |
+
}
|
| 277 |
+
|
| 278 |
+
/**
|
| 279 |
+
* Sends a pong message to the other peer.
|
| 280 |
+
*
|
| 281 |
+
* @param {*} data The message to send
|
| 282 |
+
* @param {Boolean} [mask=false] Specifies whether or not to mask `data`
|
| 283 |
+
* @param {Function} [cb] Callback
|
| 284 |
+
* @public
|
| 285 |
+
*/
|
| 286 |
+
pong(data, mask, cb) {
|
| 287 |
+
let byteLength;
|
| 288 |
+
let readOnly;
|
| 289 |
+
|
| 290 |
+
if (typeof data === 'string') {
|
| 291 |
+
byteLength = Buffer.byteLength(data);
|
| 292 |
+
readOnly = false;
|
| 293 |
+
} else if (isBlob(data)) {
|
| 294 |
+
byteLength = data.size;
|
| 295 |
+
readOnly = false;
|
| 296 |
+
} else {
|
| 297 |
+
data = toBuffer(data);
|
| 298 |
+
byteLength = data.length;
|
| 299 |
+
readOnly = toBuffer.readOnly;
|
| 300 |
+
}
|
| 301 |
+
|
| 302 |
+
if (byteLength > 125) {
|
| 303 |
+
throw new RangeError('The data size must not be greater than 125 bytes');
|
| 304 |
+
}
|
| 305 |
+
|
| 306 |
+
const options = {
|
| 307 |
+
[kByteLength]: byteLength,
|
| 308 |
+
fin: true,
|
| 309 |
+
generateMask: this._generateMask,
|
| 310 |
+
mask,
|
| 311 |
+
maskBuffer: this._maskBuffer,
|
| 312 |
+
opcode: 0x0a,
|
| 313 |
+
readOnly,
|
| 314 |
+
rsv1: false
|
| 315 |
+
};
|
| 316 |
+
|
| 317 |
+
if (isBlob(data)) {
|
| 318 |
+
if (this._state !== DEFAULT) {
|
| 319 |
+
this.enqueue([this.getBlobData, data, false, options, cb]);
|
| 320 |
+
} else {
|
| 321 |
+
this.getBlobData(data, false, options, cb);
|
| 322 |
+
}
|
| 323 |
+
} else if (this._state !== DEFAULT) {
|
| 324 |
+
this.enqueue([this.dispatch, data, false, options, cb]);
|
| 325 |
+
} else {
|
| 326 |
+
this.sendFrame(Sender.frame(data, options), cb);
|
| 327 |
+
}
|
| 328 |
+
}
|
| 329 |
+
|
| 330 |
+
/**
|
| 331 |
+
* Sends a data message to the other peer.
|
| 332 |
+
*
|
| 333 |
+
* @param {*} data The message to send
|
| 334 |
+
* @param {Object} options Options object
|
| 335 |
+
* @param {Boolean} [options.binary=false] Specifies whether `data` is binary
|
| 336 |
+
* or text
|
| 337 |
+
* @param {Boolean} [options.compress=false] Specifies whether or not to
|
| 338 |
+
* compress `data`
|
| 339 |
+
* @param {Boolean} [options.fin=false] Specifies whether the fragment is the
|
| 340 |
+
* last one
|
| 341 |
+
* @param {Boolean} [options.mask=false] Specifies whether or not to mask
|
| 342 |
+
* `data`
|
| 343 |
+
* @param {Function} [cb] Callback
|
| 344 |
+
* @public
|
| 345 |
+
*/
|
| 346 |
+
send(data, options, cb) {
|
| 347 |
+
const perMessageDeflate = this._extensions[PerMessageDeflate.extensionName];
|
| 348 |
+
let opcode = options.binary ? 2 : 1;
|
| 349 |
+
let rsv1 = options.compress;
|
| 350 |
+
|
| 351 |
+
let byteLength;
|
| 352 |
+
let readOnly;
|
| 353 |
+
|
| 354 |
+
if (typeof data === 'string') {
|
| 355 |
+
byteLength = Buffer.byteLength(data);
|
| 356 |
+
readOnly = false;
|
| 357 |
+
} else if (isBlob(data)) {
|
| 358 |
+
byteLength = data.size;
|
| 359 |
+
readOnly = false;
|
| 360 |
+
} else {
|
| 361 |
+
data = toBuffer(data);
|
| 362 |
+
byteLength = data.length;
|
| 363 |
+
readOnly = toBuffer.readOnly;
|
| 364 |
+
}
|
| 365 |
+
|
| 366 |
+
if (this._firstFragment) {
|
| 367 |
+
this._firstFragment = false;
|
| 368 |
+
if (
|
| 369 |
+
rsv1 &&
|
| 370 |
+
perMessageDeflate &&
|
| 371 |
+
perMessageDeflate.params[
|
| 372 |
+
perMessageDeflate._isServer
|
| 373 |
+
? 'server_no_context_takeover'
|
| 374 |
+
: 'client_no_context_takeover'
|
| 375 |
+
]
|
| 376 |
+
) {
|
| 377 |
+
rsv1 = byteLength >= perMessageDeflate._threshold;
|
| 378 |
+
}
|
| 379 |
+
this._compress = rsv1;
|
| 380 |
+
} else {
|
| 381 |
+
rsv1 = false;
|
| 382 |
+
opcode = 0;
|
| 383 |
+
}
|
| 384 |
+
|
| 385 |
+
if (options.fin) this._firstFragment = true;
|
| 386 |
+
|
| 387 |
+
const opts = {
|
| 388 |
+
[kByteLength]: byteLength,
|
| 389 |
+
fin: options.fin,
|
| 390 |
+
generateMask: this._generateMask,
|
| 391 |
+
mask: options.mask,
|
| 392 |
+
maskBuffer: this._maskBuffer,
|
| 393 |
+
opcode,
|
| 394 |
+
readOnly,
|
| 395 |
+
rsv1
|
| 396 |
+
};
|
| 397 |
+
|
| 398 |
+
if (isBlob(data)) {
|
| 399 |
+
if (this._state !== DEFAULT) {
|
| 400 |
+
this.enqueue([this.getBlobData, data, this._compress, opts, cb]);
|
| 401 |
+
} else {
|
| 402 |
+
this.getBlobData(data, this._compress, opts, cb);
|
| 403 |
+
}
|
| 404 |
+
} else if (this._state !== DEFAULT) {
|
| 405 |
+
this.enqueue([this.dispatch, data, this._compress, opts, cb]);
|
| 406 |
+
} else {
|
| 407 |
+
this.dispatch(data, this._compress, opts, cb);
|
| 408 |
+
}
|
| 409 |
+
}
|
| 410 |
+
|
| 411 |
+
/**
|
| 412 |
+
* Gets the contents of a blob as binary data.
|
| 413 |
+
*
|
| 414 |
+
* @param {Blob} blob The blob
|
| 415 |
+
* @param {Boolean} [compress=false] Specifies whether or not to compress
|
| 416 |
+
* the data
|
| 417 |
+
* @param {Object} options Options object
|
| 418 |
+
* @param {Boolean} [options.fin=false] Specifies whether or not to set the
|
| 419 |
+
* FIN bit
|
| 420 |
+
* @param {Function} [options.generateMask] The function used to generate the
|
| 421 |
+
* masking key
|
| 422 |
+
* @param {Boolean} [options.mask=false] Specifies whether or not to mask
|
| 423 |
+
* `data`
|
| 424 |
+
* @param {Buffer} [options.maskBuffer] The buffer used to store the masking
|
| 425 |
+
* key
|
| 426 |
+
* @param {Number} options.opcode The opcode
|
| 427 |
+
* @param {Boolean} [options.readOnly=false] Specifies whether `data` can be
|
| 428 |
+
* modified
|
| 429 |
+
* @param {Boolean} [options.rsv1=false] Specifies whether or not to set the
|
| 430 |
+
* RSV1 bit
|
| 431 |
+
* @param {Function} [cb] Callback
|
| 432 |
+
* @private
|
| 433 |
+
*/
|
| 434 |
+
getBlobData(blob, compress, options, cb) {
|
| 435 |
+
this._bufferedBytes += options[kByteLength];
|
| 436 |
+
this._state = GET_BLOB_DATA;
|
| 437 |
+
|
| 438 |
+
blob
|
| 439 |
+
.arrayBuffer()
|
| 440 |
+
.then((arrayBuffer) => {
|
| 441 |
+
if (this._socket.destroyed) {
|
| 442 |
+
const err = new Error(
|
| 443 |
+
'The socket was closed while the blob was being read'
|
| 444 |
+
);
|
| 445 |
+
|
| 446 |
+
//
|
| 447 |
+
// `callCallbacks` is called in the next tick to ensure that errors
|
| 448 |
+
// that might be thrown in the callbacks behave like errors thrown
|
| 449 |
+
// outside the promise chain.
|
| 450 |
+
//
|
| 451 |
+
process.nextTick(callCallbacks, this, err, cb);
|
| 452 |
+
return;
|
| 453 |
+
}
|
| 454 |
+
|
| 455 |
+
this._bufferedBytes -= options[kByteLength];
|
| 456 |
+
const data = toBuffer(arrayBuffer);
|
| 457 |
+
|
| 458 |
+
if (!compress) {
|
| 459 |
+
this._state = DEFAULT;
|
| 460 |
+
this.sendFrame(Sender.frame(data, options), cb);
|
| 461 |
+
this.dequeue();
|
| 462 |
+
} else {
|
| 463 |
+
this.dispatch(data, compress, options, cb);
|
| 464 |
+
}
|
| 465 |
+
})
|
| 466 |
+
.catch((err) => {
|
| 467 |
+
//
|
| 468 |
+
// `onError` is called in the next tick for the same reason that
|
| 469 |
+
// `callCallbacks` above is.
|
| 470 |
+
//
|
| 471 |
+
process.nextTick(onError, this, err, cb);
|
| 472 |
+
});
|
| 473 |
+
}
|
| 474 |
+
|
| 475 |
+
/**
|
| 476 |
+
* Dispatches a message.
|
| 477 |
+
*
|
| 478 |
+
* @param {(Buffer|String)} data The message to send
|
| 479 |
+
* @param {Boolean} [compress=false] Specifies whether or not to compress
|
| 480 |
+
* `data`
|
| 481 |
+
* @param {Object} options Options object
|
| 482 |
+
* @param {Boolean} [options.fin=false] Specifies whether or not to set the
|
| 483 |
+
* FIN bit
|
| 484 |
+
* @param {Function} [options.generateMask] The function used to generate the
|
| 485 |
+
* masking key
|
| 486 |
+
* @param {Boolean} [options.mask=false] Specifies whether or not to mask
|
| 487 |
+
* `data`
|
| 488 |
+
* @param {Buffer} [options.maskBuffer] The buffer used to store the masking
|
| 489 |
+
* key
|
| 490 |
+
* @param {Number} options.opcode The opcode
|
| 491 |
+
* @param {Boolean} [options.readOnly=false] Specifies whether `data` can be
|
| 492 |
+
* modified
|
| 493 |
+
* @param {Boolean} [options.rsv1=false] Specifies whether or not to set the
|
| 494 |
+
* RSV1 bit
|
| 495 |
+
* @param {Function} [cb] Callback
|
| 496 |
+
* @private
|
| 497 |
+
*/
|
| 498 |
+
dispatch(data, compress, options, cb) {
|
| 499 |
+
if (!compress) {
|
| 500 |
+
this.sendFrame(Sender.frame(data, options), cb);
|
| 501 |
+
return;
|
| 502 |
+
}
|
| 503 |
+
|
| 504 |
+
const perMessageDeflate = this._extensions[PerMessageDeflate.extensionName];
|
| 505 |
+
|
| 506 |
+
this._bufferedBytes += options[kByteLength];
|
| 507 |
+
this._state = DEFLATING;
|
| 508 |
+
perMessageDeflate.compress(data, options.fin, (_, buf) => {
|
| 509 |
+
if (this._socket.destroyed) {
|
| 510 |
+
const err = new Error(
|
| 511 |
+
'The socket was closed while data was being compressed'
|
| 512 |
+
);
|
| 513 |
+
|
| 514 |
+
callCallbacks(this, err, cb);
|
| 515 |
+
return;
|
| 516 |
+
}
|
| 517 |
+
|
| 518 |
+
this._bufferedBytes -= options[kByteLength];
|
| 519 |
+
this._state = DEFAULT;
|
| 520 |
+
options.readOnly = false;
|
| 521 |
+
this.sendFrame(Sender.frame(buf, options), cb);
|
| 522 |
+
this.dequeue();
|
| 523 |
+
});
|
| 524 |
+
}
|
| 525 |
+
|
| 526 |
+
/**
|
| 527 |
+
* Executes queued send operations.
|
| 528 |
+
*
|
| 529 |
+
* @private
|
| 530 |
+
*/
|
| 531 |
+
dequeue() {
|
| 532 |
+
while (this._state === DEFAULT && this._queue.length) {
|
| 533 |
+
const params = this._queue.shift();
|
| 534 |
+
|
| 535 |
+
this._bufferedBytes -= params[3][kByteLength];
|
| 536 |
+
Reflect.apply(params[0], this, params.slice(1));
|
| 537 |
+
}
|
| 538 |
+
}
|
| 539 |
+
|
| 540 |
+
/**
|
| 541 |
+
* Enqueues a send operation.
|
| 542 |
+
*
|
| 543 |
+
* @param {Array} params Send operation parameters.
|
| 544 |
+
* @private
|
| 545 |
+
*/
|
| 546 |
+
enqueue(params) {
|
| 547 |
+
this._bufferedBytes += params[3][kByteLength];
|
| 548 |
+
this._queue.push(params);
|
| 549 |
+
}
|
| 550 |
+
|
| 551 |
+
/**
|
| 552 |
+
* Sends a frame.
|
| 553 |
+
*
|
| 554 |
+
* @param {(Buffer | String)[]} list The frame to send
|
| 555 |
+
* @param {Function} [cb] Callback
|
| 556 |
+
* @private
|
| 557 |
+
*/
|
| 558 |
+
sendFrame(list, cb) {
|
| 559 |
+
if (list.length === 2) {
|
| 560 |
+
this._socket.cork();
|
| 561 |
+
this._socket.write(list[0]);
|
| 562 |
+
this._socket.write(list[1], cb);
|
| 563 |
+
this._socket.uncork();
|
| 564 |
+
} else {
|
| 565 |
+
this._socket.write(list[0], cb);
|
| 566 |
+
}
|
| 567 |
+
}
|
| 568 |
+
}
|
| 569 |
+
|
| 570 |
+
module.exports = Sender;
|
| 571 |
+
|
| 572 |
+
/**
|
| 573 |
+
* Calls queued callbacks with an error.
|
| 574 |
+
*
|
| 575 |
+
* @param {Sender} sender The `Sender` instance
|
| 576 |
+
* @param {Error} err The error to call the callbacks with
|
| 577 |
+
* @param {Function} [cb] The first callback
|
| 578 |
+
* @private
|
| 579 |
+
*/
|
| 580 |
+
function callCallbacks(sender, err, cb) {
|
| 581 |
+
if (typeof cb === 'function') cb(err);
|
| 582 |
+
|
| 583 |
+
for (let i = 0; i < sender._queue.length; i++) {
|
| 584 |
+
const params = sender._queue[i];
|
| 585 |
+
const callback = params[params.length - 1];
|
| 586 |
+
|
| 587 |
+
if (typeof callback === 'function') callback(err);
|
| 588 |
+
}
|
| 589 |
+
}
|
| 590 |
+
|
| 591 |
+
/**
|
| 592 |
+
* Handles a `Sender` error.
|
| 593 |
+
*
|
| 594 |
+
* @param {Sender} sender The `Sender` instance
|
| 595 |
+
* @param {Error} err The error
|
| 596 |
+
* @param {Function} [cb] The first pending callback
|
| 597 |
+
* @private
|
| 598 |
+
*/
|
| 599 |
+
function onError(sender, err, cb) {
|
| 600 |
+
callCallbacks(sender, err, cb);
|
| 601 |
+
sender.onerror(err);
|
| 602 |
+
}
|
platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/ws/lib/stream.js
ADDED
|
@@ -0,0 +1,161 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* eslint no-unused-vars: ["error", { "varsIgnorePattern": "^WebSocket$" }] */
|
| 2 |
+
'use strict';
|
| 3 |
+
|
| 4 |
+
const WebSocket = require('./websocket');
|
| 5 |
+
const { Duplex } = require('stream');
|
| 6 |
+
|
| 7 |
+
/**
|
| 8 |
+
* Emits the `'close'` event on a stream.
|
| 9 |
+
*
|
| 10 |
+
* @param {Duplex} stream The stream.
|
| 11 |
+
* @private
|
| 12 |
+
*/
|
| 13 |
+
function emitClose(stream) {
|
| 14 |
+
stream.emit('close');
|
| 15 |
+
}
|
| 16 |
+
|
| 17 |
+
/**
|
| 18 |
+
* The listener of the `'end'` event.
|
| 19 |
+
*
|
| 20 |
+
* @private
|
| 21 |
+
*/
|
| 22 |
+
function duplexOnEnd() {
|
| 23 |
+
if (!this.destroyed && this._writableState.finished) {
|
| 24 |
+
this.destroy();
|
| 25 |
+
}
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
/**
|
| 29 |
+
* The listener of the `'error'` event.
|
| 30 |
+
*
|
| 31 |
+
* @param {Error} err The error
|
| 32 |
+
* @private
|
| 33 |
+
*/
|
| 34 |
+
function duplexOnError(err) {
|
| 35 |
+
this.removeListener('error', duplexOnError);
|
| 36 |
+
this.destroy();
|
| 37 |
+
if (this.listenerCount('error') === 0) {
|
| 38 |
+
// Do not suppress the throwing behavior.
|
| 39 |
+
this.emit('error', err);
|
| 40 |
+
}
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
/**
|
| 44 |
+
* Wraps a `WebSocket` in a duplex stream.
|
| 45 |
+
*
|
| 46 |
+
* @param {WebSocket} ws The `WebSocket` to wrap
|
| 47 |
+
* @param {Object} [options] The options for the `Duplex` constructor
|
| 48 |
+
* @return {Duplex} The duplex stream
|
| 49 |
+
* @public
|
| 50 |
+
*/
|
| 51 |
+
function createWebSocketStream(ws, options) {
|
| 52 |
+
let terminateOnDestroy = true;
|
| 53 |
+
|
| 54 |
+
const duplex = new Duplex({
|
| 55 |
+
...options,
|
| 56 |
+
autoDestroy: false,
|
| 57 |
+
emitClose: false,
|
| 58 |
+
objectMode: false,
|
| 59 |
+
writableObjectMode: false
|
| 60 |
+
});
|
| 61 |
+
|
| 62 |
+
ws.on('message', function message(msg, isBinary) {
|
| 63 |
+
const data =
|
| 64 |
+
!isBinary && duplex._readableState.objectMode ? msg.toString() : msg;
|
| 65 |
+
|
| 66 |
+
if (!duplex.push(data)) ws.pause();
|
| 67 |
+
});
|
| 68 |
+
|
| 69 |
+
ws.once('error', function error(err) {
|
| 70 |
+
if (duplex.destroyed) return;
|
| 71 |
+
|
| 72 |
+
// Prevent `ws.terminate()` from being called by `duplex._destroy()`.
|
| 73 |
+
//
|
| 74 |
+
// - If the `'error'` event is emitted before the `'open'` event, then
|
| 75 |
+
// `ws.terminate()` is a noop as no socket is assigned.
|
| 76 |
+
// - Otherwise, the error is re-emitted by the listener of the `'error'`
|
| 77 |
+
// event of the `Receiver` object. The listener already closes the
|
| 78 |
+
// connection by calling `ws.close()`. This allows a close frame to be
|
| 79 |
+
// sent to the other peer. If `ws.terminate()` is called right after this,
|
| 80 |
+
// then the close frame might not be sent.
|
| 81 |
+
terminateOnDestroy = false;
|
| 82 |
+
duplex.destroy(err);
|
| 83 |
+
});
|
| 84 |
+
|
| 85 |
+
ws.once('close', function close() {
|
| 86 |
+
if (duplex.destroyed) return;
|
| 87 |
+
|
| 88 |
+
duplex.push(null);
|
| 89 |
+
});
|
| 90 |
+
|
| 91 |
+
duplex._destroy = function (err, callback) {
|
| 92 |
+
if (ws.readyState === ws.CLOSED) {
|
| 93 |
+
callback(err);
|
| 94 |
+
process.nextTick(emitClose, duplex);
|
| 95 |
+
return;
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
let called = false;
|
| 99 |
+
|
| 100 |
+
ws.once('error', function error(err) {
|
| 101 |
+
called = true;
|
| 102 |
+
callback(err);
|
| 103 |
+
});
|
| 104 |
+
|
| 105 |
+
ws.once('close', function close() {
|
| 106 |
+
if (!called) callback(err);
|
| 107 |
+
process.nextTick(emitClose, duplex);
|
| 108 |
+
});
|
| 109 |
+
|
| 110 |
+
if (terminateOnDestroy) ws.terminate();
|
| 111 |
+
};
|
| 112 |
+
|
| 113 |
+
duplex._final = function (callback) {
|
| 114 |
+
if (ws.readyState === ws.CONNECTING) {
|
| 115 |
+
ws.once('open', function open() {
|
| 116 |
+
duplex._final(callback);
|
| 117 |
+
});
|
| 118 |
+
return;
|
| 119 |
+
}
|
| 120 |
+
|
| 121 |
+
// If the value of the `_socket` property is `null` it means that `ws` is a
|
| 122 |
+
// client websocket and the handshake failed. In fact, when this happens, a
|
| 123 |
+
// socket is never assigned to the websocket. Wait for the `'error'` event
|
| 124 |
+
// that will be emitted by the websocket.
|
| 125 |
+
if (ws._socket === null) return;
|
| 126 |
+
|
| 127 |
+
if (ws._socket._writableState.finished) {
|
| 128 |
+
callback();
|
| 129 |
+
if (duplex._readableState.endEmitted) duplex.destroy();
|
| 130 |
+
} else {
|
| 131 |
+
ws._socket.once('finish', function finish() {
|
| 132 |
+
// `duplex` is not destroyed here because the `'end'` event will be
|
| 133 |
+
// emitted on `duplex` after this `'finish'` event. The EOF signaling
|
| 134 |
+
// `null` chunk is, in fact, pushed when the websocket emits `'close'`.
|
| 135 |
+
callback();
|
| 136 |
+
});
|
| 137 |
+
ws.close();
|
| 138 |
+
}
|
| 139 |
+
};
|
| 140 |
+
|
| 141 |
+
duplex._read = function () {
|
| 142 |
+
if (ws.isPaused) ws.resume();
|
| 143 |
+
};
|
| 144 |
+
|
| 145 |
+
duplex._write = function (chunk, encoding, callback) {
|
| 146 |
+
if (ws.readyState === ws.CONNECTING) {
|
| 147 |
+
ws.once('open', function open() {
|
| 148 |
+
duplex._write(chunk, encoding, callback);
|
| 149 |
+
});
|
| 150 |
+
return;
|
| 151 |
+
}
|
| 152 |
+
|
| 153 |
+
ws.send(chunk, callback);
|
| 154 |
+
};
|
| 155 |
+
|
| 156 |
+
duplex.on('end', duplexOnEnd);
|
| 157 |
+
duplex.on('error', duplexOnError);
|
| 158 |
+
return duplex;
|
| 159 |
+
}
|
| 160 |
+
|
| 161 |
+
module.exports = createWebSocketStream;
|
platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/ws/lib/subprotocol.js
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
'use strict';
|
| 2 |
+
|
| 3 |
+
const { tokenChars } = require('./validation');
|
| 4 |
+
|
| 5 |
+
/**
|
| 6 |
+
* Parses the `Sec-WebSocket-Protocol` header into a set of subprotocol names.
|
| 7 |
+
*
|
| 8 |
+
* @param {String} header The field value of the header
|
| 9 |
+
* @return {Set} The subprotocol names
|
| 10 |
+
* @public
|
| 11 |
+
*/
|
| 12 |
+
function parse(header) {
|
| 13 |
+
const protocols = new Set();
|
| 14 |
+
let start = -1;
|
| 15 |
+
let end = -1;
|
| 16 |
+
let i = 0;
|
| 17 |
+
|
| 18 |
+
for (i; i < header.length; i++) {
|
| 19 |
+
const code = header.charCodeAt(i);
|
| 20 |
+
|
| 21 |
+
if (end === -1 && tokenChars[code] === 1) {
|
| 22 |
+
if (start === -1) start = i;
|
| 23 |
+
} else if (
|
| 24 |
+
i !== 0 &&
|
| 25 |
+
(code === 0x20 /* ' ' */ || code === 0x09) /* '\t' */
|
| 26 |
+
) {
|
| 27 |
+
if (end === -1 && start !== -1) end = i;
|
| 28 |
+
} else if (code === 0x2c /* ',' */) {
|
| 29 |
+
if (start === -1) {
|
| 30 |
+
throw new SyntaxError(`Unexpected character at index ${i}`);
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
+
if (end === -1) end = i;
|
| 34 |
+
|
| 35 |
+
const protocol = header.slice(start, end);
|
| 36 |
+
|
| 37 |
+
if (protocols.has(protocol)) {
|
| 38 |
+
throw new SyntaxError(`The "${protocol}" subprotocol is duplicated`);
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
protocols.add(protocol);
|
| 42 |
+
start = end = -1;
|
| 43 |
+
} else {
|
| 44 |
+
throw new SyntaxError(`Unexpected character at index ${i}`);
|
| 45 |
+
}
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
if (start === -1 || end !== -1) {
|
| 49 |
+
throw new SyntaxError('Unexpected end of input');
|
| 50 |
+
}
|
| 51 |
+
|
| 52 |
+
const protocol = header.slice(start, i);
|
| 53 |
+
|
| 54 |
+
if (protocols.has(protocol)) {
|
| 55 |
+
throw new SyntaxError(`The "${protocol}" subprotocol is duplicated`);
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
protocols.add(protocol);
|
| 59 |
+
return protocols;
|
| 60 |
+
}
|
| 61 |
+
|
| 62 |
+
module.exports = { parse };
|
platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/ws/lib/validation.js
ADDED
|
@@ -0,0 +1,152 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
'use strict';
|
| 2 |
+
|
| 3 |
+
const { isUtf8 } = require('buffer');
|
| 4 |
+
|
| 5 |
+
const { hasBlob } = require('./constants');
|
| 6 |
+
|
| 7 |
+
//
|
| 8 |
+
// Allowed token characters:
|
| 9 |
+
//
|
| 10 |
+
// '!', '#', '$', '%', '&', ''', '*', '+', '-',
|
| 11 |
+
// '.', 0-9, A-Z, '^', '_', '`', a-z, '|', '~'
|
| 12 |
+
//
|
| 13 |
+
// tokenChars[32] === 0 // ' '
|
| 14 |
+
// tokenChars[33] === 1 // '!'
|
| 15 |
+
// tokenChars[34] === 0 // '"'
|
| 16 |
+
// ...
|
| 17 |
+
//
|
| 18 |
+
// prettier-ignore
|
| 19 |
+
const tokenChars = [
|
| 20 |
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 0 - 15
|
| 21 |
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 16 - 31
|
| 22 |
+
0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 1, 1, 0, 1, 1, 0, // 32 - 47
|
| 23 |
+
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, // 48 - 63
|
| 24 |
+
0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 64 - 79
|
| 25 |
+
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, // 80 - 95
|
| 26 |
+
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 96 - 111
|
| 27 |
+
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 0 // 112 - 127
|
| 28 |
+
];
|
| 29 |
+
|
| 30 |
+
/**
|
| 31 |
+
* Checks if a status code is allowed in a close frame.
|
| 32 |
+
*
|
| 33 |
+
* @param {Number} code The status code
|
| 34 |
+
* @return {Boolean} `true` if the status code is valid, else `false`
|
| 35 |
+
* @public
|
| 36 |
+
*/
|
| 37 |
+
function isValidStatusCode(code) {
|
| 38 |
+
return (
|
| 39 |
+
(code >= 1000 &&
|
| 40 |
+
code <= 1014 &&
|
| 41 |
+
code !== 1004 &&
|
| 42 |
+
code !== 1005 &&
|
| 43 |
+
code !== 1006) ||
|
| 44 |
+
(code >= 3000 && code <= 4999)
|
| 45 |
+
);
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
/**
|
| 49 |
+
* Checks if a given buffer contains only correct UTF-8.
|
| 50 |
+
* Ported from https://www.cl.cam.ac.uk/%7Emgk25/ucs/utf8_check.c by
|
| 51 |
+
* Markus Kuhn.
|
| 52 |
+
*
|
| 53 |
+
* @param {Buffer} buf The buffer to check
|
| 54 |
+
* @return {Boolean} `true` if `buf` contains only correct UTF-8, else `false`
|
| 55 |
+
* @public
|
| 56 |
+
*/
|
| 57 |
+
function _isValidUTF8(buf) {
|
| 58 |
+
const len = buf.length;
|
| 59 |
+
let i = 0;
|
| 60 |
+
|
| 61 |
+
while (i < len) {
|
| 62 |
+
if ((buf[i] & 0x80) === 0) {
|
| 63 |
+
// 0xxxxxxx
|
| 64 |
+
i++;
|
| 65 |
+
} else if ((buf[i] & 0xe0) === 0xc0) {
|
| 66 |
+
// 110xxxxx 10xxxxxx
|
| 67 |
+
if (
|
| 68 |
+
i + 1 === len ||
|
| 69 |
+
(buf[i + 1] & 0xc0) !== 0x80 ||
|
| 70 |
+
(buf[i] & 0xfe) === 0xc0 // Overlong
|
| 71 |
+
) {
|
| 72 |
+
return false;
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
i += 2;
|
| 76 |
+
} else if ((buf[i] & 0xf0) === 0xe0) {
|
| 77 |
+
// 1110xxxx 10xxxxxx 10xxxxxx
|
| 78 |
+
if (
|
| 79 |
+
i + 2 >= len ||
|
| 80 |
+
(buf[i + 1] & 0xc0) !== 0x80 ||
|
| 81 |
+
(buf[i + 2] & 0xc0) !== 0x80 ||
|
| 82 |
+
(buf[i] === 0xe0 && (buf[i + 1] & 0xe0) === 0x80) || // Overlong
|
| 83 |
+
(buf[i] === 0xed && (buf[i + 1] & 0xe0) === 0xa0) // Surrogate (U+D800 - U+DFFF)
|
| 84 |
+
) {
|
| 85 |
+
return false;
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
i += 3;
|
| 89 |
+
} else if ((buf[i] & 0xf8) === 0xf0) {
|
| 90 |
+
// 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
|
| 91 |
+
if (
|
| 92 |
+
i + 3 >= len ||
|
| 93 |
+
(buf[i + 1] & 0xc0) !== 0x80 ||
|
| 94 |
+
(buf[i + 2] & 0xc0) !== 0x80 ||
|
| 95 |
+
(buf[i + 3] & 0xc0) !== 0x80 ||
|
| 96 |
+
(buf[i] === 0xf0 && (buf[i + 1] & 0xf0) === 0x80) || // Overlong
|
| 97 |
+
(buf[i] === 0xf4 && buf[i + 1] > 0x8f) ||
|
| 98 |
+
buf[i] > 0xf4 // > U+10FFFF
|
| 99 |
+
) {
|
| 100 |
+
return false;
|
| 101 |
+
}
|
| 102 |
+
|
| 103 |
+
i += 4;
|
| 104 |
+
} else {
|
| 105 |
+
return false;
|
| 106 |
+
}
|
| 107 |
+
}
|
| 108 |
+
|
| 109 |
+
return true;
|
| 110 |
+
}
|
| 111 |
+
|
| 112 |
+
/**
|
| 113 |
+
* Determines whether a value is a `Blob`.
|
| 114 |
+
*
|
| 115 |
+
* @param {*} value The value to be tested
|
| 116 |
+
* @return {Boolean} `true` if `value` is a `Blob`, else `false`
|
| 117 |
+
* @private
|
| 118 |
+
*/
|
| 119 |
+
function isBlob(value) {
|
| 120 |
+
return (
|
| 121 |
+
hasBlob &&
|
| 122 |
+
typeof value === 'object' &&
|
| 123 |
+
typeof value.arrayBuffer === 'function' &&
|
| 124 |
+
typeof value.type === 'string' &&
|
| 125 |
+
typeof value.stream === 'function' &&
|
| 126 |
+
(value[Symbol.toStringTag] === 'Blob' ||
|
| 127 |
+
value[Symbol.toStringTag] === 'File')
|
| 128 |
+
);
|
| 129 |
+
}
|
| 130 |
+
|
| 131 |
+
module.exports = {
|
| 132 |
+
isBlob,
|
| 133 |
+
isValidStatusCode,
|
| 134 |
+
isValidUTF8: _isValidUTF8,
|
| 135 |
+
tokenChars
|
| 136 |
+
};
|
| 137 |
+
|
| 138 |
+
if (isUtf8) {
|
| 139 |
+
module.exports.isValidUTF8 = function (buf) {
|
| 140 |
+
return buf.length < 24 ? _isValidUTF8(buf) : isUtf8(buf);
|
| 141 |
+
};
|
| 142 |
+
} /* istanbul ignore else */ else if (!process.env.WS_NO_UTF_8_VALIDATE) {
|
| 143 |
+
try {
|
| 144 |
+
const isValidUTF8 = require('utf-8-validate');
|
| 145 |
+
|
| 146 |
+
module.exports.isValidUTF8 = function (buf) {
|
| 147 |
+
return buf.length < 32 ? _isValidUTF8(buf) : isValidUTF8(buf);
|
| 148 |
+
};
|
| 149 |
+
} catch (e) {
|
| 150 |
+
// Continue regardless of the error.
|
| 151 |
+
}
|
| 152 |
+
}
|
platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/ws/lib/websocket-server.js
ADDED
|
@@ -0,0 +1,550 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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varsIgnorePattern": "^Duplex$", "caughtErrors": "none" }] */
|
| 2 |
+
|
| 3 |
+
'use strict';
|
| 4 |
+
|
| 5 |
+
const EventEmitter = require('events');
|
| 6 |
+
const http = require('http');
|
| 7 |
+
const { Duplex } = require('stream');
|
| 8 |
+
const { createHash } = require('crypto');
|
| 9 |
+
|
| 10 |
+
const extension = require('./extension');
|
| 11 |
+
const PerMessageDeflate = require('./permessage-deflate');
|
| 12 |
+
const subprotocol = require('./subprotocol');
|
| 13 |
+
const WebSocket = require('./websocket');
|
| 14 |
+
const { GUID, kWebSocket } = require('./constants');
|
| 15 |
+
|
| 16 |
+
const keyRegex = /^[+/0-9A-Za-z]{22}==$/;
|
| 17 |
+
|
| 18 |
+
const RUNNING = 0;
|
| 19 |
+
const CLOSING = 1;
|
| 20 |
+
const CLOSED = 2;
|
| 21 |
+
|
| 22 |
+
/**
|
| 23 |
+
* Class representing a WebSocket server.
|
| 24 |
+
*
|
| 25 |
+
* @extends EventEmitter
|
| 26 |
+
*/
|
| 27 |
+
class WebSocketServer extends EventEmitter {
|
| 28 |
+
/**
|
| 29 |
+
* Create a `WebSocketServer` instance.
|
| 30 |
+
*
|
| 31 |
+
* @param {Object} options Configuration options
|
| 32 |
+
* @param {Boolean} [options.allowSynchronousEvents=true] Specifies whether
|
| 33 |
+
* any of the `'message'`, `'ping'`, and `'pong'` events can be emitted
|
| 34 |
+
* multiple times in the same tick
|
| 35 |
+
* @param {Boolean} [options.autoPong=true] Specifies whether or not to
|
| 36 |
+
* automatically send a pong in response to a ping
|
| 37 |
+
* @param {Number} [options.backlog=511] The maximum length of the queue of
|
| 38 |
+
* pending connections
|
| 39 |
+
* @param {Boolean} [options.clientTracking=true] Specifies whether or not to
|
| 40 |
+
* track clients
|
| 41 |
+
* @param {Function} [options.handleProtocols] A hook to handle protocols
|
| 42 |
+
* @param {String} [options.host] The hostname where to bind the server
|
| 43 |
+
* @param {Number} [options.maxPayload=104857600] The maximum allowed message
|
| 44 |
+
* size
|
| 45 |
+
* @param {Boolean} [options.noServer=false] Enable no server mode
|
| 46 |
+
* @param {String} [options.path] Accept only connections matching this path
|
| 47 |
+
* @param {(Boolean|Object)} [options.perMessageDeflate=false] Enable/disable
|
| 48 |
+
* permessage-deflate
|
| 49 |
+
* @param {Number} [options.port] The port where to bind the server
|
| 50 |
+
* @param {(http.Server|https.Server)} [options.server] A pre-created HTTP/S
|
| 51 |
+
* server to use
|
| 52 |
+
* @param {Boolean} [options.skipUTF8Validation=false] Specifies whether or
|
| 53 |
+
* not to skip UTF-8 validation for text and close messages
|
| 54 |
+
* @param {Function} [options.verifyClient] A hook to reject connections
|
| 55 |
+
* @param {Function} [options.WebSocket=WebSocket] Specifies the `WebSocket`
|
| 56 |
+
* class to use. It must be the `WebSocket` class or class that extends it
|
| 57 |
+
* @param {Function} [callback] A listener for the `listening` event
|
| 58 |
+
*/
|
| 59 |
+
constructor(options, callback) {
|
| 60 |
+
super();
|
| 61 |
+
|
| 62 |
+
options = {
|
| 63 |
+
allowSynchronousEvents: true,
|
| 64 |
+
autoPong: true,
|
| 65 |
+
maxPayload: 100 * 1024 * 1024,
|
| 66 |
+
skipUTF8Validation: false,
|
| 67 |
+
perMessageDeflate: false,
|
| 68 |
+
handleProtocols: null,
|
| 69 |
+
clientTracking: true,
|
| 70 |
+
verifyClient: null,
|
| 71 |
+
noServer: false,
|
| 72 |
+
backlog: null, // use default (511 as implemented in net.js)
|
| 73 |
+
server: null,
|
| 74 |
+
host: null,
|
| 75 |
+
path: null,
|
| 76 |
+
port: null,
|
| 77 |
+
WebSocket,
|
| 78 |
+
...options
|
| 79 |
+
};
|
| 80 |
+
|
| 81 |
+
if (
|
| 82 |
+
(options.port == null && !options.server && !options.noServer) ||
|
| 83 |
+
(options.port != null && (options.server || options.noServer)) ||
|
| 84 |
+
(options.server && options.noServer)
|
| 85 |
+
) {
|
| 86 |
+
throw new TypeError(
|
| 87 |
+
'One and only one of the "port", "server", or "noServer" options ' +
|
| 88 |
+
'must be specified'
|
| 89 |
+
);
|
| 90 |
+
}
|
| 91 |
+
|
| 92 |
+
if (options.port != null) {
|
| 93 |
+
this._server = http.createServer((req, res) => {
|
| 94 |
+
const body = http.STATUS_CODES[426];
|
| 95 |
+
|
| 96 |
+
res.writeHead(426, {
|
| 97 |
+
'Content-Length': body.length,
|
| 98 |
+
'Content-Type': 'text/plain'
|
| 99 |
+
});
|
| 100 |
+
res.end(body);
|
| 101 |
+
});
|
| 102 |
+
this._server.listen(
|
| 103 |
+
options.port,
|
| 104 |
+
options.host,
|
| 105 |
+
options.backlog,
|
| 106 |
+
callback
|
| 107 |
+
);
|
| 108 |
+
} else if (options.server) {
|
| 109 |
+
this._server = options.server;
|
| 110 |
+
}
|
| 111 |
+
|
| 112 |
+
if (this._server) {
|
| 113 |
+
const emitConnection = this.emit.bind(this, 'connection');
|
| 114 |
+
|
| 115 |
+
this._removeListeners = addListeners(this._server, {
|
| 116 |
+
listening: this.emit.bind(this, 'listening'),
|
| 117 |
+
error: this.emit.bind(this, 'error'),
|
| 118 |
+
upgrade: (req, socket, head) => {
|
| 119 |
+
this.handleUpgrade(req, socket, head, emitConnection);
|
| 120 |
+
}
|
| 121 |
+
});
|
| 122 |
+
}
|
| 123 |
+
|
| 124 |
+
if (options.perMessageDeflate === true) options.perMessageDeflate = {};
|
| 125 |
+
if (options.clientTracking) {
|
| 126 |
+
this.clients = new Set();
|
| 127 |
+
this._shouldEmitClose = false;
|
| 128 |
+
}
|
| 129 |
+
|
| 130 |
+
this.options = options;
|
| 131 |
+
this._state = RUNNING;
|
| 132 |
+
}
|
| 133 |
+
|
| 134 |
+
/**
|
| 135 |
+
* Returns the bound address, the address family name, and port of the server
|
| 136 |
+
* as reported by the operating system if listening on an IP socket.
|
| 137 |
+
* If the server is listening on a pipe or UNIX domain socket, the name is
|
| 138 |
+
* returned as a string.
|
| 139 |
+
*
|
| 140 |
+
* @return {(Object|String|null)} The address of the server
|
| 141 |
+
* @public
|
| 142 |
+
*/
|
| 143 |
+
address() {
|
| 144 |
+
if (this.options.noServer) {
|
| 145 |
+
throw new Error('The server is operating in "noServer" mode');
|
| 146 |
+
}
|
| 147 |
+
|
| 148 |
+
if (!this._server) return null;
|
| 149 |
+
return this._server.address();
|
| 150 |
+
}
|
| 151 |
+
|
| 152 |
+
/**
|
| 153 |
+
* Stop the server from accepting new connections and emit the `'close'` event
|
| 154 |
+
* when all existing connections are closed.
|
| 155 |
+
*
|
| 156 |
+
* @param {Function} [cb] A one-time listener for the `'close'` event
|
| 157 |
+
* @public
|
| 158 |
+
*/
|
| 159 |
+
close(cb) {
|
| 160 |
+
if (this._state === CLOSED) {
|
| 161 |
+
if (cb) {
|
| 162 |
+
this.once('close', () => {
|
| 163 |
+
cb(new Error('The server is not running'));
|
| 164 |
+
});
|
| 165 |
+
}
|
| 166 |
+
|
| 167 |
+
process.nextTick(emitClose, this);
|
| 168 |
+
return;
|
| 169 |
+
}
|
| 170 |
+
|
| 171 |
+
if (cb) this.once('close', cb);
|
| 172 |
+
|
| 173 |
+
if (this._state === CLOSING) return;
|
| 174 |
+
this._state = CLOSING;
|
| 175 |
+
|
| 176 |
+
if (this.options.noServer || this.options.server) {
|
| 177 |
+
if (this._server) {
|
| 178 |
+
this._removeListeners();
|
| 179 |
+
this._removeListeners = this._server = null;
|
| 180 |
+
}
|
| 181 |
+
|
| 182 |
+
if (this.clients) {
|
| 183 |
+
if (!this.clients.size) {
|
| 184 |
+
process.nextTick(emitClose, this);
|
| 185 |
+
} else {
|
| 186 |
+
this._shouldEmitClose = true;
|
| 187 |
+
}
|
| 188 |
+
} else {
|
| 189 |
+
process.nextTick(emitClose, this);
|
| 190 |
+
}
|
| 191 |
+
} else {
|
| 192 |
+
const server = this._server;
|
| 193 |
+
|
| 194 |
+
this._removeListeners();
|
| 195 |
+
this._removeListeners = this._server = null;
|
| 196 |
+
|
| 197 |
+
//
|
| 198 |
+
// The HTTP/S server was created internally. Close it, and rely on its
|
| 199 |
+
// `'close'` event.
|
| 200 |
+
//
|
| 201 |
+
server.close(() => {
|
| 202 |
+
emitClose(this);
|
| 203 |
+
});
|
| 204 |
+
}
|
| 205 |
+
}
|
| 206 |
+
|
| 207 |
+
/**
|
| 208 |
+
* See if a given request should be handled by this server instance.
|
| 209 |
+
*
|
| 210 |
+
* @param {http.IncomingMessage} req Request object to inspect
|
| 211 |
+
* @return {Boolean} `true` if the request is valid, else `false`
|
| 212 |
+
* @public
|
| 213 |
+
*/
|
| 214 |
+
shouldHandle(req) {
|
| 215 |
+
if (this.options.path) {
|
| 216 |
+
const index = req.url.indexOf('?');
|
| 217 |
+
const pathname = index !== -1 ? req.url.slice(0, index) : req.url;
|
| 218 |
+
|
| 219 |
+
if (pathname !== this.options.path) return false;
|
| 220 |
+
}
|
| 221 |
+
|
| 222 |
+
return true;
|
| 223 |
+
}
|
| 224 |
+
|
| 225 |
+
/**
|
| 226 |
+
* Handle a HTTP Upgrade request.
|
| 227 |
+
*
|
| 228 |
+
* @param {http.IncomingMessage} req The request object
|
| 229 |
+
* @param {Duplex} socket The network socket between the server and client
|
| 230 |
+
* @param {Buffer} head The first packet of the upgraded stream
|
| 231 |
+
* @param {Function} cb Callback
|
| 232 |
+
* @public
|
| 233 |
+
*/
|
| 234 |
+
handleUpgrade(req, socket, head, cb) {
|
| 235 |
+
socket.on('error', socketOnError);
|
| 236 |
+
|
| 237 |
+
const key = req.headers['sec-websocket-key'];
|
| 238 |
+
const upgrade = req.headers.upgrade;
|
| 239 |
+
const version = +req.headers['sec-websocket-version'];
|
| 240 |
+
|
| 241 |
+
if (req.method !== 'GET') {
|
| 242 |
+
const message = 'Invalid HTTP method';
|
| 243 |
+
abortHandshakeOrEmitwsClientError(this, req, socket, 405, message);
|
| 244 |
+
return;
|
| 245 |
+
}
|
| 246 |
+
|
| 247 |
+
if (upgrade === undefined || upgrade.toLowerCase() !== 'websocket') {
|
| 248 |
+
const message = 'Invalid Upgrade header';
|
| 249 |
+
abortHandshakeOrEmitwsClientError(this, req, socket, 400, message);
|
| 250 |
+
return;
|
| 251 |
+
}
|
| 252 |
+
|
| 253 |
+
if (key === undefined || !keyRegex.test(key)) {
|
| 254 |
+
const message = 'Missing or invalid Sec-WebSocket-Key header';
|
| 255 |
+
abortHandshakeOrEmitwsClientError(this, req, socket, 400, message);
|
| 256 |
+
return;
|
| 257 |
+
}
|
| 258 |
+
|
| 259 |
+
if (version !== 13 && version !== 8) {
|
| 260 |
+
const message = 'Missing or invalid Sec-WebSocket-Version header';
|
| 261 |
+
abortHandshakeOrEmitwsClientError(this, req, socket, 400, message, {
|
| 262 |
+
'Sec-WebSocket-Version': '13, 8'
|
| 263 |
+
});
|
| 264 |
+
return;
|
| 265 |
+
}
|
| 266 |
+
|
| 267 |
+
if (!this.shouldHandle(req)) {
|
| 268 |
+
abortHandshake(socket, 400);
|
| 269 |
+
return;
|
| 270 |
+
}
|
| 271 |
+
|
| 272 |
+
const secWebSocketProtocol = req.headers['sec-websocket-protocol'];
|
| 273 |
+
let protocols = new Set();
|
| 274 |
+
|
| 275 |
+
if (secWebSocketProtocol !== undefined) {
|
| 276 |
+
try {
|
| 277 |
+
protocols = subprotocol.parse(secWebSocketProtocol);
|
| 278 |
+
} catch (err) {
|
| 279 |
+
const message = 'Invalid Sec-WebSocket-Protocol header';
|
| 280 |
+
abortHandshakeOrEmitwsClientError(this, req, socket, 400, message);
|
| 281 |
+
return;
|
| 282 |
+
}
|
| 283 |
+
}
|
| 284 |
+
|
| 285 |
+
const secWebSocketExtensions = req.headers['sec-websocket-extensions'];
|
| 286 |
+
const extensions = {};
|
| 287 |
+
|
| 288 |
+
if (
|
| 289 |
+
this.options.perMessageDeflate &&
|
| 290 |
+
secWebSocketExtensions !== undefined
|
| 291 |
+
) {
|
| 292 |
+
const perMessageDeflate = new PerMessageDeflate(
|
| 293 |
+
this.options.perMessageDeflate,
|
| 294 |
+
true,
|
| 295 |
+
this.options.maxPayload
|
| 296 |
+
);
|
| 297 |
+
|
| 298 |
+
try {
|
| 299 |
+
const offers = extension.parse(secWebSocketExtensions);
|
| 300 |
+
|
| 301 |
+
if (offers[PerMessageDeflate.extensionName]) {
|
| 302 |
+
perMessageDeflate.accept(offers[PerMessageDeflate.extensionName]);
|
| 303 |
+
extensions[PerMessageDeflate.extensionName] = perMessageDeflate;
|
| 304 |
+
}
|
| 305 |
+
} catch (err) {
|
| 306 |
+
const message =
|
| 307 |
+
'Invalid or unacceptable Sec-WebSocket-Extensions header';
|
| 308 |
+
abortHandshakeOrEmitwsClientError(this, req, socket, 400, message);
|
| 309 |
+
return;
|
| 310 |
+
}
|
| 311 |
+
}
|
| 312 |
+
|
| 313 |
+
//
|
| 314 |
+
// Optionally call external client verification handler.
|
| 315 |
+
//
|
| 316 |
+
if (this.options.verifyClient) {
|
| 317 |
+
const info = {
|
| 318 |
+
origin:
|
| 319 |
+
req.headers[`${version === 8 ? 'sec-websocket-origin' : 'origin'}`],
|
| 320 |
+
secure: !!(req.socket.authorized || req.socket.encrypted),
|
| 321 |
+
req
|
| 322 |
+
};
|
| 323 |
+
|
| 324 |
+
if (this.options.verifyClient.length === 2) {
|
| 325 |
+
this.options.verifyClient(info, (verified, code, message, headers) => {
|
| 326 |
+
if (!verified) {
|
| 327 |
+
return abortHandshake(socket, code || 401, message, headers);
|
| 328 |
+
}
|
| 329 |
+
|
| 330 |
+
this.completeUpgrade(
|
| 331 |
+
extensions,
|
| 332 |
+
key,
|
| 333 |
+
protocols,
|
| 334 |
+
req,
|
| 335 |
+
socket,
|
| 336 |
+
head,
|
| 337 |
+
cb
|
| 338 |
+
);
|
| 339 |
+
});
|
| 340 |
+
return;
|
| 341 |
+
}
|
| 342 |
+
|
| 343 |
+
if (!this.options.verifyClient(info)) return abortHandshake(socket, 401);
|
| 344 |
+
}
|
| 345 |
+
|
| 346 |
+
this.completeUpgrade(extensions, key, protocols, req, socket, head, cb);
|
| 347 |
+
}
|
| 348 |
+
|
| 349 |
+
/**
|
| 350 |
+
* Upgrade the connection to WebSocket.
|
| 351 |
+
*
|
| 352 |
+
* @param {Object} extensions The accepted extensions
|
| 353 |
+
* @param {String} key The value of the `Sec-WebSocket-Key` header
|
| 354 |
+
* @param {Set} protocols The subprotocols
|
| 355 |
+
* @param {http.IncomingMessage} req The request object
|
| 356 |
+
* @param {Duplex} socket The network socket between the server and client
|
| 357 |
+
* @param {Buffer} head The first packet of the upgraded stream
|
| 358 |
+
* @param {Function} cb Callback
|
| 359 |
+
* @throws {Error} If called more than once with the same socket
|
| 360 |
+
* @private
|
| 361 |
+
*/
|
| 362 |
+
completeUpgrade(extensions, key, protocols, req, socket, head, cb) {
|
| 363 |
+
//
|
| 364 |
+
// Destroy the socket if the client has already sent a FIN packet.
|
| 365 |
+
//
|
| 366 |
+
if (!socket.readable || !socket.writable) return socket.destroy();
|
| 367 |
+
|
| 368 |
+
if (socket[kWebSocket]) {
|
| 369 |
+
throw new Error(
|
| 370 |
+
'server.handleUpgrade() was called more than once with the same ' +
|
| 371 |
+
'socket, possibly due to a misconfiguration'
|
| 372 |
+
);
|
| 373 |
+
}
|
| 374 |
+
|
| 375 |
+
if (this._state > RUNNING) return abortHandshake(socket, 503);
|
| 376 |
+
|
| 377 |
+
const digest = createHash('sha1')
|
| 378 |
+
.update(key + GUID)
|
| 379 |
+
.digest('base64');
|
| 380 |
+
|
| 381 |
+
const headers = [
|
| 382 |
+
'HTTP/1.1 101 Switching Protocols',
|
| 383 |
+
'Upgrade: websocket',
|
| 384 |
+
'Connection: Upgrade',
|
| 385 |
+
`Sec-WebSocket-Accept: ${digest}`
|
| 386 |
+
];
|
| 387 |
+
|
| 388 |
+
const ws = new this.options.WebSocket(null, undefined, this.options);
|
| 389 |
+
|
| 390 |
+
if (protocols.size) {
|
| 391 |
+
//
|
| 392 |
+
// Optionally call external protocol selection handler.
|
| 393 |
+
//
|
| 394 |
+
const protocol = this.options.handleProtocols
|
| 395 |
+
? this.options.handleProtocols(protocols, req)
|
| 396 |
+
: protocols.values().next().value;
|
| 397 |
+
|
| 398 |
+
if (protocol) {
|
| 399 |
+
headers.push(`Sec-WebSocket-Protocol: ${protocol}`);
|
| 400 |
+
ws._protocol = protocol;
|
| 401 |
+
}
|
| 402 |
+
}
|
| 403 |
+
|
| 404 |
+
if (extensions[PerMessageDeflate.extensionName]) {
|
| 405 |
+
const params = extensions[PerMessageDeflate.extensionName].params;
|
| 406 |
+
const value = extension.format({
|
| 407 |
+
[PerMessageDeflate.extensionName]: [params]
|
| 408 |
+
});
|
| 409 |
+
headers.push(`Sec-WebSocket-Extensions: ${value}`);
|
| 410 |
+
ws._extensions = extensions;
|
| 411 |
+
}
|
| 412 |
+
|
| 413 |
+
//
|
| 414 |
+
// Allow external modification/inspection of handshake headers.
|
| 415 |
+
//
|
| 416 |
+
this.emit('headers', headers, req);
|
| 417 |
+
|
| 418 |
+
socket.write(headers.concat('\r\n').join('\r\n'));
|
| 419 |
+
socket.removeListener('error', socketOnError);
|
| 420 |
+
|
| 421 |
+
ws.setSocket(socket, head, {
|
| 422 |
+
allowSynchronousEvents: this.options.allowSynchronousEvents,
|
| 423 |
+
maxPayload: this.options.maxPayload,
|
| 424 |
+
skipUTF8Validation: this.options.skipUTF8Validation
|
| 425 |
+
});
|
| 426 |
+
|
| 427 |
+
if (this.clients) {
|
| 428 |
+
this.clients.add(ws);
|
| 429 |
+
ws.on('close', () => {
|
| 430 |
+
this.clients.delete(ws);
|
| 431 |
+
|
| 432 |
+
if (this._shouldEmitClose && !this.clients.size) {
|
| 433 |
+
process.nextTick(emitClose, this);
|
| 434 |
+
}
|
| 435 |
+
});
|
| 436 |
+
}
|
| 437 |
+
|
| 438 |
+
cb(ws, req);
|
| 439 |
+
}
|
| 440 |
+
}
|
| 441 |
+
|
| 442 |
+
module.exports = WebSocketServer;
|
| 443 |
+
|
| 444 |
+
/**
|
| 445 |
+
* Add event listeners on an `EventEmitter` using a map of <event, listener>
|
| 446 |
+
* pairs.
|
| 447 |
+
*
|
| 448 |
+
* @param {EventEmitter} server The event emitter
|
| 449 |
+
* @param {Object.<String, Function>} map The listeners to add
|
| 450 |
+
* @return {Function} A function that will remove the added listeners when
|
| 451 |
+
* called
|
| 452 |
+
* @private
|
| 453 |
+
*/
|
| 454 |
+
function addListeners(server, map) {
|
| 455 |
+
for (const event of Object.keys(map)) server.on(event, map[event]);
|
| 456 |
+
|
| 457 |
+
return function removeListeners() {
|
| 458 |
+
for (const event of Object.keys(map)) {
|
| 459 |
+
server.removeListener(event, map[event]);
|
| 460 |
+
}
|
| 461 |
+
};
|
| 462 |
+
}
|
| 463 |
+
|
| 464 |
+
/**
|
| 465 |
+
* Emit a `'close'` event on an `EventEmitter`.
|
| 466 |
+
*
|
| 467 |
+
* @param {EventEmitter} server The event emitter
|
| 468 |
+
* @private
|
| 469 |
+
*/
|
| 470 |
+
function emitClose(server) {
|
| 471 |
+
server._state = CLOSED;
|
| 472 |
+
server.emit('close');
|
| 473 |
+
}
|
| 474 |
+
|
| 475 |
+
/**
|
| 476 |
+
* Handle socket errors.
|
| 477 |
+
*
|
| 478 |
+
* @private
|
| 479 |
+
*/
|
| 480 |
+
function socketOnError() {
|
| 481 |
+
this.destroy();
|
| 482 |
+
}
|
| 483 |
+
|
| 484 |
+
/**
|
| 485 |
+
* Close the connection when preconditions are not fulfilled.
|
| 486 |
+
*
|
| 487 |
+
* @param {Duplex} socket The socket of the upgrade request
|
| 488 |
+
* @param {Number} code The HTTP response status code
|
| 489 |
+
* @param {String} [message] The HTTP response body
|
| 490 |
+
* @param {Object} [headers] Additional HTTP response headers
|
| 491 |
+
* @private
|
| 492 |
+
*/
|
| 493 |
+
function abortHandshake(socket, code, message, headers) {
|
| 494 |
+
//
|
| 495 |
+
// The socket is writable unless the user destroyed or ended it before calling
|
| 496 |
+
// `server.handleUpgrade()` or in the `verifyClient` function, which is a user
|
| 497 |
+
// error. Handling this does not make much sense as the worst that can happen
|
| 498 |
+
// is that some of the data written by the user might be discarded due to the
|
| 499 |
+
// call to `socket.end()` below, which triggers an `'error'` event that in
|
| 500 |
+
// turn causes the socket to be destroyed.
|
| 501 |
+
//
|
| 502 |
+
message = message || http.STATUS_CODES[code];
|
| 503 |
+
headers = {
|
| 504 |
+
Connection: 'close',
|
| 505 |
+
'Content-Type': 'text/html',
|
| 506 |
+
'Content-Length': Buffer.byteLength(message),
|
| 507 |
+
...headers
|
| 508 |
+
};
|
| 509 |
+
|
| 510 |
+
socket.once('finish', socket.destroy);
|
| 511 |
+
|
| 512 |
+
socket.end(
|
| 513 |
+
`HTTP/1.1 ${code} ${http.STATUS_CODES[code]}\r\n` +
|
| 514 |
+
Object.keys(headers)
|
| 515 |
+
.map((h) => `${h}: ${headers[h]}`)
|
| 516 |
+
.join('\r\n') +
|
| 517 |
+
'\r\n\r\n' +
|
| 518 |
+
message
|
| 519 |
+
);
|
| 520 |
+
}
|
| 521 |
+
|
| 522 |
+
/**
|
| 523 |
+
* Emit a `'wsClientError'` event on a `WebSocketServer` if there is at least
|
| 524 |
+
* one listener for it, otherwise call `abortHandshake()`.
|
| 525 |
+
*
|
| 526 |
+
* @param {WebSocketServer} server The WebSocket server
|
| 527 |
+
* @param {http.IncomingMessage} req The request object
|
| 528 |
+
* @param {Duplex} socket The socket of the upgrade request
|
| 529 |
+
* @param {Number} code The HTTP response status code
|
| 530 |
+
* @param {String} message The HTTP response body
|
| 531 |
+
* @param {Object} [headers] The HTTP response headers
|
| 532 |
+
* @private
|
| 533 |
+
*/
|
| 534 |
+
function abortHandshakeOrEmitwsClientError(
|
| 535 |
+
server,
|
| 536 |
+
req,
|
| 537 |
+
socket,
|
| 538 |
+
code,
|
| 539 |
+
message,
|
| 540 |
+
headers
|
| 541 |
+
) {
|
| 542 |
+
if (server.listenerCount('wsClientError')) {
|
| 543 |
+
const err = new Error(message);
|
| 544 |
+
Error.captureStackTrace(err, abortHandshakeOrEmitwsClientError);
|
| 545 |
+
|
| 546 |
+
server.emit('wsClientError', err, socket, req);
|
| 547 |
+
} else {
|
| 548 |
+
abortHandshake(socket, code, message, headers);
|
| 549 |
+
}
|
| 550 |
+
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* eslint no-unused-vars: ["error", { "varsIgnorePattern": "^Duplex|Readable$", "caughtErrors": "none" }] */
|
| 2 |
+
|
| 3 |
+
'use strict';
|
| 4 |
+
|
| 5 |
+
const EventEmitter = require('events');
|
| 6 |
+
const https = require('https');
|
| 7 |
+
const http = require('http');
|
| 8 |
+
const net = require('net');
|
| 9 |
+
const tls = require('tls');
|
| 10 |
+
const { randomBytes, createHash } = require('crypto');
|
| 11 |
+
const { Duplex, Readable } = require('stream');
|
| 12 |
+
const { URL } = require('url');
|
| 13 |
+
|
| 14 |
+
const PerMessageDeflate = require('./permessage-deflate');
|
| 15 |
+
const Receiver = require('./receiver');
|
| 16 |
+
const Sender = require('./sender');
|
| 17 |
+
const { isBlob } = require('./validation');
|
| 18 |
+
|
| 19 |
+
const {
|
| 20 |
+
BINARY_TYPES,
|
| 21 |
+
EMPTY_BUFFER,
|
| 22 |
+
GUID,
|
| 23 |
+
kForOnEventAttribute,
|
| 24 |
+
kListener,
|
| 25 |
+
kStatusCode,
|
| 26 |
+
kWebSocket,
|
| 27 |
+
NOOP
|
| 28 |
+
} = require('./constants');
|
| 29 |
+
const {
|
| 30 |
+
EventTarget: { addEventListener, removeEventListener }
|
| 31 |
+
} = require('./event-target');
|
| 32 |
+
const { format, parse } = require('./extension');
|
| 33 |
+
const { toBuffer } = require('./buffer-util');
|
| 34 |
+
|
| 35 |
+
const closeTimeout = 30 * 1000;
|
| 36 |
+
const kAborted = Symbol('kAborted');
|
| 37 |
+
const protocolVersions = [8, 13];
|
| 38 |
+
const readyStates = ['CONNECTING', 'OPEN', 'CLOSING', 'CLOSED'];
|
| 39 |
+
const subprotocolRegex = /^[!#$%&'*+\-.0-9A-Z^_`|a-z~]+$/;
|
| 40 |
+
|
| 41 |
+
/**
|
| 42 |
+
* Class representing a WebSocket.
|
| 43 |
+
*
|
| 44 |
+
* @extends EventEmitter
|
| 45 |
+
*/
|
| 46 |
+
class WebSocket extends EventEmitter {
|
| 47 |
+
/**
|
| 48 |
+
* Create a new `WebSocket`.
|
| 49 |
+
*
|
| 50 |
+
* @param {(String|URL)} address The URL to which to connect
|
| 51 |
+
* @param {(String|String[])} [protocols] The subprotocols
|
| 52 |
+
* @param {Object} [options] Connection options
|
| 53 |
+
*/
|
| 54 |
+
constructor(address, protocols, options) {
|
| 55 |
+
super();
|
| 56 |
+
|
| 57 |
+
this._binaryType = BINARY_TYPES[0];
|
| 58 |
+
this._closeCode = 1006;
|
| 59 |
+
this._closeFrameReceived = false;
|
| 60 |
+
this._closeFrameSent = false;
|
| 61 |
+
this._closeMessage = EMPTY_BUFFER;
|
| 62 |
+
this._closeTimer = null;
|
| 63 |
+
this._errorEmitted = false;
|
| 64 |
+
this._extensions = {};
|
| 65 |
+
this._paused = false;
|
| 66 |
+
this._protocol = '';
|
| 67 |
+
this._readyState = WebSocket.CONNECTING;
|
| 68 |
+
this._receiver = null;
|
| 69 |
+
this._sender = null;
|
| 70 |
+
this._socket = null;
|
| 71 |
+
|
| 72 |
+
if (address !== null) {
|
| 73 |
+
this._bufferedAmount = 0;
|
| 74 |
+
this._isServer = false;
|
| 75 |
+
this._redirects = 0;
|
| 76 |
+
|
| 77 |
+
if (protocols === undefined) {
|
| 78 |
+
protocols = [];
|
| 79 |
+
} else if (!Array.isArray(protocols)) {
|
| 80 |
+
if (typeof protocols === 'object' && protocols !== null) {
|
| 81 |
+
options = protocols;
|
| 82 |
+
protocols = [];
|
| 83 |
+
} else {
|
| 84 |
+
protocols = [protocols];
|
| 85 |
+
}
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
initAsClient(this, address, protocols, options);
|
| 89 |
+
} else {
|
| 90 |
+
this._autoPong = options.autoPong;
|
| 91 |
+
this._isServer = true;
|
| 92 |
+
}
|
| 93 |
+
}
|
| 94 |
+
|
| 95 |
+
/**
|
| 96 |
+
* For historical reasons, the custom "nodebuffer" type is used by the default
|
| 97 |
+
* instead of "blob".
|
| 98 |
+
*
|
| 99 |
+
* @type {String}
|
| 100 |
+
*/
|
| 101 |
+
get binaryType() {
|
| 102 |
+
return this._binaryType;
|
| 103 |
+
}
|
| 104 |
+
|
| 105 |
+
set binaryType(type) {
|
| 106 |
+
if (!BINARY_TYPES.includes(type)) return;
|
| 107 |
+
|
| 108 |
+
this._binaryType = type;
|
| 109 |
+
|
| 110 |
+
//
|
| 111 |
+
// Allow to change `binaryType` on the fly.
|
| 112 |
+
//
|
| 113 |
+
if (this._receiver) this._receiver._binaryType = type;
|
| 114 |
+
}
|
| 115 |
+
|
| 116 |
+
/**
|
| 117 |
+
* @type {Number}
|
| 118 |
+
*/
|
| 119 |
+
get bufferedAmount() {
|
| 120 |
+
if (!this._socket) return this._bufferedAmount;
|
| 121 |
+
|
| 122 |
+
return this._socket._writableState.length + this._sender._bufferedBytes;
|
| 123 |
+
}
|
| 124 |
+
|
| 125 |
+
/**
|
| 126 |
+
* @type {String}
|
| 127 |
+
*/
|
| 128 |
+
get extensions() {
|
| 129 |
+
return Object.keys(this._extensions).join();
|
| 130 |
+
}
|
| 131 |
+
|
| 132 |
+
/**
|
| 133 |
+
* @type {Boolean}
|
| 134 |
+
*/
|
| 135 |
+
get isPaused() {
|
| 136 |
+
return this._paused;
|
| 137 |
+
}
|
| 138 |
+
|
| 139 |
+
/**
|
| 140 |
+
* @type {Function}
|
| 141 |
+
*/
|
| 142 |
+
/* istanbul ignore next */
|
| 143 |
+
get onclose() {
|
| 144 |
+
return null;
|
| 145 |
+
}
|
| 146 |
+
|
| 147 |
+
/**
|
| 148 |
+
* @type {Function}
|
| 149 |
+
*/
|
| 150 |
+
/* istanbul ignore next */
|
| 151 |
+
get onerror() {
|
| 152 |
+
return null;
|
| 153 |
+
}
|
| 154 |
+
|
| 155 |
+
/**
|
| 156 |
+
* @type {Function}
|
| 157 |
+
*/
|
| 158 |
+
/* istanbul ignore next */
|
| 159 |
+
get onopen() {
|
| 160 |
+
return null;
|
| 161 |
+
}
|
| 162 |
+
|
| 163 |
+
/**
|
| 164 |
+
* @type {Function}
|
| 165 |
+
*/
|
| 166 |
+
/* istanbul ignore next */
|
| 167 |
+
get onmessage() {
|
| 168 |
+
return null;
|
| 169 |
+
}
|
| 170 |
+
|
| 171 |
+
/**
|
| 172 |
+
* @type {String}
|
| 173 |
+
*/
|
| 174 |
+
get protocol() {
|
| 175 |
+
return this._protocol;
|
| 176 |
+
}
|
| 177 |
+
|
| 178 |
+
/**
|
| 179 |
+
* @type {Number}
|
| 180 |
+
*/
|
| 181 |
+
get readyState() {
|
| 182 |
+
return this._readyState;
|
| 183 |
+
}
|
| 184 |
+
|
| 185 |
+
/**
|
| 186 |
+
* @type {String}
|
| 187 |
+
*/
|
| 188 |
+
get url() {
|
| 189 |
+
return this._url;
|
| 190 |
+
}
|
| 191 |
+
|
| 192 |
+
/**
|
| 193 |
+
* Set up the socket and the internal resources.
|
| 194 |
+
*
|
| 195 |
+
* @param {Duplex} socket The network socket between the server and client
|
| 196 |
+
* @param {Buffer} head The first packet of the upgraded stream
|
| 197 |
+
* @param {Object} options Options object
|
| 198 |
+
* @param {Boolean} [options.allowSynchronousEvents=false] Specifies whether
|
| 199 |
+
* any of the `'message'`, `'ping'`, and `'pong'` events can be emitted
|
| 200 |
+
* multiple times in the same tick
|
| 201 |
+
* @param {Function} [options.generateMask] The function used to generate the
|
| 202 |
+
* masking key
|
| 203 |
+
* @param {Number} [options.maxPayload=0] The maximum allowed message size
|
| 204 |
+
* @param {Boolean} [options.skipUTF8Validation=false] Specifies whether or
|
| 205 |
+
* not to skip UTF-8 validation for text and close messages
|
| 206 |
+
* @private
|
| 207 |
+
*/
|
| 208 |
+
setSocket(socket, head, options) {
|
| 209 |
+
const receiver = new Receiver({
|
| 210 |
+
allowSynchronousEvents: options.allowSynchronousEvents,
|
| 211 |
+
binaryType: this.binaryType,
|
| 212 |
+
extensions: this._extensions,
|
| 213 |
+
isServer: this._isServer,
|
| 214 |
+
maxPayload: options.maxPayload,
|
| 215 |
+
skipUTF8Validation: options.skipUTF8Validation
|
| 216 |
+
});
|
| 217 |
+
|
| 218 |
+
const sender = new Sender(socket, this._extensions, options.generateMask);
|
| 219 |
+
|
| 220 |
+
this._receiver = receiver;
|
| 221 |
+
this._sender = sender;
|
| 222 |
+
this._socket = socket;
|
| 223 |
+
|
| 224 |
+
receiver[kWebSocket] = this;
|
| 225 |
+
sender[kWebSocket] = this;
|
| 226 |
+
socket[kWebSocket] = this;
|
| 227 |
+
|
| 228 |
+
receiver.on('conclude', receiverOnConclude);
|
| 229 |
+
receiver.on('drain', receiverOnDrain);
|
| 230 |
+
receiver.on('error', receiverOnError);
|
| 231 |
+
receiver.on('message', receiverOnMessage);
|
| 232 |
+
receiver.on('ping', receiverOnPing);
|
| 233 |
+
receiver.on('pong', receiverOnPong);
|
| 234 |
+
|
| 235 |
+
sender.onerror = senderOnError;
|
| 236 |
+
|
| 237 |
+
//
|
| 238 |
+
// These methods may not be available if `socket` is just a `Duplex`.
|
| 239 |
+
//
|
| 240 |
+
if (socket.setTimeout) socket.setTimeout(0);
|
| 241 |
+
if (socket.setNoDelay) socket.setNoDelay();
|
| 242 |
+
|
| 243 |
+
if (head.length > 0) socket.unshift(head);
|
| 244 |
+
|
| 245 |
+
socket.on('close', socketOnClose);
|
| 246 |
+
socket.on('data', socketOnData);
|
| 247 |
+
socket.on('end', socketOnEnd);
|
| 248 |
+
socket.on('error', socketOnError);
|
| 249 |
+
|
| 250 |
+
this._readyState = WebSocket.OPEN;
|
| 251 |
+
this.emit('open');
|
| 252 |
+
}
|
| 253 |
+
|
| 254 |
+
/**
|
| 255 |
+
* Emit the `'close'` event.
|
| 256 |
+
*
|
| 257 |
+
* @private
|
| 258 |
+
*/
|
| 259 |
+
emitClose() {
|
| 260 |
+
if (!this._socket) {
|
| 261 |
+
this._readyState = WebSocket.CLOSED;
|
| 262 |
+
this.emit('close', this._closeCode, this._closeMessage);
|
| 263 |
+
return;
|
| 264 |
+
}
|
| 265 |
+
|
| 266 |
+
if (this._extensions[PerMessageDeflate.extensionName]) {
|
| 267 |
+
this._extensions[PerMessageDeflate.extensionName].cleanup();
|
| 268 |
+
}
|
| 269 |
+
|
| 270 |
+
this._receiver.removeAllListeners();
|
| 271 |
+
this._readyState = WebSocket.CLOSED;
|
| 272 |
+
this.emit('close', this._closeCode, this._closeMessage);
|
| 273 |
+
}
|
| 274 |
+
|
| 275 |
+
/**
|
| 276 |
+
* Start a closing handshake.
|
| 277 |
+
*
|
| 278 |
+
* +----------+ +-----------+ +----------+
|
| 279 |
+
* - - -|ws.close()|-->|close frame|-->|ws.close()|- - -
|
| 280 |
+
* | +----------+ +-----------+ +----------+ |
|
| 281 |
+
* +----------+ +-----------+ |
|
| 282 |
+
* CLOSING |ws.close()|<--|close frame|<--+-----+ CLOSING
|
| 283 |
+
* +----------+ +-----------+ |
|
| 284 |
+
* | | | +---+ |
|
| 285 |
+
* +------------------------+-->|fin| - - - -
|
| 286 |
+
* | +---+ | +---+
|
| 287 |
+
* - - - - -|fin|<---------------------+
|
| 288 |
+
* +---+
|
| 289 |
+
*
|
| 290 |
+
* @param {Number} [code] Status code explaining why the connection is closing
|
| 291 |
+
* @param {(String|Buffer)} [data] The reason why the connection is
|
| 292 |
+
* closing
|
| 293 |
+
* @public
|
| 294 |
+
*/
|
| 295 |
+
close(code, data) {
|
| 296 |
+
if (this.readyState === WebSocket.CLOSED) return;
|
| 297 |
+
if (this.readyState === WebSocket.CONNECTING) {
|
| 298 |
+
const msg = 'WebSocket was closed before the connection was established';
|
| 299 |
+
abortHandshake(this, this._req, msg);
|
| 300 |
+
return;
|
| 301 |
+
}
|
| 302 |
+
|
| 303 |
+
if (this.readyState === WebSocket.CLOSING) {
|
| 304 |
+
if (
|
| 305 |
+
this._closeFrameSent &&
|
| 306 |
+
(this._closeFrameReceived || this._receiver._writableState.errorEmitted)
|
| 307 |
+
) {
|
| 308 |
+
this._socket.end();
|
| 309 |
+
}
|
| 310 |
+
|
| 311 |
+
return;
|
| 312 |
+
}
|
| 313 |
+
|
| 314 |
+
this._readyState = WebSocket.CLOSING;
|
| 315 |
+
this._sender.close(code, data, !this._isServer, (err) => {
|
| 316 |
+
//
|
| 317 |
+
// This error is handled by the `'error'` listener on the socket. We only
|
| 318 |
+
// want to know if the close frame has been sent here.
|
| 319 |
+
//
|
| 320 |
+
if (err) return;
|
| 321 |
+
|
| 322 |
+
this._closeFrameSent = true;
|
| 323 |
+
|
| 324 |
+
if (
|
| 325 |
+
this._closeFrameReceived ||
|
| 326 |
+
this._receiver._writableState.errorEmitted
|
| 327 |
+
) {
|
| 328 |
+
this._socket.end();
|
| 329 |
+
}
|
| 330 |
+
});
|
| 331 |
+
|
| 332 |
+
setCloseTimer(this);
|
| 333 |
+
}
|
| 334 |
+
|
| 335 |
+
/**
|
| 336 |
+
* Pause the socket.
|
| 337 |
+
*
|
| 338 |
+
* @public
|
| 339 |
+
*/
|
| 340 |
+
pause() {
|
| 341 |
+
if (
|
| 342 |
+
this.readyState === WebSocket.CONNECTING ||
|
| 343 |
+
this.readyState === WebSocket.CLOSED
|
| 344 |
+
) {
|
| 345 |
+
return;
|
| 346 |
+
}
|
| 347 |
+
|
| 348 |
+
this._paused = true;
|
| 349 |
+
this._socket.pause();
|
| 350 |
+
}
|
| 351 |
+
|
| 352 |
+
/**
|
| 353 |
+
* Send a ping.
|
| 354 |
+
*
|
| 355 |
+
* @param {*} [data] The data to send
|
| 356 |
+
* @param {Boolean} [mask] Indicates whether or not to mask `data`
|
| 357 |
+
* @param {Function} [cb] Callback which is executed when the ping is sent
|
| 358 |
+
* @public
|
| 359 |
+
*/
|
| 360 |
+
ping(data, mask, cb) {
|
| 361 |
+
if (this.readyState === WebSocket.CONNECTING) {
|
| 362 |
+
throw new Error('WebSocket is not open: readyState 0 (CONNECTING)');
|
| 363 |
+
}
|
| 364 |
+
|
| 365 |
+
if (typeof data === 'function') {
|
| 366 |
+
cb = data;
|
| 367 |
+
data = mask = undefined;
|
| 368 |
+
} else if (typeof mask === 'function') {
|
| 369 |
+
cb = mask;
|
| 370 |
+
mask = undefined;
|
| 371 |
+
}
|
| 372 |
+
|
| 373 |
+
if (typeof data === 'number') data = data.toString();
|
| 374 |
+
|
| 375 |
+
if (this.readyState !== WebSocket.OPEN) {
|
| 376 |
+
sendAfterClose(this, data, cb);
|
| 377 |
+
return;
|
| 378 |
+
}
|
| 379 |
+
|
| 380 |
+
if (mask === undefined) mask = !this._isServer;
|
| 381 |
+
this._sender.ping(data || EMPTY_BUFFER, mask, cb);
|
| 382 |
+
}
|
| 383 |
+
|
| 384 |
+
/**
|
| 385 |
+
* Send a pong.
|
| 386 |
+
*
|
| 387 |
+
* @param {*} [data] The data to send
|
| 388 |
+
* @param {Boolean} [mask] Indicates whether or not to mask `data`
|
| 389 |
+
* @param {Function} [cb] Callback which is executed when the pong is sent
|
| 390 |
+
* @public
|
| 391 |
+
*/
|
| 392 |
+
pong(data, mask, cb) {
|
| 393 |
+
if (this.readyState === WebSocket.CONNECTING) {
|
| 394 |
+
throw new Error('WebSocket is not open: readyState 0 (CONNECTING)');
|
| 395 |
+
}
|
| 396 |
+
|
| 397 |
+
if (typeof data === 'function') {
|
| 398 |
+
cb = data;
|
| 399 |
+
data = mask = undefined;
|
| 400 |
+
} else if (typeof mask === 'function') {
|
| 401 |
+
cb = mask;
|
| 402 |
+
mask = undefined;
|
| 403 |
+
}
|
| 404 |
+
|
| 405 |
+
if (typeof data === 'number') data = data.toString();
|
| 406 |
+
|
| 407 |
+
if (this.readyState !== WebSocket.OPEN) {
|
| 408 |
+
sendAfterClose(this, data, cb);
|
| 409 |
+
return;
|
| 410 |
+
}
|
| 411 |
+
|
| 412 |
+
if (mask === undefined) mask = !this._isServer;
|
| 413 |
+
this._sender.pong(data || EMPTY_BUFFER, mask, cb);
|
| 414 |
+
}
|
| 415 |
+
|
| 416 |
+
/**
|
| 417 |
+
* Resume the socket.
|
| 418 |
+
*
|
| 419 |
+
* @public
|
| 420 |
+
*/
|
| 421 |
+
resume() {
|
| 422 |
+
if (
|
| 423 |
+
this.readyState === WebSocket.CONNECTING ||
|
| 424 |
+
this.readyState === WebSocket.CLOSED
|
| 425 |
+
) {
|
| 426 |
+
return;
|
| 427 |
+
}
|
| 428 |
+
|
| 429 |
+
this._paused = false;
|
| 430 |
+
if (!this._receiver._writableState.needDrain) this._socket.resume();
|
| 431 |
+
}
|
| 432 |
+
|
| 433 |
+
/**
|
| 434 |
+
* Send a data message.
|
| 435 |
+
*
|
| 436 |
+
* @param {*} data The message to send
|
| 437 |
+
* @param {Object} [options] Options object
|
| 438 |
+
* @param {Boolean} [options.binary] Specifies whether `data` is binary or
|
| 439 |
+
* text
|
| 440 |
+
* @param {Boolean} [options.compress] Specifies whether or not to compress
|
| 441 |
+
* `data`
|
| 442 |
+
* @param {Boolean} [options.fin=true] Specifies whether the fragment is the
|
| 443 |
+
* last one
|
| 444 |
+
* @param {Boolean} [options.mask] Specifies whether or not to mask `data`
|
| 445 |
+
* @param {Function} [cb] Callback which is executed when data is written out
|
| 446 |
+
* @public
|
| 447 |
+
*/
|
| 448 |
+
send(data, options, cb) {
|
| 449 |
+
if (this.readyState === WebSocket.CONNECTING) {
|
| 450 |
+
throw new Error('WebSocket is not open: readyState 0 (CONNECTING)');
|
| 451 |
+
}
|
| 452 |
+
|
| 453 |
+
if (typeof options === 'function') {
|
| 454 |
+
cb = options;
|
| 455 |
+
options = {};
|
| 456 |
+
}
|
| 457 |
+
|
| 458 |
+
if (typeof data === 'number') data = data.toString();
|
| 459 |
+
|
| 460 |
+
if (this.readyState !== WebSocket.OPEN) {
|
| 461 |
+
sendAfterClose(this, data, cb);
|
| 462 |
+
return;
|
| 463 |
+
}
|
| 464 |
+
|
| 465 |
+
const opts = {
|
| 466 |
+
binary: typeof data !== 'string',
|
| 467 |
+
mask: !this._isServer,
|
| 468 |
+
compress: true,
|
| 469 |
+
fin: true,
|
| 470 |
+
...options
|
| 471 |
+
};
|
| 472 |
+
|
| 473 |
+
if (!this._extensions[PerMessageDeflate.extensionName]) {
|
| 474 |
+
opts.compress = false;
|
| 475 |
+
}
|
| 476 |
+
|
| 477 |
+
this._sender.send(data || EMPTY_BUFFER, opts, cb);
|
| 478 |
+
}
|
| 479 |
+
|
| 480 |
+
/**
|
| 481 |
+
* Forcibly close the connection.
|
| 482 |
+
*
|
| 483 |
+
* @public
|
| 484 |
+
*/
|
| 485 |
+
terminate() {
|
| 486 |
+
if (this.readyState === WebSocket.CLOSED) return;
|
| 487 |
+
if (this.readyState === WebSocket.CONNECTING) {
|
| 488 |
+
const msg = 'WebSocket was closed before the connection was established';
|
| 489 |
+
abortHandshake(this, this._req, msg);
|
| 490 |
+
return;
|
| 491 |
+
}
|
| 492 |
+
|
| 493 |
+
if (this._socket) {
|
| 494 |
+
this._readyState = WebSocket.CLOSING;
|
| 495 |
+
this._socket.destroy();
|
| 496 |
+
}
|
| 497 |
+
}
|
| 498 |
+
}
|
| 499 |
+
|
| 500 |
+
/**
|
| 501 |
+
* @constant {Number} CONNECTING
|
| 502 |
+
* @memberof WebSocket
|
| 503 |
+
*/
|
| 504 |
+
Object.defineProperty(WebSocket, 'CONNECTING', {
|
| 505 |
+
enumerable: true,
|
| 506 |
+
value: readyStates.indexOf('CONNECTING')
|
| 507 |
+
});
|
| 508 |
+
|
| 509 |
+
/**
|
| 510 |
+
* @constant {Number} CONNECTING
|
| 511 |
+
* @memberof WebSocket.prototype
|
| 512 |
+
*/
|
| 513 |
+
Object.defineProperty(WebSocket.prototype, 'CONNECTING', {
|
| 514 |
+
enumerable: true,
|
| 515 |
+
value: readyStates.indexOf('CONNECTING')
|
| 516 |
+
});
|
| 517 |
+
|
| 518 |
+
/**
|
| 519 |
+
* @constant {Number} OPEN
|
| 520 |
+
* @memberof WebSocket
|
| 521 |
+
*/
|
| 522 |
+
Object.defineProperty(WebSocket, 'OPEN', {
|
| 523 |
+
enumerable: true,
|
| 524 |
+
value: readyStates.indexOf('OPEN')
|
| 525 |
+
});
|
| 526 |
+
|
| 527 |
+
/**
|
| 528 |
+
* @constant {Number} OPEN
|
| 529 |
+
* @memberof WebSocket.prototype
|
| 530 |
+
*/
|
| 531 |
+
Object.defineProperty(WebSocket.prototype, 'OPEN', {
|
| 532 |
+
enumerable: true,
|
| 533 |
+
value: readyStates.indexOf('OPEN')
|
| 534 |
+
});
|
| 535 |
+
|
| 536 |
+
/**
|
| 537 |
+
* @constant {Number} CLOSING
|
| 538 |
+
* @memberof WebSocket
|
| 539 |
+
*/
|
| 540 |
+
Object.defineProperty(WebSocket, 'CLOSING', {
|
| 541 |
+
enumerable: true,
|
| 542 |
+
value: readyStates.indexOf('CLOSING')
|
| 543 |
+
});
|
| 544 |
+
|
| 545 |
+
/**
|
| 546 |
+
* @constant {Number} CLOSING
|
| 547 |
+
* @memberof WebSocket.prototype
|
| 548 |
+
*/
|
| 549 |
+
Object.defineProperty(WebSocket.prototype, 'CLOSING', {
|
| 550 |
+
enumerable: true,
|
| 551 |
+
value: readyStates.indexOf('CLOSING')
|
| 552 |
+
});
|
| 553 |
+
|
| 554 |
+
/**
|
| 555 |
+
* @constant {Number} CLOSED
|
| 556 |
+
* @memberof WebSocket
|
| 557 |
+
*/
|
| 558 |
+
Object.defineProperty(WebSocket, 'CLOSED', {
|
| 559 |
+
enumerable: true,
|
| 560 |
+
value: readyStates.indexOf('CLOSED')
|
| 561 |
+
});
|
| 562 |
+
|
| 563 |
+
/**
|
| 564 |
+
* @constant {Number} CLOSED
|
| 565 |
+
* @memberof WebSocket.prototype
|
| 566 |
+
*/
|
| 567 |
+
Object.defineProperty(WebSocket.prototype, 'CLOSED', {
|
| 568 |
+
enumerable: true,
|
| 569 |
+
value: readyStates.indexOf('CLOSED')
|
| 570 |
+
});
|
| 571 |
+
|
| 572 |
+
[
|
| 573 |
+
'binaryType',
|
| 574 |
+
'bufferedAmount',
|
| 575 |
+
'extensions',
|
| 576 |
+
'isPaused',
|
| 577 |
+
'protocol',
|
| 578 |
+
'readyState',
|
| 579 |
+
'url'
|
| 580 |
+
].forEach((property) => {
|
| 581 |
+
Object.defineProperty(WebSocket.prototype, property, { enumerable: true });
|
| 582 |
+
});
|
| 583 |
+
|
| 584 |
+
//
|
| 585 |
+
// Add the `onopen`, `onerror`, `onclose`, and `onmessage` attributes.
|
| 586 |
+
// See https://html.spec.whatwg.org/multipage/comms.html#the-websocket-interface
|
| 587 |
+
//
|
| 588 |
+
['open', 'error', 'close', 'message'].forEach((method) => {
|
| 589 |
+
Object.defineProperty(WebSocket.prototype, `on${method}`, {
|
| 590 |
+
enumerable: true,
|
| 591 |
+
get() {
|
| 592 |
+
for (const listener of this.listeners(method)) {
|
| 593 |
+
if (listener[kForOnEventAttribute]) return listener[kListener];
|
| 594 |
+
}
|
| 595 |
+
|
| 596 |
+
return null;
|
| 597 |
+
},
|
| 598 |
+
set(handler) {
|
| 599 |
+
for (const listener of this.listeners(method)) {
|
| 600 |
+
if (listener[kForOnEventAttribute]) {
|
| 601 |
+
this.removeListener(method, listener);
|
| 602 |
+
break;
|
| 603 |
+
}
|
| 604 |
+
}
|
| 605 |
+
|
| 606 |
+
if (typeof handler !== 'function') return;
|
| 607 |
+
|
| 608 |
+
this.addEventListener(method, handler, {
|
| 609 |
+
[kForOnEventAttribute]: true
|
| 610 |
+
});
|
| 611 |
+
}
|
| 612 |
+
});
|
| 613 |
+
});
|
| 614 |
+
|
| 615 |
+
WebSocket.prototype.addEventListener = addEventListener;
|
| 616 |
+
WebSocket.prototype.removeEventListener = removeEventListener;
|
| 617 |
+
|
| 618 |
+
module.exports = WebSocket;
|
| 619 |
+
|
| 620 |
+
/**
|
| 621 |
+
* Initialize a WebSocket client.
|
| 622 |
+
*
|
| 623 |
+
* @param {WebSocket} websocket The client to initialize
|
| 624 |
+
* @param {(String|URL)} address The URL to which to connect
|
| 625 |
+
* @param {Array} protocols The subprotocols
|
| 626 |
+
* @param {Object} [options] Connection options
|
| 627 |
+
* @param {Boolean} [options.allowSynchronousEvents=true] Specifies whether any
|
| 628 |
+
* of the `'message'`, `'ping'`, and `'pong'` events can be emitted multiple
|
| 629 |
+
* times in the same tick
|
| 630 |
+
* @param {Boolean} [options.autoPong=true] Specifies whether or not to
|
| 631 |
+
* automatically send a pong in response to a ping
|
| 632 |
+
* @param {Function} [options.finishRequest] A function which can be used to
|
| 633 |
+
* customize the headers of each http request before it is sent
|
| 634 |
+
* @param {Boolean} [options.followRedirects=false] Whether or not to follow
|
| 635 |
+
* redirects
|
| 636 |
+
* @param {Function} [options.generateMask] The function used to generate the
|
| 637 |
+
* masking key
|
| 638 |
+
* @param {Number} [options.handshakeTimeout] Timeout in milliseconds for the
|
| 639 |
+
* handshake request
|
| 640 |
+
* @param {Number} [options.maxPayload=104857600] The maximum allowed message
|
| 641 |
+
* size
|
| 642 |
+
* @param {Number} [options.maxRedirects=10] The maximum number of redirects
|
| 643 |
+
* allowed
|
| 644 |
+
* @param {String} [options.origin] Value of the `Origin` or
|
| 645 |
+
* `Sec-WebSocket-Origin` header
|
| 646 |
+
* @param {(Boolean|Object)} [options.perMessageDeflate=true] Enable/disable
|
| 647 |
+
* permessage-deflate
|
| 648 |
+
* @param {Number} [options.protocolVersion=13] Value of the
|
| 649 |
+
* `Sec-WebSocket-Version` header
|
| 650 |
+
* @param {Boolean} [options.skipUTF8Validation=false] Specifies whether or
|
| 651 |
+
* not to skip UTF-8 validation for text and close messages
|
| 652 |
+
* @private
|
| 653 |
+
*/
|
| 654 |
+
function initAsClient(websocket, address, protocols, options) {
|
| 655 |
+
const opts = {
|
| 656 |
+
allowSynchronousEvents: true,
|
| 657 |
+
autoPong: true,
|
| 658 |
+
protocolVersion: protocolVersions[1],
|
| 659 |
+
maxPayload: 100 * 1024 * 1024,
|
| 660 |
+
skipUTF8Validation: false,
|
| 661 |
+
perMessageDeflate: true,
|
| 662 |
+
followRedirects: false,
|
| 663 |
+
maxRedirects: 10,
|
| 664 |
+
...options,
|
| 665 |
+
socketPath: undefined,
|
| 666 |
+
hostname: undefined,
|
| 667 |
+
protocol: undefined,
|
| 668 |
+
timeout: undefined,
|
| 669 |
+
method: 'GET',
|
| 670 |
+
host: undefined,
|
| 671 |
+
path: undefined,
|
| 672 |
+
port: undefined
|
| 673 |
+
};
|
| 674 |
+
|
| 675 |
+
websocket._autoPong = opts.autoPong;
|
| 676 |
+
|
| 677 |
+
if (!protocolVersions.includes(opts.protocolVersion)) {
|
| 678 |
+
throw new RangeError(
|
| 679 |
+
`Unsupported protocol version: ${opts.protocolVersion} ` +
|
| 680 |
+
`(supported versions: ${protocolVersions.join(', ')})`
|
| 681 |
+
);
|
| 682 |
+
}
|
| 683 |
+
|
| 684 |
+
let parsedUrl;
|
| 685 |
+
|
| 686 |
+
if (address instanceof URL) {
|
| 687 |
+
parsedUrl = address;
|
| 688 |
+
} else {
|
| 689 |
+
try {
|
| 690 |
+
parsedUrl = new URL(address);
|
| 691 |
+
} catch (e) {
|
| 692 |
+
throw new SyntaxError(`Invalid URL: ${address}`);
|
| 693 |
+
}
|
| 694 |
+
}
|
| 695 |
+
|
| 696 |
+
if (parsedUrl.protocol === 'http:') {
|
| 697 |
+
parsedUrl.protocol = 'ws:';
|
| 698 |
+
} else if (parsedUrl.protocol === 'https:') {
|
| 699 |
+
parsedUrl.protocol = 'wss:';
|
| 700 |
+
}
|
| 701 |
+
|
| 702 |
+
websocket._url = parsedUrl.href;
|
| 703 |
+
|
| 704 |
+
const isSecure = parsedUrl.protocol === 'wss:';
|
| 705 |
+
const isIpcUrl = parsedUrl.protocol === 'ws+unix:';
|
| 706 |
+
let invalidUrlMessage;
|
| 707 |
+
|
| 708 |
+
if (parsedUrl.protocol !== 'ws:' && !isSecure && !isIpcUrl) {
|
| 709 |
+
invalidUrlMessage =
|
| 710 |
+
'The URL\'s protocol must be one of "ws:", "wss:", ' +
|
| 711 |
+
'"http:", "https:", or "ws+unix:"';
|
| 712 |
+
} else if (isIpcUrl && !parsedUrl.pathname) {
|
| 713 |
+
invalidUrlMessage = "The URL's pathname is empty";
|
| 714 |
+
} else if (parsedUrl.hash) {
|
| 715 |
+
invalidUrlMessage = 'The URL contains a fragment identifier';
|
| 716 |
+
}
|
| 717 |
+
|
| 718 |
+
if (invalidUrlMessage) {
|
| 719 |
+
const err = new SyntaxError(invalidUrlMessage);
|
| 720 |
+
|
| 721 |
+
if (websocket._redirects === 0) {
|
| 722 |
+
throw err;
|
| 723 |
+
} else {
|
| 724 |
+
emitErrorAndClose(websocket, err);
|
| 725 |
+
return;
|
| 726 |
+
}
|
| 727 |
+
}
|
| 728 |
+
|
| 729 |
+
const defaultPort = isSecure ? 443 : 80;
|
| 730 |
+
const key = randomBytes(16).toString('base64');
|
| 731 |
+
const request = isSecure ? https.request : http.request;
|
| 732 |
+
const protocolSet = new Set();
|
| 733 |
+
let perMessageDeflate;
|
| 734 |
+
|
| 735 |
+
opts.createConnection =
|
| 736 |
+
opts.createConnection || (isSecure ? tlsConnect : netConnect);
|
| 737 |
+
opts.defaultPort = opts.defaultPort || defaultPort;
|
| 738 |
+
opts.port = parsedUrl.port || defaultPort;
|
| 739 |
+
opts.host = parsedUrl.hostname.startsWith('[')
|
| 740 |
+
? parsedUrl.hostname.slice(1, -1)
|
| 741 |
+
: parsedUrl.hostname;
|
| 742 |
+
opts.headers = {
|
| 743 |
+
...opts.headers,
|
| 744 |
+
'Sec-WebSocket-Version': opts.protocolVersion,
|
| 745 |
+
'Sec-WebSocket-Key': key,
|
| 746 |
+
Connection: 'Upgrade',
|
| 747 |
+
Upgrade: 'websocket'
|
| 748 |
+
};
|
| 749 |
+
opts.path = parsedUrl.pathname + parsedUrl.search;
|
| 750 |
+
opts.timeout = opts.handshakeTimeout;
|
| 751 |
+
|
| 752 |
+
if (opts.perMessageDeflate) {
|
| 753 |
+
perMessageDeflate = new PerMessageDeflate(
|
| 754 |
+
opts.perMessageDeflate !== true ? opts.perMessageDeflate : {},
|
| 755 |
+
false,
|
| 756 |
+
opts.maxPayload
|
| 757 |
+
);
|
| 758 |
+
opts.headers['Sec-WebSocket-Extensions'] = format({
|
| 759 |
+
[PerMessageDeflate.extensionName]: perMessageDeflate.offer()
|
| 760 |
+
});
|
| 761 |
+
}
|
| 762 |
+
if (protocols.length) {
|
| 763 |
+
for (const protocol of protocols) {
|
| 764 |
+
if (
|
| 765 |
+
typeof protocol !== 'string' ||
|
| 766 |
+
!subprotocolRegex.test(protocol) ||
|
| 767 |
+
protocolSet.has(protocol)
|
| 768 |
+
) {
|
| 769 |
+
throw new SyntaxError(
|
| 770 |
+
'An invalid or duplicated subprotocol was specified'
|
| 771 |
+
);
|
| 772 |
+
}
|
| 773 |
+
|
| 774 |
+
protocolSet.add(protocol);
|
| 775 |
+
}
|
| 776 |
+
|
| 777 |
+
opts.headers['Sec-WebSocket-Protocol'] = protocols.join(',');
|
| 778 |
+
}
|
| 779 |
+
if (opts.origin) {
|
| 780 |
+
if (opts.protocolVersion < 13) {
|
| 781 |
+
opts.headers['Sec-WebSocket-Origin'] = opts.origin;
|
| 782 |
+
} else {
|
| 783 |
+
opts.headers.Origin = opts.origin;
|
| 784 |
+
}
|
| 785 |
+
}
|
| 786 |
+
if (parsedUrl.username || parsedUrl.password) {
|
| 787 |
+
opts.auth = `${parsedUrl.username}:${parsedUrl.password}`;
|
| 788 |
+
}
|
| 789 |
+
|
| 790 |
+
if (isIpcUrl) {
|
| 791 |
+
const parts = opts.path.split(':');
|
| 792 |
+
|
| 793 |
+
opts.socketPath = parts[0];
|
| 794 |
+
opts.path = parts[1];
|
| 795 |
+
}
|
| 796 |
+
|
| 797 |
+
let req;
|
| 798 |
+
|
| 799 |
+
if (opts.followRedirects) {
|
| 800 |
+
if (websocket._redirects === 0) {
|
| 801 |
+
websocket._originalIpc = isIpcUrl;
|
| 802 |
+
websocket._originalSecure = isSecure;
|
| 803 |
+
websocket._originalHostOrSocketPath = isIpcUrl
|
| 804 |
+
? opts.socketPath
|
| 805 |
+
: parsedUrl.host;
|
| 806 |
+
|
| 807 |
+
const headers = options && options.headers;
|
| 808 |
+
|
| 809 |
+
//
|
| 810 |
+
// Shallow copy the user provided options so that headers can be changed
|
| 811 |
+
// without mutating the original object.
|
| 812 |
+
//
|
| 813 |
+
options = { ...options, headers: {} };
|
| 814 |
+
|
| 815 |
+
if (headers) {
|
| 816 |
+
for (const [key, value] of Object.entries(headers)) {
|
| 817 |
+
options.headers[key.toLowerCase()] = value;
|
| 818 |
+
}
|
| 819 |
+
}
|
| 820 |
+
} else if (websocket.listenerCount('redirect') === 0) {
|
| 821 |
+
const isSameHost = isIpcUrl
|
| 822 |
+
? websocket._originalIpc
|
| 823 |
+
? opts.socketPath === websocket._originalHostOrSocketPath
|
| 824 |
+
: false
|
| 825 |
+
: websocket._originalIpc
|
| 826 |
+
? false
|
| 827 |
+
: parsedUrl.host === websocket._originalHostOrSocketPath;
|
| 828 |
+
|
| 829 |
+
if (!isSameHost || (websocket._originalSecure && !isSecure)) {
|
| 830 |
+
//
|
| 831 |
+
// Match curl 7.77.0 behavior and drop the following headers. These
|
| 832 |
+
// headers are also dropped when following a redirect to a subdomain.
|
| 833 |
+
//
|
| 834 |
+
delete opts.headers.authorization;
|
| 835 |
+
delete opts.headers.cookie;
|
| 836 |
+
|
| 837 |
+
if (!isSameHost) delete opts.headers.host;
|
| 838 |
+
|
| 839 |
+
opts.auth = undefined;
|
| 840 |
+
}
|
| 841 |
+
}
|
| 842 |
+
|
| 843 |
+
//
|
| 844 |
+
// Match curl 7.77.0 behavior and make the first `Authorization` header win.
|
| 845 |
+
// If the `Authorization` header is set, then there is nothing to do as it
|
| 846 |
+
// will take precedence.
|
| 847 |
+
//
|
| 848 |
+
if (opts.auth && !options.headers.authorization) {
|
| 849 |
+
options.headers.authorization =
|
| 850 |
+
'Basic ' + Buffer.from(opts.auth).toString('base64');
|
| 851 |
+
}
|
| 852 |
+
|
| 853 |
+
req = websocket._req = request(opts);
|
| 854 |
+
|
| 855 |
+
if (websocket._redirects) {
|
| 856 |
+
//
|
| 857 |
+
// Unlike what is done for the `'upgrade'` event, no early exit is
|
| 858 |
+
// triggered here if the user calls `websocket.close()` or
|
| 859 |
+
// `websocket.terminate()` from a listener of the `'redirect'` event. This
|
| 860 |
+
// is because the user can also call `request.destroy()` with an error
|
| 861 |
+
// before calling `websocket.close()` or `websocket.terminate()` and this
|
| 862 |
+
// would result in an error being emitted on the `request` object with no
|
| 863 |
+
// `'error'` event listeners attached.
|
| 864 |
+
//
|
| 865 |
+
websocket.emit('redirect', websocket.url, req);
|
| 866 |
+
}
|
| 867 |
+
} else {
|
| 868 |
+
req = websocket._req = request(opts);
|
| 869 |
+
}
|
| 870 |
+
|
| 871 |
+
if (opts.timeout) {
|
| 872 |
+
req.on('timeout', () => {
|
| 873 |
+
abortHandshake(websocket, req, 'Opening handshake has timed out');
|
| 874 |
+
});
|
| 875 |
+
}
|
| 876 |
+
|
| 877 |
+
req.on('error', (err) => {
|
| 878 |
+
if (req === null || req[kAborted]) return;
|
| 879 |
+
|
| 880 |
+
req = websocket._req = null;
|
| 881 |
+
emitErrorAndClose(websocket, err);
|
| 882 |
+
});
|
| 883 |
+
|
| 884 |
+
req.on('response', (res) => {
|
| 885 |
+
const location = res.headers.location;
|
| 886 |
+
const statusCode = res.statusCode;
|
| 887 |
+
|
| 888 |
+
if (
|
| 889 |
+
location &&
|
| 890 |
+
opts.followRedirects &&
|
| 891 |
+
statusCode >= 300 &&
|
| 892 |
+
statusCode < 400
|
| 893 |
+
) {
|
| 894 |
+
if (++websocket._redirects > opts.maxRedirects) {
|
| 895 |
+
abortHandshake(websocket, req, 'Maximum redirects exceeded');
|
| 896 |
+
return;
|
| 897 |
+
}
|
| 898 |
+
|
| 899 |
+
req.abort();
|
| 900 |
+
|
| 901 |
+
let addr;
|
| 902 |
+
|
| 903 |
+
try {
|
| 904 |
+
addr = new URL(location, address);
|
| 905 |
+
} catch (e) {
|
| 906 |
+
const err = new SyntaxError(`Invalid URL: ${location}`);
|
| 907 |
+
emitErrorAndClose(websocket, err);
|
| 908 |
+
return;
|
| 909 |
+
}
|
| 910 |
+
|
| 911 |
+
initAsClient(websocket, addr, protocols, options);
|
| 912 |
+
} else if (!websocket.emit('unexpected-response', req, res)) {
|
| 913 |
+
abortHandshake(
|
| 914 |
+
websocket,
|
| 915 |
+
req,
|
| 916 |
+
`Unexpected server response: ${res.statusCode}`
|
| 917 |
+
);
|
| 918 |
+
}
|
| 919 |
+
});
|
| 920 |
+
|
| 921 |
+
req.on('upgrade', (res, socket, head) => {
|
| 922 |
+
websocket.emit('upgrade', res);
|
| 923 |
+
|
| 924 |
+
//
|
| 925 |
+
// The user may have closed the connection from a listener of the
|
| 926 |
+
// `'upgrade'` event.
|
| 927 |
+
//
|
| 928 |
+
if (websocket.readyState !== WebSocket.CONNECTING) return;
|
| 929 |
+
|
| 930 |
+
req = websocket._req = null;
|
| 931 |
+
|
| 932 |
+
const upgrade = res.headers.upgrade;
|
| 933 |
+
|
| 934 |
+
if (upgrade === undefined || upgrade.toLowerCase() !== 'websocket') {
|
| 935 |
+
abortHandshake(websocket, socket, 'Invalid Upgrade header');
|
| 936 |
+
return;
|
| 937 |
+
}
|
| 938 |
+
|
| 939 |
+
const digest = createHash('sha1')
|
| 940 |
+
.update(key + GUID)
|
| 941 |
+
.digest('base64');
|
| 942 |
+
|
| 943 |
+
if (res.headers['sec-websocket-accept'] !== digest) {
|
| 944 |
+
abortHandshake(websocket, socket, 'Invalid Sec-WebSocket-Accept header');
|
| 945 |
+
return;
|
| 946 |
+
}
|
| 947 |
+
|
| 948 |
+
const serverProt = res.headers['sec-websocket-protocol'];
|
| 949 |
+
let protError;
|
| 950 |
+
|
| 951 |
+
if (serverProt !== undefined) {
|
| 952 |
+
if (!protocolSet.size) {
|
| 953 |
+
protError = 'Server sent a subprotocol but none was requested';
|
| 954 |
+
} else if (!protocolSet.has(serverProt)) {
|
| 955 |
+
protError = 'Server sent an invalid subprotocol';
|
| 956 |
+
}
|
| 957 |
+
} else if (protocolSet.size) {
|
| 958 |
+
protError = 'Server sent no subprotocol';
|
| 959 |
+
}
|
| 960 |
+
|
| 961 |
+
if (protError) {
|
| 962 |
+
abortHandshake(websocket, socket, protError);
|
| 963 |
+
return;
|
| 964 |
+
}
|
| 965 |
+
|
| 966 |
+
if (serverProt) websocket._protocol = serverProt;
|
| 967 |
+
|
| 968 |
+
const secWebSocketExtensions = res.headers['sec-websocket-extensions'];
|
| 969 |
+
|
| 970 |
+
if (secWebSocketExtensions !== undefined) {
|
| 971 |
+
if (!perMessageDeflate) {
|
| 972 |
+
const message =
|
| 973 |
+
'Server sent a Sec-WebSocket-Extensions header but no extension ' +
|
| 974 |
+
'was requested';
|
| 975 |
+
abortHandshake(websocket, socket, message);
|
| 976 |
+
return;
|
| 977 |
+
}
|
| 978 |
+
|
| 979 |
+
let extensions;
|
| 980 |
+
|
| 981 |
+
try {
|
| 982 |
+
extensions = parse(secWebSocketExtensions);
|
| 983 |
+
} catch (err) {
|
| 984 |
+
const message = 'Invalid Sec-WebSocket-Extensions header';
|
| 985 |
+
abortHandshake(websocket, socket, message);
|
| 986 |
+
return;
|
| 987 |
+
}
|
| 988 |
+
|
| 989 |
+
const extensionNames = Object.keys(extensions);
|
| 990 |
+
|
| 991 |
+
if (
|
| 992 |
+
extensionNames.length !== 1 ||
|
| 993 |
+
extensionNames[0] !== PerMessageDeflate.extensionName
|
| 994 |
+
) {
|
| 995 |
+
const message = 'Server indicated an extension that was not requested';
|
| 996 |
+
abortHandshake(websocket, socket, message);
|
| 997 |
+
return;
|
| 998 |
+
}
|
| 999 |
+
|
| 1000 |
+
try {
|
| 1001 |
+
perMessageDeflate.accept(extensions[PerMessageDeflate.extensionName]);
|
| 1002 |
+
} catch (err) {
|
| 1003 |
+
const message = 'Invalid Sec-WebSocket-Extensions header';
|
| 1004 |
+
abortHandshake(websocket, socket, message);
|
| 1005 |
+
return;
|
| 1006 |
+
}
|
| 1007 |
+
|
| 1008 |
+
websocket._extensions[PerMessageDeflate.extensionName] =
|
| 1009 |
+
perMessageDeflate;
|
| 1010 |
+
}
|
| 1011 |
+
|
| 1012 |
+
websocket.setSocket(socket, head, {
|
| 1013 |
+
allowSynchronousEvents: opts.allowSynchronousEvents,
|
| 1014 |
+
generateMask: opts.generateMask,
|
| 1015 |
+
maxPayload: opts.maxPayload,
|
| 1016 |
+
skipUTF8Validation: opts.skipUTF8Validation
|
| 1017 |
+
});
|
| 1018 |
+
});
|
| 1019 |
+
|
| 1020 |
+
if (opts.finishRequest) {
|
| 1021 |
+
opts.finishRequest(req, websocket);
|
| 1022 |
+
} else {
|
| 1023 |
+
req.end();
|
| 1024 |
+
}
|
| 1025 |
+
}
|
| 1026 |
+
|
| 1027 |
+
/**
|
| 1028 |
+
* Emit the `'error'` and `'close'` events.
|
| 1029 |
+
*
|
| 1030 |
+
* @param {WebSocket} websocket The WebSocket instance
|
| 1031 |
+
* @param {Error} The error to emit
|
| 1032 |
+
* @private
|
| 1033 |
+
*/
|
| 1034 |
+
function emitErrorAndClose(websocket, err) {
|
| 1035 |
+
websocket._readyState = WebSocket.CLOSING;
|
| 1036 |
+
//
|
| 1037 |
+
// The following assignment is practically useless and is done only for
|
| 1038 |
+
// consistency.
|
| 1039 |
+
//
|
| 1040 |
+
websocket._errorEmitted = true;
|
| 1041 |
+
websocket.emit('error', err);
|
| 1042 |
+
websocket.emitClose();
|
| 1043 |
+
}
|
| 1044 |
+
|
| 1045 |
+
/**
|
| 1046 |
+
* Create a `net.Socket` and initiate a connection.
|
| 1047 |
+
*
|
| 1048 |
+
* @param {Object} options Connection options
|
| 1049 |
+
* @return {net.Socket} The newly created socket used to start the connection
|
| 1050 |
+
* @private
|
| 1051 |
+
*/
|
| 1052 |
+
function netConnect(options) {
|
| 1053 |
+
options.path = options.socketPath;
|
| 1054 |
+
return net.connect(options);
|
| 1055 |
+
}
|
| 1056 |
+
|
| 1057 |
+
/**
|
| 1058 |
+
* Create a `tls.TLSSocket` and initiate a connection.
|
| 1059 |
+
*
|
| 1060 |
+
* @param {Object} options Connection options
|
| 1061 |
+
* @return {tls.TLSSocket} The newly created socket used to start the connection
|
| 1062 |
+
* @private
|
| 1063 |
+
*/
|
| 1064 |
+
function tlsConnect(options) {
|
| 1065 |
+
options.path = undefined;
|
| 1066 |
+
|
| 1067 |
+
if (!options.servername && options.servername !== '') {
|
| 1068 |
+
options.servername = net.isIP(options.host) ? '' : options.host;
|
| 1069 |
+
}
|
| 1070 |
+
|
| 1071 |
+
return tls.connect(options);
|
| 1072 |
+
}
|
| 1073 |
+
|
| 1074 |
+
/**
|
| 1075 |
+
* Abort the handshake and emit an error.
|
| 1076 |
+
*
|
| 1077 |
+
* @param {WebSocket} websocket The WebSocket instance
|
| 1078 |
+
* @param {(http.ClientRequest|net.Socket|tls.Socket)} stream The request to
|
| 1079 |
+
* abort or the socket to destroy
|
| 1080 |
+
* @param {String} message The error message
|
| 1081 |
+
* @private
|
| 1082 |
+
*/
|
| 1083 |
+
function abortHandshake(websocket, stream, message) {
|
| 1084 |
+
websocket._readyState = WebSocket.CLOSING;
|
| 1085 |
+
|
| 1086 |
+
const err = new Error(message);
|
| 1087 |
+
Error.captureStackTrace(err, abortHandshake);
|
| 1088 |
+
|
| 1089 |
+
if (stream.setHeader) {
|
| 1090 |
+
stream[kAborted] = true;
|
| 1091 |
+
stream.abort();
|
| 1092 |
+
|
| 1093 |
+
if (stream.socket && !stream.socket.destroyed) {
|
| 1094 |
+
//
|
| 1095 |
+
// On Node.js >= 14.3.0 `request.abort()` does not destroy the socket if
|
| 1096 |
+
// called after the request completed. See
|
| 1097 |
+
// https://github.com/websockets/ws/issues/1869.
|
| 1098 |
+
//
|
| 1099 |
+
stream.socket.destroy();
|
| 1100 |
+
}
|
| 1101 |
+
|
| 1102 |
+
process.nextTick(emitErrorAndClose, websocket, err);
|
| 1103 |
+
} else {
|
| 1104 |
+
stream.destroy(err);
|
| 1105 |
+
stream.once('error', websocket.emit.bind(websocket, 'error'));
|
| 1106 |
+
stream.once('close', websocket.emitClose.bind(websocket));
|
| 1107 |
+
}
|
| 1108 |
+
}
|
| 1109 |
+
|
| 1110 |
+
/**
|
| 1111 |
+
* Handle cases where the `ping()`, `pong()`, or `send()` methods are called
|
| 1112 |
+
* when the `readyState` attribute is `CLOSING` or `CLOSED`.
|
| 1113 |
+
*
|
| 1114 |
+
* @param {WebSocket} websocket The WebSocket instance
|
| 1115 |
+
* @param {*} [data] The data to send
|
| 1116 |
+
* @param {Function} [cb] Callback
|
| 1117 |
+
* @private
|
| 1118 |
+
*/
|
| 1119 |
+
function sendAfterClose(websocket, data, cb) {
|
| 1120 |
+
if (data) {
|
| 1121 |
+
const length = isBlob(data) ? data.size : toBuffer(data).length;
|
| 1122 |
+
|
| 1123 |
+
//
|
| 1124 |
+
// The `_bufferedAmount` property is used only when the peer is a client and
|
| 1125 |
+
// the opening handshake fails. Under these circumstances, in fact, the
|
| 1126 |
+
// `setSocket()` method is not called, so the `_socket` and `_sender`
|
| 1127 |
+
// properties are set to `null`.
|
| 1128 |
+
//
|
| 1129 |
+
if (websocket._socket) websocket._sender._bufferedBytes += length;
|
| 1130 |
+
else websocket._bufferedAmount += length;
|
| 1131 |
+
}
|
| 1132 |
+
|
| 1133 |
+
if (cb) {
|
| 1134 |
+
const err = new Error(
|
| 1135 |
+
`WebSocket is not open: readyState ${websocket.readyState} ` +
|
| 1136 |
+
`(${readyStates[websocket.readyState]})`
|
| 1137 |
+
);
|
| 1138 |
+
process.nextTick(cb, err);
|
| 1139 |
+
}
|
| 1140 |
+
}
|
| 1141 |
+
|
| 1142 |
+
/**
|
| 1143 |
+
* The listener of the `Receiver` `'conclude'` event.
|
| 1144 |
+
*
|
| 1145 |
+
* @param {Number} code The status code
|
| 1146 |
+
* @param {Buffer} reason The reason for closing
|
| 1147 |
+
* @private
|
| 1148 |
+
*/
|
| 1149 |
+
function receiverOnConclude(code, reason) {
|
| 1150 |
+
const websocket = this[kWebSocket];
|
| 1151 |
+
|
| 1152 |
+
websocket._closeFrameReceived = true;
|
| 1153 |
+
websocket._closeMessage = reason;
|
| 1154 |
+
websocket._closeCode = code;
|
| 1155 |
+
|
| 1156 |
+
if (websocket._socket[kWebSocket] === undefined) return;
|
| 1157 |
+
|
| 1158 |
+
websocket._socket.removeListener('data', socketOnData);
|
| 1159 |
+
process.nextTick(resume, websocket._socket);
|
| 1160 |
+
|
| 1161 |
+
if (code === 1005) websocket.close();
|
| 1162 |
+
else websocket.close(code, reason);
|
| 1163 |
+
}
|
| 1164 |
+
|
| 1165 |
+
/**
|
| 1166 |
+
* The listener of the `Receiver` `'drain'` event.
|
| 1167 |
+
*
|
| 1168 |
+
* @private
|
| 1169 |
+
*/
|
| 1170 |
+
function receiverOnDrain() {
|
| 1171 |
+
const websocket = this[kWebSocket];
|
| 1172 |
+
|
| 1173 |
+
if (!websocket.isPaused) websocket._socket.resume();
|
| 1174 |
+
}
|
| 1175 |
+
|
| 1176 |
+
/**
|
| 1177 |
+
* The listener of the `Receiver` `'error'` event.
|
| 1178 |
+
*
|
| 1179 |
+
* @param {(RangeError|Error)} err The emitted error
|
| 1180 |
+
* @private
|
| 1181 |
+
*/
|
| 1182 |
+
function receiverOnError(err) {
|
| 1183 |
+
const websocket = this[kWebSocket];
|
| 1184 |
+
|
| 1185 |
+
if (websocket._socket[kWebSocket] !== undefined) {
|
| 1186 |
+
websocket._socket.removeListener('data', socketOnData);
|
| 1187 |
+
|
| 1188 |
+
//
|
| 1189 |
+
// On Node.js < 14.0.0 the `'error'` event is emitted synchronously. See
|
| 1190 |
+
// https://github.com/websockets/ws/issues/1940.
|
| 1191 |
+
//
|
| 1192 |
+
process.nextTick(resume, websocket._socket);
|
| 1193 |
+
|
| 1194 |
+
websocket.close(err[kStatusCode]);
|
| 1195 |
+
}
|
| 1196 |
+
|
| 1197 |
+
if (!websocket._errorEmitted) {
|
| 1198 |
+
websocket._errorEmitted = true;
|
| 1199 |
+
websocket.emit('error', err);
|
| 1200 |
+
}
|
| 1201 |
+
}
|
| 1202 |
+
|
| 1203 |
+
/**
|
| 1204 |
+
* The listener of the `Receiver` `'finish'` event.
|
| 1205 |
+
*
|
| 1206 |
+
* @private
|
| 1207 |
+
*/
|
| 1208 |
+
function receiverOnFinish() {
|
| 1209 |
+
this[kWebSocket].emitClose();
|
| 1210 |
+
}
|
| 1211 |
+
|
| 1212 |
+
/**
|
| 1213 |
+
* The listener of the `Receiver` `'message'` event.
|
| 1214 |
+
*
|
| 1215 |
+
* @param {Buffer|ArrayBuffer|Buffer[])} data The message
|
| 1216 |
+
* @param {Boolean} isBinary Specifies whether the message is binary or not
|
| 1217 |
+
* @private
|
| 1218 |
+
*/
|
| 1219 |
+
function receiverOnMessage(data, isBinary) {
|
| 1220 |
+
this[kWebSocket].emit('message', data, isBinary);
|
| 1221 |
+
}
|
| 1222 |
+
|
| 1223 |
+
/**
|
| 1224 |
+
* The listener of the `Receiver` `'ping'` event.
|
| 1225 |
+
*
|
| 1226 |
+
* @param {Buffer} data The data included in the ping frame
|
| 1227 |
+
* @private
|
| 1228 |
+
*/
|
| 1229 |
+
function receiverOnPing(data) {
|
| 1230 |
+
const websocket = this[kWebSocket];
|
| 1231 |
+
|
| 1232 |
+
if (websocket._autoPong) websocket.pong(data, !this._isServer, NOOP);
|
| 1233 |
+
websocket.emit('ping', data);
|
| 1234 |
+
}
|
| 1235 |
+
|
| 1236 |
+
/**
|
| 1237 |
+
* The listener of the `Receiver` `'pong'` event.
|
| 1238 |
+
*
|
| 1239 |
+
* @param {Buffer} data The data included in the pong frame
|
| 1240 |
+
* @private
|
| 1241 |
+
*/
|
| 1242 |
+
function receiverOnPong(data) {
|
| 1243 |
+
this[kWebSocket].emit('pong', data);
|
| 1244 |
+
}
|
| 1245 |
+
|
| 1246 |
+
/**
|
| 1247 |
+
* Resume a readable stream
|
| 1248 |
+
*
|
| 1249 |
+
* @param {Readable} stream The readable stream
|
| 1250 |
+
* @private
|
| 1251 |
+
*/
|
| 1252 |
+
function resume(stream) {
|
| 1253 |
+
stream.resume();
|
| 1254 |
+
}
|
| 1255 |
+
|
| 1256 |
+
/**
|
| 1257 |
+
* The `Sender` error event handler.
|
| 1258 |
+
*
|
| 1259 |
+
* @param {Error} The error
|
| 1260 |
+
* @private
|
| 1261 |
+
*/
|
| 1262 |
+
function senderOnError(err) {
|
| 1263 |
+
const websocket = this[kWebSocket];
|
| 1264 |
+
|
| 1265 |
+
if (websocket.readyState === WebSocket.CLOSED) return;
|
| 1266 |
+
if (websocket.readyState === WebSocket.OPEN) {
|
| 1267 |
+
websocket._readyState = WebSocket.CLOSING;
|
| 1268 |
+
setCloseTimer(websocket);
|
| 1269 |
+
}
|
| 1270 |
+
|
| 1271 |
+
//
|
| 1272 |
+
// `socket.end()` is used instead of `socket.destroy()` to allow the other
|
| 1273 |
+
// peer to finish sending queued data. There is no need to set a timer here
|
| 1274 |
+
// because `CLOSING` means that it is already set or not needed.
|
| 1275 |
+
//
|
| 1276 |
+
this._socket.end();
|
| 1277 |
+
|
| 1278 |
+
if (!websocket._errorEmitted) {
|
| 1279 |
+
websocket._errorEmitted = true;
|
| 1280 |
+
websocket.emit('error', err);
|
| 1281 |
+
}
|
| 1282 |
+
}
|
| 1283 |
+
|
| 1284 |
+
/**
|
| 1285 |
+
* Set a timer to destroy the underlying raw socket of a WebSocket.
|
| 1286 |
+
*
|
| 1287 |
+
* @param {WebSocket} websocket The WebSocket instance
|
| 1288 |
+
* @private
|
| 1289 |
+
*/
|
| 1290 |
+
function setCloseTimer(websocket) {
|
| 1291 |
+
websocket._closeTimer = setTimeout(
|
| 1292 |
+
websocket._socket.destroy.bind(websocket._socket),
|
| 1293 |
+
closeTimeout
|
| 1294 |
+
);
|
| 1295 |
+
}
|
| 1296 |
+
|
| 1297 |
+
/**
|
| 1298 |
+
* The listener of the socket `'close'` event.
|
| 1299 |
+
*
|
| 1300 |
+
* @private
|
| 1301 |
+
*/
|
| 1302 |
+
function socketOnClose() {
|
| 1303 |
+
const websocket = this[kWebSocket];
|
| 1304 |
+
|
| 1305 |
+
this.removeListener('close', socketOnClose);
|
| 1306 |
+
this.removeListener('data', socketOnData);
|
| 1307 |
+
this.removeListener('end', socketOnEnd);
|
| 1308 |
+
|
| 1309 |
+
websocket._readyState = WebSocket.CLOSING;
|
| 1310 |
+
|
| 1311 |
+
let chunk;
|
| 1312 |
+
|
| 1313 |
+
//
|
| 1314 |
+
// The close frame might not have been received or the `'end'` event emitted,
|
| 1315 |
+
// for example, if the socket was destroyed due to an error. Ensure that the
|
| 1316 |
+
// `receiver` stream is closed after writing any remaining buffered data to
|
| 1317 |
+
// it. If the readable side of the socket is in flowing mode then there is no
|
| 1318 |
+
// buffered data as everything has been already written and `readable.read()`
|
| 1319 |
+
// will return `null`. If instead, the socket is paused, any possible buffered
|
| 1320 |
+
// data will be read as a single chunk.
|
| 1321 |
+
//
|
| 1322 |
+
if (
|
| 1323 |
+
!this._readableState.endEmitted &&
|
| 1324 |
+
!websocket._closeFrameReceived &&
|
| 1325 |
+
!websocket._receiver._writableState.errorEmitted &&
|
| 1326 |
+
(chunk = websocket._socket.read()) !== null
|
| 1327 |
+
) {
|
| 1328 |
+
websocket._receiver.write(chunk);
|
| 1329 |
+
}
|
| 1330 |
+
|
| 1331 |
+
websocket._receiver.end();
|
| 1332 |
+
|
| 1333 |
+
this[kWebSocket] = undefined;
|
| 1334 |
+
|
| 1335 |
+
clearTimeout(websocket._closeTimer);
|
| 1336 |
+
|
| 1337 |
+
if (
|
| 1338 |
+
websocket._receiver._writableState.finished ||
|
| 1339 |
+
websocket._receiver._writableState.errorEmitted
|
| 1340 |
+
) {
|
| 1341 |
+
websocket.emitClose();
|
| 1342 |
+
} else {
|
| 1343 |
+
websocket._receiver.on('error', receiverOnFinish);
|
| 1344 |
+
websocket._receiver.on('finish', receiverOnFinish);
|
| 1345 |
+
}
|
| 1346 |
+
}
|
| 1347 |
+
|
| 1348 |
+
/**
|
| 1349 |
+
* The listener of the socket `'data'` event.
|
| 1350 |
+
*
|
| 1351 |
+
* @param {Buffer} chunk A chunk of data
|
| 1352 |
+
* @private
|
| 1353 |
+
*/
|
| 1354 |
+
function socketOnData(chunk) {
|
| 1355 |
+
if (!this[kWebSocket]._receiver.write(chunk)) {
|
| 1356 |
+
this.pause();
|
| 1357 |
+
}
|
| 1358 |
+
}
|
| 1359 |
+
|
| 1360 |
+
/**
|
| 1361 |
+
* The listener of the socket `'end'` event.
|
| 1362 |
+
*
|
| 1363 |
+
* @private
|
| 1364 |
+
*/
|
| 1365 |
+
function socketOnEnd() {
|
| 1366 |
+
const websocket = this[kWebSocket];
|
| 1367 |
+
|
| 1368 |
+
websocket._readyState = WebSocket.CLOSING;
|
| 1369 |
+
websocket._receiver.end();
|
| 1370 |
+
this.end();
|
| 1371 |
+
}
|
| 1372 |
+
|
| 1373 |
+
/**
|
| 1374 |
+
* The listener of the socket `'error'` event.
|
| 1375 |
+
*
|
| 1376 |
+
* @private
|
| 1377 |
+
*/
|
| 1378 |
+
function socketOnError() {
|
| 1379 |
+
const websocket = this[kWebSocket];
|
| 1380 |
+
|
| 1381 |
+
this.removeListener('error', socketOnError);
|
| 1382 |
+
this.on('error', NOOP);
|
| 1383 |
+
|
| 1384 |
+
if (websocket) {
|
| 1385 |
+
websocket._readyState = WebSocket.CLOSING;
|
| 1386 |
+
this.destroy();
|
| 1387 |
+
}
|
| 1388 |
+
}
|
platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/src/middleware/auth.ts
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { FastifyRequest, FastifyReply } from "fastify";
|
| 2 |
+
|
| 3 |
+
export const apiKeyAuth =
|
| 4 |
+
(config: any) =>
|
| 5 |
+
async (req: FastifyRequest, reply: FastifyReply, done: () => void) => {
|
| 6 |
+
// Public endpoints that don't require authentication
|
| 7 |
+
if (["/", "/health"].includes(req.url) || req.url.startsWith("/ui")) {
|
| 8 |
+
return done();
|
| 9 |
+
}
|
| 10 |
+
|
| 11 |
+
const apiKey = config.APIKEY;
|
| 12 |
+
if (!apiKey) {
|
| 13 |
+
// If no API key is set, enable CORS for local
|
| 14 |
+
const allowedOrigins = [
|
| 15 |
+
`http://127.0.0.1:${config.PORT || 3456}`,
|
| 16 |
+
`http://localhost:${config.PORT || 3456}`,
|
| 17 |
+
];
|
| 18 |
+
if (req.headers.origin && !allowedOrigins.includes(req.headers.origin)) {
|
| 19 |
+
reply.status(403).send("CORS not allowed for this origin");
|
| 20 |
+
return;
|
| 21 |
+
} else {
|
| 22 |
+
reply.header('Access-Control-Allow-Origin', `http://127.0.0.1:${config.PORT || 3456}`);
|
| 23 |
+
reply.header('Access-Control-Allow-Origin', `http://localhost:${config.PORT || 3456}`);
|
| 24 |
+
}
|
| 25 |
+
return done();
|
| 26 |
+
}
|
| 27 |
+
const isConfigEndpoint = req.url.startsWith("/api/config");
|
| 28 |
+
const isRestartEndpoint = req.url === "/api/restart";
|
| 29 |
+
|
| 30 |
+
// For config endpoints and restart endpoint, we implement granular access control
|
| 31 |
+
if (isConfigEndpoint || isRestartEndpoint) {
|
| 32 |
+
// Attach access level to request for later use
|
| 33 |
+
(req as any).accessLevel = "restricted";
|
| 34 |
+
|
| 35 |
+
// If no API key is set in config, allow restricted access
|
| 36 |
+
if (!apiKey) {
|
| 37 |
+
(req as any).accessLevel = "restricted";
|
| 38 |
+
return done();
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
// If API key is set, check authentication
|
| 42 |
+
const authHeaderValue =
|
| 43 |
+
req.headers.authorization || req.headers["x-api-key"];
|
| 44 |
+
const authKey: string = Array.isArray(authHeaderValue)
|
| 45 |
+
? authHeaderValue[0]
|
| 46 |
+
: authHeaderValue || "";
|
| 47 |
+
|
| 48 |
+
if (!authKey) {
|
| 49 |
+
(req as any).accessLevel = "restricted";
|
| 50 |
+
return done();
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
let token = "";
|
| 54 |
+
if (authKey.startsWith("Bearer")) {
|
| 55 |
+
token = authKey.split(" ")[1];
|
| 56 |
+
} else {
|
| 57 |
+
token = authKey;
|
| 58 |
+
}
|
| 59 |
+
|
| 60 |
+
if (token !== apiKey) {
|
| 61 |
+
(req as any).accessLevel = "restricted";
|
| 62 |
+
return done();
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
// Full access for authenticated users
|
| 66 |
+
(req as any).accessLevel = "full";
|
| 67 |
+
return done();
|
| 68 |
+
}
|
| 69 |
+
|
| 70 |
+
const authHeaderValue =
|
| 71 |
+
req.headers.authorization || req.headers["x-api-key"];
|
| 72 |
+
const authKey: string = Array.isArray(authHeaderValue)
|
| 73 |
+
? authHeaderValue[0]
|
| 74 |
+
: authHeaderValue || "";
|
| 75 |
+
if (!authKey) {
|
| 76 |
+
reply.status(401).send("APIKEY is missing");
|
| 77 |
+
return;
|
| 78 |
+
}
|
| 79 |
+
let token = "";
|
| 80 |
+
if (authKey.startsWith("Bearer")) {
|
| 81 |
+
token = authKey.split(" ")[1];
|
| 82 |
+
} else {
|
| 83 |
+
token = authKey;
|
| 84 |
+
}
|
| 85 |
+
|
| 86 |
+
if (token !== apiKey) {
|
| 87 |
+
reply.status(401).send("Invalid API key");
|
| 88 |
+
return;
|
| 89 |
+
}
|
| 90 |
+
|
| 91 |
+
done();
|
| 92 |
+
};
|
platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/src/utils/cache.ts
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// LRU cache for session usage
|
| 2 |
+
|
| 3 |
+
export interface Usage {
|
| 4 |
+
input_tokens: number;
|
| 5 |
+
output_tokens: number;
|
| 6 |
+
}
|
| 7 |
+
|
| 8 |
+
class LRUCache<K, V> {
|
| 9 |
+
private capacity: number;
|
| 10 |
+
private cache: Map<K, V>;
|
| 11 |
+
|
| 12 |
+
constructor(capacity: number) {
|
| 13 |
+
this.capacity = capacity;
|
| 14 |
+
this.cache = new Map<K, V>();
|
| 15 |
+
}
|
| 16 |
+
|
| 17 |
+
get(key: K): V | undefined {
|
| 18 |
+
if (!this.cache.has(key)) {
|
| 19 |
+
return undefined;
|
| 20 |
+
}
|
| 21 |
+
const value = this.cache.get(key) as V;
|
| 22 |
+
// Move to end to mark as recently used
|
| 23 |
+
this.cache.delete(key);
|
| 24 |
+
this.cache.set(key, value);
|
| 25 |
+
return value;
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
put(key: K, value: V): void {
|
| 29 |
+
if (this.cache.has(key)) {
|
| 30 |
+
// If key exists, delete it to update its position
|
| 31 |
+
this.cache.delete(key);
|
| 32 |
+
} else if (this.cache.size >= this.capacity) {
|
| 33 |
+
// If cache is full, delete the least recently used item
|
| 34 |
+
const leastRecentlyUsedKey = this.cache.keys().next().value;
|
| 35 |
+
if (leastRecentlyUsedKey !== undefined) {
|
| 36 |
+
this.cache.delete(leastRecentlyUsedKey);
|
| 37 |
+
}
|
| 38 |
+
}
|
| 39 |
+
this.cache.set(key, value);
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
values(): V[] {
|
| 43 |
+
return Array.from(this.cache.values());
|
| 44 |
+
}
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
export const sessionUsageCache = new LRUCache<string, Usage>(100);
|
platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/src/utils/close.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { isServiceRunning, cleanupPidFile, getReferenceCount } from './processCheck';
|
| 2 |
+
import { readFileSync } from 'fs';
|
| 3 |
+
import { HOME_DIR } from '../constants';
|
| 4 |
+
import { join } from 'path';
|
| 5 |
+
|
| 6 |
+
export async function closeService() {
|
| 7 |
+
const PID_FILE = join(HOME_DIR, '.claude-code-router.pid');
|
| 8 |
+
|
| 9 |
+
if (!isServiceRunning()) {
|
| 10 |
+
console.log("No service is currently running.");
|
| 11 |
+
return;
|
| 12 |
+
}
|
| 13 |
+
|
| 14 |
+
if (getReferenceCount() > 0) {
|
| 15 |
+
return;
|
| 16 |
+
}
|
| 17 |
+
|
| 18 |
+
try {
|
| 19 |
+
const pid = parseInt(readFileSync(PID_FILE, 'utf-8'));
|
| 20 |
+
process.kill(pid);
|
| 21 |
+
cleanupPidFile();
|
| 22 |
+
console.log("claude code router service has been successfully stopped.");
|
| 23 |
+
} catch (e) {
|
| 24 |
+
console.log("Failed to stop the service. It may have already been stopped.");
|
| 25 |
+
cleanupPidFile();
|
| 26 |
+
}
|
| 27 |
+
}
|
platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/src/utils/codeCommand.ts
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { spawn, type StdioOptions } from "child_process";
|
| 2 |
+
import { readConfigFile } from ".";
|
| 3 |
+
import { closeService } from "./close";
|
| 4 |
+
import {
|
| 5 |
+
decrementReferenceCount,
|
| 6 |
+
incrementReferenceCount,
|
| 7 |
+
} from "./processCheck";
|
| 8 |
+
|
| 9 |
+
export async function executeCodeCommand(args: string[] = []) {
|
| 10 |
+
// Set environment variables
|
| 11 |
+
const config = await readConfigFile();
|
| 12 |
+
const env: Record<string, string> = {
|
| 13 |
+
...process.env,
|
| 14 |
+
ANTHROPIC_AUTH_TOKEN: config?.APIKEY || "test",
|
| 15 |
+
ANTHROPIC_API_KEY: '',
|
| 16 |
+
ANTHROPIC_BASE_URL: `http://127.0.0.1:${config.PORT || 3456}`,
|
| 17 |
+
API_TIMEOUT_MS: String(config.API_TIMEOUT_MS ?? 600000), // Default to 10 minutes if not set
|
| 18 |
+
};
|
| 19 |
+
let settingsFlag: Record<string, any> | undefined;
|
| 20 |
+
if (config?.StatusLine?.enabled) {
|
| 21 |
+
settingsFlag = {
|
| 22 |
+
statusLine: {
|
| 23 |
+
type: "command",
|
| 24 |
+
command: "ccr statusline",
|
| 25 |
+
padding: 0,
|
| 26 |
+
}
|
| 27 |
+
}
|
| 28 |
+
args.push(`--settings=${JSON.stringify(settingsFlag)}`);
|
| 29 |
+
}
|
| 30 |
+
|
| 31 |
+
// Non-interactive mode for automation environments
|
| 32 |
+
if (config.NON_INTERACTIVE_MODE) {
|
| 33 |
+
env.CI = "true";
|
| 34 |
+
env.FORCE_COLOR = "0";
|
| 35 |
+
env.NODE_NO_READLINE = "1";
|
| 36 |
+
env.TERM = "dumb";
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
// Set ANTHROPIC_SMALL_FAST_MODEL if it exists in config
|
| 40 |
+
if (config?.ANTHROPIC_SMALL_FAST_MODEL) {
|
| 41 |
+
env.ANTHROPIC_SMALL_FAST_MODEL = config.ANTHROPIC_SMALL_FAST_MODEL;
|
| 42 |
+
}
|
| 43 |
+
|
| 44 |
+
// if (config?.APIKEY) {
|
| 45 |
+
// env.ANTHROPIC_API_KEY = config.APIKEY;
|
| 46 |
+
// delete env.ANTHROPIC_AUTH_TOKEN;
|
| 47 |
+
// }
|
| 48 |
+
|
| 49 |
+
// Increment reference count when command starts
|
| 50 |
+
incrementReferenceCount();
|
| 51 |
+
|
| 52 |
+
// Execute claude command
|
| 53 |
+
const claudePath = config?.CLAUDE_PATH || process.env.CLAUDE_PATH || "claude";
|
| 54 |
+
|
| 55 |
+
// Properly join arguments to preserve spaces in quotes
|
| 56 |
+
// Wrap each argument in double quotes to preserve single and double quotes inside arguments
|
| 57 |
+
const joinedArgs =
|
| 58 |
+
args.length > 0
|
| 59 |
+
? args.map((arg) => `"${arg.replace(/\"/g, '\\"')}"`).join(" ")
|
| 60 |
+
: "";
|
| 61 |
+
|
| 62 |
+
// 🔥 CONFIG-DRIVEN: stdio configuration based on environment
|
| 63 |
+
const stdioConfig: StdioOptions = config.NON_INTERACTIVE_MODE
|
| 64 |
+
? ["pipe", "inherit", "inherit"] // Pipe stdin for non-interactive
|
| 65 |
+
: "inherit"; // Default inherited behavior
|
| 66 |
+
|
| 67 |
+
const claudeProcess = spawn(
|
| 68 |
+
claudePath + (joinedArgs ? ` ${joinedArgs}` : ""),
|
| 69 |
+
[],
|
| 70 |
+
{
|
| 71 |
+
env,
|
| 72 |
+
stdio: stdioConfig,
|
| 73 |
+
shell: true,
|
| 74 |
+
}
|
| 75 |
+
);
|
| 76 |
+
|
| 77 |
+
// Close stdin for non-interactive mode
|
| 78 |
+
if (config.NON_INTERACTIVE_MODE) {
|
| 79 |
+
claudeProcess.stdin?.end();
|
| 80 |
+
}
|
| 81 |
+
|
| 82 |
+
claudeProcess.on("error", (error) => {
|
| 83 |
+
console.error("Failed to start claude command:", error.message);
|
| 84 |
+
console.log(
|
| 85 |
+
"Make sure Claude Code is installed: npm install -g @anthropic-ai/claude-code"
|
| 86 |
+
);
|
| 87 |
+
decrementReferenceCount();
|
| 88 |
+
process.exit(1);
|
| 89 |
+
});
|
| 90 |
+
|
| 91 |
+
claudeProcess.on("close", (code) => {
|
| 92 |
+
decrementReferenceCount();
|
| 93 |
+
closeService();
|
| 94 |
+
process.exit(code || 0);
|
| 95 |
+
});
|
| 96 |
+
}
|
platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/src/utils/index.ts
ADDED
|
@@ -0,0 +1,167 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import fs from "node:fs/promises";
|
| 2 |
+
import readline from "node:readline";
|
| 3 |
+
import JSON5 from "json5";
|
| 4 |
+
import path from "node:path";
|
| 5 |
+
import {
|
| 6 |
+
CONFIG_FILE,
|
| 7 |
+
DEFAULT_CONFIG,
|
| 8 |
+
HOME_DIR,
|
| 9 |
+
PLUGINS_DIR,
|
| 10 |
+
} from "../constants";
|
| 11 |
+
import { cleanupLogFiles } from "./logCleanup";
|
| 12 |
+
|
| 13 |
+
// Function to interpolate environment variables in config values
|
| 14 |
+
const interpolateEnvVars = (obj: any): any => {
|
| 15 |
+
if (typeof obj === "string") {
|
| 16 |
+
// Replace $VAR_NAME or ${VAR_NAME} with environment variable values
|
| 17 |
+
return obj.replace(/\$\{([^}]+)\}|\$([A-Z_][A-Z0-9_]*)/g, (match, braced, unbraced) => {
|
| 18 |
+
const varName = braced || unbraced;
|
| 19 |
+
return process.env[varName] || match; // Keep original if env var doesn't exist
|
| 20 |
+
});
|
| 21 |
+
} else if (Array.isArray(obj)) {
|
| 22 |
+
return obj.map(interpolateEnvVars);
|
| 23 |
+
} else if (obj !== null && typeof obj === "object") {
|
| 24 |
+
const result: any = {};
|
| 25 |
+
for (const [key, value] of Object.entries(obj)) {
|
| 26 |
+
result[key] = interpolateEnvVars(value);
|
| 27 |
+
}
|
| 28 |
+
return result;
|
| 29 |
+
}
|
| 30 |
+
return obj;
|
| 31 |
+
};
|
| 32 |
+
|
| 33 |
+
const ensureDir = async (dir_path: string) => {
|
| 34 |
+
try {
|
| 35 |
+
await fs.access(dir_path);
|
| 36 |
+
} catch {
|
| 37 |
+
await fs.mkdir(dir_path, { recursive: true });
|
| 38 |
+
}
|
| 39 |
+
};
|
| 40 |
+
|
| 41 |
+
export const initDir = async () => {
|
| 42 |
+
await ensureDir(HOME_DIR);
|
| 43 |
+
await ensureDir(PLUGINS_DIR);
|
| 44 |
+
await ensureDir(path.join(HOME_DIR, "logs"));
|
| 45 |
+
};
|
| 46 |
+
|
| 47 |
+
const createReadline = () => {
|
| 48 |
+
return readline.createInterface({
|
| 49 |
+
input: process.stdin,
|
| 50 |
+
output: process.stdout,
|
| 51 |
+
});
|
| 52 |
+
};
|
| 53 |
+
|
| 54 |
+
const question = (query: string): Promise<string> => {
|
| 55 |
+
return new Promise((resolve) => {
|
| 56 |
+
const rl = createReadline();
|
| 57 |
+
rl.question(query, (answer) => {
|
| 58 |
+
rl.close();
|
| 59 |
+
resolve(answer);
|
| 60 |
+
});
|
| 61 |
+
});
|
| 62 |
+
};
|
| 63 |
+
|
| 64 |
+
const confirm = async (query: string): Promise<boolean> => {
|
| 65 |
+
const answer = await question(query);
|
| 66 |
+
return answer.toLowerCase() !== "n";
|
| 67 |
+
};
|
| 68 |
+
|
| 69 |
+
export const readConfigFile = async () => {
|
| 70 |
+
try {
|
| 71 |
+
const config = await fs.readFile(CONFIG_FILE, "utf-8");
|
| 72 |
+
try {
|
| 73 |
+
// Try to parse with JSON5 first (which also supports standard JSON)
|
| 74 |
+
const parsedConfig = JSON5.parse(config);
|
| 75 |
+
// Interpolate environment variables in the parsed config
|
| 76 |
+
return interpolateEnvVars(parsedConfig);
|
| 77 |
+
} catch (parseError) {
|
| 78 |
+
console.error(`Failed to parse config file at ${CONFIG_FILE}`);
|
| 79 |
+
console.error("Error details:", (parseError as Error).message);
|
| 80 |
+
console.error("Please check your config file syntax.");
|
| 81 |
+
process.exit(1);
|
| 82 |
+
}
|
| 83 |
+
} catch (readError: any) {
|
| 84 |
+
if (readError.code === "ENOENT") {
|
| 85 |
+
// Config file doesn't exist, prompt user for initial setup
|
| 86 |
+
const name = await question("Enter Provider Name: ");
|
| 87 |
+
const APIKEY = await question("Enter Provider API KEY: ");
|
| 88 |
+
const baseUrl = await question("Enter Provider URL: ");
|
| 89 |
+
const model = await question("Enter MODEL Name: ");
|
| 90 |
+
const config = Object.assign({}, DEFAULT_CONFIG, {
|
| 91 |
+
Providers: [
|
| 92 |
+
{
|
| 93 |
+
name,
|
| 94 |
+
api_base_url: baseUrl,
|
| 95 |
+
api_key: APIKEY,
|
| 96 |
+
models: [model],
|
| 97 |
+
},
|
| 98 |
+
],
|
| 99 |
+
Router: {
|
| 100 |
+
default: `${name},${model}`,
|
| 101 |
+
},
|
| 102 |
+
});
|
| 103 |
+
await writeConfigFile(config);
|
| 104 |
+
return config;
|
| 105 |
+
} else {
|
| 106 |
+
console.error(`Failed to read config file at ${CONFIG_FILE}`);
|
| 107 |
+
console.error("Error details:", readError.message);
|
| 108 |
+
process.exit(1);
|
| 109 |
+
}
|
| 110 |
+
}
|
| 111 |
+
};
|
| 112 |
+
|
| 113 |
+
export const backupConfigFile = async () => {
|
| 114 |
+
try {
|
| 115 |
+
if (await fs.access(CONFIG_FILE).then(() => true).catch(() => false)) {
|
| 116 |
+
const timestamp = new Date().toISOString().replace(/[:.]/g, '-');
|
| 117 |
+
const backupPath = `${CONFIG_FILE}.${timestamp}.bak`;
|
| 118 |
+
await fs.copyFile(CONFIG_FILE, backupPath);
|
| 119 |
+
|
| 120 |
+
// Clean up old backups, keeping only the 3 most recent
|
| 121 |
+
try {
|
| 122 |
+
const configDir = path.dirname(CONFIG_FILE);
|
| 123 |
+
const configFileName = path.basename(CONFIG_FILE);
|
| 124 |
+
const files = await fs.readdir(configDir);
|
| 125 |
+
|
| 126 |
+
// Find all backup files for this config
|
| 127 |
+
const backupFiles = files
|
| 128 |
+
.filter(file => file.startsWith(configFileName) && file.endsWith('.bak'))
|
| 129 |
+
.sort()
|
| 130 |
+
.reverse(); // Sort in descending order (newest first)
|
| 131 |
+
|
| 132 |
+
// Delete all but the 3 most recent backups
|
| 133 |
+
if (backupFiles.length > 3) {
|
| 134 |
+
for (let i = 3; i < backupFiles.length; i++) {
|
| 135 |
+
const oldBackupPath = path.join(configDir, backupFiles[i]);
|
| 136 |
+
await fs.unlink(oldBackupPath);
|
| 137 |
+
}
|
| 138 |
+
}
|
| 139 |
+
} catch (cleanupError) {
|
| 140 |
+
console.warn("Failed to clean up old backups:", cleanupError);
|
| 141 |
+
}
|
| 142 |
+
|
| 143 |
+
return backupPath;
|
| 144 |
+
}
|
| 145 |
+
} catch (error) {
|
| 146 |
+
console.error("Failed to backup config file:", error);
|
| 147 |
+
}
|
| 148 |
+
return null;
|
| 149 |
+
};
|
| 150 |
+
|
| 151 |
+
export const writeConfigFile = async (config: any) => {
|
| 152 |
+
await ensureDir(HOME_DIR);
|
| 153 |
+
const configWithComment = `${JSON.stringify(config, null, 2)}`;
|
| 154 |
+
await fs.writeFile(CONFIG_FILE, configWithComment);
|
| 155 |
+
};
|
| 156 |
+
|
| 157 |
+
export const initConfig = async () => {
|
| 158 |
+
const config = await readConfigFile();
|
| 159 |
+
Object.assign(process.env, config);
|
| 160 |
+
return config;
|
| 161 |
+
};
|
| 162 |
+
|
| 163 |
+
// 导出日志清理函数
|
| 164 |
+
export { cleanupLogFiles };
|
| 165 |
+
|
| 166 |
+
// 导出更新功能
|
| 167 |
+
export { checkForUpdates, performUpdate } from "./update";
|
platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/src/utils/log.ts
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import fs from "node:fs";
|
| 2 |
+
import path from "node:path";
|
| 3 |
+
import { HOME_DIR } from "../constants";
|
| 4 |
+
|
| 5 |
+
const LOG_FILE = path.join(HOME_DIR, "claude-code-router.log");
|
| 6 |
+
|
| 7 |
+
// Ensure log directory exists
|
| 8 |
+
if (!fs.existsSync(HOME_DIR)) {
|
| 9 |
+
fs.mkdirSync(HOME_DIR, { recursive: true });
|
| 10 |
+
}
|
| 11 |
+
|
| 12 |
+
// Global variable to store the logging configuration
|
| 13 |
+
let isLogEnabled: boolean | null = null;
|
| 14 |
+
let logLevel: string = "info";
|
| 15 |
+
|
| 16 |
+
// Function to configure logging
|
| 17 |
+
export function configureLogging(config: { LOG?: boolean; LOG_LEVEL?: string }) {
|
| 18 |
+
isLogEnabled = config.LOG !== false; // Default to true if not explicitly set to false
|
| 19 |
+
logLevel = config.LOG_LEVEL || "debug";
|
| 20 |
+
}
|
| 21 |
+
|
| 22 |
+
export function log(...args: any[]) {
|
| 23 |
+
// If logging configuration hasn't been set, default to enabled
|
| 24 |
+
if (isLogEnabled === null) {
|
| 25 |
+
isLogEnabled = true;
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
if (!isLogEnabled) {
|
| 29 |
+
return;
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
const timestamp = new Date().toISOString();
|
| 33 |
+
const logMessage = `[${timestamp}] ${
|
| 34 |
+
Array.isArray(args)
|
| 35 |
+
? args
|
| 36 |
+
.map((arg) =>
|
| 37 |
+
typeof arg === "object" ? JSON.stringify(arg) : String(arg)
|
| 38 |
+
)
|
| 39 |
+
.join(" ")
|
| 40 |
+
: ""
|
| 41 |
+
}\n`;
|
| 42 |
+
|
| 43 |
+
// Append to log file
|
| 44 |
+
fs.appendFileSync(LOG_FILE, logMessage, "utf8");
|
| 45 |
+
}
|
platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/src/utils/logCleanup.ts
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import fs from "node:fs/promises";
|
| 2 |
+
import path from "node:path";
|
| 3 |
+
import { HOME_DIR } from "../constants";
|
| 4 |
+
|
| 5 |
+
/**
|
| 6 |
+
* Cleans up old log files, keeping only the most recent ones
|
| 7 |
+
* @param maxFiles - Maximum number of log files to keep (default: 9)
|
| 8 |
+
*/
|
| 9 |
+
export async function cleanupLogFiles(maxFiles: number = 9): Promise<void> {
|
| 10 |
+
try {
|
| 11 |
+
const logsDir = path.join(HOME_DIR, "logs");
|
| 12 |
+
|
| 13 |
+
// Check if logs directory exists
|
| 14 |
+
try {
|
| 15 |
+
await fs.access(logsDir);
|
| 16 |
+
} catch {
|
| 17 |
+
// Logs directory doesn't exist, nothing to clean up
|
| 18 |
+
return;
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
// Read all files in the logs directory
|
| 22 |
+
const files = await fs.readdir(logsDir);
|
| 23 |
+
|
| 24 |
+
// Filter for log files (files starting with 'ccr-' and ending with '.log')
|
| 25 |
+
const logFiles = files
|
| 26 |
+
.filter(file => file.startsWith('ccr-') && file.endsWith('.log'))
|
| 27 |
+
.sort()
|
| 28 |
+
.reverse(); // Sort in descending order (newest first)
|
| 29 |
+
|
| 30 |
+
// Delete files exceeding the maxFiles limit
|
| 31 |
+
if (logFiles.length > maxFiles) {
|
| 32 |
+
for (let i = maxFiles; i < logFiles.length; i++) {
|
| 33 |
+
const filePath = path.join(logsDir, logFiles[i]);
|
| 34 |
+
try {
|
| 35 |
+
await fs.unlink(filePath);
|
| 36 |
+
} catch (error) {
|
| 37 |
+
console.warn(`Failed to delete log file ${filePath}:`, error);
|
| 38 |
+
}
|
| 39 |
+
}
|
| 40 |
+
}
|
| 41 |
+
} catch (error) {
|
| 42 |
+
console.warn("Failed to clean up log files:", error);
|
| 43 |
+
}
|
| 44 |
+
}
|
platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/src/utils/processCheck.ts
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { existsSync, readFileSync, writeFileSync } from 'fs';
|
| 2 |
+
import { PID_FILE, REFERENCE_COUNT_FILE } from '../constants';
|
| 3 |
+
import { readConfigFile } from '.';
|
| 4 |
+
|
| 5 |
+
export function incrementReferenceCount() {
|
| 6 |
+
let count = 0;
|
| 7 |
+
if (existsSync(REFERENCE_COUNT_FILE)) {
|
| 8 |
+
count = parseInt(readFileSync(REFERENCE_COUNT_FILE, 'utf-8')) || 0;
|
| 9 |
+
}
|
| 10 |
+
count++;
|
| 11 |
+
writeFileSync(REFERENCE_COUNT_FILE, count.toString());
|
| 12 |
+
}
|
| 13 |
+
|
| 14 |
+
export function decrementReferenceCount() {
|
| 15 |
+
let count = 0;
|
| 16 |
+
if (existsSync(REFERENCE_COUNT_FILE)) {
|
| 17 |
+
count = parseInt(readFileSync(REFERENCE_COUNT_FILE, 'utf-8')) || 0;
|
| 18 |
+
}
|
| 19 |
+
count = Math.max(0, count - 1);
|
| 20 |
+
writeFileSync(REFERENCE_COUNT_FILE, count.toString());
|
| 21 |
+
}
|
| 22 |
+
|
| 23 |
+
export function getReferenceCount(): number {
|
| 24 |
+
if (!existsSync(REFERENCE_COUNT_FILE)) {
|
| 25 |
+
return 0;
|
| 26 |
+
}
|
| 27 |
+
return parseInt(readFileSync(REFERENCE_COUNT_FILE, 'utf-8')) || 0;
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
export function isServiceRunning(): boolean {
|
| 31 |
+
if (!existsSync(PID_FILE)) {
|
| 32 |
+
return false;
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
try {
|
| 36 |
+
const pid = parseInt(readFileSync(PID_FILE, 'utf-8'));
|
| 37 |
+
process.kill(pid, 0);
|
| 38 |
+
return true;
|
| 39 |
+
} catch (e) {
|
| 40 |
+
// Process not running, clean up pid file
|
| 41 |
+
cleanupPidFile();
|
| 42 |
+
return false;
|
| 43 |
+
}
|
| 44 |
+
}
|
| 45 |
+
|
| 46 |
+
export function savePid(pid: number) {
|
| 47 |
+
writeFileSync(PID_FILE, pid.toString());
|
| 48 |
+
}
|
| 49 |
+
|
| 50 |
+
export function cleanupPidFile() {
|
| 51 |
+
if (existsSync(PID_FILE)) {
|
| 52 |
+
try {
|
| 53 |
+
const fs = require('fs');
|
| 54 |
+
fs.unlinkSync(PID_FILE);
|
| 55 |
+
} catch (e) {
|
| 56 |
+
// Ignore cleanup errors
|
| 57 |
+
}
|
| 58 |
+
}
|
| 59 |
+
}
|
| 60 |
+
|
| 61 |
+
export function getServicePid(): number | null {
|
| 62 |
+
if (!existsSync(PID_FILE)) {
|
| 63 |
+
return null;
|
| 64 |
+
}
|
| 65 |
+
|
| 66 |
+
try {
|
| 67 |
+
const pid = parseInt(readFileSync(PID_FILE, 'utf-8'));
|
| 68 |
+
return isNaN(pid) ? null : pid;
|
| 69 |
+
} catch (e) {
|
| 70 |
+
return null;
|
| 71 |
+
}
|
| 72 |
+
}
|
| 73 |
+
|
| 74 |
+
export async function getServiceInfo() {
|
| 75 |
+
const pid = getServicePid();
|
| 76 |
+
const running = isServiceRunning();
|
| 77 |
+
const config = await readConfigFile();
|
| 78 |
+
const port = config.PORT || 3456;
|
| 79 |
+
|
| 80 |
+
return {
|
| 81 |
+
running,
|
| 82 |
+
pid,
|
| 83 |
+
port,
|
| 84 |
+
endpoint: `http://127.0.0.1:${port}`,
|
| 85 |
+
pidFile: PID_FILE,
|
| 86 |
+
referenceCount: getReferenceCount()
|
| 87 |
+
};
|
| 88 |
+
}
|
platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/src/utils/router.ts
ADDED
|
@@ -0,0 +1,178 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import {
|
| 2 |
+
MessageCreateParamsBase,
|
| 3 |
+
MessageParam,
|
| 4 |
+
Tool,
|
| 5 |
+
} from "@anthropic-ai/sdk/resources/messages";
|
| 6 |
+
import { get_encoding } from "tiktoken";
|
| 7 |
+
import { log } from "./log";
|
| 8 |
+
import { sessionUsageCache, Usage } from "./cache";
|
| 9 |
+
|
| 10 |
+
const enc = get_encoding("cl100k_base");
|
| 11 |
+
|
| 12 |
+
const calculateTokenCount = (
|
| 13 |
+
messages: MessageParam[],
|
| 14 |
+
system: any,
|
| 15 |
+
tools: Tool[]
|
| 16 |
+
) => {
|
| 17 |
+
let tokenCount = 0;
|
| 18 |
+
if (Array.isArray(messages)) {
|
| 19 |
+
messages.forEach((message) => {
|
| 20 |
+
if (typeof message.content === "string") {
|
| 21 |
+
tokenCount += enc.encode(message.content).length;
|
| 22 |
+
} else if (Array.isArray(message.content)) {
|
| 23 |
+
message.content.forEach((contentPart: any) => {
|
| 24 |
+
if (contentPart.type === "text") {
|
| 25 |
+
tokenCount += enc.encode(contentPart.text).length;
|
| 26 |
+
} else if (contentPart.type === "tool_use") {
|
| 27 |
+
tokenCount += enc.encode(JSON.stringify(contentPart.input)).length;
|
| 28 |
+
} else if (contentPart.type === "tool_result") {
|
| 29 |
+
tokenCount += enc.encode(
|
| 30 |
+
typeof contentPart.content === "string"
|
| 31 |
+
? contentPart.content
|
| 32 |
+
: JSON.stringify(contentPart.content)
|
| 33 |
+
).length;
|
| 34 |
+
}
|
| 35 |
+
});
|
| 36 |
+
}
|
| 37 |
+
});
|
| 38 |
+
}
|
| 39 |
+
if (typeof system === "string") {
|
| 40 |
+
tokenCount += enc.encode(system).length;
|
| 41 |
+
} else if (Array.isArray(system)) {
|
| 42 |
+
system.forEach((item: any) => {
|
| 43 |
+
if (item.type !== "text") return;
|
| 44 |
+
if (typeof item.text === "string") {
|
| 45 |
+
tokenCount += enc.encode(item.text).length;
|
| 46 |
+
} else if (Array.isArray(item.text)) {
|
| 47 |
+
item.text.forEach((textPart: any) => {
|
| 48 |
+
tokenCount += enc.encode(textPart || "").length;
|
| 49 |
+
});
|
| 50 |
+
}
|
| 51 |
+
});
|
| 52 |
+
}
|
| 53 |
+
if (tools) {
|
| 54 |
+
tools.forEach((tool: Tool) => {
|
| 55 |
+
if (tool.description) {
|
| 56 |
+
tokenCount += enc.encode(tool.name + tool.description).length;
|
| 57 |
+
}
|
| 58 |
+
if (tool.input_schema) {
|
| 59 |
+
tokenCount += enc.encode(JSON.stringify(tool.input_schema)).length;
|
| 60 |
+
}
|
| 61 |
+
});
|
| 62 |
+
}
|
| 63 |
+
return tokenCount;
|
| 64 |
+
};
|
| 65 |
+
|
| 66 |
+
const getUseModel = async (
|
| 67 |
+
req: any,
|
| 68 |
+
tokenCount: number,
|
| 69 |
+
config: any,
|
| 70 |
+
lastUsage?: Usage | undefined
|
| 71 |
+
) => {
|
| 72 |
+
if (req.body.model.includes(",")) {
|
| 73 |
+
const [provider, model] = req.body.model.split(",");
|
| 74 |
+
const finalProvider = config.Providers.find(
|
| 75 |
+
(p: any) => p.name.toLowerCase() === provider
|
| 76 |
+
);
|
| 77 |
+
const finalModel = finalProvider?.models?.find(
|
| 78 |
+
(m: any) => m.toLowerCase() === model
|
| 79 |
+
);
|
| 80 |
+
if (finalProvider && finalModel) {
|
| 81 |
+
return `${finalProvider.name},${finalModel}`;
|
| 82 |
+
}
|
| 83 |
+
return req.body.model;
|
| 84 |
+
}
|
| 85 |
+
// if tokenCount is greater than the configured threshold, use the long context model
|
| 86 |
+
const longContextThreshold = config.Router.longContextThreshold || 60000;
|
| 87 |
+
const lastUsageThreshold =
|
| 88 |
+
lastUsage &&
|
| 89 |
+
lastUsage.input_tokens > longContextThreshold &&
|
| 90 |
+
tokenCount > 20000;
|
| 91 |
+
const tokenCountThreshold = tokenCount > longContextThreshold;
|
| 92 |
+
if (
|
| 93 |
+
(lastUsageThreshold || tokenCountThreshold) &&
|
| 94 |
+
config.Router.longContext
|
| 95 |
+
) {
|
| 96 |
+
log(
|
| 97 |
+
"Using long context model due to token count:",
|
| 98 |
+
tokenCount,
|
| 99 |
+
"threshold:",
|
| 100 |
+
longContextThreshold
|
| 101 |
+
);
|
| 102 |
+
return config.Router.longContext;
|
| 103 |
+
}
|
| 104 |
+
if (
|
| 105 |
+
req.body?.system?.length > 1 &&
|
| 106 |
+
req.body?.system[1]?.text?.startsWith("<CCR-SUBAGENT-MODEL>")
|
| 107 |
+
) {
|
| 108 |
+
const model = req.body?.system[1].text.match(
|
| 109 |
+
/<CCR-SUBAGENT-MODEL>(.*?)<\/CCR-SUBAGENT-MODEL>/s
|
| 110 |
+
);
|
| 111 |
+
if (model) {
|
| 112 |
+
req.body.system[1].text = req.body.system[1].text.replace(
|
| 113 |
+
`<CCR-SUBAGENT-MODEL>${model[1]}</CCR-SUBAGENT-MODEL>`,
|
| 114 |
+
""
|
| 115 |
+
);
|
| 116 |
+
return model[1];
|
| 117 |
+
}
|
| 118 |
+
}
|
| 119 |
+
// If the model is claude-3-5-haiku, use the background model
|
| 120 |
+
if (
|
| 121 |
+
req.body.model?.startsWith("claude-3-5-haiku") &&
|
| 122 |
+
config.Router.background
|
| 123 |
+
) {
|
| 124 |
+
log("Using background model for ", req.body.model);
|
| 125 |
+
return config.Router.background;
|
| 126 |
+
}
|
| 127 |
+
// if exits thinking, use the think model
|
| 128 |
+
if (req.body.thinking && config.Router.think) {
|
| 129 |
+
log("Using think model for ", req.body.thinking);
|
| 130 |
+
return config.Router.think;
|
| 131 |
+
}
|
| 132 |
+
if (
|
| 133 |
+
Array.isArray(req.body.tools) &&
|
| 134 |
+
req.body.tools.some((tool: any) => tool.type?.startsWith("web_search")) &&
|
| 135 |
+
config.Router.webSearch
|
| 136 |
+
) {
|
| 137 |
+
return config.Router.webSearch;
|
| 138 |
+
}
|
| 139 |
+
return config.Router!.default;
|
| 140 |
+
};
|
| 141 |
+
|
| 142 |
+
export const router = async (req: any, _res: any, config: any) => {
|
| 143 |
+
// Parse sessionId from metadata.user_id
|
| 144 |
+
if (req.body.metadata?.user_id) {
|
| 145 |
+
const parts = req.body.metadata.user_id.split("_session_");
|
| 146 |
+
if (parts.length > 1) {
|
| 147 |
+
req.sessionId = parts[1];
|
| 148 |
+
}
|
| 149 |
+
}
|
| 150 |
+
const lastMessageUsage = sessionUsageCache.get(req.sessionId);
|
| 151 |
+
const { messages, system = [], tools }: MessageCreateParamsBase = req.body;
|
| 152 |
+
try {
|
| 153 |
+
const tokenCount = calculateTokenCount(
|
| 154 |
+
messages as MessageParam[],
|
| 155 |
+
system,
|
| 156 |
+
tools as Tool[]
|
| 157 |
+
);
|
| 158 |
+
|
| 159 |
+
let model;
|
| 160 |
+
if (config.CUSTOM_ROUTER_PATH) {
|
| 161 |
+
try {
|
| 162 |
+
const customRouter = require(config.CUSTOM_ROUTER_PATH);
|
| 163 |
+
req.tokenCount = tokenCount; // Pass token count to custom router
|
| 164 |
+
model = await customRouter(req, config);
|
| 165 |
+
} catch (e: any) {
|
| 166 |
+
log("failed to load custom router", e.message);
|
| 167 |
+
}
|
| 168 |
+
}
|
| 169 |
+
if (!model) {
|
| 170 |
+
model = await getUseModel(req, tokenCount, config, lastMessageUsage);
|
| 171 |
+
}
|
| 172 |
+
req.body.model = model;
|
| 173 |
+
} catch (error: any) {
|
| 174 |
+
log("Error in router middleware:", error.message);
|
| 175 |
+
req.body.model = config.Router!.default;
|
| 176 |
+
}
|
| 177 |
+
return;
|
| 178 |
+
};
|
platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/src/utils/status.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { getServiceInfo } from './processCheck';
|
| 2 |
+
|
| 3 |
+
export async function showStatus() {
|
| 4 |
+
const info = await getServiceInfo();
|
| 5 |
+
|
| 6 |
+
console.log('\n📊 Claude Code Router Status');
|
| 7 |
+
console.log('═'.repeat(40));
|
| 8 |
+
|
| 9 |
+
if (info.running) {
|
| 10 |
+
console.log('✅ Status: Running');
|
| 11 |
+
console.log(`🆔 Process ID: ${info.pid}`);
|
| 12 |
+
console.log(`🌐 Port: ${info.port}`);
|
| 13 |
+
console.log(`📡 API Endpoint: ${info.endpoint}`);
|
| 14 |
+
console.log(`📄 PID File: ${info.pidFile}`);
|
| 15 |
+
console.log('');
|
| 16 |
+
console.log('🚀 Ready to use! Run the following commands:');
|
| 17 |
+
console.log(' ccr code # Start coding with Claude');
|
| 18 |
+
console.log(' ccr stop # Stop the service');
|
| 19 |
+
} else {
|
| 20 |
+
console.log('❌ Status: Not Running');
|
| 21 |
+
console.log('');
|
| 22 |
+
console.log('💡 To start the service:');
|
| 23 |
+
console.log(' ccr start');
|
| 24 |
+
}
|
| 25 |
+
|
| 26 |
+
console.log('');
|
| 27 |
+
}
|
platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/src/utils/statusline.ts
ADDED
|
@@ -0,0 +1,813 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import fs from "node:fs/promises";
|
| 2 |
+
import { execSync } from "child_process";
|
| 3 |
+
import path from "node:path";
|
| 4 |
+
import { CONFIG_FILE, HOME_DIR } from "../constants";
|
| 5 |
+
import JSON5 from "json5";
|
| 6 |
+
|
| 7 |
+
export interface StatusLineModuleConfig {
|
| 8 |
+
type: string;
|
| 9 |
+
icon?: string;
|
| 10 |
+
text: string;
|
| 11 |
+
color?: string;
|
| 12 |
+
background?: string;
|
| 13 |
+
scriptPath?: string; // 用于script类型的模块,指定要执行的Node.js脚本文件路径
|
| 14 |
+
}
|
| 15 |
+
|
| 16 |
+
export interface StatusLineThemeConfig {
|
| 17 |
+
modules: StatusLineModuleConfig[];
|
| 18 |
+
}
|
| 19 |
+
|
| 20 |
+
export interface StatusLineInput {
|
| 21 |
+
hook_event_name: string;
|
| 22 |
+
session_id: string;
|
| 23 |
+
transcript_path: string;
|
| 24 |
+
cwd: string;
|
| 25 |
+
model: {
|
| 26 |
+
id: string;
|
| 27 |
+
display_name: string;
|
| 28 |
+
};
|
| 29 |
+
workspace: {
|
| 30 |
+
current_dir: string;
|
| 31 |
+
project_dir: string;
|
| 32 |
+
};
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
export interface AssistantMessage {
|
| 36 |
+
type: "assistant";
|
| 37 |
+
message: {
|
| 38 |
+
model: string;
|
| 39 |
+
usage: {
|
| 40 |
+
input_tokens: number;
|
| 41 |
+
output_tokens: number;
|
| 42 |
+
};
|
| 43 |
+
};
|
| 44 |
+
}
|
| 45 |
+
|
| 46 |
+
// ANSIColor代码
|
| 47 |
+
const COLORS: Record<string, string> = {
|
| 48 |
+
reset: "\x1b[0m",
|
| 49 |
+
bold: "\x1b[1m",
|
| 50 |
+
dim: "\x1b[2m",
|
| 51 |
+
// 标准颜色
|
| 52 |
+
black: "\x1b[30m",
|
| 53 |
+
red: "\x1b[31m",
|
| 54 |
+
green: "\x1b[32m",
|
| 55 |
+
yellow: "\x1b[33m",
|
| 56 |
+
blue: "\x1b[34m",
|
| 57 |
+
magenta: "\x1b[35m",
|
| 58 |
+
cyan: "\x1b[36m",
|
| 59 |
+
white: "\x1b[37m",
|
| 60 |
+
// 亮色
|
| 61 |
+
bright_black: "\x1b[90m",
|
| 62 |
+
bright_red: "\x1b[91m",
|
| 63 |
+
bright_green: "\x1b[92m",
|
| 64 |
+
bright_yellow: "\x1b[93m",
|
| 65 |
+
bright_blue: "\x1b[94m",
|
| 66 |
+
bright_magenta: "\x1b[95m",
|
| 67 |
+
bright_cyan: "\x1b[96m",
|
| 68 |
+
bright_white: "\x1b[97m",
|
| 69 |
+
// 背景颜色
|
| 70 |
+
bg_black: "\x1b[40m",
|
| 71 |
+
bg_red: "\x1b[41m",
|
| 72 |
+
bg_green: "\x1b[42m",
|
| 73 |
+
bg_yellow: "\x1b[43m",
|
| 74 |
+
bg_blue: "\x1b[44m",
|
| 75 |
+
bg_magenta: "\x1b[45m",
|
| 76 |
+
bg_cyan: "\x1b[46m",
|
| 77 |
+
bg_white: "\x1b[47m",
|
| 78 |
+
// 亮背景色
|
| 79 |
+
bg_bright_black: "\x1b[100m",
|
| 80 |
+
bg_bright_red: "\x1b[101m",
|
| 81 |
+
bg_bright_green: "\x1b[102m",
|
| 82 |
+
bg_bright_yellow: "\x1b[103m",
|
| 83 |
+
bg_bright_blue: "\x1b[104m",
|
| 84 |
+
bg_bright_magenta: "\x1b[105m",
|
| 85 |
+
bg_bright_cyan: "\x1b[106m",
|
| 86 |
+
bg_bright_white: "\x1b[107m",
|
| 87 |
+
};
|
| 88 |
+
|
| 89 |
+
// 使用TrueColor(24位色)支持十六进制颜色
|
| 90 |
+
const TRUE_COLOR_PREFIX = "\x1b[38;2;";
|
| 91 |
+
const TRUE_COLOR_BG_PREFIX = "\x1b[48;2;";
|
| 92 |
+
|
| 93 |
+
// 将十六进制颜色转为RGB格式
|
| 94 |
+
function hexToRgb(hex: string): { r: number; g: number; b: number } | null {
|
| 95 |
+
// 移除#和空格
|
| 96 |
+
hex = hex.replace(/^#/, '').trim();
|
| 97 |
+
|
| 98 |
+
// 处理简写形式 (#RGB -> #RRGGBB)
|
| 99 |
+
if (hex.length === 3) {
|
| 100 |
+
hex = hex[0] + hex[0] + hex[1] + hex[1] + hex[2] + hex[2];
|
| 101 |
+
}
|
| 102 |
+
|
| 103 |
+
if (hex.length !== 6) {
|
| 104 |
+
return null;
|
| 105 |
+
}
|
| 106 |
+
|
| 107 |
+
const r = parseInt(hex.substring(0, 2), 16);
|
| 108 |
+
const g = parseInt(hex.substring(2, 4), 16);
|
| 109 |
+
const b = parseInt(hex.substring(4, 6), 16);
|
| 110 |
+
|
| 111 |
+
// 验证RGB值是否有效
|
| 112 |
+
if (isNaN(r) || isNaN(g) || isNaN(b) || r < 0 || r > 255 || g < 0 || g > 255 || b < 0 || b > 255) {
|
| 113 |
+
return null;
|
| 114 |
+
}
|
| 115 |
+
|
| 116 |
+
return { r, g, b };
|
| 117 |
+
}
|
| 118 |
+
|
| 119 |
+
// 获取颜色代码
|
| 120 |
+
function getColorCode(colorName: string): string {
|
| 121 |
+
// 检查是否是十六进制颜色
|
| 122 |
+
if (colorName.startsWith('#') || /^[0-9a-fA-F]{6}$/.test(colorName) || /^[0-9a-fA-F]{3}$/.test(colorName)) {
|
| 123 |
+
const rgb = hexToRgb(colorName);
|
| 124 |
+
if (rgb) {
|
| 125 |
+
return `${TRUE_COLOR_PREFIX}${rgb.r};${rgb.g};${rgb.b}m`;
|
| 126 |
+
}
|
| 127 |
+
}
|
| 128 |
+
|
| 129 |
+
// 默认返回空字符串
|
| 130 |
+
return "";
|
| 131 |
+
}
|
| 132 |
+
|
| 133 |
+
|
| 134 |
+
// 变量替换函数,支持{{var}}格式的变量替换
|
| 135 |
+
function replaceVariables(text: string, variables: Record<string, string>): string {
|
| 136 |
+
return text.replace(/\{\{(\w+)\}\}/g, (_match, varName) => {
|
| 137 |
+
return variables[varName] || "";
|
| 138 |
+
});
|
| 139 |
+
}
|
| 140 |
+
|
| 141 |
+
// 执行脚本并获取输出
|
| 142 |
+
async function executeScript(scriptPath: string, variables: Record<string, string>): Promise<string> {
|
| 143 |
+
try {
|
| 144 |
+
// 检查文件是否存在
|
| 145 |
+
await fs.access(scriptPath);
|
| 146 |
+
|
| 147 |
+
// 使用require动态加载脚本模块
|
| 148 |
+
const scriptModule = require(scriptPath);
|
| 149 |
+
|
| 150 |
+
// 如果导出的是函数,则调用它并传入变量
|
| 151 |
+
if (typeof scriptModule === 'function') {
|
| 152 |
+
const result = scriptModule(variables);
|
| 153 |
+
// 如果返回的是Promise,则等待它完成
|
| 154 |
+
if (result instanceof Promise) {
|
| 155 |
+
return await result;
|
| 156 |
+
}
|
| 157 |
+
return result;
|
| 158 |
+
}
|
| 159 |
+
|
| 160 |
+
// 如果导出的是default函数,则调用它
|
| 161 |
+
if (scriptModule.default && typeof scriptModule.default === 'function') {
|
| 162 |
+
const result = scriptModule.default(variables);
|
| 163 |
+
// 如果返回的是Promise,则等待它完成
|
| 164 |
+
if (result instanceof Promise) {
|
| 165 |
+
return await result;
|
| 166 |
+
}
|
| 167 |
+
return result;
|
| 168 |
+
}
|
| 169 |
+
|
| 170 |
+
// 如果导出的是字符串,则直接返回
|
| 171 |
+
if (typeof scriptModule === 'string') {
|
| 172 |
+
return scriptModule;
|
| 173 |
+
}
|
| 174 |
+
|
| 175 |
+
// 如果导出的是default字符串,则返回它
|
| 176 |
+
if (scriptModule.default && typeof scriptModule.default === 'string') {
|
| 177 |
+
return scriptModule.default;
|
| 178 |
+
}
|
| 179 |
+
|
| 180 |
+
// 默认情况下返回空字符串
|
| 181 |
+
return "";
|
| 182 |
+
} catch (error) {
|
| 183 |
+
console.error(`执行脚本 ${scriptPath} 时出错:`, error);
|
| 184 |
+
return "";
|
| 185 |
+
}
|
| 186 |
+
}
|
| 187 |
+
|
| 188 |
+
// 默认主题配置 - 使用Nerd Fonts图标和美观配色
|
| 189 |
+
const DEFAULT_THEME: StatusLineThemeConfig = {
|
| 190 |
+
modules: [
|
| 191 |
+
{
|
| 192 |
+
type: "workDir",
|
| 193 |
+
icon: "", // nf-md-folder_outline
|
| 194 |
+
text: "{{workDirName}}",
|
| 195 |
+
color: "bright_blue"
|
| 196 |
+
},
|
| 197 |
+
{
|
| 198 |
+
type: "gitBranch",
|
| 199 |
+
icon: "", // nf-dev-git_branch
|
| 200 |
+
text: "{{gitBranch}}",
|
| 201 |
+
color: "bright_magenta"
|
| 202 |
+
},
|
| 203 |
+
{
|
| 204 |
+
type: "model",
|
| 205 |
+
icon: "", // nf-md-robot_outline
|
| 206 |
+
text: "{{model}}",
|
| 207 |
+
color: "bright_cyan"
|
| 208 |
+
},
|
| 209 |
+
{
|
| 210 |
+
type: "usage",
|
| 211 |
+
icon: "↑", // 上箭头
|
| 212 |
+
text: "{{inputTokens}}",
|
| 213 |
+
color: "bright_green"
|
| 214 |
+
},
|
| 215 |
+
{
|
| 216 |
+
type: "usage",
|
| 217 |
+
icon: "↓", // 下箭头
|
| 218 |
+
text: "{{outputTokens}}",
|
| 219 |
+
color: "bright_yellow"
|
| 220 |
+
}
|
| 221 |
+
]
|
| 222 |
+
};
|
| 223 |
+
|
| 224 |
+
// Powerline风格主题配置
|
| 225 |
+
const POWERLINE_THEME: StatusLineThemeConfig = {
|
| 226 |
+
modules: [
|
| 227 |
+
{
|
| 228 |
+
type: "workDir",
|
| 229 |
+
icon: "", // nf-md-folder_outline
|
| 230 |
+
text: "{{workDirName}}",
|
| 231 |
+
color: "white",
|
| 232 |
+
background: "bg_bright_blue"
|
| 233 |
+
},
|
| 234 |
+
{
|
| 235 |
+
type: "gitBranch",
|
| 236 |
+
icon: "", // nf-dev-git_branch
|
| 237 |
+
text: "{{gitBranch}}",
|
| 238 |
+
color: "white",
|
| 239 |
+
background: "bg_bright_magenta"
|
| 240 |
+
},
|
| 241 |
+
{
|
| 242 |
+
type: "model",
|
| 243 |
+
icon: "", // nf-md-robot_outline
|
| 244 |
+
text: "{{model}}",
|
| 245 |
+
color: "white",
|
| 246 |
+
background: "bg_bright_cyan"
|
| 247 |
+
},
|
| 248 |
+
{
|
| 249 |
+
type: "usage",
|
| 250 |
+
icon: "↑", // 上箭头
|
| 251 |
+
text: "{{inputTokens}}",
|
| 252 |
+
color: "white",
|
| 253 |
+
background: "bg_bright_green"
|
| 254 |
+
},
|
| 255 |
+
{
|
| 256 |
+
type: "usage",
|
| 257 |
+
icon: "↓", // 下箭头
|
| 258 |
+
text: "{{outputTokens}}",
|
| 259 |
+
color: "white",
|
| 260 |
+
background: "bg_bright_yellow"
|
| 261 |
+
}
|
| 262 |
+
]
|
| 263 |
+
};
|
| 264 |
+
|
| 265 |
+
// 简单文本主题配置 - 用于图标无法显示时的fallback
|
| 266 |
+
const SIMPLE_THEME: StatusLineThemeConfig = {
|
| 267 |
+
modules: [
|
| 268 |
+
{
|
| 269 |
+
type: "workDir",
|
| 270 |
+
icon: "",
|
| 271 |
+
text: "{{workDirName}}",
|
| 272 |
+
color: "bright_blue"
|
| 273 |
+
},
|
| 274 |
+
{
|
| 275 |
+
type: "gitBranch",
|
| 276 |
+
icon: "",
|
| 277 |
+
text: "{{gitBranch}}",
|
| 278 |
+
color: "bright_magenta"
|
| 279 |
+
},
|
| 280 |
+
{
|
| 281 |
+
type: "model",
|
| 282 |
+
icon: "",
|
| 283 |
+
text: "{{model}}",
|
| 284 |
+
color: "bright_cyan"
|
| 285 |
+
},
|
| 286 |
+
{
|
| 287 |
+
type: "usage",
|
| 288 |
+
icon: "↑",
|
| 289 |
+
text: "{{inputTokens}}",
|
| 290 |
+
color: "bright_green"
|
| 291 |
+
},
|
| 292 |
+
{
|
| 293 |
+
type: "usage",
|
| 294 |
+
icon: "↓",
|
| 295 |
+
text: "{{outputTokens}}",
|
| 296 |
+
color: "bright_yellow"
|
| 297 |
+
}
|
| 298 |
+
]
|
| 299 |
+
};
|
| 300 |
+
|
| 301 |
+
// 格式化usage信息,如果大于1000则使用k单位
|
| 302 |
+
function formatUsage(input_tokens: number, output_tokens: number): string {
|
| 303 |
+
if (input_tokens > 1000 || output_tokens > 1000) {
|
| 304 |
+
const inputFormatted = input_tokens > 1000 ? `${(input_tokens / 1000).toFixed(1)}k` : `${input_tokens}`;
|
| 305 |
+
const outputFormatted = output_tokens > 1000 ? `${(output_tokens / 1000).toFixed(1)}k` : `${output_tokens}`;
|
| 306 |
+
return `${inputFormatted} ${outputFormatted}`;
|
| 307 |
+
}
|
| 308 |
+
return `${input_tokens} ${output_tokens}`;
|
| 309 |
+
}
|
| 310 |
+
|
| 311 |
+
// 读取用户主目录的主题配置
|
| 312 |
+
async function getProjectThemeConfig(): Promise<{ theme: StatusLineThemeConfig | null, style: string }> {
|
| 313 |
+
try {
|
| 314 |
+
// 只使用主目录的固定配置文件
|
| 315 |
+
const configPath = CONFIG_FILE;
|
| 316 |
+
|
| 317 |
+
// 检查配置文件是否存在
|
| 318 |
+
try {
|
| 319 |
+
await fs.access(configPath);
|
| 320 |
+
} catch {
|
| 321 |
+
return { theme: null, style: 'default' };
|
| 322 |
+
}
|
| 323 |
+
|
| 324 |
+
const configContent = await fs.readFile(configPath, "utf-8");
|
| 325 |
+
const config = JSON5.parse(configContent);
|
| 326 |
+
|
| 327 |
+
// 检查是否有StatusLine配置
|
| 328 |
+
if (config.StatusLine) {
|
| 329 |
+
// 获取当前使用的风格,默认为default
|
| 330 |
+
const currentStyle = config.StatusLine.currentStyle || 'default';
|
| 331 |
+
|
| 332 |
+
// 检查是否有对应风格的配置
|
| 333 |
+
if (config.StatusLine[currentStyle] && config.StatusLine[currentStyle].modules) {
|
| 334 |
+
return { theme: config.StatusLine[currentStyle], style: currentStyle };
|
| 335 |
+
}
|
| 336 |
+
}
|
| 337 |
+
} catch (error) {
|
| 338 |
+
// 如果读取失败,返回null
|
| 339 |
+
// console.error("Failed to read theme config:", error);
|
| 340 |
+
}
|
| 341 |
+
|
| 342 |
+
return { theme: null, style: 'default' };
|
| 343 |
+
}
|
| 344 |
+
|
| 345 |
+
// 检查是否应该使用简单主题(fallback方案)
|
| 346 |
+
// 当环境变量 USE_SIMPLE_ICONS 被设置时,或者当检测到可能不支持Nerd Fonts的终端时
|
| 347 |
+
function shouldUseSimpleTheme(): boolean {
|
| 348 |
+
// 检查环境变量
|
| 349 |
+
if (process.env.USE_SIMPLE_ICONS === 'true') {
|
| 350 |
+
return true;
|
| 351 |
+
}
|
| 352 |
+
|
| 353 |
+
// 检查终端类型(一些常见的不支持复杂图标的终端)
|
| 354 |
+
const term = process.env.TERM || '';
|
| 355 |
+
const unsupportedTerms = ['dumb', 'unknown'];
|
| 356 |
+
if (unsupportedTerms.includes(term)) {
|
| 357 |
+
return true;
|
| 358 |
+
}
|
| 359 |
+
|
| 360 |
+
// 默认情况下,假设终端支持Nerd Fonts
|
| 361 |
+
return false;
|
| 362 |
+
}
|
| 363 |
+
|
| 364 |
+
// 检查Nerd Fonts图标是否能正确显示
|
| 365 |
+
// 通过检查终端字体信息或使用试探性方法
|
| 366 |
+
function canDisplayNerdFonts(): boolean {
|
| 367 |
+
// 如果环境变量明确指定使用简单图标,则不能显示Nerd Fonts
|
| 368 |
+
if (process.env.USE_SIMPLE_ICONS === 'true') {
|
| 369 |
+
return false;
|
| 370 |
+
}
|
| 371 |
+
|
| 372 |
+
// 检查一些常见的支持Nerd Fonts的终端环境变量
|
| 373 |
+
const fontEnvVars = ['NERD_FONT', 'NERDFONT', 'FONT'];
|
| 374 |
+
for (const envVar of fontEnvVars) {
|
| 375 |
+
const value = process.env[envVar];
|
| 376 |
+
if (value && (value.includes('Nerd') || value.includes('nerd'))) {
|
| 377 |
+
return true;
|
| 378 |
+
}
|
| 379 |
+
}
|
| 380 |
+
|
| 381 |
+
// 检查终端类型
|
| 382 |
+
const termProgram = process.env.TERM_PROGRAM || '';
|
| 383 |
+
const supportedTerminals = ['iTerm.app', 'vscode', 'Hyper', 'kitty', 'alacritty'];
|
| 384 |
+
if (supportedTerminals.includes(termProgram)) {
|
| 385 |
+
return true;
|
| 386 |
+
}
|
| 387 |
+
|
| 388 |
+
// 检查COLORTERM环境变量
|
| 389 |
+
const colorTerm = process.env.COLORTERM || '';
|
| 390 |
+
if (colorTerm.includes('truecolor') || colorTerm.includes('24bit')) {
|
| 391 |
+
return true;
|
| 392 |
+
}
|
| 393 |
+
|
| 394 |
+
// 默认情况下,假设可以显示Nerd Fonts(但允许用户通过环境变量覆盖)
|
| 395 |
+
return process.env.USE_SIMPLE_ICONS !== 'true';
|
| 396 |
+
}
|
| 397 |
+
|
| 398 |
+
// 检查特定Unicode字符是否能正确显示
|
| 399 |
+
// 这是一个简单的试探性检查
|
| 400 |
+
function canDisplayUnicodeCharacter(char: string): boolean {
|
| 401 |
+
// 对于Nerd Fonts图标,我们假设支持UTF-8的终端可以显示
|
| 402 |
+
// 但实际上很难准确检测,所以我们依赖环境变量和终端类型检测
|
| 403 |
+
try {
|
| 404 |
+
// 检查终端是否支持UTF-8
|
| 405 |
+
const lang = process.env.LANG || process.env.LC_ALL || process.env.LC_CTYPE || '';
|
| 406 |
+
if (lang.includes('UTF-8') || lang.includes('utf8') || lang.includes('UTF8')) {
|
| 407 |
+
return true;
|
| 408 |
+
}
|
| 409 |
+
|
| 410 |
+
// 检查LC_*环境变量
|
| 411 |
+
const lcVars = ['LC_ALL', 'LC_CTYPE', 'LANG'];
|
| 412 |
+
for (const lcVar of lcVars) {
|
| 413 |
+
const value = process.env[lcVar];
|
| 414 |
+
if (value && (value.includes('UTF-8') || value.includes('utf8'))) {
|
| 415 |
+
return true;
|
| 416 |
+
}
|
| 417 |
+
}
|
| 418 |
+
} catch (e) {
|
| 419 |
+
// 如果检查失败,默认返回true
|
| 420 |
+
return true;
|
| 421 |
+
}
|
| 422 |
+
|
| 423 |
+
// 默认情况下,假设可以显示
|
| 424 |
+
return true;
|
| 425 |
+
}
|
| 426 |
+
|
| 427 |
+
export async function parseStatusLineData(input: StatusLineInput): Promise<string> {
|
| 428 |
+
try {
|
| 429 |
+
// 检查是否应该使用简单主题
|
| 430 |
+
const useSimpleTheme = shouldUseSimpleTheme();
|
| 431 |
+
|
| 432 |
+
// 检查是否可以显示Nerd Fonts图标
|
| 433 |
+
const canDisplayNerd = canDisplayNerdFonts();
|
| 434 |
+
|
| 435 |
+
// 确定使用的主题:如果用户强制使用简单主题或无法显示Nerd Fonts,则使用简单主题
|
| 436 |
+
const effectiveTheme = useSimpleTheme || !canDisplayNerd ? SIMPLE_THEME : DEFAULT_THEME;
|
| 437 |
+
|
| 438 |
+
// 获取主目录的主题配置,如果没有则使用确定的默认配置
|
| 439 |
+
const { theme: projectTheme, style: currentStyle } = await getProjectThemeConfig();
|
| 440 |
+
const theme = projectTheme || effectiveTheme;
|
| 441 |
+
|
| 442 |
+
// 获取当前工作目录和Git分支
|
| 443 |
+
const workDir = input.workspace.current_dir;
|
| 444 |
+
let gitBranch = "";
|
| 445 |
+
|
| 446 |
+
try {
|
| 447 |
+
// 尝试获取Git分支名
|
| 448 |
+
gitBranch = execSync("git branch --show-current", {
|
| 449 |
+
cwd: workDir,
|
| 450 |
+
stdio: ["pipe", "pipe", "ignore"],
|
| 451 |
+
})
|
| 452 |
+
.toString()
|
| 453 |
+
.trim();
|
| 454 |
+
} catch (error) {
|
| 455 |
+
// 如果不是Git仓库或获取失败,则忽略错误
|
| 456 |
+
}
|
| 457 |
+
|
| 458 |
+
// 从transcript_path文件中读取最后一条assistant消息
|
| 459 |
+
const transcriptContent = await fs.readFile(input.transcript_path, "utf-8");
|
| 460 |
+
const lines = transcriptContent.trim().split("\n");
|
| 461 |
+
|
| 462 |
+
// 反向遍历寻找最后一条assistant消息
|
| 463 |
+
let model = "";
|
| 464 |
+
let inputTokens = 0;
|
| 465 |
+
let outputTokens = 0;
|
| 466 |
+
|
| 467 |
+
for (let i = lines.length - 1; i >= 0; i--) {
|
| 468 |
+
try {
|
| 469 |
+
const message: AssistantMessage = JSON.parse(lines[i]);
|
| 470 |
+
if (message.type === "assistant" && message.message.model) {
|
| 471 |
+
model = message.message.model;
|
| 472 |
+
|
| 473 |
+
if (message.message.usage) {
|
| 474 |
+
inputTokens = message.message.usage.input_tokens;
|
| 475 |
+
outputTokens = message.message.usage.output_tokens;
|
| 476 |
+
}
|
| 477 |
+
break;
|
| 478 |
+
}
|
| 479 |
+
} catch (parseError) {
|
| 480 |
+
// 忽略解析错误,继续查找
|
| 481 |
+
continue;
|
| 482 |
+
}
|
| 483 |
+
}
|
| 484 |
+
|
| 485 |
+
// 如果没有从transcript中获取到模型名称,则尝试从配置文件中获取
|
| 486 |
+
if (!model) {
|
| 487 |
+
try {
|
| 488 |
+
// 获取项目配置文件路径
|
| 489 |
+
const projectConfigPath = path.join(workDir, ".claude-code-router", "config.json");
|
| 490 |
+
let configPath = projectConfigPath;
|
| 491 |
+
|
| 492 |
+
// 检查项目配置文件是否存在,如果不存在则使用用户主目录的配置文件
|
| 493 |
+
try {
|
| 494 |
+
await fs.access(projectConfigPath);
|
| 495 |
+
} catch {
|
| 496 |
+
configPath = CONFIG_FILE;
|
| 497 |
+
}
|
| 498 |
+
|
| 499 |
+
// 读取配置文件
|
| 500 |
+
const configContent = await fs.readFile(configPath, "utf-8");
|
| 501 |
+
const config = JSON5.parse(configContent);
|
| 502 |
+
|
| 503 |
+
// 从Router字段的default内容中获取模型名称
|
| 504 |
+
if (config.Router && config.Router.default) {
|
| 505 |
+
const [, defaultModel] = config.Router.default.split(",");
|
| 506 |
+
if (defaultModel) {
|
| 507 |
+
model = defaultModel.trim();
|
| 508 |
+
}
|
| 509 |
+
}
|
| 510 |
+
} catch (configError) {
|
| 511 |
+
// 如果配置文件读取失败,则忽略错误
|
| 512 |
+
}
|
| 513 |
+
}
|
| 514 |
+
|
| 515 |
+
// ���果仍然没有获取到模型名称,则使用传入的JSON数据中的model字段的display_name
|
| 516 |
+
if (!model) {
|
| 517 |
+
model = input.model.display_name;
|
| 518 |
+
}
|
| 519 |
+
|
| 520 |
+
// 获取工作目录名
|
| 521 |
+
const workDirName = workDir.split("/").pop() || "";
|
| 522 |
+
|
| 523 |
+
// 格式化usage信息
|
| 524 |
+
const usage = formatUsage(inputTokens, outputTokens);
|
| 525 |
+
const [formattedInputTokens, formattedOutputTokens] = usage.split(" ");
|
| 526 |
+
|
| 527 |
+
// 定义变量替换映射
|
| 528 |
+
const variables = {
|
| 529 |
+
workDirName,
|
| 530 |
+
gitBranch,
|
| 531 |
+
model,
|
| 532 |
+
inputTokens: formattedInputTokens,
|
| 533 |
+
outputTokens: formattedOutputTokens
|
| 534 |
+
};
|
| 535 |
+
|
| 536 |
+
// 确定使用的风格
|
| 537 |
+
const isPowerline = currentStyle === 'powerline';
|
| 538 |
+
|
| 539 |
+
// 根据风格渲染状态行
|
| 540 |
+
if (isPowerline) {
|
| 541 |
+
return await renderPowerlineStyle(theme, variables);
|
| 542 |
+
} else {
|
| 543 |
+
return await renderDefaultStyle(theme, variables);
|
| 544 |
+
}
|
| 545 |
+
} catch (error) {
|
| 546 |
+
// 发生错误时返回空字符串
|
| 547 |
+
return "";
|
| 548 |
+
}
|
| 549 |
+
}
|
| 550 |
+
|
| 551 |
+
// 读取用户主目录的主题配置(指定风格)
|
| 552 |
+
async function getProjectThemeConfigForStyle(style: string): Promise<StatusLineThemeConfig | null> {
|
| 553 |
+
try {
|
| 554 |
+
// 只使用主目录的固定配置文件
|
| 555 |
+
const configPath = CONFIG_FILE;
|
| 556 |
+
|
| 557 |
+
// 检查配置文件是否存在
|
| 558 |
+
try {
|
| 559 |
+
await fs.access(configPath);
|
| 560 |
+
} catch {
|
| 561 |
+
return null;
|
| 562 |
+
}
|
| 563 |
+
|
| 564 |
+
const configContent = await fs.readFile(configPath, "utf-8");
|
| 565 |
+
const config = JSON5.parse(configContent);
|
| 566 |
+
|
| 567 |
+
// 检查是否有StatusLine配置
|
| 568 |
+
if (config.StatusLine && config.StatusLine[style] && config.StatusLine[style].modules) {
|
| 569 |
+
return config.StatusLine[style];
|
| 570 |
+
}
|
| 571 |
+
} catch (error) {
|
| 572 |
+
// 如果读取失败,返回null
|
| 573 |
+
// console.error("Failed to read theme config:", error);
|
| 574 |
+
}
|
| 575 |
+
|
| 576 |
+
return null;
|
| 577 |
+
}
|
| 578 |
+
|
| 579 |
+
// 渲染默认风格的状态行
|
| 580 |
+
async function renderDefaultStyle(
|
| 581 |
+
theme: StatusLineThemeConfig,
|
| 582 |
+
variables: Record<string, string>
|
| 583 |
+
): Promise<string> {
|
| 584 |
+
const modules = theme.modules || DEFAULT_THEME.modules;
|
| 585 |
+
const parts: string[] = [];
|
| 586 |
+
|
| 587 |
+
// 遍历模块数组,渲染每个模块
|
| 588 |
+
for (let i = 0; i < Math.min(modules.length, 5); i++) {
|
| 589 |
+
const module = modules[i];
|
| 590 |
+
const color = module.color ? getColorCode(module.color) : "";
|
| 591 |
+
const background = module.background ? getColorCode(module.background) : "";
|
| 592 |
+
const icon = module.icon || "";
|
| 593 |
+
|
| 594 |
+
// 如果是script类型,执行脚本获取文本
|
| 595 |
+
let text = "";
|
| 596 |
+
if (module.type === "script" && module.scriptPath) {
|
| 597 |
+
text = await executeScript(module.scriptPath, variables);
|
| 598 |
+
} else {
|
| 599 |
+
text = replaceVariables(module.text, variables);
|
| 600 |
+
}
|
| 601 |
+
|
| 602 |
+
// 构建显示文本
|
| 603 |
+
let displayText = "";
|
| 604 |
+
if (icon) {
|
| 605 |
+
displayText += `${icon} `;
|
| 606 |
+
}
|
| 607 |
+
displayText += text;
|
| 608 |
+
|
| 609 |
+
// 如果displayText为空,或者只有图标没有实际文本,则跳过该模块
|
| 610 |
+
if (!displayText || !text) {
|
| 611 |
+
continue;
|
| 612 |
+
}
|
| 613 |
+
|
| 614 |
+
// 构建模块字符串
|
| 615 |
+
let part = `${background}${color}`;
|
| 616 |
+
part += `${displayText}${COLORS.reset}`;
|
| 617 |
+
|
| 618 |
+
parts.push(part);
|
| 619 |
+
}
|
| 620 |
+
|
| 621 |
+
// 使用空格连接所有部分
|
| 622 |
+
return parts.join(" ");
|
| 623 |
+
}
|
| 624 |
+
|
| 625 |
+
// Powerline符号
|
| 626 |
+
const SEP_RIGHT = "\uE0B0"; //
|
| 627 |
+
|
| 628 |
+
// 颜色编号(256色表)
|
| 629 |
+
const COLOR_MAP: Record<string, number> = {
|
| 630 |
+
// 基础颜色映射到256色
|
| 631 |
+
black: 0,
|
| 632 |
+
red: 1,
|
| 633 |
+
green: 2,
|
| 634 |
+
yellow: 3,
|
| 635 |
+
blue: 4,
|
| 636 |
+
magenta: 5,
|
| 637 |
+
cyan: 6,
|
| 638 |
+
white: 7,
|
| 639 |
+
bright_black: 8,
|
| 640 |
+
bright_red: 9,
|
| 641 |
+
bright_green: 10,
|
| 642 |
+
bright_yellow: 11,
|
| 643 |
+
bright_blue: 12,
|
| 644 |
+
bright_magenta: 13,
|
| 645 |
+
bright_cyan: 14,
|
| 646 |
+
bright_white: 15,
|
| 647 |
+
// 亮背景色映射
|
| 648 |
+
bg_black: 0,
|
| 649 |
+
bg_red: 1,
|
| 650 |
+
bg_green: 2,
|
| 651 |
+
bg_yellow: 3,
|
| 652 |
+
bg_blue: 4,
|
| 653 |
+
bg_magenta: 5,
|
| 654 |
+
bg_cyan: 6,
|
| 655 |
+
bg_white: 7,
|
| 656 |
+
bg_bright_black: 8,
|
| 657 |
+
bg_bright_red: 9,
|
| 658 |
+
bg_bright_green: 10,
|
| 659 |
+
bg_bright_yellow: 11,
|
| 660 |
+
bg_bright_blue: 12,
|
| 661 |
+
bg_bright_magenta: 13,
|
| 662 |
+
bg_bright_cyan: 14,
|
| 663 |
+
bg_bright_white: 15,
|
| 664 |
+
// 自定义颜色映射
|
| 665 |
+
bg_bright_orange: 202,
|
| 666 |
+
bg_bright_purple: 129,
|
| 667 |
+
};
|
| 668 |
+
|
| 669 |
+
// 获取TrueColor的RGB值
|
| 670 |
+
function getTrueColorRgb(colorName: string): { r: number; g: number; b: number } | null {
|
| 671 |
+
// 如果是预定义颜色,返回对应RGB
|
| 672 |
+
if (COLOR_MAP[colorName] !== undefined) {
|
| 673 |
+
const color256 = COLOR_MAP[colorName];
|
| 674 |
+
return color256ToRgb(color256);
|
| 675 |
+
}
|
| 676 |
+
|
| 677 |
+
// 处理十六进制颜色
|
| 678 |
+
if (colorName.startsWith('#') || /^[0-9a-fA-F]{6}$/.test(colorName) || /^[0-9a-fA-F]{3}$/.test(colorName)) {
|
| 679 |
+
return hexToRgb(colorName);
|
| 680 |
+
}
|
| 681 |
+
|
| 682 |
+
// 处理背景色十六进制
|
| 683 |
+
if (colorName.startsWith('bg_#')) {
|
| 684 |
+
return hexToRgb(colorName.substring(3));
|
| 685 |
+
}
|
| 686 |
+
|
| 687 |
+
return null;
|
| 688 |
+
}
|
| 689 |
+
|
| 690 |
+
// 将256色表索引转换为RGB值
|
| 691 |
+
function color256ToRgb(index: number): { r: number; g: number; b: number } | null {
|
| 692 |
+
if (index < 0 || index > 255) return null;
|
| 693 |
+
|
| 694 |
+
// ANSI 256色表转换
|
| 695 |
+
if (index < 16) {
|
| 696 |
+
// 基本颜色
|
| 697 |
+
const basicColors = [
|
| 698 |
+
[0, 0, 0], [128, 0, 0], [0, 128, 0], [128, 128, 0],
|
| 699 |
+
[0, 0, 128], [128, 0, 128], [0, 128, 128], [192, 192, 192],
|
| 700 |
+
[128, 128, 128], [255, 0, 0], [0, 255, 0], [255, 255, 0],
|
| 701 |
+
[0, 0, 255], [255, 0, 255], [0, 255, 255], [255, 255, 255]
|
| 702 |
+
];
|
| 703 |
+
return { r: basicColors[index][0], g: basicColors[index][1], b: basicColors[index][2] };
|
| 704 |
+
} else if (index < 232) {
|
| 705 |
+
// 216色:6×6×6的颜色立方体
|
| 706 |
+
const i = index - 16;
|
| 707 |
+
const r = Math.floor(i / 36);
|
| 708 |
+
const g = Math.floor((i % 36) / 6);
|
| 709 |
+
const b = i % 6;
|
| 710 |
+
const rgb = [0, 95, 135, 175, 215, 255];
|
| 711 |
+
return { r: rgb[r], g: rgb[g], b: rgb[b] };
|
| 712 |
+
} else {
|
| 713 |
+
// 灰度色
|
| 714 |
+
const gray = 8 + (index - 232) * 10;
|
| 715 |
+
return { r: gray, g: gray, b: gray };
|
| 716 |
+
}
|
| 717 |
+
}
|
| 718 |
+
|
| 719 |
+
// 生成一个无缝拼接的段:文本在 bgN 上显示,分隔符从 bgN 过渡到 nextBgN
|
| 720 |
+
function segment(text: string, textFg: string, bgColor: string, nextBgColor: string | null): string {
|
| 721 |
+
const bgRgb = getTrueColorRgb(bgColor);
|
| 722 |
+
if (!bgRgb) {
|
| 723 |
+
// 如果无法获取RGB,使用默认蓝色背景
|
| 724 |
+
const defaultBlueRgb = { r: 33, g: 150, b: 243 };
|
| 725 |
+
const curBg = `\x1b[48;2;${defaultBlueRgb.r};${defaultBlueRgb.g};${defaultBlueRgb.b}m`;
|
| 726 |
+
const fgColor = `\x1b[38;2;255;255;255m`;
|
| 727 |
+
const body = `${curBg}${fgColor} ${text} \x1b[0m`;
|
| 728 |
+
return body;
|
| 729 |
+
}
|
| 730 |
+
|
| 731 |
+
const curBg = `\x1b[48;2;${bgRgb.r};${bgRgb.g};${bgRgb.b}m`;
|
| 732 |
+
|
| 733 |
+
// 获取前景色RGB
|
| 734 |
+
let fgRgb = { r: 255, g: 255, b: 255 }; // 默认前景色为白色
|
| 735 |
+
const textFgRgb = getTrueColorRgb(textFg);
|
| 736 |
+
if (textFgRgb) {
|
| 737 |
+
fgRgb = textFgRgb;
|
| 738 |
+
}
|
| 739 |
+
|
| 740 |
+
const fgColor = `\x1b[38;2;${fgRgb.r};${fgRgb.g};${fgRgb.b}m`;
|
| 741 |
+
const body = `${curBg}${fgColor} ${text} \x1b[0m`;
|
| 742 |
+
|
| 743 |
+
if (nextBgColor != null) {
|
| 744 |
+
const nextBgRgb = getTrueColorRgb(nextBgColor);
|
| 745 |
+
if (nextBgRgb) {
|
| 746 |
+
// 分隔符:前景色是当前段的背景色,背景色是下一段的背景色
|
| 747 |
+
const sepCurFg = `\x1b[38;2;${bgRgb.r};${bgRgb.g};${bgRgb.b}m`;
|
| 748 |
+
const sepNextBg = `\x1b[48;2;${nextBgRgb.r};${nextBgRgb.g};${nextBgRgb.b}m`;
|
| 749 |
+
const sep = `${sepCurFg}${sepNextBg}${SEP_RIGHT}\x1b[0m`;
|
| 750 |
+
return body + sep;
|
| 751 |
+
}
|
| 752 |
+
// 如果没有下一个背景色,假设终端背景为黑色并渲染黑色箭头
|
| 753 |
+
const sepCurFg = `\x1b[38;2;${bgRgb.r};${bgRgb.g};${bgRgb.b}m`;
|
| 754 |
+
const sepNextBg = `\x1b[48;2;0;0;0m`; // 黑色背景
|
| 755 |
+
const sep = `${sepCurFg}${sepNextBg}${SEP_RIGHT}\x1b[0m`;
|
| 756 |
+
return body + sep;
|
| 757 |
+
}
|
| 758 |
+
|
| 759 |
+
return body;
|
| 760 |
+
}
|
| 761 |
+
|
| 762 |
+
// 渲染Powerline风格的状态行
|
| 763 |
+
async function renderPowerlineStyle(
|
| 764 |
+
theme: StatusLineThemeConfig,
|
| 765 |
+
variables: Record<string, string>
|
| 766 |
+
): Promise<string> {
|
| 767 |
+
const modules = theme.modules || POWERLINE_THEME.modules;
|
| 768 |
+
const segments: string[] = [];
|
| 769 |
+
|
| 770 |
+
// 遍历模块数组,渲染每个模块
|
| 771 |
+
for (let i = 0; i < Math.min(modules.length, 5); i++) {
|
| 772 |
+
const module = modules[i];
|
| 773 |
+
const color = module.color || "white";
|
| 774 |
+
const backgroundName = module.background || "";
|
| 775 |
+
const icon = module.icon || "";
|
| 776 |
+
|
| 777 |
+
// 如果是script类型,执行脚本获取文本
|
| 778 |
+
let text = "";
|
| 779 |
+
if (module.type === "script" && module.scriptPath) {
|
| 780 |
+
text = await executeScript(module.scriptPath, variables);
|
| 781 |
+
} else {
|
| 782 |
+
text = replaceVariables(module.text, variables);
|
| 783 |
+
}
|
| 784 |
+
|
| 785 |
+
// 构建显示文本
|
| 786 |
+
let displayText = "";
|
| 787 |
+
if (icon) {
|
| 788 |
+
displayText += `${icon} `;
|
| 789 |
+
}
|
| 790 |
+
displayText += text;
|
| 791 |
+
|
| 792 |
+
// 如果displayText为空,或者只有图标没有实际文本,则跳过该模块
|
| 793 |
+
if (!displayText || !text) {
|
| 794 |
+
continue;
|
| 795 |
+
}
|
| 796 |
+
|
| 797 |
+
// 获取下一个模块的背景色(用于分隔符)
|
| 798 |
+
let nextBackground: string | null = null;
|
| 799 |
+
if (i < modules.length - 1) {
|
| 800 |
+
const nextModule = modules[i + 1];
|
| 801 |
+
nextBackground = nextModule.background || null;
|
| 802 |
+
}
|
| 803 |
+
|
| 804 |
+
// 使用模块定义的背景色,或者为Powerline风格提供默认背景色
|
| 805 |
+
const actualBackground = backgroundName || "bg_bright_blue";
|
| 806 |
+
|
| 807 |
+
// 生成段,支持十六进制颜色
|
| 808 |
+
const segmentStr = segment(displayText, color, actualBackground, nextBackground);
|
| 809 |
+
segments.push(segmentStr);
|
| 810 |
+
}
|
| 811 |
+
|
| 812 |
+
return segments.join("");
|
| 813 |
+
}
|