Capture complete prompt resources for inspection

This commit is contained in:
2026-11-06 15:18:57 +00:00
parent 4cbd4e2da0
commit bf3d2e19bd
7 changed files with 108 additions and 6 deletions

View File

@@ -32,6 +32,74 @@ type BackendResource struct {
SmokeTests *domain.BackendSmokeTestConfig
}
// PromptResource is the resolved prompt with already captured message text.
type PromptResource struct {
ID, Hash string
DefaultProfile, Description, SessionID *string
Inputs *[]PromptInputResource
Messages []PromptMessageResource
Output PromptOutputResource
}
type PromptInputResource struct {
Name string
Required *bool
ContentType, Description *string
}
type PromptMessageResource struct {
Role, Content string
CacheControl *PromptCacheControlResource
}
type PromptCacheControlResource struct {
Type domain.CacheControlType
TTL *string
}
type PromptOutputResource struct {
Format domain.OutputFormat
ValidationMode domain.ValidationMode
SchemaPath *string
RepairAttempts *int
}
func (state *loaded) InspectPrompt(ctx context.Context, id string) (*PromptResource, error) {
if err := ctx.Err(); err != nil {
return nil, err
}
entry, err := state.lookupPromptEntry(id)
if err != nil {
return nil, promptLookupError(err)
}
raw := entry.resource
result := &PromptResource{ID: id, Hash: entry.hash, DefaultProfile: raw.DefaultProfile, Description: raw.Description, SessionID: raw.SessionID}
if raw.Inputs != nil {
inputs := make([]PromptInputResource, len(raw.Inputs))
for i, input := range raw.Inputs {
inputs[i] = PromptInputResource{Name: input.Name, ContentType: input.ContentType, Description: input.Description}
if state.promptMetadata[id][i].required == fieldValue {
required := input.Required
inputs[i].Required = &required
}
}
result.Inputs = &inputs
}
result.Messages = make([]PromptMessageResource, len(entry.definition.Templates))
for i, message := range entry.definition.Templates {
result.Messages[i] = PromptMessageResource{Role: message.Role, Content: message.Content}
if message.CacheControl != nil {
result.Messages[i].CacheControl = &PromptCacheControlResource{Type: message.CacheControl.Type, TTL: raw.Messages[i].CacheControl.TTL}
}
}
result.Output = PromptOutputResource{Format: entry.definition.Validation.Format, ValidationMode: entry.definition.Validation.ValidationMode, SchemaPath: raw.Output.SchemaPath}
if state.promptRepair[id] {
value := raw.Output.RepairAttempts
result.Output.RepairAttempts = &value
}
return result, nil
}
func (state *loaded) InspectProfile(ctx context.Context, id string) (*ProfileResource, error) {
if err := ctx.Err(); err != nil {
return nil, err