local-tool/: visionA-local desktop app
- M1: Wails shell + Go server + Next.js UI + Mock mode (macOS dmg ready)
- M2: i18n (zh-TW/en) + Settings 4-tab refactor
- M3: Embedded Python 3.12 runtime (python-build-standalone) + KneronPLUS wheels
- M4: Windows Inno Setup script (build on Windows runner)
- M5: Linux AppImage script + udev rule (build on Linux runner)
- M6: ffmpeg (GPL, pending legal review) + yt-dlp bundled
- Lifecycle: watchServer health check, fatal native dialog,
Wails IPC raise endpoint, stale process cleanup
.autoflow/: full PRD / Design Spec / Architecture / Testing docs
(4 rounds tri-party discussion + cross review)
.github/workflows/: macOS / Windows / Linux build CI
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
101 lines
2.0 KiB
Go
101 lines
2.0 KiB
Go
package model
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"os"
|
|
"strings"
|
|
"sync"
|
|
)
|
|
|
|
type Repository struct {
|
|
models []Model
|
|
mu sync.RWMutex
|
|
}
|
|
|
|
func NewRepository(dataPath string) *Repository {
|
|
r := &Repository{}
|
|
data, err := os.ReadFile(dataPath)
|
|
if err != nil {
|
|
fmt.Printf("Warning: could not load models from %s: %v\n", dataPath, err)
|
|
return r
|
|
}
|
|
if err := json.Unmarshal(data, &r.models); err != nil {
|
|
fmt.Printf("Warning: could not parse models JSON: %v\n", err)
|
|
}
|
|
return r
|
|
}
|
|
|
|
func (r *Repository) List(filter ModelFilter) ([]ModelSummary, int) {
|
|
r.mu.RLock()
|
|
defer r.mu.RUnlock()
|
|
|
|
var results []ModelSummary
|
|
for _, m := range r.models {
|
|
if filter.TaskType != "" && m.TaskType != filter.TaskType {
|
|
continue
|
|
}
|
|
if filter.Hardware != "" {
|
|
found := false
|
|
for _, hw := range m.SupportedHardware {
|
|
if hw == filter.Hardware {
|
|
found = true
|
|
break
|
|
}
|
|
}
|
|
if !found {
|
|
continue
|
|
}
|
|
}
|
|
if filter.Query != "" {
|
|
q := strings.ToLower(filter.Query)
|
|
if !strings.Contains(strings.ToLower(m.Name), q) &&
|
|
!strings.Contains(strings.ToLower(m.Description), q) {
|
|
continue
|
|
}
|
|
}
|
|
results = append(results, m.ToSummary())
|
|
}
|
|
return results, len(results)
|
|
}
|
|
|
|
func (r *Repository) GetByID(id string) (*Model, error) {
|
|
r.mu.RLock()
|
|
defer r.mu.RUnlock()
|
|
|
|
for i := range r.models {
|
|
if r.models[i].ID == id {
|
|
return &r.models[i], nil
|
|
}
|
|
}
|
|
return nil, fmt.Errorf("model not found: %s", id)
|
|
}
|
|
|
|
func (r *Repository) Count() int {
|
|
r.mu.RLock()
|
|
defer r.mu.RUnlock()
|
|
return len(r.models)
|
|
}
|
|
|
|
func (r *Repository) Add(m Model) {
|
|
r.mu.Lock()
|
|
defer r.mu.Unlock()
|
|
r.models = append(r.models, m)
|
|
}
|
|
|
|
func (r *Repository) Remove(id string) error {
|
|
r.mu.Lock()
|
|
defer r.mu.Unlock()
|
|
|
|
for i := range r.models {
|
|
if r.models[i].ID == id {
|
|
if !r.models[i].IsCustom {
|
|
return fmt.Errorf("cannot delete built-in model: %s", id)
|
|
}
|
|
r.models = append(r.models[:i], r.models[i+1:]...)
|
|
return nil
|
|
}
|
|
}
|
|
return fmt.Errorf("model not found: %s", id)
|
|
}
|