Anydoc / anydoc parser engine (push) Canceled after 0s
App / Format, vet, test, and build (push) Canceled after 0s
CLI / test (macos-latest / go 1.26) (push) Canceled after 0s
CLI / test (ubuntu-latest / go 1.26) (push) Canceled after 0s
CLI / test (windows-latest / go 1.26) (push) Canceled after 0s
Build and Push Docker Image / build-ui (push) Canceled after 0s
Build and Push Docker Image / build-docreader (push) Canceled after 0s
Build and Push Docker Image / build-sandbox (push) Canceled after 0s
Build and Push Docker Image / build-app (amd64, linux/amd64, ubuntu-latest) (push) Canceled after 0s
Build and Push Docker Image / build-app (arm64, linux/arm64, ubuntu-24.04-arm) (push) Canceled after 0s
DocReader / Python tests and Go client tests (push) Canceled after 0s
Build & Publish (dsh-weknora) / Typecheck, test, pack (push) Canceled after 0s
Build & Publish (dsh-weknora) / End-to-end inside dsh (pinned) (push) Canceled after 0s
Build & Publish (dsh-weknora) / End-to-end inside dsh (latest, advisory) (push) Canceled after 0s
Frontend / Test, type-check, and build (push) Canceled after 0s
Go Lint Cache / warm lint cache (.) (push) Canceled after 0s
Go Lint Cache / warm lint cache (cli) (push) Canceled after 0s
Go Lint Cache / warm lint cache (client) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.10) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.11) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.12) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.13) (push) Canceled after 0s
Build and Push Docker Image / merge (push) Canceled after 0s
Build & Publish (dsh-weknora) / Publish to npm (push) Canceled after 0s
Build & Publish (mcp-server) / Build sdist + wheel (push) Canceled after 0s
Build & Publish (mcp-server) / Publish to PyPI (push) Canceled after 0s
203 lines
8.0 KiB
Go
203 lines
8.0 KiB
Go
package workbench
|
|
|
|
import (
|
|
"database/sql/driver"
|
|
"encoding/json"
|
|
"fmt"
|
|
"time"
|
|
)
|
|
|
|
type JSON map[string]any
|
|
|
|
func (j JSON) Value() (driver.Value, error) {
|
|
if j == nil {
|
|
return "{}", nil
|
|
}
|
|
b, e := json.Marshal(j)
|
|
return string(b), e
|
|
}
|
|
func (j *JSON) Scan(v any) error {
|
|
switch x := v.(type) {
|
|
case nil:
|
|
*j = JSON{}
|
|
return nil
|
|
case string:
|
|
return json.Unmarshal([]byte(x), j)
|
|
case []byte:
|
|
return json.Unmarshal(x, j)
|
|
default:
|
|
return fmt.Errorf("invalid JSON type %T", v)
|
|
}
|
|
}
|
|
|
|
type Resource struct {
|
|
pendingMemory *PendingMemory
|
|
ID string `json:"id" gorm:"primaryKey;type:varchar(36)"`
|
|
TenantID uint64 `json:"tenant_id" gorm:"index:wb_resource_scope"`
|
|
OwnerID string `json:"owner_id" gorm:"index:wb_resource_scope;type:varchar(36)"`
|
|
OwnerName string `json:"owner_name"`
|
|
Kind string `json:"kind" gorm:"index:wb_resource_scope;type:varchar(40)"`
|
|
Name string `json:"name"`
|
|
Status string `json:"status"`
|
|
Version int `json:"version"`
|
|
Data JSON `json:"data" gorm:"type:jsonb"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
UpdatedAt time.Time `json:"updated_at"`
|
|
}
|
|
|
|
func (Resource) TableName() string { return "workbench_resources" }
|
|
|
|
type Revision struct {
|
|
ID string `gorm:"primaryKey;type:varchar(36)" json:"id"`
|
|
TenantID uint64 `json:"tenant_id"`
|
|
ResourceID string `json:"resource_id" gorm:"uniqueIndex:wb_revision"`
|
|
Version int `json:"version" gorm:"uniqueIndex:wb_revision"`
|
|
ActorID string `json:"actor_id"`
|
|
Data JSON `json:"data" gorm:"type:jsonb"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
}
|
|
|
|
func (Revision) TableName() string { return "workbench_revisions" }
|
|
|
|
type ActionRequest struct {
|
|
QualitySettings *QualitySettings `json:"quality_settings,omitempty"`
|
|
Version int `json:"version"`
|
|
Advice string `json:"advice"`
|
|
Day int `json:"day"`
|
|
SegmentID string `json:"segment_id"`
|
|
AgentID string `json:"agent_id"`
|
|
NodeID string `json:"node_id,omitempty"`
|
|
Quote string `json:"quote,omitempty"`
|
|
}
|
|
|
|
type Job struct {
|
|
ID string `json:"id" gorm:"primaryKey;type:varchar(36)"`
|
|
TenantID uint64 `json:"tenant_id" gorm:"index"`
|
|
OwnerID string `json:"owner_id"`
|
|
ResourceID string `json:"resource_id" gorm:"index"`
|
|
Kind string `json:"kind"`
|
|
Action string `json:"action"`
|
|
Status string `json:"status" gorm:"index"`
|
|
Progress int `json:"progress"`
|
|
Stage string `json:"stage"`
|
|
Error string `json:"error"`
|
|
Generation JSON `json:"generation,omitempty" gorm:"type:jsonb"`
|
|
Request JSON `json:"-" gorm:"type:jsonb"`
|
|
LeaseToken string `json:"-"`
|
|
LeaseUntil *time.Time `json:"-"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
UpdatedAt time.Time `json:"updated_at"`
|
|
}
|
|
|
|
func (Job) TableName() string { return "workbench_jobs" }
|
|
|
|
type Event struct {
|
|
ID string `json:"id" gorm:"primaryKey;type:varchar(36)"`
|
|
TenantID uint64 `json:"tenant_id" gorm:"index"`
|
|
OwnerID string `json:"owner_id" gorm:"index"`
|
|
ResourceID string `json:"resource_id"`
|
|
Action string `json:"action"`
|
|
Message string `json:"message"`
|
|
Level string `json:"level"`
|
|
Read bool `json:"read"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
}
|
|
|
|
func (Event) TableName() string { return "workbench_events" }
|
|
|
|
type Node struct {
|
|
ID string `json:"id"`
|
|
Label string `json:"label"`
|
|
Children []Node `json:"children,omitempty"`
|
|
}
|
|
type Day struct {
|
|
Day int `json:"day"`
|
|
Title string `json:"title"`
|
|
Prerequisite string `json:"prerequisite"`
|
|
Hook string `json:"hook"`
|
|
Nodes []Node `json:"nodes"`
|
|
Framework string `json:"framework"`
|
|
Confirmed bool `json:"confirmed"`
|
|
}
|
|
type MapData struct {
|
|
ReadingMode string `json:"reading_mode,omitempty"`
|
|
Reading *ReadingReport `json:"reading,omitempty"`
|
|
Topic string `json:"topic"`
|
|
DaysCount int `json:"days_count"`
|
|
DaysAuto bool `json:"days_auto,omitempty"`
|
|
AgentID string `json:"agent_id"`
|
|
KBIDs []string `json:"knowledge_base_ids"`
|
|
KnowledgeIDs []string `json:"knowledge_ids"`
|
|
KnowledgeFolders map[string][]string `json:"knowledge_folders,omitempty"`
|
|
KnowledgeTags map[string][]string `json:"knowledge_tags,omitempty"`
|
|
Days []Day `json:"days"`
|
|
Advice string `json:"advice,omitempty"`
|
|
}
|
|
type FlowNode struct {
|
|
ID string `json:"id"`
|
|
AgentID string `json:"agent_id"`
|
|
Label string `json:"label"`
|
|
}
|
|
type FlowEdge struct {
|
|
Source string `json:"source"`
|
|
Target string `json:"target"`
|
|
}
|
|
type FlowData struct {
|
|
Nodes []FlowNode `json:"nodes"`
|
|
Edges []FlowEdge `json:"edges"`
|
|
Description string `json:"description"`
|
|
KBIDs []string `json:"knowledge_base_ids,omitempty"`
|
|
KnowledgeIDs []string `json:"knowledge_ids,omitempty"`
|
|
KnowledgeFolders map[string][]string `json:"knowledge_folders,omitempty"`
|
|
KnowledgeTags map[string][]string `json:"knowledge_tags,omitempty"`
|
|
}
|
|
type Segment struct {
|
|
MemoryAdvice string `json:"memory_advice,omitempty"`
|
|
CategoryID string `json:"category_id,omitempty"`
|
|
RecommendedCategoryID string `json:"recommended_category_id,omitempty"`
|
|
CategoryReason string `json:"category_reason,omitempty"`
|
|
ID string `json:"id"`
|
|
NodeID string `json:"node_id,omitempty"`
|
|
Title string `json:"title"`
|
|
AgentID string `json:"agent_id"`
|
|
Status string `json:"status"`
|
|
Content string `json:"content"`
|
|
Review string `json:"review"`
|
|
SourceIDs []string `json:"source_ids"`
|
|
}
|
|
type TaskData struct {
|
|
DurationMinutes int `json:"duration_minutes,omitempty"`
|
|
QualitySettings QualitySettings `json:"quality_settings,omitempty"`
|
|
CategoryOptions []SegmentCategory `json:"category_options,omitempty"`
|
|
AgentCategoryOptions map[string][]SegmentCategory `json:"agent_category_options,omitempty"`
|
|
ContinuityAnchors map[string]ContinuityAnchor `json:"continuity_anchors,omitempty"`
|
|
ReadingMode string `json:"reading_mode,omitempty"`
|
|
Reading *ReadingReport `json:"reading,omitempty"`
|
|
SourceText string `json:"source_text,omitempty"`
|
|
SourceImage string `json:"source_image,omitempty"`
|
|
MapID string `json:"map_id"`
|
|
Day int `json:"day"`
|
|
FlowID string `json:"flow_id"`
|
|
AgentID string `json:"agent_id"`
|
|
KBIDs []string `json:"knowledge_base_ids"`
|
|
KnowledgeIDs []string `json:"knowledge_ids"`
|
|
KnowledgeFolders map[string][]string `json:"knowledge_folders,omitempty"`
|
|
KnowledgeTags map[string][]string `json:"knowledge_tags,omitempty"`
|
|
Segments []Segment `json:"segments"`
|
|
Review string `json:"review"`
|
|
Composed string `json:"composed"`
|
|
Quality *QualityReport `json:"quality,omitempty"`
|
|
FlowSnapshot *FlowData `json:"flow_snapshot,omitempty"`
|
|
AgentSnapshots map[string]AgentSnapshot `json:"agent_snapshots,omitempty"`
|
|
}
|
|
|
|
func decode[T any](j JSON) (T, error) {
|
|
var t T
|
|
b, e := json.Marshal(j)
|
|
if e == nil {
|
|
e = json.Unmarshal(b, &t)
|
|
}
|
|
return t, e
|
|
}
|
|
func asJSON(v any) JSON { b, _ := json.Marshal(v); var j JSON; _ = json.Unmarshal(b, &j); return j }
|