mirror of
https://github.com/kiddin9/op-packages.git
synced 2026-11-02 04:43:56 +08:00
🌈 Sync 2026-04-28 04:37:16
This commit is contained in:
1 parent
c617d785db
commit
37afaea9db
1254 files changed
+150
-652660
No files matched your search
@@ -1111,6 +1111,60 @@ function action_config_data()
|
||||
end
|
||||
|
||||
local function write_runtime_config(base_dir, service_cfg, runtime_cfg)
|
||||
local function is_array(node)
|
||||
if type(node) ~= "table" then
|
||||
return false
|
||||
end
|
||||
local count = 0
|
||||
for k, _ in pairs(node) do
|
||||
if type(k) ~= "number" or k < 1 or k % 1 ~= 0 then
|
||||
return false
|
||||
end
|
||||
count = count + 1
|
||||
end
|
||||
for i = 1, count do
|
||||
if node[i] == nil then
|
||||
return false
|
||||
end
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
local function prune_empty_tables(node)
|
||||
if type(node) ~= "table" then
|
||||
return false
|
||||
end
|
||||
|
||||
if is_array(node) then
|
||||
local compact = {}
|
||||
for i = 1, #node do
|
||||
local value = node[i]
|
||||
if type(value) == "table" then
|
||||
if not prune_empty_tables(value) then
|
||||
compact[#compact + 1] = value
|
||||
end
|
||||
else
|
||||
compact[#compact + 1] = value
|
||||
end
|
||||
end
|
||||
for i = #node, 1, -1 do
|
||||
node[i] = nil
|
||||
end
|
||||
for i = 1, #compact do
|
||||
node[i] = compact[i]
|
||||
end
|
||||
return #node == 0
|
||||
end
|
||||
|
||||
for k, v in pairs(node) do
|
||||
if type(v) == "table" and prune_empty_tables(v) then
|
||||
node[k] = nil
|
||||
end
|
||||
end
|
||||
|
||||
return next(node) == nil
|
||||
end
|
||||
|
||||
local path = config_path(base_dir)
|
||||
if path == "" then
|
||||
return false
|
||||
@@ -1187,6 +1241,8 @@ function action_config_data()
|
||||
local model_cfg = ensure_table(defaults, "model")
|
||||
model_cfg.primary = normalized_model_path(runtime_cfg.default_agent, model_name, infer_custom_provider_model(base_dir))
|
||||
|
||||
prune_empty_tables(cfg)
|
||||
|
||||
return write_json_file(path, cfg)
|
||||
end
|
||||
|
||||
|
||||
Reference in new issue
Block a user