Add schema selection values and ownership

This commit is contained in:
2026-11-20 15:20:29 +00:00
parent e775a3c116
commit fbe3d427a2
17 changed files with 186 additions and 9 deletions

View File

@@ -1,6 +1,10 @@
package promptkit
import "go.maximumdirect.net/configkit"
import (
"reflect"
"go.maximumdirect.net/configkit"
)
// PromptConfig is a presence-aware source input for one prompt. Extends names
// a sibling prompt. Nil optional pointers and slices are omitted; non-nil
@@ -35,8 +39,9 @@ type PromptCacheControlConfig struct{ Type, TTL *string }
// PromptOutputConfig supplies optional output contract source fields.
type PromptOutputConfig struct {
Format, ValidationMode, SchemaPath *string
RepairAttempts *int
Format, ValidationMode, SchemaPath, SchemaFile *string
Schema any
RepairAttempts *int
}
// PromptSource creates a labeled ConfigKit mapping in caller order. Nil
@@ -118,6 +123,12 @@ func PromptSource(label string, prompts []PromptConfig) configkit.Source {
if config.Output.SchemaPath != nil {
output["schema_path"] = *config.Output.SchemaPath
}
if value := reflect.ValueOf(config.Output.Schema); value.IsValid() && !((value.Kind() == reflect.Pointer || value.Kind() == reflect.Map || value.Kind() == reflect.Slice || value.Kind() == reflect.Interface) && value.IsNil()) {
output["schema"] = config.Output.Schema
}
if config.Output.SchemaFile != nil {
output["schema_file"] = *config.Output.SchemaFile
}
if config.Output.RepairAttempts != nil {
output["repair_attempts"] = *config.Output.RepairAttempts
}