@maiyunnet/kebab 3.2.23 → 3.2.25
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/index.d.ts +3 -1
- package/index.js +1 -1
- package/lib/ai.d.ts +8 -2
- package/lib/ai.js +9 -2
- package/lib/kv.d.ts +1 -0
- package/lib/kv.js +1 -0
- package/package.json +1 -1
- package/sys/child.js +4 -2
- package/sys/cmd.js +3 -0
- package/sys/mod.d.ts +4 -0
- package/sys/mod.js +8 -1
- package/sys/route.d.ts +1 -1
- package/sys/route.js +2 -3
package/index.d.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* --- 本文件用来定义每个目录实体地址的常量 ---
|
|
6
6
|
*/
|
|
7
7
|
/** --- 当前系统版本号 --- */
|
|
8
|
-
export declare const VER = "3.2.
|
|
8
|
+
export declare const VER = "3.2.25";
|
|
9
9
|
/** --- 框架根目录,以 / 结尾 --- */
|
|
10
10
|
export declare const ROOT_PATH: string;
|
|
11
11
|
export declare const LIB_PATH: string;
|
|
@@ -84,6 +84,8 @@ export interface IConfigS3 {
|
|
|
84
84
|
}
|
|
85
85
|
/** --- AI --- */
|
|
86
86
|
export interface IConfigAi {
|
|
87
|
+
/** --- 目前只有微软 Azure 有 --- */
|
|
88
|
+
'endpoint'?: string;
|
|
87
89
|
'skey': string;
|
|
88
90
|
}
|
|
89
91
|
/** --- 向量数据库 --- */
|
package/index.js
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* --- 本文件用来定义每个目录实体地址的常量 ---
|
|
7
7
|
*/
|
|
8
8
|
/** --- 当前系统版本号 --- */
|
|
9
|
-
export const VER = '3.2.
|
|
9
|
+
export const VER = '3.2.25';
|
|
10
10
|
// --- 服务端用的路径 ---
|
|
11
11
|
const imu = decodeURIComponent(import.meta.url).replace('file://', '').replace(/^\/(\w:)/, '$1');
|
|
12
12
|
/** --- /xxx/xxx --- */
|
package/lib/ai.d.ts
CHANGED
|
@@ -14,14 +14,20 @@ export declare enum ESERVICE {
|
|
|
14
14
|
/** --- 阿里中国大陆区 --- */
|
|
15
15
|
'ALICN' = 0,
|
|
16
16
|
/** --- 阿里国际区 --- */
|
|
17
|
-
'ALIAS' = 1
|
|
17
|
+
'ALIAS' = 1,
|
|
18
|
+
/** --- 微软 Azure --- */
|
|
19
|
+
'AZURE' = 2
|
|
18
20
|
}
|
|
19
21
|
/** --- 选项 --- */
|
|
20
22
|
export interface IOptions {
|
|
21
23
|
/** --- 服务商 ---- */
|
|
22
24
|
'service': ESERVICE;
|
|
23
|
-
/** ---
|
|
25
|
+
/** --- 接入点 --- */
|
|
26
|
+
'endpoint'?: string;
|
|
27
|
+
/** --- 密钥 --- */
|
|
24
28
|
'secretKey'?: string;
|
|
29
|
+
/** --- 自定义 fetch 函数 --- */
|
|
30
|
+
'fetch'?: (input: string | URL | Request, init?: RequestInit) => Promise<Response>;
|
|
25
31
|
}
|
|
26
32
|
export declare class Ai {
|
|
27
33
|
/** --- openai 原生对象,建议只读 --- */
|
package/lib/ai.js
CHANGED
|
@@ -15,6 +15,8 @@ export var ESERVICE;
|
|
|
15
15
|
ESERVICE[ESERVICE["ALICN"] = 0] = "ALICN";
|
|
16
16
|
/** --- 阿里国际区 --- */
|
|
17
17
|
ESERVICE[ESERVICE["ALIAS"] = 1] = "ALIAS";
|
|
18
|
+
/** --- 微软 Azure --- */
|
|
19
|
+
ESERVICE[ESERVICE["AZURE"] = 2] = "AZURE";
|
|
18
20
|
})(ESERVICE || (ESERVICE = {}));
|
|
19
21
|
/** --- openai 的连接对象 --- */
|
|
20
22
|
const links = [];
|
|
@@ -25,11 +27,15 @@ export class Ai {
|
|
|
25
27
|
let endpoint;
|
|
26
28
|
switch (opt.service) {
|
|
27
29
|
case ESERVICE.ALICN: {
|
|
28
|
-
endpoint = `https://dashscope.aliyuncs.com/compatible-mode/v1`;
|
|
30
|
+
endpoint = opt.endpoint ?? `https://dashscope.aliyuncs.com/compatible-mode/v1`;
|
|
29
31
|
break;
|
|
30
32
|
}
|
|
31
33
|
case ESERVICE.ALIAS: {
|
|
32
|
-
endpoint = `https://dashscope-intl.aliyuncs.com/compatible-mode/v1`;
|
|
34
|
+
endpoint = opt.endpoint ?? `https://dashscope-intl.aliyuncs.com/compatible-mode/v1`;
|
|
35
|
+
break;
|
|
36
|
+
}
|
|
37
|
+
case ESERVICE.AZURE: {
|
|
38
|
+
endpoint = opt.endpoint ?? config.ai?.[ESERVICE[opt.service]]?.endpoint ?? '';
|
|
33
39
|
break;
|
|
34
40
|
}
|
|
35
41
|
default: {
|
|
@@ -45,6 +51,7 @@ export class Ai {
|
|
|
45
51
|
this.link = new openai.OpenAI({
|
|
46
52
|
'apiKey': secretKey,
|
|
47
53
|
'baseURL': endpoint,
|
|
54
|
+
'fetch': opt.fetch,
|
|
48
55
|
});
|
|
49
56
|
links.push({
|
|
50
57
|
'token': token,
|
package/lib/kv.d.ts
CHANGED
package/lib/kv.js
CHANGED
package/package.json
CHANGED
package/sys/child.js
CHANGED
|
@@ -90,7 +90,7 @@ async function run() {
|
|
|
90
90
|
const host = (req.headers[':authority'] ?? req.headers['host'] ?? '');
|
|
91
91
|
if (!host) {
|
|
92
92
|
lCore.writeHead(res, 403);
|
|
93
|
-
res.end();
|
|
93
|
+
res.end('403 Forbidden');
|
|
94
94
|
return;
|
|
95
95
|
}
|
|
96
96
|
const key = host + req.url;
|
|
@@ -141,6 +141,7 @@ async function run() {
|
|
|
141
141
|
httpServer = http.createServer(function (req, res) {
|
|
142
142
|
const host = (req.headers['host'] ?? '');
|
|
143
143
|
if (!host) {
|
|
144
|
+
res.setHeader('x-kebab-error', '0');
|
|
144
145
|
lCore.writeHead(res, 403);
|
|
145
146
|
res.end();
|
|
146
147
|
return;
|
|
@@ -233,6 +234,7 @@ async function requestHandler(req, res, https) {
|
|
|
233
234
|
/** --- 当前的 vhost 配置文件 --- */
|
|
234
235
|
const vhost = await getVhostByHostname(uri.hostname ?? '');
|
|
235
236
|
if (!vhost) {
|
|
237
|
+
res.setHeader('x-kebab-error', '1');
|
|
236
238
|
lCore.writeHead(res, 403);
|
|
237
239
|
res.end();
|
|
238
240
|
return;
|
|
@@ -553,7 +555,7 @@ process.on('message', function (msg) {
|
|
|
553
555
|
for (const key in linkCount) {
|
|
554
556
|
str.push(key + ':' + linkCount[key].toString());
|
|
555
557
|
}
|
|
556
|
-
lCore.
|
|
558
|
+
lCore.debug(`[CHILD] Worker ${process.pid} busy: ${str.join(',')}.`);
|
|
557
559
|
lCore.log({}, `[CHILD] Worker ${process.pid} busy: ${str.join(',')}.`, '-warning');
|
|
558
560
|
await lCore.sleep(30_000);
|
|
559
561
|
waiting += 30_000;
|
package/sys/cmd.js
CHANGED
|
@@ -152,6 +152,9 @@ async function run() {
|
|
|
152
152
|
config.ai['ALICN'].skey ??= '';
|
|
153
153
|
config.ai['ALIAS'] ??= {};
|
|
154
154
|
config.ai['ALIAS'].skey ??= '';
|
|
155
|
+
config.ai['AZURE'] ??= {};
|
|
156
|
+
config.ai['AZURE'].endpoint ??= '';
|
|
157
|
+
config.ai['AZURE'].skey ??= '';
|
|
155
158
|
// --- config - vector ---
|
|
156
159
|
config.vector ??= {};
|
|
157
160
|
config.vector.host ??= '127.0.0.1';
|
package/sys/mod.d.ts
CHANGED
package/sys/mod.js
CHANGED
|
@@ -1184,7 +1184,7 @@ class Mod {
|
|
|
1184
1184
|
* --- 根据当前条件,筛选出当前条目该有的数据条数 ---
|
|
1185
1185
|
*/
|
|
1186
1186
|
async count() {
|
|
1187
|
-
const sql = this._sql.getSql().replace(/SELECT .+? FROM/, 'SELECT COUNT(
|
|
1187
|
+
const sql = this._sql.getSql().replace(/SELECT .+? FROM/, 'SELECT COUNT(0) AS `count` FROM');
|
|
1188
1188
|
const r = await this._db.query(sql, this._sql.getData());
|
|
1189
1189
|
if (r.rows === null) {
|
|
1190
1190
|
lCore.log(this._ctr ?? {}, '[count, mod] ' + lText.stringifyJson(r.error?.message ?? '').slice(1, -1).replace(/"/g, '""'), '-error');
|
|
@@ -1196,6 +1196,13 @@ class Mod {
|
|
|
1196
1196
|
}
|
|
1197
1197
|
return count;
|
|
1198
1198
|
}
|
|
1199
|
+
/**
|
|
1200
|
+
* --- 获取当前条件下的 count 的 SQL 语句 ---
|
|
1201
|
+
*/
|
|
1202
|
+
countSql() {
|
|
1203
|
+
const sql = this._sql.getSql().replace(/SELECT .+? FROM/, 'SELECT COUNT(0) AS `count` FROM');
|
|
1204
|
+
return this._sql.format(sql, this._sql.getData());
|
|
1205
|
+
}
|
|
1199
1206
|
/**
|
|
1200
1207
|
* @param f 表名
|
|
1201
1208
|
* @param s ON 信息
|
package/sys/route.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Project: Kebab, User: JianSuoQiYue
|
|
3
3
|
* Date: 2019-4-15 13:40
|
|
4
|
-
* Last: 2020-4-14 13:52:00, 2022-09-07 01:43:31, 2023-12-29 17:24:03, 2024-2-7 00:28:50, 2024-6-6 15:15:54, 2025-6-13 19:23:53, 2025-9-22 15:48:53, 2025-9-23 11:26:50
|
|
4
|
+
* Last: 2020-4-14 13:52:00, 2022-09-07 01:43:31, 2023-12-29 17:24:03, 2024-2-7 00:28:50, 2024-6-6 15:15:54, 2025-6-13 19:23:53, 2025-9-22 15:48:53, 2025-9-23 11:26:50, 2025-10-30 17:44:41
|
|
5
5
|
*/
|
|
6
6
|
import * as http from 'http';
|
|
7
7
|
import * as http2 from 'http2';
|
package/sys/route.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Project: Kebab, User: JianSuoQiYue
|
|
3
3
|
* Date: 2019-4-15 13:40
|
|
4
|
-
* Last: 2020-4-14 13:52:00, 2022-09-07 01:43:31, 2023-12-29 17:24:03, 2024-2-7 00:28:50, 2024-6-6 15:15:54, 2025-6-13 19:23:53, 2025-9-22 15:48:53, 2025-9-23 11:26:50
|
|
4
|
+
* Last: 2020-4-14 13:52:00, 2022-09-07 01:43:31, 2023-12-29 17:24:03, 2024-2-7 00:28:50, 2024-6-6 15:15:54, 2025-6-13 19:23:53, 2025-9-22 15:48:53, 2025-9-23 11:26:50, 2025-10-30 17:44:41
|
|
5
5
|
*/
|
|
6
6
|
import * as http from 'http';
|
|
7
7
|
import * as stream from 'stream';
|
|
@@ -12,7 +12,6 @@ import * as lFs from '#kebab/lib/fs.js';
|
|
|
12
12
|
import * as lZlib from '#kebab/lib/zlib.js';
|
|
13
13
|
import * as lCore from '#kebab/lib/core.js';
|
|
14
14
|
import * as lText from '#kebab/lib/text.js';
|
|
15
|
-
import * as lTime from '#kebab/lib/time.js';
|
|
16
15
|
import * as lResponse from '#kebab/lib/net/response.js';
|
|
17
16
|
import * as lWs from '#kebab/lib/ws.js';
|
|
18
17
|
import * as lLang from '#kebab/lib/lang.js';
|
|
@@ -567,7 +566,7 @@ export async function run(data) {
|
|
|
567
566
|
}
|
|
568
567
|
// --- 设置缓存 ---
|
|
569
568
|
if (!data.res.headersSent && (cacheTTL > 0)) {
|
|
570
|
-
data.res.setHeader('expires',
|
|
569
|
+
data.res.setHeader('expires', new Date(Date.now() + cacheTTL * 1_000).toUTCString());
|
|
571
570
|
data.res.setHeader('cache-control', 'max-age=' + cacheTTL.toString());
|
|
572
571
|
}
|
|
573
572
|
// --- 设置自定义 hcode ---
|