auto-coder 0.1.325__py3-none-any.whl → 0.1.327__py3-none-any.whl

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.

Potentially problematic release.


This version of auto-coder might be problematic. Click here for more details.

@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: auto-coder
3
- Version: 0.1.325
3
+ Version: 0.1.327
4
4
  Summary: AutoCoder: AutoCoder
5
5
  Author: allwefantasy
6
6
  Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
@@ -14,7 +14,7 @@ autocoder/command_parser.py,sha256=fx1g9E6GaM273lGTcJqaFQ-hoksS_Ik2glBMnVltPCE,1
14
14
  autocoder/lang.py,sha256=U6AjVV8Rs1uLyjFCZ8sT6WWuNUxMBqkXXIOs4S120uk,14511
15
15
  autocoder/models.py,sha256=AyoZ-Pzy0oyYUmWCxOIRiOImsqboSfRET7LO9-UOuxI,11172
16
16
  autocoder/run_context.py,sha256=IUfSO6_gp2Wt1blFWAmOpN0b0nDrTTk4LmtCYUBIoro,1643
17
- autocoder/version.py,sha256=TxojfQzNkFOvmUKL-Ubl0Ef5fbfT55MT6Y10DbUHCPI,23
17
+ autocoder/version.py,sha256=miEiKBcN07ycv510z1gvZ9J70UiJ9CPTI0zhuZXmYxg,23
18
18
  autocoder/agent/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
19
19
  autocoder/agent/auto_demand_organizer.py,sha256=URAq0gSEiHeV_W4zwhOI_83kHz0Ryfj1gcfh5jwCv_w,6501
20
20
  autocoder/agent/auto_filegroup.py,sha256=pBsAkBcpFTff-9L5OwI8xhf2xPKpl-aZwz-skF2B6dc,6296
@@ -83,7 +83,7 @@ autocoder/common/search.py,sha256=245iPFgWhMldoUK3CqCP89ltaxZiNPK73evoG6Fp1h8,16
83
83
  autocoder/common/search_replace.py,sha256=GphFkc57Hb673CAwmbiocqTbw8vrV7TrZxtOhD0332g,22147
84
84
  autocoder/common/shells.py,sha256=elminFpNosnV0hsEUcsugDxlGO8NfH96uah-8bkaBvA,19929
85
85
  autocoder/common/stats_panel.py,sha256=wGl9O45pjVVDxhNumLv4_NfLYSlUP_18Tw4hcJSjw50,4596
86
- autocoder/common/stream_out_type.py,sha256=XWONDrdNsWQTSzloVJSwbKD_Tacxe9mX_ozXdl-5VIc,379
86
+ autocoder/common/stream_out_type.py,sha256=PTkrY4_QEAFBPTcc_VUzb2dLL8XnRtV7MypNFGMjrHs,443
87
87
  autocoder/common/sys_prompt.py,sha256=JlexfjZt554faqbgkCmzOJqYUzDHfbnxly5ugFfHfEE,26403
88
88
  autocoder/common/text.py,sha256=KGRQq314GHBmY4MWG8ossRoQi1_DTotvhxchpn78c-k,1003
89
89
  autocoder/common/token_cost_caculate.py,sha256=MSWJtl7YpQSUt-gFQoqUcJMblyPqHXe2ZioiZOFkV80,10085
@@ -102,7 +102,7 @@ autocoder/common/v2/code_auto_merge_diff.py,sha256=xh93G9Gn8zSRhGq6L90tlodFM2u-g
102
102
  autocoder/common/v2/code_auto_merge_editblock.py,sha256=FpXdHAuHhtOLXybrUd2e1rDrxqoge-CpUyWpX0yNEv8,22018
103
103
  autocoder/common/v2/code_auto_merge_strict_diff.py,sha256=jIIedNZGW52dhSmNxb3vB7UdJZp8tg59Z2gg3sCpqoM,10117
104
104
  autocoder/common/v2/code_diff_manager.py,sha256=ciXviNjldX9ce9lgIvmWoG_8JT2GnwRW8U7QCWVdAH0,10512
