@longzai-intelligence-workflow/core 0.0.1 → 0.0.5

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 (48) hide show
  1. package/.turbo/turbo-build.log +5 -0
  2. package/.turbo/turbo-lint.log +1305 -0
  3. package/.turbo/turbo-typecheck.log +12 -0
  4. package/CHANGELOG.md +24 -1
  5. package/coverage/.lcov.info.09bb1f2a9aba2380.tmp +169 -0
  6. package/coverage/.lcov.info.0e095d78ac9192b0.tmp +329 -0
  7. package/coverage/.lcov.info.53a7ebfa7c8664ce.tmp +12 -0
  8. package/coverage/.lcov.info.6ea86c7cbc796fe0.tmp +12 -0
  9. package/coverage/.lcov.info.8f2985e5b3ad22cc.tmp +329 -0
  10. package/coverage/.lcov.info.a6ce2b7c3df2438b.tmp +228 -0
  11. package/coverage/.lcov.info.cc45f2f81aa7e02f.tmp +12 -0
  12. package/coverage/.lcov.info.cd0e8c028b2d5097.tmp +329 -0
  13. package/coverage/.lcov.info.dae76ebcf998e663.tmp +12 -0
  14. package/coverage/.lcov.info.e3bdb201eb5ce330.tmp +170 -0
  15. package/coverage/.lcov.info.e54e42fa06f69854.tmp +12 -0
  16. package/coverage/.lcov.info.f3e7537ac7b81e07.tmp +12 -0
  17. package/coverage/.lcov.info.fbb8af17757faa2d.tmp +329 -0
  18. package/coverage/lcov.info +208 -48
  19. package/dist/index.d.ts +3 -29
  20. package/dist/index.js +3 -3
  21. package/docs/overview.md +1 -1
  22. package/package.json +2 -1
  23. package/src/__tests__/unit/constants.test.ts +75 -30
  24. package/src/__tests__/unit/utils.test.ts +110 -38
  25. package/src/__tests__/work-item-rules.test.ts +18 -5
  26. package/src/index.ts +19 -5
  27. package/src/ports/action-executor.port.ts +2 -1
  28. package/src/ports/feed-event.port.ts +1 -1
  29. package/src/ports/index.ts +1 -0
  30. package/src/schemas/action-executor.schema.ts +2 -1
  31. package/src/schemas/definition.schema.ts +1 -1
  32. package/src/schemas/feed-event-trigger.schema.ts +1 -1
  33. package/src/schemas/index.ts +7 -0
  34. package/src/schemas/instance.schema.ts +1 -1
  35. package/src/schemas/monitoring.schema.ts +1 -1
  36. package/src/schemas/trigger.schema.ts +1 -1
  37. package/src/schemas/workflow-doc.schema.ts +4 -2
  38. package/src/types/action-executor.ts +1 -1
  39. package/src/types/feed-event-trigger.ts +1 -1
  40. package/src/types/index.ts +5 -0
  41. package/src/utils/dag.utils.ts +14 -93
  42. package/src/utils/index.ts +4 -2
  43. package/src/utils/work-item-rules.utils.ts +28 -7
  44. package/tsconfig/.cache/build.tsbuildinfo +1 -1
  45. package/tsconfig/.cache/node.tsbuildinfo +1 -1
  46. package/tsconfig/.cache/test.tsbuildinfo +1 -1
  47. package/tsconfig/node.json +1 -1
  48. package/tsconfig.json +9 -1
@@ -10,7 +10,7 @@ import type {
10
10
  feedEventNameSchema,
11
11
  feedEventPayloadSchema,
12
12
  feedEventTriggerSchema,
13
- } from '../schemas';
13
+ } from '@/schemas';
14
14
  import type { z } from 'zod';
15
15
 
16
16
  /**
@@ -1,6 +1,11 @@
1
1
  export * from './definition';
2
+
2
3
  export * from './instance';
4
+
3
5
  export * from './trigger';
6
+
4
7
  export * from './monitoring';
8
+
5
9
  export * from './feed-event-trigger';
10
+
6
11
  export * from './action-executor';
@@ -1,95 +1,16 @@
1
1
  /**
2
- * DAG 机件(环检测 + 拓扑分层 + 依赖满足判定)
3
- *
4
- * 共享基础(设计对齐 scheduler workflow 域已验证机件;真源归本包,禁止再镜像)。
2
+ * DAG 机件转发出口(真源 = @longzai-intelligence-dag/core 基础能力域;消费方零改动兼容)
5
3
  */
