mirror of
https://github.com/memohai/Memoh.git
synced 2026-04-27 07:16:19 +09:00
64378d29ed
* feat(web): add provider oauth management ui * feat: add OAuth callback support on port 1455 * feat: enhance reasoning effort options and support for OpenAI Codex OAuth * feat: update twilight-ai dependency to v0.3.4 * refactor: promote openai-codex to first-class client_type, remove auth_type Replace the previous openai-responses + metadata auth_type=openai-codex-oauth combo with a dedicated openai-codex client_type. OAuth requirement is now determined solely by client_type, eliminating the auth_type concept from the LLM provider domain entirely. - Add openai-codex to DB CHECK constraint (migration 0047) with data migration - Add ClientTypeOpenAICodex constant and dedicated SDK/probe branches - Remove AuthType from SDKModelConfig, ModelCredentials, TriggerConfig, etc. - Simplify supportsOAuth to check client_type == openai-codex - Add conf/providers/codex.yaml preset with Codex catalog models - Frontend: replace auth_type selector with client_type-driven OAuth UI --------- Co-authored-by: Acbox <acbox0328@gmail.com>
64 lines
1.7 KiB
Go
64 lines
1.7 KiB
Go
package flow
|
|
|
|
import (
|
|
"context"
|
|
"log/slog"
|
|
|
|
"github.com/memohai/memoh/internal/compaction"
|
|
"github.com/memohai/memoh/internal/conversation"
|
|
"github.com/memohai/memoh/internal/models"
|
|
"github.com/memohai/memoh/internal/providers"
|
|
)
|
|
|
|
func (r *Resolver) maybeCompact(ctx context.Context, req conversation.ChatRequest, rc resolvedContext, inputTokens int) {
|
|
if r.compactionService == nil || r.settingsService == nil {
|
|
return
|
|
}
|
|
settings, err := r.settingsService.GetBot(ctx, req.BotID)
|
|
if err != nil {
|
|
r.logger.Warn("compaction: failed to load settings", slog.Any("error", err))
|
|
return
|
|
}
|
|
if !settings.CompactionEnabled || settings.CompactionThreshold <= 0 {
|
|
return
|
|
}
|
|
if !compaction.ShouldCompact(inputTokens, settings.CompactionThreshold) {
|
|
return
|
|
}
|
|
|
|
modelID := settings.CompactionModelID
|
|
if modelID == "" {
|
|
modelID = rc.model.ID
|
|
}
|
|
|
|
cfg := compaction.TriggerConfig{
|
|
BotID: req.BotID,
|
|
SessionID: req.SessionID,
|
|
}
|
|
|
|
model, err := r.modelsService.GetByID(ctx, modelID)
|
|
if err != nil {
|
|
r.logger.Warn("compaction: failed to resolve model", slog.Any("error", err))
|
|
return
|
|
}
|
|
cfg.ModelID = model.ModelID
|
|
|
|
provider, err := models.FetchProviderByID(ctx, r.queries, model.LlmProviderID)
|
|
if err != nil {
|
|
r.logger.Warn("compaction: failed to fetch provider", slog.Any("error", err))
|
|
return
|
|
}
|
|
authResolver := providers.NewService(nil, r.queries, "")
|
|
creds, err := authResolver.ResolveModelCredentials(ctx, provider)
|
|
if err != nil {
|
|
r.logger.Warn("compaction: failed to resolve provider credentials", slog.Any("error", err))
|
|
return
|
|
}
|
|
cfg.ClientType = provider.ClientType
|
|
cfg.APIKey = creds.APIKey
|
|
cfg.CodexAccountID = creds.CodexAccountID
|
|
cfg.BaseURL = provider.BaseUrl
|
|
|
|
r.compactionService.TriggerCompaction(ctx, cfg)
|
|
}
|