MCPcopy Create free account
hub / github.com/diillson/chatcli / startColocatedGateway

Function startColocatedGateway

cmd/server.go:281–304  ·  view source on GitHub ↗

startColocatedGateway runs the messaging gateway inside the server process when CHATCLI_GATEWAY_IN_SERVER=true, sharing the server's in-memory hub broker so a Telegram/Slack message pushes to a connected notebook CLI in real time (cross-process deployments only sync on connect/resync). It returns a

(llmMgr manager.LLMManager, srv *server.Server, logger *zap.Logger)

Source from the content-addressed store, hash-verified

279// time (cross-process deployments only sync on connect/resync). It returns a
280// stop function to defer, or nil when co-location is disabled or unavailable.
281func startColocatedGateway(llmMgr manager.LLMManager, srv *server.Server, logger *zap.Logger) func() {
282 if !strings.EqualFold(os.Getenv("CHATCLI_GATEWAY_IN_SERVER"), "true") {
283 return nil
284 }
285 broker := srv.Hub()
286 if broker == nil {
287 logger.Warn(i18n.T("cmd.server.gateway_hub_disabled"))
288 return nil
289 }
290 gwCLI, err := cli.NewChatCLI(context.Background(), llmMgr, logger)
291 if err != nil {
292 logger.Warn(i18n.T("cmd.server.gateway_init_failed"), zap.Error(err))
293 return nil
294 }
295 ctx, cancel := context.WithCancel(context.Background())
296 go func() {
297 if err := gwCLI.RunGatewayWithBroker(ctx, broker); err != nil && ctx.Err() == nil {
298 logger.Error(i18n.T("cmd.server.gateway_stopped"), zap.Error(err))
299 }
300 }()
301 logger.Info(i18n.T("cmd.server.gateway_colocated"))
302 fmt.Println(i18n.T("cmd.server.gateway_colocated"))
303 return cancel
304}
305
306// fallbackChainSink is the slice of server.Server's API that
307// initFallbackChain actually needs. Narrowing the parameter type

Callers 1

RunServerFunction · 0.85

Calls 7

RunGatewayWithBrokerMethod · 0.95
TFunction · 0.92
NewChatCLIFunction · 0.92
HubMethod · 0.80
WarnMethod · 0.80
ErrorMethod · 0.65
InfoMethod · 0.65

Tested by

no test coverage detected