@tencentcloud/sdk-mcp 1.6.8 → 1.7.1

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 (158) hide show
  1. package/CHANGELOG.md +36 -0
  2. package/README.md +59 -35
  3. package/knowledge/build-index.js +28 -4
  4. package/knowledge/chunker.js +82 -14
  5. package/knowledge/chunking-policy.js +100 -0
  6. package/knowledge/doc-url-resolver.js +70 -19
  7. package/knowledge/frontmatter-meta.js +167 -0
  8. package/knowledge/path-meta.js +28 -6
  9. package/knowledge/search/exact-lookup.js +126 -125
  10. package/knowledge/search/filter-pool.js +12 -29
  11. package/knowledge/search/framework-fallback.js +22 -0
  12. package/knowledge/search/intent-router.js +29 -0
  13. package/knowledge/search/l1-enrich.js +159 -0
  14. package/knowledge/search/query-normalizer.js +63 -3
  15. package/knowledge/search/search-core.js +410 -0
  16. package/knowledge/search/search-knowledge.js +419 -377
  17. package/knowledge/search/search-message.js +88 -0
  18. package/knowledge/search/search-pass.js +428 -0
  19. package/knowledge/search/search-types.js +1 -0
  20. package/knowledge/search/url-row-idf.js +120 -0
  21. package/knowledge/search/url-row-scorer.js +337 -0
  22. package/package.json +3 -1
  23. package/resource/index/manifest.json +1 -1
  24. package/resource/integration/callkit/preset/flutter/integration.md +7 -3
  25. package/resource/integration/callkit/preset/ios/integration.md +1 -0
  26. package/resource/integration/chat/preset/android/integration.md +1 -0
  27. package/resource/integration/chat/preset/flutter/integration.md +111 -10
  28. package/resource/integration/chat/preset/ios/integration.md +1 -0
  29. package/resource/integration/chat/preset/react/integration.md +1 -0
  30. package/resource/integration/chat/preset/uni-app/integration.md +1 -0
  31. package/resource/integration/chat/preset/vue/integration.md +1 -0
  32. package/resource/integration/livekit/preset/live/android/prepare-integration.md +1 -0
  33. package/resource/integration/livekit/preset/live/vue/live-player-desk-integration.md +12 -10
  34. package/resource/integration/livekit/preset/live/vue/live-pusher-integration.md +14 -14
  35. package/resource/integration/roomkit/preset/vue/integration.md +1 -0
  36. package/resource/knowledge/callkit/best-practice/callkit-miniprogram/uniapp-shrink.md +64 -0
  37. package/resource/knowledge/callkit/best-practice/common/call-autoplay-blocked.md +81 -0
  38. package/resource/knowledge/callkit/best-practice/common/call-message-in-chat.md +84 -0
  39. package/resource/knowledge/callkit/best-practice/common/call-vs-calls.md +114 -0
  40. package/resource/knowledge/callkit/best-practice/common/callengine-call-flow.md +128 -0
  41. package/resource/knowledge/callkit/best-practice/common/callengine-log-level.md +72 -0
  42. package/resource/knowledge/callkit/best-practice/common/callkit-get-engine-instance.md +87 -0
  43. package/resource/knowledge/callkit/best-practice/common/callkit-get-roomid.md +83 -0
  44. package/resource/knowledge/callkit/best-practice/common/callkit-limitations.md +37 -0
  45. package/resource/knowledge/callkit/best-practice/common/callkit-user-register-and-kicked.md +103 -0
  46. package/resource/knowledge/callkit/core-sdk/android/answer-call.md +1 -0
  47. package/resource/knowledge/callkit/core-sdk/android/make-call.md +1 -0
  48. package/resource/knowledge/callkit/core-sdk/flutter/answer-call.md +1 -0
  49. package/resource/knowledge/callkit/core-sdk/flutter/make-call.md +1 -0
  50. package/resource/knowledge/callkit/core-sdk/ios/answer-call.md +1 -0
  51. package/resource/knowledge/callkit/core-sdk/ios/make-call.md +1 -0
  52. package/resource/knowledge/callkit/core-sdk/ios/offline-push.md +1 -1
  53. package/resource/knowledge/callkit/core-sdk/uni-app/answer-call.md +1 -0
  54. package/resource/knowledge/callkit/core-sdk/uni-app/make-call.md +1 -0
  55. package/resource/knowledge/callkit/faq/flutter.md +1 -0
  56. package/resource/knowledge/callkit/faq/uniapp-app.md +1 -0
  57. package/resource/knowledge/callkit/preset/react/api.md +1 -150
  58. package/resource/knowledge/callkit/preset/vue/api.md +1 -38
  59. package/resource/knowledge/chat/best-practice/common/avchatroom-message-loss-diagnosis.md +71 -0
  60. package/resource/knowledge/chat/best-practice/common/group-conversation-cleanup-on-system-notice.md +67 -0
  61. package/resource/knowledge/chat/best-practice/common/image-message-url-lifecycle.md +63 -0
  62. package/resource/knowledge/chat/best-practice/common/login-repeat-2025-diagnosis.md +65 -0
  63. package/resource/knowledge/chat/best-practice/common/message-read-report-and-receipt.md +72 -0
  64. package/resource/knowledge/chat/best-practice/common/message-receive-event.md +70 -0
  65. package/resource/knowledge/chat/best-practice/common/message-risk-error-and-render.md +69 -0
  66. package/resource/knowledge/chat/best-practice/common/message-unread-count.md +71 -0
  67. package/resource/knowledge/chat/best-practice/miniprogram/audio-message-send.md +118 -0
  68. package/resource/knowledge/chat/best-practice/miniprogram/login-timeout-2801-diagnosis.md +67 -0
  69. package/resource/knowledge/chat/best-practice/miniprogram/media-upload-fail-diagnosis.md +68 -0
  70. package/resource/knowledge/chat/best-practice/web/audio-message-send.md +123 -0
  71. package/resource/knowledge/chat/preset/android/features/conversation-list.md +1 -0
  72. package/resource/knowledge/chat/preset/android/features/language.md +1 -0
  73. package/resource/knowledge/chat/preset/android/features/message-input.md +1 -0
  74. package/resource/knowledge/chat/preset/android/features/message-list.md +1 -0
  75. package/resource/knowledge/chat/preset/android-view/integration.md +1 -0
  76. package/resource/knowledge/chat/preset/flutter/features/conversation-list.md +1 -0
  77. package/resource/knowledge/chat/preset/flutter/features/message-input.md +1 -0
  78. package/resource/knowledge/chat/preset/flutter/features/message-list.md +1 -0
  79. package/resource/knowledge/chat/preset/ios/features/conversation-list.md +1 -0
  80. package/resource/knowledge/chat/preset/ios/features/message-input.md +1 -0
  81. package/resource/knowledge/chat/preset/ios/features/message-list.md +1 -0
  82. package/resource/knowledge/chat/preset/ios-uikit/integration.md +1 -0
  83. package/resource/knowledge/chat/preset/react/features/conversation-preview.md +1 -0
  84. package/resource/knowledge/chat/preset/react/features/message-input.md +61 -3
  85. package/resource/knowledge/chat/preset/react/features/message-list.md +7 -0
  86. package/resource/knowledge/chat/preset/vue/features/message-input.md +58 -5
  87. package/resource/knowledge/chat/preset/vue/features/message-list.md +7 -0
  88. package/resource/knowledge/chat/urls/product.md +8 -8
  89. package/resource/knowledge/chat/urls/restapi.md +3 -3
  90. package/resource/knowledge/chat/urls/sdk/android.md +5 -5
  91. package/resource/knowledge/chat/urls/sdk/flutter.md +5 -5
  92. package/resource/knowledge/chat/urls/sdk/ios.md +5 -5
  93. package/resource/knowledge/chat/urls/sdk/web.md +8 -8
  94. package/resource/knowledge/chat/urls/webhook.md +11 -17
  95. package/resource/knowledge/livekit/best-practice/android/voice-room-anchor-start.md +124 -0
  96. package/resource/knowledge/livekit/best-practice/common/admin-take-seat.md +73 -0
  97. package/resource/knowledge/livekit/best-practice/common/audience-leave-live.md +81 -0
  98. package/resource/knowledge/livekit/best-practice/common/voice-room-no-audio-troubleshoot.md +100 -0
  99. package/resource/knowledge/livekit/best-practice/common/voice-room-seat-list-change.md +65 -0
  100. package/resource/knowledge/livekit/best-practice/flutter/voice-room-anchor-start.md +126 -0
  101. package/resource/knowledge/livekit/best-practice/ios/voice-room-anchor-start.md +130 -0
  102. package/resource/knowledge/push/config/harmonyos.md +1 -1
  103. package/resource/knowledge/push/config/ios.md +2 -2
  104. package/resource/knowledge/push/config/react-native.md +1 -0
  105. package/resource/knowledge/push/config/unity.md +1 -0
  106. package/resource/knowledge/push/config/unreal-engine.md +1 -0
  107. package/resource/knowledge/push/integration/android.md +17 -16
  108. package/resource/knowledge/push/integration/donut.md +2 -2
  109. package/resource/knowledge/push/integration/flutter.md +4 -3
  110. package/resource/knowledge/push/integration/harmonyos.md +1 -1
  111. package/resource/knowledge/push/integration/ios.md +4 -3
  112. package/resource/knowledge/push/integration/react-native.md +1 -1
  113. package/resource/knowledge/push/integration/uni-app.md +1 -0
  114. package/resource/knowledge/push/integration/unity.md +4 -4
  115. package/resource/knowledge/push/integration/unreal-engine.md +37 -35
  116. package/resource/knowledge/roomkit/best-practice/common/room-ghost-member.md +75 -0
  117. package/resource/knowledge/roomkit/best-practice/common/room-limit-and-multi.md +88 -0
  118. package/resource/knowledge/roomkit/best-practice/common/room-screen-share-preview.md +87 -0
  119. package/resource/knowledge/roomkit/best-practice/common/room-status-after-all-leave.md +73 -0
  120. package/resource/knowledge/roomkit/best-practice/vue/room-uikit-vs-atomicx.md +115 -0
  121. package/resource/knowledge/roomkit/core-sdk/android/call-user-to-room.md +1 -0
  122. package/resource/knowledge/roomkit/core-sdk/android/room-participant-state.md +1 -0
  123. package/resource/knowledge/roomkit/core-sdk/android/room-state.md +1 -0
  124. package/resource/knowledge/roomkit/core-sdk/android/schedule-room.md +1 -0
  125. package/resource/knowledge/roomkit/core-sdk/flutter/call-user-to-room.md +1 -0
  126. package/resource/knowledge/roomkit/core-sdk/flutter/room-participant-state.md +1 -0
  127. package/resource/knowledge/roomkit/core-sdk/flutter/room-state.md +1 -0
  128. package/resource/knowledge/roomkit/core-sdk/flutter/schedule-room.md +1 -0
  129. package/resource/knowledge/roomkit/core-sdk/ios/call-user-to-room.md +1 -0
  130. package/resource/knowledge/roomkit/core-sdk/ios/room-participant-state.md +1 -0
  131. package/resource/knowledge/roomkit/core-sdk/ios/room-state.md +1 -0
  132. package/resource/knowledge/roomkit/core-sdk/ios/schedule-room.md +1 -0
  133. package/resource/knowledge/roomkit/core-sdk/vue/room-view.md +1 -0
  134. package/resource/knowledge/roomkit/preset/react/integration.md +1 -0
  135. package/resource/knowledge/rtcengine/web/plugin/30-advanced-cross-room-link.md +2 -0
  136. package/resource/knowledge/rtcengine/web/plugin/39-advanced-video-decoder.md +2 -0
  137. package/resource/knowledge/trtc/android/TRTCCloud.md +1 -0
  138. package/resource/knowledge/trtc/c++/ITRTCCloud.md +1 -0
  139. package/resource/knowledge/trtc/ios/TRTCCloud.md +1 -0
  140. package/server.js +9 -4
  141. package/streamable-http.js +19 -54
  142. package/tools/common/search_trtc_knowledge.js +24 -12
  143. package/tools/definitions/finalize_answer_def.js +2 -2
  144. package/tools/definitions/integration-boundary.js +2 -1
  145. package/tools/definitions/search_trtc_knowledge_def.js +5 -3
  146. package/utils/fetch-doc-content.js +198 -0
  147. package/utils/preflight-route.js +197 -0
  148. package/utils/report-cls-client.js +1 -1
  149. package/utils/report-es-client.js +1 -1
  150. package/cursor-setting.png +0 -0
  151. package/mcp-server-prompt.png +0 -0
  152. package/resource/knowledge/callkit/best-practice/web/callengine-invitation.md +0 -80
  153. package/resource/knowledge/callkit/best-practice/web/callengine-log-control.md +0 -20
  154. package/resource/knowledge/callkit/best-practice/web/callkit-call-vs-calls.md +0 -116
  155. package/resource/knowledge/callkit/preset/react/uikit-api-reference.md +0 -469
  156. package/resource/knowledge/callkit/preset/vue/uikit-api-reference.md +0 -581
  157. package/resource/knowledge/callkit/preset/web/api.md +0 -79
  158. package/resource/knowledge/chat/best-practice/web/image-message-url-handling.md +0 -16