6
-
7
- /**
8
- * 依赖边(from 完成后 to 可启)
9
- */
10
- export type DependencyEdge = { readonly from: string; readonly to: string };
11
-
12
- /**
13
- * 环检测(DFS 三色标记;返回首个环路径,无环为 null)
14
- *
15
- * @param edges - 依赖边集合
16
- */
17
- export function detectCycle(edges: readonly DependencyEdge[]): readonly string[] | null {
18
- /**
19
- * 邻接表
20
- */
21
- const adjacency = new Map<string, string[]>();
22
- for (const edge of edges) {
23
- adjacency.set(edge.from, [...(adjacency.get(edge.from) ?? []), edge.to]);
24
- }
25
-
26
- /**
27
- * 节点访问状态(0=未访问 1=在栈 2=完成)
28
- */
29
- const state = new Map<string, 0 | 1 | 2>();
30
-
31
- /**
32
- * 当前 DFS 路径
33
- */
34
- const path: string[] = [];
35
-
36
- /**
37
- * 单节点深搜(返回环路径或 null)
38
- */
39
- const visit = (node: string): readonly string[] | null => {
40
- /**
41
- * 当前节点状态
42
- */
43
- const current = state.get(node) ?? 0;
44
- if (current === 1) {
45
- /**
46
- * 环路径:当前路径中该节点之后的部分 + 首尾相接
47
- */
48
- const start = path.indexOf(node);
49
- return [...path.slice(start), node];
50
- }
51
- if (current === 2) {
52
- return null;
53
- }
54
- state.set(node, 1);
55
- path.push(node);
56
- for (const next of adjacency.get(node) ?? []) {
57
- /**
58
- * 后继环路径
59
- */
60
- const cycle = visit(next);
61
- if (cycle !== null) {
62
- return cycle;
63
- }
64
- }
65
- path.pop();
66
- state.set(node, 2);
67
- return null;
68
- };
69
-
70
- /**
71
- * 全部节点(确定性排序)
72
- */
73
- const nodes = [...new Set(edges.flatMap((edge) => [edge.from, edge.to]))].sort((left, right) => (left < right ? -1 : 1));
74
- for (const node of nodes) {
75
- /**
76
- * 各节点环检测
77
- */
78
- const cycle = visit(node);
79
- if (cycle !== null) {
80
- return cycle;
81
- }
82
- }
83
- return null;
84
- }
85
-
86
- /**
87
- * 依赖满足判定(全部前置达完成/验收才算满足;无前置视为满足)
88
- *
89
- * @param node - 目标工作项 id
90
- * @param edges - 依赖边集合
91
- * @param settled - 已闭环(完成/验收)的工作项集合
92
- */
93
- export function dependenciesMet(node: string, edges: readonly DependencyEdge[], settled: ReadonlySet<string>): boolean {
94
- return edges.filter((edge) => edge.to === node).every((edge) => settled.has(edge.from));
95
- }
4
+ export {
5
+ type DependencyEdge,
6
+ detectCycle,
7
+ detectCycles,
8
+ dependenciesMet,
9
+ areAllDependenciesMet,
10
+ downstreamOf,
11
+ nodesOf,
12
+ topologicalLevels,
13
+ topologicalSort,
14
+ validateEdges,
15
+ type EdgeIssue,
16
+ } from '@longzai-intelligence-dag/core';
@@ -1,4 +1,4 @@
1
- import { DEFAULT_PAGE_SIZE, MAX_PAGE_SIZE } from '../constants/workflow';
1
+ import { DEFAULT_PAGE_SIZE, MAX_PAGE_SIZE } from '@/constants/workflow';
2
2
 
