mirror of
https://github.com/chenhg5/cc-connect.git
synced 2026-10-25 17:36:43 +08:00
feat(streaming): add per-platform streaming preview control
Add disabled_platforms config option to disable streaming preview for specific platforms (e.g. feishu) where it causes formatting issues. - Add DisabledPlatforms field to StreamPreviewConfig and StreamPreviewCfg - Check platform name against disabled list in canPreview() - Allows pure text messages to use correct message type instead of cards Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
1 parent
44c48de8f2
commit
2160090ec6
4 files changed
+33
-19
No files matched your search
@@ -247,12 +247,15 @@ func main() {
|
||||
spcfg.MinDeltaChars = *cfg.StreamPreview.MinDeltaChars
|
||||
}
|
||||
if cfg.StreamPreview.MaxChars != nil {
|
||||
spcfg.MaxChars = *cfg.StreamPreview.MaxChars
|
||||
}
|
||||
engine.SetStreamPreviewCfg(spcfg)
|
||||
}
|
||||
spcfg.MaxChars = *cfg.StreamPreview.MaxChars
|
||||
}
|
||||
if cfg.StreamPreview.DisabledPlatforms != nil {
|
||||
spcfg.DisabledPlatforms = cfg.StreamPreview.DisabledPlatforms
|
||||
}
|
||||
engine.SetStreamPreviewCfg(spcfg)
|
||||
}
|
||||
|
||||
// Wire rate limiting
|
||||
// Wire rate limiting
|
||||
{
|
||||
maxMsg := 20
|
||||
windowSecs := 60
|
||||
|
||||
+5
-4
@@ -44,10 +44,11 @@ type DisplayConfig struct {
|
||||
|
||||
// StreamPreviewConfig controls real-time streaming preview in IM.
|
||||
type StreamPreviewConfig struct {
|
||||
Enabled *bool `toml:"enabled"` // default true
|
||||
IntervalMs *int `toml:"interval_ms"` // min ms between updates; default 1500
|
||||
MinDeltaChars *int `toml:"min_delta_chars"` // min new chars before update; default 30
|
||||
MaxChars *int `toml:"max_chars"` // max preview length; default 2000
|
||||
Enabled *bool `toml:"enabled"` // default true
|
||||
DisabledPlatforms []string `toml:"disabled_platforms,omitempty"` // platforms where preview is disabled (e.g. ["feishu"])
|
||||
IntervalMs *int `toml:"interval_ms"` // min ms between updates; default 1500
|
||||
MinDeltaChars *int `toml:"min_delta_chars"` // min new chars before update; default 30
|
||||
MaxChars *int `toml:"max_chars"` // max preview length; default 2000
|
||||
}
|
||||
|
||||
// RateLimitConfig controls per-session message rate limiting.
|
||||
|
||||
+19
-9
@@ -3,25 +3,28 @@ package core
|
||||
import (
|
||||
"context"
|
||||
"log/slog"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
// StreamPreviewCfg controls the streaming preview behavior.
|
||||
type StreamPreviewCfg struct {
|
||||
Enabled bool // global toggle
|
||||
IntervalMs int // minimum ms between updates (default 1500)
|
||||
MinDeltaChars int // minimum new chars before sending an update (default 30)
|
||||
MaxChars int // max preview length (default 2000)
|
||||
Enabled bool // global toggle
|
||||
DisabledPlatforms []string // platforms where streaming preview is disabled (e.g. "feishu")
|
||||
IntervalMs int // minimum ms between updates (default 1500)
|
||||
MinDeltaChars int // minimum new chars before sending an update (default 30)
|
||||
MaxChars int // max preview length (default 2000)
|
||||
}
|
||||
|
||||
// DefaultStreamPreviewCfg returns sensible defaults.
|
||||
func DefaultStreamPreviewCfg() StreamPreviewCfg {
|
||||
return StreamPreviewCfg{
|
||||
Enabled: true,
|
||||
IntervalMs: 1500,
|
||||
MinDeltaChars: 30,
|
||||
MaxChars: 2000,
|
||||
Enabled: true,
|
||||
DisabledPlatforms: nil,
|
||||
IntervalMs: 1500,
|
||||
MinDeltaChars: 30,
|
||||
MaxChars: 2000,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -73,11 +76,18 @@ func newStreamPreview(cfg StreamPreviewCfg, p Platform, replyCtx any, ctx contex
|
||||
}
|
||||
}
|
||||
|
||||
// canPreview returns true if the platform supports message updating.
|
||||
// canPreview returns true if the platform supports message updating and is not disabled.
|
||||
func (sp *streamPreview) canPreview() bool {
|
||||
if sp.degraded || !sp.cfg.Enabled {
|
||||
return false
|
||||
}
|
||||
// Check if platform is in disabled list
|
||||
platformName := sp.platform.Name()
|
||||
for _, disabled := range sp.cfg.DisabledPlatforms {
|
||||
if strings.EqualFold(disabled, platformName) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
_, ok := sp.platform.(MessageUpdater)
|
||||
return ok
|
||||
}
|
||||
|
||||
@@ -10,13 +10,13 @@ require (
|
||||
github.com/larksuite/oapi-sdk-go/v3 v3.5.3
|
||||
github.com/line/line-bot-sdk-go/v8 v8.19.0
|
||||
github.com/open-dingtalk/dingtalk-stream-sdk-go v0.9.1
|
||||
github.com/robfig/cron/v3 v3.0.1
|
||||
github.com/slack-go/slack v0.15.0
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/gogo/protobuf v1.3.2 // indirect
|
||||
github.com/google/uuid v1.3.0 // indirect
|
||||
github.com/robfig/cron/v3 v3.0.1 // indirect
|
||||
golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b // indirect
|
||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68 // indirect
|
||||
)
|
||||
Reference in new issue
Block a user