@xtalpi/agentic-lab-skills 0.0.9 → 0.0.11

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 (68) hide show
  1. package/README.md +1 -1
  2. package/package.json +14 -14
  3. package/skills/lab-flow-designer/SKILL.md +612 -593
  4. package/skills/lab-flow-designer/embedded-template/SKILL.md +103 -88
  5. package/skills/lab-flow-designer/embedded-template/pools//345/205/245/345/217/243/346/261/240.md +21 -12
  6. package/skills/lab-flow-designer/embedded-template/pools//345/207/272/345/217/243/346/261/240.md +21 -12
  7. package/skills/lab-flow-designer/embedded-template/scripts//347/244/272/344/276/213/346/225/260/346/215/256/344/270/216/346/240/241/351/252/214/351/227/250/346/216/247.js +142 -142
  8. package/skills/lab-flow-designer/embedded-template/valves//347/244/272/344/276/213/346/225/260/346/215/256/344/270/216/346/240/241/351/252/214/351/227/250/346/216/247.md +114 -99
  9. package/skills/lab-flow-designer/references/agentic-lab-processer.md +122 -78
  10. package/skills/lab-flow-designer/references/agentic-lab-sdk.md +534 -361
  11. package/skills/lab-flow-designer/references/rhea-api/README.md +7 -7
  12. package/skills/lab-flow-designer/references/rhea-api/execute_process_batch.md +58 -58
  13. package/skills/lab-flow-designer/references/skill-package-layout.md +268 -204
  14. package/skills/lab-flow-designer/references//344/270/232/345/212/241/346/265/201/347/250/213/346/226/207/346/241/243/346/240/207/345/207/206.md +216 -208
  15. package/skills/lab-flow-designer/templates//344/270/232/345/212/241/346/265/201/347/250/213/346/226/207/346/241/243/346/250/241/346/235/277.md +192 -169
  16. package/skills/lab-flow-designer/templates//344/270/232/345/212/241/346/265/201/347/250/213/346/226/207/346/241/243/347/244/272/344/276/213.md +207 -197
  17. package/skills/lab-flow-designer/testing/test-processer.mjs +1240 -1075
  18. package/skills/lab-nocobase-flow-generator/SKILL.md +164 -164
  19. package/skills/lab-nocobase-flow-generator/examples/setting/350/241/250/350/216/267/345/217/226/345/244/226/351/203/250/346/234/215/345/212/241.js +70 -70
  20. package/skills/lab-nocobase-flow-generator/examples//346/237/245/350/257/242/345/214/226/345/255/246/345/223/201/344/277/241/346/201/257.js +30 -30
  21. package/skills/lab-nocobase-flow-generator/references/doc-standard.md +84 -84
  22. package/skills/lab-nocobase-flow-generator/references/runtime-api.md +224 -224
  23. package/skills/lab-nocobase-flow-generator/templates//350/204/232/346/234/254/351/200/273/350/276/221/346/226/207/346/241/243/346/250/241/346/235/277.md +121 -121
  24. package/skills/lab-nocobase-flow-generator/templates//350/204/232/346/234/254/351/200/273/350/276/221/346/226/207/346/241/243/347/244/272/344/276/213.md +67 -67
  25. package/skills/lab-orbit-component-builder/SKILL.md +353 -353
  26. package/skills/lab-orbit-component-builder/examples/xnb-component-template/.env.local.example +27 -27
  27. package/skills/lab-orbit-component-builder/examples/xnb-component-template/.eslintignore +7 -7
  28. package/skills/lab-orbit-component-builder/examples/xnb-component-template/.eslintrc.cjs +88 -88
  29. package/skills/lab-orbit-component-builder/examples/xnb-component-template/.nvmrc +1 -1
  30. package/skills/lab-orbit-component-builder/examples/xnb-component-template/AgenticAppAPI.md +268 -268
  31. package/skills/lab-orbit-component-builder/examples/xnb-component-template/Jenkinsfile +106 -106
  32. package/skills/lab-orbit-component-builder/examples/xnb-component-template/OrbitAPI.md +453 -453
  33. package/skills/lab-orbit-component-builder/examples/xnb-component-template/README.md +176 -176
  34. package/skills/lab-orbit-component-builder/examples/xnb-component-template/dev/public/index.html +12 -12
  35. package/skills/lab-orbit-component-builder/examples/xnb-component-template/dev/src/App.vue +151 -151
  36. package/skills/lab-orbit-component-builder/examples/xnb-component-template/dev/src/components/DevOpenerLauncher.vue +143 -143
  37. package/skills/lab-orbit-component-builder/examples/xnb-component-template/dev/src/global.d.ts +77 -77
  38. package/skills/lab-orbit-component-builder/examples/xnb-component-template/dev/src/main.ts +308 -308
  39. package/skills/lab-orbit-component-builder/examples/xnb-component-template/dev/src/mockXNBBitable.ts +119 -119
  40. package/skills/lab-orbit-component-builder/examples/xnb-component-template/dev/src/shims-vue.d.ts +6 -6
  41. package/skills/lab-orbit-component-builder/examples/xnb-component-template/dev/src/utils/devOpenerHost.ts +75 -75
  42. package/skills/lab-orbit-component-builder/examples/xnb-component-template/index.html +13 -13
  43. package/skills/lab-orbit-component-builder/examples/xnb-component-template/package.json +60 -60
  44. package/skills/lab-orbit-component-builder/examples/xnb-component-template/src/api/agenticlabTickets.ts +110 -110
  45. package/skills/lab-orbit-component-builder/examples/xnb-component-template/src/entries/bitable.ts +4 -4
  46. package/skills/lab-orbit-component-builder/examples/xnb-component-template/src/entries/custom-page.ts +4 -4
  47. package/skills/lab-orbit-component-builder/examples/xnb-component-template/src/index.ts +1 -1
  48. package/skills/lab-orbit-component-builder/examples/xnb-component-template/src/styles/orbit-quasar-host.scss +19 -19
  49. package/skills/lab-orbit-component-builder/examples/xnb-component-template/src/types/context.ts +15 -15
  50. package/skills/lab-orbit-component-builder/examples/xnb-component-template/src/types/xnb-context.ts +70 -70
  51. package/skills/lab-orbit-component-builder/examples/xnb-component-template/src/use/useBitablePage.ts +189 -189
  52. package/skills/lab-orbit-component-builder/examples/xnb-component-template/src/use/useSuperCellDemo.ts +257 -257
  53. package/skills/lab-orbit-component-builder/examples/xnb-component-template/src/use/useSuperTableBitableLifecycle.ts +555 -555
  54. package/skills/lab-orbit-component-builder/examples/xnb-component-template/src/utils/openerInitParams.ts +158 -158
  55. package/skills/lab-orbit-component-builder/examples/xnb-component-template/src/utils/openerTicketIds.ts +32 -32
  56. package/skills/lab-orbit-component-builder/examples/xnb-component-template/src/utils/orbitHttpClient.ts +110 -110
  57. package/skills/lab-orbit-component-builder/examples/xnb-component-template/src/utils/request.ts +92 -92
  58. package/skills/lab-orbit-component-builder/examples/xnb-component-template/src/views/bitable.vue +67 -67
  59. package/skills/lab-orbit-component-builder/examples/xnb-component-template/src/views/custom-page.vue +140 -140
  60. package/skills/lab-orbit-component-builder/examples/xnb-component-template/tsconfig.json +45 -45
  61. package/skills/lab-orbit-component-builder/examples/xnb-component-template/vite.config.ts +170 -170
  62. package/skills/lab-orbit-component-builder/examples/xnb-component-template/vite.dev.config.ts +58 -58
  63. package/skills/lab-orbit-component-builder/references/flow-document-human-ui.md +65 -65
  64. package/skills/lab-orbit-component-builder/references/orbit-vue-conventions.md +133 -133
  65. package/skills/lab-orbit-component-builder/references/pool-schema-to-columns.md +67 -67
  66. package/skills/lab-orbit-component-builder/references/vue-template-checklist.md +179 -179
  67. package/skills/lab-orbit-component-builder/references/xnb-context-vue-props.md +49 -49
  68. package/skills/lab-orbit-component-builder/references/xnbitable-vue-parity.md +32 -32
