F01:新增 /api/v1/system/worker-capabilities,按 job_types 判定 test.upload 执行器是否注册, 服务卡片分「地址可达 / 凭据与库读取 / 执行器能力」三行。 F04:routing-bindings 返回 LIBRARY_SOURCE_KB_* 与一致性,设置页同屏显示入库目标与封存源。 结构:测试绑定与生产目标合并为「知识库映射」。
This commit is contained in:
@@ -1,5 +1,18 @@
|
||||
# Changelog
|
||||
|
||||
## 开发快照 0.1.384(系统设置审查修复:能力心跳、封存源对照、分区合并)
|
||||
|
||||
### Added
|
||||
|
||||
- `GET /api/v1/system/worker-capabilities`:读取 worker 认领记录里的 job_types,
|
||||
页面据此显示“执行器已启用/已停用/无认领”,不再把 readiness 当成可接单。
|
||||
- 测试知识库绑定接口返回整库封存源与一致性状态,设置页同屏对照“入库目标 / 封存源”。
|
||||
|
||||
### Changed
|
||||
|
||||
- 系统设置分区合并为“知识库映射”(测试入库 + 生产目标 + 封存源对照)。
|
||||
- 服务卡片分三行:地址可达、凭据与库读取、执行器能力。
|
||||
|
||||
## 开发快照 0.1.383(发布管理精简 + 系统设置审查修复)
|
||||
|
||||
### Changed
|
||||
|
||||
@@ -3434,6 +3434,26 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"/api/v1/system/worker-capabilities": {
|
||||
"get": {
|
||||
"tags": [
|
||||
"Settings"
|
||||
],
|
||||
"operationId": "getWorkerCapabilities",
|
||||
"summary": "读取 worker 能力心跳(执行器是否注册上传/解析链)",
|
||||
"responses": {
|
||||
"200": {
|
||||
"$ref": "#/components/responses/Envelope"
|
||||
},
|
||||
"400": {
|
||||
"$ref": "#/components/responses/BadRequest"
|
||||
},
|
||||
"500": {
|
||||
"$ref": "#/components/responses/InternalError"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/api/v1/routing-bindings": {
|
||||
"get": {
|
||||
"tags": [
|
||||
|
||||
@@ -41,6 +41,24 @@ type routingBindingView struct {
|
||||
// that had not been uploaded yet. A plain read reports zeros.
|
||||
Replanned int `json:"replanned"`
|
||||
RetiredDuplicates int `json:"retired_duplicates"`
|
||||
// 整库封存源(LIBRARY_SOURCE_KB_*)与“测试入库绑定”是两套配置:
|
||||
// 页面必须同时给出两者,并标明是否一致,避免改绑后名字变了、封存还是旧库。
|
||||
LibrarySourceInternalKB string `json:"library_source_internal_kb"`
|
||||
LibrarySourceExternalKB string `json:"library_source_external_kb"`
|
||||
InternalSourceState string `json:"internal_source_state"`
|
||||
ExternalSourceState string `json:"external_source_state"`
|
||||
}
|
||||
|
||||
// sourceState 只回答“入库目标与封存源是不是同一个库”。
|
||||
func sourceState(binding, source string) string {
|
||||
switch {
|
||||
case source == "":
|
||||
return "unconfigured"
|
||||
case binding == source:
|
||||
return "consistent"
|
||||
default:
|
||||
return "mismatch"
|
||||
}
|
||||
}
|
||||
|
||||
type routingKnowledgeBaseOption struct {
|
||||
@@ -101,7 +119,11 @@ func (config Config) routingBindingPayload(ctx context.Context, replan postgress
|
||||
InternalEnvFallback: storedInternal == "" && config.InternalRoutingKnowledgeBaseID != "",
|
||||
ExternalEnvFallback: storedExternal == "" && config.ExternalRoutingKnowledgeBaseID != "",
|
||||
InternalKBName: names[storedInternal], ExternalKBName: names[storedExternal],
|
||||
UpdatedBy: updatedBy, WeKnoraConnected: connected,
|
||||
LibrarySourceInternalKB: config.LibrarySourceInternalKB,
|
||||
LibrarySourceExternalKB: config.LibrarySourceExternalKB,
|
||||
InternalSourceState: sourceState(internal, config.LibrarySourceInternalKB),
|
||||
ExternalSourceState: sourceState(external, config.LibrarySourceExternalKB),
|
||||
UpdatedBy: updatedBy, WeKnoraConnected: connected,
|
||||
Replanned: replan.Replanned, RetiredDuplicates: replan.RetiredDuplicates,
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -377,6 +377,9 @@ func NewHandler(config Config) (http.Handler, error) {
|
||||
internal, external := config.effectiveRoutingTargets(r.Context())
|
||||
writeJSON(w, http.StatusOK, map[string]any{"data": map[string]bool{"internal_enabled": internal != "", "external_enabled": external != ""}})
|
||||
})
|
||||
mux.HandleFunc("GET /api/v1/system/worker-capabilities", func(w http.ResponseWriter, r *http.Request) {
|
||||
config.handleWorkerCapabilities(w, r)
|
||||
})
|
||||
mux.HandleFunc("GET /api/v1/routing-bindings", func(w http.ResponseWriter, r *http.Request) {
|
||||
if config.RoutingBindings == nil {
|
||||
writeJSON(w, http.StatusServiceUnavailable, map[string]string{"error": "routing bindings storage unavailable"})
|
||||
|
||||
@@ -0,0 +1,91 @@
|
||||
package httpapi
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"slices"
|
||||
"time"
|
||||
|
||||
postgresstore "knowledge-governance/internal/platform/postgres"
|
||||
)
|
||||
|
||||
// workerHeartbeatStore 是队列存活记录的只读视图。页面要回答“执行器在不在”,
|
||||
// 只能看 worker 认领任务时自己写下的 job_types;readiness 只证明接口可达。
|
||||
type workerHeartbeatStore interface {
|
||||
ListWorkerHeartbeats(context.Context) ([]postgresstore.WorkerHeartbeat, error)
|
||||
}
|
||||
|
||||
type workerCapabilityView struct {
|
||||
WorkerID string `json:"worker_id"`
|
||||
JobTypes []string `json:"job_types"`
|
||||
Alive bool `json:"alive"`
|
||||
LastSeenAt string `json:"last_seen_at"`
|
||||
}
|
||||
|
||||
type testUploadCapability struct {
|
||||
State string `json:"state"`
|
||||
Consumers int `json:"consumers"`
|
||||
Detail string `json:"detail"`
|
||||
}
|
||||
|
||||
// 与 qaopsmirror 的工作就绪判定同一个窗口:2 分钟没有认领记录就当作不在线。
|
||||
const workerHeartbeatTTL = 2 * time.Minute
|
||||
|
||||
const testUploadJobType = "test.upload"
|
||||
|
||||
func testUploadCapabilityOf(workers []postgresstore.WorkerHeartbeat, now time.Time) testUploadCapability {
|
||||
alive, consumers := 0, 0
|
||||
for _, worker := range workers {
|
||||
if now.Sub(worker.LastSeenAt) > workerHeartbeatTTL {
|
||||
continue
|
||||
}
|
||||
alive++
|
||||
if slices.Contains(worker.JobTypes, testUploadJobType) {
|
||||
consumers++
|
||||
}
|
||||
}
|
||||
switch {
|
||||
case consumers > 0:
|
||||
return testUploadCapability{State: "enabled", Consumers: consumers,
|
||||
Detail: "上传/解析执行器已注册(认领过 test.upload)"}
|
||||
case alive > 0:
|
||||
return testUploadCapability{State: "disabled", Consumers: 0,
|
||||
Detail: "worker 在线但没有注册 test.upload:上传/解析任务不会被消费"}
|
||||
default:
|
||||
return testUploadCapability{State: "stale", Consumers: 0,
|
||||
Detail: "没有有效的 worker 认领记录:执行器未运行,或从未接单"}
|
||||
}
|
||||
}
|
||||
|
||||
func (config Config) handleWorkerCapabilities(w http.ResponseWriter, r *http.Request) {
|
||||
store, ok := config.Store.(workerHeartbeatStore)
|
||||
if !ok || store == nil {
|
||||
writeJSON(w, http.StatusOK, map[string]any{"data": map[string]any{
|
||||
"test_upload": testUploadCapability{State: "unknown", Detail: "worker 存活记录不可用"},
|
||||
"workers": []workerCapabilityView{},
|
||||
}})
|
||||
return
|
||||
}
|
||||
workers, err := store.ListWorkerHeartbeats(r.Context())
|
||||
if err != nil {
|
||||
writeJSON(w, http.StatusOK, map[string]any{"data": map[string]any{
|
||||
"test_upload": testUploadCapability{State: "unknown", Detail: "读取 worker 存活记录失败"},
|
||||
"workers": []workerCapabilityView{},
|
||||
}})
|
||||
return
|
||||
}
|
||||
now := time.Now().UTC()
|
||||
views := make([]workerCapabilityView, 0, len(workers))
|
||||
for _, worker := range workers {
|
||||
views = append(views, workerCapabilityView{
|
||||
WorkerID: worker.WorkerID,
|
||||
JobTypes: worker.JobTypes,
|
||||
Alive: now.Sub(worker.LastSeenAt) <= workerHeartbeatTTL,
|
||||
LastSeenAt: worker.LastSeenAt.UTC().Format(time.RFC3339),
|
||||
})
|
||||
}
|
||||
writeJSON(w, http.StatusOK, map[string]any{"data": map[string]any{
|
||||
"test_upload": testUploadCapabilityOf(workers, now),
|
||||
"workers": views,
|
||||
}})
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package httpapi
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
postgresstore "knowledge-governance/internal/platform/postgres"
|
||||
)
|
||||
|
||||
func TestTestUploadCapabilityReflectsWorkerHeartbeats(t *testing.T) {
|
||||
now := time.Date(2026, time.November, 17, 7, 0, 0, 0, time.UTC)
|
||||
fresh := now.Add(-10 * time.Second)
|
||||
stale := now.Add(-5 * time.Minute)
|
||||
|
||||
cases := []struct {
|
||||
name string
|
||||
workers []postgresstore.WorkerHeartbeat
|
||||
state string
|
||||
consume int
|
||||
}{
|
||||
{"no heartbeats", nil, "stale", 0},
|
||||
{"heartbeat too old", []postgresstore.WorkerHeartbeat{{LastSeenAt: stale, JobTypes: []string{"test.upload"}}}, "stale", 0},
|
||||
{"worker online without upload chain", []postgresstore.WorkerHeartbeat{{LastSeenAt: fresh, JobTypes: []string{"source.scan.dingtalk"}}}, "disabled", 0},
|
||||
{"enabled consumer", []postgresstore.WorkerHeartbeat{{LastSeenAt: fresh, JobTypes: []string{"test.upload", "test.poll"}}}, "enabled", 1},
|
||||
}
|
||||
for _, tc := range cases {
|
||||
got := testUploadCapabilityOf(tc.workers, now)
|
||||
if got.State != tc.state || got.Consumers != tc.consume {
|
||||
t.Fatalf("%s: got state=%s consumers=%d, want %s/%d", tc.name, got.State, got.Consumers, tc.state, tc.consume)
|
||||
}
|
||||
if got.Detail == "" {
|
||||
t.Fatalf("%s: detail must explain the state", tc.name)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package postgres
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
// WorkerHeartbeat 是队列认领时顺手写下的存活记录(P10)。
|
||||
// 它本来就带 job_types:页面用它判断“这个 worker 有没有注册上传/解析链”,
|
||||
// 不需要再开一张表,也不该拿 readiness 或 env 去猜。
|
||||
type WorkerHeartbeat struct {
|
||||
WorkerID string
|
||||
JobTypes []string
|
||||
StartedAt time.Time
|
||||
LastSeenAt time.Time
|
||||
}
|
||||
|
||||
func (s *Store) ListWorkerHeartbeats(ctx context.Context) ([]WorkerHeartbeat, error) {
|
||||
rows, err := s.db.Query(ctx, `
|
||||
SELECT worker_id, job_types, started_at, last_seen_at
|
||||
FROM worker_heartbeats ORDER BY last_seen_at DESC`)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var out []WorkerHeartbeat
|
||||
for rows.Next() {
|
||||
var hb WorkerHeartbeat
|
||||
var types string
|
||||
if err := rows.Scan(&hb.WorkerID, &types, &hb.StartedAt, &hb.LastSeenAt); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if types != "" {
|
||||
hb.JobTypes = strings.Split(types, ",")
|
||||
}
|
||||
out = append(out, hb)
|
||||
}
|
||||
return out, rows.Err()
|
||||
}
|
||||
@@ -108,7 +108,13 @@ func (handler *PollHandler) Handle(ctx context.Context, job jobs.Job) error {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
cutoff := now.Add(-handler.stallAfter)
|
||||
stall := handler.stallAfter
|
||||
if handler.stallAfterSource != nil {
|
||||
if fromSettings := handler.stallAfterSource(); fromSettings > 0 {
|
||||
stall = fromSettings
|
||||
}
|
||||
}
|
||||
cutoff := now.Add(-stall)
|
||||
lastProgress := publication.LastProgressAt
|
||||
if lastProgress == nil {
|
||||
lastProgress = publication.ProcessingStartedAt
|
||||
|
||||
@@ -186,3 +186,61 @@ func (store *pollStoreStub) MarkStalled(_ context.Context, _ string, _ int, cuto
|
||||
store.stalledCutoff = cutoff
|
||||
return nil
|
||||
}
|
||||
|
||||
// F02 验收:停滞判定必须用“活动配置”的阈值,而不是启动时的常量。
|
||||
// 同一条已经停在同一进度上的解析任务:阈值 30 分钟判停,阈值 2 小时不判停。
|
||||
func TestPollHandlerStallThresholdFollowsActiveSettings(t *testing.T) {
|
||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
_, _ = w.Write([]byte(`{"success":true,"data":{"id":"knowledge-1","knowledge_base_id":"kb-1","parse_status":"processing","updated_at":"2026-09-04T03:00:00Z"}}`))
|
||||
}))
|
||||
defer server.Close()
|
||||
client, err := weknora.NewClient(weknora.ClientConfig{BaseURL: server.URL, APIKey: "test-key", Timeout: time.Second})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
now := time.Date(2026, time.September, 4, 4, 0, 0, 0, time.UTC)
|
||||
progressAt := now.Add(-45 * time.Minute)
|
||||
makeStore := func() *pollStoreStub {
|
||||
return &pollStoreStub{publication: postgresstore.PublicationForPoll{
|
||||
ID: "publication-1", TestKBID: "kb-1", KnowledgeID: "knowledge-1",
|
||||
ProcessingState: governance.ProcessingProcessing, PollSequence: 3,
|
||||
LastProgressAt: &progressAt, ProcessingStartedAt: &progressAt,
|
||||
}}
|
||||
}
|
||||
payload := jobs.Job{Payload: []byte(`{"publication_id":"publication-1","sequence":3}`)}
|
||||
|
||||
// 启动常量 30 分钟、活动配置也是 30 分钟:45 分钟没进度 → 判停。
|
||||
store := makeStore()
|
||||
handler, err := NewPollHandler(PollHandlerConfig{
|
||||
Store: store, Client: client, PollDelay: 15 * time.Second,
|
||||
StallAfter: 30 * time.Minute, Now: func() time.Time { return now },
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := handler.Handle(context.Background(), payload); err != nil {
|
||||
t.Fatalf("Handle() error = %v", err)
|
||||
}
|
||||
if !store.stalledMarked {
|
||||
t.Fatal("30 分钟阈值下 45 分钟无进度应判停")
|
||||
}
|
||||
|
||||
// 活动配置改成 2 小时:同一条任务不应再判停。
|
||||
store = makeStore()
|
||||
handler, err = NewPollHandler(PollHandlerConfig{
|
||||
Store: store, Client: client, PollDelay: 15 * time.Second,
|
||||
StallAfter: 30 * time.Minute,
|
||||
StallAfterSource: func() time.Duration { return 2 * time.Hour },
|
||||
Now: func() time.Time { return now },
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := handler.Handle(context.Background(), payload); err != nil {
|
||||
t.Fatalf("Handle() error = %v", err)
|
||||
}
|
||||
if store.stalledMarked {
|
||||
t.Fatal("活动配置 2 小时阈值下不应判停:阈值没有接入实际判定")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -124,22 +124,46 @@ export function RoutingBindingsSection() {
|
||||
</p>
|
||||
) : null}
|
||||
{bindings ? (
|
||||
<div className="kb-binding-grid">
|
||||
{renderSide(
|
||||
'对内知识库',
|
||||
bindings.internal_kb_id,
|
||||
bindings.internal_kb_name,
|
||||
bindings.internal_env_fallback,
|
||||
bindings.internal_bound_by_ui
|
||||
)}
|
||||
{renderSide(
|
||||
'对外知识库',
|
||||
bindings.external_kb_id,
|
||||
bindings.external_kb_name,
|
||||
bindings.external_env_fallback,
|
||||
bindings.external_bound_by_ui
|
||||
)}
|
||||
</div>
|
||||
<>
|
||||
<div className="source-consistency" role="status" aria-label="入库目标与封存源对照">
|
||||
{(['internal', 'external'] as const).map((scope) => {
|
||||
const binding = scope === 'internal' ? bindings.internal_kb_id : bindings.external_kb_id
|
||||
const source =
|
||||
scope === 'internal' ? bindings.library_source_internal_kb : bindings.library_source_external_kb
|
||||
const state = scope === 'internal' ? bindings.internal_source_state : bindings.external_source_state
|
||||
return (
|
||||
<div key={scope} className={`source-consistency-row ${state}`}>
|
||||
<b>{scope === 'internal' ? '对内' : '对外'}</b>
|
||||
<span>入库目标 {binding ? `${binding.slice(0, 8)}…` : '未绑定'}</span>
|
||||
<span>封存源 {source ? `${source.slice(0, 8)}…` : '未配置(LIBRARY_SOURCE_KB_*)'}</span>
|
||||
<em>
|
||||
{state === 'consistent'
|
||||
? '一致'
|
||||
: state === 'mismatch'
|
||||
? '不一致:改绑定不会改封存源,封存仍导出旧库'
|
||||
: '未配置:整库封存无法定位来源'}
|
||||
</em>
|
||||
</div>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
<div className="kb-binding-grid">
|
||||
{renderSide(
|
||||
'对内知识库',
|
||||
bindings.internal_kb_id,
|
||||
bindings.internal_kb_name,
|
||||
bindings.internal_env_fallback,
|
||||
bindings.internal_bound_by_ui
|
||||
)}
|
||||
{renderSide(
|
||||
'对外知识库',
|
||||
bindings.external_kb_id,
|
||||
bindings.external_kb_name,
|
||||
bindings.external_env_fallback,
|
||||
bindings.external_bound_by_ui
|
||||
)}
|
||||
</div>
|
||||
</>
|
||||
) : null}
|
||||
{bindings && !bindings.weknora_connected ? (
|
||||
<p className="hint">当前读不到 WeKnora 的库列表,只能按 ID 填写;连接恢复后可改为下拉选择。</p>
|
||||
|
||||
@@ -328,8 +328,8 @@ describe('SystemSettingsView', () => {
|
||||
/>
|
||||
</AuthContext.Provider>
|
||||
)
|
||||
expect(view('sources')).toContain('测试知识库绑定')
|
||||
expect(view('sources')).toContain('生产知识库绑定')
|
||||
// 测试绑定与生产目标已合并为「知识库映射」:入库目标、封存源、生产目标同屏。
|
||||
expect(view('sources')).toContain('知识库映射')
|
||||
const bound = view('bindings')
|
||||
expect(bound).toContain('id="settings-routing-bindings"')
|
||||
expect(bound).toContain('分发到对应的测试 WeKnora 知识库')
|
||||
|
||||
@@ -12,6 +12,8 @@ import { useOptionalAuth } from './auth'
|
||||
import { fetchMonitorOverview } from './monitor'
|
||||
import type { MonitorOverview } from './monitor'
|
||||
import { fetchReleaseCapabilities } from './reviewRelease'
|
||||
import { fetchWorkerCapabilities, testUploadLabel } from './systemCapabilities'
|
||||
import type { WorkerCapabilities } from './systemCapabilities'
|
||||
import { fetchCatalogRoutingCapabilities, fetchCatalogSources } from './sourceCatalog'
|
||||
import type { CatalogRoutingCapabilities, CatalogSource } from './sourceCatalog'
|
||||
import { archiveSourceConnection, fetchSourceConnectionList } from './sourceConnections'
|
||||
@@ -35,6 +37,7 @@ interface Props {
|
||||
productionEnabled: boolean
|
||||
productionBackupRestoreVerified?: boolean
|
||||
routingCapabilities: CatalogRoutingCapabilities
|
||||
workerCapabilities?: WorkerCapabilities | null
|
||||
loading: boolean
|
||||
saving: boolean
|
||||
error: string | null
|
||||
@@ -42,16 +45,16 @@ interface Props {
|
||||
onSave: (input: UISettingsCandidateInput) => void
|
||||
onSourcesChanged: () => void
|
||||
onRefresh: () => void
|
||||
initialSection?: SectionKey
|
||||
// 兼容旧入口:'bindings'/'production-bindings' 已合并为“知识库映射”。
|
||||
initialSection?: SectionKey | 'bindings' | 'production-bindings'
|
||||
}
|
||||
|
||||
type SectionKey = 'sources' | 'services' | 'bindings' | 'production-bindings' | 'storage' | 'refresh' | 'members'
|
||||
type SectionKey = 'sources' | 'services' | 'knowledge-map' | 'storage' | 'refresh' | 'members'
|
||||
|
||||
const sections: { key: SectionKey; label: string; adminOnly?: boolean }[] = [
|
||||
{ key: 'sources', label: '数据源配置' },
|
||||
{ key: 'services', label: '服务配置' },
|
||||
{ key: 'bindings', label: '测试知识库绑定' },
|
||||
{ key: 'production-bindings', label: '生产知识库绑定' },
|
||||
{ key: 'knowledge-map', label: '知识库映射' },
|
||||
{ key: 'storage', label: '存储与备份' },
|
||||
{ key: 'refresh', label: '刷新策略' },
|
||||
{ key: 'members', label: '成员与角色', adminOnly: true },
|
||||
@@ -173,6 +176,7 @@ export function SystemSettingsView({
|
||||
productionEnabled,
|
||||
productionBackupRestoreVerified = false,
|
||||
routingCapabilities,
|
||||
workerCapabilities = null,
|
||||
loading,
|
||||
saving,
|
||||
error,
|
||||
@@ -183,7 +187,11 @@ export function SystemSettingsView({
|
||||
}: Props) {
|
||||
const auth = useOptionalAuth()
|
||||
const identity = auth?.identity ?? null
|
||||
const [section, setSection] = useState<SectionKey>(initialSection)
|
||||
const [section, setSection] = useState<SectionKey>(
|
||||
initialSection === 'bindings' || initialSection === 'production-bindings'
|
||||
? 'knowledge-map'
|
||||
: (initialSection as SectionKey)
|
||||
)
|
||||
const [documentRefresh, setDocumentRefresh] = useState<15 | 30 | 60>(settings?.document_refresh_seconds ?? 15)
|
||||
const [resourceRefresh, setResourceRefresh] = useState<30 | 60>(settings?.resource_refresh_seconds ?? 30)
|
||||
const [stalled, setStalled] = useState<1800 | 3600>(settings?.stalled_after_seconds ?? 1800)
|
||||
@@ -326,7 +334,11 @@ export function SystemSettingsView({
|
||||
<article>
|
||||
<b>测试 WeKnora</b>
|
||||
<span>{testWeKnoraLabel(findHealth(monitor, 'WeKnora API'), undefined)}</span>
|
||||
<small>{`${healthStateDetail(findHealth(monitor, 'WeKnora API'), undefined) || '端点探测:未配置'};解析队列 对内 ${routingCapabilities.internal_enabled ? '已配置' : '未配置'} · 对外 ${routingCapabilities.external_enabled ? '已配置' : '未配置'};上传/解析执行器能力不在本卡片验证`}</small>
|
||||
<small>{`${healthStateDetail(findHealth(monitor, 'WeKnora API'), undefined) || '端点探测:未配置'};解析队列 对内 ${routingCapabilities.internal_enabled ? '已配置' : '未配置'} · 对外 ${routingCapabilities.external_enabled ? '已配置' : '未配置'}`}</small>
|
||||
<small className={`worker-capability ${workerCapabilities?.test_upload.state ?? 'unknown'}`}>
|
||||
{testUploadLabel(workerCapabilities)}
|
||||
{workerCapabilities ? `:${workerCapabilities.test_upload.detail}` : ''}
|
||||
</small>
|
||||
</article>
|
||||
<article className="production">
|
||||
<b>生产 WeKnora</b>
|
||||
@@ -447,8 +459,17 @@ export function SystemSettingsView({
|
||||
)}
|
||||
</section>
|
||||
) : null}
|
||||
{section === 'bindings' ? <RoutingBindingsSection /> : null}
|
||||
{section === 'production-bindings' ? <ProductionBindingsSection /> : null}
|
||||
{section === 'knowledge-map' ? (
|
||||
<>
|
||||
<p className="settings-hint-wide">
|
||||
一张图看清三件事:<strong>入库目标</strong>(来源打标分发到此库)、
|
||||
<strong>封存源</strong>(整库封存实际导出的库)、<strong>生产目标</strong>(同步写入的库)。
|
||||
前两者不一致时,发布页显示的名字与封存出来的内容会对不上。
|
||||
</p>
|
||||
<RoutingBindingsSection />
|
||||
<ProductionBindingsSection />
|
||||
</>
|
||||
) : null}
|
||||
{section === 'storage' ? (
|
||||
<>
|
||||
<LibraryStorageSection />
|
||||
@@ -580,6 +601,8 @@ export function SystemSettings() {
|
||||
internal_enabled: false,
|
||||
external_enabled: false,
|
||||
})
|
||||
// 执行器能力单独加载:读不到只是这一行显示未知,不影响其它分区。
|
||||
const [workerCapabilities, setWorkerCapabilities] = useState<WorkerCapabilities | null>(null)
|
||||
const [loading, setLoading] = useState(true)
|
||||
const [saving, setSaving] = useState(false)
|
||||
const [error, setError] = useState<string | null>(null)
|
||||
@@ -613,6 +636,7 @@ export function SystemSettings() {
|
||||
'发布能力'
|
||||
),
|
||||
track(fetchCatalogRoutingCapabilities(controller.signal), setRoutingCapabilities, '路由能力'),
|
||||
track(fetchWorkerCapabilities(controller.signal), setWorkerCapabilities, '执行器能力'),
|
||||
track(fetchActiveUISettings(controller.signal), setSettings, '系统设置'),
|
||||
]).finally(() => {
|
||||
if (controller.signal.aborted) return
|
||||
@@ -660,6 +684,7 @@ export function SystemSettings() {
|
||||
productionEnabled={productionEnabled}
|
||||
productionBackupRestoreVerified={productionBackupRestoreVerified}
|
||||
routingCapabilities={routingCapabilities}
|
||||
workerCapabilities={workerCapabilities}
|
||||
loading={loading}
|
||||
saving={saving}
|
||||
error={error}
|
||||
|
||||
@@ -14,6 +14,11 @@ export interface RoutingBindings {
|
||||
// 本次保存把多少条「还没上传」的待入库项重新指向了新库(读取时为 0)。
|
||||
replanned: number
|
||||
retired_duplicates: number
|
||||
// 整库封存源与“测试入库绑定”是两套配置:这里给出封存源 ID 与一致性判定。
|
||||
library_source_internal_kb: string
|
||||
library_source_external_kb: string
|
||||
internal_source_state: 'consistent' | 'mismatch' | 'unconfigured'
|
||||
external_source_state: 'consistent' | 'mismatch' | 'unconfigured'
|
||||
}
|
||||
|
||||
export interface KnowledgeBaseOption {
|
||||
@@ -38,6 +43,18 @@ function bindingProjection(item: Record<string, unknown>): RoutingBindings {
|
||||
updated_by: typeof item.updated_by === 'string' ? item.updated_by : '',
|
||||
weknora_connected: item.weknora_connected === true,
|
||||
replanned: typeof item.replanned === 'number' ? item.replanned : 0,
|
||||
library_source_internal_kb:
|
||||
typeof item.library_source_internal_kb === 'string' ? item.library_source_internal_kb : '',
|
||||
library_source_external_kb:
|
||||
typeof item.library_source_external_kb === 'string' ? item.library_source_external_kb : '',
|
||||
internal_source_state:
|
||||
item.internal_source_state === 'consistent' || item.internal_source_state === 'mismatch'
|
||||
? item.internal_source_state
|
||||
: 'unconfigured',
|
||||
external_source_state:
|
||||
item.external_source_state === 'consistent' || item.external_source_state === 'mismatch'
|
||||
? item.external_source_state
|
||||
: 'unconfigured',
|
||||
retired_duplicates: typeof item.retired_duplicates === 'number' ? item.retired_duplicates : 0,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
// Worker 能力心跳:页面的“执行器能力”只信 worker 自己上报的记录。
|
||||
export interface WorkerCapability {
|
||||
worker_id: string
|
||||
job_types: string[]
|
||||
alive: boolean
|
||||
last_seen_at: string
|
||||
}
|
||||
|
||||
export interface WorkerCapabilities {
|
||||
test_upload: { state: 'enabled' | 'disabled' | 'stale' | 'unknown'; consumers: number; detail: string }
|
||||
workers: WorkerCapability[]
|
||||
}
|
||||
|
||||
const record = (value: unknown): value is Record<string, unknown> =>
|
||||
Boolean(value) && typeof value === 'object' && !Array.isArray(value)
|
||||
|
||||
export async function fetchWorkerCapabilities(signal?: AbortSignal): Promise<WorkerCapabilities> {
|
||||
const response = await fetch('/api/v1/system/worker-capabilities', { credentials: 'include', signal })
|
||||
if (!response.ok) throw new Error(`读取执行器能力失败(${response.status})`)
|
||||
const body = (await response.json()) as { data?: unknown }
|
||||
const data = record(body.data) ? body.data : {}
|
||||
const upload = record(data.test_upload) ? data.test_upload : {}
|
||||
const state = upload.state
|
||||
const workers = Array.isArray(data.workers)
|
||||
? data.workers.filter(record).map((item) => ({
|
||||
worker_id: typeof item.worker_id === 'string' ? item.worker_id : '',
|
||||
job_types: Array.isArray(item.job_types)
|
||||
? item.job_types.filter((t): t is string => typeof t === 'string')
|
||||
: [],
|
||||
alive: item.alive === true,
|
||||
last_seen_at: typeof item.last_seen_at === 'string' ? item.last_seen_at : '',
|
||||
}))
|
||||
: []
|
||||
return {
|
||||
test_upload: {
|
||||
state: state === 'enabled' || state === 'disabled' || state === 'stale' ? state : 'unknown',
|
||||
consumers: typeof upload.consumers === 'number' ? upload.consumers : 0,
|
||||
detail: typeof upload.detail === 'string' ? upload.detail : '能力心跳不可用',
|
||||
},
|
||||
workers,
|
||||
}
|
||||
}
|
||||
|
||||
export const testUploadLabel = (capabilities: WorkerCapabilities | null): string => {
|
||||
if (!capabilities) return '执行器:未知'
|
||||
switch (capabilities.test_upload.state) {
|
||||
case 'enabled':
|
||||
return `执行器:已启用(${capabilities.test_upload.consumers} 个 worker)`
|
||||
case 'disabled':
|
||||
return '执行器:已停用(不会消费上传/解析)'
|
||||
case 'stale':
|
||||
return '执行器:无心跳(worker 未运行)'
|
||||
default:
|
||||
return '执行器:未知'
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user