079project 8.0.0 → 9.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +165 -0
- package/README.en.md +81 -1
- package/README.md +85 -1
- package/Redis-8.0.3-Windows-x64-cygwin-with-Service/dump.rdb +0 -0
- package/groupWorker.cjs +253 -0
- package/inferenceWorker.cjs +94 -0
- package/main.cjs +1263 -173
- package/mainFailedOfJing1Xi4Hua4Zhi4Duan3Yu3.cjs +6320 -0
- package/optimization.cjs +720 -0
- package/package.json +3 -2
- package/test_automatic/answer.csv +401 -0
- package/test_automatic/generate_daily_qa.py +645 -0
- package/test_automatic/question.csv +401 -0
- package/test_automatic.cjs +441 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
GNU LESSER GENERAL PUBLIC LICENSE
|
|
2
|
+
Version 3, 29 June 2007
|
|
3
|
+
|
|
4
|
+
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
|
5
|
+
Everyone is permitted to copy and distribute verbatim copies
|
|
6
|
+
of this license document, but changing it is not allowed.
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
This version of the GNU Lesser General Public License incorporates
|
|
10
|
+
the terms and conditions of version 3 of the GNU General Public
|
|
11
|
+
License, supplemented by the additional permissions listed below.
|
|
12
|
+
|
|
13
|
+
0. Additional Definitions.
|
|
14
|
+
|
|
15
|
+
As used herein, "this License" refers to version 3 of the GNU Lesser
|
|
16
|
+
General Public License, and the "GNU GPL" refers to version 3 of the GNU
|
|
17
|
+
General Public License.
|
|
18
|
+
|
|
19
|
+
"The Library" refers to a covered work governed by this License,
|
|
20
|
+
other than an Application or a Combined Work as defined below.
|
|
21
|
+
|
|
22
|
+
An "Application" is any work that makes use of an interface provided
|
|
23
|
+
by the Library, but which is not otherwise based on the Library.
|
|
24
|
+
Defining a subclass of a class defined by the Library is deemed a mode
|
|
25
|
+
of using an interface provided by the Library.
|
|
26
|
+
|
|
27
|
+
A "Combined Work" is a work produced by combining or linking an
|
|
28
|
+
Application with the Library. The particular version of the Library
|
|
29
|
+
with which the Combined Work was made is also called the "Linked
|
|
30
|
+
Version".
|
|
31
|
+
|
|
32
|
+
The "Minimal Corresponding Source" for a Combined Work means the
|
|
33
|
+
Corresponding Source for the Combined Work, excluding any source code
|
|
34
|
+
for portions of the Combined Work that, considered in isolation, are
|
|
35
|
+
based on the Application, and not on the Linked Version.
|
|
36
|
+
|
|
37
|
+
The "Corresponding Application Code" for a Combined Work means the
|
|
38
|
+
object code and/or source code for the Application, including any data
|
|
39
|
+
and utility programs needed for reproducing the Combined Work from the
|
|
40
|
+
Application, but excluding the System Libraries of the Combined Work.
|
|
41
|
+
|
|
42
|
+
1. Exception to Section 3 of the GNU GPL.
|
|
43
|
+
|
|
44
|
+
You may convey a covered work under sections 3 and 4 of this License
|
|
45
|
+
without being bound by section 3 of the GNU GPL.
|
|
46
|
+
|
|
47
|
+
2. Conveying Modified Versions.
|
|
48
|
+
|
|
49
|
+
If you modify a copy of the Library, and, in your modifications, a
|
|
50
|
+
facility refers to a function or data to be supplied by an Application
|
|
51
|
+
that uses the facility (other than as an argument passed when the
|
|
52
|
+
facility is invoked), then you may convey a copy of the modified
|
|
53
|
+
version:
|
|
54
|
+
|
|
55
|
+
a) under this License, provided that you make a good faith effort to
|
|
56
|
+
ensure that, in the event an Application does not supply the
|
|
57
|
+
function or data, the facility still operates, and performs
|
|
58
|
+
whatever part of its purpose remains meaningful, or
|
|
59
|
+
|
|
60
|
+
b) under the GNU GPL, with none of the additional permissions of
|
|
61
|
+
this License applicable to that copy.
|
|
62
|
+
|
|
63
|
+
3. Object Code Incorporating Material from Library Header Files.
|
|
64
|
+
|
|
65
|
+
The object code form of an Application may incorporate material from
|
|
66
|
+
a header file that is part of the Library. You may convey such object
|
|
67
|
+
code under terms of your choice, provided that, if the incorporated
|
|
68
|
+
material is not limited to numerical parameters, data structure
|
|
69
|
+
layouts and accessors, or small macros, inline functions and templates
|
|
70
|
+
(ten or fewer lines in length), you do both of the following:
|
|
71
|
+
|
|
72
|
+
a) Give prominent notice with each copy of the object code that the
|
|
73
|
+
Library is used in it and that the Library and its use are
|
|
74
|
+
covered by this License.
|
|
75
|
+
|
|
76
|
+
b) Accompany the object code with a copy of the GNU GPL and this license
|
|
77
|
+
document.
|
|
78
|
+
|
|
79
|
+
4. Combined Works.
|
|
80
|
+
|
|
81
|
+
You may convey a Combined Work under terms of your choice that,
|
|
82
|
+
taken together, effectively do not restrict modification of the
|
|
83
|
+
portions of the Library contained in the Combined Work and reverse
|
|
84
|
+
engineering for debugging such modifications, if you also do each of
|
|
85
|
+
the following:
|
|
86
|
+
|
|
87
|
+
a) Give prominent notice with each copy of the Combined Work that
|
|
88
|
+
the Library is used in it and that the Library and its use are
|
|
89
|
+
covered by this License.
|
|
90
|
+
|
|
91
|
+
b) Accompany the Combined Work with a copy of the GNU GPL and this license
|
|
92
|
+
document.
|
|
93
|
+
|
|
94
|
+
c) For a Combined Work that displays copyright notices during
|
|
95
|
+
execution, include the copyright notice for the Library among
|
|
96
|
+
these notices, as well as a reference directing the user to the
|
|
97
|
+
copies of the GNU GPL and this license document.
|
|
98
|
+
|
|
99
|
+
d) Do one of the following:
|
|
100
|
+
|
|
101
|
+
0) Convey the Minimal Corresponding Source under the terms of this
|
|
102
|
+
License, and the Corresponding Application Code in a form
|
|
103
|
+
suitable for, and under terms that permit, the user to
|
|
104
|
+
recombine or relink the Application with a modified version of
|
|
105
|
+
the Linked Version to produce a modified Combined Work, in the
|
|
106
|
+
manner specified by section 6 of the GNU GPL for conveying
|
|
107
|
+
Corresponding Source.
|
|
108
|
+
|
|
109
|
+
1) Use a suitable shared library mechanism for linking with the
|
|
110
|
+
Library. A suitable mechanism is one that (a) uses at run time
|
|
111
|
+
a copy of the Library already present on the user's computer
|
|
112
|
+
system, and (b) will operate properly with a modified version
|
|
113
|
+
of the Library that is interface-compatible with the Linked
|
|
114
|
+
Version.
|
|
115
|
+
|
|
116
|
+
e) Provide Installation Information, but only if you would otherwise
|
|
117
|
+
be required to provide such information under section 6 of the
|
|
118
|
+
GNU GPL, and only to the extent that such information is
|
|
119
|
+
necessary to install and execute a modified version of the
|
|
120
|
+
Combined Work produced by recombining or relinking the
|
|
121
|
+
Application with a modified version of the Linked Version. (If
|
|
122
|
+
you use option 4d0, the Installation Information must accompany
|
|
123
|
+
the Minimal Corresponding Source and Corresponding Application
|
|
124
|
+
Code. If you use option 4d1, you must provide the Installation
|
|
125
|
+
Information in the manner specified by section 6 of the GNU GPL
|
|
126
|
+
for conveying Corresponding Source.)
|
|
127
|
+
|
|
128
|
+
5. Combined Libraries.
|
|
129
|
+
|
|
130
|
+
You may place library facilities that are a work based on the
|
|
131
|
+
Library side by side in a single library together with other library
|
|
132
|
+
facilities that are not Applications and are not covered by this
|
|
133
|
+
License, and convey such a combined library under terms of your
|
|
134
|
+
choice, if you do both of the following:
|
|
135
|
+
|
|
136
|
+
a) Accompany the combined library with a copy of the same work based
|
|
137
|
+
on the Library, uncombined with any other library facilities,
|
|
138
|
+
conveyed under the terms of this License.
|
|
139
|
+
|
|
140
|
+
b) Give prominent notice with the combined library that part of it
|
|
141
|
+
is a work based on the Library, and explaining where to find the
|
|
142
|
+
accompanying uncombined form of the same work.
|
|
143
|
+
|
|
144
|
+
6. Revised Versions of the GNU Lesser General Public License.
|
|
145
|
+
|
|
146
|
+
The Free Software Foundation may publish revised and/or new versions
|
|
147
|
+
of the GNU Lesser General Public License from time to time. Such new
|
|
148
|
+
versions will be similar in spirit to the present version, but may
|
|
149
|
+
differ in detail to address new problems or concerns.
|
|
150
|
+
|
|
151
|
+
Each version is given a distinguishing version number. If the
|
|
152
|
+
Library as you received it specifies that a certain numbered version
|
|
153
|
+
of the GNU Lesser General Public License "or any later version"
|
|
154
|
+
applies to it, you have the option of following the terms and
|
|
155
|
+
conditions either of that published version or of any later version
|
|
156
|
+
published by the Free Software Foundation. If the Library as you
|
|
157
|
+
received it does not specify a version number of the GNU Lesser
|
|
158
|
+
General Public License, you may choose any version of the GNU Lesser
|
|
159
|
+
General Public License ever published by the Free Software Foundation.
|
|
160
|
+
|
|
161
|
+
If the Library as you received it specifies that a proxy can decide
|
|
162
|
+
whether future versions of the GNU Lesser General Public License shall
|
|
163
|
+
apply, that proxy's public statement of acceptance of any version is
|
|
164
|
+
permanent authorization for you to choose that version for the
|
|
165
|
+
Library.
|
package/README.en.md
CHANGED
|
@@ -55,7 +55,7 @@ Default ports:
|
|
|
55
55
|
|
|
56
56
|
- Main AI: `127.0.0.1:5080`
|
|
57
57
|
- Identity + Web: `127.0.0.1:5081`
|
|
58
|
-
|
|
58
|
+
## Attention! before all mode start,you must start a redis server first.
|
|
59
59
|
### Mode A (Recommended): Identity+Web hosts UI and proxies `/api`
|
|
60
60
|
|
|
61
61
|
1) Start the main AI process (serves `/api/*` only):
|
|
@@ -67,6 +67,12 @@ $env:AI_AUTH_JWT_SECRET="change-me"
|
|
|
67
67
|
node .\main.cjs
|
|
68
68
|
```
|
|
69
69
|
|
|
70
|
+
If you want to use the “performance/concurrency experimental switches” (`--group-proc` / `--infer-mp` / `--single-proc`), use:
|
|
71
|
+
|
|
72
|
+
```powershell
|
|
73
|
+
node .\mainFailedOfJing1Xi4Hua4Zhi4Duan3Yu3.cjs
|
|
74
|
+
```
|
|
75
|
+
|
|
70
76
|
2) Start the identity + web process (hosts UI and proxies `/api/*` to the main AI):
|
|
71
77
|
|
|
72
78
|
```powershell
|
|
@@ -127,6 +133,72 @@ Open: `http://127.0.0.1:5081/`
|
|
|
127
133
|
|
|
128
134
|
---
|
|
129
135
|
|
|
136
|
+
## Quick Start Matrix (By Scenario)
|
|
137
|
+
|
|
138
|
+
Notes:
|
|
139
|
+
|
|
140
|
+
- `main.cjs`: “classic single-process” entry (stable/default).
|
|
141
|
+
- `mainFailedOfJing1Xi4Hua4Zhi4Duan3Yu3.cjs`: entry that includes experimental concurrency switches (`--group-proc` / `--infer-mp` / `--single-proc`).
|
|
142
|
+
|
|
143
|
+
### Scenario 1: Minimal local dev (single process + no auth + fast boot)
|
|
144
|
+
|
|
145
|
+
```powershell
|
|
146
|
+
cd "079Project/"
|
|
147
|
+
$env:AI_AUTH_ENABLED="false"
|
|
148
|
+
$env:AI_ROBOTS_AUTOLOAD="false"
|
|
149
|
+
node .\mainFailedOfJing1Xi4Hua4Zhi4Duan3Yu3.cjs --single-proc=true --robots-autoload=false --tests-autoload=false --port=5080
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
### Scenario 2: Recommended daily use (two processes: Identity/UI + API reverse proxy)
|
|
153
|
+
|
|
154
|
+
Main AI:
|
|
155
|
+
|
|
156
|
+
```powershell
|
|
157
|
+
cd "079Project/"
|
|
158
|
+
$env:AI_AUTH_ENABLED="true"
|
|
159
|
+
$env:AI_AUTH_JWT_SECRET="change-me"
|
|
160
|
+
node .\main.cjs --port=5080
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
Identity + Web:
|
|
164
|
+
|
|
165
|
+
```powershell
|
|
166
|
+
cd "079Project/"
|
|
167
|
+
$env:AUTH_JWT_SECRET="change-me"
|
|
168
|
+
$env:AI_API_BASE="http://127.0.0.1:5080"
|
|
169
|
+
node .\auth_frontend_server.cjs
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
### Scenario 3: Force single-process (more predictable if multi-process is slower)
|
|
173
|
+
|
|
174
|
+
```powershell
|
|
175
|
+
cd "079Project/"
|
|
176
|
+
node .\mainFailedOfJing1Xi4Hua4Zhi4Duan3Yu3.cjs --single-proc=true --port=5080
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
`--single-proc=true` forces `--group-proc=false` and `--infer-mp=false`.
|
|
180
|
+
|
|
181
|
+
### Scenario 4: Higher throughput on multi-core (one process per group)
|
|
182
|
+
|
|
183
|
+
Good for heavier requests and higher concurrency; may be slower if IPC overhead dominates.
|
|
184
|
+
|
|
185
|
+
```powershell
|
|
186
|
+
cd "079Project/"
|
|
187
|
+
$env:AI_AUTH_ENABLED="false"
|
|
188
|
+
node .\mainFailedOfJing1Xi4Hua4Zhi4Duan3Yu3.cjs --group-proc=true --group-count=6 --group-size=3 --port=5080
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
### Scenario 5: Multi-core inference pool (Spark dispatch only; not group-proc)
|
|
192
|
+
|
|
193
|
+
```powershell
|
|
194
|
+
cd "079Project/"
|
|
195
|
+
node .\mainFailedOfJing1Xi4Hua4Zhi4Duan3Yu3.cjs --infer-mp=true --infer-workers=6 --port=5080
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
Note: when `group-proc` is enabled, `infer-mp` is automatically disabled (to avoid double multi-processing).
|
|
199
|
+
|
|
200
|
+
---
|
|
201
|
+
|
|
130
202
|
## Main AI CLI Options (Common)
|
|
131
203
|
|
|
132
204
|
`main.cjs` supports some CLI / env options (partial list):
|
|
@@ -145,6 +217,14 @@ Example: listen on `0.0.0.0:5080`:
|
|
|
145
217
|
node .\main.cjs --gateway-host=0.0.0.0 --port=5080
|
|
146
218
|
```
|
|
147
219
|
|
|
220
|
+
Extra options supported by `mainFailedOfJing1Xi4Hua4Zhi4Duan3Yu3.cjs` (concurrency/perf experiments):
|
|
221
|
+
|
|
222
|
+
- `--single-proc` / `AI_SINGLE_PROC`: force single-process (disables `group-proc` and `infer-mp`).
|
|
223
|
+
- `--group-proc` / `AI_GROUP_PROC`: one process per group.
|
|
224
|
+
- `--group-proc-timeout-ms` / `AI_GROUP_PROC_TIMEOUT_MS`: RPC timeout for group workers.
|
|
225
|
+
- `--infer-mp` / `AI_INFER_MP`: inference worker pool (Spark dispatch only).
|
|
226
|
+
- `--infer-workers` / `AI_INFER_WORKERS`: number of inference workers.
|
|
227
|
+
|
|
148
228
|
---
|
|
149
229
|
|
|
150
230
|
## Identity System (SQLite + JWT)
|
package/README.md
CHANGED
|
@@ -55,7 +55,7 @@ npm install
|
|
|
55
55
|
|
|
56
56
|
- 主 AI:`127.0.0.1:5080`
|
|
57
57
|
- 身份 + 前端:`127.0.0.1:5081`
|
|
58
|
-
|
|
58
|
+
## 注意,在所有的启动之前,必须要先启动一个redis服务器
|
|
59
59
|
### 模式 A:推荐(身份+前端托管 + /api 反代)
|
|
60
60
|
|
|
61
61
|
1) 启动主 AI(只提供 `/api/*`):
|
|
@@ -67,6 +67,12 @@ $env:AI_AUTH_JWT_SECRET="change-me"
|
|
|
67
67
|
node .\main.cjs
|
|
68
68
|
```
|
|
69
69
|
|
|
70
|
+
如果你需要启用“性能/并发实验功能”(`--group-proc`/`--infer-mp`/`--single-proc`),请改用:
|
|
71
|
+
|
|
72
|
+
```powershell
|
|
73
|
+
node .\mainFailedOfJing1Xi4Hua4Zhi4Duan3Yu3.cjs
|
|
74
|
+
```
|
|
75
|
+
|
|
70
76
|
2) 启动身份服务 + 前端托管(同时反代 `/api/*` 到主 AI):
|
|
71
77
|
|
|
72
78
|
```powershell
|
|
@@ -129,6 +135,76 @@ node .\auth_frontend_server.cjs
|
|
|
129
135
|
|
|
130
136
|
---
|
|
131
137
|
|
|
138
|
+
## 启动方式速查(按场景)
|
|
139
|
+
|
|
140
|
+
说明:
|
|
141
|
+
|
|
142
|
+
- `main.cjs`:偏“传统单进程”入口(稳定/默认)。
|
|
143
|
+
- `mainFailedOfJing1Xi4Hua4Zhi4Duan3Yu3.cjs`:包含并发实验开关(`--group-proc`/`--infer-mp`/`--single-proc`)的入口。
|
|
144
|
+
|
|
145
|
+
### 场景 1:最简本地调试(单进程 + 免鉴权 + 快速启动)
|
|
146
|
+
|
|
147
|
+
```powershell
|
|
148
|
+
cd "079Project/"
|
|
149
|
+
$env:AI_AUTH_ENABLED="false"
|
|
150
|
+
$env:AI_ROBOTS_AUTOLOAD="false"
|
|
151
|
+
node .\mainFailedOfJing1Xi4Hua4Zhi4Duan3Yu3.cjs --single-proc=true --robots-autoload=false --tests-autoload=false --port=5080
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
### 场景 2:推荐日常使用(两进程:身份/前端托管 + API 反代)
|
|
155
|
+
|
|
156
|
+
主 AI:
|
|
157
|
+
|
|
158
|
+
```powershell
|
|
159
|
+
cd "079Project/"
|
|
160
|
+
$env:AI_AUTH_ENABLED="true"
|
|
161
|
+
$env:AI_AUTH_JWT_SECRET="change-me"
|
|
162
|
+
node .\main.cjs --port=5080
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
身份 + 前端:
|
|
166
|
+
|
|
167
|
+
```powershell
|
|
168
|
+
cd "079Project/"
|
|
169
|
+
$env:AUTH_JWT_SECRET="change-me"
|
|
170
|
+
$env:AI_API_BASE="http://127.0.0.1:5080"
|
|
171
|
+
node .\auth_frontend_server.cjs
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
### 场景 3:强制单进程(避免多进程导致变慢/更稳定)
|
|
175
|
+
|
|
176
|
+
当你发现多进程模式在当前机器/当前负载下反而更慢,使用:
|
|
177
|
+
|
|
178
|
+
```powershell
|
|
179
|
+
cd "079Project/"
|
|
180
|
+
node .\mainFailedOfJing1Xi4Hua4Zhi4Duan3Yu3.cjs --single-proc=true --port=5080
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
说明:`--single-proc=true` 会强制关闭 `--group-proc` 与 `--infer-mp`。
|
|
184
|
+
|
|
185
|
+
### 场景 4:多核吞吐(每个 group 一个进程)
|
|
186
|
+
|
|
187
|
+
适用于并发请求较多、单次请求较重、且 CPU 核数充足的机器;如果请求很轻或 IPC 开销占比过高,可能“更慢”。
|
|
188
|
+
|
|
189
|
+
```powershell
|
|
190
|
+
cd "079Project/"
|
|
191
|
+
$env:AI_AUTH_ENABLED="false"
|
|
192
|
+
node .\mainFailedOfJing1Xi4Hua4Zhi4Duan3Yu3.cjs --group-proc=true --group-count=6 --group-size=3 --port=5080
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
### 场景 5:多核加速(推理多进程池,仅用于 Spark 汇聚的 respond 分发)
|
|
196
|
+
|
|
197
|
+
适用于不启用 `group-proc` 的情况下,想让 SparkArray/BigSparkArray 的分发利用多核:
|
|
198
|
+
|
|
199
|
+
```powershell
|
|
200
|
+
cd "079Project/"
|
|
201
|
+
node .\mainFailedOfJing1Xi4Hua4Zhi4Duan3Yu3.cjs --infer-mp=true --infer-workers=6 --port=5080
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
说明:启用 `group-proc` 时会自动禁用 `infer-mp`(避免双层多进程)。
|
|
205
|
+
|
|
206
|
+
---
|
|
207
|
+
|
|
132
208
|
## 后端启动参数(常用)
|
|
133
209
|
|
|
134
210
|
`main.cjs` 支持部分 CLI/环境变量(这里只列近期常用的):
|
|
@@ -147,6 +223,14 @@ node .\auth_frontend_server.cjs
|
|
|
147
223
|
node .\main.cjs --gateway-host=0.0.0.0 --port=5080
|
|
148
224
|
```
|
|
149
225
|
|
|
226
|
+
`mainFailedOfJing1Xi4Hua4Zhi4Duan3Yu3.cjs` 额外支持(并发/性能实验):
|
|
227
|
+
|
|
228
|
+
- `--single-proc` / `AI_SINGLE_PROC`:强制单进程(关闭 `group-proc` 与 `infer-mp`)。
|
|
229
|
+
- `--group-proc` / `AI_GROUP_PROC`:每个 group 一个进程。
|
|
230
|
+
- `--group-proc-timeout-ms` / `AI_GROUP_PROC_TIMEOUT_MS`:group RPC 超时。
|
|
231
|
+
- `--infer-mp` / `AI_INFER_MP`:推理多进程池(仅分发 Spark 汇聚推理)。
|
|
232
|
+
- `--infer-workers` / `AI_INFER_WORKERS`:推理子进程数量。
|
|
233
|
+
|
|
150
234
|
## 身份系统(SQLite + JWT)
|
|
151
235
|
|
|
152
236
|
身份系统存储:默认 `079Project/runtime_store/auth.sqlite`。
|
|
Binary file
|
package/groupWorker.cjs
ADDED
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const path = require('path');
|
|
4
|
+
|
|
5
|
+
const GROUP_ID = String(process.env.AI_GROUP_ID || 'G1').trim() || 'G1';
|
|
6
|
+
const GROUP_SIZE = Math.max(1, Number(process.env.AI_GROUP_SIZE || 7) || 7);
|
|
7
|
+
const LMDB_ROOT = String(process.env.AI_LMDB_ROOT || path.join(__dirname, 'lmdb'));
|
|
8
|
+
const LMDB_MAP_BYTES = Math.max(64 * 1024 * 1024, Number(process.env.AI_LMDB_MAP_BYTES || 512 * 1024 * 1024) || 512 * 1024 * 1024);
|
|
9
|
+
|
|
10
|
+
const core = require('./mainFailedOfJing1Xi4Hua4Zhi4Duan3Yu3.cjs');
|
|
11
|
+
|
|
12
|
+
const { LmdbStore, NamespacedStore, RuntimeState, MemeBarrier } = core;
|
|
13
|
+
const modelDefaults = core.MODEL_DEFAULTS || {};
|
|
14
|
+
|
|
15
|
+
const safeCall = async (fn) => {
|
|
16
|
+
try {
|
|
17
|
+
const result = await Promise.resolve().then(fn);
|
|
18
|
+
return { ok: true, result };
|
|
19
|
+
} catch (e) {
|
|
20
|
+
return { ok: false, error: e?.message || String(e) };
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const kvmStore = new LmdbStore({ name: 'kvm', rootDir: LMDB_ROOT, mapSizeBytes: LMDB_MAP_BYTES });
|
|
25
|
+
const memeStore = new LmdbStore({ name: 'meme_graph', rootDir: LMDB_ROOT, mapSizeBytes: LMDB_MAP_BYTES });
|
|
26
|
+
const sessionStore = new LmdbStore({ name: 'session', rootDir: LMDB_ROOT, mapSizeBytes: LMDB_MAP_BYTES });
|
|
27
|
+
|
|
28
|
+
const sharedStores = {
|
|
29
|
+
kvmStore: new NamespacedStore(kvmStore, `${GROUP_ID}:kvm`),
|
|
30
|
+
memeStore: new NamespacedStore(memeStore, `${GROUP_ID}:graph`),
|
|
31
|
+
sessionStore: new NamespacedStore(sessionStore, `${GROUP_ID}:session`)
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const controllers = {}; // name -> { runtime }
|
|
35
|
+
const controllerNames = [];
|
|
36
|
+
for (let i = 0; i < GROUP_SIZE; i++) {
|
|
37
|
+
const name = `${GROUP_ID}_AI${i + 1}`;
|
|
38
|
+
controllerNames.push(name);
|
|
39
|
+
const stores = {
|
|
40
|
+
...sharedStores,
|
|
41
|
+
config: {
|
|
42
|
+
controllerName: name,
|
|
43
|
+
groupId: GROUP_ID,
|
|
44
|
+
groupIndex: i + 1,
|
|
45
|
+
robotsDir: process.env.AI_ROBOTS_DIR || undefined,
|
|
46
|
+
testsDir: process.env.AI_TESTS_DIR || undefined
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
controllers[name] = { runtime: new RuntimeState(stores) };
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const getRuntime = (controllerName) => {
|
|
53
|
+
const name = String(controllerName || '').trim();
|
|
54
|
+
if (!name) throw new Error('controllerName required');
|
|
55
|
+
const entry = controllers[name];
|
|
56
|
+
if (!entry) throw new Error(`controller-not-found:${name}`);
|
|
57
|
+
return entry.runtime;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
const allowedRuntimeCalls = new Set([
|
|
61
|
+
'onlineLookup',
|
|
62
|
+
'collectRobotsDocuments',
|
|
63
|
+
'listRobotsFiles',
|
|
64
|
+
'exportGraphToFile',
|
|
65
|
+
'getSearchConfig',
|
|
66
|
+
'setSearchConfig',
|
|
67
|
+
'learnFromDialog'
|
|
68
|
+
]);
|
|
69
|
+
|
|
70
|
+
let memeBarrier = null;
|
|
71
|
+
const getBarrier = (maliciousThreshold) => {
|
|
72
|
+
if (!MemeBarrier) {
|
|
73
|
+
throw new Error('MemeBarrier export missing');
|
|
74
|
+
}
|
|
75
|
+
if (!memeBarrier) {
|
|
76
|
+
const runtime = controllers[controllerNames[0]]?.runtime;
|
|
77
|
+
if (!runtime) {
|
|
78
|
+
throw new Error('no-runtime-for-barrier');
|
|
79
|
+
}
|
|
80
|
+
memeBarrier = new MemeBarrier(runtime, {
|
|
81
|
+
maliciousThreshold: Number.isFinite(Number(maliciousThreshold))
|
|
82
|
+
? Number(maliciousThreshold)
|
|
83
|
+
: (modelDefaults.maliciousThreshold ?? 0.7)
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
return memeBarrier;
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
process.on('message', async (msg) => {
|
|
90
|
+
if (!msg || typeof msg !== 'object') return;
|
|
91
|
+
const { id, cmd } = msg;
|
|
92
|
+
if (!id || !cmd) return;
|
|
93
|
+
|
|
94
|
+
const reply = await safeCall(async () => {
|
|
95
|
+
if (cmd === 'respond') {
|
|
96
|
+
const runtime = getRuntime(msg.controllerName);
|
|
97
|
+
return runtime.processInput(msg.payload || {});
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
if (cmd === 'metrics') {
|
|
101
|
+
const runtime = getRuntime(msg.controllerName);
|
|
102
|
+
return {
|
|
103
|
+
name: String(msg.controllerName),
|
|
104
|
+
online: true,
|
|
105
|
+
health: { status: 'ok', since: Date.now(), failures: 0 },
|
|
106
|
+
metrics: runtime.metrics,
|
|
107
|
+
params: runtime.cloneParams()
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
if (cmd === 'cloneParams') {
|
|
112
|
+
const runtime = getRuntime(msg.controllerName);
|
|
113
|
+
return runtime.cloneParams();
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
if (cmd === 'applyParams') {
|
|
117
|
+
const runtime = getRuntime(msg.controllerName);
|
|
118
|
+
runtime.setParams(msg.params || {});
|
|
119
|
+
return true;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
if (cmd === 'snapshot') {
|
|
123
|
+
const runtime = getRuntime(msg.controllerName);
|
|
124
|
+
return runtime.toSnapshot();
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
if (cmd === 'applySnapshot') {
|
|
128
|
+
const runtime = getRuntime(msg.controllerName);
|
|
129
|
+
await runtime.fromSnapshot(msg.snapshot);
|
|
130
|
+
return true;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
if (cmd === 'applySnapshotAll') {
|
|
134
|
+
const snapshot = msg.snapshot;
|
|
135
|
+
for (const name of controllerNames) {
|
|
136
|
+
const runtime = getRuntime(name);
|
|
137
|
+
await runtime.fromSnapshot(snapshot);
|
|
138
|
+
}
|
|
139
|
+
return true;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
if (cmd === 'listMetrics') {
|
|
143
|
+
return controllerNames.map((name) => {
|
|
144
|
+
const runtime = controllers[name].runtime;
|
|
145
|
+
return {
|
|
146
|
+
name,
|
|
147
|
+
online: true,
|
|
148
|
+
health: { status: 'ok', since: Date.now(), failures: 0 },
|
|
149
|
+
metrics: runtime.metrics,
|
|
150
|
+
params: runtime.cloneParams()
|
|
151
|
+
};
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
if (cmd === 'ingestDocument') {
|
|
156
|
+
const doc = msg.doc || {};
|
|
157
|
+
const results = [];
|
|
158
|
+
for (const name of controllerNames) {
|
|
159
|
+
const runtime = getRuntime(name);
|
|
160
|
+
results.push(await runtime.ingestDocument(doc));
|
|
161
|
+
}
|
|
162
|
+
return results;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
if (cmd === 'ingestDocumentTo') {
|
|
166
|
+
const runtime = getRuntime(msg.controllerName);
|
|
167
|
+
return runtime.ingestDocument(msg.doc || {});
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
if (cmd === 'ingestDocumentToGroup') {
|
|
171
|
+
const doc = msg.doc || {};
|
|
172
|
+
const results = [];
|
|
173
|
+
for (const name of controllerNames) {
|
|
174
|
+
const runtime = getRuntime(name);
|
|
175
|
+
results.push(await runtime.ingestDocument(doc));
|
|
176
|
+
}
|
|
177
|
+
return results;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
if (cmd === 'forgetMemes') {
|
|
181
|
+
const criteria = msg.criteria || {};
|
|
182
|
+
const results = [];
|
|
183
|
+
for (const name of controllerNames) {
|
|
184
|
+
const runtime = getRuntime(name);
|
|
185
|
+
results.push(await runtime.forgetMemes(criteria));
|
|
186
|
+
}
|
|
187
|
+
return results;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
if (cmd === 'runtimeCall') {
|
|
191
|
+
const runtime = getRuntime(msg.controllerName);
|
|
192
|
+
const method = String(msg.method || '').trim();
|
|
193
|
+
if (!allowedRuntimeCalls.has(method)) {
|
|
194
|
+
throw new Error(`runtimeCall not allowed: ${method}`);
|
|
195
|
+
}
|
|
196
|
+
const args = Array.isArray(msg.args) ? msg.args : [];
|
|
197
|
+
const fn = runtime[method];
|
|
198
|
+
if (typeof fn !== 'function') {
|
|
199
|
+
throw new Error(`runtime method missing: ${method}`);
|
|
200
|
+
}
|
|
201
|
+
return fn.apply(runtime, args);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
if (cmd === 'memebarrierStart') {
|
|
205
|
+
const barrier = getBarrier(msg.maliciousThreshold);
|
|
206
|
+
if (typeof msg.maliciousThreshold === 'number' && Number.isFinite(msg.maliciousThreshold)) {
|
|
207
|
+
barrier.maliciousThreshold = msg.maliciousThreshold;
|
|
208
|
+
}
|
|
209
|
+
barrier.start();
|
|
210
|
+
return { running: true, threshold: barrier.maliciousThreshold, stats: barrier.getStats() };
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
if (cmd === 'memebarrierStop') {
|
|
214
|
+
if (memeBarrier) {
|
|
215
|
+
memeBarrier.stop();
|
|
216
|
+
}
|
|
217
|
+
return { running: false };
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
if (cmd === 'memebarrierStats') {
|
|
221
|
+
if (!memeBarrier) {
|
|
222
|
+
return { running: false, threshold: (modelDefaults.maliciousThreshold ?? 0.7), stats: null };
|
|
223
|
+
}
|
|
224
|
+
return { running: Boolean(memeBarrier.running), threshold: memeBarrier.maliciousThreshold, stats: memeBarrier.getStats() };
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
if (cmd === 'memebarrierSetThreshold') {
|
|
228
|
+
const value = Number(msg.maliciousThreshold);
|
|
229
|
+
if (!Number.isFinite(value)) {
|
|
230
|
+
throw new Error('invalid-threshold');
|
|
231
|
+
}
|
|
232
|
+
const barrier = getBarrier(value);
|
|
233
|
+
barrier.maliciousThreshold = value;
|
|
234
|
+
return { threshold: barrier.maliciousThreshold };
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
throw new Error(`unknown-cmd:${cmd}`);
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
try {
|
|
241
|
+
process.send({ id, ...reply });
|
|
242
|
+
} catch (_e) {
|
|
243
|
+
// ignore
|
|
244
|
+
}
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
process.on('SIGINT', () => {
|
|
248
|
+
process.exit(0);
|
|
249
|
+
});
|
|
250
|
+
|
|
251
|
+
process.on('disconnect', () => {
|
|
252
|
+
process.exit(0);
|
|
253
|
+
});
|