更新客户端渲染,更新了壳
This commit is contained in:
@@ -17,7 +17,7 @@ public static class ToolResultBuilder
|
||||
blocks = ToolResultDocument.FromOutput(module, output).Blocks;
|
||||
}
|
||||
|
||||
return Document(module.Id, spec.Result, output, blocks, language: language);
|
||||
return Document(module, spec, output, blocks, language);
|
||||
}
|
||||
|
||||
public static ToolResultDocument FromRemote(ApiEndpoint endpoint, ApiResponse response, string output, string language = "zh-CN")
|
||||
@@ -96,6 +96,11 @@ public static class ToolResultBuilder
|
||||
return BuildRdapBlocks(lines, language);
|
||||
}
|
||||
|
||||
if (module.Id is "sanguosha_skin")
|
||||
{
|
||||
return BuildSanguoshaSkinBlocks(lines, language);
|
||||
}
|
||||
|
||||
if (IsReferenceTool(module.Id))
|
||||
{
|
||||
return BuildReferenceBlocksV2(lines, language);
|
||||
@@ -562,6 +567,95 @@ public static class ToolResultBuilder
|
||||
return blocks.Count == 0 ? GenericTextBlocks(lines, language) : blocks;
|
||||
}
|
||||
|
||||
private static IReadOnlyList<ToolResultBlock> BuildSanguoshaSkinBlocks(IReadOnlyList<string> lines, string language)
|
||||
{
|
||||
var rows = new List<string[]>
|
||||
{
|
||||
new[]
|
||||
{
|
||||
T(language, "皮肤 ID", "Skin ID"),
|
||||
T(language, "条目", "Item"),
|
||||
T(language, "武将", "General"),
|
||||
T(language, "皮肤", "Skin"),
|
||||
T(language, "性别/品质", "Gender / quality")
|
||||
}
|
||||
};
|
||||
var sourcePairs = new List<KeyValuePair<string, string>>();
|
||||
var statuses = new List<ToolResultListItem>();
|
||||
|
||||
foreach (var line in lines)
|
||||
{
|
||||
if (IsSourceLine(line) || line.Contains("data/sanguosha", StringComparison.OrdinalIgnoreCase) || line.Contains("Assets/data/sanguosha", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
sourcePairs.Add(Pair(T(language, "配置来源", "Config source"), SplitValue(line)));
|
||||
continue;
|
||||
}
|
||||
|
||||
if (line.Contains("未找到", StringComparison.OrdinalIgnoreCase) ||
|
||||
line.Contains("缺", StringComparison.OrdinalIgnoreCase) ||
|
||||
line.Contains("修复", StringComparison.OrdinalIgnoreCase) ||
|
||||
line.Contains("not found", StringComparison.OrdinalIgnoreCase) ||
|
||||
line.Contains("missing", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
statuses.Add(new ToolResultListItem("!", line, string.Empty, "error", string.Empty));
|
||||
continue;
|
||||
}
|
||||
|
||||
var parts = line.Split(" / ", StringSplitOptions.TrimEntries);
|
||||
if (parts.Length >= 4)
|
||||
{
|
||||
var id = parts.ElementAtOrDefault(0) ?? string.Empty;
|
||||
var item = parts.ElementAtOrDefault(1) ?? string.Empty;
|
||||
var general = StripLabel(parts.ElementAtOrDefault(2) ?? string.Empty);
|
||||
var skin = StripLabel(parts.ElementAtOrDefault(3) ?? string.Empty);
|
||||
var gender = parts.Length > 4 ? parts[4] : string.Empty;
|
||||
rows.Add([id, item, general, skin, gender]);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(line))
|
||||
{
|
||||
statuses.Add(new ToolResultListItem("i", line, string.Empty, StatusOf(line), string.Empty));
|
||||
}
|
||||
}
|
||||
|
||||
var blocks = new List<ToolResultBlock>();
|
||||
if (rows.Count > 1)
|
||||
{
|
||||
blocks.Add(ToolResultBlock.Metric(
|
||||
T(language, "三国杀皮肤摘要", "Sanguosha skin summary"),
|
||||
[
|
||||
Pair(T(language, "命中皮肤", "Matches"), (rows.Count - 1).ToString()),
|
||||
Pair(T(language, "资源目录", "Resource folder"), "Assets/data/sanguosha"),
|
||||
Pair(T(language, "配置文件", "Config file"), "skin_config.json")
|
||||
],
|
||||
BlockMeta("metric", "summary", "high")));
|
||||
blocks.Add(ToolResultBlock.Table(
|
||||
T(language, "皮肤配置", "Skin configuration"),
|
||||
rows,
|
||||
BlockMeta("table", "sanguosha-skins", "high")));
|
||||
}
|
||||
|
||||
if (sourcePairs.Count > 0)
|
||||
{
|
||||
blocks.Add(ToolResultBlock.KeyValue(
|
||||
T(language, "资源与路径", "Resources and paths"),
|
||||
sourcePairs,
|
||||
BlockMeta("text/plain", "source", "normal")));
|
||||
}
|
||||
|
||||
if (statuses.Count > 0)
|
||||
{
|
||||
blocks.Add(ToolResultBlock.List(
|
||||
ToolResultBlockKind.Status,
|
||||
T(language, "检查结果", "Check result"),
|
||||
statuses,
|
||||
BlockMeta("text/plain", "status", rows.Count > 1 ? "normal" : "high")));
|
||||
}
|
||||
|
||||
return blocks.Count == 0 ? GenericTextBlocks(lines, language) : blocks;
|
||||
}
|
||||
|
||||
private static IReadOnlyList<ToolResultBlock> BuildCodecBlocks(IReadOnlyList<string> lines, string language)
|
||||
{
|
||||
var blocks = new List<ToolResultBlock>();
|
||||
@@ -816,14 +910,15 @@ public static class ToolResultBuilder
|
||||
: ToolResultKind.KeyValueCards;
|
||||
}
|
||||
|
||||
private static ToolResultDocument Document(string toolId, ToolResultKind kind, string output, IReadOnlyList<ToolResultBlock> blocks, string language)
|
||||
private static ToolResultDocument Document(IToolModule module, ToolPageSpec spec, string output, IReadOnlyList<ToolResultBlock> blocks, string language)
|
||||
{
|
||||
return new ToolResultDocument(toolId, kind, output, blocks, Metadata(toolId, kind, language, DisplayProfile(kind)), output, string.Empty, "ok");
|
||||
var experience = ToolResultExperienceCatalog.CreateExperience(module);
|
||||
return new ToolResultDocument(module.Id, spec.Result, output, blocks, Metadata(module.Id, spec.Result, language, DisplayProfile(spec.Result), experience), output, string.Empty, "ok");
|
||||
}
|
||||
|
||||
private static Dictionary<string, string> Metadata(string toolId, ToolResultKind kind, string language, string displayProfile)
|
||||
private static Dictionary<string, string> Metadata(string toolId, ToolResultKind kind, string language, string displayProfile, ToolResultExperience? experience = null)
|
||||
{
|
||||
return new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase)
|
||||
var metadata = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase)
|
||||
{
|
||||
["toolId"] = toolId,
|
||||
["resultKind"] = kind.ToString(),
|
||||
@@ -833,6 +928,17 @@ public static class ToolResultBuilder
|
||||
["dataFreshness"] = "live",
|
||||
["displayProfile"] = displayProfile
|
||||
};
|
||||
if (experience is not null)
|
||||
{
|
||||
metadata["profile"] = experience.Profile;
|
||||
metadata["domain"] = experience.Domain;
|
||||
metadata["preferredBlocks"] = string.Join(",", experience.PreferredBlocks ?? []);
|
||||
metadata["copyPolicy"] = experience.CopyPolicy;
|
||||
metadata["privacyLevel"] = experience.PrivacyLevel;
|
||||
metadata["defaultExpandedBlocks"] = string.Join(",", experience.DefaultExpandedBlocks ?? []);
|
||||
}
|
||||
|
||||
return metadata;
|
||||
}
|
||||
|
||||
private static Dictionary<string, string> RemoteMetadata(ApiEndpoint endpoint, ToolResultKind kind, string language)
|
||||
@@ -922,6 +1028,12 @@ public static class ToolResultBuilder
|
||||
return index >= 0 && index < line.Length - 1 ? line[(index + 1)..].Trim() : line;
|
||||
}
|
||||
|
||||
private static string StripLabel(string value)
|
||||
{
|
||||
var index = value.IndexOfAny([':', ':']);
|
||||
return index >= 0 && index < value.Length - 1 ? value[(index + 1)..].Trim() : value.Trim();
|
||||
}
|
||||
|
||||
private static IEnumerable<string> ExtractLinks(IEnumerable<string> lines)
|
||||
{
|
||||
foreach (var line in lines)
|
||||
|
||||
Reference in New Issue
Block a user