@opensumi/ide-ai-native 3.9.1-next-1749175927.0 → 3.9.1-next-1749196667.0
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.
- package/lib/browser/ai-core.contribution.d.ts.map +1 -1
- package/lib/browser/ai-core.contribution.js +4 -9
- package/lib/browser/ai-core.contribution.js.map +1 -1
- package/lib/browser/chat/apply.service.d.ts +0 -3
- package/lib/browser/chat/apply.service.d.ts.map +1 -1
- package/lib/browser/chat/apply.service.js +0 -47
- package/lib/browser/chat/apply.service.js.map +1 -1
- package/lib/browser/chat/chat-manager.service.d.ts +0 -1
- package/lib/browser/chat/chat-manager.service.d.ts.map +1 -1
- package/lib/browser/chat/chat-manager.service.js +3 -9
- package/lib/browser/chat/chat-manager.service.js.map +1 -1
- package/lib/browser/chat/chat-model.d.ts +1 -8
- package/lib/browser/chat/chat-model.d.ts.map +1 -1
- package/lib/browser/chat/chat-model.js +76 -113
- package/lib/browser/chat/chat-model.js.map +1 -1
- package/lib/browser/chat/chat-proxy.service.d.ts +2 -0
- package/lib/browser/chat/chat-proxy.service.d.ts.map +1 -1
- package/lib/browser/chat/chat-proxy.service.js +57 -50
- package/lib/browser/chat/chat-proxy.service.js.map +1 -1
- package/lib/browser/chat/chat.feature.registry.d.ts +1 -4
- package/lib/browser/chat/chat.feature.registry.d.ts.map +1 -1
- package/lib/browser/chat/chat.feature.registry.js +0 -6
- package/lib/browser/chat/chat.feature.registry.js.map +1 -1
- package/lib/browser/chat/chat.view.d.ts.map +1 -1
- package/lib/browser/chat/chat.view.js +10 -51
- package/lib/browser/chat/chat.view.js.map +1 -1
- package/lib/browser/components/ChatEditor.js +2 -2
- package/lib/browser/components/ChatEditor.js.map +1 -1
- package/lib/browser/components/ChatHistory.d.ts.map +1 -1
- package/lib/browser/components/ChatHistory.js +1 -2
- package/lib/browser/components/ChatHistory.js.map +1 -1
- package/lib/browser/components/ChatMentionInput.d.ts.map +1 -1
- package/lib/browser/components/ChatMentionInput.js +28 -124
- package/lib/browser/components/ChatMentionInput.js.map +1 -1
- package/lib/browser/components/ChatToolRender.d.ts.map +1 -1
- package/lib/browser/components/ChatToolRender.js +2 -7
- package/lib/browser/components/ChatToolRender.js.map +1 -1
- package/lib/browser/components/ChatToolRender.module.less +0 -25
- package/lib/browser/components/components.module.less +0 -7
- package/lib/browser/components/mention-input/mention-input.d.ts.map +1 -1
- package/lib/browser/components/mention-input/mention-input.js +13 -155
- package/lib/browser/components/mention-input/mention-input.js.map +1 -1
- package/lib/browser/components/mention-input/mention-input.module.less +0 -165
- package/lib/browser/components/mention-input/types.d.ts +1 -15
- package/lib/browser/components/mention-input/types.d.ts.map +1 -1
- package/lib/browser/components/mention-input/types.js +0 -1
- package/lib/browser/components/mention-input/types.js.map +1 -1
- package/lib/browser/components/utils.d.ts +2 -2
- package/lib/browser/context/llm-context.service.d.ts +2 -21
- package/lib/browser/context/llm-context.service.d.ts.map +1 -1
- package/lib/browser/context/llm-context.service.js +20 -162
- package/lib/browser/context/llm-context.service.js.map +1 -1
- package/lib/browser/contrib/intelligent-completions/decoration/additions-deletions.decoration.d.ts.map +1 -1
- package/lib/browser/contrib/intelligent-completions/decoration/additions-deletions.decoration.js.map +1 -1
- package/lib/browser/contrib/intelligent-completions/diff-computer.js +1 -1
- package/lib/browser/contrib/intelligent-completions/diff-computer.js.map +1 -1
- package/lib/browser/contrib/terminal/terminal.feature.registry.js.map +1 -1
- package/lib/browser/index.d.ts.map +1 -1
- package/lib/browser/index.js +0 -7
- package/lib/browser/index.js.map +1 -1
- package/lib/browser/layout/ai-layout.d.ts.map +1 -1
- package/lib/browser/layout/ai-layout.js +4 -6
- package/lib/browser/layout/ai-layout.js.map +1 -1
- package/lib/browser/layout/tabbar.view.d.ts +1 -1
- package/lib/browser/layout/tabbar.view.d.ts.map +1 -1
- package/lib/browser/layout/tabbar.view.js +12 -5
- package/lib/browser/layout/tabbar.view.js.map +1 -1
- package/lib/browser/mcp/base-apply.service.d.ts +4 -5
- package/lib/browser/mcp/base-apply.service.d.ts.map +1 -1
- package/lib/browser/mcp/base-apply.service.js +5 -23
- package/lib/browser/mcp/base-apply.service.js.map +1 -1
- package/lib/browser/mcp/mcp-server-proxy.service.d.ts +1 -3
- package/lib/browser/mcp/mcp-server-proxy.service.d.ts.map +1 -1
- package/lib/browser/mcp/mcp-server-proxy.service.js +0 -4
- package/lib/browser/mcp/mcp-server-proxy.service.js.map +1 -1
- package/lib/browser/mcp/tools/getDiagnosticsByPath.js.map +1 -1
- package/lib/browser/mcp/tools/getOpenEditorFileDiagnostics.js.map +1 -1
- package/lib/browser/mcp/tools/handlers/ListDir.js.map +1 -1
- package/lib/browser/mcp/tools/runTerminalCmd.js.map +1 -1
- package/lib/browser/model/msg-history-manager.d.ts +1 -47
- package/lib/browser/model/msg-history-manager.d.ts.map +1 -1
- package/lib/browser/model/msg-history-manager.js +2 -127
- package/lib/browser/model/msg-history-manager.js.map +1 -1
- package/lib/browser/preferences/schema.d.ts.map +1 -1
- package/lib/browser/preferences/schema.js +0 -5
- package/lib/browser/preferences/schema.js.map +1 -1
- package/lib/browser/types.d.ts +1 -12
- package/lib/browser/types.d.ts.map +1 -1
- package/lib/browser/types.js.map +1 -1
- package/lib/browser/widget/inline-stream-diff/live-preview.component.d.ts.map +1 -1
- package/lib/browser/widget/inline-stream-diff/live-preview.component.js.map +1 -1
- package/lib/common/index.d.ts +1 -5
- package/lib/common/index.d.ts.map +1 -1
- package/lib/common/index.js +0 -2
- package/lib/common/index.js.map +1 -1
- package/lib/common/llm-context.d.ts +0 -19
- package/lib/common/llm-context.d.ts.map +1 -1
- package/lib/common/llm-context.js.map +1 -1
- package/lib/common/prompts/context-prompt-provider.d.ts +2 -0
- package/lib/common/prompts/context-prompt-provider.d.ts.map +1 -1
- package/lib/common/prompts/context-prompt-provider.js +29 -35
- package/lib/common/prompts/context-prompt-provider.js.map +1 -1
- package/lib/common/types.d.ts +0 -21
- package/lib/common/types.d.ts.map +1 -1
- package/lib/common/types.js.map +1 -1
- package/lib/common/utils.d.ts +0 -1
- package/lib/common/utils.d.ts.map +1 -1
- package/lib/common/utils.js +2 -5
- package/lib/common/utils.js.map +1 -1
- package/lib/node/base-language-model.d.ts +1 -2
- package/lib/node/base-language-model.d.ts.map +1 -1
- package/lib/node/base-language-model.js +1 -10
- package/lib/node/base-language-model.js.map +1 -1
- package/lib/node/mcp/sumi-mcp-server.d.ts +1 -3
- package/lib/node/mcp/sumi-mcp-server.d.ts.map +1 -1
- package/lib/node/mcp/sumi-mcp-server.js +1 -7
- package/lib/node/mcp/sumi-mcp-server.js.map +1 -1
- package/lib/node/mcp-server-manager-impl.d.ts +1 -3
- package/lib/node/mcp-server-manager-impl.d.ts.map +1 -1
- package/lib/node/mcp-server-manager-impl.js +2 -14
- package/lib/node/mcp-server-manager-impl.js.map +1 -1
- package/package.json +24 -25
- package/src/browser/ai-core.contribution.ts +4 -14
- package/src/browser/chat/apply.service.ts +1 -62
- package/src/browser/chat/chat-manager.service.ts +7 -16
- package/src/browser/chat/chat-model.ts +73 -130
- package/src/browser/chat/chat-proxy.service.ts +81 -68
- package/src/browser/chat/chat.feature.registry.ts +1 -17
- package/src/browser/chat/chat.view.tsx +12 -74
- package/src/browser/components/ChatEditor.tsx +1 -1
- package/src/browser/components/ChatHistory.tsx +1 -2
- package/src/browser/components/ChatMentionInput.tsx +32 -144
- package/src/browser/components/ChatToolRender.module.less +0 -25
- package/src/browser/components/ChatToolRender.tsx +2 -10
- package/src/browser/components/components.module.less +0 -7
- package/src/browser/components/mention-input/mention-input.module.less +0 -165
- package/src/browser/components/mention-input/mention-input.tsx +29 -244
- package/src/browser/components/mention-input/types.ts +0 -15
- package/src/browser/context/llm-context.service.ts +21 -182
- package/src/browser/contrib/intelligent-completions/decoration/additions-deletions.decoration.ts +1 -1
- package/src/browser/contrib/intelligent-completions/diff-computer.ts +1 -1
- package/src/browser/contrib/terminal/terminal.feature.registry.ts +1 -1
- package/src/browser/index.ts +0 -8
- package/src/browser/layout/ai-layout.tsx +8 -12
- package/src/browser/layout/tabbar.view.tsx +23 -10
- package/src/browser/mcp/base-apply.service.ts +10 -30
- package/src/browser/mcp/mcp-server-proxy.service.ts +1 -6
- package/src/browser/mcp/tools/getDiagnosticsByPath.ts +1 -1
- package/src/browser/mcp/tools/getOpenEditorFileDiagnostics.ts +1 -1
- package/src/browser/mcp/tools/handlers/ListDir.ts +1 -1
- package/src/browser/mcp/tools/runTerminalCmd.ts +1 -1
- package/src/browser/model/msg-history-manager.ts +2 -181
- package/src/browser/preferences/schema.ts +0 -5
- package/src/browser/types.ts +0 -18
- package/src/browser/widget/inline-stream-diff/live-preview.component.tsx +1 -0
- package/src/common/index.ts +1 -6
- package/src/common/llm-context.ts +0 -23
- package/src/common/prompts/context-prompt-provider.ts +40 -55
- package/src/common/types.ts +0 -18
- package/src/common/utils.ts +1 -4
- package/src/node/base-language-model.ts +13 -10
- package/src/node/mcp/sumi-mcp-server.ts +2 -10
- package/src/node/mcp-server-manager-impl.ts +2 -17
- package/lib/browser/rules/rules.contribution.d.ts +0 -29
- package/lib/browser/rules/rules.contribution.d.ts.map +0 -1
- package/lib/browser/rules/rules.contribution.js +0 -94
- package/lib/browser/rules/rules.contribution.js.map +0 -1
- package/lib/browser/rules/rules.module.less +0 -174
- package/lib/browser/rules/rules.service.d.ts +0 -25
- package/lib/browser/rules/rules.service.d.ts.map +0 -1
- package/lib/browser/rules/rules.service.js +0 -180
- package/lib/browser/rules/rules.service.js.map +0 -1
- package/lib/browser/rules/rules.view.d.ts +0 -3
- package/lib/browser/rules/rules.view.d.ts.map +0 -1
- package/lib/browser/rules/rules.view.js +0 -76
- package/lib/browser/rules/rules.view.js.map +0 -1
- package/lib/common/MDC_PARSER_README.md +0 -171
- package/lib/common/image-compression.d.ts +0 -25
- package/lib/common/image-compression.d.ts.map +0 -1
- package/lib/common/image-compression.js +0 -153
- package/lib/common/image-compression.js.map +0 -1
- package/lib/common/mdc-parser.d.ts +0 -60
- package/lib/common/mdc-parser.d.ts.map +0 -1
- package/lib/common/mdc-parser.js +0 -246
- package/lib/common/mdc-parser.js.map +0 -1
- package/lib/common/prompts/system-prompt.d.ts +0 -2
- package/lib/common/prompts/system-prompt.d.ts.map +0 -1
- package/lib/common/prompts/system-prompt.js +0 -5
- package/lib/common/prompts/system-prompt.js.map +0 -1
- package/src/browser/rules/rules.contribution.ts +0 -105
- package/src/browser/rules/rules.module.less +0 -174
- package/src/browser/rules/rules.service.ts +0 -189
- package/src/browser/rules/rules.view.tsx +0 -127
- package/src/common/MDC_PARSER_README.md +0 -171
- package/src/common/image-compression.ts +0 -174
- package/src/common/mdc-parser.ts +0 -295
- package/src/common/prompts/system-prompt.ts +0 -2
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"rules.view.js","sourceRoot":"","sources":["../../../src/browser/rules/rules.view.tsx"],"names":[],"mappings":";;;;AAAA,uDAAgE;AAEhE,6DAAgD;AAChD,iEAA2D;AAC3D,+DAAwE;AAIxE,oFAAyC;AAGlC,MAAM,SAAS,GAAa,GAAG,EAAE;IACtC,MAAM,YAAY,GAAG,IAAA,gCAAa,EAAe,mCAAiB,CAAC,CAAC;IACpE,MAAM,CAAC,WAAW,EAAE,cAAc,CAAC,GAAG,IAAA,gBAAQ,EAAS,YAAY,CAAC,WAAqB,CAAC,CAAC;IAC3F,MAAM,CAAC,YAAY,EAAE,eAAe,CAAC,GAAG,IAAA,gBAAQ,EAAgB,EAAE,CAAC,CAAC;IAEpE,IAAA,iBAAS,EAAC,GAAG,EAAE;QACb,eAAe,CAAC,YAAY,CAAC,YAAY,CAAC,CAAC;IAC7C,CAAC,EAAE,CAAC,YAAY,CAAC,CAAC,CAAC;IAEnB,MAAM,uBAAuB,GAAG,IAAA,mBAAW,EACzC,CAAC,CAAC,EAAE,EAAE;QACJ,cAAc,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QAC/B,YAAY,CAAC,iBAAiB,CAAC,CAAC,CA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,EAAC,oCAAoC,CAAC,CAAO,CAC3F,CACG,CACF,CACF,CACP,CAAC;AACJ,CAAC,CAAC;AAnHW,QAAA,SAAS,aAmHpB"}
|
|
@@ -1,171 +0,0 @@
|
|
|
1
|
-
# MDC 文件解析器
|
|
2
|
-
|
|
3
|
-
MDC (Markdown with YAML Frontmatter) 解析器用于解析和序列化带有 YAML frontmatter 的 Markdown 文件。
|
|
4
|
-
|
|
5
|
-
## 文件格式
|
|
6
|
-
|
|
7
|
-
MDC 文件格式如下:
|
|
8
|
-
|
|
9
|
-
```
|
|
10
|
-
---
|
|
11
|
-
description:
|
|
12
|
-
globs:
|
|
13
|
-
alwaysApply: false
|
|
14
|
-
---
|
|
15
|
-
icejs is a react-like framework
|
|
16
|
-
```
|
|
17
|
-
|
|
18
|
-
其中:
|
|
19
|
-
|
|
20
|
-
- `---` 分隔符之间的部分是 YAML frontmatter
|
|
21
|
-
- 分隔符之后的部分是 Markdown 内容
|
|
22
|
-
|
|
23
|
-
## API 接口
|
|
24
|
-
|
|
25
|
-
### 类型定义
|
|
26
|
-
|
|
27
|
-
```typescript
|
|
28
|
-
interface IMDCFrontmatter {
|
|
29
|
-
description?: string;
|
|
30
|
-
globs?: string | string[];
|
|
31
|
-
alwaysApply?: boolean;
|
|
32
|
-
[key: string]: any;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
interface IMDCParseResult {
|
|
36
|
-
frontmatter: IMDCFrontmatter;
|
|
37
|
-
content: string;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
interface IMDCContent {
|
|
41
|
-
frontmatter: IMDCFrontmatter;
|
|
42
|
-
content: string;
|
|
43
|
-
}
|
|
44
|
-
```
|
|
45
|
-
|
|
46
|
-
### 主要函数
|
|
47
|
-
|
|
48
|
-
#### `parseMDC(rawContent: string): IMDCParseResult`
|
|
49
|
-
|
|
50
|
-
解析 MDC 文件内容,返回解析后的 frontmatter 和内容。
|
|
51
|
-
|
|
52
|
-
**示例:**
|
|
53
|
-
|
|
54
|
-
```typescript
|
|
55
|
-
const content = `---
|
|
56
|
-
description: "React规则"
|
|
57
|
-
globs: ["*.tsx", "*.jsx"]
|
|
58
|
-
alwaysApply: true
|
|
59
|
-
---
|
|
60
|
-
使用React hooks和函数组件`;
|
|
61
|
-
|
|
62
|
-
const result = parseMDC(content);
|
|
63
|
-
// result.frontmatter = { description: "React规则", globs: ["*.tsx", "*.jsx"], alwaysApply: true }
|
|
64
|
-
// result.content = "使用React hooks和函数组件"
|
|
65
|
-
```
|
|
66
|
-
|
|
67
|
-
#### `serializeMDC(mdcContent: IMDCContent): string`
|
|
68
|
-
|
|
69
|
-
将 MDC 内容对象序列化为字符串格式。
|
|
70
|
-
|
|
71
|
-
**示例:**
|
|
72
|
-
|
|
73
|
-
```typescript
|
|
74
|
-
const mdcContent = {
|
|
75
|
-
frontmatter: {
|
|
76
|
-
description: 'TypeScript规则',
|
|
77
|
-
globs: ['*.ts'],
|
|
78
|
-
alwaysApply: false,
|
|
79
|
-
},
|
|
80
|
-
content: '使用严格的类型检查',
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
const serialized = serializeMDC(mdcContent);
|
|
84
|
-
// 输出:
|
|
85
|
-
// ---
|
|
86
|
-
// description: TypeScript规则
|
|
87
|
-
// globs:
|
|
88
|
-
// - "*.ts"
|
|
89
|
-
// alwaysApply: false
|
|
90
|
-
// ---
|
|
91
|
-
// 使用严格的类型检查
|
|
92
|
-
```
|
|
93
|
-
|
|
94
|
-
#### `updateMDCFrontmatter(rawContent: string, newFrontmatter: Partial<IMDCFrontmatter>): string`
|
|
95
|
-
|
|
96
|
-
更新现有 MDC 内容的 frontmatter。
|
|
97
|
-
|
|
98
|
-
**示例:**
|
|
99
|
-
|
|
100
|
-
```typescript
|
|
101
|
-
const original = `---
|
|
102
|
-
description:
|
|
103
|
-
alwaysApply: false
|
|
104
|
-
---
|
|
105
|
-
原始内容`;
|
|
106
|
-
|
|
107
|
-
const updated = updateMDCFrontmatter(original, {
|
|
108
|
-
description: '更新后的描述',
|
|
109
|
-
globs: ['*.js'],
|
|
110
|
-
});
|
|
111
|
-
// 更新 frontmatter,保持原始内容不变
|
|
112
|
-
```
|
|
113
|
-
|
|
114
|
-
#### `extractMDCContent(rawContent: string): string`
|
|
115
|
-
|
|
116
|
-
从 MDC 内容中提取纯文本内容(不包含 frontmatter)。
|
|
117
|
-
|
|
118
|
-
**示例:**
|
|
119
|
-
|
|
120
|
-
```typescript
|
|
121
|
-
const content = extractMDCContent(mdcContent);
|
|
122
|
-
// 只返回 Markdown 内容部分
|
|
123
|
-
```
|
|
124
|
-
|
|
125
|
-
#### `validateMDCFrontmatter(frontmatter: any): boolean`
|
|
126
|
-
|
|
127
|
-
验证 frontmatter 对象是否符合规范。
|
|
128
|
-
|
|
129
|
-
#### `createDefaultMDCFrontmatter(): IMDCFrontmatter`
|
|
130
|
-
|
|
131
|
-
创建默认的 frontmatter 对象。
|
|
132
|
-
|
|
133
|
-
## 在 RulesService 中的使用
|
|
134
|
-
|
|
135
|
-
`RulesService` 类已经集成了 MDC 解析功能:
|
|
136
|
-
|
|
137
|
-
```typescript
|
|
138
|
-
// 解析全局规则
|
|
139
|
-
const mdcRules = rulesService.parseGlobalRulesAsMDC();
|
|
140
|
-
if (mdcRules) {
|
|
141
|
-
console.log('规则描述:', mdcRules.frontmatter.description);
|
|
142
|
-
console.log('适用文件:', mdcRules.frontmatter.globs);
|
|
143
|
-
console.log('规则内容:', mdcRules.content);
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
// 更新全局规则
|
|
147
|
-
const newMDCContent = {
|
|
148
|
-
frontmatter: {
|
|
149
|
-
description: '新的编码规范',
|
|
150
|
-
globs: ['src/**/*.ts'],
|
|
151
|
-
alwaysApply: true,
|
|
152
|
-
},
|
|
153
|
-
content: '遵循 TypeScript 最佳实践',
|
|
154
|
-
};
|
|
155
|
-
rulesService.updateGlobalRulesWithMDC(newMDCContent);
|
|
156
|
-
```
|
|
157
|
-
|
|
158
|
-
## 错误处理
|
|
159
|
-
|
|
160
|
-
解析器对错误具有良好的容错性:
|
|
161
|
-
|
|
162
|
-
- 如果 YAML frontmatter 格式错误,将返回空的 frontmatter 对象
|
|
163
|
-
- 如果没有 frontmatter,整个内容将作为 content 返回
|
|
164
|
-
- 序列化失败时,只返回内容部分
|
|
165
|
-
|
|
166
|
-
## 注意事项
|
|
167
|
-
|
|
168
|
-
1. frontmatter 中的 `globs` 字段可以是字符串或字符串数组
|
|
169
|
-
2. 所有 frontmatter 字段都是可选的
|
|
170
|
-
3. frontmatter 支持扩展,可以包含任意额外字段
|
|
171
|
-
4. 内容部分会自动去除首尾空白字符
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { IMCPToolResult } from './types';
|
|
2
|
-
export interface ImageCompressionOptions {
|
|
3
|
-
maxSizeKB?: number;
|
|
4
|
-
quality?: number;
|
|
5
|
-
maxWidth?: number;
|
|
6
|
-
maxHeight?: number;
|
|
7
|
-
mimeType?: string;
|
|
8
|
-
}
|
|
9
|
-
/**
|
|
10
|
-
* 获取 base64 图像的大小(KB)
|
|
11
|
-
*/
|
|
12
|
-
export declare function getBase64ImageSize(base64String: string): number;
|
|
13
|
-
/**
|
|
14
|
-
* 使用 Canvas API 进行真正的图像压缩
|
|
15
|
-
*/
|
|
16
|
-
export declare function compressBase64Image(base64String: string, options?: ImageCompressionOptions): Promise<string>;
|
|
17
|
-
/**
|
|
18
|
-
* 压缩内容数组格式的工具结果
|
|
19
|
-
*/
|
|
20
|
-
export declare function compressContentArrayResult(result: IMCPToolResult, options?: ImageCompressionOptions): Promise<IMCPToolResult>;
|
|
21
|
-
/**
|
|
22
|
-
* 智能压缩工具结果,支持多种格式
|
|
23
|
-
*/
|
|
24
|
-
export declare function compressToolResultSmart(result: IMCPToolResult, options?: ImageCompressionOptions): Promise<any>;
|
|
25
|
-
//# sourceMappingURL=image-compression.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"image-compression.d.ts","sourceRoot":"","sources":["../../src/common/image-compression.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAyB,MAAM,SAAS,CAAC;AAEhE,MAAM,WAAW,uBAAuB;IACtC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAUD;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,CAW/D;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,YAAY,EAAE,MAAM,EAAE,OAAO,GAAE,uBAA4B,GAAG,OAAO,CAAC,MAAM,CAAC,CA0EhH;AAED;;GAEG;AACH,wBAAsB,0BAA0B,CAC9C,MAAM,EAAE,cAAc,EACtB,OAAO,GAAE,uBAA4B,GACpC,OAAO,CAAC,cAAc,CAAC,CAgCzB;AAED;;GAEG;AACH,wBAAsB,uBAAuB,CAC3C,MAAM,EAAE,cAAc,EACtB,OAAO,GAAE,uBAA4B,GACpC,OAAO,CAAC,GAAG,CAAC,CAYd"}
|
|
@@ -1,153 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getBase64ImageSize = getBase64ImageSize;
|
|
4
|
-
exports.compressBase64Image = compressBase64Image;
|
|
5
|
-
exports.compressContentArrayResult = compressContentArrayResult;
|
|
6
|
-
exports.compressToolResultSmart = compressToolResultSmart;
|
|
7
|
-
const ide_utils_1 = require("@opensumi/ide-utils");
|
|
8
|
-
const DEFAULT_OPTIONS = {
|
|
9
|
-
maxSizeKB: 500, // 500KB
|
|
10
|
-
quality: 0.8,
|
|
11
|
-
maxWidth: 1920,
|
|
12
|
-
maxHeight: 1080,
|
|
13
|
-
mimeType: 'image/jpeg',
|
|
14
|
-
};
|
|
15
|
-
/**
|
|
16
|
-
* 获取 base64 图像的大小(KB)
|
|
17
|
-
*/
|
|
18
|
-
function getBase64ImageSize(base64String) {
|
|
19
|
-
if (!base64String) {
|
|
20
|
-
return 0;
|
|
21
|
-
}
|
|
22
|
-
// 移除 data URL 前缀
|
|
23
|
-
const base64Data = base64String.split(',')[1] || base64String;
|
|
24
|
-
// Base64 编码后的大小约为原始大小的 4/3
|
|
25
|
-
const sizeInBytes = (base64Data.length * 3) / 4;
|
|
26
|
-
return sizeInBytes / 1024; // 转换为 KB
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* 使用 Canvas API 进行真正的图像压缩
|
|
30
|
-
*/
|
|
31
|
-
function compressBase64Image(base64String, options = {}) {
|
|
32
|
-
return new Promise((resolve) => {
|
|
33
|
-
try {
|
|
34
|
-
// 输入验证
|
|
35
|
-
if (!base64String || typeof base64String !== 'string') {
|
|
36
|
-
resolve(base64String || '');
|
|
37
|
-
return;
|
|
38
|
-
}
|
|
39
|
-
if (!base64String.startsWith('data:') && options.mimeType) {
|
|
40
|
-
base64String = `data:${options.mimeType};base64,${base64String}`;
|
|
41
|
-
}
|
|
42
|
-
const opts = { ...DEFAULT_OPTIONS, ...options };
|
|
43
|
-
const currentSize = getBase64ImageSize(base64String);
|
|
44
|
-
// 如果图像已经小于目标大小,直接返回
|
|
45
|
-
if (currentSize <= opts.maxSizeKB) {
|
|
46
|
-
resolve(base64String);
|
|
47
|
-
return;
|
|
48
|
-
}
|
|
49
|
-
// 创建图像对象
|
|
50
|
-
const img = new Image();
|
|
51
|
-
img.onload = () => {
|
|
52
|
-
try {
|
|
53
|
-
// 计算新的尺寸,保持宽高比
|
|
54
|
-
let { width, height } = img;
|
|
55
|
-
// 处理极小图片
|
|
56
|
-
if (width <= 1 || height <= 1) {
|
|
57
|
-
resolve(base64String);
|
|
58
|
-
return;
|
|
59
|
-
}
|
|
60
|
-
const aspectRatio = width / height;
|
|
61
|
-
if (width > opts.maxWidth) {
|
|
62
|
-
width = opts.maxWidth;
|
|
63
|
-
height = width / aspectRatio;
|
|
64
|
-
}
|
|
65
|
-
if (height > opts.maxHeight) {
|
|
66
|
-
height = opts.maxHeight;
|
|
67
|
-
width = height * aspectRatio;
|
|
68
|
-
}
|
|
69
|
-
const canvas = document.createElement('canvas');
|
|
70
|
-
const ctx = canvas.getContext('2d');
|
|
71
|
-
if (!ctx) {
|
|
72
|
-
resolve(base64String);
|
|
73
|
-
return;
|
|
74
|
-
}
|
|
75
|
-
canvas.width = Math.round(width);
|
|
76
|
-
canvas.height = Math.round(height);
|
|
77
|
-
ctx.drawImage(img, 0, 0, canvas.width, canvas.height);
|
|
78
|
-
let compressedBase64 = canvas.toDataURL(opts.mimeType, opts.quality);
|
|
79
|
-
let compressedSize = getBase64ImageSize(compressedBase64);
|
|
80
|
-
let currentQuality = opts.quality;
|
|
81
|
-
let attempts = 0;
|
|
82
|
-
const maxAttempts = 5;
|
|
83
|
-
while (compressedSize > opts.maxSizeKB && attempts < maxAttempts) {
|
|
84
|
-
currentQuality *= 0.6;
|
|
85
|
-
compressedBase64 = canvas.toDataURL(opts.mimeType, currentQuality);
|
|
86
|
-
compressedSize = getBase64ImageSize(compressedBase64);
|
|
87
|
-
attempts++;
|
|
88
|
-
}
|
|
89
|
-
const [, base64] = compressedBase64.split(',');
|
|
90
|
-
resolve(base64);
|
|
91
|
-
}
|
|
92
|
-
catch (error) {
|
|
93
|
-
// 压缩失败,返回原始图像
|
|
94
|
-
resolve(base64String);
|
|
95
|
-
}
|
|
96
|
-
};
|
|
97
|
-
img.onerror = () => {
|
|
98
|
-
// 图像加载失败,返回原始字符串
|
|
99
|
-
resolve(base64String);
|
|
100
|
-
};
|
|
101
|
-
img.src = base64String;
|
|
102
|
-
}
|
|
103
|
-
catch (error) {
|
|
104
|
-
resolve(base64String);
|
|
105
|
-
}
|
|
106
|
-
});
|
|
107
|
-
}
|
|
108
|
-
/**
|
|
109
|
-
* 压缩内容数组格式的工具结果
|
|
110
|
-
*/
|
|
111
|
-
async function compressContentArrayResult(result, options = {}) {
|
|
112
|
-
if (!result || !result.content || !Array.isArray(result.content)) {
|
|
113
|
-
return result;
|
|
114
|
-
}
|
|
115
|
-
const compressedContent = await Promise.all(result.content.map(async (item) => {
|
|
116
|
-
if (item.type === 'image') {
|
|
117
|
-
let compressedData;
|
|
118
|
-
// 检测环境
|
|
119
|
-
if (typeof window !== 'undefined' && typeof document !== 'undefined') {
|
|
120
|
-
compressedData = await compressBase64Image(item.data, {
|
|
121
|
-
...options,
|
|
122
|
-
mimeType: item.mimeType,
|
|
123
|
-
});
|
|
124
|
-
}
|
|
125
|
-
else {
|
|
126
|
-
compressedData = item.data;
|
|
127
|
-
}
|
|
128
|
-
return {
|
|
129
|
-
...item,
|
|
130
|
-
data: compressedData,
|
|
131
|
-
};
|
|
132
|
-
}
|
|
133
|
-
return item;
|
|
134
|
-
}));
|
|
135
|
-
return {
|
|
136
|
-
...result,
|
|
137
|
-
content: compressedContent,
|
|
138
|
-
};
|
|
139
|
-
}
|
|
140
|
-
/**
|
|
141
|
-
* 智能压缩工具结果,支持多种格式
|
|
142
|
-
*/
|
|
143
|
-
async function compressToolResultSmart(result, options = {}) {
|
|
144
|
-
if (result &&
|
|
145
|
-
(0, ide_utils_1.isObject)(result) &&
|
|
146
|
-
result.content &&
|
|
147
|
-
Array.isArray(result.content) &&
|
|
148
|
-
result.content.some((item) => item.type === 'image')) {
|
|
149
|
-
return await compressContentArrayResult(result, options);
|
|
150
|
-
}
|
|
151
|
-
return result;
|
|
152
|
-
}
|
|
153
|
-
//# sourceMappingURL=image-compression.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"image-compression.js","sourceRoot":"","sources":["../../src/common/image-compression.ts"],"names":[],"mappings":";;AAuBA,gDAWC;AAKD,kDA0EC;AAKD,gEAmCC;AAKD,0DAeC;AA7KD,mDAA+C;AAY/C,MAAM,eAAe,GAAsC;IACzD,SAAS,EAAE,GAAG,E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AAC"}
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* MDC 文件的 frontmatter 接口定义
|
|
3
|
-
*/
|
|
4
|
-
export interface IMDCFrontmatter {
|
|
5
|
-
description?: string;
|
|
6
|
-
globs?: string | string[];
|
|
7
|
-
alwaysApply?: boolean;
|
|
8
|
-
[key: string]: any;
|
|
9
|
-
}
|
|
10
|
-
/**
|
|
11
|
-
* MDC 文件解析结果接口
|
|
12
|
-
*/
|
|
13
|
-
export interface IMDCParseResult {
|
|
14
|
-
frontmatter: IMDCFrontmatter;
|
|
15
|
-
content: string;
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* MDC 文件内容结构
|
|
19
|
-
*/
|
|
20
|
-
export interface IMDCContent {
|
|
21
|
-
frontmatter: IMDCFrontmatter;
|
|
22
|
-
content: string;
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* 解析 .mdc 文件内容
|
|
26
|
-
* @param rawContent - 原始文件内容
|
|
27
|
-
* @returns 解析后的结果,包含 frontmatter 和 content
|
|
28
|
-
*/
|
|
29
|
-
export declare function parseMDC(rawContent: string): IMDCParseResult;
|
|
30
|
-
/**
|
|
31
|
-
* 序列化 MDC 内容为字符串
|
|
32
|
-
* @param mdcContent - MDC 内容对象
|
|
33
|
-
* @returns 序列化后的字符串
|
|
34
|
-
*/
|
|
35
|
-
export declare function serializeMDC(mdcContent: IMDCContent): string;
|
|
36
|
-
/**
|
|
37
|
-
* 验证 MDC frontmatter 是否有效
|
|
38
|
-
* @param frontmatter - 要验证的 frontmatter 对象
|
|
39
|
-
* @returns 验证结果
|
|
40
|
-
*/
|
|
41
|
-
export declare function validateMDCFrontmatter(frontmatter: any): frontmatter is IMDCFrontmatter;
|
|
42
|
-
/**
|
|
43
|
-
* 创建默认的 MDC frontmatter
|
|
44
|
-
* @returns 默认的 frontmatter 对象
|
|
45
|
-
*/
|
|
46
|
-
export declare function createDefaultMDCFrontmatter(): IMDCFrontmatter;
|
|
47
|
-
/**
|
|
48
|
-
* 更新 MDC 文件的 frontmatter
|
|
49
|
-
* @param rawContent - 原始文件内容
|
|
50
|
-
* @param newFrontmatter - 新的 frontmatter
|
|
51
|
-
* @returns 更新后的文件内容
|
|
52
|
-
*/
|
|
53
|
-
export declare function updateMDCFrontmatter(rawContent: string, newFrontmatter: Partial<IMDCFrontmatter>): string;
|
|
54
|
-
/**
|
|
55
|
-
* 从 MDC 内容中提取纯文本内容(不包含 frontmatter)
|
|
56
|
-
* @param rawContent - 原始文件内容
|
|
57
|
-
* @returns 纯文本内容
|
|
58
|
-
*/
|
|
59
|
-
export declare function extractMDCContent(rawContent: string): string;
|
|
60
|
-
//# sourceMappingURL=mdc-parser.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"mdc-parser.d.ts","sourceRoot":"","sources":["../../src/common/mdc-parser.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IAC1B,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACpB;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,WAAW,EAAE,eAAe,CAAC;IAC7B,OAAO,EAAE,MAAM,CAAC;CACjB;AAED;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,WAAW,EAAE,eAAe,CAAC;IAC7B,OAAO,EAAE,MAAM,CAAC;CACjB;AA8ID;;;;GAIG;AACH,wBAAgB,QAAQ,CAAC,UAAU,EAAE,MAAM,GAAG,eAAe,CA4B5D;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,UAAU,EAAE,WAAW,GAAG,MAAM,CAiB5D;AAED;;;;GAIG;AACH,wBAAgB,sBAAsB,CAAC,WAAW,EAAE,GAAG,GAAG,WAAW,IAAI,eAAe,CA0BvF;AAED;;;GAGG;AACH,wBAAgB,2BAA2B,IAAI,eAAe,CAM7D;AAED;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAAC,UAAU,EAAE,MAAM,EAAE,cAAc,EAAE,OAAO,CAAC,eAAe,CAAC,GAAG,MAAM,CAQzG;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,CAG5D"}
|
package/lib/common/mdc-parser.js
DELETED
|
@@ -1,246 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.parseMDC = parseMDC;
|
|
4
|
-
exports.serializeMDC = serializeMDC;
|
|
5
|
-
exports.validateMDCFrontmatter = validateMDCFrontmatter;
|
|
6
|
-
exports.createDefaultMDCFrontmatter = createDefaultMDCFrontmatter;
|
|
7
|
-
exports.updateMDCFrontmatter = updateMDCFrontmatter;
|
|
8
|
-
exports.extractMDCContent = extractMDCContent;
|
|
9
|
-
/**
|
|
10
|
-
* 解析简单的 YAML 值
|
|
11
|
-
* @param value - 要解析的值字符串
|
|
12
|
-
* @returns 解析后的值
|
|
13
|
-
*/
|
|
14
|
-
function parseYamlValue(value) {
|
|
15
|
-
const trimmed = value.trim();
|
|
16
|
-
// 布尔值
|
|
17
|
-
if (trimmed === 'true') {
|
|
18
|
-
return true;
|
|
19
|
-
}
|
|
20
|
-
if (trimmed === 'false') {
|
|
21
|
-
return false;
|
|
22
|
-
}
|
|
23
|
-
// null/undefined
|
|
24
|
-
if (trimmed === 'null' || trimmed === '~' || trimmed === '') {
|
|
25
|
-
return null;
|
|
26
|
-
}
|
|
27
|
-
// 数字
|
|
28
|
-
if (/^-?\d+(\.\d+)?$/.test(trimmed)) {
|
|
29
|
-
return trimmed.includes('.') ? parseFloat(trimmed) : parseInt(trimmed, 10);
|
|
30
|
-
}
|
|
31
|
-
// 数组 (简单格式: [item1, item2, item3] 或 - item 格式)
|
|
32
|
-
if (trimmed.startsWith('[') && trimmed.endsWith(']')) {
|
|
33
|
-
const arrayContent = trimmed.slice(1, -1).trim();
|
|
34
|
-
if (!arrayContent) {
|
|
35
|
-
return [];
|
|
36
|
-
}
|
|
37
|
-
return arrayContent.split(',').map((item) => parseYamlValue(item));
|
|
38
|
-
}
|
|
39
|
-
// 字符串 (移除引号)
|
|
40
|
-
if ((trimmed.startsWith('"') && trimmed.endsWith('"')) || (trimmed.startsWith("'") && trimmed.endsWith("'"))) {
|
|
41
|
-
return trimmed.slice(1, -1);
|
|
42
|
-
}
|
|
43
|
-
// 默认作为字符串处理
|
|
44
|
-
return trimmed;
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* 按行解析 YAML frontmatter
|
|
48
|
-
* @param frontmatterStr - frontmatter 字符串
|
|
49
|
-
* @returns 解析后的对象
|
|
50
|
-
*/
|
|
51
|
-
function parseFrontmatterByLine(frontmatterStr) {
|
|
52
|
-
const result = {};
|
|
53
|
-
const lines = frontmatterStr.split('\n');
|
|
54
|
-
let currentKey = null;
|
|
55
|
-
let arrayItems = [];
|
|
56
|
-
let isInArray = false;
|
|
57
|
-
for (const line of lines) {
|
|
58
|
-
const trimmedLine = line.trim();
|
|
59
|
-
// 跳过空行和注释
|
|
60
|
-
if (!trimmedLine || trimmedLine.startsWith('#')) {
|
|
61
|
-
continue;
|
|
62
|
-
}
|
|
63
|
-
// 检查是否是数组项 (以 - 开头)
|
|
64
|
-
if (trimmedLine.startsWith('- ')) {
|
|
65
|
-
if (currentKey && isInArray) {
|
|
66
|
-
arrayItems.push(trimmedLine.slice(2).trim());
|
|
67
|
-
}
|
|
68
|
-
continue;
|
|
69
|
-
}
|
|
70
|
-
// 如果之前在处理数组,现在遇到新的键值对,先保存数组
|
|
71
|
-
if (isInArray && currentKey) {
|
|
72
|
-
result[currentKey] = arrayItems.map((item) => parseYamlValue(item));
|
|
73
|
-
arrayItems = [];
|
|
74
|
-
isInArray = false;
|
|
75
|
-
currentKey = null;
|
|
76
|
-
}
|
|
77
|
-
// 解析键值对
|
|
78
|
-
const colonIndex = trimmedLine.indexOf(':');
|
|
79
|
-
if (colonIndex === -1) {
|
|
80
|
-
continue;
|
|
81
|
-
}
|
|
82
|
-
const key = trimmedLine.slice(0, colonIndex).trim();
|
|
83
|
-
const value = trimmedLine.slice(colonIndex + 1).trim();
|
|
84
|
-
currentKey = key;
|
|
85
|
-
if (value) {
|
|
86
|
-
result[key] = parseYamlValue(value);
|
|
87
|
-
isInArray = false;
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
// 处理最后的数组
|
|
91
|
-
if (isInArray && currentKey) {
|
|
92
|
-
result[currentKey] = arrayItems.map((item) => parseYamlValue(item));
|
|
93
|
-
}
|
|
94
|
-
return result;
|
|
95
|
-
}
|
|
96
|
-
/**
|
|
97
|
-
* 序列化对象为简单的 YAML 格式
|
|
98
|
-
* @param obj - 要序列化的对象
|
|
99
|
-
* @returns YAML 字符串
|
|
100
|
-
*/
|
|
101
|
-
function serializeToYaml(obj) {
|
|
102
|
-
const lines = [];
|
|
103
|
-
for (const [key, value] of Object.entries(obj)) {
|
|
104
|
-
if (value === null || value === undefined) {
|
|
105
|
-
lines.push(`${key}:`);
|
|
106
|
-
}
|
|
107
|
-
else if (Array.isArray(value)) {
|
|
108
|
-
if (value.length === 0) {
|
|
109
|
-
lines.push(`${key}: []`);
|
|
110
|
-
}
|
|
111
|
-
else {
|
|
112
|
-
lines.push(`${key}:`);
|
|
113
|
-
for (const item of value) {
|
|
114
|
-
lines.push(` - ${typeof item === 'string' ? item : JSON.stringify(item)}`);
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
else if (typeof value === 'string') {
|
|
119
|
-
// 如果字符串包含特殊字符或空格,使用引号
|
|
120
|
-
if (value.includes(':') || value.includes('#') || value.includes('\n') || value.trim() !== value) {
|
|
121
|
-
lines.push(`${key}: "${value.replace(/"/g, '\\"')}"`);
|
|
122
|
-
}
|
|
123
|
-
else {
|
|
124
|
-
lines.push(`${key}: ${value}`);
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
else {
|
|
128
|
-
lines.push(`${key}: ${value}`);
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
return lines.join('\n');
|
|
132
|
-
}
|
|
133
|
-
/**
|
|
134
|
-
* 解析 .mdc 文件内容
|
|
135
|
-
* @param rawContent - 原始文件内容
|
|
136
|
-
* @returns 解析后的结果,包含 frontmatter 和 content
|
|
137
|
-
*/
|
|
138
|
-
function parseMDC(rawContent) {
|
|
139
|
-
const frontmatterRegex = /^---\s*\n([\s\S]*?)\n---\s*\n?([\s\S]*)$/;
|
|
140
|
-
const match = rawContent.match(frontmatterRegex);
|
|
141
|
-
if (!match) {
|
|
142
|
-
// 如果没有 frontmatter,整个内容作为 content
|
|
143
|
-
return {
|
|
144
|
-
frontmatter: {},
|
|
145
|
-
content: rawContent.trim(),
|
|
146
|
-
};
|
|
147
|
-
}
|
|
148
|
-
const [, frontmatterStr, content] = match;
|
|
149
|
-
let frontmatter = {};
|
|
150
|
-
try {
|
|
151
|
-
// 按行解析 YAML frontmatter
|
|
152
|
-
frontmatter = parseFrontmatterByLine(frontmatterStr);
|
|
153
|
-
}
|
|
154
|
-
catch (error) {
|
|
155
|
-
// 如果解析失败,返回空的 frontmatter
|
|
156
|
-
frontmatter = {};
|
|
157
|
-
}
|
|
158
|
-
return {
|
|
159
|
-
frontmatter,
|
|
160
|
-
content: content.trim(),
|
|
161
|
-
};
|
|
162
|
-
}
|
|
163
|
-
/**
|
|
164
|
-
* 序列化 MDC 内容为字符串
|
|
165
|
-
* @param mdcContent - MDC 内容对象
|
|
166
|
-
* @returns 序列化后的字符串
|
|
167
|
-
*/
|
|
168
|
-
function serializeMDC(mdcContent) {
|
|
169
|
-
const { frontmatter, content } = mdcContent;
|
|
170
|
-
// 如果 frontmatter 为空或没有有效内容,只返回 content
|
|
171
|
-
if (!frontmatter || Object.keys(frontmatter).length === 0) {
|
|
172
|
-
return content;
|
|
173
|
-
}
|
|
174
|
-
try {
|
|
175
|
-
// 序列化 frontmatter 为 YAML
|
|
176
|
-
const frontmatterStr = serializeToYaml(frontmatter);
|
|
177
|
-
return `---\n${frontmatterStr}\n---\n${content}`;
|
|
178
|
-
}
|
|
179
|
-
catch (error) {
|
|
180
|
-
// 如果序列化失败,只返回 content
|
|
181
|
-
return content;
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
/**
|
|
185
|
-
* 验证 MDC frontmatter 是否有效
|
|
186
|
-
* @param frontmatter - 要验证的 frontmatter 对象
|
|
187
|
-
* @returns 验证结果
|
|
188
|
-
*/
|
|
189
|
-
function validateMDCFrontmatter(frontmatter) {
|
|
190
|
-
if (typeof frontmatter !== 'object' || frontmatter === null) {
|
|
191
|
-
return false;
|
|
192
|
-
}
|
|
193
|
-
// 可选的字段类型检查
|
|
194
|
-
if (frontmatter.description !== undefined && typeof frontmatter.description !== 'string') {
|
|
195
|
-
return false;
|
|
196
|
-
}
|
|
197
|
-
if (frontmatter.globs !== undefined) {
|
|
198
|
-
if (typeof frontmatter.globs !== 'string' && !Array.isArray(frontmatter.globs)) {
|
|
199
|
-
return false;
|
|
200
|
-
}
|
|
201
|
-
if (Array.isArray(frontmatter.globs)) {
|
|
202
|
-
if (!frontmatter.globs.every((glob) => typeof glob === 'string')) {
|
|
203
|
-
return false;
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
if (frontmatter.alwaysApply !== undefined && typeof frontmatter.alwaysApply !== 'boolean') {
|
|
208
|
-
return false;
|
|
209
|
-
}
|
|
210
|
-
return true;
|
|
211
|
-
}
|
|
212
|
-
/**
|
|
213
|
-
* 创建默认的 MDC frontmatter
|
|
214
|
-
* @returns 默认的 frontmatter 对象
|
|
215
|
-
*/
|
|
216
|
-
function createDefaultMDCFrontmatter() {
|
|
217
|
-
return {
|
|
218
|
-
description: '',
|
|
219
|
-
globs: '',
|
|
220
|
-
alwaysApply: false,
|
|
221
|
-
};
|
|
222
|
-
}
|
|
223
|
-
/**
|
|
224
|
-
* 更新 MDC 文件的 frontmatter
|
|
225
|
-
* @param rawContent - 原始文件内容
|
|
226
|
-
* @param newFrontmatter - 新的 frontmatter
|
|
227
|
-
* @returns 更新后的文件内容
|
|
228
|
-
*/
|
|
229
|
-
function updateMDCFrontmatter(rawContent, newFrontmatter) {
|
|
230
|
-
const parsed = parseMDC(rawContent);
|
|
231
|
-
const updatedFrontmatter = { ...parsed.frontmatter, ...newFrontmatter };
|
|
232
|
-
return serializeMDC({
|
|
233
|
-
frontmatter: updatedFrontmatter,
|
|
234
|
-
content: parsed.content,
|
|
235
|
-
});
|
|
236
|
-
}
|
|
237
|
-
/**
|
|
238
|
-
* 从 MDC 内容中提取纯文本内容(不包含 frontmatter)
|
|
239
|
-
* @param rawContent - 原始文件内容
|
|
240
|
-
* @returns 纯文本内容
|
|
241
|
-
*/
|
|
242
|
-
function extractMDCContent(rawContent) {
|
|
243
|
-
const parsed = parseMDC(rawContent);
|
|
244
|
-
return parsed.content;
|
|
245
|
-
}
|
|
246
|
-
//# sourceMappingURL=mdc-parser.js.map
|