gz-laya-pilot 0.1.0 → 0.1.2

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 (95) hide show
  1. package/NOTICE.md +20 -2
  2. package/README.md +54 -2
  3. package/dist/agent/bridge.d.ts +21 -0
  4. package/dist/agent/bridge.js +158 -0
  5. package/dist/agent/bridge.js.map +1 -0
  6. package/dist/agent/report.d.ts +54 -0
  7. package/dist/agent/report.js +100 -0
  8. package/dist/agent/report.js.map +1 -0
  9. package/dist/agent/run.d.ts +19 -0
  10. package/dist/agent/run.js +121 -0
  11. package/dist/agent/run.js.map +1 -0
  12. package/dist/agent/schema.d.ts +42 -0
  13. package/dist/agent/schema.js +9 -0
  14. package/dist/agent/schema.js.map +1 -0
  15. package/dist/agent/worker.d.ts +1 -0
  16. package/dist/agent/worker.js +102 -0
  17. package/dist/agent/worker.js.map +1 -0
  18. package/dist/cli.d.ts +2 -0
  19. package/dist/cli.js +7 -0
  20. package/dist/cli.js.map +1 -0
  21. package/dist/index.d.ts +3 -0
  22. package/dist/index.js +2 -0
  23. package/dist/index.js.map +1 -1
  24. package/package.json +14 -6
  25. package/src/agent/bridge.ts +180 -0
  26. package/src/agent/report.ts +139 -0
  27. package/src/agent/run.ts +136 -0
  28. package/src/agent/schema.ts +38 -0
  29. package/src/agent/worker.ts +114 -0
  30. package/src/cli.ts +5 -0
  31. package/src/index.ts +3 -0
  32. package/vendor/.gitattributes +5 -0
  33. package/vendor/UPSTREAM.json +168 -0
  34. package/vendor/laya-pilot/LICENSE +21 -0
  35. package/vendor/laya-pilot/README.en.md +116 -0
  36. package/vendor/laya-pilot/README.md +116 -0
  37. package/vendor/laya-pilot/ROADMAP.md +21 -0
  38. package/vendor/laya-pilot/config.example.json +14 -0
  39. package/vendor/laya-pilot/docs/architecture.md +21 -0
  40. package/vendor/laya-pilot/docs/browser-use-evaluation.md +32 -0
  41. package/vendor/laya-pilot/docs/demo.png +0 -0
  42. package/vendor/laya-pilot/docs/local-runtime.md +88 -0
  43. package/vendor/laya-pilot/docs/pr1-selection.md +33 -0
  44. package/vendor/laya-pilot/docs/retry-policy.md +14 -0
  45. package/vendor/laya-pilot/examples/demo-cases.xlsx +0 -0
  46. package/vendor/laya-pilot/examples/demo-server.mjs +19 -0
  47. package/vendor/laya-pilot/examples/demo.html +733 -0
  48. package/vendor/laya-pilot/lib/auth-state.mjs +141 -0
  49. package/vendor/laya-pilot/lib/browser-provider.mjs +43 -0
  50. package/vendor/laya-pilot/lib/diagnostics.mjs +210 -0
  51. package/vendor/laya-pilot/lib/discovery.mjs +474 -0
  52. package/vendor/laya-pilot/lib/dom.mjs +539 -0
  53. package/vendor/laya-pilot/lib/engine.mjs +879 -0
  54. package/vendor/laya-pilot/lib/form.mjs +377 -0
  55. package/vendor/laya-pilot/lib/language.mjs +273 -0
  56. package/vendor/laya-pilot/lib/model.mjs +271 -0
  57. package/vendor/laya-pilot/lib/page-capabilities.mjs +356 -0
  58. package/vendor/laya-pilot/lib/page-exploration.mjs +372 -0
  59. package/vendor/laya-pilot/lib/page-session.mjs +69 -0
  60. package/vendor/laya-pilot/lib/pending-writes.mjs +50 -0
  61. package/vendor/laya-pilot/lib/planner.mjs +127 -0
  62. package/vendor/laya-pilot/lib/project-config.mjs +95 -0
  63. package/vendor/laya-pilot/lib/readiness.mjs +179 -0
  64. package/vendor/laya-pilot/lib/related-records.mjs +328 -0
  65. package/vendor/laya-pilot/lib/replay-model.mjs +44 -0
  66. package/vendor/laya-pilot/lib/run-state.mjs +133 -0
  67. package/vendor/laya-pilot/lib/test-data.mjs +128 -0
  68. package/vendor/laya-pilot/lib/workflow-policy.mjs +68 -0
  69. package/vendor/laya-pilot/lib/workflow.mjs +2321 -0
  70. package/vendor/laya-pilot/lib/workflow_excel.py +462 -0
  71. package/vendor/laya-pilot/requirements-local.txt +2 -0
  72. package/vendor/laya-pilot/requirements.txt +1 -0
  73. package/vendor/laya-pilot/runner.mjs +452 -0
  74. package/vendor/laya-pilot/tests/api.test.mjs +98 -0
  75. package/vendor/laya-pilot/tests/browser/runtime.test.mjs +847 -0
  76. package/vendor/laya-pilot/tests/config.test.mjs +109 -0
  77. package/vendor/laya-pilot/tests/diagnostics.test.mjs +91 -0
  78. package/vendor/laya-pilot/tests/discovery.test.mjs +76 -0
  79. package/vendor/laya-pilot/tests/fixtures/local-model/laya.py +28 -0
  80. package/vendor/laya-pilot/tests/fixtures/local-model/torch.py +5 -0
  81. package/vendor/laya-pilot/tests/guards.test.mjs +43 -0
  82. package/vendor/laya-pilot/tests/language.test.mjs +39 -0
  83. package/vendor/laya-pilot/tests/planner.test.mjs +129 -0
  84. package/vendor/laya-pilot/tests/readiness.test.mjs +118 -0
  85. package/vendor/laya-pilot/tests/real-model.smoke.mjs +74 -0
  86. package/vendor/laya-pilot/tests/replay-model.test.mjs +90 -0
  87. package/vendor/laya-pilot/tests/retries.test.mjs +270 -0
  88. package/vendor/laya-pilot/tests/run-state.test.mjs +162 -0
  89. package/vendor/laya-pilot/tests/selected-pr1.test.mjs +309 -0
  90. package/vendor/laya-pilot/tests/test-data.test.mjs +83 -0
  91. package/vendor/laya-pilot/tests/test_workflow_excel.py +162 -0
  92. package/vendor/laya-pilot/tests/worker_test.py +33 -0
  93. package/vendor/laya-pilot/tests/workflow.test.mjs +98 -0
  94. package/vendor/laya-pilot/worker.py +135 -0
  95. package/vendor/patches/0001-native-field-recipes.patch +3009 -0