@@ -1,88 +1,103 @@
1
- ---
2
- name: embedded-flow-example
3
- description: >-
4
- 示意流程注册包。仅作 lab-flow-designer 内置版式样例,演示 SKILL/pools/valves/scripts 目录与章节结构。
5
- Do not install as a standalone skill; copy layout to your output directory and replace name with the output folder name.
6
- metadata:
7
- version: "1.0.0"
8
- generated_by: lab-flow-designer
9
- generated_at: "2026-06-20"
10
- ---
11
-
12
- # 示意流程
13
-
14
- ## 概述
15
-
16
- 示意流程用于演示「数据池 + 门控」协作时的文档写法:记录从入口池进入门控,经 **compound / chemical_record 类查询** 与规则校验后写入出口池。生成真实流程注册包时,本段替换为流程说明中的业务摘要。
17
-
18
- ## 核心概念
19
-
20
- ### 数据池(Pool)
21
-
22
- Pool 存多条记录,每池有独立 Schema,字段随阶段可不同。
23
-
24
- ### 门控(Valve)
25
-
26
- 每个门控对应一个脚本,导出 `Processer`,实现 `start` 与 `complete`。`this.context` 能力以本 skill 的 [references/agentic-lab-sdk.md](../references/agentic-lab-sdk.md) 为准;门控文档结构见 [valves/示例数据与校验门控.md](valves/示例数据与校验门控.md)。
27
-
28
- ## 流程图
29
-
30
- (与 lab-flow-designer 约定一致:**池 = 矩形 `[…]`,门控 = 六边形 `{{…}}`**。)
31
-
32
- ```mermaid
33
- flowchart LR
34
- in_pool[入口池]
35
- gate{{示例数据与校验门控}}
36
- out_pool[出口池]
37
- in_pool --> gate --> out_pool
38
- ```
39
-
40
- **连接关系:**
41
-
42
- 1. `入口池` → `示例数据与校验门控`:待处理记录进入门控
43
- 2. `示例数据与校验门控` → `出口池`:校验与回填完成后写入出口池
44
-
45
- ## 节点清单
46
-
47
- ### Pool 节点(数据池)
48
-
49
- | 名称 | 文件 | 用途 |
50
- |------|------|------|
51
- | 入口池 | [pools/入口池.md](pools/入口池.md) | 流程入口数据 |
52
- | 出口池 | [pools/出口池.md](pools/出口池.md) | 流程出口数据 |
53
-
54
- ### Valve 节点(门控)
55
-
56
- | 名称 | 文件 | 脚本 | 类型 |
57
- |------|------|------|------|
58
- | 示例数据与校验门控 | [valves/示例数据与校验门控.md](valves/示例数据与校验门控.md) | [scripts/示例数据与校验门控.js](scripts/示例数据与校验门控.js) | 自动化 |
59
-
60
- ## 门控执行规范
61
-
62
- 每个 Valve 的 JavaScript 脚本导出 `Processer` 类,必须实现 `start` / `complete`。由流程说明生成真实流程注册包时,脚本**仅实现文档明确要求**的逻辑与字段处理,须遵循主 `SKILL.md`「门控脚本编写指引」;下方代码块仅示意类骨架。
63
-
64
- ```javascript
65
- class Processer {
66
- constructor(context) {
67
- this.context = context;
68
- }
69
-
70
- async start(params) {
71
- // params: { valve_id, pool_ids }
72
- // 从入口池拉取数据,执行处理逻辑
73
- // 返回中间结果
74
- }
75
-
76
- async complete(params) {
77
- // params: { valve_id, tickets }
78
- // 将数据分发到出口池,更新状态
79
- // 返回最终结果
80
- }
81
- }
82
- ```
83
-
84
- ## 使用方式
85
-
86
- 1. 查看各 Pool 的 [pools/](pools/) 目录了解数据表结构
87
- 2. 查看各 Valve 的 [valves/](valves/) 目录了解门控逻辑和脚本路径
88
- 3. 执行门控时,调用对应脚本的 `Processer` 类
1
+ ---
2
+ name: embedded-flow-example
3
+ description: >-
4
+ 示意流程注册包。仅作 lab-flow-designer 内置版式样例,演示 SKILL/pools/valves/scripts 目录与章节结构。
5
+ Do not install as a standalone skill; copy layout to your output directory and replace name with the output folder name.
6
+ metadata:
7
+ version: "1.0.0"
8
+ generated_by: lab-flow-designer
9
+ generated_at: "2026-06-20"
10
+ ---
11
+
12
+ # 示意流程
13
+
14
+ ## 概述
15
+
16
+ 示意流程用于演示「数据池 + 门控」协作时的文档写法:记录从入口池进入门控,经 **compound / chemical_record 类查询** 与规则校验后写入出口池。生成真实流程注册包时,本段替换为流程说明中的业务摘要。
17
+
18
+ ## 核心概念
19
+
20
+ ### 数据池(Pool)
21
+
22
+ Pool 存多条记录,每池有独立 Schema,字段随阶段可不同。
23
+
24
+ ### 门控(Valve)
25
+
26
+ 每个门控对应一个脚本,导出 `Processer`,实现 `start` 与 `complete`。`this.context` 能力以本 skill 的 [references/agentic-lab-sdk.md](../references/agentic-lab-sdk.md) 为准;门控文档结构见 [valves/示例数据与校验门控.md](valves/示例数据与校验门控.md)。
27
+
28
+ ## 流程图
29
+
30
+ (与 lab-flow-designer 约定一致:**池 = 矩形 `[…]`,门控 = 六边形 `{{…}}`**。)
31
+
32
+ ```mermaid
33
+ flowchart LR
34
+ in_pool[入口池]
35
+ gate{{示例数据与校验门控}}
36
+ out_pool[出口池]
37
+ in_pool --> gate --> out_pool
38
+ ```
39
+
40
+ **连接关系:**
41
+
42
+ 1. `入口池` → `示例数据与校验门控`:待处理记录进入门控
43
+ 2. `示例数据与校验门控` → `出口池`:校验与回填完成后写入出口池
44
+
45
+ ## 节点清单
46
+
47
+ ### Pool 节点(数据池)
48
+
49
+ | 名称 | 文件 | 用途 |
50
+ |------|------|------|
51
+ | 入口池 | [pools/入口池.md](pools/入口池.md) | 流程入口数据 |
52
+ | 出口池 | [pools/出口池.md](pools/出口池.md) | 流程出口数据 |
53
+
54
+ ### Valve 节点(门控)
55
+
56
+ | 名称 | 文件 | 脚本 | 类型 |
57
+ |------|------|------|------|
58
+ | 示例数据与校验门控 | [valves/示例数据与校验门控.md](valves/示例数据与校验门控.md) | [scripts/示例数据与校验门控.js](scripts/示例数据与校验门控.js) | 自动化 |
59
+
60
+ ## 门控执行规范
61
+
62
+ 每个 Valve 的 JavaScript 脚本导出 `Processer` 类,必须实现 `start` / `complete`(人工触发)或 `run`(自动触发)。由流程说明生成真实流程注册包时,脚本**仅实现文档明确要求**的逻辑与字段处理,须遵循主 `SKILL.md`「门控脚本编写指引」;下方代码块仅示意类骨架。
63
+
64
+ ```javascript
65
+ class Processer {
66
+ constructor(context) {
67
+ this.context = context;
68
+ }
69
+
70
+ async start(params) {
71
+ // params: { valve_id, pool_ids }
72
+ // 从入口池拉取数据,执行处理逻辑
73
+ // 返回中间结果
74
+ }
75
+
76
+ async complete(params) {
77
+ // params: { valve_id, tickets }
78
+ // 将数据分发到出口池,更新状态
79
+ // 返回最终结果
80
+ }
81
+ }
82
+ ```
83
+
84
+ **自动触发门控**使用 `run` 替代 `start` + `complete`(详见 [references/agentic-lab-processer.md](../references/agentic-lab-processer.md)):
85
+
86
+ ```javascript
87
+ class Processer {
88
+ constructor(context) {
89
+ this.context = context;
90
+ }
91
+
92
+ async run(params) {
93
+ // params: { valve_id, pool_ids }
94
+ // 查询入口池 → 执行业务逻辑 → 获取出口池 → 映射 new_tickets
95
+ }
96
+ }
97
+ ```
98
+
99
+ ## 使用方式
100
+
101
+ 1. 查看各 Pool 的 [pools/](pools/) 目录了解数据表结构
102
+ 2. 查看各 Valve 的 [valves/](valves/) 目录了解门控逻辑和脚本路径
103
+ 3. 执行门控时,调用对应脚本的 `Processer` 类
@@ -1,12 +1,21 @@
1
- # 入口池
2
-
3
- ## 概述
4
-
5
- 流程入口池,存放尚未经门控处理的记录。
6
-
7
- ## Schema
8
-
9
- | 字段 | 字段标题 | 字段描述 | 字段类型 | 属性 | 默认值 |
10
- |------|----------|----------|----------|------|--------|
11
- | id | ID | 业务主键 | string | | - |
12
- | detail | Detail | 业务明细 JSON | json | | - |
1
+ # 入口池
2
+
3
+ ## 概述
4
+
5
+ 流程入口池,存放尚未经门控处理的记录。
6
+
7
+ ## Schema
8
+
9
+ | 字段 | 字段标题 | 字段描述 | 字段类型 | 属性 | 默认值 |
10
+ |------|----------|----------|----------|------|--------|
11
+ | id | ID | 业务主键 | string | | - |
12
+ | detail | Detail | 业务明细 JSON | json | | - |
13
+
14
+ ## 模型引用
15
+
16
+ > 本池无关联 3D 模型,本节仅作版式示意。实际生成时,无模型引用的池省略本节。
17
+
18
+ | 属性 | 值 |
19
+ |------|-----|
20
+ | 名称 | example-pool-model |
21
+ | 版本 | 1.0.0 |
@@ -1,12 +1,21 @@
1
- # 出口池
2
-
3
- ## 概述
4
-
5
- 流程出口池,存放经门控处理后的记录。
6
-
7
- ## Schema
8
-
9
- | 字段 | 字段标题 | 字段描述 | 字段类型 | 属性 | 默认值 |
10
- |------|----------|----------|----------|------|--------|
11
- | id | ID | 业务主键 | string | | - |
12
- | detail | Detail | 业务明细 JSON | json | | - |
1
+ # 出口池
2
+
3
+ ## 概述
4
+
5
+ 流程出口池,存放经门控处理后的记录。
6
+
7
+ ## Schema
8
+
9
+ | 字段 | 字段标题 | 字段描述 | 字段类型 | 属性 | 默认值 |
10
+ |------|----------|----------|----------|------|--------|
11
+ | id | ID | 业务主键 | string | | - |
12
+ | detail | Detail | 业务明细 JSON | json | | - |
13
+
14
+ ## 模型引用
15
+
16
+ > 本池无关联 3D 模型,本节仅作版式示意。实际生成时,无模型引用的池省略本节。
17
+
18
+ | 属性 | 值 |
19
+ |------|-----|
20
+ | 名称 | example-pool-model |
21
+ | 版本 | 1.0.0 |
@@ -1,142 +1,142 @@
1
- /**
2
- * 示例门控脚本:结构对齐本 skill 主 SKILL.md 与 embedded-template;API 对齐 references/agentic-lab-sdk.md
3
- * 输入输出类型对齐 references/agentic-lab-processer.md(参数与返回值均为 snake_case)。
4
- * 业务规则以用户提供的流程说明 Markdown 为准(「数据查询方式」「字段映射」「数据处理规则」等)。
5
- *
6
- * 门控执行顺序:前置处理(start) → 人工处理(页面) → 后置处理(complete)
7
- *
8
- * 列表类查询:流程说明未要求分页时,显式 limit/offset(见主 SKILL「门控脚本编写指引 → 分页与查全量」)。
9
- *
10
- * 类型安全:ticket.detail 值为任意 JSON 类型(string/number/null/array/object),
11
- * 禁止直接调 .trim()/.split() 等 String 方法——须先 String() 转换(见「编写指引 §5」)。
12
- */
13
-
14
- // --- Artifact Version ---
15
- const __ARTIFACT_VERSION__ = '1.0.0';
16
- const __ARTIFACT_SKILL__ = 'lab-flow-designer';
17
-
18
- const DEFAULT_QUERY_LIMIT = 999999;
19
-
20
- // orbit_link 由流程文档门控脚本配置项中的 PageUrl 与门控前置处理中的 bookid 组合生成
21
- const PAGE_URL = 'http://10.249.133.129:9048/?view=book&book={bookid}';
22
- const BOOK_ID = '1';
23
-
24
- // --- 类型安全辅助函数(detail 值可为任意 JSON 类型,须先转换再操作)---
25
- function str(v) {
26
- return v != null ? String(v) : '';
27
- }
28
- function num(v, fallback) {
29
- const n = Number(v);
30
- return Number.isFinite(n) ? n : (fallback !== undefined ? fallback : 0);
31
- }
32
-
33
- class Processer {
34
- constructor(context) {
35
- this.context = context;
36
- console.info(`[Processer] v${__ARTIFACT_VERSION__} (skill: ${__ARTIFACT_SKILL__})`);
37
- }
38
-
39
- // --- 前置处理 → start ---
40
- // params: { valve_id, pool_ids }
41
- // returns: { orbit_link, ticket_ids }
42
- async start(params) {
43
- const { valve_id, pool_ids } = params;
44
- const { list: tickets } = await this.context.ticket.list({
45
- pool_id__in: pool_ids,
46
- limit: DEFAULT_QUERY_LIMIT,
47
- offset: 0,
48
- });
49
-
50
- const compoundIdList = [
51
- ...new Set(
52
- tickets
53
- .map((t) => t.detail?.cmpd_id || t.detail?.compound_id)
54
- .filter(Boolean)
55
- ),
56
- ];
57
-
58
- let stockRecords = [];
59
- if (compoundIdList.length > 0) {
60
- const filter = { 'cas.$in': compoundIdList };
61
- const stockResponse = await this.context.compound.getStockFromXfcSh({
62
- filter,
63
- });
64
- stockRecords = stockResponse.data || [];
65
- }
66
-
67
- const stations = await this.context.station.list();
68
- const processIds = tickets
69
- .flatMap((t) => t.detail?.process_ids || [])
70
- .filter(Boolean);
71
- const processes =
72
- processIds.length > 0
73
- ? await this.context.process.list({
74
- processIds,
75
- limit: DEFAULT_QUERY_LIMIT,
76
- offset: 0,
77
- })
78
- : [];
79
-
80
- // --- 规则 1.1~1.4:按 valves/示例数据与校验门控.md「数据处理规则」写回 detail(以下为示意)---
81
- for (const ticket of tickets) {
82
- const d = ticket.detail || {};
83
- const stock = stockRecords.filter((r) => str(r.cas) === str(d.cmpd_id));
84
-
85
- if (stock.length) {
86
- d.available_amount_mg = stock.reduce(
87
- (s, r) => s + num(r.latest_amount_mg, 0),
88
- 0
89
- );
90
- }
91
- d._stations_count = stations.length;
92
- d._processes_preview = processes;
93
- ticket.detail = d;
94
- }
95
-
96
- await this.context.ticket.update(tickets);
97
-
98
- const orbit_link = PAGE_URL.replace('{bookid}', BOOK_ID);
99
-
100
- return {
101
- orbit_link,
102
- ticket_ids: tickets.map((t) => t.id),
103
- };
104
- }
105
-
106
- // --- 后置处理 → complete ---
107
- // params: { valve_id, tickets }
108
- // returns: { new_tickets }
109
- async complete(params) {
110
- const { valve_id, tickets } = params;
111
-
112
- const nextPools = await this.context.pool.getNext(valve_id);
113
- const outPool = nextPools.find((p) => p.name === '出口池');
114
-
115
- if (!outPool) {
116
- throw new Error(
117
- `未找到出口池;nextPools=${nextPools.map((p) => p.name).join(',')}`
118
- );
119
- }
120
-
121
- // 将入口池的tickets更新为”已完成”状态,避免重复处理
122
- const finished = tickets.map((t) => ({
123
- ...t,
124
- status: 'finished',
125
- }));
126
- await this.context.ticket.update(finished);
127
-
128
- // 按出口池 schema 映射为新 tickets,由引擎自动创建(不在脚本内调用 ticket.append)
129
- const new_tickets = finished.map((t) => ({
130
- flow_id: t.flow_id,
131
- pool_id: outPool.id,
132
- order_id: t.order_id,
133
- detail: t.detail,
134
- status: 'created',
135
- parent_ticket_id: t.id,
136
- }));
137
-
138
- return {
139
- new_tickets,
140
- };
141
- }
142
- }
1
+ /**
2
+ * 示例门控脚本:结构对齐本 skill 主 SKILL.md 与 embedded-template;API 对齐 references/agentic-lab-sdk.md
3
+ * 输入输出类型对齐 references/agentic-lab-processer.md(参数与返回值均为 snake_case)。
4
+ * 业务规则以用户提供的流程说明 Markdown 为准(「数据查询方式」「字段映射」「数据处理规则」等)。
5
+ *
6
+ * 门控执行顺序:前置处理(start) → 人工处理(页面) → 后置处理(complete)
7
+ *
8
+ * 列表类查询:流程说明未要求分页时,显式 limit/offset(见主 SKILL「门控脚本编写指引 → 分页与查全量」)。
9
+ *
10
+ * 类型安全:ticket.detail 值为任意 JSON 类型(string/number/null/array/object),
11
+ * 禁止直接调 .trim()/.split() 等 String 方法——须先 String() 转换(见「编写指引 §5」)。
12
+ */
13
+
14
+ // --- Artifact Version ---
15
+ const __ARTIFACT_VERSION__ = '1.0.0';
16
+ const __ARTIFACT_SKILL__ = 'lab-flow-designer';
17
+
18
+ const DEFAULT_QUERY_LIMIT = 999999;
19
+
20
+ // orbit_link 由流程文档门控脚本配置项中的 PageUrl 与门控前置处理中的 bookid 组合生成
21
+ const PAGE_URL = 'http://10.249.133.129:9048/?view=book&book={bookid}';
22
+ const BOOK_ID = '1';
23
+
24
+ // --- 类型安全辅助函数(detail 值可为任意 JSON 类型,须先转换再操作)---
25
+ function str(v) {
26
+ return v != null ? String(v) : '';
27
+ }
28
+ function num(v, fallback) {
29
+ const n = Number(v);
30
+ return Number.isFinite(n) ? n : (fallback !== undefined ? fallback : 0);
31
+ }
32
+
33
+ class Processer {
34
+ constructor(context) {
35
+ this.context = context;
36
+ console.info(`[Processer] v${__ARTIFACT_VERSION__} (skill: ${__ARTIFACT_SKILL__})`);
37
+ }
38
+
39
+ // --- 前置处理 → start ---
40
+ // params: { valve_id, pool_ids }
41
+ // returns: { orbit_link, ticket_ids }
42
+ async start(params) {
43
+ const { valve_id, pool_ids } = params;
44
+ const { list: tickets } = await this.context.ticket.list({
45
+ pool_id__in: pool_ids,
46
+ limit: DEFAULT_QUERY_LIMIT,
47
+ offset: 0,
48
+ });
49
+
50
+ const compoundIdList = [
51
+ ...new Set(
52
+ tickets
53
+ .map((t) => t.detail?.cmpd_id || t.detail?.compound_id)
54
+ .filter(Boolean)
55
+ ),
56
+ ];
57
+
58
+ let stockRecords = [];
59
+ if (compoundIdList.length > 0) {
60
+ const filter = { 'cas.$in': compoundIdList };
61
+ const stockResponse = await this.context.compound.getStockFromXfcSh({
62
+ filter,
63
+ });
64
+ stockRecords = stockResponse.data || [];
65
+ }
66
+
67
+ const stations = await this.context.station.list();
68
+ const processIds = tickets
69
+ .flatMap((t) => t.detail?.process_ids || [])
70
+ .filter(Boolean);
71
+ const processes =
72
+ processIds.length > 0
73
+ ? await this.context.process.list({
74
+ processIds,
75
+ limit: DEFAULT_QUERY_LIMIT,
76
+ offset: 0,
77
+ })
78
+ : [];
79
+
80
+ // --- 规则 1.1~1.4:按 valves/示例数据与校验门控.md「数据处理规则」写回 detail(以下为示意)---
81
+ for (const ticket of tickets) {
82
+ const d = ticket.detail || {};
83
+ const stock = stockRecords.filter((r) => str(r.cas) === str(d.cmpd_id));
84
+
85
+ if (stock.length) {
86
+ d.available_amount_mg = stock.reduce(
87
+ (s, r) => s + num(r.latest_amount_mg, 0),
88
+ 0
89
+ );
90
+ }
91
+ d._stations_count = stations.length;
92
+ d._processes_preview = processes;
93
+ ticket.detail = d;
94
+ }
95
+
96
+ await this.context.ticket.update(tickets);
97
+
98
+ const orbit_link = PAGE_URL.replace('{bookid}', BOOK_ID);
99
+
100
+ return {
101
+ orbit_link,
102
+ ticket_ids: tickets.map((t) => t.id),
103
+ };
104
+ }
105
+
106
+ // --- 后置处理 → complete ---
107
+ // params: { valve_id, tickets }
108
+ // returns: { new_tickets }
109
+ async complete(params) {
110
+ const { valve_id, tickets } = params;
111
+
112
+ const nextPools = await this.context.pool.getNext(valve_id);
113
+ const outPool = nextPools.find((p) => p.name === '出口池');
114
+
115
+ if (!outPool) {
116
+ throw new Error(
117
+ `未找到出口池;nextPools=${nextPools.map((p) => p.name).join(',')}`
118
+ );
119
+ }
120
+
121
+ // 将入口池的tickets更新为”已完成”状态,避免重复处理
122
+ const finished = tickets.map((t) => ({
123
+ ...t,
124
+ status: 'finished',
125
+ }));
126
+ await this.context.ticket.update(finished);
127
+
128
+ // 按出口池 schema 映射为新 tickets,由引擎自动创建(不在脚本内调用 ticket.append)
129
+ const new_tickets = finished.map((t) => ({
130
+ flow_id: t.flow_id,
131
+ pool_id: outPool.id,
132
+ order_id: t.order_id,
133
+ detail: t.detail,
134
+ status: 'created',
135
+ parent_ticket_id: t.id,
136
+ }));
137
+
138
+ return {
139
+ new_tickets,
140
+ };
141
+ }
142
+ }