2026-11-07 04:23:39 +00:00
package ckprompt
import (
commandkit "go.maximumdirect.net/commandkit"
promptkit "go.maximumdirect.net/promptkit"
)
// WithNamespaces enables standard resource namespace selection with explicit
// defaults. Supplied CLI namespace flags replace only the corresponding default.
// Loaders used with this option should leave namespace selection to the adapter.
func WithNamespaces [ I , S any ] ( suite Suite [ I , S ] , defaults promptkit . Namespaces ) Suite [ I , S ] {
suite . namespaces = & defaults
return suite
}
type namespaceInput struct {
prompt , profile , backend commandkit . Supplied [ string ]
}
2026-11-07 04:27:28 +00:00
func namespaceFlags [ I any ] ( destination func ( * I ) * namespaceInput , kinds ... string ) [ ] requestBinding [ I ] {
flags := make ( [ ] requestBinding [ I ] , 0 , len ( kinds ) )
2026-11-07 04:23:39 +00:00
for _ , kind := range kinds {
2026-11-07 04:27:28 +00:00
var definition requestFlagDefinition
2026-11-07 04:23:39 +00:00
var field func ( * namespaceInput ) * commandkit . Supplied [ string ]
switch kind {
case "prompt" :
2026-11-07 04:27:28 +00:00
definition = namespaceFlagDefinitions . prompt
2026-11-07 04:23:39 +00:00
field = func ( input * namespaceInput ) * commandkit . Supplied [ string ] { return & input . prompt }
case "profile" :
2026-11-07 04:27:28 +00:00
definition = namespaceFlagDefinitions . profile
2026-11-07 04:23:39 +00:00
field = func ( input * namespaceInput ) * commandkit . Supplied [ string ] { return & input . profile }
case "backend" :
2026-11-07 04:27:28 +00:00
definition = namespaceFlagDefinitions . backend
2026-11-07 04:23:39 +00:00
field = func ( input * namespaceInput ) * commandkit . Supplied [ string ] { return & input . backend }
}
2026-11-07 04:27:28 +00:00
flags = append ( flags , requestBinding [ I ] { commandkit . ValueFlag ( definition . meta , ( * string ) ( nil ) , parseDefinitionString , func ( input * I , value commandkit . Supplied [ string ] ) { * field ( destination ( input ) ) = value } ) , definition } )
2026-11-07 04:23:39 +00:00
}
return flags
}
var namespaceFlagDefinitions = struct { prompt , profile , backend requestFlagDefinition } {
2026-11-07 23:31:14 +00:00
prompt : requestFlagDefinition { commandkit . FlagMeta { Name : "llm-prompt-namespace" , Usage : "Use this namespace for unqualified prompt IDs." } , [ ] string { "prompt-namespace" } } ,
profile : requestFlagDefinition { commandkit . FlagMeta { Name : "llm-profile-namespace" , Usage : "Use this namespace for unqualified profile IDs." } , [ ] string { "profile-namespace" } } ,
backend : requestFlagDefinition { commandkit . FlagMeta { Name : "llm-backend-namespace" , Usage : "Use this namespace for unqualified backend IDs." } , [ ] string { "backend-namespace" } } ,
2026-11-07 04:23:39 +00:00
}
func selectedNamespaces ( defaults * promptkit . Namespaces , selected namespaceInput ) * promptkit . Namespaces {
if defaults == nil {
return nil
}
value := * defaults
if selected . prompt . Set {
value . Prompt = selected . prompt . Value
}
if selected . profile . Set {
value . Profile = selected . profile . Value
}
if selected . backend . Set {
value . Backend = selected . backend . Value
}
return & value
}
func namespacedEngine ( engine * promptkit . Engine , namespaces * promptkit . Namespaces ) ( * promptkit . Engine , error ) {
if namespaces == nil {
return engine , nil
}
return engine . WithNamespaces ( * namespaces )
}