From d57dff58f326bc290e81d92463f517d44fba256f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=97=A0=E9=97=BB=E9=A3=8E?= Date: Thu, 18 Jun 2026 18:43:42 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=8D=E6=9E=84=EF=BC=9A=E6=8A=8A=E5=89=A9?= =?UTF-8?q?=E4=BD=99=2012=20=E4=B8=AA=E9=A1=B6=E5=B1=82=E5=8C=85=E5=85=A8?= =?UTF-8?q?=E9=83=A8=E8=BF=81=E5=88=B0=20internal/?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 继续之前的重构:把根目录残留的非数据/资源类子目录(agents、agenttool、ai、 autoreply、completion、conversation、llm、message、mqtpp、stream、 toolmanager、toolrouter)一并搬到 internal/ 下,并把全工程引用它们的 import 路径从 "meshtastic_mqtt_server/" 重写为 "meshtastic_mqtt_server/internal/"。 变更 - git mv 12 个顶层目录进 internal/,无函数体改动。 - 全工程 sed 把 import path 加上 internal/ 前缀,包括 main.go、 internal/bot/bot_service.go、internal/store/bot_store.go 中对 mqtpp 的引用,以及 ai 子系统内部 agents/agenttool/autoreply/conversation/ llm/toolmanager/toolrouter 之间的相互引用。 验证 - go build ./... 通过;go test ./... 全部包通过。 - AI 自动回复链路(main → ai.NewService → autoreply.Service → botSender) 保持不变,仅 import 路径调整。 - 根目录最终只剩 main.go / main_test.go / internal/ 加 go.mod / go.sum 与数据资源目录(dist、doc、firmware、py、win、meshmap_frontend)。 Co-Authored-By: Claude --- .../agents}/calculator/calculator.go | 2 +- {agents => internal/agents}/time/time.go | 2 +- {agenttool => internal/agenttool}/registry.go | 0 {ai => internal/ai}/service.go | 16 ++++++++-------- {autoreply => internal/autoreply}/botsender.go | 0 {autoreply => internal/autoreply}/queue.go | 0 {autoreply => internal/autoreply}/service.go | 12 ++++++------ internal/bot/bot_service.go | 2 +- .../completion}/completion.go | 4 ++-- {conversation => internal/conversation}/store.go | 2 +- {llm => internal/llm}/state.go | 0 {message => internal/message}/types.go | 0 {mqtpp => internal/mqtpp}/builder.go | 0 {mqtpp => internal/mqtpp}/builder_test.go | 0 {mqtpp => internal/mqtpp}/mqtpp.go | 0 {mqtpp => internal/mqtpp}/mqtpp_test.go | 0 {mqtpp => internal/mqtpp}/pki.go | 0 {mqtpp => internal/mqtpp}/pki_test.go | 0 internal/store/bot_store.go | 2 +- {stream => internal/stream}/stream.go | 0 {toolmanager => internal/toolmanager}/manager.go | 2 +- {toolrouter => internal/toolrouter}/loop.go | 10 +++++----- {toolrouter => internal/toolrouter}/state.go | 2 +- {toolrouter => internal/toolrouter}/tools.go | 8 ++++---- main.go | 8 ++++---- 25 files changed, 36 insertions(+), 36 deletions(-) rename {agents => internal/agents}/calculator/calculator.go (99%) rename {agents => internal/agents}/time/time.go (98%) rename {agenttool => internal/agenttool}/registry.go (100%) rename {ai => internal/ai}/service.go (89%) rename {autoreply => internal/autoreply}/botsender.go (100%) rename {autoreply => internal/autoreply}/queue.go (100%) rename {autoreply => internal/autoreply}/service.go (98%) rename {completion => internal/completion}/completion.go (97%) rename {conversation => internal/conversation}/store.go (99%) rename {llm => internal/llm}/state.go (100%) rename {message => internal/message}/types.go (100%) rename {mqtpp => internal/mqtpp}/builder.go (100%) rename {mqtpp => internal/mqtpp}/builder_test.go (100%) rename {mqtpp => internal/mqtpp}/mqtpp.go (100%) rename {mqtpp => internal/mqtpp}/mqtpp_test.go (100%) rename {mqtpp => internal/mqtpp}/pki.go (100%) rename {mqtpp => internal/mqtpp}/pki_test.go (100%) rename {stream => internal/stream}/stream.go (100%) rename {toolmanager => internal/toolmanager}/manager.go (98%) rename {toolrouter => internal/toolrouter}/loop.go (96%) rename {toolrouter => internal/toolrouter}/state.go (97%) rename {toolrouter => internal/toolrouter}/tools.go (96%) diff --git a/agents/calculator/calculator.go b/internal/agents/calculator/calculator.go similarity index 99% rename from agents/calculator/calculator.go rename to internal/agents/calculator/calculator.go index 7952998..7922bab 100644 --- a/agents/calculator/calculator.go +++ b/internal/agents/calculator/calculator.go @@ -10,7 +10,7 @@ import ( "math" "strconv" - "meshtastic_mqtt_server/agenttool" + "meshtastic_mqtt_server/internal/agenttool" "github.com/volcengine/volcengine-go-sdk/service/arkruntime/model" ) diff --git a/agents/time/time.go b/internal/agents/time/time.go similarity index 98% rename from agents/time/time.go rename to internal/agents/time/time.go index d2d27d4..42767e5 100644 --- a/agents/time/time.go +++ b/internal/agents/time/time.go @@ -6,7 +6,7 @@ import ( "fmt" "time" - "meshtastic_mqtt_server/agenttool" + "meshtastic_mqtt_server/internal/agenttool" "github.com/volcengine/volcengine-go-sdk/service/arkruntime/model" ) diff --git a/agenttool/registry.go b/internal/agenttool/registry.go similarity index 100% rename from agenttool/registry.go rename to internal/agenttool/registry.go diff --git a/ai/service.go b/internal/ai/service.go similarity index 89% rename from ai/service.go rename to internal/ai/service.go index 8752d55..19e1f60 100644 --- a/ai/service.go +++ b/internal/ai/service.go @@ -6,14 +6,14 @@ import ( "os" "path/filepath" - "meshtastic_mqtt_server/agenttool" - _ "meshtastic_mqtt_server/agents/calculator" - _ "meshtastic_mqtt_server/agents/time" - "meshtastic_mqtt_server/autoreply" - "meshtastic_mqtt_server/conversation" - "meshtastic_mqtt_server/llm" - "meshtastic_mqtt_server/toolmanager" - "meshtastic_mqtt_server/toolrouter" + "meshtastic_mqtt_server/internal/agenttool" + _ "meshtastic_mqtt_server/internal/agents/calculator" + _ "meshtastic_mqtt_server/internal/agents/time" + "meshtastic_mqtt_server/internal/autoreply" + "meshtastic_mqtt_server/internal/conversation" + "meshtastic_mqtt_server/internal/llm" + "meshtastic_mqtt_server/internal/toolmanager" + "meshtastic_mqtt_server/internal/toolrouter" "gorm.io/gorm" ) diff --git a/autoreply/botsender.go b/internal/autoreply/botsender.go similarity index 100% rename from autoreply/botsender.go rename to internal/autoreply/botsender.go diff --git a/autoreply/queue.go b/internal/autoreply/queue.go similarity index 100% rename from autoreply/queue.go rename to internal/autoreply/queue.go diff --git a/autoreply/service.go b/internal/autoreply/service.go similarity index 98% rename from autoreply/service.go rename to internal/autoreply/service.go index a277e86..e4ef805 100644 --- a/autoreply/service.go +++ b/internal/autoreply/service.go @@ -8,12 +8,12 @@ import ( "time" "unicode/utf8" - "meshtastic_mqtt_server/completion" - "meshtastic_mqtt_server/conversation" - "meshtastic_mqtt_server/llm" - "meshtastic_mqtt_server/message" - "meshtastic_mqtt_server/toolmanager" - "meshtastic_mqtt_server/toolrouter" + "meshtastic_mqtt_server/internal/completion" + "meshtastic_mqtt_server/internal/conversation" + "meshtastic_mqtt_server/internal/llm" + "meshtastic_mqtt_server/internal/message" + "meshtastic_mqtt_server/internal/toolmanager" + "meshtastic_mqtt_server/internal/toolrouter" "github.com/volcengine/volcengine-go-sdk/service/arkruntime/model" ) diff --git a/internal/bot/bot_service.go b/internal/bot/bot_service.go index 39f05f8..dec08cd 100644 --- a/internal/bot/bot_service.go +++ b/internal/bot/bot_service.go @@ -16,7 +16,7 @@ import ( "gorm.io/gorm" storepkg "meshtastic_mqtt_server/internal/store" - "meshtastic_mqtt_server/mqtpp" + "meshtastic_mqtt_server/internal/mqtpp" ) const botMaxTextBytes = 200 diff --git a/completion/completion.go b/internal/completion/completion.go similarity index 97% rename from completion/completion.go rename to internal/completion/completion.go index 3b9fc8a..a288d85 100644 --- a/completion/completion.go +++ b/internal/completion/completion.go @@ -6,8 +6,8 @@ import ( "strings" "time" - "meshtastic_mqtt_server/llm" - "meshtastic_mqtt_server/message" + "meshtastic_mqtt_server/internal/llm" + "meshtastic_mqtt_server/internal/message" "github.com/volcengine/volcengine-go-sdk/service/arkruntime/model" ) diff --git a/conversation/store.go b/internal/conversation/store.go similarity index 99% rename from conversation/store.go rename to internal/conversation/store.go index 475b320..17b25f7 100644 --- a/conversation/store.go +++ b/internal/conversation/store.go @@ -11,7 +11,7 @@ import ( "sync" "time" - "meshtastic_mqtt_server/message" + "meshtastic_mqtt_server/internal/message" ) // Store manages conversations stored as JSON files diff --git a/llm/state.go b/internal/llm/state.go similarity index 100% rename from llm/state.go rename to internal/llm/state.go diff --git a/message/types.go b/internal/message/types.go similarity index 100% rename from message/types.go rename to internal/message/types.go diff --git a/mqtpp/builder.go b/internal/mqtpp/builder.go similarity index 100% rename from mqtpp/builder.go rename to internal/mqtpp/builder.go diff --git a/mqtpp/builder_test.go b/internal/mqtpp/builder_test.go similarity index 100% rename from mqtpp/builder_test.go rename to internal/mqtpp/builder_test.go diff --git a/mqtpp/mqtpp.go b/internal/mqtpp/mqtpp.go similarity index 100% rename from mqtpp/mqtpp.go rename to internal/mqtpp/mqtpp.go diff --git a/mqtpp/mqtpp_test.go b/internal/mqtpp/mqtpp_test.go similarity index 100% rename from mqtpp/mqtpp_test.go rename to internal/mqtpp/mqtpp_test.go diff --git a/mqtpp/pki.go b/internal/mqtpp/pki.go similarity index 100% rename from mqtpp/pki.go rename to internal/mqtpp/pki.go diff --git a/mqtpp/pki_test.go b/internal/mqtpp/pki_test.go similarity index 100% rename from mqtpp/pki_test.go rename to internal/mqtpp/pki_test.go diff --git a/internal/store/bot_store.go b/internal/store/bot_store.go index 66631f4..9c2d56c 100644 --- a/internal/store/bot_store.go +++ b/internal/store/bot_store.go @@ -11,7 +11,7 @@ import ( "time" "unicode/utf8" - "meshtastic_mqtt_server/mqtpp" + "meshtastic_mqtt_server/internal/mqtpp" "gorm.io/gorm" ) diff --git a/stream/stream.go b/internal/stream/stream.go similarity index 100% rename from stream/stream.go rename to internal/stream/stream.go diff --git a/toolmanager/manager.go b/internal/toolmanager/manager.go similarity index 98% rename from toolmanager/manager.go rename to internal/toolmanager/manager.go index 3b313e0..abd1614 100644 --- a/toolmanager/manager.go +++ b/internal/toolmanager/manager.go @@ -8,7 +8,7 @@ import ( "sort" "strings" - "meshtastic_mqtt_server/agenttool" + "meshtastic_mqtt_server/internal/agenttool" ) // Manager manages loaded AI tools diff --git a/toolrouter/loop.go b/internal/toolrouter/loop.go similarity index 96% rename from toolrouter/loop.go rename to internal/toolrouter/loop.go index 663ed01..df40de4 100644 --- a/toolrouter/loop.go +++ b/internal/toolrouter/loop.go @@ -6,11 +6,11 @@ import ( "strings" "time" - "meshtastic_mqtt_server/completion" - "meshtastic_mqtt_server/llm" - "meshtastic_mqtt_server/message" - "meshtastic_mqtt_server/stream" - "meshtastic_mqtt_server/toolmanager" + "meshtastic_mqtt_server/internal/completion" + "meshtastic_mqtt_server/internal/llm" + "meshtastic_mqtt_server/internal/message" + "meshtastic_mqtt_server/internal/stream" + "meshtastic_mqtt_server/internal/toolmanager" "github.com/volcengine/volcengine-go-sdk/service/arkruntime/model" ) diff --git a/toolrouter/state.go b/internal/toolrouter/state.go similarity index 97% rename from toolrouter/state.go rename to internal/toolrouter/state.go index 4ec64f1..c060275 100644 --- a/toolrouter/state.go +++ b/internal/toolrouter/state.go @@ -5,7 +5,7 @@ import ( "fmt" "strings" - "meshtastic_mqtt_server/llm" + "meshtastic_mqtt_server/internal/llm" ) // Config holds the tool router configuration diff --git a/toolrouter/tools.go b/internal/toolrouter/tools.go similarity index 96% rename from toolrouter/tools.go rename to internal/toolrouter/tools.go index 49ae0c5..644ce74 100644 --- a/toolrouter/tools.go +++ b/internal/toolrouter/tools.go @@ -6,10 +6,10 @@ import ( "strings" "time" - "meshtastic_mqtt_server/agenttool" - "meshtastic_mqtt_server/llm" - "meshtastic_mqtt_server/stream" - "meshtastic_mqtt_server/toolmanager" + "meshtastic_mqtt_server/internal/agenttool" + "meshtastic_mqtt_server/internal/llm" + "meshtastic_mqtt_server/internal/stream" + "meshtastic_mqtt_server/internal/toolmanager" "github.com/volcengine/volcengine-go-sdk/service/arkruntime/model" ) diff --git a/main.go b/main.go index adf63c0..0032522 100644 --- a/main.go +++ b/main.go @@ -19,8 +19,8 @@ import ( "github.com/mochi-mqtt/server/v2/listeners" "github.com/mochi-mqtt/server/v2/packets" - "meshtastic_mqtt_server/ai" - "meshtastic_mqtt_server/autoreply" + "meshtastic_mqtt_server/internal/ai" + "meshtastic_mqtt_server/internal/autoreply" "meshtastic_mqtt_server/internal/auth" blockingpkg "meshtastic_mqtt_server/internal/blocking" botpkg "meshtastic_mqtt_server/internal/bot" @@ -29,8 +29,8 @@ import ( rspkg "meshtastic_mqtt_server/internal/runtimesettings" storepkg "meshtastic_mqtt_server/internal/store" webpkg "meshtastic_mqtt_server/internal/web" - "meshtastic_mqtt_server/llm" - "meshtastic_mqtt_server/mqtpp" + "meshtastic_mqtt_server/internal/llm" + "meshtastic_mqtt_server/internal/mqtpp" ) const (