3
3
  export function getPagination(page?: number, pageSize?: number): { offset: number; limit: number } {
4
4
  const limit = Math.min(pageSize ?? DEFAULT_PAGE_SIZE, MAX_PAGE_SIZE);
@@ -15,5 +15,7 @@ export function formatDate(date: string | Date): string {
15
15
  }
16
16
 
17
17
  export * from './declaration-frontmatter.utils';
18
- export * from './dag.utils';
18
+
19
19
  export * from './work-item-rules.utils';
20
+
21
+ export * from './dag.utils';
@@ -1,15 +1,24 @@
1
+ import type {
2
+ WorkflowEdge,
3
+ WorkflowGate,
4
+ WorkflowItem,
5
+ WorkItemStatus,
6
+ } from '@/schemas/workflow-doc.schema';
7
+
1
8
  /**
2
9
  * 工作项判定核(纯函数、零 I/O——输入声明形态,输出视图与违规)
3
10
  *
4
11
  * 判定器契约:只判不动(对齐家族 verify 模式);执行状态归声明档由属主维护,
5
12
  * 本模块不做任何状态写入,仅依据声明现状派生视图与转移合法性。
6
13
  */
7
- import type { WorkflowEdge, WorkflowGate, WorkflowItem, WorkItemStatus } from '../schemas/workflow-doc.schema';
14
+ import { dependenciesMet } from '@longzai-intelligence-dag/core';
8
15
 
9
16
  /**
10
17
  * 工作项合法状态转移表(状态机唯一注册点;供编辑工具与判定器共用的规则真源)
11
18
  */
12
- export const ALLOWED_STATUS_TRANSITIONS: Readonly<Record<WorkItemStatus, readonly WorkItemStatus[]>> = {
19
+ export const ALLOWED_STATUS_TRANSITIONS: Readonly<
20
+ Record<WorkItemStatus, readonly WorkItemStatus[]>
21
+ > = {
13
22
  todo: ['doing', 'blocked', 'dropped'],
14
23
  doing: ['blocked', 'done', 'dropped'],
15
24
  blocked: ['todo', 'doing', 'dropped'],
@@ -39,7 +48,10 @@ export type InvalidTransitionError = {
39
48
  * @param to - 目标状态
40
49
  * @returns 合法时为 null;非法时携带合法后继清单
41
50
  */
42
- export function checkStatusTransition(from: WorkItemStatus, to: WorkItemStatus): InvalidTransitionError | null {
51
+ export function checkStatusTransition(
52
+ from: WorkItemStatus,
53
+ to: WorkItemStatus,
54
+ ): InvalidTransitionError | null {
43
55
  /**
44
56
  * 注册表中的合法后继
45
57
  */
@@ -48,7 +60,10 @@ export function checkStatusTransition(from: WorkItemStatus, to: WorkItemStatus):
48
60
  return { code: 'INVALID_TRANSITION', message: `未知状态:${from}` };
49
61
  }
50
62
  if (!allowed.includes(to)) {
51
- return { code: 'INVALID_TRANSITION', message: `非法转移:${from} → ${to}(合法后继:${allowed.join(' / ')})` };
63
+ return {
64
+ code: 'INVALID_TRANSITION',
65
+ message: `非法转移:${from} → ${to}(合法后继:${allowed.join(' / ')})`,
66
+ };
52
67
  }
53
68
  return null;
54
69
  }
@@ -132,6 +147,7 @@ export type WorkflowView = {
132
147
  * 已闭环状态集合(依赖满足判定基准:done 或 dropped 均不再阻塞后继)
133
148
  *
134
149
  * @param status - 工作项状态
150
+ * @returns 状态为 done 或 dropped 时为 true,否则为 false
135
151
  */
136
152
  function isSettled(status: WorkItemStatus): boolean {
137
153
  return status === 'done' || status === 'dropped';
@@ -143,6 +159,7 @@ function isSettled(status: WorkItemStatus): boolean {
143
159
  * @param items - 工作项清单(声明档现状)
144
160
  * @param edges - 依赖边清单
145
161
  * @param gates - 裁定门清单(含裁定事实)
162
+ * @returns 工作流声明视图,含全部工作项视图与未决裁定清单
146
163
  */
147
164
  export function deriveWorkflowView(
148
165
  items: readonly WorkflowItem[],
@@ -157,16 +174,20 @@ export function deriveWorkflowView(
157
174
  /**
158
175
  * 各工作项挂靠的未批准门(ruling.status 非 approved 即阻塞)
159
176
  */
160
- const unapprovedGateAt = new Set(gates.filter((gate) => gate.ruling.status !== 'approved' && gate.at !== 'workflow').map((gate) => gate.at));
177
+ const unapprovedGateAt = new Set(
178
+ gates
179
+ .filter((gate) => gate.ruling.status !== 'approved' && gate.at !== 'workflow')
180
+ .map((gate) => gate.at),
181
+ );
161
182
 
162
183
  /**
163
184
  * 工作项视图累积
164
185
  */
165
186
  const views: WorkItemView[] = items.map((item) => {
166
187
  /**
167
- * 依赖满足判定(全部前置闭环)
188
+ * 依赖满足判定(DAG 基础能力域机件,闭环定义由本域注入)
168
189
  */
169
- const depsMet = edges.filter((edge) => edge.to === item.id).every((edge) => settled.has(edge.from));
190
+ const depsMet = dependenciesMet(item.id, edges, settled);
170
191
 
171
192
  return {
172
193
  id: item.id,