105
- autocoder/common/v2/code_editblock_manager.py,sha256=AUT_zbawG9nSOrMr68bSfUB5fckSFWMv4yWcBUInyXM,12221
105
+ autocoder/common/v2/code_editblock_manager.py,sha256=vnqXHKSmp6U6Kb1esSO2NRZ7j1Bh5KTaGY6ZxX-6324,11750
106
106
  autocoder/common/v2/code_manager.py,sha256=C403bS-f6urixwitlKHcml-J03hci-UyNwHJOqBiY6Q,9182
107
107
  autocoder/common/v2/code_strict_diff_manager.py,sha256=v-J1kDyLg7tLGg_6_lbO9S4fNkx7M_L8Xr2G7fPptiU,9347
108
108
  autocoder/data/byzerllm.md,sha256=SGCMpEaUQ0ysPxQsgzyyp5sgvEr8dZsxEGAfVcPBIq0,47741
@@ -117,7 +117,7 @@ autocoder/dispacher/actions/plugins/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQ
117
117
  autocoder/dispacher/actions/plugins/action_regex_project.py,sha256=Vp07ANh0LlHoVPLM9ovTiIKv1gsUuCF57Gje4XiFVDA,8000
118
118
  autocoder/dispacher/actions/plugins/action_translate.py,sha256=GEn7dZA22jy5WyzINomjmzzB795p2Olg-CJla97lRF8,7744
119
119
  autocoder/events/__init__.py,sha256=1x_juwr9Ows2RADDa2LyI4QlmPxOVOXZeLO1cht-slM,1443
120
- autocoder/events/event_content.py,sha256=0unVmskGrfvnsniLvNXobco9KG-r6cv_C-gXK3L5zXQ,11557
120
+ autocoder/events/event_content.py,sha256=g55Z55s-ud9IzYp6u7BnLSsHHAAg34w1jrHo-C1w68A,12280
121
121
  autocoder/events/event_manager.py,sha256=WsEog4diXPsidCcN-Ycm18iPbX21PBibkcmjee-aRcQ,11739
122
122
  autocoder/events/event_manager_singleton.py,sha256=8aBp97fgbas0KYrpHbljTg2n4RcWd85SOgQITu47ZWA,8809
123
123
  autocoder/events/event_store.py,sha256=y6tT3P-o3yhDptrKi-UmqI_ZBNg7v21FriI3f7lo_ME,12709
@@ -127,7 +127,7 @@ autocoder/helper/project_creator.py,sha256=RITjVfZ_Y5zytSHTNYiwxfn2Eqfvf2Ywe13e6
127
127
  autocoder/index/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
128
128
  autocoder/index/entry.py,sha256=a8KhkNd6tKuD6W9fh9ohdri2r4UYeZWswi14pVwpr-Q,15740
129
129
  autocoder/index/for_command.py,sha256=BFvljE4t6VaMBGboZAuhUCzVK0EitCy_n5D_7FEnihw,3204
130
- autocoder/index/index.py,sha256=Y72N_w6tdI-Lv3GhgGDeCKxKfSzhxpdVuZpSAdJTsDU,30831
130
+ autocoder/index/index.py,sha256=-_GtT67ERxqdI4ajDyWr2cTsordpG_G9SYSwbTxDAcA,32491
131
131
  autocoder/index/symbols_utils.py,sha256=_EP7E_qWXxluAxq3FGZLlLfdrfwx3FmxCdulI8VGuac,2244
132
132
  autocoder/index/types.py,sha256=a2s_KV5FJlq7jqA2ELSo9E1sjuLwDB-JJYMhSpzBAhU,596
133
133
  autocoder/index/filter/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -226,9 +226,9 @@ autocoder/utils/types.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
226
226
  autocoder/utils/auto_coder_utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
227
227
  autocoder/utils/auto_coder_utils/chat_stream_out.py,sha256=xuBeWD0YOckqRo8JB1WkVIMOYH6c24m7JfV4svBfPDo,15113
228
228
  autocoder/utils/chat_auto_coder_utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
