124 lines
3.5 KiB
Go
124 lines
3.5 KiB
Go
|
|
package app
|
||
|
|
|
||
|
|
import (
|
||
|
|
"fmt"
|
||
|
|
"os"
|
||
|
|
"sort"
|
||
|
|
"strings"
|
||
|
|
|
||
|
|
"gitea.maximumdirect.net/eric/narratio/internal/artifactmodel"
|
||
|
|
"gitea.maximumdirect.net/eric/narratio/internal/artifacts"
|
||
|
|
"gitea.maximumdirect.net/eric/narratio/internal/config"
|
||
|
|
"gitea.maximumdirect.net/eric/narratio/internal/manifest"
|
||
|
|
)
|
||
|
|
|
||
|
|
// unavailablePlannedBuiltIns reports selected real inputs that neither exist
|
||
|
|
// nor have a producer scheduled by this projection.
|
||
|
|
func unavailablePlannedBuiltIns(cfg *config.Config, m *manifest.Manifest, projection *workProjection) []string {
|
||
|
|
if cfg == nil || cfg.Pipeline == nil || cfg.Session == nil || m == nil || !suppliedCompletion(cfg, m)["transcribe"] {
|
||
|
|
return nil
|
||
|
|
}
|
||
|
|
paths := artifacts.NewLocalStore(cfg.Pipeline.Workspace.Root).SessionPathsFor(cfg.Session.Campaign, cfg.Session.SessionID)
|
||
|
|
running := map[string]bool{}
|
||
|
|
for _, item := range projection.Stages {
|
||
|
|
if item.Decision.action == stageActionRun {
|
||
|
|
running[item.Name] = true
|
||
|
|
}
|
||
|
|
}
|
||
|
|
missing := map[string]bool{}
|
||
|
|
if running["transcribe"] && strings.TrimSpace(cfg.Session.Inputs.AudioDir) == "" && len(cfg.Session.Inputs.AudioFiles) == 0 && cfg.Session.Inputs.AudioS3 == nil {
|
||
|
|
audioAvailable := false
|
||
|
|
for _, input := range m.Inputs {
|
||
|
|
if input.Kind != "audio" {
|
||
|
|
continue
|
||
|
|
}
|
||
|
|
info, err := os.Stat(artifacts.ResolveSessionLocalPathForRead(paths, input.Path))
|
||
|
|
if err == nil && info.Mode().IsRegular() {
|
||
|
|
audioAvailable = true
|
||
|
|
break
|
||
|
|
}
|
||
|
|
}
|
||
|
|
if !audioAvailable {
|
||
|
|
missing["audio"] = true
|
||
|
|
}
|
||
|
|
}
|
||
|
|
check := func(source string) {
|
||
|
|
id, err := artifacts.NormalizeSessionArtifactSource(source)
|
||
|
|
if err != nil {
|
||
|
|
return
|
||
|
|
}
|
||
|
|
if _, err = artifacts.ResolveSessionArtifact(paths, m, id); err == nil {
|
||
|
|
return
|
||
|
|
}
|
||
|
|
producer := ""
|
||
|
|
if spec, ok := artifactmodel.LookupRuntimeTranscriptArtifact(id); ok {
|
||
|
|
producer = spec.ProducerStage
|
||
|
|
} else if id == artifacts.ArtifactBoundsSession {
|
||
|
|
producer = "trim"
|
||
|
|
}
|
||
|
|
willProduce := running[producer]
|
||
|
|
if willProduce && producer == "render" {
|
||
|
|
names := []string{"normalized", "trimmed"}
|
||
|
|
if cfg.Pipeline.Render != nil {
|
||
|
|
if cfg.Pipeline.Render.Enabled != nil && !*cfg.Pipeline.Render.Enabled {
|
||
|
|
names = nil
|
||
|
|
} else {
|
||
|
|
names = cfg.Pipeline.Render.Variants
|
||
|
|
}
|
||
|
|
}
|
||
|
|
variants, _ := artifactmodel.SelectRenderVariants(names)
|
||
|
|
willProduce = false
|
||
|
|
for _, variant := range variants {
|
||
|
|
if variant.OutputSource == id {
|
||
|
|
willProduce = true
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
if !willProduce {
|
||
|
|
missing[id] = true
|
||
|
|
}
|
||
|
|
}
|
||
|
|
for _, item := range projection.Stages {
|
||
|
|
if item.Decision.action != stageActionRun {
|
||
|
|
continue
|
||
|
|
}
|
||
|
|
switch item.Name {
|
||
|
|
case "render":
|
||
|
|
names := []string{"normalized", "trimmed"}
|
||
|
|
if cfg.Pipeline.Render != nil {
|
||
|
|
if cfg.Pipeline.Render.Enabled != nil && !*cfg.Pipeline.Render.Enabled {
|
||
|
|
continue
|
||
|
|
}
|
||
|
|
names = cfg.Pipeline.Render.Variants
|
||
|
|
}
|
||
|
|
variants, _ := artifactmodel.SelectRenderVariants(names)
|
||
|
|
for _, variant := range variants {
|
||
|
|
check(variant.InputSource)
|
||
|
|
}
|
||
|
|
case "extract":
|
||
|
|
check(artifacts.ArtifactTranscriptFinalTrimmed)
|
||
|
|
case "analyze":
|
||
|
|
if item.Analysis == nil {
|
||
|
|
continue
|
||
|
|
}
|
||
|
|
for _, target := range item.Analysis.ExecutionOrder {
|
||
|
|
for _, input := range cfg.ConcreteArtifacts()[target.Key].Inputs {
|
||
|
|
if input.Required {
|
||
|
|
check(input.Source)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
ids := make([]string, 0, len(missing))
|
||
|
|
for id := range missing {
|
||
|
|
ids = append(ids, id)
|
||
|
|
}
|
||
|
|
sort.Strings(ids)
|
||
|
|
result := make([]string, 0, len(ids))
|
||
|
|
for _, id := range ids {
|
||
|
|
result = append(result, fmt.Sprintf("required source %q is unavailable", id))
|
||
|
|
}
|
||
|
|
return result
|
||
|
|
}
|