mirror of
https://github.com/caiwx86/small-packages.git
synced 2026-11-01 16:44:45 +08:00
update 2026-09-24 16:56:26
This commit is contained in:
1 parent
b31a5c3878
commit
e4cee331e9
6885 files changed
+3240523
No files matched your search
Executable
+28
@@ -0,0 +1,28 @@
|
||||
#
|
||||
# Copyright (C) 2008-2014 The LuCI Team <luci@lists.subsignal.org>
|
||||
#
|
||||
# This is free software, licensed under the Apache License, Version 2.0 .
|
||||
#
|
||||
|
||||
include $(TOPDIR)/rules.mk
|
||||
|
||||
LUCI_TITLE:=kai
|
||||
PKG_VERSION:=1.0.2
|
||||
PKG_RELEASE:=5
|
||||
LUCI_DEPENDS:=+kai +luci-compat +luci-lib-linkeaseauth +linkease-app-entry
|
||||
LUCI_MINIFY_CSS:=0
|
||||
LUCI_MINIFY_JS:=0
|
||||
|
||||
define Package/luci-app-kai/conffiles
|
||||
/etc/config/kai
|
||||
endef
|
||||
|
||||
define Package/luci-app-kai/postrm
|
||||
#!/bin/sh
|
||||
rm -f /tmp/luci-indexcache
|
||||
exit 0
|
||||
endef
|
||||
|
||||
include $(TOPDIR)/feeds/luci/luci.mk
|
||||
|
||||
# call BuildPackage - OpenWrt buildroot signature
|
||||
@@ -0,0 +1,29 @@
|
||||
local http = require "luci.http"
|
||||
|
||||
module("luci.controller.kai", package.seeall)
|
||||
|
||||
function index()
|
||||
if not nixio.fs.access("/etc/config/kai") then
|
||||
return
|
||||
end
|
||||
local page
|
||||
page = entry({"admin", "services","kai"}, cbi("kai"), _("KAI"), 100)
|
||||
page.dependent = true
|
||||
entry({"admin", "services", "kai_status"}, call("kai_status"))
|
||||
|
||||
end
|
||||
|
||||
function kai_status()
|
||||
local sys = require "luci.sys"
|
||||
local uci = require "luci.model.uci".cursor()
|
||||
local port = tonumber(uci:get_first("kai", "kai", "port")) or 8197
|
||||
if port < 1 or port > 65535 or port % 1 ~= 0 then
|
||||
port = 8197
|
||||
end
|
||||
local status = {
|
||||
running = (sys.call("pidof kai_bin >/dev/null") == 0),
|
||||
port = port
|
||||
}
|
||||
http.prepare_content("application/json")
|
||||
http.write_json(status)
|
||||
end
|
||||
@@ -0,0 +1,32 @@
|
||||
local m, s
|
||||
|
||||
m = Map("kai", translate("KAI"), translate("KAI is an efficient AI tool."))
|
||||
m:section(SimpleSection).template = "kai/kai_status"
|
||||
|
||||
s=m:section(TypedSection, "kai", translate("Global settings"))
|
||||
s.addremove=false
|
||||
s.anonymous=true
|
||||
|
||||
s:option(Flag, "enabled", translate("Enable")).rmempty=false
|
||||
|
||||
local kai_model = require "luci.model.kai"
|
||||
local blocks = kai_model.blocks()
|
||||
local home = kai_model.home()
|
||||
|
||||
local data_dir = s:option(Value, "data_dir", translate("Data directory"))
|
||||
data_dir.rmempty = false
|
||||
data_dir.description = translate("Required. KAI session will store cwd/cache/data/config/state under this directory (subfolders: cwd, cache, data, config, state).")
|
||||
|
||||
local paths, default_path = kai_model.find_paths(blocks, home, "Configs")
|
||||
for _, val in pairs(paths) do
|
||||
data_dir:value(val, val)
|
||||
end
|
||||
data_dir.default = default_path
|
||||
|
||||
local port = s:option(Value, "port", translate("API port"))
|
||||
port.default = "8197"
|
||||
port.rmempty = false
|
||||
port.datatype = "port"
|
||||
port.description = translate("Port for KAI HTTP server (kai_bin). kai_session will read OPENCODE_CONFIG via 127.0.0.1:<port>.")
|
||||
|
||||
return m
|
||||
@@ -0,0 +1,54 @@
|
||||
local jsonc = require "luci.jsonc"
|
||||
|
||||
local kai = {}
|
||||
|
||||
kai.blocks = function()
|
||||
local f = io.popen("lsblk -s -f -b -o NAME,FSSIZE,MOUNTPOINT --json", "r")
|
||||
local vals = {}
|
||||
if f then
|
||||
local ret = f:read("*all")
|
||||
f:close()
|
||||
local obj = jsonc.parse(ret)
|
||||
for _, val in pairs(obj and obj["blockdevices"] or {}) do
|
||||
local fsize = val["fssize"]
|
||||
if fsize ~= nil and string.len(fsize) > 10 and val["mountpoint"] then
|
||||
vals[#vals + 1] = val["mountpoint"]
|
||||
end
|
||||
end
|
||||
end
|
||||
return vals
|
||||
end
|
||||
|
||||
kai.home = function()
|
||||
local uci = require "luci.model.uci".cursor()
|
||||
local home_dirs = {}
|
||||
home_dirs["main_dir"] = uci:get_first("quickstart", "main", "main_dir", "/root")
|
||||
home_dirs["Configs"] = uci:get_first("quickstart", "main", "conf_dir", home_dirs["main_dir"] .. "/Configs")
|
||||
home_dirs["Public"] = uci:get_first("quickstart", "main", "pub_dir", home_dirs["main_dir"] .. "/Public")
|
||||
home_dirs["Downloads"] = uci:get_first("quickstart", "main", "dl_dir", home_dirs["Public"] .. "/Downloads")
|
||||
home_dirs["Caches"] = uci:get_first("quickstart", "main", "tmp_dir", home_dirs["main_dir"] .. "/Caches")
|
||||
return home_dirs
|
||||
end
|
||||
|
||||
kai.find_paths = function(blocks, home_dirs, path_name)
|
||||
local default_path = ""
|
||||
local paths = {}
|
||||
|
||||
default_path = home_dirs[path_name] .. "/KAI"
|
||||
if #blocks == 0 then
|
||||
table.insert(paths, default_path)
|
||||
else
|
||||
for _, val in pairs(blocks) do
|
||||
table.insert(paths, val .. "/" .. path_name .. "/KAI")
|
||||
end
|
||||
local without_conf_dir = "/root/" .. path_name .. "/KAI"
|
||||
if default_path == without_conf_dir then
|
||||
default_path = paths[1]
|
||||
end
|
||||
end
|
||||
|
||||
return paths, default_path
|
||||
end
|
||||
|
||||
return kai
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
<script type="text/javascript">//<![CDATA[
|
||||
var kaiOpenUrl = '<%=url("admin/services/linkease_apps/open")%>?id=kai';
|
||||
|
||||
XHR.poll(5, '<%=url("admin/services/kai_status")%>', null,function(x, st){
|
||||
var el = document.getElementById('kai_status');
|
||||
if (st && el){
|
||||
if(!st.running){
|
||||
el.innerHTML = '<br/><em style=\"color:red\"><%:The KAI service is not running.%></em>';
|
||||
}
|
||||
if (st.running){
|
||||
el.innerHTML = '<br/><em style=\"color:green\"><%:The KAI service is running.%></em>'
|
||||
+ "<br/><br/><input class=\"btn cbi-button cbi-button-apply\" type=\"button\" value=\" <%:Click to open KAI%> \" onclick=\"window.open(kaiOpenUrl, '_blank', 'noopener')\"/>";
|
||||
}
|
||||
}
|
||||
});
|
||||
//]]></script>
|
||||
|
||||
<fieldset class="cbi-section">
|
||||
<legend><%:Status%></legend>
|
||||
<p id="kai_status">
|
||||
<em><%:Collecting data...%></em>
|
||||
</p>
|
||||
</fieldset>
|
||||
Reference in new issue
Block a user