version: 2
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
import type { StrategyInstance } from '../bridge/contracts'
|
||||
|
||||
/**
|
||||
* get_policy 的纯函数实现(分组分组已在 chat store 缓存完成)。
|
||||
*
|
||||
* @param bucket 已按分组分好组后的 StrategyInstance[](全量或某一类)
|
||||
* @param name 可选:模糊匹配(name 子串,不区分大小写)
|
||||
* @param id 可选:精确匹配(StrategyInstance.id)
|
||||
*
|
||||
* 命中规则:
|
||||
* - 传 id ⇒ 在 bucket 里按 id 精确取(0 或 1 条)
|
||||
* - 传 name ⇒ 在 bucket 里按 name 子串取(0..N 条;命中多条全返回,模型自行判断)
|
||||
* - 都不传 ⇒ 空数组
|
||||
*
|
||||
* 不抛异常;不解析 `data` 内部。
|
||||
*/
|
||||
export function getPolicy(
|
||||
bucket: StrategyInstance[],
|
||||
name?: string,
|
||||
id?: number,
|
||||
): StrategyInstance[] {
|
||||
if (id !== undefined) {
|
||||
return bucket.filter((s) => s.id === id)
|
||||
}
|
||||
if (name && name.trim()) {
|
||||
const q = name.trim().toLowerCase()
|
||||
return bucket.filter((s) => s.name?.toLowerCase().includes(q))
|
||||
}
|
||||
return []
|
||||
}
|
||||
Reference in New Issue
Block a user