229
- auto_coder-0.1.325.dist-info/LICENSE,sha256=HrhfyXIkWY2tGFK11kg7vPCqhgh5DcxleloqdhrpyMY,11558
230
- auto_coder-0.1.325.dist-info/METADATA,sha256=lNMC89BQ-3DS6bxOqOqb4EmcgOKZxrqTBp221h4_ac4,2747
231
- auto_coder-0.1.325.dist-info/WHEEL,sha256=GV9aMThwP_4oNCtvEC2ec3qUYutgWeAzklro_0m4WJQ,91
232
- auto_coder-0.1.325.dist-info/entry_points.txt,sha256=0nzHtHH4pNcM7xq4EBA2toS28Qelrvcbrr59GqD_0Ak,350
233
- auto_coder-0.1.325.dist-info/top_level.txt,sha256=Jqc0_uJSw2GwoFQAa9iJxYns-2mWla-9ok_Y3Gcznjk,10
234
- auto_coder-0.1.325.dist-info/RECORD,,
229
+ auto_coder-0.1.327.dist-info/LICENSE,sha256=HrhfyXIkWY2tGFK11kg7vPCqhgh5DcxleloqdhrpyMY,11558
230
+ auto_coder-0.1.327.dist-info/METADATA,sha256=xGfc33ogoMBS7t9utBeDgZs3YW_7yRnJWaOb0tZuXX0,2747
231
+ auto_coder-0.1.327.dist-info/WHEEL,sha256=GV9aMThwP_4oNCtvEC2ec3qUYutgWeAzklro_0m4WJQ,91
232
+ auto_coder-0.1.327.dist-info/entry_points.txt,sha256=0nzHtHH4pNcM7xq4EBA2toS28Qelrvcbrr59GqD_0Ak,350
233
+ auto_coder-0.1.327.dist-info/top_level.txt,sha256=Jqc0_uJSw2GwoFQAa9iJxYns-2mWla-9ok_Y3Gcznjk,10
234
+ auto_coder-0.1.327.dist-info/RECORD,,
@@ -15,3 +15,6 @@ class CodeRankStreamOutType(Enum):
15
15
 
16
16
  class LintStreamOutType(Enum):
17
17
  LINT = "lint"
18
+
19
+ class IndexStreamOutType(Enum):
20
+ INDEX_BUILD = "index_build"
@@ -39,7 +39,7 @@ class CodeEditBlockManager:
39
39
  It generates code, lints it, and if there are errors, regenerates the code up to 5 times
40
40
  before merging the final result.
41
41
  """
42
-
42
+
43
43
  def __init__(
44
44
  self,
45
45
  llm: byzerllm.ByzerLLM,
@@ -56,11 +56,12 @@ class CodeEditBlockManager:
56
56
  self.generate_times_same_model = args.generate_times_same_model
57
57
  self.max_correction_attempts = args.auto_fix_lint_max_attempts
58
58
  self.printer = Printer()
59
-
59
+
60
60
  # Initialize sub-components
61
- self.code_generator = CodeAutoGenerateEditBlock(llm, args, action, fence_0, fence_1)
61
+ self.code_generator = CodeAutoGenerateEditBlock(
62
+ llm, args, action, fence_0, fence_1)
62
63
  self.code_merger = CodeAutoMergeEditBlock(llm, args, fence_0, fence_1)
63
-
64
+
64
65
  # Create shadow manager for linting
65
66
  self.shadow_manager = ShadowManager(args.source_dir, args.event_file)
66
67
  self.shadow_linter = ShadowLinter(self.shadow_manager, verbose=False)
@@ -72,7 +73,7 @@ class CodeEditBlockManager:
72
73
  <lint_issues>
73
74
  {{ lint_issues }}
74
75
  </lint_issues>
75
-
76
+
76
77
  用户原始需求:
77
78
  <user_query_wrapper>
78
79
  {{ query }}
@@ -81,79 +82,80 @@ class CodeEditBlockManager:
81
82
  修复上述问题,请确保代码质量问题被解决,同时保持代码的原有功能。
82
83
  请严格遵守*SEARCH/REPLACE block*的格式。
83
84
  """
84
-
85
+
85
86
  def _create_shadow_files_from_edits(self, generation_result: CodeGenerateResult) -> Dict[str, str]:
86
87
  """
87
88
  从编辑块内容中提取代码并创建临时影子文件用于检查。
88
-
89
+
89
90
  参数:
90
91
  generation_result (CodeGenerateResult): 包含SEARCH/REPLACE块的内容
91
-
92
+
92
93
  返回:
93
94
  Dict[str, str]: 映射 {影子文件路径: 内容}
94
95
  """
95
96
  result = self.code_merger.choose_best_choice(generation_result)
96
- merge = self.code_merger._merge_code_without_effect(result.contents[0])
97
+ merge = self.code_merger._merge_code_without_effect(result.contents[0])
97
98
  shadow_files = {}
