czon 0.4.3 → 0.4.4

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.
@@ -12,24 +12,27 @@ async function extractMetadataByAI() {
12
12
  if (metadata_1.MetaData.options.verbose)
13
13
  console.log(`🤖 Running AI metadata extraction...`);
14
14
  console.log(`🤖 Processing ${files.length} files with AI...`);
15
- await Promise.all(files.map(async (file) => {
15
+ const results = await Promise.allSettled(files.map(async (file) => {
16
16
  if (!file.path.endsWith('.md')) {
17
17
  console.info(`ℹ️ Skipping ${file.path}, not a Markdown file`);
18
18
  return;
19
19
  }
20
- try {
21
- if (file.metadata && file.metadata.slug && file.metadata.short_summary) {
22
- console.info(`ℹ️ Skipping ${file.path}, already has metadata`);
23
- return;
24
- }
25
- const content = await (0, promises_1.readFile)(file.path, 'utf-8');
26
- file.metadata = await (0, extractMetadataFromMarkdown_1.extractMetadataFromMarkdown)(file.path, content);
27
- console.log(`✅ Extracted AI metadata for ${file.path}`, file.metadata.tokens_used);
28
- }
29
- catch (error) {
30
- console.error(`⚠️ Failed to process file ${file.path}:`, error);
20
+ if (file.metadata && file.metadata.slug && file.metadata.short_summary) {
21
+ console.info(`ℹ️ Skipping ${file.path}, already has metadata`);
22
+ return;
31
23
  }
24
+ const content = await (0, promises_1.readFile)(file.path, 'utf-8');
25
+ file.metadata = await (0, extractMetadataFromMarkdown_1.extractMetadataFromMarkdown)(file.path, content);
26
+ console.log(`✅ Extracted AI metadata for ${file.path}`, file.metadata.tokens_used);
32
27
  }));
28
+ const errors = results.filter(r => r.status === 'rejected');
29
+ if (errors.length > 0) {
30
+ console.warn(`⚠️ Some files failed to process.`);
31
+ errors.forEach((err, index) => {
32
+ console.error(`❌ Failed to process file ${files[index].path}`, err.reason);
33
+ });
34
+ throw new Error('AI metadata extraction encountered errors.');
35
+ }
33
36
  console.log(`✅ AI processing completed for ${files.length} files`);
34
37
  }
35
38
  //# sourceMappingURL=extractMetadataByAI.js.map
@@ -29,6 +29,7 @@ const setupReport = async () => {
29
29
  catch (e) { }
30
30
  await new Promise(resolve => setTimeout(resolve, 1000));
31
31
  }
32
+ isReporting = false;
32
33
  };
33
34
  /**
34
35
  * 使用 OpenAI API 补全消息
@@ -37,24 +38,24 @@ const setupReport = async () => {
37
38
  * @returns Promise<OpenAIResponse> 返回完整的OpenAI响应
38
39
  */
39
40
  const completeMessages = async (messages, options) => {
40
- if (options?.task_id) {
41
- processingTaskIds.add(options.task_id);
42
- setupReport();
43
- }
44
- // 从环境变量读取配置
45
- const apiKey = process.env.OPENAI_API_KEY || '';
46
- const baseUrl = process.env.OPENAI_BASE_URL || 'https://api.openai.com/v1';
47
- const model = process.env.OPENAI_MODEL || 'gpt-3.5-turbo';
48
- const max_tokens = process.env.OPENAI_MAX_TOKENS ? +process.env.OPENAI_MAX_TOKENS : undefined; // 不填就使用模型默认值
49
- if (!apiKey) {
50
- throw new Error('OPENAI_API_KEY environment variable is not set');
51
- }
52
- let finishReason = null;
53
- let responseId = null;
54
- let responseModel = null;
55
- let responseCreated = null;
56
- let usage = null;
57
41
  try {
42
+ if (options?.task_id) {
43
+ processingTaskIds.add(options.task_id);
44
+ setupReport();
45
+ }
46
+ // 从环境变量读取配置
47
+ const apiKey = process.env.OPENAI_API_KEY || '';
48
+ const baseUrl = process.env.OPENAI_BASE_URL || 'https://api.openai.com/v1';
49
+ const model = process.env.OPENAI_MODEL || 'gpt-3.5-turbo';
50
+ const max_tokens = process.env.OPENAI_MAX_TOKENS ? +process.env.OPENAI_MAX_TOKENS : undefined; // 不填就使用模型默认值
51
+ if (!apiKey) {
52
+ throw new Error('OPENAI_API_KEY environment variable is not set');
53
+ }
54
+ let finishReason = null;
55
+ let responseId = null;
56
+ let responseModel = null;
57
+ let responseCreated = null;
58
+ let usage = null;
58
59
  const requestBody = {
59
60
  model,
60
61
  messages,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "czon",
3
- "version": "0.4.3",
3
+ "version": "0.4.4",
4
4
  "description": "CZone - AI enhanced Markdown content engine",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",