mirror of
https://github.com/kiddin9/op-packages.git
synced 2026-11-01 12:23:56 +08:00
🌈 Sync 2026-09-24 15:19:50
This commit is contained in:
1 parent
b1685a36b7
commit
37ff0ceb2f
126 files changed
+4403
-2879
No files matched your search
+23
-4
@@ -10,10 +10,10 @@ include $(TOPDIR)/rules.mk
|
||||
PKG_ARCH_kai:=$(ARCH)
|
||||
|
||||
PKG_NAME:=kai
|
||||
PKG_VERSION:=0.0.6
|
||||
PKG_RELEASE:=5
|
||||
PKG_VERSION:=linkease-app-entry-runtime-v3.0.22
|
||||
PKG_RELEASE:=6
|
||||
PKG_SOURCE:=$(PKG_NAME)-binary-$(PKG_VERSION).tar.gz
|
||||
PKG_SOURCE_URL:=https://github.com/linkease/istore-packages/releases/download/prebuilt/
|
||||
PKG_SOURCE_URL:=https://github.com/istoreos/istoreos-app-hub/releases/download/kai-runtime-v$(PKG_VERSION)/
|
||||
PKG_HASH:=skip
|
||||
PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)-binary-$(PKG_VERSION)
|
||||
|
||||
@@ -27,6 +27,7 @@ define Package/$(PKG_NAME)
|
||||
CATEGORY:=System
|
||||
SUBMENU:=
|
||||
TITLE:=KAI
|
||||
DEPENDS:=+kai_session +kai-agent +luci-lib-linkeaseauth +linkease-app-entry
|
||||
URL:=https://github.com/Carseason/openwrt-packages
|
||||
endef
|
||||
|
||||
@@ -38,6 +39,19 @@ define Package/$(PKG_NAME)/conffiles
|
||||
/etc/config/kai
|
||||
endef
|
||||
|
||||
define Package/$(PKG_NAME)/prerm
|
||||
#!/bin/sh
|
||||
if [ "$${IPKG_INSTROOT}" = "" ]; then
|
||||
if [ "$$(readlink /usr/share/linkease/apps.d/05-kai-plugin.json 2>/dev/null)" = "/usr/share/kai/kai-plugin.json" ]; then
|
||||
rm -f /usr/share/linkease/apps.d/05-kai-plugin.json
|
||||
fi
|
||||
if [ "$$(readlink /usr/share/linkeasefull/desktop-apps.d/05-kai-plugin.json 2>/dev/null)" = "/usr/share/kai/kai-plugin.json" ]; then
|
||||
rm -f /usr/share/linkeasefull/desktop-apps.d/05-kai-plugin.json
|
||||
fi
|
||||
fi
|
||||
exit 0
|
||||
endef
|
||||
|
||||
define Build/Configure
|
||||
endef
|
||||
|
||||
@@ -45,10 +59,15 @@ define Build/Compile
|
||||
endef
|
||||
|
||||
define Package/$(PKG_NAME)/install
|
||||
$(INSTALL_DIR) $(1)/usr/sbin $(1)/etc/init.d $(1)/etc/config
|
||||
$(INSTALL_DIR) $(1)/usr/sbin $(1)/usr/libexec $(1)/etc/init.d $(1)/etc/config $(1)/usr/share/kai/www $(1)/usr/share/linkease/apps.d $(1)/usr/share/linkeasefull/desktop-apps.d
|
||||
$(INSTALL_BIN) $(PKG_BUILD_DIR)/kai.$(PKG_ARCH_kai) $(1)/usr/sbin/kai_bin
|
||||
$(INSTALL_BIN) ./files/kai-session-launch $(1)/usr/libexec/kai-session-launch
|
||||
$(INSTALL_BIN) ./files/kai.init $(1)/etc/init.d/kai
|
||||
$(INSTALL_CONF) ./files/kai.config $(1)/etc/config/kai
|
||||
$(INSTALL_DATA) ./files/kai-plugin.json $(1)/usr/share/kai/kai-plugin.json
|
||||
$(INSTALL_DATA) ./files/logo.png $(1)/usr/share/kai/www/logo.png
|
||||
ln -sf /usr/share/kai/kai-plugin.json $(1)/usr/share/linkease/apps.d/05-kai-plugin.json
|
||||
ln -sf /usr/share/kai/kai-plugin.json $(1)/usr/share/linkeasefull/desktop-apps.d/05-kai-plugin.json
|
||||
endef
|
||||
|
||||
$(eval $(call BuildPackage,$(PKG_NAME)))
|
||||
@@ -0,0 +1,59 @@
|
||||
{
|
||||
"schemaVersion": 1,
|
||||
"id": "kai",
|
||||
"name": "KAI",
|
||||
"icon": "logo.png",
|
||||
"staticRoot": "/usr/share/kai/www",
|
||||
"desktop": {
|
||||
"mode": "iframe",
|
||||
"target": {
|
||||
"scheme": "http",
|
||||
"hostMode": "request-host",
|
||||
"port": {
|
||||
"default": 8197,
|
||||
"keys": {
|
||||
"uci": "kai.@kai[0].port"
|
||||
}
|
||||
},
|
||||
"path": "/apps/kai/"
|
||||
},
|
||||
"access": {
|
||||
"scope": "lan",
|
||||
"blockedTitle": "请在局域网内打开 KAI",
|
||||
"blockedMessage": "KAI 运行在设备的独立服务端口,请连接设备所在局域网后再打开。"
|
||||
}
|
||||
},
|
||||
"standalone": {
|
||||
"basePath": "/apps/kai/",
|
||||
"externalOpen": {
|
||||
"enabled": true,
|
||||
"label": "在浏览器中打开 KAI"
|
||||
}
|
||||
},
|
||||
"config": {
|
||||
"providerOrder": ["uci"],
|
||||
"providers": {
|
||||
"uci": {
|
||||
"type": "uci"
|
||||
}
|
||||
}
|
||||
},
|
||||
"backend": {
|
||||
"type": "http",
|
||||
"transport": "tcp",
|
||||
"scheme": "http",
|
||||
"host": "127.0.0.1",
|
||||
"portFromUci": "kai.@kai[0].port",
|
||||
"defaultPort": 8197,
|
||||
"upstreamBasePath": "/apps/kai/",
|
||||
"pathMode": "preserve",
|
||||
"proxyMode": "app-base"
|
||||
},
|
||||
"window": {
|
||||
"width": 1180,
|
||||
"height": 760,
|
||||
"singleton": true
|
||||
},
|
||||
"capabilities": ["assistant", "chat"],
|
||||
"categories": ["other"]
|
||||
}
|
||||
Executable
+10
@@ -0,0 +1,10 @@
|
||||
#!/bin/sh
|
||||
set -eu
|
||||
|
||||
if [ "$#" -ne 1 ] || [ -z "$1" ]; then
|
||||
echo "usage: kai-session-launch WORKING_DIRECTORY" >&2
|
||||
exit 2
|
||||
fi
|
||||
|
||||
cd "$1"
|
||||
exec /usr/sbin/kai_session serve --port 8196 --hostname 127.0.0.1
|
||||
@@ -2,3 +2,4 @@ config kai
|
||||
option 'enabled' '0'
|
||||
option 'data_dir' ''
|
||||
option 'port' '8197'
|
||||
option 'auth_mode' 'openwrt_luci'
|
||||
+14
-71
@@ -7,74 +7,12 @@ get_config() {
|
||||
config_get_bool enabled $1 enabled 1
|
||||
config_get data_dir $1 data_dir ""
|
||||
config_get port $1 port "8197"
|
||||
}
|
||||
|
||||
http_get() {
|
||||
local url="$1"
|
||||
if command -v uclient-fetch >/dev/null 2>&1; then
|
||||
uclient-fetch -O /dev/stdout "$url" 2>/dev/null
|
||||
return $?
|
||||
fi
|
||||
if command -v wget >/dev/null 2>&1; then
|
||||
wget -qO- "$url" 2>/dev/null
|
||||
return $?
|
||||
fi
|
||||
if command -v curl >/dev/null 2>&1; then
|
||||
curl -fsL "$url" 2>/dev/null
|
||||
return $?
|
||||
fi
|
||||
return 1
|
||||
}
|
||||
|
||||
maybe_refresh_opencode_skills_cache() {
|
||||
[ -n "$data_dir" ] || return 0
|
||||
[ -n "$port" ] || return 0
|
||||
command -v jsonfilter >/dev/null 2>&1 || return 0
|
||||
|
||||
local cache_root="${data_dir}/cache/opencode/skills"
|
||||
local state_root="${data_dir}/state/opencode"
|
||||
local version_file="${state_root}/skills.manifest.version"
|
||||
local managed_file="${state_root}/skills.managed.list"
|
||||
local manifest_url="http://127.0.0.1:${port}/agentconf/skills/manifest.json"
|
||||
|
||||
[ -d "$cache_root" ] || mkdir -p "$cache_root"
|
||||
[ -d "$state_root" ] || mkdir -p "$state_root"
|
||||
|
||||
local manifest version prev_version skills
|
||||
manifest="$(http_get "$manifest_url")" || return 0
|
||||
version="$(printf '%s' "$manifest" | jsonfilter -e '@.version' 2>/dev/null)"
|
||||
[ -n "$version" ] || return 0
|
||||
|
||||
prev_version=""
|
||||
[ -f "$version_file" ] && prev_version="$(cat "$version_file" 2>/dev/null)"
|
||||
[ "$version" = "$prev_version" ] && return 0
|
||||
|
||||
logger -t kai "opencode skills manifest changed; refreshing managed skill cache"
|
||||
|
||||
if [ -f "$managed_file" ]; then
|
||||
while IFS= read -r s; do
|
||||
[ -n "$s" ] || continue
|
||||
rm -rf "${cache_root}/${s}"
|
||||
done <"$managed_file"
|
||||
fi
|
||||
|
||||
skills="$(printf '%s' "$manifest" | jsonfilter -e '@.skills[*]' 2>/dev/null)"
|
||||
if [ -n "$skills" ]; then
|
||||
printf '%s\n' "$skills" >"$managed_file"
|
||||
printf '%s\n' "$skills" | while IFS= read -r s; do
|
||||
[ -n "$s" ] || continue
|
||||
rm -rf "${cache_root}/${s}"
|
||||
done
|
||||
else
|
||||
: >"$managed_file"
|
||||
fi
|
||||
|
||||
printf '%s\n' "$version" >"$version_file"
|
||||
return 0
|
||||
config_get auth_mode $1 auth_mode "openwrt_luci"
|
||||
}
|
||||
|
||||
start_kai_bin(){
|
||||
procd_open_instance kai_bin
|
||||
procd_set_param env KAI_AUTH_MODE="$auth_mode"
|
||||
procd_set_param command /usr/sbin/kai_bin -a 0.0.0.0 -p "$port"
|
||||
procd_set_param stderr 1
|
||||
procd_set_param respawn
|
||||
@@ -87,15 +25,21 @@ start_kai_session(){
|
||||
procd_open_instance kai_session
|
||||
local root="${data_dir}"
|
||||
local cwd="${data_dir}/cwd"
|
||||
local agent_root="/usr/share/kai/agent"
|
||||
if [ ! -f "${agent_root}/opencode.json" ] || [ ! -d "${agent_root}/skills" ]; then
|
||||
logger -t kai "local OpenCode Agent bundle is missing under ${agent_root}"
|
||||
return 1
|
||||
fi
|
||||
procd_set_param env \
|
||||
OPENCODE_CWD="${cwd}" \
|
||||
OPENCODE_CONFIG="http://127.0.0.1:${port}/agentconf/opencode.json" \
|
||||
OPENCODE_CONFIG="${agent_root}/opencode.json" \
|
||||
KAIPLUS_SKILLS_DIR="${agent_root}/skills" \
|
||||
ISTORE_AI_HELPER_BASE="http://127.0.0.1:${port}" \
|
||||
XDG_CACHE_HOME="${root}/cache" \
|
||||
XDG_DATA_HOME="${root}/data" \
|
||||
XDG_CONFIG_HOME="${root}/config" \
|
||||
XDG_STATE_HOME="${root}/state"
|
||||
procd_set_param command /usr/sbin/kai_session
|
||||
procd_append_param command serve --port "8196" --hostname "127.0.0.1"
|
||||
procd_set_param command /usr/libexec/kai-session-launch "${cwd}"
|
||||
procd_set_param file "${agent_root}/opencode.json" "${agent_root}/manifest.json"
|
||||
procd_set_param stderr 1
|
||||
procd_set_param respawn
|
||||
procd_close_instance
|
||||
@@ -103,7 +47,7 @@ start_kai_session(){
|
||||
start_service() {
|
||||
config_load kai
|
||||
config_foreach get_config kai
|
||||
if [ $enabled != 1 ]; then
|
||||
if [ "$enabled" != 1 ]; then
|
||||
return 1
|
||||
fi
|
||||
if [ -z "${data_dir}" ]; then
|
||||
@@ -119,8 +63,7 @@ start_service() {
|
||||
mkdir_cwd "${data_dir}/data"
|
||||
mkdir_cwd "${data_dir}/config"
|
||||
mkdir_cwd "${data_dir}/state"
|
||||
maybe_refresh_opencode_skills_cache
|
||||
start_kai_session
|
||||
start_kai_session || return 1
|
||||
logger -t kai "Starting KAI Service Completed"
|
||||
}
|
||||
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 20 KiB |
Reference in new issue
Block a user