98
99
  for file_path, new_content in merge.success_blocks:
99
100
  self.shadow_manager.update_file(file_path, new_content)
100
- shadow_files[self.shadow_manager.to_shadow_path(file_path)] = new_content
101
+ shadow_files[self.shadow_manager.to_shadow_path(
102
+ file_path)] = new_content
101
103
 
102
104
  return shadow_files
103
105
 
104
- def _format_lint_issues(self, lint_results:ProjectLintResult,levels:List[IssueSeverity]=[IssueSeverity.ERROR]) -> str:
106
+ def _format_lint_issues(self, lint_results: ProjectLintResult, levels: List[IssueSeverity] = [IssueSeverity.ERROR]) -> str:
105
107
  """
106
108
  将linter结果格式化为字符串供模型使用
107
-
109
+
108
110
  参数:
109
111
  lint_results: Linter结果对象
110
112
  level: 过滤问题的级别
111
-
113
+
112
114
  返回:
113
115
  str: 格式化的问题描述
114
116
  """
115
117
  formatted_issues = []
116
-
117
- for file_path, result in lint_results.file_results.items():
118
+
119
+ for file_path, result in lint_results.file_results.items():
118
120
  file_has_issues = False
119
121
  file_issues = []
120
-
121
- for issue in result.issues:
122
+
123
+ for issue in result.issues:
122
124
  if issue.severity.value not in levels:
123
125
  continue
124
-
126
+
125
127
  if not file_has_issues:
126
128
  file_has_issues = True
127
129
  file_issues.append(f"文件: {file_path}")
128
-
130
+
129
131
  severity = "错误" if issue.severity == IssueSeverity.ERROR else "警告" if issue.severity == IssueSeverity.WARNING else "信息"
130
132
  line_info = f"第{issue.position.line}行"
131
133
  if issue.position.column:
132
134
  line_info += f", 第{issue.position.column}列"
133
-
135
+
134
136
  file_issues.append(
135
137
  f" - [{severity}] {line_info}: {issue.message} (规则: {issue.code})"
136
138
  )
137
-
139
+
138
140
  if file_has_issues:
139
141
  formatted_issues.extend(file_issues)
140
142
  formatted_issues.append("") # 空行分隔不同文件
141
-
143
+
142
144
  return "\n".join(formatted_issues)
143
145
 
144
- def _count_errors(self, lint_results:ProjectLintResult,levels:List[IssueSeverity]=[IssueSeverity.ERROR]) -> int:
146
+ def _count_errors(self, lint_results: ProjectLintResult, levels: List[IssueSeverity] = [IssueSeverity.ERROR]) -> int:
145
147
  """
146
148
  计算lint结果中的错误数量
147
-
149
+
148
150
  参数:
149
151
  lint_results: Linter结果对象
150
-
152
+
151
153
  返回:
152
154
  int: 错误数量
153
155
  """
154
156
  error_count = 0
155
-
156
- for _, result in lint_results.file_results.items():
157
+
158
+ for _, result in lint_results.file_results.items():
157
159
  if IssueSeverity.ERROR in levels:
158
160
  error_count += result.error_count
159
161
  if IssueSeverity.WARNING in levels:
@@ -162,25 +164,26 @@ class CodeEditBlockManager:
162
164
  error_count += result.info_count
163
165
  if IssueSeverity.HINT in levels:
164
166
  error_count += result.hint_count
165
-
167
+
166
168
  return error_count
167
169
 
168
170
  def generate_and_fix(self, query: str, source_code_list: SourceCodeList) -> CodeGenerateResult:
169
171
  """
170
172
  生成代码,运行linter,修复错误,最多尝试指定次数
171
-
173
+
172
174
  参数:
173
175
  query (str): 用户查询
174
176
  source_code_list (SourceCodeList): 源代码列表
175
-
177
+
176
178
  返回:
177
179
  CodeGenerateResult: 生成的代码结果
178
180
  """
179
181
  # 初始代码生成
180
182
  self.printer.print_in_terminal("generating_initial_code")
181
183
  start_time = time.time()
182
- generation_result = self.code_generator.single_round_run(query, source_code_list)
183
-
184
+ generation_result = self.code_generator.single_round_run(
185
+ query, source_code_list)
186
+
184
187
  token_cost_calculator = TokenCostCalculator(args=self.args)
