@reglow/reglow 0.10.0 → 0.12.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.
Files changed (162) hide show
  1. package/dist/reglow/common/errors.js +1 -1
  2. package/dist/reglow/common/errors.js.map +1 -1
  3. package/dist/reglow/core/config.js +1 -1
  4. package/dist/reglow/core/entities.d.ts +113 -1
  5. package/dist/reglow/core/models.d.ts +16 -0
  6. package/dist/reglow/core/models.js +9 -0
  7. package/dist/reglow/core/models.js.map +1 -1
  8. package/dist/reglow/modules/ai/controller.d.ts +15 -0
  9. package/dist/reglow/modules/ai/controller.js +21 -16
  10. package/dist/reglow/modules/ai/controller.js.map +1 -1
  11. package/dist/reglow/modules/ai/service.d.ts +4 -0
  12. package/dist/reglow/modules/ai/service.js +31 -1
  13. package/dist/reglow/modules/ai/service.js.map +1 -1
  14. package/dist/reglow/modules/analytics/collect.d.ts +13 -0
  15. package/dist/reglow/modules/analytics/collect.js +237 -0
  16. package/dist/reglow/modules/analytics/collect.js.map +1 -0
  17. package/dist/reglow/modules/analytics/controller.d.ts +6 -0
  18. package/dist/reglow/modules/analytics/controller.js +338 -0
  19. package/dist/reglow/modules/analytics/controller.js.map +1 -0
  20. package/dist/reglow/modules/analytics/controller_client.d.ts +6 -0
  21. package/dist/reglow/modules/analytics/controller_client.js +34 -0
  22. package/dist/reglow/modules/analytics/controller_client.js.map +1 -0
  23. package/dist/reglow/modules/analytics/gov.d.ts +30 -0
  24. package/dist/reglow/modules/analytics/gov.js +140 -0
  25. package/dist/reglow/modules/analytics/gov.js.map +1 -0
  26. package/dist/reglow/modules/analytics/model.d.ts +190 -0
  27. package/dist/reglow/modules/analytics/model.js +14 -0
  28. package/dist/reglow/modules/analytics/model.js.map +1 -0
  29. package/dist/reglow/modules/analytics/repository.d.ts +66 -0
  30. package/dist/reglow/modules/analytics/repository.js +451 -0
  31. package/dist/reglow/modules/analytics/repository.js.map +1 -0
  32. package/dist/reglow/modules/analytics/rollup.d.ts +17 -0
  33. package/dist/reglow/modules/analytics/rollup.js +299 -0
  34. package/dist/reglow/modules/analytics/rollup.js.map +1 -0
  35. package/dist/reglow/modules/analytics/router.d.ts +16 -0
  36. package/dist/reglow/modules/analytics/router.js +11 -0
  37. package/dist/reglow/modules/analytics/router.js.map +1 -0
  38. package/dist/reglow/modules/analytics/schema.d.ts +275 -0
  39. package/dist/reglow/modules/analytics/schema.js +7 -0
  40. package/dist/reglow/modules/analytics/schema.js.map +1 -0
  41. package/dist/reglow/modules/analytics/service.d.ts +51 -0
  42. package/dist/reglow/modules/analytics/service.js +653 -0
  43. package/dist/reglow/modules/analytics/service.js.map +1 -0
  44. package/dist/reglow/modules/analytics/snapshot.d.ts +10 -0
  45. package/dist/reglow/modules/analytics/snapshot.js +63 -0
  46. package/dist/reglow/modules/analytics/snapshot.js.map +1 -0
  47. package/dist/reglow/modules/article/controller.js +1 -0
  48. package/dist/reglow/modules/article/controller.js.map +1 -1
  49. package/dist/reglow/modules/article/schema.d.ts +2 -0
  50. package/dist/reglow/modules/article/schema.js +2 -0
  51. package/dist/reglow/modules/article/schema.js.map +1 -1
  52. package/dist/reglow/modules/article/service.d.ts +5 -0
  53. package/dist/reglow/modules/article/service.js +26 -1
  54. package/dist/reglow/modules/article/service.js.map +1 -1
  55. package/dist/reglow/modules/config/controller.js +3 -1
  56. package/dist/reglow/modules/config/controller.js.map +1 -1
  57. package/dist/reglow/modules/customer_service/repository.js +4 -2
  58. package/dist/reglow/modules/customer_service/repository.js.map +1 -1
  59. package/dist/reglow/modules/customer_service/sdk_template.html +4 -3
  60. package/dist/reglow/modules/dashboard/controller.js +7 -1
  61. package/dist/reglow/modules/dashboard/controller.js.map +1 -1
  62. package/dist/reglow/modules/dashboard/service.d.ts +1 -0
  63. package/dist/reglow/modules/dashboard/service.js +152 -0
  64. package/dist/reglow/modules/dashboard/service.js.map +1 -1
  65. package/dist/reglow/modules/material/controller.js +16 -0
  66. package/dist/reglow/modules/material/controller.js.map +1 -1
  67. package/dist/reglow/modules/material/repository.js +2 -2
  68. package/dist/reglow/modules/material/repository.js.map +1 -1
  69. package/dist/reglow/modules/material/service.d.ts +2 -0
  70. package/dist/reglow/modules/material/service.js +46 -4
  71. package/dist/reglow/modules/material/service.js.map +1 -1
  72. package/dist/reglow/modules/payment/service.js +7 -1
  73. package/dist/reglow/modules/payment/service.js.map +1 -1
  74. package/dist/reglow/modules/photo/controller.js +81 -55
  75. package/dist/reglow/modules/photo/controller.js.map +1 -1
  76. package/dist/reglow/modules/photo/repository.js +1 -1
  77. package/dist/reglow/modules/photo/repository.js.map +1 -1
  78. package/dist/reglow/modules/photo/service.d.ts +11 -1
  79. package/dist/reglow/modules/photo/service.js +65 -3
  80. package/dist/reglow/modules/photo/service.js.map +1 -1
  81. package/dist/reglow/modules/skill/controller.d.ts +8 -0
  82. package/dist/reglow/modules/skill/controller.js +93 -0
  83. package/dist/reglow/modules/skill/controller.js.map +1 -0
  84. package/dist/reglow/modules/skill/model.d.ts +19 -0
  85. package/dist/reglow/modules/skill/model.js +49 -0
  86. package/dist/reglow/modules/skill/model.js.map +1 -0
  87. package/dist/reglow/modules/skill/repository.d.ts +8 -0
  88. package/dist/reglow/modules/skill/repository.js +101 -0
  89. package/dist/reglow/modules/skill/repository.js.map +1 -0
  90. package/dist/reglow/modules/skill/router.d.ts +10 -0
  91. package/dist/reglow/modules/skill/router.js +8 -0
  92. package/dist/reglow/modules/skill/router.js.map +1 -0
  93. package/dist/reglow/modules/skill/schema.d.ts +39 -0
  94. package/dist/reglow/modules/skill/schema.js +38 -0
  95. package/dist/reglow/modules/skill/schema.js.map +1 -0
  96. package/dist/reglow/modules/skill/service.d.ts +62 -0
  97. package/dist/reglow/modules/skill/service.js +285 -0
  98. package/dist/reglow/modules/skill/service.js.map +1 -0
  99. package/dist/reglow/modules/studio/controller.d.ts +9 -0
  100. package/dist/reglow/modules/studio/controller.js +303 -0
  101. package/dist/reglow/modules/studio/controller.js.map +1 -0
  102. package/dist/reglow/modules/studio/deps.d.ts +47 -0
  103. package/dist/reglow/modules/studio/deps.js +175 -0
  104. package/dist/reglow/modules/studio/deps.js.map +1 -0
  105. package/dist/reglow/modules/studio/engine.d.ts +85 -0
  106. package/dist/reglow/modules/studio/engine.js +881 -0
  107. package/dist/reglow/modules/studio/engine.js.map +1 -0
  108. package/dist/reglow/modules/studio/llm.d.ts +30 -0
  109. package/dist/reglow/modules/studio/llm.js +151 -0
  110. package/dist/reglow/modules/studio/llm.js.map +1 -0
  111. package/dist/reglow/modules/studio/mcp/client.d.ts +22 -0
  112. package/dist/reglow/modules/studio/mcp/client.js +99 -0
  113. package/dist/reglow/modules/studio/mcp/client.js.map +1 -0
  114. package/dist/reglow/modules/studio/mcp/transport.d.ts +59 -0
  115. package/dist/reglow/modules/studio/mcp/transport.js +259 -0
  116. package/dist/reglow/modules/studio/mcp/transport.js.map +1 -0
  117. package/dist/reglow/modules/studio/media.d.ts +52 -0
  118. package/dist/reglow/modules/studio/media.js +484 -0
  119. package/dist/reglow/modules/studio/media.js.map +1 -0
  120. package/dist/reglow/modules/studio/model.d.ts +23 -0
  121. package/dist/reglow/modules/studio/model.js +35 -0
  122. package/dist/reglow/modules/studio/model.js.map +1 -0
  123. package/dist/reglow/modules/studio/repository.d.ts +31 -0
  124. package/dist/reglow/modules/studio/repository.js +300 -0
  125. package/dist/reglow/modules/studio/repository.js.map +1 -0
  126. package/dist/reglow/modules/studio/router.d.ts +10 -0
  127. package/dist/reglow/modules/studio/router.js +8 -0
  128. package/dist/reglow/modules/studio/router.js.map +1 -0
  129. package/dist/reglow/modules/studio/schema.d.ts +194 -0
  130. package/dist/reglow/modules/studio/schema.js +739 -0
  131. package/dist/reglow/modules/studio/schema.js.map +1 -0
  132. package/dist/reglow/modules/studio/service.d.ts +168 -0
  133. package/dist/reglow/modules/studio/service.js +673 -0
  134. package/dist/reglow/modules/studio/service.js.map +1 -0
  135. package/dist/reglow/modules/studio/tools/builtins.d.ts +9 -0
  136. package/dist/reglow/modules/studio/tools/builtins.js +162 -0
  137. package/dist/reglow/modules/studio/tools/builtins.js.map +1 -0
  138. package/dist/reglow/modules/studio/tools/media_tools.d.ts +31 -0
  139. package/dist/reglow/modules/studio/tools/media_tools.js +412 -0
  140. package/dist/reglow/modules/studio/tools/media_tools.js.map +1 -0
  141. package/dist/reglow/modules/studio/tools/registry.d.ts +46 -0
  142. package/dist/reglow/modules/studio/tools/registry.js +160 -0
  143. package/dist/reglow/modules/studio/tools/registry.js.map +1 -0
  144. package/dist/reglow/modules/studio/tools/runner.d.ts +18 -0
  145. package/dist/reglow/modules/studio/tools/runner.js +89 -0
  146. package/dist/reglow/modules/studio/tools/runner.js.map +1 -0
  147. package/dist/reglow/modules/user/controller_client.js +1 -1
  148. package/dist/reglow/modules/user/controller_client.js.map +1 -1
  149. package/dist/reglow/modules/video/controller.js +1 -0
  150. package/dist/reglow/modules/video/controller.js.map +1 -1
  151. package/dist/reglow/modules/video/schema.d.ts +2 -0
  152. package/dist/reglow/modules/video/schema.js +2 -0
  153. package/dist/reglow/modules/video/schema.js.map +1 -1
  154. package/dist/reglow/modules/video/service.d.ts +5 -0
  155. package/dist/reglow/modules/video/service.js +26 -1
  156. package/dist/reglow/modules/video/service.js.map +1 -1
  157. package/dist/reglow/scripts/init-data.js +414 -2
  158. package/dist/reglow/scripts/init-data.js.map +1 -1
  159. package/dist/reglow/scripts/schema.d.ts +9 -0
  160. package/dist/reglow/scripts/schema.js +448 -1
  161. package/dist/reglow/scripts/schema.js.map +1 -1
  162. package/package.json +83 -83
