Add PromptKit catalog YAML encoders
This commit is contained in:
@@ -322,6 +322,34 @@ func encodePromptYAML(writer io.Writer, value any) error {
|
||||
return encoder.Encode(value)
|
||||
}
|
||||
|
||||
type promptCatalogEntry struct {
|
||||
ID string `yaml:"id"`
|
||||
Version string `yaml:"version"`
|
||||
}
|
||||
|
||||
func encodePromptCatalog(prompts []promptkit.PromptIdentity) ([]byte, error) {
|
||||
entries := make([]promptCatalogEntry, len(prompts))
|
||||
for index, prompt := range prompts {
|
||||
entries[index] = promptCatalogEntry{ID: prompt.ID, Version: prompt.Version}
|
||||
}
|
||||
return encodePromptYAMLBytes(entries)
|
||||
}
|
||||
|
||||
func encodeProfileCatalog(profiles []string) ([]byte, error) {
|
||||
if profiles == nil {
|
||||
profiles = []string{}
|
||||
}
|
||||
return encodePromptYAMLBytes(profiles)
|
||||
}
|
||||
|
||||
func encodePromptYAMLBytes(value any) ([]byte, error) {
|
||||
var output bytes.Buffer
|
||||
if err := encodePromptYAML(&output, value); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return output.Bytes(), nil
|
||||
}
|
||||
|
||||
func writePromptReport(invocation commandkit.Invocation, output []byte, diagnostics []commandkit.Diagnostic) commandkit.Outcome {
|
||||
if invocation.Context != nil {
|
||||
if err := invocation.Context.Err(); err != nil {
|
||||
|
||||
Reference in New Issue
Block a user