@@ -0,0 +1,135 @@
1
+ """Offline typed Laya decisions and read-only Excel import. No per-module recipes."""
2
+
3
+ import os, sys, json, time, contextlib, re
4
+
5
+ os.environ.setdefault('USE_TF', '0')
6
+ os.environ.setdefault('TOKENIZERS_PARALLELISM', 'false')
7
+ ALIASES = {
8
+ 'id': ['测试编号', '用例编号', '编号', 'caseid', 'id'],
9
+ 'title': ['测试用例名称', '测试用例', '用例名称', '标题', 'title', 'name', 'testcase'],
10
+ 'steps': ['测试步骤', '操作步骤', '步骤', 'steps', 'teststeps'],
11
+ 'expected': ['预期结果', '期望结果', '预期', 'expected', 'expectedresult'],
12
+ 'preconditions': ['前提条件', '前置条件', '前提', 'preconditions'],
13
+ 'data': ['测试数据', '数据', 'testdata', 'data'],
14
+ 'url': ['页面地址', '网址', 'url', 'pageurl'],
15
+ 'source_result': [
16
+ '实际执行结果',
17
+ '实际结果',
18
+ '测试结果',
19
+ 'actualresult',
20
+ 'testresult',
21
+ 'result',
22
+ ],
23
+ }
24
+
25
+
26
+ def normalize(s):
27
+ return re.sub(r'[\s_\-]', '', str(s or '')).lower()
28
+
29
+
30
+ def read_excel(filename):
31
+ from openpyxl import load_workbook
32
+
33
+ wb = load_workbook(filename, read_only=True, data_only=False)
34
+ cases = []
35
+ warnings = []
36
+ for sheet in wb:
37
+ mapping = None
38
+ for rowno, row in enumerate(sheet.iter_rows(), 1):
39
+ vals = [str(c.value if c.value is not None else '') for c in row]
40
+ if mapping is None:
41
+ names = [normalize(v) for v in vals]
42
+ found = {
43
+ key: next((i for i, n in enumerate(names) if n in synonyms), None)
44
+ for key, synonyms in ALIASES.items()
45
+ }
46
+ if found['steps'] is not None and found['expected'] is not None:
47
+ mapping = found
48
+ continue
49
+ if rowno >= 15:
50
+ break
51
+ continue
52
+ get = lambda key: (
53
+ vals[mapping[key]]
54
+ if mapping.get(key) is not None and mapping[key] < len(vals)
55
+ else ''
56
+ )
57
+ if not any(v.strip() for v in vals):
58
+ continue
59
+ if not get('steps') and not get('expected'):
60
+ continue
61
+ cid = get('id') or f'{sheet.title}-{rowno}'
62
+ if cid.isdigit():
63
+ cid = cid.zfill(3)
64
+ formulas = [
65
+ row[i].coordinate
66
+ for i in mapping.values()
67
+ if i is not None and i < len(row) and row[i].data_type == 'f'
68
+ ]
69
+ item = {
70
+ **{key: get(key) for key in ALIASES},
71
+ 'id': cid,
72
+ 'sheet': sheet.title,
73
+ 'row': rowno,
74
+ 'key': f'{sheet.title}:{rowno}',
75
+ 'import_error': ('执行列含公式,需提供明确文本:' + ','.join(formulas))
76
+ if formulas
77
+ else '',
78
+ }
79
+ # Common merged-ID layout: blank ID/title rows continue the preceding case.
80
+ if not get('id') and not get('title') and cases and cases[-1]['sheet'] == sheet.title:
81
+ for key in ('steps', 'expected', 'preconditions', 'data', 'import_error'):
82
+ if item[key]:
83
+ cases[-1][key] += ('\n' if cases[-1][key] else '') + item[key]
84
+ else:
85
+ cases.append(item)
86
+ if mapping is None:
87
+ warnings.append(f'{sheet.title}:前15行找不到步骤与预期结果表头,未读取')
88
+ wb.close()
89
+ return {'cases': cases, 'warnings': warnings}
90
+
91
+
92
+ agent = None
93
+ for line in sys.stdin:
94
+ req = {}
95
+ try:
96
+ req = json.loads(line)
97
+ if req['action'] == 'read_excel':
98
+ result = read_excel(req['path'])
99
+ else:
100
+ if agent is None:
101
+ start = time.perf_counter()
102
+ with contextlib.redirect_stdout(sys.stderr):
103
+ import laya, torch
104
+
105
+ torch.set_num_threads(4)
106
+ agent = laya.load(req['model'], device='cpu')
107
+ load_ms = round((time.perf_counter() - start) * 1000, 2)
108
+ if req['action'] == 'load':
109
+ result = {'load_ms': load_ms, 'device': 'cpu'}
110
+ elif req['action'] == 'decide':
111
+ if not 2 <= len(req['criteria']) <= 8:
112
+ raise ValueError('每次选择必须有2至8个候选,包括无法判断选项')
113
+ start = time.perf_counter()
114
+ with contextlib.redirect_stdout(sys.stderr):
115
+ answer = agent.predict(
116
+ req['state'],
117
+ {
118
+ 'scenario': {
119
+ 'type': 'choice',
120
+ 'instructions': '用户请求对应哪个操作?',
121
+ 'criteria': req['criteria'],
122
+ }
123
+ },
124
+ )['answers']['scenario']
125
+ result = {**answer, 'inference_ms': round((time.perf_counter() - start) * 1000, 2)}
126
+ else:
127
+ raise ValueError('不支持的请求')
128
+ print(json.dumps({'id': req['id'], **result}, ensure_ascii=False), flush=True)
129
+ except Exception as e:
130
+ print(
131
+ json.dumps(
132
+ {'id': req.get('id'), 'error': f'{type(e).__name__}: {e}'}, ensure_ascii=False
133
+ ),
134
+ flush=True,
135
+ )