@dazitech/cli 3.0.6 → 3.0.8

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 (76) hide show
  1. package/README.md +1 -1
  2. package/dist/clis/dazi-app.js +1 -1
  3. package/dist/clis/dazi-flow.js +43 -24
  4. package/dist/clis/dazi-onto.js +73 -22
  5. package/dist/clis/dazi.js +266 -171
  6. package/dist/docs/flow/ai-workflow-playbook.md +4 -2
  7. package/dist/docs/flow/flow-project-guide.md +9 -5
  8. package/dist/docs/flow/flows-guide.md +2 -2
  9. package/dist/docs/flow/node-code-guide.md +408 -401
  10. package/dist/docs/flow/run-guide.md +13 -6
  11. package/dist/docs/flow/variables-guide.md +407 -406
  12. package/dist/docs/guides/quickstart.md +18 -4
  13. package/dist/docs/guides/troubleshooting.md +1 -1
  14. package/dist/docs/guides/workspace-v3.md +43 -23
  15. package/dist/docs/index.json +9 -3
  16. package/dist/docs/onto/action-guide.md +3 -3
  17. package/dist/docs/onto/dazi_script_sdk_reference.md +178 -174
  18. package/dist/docs/onto/dazi_script_seed_data_guide.md +158 -155
  19. package/dist/docs/onto/function-guide.md +37 -10
  20. package/dist/docs/onto/space-management.md +3 -1
  21. package/dist/docs/onto//346/234/254/344/275/223/350/204/232/346/234/254/347/274/226/345/206/231/346/214/207/345/215/227.md +138 -34
  22. package/dist/docs/onto//346/234/254/344/275/223/350/247/204/345/210/222/346/214/207/345/215/227.md +73 -31
  23. package/dist/docs/onto//350/247/204/345/210/222/347/244/272/344/276/213_/344/272/247/345/223/201/351/224/200/345/224/256/346/234/254/344/275/223/350/247/204/345/210/222/346/226/271/346/241/210.md +497 -0
  24. package/dist/docs/onto//350/247/204/345/210/222/347/244/272/344/276/213_/345/210/251/346/266/246/345/210/206/346/236/220/346/234/254/344/275/223/346/226/271/346/241/210.md +597 -541
  25. package/dist/examples/index.json +202 -22
  26. package/dist/examples/onto/README.md +43 -0
  27. package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/function/profit_fn_account_breakdown.py +99 -0
  28. package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/function/profit_fn_budget_vs_actual.py +116 -0
  29. package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/function/profit_fn_cost_center_profit.py +85 -0
  30. package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/function/profit_fn_get_summary.py +76 -0
  31. package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/function/profit_fn_mom_analysis.py +86 -0
  32. package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/function/profit_fn_top_accounts.py +103 -0
  33. package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/function/profit_fn_yoy_analysis.py +86 -0
  34. package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/function/save_test_arguments.ps1 +27 -0
  35. package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/function/test_arguments/profit.fn.account_breakdown.json +10 -0
  36. package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/function/test_arguments/profit.fn.budget_vs_actual.json +10 -0
  37. package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/function/test_arguments/profit.fn.cost_center_profit.json +9 -0
  38. package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/function/test_arguments/profit.fn.get_summary.json +9 -0
  39. package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/function/test_arguments/profit.fn.mom_analysis.json +9 -0
  40. package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/function/test_arguments/profit.fn.top_accounts.json +11 -0
  41. package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/function/test_arguments/profit.fn.yoy_analysis.json +9 -0
  42. package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/setup/profit_ontology_init.py +521 -0
  43. package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/setup/profit_seed_data.py +213 -0
  44. package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/README.md +25 -0
  45. package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/sales_fn_channel_mix.py +86 -0
  46. package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/sales_fn_customer_segmentation.py +123 -0
  47. package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/sales_fn_get_summary.py +81 -0
  48. package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/sales_fn_mom_analysis.py +90 -0
  49. package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/sales_fn_region_breakdown.py +85 -0
  50. package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/sales_fn_top_products.py +101 -0
  51. package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/sales_fn_yoy_analysis.py +90 -0
  52. package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/save_test_arguments.ps1 +25 -0
  53. package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/test_arguments/sales.fn.channel_mix.json +8 -0
  54. package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/test_arguments/sales.fn.customer_segmentation.json +10 -0
  55. package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/test_arguments/sales.fn.get_summary.json +8 -0
  56. package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/test_arguments/sales.fn.mom_analysis.json +8 -0
  57. package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/test_arguments/sales.fn.region_breakdown.json +8 -0
  58. package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/test_arguments/sales.fn.top_products.json +10 -0
  59. package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/test_arguments/sales.fn.yoy_analysis.json +8 -0
  60. package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/setup/README.md +5 -0
  61. package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/setup/sales_ontology_init.py +403 -0
  62. package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/setup/sales_seed_data.py +124 -0
  63. package/dist/prompts/flow/ai-workflow-playbook.md +4 -2
  64. package/dist/prompts/flow/flow-design.md +12 -9
  65. package/dist/prompts/flow/run-fix-loop.md +37 -22
  66. package/dist/prompts/index.json +2 -2
  67. package/dist/prompts/onto/action-design.md +4 -1
  68. package/dist/prompts/onto/function-design.md +9 -2
  69. package/dist/prompts/onto/rule-seed.md +5 -1
  70. package/dist/prompts/onto/script-publish-run.md +72 -24
  71. package/package.json +1 -1
  72. package/dist/examples/onto/function/profit_fn_customer_segmentation.py +0 -117
  73. package/dist/examples/onto/function/profit_fn_mom_analysis.py +0 -89
  74. package/dist/examples/onto/function/profit_fn_top_products.py +0 -89
  75. package/dist/examples/onto/function/profit_fn_yoy_analysis.py +0 -89
  76. package/dist/examples/onto/setup/profit_ontology_init.py +0 -388
