version: 2
This commit is contained in:
@@ -41,3 +41,57 @@ export function validateHttpUrl(url: string): boolean {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
// 简化版 cl100k_base 估算
|
||||
export function estimateTokenCount(text: string): number {
|
||||
if (!text) return 0
|
||||
const chinese = (text.match(/[^\u0000-\u00FF]/g) || []).length // 中文 ≈ 1 token/字
|
||||
const english = (text.match(/[a-zA-Z]/g) || []).length // 英文 ≈ 1 token/4 字符
|
||||
const special = (text.match(/[\s.,!?;:\-\'",。!?;:——\n\r]/g) || []).length // 标点/空格
|
||||
return chinese + Math.ceil(english / 4) + Math.ceil(special * 0.25)
|
||||
}
|
||||
|
||||
/**
|
||||
* 按 token 截断,**整轮保留**:一轮 = 一条 user + 其后所有消息(assistant/tool),
|
||||
* 按 `role === 'user'` 切组,从最新轮向前累加,总 token 超过上限时停止。
|
||||
* 整轮保留 ⇒ 不拆 user/assistant 对,也不留孤儿 tool 消息
|
||||
* (assistant(tool_calls) 与它的 tool 消息必然同组,按组切永远不会拆开)。
|
||||
* 头部防御:开头若不是 user(异常形态)⇒ 丢到第一条 user 为止 ——
|
||||
* tool / assistant(tool_calls) 开头的序列网关直接 400。
|
||||
* 最新一轮即使自身超上限也保留(否则空历史,请求无法发出)。
|
||||
*/
|
||||
export function truncateMessagesByTokenCount<T extends { content: string; role: string }>(
|
||||
messages: T[],
|
||||
maxTokens: number,
|
||||
): T[] {
|
||||
const limit = Math.max(Number(maxTokens), 0)
|
||||
if (!limit || !messages.length) return []
|
||||
|
||||
const groups: T[][] = []
|
||||
let current: T[] = []
|
||||
for (const message of messages) {
|
||||
if (message.role === 'user' && current.length) {
|
||||
groups.push(current)
|
||||
current = []
|
||||
}
|
||||
current.push(message)
|
||||
}
|
||||
if (current.length) groups.push(current)
|
||||
|
||||
const keptGroups: T[][] = []
|
||||
let total = 0
|
||||
for (let index = groups.length - 1; index >= 0; index -= 1) {
|
||||
const groupTokens = groups[index].reduce(
|
||||
(sum, message) => sum + estimateTokenCount(message.content),
|
||||
0,
|
||||
)
|
||||
if (keptGroups.length && total + groupTokens > limit) break
|
||||
keptGroups.unshift(groups[index])
|
||||
total += groupTokens
|
||||
}
|
||||
|
||||
const kept = keptGroups.flat()
|
||||
let start = 0
|
||||
while (start < kept.length && kept[start].role !== 'user') start += 1
|
||||
return kept.slice(start)
|
||||
}
|
||||
|
||||
+98
-120
@@ -1,131 +1,24 @@
|
||||
import MarkdownIt from 'markdown-it'
|
||||
import hljs from 'highlight.js/lib/core'
|
||||
import javascript from 'highlight.js/lib/languages/javascript'
|
||||
import json from 'highlight.js/lib/languages/json'
|
||||
import 'highlight.js/styles/github.css'
|
||||
|
||||
hljs.registerLanguage('javascript', javascript)
|
||||
hljs.registerLanguage('json', json)
|
||||
|
||||
const CODE_LANGUAGES = ['sql', 'javascript', 'typescript', 'java', 'python', 'json', 'html', 'css', 'bash', 'shell', 'vue', 'xml', 'yaml', 'markdown']
|
||||
const LANGUAGE_ALIASES: Record<string, string> = {
|
||||
js: 'javascript',
|
||||
jsx: 'javascript',
|
||||
ts: 'typescript',
|
||||
tsx: 'typescript',
|
||||
sh: 'bash',
|
||||
shell: 'bash',
|
||||
zsh: 'bash',
|
||||
yml: 'yaml',
|
||||
md: 'markdown',
|
||||
text: 'plaintext',
|
||||
}
|
||||
const CODE_FENCE_PATTERN = /```[\s\S]*?```/
|
||||
const CODE_FENCE_LINE_PATTERN = /^```/gm
|
||||
const SQL_KEYWORDS = /\b(select|insert|update|delete|create|alter|drop|from|where|join|group by|order by|limit)\b/i
|
||||
const CODE_STRUCTURE_PATTERN = /[{};<>]|\b(function|const|let|var|public|private|class|interface|return|import|export|try|catch|async|await)\b/
|
||||
|
||||
function escapeCodeHtml(code: string): string {
|
||||
return code
|
||||
.replace(/&/g, '&')
|
||||
.replace(/</g, '<')
|
||||
.replace(/>/g, '>')
|
||||
.replace(/"/g, '"')
|
||||
.replace(/'/g, ''')
|
||||
}
|
||||
|
||||
function escapeAttribute(value: string): string {
|
||||
return value
|
||||
.replace(/&/g, '&')
|
||||
.replace(/"/g, '"')
|
||||
.replace(/</g, '<')
|
||||
.replace(/>/g, '>')
|
||||
}
|
||||
|
||||
function normalizeLanguage(language = ''): string {
|
||||
const normalized = language.trim().toLowerCase()
|
||||
return LANGUAGE_ALIASES[normalized] || normalized || 'plaintext'
|
||||
}
|
||||
|
||||
function getDisplayLanguage(language: string): string {
|
||||
return language === 'plaintext' ? 'text' : language
|
||||
}
|
||||
|
||||
function detectCodeLanguage(content: string): string {
|
||||
const normalized = content.trim().toLowerCase()
|
||||
|
||||
if (SQL_KEYWORDS.test(normalized)) return 'sql'
|
||||
if (/^\s*[{[]/.test(content) && /[}\]]\s*$/.test(content)) return 'json'
|
||||
if (/<[a-z][\s\S]*?>/i.test(content)) return 'html'
|
||||
if (/\b(interface|type|implements|readonly|enum)\b/.test(normalized)) return 'typescript'
|
||||
if (/\b(system\.out\.println|public static void main|new \w+\()/i.test(content)) return 'java'
|
||||
if (/\b(def |import |from .+ import |print\()/i.test(content)) return 'python'
|
||||
if (/\b(const|let|var|function|=>|console\.log)\b/.test(normalized)) return 'javascript'
|
||||
if (/\b(selectors?|padding|margin|color|background|display|flex)\s*:/i.test(content)) return 'css'
|
||||
if (/^(npm|pnpm|yarn|git|curl|docker|cd|ls|dir)\b/im.test(content)) return 'bash'
|
||||
|
||||
return 'plaintext'
|
||||
}
|
||||
|
||||
function shouldRenderAsCode(content: string): boolean {
|
||||
const trimmed = content.trim()
|
||||
if (!trimmed || CODE_FENCE_PATTERN.test(trimmed)) return false
|
||||
|
||||
const lines = trimmed.split(/\r?\n/).filter((line) => line.trim())
|
||||
if (lines.length >= 2 && (SQL_KEYWORDS.test(trimmed) || CODE_STRUCTURE_PATTERN.test(trimmed))) {
|
||||
return true
|
||||
}
|
||||
|
||||
if (lines.length === 1) {
|
||||
return /^(select|insert|update|delete)\b/i.test(trimmed) || /^[{[]/.test(trimmed)
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
function normalizeMarkdownContent(content: string): string {
|
||||
if (!shouldRenderAsCode(content)) {
|
||||
return content
|
||||
}
|
||||
|
||||
const language = detectCodeLanguage(content)
|
||||
if (CODE_LANGUAGES.includes(language) || language === 'plaintext') {
|
||||
return `\n\n\`\`\`${language}\n${content.trim()}\n\`\`\`\n\n`
|
||||
}
|
||||
|
||||
return content
|
||||
}
|
||||
|
||||
function closeUnclosedCodeFence(content: string): string {
|
||||
const fenceCount = content.match(CODE_FENCE_LINE_PATTERN)?.length || 0
|
||||
return fenceCount % 2 === 1 ? `${content}\n\`\`\`` : content
|
||||
}
|
||||
// 界面侧兜底:禁止任何代码展示(模型侧行为准则已禁止输出代码,这里防漏网)。
|
||||
// - 围栏代码块(``` / ~~~)与缩进代码块:整块不渲染,用户看不到任何代码
|
||||
// - 行内 code:只保留文字、不输出 <code> 标签 —— 行内片段通常是字段名等,
|
||||
// 删掉文字会伤句子可读性,去掉「代码」外观即可
|
||||
|
||||
const markdown: MarkdownIt = new MarkdownIt({
|
||||
html: false,
|
||||
linkify: true,
|
||||
breaks: true,
|
||||
typographer: true,
|
||||
highlight(code: string, language: string): string {
|
||||
const normalizedLanguage = normalizeLanguage(language)
|
||||
const languageLabel = hljs.getLanguage(normalizedLanguage) ? normalizedLanguage : 'plaintext'
|
||||
const displayLanguage = getDisplayLanguage(languageLabel)
|
||||
const highlightedCode = hljs.getLanguage(languageLabel)
|
||||
? hljs.highlight(code, { language: languageLabel }).value
|
||||
: escapeCodeHtml(code)
|
||||
|
||||
return `
|
||||
<div class="md-code-block" data-language="${escapeAttribute(displayLanguage)}">
|
||||
<div class="md-code-block__toolbar">
|
||||
<span class="md-code-block__language">${escapeAttribute(displayLanguage)}</span>
|
||||
<button type="button" class="md-code-block__copy" aria-label="复制代码">复制代码</button>
|
||||
</div>
|
||||
<pre class="hljs"><code>${highlightedCode}</code></pre>
|
||||
</div>
|
||||
`
|
||||
},
|
||||
})
|
||||
|
||||
// 围栏代码块(``` / ~~~):整块不输出到 html
|
||||
markdown.renderer.rules.fence = () => ''
|
||||
// 缩进代码块:同样属于代码展示,一并整块丢弃
|
||||
markdown.renderer.rules.code_block = () => ''
|
||||
// 行内 code:只保留转义后的文字,不包裹任何标签
|
||||
markdown.renderer.rules.code_inline = (tokens, index) => markdown.utils.escapeHtml(tokens[index].content)
|
||||
|
||||
const defaultLinkOpenRenderer = markdown.renderer.rules.link_open
|
||||
markdown.renderer.rules.link_open = (tokens, index, options, env, self) => {
|
||||
const token = tokens[index]
|
||||
@@ -142,7 +35,92 @@ markdown.renderer.rules.link_open = (tokens, index, options, env, self) => {
|
||||
markdown.renderer.rules.table_open = () => '<div class="md-table-wrapper"><table>\n'
|
||||
markdown.renderer.rules.table_close = () => '</table></div>\n'
|
||||
|
||||
// 裸 JSON 段落:模型不加围栏直接输出一段 JSON 时,会作为普通段落漏出来,等于代码展示漏网。
|
||||
// 判定是精确的:整段文本 trim 后能被 JSON.parse 成功,且解析结果是**对象或数组** ⇒ 判定为 json ⇒ 整段丢弃。
|
||||
// 纯标量(数字 / 字符串 / 布尔 / null)虽然也能 parse 成功,但那是正常回复内容(例如模型答「42」),必须保留。
|
||||
// 不做任何「像代码」的模糊猜测(不按 { / [ 出现次数、不按行数猜);
|
||||
// 只处理顶层独立段落 —— 列表项 / 引用里的段落一律不动,保证列表、引用渲染不受影响。
|
||||
function isBareJson(text: string): boolean {
|
||||
const trimmed = text.trim()
|
||||
|
||||
if (!trimmed) return false
|
||||
|
||||
try {
|
||||
const parsed: unknown = JSON.parse(trimmed)
|
||||
return typeof parsed === 'object' && parsed !== null
|
||||
} catch {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
// 从原始 markdown 文本里剔除「整段都是裸 JSON」的顶层段落。
|
||||
// 界面渲染(renderMarkdown)与「复制整条消息」共用这一个判定,保证两边口径一致。
|
||||
export function stripBareJsonBlocks(content = ''): string {
|
||||
if (!content) return ''
|
||||
|
||||
const tokens = markdown.parse(content, {})
|
||||
const lines = content.split(/\r?\n/)
|
||||
const dropLines = new Set<number>()
|
||||
let depth = 0
|
||||
|
||||
for (let i = 0; i < tokens.length; i++) {
|
||||
const token = tokens[i]
|
||||
|
||||
// 顶层段落结构固定为 paragraph_open → inline → paragraph_close;
|
||||
// inline token 的 content 就是该段未解析的原始文本。
|
||||
if (token.type === 'paragraph_open' && depth === 0 && token.map) {
|
||||
const inline = tokens[i + 1]
|
||||
|
||||
if (inline?.type === 'inline' && isBareJson(inline.content)) {
|
||||
for (let line = token.map[0]; line < token.map[1]; line++) {
|
||||
dropLines.add(line)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 段落本身不算容器层级;其余 *_open / *_close 记录是否处于列表、引用等容器内
|
||||
if (token.type !== 'paragraph_open' && token.type !== 'paragraph_close') {
|
||||
if (token.type.endsWith('_open')) depth++
|
||||
else if (token.type.endsWith('_close')) depth--
|
||||
}
|
||||
}
|
||||
|
||||
if (dropLines.size === 0) return content
|
||||
|
||||
return lines.filter((_, index) => !dropLines.has(index)).join('\n').trim()
|
||||
}
|
||||
|
||||
// 从原始 markdown 文本里剔除围栏代码块(含未闭合的尾部围栏),供「复制整条消息」用,
|
||||
// 保证复制到的文本与界面所见一致(不含代码)。
|
||||
export function stripFencedCode(content = ''): string {
|
||||
if (!content) return ''
|
||||
|
||||
const lines = content.split(/\r?\n/)
|
||||
const kept: string[] = []
|
||||
let fenceChar = ''
|
||||
|
||||
for (const line of lines) {
|
||||
const fenceMatch = /^\s*(`{3,}|~{3,})/.exec(line)
|
||||
|
||||
if (!fenceChar) {
|
||||
if (fenceMatch) {
|
||||
fenceChar = fenceMatch[1][0]
|
||||
} else {
|
||||
kept.push(line)
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
// 围栏内:遇到同字符的闭合围栏则结束,其余行一律丢弃
|
||||
if (fenceMatch && fenceMatch[1][0] === fenceChar) {
|
||||
fenceChar = ''
|
||||
}
|
||||
}
|
||||
|
||||
return kept.join('\n').trim()
|
||||
}
|
||||
|
||||
export function renderMarkdown(content = ''): string {
|
||||
const normalizedContent = normalizeMarkdownContent(content)
|
||||
return markdown.render(closeUnclosedCodeFence(normalizedContent))
|
||||
// 先剔除裸 JSON 段落再渲染,界面与复制共用同一判定
|
||||
return markdown.render(stripBareJsonBlocks(content))
|
||||
}
|
||||
|
||||
@@ -1,5 +1,11 @@
|
||||
import { ElMessage } from 'element-plus'
|
||||
|
||||
/** localStorage 用量阈值:2,000,000 UTF-16 码元(≈4MB 字节,按字面 4M 码元 ≈8MB 会撞浏览器 ~5MB 配额) */
|
||||
const LOCAL_STORAGE_SIZE_THRESHOLD = 2_000_000
|
||||
|
||||
/** 去重门控:已提示且用量未回落到阈值下 ⇒ 不重弹(流式每轮 flush 都会触发检查) */
|
||||
let quotaWarningShown = false
|
||||
|
||||
function notifyStorageError(action: string, key: string, error: unknown): void {
|
||||
const isQuotaExceeded = error instanceof DOMException && (
|
||||
error.name === 'QuotaExceededError' ||
|
||||
@@ -41,3 +47,40 @@ export function removeLocalStorage(key: string): void {
|
||||
notifyStorageError('删除', key, error)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 估算 localStorage 用量(改造清单附 1 原文:UTF-16 码元计数,key.length + value.length)。
|
||||
* 估算本身很便宜(遍历所有键取 length),正常用量下零可感知开销。
|
||||
*/
|
||||
export function getLocalStorageSize(): number {
|
||||
let total = 0
|
||||
for (let i = 0; i < localStorage.length; i++) {
|
||||
const key = localStorage.key(i)
|
||||
const value = key === null ? null : localStorage.getItem(key)
|
||||
// 计算键和值的字符长度(UTF-16 编码单元)
|
||||
total += (key?.length ?? 0) + (value?.length ?? 0)
|
||||
}
|
||||
return total
|
||||
}
|
||||
|
||||
/**
|
||||
* 会话持久化写入成功后调用:超阈值提示一次,引导删除**其它**历史会话(不引导删当前会话)。
|
||||
* 去重:提示后只要用量没回落到阈值下就不重弹;回落 ⇒ 复位门控,再超可再提示。
|
||||
* 与 notifyStorageError 的 QuotaExceededError 分支不冲突(那是写入失败时的兜底,本函数是写入成功后的提前预警)。
|
||||
*/
|
||||
export function checkLocalStorageUsage(): void {
|
||||
try {
|
||||
const used = getLocalStorageSize()
|
||||
if (used < LOCAL_STORAGE_SIZE_THRESHOLD) {
|
||||
quotaWarningShown = false
|
||||
return
|
||||
}
|
||||
if (quotaWarningShown) return
|
||||
quotaWarningShown = true
|
||||
const usedMb = (used * 2 / 1024 / 1024).toFixed(1)
|
||||
ElMessage.warning(`本地存储用量已接近浏览器上限(约 ${usedMb}MB)。建议删除其它历史会话以释放空间;当前会话不受影响。`)
|
||||
} catch (error) {
|
||||
// 估算失败不影响持久化主流程
|
||||
console.error('估算 localStorage 用量失败', error)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,103 @@
|
||||
/**
|
||||
* 解析 native 出的**技能清单 md**,得到「9 个类型 + 分组 + skill 名」。
|
||||
*
|
||||
* ── 为什么 app 侧要解析清单 ──────────────────────────────────────────────
|
||||
* UI 的「类型」区(生成任务 ⇒ 9 个类型;解释·改写 ⇒ 分组 2 项)需要
|
||||
* 类型名 / 分组 / skill 名,而这些**只有 native 出的清单里才有**。
|
||||
* ⇒ app **不硬编码**任何类名 / 分组 / skill 名 —— 清单是唯一事实来源,
|
||||
* 格式见 `constants/policy-skills.ts` 头部的「清单的格式规范」。
|
||||
*
|
||||
* ── 解析规则 ────────────────────────────────────────────────────────────
|
||||
* 按 `^## ` 切节;每节:
|
||||
* ## 常规打法技能 ⇒ 类型 = 去掉结尾「技能」→「常规打法」
|
||||
* - **分组**:打法策略 ⇒ 分组
|
||||
* - **概述**:…… ⇒ description(缺失 ⇒ 空串,不跳过该节)
|
||||
* - **英文名**:`normalBet`(…) ⇒ 取第一个反引号里的英文名 = skill 名
|
||||
*
|
||||
* ── 容错 ────────────────────────────────────────────────────────────────
|
||||
* 缺行(无「分组」/ 无「英文名」/ 标题不以「技能」结尾)就**跳过该节**,
|
||||
* **绝不抛异常**。清单取不到 / 全不合规 ⇒ 返回空数组 ⇒ 界面隐藏类型区。
|
||||
* ⚠️ 例外:「概述」缺失或为空 ⇒ description = 空串、**不跳过该节** ——
|
||||
* description 只用于悬停提示,不能因为缺它就让类型按钮消失。
|
||||
* ⚠️ `## 总体规则` 一节没有「技能」结尾的标题,天然被跳过 ——
|
||||
* 本函数喂清单正文或整段拼装结果都安全。
|
||||
*/
|
||||
|
||||
export interface StrategyClass {
|
||||
/** 类型,如「常规注码」(节标题去掉结尾「技能」) */
|
||||
className: string
|
||||
/** 分组,如「注码策略」 */
|
||||
category: string
|
||||
/** 如 'normalChip'(「英文名」行第一个反引号里的值) */
|
||||
skillName: string
|
||||
/** 「概述」行的值(悬停提示用);缺失或为空 ⇒ 空串(不因此跳过该节) */
|
||||
description: string
|
||||
}
|
||||
|
||||
/** 节标题:`## XX技能` → XX;不以「技能」结尾 / 剥完为空 ⇒ null。 */
|
||||
function extractClassName(title: string): string | null {
|
||||
const trimmed = title.trim()
|
||||
if (!trimmed.endsWith('技能')) return null
|
||||
const className = trimmed.slice(0, -'技能'.length).trim()
|
||||
return className || null
|
||||
}
|
||||
|
||||
/** 取 `- **分组**:xxx` 行的值;没有该行 ⇒ null。 */
|
||||
function extractCategory(sectionText: string): string | null {
|
||||
const line = sectionText
|
||||
.split('\n')
|
||||
.find((l) => /^- \*\*分组\*\*[::]/.test(l.trim()))
|
||||
if (!line) return null
|
||||
const value = line.trim().replace(/^- \*\*分组\*\*[::]/, '').trim()
|
||||
return value || null
|
||||
}
|
||||
|
||||
/** 取 `- **概述**:xxx` 行的值;没有该行 / 值为空 ⇒ ''(不跳过该节,见容错说明)。 */
|
||||
function extractOverview(sectionText: string): string {
|
||||
const line = sectionText
|
||||
.split('\n')
|
||||
.find((l) => /^- \*\*概述\*\*[::]/.test(l.trim()))
|
||||
if (!line) return ''
|
||||
// 只替换行首标签(概述正文里可能含「:」,不能贪婪截断)
|
||||
const value = line.trim().replace(/^- \*\*概述\*\*[::]/, '').trim()
|
||||
return value
|
||||
}
|
||||
|
||||
/** 取「英文名」行里第一个反引号值(`[A-Za-z][A-Za-z0-9]*`);没有 ⇒ null。 */
|
||||
function extractSkillName(sectionText: string): string | null {
|
||||
const line = sectionText
|
||||
.split('\n')
|
||||
.find((l) => /^- \*\*英文名\*\*[::]/.test(l.trim()))
|
||||
if (!line) return null
|
||||
const name = line.match(/`([A-Za-z][A-Za-z0-9]*)`/)?.[1]
|
||||
return name || null
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析技能清单 md → 类型条目数组。**不抛异常**;不合规的节一律跳过。
|
||||
*
|
||||
* @param skillListText native 给的清单正文(md 文本);空 / 非字符串 ⇒ 空数组
|
||||
*/
|
||||
export function parseStrategyClasses(skillListText: string): StrategyClass[] {
|
||||
if (typeof skillListText !== 'string' || !skillListText.trim()) {
|
||||
return []
|
||||
}
|
||||
|
||||
const results: StrategyClass[] = []
|
||||
// 按 `^## ` 切节:`(?=## )` 是「两个井号+空格」—— `# `(单井号)匹配不到
|
||||
// `## XX技能` 标题(`# ` 后面跟的是空格,而标题第二字符是 #)。
|
||||
// split 保留每节含标题行的整块;`# 技能清单` 等单井号块不以 `## ` 开头 ⇒ 天然跳过。
|
||||
const sections = skillListText.split(/^(?=## )/m)
|
||||
for (const section of sections) {
|
||||
if (!section.startsWith('## ')) continue
|
||||
const titleLine = section.split('\n', 1)[0]
|
||||
const className = extractClassName(titleLine.replace(/^## /, ''))
|
||||
if (!className) continue
|
||||
const category = extractCategory(section)
|
||||
if (!category) continue
|
||||
const skillName = extractSkillName(section)
|
||||
if (!skillName) continue
|
||||
results.push({ className, category, skillName, description: extractOverview(section) })
|
||||
}
|
||||
return results
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
import type { StrategyInstance } from '../bridge/contracts'
|
||||
|
||||
/**
|
||||
* 判断一个策略实例是否为「特例实例」(没有可编辑行)。
|
||||
*
|
||||
* **判据是 `data.rows` 为空数组,不是名称匹配** —— 不写死「庄闲差」「庄闲问路」
|
||||
* 「随机注码」等任何实例名,native 侧新增同类特例时无需改这里。
|
||||
*
|
||||
* 为什么只用于「改写策略」任务:这三个特例「只解释,不改写,不生成」
|
||||
* (依据 `src/constants/policySkillsHeader.md` L4 / L22)。解释与生成任务
|
||||
* 不受影响 —— 解释本来就该列出它们,生成走的是类型清单而非实例列表。
|
||||
*
|
||||
* @returns true = 特例实例(应从改写任务的实例列表中排除);
|
||||
* false = 普通实例(保留)。非对象 data / 无 rows / rows 非数组 ⇒ 普通实例。
|
||||
*/
|
||||
export function hasNoEditableRows(instance: StrategyInstance): boolean {
|
||||
const data = instance.data
|
||||
if (typeof data !== 'object' || data === null) return false
|
||||
const rows = (data as { rows?: unknown }).rows
|
||||
return Array.isArray(rows) && rows.length === 0
|
||||
}
|
||||
Reference in New Issue
Block a user