@longzai-intelligence-pipeline/config 0.0.1

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 ADDED
@@ -0,0 +1,44 @@
1
+ # @longzai-intelligence-pipeline/config
2
+
3
+ 管道配置包:`lzi-pipeline.config.ts` 的一切——结构 schema、加载器、骨架生成。
4
+
5
+ ## 定位
6
+
7
+ longzai-intelligence-pipeline 三包之一(config / core / cli):本包持有配置结构真源;core 依赖本包(并 re-export);apps/cli 的 config 命令组消费本包。用户仓配置文件可从本包 import 工厂获得类型推导。
8
+
9
+ ## 用法
10
+
11
+ ```ts
12
+ // lzi-pipeline.config.ts(推荐:类型推导)
13
+ import { definePipelineConfig } from '@longzai-intelligence-pipeline/config';
14
+
15
+ export default definePipelineConfig({
16
+ version: 1,
17
+ library: { root: '../my-library-repo' }, // 必填:用户自建独立 git 仓路径(编排层零 git)
18
+ pipelines: [
19
+ {
20
+ id: 'demo',
21
+ sources: [{ id: 'mock-1', plugin: 'builtin:mock', config: { /* 插件 configSchema 二次校验 */ } }],
22
+ processors: [{ uses: 'builtin:markdown' }],
23
+ outputs: [{ collection: 'daily' }],
24
+ },
25
+ ],
26
+ });
27
+ ```
28
+
29
+ 零依赖形态:`config init` 生成的骨架为**零 import 裸对象**(任何目录可加载,运行时由 zod 校验兜底)。
30
+
31
+ ## API 面
32
+
33
+ | 导出 | 说明 |
34
+ | --- | --- |
35
+ | `PipelineConfigSchema` / 相关类型 | 配置结构(library.root 必填;**无 schedule 字段**——本阶段不考虑调度,reviews/005) |
36
+ | `definePipelineConfig()` | 配置工厂(identity + 类型收口) |
37
+ | `discoverConfigPath(explicit?)` | 配置发现:显式路径 → cwd 向上查找(最多 5 级) |
38
+ | `loadPipelineConfig(explicit?)` | 动态 import + PipelineConfigSchema 一级校验 |
39
+ | `scaffoldConfigText(root)` | 零 import 配置骨架文本(config init 用) |
40
+ | `CONFIG_FILENAME` | 约定文件名 `lzi-pipeline.config.ts` |
41
+
42
+ ## 裁定出处
43
+
44
+ TS 配置模块(专题 reviews/001);无 schedule 字段(reviews/005);独立 config 包(统帅部仓结构裁定,records/015)——真源:`longzai-intelligence-architecture/docs/reports/report-20260919-feed-pipeline-orchestration-refactor/`。
@@ -0,0 +1,127 @@
1
+ import { z } from "zod";
2
+ //#region src/schemas/pipeline-config.schema.d.ts
3
+ /** 原始层目标声明:shared(通用 raw_items 库)/ plugin-owned(插件自管库) */
4
+ declare const RawStoreTargetSchema: z.ZodObject<{
5
+ kind: z.ZodDefault<z.ZodEnum<{
6
+ "plugin-owned": "plugin-owned";
7
+ shared: "shared";
8
+ }>>;
9
+ path: z.ZodOptional<z.ZodString>;
10
+ }, z.core.$strip>;
11
+ /** 源实例配置(源 = 插件实例) */
12
+ declare const PipelineSourceConfigSchema: z.ZodObject<{
13
+ id: z.ZodString;
14
+ plugin: z.ZodString;
15
+ config: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
16
+ rawStore: z.ZodDefault<z.ZodObject<{
17
+ kind: z.ZodDefault<z.ZodEnum<{
18
+ "plugin-owned": "plugin-owned";
19
+ shared: "shared";
20
+ }>>;
21
+ path: z.ZodOptional<z.ZodString>;
22
+ }, z.core.$strip>>;
23
+ }, z.core.$strip>;
24
+ /** 处理链步骤配置(顺序执行) */
25
+ declare const PipelineProcessorConfigSchema: z.ZodObject<{
26
+ uses: z.ZodString;
27
+ config: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
28
+ }, z.core.$strip>;
29
+ /** 资料层输出声明 */
30
+ declare const PipelineOutputConfigSchema: z.ZodObject<{
31
+ collection: z.ZodString;
32
+ template: z.ZodDefault<z.ZodString>;
33
+ }, z.core.$strip>;
34
+ /** 单条管道定义 */
35
+ declare const PipelineDefinitionSchema: z.ZodObject<{
36
+ id: z.ZodString;
37
+ enabled: z.ZodDefault<z.ZodBoolean>;
38
+ sources: z.ZodArray<z.ZodObject<{
39
+ id: z.ZodString;
40
+ plugin: z.ZodString;
41
+ config: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
42
+ rawStore: z.ZodDefault<z.ZodObject<{
43
+ kind: z.ZodDefault<z.ZodEnum<{
44
+ "plugin-owned": "plugin-owned";
45
+ shared: "shared";
46
+ }>>;
47
+ path: z.ZodOptional<z.ZodString>;
48
+ }, z.core.$strip>>;
49
+ }, z.core.$strip>>;
50
+ processors: z.ZodDefault<z.ZodArray<z.ZodObject<{
51
+ uses: z.ZodString;
52
+ config: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
53
+ }, z.core.$strip>>>;
54
+ outputs: z.ZodDefault<z.ZodArray<z.ZodObject<{
55
+ collection: z.ZodString;
56
+ template: z.ZodDefault<z.ZodString>;
57
+ }, z.core.$strip>>>;
58
+ }, z.core.$strip>;
59
+ /** 管道总配置(lzi-pipeline.config.ts 默认导出形态) */
60
+ declare const PipelineConfigSchema: z.ZodObject<{
61
+ version: z.ZodLiteral<1>;
62
+ library: z.ZodObject<{
63
+ root: z.ZodString;
64
+ }, z.core.$strip>;
65
+ pipelines: z.ZodDefault<z.ZodArray<z.ZodObject<{
66
+ id: z.ZodString;
67
+ enabled: z.ZodDefault<z.ZodBoolean>;
68
+ sources: z.ZodArray<z.ZodObject<{
69
+ id: z.ZodString;
70
+ plugin: z.ZodString;
71
+ config: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
72
+ rawStore: z.ZodDefault<z.ZodObject<{
73
+ kind: z.ZodDefault<z.ZodEnum<{
74
+ "plugin-owned": "plugin-owned";
75
+ shared: "shared";
76
+ }>>;
77
+ path: z.ZodOptional<z.ZodString>;
78
+ }, z.core.$strip>>;
79
+ }, z.core.$strip>>;
80
+ processors: z.ZodDefault<z.ZodArray<z.ZodObject<{
81
+ uses: z.ZodString;
82
+ config: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
83
+ }, z.core.$strip>>>;
84
+ outputs: z.ZodDefault<z.ZodArray<z.ZodObject<{
85
+ collection: z.ZodString;
86
+ template: z.ZodDefault<z.ZodString>;
87
+ }, z.core.$strip>>>;
88
+ }, z.core.$strip>>>;
89
+ }, z.core.$strip>;
90
+ type RawStoreTarget = z.infer<typeof RawStoreTargetSchema>;
91
+ type PipelineSourceConfig = z.infer<typeof PipelineSourceConfigSchema>;
92
+ type PipelineProcessorConfig = z.infer<typeof PipelineProcessorConfigSchema>;
93
+ type PipelineOutputConfig = z.infer<typeof PipelineOutputConfigSchema>;
94
+ type PipelineDefinition = z.infer<typeof PipelineDefinitionSchema>;
95
+ type PipelineConfig = z.infer<typeof PipelineConfigSchema>;
96
+ /**
97
+ * 管道配置工厂:类型收口 + 便于 IDE 推导。
98
+ *
99
+ * 运行时校验由加载方(CLI loadConfig)执行;此处保持 identity 语义。
100
+ */
101
+ declare function definePipelineConfig(config: PipelineConfig): PipelineConfig;
102
+ //#endregion
103
+ //#region src/loader.d.ts
104
+ /** 配置文件约定名 */
105
+ declare const CONFIG_FILENAME = "lzi-pipeline.config.ts";
106
+ /** 配置加载错误 */
107
+ interface ConfigLoadError {
108
+ readonly code: 'CONFIG_NOT_FOUND' | 'CONFIG_INVALID';
109
+ readonly message: string;
110
+ }
111
+ /** 加载结果 */
112
+ type ConfigLoadResult = {
113
+ readonly ok: true;
114
+ readonly config: PipelineConfig;
115
+ readonly path: string;
116
+ } | {
117
+ readonly ok: false;
118
+ readonly error: ConfigLoadError;
119
+ };
120
+ /** 自 cwd 向上查找配置文件(最多 5 级) */
121
+ declare function discoverConfigPath(explicitPath?: string): string | undefined;
122
+ /** 加载并一级校验配置 */
123
+ declare function loadPipelineConfig(explicitPath?: string): Promise<ConfigLoadResult>;
124
+ /** 生成配置骨架文本(config init 用;零 import 依赖,任何目录可加载) */
125
+ declare function scaffoldConfigText(libraryRoot: string): string;
126
+ //#endregion
127
+ export { CONFIG_FILENAME, ConfigLoadError, ConfigLoadResult, PipelineConfig, PipelineConfigSchema, PipelineDefinition, PipelineDefinitionSchema, PipelineOutputConfig, PipelineOutputConfigSchema, PipelineProcessorConfig, PipelineProcessorConfigSchema, PipelineSourceConfig, PipelineSourceConfigSchema, RawStoreTarget, RawStoreTargetSchema, definePipelineConfig, discoverConfigPath, loadPipelineConfig, scaffoldConfigText };
package/dist/index.js ADDED
@@ -0,0 +1,23 @@
1
+ import{z as e}from"zod";import{existsSync as t}from"node:fs";import{join as n,resolve as r}from"node:path";const i=e.object({kind:e.enum([`shared`,`plugin-owned`]).default(`shared`),path:e.string().min(1).optional()}),a=e.object({id:e.string().min(1),plugin:e.string().min(1),config:e.record(e.string(),e.unknown()).default({}),rawStore:i.default({kind:`shared`})}),o=e.object({uses:e.string().min(1),config:e.record(e.string(),e.unknown()).default({})}),s=e.object({collection:e.string().min(1),template:e.string().min(1).default(`default`)}),c=e.object({id:e.string().min(1),enabled:e.boolean().default(!0),sources:e.array(a).min(1),processors:e.array(o).default([]),outputs:e.array(s).default([])}),l=e.object({version:e.literal(1),library:e.object({root:e.string().min(1)}),pipelines:e.array(c).default([])});function u(e){return e}const d=`lzi-pipeline.config.ts`;function f(e){if(e!==void 0)return t(e)?r(e):void 0;let i=process.cwd();for(let e=0;e<5;e+=1){let e=n(i,d);if(t(e))return e;let r=n(i,`..`);if(r===i)break;i=r}}async function p(e){let t=f(e);if(t===void 0)return{ok:!1,error:{code:`CONFIG_NOT_FOUND`,message:`未找到配置文件(${d}),可用 --config 显式指定`}};let n=await import(t),r=l.safeParse(n.default);return r.success?{ok:!0,config:r.data,path:t}:{ok:!1,error:{code:`CONFIG_INVALID`,message:`配置不合法:${r.error.message}`}}}function m(e){return`// lzi-pipeline 配置(运行时由 PipelineConfigSchema 校验;无需安装任何包即可加载)。
2
+ // 如需类型推导,可在已安装 @longzai-intelligence-pipeline/core 的项目中改为:
3
+ // import { definePipelineConfig } from '@longzai-intelligence-pipeline/config';
4
+ // export default definePipelineConfig({ ... });
5
+ export default {
6
+ version: 1,
7
+ library: { root: '${e}' },
8
+ pipelines: [
9
+ {
10
+ id: 'demo',
11
+ sources: [
12
+ {
13
+ id: 'mock-1',
14
+ plugin: 'builtin:mock',
15
+ config: { items: [{ slug: 'hello', title: 'Hello Pipeline', payload: { greeting: 'hello' } }] },
16
+ },
17
+ ],
18
+ processors: [{ uses: 'builtin:markdown' }],
19
+ outputs: [{ collection: 'daily' }],
20
+ },
21
+ ],
22
+ };
23
+ `}export{d as CONFIG_FILENAME,l as PipelineConfigSchema,c as PipelineDefinitionSchema,s as PipelineOutputConfigSchema,o as PipelineProcessorConfigSchema,a as PipelineSourceConfigSchema,i as RawStoreTargetSchema,u as definePipelineConfig,f as discoverConfigPath,p as loadPipelineConfig,m as scaffoldConfigText};
package/package.json ADDED
@@ -0,0 +1,39 @@
1
+ {
2
+ "name": "@longzai-intelligence-pipeline/config",
3
+ "version": "0.0.1",
4
+ "license": "UNLICENSED",
5
+ "files": [
6
+ "dist"
7
+ ],
8
+ "type": "module",
9
+ "main": "src/index.ts",
10
+ "types": "src/index.ts",
11
+ "exports": {
12
+ ".": {
13
+ "types": "./dist/index.d.ts",
14
+ "bun": "./src/index.ts",
15
+ "import": "./dist/index.js"
16
+ }
17
+ },
18
+ "scripts": {
19
+ "build": "lzi-builder",
20
+ "build:prod": "NODE_ENV=production bun run build",
21
+ "prepublishOnly": "bun run build:prod",
22
+ "typecheck": "bun run typecheck:app && bun run typecheck:node && bun run typecheck:test",
23
+ "typecheck:app": "lzi-tsgo typecheck tsconfig/app.json",
24
+ "typecheck:node": "lzi-tsgo typecheck tsconfig/node.json",
25
+ "typecheck:test": "lzi-tsgo typecheck tsconfig/test.json",
26
+ "lint": "oxlint && oxfmt --check",
27
+ "lint:fix": "oxlint --fix && oxfmt",
28
+ "test": "lzi-bun-cli test",
29
+ "test:watch": "lzi-bun-cli test --watch",
30
+ "test:coverage": "lzi-bun-cli test --coverage",
31
+ "clean": "lzi-dev-cli clean"
32
+ },
33
+ "dependencies": {
34
+ "zod": "^4.4.3"
35
+ },
36
+ "devDependencies": {
37
+ "@types/bun": "^1.3.14"
38
+ }
39
+ }