@@ -0,0 +1,85 @@
1
+ """区域销售分布 sales.fn.region_breakdown
2
+
3
+ 参数:start_date, end_date
4
+ 返回:各区域销售额、销量、订单数及占比
5
+
6
+ 发布:
7
+ dazi onto script publish 项目/潘达石化/本体/ontos/产品销售本体方案/functions/sales_fn_region_breakdown.py \\
8
+ --space space__zlj --register-function-id sales.fn.region_breakdown
9
+
10
+ 保存测试参数(function run 验证通过后;侧栏「运行函数」预填):
11
+ 见 functions/README.md;推荐 save_test_arguments.ps1(CLI 须 ofn_xxx 内部 id,勿直接用 function_id)
12
+ """
13
+
14
+ TEST_ARGUMENTS = {
15
+ "v": 1,
16
+ "arguments": {"start_date": "2025-01-01", "end_date": "2026-06-30"},
17
+ "object_type_code": "SalesAnalysis",
18
+ }
19
+
20
+
21
+ def _build_where(start_date, end_date):
22
+ clauses = ["order_status IN ('已完成', '已发货')"]
23
+ if start_date and end_date:
24
+ clauses.append(f"order_date >= '{start_date}' AND order_date <= '{end_date}'")
25
+ return "WHERE " + " AND ".join(clauses)
26
+
27
+
28
+ def _ontology_fn_body(p):
29
+ params = dict(p.get_params() or {})
30
+ start_date = params.get("start_date", "")
31
+ end_date = params.get("end_date", "")
32
+ where_clause = _build_where(start_date, end_date)
33
+
34
+ sql = f"""
35
+ SELECT
36
+ customer_region,
37
+ sum(sales_amount) AS sales_amount,
38
+ sum(quantity) AS quantity,
39
+ uniq(order_id) AS order_count
40
+ FROM sales_order_fact
41
+ {where_clause}
42
+ GROUP BY customer_region
43
+ ORDER BY sales_amount DESC
44
+ """
45
+
46
+ result = p.sql.query(sql)
47
+ if not result:
48
+ return p.function_result(
49
+ columns=["customer_region", "sales_amount", "quantity", "order_count", "share_pct"],
50
+ data=[],
51
+ row_count=0,
52
+ )
53
+
54
+ total = sum(float(r.get("sales_amount", 0) or 0) for r in result)
55
+ data = []
56
+ for row in result:
57
+ sales_amount = float(row.get("sales_amount", 0) or 0)
58
+ data.append({
59
+ "customer_region": str(row.get("customer_region", "")),
60
+ "sales_amount": round(sales_amount, 2),
61
+ "quantity": int(row.get("quantity", 0) or 0),
62
+ "order_count": int(row.get("order_count", 0) or 0),
63
+ "share_pct": round(sales_amount / total if total > 0 else 0.0, 4),
64
+ })
65
+
66
+ return p.function_result(
67
+ columns=["customer_region", "sales_amount", "quantity", "order_count", "share_pct"],
68
+ data=data,
69
+ row_count=len(data),
70
+ )
71
+
72
+
73
+ def main():
74
+ s = space.get(ctx.space_id or "")
75
+ _Ports = type(
76
+ "_Ports",
77
+ (),
78
+ {
79
+ "get_params": lambda self: dict(ctx.params or {}),
80
+ "function_result": lambda self, **kw: onto.function_result(**kw),
81
+ },
82
+ )
83
+ p = _Ports()
84
+ p.sql = s.sql
85
+ return _ontology_fn_body(p)
@@ -0,0 +1,101 @@
1
+ """产品销量/销售额排行 sales.fn.top_products
2
+
3
+ 参数:limit, metric(sales_amount|quantity), start_date, end_date
4
+ 返回:产品排行及销售占比
5
+
6
+ 发布:
7
+ dazi onto script publish 项目/潘达石化/本体/ontos/产品销售本体方案/functions/sales_fn_top_products.py \\
8
+ --space space__zlj --register-function-id sales.fn.top_products
9
+
10
+ 保存测试参数(function run 验证通过后;侧栏「运行函数」预填):
11
+ 见 functions/README.md;推荐 save_test_arguments.ps1(CLI 须 ofn_xxx 内部 id,勿直接用 function_id)
12
+ """
13
+
14
+ TEST_ARGUMENTS = {
15
+ "v": 1,
16
+ "arguments": {
17
+ "limit": 5,
18
+ "metric": "sales_amount",
19
+ "start_date": "2025-01-01",
20
+ "end_date": "2026-06-30",
21
+ },
22
+ "object_type_code": "Product",
23
+ }
24
+
25
+
26
+ def _build_where(start_date, end_date):
27
+ clauses = ["f.order_status IN ('已完成', '已发货')"]
28
+ if start_date and end_date:
29
+ clauses.append(f"f.order_date >= '{start_date}' AND f.order_date <= '{end_date}'")
30
+ return "WHERE " + " AND ".join(clauses)
31
+
32
+
33
+ def _ontology_fn_body(p):
34
+ params = dict(p.get_params() or {})
35
+ limit = int(params.get("limit", 10) or 10)
36
+ metric = params.get("metric", "sales_amount")
37
+ start_date = params.get("start_date", "")
38
+ end_date = params.get("end_date", "")
39
+ where_clause = _build_where(start_date, end_date)
40
+ order_by = "quantity DESC" if metric == "quantity" else "sales_amount DESC"
41
+
42
+ sql = f"""
43
+ SELECT
44
+ f.product_id,
45
+ any(pm.product_name) AS product_name,
46
+ f.product_category,
47
+ sum(f.sales_amount) AS sales_amount,
48
+ sum(f.quantity) AS quantity
49
+ FROM sales_order_fact AS f
50
+ LEFT JOIN product_master AS pm ON f.product_id = pm.product_id
51
+ {where_clause}
52
+ GROUP BY f.product_id, f.product_category
53
+ ORDER BY {order_by}
54
+ LIMIT {limit}
55
+ """
56
+
57
+ result = p.sql.query(sql)
58
+ if not result:
59
+ return p.function_result(
60
+ columns=["rank", "product_id", "product_name", "product_category", "sales_amount", "quantity", "share_pct"],
61
+ data=[],
62
+ row_count=0,
63
+ )
64
+
65
+ total_key = "quantity" if metric == "quantity" else "sales_amount"
66
+ total = sum(float(r.get(total_key, 0) or 0) for r in result)
67
+
68
+ data = []
69
+ for rank, row in enumerate(result, start=1):
70
+ val = float(row.get(total_key, 0) or 0)
71
+ share_pct = val / total if total > 0 else 0.0
72
+ data.append({
73
+ "rank": rank,
74
+ "product_id": str(row.get("product_id", "")),
75
+ "product_name": str(row.get("product_name", "")),
76
+ "product_category": str(row.get("product_category", "")),
77
+ "sales_amount": round(float(row.get("sales_amount", 0) or 0), 2),
78
+ "quantity": int(row.get("quantity", 0) or 0),
79
+ "share_pct": round(share_pct, 4),
80
+ })
81
+
82
+ return p.function_result(
83
+ columns=["rank", "product_id", "product_name", "product_category", "sales_amount", "quantity", "share_pct"],
84
+ data=data,
85
+ row_count=len(data),
86
+ )
87
+
88
+
89
+ def main():
90
+ s = space.get(ctx.space_id or "")
91
+ _Ports = type(
92
+ "_Ports",
93
+ (),
94
+ {
95
+ "get_params": lambda self: dict(ctx.params or {}),
96
+ "function_result": lambda self, **kw: onto.function_result(**kw),
97
+ },
98
+ )
99
+ p = _Ports()
100
+ p.sql = s.sql
101
+ return _ontology_fn_body(p)
@@ -0,0 +1,90 @@
1
+ """年度同比分析 sales.fn.yoy_analysis
2
+
3
+ 参数:start_date, end_date
4
+ 返回:年度销售额、销量、订单数及同比增长率
5
+
6
+ 发布:
7
+ dazi onto script publish 项目/潘达石化/本体/ontos/产品销售本体方案/functions/sales_fn_yoy_analysis.py \\
8
+ --space space__zlj --register-function-id sales.fn.yoy_analysis
9
+
10
+ 保存测试参数(function run 验证通过后;侧栏「运行函数」预填):
11
+ 见 functions/README.md;推荐 save_test_arguments.ps1(CLI 须 ofn_xxx 内部 id,勿直接用 function_id)
12
+ """
13
+
14
+ TEST_ARGUMENTS = {
15
+ "v": 1,
16
+ "arguments": {"start_date": "2025-01-01", "end_date": "2026-06-30"},
17
+ "object_type_code": "SalesAnalysis",
18
+ }
19
+
20
+
21
+ def _build_where(start_date, end_date):
22
+ clauses = ["order_status IN ('已完成', '已发货')"]
23
+ if start_date and end_date:
24
+ clauses.append(f"order_date >= '{start_date}' AND order_date <= '{end_date}'")
25
+ return "WHERE " + " AND ".join(clauses)
26
+
27
+
28
+ def _ontology_fn_body(p):
29
+ params = dict(p.get_params() or {})
30
+ start_date = params.get("start_date", "")
31
+ end_date = params.get("end_date", "")
32
+ where_clause = _build_where(start_date, end_date)
33
+
34
+ sql = f"""
35
+ SELECT
36
+ toYear(order_date) AS year,
37
+ sum(sales_amount) AS sales_amount,
38
+ sum(quantity) AS quantity,
39
+ uniq(order_id) AS order_count
40
+ FROM sales_order_fact
41
+ {where_clause}
42
+ GROUP BY toYear(order_date)
43
+ ORDER BY year
44
+ """
45
+
46
+ result = p.sql.query(sql)
47
+ if not result:
48
+ return p.function_result(
49
+ columns=["year", "sales_amount", "quantity", "order_count", "yoy_growth"],
50
+ data=[],
51
+ row_count=0,
52
+ )
53
+
54
+ data = []
55
+ prev_sales = None
56
+ for row in result:
57
+ sales_amount = float(row.get("sales_amount", 0) or 0)
58
+ if prev_sales is not None and prev_sales != 0:
59
+ yoy_growth = (sales_amount - prev_sales) / prev_sales
60
+ else:
61
+ yoy_growth = 0.0
62
+ data.append({
63
+ "year": int(row.get("year", 0)),
64
+ "sales_amount": round(sales_amount, 2),
65
+ "quantity": int(row.get("quantity", 0) or 0),
66
+ "order_count": int(row.get("order_count", 0) or 0),
67
+ "yoy_growth": round(yoy_growth, 4),
68
+ })
69
+ prev_sales = sales_amount
70
+
71
+ return p.function_result(
72
+ columns=["year", "sales_amount", "quantity", "order_count", "yoy_growth"],
73
+ data=data,
74
+ row_count=len(data),
75
+ )
76
+
77
+
78
+ def main():
79
+ s = space.get(ctx.space_id or "")
80
+ _Ports = type(
81
+ "_Ports",
82
+ (),
83
+ {
84
+ "get_params": lambda self: dict(ctx.params or {}),
85
+ "function_result": lambda self, **kw: onto.function_result(**kw),
86
+ },
87
+ )
88
+ p = _Ports()
89
+ p.sql = s.sql
90
+ return _ontology_fn_body(p)
@@ -0,0 +1,25 @@
1
+ # 批量保存函数 test_arguments 到平台(space__zlj)
2
+ # 用法:在 dazi-work 根目录执行 .\项目\潘达石化\本体\ontos\产品销售本体方案\functions\save_test_arguments.ps1
3
+
4
+ $ErrorActionPreference = "Stop"
5
+ $space = "space__zlj"
6
+ $base = "项目/潘达石化/本体/ontos/产品销售本体方案/functions/test_arguments"
7
+
8
+ $raw = dazi onto function list --space $space 2>&1 | Out-String
9
+ $jsonPart = ($raw -split '__JSON_SUMMARY__')[-1].Trim()
10
+ $data = $jsonPart | ConvertFrom-Json
11
+
12
+ foreach ($fn in $data.data.functions) {
13
+ $fid = $fn.function_id
14
+ $ofn = $fn.id
15
+ $file = Join-Path $base "$fid.json"
16
+ if (-not (Test-Path $file)) {
17
+ Write-Host "SKIP 无 JSON: $fid"
18
+ continue
19
+ }
20
+ Write-Host "save $fid ..."
21
+ # 注意:CLI 须用平台内部 id(ofn_xxx),不能用 function_id 字符串
22
+ dazi onto function save-test-arguments $ofn --space $space --arguments-json-file $file
23
+ }
24
+
25
+ Write-Host "完成。"
@@ -0,0 +1,8 @@
1
+ {
2
+ "v": 1,
3
+ "arguments": {
4
+ "start_date": "2025-01-01",
5
+ "end_date": "2026-06-30"
6
+ },
7
+ "object_type_code": "SalesChannel"
8
+ }
@@ -0,0 +1,10 @@
1
+ {
2
+ "v": 1,
3
+ "arguments": {
4
+ "metric": "sales_amount",
5
+ "method": "quartile",
6
+ "start_date": "2025-01-01",
7
+ "end_date": "2026-06-30"
8
+ },
9
+ "object_type_code": "Customer"
10
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "v": 1,
3
+ "arguments": {
4
+ "start_date": "2025-01-01",
5
+ "end_date": "2026-06-30"
6
+ },
7
+ "object_type_code": "SalesAnalysis"
8
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "v": 1,
3
+ "arguments": {
4
+ "start_date": "2025-01-01",
5
+ "end_date": "2026-06-30"
6
+ },
7
+ "object_type_code": "SalesAnalysis"
8
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "v": 1,
3
+ "arguments": {
4
+ "start_date": "2025-01-01",
5
+ "end_date": "2026-06-30"
6
+ },
7
+ "object_type_code": "SalesAnalysis"
8
+ }
@@ -0,0 +1,10 @@
1
+ {
2
+ "v": 1,
3
+ "arguments": {
4
+ "limit": 5,
5
+ "metric": "sales_amount",
6
+ "start_date": "2025-01-01",
7
+ "end_date": "2026-06-30"
8
+ },
9
+ "object_type_code": "Product"
10
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "v": 1,
3
+ "arguments": {
4
+ "start_date": "2025-01-01",
5
+ "end_date": "2026-06-30"
6
+ },
7
+ "object_type_code": "SalesAnalysis"
8
+ }
@@ -0,0 +1,5 @@
1
+ # setup
2
+
3
+ 初始化(`ontology_init`)与灌数(`seed`)脚本。
4
+
5
+ 发布示例:`dazi onto script publish 项目/<业务>/本体/ontos/<实现名>/setup/<file>.py --space <space_id> --type setup|data`