@maiyunnet/kebab 3.2.22 → 3.2.23

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 CHANGED
@@ -5,7 +5,7 @@
5
5
  * --- 本文件用来定义每个目录实体地址的常量 ---
6
6
  */
7
7
  /** --- 当前系统版本号 --- */
8
- export declare const VER = "3.2.22";
8
+ export declare const VER = "3.2.23";
9
9
  /** --- 框架根目录,以 / 结尾 --- */
10
10
  export declare const ROOT_PATH: string;
11
11
  export declare const LIB_PATH: string;
@@ -52,7 +52,7 @@ export interface IConfig {
52
52
  's3': Record<string, IConfigS3>;
53
53
  'turnstile': IConfigTurnstile;
54
54
  'ai': Record<string, IConfigAi>;
55
- 'vector': Record<string, IConfigVector>;
55
+ 'vector': IConfigVector;
56
56
  [key: string]: Record<string, Json>;
57
57
  }
58
58
  export interface IUrlParse {
package/index.js CHANGED
@@ -6,7 +6,7 @@
6
6
  * --- 本文件用来定义每个目录实体地址的常量 ---
7
7
  */
8
8
  /** --- 当前系统版本号 --- */
9
- export const VER = '3.2.22';
9
+ export const VER = '3.2.23';
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
@@ -26,7 +26,6 @@ export interface IOptions {
26
26
  export declare class Ai {
27
27
  /** --- openai 原生对象,建议只读 --- */
28
28
  readonly link: openai.OpenAI;
29
- private readonly _ctr;
30
29
  constructor(ctr: sCtr.Ctr, opt: IOptions);
31
30
  }
32
31
  /**
package/lib/ai.js CHANGED
@@ -20,7 +20,6 @@ export var ESERVICE;
20
20
  const links = [];
21
21
  export class Ai {
22
22
  constructor(ctr, opt) {
23
- this._ctr = ctr;
24
23
  const config = ctr.getPrototype('_config');
25
24
  const secretKey = opt.secretKey ?? config.ai?.[ESERVICE[opt.service]]?.skey ?? '';
26
25
  let endpoint;
package/lib/net.js CHANGED
@@ -155,7 +155,7 @@ export async function request(u, data, opt = {}) {
155
155
  const res = new lResponse.Response(null);
156
156
  res.error = {
157
157
  'name': 'Possible mProxy error',
158
- 'message': 'host not found'
158
+ 'message': 'host not found',
159
159
  };
160
160
  return res;
161
161
  }
@@ -165,7 +165,7 @@ export async function request(u, data, opt = {}) {
165
165
  const res = new lResponse.Response(null);
166
166
  res.error = {
167
167
  'name': 'hosts error',
168
- 'message': 'hosts param error'
168
+ 'message': 'hosts param error',
169
169
  };
170
170
  return res;
171
171
  }
@@ -176,7 +176,7 @@ export async function request(u, data, opt = {}) {
176
176
  'url': opt.mproxy ? opt.mproxy.url + (opt.mproxy.url.includes('?') ? '&' : '?') + lText.queryStringify({
177
177
  'url': u,
178
178
  'auth': opt.mproxy.auth,
179
- 'data': opt.mproxy.data ? lText.stringifyJson(opt.mproxy.data) : '{}'
179
+ 'data': opt.mproxy.data ? lText.stringifyJson(opt.mproxy.data) : '{}',
180
180
  }) : u,
181
181
  'method': method,
182
182
  'data': data,
@@ -0,0 +1,52 @@
1
+ /**
2
+ * Project: Kebab, User: JianSuoQiYue
3
+ * Date: 2025-10-28 15:18:41
4
+ * Last: 2025-10-28 15:18:44
5
+ */
6
+ import * as milvus from '@zilliz/milvus2-sdk-node';
7
+ import * as sCtr from '#kebab/sys/ctr.js';
8
+ /** --- 选项 --- */
9
+ export interface IOptions {
10
+ /** --- 主机地址 --- */
11
+ 'host'?: string;
12
+ /** --- 端口号 --- */
13
+ 'port'?: number;
14
+ /** --- 数据库名称 --- */
15
+ 'name'?: string;
16
+ /** --- 用户名 --- */
17
+ 'user'?: string;
18
+ /** --- 密码 --- */
19
+ 'pwd'?: string;
20
+ }
21
+ export declare class Vector {
22
+ /** --- milvus 原生对象,建议只读 --- */
23
+ readonly link: milvus.MilvusClient;
24
+ constructor(ctr: sCtr.Ctr, opt?: IOptions);
25
+ /** --- 搜索 --- */
26
+ seach(data: {
27
+ /** --- 表名 --- */
28
+ 'collection': string;
29
+ /** --- 查询的向量 --- */
30
+ 'data': number[];
31
+ /** --- 过滤器,如 word_count > 0 --- */
32
+ 'filter'?: string;
33
+ /** --- 返回的结果数量,默认为 20 --- */
34
+ 'limit'?: number;
35
+ /** --- 计算两个向量相似度的度量,默认 L2 --- */
36
+ 'metric'?: 'L2' | 'IP' | 'COSINE';
37
+ /** --- 输出的字段,如 ['book_id', 'word_count'],默认全部 --- */
38
+ 'fields'?: string[];
39
+ }): Promise<false | milvus.SearchResults<{
40
+ collection_name: string;
41
+ data: number[];
42
+ filter: string | undefined;
43
+ limit: number;
44
+ metric_type: "L2" | "IP" | "COSINE";
45
+ output_fields: string[] | undefined;
46
+ }>>;
47
+ }
48
+ /**
49
+ * --- 创建一个 Vector 对象 ---
50
+ * @param opt 选项
51
+ */
52
+ export declare function get(ctr: sCtr.Ctr, opt?: IOptions): Vector;
package/lib/vector.js ADDED
@@ -0,0 +1,59 @@
1
+ /**
2
+ * Project: Kebab, User: JianSuoQiYue
3
+ * Date: 2025-10-28 15:18:41
4
+ * Last: 2025-10-28 15:18:44
5
+ */
6
+ import * as milvus from '@zilliz/milvus2-sdk-node';
7
+ /** --- milvus 的连接对象 --- */
8
+ const links = [];
9
+ export class Vector {
10
+ constructor(ctr, opt) {
11
+ const config = ctr.getPrototype('_config');
12
+ const host = opt?.host ?? config.vector?.host ?? '127.0.0.1';
13
+ const port = opt?.port ?? config.vector?.port ?? 19530;
14
+ const name = opt?.name ?? config.vector?.name ?? 'default';
15
+ const user = opt?.user ?? config.vector?.user ?? 'root';
16
+ const pwd = opt?.pwd ?? config.vector?.pwd ?? 'Milvue';
17
+ const token = `${host}-${port}-${name}-${user}`;
18
+ const link = links.find((item) => item.token === token);
19
+ if (link) {
20
+ this.link = link.link;
21
+ return;
22
+ }
23
+ this.link = new milvus.MilvusClient({
24
+ 'address': `${host}:${port}`,
25
+ 'ssl': false,
26
+ 'database': name,
27
+ 'username': user,
28
+ 'password': pwd,
29
+ });
30
+ links.push({
31
+ 'token': token,
32
+ 'link': this.link,
33
+ });
34
+ }
35
+ /** --- 搜索 --- */
36
+ // eslint-disable-next-line @typescript-eslint/explicit-function-return-type
37
+ async seach(data) {
38
+ try {
39
+ return await this.link.search({
40
+ 'collection_name': data.collection,
41
+ 'data': data.data,
42
+ 'filter': data.filter,
43
+ 'limit': data.limit ?? 20,
44
+ 'metric_type': data.metric ?? 'L2',
45
+ 'output_fields': data.fields,
46
+ });
47
+ }
48
+ catch {
49
+ return false;
50
+ }
51
+ }
52
+ }
53
+ /**
54
+ * --- 创建一个 Vector 对象 ---
55
+ * @param opt 选项
56
+ */
57
+ export function get(ctr, opt) {
58
+ return new Vector(ctr, opt);
59
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@maiyunnet/kebab",
3
- "version": "3.2.22",
3
+ "version": "3.2.23",
4
4
  "description": "Simple, easy-to-use, and fully-featured Node.js framework that is ready-to-use out of the box.",
5
5
  "type": "module",
6
6
  "keywords": [
@@ -26,6 +26,7 @@
26
26
  "@litert/redis": "^3.0.5",
27
27
  "@litert/websocket": "^0.2.7",
28
28
  "@types/ssh2": "^1.15.5",
29
+ "@zilliz/milvus2-sdk-node": "^2.6.2",
29
30
  "ejs": "^3.1.10",
30
31
  "jszip": "^3.10.1",
31
32
  "mysql2": "^3.15.3",
@@ -49,6 +49,7 @@ export default class extends sCtr.Ctr {
49
49
  crypto(): Promise<string>;
50
50
  db(): Promise<kebab.Json>;
51
51
  private _dbTable;
52
+ vector(): Promise<any>;
52
53
  kv(): Promise<kebab.Json>;
53
54
  net(): Promise<string>;
54
55
  netPipe(): Promise<kebab.Json>;
@@ -72,6 +73,7 @@ export default class extends sCtr.Ctr {
72
73
  netHosts(): Promise<string>;
73
74
  netMproxy(): Promise<string | boolean>;
74
75
  netMproxy1(): Promise<string | boolean>;
76
+ netMproxy2(): any[];
75
77
  netFilterheaders(): string;
76
78
  scan(): Promise<kebab.Json>;
77
79
  scan1(): Promise<kebab.Json>;
@@ -3,6 +3,7 @@ import * as kebab from '#kebab/index.js';
3
3
  import * as lCore from '#kebab/lib/core.js';
4
4
  import * as lNet from '#kebab/lib/net.js';
5
5
  import * as lDb from '#kebab/lib/db.js';
6
+ import * as lVector from '#kebab/lib/vector.js';
6
7
  import * as lFs from '#kebab/lib/fs.js';
7
8
  import * as lText from '#kebab/lib/text.js';
8
9
  import * as lCrypto from '#kebab/lib/crypto.js';
@@ -144,6 +145,8 @@ export default class extends sCtr.Ctr {
144
145
  `<br><br><a href="${this._config.const.urlBase}test/crypto">View "test/crypto"</a>`,
145
146
  '<br><br><b>Db:</b>',
146
147
  `<br><br><a href="${this._config.const.urlBase}test/db">View "test/db"</a>`,
148
+ `<br><br><b>Vector:</b>`,
149
+ `<br><br><a href="${this._config.const.urlBase}test/vector">View "test/vector"</a>`,
147
150
  '<br><br><b>Kv:</b>',
148
151
  `<br><br><a href="${this._config.const.urlBase}test/kv">View "test/kv"</a>`,
149
152
  '<br><br><b>Net:</b>',
@@ -1337,6 +1340,20 @@ exec: ${JSON.stringify(exec)}<br><br>`);
1337
1340
  }
1338
1341
  echo.push('</table>');
1339
1342
  }
1343
+ async vector() {
1344
+ const vector = lVector.get(this);
1345
+ const res = await vector.seach({
1346
+ 'collection': 'oas_wiki',
1347
+ 'metric': 'COSINE',
1348
+ 'data': [0.4100031323819555, 0.7188991736586672, 0.32890290245747833, 0.9187961849628559, 0.023142186415922916, 0.45239563148580797, 0.23537591588175988, 0.6848990771759962, 0.9865744633216178, 0.8239142304110896, 0.997768380245414, 0.3012929412655765, 0.13731236076734943, 0.5126131685642945, 0.9806290097015617, 0.1870468071764284, 0.17178642706602143, 0.4016660911946244, 0.15484433366942607, 0.29719222215610386, 0.3103748731148619, 0.6892950176658315, 0.01785695346759608, 0.08539564964986557, 0.2655959514380064, 0.9964617086704073, 0.2838371937684081, 0.14987010598298633, 0.6228479079557896, 0.8080833516756243, 0.15438562173495285, 0.5078008662168574, 0.27262149922940804, 0.23104911473240675, 0.6266656488428926, 0.8553958245035254, 0.11699454830789868, 0.2300336351244865, 0.3042943975707315, 0.20182231286864427, 0.14334825938359863, 0.5272057735967806, 0.6568390179350452, 0.11388912236667226, 0.4916225414998463, 0.4913046496135085, 0.6301252401085475, 0.26051075673874036, 0.17023441587522825, 0.371755148312803, 0.5831318953846139, 0.9756820442368113, 0.6818893859710211, 0.5188330204766185, 0.7868335112863099, 0.7263293211859105, 0.15777067513918275, 0.25071428052177835, 0.9055952502390328, 0.39066574162485046, 0.6694768856781026, 0.904527206408617, 0.5359679189729842, 0.42923033393177423, 0.6959492373261136, 0.4721197667950616, 0.6861043448179791, 0.05188999799541438, 0.7346607591003518, 0.1574483630625012, 0.9141756884547747, 0.9116789303557802, 0.7609450526832306, 0.7763073356227885, 0.7334996162535046, 0.8036447394427264, 0.21291521237560262, 0.4628513517221038, 0.005054981316060525, 0.6289756103407573, 0.9376033918403373, 0.79713161153396, 0.1795021378890418, 0.32421299215073773, 0.5585715705291334, 0.1964507020528392, 0.9170965358836494, 0.44199069294404825, 0.46924875851341463, 0.005915168915280544, 0.4519648598811945, 0.7817208441823769, 0.39630447274483926, 0.874803477246406, 0.02593537985516514, 0.03494415508402371, 0.6948556600612117, 0.02531235612016558, 0.3252859275909026, 0.6124602304575255, 0.6662991517754546, 0.054786469959723805, 0.09541281916656552, 0.047971618444194286, 0.9888851535738363, 0.09923862294731634, 0.37389883211204245, 0.0510449762242422, 0.5140187522339308, 0.9165108670272317, 0.473682888066292, 0.7553395418192084, 0.48450479101753663, 0.22080081972551513, 0.8461012374988566, 0.32711442729081885, 0.46740436391036244, 0.9330234279632854, 0.7456194346850014, 0.8575560505025164, 0.2617623984893922, 0.6418053194775086, 0.607749877895083, 0.2176063100000032, 0.5366633111896186, 0.9689538808794083, 0.8226310778269623, 0.4813948057818185]
1349
+ });
1350
+ const echo = [`<pre>const res = await vector.seach({
1351
+ 'collection': 'oas_wiki',
1352
+ 'metric': 'COSINE',
1353
+ 'data': [0.4100031323819555, 0.7188991736586672, 0.32890290245747833, ...]
1354
+ });</pre>res:<pre>${JSON.stringify(res, null, 4)}</pre>`];
1355
+ return echo.join('') + '<br>' + this._getEnd();
1356
+ }
1340
1357
  async kv() {
1341
1358
  const kv = lKv.get(this);
1342
1359
  if (!await kv.ping()) {
@@ -1802,14 +1819,16 @@ error: <pre>${JSON.stringify(res.error, null, 4)}</pre>`);
1802
1819
  }
1803
1820
  async netMproxy() {
1804
1821
  const echo = [];
1805
- const res = await lNet.get('https://cdn.jsdelivr.net/npm/deskrt@2.0.10/package.json', {
1822
+ const res = await lNet.postJson(this._internalUrl + 'test/net-mproxy2', {
1823
+ 'abc': 'ok',
1824
+ }, {
1806
1825
  'mproxy': {
1807
1826
  'url': this._internalUrl + 'test/net-mproxy1',
1808
1827
  'auth': '123456',
1809
1828
  'data': { 'test': '123' },
1810
1829
  }
1811
1830
  });
1812
- echo.push(`<pre>lNet.get('https://cdn.jsdelivr.net/npm/deskrt@2.0.10/package.json', {
1831
+ echo.push(`<pre>lNet.get('${this._internalUrl}test/net-mproxy2', {
1813
1832
  'mproxy': {
1814
1833
  'url': '${this._internalUrl}test/net-mproxy1',
1815
1834
  'auth': '123456',
@@ -1830,6 +1849,11 @@ error: <pre>${JSON.stringify(res.error, null, 4)}</pre>`);
1830
1849
  }
1831
1850
  return 'Nothing(' + rtn + ')';
1832
1851
  }
1852
+ netMproxy2() {
1853
+ return [1, {
1854
+ 'data': this._post,
1855
+ }];
1856
+ }
1833
1857
  netFilterheaders() {
1834
1858
  const echo = [];
1835
1859
  const headers = {