mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-02-15 21:41:37 +00:00
fixed dropdown parsing
This commit is contained in:
parent
488747b762
commit
d37c3f26fb
@ -253,7 +253,60 @@ public sealed class PluginAssistants(bool isInternal, LuaState state, PluginType
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AssistantDropdownItem
|
||||||
|
if (val.TryRead<LuaTable>(out var table) && this.TryParseDropdownItem(table, out var item))
|
||||||
|
{
|
||||||
|
result = item;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// List<AssistantDropdownItem>
|
||||||
|
if (val.TryRead<LuaTable>(out var listTable) && this.TryParseDropdownItemList(listTable, out var itemList))
|
||||||
|
{
|
||||||
|
result = itemList;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
result = null!;
|
result = null!;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private bool TryParseDropdownItem(LuaTable table, out AssistantDropdownItem item)
|
||||||
|
{
|
||||||
|
item = new AssistantDropdownItem();
|
||||||
|
|
||||||
|
if (!table.TryGetValue("Value", out var valueVal) || !valueVal.TryRead<string>(out var value))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (!table.TryGetValue("Display", out var displayVal) || !displayVal.TryRead<string>(out var display))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
item.Value = value;
|
||||||
|
item.Display = display;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private bool TryParseDropdownItemList(LuaTable table, out List<AssistantDropdownItem> items)
|
||||||
|
{
|
||||||
|
items = new List<AssistantDropdownItem>();
|
||||||
|
|
||||||
|
var length = table.ArrayLength;
|
||||||
|
for (var i = 1; i <= length; i++)
|
||||||
|
{
|
||||||
|
var value = table[i];
|
||||||
|
|
||||||
|
if (value.TryRead<LuaTable>(out var subTable) && this.TryParseDropdownItem(subTable, out var item))
|
||||||
|
{
|
||||||
|
items.Add(item);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
items = null!;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue
Block a user