Phase 1 (extract the Gateway Service), first stage. Repairs the half-migrated working tree so the default (inproc) daemon path works again while keeping the WIP's direction: - chatTaskActorAdapter is contract-only (no HTTP detour); nil contract returns ErrChatCapabilityUnavailable instead of panicking. - openStores opens the conversation store for both processes again; the standalone gateway no longer owns it exclusively. Phase 1 keeps the daemon's Telegram/email routers and session-memory curator reading the same SQLite file; remote conversations arrive when a process that cannot open the file needs them. - setupLLMAndChat composes the local gateway (setupGatewayChat) in default mode and a remote gRPC client in mode=remote; the returned contract is never nil, and Run handles the error. - taskactions.Service is now the single task-mutation implementation shared by the dashboard (webui TaskActionService), the daemon's local gateway actor, and the NATS responder. The daemon registers taskactions.Register so the standalone Gateway's client can forward actions; transport follows the repo's natsrpc pattern. - uncommitted sessions.proto / SessionStoreService gRPC contract deferred: it has no wired consumers (scope creep for this stage). - task_action_adapter_test.go rewritten against the contract chain. task check passes; archied and archie-gateway both build.
78 lines
3.5 KiB
Go
78 lines
3.5 KiB
Go
package archied
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"github.com/samcharles93/archie-core/internal/agentexec"
|
|
"github.com/samcharles93/archie-core/internal/config"
|
|
"github.com/samcharles93/archie-core/internal/gateway"
|
|
"github.com/samcharles93/archie-core/internal/tools"
|
|
)
|
|
|
|
// setupChatRuntime wires the model runtime, tool registry, persona registry,
|
|
// chat task creator/controller, default chat identity and the release-update
|
|
// service. Both the daemon (its own Telegram/email routers) and the standalone
|
|
// Gateway (the web router) build through this one constructor so the two
|
|
// processes cannot diverge.
|
|
func (b *boot) setupChatRuntime(cfg config.Config) {
|
|
// ── LLM runtime ──────────────────────────────────────────────────
|
|
// Created before gateways so the LLMResponder can be wired into the
|
|
// Telegram router for non-command message processing.
|
|
providers := executionProviders(cfg)
|
|
b.llm = agentexec.NewRuntime(providers)
|
|
b.toolReg = tools.NewRegistry()
|
|
chatModels := newChatModelManager(cfg.Models, cfg.Chat.Models, b.catalogModels)
|
|
chatModels.ApplyModelCatalog(b.catalog)
|
|
b.chatModels = chatModels
|
|
|
|
// ── Persona registry ─────────────────────────────────────────────
|
|
b.personas = gateway.NewPersonaRegistry(gateway.DefaultPersonas())
|
|
|
|
profiles, defaultChatIdentity := chatTaskProfiles(cfg)
|
|
var chatTasks gateway.TaskCreator
|
|
if len(profiles) > 0 {
|
|
chatTasks = gateway.NewStoreTaskCreatorForProfiles(
|
|
chatTaskWriterAdapter{enqueue: b.st.EnqueueChatTask},
|
|
profiles,
|
|
)
|
|
}
|
|
b.chatTasks = chatTasks
|
|
b.defaultChatIdentity = defaultChatIdentity
|
|
b.chatController = gateway.NewStoreTaskController(chatTaskControllerAdapter{
|
|
taskByID: b.st.TaskByID,
|
|
requeue: b.st.Requeue,
|
|
transition: b.st.Transition,
|
|
})
|
|
b.updateService = makeUpdateService(telegramSetup{Cfg: config.NewHolder(cfg)})
|
|
}
|
|
|
|
// setupGatewayChat is the sole production constructor of the local contract.
|
|
// Frontends use its gRPC representation; only this service owns the router.
|
|
func (b *boot) setupGatewayChat(ctx context.Context, actor gateway.ChatTaskActor) gateway.ChatContract {
|
|
b.setupChatRuntime(b.cfg)
|
|
cfg := b.cfg
|
|
router := gateway.NewRouter(b.st, nil, "web")
|
|
router.Version = fmt.Sprintf("Archie\nGateway: %s\nRuntime: %s", gatewayVersion, runtimeVersion)
|
|
router.Models = b.chatModels
|
|
router.Personas = b.personas
|
|
router.Updates = b.updateService
|
|
router.InitSessions(b.chatSessionStore)
|
|
configureTaskCommands(router, b.chatTasks, b.chatController, chatTaskListerAdapter{tasks: b.st.Tasks}, b.defaultChatIdentity)
|
|
setup := telegramSetup{
|
|
Cfg: config.NewHolder(cfg), St: b.st, LLM: b.llm, ChatModels: b.chatModels, ToolReg: b.toolReg,
|
|
Personas: b.personas, ChatTasks: b.chatTasks, ChatController: b.chatController,
|
|
ChatTaskLister: chatTaskListerAdapter{tasks: b.st.Tasks},
|
|
ChatTaskLogs: chatTaskLogReaderAdapter{tasks: b.st.TaskByID, taskLogs: b.taskLogs},
|
|
ChatTaskActor: actor, DefaultChatIdentity: b.defaultChatIdentity, SessionStore: b.chatSessionStore,
|
|
Bus: b.bus, Log: b.log, Secrets: b.secrets,
|
|
}
|
|
router.LLM, router.LLMStream = makeChatLLMResponder(ctx, "web", setup, b.chatSessionStore, router)
|
|
router.Titles = newChatTitleGenerator(setup)
|
|
router.Log = b.log
|
|
return &gateway.LocalChatAdapter{
|
|
Router: router, Sessions: b.chatSessionStore, Turns: gateway.NewTurns(b.log),
|
|
Models: b.chatModels, Personas: b.personas, TaskActor: actor,
|
|
}
|
|
}
|