@@ -0,0 +1,47 @@
1
+ import type { StudioAsset, StudioJob } from "../../core/entities.js";
2
+ /** 确保技能库已播种(幂等)。未就绪时静默忽略,不阻断智能工坊运行。 */
3
+ export declare function ensureSkills(): Promise<void>;
4
+ /**
5
+ * 加载**提示词类**技能 {技能ID: 技能正文},用于角色产出时注入系统提示词。
6
+ *
7
+ * kind=tool 的技能属可执行工具,由工具注册表分派,不注入提示词。
8
+ */
9
+ export declare function loadSkills(): Promise<Record<number, string>>;
10
+ /** 技能名 → 技能ID,用于内置角色播种时绑定技能。 */
11
+ export declare function skillIdsByName(): Promise<Record<string, number>>;
12
+ declare function scaleAsset(row: StudioAsset): StudioAsset;
13
+ declare function scaleJob(row: StudioJob): StudioJob;
14
+ export interface CreateAssetOptions {
15
+ run_id?: number | null;
16
+ step_key?: string | null;
17
+ tool_key?: string | null;
18
+ kind?: string;
19
+ name?: string | null;
20
+ url?: string | null;
21
+ path?: string | null;
22
+ content?: Buffer | Uint8Array | null;
23
+ mime?: string | null;
24
+ meta?: Record<string, unknown> | null;
25
+ created_by?: number | null;
26
+ }
27
+ /** 登记工坊产物:物理文件落 storage,本表只记产物语义。
28
+ *
29
+ * 是否登记为系统素材由用户在产物资产页决定(`saveAssetToMaterial`),
30
+ * 生成时不再自动写入 `sys_material`。
31
+ */
32
+ export declare function createAsset(opts: CreateAssetOptions): Promise<StudioAsset>;
33
+ /** 把已存在的产物文件登记为系统素材(复用原文件,不复制),并回写 asset.material_id。 */
34
+ export declare function saveAssetToMaterial(asset: StudioAsset): Promise<number>;
35
+ export interface CreateJobOptions {
36
+ run_id?: number | null;
37
+ step_key?: string | null;
38
+ tool_key?: string | null;
39
+ provider?: string | null;
40
+ external_task_id?: string | null;
41
+ status?: string;
42
+ progress?: number;
43
+ result?: Record<string, unknown> | null;
44
+ }
45
+ /** 登记工坊长任务(媒体生成耗时分钟级),供轮询与断点恢复。 */
46
+ export declare function createJob(opts: CreateJobOptions): Promise<StudioJob>;
47
+ export { scaleAsset, scaleJob };
@@ -0,0 +1,175 @@
1
+ /**
2
+ * 智能工坊 Studio - 能力依赖适配(可插拔单一入口)
3
+ * 对应 backend-python 的 reglow/modules/studio/deps.py
4
+ *
5
+ * 智能工坊需要「技能库」能力,技能库位于基础库 reglow/modules/skill。
6
+ * 这里把对技能库的访问**收敛到本文件**,避免其余代码散落依赖。
7
+ * 约定:本文件是智能工坊唯一允许触碰技能库的地方。
8
+ */
9
+ import { logger } from "../../core/logging.js";
10
+ import { knex } from "../../core/database.js";
11
+ import { ModelRegistry } from "../../core/models.js";
12
+ import { generateKey, getStorage } from "../../core/storage.js";
13
+ import { SkillService } from "../skill/service.js";
14
+ import { SkillRepository } from "../skill/repository.js";
15
+ const MaterialT = ModelRegistry.get("Material");
16
+ const AssetT = ModelRegistry.get("StudioAsset");
17
+ const JobT = ModelRegistry.get("StudioJob");
18
+ /** 确保技能库已播种(幂等)。未就绪时静默忽略,不阻断智能工坊运行。 */
19
+ export async function ensureSkills() {
20
+ try {
21
+ await new SkillService().ensureSeed();
22
+ }
23
+ catch (e) {
24
+ logger.debug("技能库初始化失败,忽略", e.message);
25
+ }
26
+ }
27
+ /**
28
+ * 加载**提示词类**技能 {技能ID: 技能正文},用于角色产出时注入系统提示词。
29
+ *
30
+ * kind=tool 的技能属可执行工具,由工具注册表分派,不注入提示词。
31
+ */
32
+ export async function loadSkills() {
33
+ try {
34
+ const items = await new SkillRepository().listAll();
35
+ const map = {};
36
+ for (const s of items) {
37
+ if ((s.kind ?? "prompt") === "prompt")
38
+ map[s.id] = s.content;
39
+ }
40
+ return map;
41
+ }
42
+ catch (e) {
43
+ logger.debug("技能加载失败,忽略", e.message);
44
+ return {};
45
+ }
46
+ }
47
+ /** 技能名 → 技能ID,用于内置角色播种时绑定技能。 */
48
+ export async function skillIdsByName() {
49
+ try {
50
+ const items = await new SkillRepository().listAll();
51
+ const map = {};
52
+ for (const s of items)
53
+ map[s.name] = s.id;
54
+ return map;
55
+ }
56
+ catch (e) {
57
+ logger.debug("技能名映射失败,忽略", e.message);
58
+ return {};
59
+ }
60
+ }
61
+ // ─────────────── 产物 / 长任务(P0-4 / P0-5,单一入口) ───────────────
62
+ /** 可复用产物(素材型)→ 登记系统素材 */
63
+ const MATERIAL_KINDS = new Set(["image", "audio", "video", "file"]);
64
+ const MATERIAL_TYPE = {
65
+ image: "image",
66
+ video: "video",
67
+ };
68
+ function materialType(kind) {
69
+ return MATERIAL_TYPE[kind] ?? "file";
70
+ }
71
+ /** JSON 列读取:兼容 text 存储与驱动已解析的对象 */
72
+ function parseJson(v, fallback) {
73
+ if (v === null || v === undefined)
74
+ return fallback;
75
+ if (typeof v === "string") {
76
+ try {
77
+ return JSON.parse(v);
78
+ }
79
+ catch {
80
+ return fallback;
81
+ }
82
+ }
83
+ return v;
84
+ }
85
+ function scaleAsset(row) {
86
+ return {
87
+ ...row,
88
+ meta: parseJson(row.meta, null),
89
+ };
90
+ }
91
+ function scaleJob(row) {
92
+ return {
93
+ ...row,
94
+ result: parseJson(row.result, null),
95
+ };
96
+ }
97
+ /** 登记工坊产物:物理文件落 storage,本表只记产物语义。
98
+ *
99
+ * 是否登记为系统素材由用户在产物资产页决定(`saveAssetToMaterial`),
100
+ * 生成时不再自动写入 `sys_material`。
101
+ */
102
+ export async function createAsset(opts) {
103
+ const kind = opts.kind ?? "file";
104
+ const storage = getStorage();
105
+ let url = opts.url ?? null;
106
+ let path = opts.path ?? null;
107
+ const content = opts.content ?? null;
108
+ if (content !== null) {
109
+ const nameStr = opts.name ?? "";
110
+ const ext = nameStr.includes(".")
111
+ ? nameStr.slice(nameStr.lastIndexOf(".") + 1)
112
+ : "bin";
113
+ const key = generateKey("studio", ext);
114
+ url = await storage.upload(Buffer.from(content), key, opts.mime || "application/octet-stream");
115
+ path = key;
116
+ }
117
+ const [id] = await knex(AssetT).insert({
118
+ run_id: opts.run_id ?? null,
119
+ step_key: opts.step_key ?? null,
120
+ tool_key: opts.tool_key ?? null,
121
+ kind,
122
+ name: opts.name ?? null,
123
+ material_id: null,
124
+ url,
125
+ path,
126
+ meta: opts.meta ? JSON.stringify(opts.meta) : null,
127
+ source_tool: opts.tool_key ?? null,
128
+ created_by: opts.created_by ?? null,
129
+ });
130
+ const row = (await knex(AssetT).where("id", id).first());
131
+ return scaleAsset(row);
132
+ }
133
+ /** 把已存在的产物文件登记为系统素材(复用原文件,不复制),并回写 asset.material_id。 */
134
+ export async function saveAssetToMaterial(asset) {
135
+ if (asset.material_id)
136
+ return asset.material_id;
137
+ const url = asset.url;
138
+ const kind = asset.kind ?? "file";
139
+ if (!MATERIAL_KINDS.has(kind) || !url) {
140
+ throw new Error("该产物不支持保存到系统素材");
141
+ }
142
+ const meta = asset.meta ?? {};
143
+ const storage = getStorage();
144
+ const [materialId] = await knex(MaterialT).insert({
145
+ name: asset.name || (url.split("/").pop() ?? "asset"),
146
+ type: materialType(kind),
147
+ url,
148
+ size: Number(meta.size ?? 0) || 0,
149
+ mime_type: meta.mime ?? null,
150
+ storage: storage.backend_name,
151
+ source: "工坊产物",
152
+ });
153
+ await knex(AssetT).where("id", asset.id).update({
154
+ material_id: materialId,
155
+ });
156
+ asset.material_id = materialId;
157
+ return materialId;
158
+ }
159
+ /** 登记工坊长任务(媒体生成耗时分钟级),供轮询与断点恢复。 */
160
+ export async function createJob(opts) {
161
+ const [id] = await knex(JobT).insert({
162
+ run_id: opts.run_id ?? null,
163
+ step_key: opts.step_key ?? null,
164
+ tool_key: opts.tool_key ?? null,
165
+ provider: opts.provider ?? null,
166
+ external_task_id: opts.external_task_id ?? null,
167
+ status: opts.status ?? "pending",
168
+ progress: opts.progress ?? 0,
169
+ result: opts.result ? JSON.stringify(opts.result) : null,
170
+ });
171
+ const row = (await knex(JobT).where("id", id).first());
172
+ return scaleJob(row);
173
+ }
174
+ export { scaleAsset, scaleJob };
175
+ //# sourceMappingURL=deps.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"deps.js","sourceRoot":"","sources":["../../../../reglow/modules/studio/deps.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAC/C,OAAO,EAAE,IAAI,EAAE,MAAM,wBAAwB,CAAC;AAC9C,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAChE,OAAO,EAAE,YAAY,EAA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EAAE,CAAc,CAAC;IACpE,OAAO,QAAQ,CAAC,GAAG,CAAC,CAAC;AACvB,CAAC;AAED,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,CAAC"}
@@ -0,0 +1,85 @@
1
+ import type { StudioRole, StudioRun } from "../../core/entities.js";
2
+ import type { StudioRepository } from "./repository.js";
3
+ export interface StudioStep {
4
+ key: string;
5
+ name: string;
6
+ role_key: string;
7
+ task: string;
8
+ depends_on: string[];
9
+ approval: boolean;
10
+ tool_key?: string | null;
11
+ args?: Record<string, unknown> | null;
12
+ }
13
+ export interface StepState {
14
+ name?: string | null;
15
+ role_key?: string | null;
16
+ approval?: boolean;
17
+ status: string;
18
+ output?: string | null;
19
+ output_kind?: string | null;
20
+ error?: string | null;
21
+ started_at?: string;
22
+ finished_at?: string;
23
+ approved_by?: string;
24
+ assets?: number[];
25
+ job_id?: number;
26
+ }
27
+ export interface PlanResult {
28
+ name: string;
29
+ goal: string;
30
+ steps: StudioStep[];
31
+ mode: string;
32
+ }
33
+ /** 一句话任务附件:文本内容或已上传的素材地址。 */
34
+ export interface ComposeAttachment {
35
+ name: string;
36
+ kind?: string;
37
+ content?: string | null;
38
+ url?: string | null;
39
+ mime?: string | null;
40
+ size?: number | null;
41
+ }
42
+ /** 把用户附件整理为提示词上下文(图片给地址,文本给正文,其余给地址)。 */
43
+ export declare function attachmentsBrief(attachments?: ComposeAttachment[] | null): string;
44
+ /** 一句话任务允许 AI 自动编排的工具:只开放「产物型」内建工具。 */
45
+ export declare const COMPOSE_TOOL_KEYS: string[];
46
+ /** 保证一次运行至少产出一个文件产物:缺 file.write 步骤时补「交付文档」。 */
47
+ export declare function ensureDeliveryStep(steps: StudioStep[], validTools: Set<string>, roles: StudioRole[], intent: string): StudioStep[];
48
+ type StepStates = Record<string, StepState>;
49
+ /** 从 LLM 输出中宽松提取 JSON 对象 */
50
+ export declare function parseJson(text: string): Record<string, unknown> | null;
51
+ /**
52
+ * 校验并规整步骤:role_key 合法、key 唯一、依赖存在、工具存在、最后补人工终审。
53
+ *
54
+ * `validTools` 为 undefined 表示不校验工具(保持旧行为);否则未知 tool_key 会被清空,
55
+ * 该步骤退化为普通 LLM 文本步骤,避免规划出必然失败的步骤。
56
+ */
57
+ export declare function normalizeSteps(rawSteps: unknown, validKeys: Set<string>, validTools?: Set<string> | null): StudioStep[];
58
+ /**
59
+ * 未配置 AI 或解析失败时的规则化保底计划(演示可跑通)。
60
+ *
61
+ * `toolKeys` 为当前可用工具集合:有生图能力时补「生成配图」,
62
+ * 有 file.write 时补「交付文档」,让一句话任务在无 AI 编排时也能产出文件级产物。
63
+ */
64
+ export declare function fallbackPlan(intent: string, roles: StudioRole[], toolKeys?: Set<string>): PlanResult;
65
+ /** 一句话 → 计划:AI 自动从角色库挑人组队并拆解 DAG(可含工具步骤/附件) */
66
+ export declare function composePlan(intent: string, roles: StudioRole[], attachments?: ComposeAttachment[] | null): Promise<PlanResult>;
67
+ /** 润色一句话任务:更清晰、具体、可执行(未配置 AI 时原样返回)。 */
68
+ export declare function polishIntent(intent: string): Promise<string>;
69
+ export declare function buildSystemPrompt(role: StudioRole | undefined, skillsMap: Record<number, string>): string;
70
+ export declare const EXPRESSION_GUIDE: string;
71
+ export declare function buildUserPrompt(goal: string, step: StudioStep, _steps: StudioStep[], states: StepStates): string;
72
+ export declare function mockStepOutput(role: StudioRole | undefined, step: StudioStep, goal: string): string;
73
+ /** 执行/恢复运行:依赖满足即并发执行,遇审批暂停。返回最新 run。 */
74
+ export declare function executeRun(repo: StudioRepository, run: StudioRun): Promise<StudioRun | undefined>;
75
+ /** 应用人工审批结果(仅落库,不执行):通过则标记完成,驳回则终止。 */
76
+ export declare function applyApproval(repo: StudioRepository, run: StudioRun, stepKey: string, decision: string, comment: string | null, editedOutput: string | null): Promise<StudioRun | undefined>;
77
+ /** 收集需重置的步骤:目标步及其全部下游(依赖闭包)。 */
78
+ export declare function collectResetTargets(steps: StudioStep[], stepKey: string): Set<string>;
79
+ /** 把指定步骤重置为待执行,并清空产出/错误/审批记录。 */
80
+ export declare function resetSteps(states: StepStates, steps: StudioStep[], affected: Set<string>): void;
81
+ /** 应用返工:把该步及所有下游重置为待执行,返工意见并入任务,并重置运行状态触发重跑。 */
82
+ export declare function applyRework(repo: StudioRepository, run: StudioRun, stepKey: string, comment: string): Promise<StudioRun | undefined>;
83
+ /** 重试某步:把该步及下游重置为待执行(不改任务),并重置运行状态触发重跑。 */
84
+ export declare function applyRetry(repo: StudioRepository, run: StudioRun, stepKey: string): Promise<StudioRun | undefined>;
85
+ export {};