185
188
  token_cost_calculator.track_token_usage_by_generate(
186
189
  llm=self.llm,
@@ -189,113 +192,112 @@ class CodeEditBlockManager:
189
192
  start_time=start_time,
190
193
  end_time=time.time()
191
194
  )
192
-
195
+
193
196
  # 确保结果非空
194
197
  if not generation_result.contents:
195
198
  self.printer.print_in_terminal("generation_failed", style="red")
196
199
  return generation_result
197
-
198
-
200
+
199
201
  # 最多尝试修复5次
200
202
  for attempt in range(self.max_correction_attempts):
201
203
  global_cancel.check_and_raise()
202
204
  # 代码生成结果更新到影子文件里去
203
- shadow_files = self._create_shadow_files_from_edits(generation_result)
204
-
205
+ shadow_files = self._create_shadow_files_from_edits(
206
+ generation_result)
207
+
205
208
  if not shadow_files:
206
- self.printer.print_in_terminal("no_files_to_lint", style="yellow")
209
+ self.printer.print_in_terminal(
210
+ "no_files_to_lint", style="yellow")
207
211
  break
208
-
212
+
209
213
  # 运行linter
210
214
  lint_results = self.shadow_linter.lint_all_shadow_files()
211
215
  error_count = self._count_errors(lint_results)
212
216
  # print(f"error_count: {error_count}")
213
- # print(f"lint_results: {json.dumps(lint_results.model_dump(), indent=4,ensure_ascii=False)}")
214
-
217
+ # print(f"lint_results: {json.dumps(lint_results.model_dump(), indent=4,ensure_ascii=False)}")
218
+
215
219
  # 如果没有错误则完成
216
220
  if error_count == 0:
217
- self.printer.print_in_terminal("no_lint_errors_found", style="green")
221
+ self.printer.print_in_terminal(
222
+ "no_lint_errors_found", style="green")
218
223
  break
219
224
 
220
225
  # 格式化lint问题
221
- formatted_issues = self._format_lint_issues(lint_results, [IssueSeverity.ERROR, IssueSeverity.WARNING])
226
+ formatted_issues = self._format_lint_issues(
227
+ lint_results, [IssueSeverity.ERROR, IssueSeverity.WARNING])
222
228
 
223
229
  # 打印当前错误
224
230
  self.printer.print_in_terminal(
225
- "lint_attempt_status",
226
- style="yellow",
227
- attempt=(attempt + 1),
231
+ "lint_attempt_status",
232
+ style="yellow",
233
+ attempt=(attempt + 1),
228
234
  max_correction_attempts=self.max_correction_attempts,
229
235
  error_count=error_count,
230
236
  formatted_issues=formatted_issues
231
237
  )
232
238
 
