@visiblebase/core 0.2.0 → 0.2.3
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/README.md +12 -11
- package/bin/core/auth/authenticator.d.ts +17 -6
- package/bin/core/auth/authenticator.d.ts.map +1 -1
- package/bin/core/auth/authenticator.js +49 -30
- package/bin/core/auth/authenticator.js.map +1 -1
- package/bin/core/base/base.d.ts +11 -40
- package/bin/core/base/base.d.ts.map +1 -1
- package/bin/core/base/base.js +146 -102
- package/bin/core/base/base.js.map +1 -1
- package/bin/core/runtime.d.ts +10 -0
- package/bin/core/runtime.d.ts.map +1 -1
- package/bin/index.d.ts +5 -14
- package/bin/index.d.ts.map +1 -1
- package/bin/index.js +5 -14
- package/bin/index.js.map +1 -1
- package/bin/service/action.d.ts +44 -0
- package/bin/service/action.d.ts.map +1 -0
- package/bin/service/action.js +48 -0
- package/bin/service/action.js.map +1 -0
- package/bin/service/ai/ai-service.d.ts +36 -60
- package/bin/service/ai/ai-service.d.ts.map +1 -1
- package/bin/service/ai/ai-service.js +194 -120
- package/bin/service/ai/ai-service.js.map +1 -1
- package/bin/service/ai/provider.d.ts +24 -58
- package/bin/service/ai/provider.d.ts.map +1 -1
- package/bin/service/ai/provider.js +20 -41
- package/bin/service/ai/provider.js.map +1 -1
- package/bin/service/ai/types.d.ts +57 -35
- package/bin/service/ai/types.d.ts.map +1 -1
- package/bin/service/ai/types.js +1 -1
- package/bin/service/env/env-service.d.ts +0 -4
- package/bin/service/env/env-service.d.ts.map +1 -1
- package/bin/service/env/env-service.js +15 -25
- package/bin/service/env/env-service.js.map +1 -1
- package/bin/service/hook.d.ts +8 -5
- package/bin/service/hook.d.ts.map +1 -1
- package/bin/service/hook.js +11 -14
- package/bin/service/hook.js.map +1 -1
- package/bin/service/plugin.d.ts +20 -96
- package/bin/service/plugin.d.ts.map +1 -1
- package/bin/service/plugin.js +24 -61
- package/bin/service/plugin.js.map +1 -1
- package/bin/service/products/products-service.d.ts +0 -5
- package/bin/service/products/products-service.d.ts.map +1 -1
- package/bin/service/products/products-service.js +19 -25
- package/bin/service/products/products-service.js.map +1 -1
- package/bin/service/service.d.ts +76 -65
- package/bin/service/service.d.ts.map +1 -1
- package/bin/service/service.js +47 -80
- package/bin/service/service.js.map +1 -1
- package/bin/service/types.d.ts +2 -8
- package/bin/service/types.d.ts.map +1 -1
- package/bin/store/db.d.ts +5 -4
- package/bin/store/db.d.ts.map +1 -1
- package/bin/store/db.js +3 -2
- package/bin/store/db.js.map +1 -1
- package/package.json +8 -9
|
@@ -1,76 +1,42 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* AI Provider 模块。
|
|
3
3
|
*
|
|
4
|
-
* Provider 封装第三方 AI 提供商的
|
|
5
|
-
* 通过 model()
|
|
6
|
-
* 可直接传给 AIService.use() 完成注册。
|
|
4
|
+
* Provider 封装第三方 AI 提供商的 action 实现、环境变量声明和连接信息。
|
|
5
|
+
* 通过 model() 方法生成模型配置,可直接传给 AIService.use() 完成注册。
|
|
7
6
|
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
* stream: openaiStreamHandler,
|
|
14
|
-
* image: openaiImageHandler,
|
|
15
|
-
* });
|
|
16
|
-
*
|
|
17
|
-
* ai.use(
|
|
18
|
-
* openai.model({ id: "gpt-4o", name: "GPT-4o", default: true }),
|
|
19
|
-
* openai.model({ id: "gpt-4o-mini", name: "GPT-4o Mini" }),
|
|
20
|
-
* );
|
|
21
|
-
* ```
|
|
7
|
+
* 两条独立通路:
|
|
8
|
+
* - SDK 通路:text / stream — 给 UserClient 用
|
|
9
|
+
* - OpenAI 兼容通路:openai — 给 /chat/completions 端点用
|
|
10
|
+
* - 未提供 openai action → AIService 自动透传(需 baseURL + envKey)
|
|
11
|
+
* - 提供了 openai action → 按自定义逻辑处理
|
|
22
12
|
*/
|
|
23
|
-
import type {
|
|
13
|
+
import type { ActionFn } from "../action.js";
|
|
24
14
|
import type { ModelConfig } from "./types.js";
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
15
|
+
export interface ProviderOptions {
|
|
16
|
+
env?: Record<string, string>;
|
|
17
|
+
baseURL?: string;
|
|
18
|
+
envKey?: string;
|
|
19
|
+
passthroughModel?: string;
|
|
20
|
+
text: ActionFn;
|
|
21
|
+
stream: ActionFn;
|
|
22
|
+
image?: ActionFn;
|
|
23
|
+
video?: ActionFn;
|
|
24
|
+
openai?: ActionFn;
|
|
25
|
+
}
|
|
31
26
|
export declare class Provider {
|
|
32
|
-
/** Provider 唯一 ID */
|
|
33
27
|
readonly id: string;
|
|
34
|
-
/** Provider 所需环境变量(key → 描述) */
|
|
35
28
|
readonly env?: Record<string, string>;
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
/** 文本生成 handler */
|
|
42
|
-
text: ServiceHandler;
|
|
43
|
-
/** 流式生成 handler */
|
|
44
|
-
stream: ServiceHandler;
|
|
45
|
-
/** 图片生成 handler */
|
|
46
|
-
image?: ServiceHandler;
|
|
47
|
-
/** 视频生成 handler */
|
|
48
|
-
video?: ServiceHandler;
|
|
49
|
-
});
|
|
50
|
-
/**
|
|
51
|
-
* 创建一个使用此 Provider handler 的模型配置。
|
|
52
|
-
*
|
|
53
|
-
* 返回的 ModelConfig 可直接传给 AIService.use() 注册:
|
|
54
|
-
* ```ts
|
|
55
|
-
* const m = provider.model({ id: "gpt-4o", name: "GPT-4o", default: true });
|
|
56
|
-
* ai.use(m);
|
|
57
|
-
* ```
|
|
58
|
-
*
|
|
59
|
-
* @param spec - 模型规格
|
|
60
|
-
* @returns 完整的模型配置(含 handler 绑定)
|
|
61
|
-
*/
|
|
29
|
+
readonly baseURL?: string;
|
|
30
|
+
readonly envKey?: string;
|
|
31
|
+
readonly passthroughModel?: string;
|
|
32
|
+
private readonly actions;
|
|
33
|
+
constructor(id: string, opts: ProviderOptions);
|
|
62
34
|
model(spec: {
|
|
63
|
-
/** 模型唯一 ID */
|
|
64
35
|
id: string;
|
|
65
|
-
/** 模型展示名称 */
|
|
66
36
|
name: string;
|
|
67
|
-
/** 模型描述 */
|
|
68
37
|
description?: string;
|
|
69
|
-
/** 模型标签 */
|
|
70
38
|
tags?: string[];
|
|
71
|
-
/** 模型元数据(如价格、上下文窗口等) */
|
|
72
39
|
meta?: Record<string, unknown>;
|
|
73
|
-
/** 是否为默认模型。true 全局默认,或指定 modality 列表 */
|
|
74
40
|
default?: boolean | string[];
|
|
75
41
|
}): ModelConfig;
|
|
76
42
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../../../src/service/ai/provider.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../../../src/service/ai/provider.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,KAAK,EAAE,WAAW,EAAgB,MAAM,YAAY,CAAC;AAE5D,MAAM,WAAW,eAAe;IAC9B,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC7B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,IAAI,EAAE,QAAQ,CAAC;IACf,MAAM,EAAE,QAAQ,CAAC;IACjB,KAAK,CAAC,EAAE,QAAQ,CAAC;IACjB,KAAK,CAAC,EAAE,QAAQ,CAAC;IACjB,MAAM,CAAC,EAAE,QAAQ,CAAC;CACnB;AAED,qBAAa,QAAQ;IACnB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACtC,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,gBAAgB,CAAC,EAAE,MAAM,CAAC;IACnC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAe;gBAE3B,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,eAAe;IAe7C,KAAK,CAAC,IAAI,EAAE;QACV,EAAE,EAAE,MAAM,CAAC;QACX,IAAI,EAAE,MAAM,CAAC;QACb,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;QAChB,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QAC/B,OAAO,CAAC,EAAE,OAAO,GAAG,MAAM,EAAE,CAAC;KAC9B,GAAG,WAAW;CAehB"}
|
|
@@ -1,60 +1,36 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* AI Provider 模块。
|
|
3
3
|
*
|
|
4
|
-
* Provider 封装第三方 AI 提供商的
|
|
5
|
-
* 通过 model()
|
|
6
|
-
* 可直接传给 AIService.use() 完成注册。
|
|
4
|
+
* Provider 封装第三方 AI 提供商的 action 实现、环境变量声明和连接信息。
|
|
5
|
+
* 通过 model() 方法生成模型配置,可直接传给 AIService.use() 完成注册。
|
|
7
6
|
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
* stream: openaiStreamHandler,
|
|
14
|
-
* image: openaiImageHandler,
|
|
15
|
-
* });
|
|
16
|
-
*
|
|
17
|
-
* ai.use(
|
|
18
|
-
* openai.model({ id: "gpt-4o", name: "GPT-4o", default: true }),
|
|
19
|
-
* openai.model({ id: "gpt-4o-mini", name: "GPT-4o Mini" }),
|
|
20
|
-
* );
|
|
21
|
-
* ```
|
|
22
|
-
*/
|
|
23
|
-
/**
|
|
24
|
-
* AI Provider。
|
|
25
|
-
*
|
|
26
|
-
* 封装第三方 AI 提供商的 handler 实现和环境变量声明。
|
|
27
|
-
* 通过 model() 方法生成模型配置,可传给 AIService.use() 批量注册。
|
|
7
|
+
* 两条独立通路:
|
|
8
|
+
* - SDK 通路:text / stream — 给 UserClient 用
|
|
9
|
+
* - OpenAI 兼容通路:openai — 给 /chat/completions 端点用
|
|
10
|
+
* - 未提供 openai action → AIService 自动透传(需 baseURL + envKey)
|
|
11
|
+
* - 提供了 openai action → 按自定义逻辑处理
|
|
28
12
|
*/
|
|
29
13
|
export class Provider {
|
|
30
|
-
/** Provider 唯一 ID */
|
|
31
14
|
id;
|
|
32
|
-
/** Provider 所需环境变量(key → 描述) */
|
|
33
15
|
env;
|
|
34
|
-
|
|
35
|
-
|
|
16
|
+
baseURL;
|
|
17
|
+
envKey;
|
|
18
|
+
passthroughModel;
|
|
19
|
+
actions;
|
|
36
20
|
constructor(id, opts) {
|
|
37
21
|
this.id = id;
|
|
38
22
|
this.env = opts.env;
|
|
39
|
-
this.
|
|
23
|
+
this.baseURL = opts.baseURL;
|
|
24
|
+
this.envKey = opts.envKey;
|
|
25
|
+
this.passthroughModel = opts.passthroughModel;
|
|
26
|
+
this.actions = {
|
|
40
27
|
text: opts.text,
|
|
41
28
|
stream: opts.stream,
|
|
42
29
|
image: opts.image,
|
|
43
30
|
video: opts.video,
|
|
31
|
+
openai: opts.openai,
|
|
44
32
|
};
|
|
45
33
|
}
|
|
46
|
-
/**
|
|
47
|
-
* 创建一个使用此 Provider handler 的模型配置。
|
|
48
|
-
*
|
|
49
|
-
* 返回的 ModelConfig 可直接传给 AIService.use() 注册:
|
|
50
|
-
* ```ts
|
|
51
|
-
* const m = provider.model({ id: "gpt-4o", name: "GPT-4o", default: true });
|
|
52
|
-
* ai.use(m);
|
|
53
|
-
* ```
|
|
54
|
-
*
|
|
55
|
-
* @param spec - 模型规格
|
|
56
|
-
* @returns 完整的模型配置(含 handler 绑定)
|
|
57
|
-
*/
|
|
58
34
|
model(spec) {
|
|
59
35
|
return {
|
|
60
36
|
id: spec.id,
|
|
@@ -64,7 +40,10 @@ export class Provider {
|
|
|
64
40
|
meta: spec.meta,
|
|
65
41
|
default: spec.default,
|
|
66
42
|
env: this.env,
|
|
67
|
-
|
|
43
|
+
baseURL: this.baseURL,
|
|
44
|
+
envKey: this.envKey,
|
|
45
|
+
passthroughModel: this.passthroughModel,
|
|
46
|
+
actions: this.actions,
|
|
68
47
|
};
|
|
69
48
|
}
|
|
70
49
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provider.js","sourceRoot":"","sources":["../../../src/service/ai/provider.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"provider.js","sourceRoot":"","sources":["../../../src/service/ai/provider.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAiBH,MAAM,OAAO,QAAQ;IACV,EAAE,CAAS;IACX,GAAG,CAA0B;IAC7B,OAAO,CAAU;IACjB,MAAM,CAAU;IAChB,gBAAgB,CAAU;IAClB,OAAO,CAAe;IAEvC,YAAY,EAAU,EAAE,IAAqB;QAC3C,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC;QACb,IAAI,CAAC,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC;QACpB,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC;QAC5B,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;QAC1B,IAAI,CAAC,gBAAgB,GAAG,IAAI,CAAC,gBAAgB,CAAC;QAC9C,IAAI,CAAC,OAAO,GAAG;YACb,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,MAAM,EAAE,IAAI,CAAC,MAAM;YACnB,KAAK,EAAE,IAAI,CAAC,KAAK;YACjB,KAAK,EAAE,IAAI,CAAC,KAAK;YACjB,MAAM,EAAE,IAAI,CAAC,MAAM;SACpB,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,IAOL;QACC,OAAO;YACL,EAAE,EAAE,IAAI,CAAC,EAAE;YACX,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,WAAW,EAAE,IAAI,CAAC,WAAW;YAC7B,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,GAAG,EAAE,IAAI,CAAC,GAAG;YACb,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,MAAM,EAAE,IAAI,CAAC,MAAM;YACnB,gBAAgB,EAAE,IAAI,CAAC,gBAAgB;YACvC,OAAO,EAAE,IAAI,CAAC,OAAO;SACtB,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -1,58 +1,64 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* AI Service 类型模块。
|
|
3
3
|
*
|
|
4
|
-
* 包含模型配置、
|
|
4
|
+
* 包含模型配置、action 映射、运行时模型和执行上下文类型。
|
|
5
5
|
*/
|
|
6
|
-
import type {
|
|
6
|
+
import type { ActionFn } from "../action.js";
|
|
7
7
|
/**
|
|
8
|
-
* 模型
|
|
8
|
+
* 模型 action 映射,key 为通路名称。
|
|
9
9
|
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
10
|
+
* 两条独立通路:
|
|
11
|
+
* - SDK 通路:text / stream / image / video / tts / asr — 给 UserClient 用
|
|
12
|
+
* - OpenAI 兼容通路:openai — 给 /chat/completions 端点用
|
|
13
|
+
*
|
|
14
|
+
* 每个 action 接收 Context,返回对应通路的结果。
|
|
15
|
+
* Provider 在构造时提供这些 action,通过 model() 方法绑定到模型配置。
|
|
12
16
|
*/
|
|
13
|
-
export interface
|
|
14
|
-
/** 文本生成
|
|
15
|
-
text?:
|
|
16
|
-
/** 流式生成
|
|
17
|
-
stream?:
|
|
18
|
-
/** 图片生成
|
|
19
|
-
image?:
|
|
20
|
-
/** 视频生成
|
|
21
|
-
video?:
|
|
22
|
-
/** 语音合成
|
|
23
|
-
tts?:
|
|
24
|
-
/** 语音识别
|
|
25
|
-
asr?:
|
|
26
|
-
/**
|
|
27
|
-
|
|
17
|
+
export interface ModelActions {
|
|
18
|
+
/** 文本生成 action */
|
|
19
|
+
text?: ActionFn;
|
|
20
|
+
/** 流式生成 action */
|
|
21
|
+
stream?: ActionFn;
|
|
22
|
+
/** 图片生成 action */
|
|
23
|
+
image?: ActionFn;
|
|
24
|
+
/** 视频生成 action */
|
|
25
|
+
video?: ActionFn;
|
|
26
|
+
/** 语音合成 action */
|
|
27
|
+
tts?: ActionFn;
|
|
28
|
+
/** 语音识别 action */
|
|
29
|
+
asr?: ActionFn;
|
|
30
|
+
/** OpenAI 兼容 /chat/completions action。未提供时 AIService 自动透传 */
|
|
31
|
+
openai?: ActionFn;
|
|
32
|
+
/** 扩展 modality action */
|
|
33
|
+
[modality: string]: ActionFn | undefined;
|
|
28
34
|
}
|
|
29
35
|
/**
|
|
30
36
|
* 模型配置(Provider.model() 的返回值)。
|
|
31
|
-
*
|
|
32
|
-
* 包含模型的完整元信息和各 modality 的 handler 绑定,
|
|
33
|
-
* 可直接传给 AIService.use() 完成注册。
|
|
34
37
|
*/
|
|
35
38
|
export interface ModelConfig {
|
|
36
|
-
/** 模型唯一 ID
|
|
39
|
+
/** 模型唯一 ID */
|
|
37
40
|
id: string;
|
|
38
41
|
/** 模型展示名称 */
|
|
39
42
|
name: string;
|
|
40
43
|
/** 模型描述 */
|
|
41
44
|
description?: string;
|
|
42
|
-
/**
|
|
45
|
+
/** 模型标签 */
|
|
43
46
|
tags?: string[];
|
|
44
|
-
/**
|
|
47
|
+
/** 模型元数据 */
|
|
45
48
|
meta?: Record<string, unknown>;
|
|
46
|
-
/**
|
|
49
|
+
/** 是否为默认模型 */
|
|
47
50
|
default?: boolean | string[];
|
|
48
|
-
/**
|
|
51
|
+
/** 模型所需环境变量 */
|
|
49
52
|
env?: Record<string, string>;
|
|
50
|
-
/**
|
|
51
|
-
|
|
53
|
+
/** Provider 的 baseURL(用于自动透传) */
|
|
54
|
+
baseURL?: string;
|
|
55
|
+
/** Provider 的环境变量 key */
|
|
56
|
+
envKey?: string;
|
|
57
|
+
/** 上游 API 实际模型 ID(自动透传时替换 body.model) */
|
|
58
|
+
passthroughModel?: string;
|
|
59
|
+
/** 各通路 action 绑定 */
|
|
60
|
+
actions: ModelActions;
|
|
52
61
|
}
|
|
53
|
-
/**
|
|
54
|
-
* 公开模型列表项(API 返回给客户端)。
|
|
55
|
-
*/
|
|
56
62
|
export interface PublicModel {
|
|
57
63
|
/** 模型 ID */
|
|
58
64
|
id: string;
|
|
@@ -66,7 +72,23 @@ export interface PublicModel {
|
|
|
66
72
|
tags: string[];
|
|
67
73
|
/** 模型元数据 */
|
|
68
74
|
meta: Record<string, unknown>;
|
|
69
|
-
/**
|
|
70
|
-
|
|
75
|
+
/** 模型依赖的环境变量需求(通常仅在 admin 身份下返回) */
|
|
76
|
+
env_requirements?: AIModelEnvRequirement[];
|
|
77
|
+
/** 模型默认负责的 modality 列表(通常仅在 admin 身份下返回) */
|
|
78
|
+
default_modes?: string[];
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* AI 模型环境变量需求。
|
|
82
|
+
*
|
|
83
|
+
* 用于 admin 视角展示某个模型依赖哪些运行时 key,
|
|
84
|
+
* 以及这些 key 当前是否已经配置完成。
|
|
85
|
+
*/
|
|
86
|
+
export interface AIModelEnvRequirement {
|
|
87
|
+
/** 环境变量 key,例如 `DEEPSEEK_API_KEY` */
|
|
88
|
+
key: string;
|
|
89
|
+
/** 给管理员展示的说明文本 */
|
|
90
|
+
description: string;
|
|
91
|
+
/** 当前是否必须提供该 key 才能调用模型 */
|
|
92
|
+
required: boolean;
|
|
71
93
|
}
|
|
72
94
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/service/ai/types.ts"],"names":[],"mappings":"AAAA;;;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zC,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,oBAAoB;IACpB,OAAO,EAAE,YAAY,CAAC;CACvB;AAMD,MAAM,WAAW,WAAW;IAC1B,YAAY;IACZ,EAAE,EAAE,MAAM,CAAC;IACX,aAAa;IACb,IAAI,EAAE,MAAM,CAAC;IACb,WAAW;IACX,WAAW,EAAE,MAAM,CAAC;IACpB,wBAAwB;IACxB,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,WAAW;IACX,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,YAAY;IACZ,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC9B,oCAAoC;IACpC,gBAAgB,CAAC,EAAE,qBAAqB,EAAE,CAAC;IAC3C,4CAA4C;IAC5C,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC;CAC1B;AAED;;;;;GAKG;AACH,MAAM,WAAW,qBAAqB;IACpC,qCAAqC;IACrC,GAAG,EAAE,MAAM,CAAC;IACZ,kBAAkB;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,2BAA2B;IAC3B,QAAQ,EAAE,OAAO,CAAC;CACnB"}
|
package/bin/service/ai/types.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"env-service.d.ts","sourceRoot":"","sources":["../../../src/service/env/env-service.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"env-service.d.ts","sourceRoot":"","sources":["../../../src/service/env/env-service.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAEzD,qBAAa,UAAW,SAAQ,OAAO;IACrC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAc;gBAE9B,WAAW,EAAE,WAAW;CA4BrC"}
|
|
@@ -1,42 +1,32 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* env 内置服务。
|
|
3
|
-
*
|
|
4
|
-
* 提供 admin API 路由用于管理运行时环境变量。
|
|
5
|
-
* EnvStore 的创建和 attach 逻辑已由 Base 内部处理,
|
|
6
|
-
* 本 Service 只负责路由。
|
|
7
3
|
*/
|
|
8
4
|
import { Service } from "../service.js";
|
|
9
|
-
const INTERNAL_KEYS = new Set([
|
|
10
|
-
"VISIBLEBASE_ADMIN_SECRET_KEY",
|
|
11
|
-
"VISIBLEBASE_TOKEN_SIGNING_KEY",
|
|
12
|
-
]);
|
|
13
5
|
export class EnvService extends Service {
|
|
14
6
|
envProvider;
|
|
15
7
|
constructor(envProvider) {
|
|
16
8
|
super({ id: "env", name: "Env" });
|
|
17
9
|
this.envProvider = envProvider;
|
|
18
|
-
this.
|
|
19
|
-
const list = this.envProvider.list();
|
|
10
|
+
this.action("list", async (ctx) => {
|
|
11
|
+
const list = await this.envProvider.list();
|
|
20
12
|
const items = Array.isArray(list) ? list : [];
|
|
21
|
-
return {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}, { auth: "admin" });
|
|
25
|
-
this.post("/upsert", async ({ input }) => {
|
|
13
|
+
return { items };
|
|
14
|
+
}, { method: "GET", auth: ["admin"] });
|
|
15
|
+
this.action("upsert", async (ctx) => {
|
|
26
16
|
const entry = await this.envProvider.upsert({
|
|
27
|
-
key: String(input.key ?? ""),
|
|
28
|
-
value: String(input.value ?? ""),
|
|
17
|
+
key: String(ctx.input.key ?? ""),
|
|
18
|
+
value: String(ctx.input.value ?? ""),
|
|
29
19
|
});
|
|
30
20
|
return { success: true, key: entry.key };
|
|
31
|
-
}, { auth: "admin" });
|
|
32
|
-
this.
|
|
33
|
-
await this.envProvider.remove(String(input.key ?? ""));
|
|
34
|
-
return { success: true, key: String(input.key ?? "") };
|
|
35
|
-
}, { auth: "admin" });
|
|
36
|
-
this.
|
|
37
|
-
const entries = await this.envProvider.import(input.raw);
|
|
21
|
+
}, { auth: ["admin"] });
|
|
22
|
+
this.action("remove", async (ctx) => {
|
|
23
|
+
await this.envProvider.remove(String(ctx.input.key ?? ""));
|
|
24
|
+
return { success: true, key: String(ctx.input.key ?? "") };
|
|
25
|
+
}, { auth: ["admin"] });
|
|
26
|
+
this.action("import", async (ctx) => {
|
|
27
|
+
const entries = await this.envProvider.import(ctx.input.raw);
|
|
38
28
|
return { success: true, count: entries.length, keys: entries.map((e) => e.key) };
|
|
39
|
-
}, { auth: "admin" });
|
|
29
|
+
}, { auth: ["admin"] });
|
|
40
30
|
}
|
|
41
31
|
}
|
|
42
32
|
//# sourceMappingURL=env-service.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"env-service.js","sourceRoot":"","sources":["../../../src/service/env/env-service.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"env-service.js","sourceRoot":"","sources":["../../../src/service/env/env-service.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAGxC,MAAM,OAAO,UAAW,SAAQ,OAAO;IACpB,WAAW,CAAc;IAE1C,YAAY,WAAwB;QAClC,KAAK,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;QAClC,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;QAE/B,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,KAAK,EAAE,GAAG,EAAE,EAAE;YAChC,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,WAAW,CAAC,IAAI,EAAE,CAAC;YAC3C,MAAM,KAAK,GAAG,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC;YAC9C,OAAO,EAAE,KAAK,EAAE,CAAC;QACnB,CAAC,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;QAEvC,IAAI,CAAC,MAAM,CAAC,Q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AAE,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;IAC1B,CAAC;CACF"}
|
package/bin/service/hook.d.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Hook 模块。
|
|
3
3
|
*
|
|
4
|
-
* Hook
|
|
5
|
-
* 所有 hook 函数接收 Context
|
|
4
|
+
* Hook 是执行生命周期中可注册的回调链,支持 before / after / onError 三个阶段。
|
|
5
|
+
* 所有 hook 函数接收 Context,不返回值(直接在 ctx 上修改)。
|
|
6
6
|
*/
|
|
7
|
-
import type { HookFn } from "./types.js";
|
|
8
7
|
import type { Context } from "./service.js";
|
|
8
|
+
/** Hook 回调函数 */
|
|
9
|
+
export type HookFn = (ctx: Context) => void | Promise<void>;
|
|
9
10
|
export declare class Hook {
|
|
10
11
|
private befores;
|
|
11
12
|
private afters;
|
|
@@ -13,8 +14,10 @@ export declare class Hook {
|
|
|
13
14
|
before(fn: HookFn): this;
|
|
14
15
|
after(fn: HookFn): this;
|
|
15
16
|
onError(fn: HookFn): this;
|
|
16
|
-
runBefore(ctx: Context): Promise<
|
|
17
|
-
runAfter(ctx: Context): Promise<
|
|
17
|
+
runBefore(ctx: Context): Promise<void>;
|
|
18
|
+
runAfter(ctx: Context): Promise<void>;
|
|
18
19
|
runOnError(ctx: Context): Promise<void>;
|
|
20
|
+
/** 清空所有 hook */
|
|
21
|
+
clear(): this;
|
|
19
22
|
}
|
|
20
23
|
//# sourceMappingURL=hook.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hook.d.ts","sourceRoot":"","sources":["../../src/service/hook.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;
|
|
1
|
+
{"version":3,"file":"hook.d.ts","sourceRoot":"","sources":["../../src/service/hook.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAE5C,gBAAgB;AAChB,MAAM,MAAM,MAAM,GAAG,CAAC,GAAG,EAAE,OAAO,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;AAE5D,qBAAa,IAAI;IACf,OAAO,CAAC,OAAO,CAAgB;IAC/B,OAAO,CAAC,MAAM,CAAgB;IAC9B,OAAO,CAAC,MAAM,CAAgB;IAE9B,MAAM,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI;IAKxB,KAAK,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI;IAKvB,OAAO,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI;IAKnB,SAAS,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;IAMtC,QAAQ,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;IAMrC,UAAU,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;IAM7C,gBAAgB;IAChB,KAAK,IAAI,IAAI;CAMd"}
|
package/bin/service/hook.js
CHANGED
|
@@ -1,44 +1,34 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Hook 模块。
|
|
3
3
|
*
|
|
4
|
-
* Hook
|
|
5
|
-
* 所有 hook 函数接收 Context
|
|
4
|
+
* Hook 是执行生命周期中可注册的回调链,支持 before / after / onError 三个阶段。
|
|
5
|
+
* 所有 hook 函数接收 Context,不返回值(直接在 ctx 上修改)。
|
|
6
6
|
*/
|
|
7
|
-
import { assertFunction } from "../utils/validation.js";
|
|
8
7
|
export class Hook {
|
|
9
8
|
befores = [];
|
|
10
9
|
afters = [];
|
|
11
10
|
errors = [];
|
|
12
11
|
before(fn) {
|
|
13
|
-
assertFunction(fn, "before");
|
|
14
12
|
this.befores.push(fn);
|
|
15
13
|
return this;
|
|
16
14
|
}
|
|
17
15
|
after(fn) {
|
|
18
|
-
assertFunction(fn, "after");
|
|
19
16
|
this.afters.push(fn);
|
|
20
17
|
return this;
|
|
21
18
|
}
|
|
22
19
|
onError(fn) {
|
|
23
|
-
assertFunction(fn, "onError");
|
|
24
20
|
this.errors.push(fn);
|
|
25
21
|
return this;
|
|
26
22
|
}
|
|
27
23
|
async runBefore(ctx) {
|
|
28
24
|
for (const fn of this.befores) {
|
|
29
|
-
|
|
30
|
-
if (next !== undefined)
|
|
31
|
-
ctx = next;
|
|
25
|
+
await fn(ctx);
|
|
32
26
|
}
|
|
33
|
-
return ctx;
|
|
34
27
|
}
|
|
35
28
|
async runAfter(ctx) {
|
|
36
29
|
for (const fn of this.afters) {
|
|
37
|
-
|
|
38
|
-
if (next !== undefined)
|
|
39
|
-
ctx = next;
|
|
30
|
+
await fn(ctx);
|
|
40
31
|
}
|
|
41
|
-
return ctx;
|
|
42
32
|
}
|
|
43
33
|
async runOnError(ctx) {
|
|
44
34
|
for (const fn of this.errors) {
|
|
@@ -48,5 +38,12 @@ export class Hook {
|
|
|
48
38
|
catch { /* 不覆盖原始错误 */ }
|
|
49
39
|
}
|
|
50
40
|
}
|
|
41
|
+
/** 清空所有 hook */
|
|
42
|
+
clear() {
|
|
43
|
+
this.befores = [];
|
|
44
|
+
this.afters = [];
|
|
45
|
+
this.errors = [];
|
|
46
|
+
return this;
|
|
47
|
+
}
|
|
51
48
|
}
|
|
52
49
|
//# sourceMappingURL=hook.js.map
|
package/bin/service/hook.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hook.js","sourceRoot":"","sources":["../../src/service/hook.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;
|
|
1
|
+
{"version":3,"file":"hook.js","sourceRoot":"","sources":["../../src/service/hook.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAOH,MAAM,OAAO,IAAI;IACP,OAAO,GAAa,EAAE,CAAC;IACvB,MAAM,GAAa,EAAE,CAAC;IACtB,MAAM,GAAa,EAAE,CAAC;IAE9B,MAAM,CAAC,EAAU;QACf,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QACtB,OAAO,IAAI,CAAC;IACd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