@@ -0,0 +1,167 @@
1
+ import * as yaml from 'js-yaml';
2
+ const FRONTMATTER_RE = /^\uFEFF?---\r?\n([\s\S]*?)\r?\n---\r?\n?/;
3
+ function uniq(arr) {
4
+ return [...new Set(arr)];
5
+ }
6
+ function normalizeString(value) {
7
+ if (typeof value !== 'string')
8
+ return undefined;
9
+ const normalized = value.trim();
10
+ return normalized ? normalized : undefined;
11
+ }
12
+ function normalizeStringArray(value) {
13
+ if (Array.isArray(value)) {
14
+ const normalized = value
15
+ .map((item) => (typeof item === 'string' ? item.trim() : ''))
16
+ .filter(Boolean);
17
+ return normalized.length ? uniq(normalized) : undefined;
18
+ }
19
+ if (typeof value === 'string') {
20
+ const normalized = value
21
+ .split(',')
22
+ .map((item) => item.trim())
23
+ .filter(Boolean);
24
+ return normalized.length ? uniq(normalized) : undefined;
25
+ }
26
+ return undefined;
27
+ }
28
+ function normalizeScenario(value) {
29
+ if (value === 'live' || value === 'voice')
30
+ return value;
31
+ return undefined;
32
+ }
33
+ function normalizeVariant(value) {
34
+ if (value === 'core-sdk' || value === 'preset')
35
+ return value;
36
+ return undefined;
37
+ }
38
+ function normalizeDocKind(value) {
39
+ if (value === 'capability_matrix' || value === 'unsupported_summary' || value === 'negative_faq') {
40
+ return value;
41
+ }
42
+ return undefined;
43
+ }
44
+ function normalizeCapabilityStatus(value) {
45
+ if (value === 'supported' || value === 'unsupported' || value === 'partial' || value === 'version_gated') {
46
+ return value;
47
+ }
48
+ return undefined;
49
+ }
50
+ function normalizeRetrievableScope(value) {
51
+ if (value === 'always')
52
+ return 'always';
53
+ return normalizeStringArray(value);
54
+ }
55
+ function parseFrontmatterObject(input) {
56
+ if (!input || typeof input !== 'object' || Array.isArray(input)) {
57
+ return {};
58
+ }
59
+ return input;
60
+ }
61
+ export function resolveFrontmatterMeta(rawMarkdown) {
62
+ const match = rawMarkdown.match(FRONTMATTER_RE);
63
+ if (!match) {
64
+ return {
65
+ content: rawMarkdown,
66
+ contentOffset: 0,
67
+ hasFrontmatter: false,
68
+ frontmatterMeta: {},
69
+ overrideFields: [],
70
+ };
71
+ }
72
+ const rawBlock = match[1] ?? '';
73
+ const contentOffset = match[0].length;
74
+ const content = rawMarkdown.slice(contentOffset);
75
+ let parsed;
76
+ try {
77
+ parsed = yaml.load(rawBlock);
78
+ }
79
+ catch (error) {
80
+ const parseError = error instanceof Error ? error.message : String(error);
81
+ return {
82
+ content,
83
+ contentOffset,
84
+ hasFrontmatter: true,
85
+ parseError,
86
+ frontmatterMeta: {},
87
+ overrideFields: [],
88
+ };
89
+ }
90
+ const fm = parseFrontmatterObject(parsed);
91
+ const frontmatterMeta = {};
92
+ const overrideFields = [];
93
+ const product = normalizeString(fm.product);
94
+ if (product) {
95
+ frontmatterMeta.product = product;
96
+ overrideFields.push('product');
97
+ }
98
+ const framework = normalizeStringArray(fm.frameworks) ?? normalizeStringArray(fm.framework);
99
+ if (framework?.length) {
100
+ frontmatterMeta.framework = framework;
101
+ overrideFields.push('framework');
102
+ }
103
+ const types = normalizeStringArray(fm.types);
104
+ if (types?.length) {
105
+ frontmatterMeta.types = types;
106
+ overrideFields.push('types');
107
+ }
108
+ const scenario = normalizeScenario(fm.scenario);
109
+ if (scenario !== undefined) {
110
+ frontmatterMeta.scenario = scenario;
111
+ overrideFields.push('scenario');
112
+ }
113
+ const variant = normalizeVariant(fm.variant);
114
+ if (variant) {
115
+ frontmatterMeta.variant = variant;
116
+ overrideFields.push('variant');
117
+ }
118
+ const scope = normalizeString(fm.scope);
119
+ if (scope) {
120
+ frontmatterMeta.scope = scope;
121
+ overrideFields.push('scope');
122
+ }
123
+ const docKind = normalizeDocKind(fm.doc_kind);
124
+ if (docKind) {
125
+ frontmatterMeta.doc_kind = docKind;
126
+ overrideFields.push('doc_kind');
127
+ }
128
+ const capabilityStatus = normalizeCapabilityStatus(fm.capability_status);
129
+ if (capabilityStatus) {
130
+ frontmatterMeta.capability_status = capabilityStatus;
131
+ overrideFields.push('capability_status');
132
+ }
133
+ const retrievableScope = normalizeRetrievableScope(fm.retrievable_scope);
134
+ if (retrievableScope) {
135
+ frontmatterMeta.retrievable_scope = retrievableScope;
136
+ overrideFields.push('retrievable_scope');
137
+ }
138
+ return {
139
+ content,
140
+ contentOffset,
141
+ hasFrontmatter: true,
142
+ frontmatterMeta,
143
+ overrideFields: uniq(overrideFields),
144
+ };
145
+ }
146
+ export function mergePathMetaWithFrontmatter(pathMeta, frontmatterMeta, overrideFields) {
147
+ if (!overrideFields.length) {
148
+ return {
149
+ ...pathMeta,
150
+ meta_source: 'path',
151
+ meta_override_fields: [],
152
+ };
153
+ }
154
+ const merged = {
155
+ ...pathMeta,
156
+ meta_source: 'merged',
157
+ meta_override_fields: uniq(overrideFields),
158
+ };
159
+ for (const field of overrideFields) {
160
+ const value = frontmatterMeta[field];
161
+ if (value === undefined)
162
+ continue;
163
+ // PathMeta 字段由 frontmatter 显式声明时优先;未声明字段保留路径推断兜底。
164
+ merged[field] = value;
165
+ }
166
+ return merged;
167
+ }
@@ -110,7 +110,9 @@ export function inferPathMeta(relativeSource) {
110
110
  // 两者都统一标记为 types=['faq'],便于通过 types=faq 命中“经验类问答”。
111
111
  if (parts[1] === 'chat' && parts[2] === 'best-practice' && parts.length >= 5) {
112
112
  const fwSlug = normalizeFrameworkDir(parts[3]);
113
- framework = [fwSlug];
113
+ // chat best-practice 的 common 目录表示平台通用(Web + 小程序),
114
+ // 不能按 framework=common 打标,否则会被 framework 硬过滤误排除。
115
+ framework = fwSlug === 'common' ? ['web', 'miniprogram'] : [fwSlug];
114
116
  types.push('faq');
115
117
  }
116
118
  if (parts[1] === 'chat' && parts[2] === 'faq' && parts.length >= 4) {
@@ -137,13 +139,13 @@ export function inferPathMeta(relativeSource) {
137
139
  }
138
140
  // callkit 最佳实践目录:knowledge/callkit/best-practice/{platform}/{topic}.md
139
141
  // 统一按 FAQ/经验类知识处理,支持 types=faq + frameworks={platform} 的精确检索。
142
+ // 与 chat best-practice 对齐:common 目录表示多平台通用,按最全集覆盖。
140
143
  if (parts[1] === 'callkit' && parts[2] === 'best-practice' && parts.length >= 5) {
141
- framework = [normalizeFrameworkDir(parts[3])];
144
+ const fwSlug = normalizeFrameworkDir(parts[3]);
145
+ framework = fwSlug === 'common'
146
+ ? ['react', 'vue', 'miniprogram', 'web', 'android', 'ios', 'flutter', 'uni-app']
147
+ : [fwSlug];
142
148
  types.push('faq');
143
- // calls 相关最佳实践既是 FAQ 也是 API 语义,避免 types=api 时被误过滤。
144
- if (/(callengine-invitation|callkit-call-vs-calls)\.md$/i.test(fileName)) {
145
- types.push('api');
146
- }
147
149
  }
148
150
  if (parts.includes('faq'))
149
151
  types.push('faq', 'error_code');
@@ -226,6 +228,15 @@ export function inferPathMeta(relativeSource) {
226
228
  types.push('component');
227
229
  if (fileName === 'faq.md')
228
230
  types.push('faq');
231
+ // livekit 最佳实践目录:knowledge/livekit/best-practice/{platform}/{topic}.md
232
+ // 与 chat/callkit 对齐:common 目录表示多平台通用,按最全集覆盖。
233
+ if (parts[1] === 'livekit' && parts[2] === 'best-practice' && parts.length >= 5) {
234
+ const fwSlug = normalizeFrameworkDir(parts[3]);
235
+ framework = fwSlug === 'common'
236
+ ? ['react', 'vue', 'web', 'android', 'ios', 'flutter']
237
+ : [fwSlug];
238
+ types.push('faq');
239
+ }
229
240
  // 与 roomkit 对齐:core-sdk 下 capability-matrix.md / unsupported-features.md
230
241
  // 视为能力边界文档(doc_kind + capability_status),方便检索层按 doc_kind 过滤
231
242
  const docMeta = inferDocMeta(fileName);
@@ -255,6 +266,15 @@ export function inferPathMeta(relativeSource) {
255
266
  types.push('feature');
256
267
  if (parts.includes('faq'))
257
268
  types.push('faq', 'error_code');
269
+ // roomkit 最佳实践目录:knowledge/roomkit/best-practice/{platform}/{topic}.md
270
+ // 与 chat/callkit 对齐:common 目录表示多平台通用,按最全集覆盖。
271
+ if (parts[1] === 'roomkit' && parts[2] === 'best-practice' && parts.length >= 5) {
272
+ const fwSlug = normalizeFrameworkDir(parts[3]);
273
+ framework = fwSlug === 'common'
274
+ ? ['react', 'vue', 'web', 'android', 'ios', 'flutter']
275
+ : [fwSlug];
276
+ types.push('faq');
277
+ }
258
278
  const docMeta = inferDocMeta(fileName);
259
279
  doc_kind = docMeta.doc_kind;
260
280
  capability_status = docMeta.capability_status ?? capability_status;
@@ -333,5 +353,7 @@ export function inferPathMeta(relativeSource) {
333
353
  doc_kind,
334
354
  capability_status,
335
355
  retrievable_scope,
356
+ meta_source: 'path',
357
+ meta_override_fields: [],
336
358
  };
337
359
  }
@@ -1,8 +1,16 @@
1
1
  import fs from 'fs';
2
2
  import path from 'path';
3
3
  import { fileURLToPath } from 'url';
4
+ import { getSourceFileContent } from '../content-loader.js';
5
+ import { computeCommonSectionTokens, isUrlMappingSource, normalizeUrlRowQuery, queryMatchesSection, scoreUrlRow } from './url-row-scorer.js';
4
6
  const __dirname = path.dirname(fileURLToPath(import.meta.url));
5
7
  const SCHEMA_ROOT = path.resolve(__dirname, '../../resource/_schema');
8
+ /**
9
+ * 分组语义命中的基础分:当 scoreUrlRow=0 但该 url 行「分组被 query 命中 + types 匹配」时给予。
10
+ * 取值需满足 E7 strongCandidates 门槛(typeMatch ×1.2 后 ≥500 → base ≥417)。
11
+ * 只在「分组命中」时给(区别于旧的「所有 types 匹配行给 500」),避免无关行涌入。
12
+ */
13
+ const SECTION_MATCH_BASE_SCORE = 450;
6
14
  export const DOC_PATH_MAP = {
7
15
  android: {
8
16
  core_api: 'TRTCCloud',
@@ -94,19 +102,6 @@ function loadFeatureAliases() {
94
102
  }
95
103
  return result;
96
104
  }
97
- /**
98
- * 将 prompt 按分隔符拆成子句列表,用于 url 行匹配。
99
- * 分隔符:、 , , ; ; 空格
100
- * 保留每个子句的原文(去首尾空白),不引入新词。
101
- */
102
- function splitPromptIntoClauses(prompt) {
103
- const raw = prompt
104
- .replace(/rest\s*api|服务端|server\s*api|api|怎么|如何|什么|用哪个|查询/g, '')
105
- .replace(/\s+/g, ' ')
106
- .trim();
107
- const parts = raw.split(/[、,,;;、\s]+/).filter((p) => p.length >= 2);
108
- return parts.length > 0 ? parts : [raw];
109
- }
110
105
  const ROOM_CORE_SIGNAL = /atomicx\s*core|atomicxcore|atomicx|core\s*sdk|无\s*ui|自定义\s*ui|自实现|roomstore|store|useRoomState|useDeviceState|useLoginState/i;
111
106
  const ROOM_PRESET_SIGNAL = /预制|preset|roommainview|roommainwidget|默认\s*ui|主页面|房间主页面/i;
112
107
  const ROOM_FEATURE_SPECS = [
@@ -149,8 +144,6 @@ const ROOM_FEATURE_SPECS = [
149
144
  function detectRoomFeatureHits(prompt) {
150
145
  return ROOM_FEATURE_SPECS.filter((spec) => spec.promptPattern.test(prompt));
151
146
  }
152
- const LIVE_LIFECYCLE_PROMPT = /开播|创建直播|结束直播|停播|观看直播|退出直播|进房|离房|createLive|endLive|joinLive|leaveLive|host_streaming|audience_streaming/i;
153
- const LIVE_LIFECYCLE_APIS = ['createLive', 'endLive', 'joinLive', 'leaveLive'];
154
147
  export function runExactLookup(prompt, pool, norm) {
155
148
  const boosts = {};
156
149
  const exactHits = [];
@@ -300,113 +293,143 @@ export function runExactLookup(prompt, pool, norm) {
300
293
  }
301
294
  }
302
295
  }
303
- // E6: chat urls boost(L1 URL 映射;错误码单独指向 urls/error-code.md)
304
- if (!norm.product?.length || norm.product.includes('chat')) {
296
+ // E6: URL 映射文件 boost(L1;产品无关:任意 product 的 urls 均适用)
297
+ const hasUrlChunks = pool.some((c) => isUrlMappingSource(c.source));
298
+ if (hasUrlChunks) {
305
299
  if (/payload|登录|usersig|鉴权/i.test(prompt)) {
306
300
  for (const chunk of pool) {
307
- if (chunk.source.includes('knowledge/chat/urls/')) {
308
- addBoost(chunk, 100, 'E6:chat-urls');
301
+ if (isUrlMappingSource(chunk.source)) {
302
+ addBoost(chunk, 100, 'E6:urls');
309
303
  }
310
304
  }
311
305
  }
312
306
  const errorCodeIntent = /错误码/i.test(prompt) || errorMatches.length > 0 || norm.searchIntent?.includes('error_code');
313
307
  if (errorCodeIntent) {
314
308
  for (const chunk of pool) {
315
- if (chunk.source.includes('knowledge/chat/urls/error-code.md')) {
316
- addBoost(chunk, 180, 'E6:chat-error-code-url');
309
+ if (/\/error-code\.md$/i.test(chunk.source)) {
310
+ addBoost(chunk, 180, 'E6:error-code-url');
317
311
  }
318
312
  }
319
313
  }
320
314
  // E7: URL 映射表行级匹配(chunk.title = 子问题列)
321
- // 策略:保留整句匹配,同时补充子句拆分 + 逐行匹配,同一 chunk 取最高分。
322
- // 子句拆分使 "创建群组、加入群组、发送群组自定义消息" 能命中多行。
323
- const clauses = splitPromptIntoClauses(prompt.toLowerCase());
324
- const candidates = [];
325
- for (const chunk of pool) {
326
- if (!chunk.source.includes('knowledge/chat/urls/'))
327
- continue;
328
- const titleNorm = chunk.title.toLowerCase().replace(/\s+/g, '');
329
- if (!titleNorm)
330
- continue;
331
- // 对每个子句和整句分别打分,取最高分
332
- let bestScore = 0;
333
- const allParts = [...clauses, prompt.toLowerCase().replace(/\s+/g, '')];
334
- // 也按常见分隔符拆分 title 得到 tokens,用于不连续匹配
335
- const titleTokens = titleNorm.split(/[\/(((、,,\s]+/).filter(Boolean);
336
- const seen = new Set();
337
- for (const part of allParts) {
338
- const pn = part.replace(/\s+/g, '');
339
- if (pn.length < 2 || seen.has(pn))
340
- continue;
341
- seen.add(pn);
342
- let s = 0;
343
- if (pn === titleNorm) {
344
- s = 1000;
345
- }
346
- else if (titleNorm.includes(pn)) {
347
- const trailing = titleNorm.slice(titleNorm.indexOf(pn) + pn.length);
348
- s = 800 - trailing.length * 80;
315
+ // 共享 scorer 按「REST 端点 > API token > 语义词对齐(IDF 加权)」打分。
316
+ // 支持 types 领域限定:上游推断出 types 时,优先 types 匹配的子文件行,
317
+ // 不匹配的行降权(避免跨域误命中,如 SDK 问题命中 restapi)。
318
+ if (normalizeUrlRowQuery(prompt).replace(/\s+/g, '').length >= 2) {
319
+ const candidates = [];
320
+ const hasTypeFilter = Boolean(norm.searchIntent?.length);
321
+ // 预收集 urls 行的分组结构:按 source 读整个 md 源文件,解析 `##` 分组与每行归属。
322
+ // 分组粗筛对所有 urls 资源生效(产品无关),不针对 webhook.md 打补丁。
323
+ const urlChunks = pool.filter((c) => isUrlMappingSource(c.source) && c.title.trim());
324
+ const sectionByChunk = new Map(); // chunk.id -> 分组标题
325
+ const sectionsBySource = new Map(); // source -> 分组标题集合
326
+ const mdRowsBySource = new Map(); // source -> {行title -> 分组标题}
327
+ for (const source of new Set(urlChunks.map((c) => c.source))) {
328
+ let full = '';
329
+ try {
330
+ full = getSourceFileContent(source);
349
331
  }
350
- else if (pn.includes(titleNorm)) {
351
- s = 700 + titleNorm.length;
332
+ catch {
333
+ full = '';
352
334
  }
353
- else if (titleTokens.some((token) => pn.includes(token) || token.includes(pn))) {
354
- // 子句匹配 title 的 token(如 "创建群组" 匹配 "创建/解散群组(普通群管理)" 中的 "创建" token)
355
- s = 600;
335
+ let cur = '';
336
+ const rows = new Map();
337
+ const sections = new Set();
338
+ for (const line of full.split('\n')) {
339
+ const h = line.match(/^#{2,3}\s+(.+)$/);
340
+ if (h) {
341
+ cur = h[1].trim();
342
+ sections.add(cur);
343
+ continue;
344
+ }
345
+ const row = line.match(/^\|\s*([^|]+?)\s*\|\s*`(https?:[^`]+)`/);
346
+ if (row)
347
+ rows.set(row[1].trim(), cur);
356
348
  }
357
- if (s > bestScore)
358
- bestScore = s;
349
+ mdRowsBySource.set(source, rows);
350
+ sectionsBySource.set(source, sections);
359
351
  }
360
- if (bestScore <= 0) {
361
- // 退化:子句无匹配时,试 loose(去噪声字 + 单字容错)
362
- const qn = clauses[0].replace(/发送/g, '发');
363
- if (qn.length >= 3 && titleNorm.includes(qn)) {
364
- bestScore = 500;
365
- if (/批量|群组|群流|广播|导入|公众号|已读|回执/.test(titleNorm)
366
- && !/批量|群组|群|已读|回执/.test(clauses[0])) {
367
- bestScore -= 250;
368
- }
369
- if (/^单发/.test(titleNorm) && /发送|单聊/.test(clauses[0])) {
370
- bestScore += 120;
352
+ for (const chunk of urlChunks) {
353
+ const section = mdRowsBySource.get(chunk.source)?.get(chunk.title);
354
+ if (section)
355
+ sectionByChunk.set(chunk.id, section);
356
+ }
357
+ // 计算每个 source 的共有词(该文件所有分组都出现的词)
358
+ const commonTokensBySource = new Map();
359
+ for (const [source, sections] of sectionsBySource) {
360
+ commonTokensBySource.set(source, computeCommonSectionTokens([...sections]));
361
+ }
362
+ for (const chunk of urlChunks) {
363
+ const scoreResult = scoreUrlRow(prompt, chunk.title);
364
+ // types 领域限定:query types 与 chunk types 是否有交集
365
+ const typeMatch = hasTypeFilter
366
+ ? (norm.searchIntent ?? []).some((t) => chunk.types.includes(t))
367
+ : true;
368
+ // 分组粗筛:query 是否命中该 chunk 所在的分组。
369
+ // 命中分组 → 正常;未命中分组 → 降权(不排除,避免 query 与分组名匹配不准时误杀)。
370
+ const section = sectionByChunk.get(chunk.id);
371
+ const commonTokens = commonTokensBySource.get(chunk.source);
372
+ const sectionMatch = section && commonTokens
373
+ ? queryMatchesSection(prompt, section, commonTokens)
374
+ : true; // 无分组信息时不做粗筛(保持原行为)
375
+ // 高 scoreUrlRow 兜底:scoreUrlRow ≥ 700 是极强语义信号(query 2-gram 全覆盖),
376
+ // 此时不应被 sectionMatch 软降权压制。常见场景:短 query 如「群消息发送异常」
377
+ // 跟 section 标题「群组系统回调」共享字符少(仅「群」),sectionMatch 失败,
378
+ // 但 row title 本身完美匹配 user 意图,强行降权会让单聊 row 顶上。
379
+ const highConfidence = scoreResult.score >= 700;
380
+ // 分组语义命中基础分:scoreUrlRow 可能因「同义词/长句」对精确行打 0 分
381
+ // (如「群消息发送前回调」vs「群内发言之前回调」),但分组已语义命中,
382
+ // 给予基础分进入候选,避免该领域行被 score<=0 排除。
383
+ // 区别于旧的「所有 types 匹配行给 500」——只在分组命中时才给,避免无关行涌入。
384
+ if (scoreResult.score <= 0) {
385
+ if (sectionMatch && typeMatch) {
386
+ candidates.push({ chunk, score: SECTION_MATCH_BASE_SCORE, typeMatch, sectionMatch });
371
387
  }
388
+ continue;
372
389
  }
390
+ // finalScore 排序用:sectionMatch 失败且非高置信时,×0.7 软降权。
391
+ // 高置信(scoreUrlRow ≥ 700)跳过降权,避免短 query + 长 section 标题时的误杀。
392
+ const finalScore = (sectionMatch || highConfidence) ? scoreResult.score : scoreResult.score * 0.7;
393
+ candidates.push({ chunk, score: finalScore, typeMatch, sectionMatch });
373
394
  }
374
- if (bestScore > 0) {
375
- candidates.push({ chunk, score: bestScore });
376
- }
377
- }
378
- candidates.sort((a, b) => b.score - a.score);
379
- const strongCandidates = candidates
380
- .filter(({ score }) => score >= 500)
381
- .slice(0, 12);
382
- strongCandidates.forEach(({ chunk, score }, idx) => {
383
- // 递减 boost:前两条更高,其余保持可召回但不过度压制 BM25
384
- // token 匹配(600 分)至少给 150,确保子句拆分的行不被 BM25 原始分压掉
385
- const amount = idx === 0
386
- ? 200 + Math.min(score, 100)
387
- : idx === 1
388
- ? 170 + Math.min(score, 90)
389
- : Math.max(score >= 600 ? 150 : 90, 140 - idx * 8);
390
- addBoost(chunk, amount, `E7:url-row:${chunk.title}`);
391
- urlRowHitChunkIds.add(chunk.id);
392
- });
393
- }
394
- // E8: 集成查阅意图 boost——prompt 含集成/接入/快速开始/接入文档等意图词时,
395
- // 把 {integration|knowledge}/{product}/preset/{fw}/integration.md 系列文件顶到前列。
396
- // 解决问题:集成文档内容长、词密度低,BM25 原始分常被短小的 features/ 文档压过。
397
- // 注:android-view / ios-uikit 已迁到 knowledge corpus,但同样是集成指引,需要一并 boost。
398
- const isIntegrationIntent = /集成|接入|快速开始|快速接入|集成文档|接入文档|集成指南|接入指南|接入流程|集成步骤|如何接入|如何集成|怎么接入|怎么集成/i.test(prompt);
399
- if (isIntegrationIntent && norm.product?.length && norm.frameworks?.length) {
400
- for (const chunk of pool) {
401
- if (!norm.product.includes(chunk.product))
402
- continue;
403
- const fwMatch = norm.frameworks.some((fw) => chunk.framework.includes(fw));
404
- if (!fwMatch)
405
- continue;
406
- // 命中 preset/{fw}/integration.md 系列(含 integration/ 和 knowledge/ 两种 corpus)
407
- if (!chunk.source.includes('/preset/') || (!chunk.source.endsWith('integration.md') && !chunk.source.endsWith('-integration.md')))
408
- continue;
409
- addBoost(chunk, 120, `E8:integration-doc:${chunk.source}`);
395
+ candidates.sort((a, b) => b.score - a.score);
396
+ // types 匹配的行加分(更优先);不匹配的行轻度降权但仍可兜底召回。
397
+ // 避免上游 types 推断不准确时误杀正确文档(如「多端登录配置」被推断为 feature 而非 product)。
398
+ const typeScored = candidates
399
+ .map((c) => (c.typeMatch ? { ...c, score: c.score * 1.2 } : { ...c, score: c.score * 0.6 }))
400
+ .filter(({ score }) => score >= 500);
401
+ // 同分 row(典型:query「群消息撤回回调」时「撤回群消息」跟「单聊消息撤回」都 scoreUrlRow=660),
402
+ // 按「query 字符集被 row title 覆盖比例」再排,覆盖更高的 row 排前。
403
+ // 修 E7 boost idx=0 多 40 分的副作用:让字符集更精准的 row 拿 idx=0 → 300 分而不是 260 分。
404
+ const queryChars = new Set(prompt.match(/[\u4e00-\u9fff]/g) ?? []);
405
+ const charCoverage = (title) => {
406
+ if (queryChars.size === 0)
407
+ return 0;
408
+ const titleChars = new Set(title.match(/[\u4e00-\u9fff]/g) ?? []);
409
+ let hit = 0;
410
+ for (const ch of queryChars)
411
+ if (titleChars.has(ch))
412
+ hit += 1;
413
+ return hit / queryChars.size;
414
+ };
415
+ const strongCandidates = typeScored
416
+ .sort((a, b) => {
417
+ // 优先按 typeScored score 降序;同分时按字符集覆盖率降序
418
+ if (b.score !== a.score)
419
+ return b.score - a.score;
420
+ return charCoverage(b.chunk.title) - charCoverage(a.chunk.title);
421
+ })
422
+ .slice(0, 12);
423
+ strongCandidates.forEach(({ chunk, score }, idx) => {
424
+ // 递减 boost:前两条更高,其余保持可召回但不过度压制 BM25
425
+ const amount = idx === 0
426
+ ? 200 + Math.min(score, 100)
427
+ : idx === 1
428
+ ? 170 + Math.min(score, 90)
429
+ : Math.max(score >= 600 ? 150 : 90, 140 - idx * 8);
430
+ addBoost(chunk, amount, `E7:url-row:${chunk.title}`);
431
+ urlRowHitChunkIds.add(chunk.id);
432
+ });
410
433
  }
411
434
  }
412
435
  // E9: chat faq——types=faq 时优先 knowledge 语料,避免 integration 文档内 FAQ 章节抢首位
@@ -422,28 +445,6 @@ export function runExactLookup(prompt, pool, norm) {
422
445
  }
423
446
  }
424
447
  }
425
- // E11: LiveKit 生命周期意图强召回(开播/停播/观看/退出)
426
- if (norm.product?.includes('live') && LIVE_LIFECYCLE_PROMPT.test(prompt)) {
427
- const queryApiHits = LIVE_LIFECYCLE_APIS.filter((api) => new RegExp(api, 'i').test(prompt));
428
- for (const chunk of pool) {
429
- const isLiveCoreIntegration = chunk.source.startsWith('knowledge/livekit/core-sdk/live/')
430
- && chunk.source.endsWith('/integration.md');
431
- const isVoiceCoreIntegration = chunk.source.startsWith('knowledge/livekit/core-sdk/voice/')
432
- && chunk.source.endsWith('/integration.md');
433
- if (!isLiveCoreIntegration && !isVoiceCoreIntegration)
434
- continue;
435
- if (norm.scenario === 'live' && !isLiveCoreIntegration)
436
- continue;
437
- if (norm.scenario === 'voice' && !isVoiceCoreIntegration)
438
- continue;
439
- addBoost(chunk, 140, 'E11:live-lifecycle-core-integration');
440
- for (const api of queryApiHits) {
441
- if (chunk.api_names?.some((name) => name.toLowerCase() === api.toLowerCase())) {
442
- addBoost(chunk, 160, `E11:live-lifecycle-api:${api}`);
443
- }
444
- }
445
- }
446
- }
447
448
  // E10: roomkit Core/Preset 消歧 + unsupported feature 强召回
448
449
  if (norm.product?.includes('room') && norm.frameworks?.length) {
449
450
  const platform = norm.frameworks.find((fw) => ['android', 'ios', 'flutter', 'vue'].includes(fw));
@@ -1,5 +1,6 @@
1
1
  import { downgradeToProductType } from './product-scope-intent.js';
2
2
  import { normalizeQueryPrompt } from './query-normalizer.js';
3
+ import { hasExplicitFrameworkMatch, hasFrameworkFallbackMatch } from './framework-fallback.js';
3
4
  /**
4
5
  * MCP framework enum → index 中对应的 framework 值列表。
5
6
  * path-meta.ts 已通过 normalizeFrameworkDir 把目录名归一到标准 framework,
@@ -42,14 +43,6 @@ function resolveTypes(products, types, prompt, frameworks) {
42
43
  return undefined;
43
44
  const downgraded = downgradeToProductType(products, types, prompt, frameworks);
44
45
  const expanded = expandTypeAliases(downgraded);
45
- // Live 生命周期兼容:用户常传 types=['api'],但核心生命周期方法来自 core-sdk/live|voice/*/integration.md。
46
- // 这里补充 core/integration,避免被类型硬过滤提前排除。
47
- if (products?.includes('live') && expanded.includes('api') && LIVE_LIFECYCLE_PROMPT.test(prompt)) {
48
- if (!expanded.includes('core'))
49
- expanded.push('core');
50
- if (!expanded.includes('integration'))
51
- expanded.push('integration');
52
- }
53
46
  return expanded;
54
47
  }
55
48
  /** 单平台产品的隐式 framework 推断:避免对显然唯一的平台再发起询问 */
@@ -133,33 +126,23 @@ export function filterPool(chunks, norm) {
133
126
  // 收紧:framework=['*'] 仅在该 chunk 明确是跨平台 type(product/server_api/webhook)时放行;
134
127
  // 否则要求 chunk.framework 与请求 framework 有交集。
135
128
  const wildcardAllowed = isWildcardChunk && chunkIsCrossPlatform(chunk.types);
136
- const explicitMatch = norm.frameworks.some((fw) => chunk.framework.includes(fw));
137
- // CallKit 特例:core-sdk 仍维持 web 单套(纯 JS),允许 react/vue 查询命中 core-sdk/web。
138
- const callCoreWebFallback = Boolean(norm.product?.includes('call')
139
- && (norm.framework === 'react' || norm.framework === 'vue')
140
- && chunk.variant === 'core-sdk'
141
- && chunk.framework.includes('web'));
142
- // Live 特例:写写侧把 'Web' 平台归到 livekit/core-sdk/api-reference/{vue,web} 目录(写写节点名是 'Web'),
143
- // 本地目录重命名为 'vue' 后 framework 标签变为 'vue'。'web' 查询仍应能命中这些 chunk。
144
- const liveWebVueFallback = Boolean(norm.product?.includes('live')
145
- && norm.framework === 'web'
146
- && chunk.variant === 'core-sdk'
147
- && chunk.framework.includes('vue')
148
- && chunk.source.includes('/api-reference/'));
149
- // Room 特例:Conference Web 实际语料在 roomkit/core-sdk/vue,web 查询应可命中。
150
- const roomWebVueFallback = Boolean(norm.product?.includes('room')
151
- && norm.framework === 'web'
152
- && chunk.variant === 'core-sdk'
153
- && chunk.framework.includes('vue')
154
- && chunk.source.includes('knowledge/roomkit/core-sdk/vue/'));
155
- if (!explicitMatch && !wildcardAllowed && !callCoreWebFallback && !liveWebVueFallback && !roomWebVueFallback)
129
+ const explicitMatch = hasExplicitFrameworkMatch(chunk.framework, norm.frameworks);
130
+ const fallbackMatch = hasFrameworkFallbackMatch(chunk, {
131
+ product: norm.product,
132
+ framework: norm.framework,
133
+ frameworks: norm.frameworks,
134
+ });
135
+ if (!explicitMatch && !wildcardAllowed && !fallbackMatch)
156
136
  return false;
157
137
  }
158
138
  if (norm.scenario && chunk.scenario && chunk.scenario !== norm.scenario) {
159
139
  return false;
160
140
  }
141
+ // best-practice 文档对 types 过滤免疫:内容不依赖 types 分类,应始终进 pool 靠 BM25 自然排名。
142
+ // 典型场景:Agent 传 types=['api'] 时,types=['faq'] 的 best-practice 不应被过滤掉。
161
143
  if (norm.types?.length && !norm.types.some((t) => chunk.types.includes(t))) {
162
- return false;
144
+ if (!chunk.source.includes('/best-practice/'))
145
+ return false;
163
146
  }
164
147
  return true;
165
148
  });
@@ -0,0 +1,22 @@
1
+ export function hasExplicitFrameworkMatch(chunkFrameworks, requestFrameworks) {
2
+ if (!requestFrameworks?.length)
3
+ return false;
4
+ return requestFrameworks.some((fw) => chunkFrameworks.includes(fw));
5
+ }
6
+ export function hasFrameworkFallbackMatch(chunk, opts) {
7
+ const callCoreWebFallback = Boolean(opts.product?.includes('call')
8
+ && (opts.framework === 'react' || opts.framework === 'vue')
9
+ && chunk.variant === 'core-sdk'
10
+ && chunk.framework.includes('web'));
11
+ const liveWebVueFallback = Boolean(opts.product?.includes('live')
12
+ && opts.framework === 'web'
13
+ && chunk.variant === 'core-sdk'
14
+ && chunk.framework.includes('vue')
15
+ && chunk.source.includes('/api-reference/'));
16
+ const roomWebVueFallback = Boolean(opts.product?.includes('room')
17
+ && opts.framework === 'web'
18
+ && chunk.variant === 'core-sdk'
19
+ && chunk.framework.includes('vue')
20
+ && chunk.source.includes('knowledge/roomkit/core-sdk/vue/'));
21
+ return callCoreWebFallback || liveWebVueFallback || roomWebVueFallback;
22
+ }