233
- get_event_manager(self.args.event_file).add_event(Event(
234
- event_type=EventType.RESULT,
235
- content=EventContentCreator.create_result(
236
- content=EventContentCreator.ResultContent(
237
- content=f"Lint attempt {attempt + 1}/{self.max_correction_attempts}: Found {error_count} issues:\n {formatted_issues}",
238
- metadata={}
239
- )
240
- ).to_dict(),
239
+ get_event_manager(self.args.event_file).write_result(EventContentCreator.create_result(
240
+ content=EventContentCreator.ResultContent(content=f"Lint attempt {attempt + 1}/{self.max_correction_attempts}: Found {error_count} issues:\n {formatted_issues}",
241
+ metadata={}
242
+ ).to_dict(),
241
243
  metadata={
242
244
  "stream_out_type": LintStreamOutType.LINT.value,
243
245
  "action_file": self.args.file
244
246
  }
245
247
  ))
246
-
248
+
247
249
  if attempt == self.max_correction_attempts - 1:
248
- self.printer.print_in_terminal("max_attempts_reached", style="yellow")
250
+ self.printer.print_in_terminal(
251
+ "max_attempts_reached", style="yellow")
249
252
  break
250
-
251
-
252
-
253
+
253
254
  # 准备修复提示
254
255
  fix_prompt = self.fix_linter_errors.prompt(
255
256
  query=query,
256
257
  lint_issues=formatted_issues
257
258
  )
258
-
259
+
259
260
  # for source in source_code_list.sources:
260
- # print(f"file_path: {source.module_name}")
261
+ # print(f"file_path: {source.module_name}")
261
262
  # print(f"fix_prompt: {fix_prompt}")
262
-
263
+
263
264
  # 将 shadow_files 转化为 source_code_list
264
265
  start_time = time.time()
265
- source_code_list = self.code_merger.get_source_code_list_from_shadow_files(shadow_files)
266
- generation_result = self.code_generator.single_round_run(fix_prompt, source_code_list)
266
+ source_code_list = self.code_merger.get_source_code_list_from_shadow_files(
267
+ shadow_files)
268
+ generation_result = self.code_generator.single_round_run(
269
+ fix_prompt, source_code_list)
267
270
  token_cost_calculator.track_token_usage_by_generate(
268
271
  llm=self.llm,
269
272
  generate=generation_result,
270
273
  operation_name="code_generation_complete",
271
274
  start_time=start_time,
272
275
  end_time=time.time()
273
- )
276
+ )
274
277
 
275
-
276
278
  # 清理临时影子文件
277
279
  self.shadow_manager.clean_shadows()
278
-
280
+
279
281
  # 返回最终结果
280
282
  return generation_result
281
283
 
282
284
  def run(self, query: str, source_code_list: SourceCodeList) -> CodeGenerateResult:
283
285
  """
284
286
  执行完整的代码生成、修复、合并流程
285
-
287
+
286
288
  参数:
287
289
  query (str): 用户查询
288
290
  source_code_list (SourceCodeList): 源代码列表
289
-
291
+
290
292
  返回:
291
293
  CodeGenerateResult: 生成和修复的代码结果
292
294
  """
293
- # 生成代码并自动修复lint错误
295
+ # 生成代码并自动修复lint错误
294
296
 
295
297
  generation_result = self.generate_and_fix(query, source_code_list)
296
- global_cancel.check_and_raise()
298
+ global_cancel.check_and_raise()
297
299
 
298
- # 合并代码
300
+ # 合并代码
299
301
  self.code_merger.merge_code(generation_result)
300
-
301
- return generation_result
302
+
303
+ return generation_result
@@ -119,6 +119,35 @@ class ResultTokenStatContent(BaseModel):
119
119
  """转换为JSON字符串"""
120
120
  return self.model_dump_json()
121
121
 
122
+ class IndexBuildStartContent(BaseModel):
123
+ file_number:int = 0
124
+ total_files:int = 0
125
+
126
+ def to_dict(self) -> Dict[str, Any]:
127
+ """转换为字典"""
128
+ return self.model_dump()
129
+
130
+ def to_json(self) -> str:
131
+ """转换为JSON字符串"""
132
+ return self.model_dump_json()
133
+
134
+ class IndexBuildEndContent(BaseModel):
135
+ updated_files:int = 0
136
+ removed_files:int = 0
137
+ input_tokens:int = 0
138
+ output_tokens:int = 0
139
+ input_cost:float = 0.0
140
+ output_cost:float = 0.0
141
+
142
+ def to_dict(self) -> Dict[str, Any]:
143
+ """转换为字典"""
144
+ return self.model_dump()
145
+
146
+ def to_json(self) -> str:
147
+ """转换为JSON字符串"""
148
+ return self.model_dump_json()
149
+
150
+
122
151
 
123
152
  class ResultCommandPrepareStatContent(BaseModel):
124
153
  command:str = ""
autocoder/index/index.py CHANGED
@@ -28,7 +28,9 @@ from autocoder.index.types import (
28
28
  from autocoder.common.global_cancel import global_cancel
29
29
  from autocoder.utils.llms import get_llm_names
30
30
  from autocoder.rag.token_counter import count_tokens
31
-
31
+ from autocoder.common.stream_out_type import IndexStreamOutType
32
+ from autocoder.events.event_manager_singleton import get_event_manager
33
+ from autocoder.events import event_content as EventContentCreator
32
34
 
33
35
  class IndexManager:
34
36
  def __init__(
@@ -190,7 +192,7 @@ class IndexManager:
190
192
  {{ code }}
191
193
 
192
194
  ## 输出
193
- """
195
+ """
194
196
 
195
197
  @byzerllm.prompt()
196
198
  def jsp_get_all_file_symbols(self, path: str, code: str) -> str:
@@ -224,11 +226,11 @@ class IndexManager:
224
226
  url : "admWorkingDay!updateAdmWorkingDayList.action", 中,那么对应的为 <ajax method="post" url="admWorkingDay!updateAdmWorkingDayList.action">
225
227
  10. 导入语句中需要包含超连接,比如 <a href="admRiskLimits!queryAdmRiskLimitsById.action?admRiskLimits.id=${fn:escapeXml(item.id)}">${fn:escapeXml(item.classification)}, 对应的为 <a href="admRiskLimits!queryAdmRiskLimitsById.action"}
226
228
  11. 导入语句中需要包含一些js函数里的值,比如 window.onbeforeunload = function() {
227
- var actionType = document.ap_ActionPlanForm.action.value;
228
- if(typeof(window.opener.reloadApCount)!="undefined"&&(actionType&&actionType!='Discard')){
229
- }
229
+ var actionType = document.ap_ActionPlanForm.action.value;
230
+ if(typeof(window.opener.reloadApCount)!="undefined"&&(actionType&&actionType!='Discard')){
231
+ }
230
232
  } 对应为 <window.onbeforeunload url="from 表单名字为ap_ActionPlanForm的action的值">
231
-
233
+
232
234
  下面是一段示例:
233
235
 
234
236
  ## 输入
@@ -363,14 +365,14 @@ class IndexManager:
363
365
  else:
364
366
  meta_holder = byzerllm.MetaHolder()
365
367
  ext = os.path.splitext(file_path)[1].lower()
366
- ## 需要有特殊prompt
368
+ # 需要有特殊prompt
367
369
  if ext == ".jsp":
368
370
  symbols = self.jsp_get_all_file_symbols.with_llm(
369
371
  self.index_llm).with_meta(meta_holder).run(source.module_name, source_code)
370
372
  else:
371
373
  symbols = self.get_all_file_symbols.with_llm(
372
374
  self.index_llm).with_meta(meta_holder).run(source.module_name, source_code)
373
-
375
+
374
376
  time.sleep(self.anti_quota_limit)
375
377
 
376
378
  if meta_holder.get_meta():
@@ -478,7 +480,8 @@ class IndexManager:
478
480
 
479
481
  # 删除被排除的文件
480
482
  try:
481
- exclude_patterns = self.parse_exclude_files(self.args.exclude_files)
483
+ exclude_patterns = self.parse_exclude_files(
484
+ self.args.exclude_files)
482
485
  for file_path in index_data:
483
486
  if self.filter_exclude_files(file_path, exclude_patterns):
484
487
  keys_to_remove.append(file_path)
@@ -546,6 +549,19 @@ class IndexManager:
546
549
  num_files=num_files
547
550
  )
548
551
 
552
+ get_event_manager(self.args.event_file).write_result(
553
+ EventContentCreator.create_result(
554
+ content=EventContentCreator.IndexBuildStartContent(
555
+ file_number=num_files,
556
+ total_files=total_files
557
+ ).to_dict(),
558
+ metadata={
559
+ "stream_out_type": IndexStreamOutType.INDEX_BUILD.value,
560
+ "action_file": self.args.file
561
+ }
562
+ )
563
+ )
564
+
549
565
  futures = [
550
566
  executor.submit(self.build_index_for_single_source, source)
551
567
  for source in wait_to_build_files
@@ -592,6 +608,24 @@ class IndexManager:
592
608
  )
593
609
  print("")
594
610
 
611
+ # 记录索引构建完成事件
612
+ get_event_manager(self.args.event_file).write_result(
613
+ EventContentCreator.create_result(
614
+ content=EventContentCreator.IndexBuildEndContent(
615
+ updated_files=len(updated_sources),
616
+ removed_files=len(keys_to_remove),
617
+ input_tokens=total_input_tokens,
618
+ output_tokens=total_output_tokens,
619
+ input_cost=total_input_cost,
620
+ output_cost=total_output_cost
621
+ ).to_dict(),
622
+ metadata={}
623
+ ).to_dict(),
624
+ metadata={
625
+ "stream_out_type": IndexStreamOutType.INDEX_BUILD.value,
626
+ "action_file": self.args.file
627
+ }
628
+ )
595
629
  return index_data
596
630
 
597
631
  def read_index_as_str(self):
autocoder/version.py CHANGED
@@ -1 +1 @@
1
- __version__ = "0.1.325"
1
+ __version__ = "0.1.327"