Implement positional prompt execution with native reporting and outcomes
This commit is contained in:
76
internal/adapter/cli/outcomes.go
Normal file
76
internal/adapter/cli/outcomes.go
Normal file
@@ -0,0 +1,76 @@
|
||||
package cli
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
"go.maximumdirect.net/ckconfig"
|
||||
"go.maximumdirect.net/commandkit"
|
||||
"go.maximumdirect.net/promptkit"
|
||||
)
|
||||
|
||||
func completedRunOutcome(result *promptkit.RunResult) commandkit.Outcome {
|
||||
if result == nil {
|
||||
return commandkit.Failure("Prompt execution returned no result.").WithCause(errors.New("engine returned neither a result nor an error"))
|
||||
}
|
||||
if result.Validation.Status == promptkit.ValidationFailed {
|
||||
return commandkit.Domain("validation_failed", 4).WithExplanation("Generated content failed validation.")
|
||||
}
|
||||
return commandkit.Success()
|
||||
}
|
||||
|
||||
func requestFailure(err error, explanation commandkit.Explanation) commandkit.Outcome {
|
||||
message := "The requested operation failed."
|
||||
switch {
|
||||
case errors.Is(err, promptkit.ErrOperationTimeout):
|
||||
message = "The operation timeout expired."
|
||||
case errors.Is(err, context.Canceled):
|
||||
message = "The operation was canceled."
|
||||
case errors.Is(err, context.DeadlineExceeded):
|
||||
message = "The caller deadline expired."
|
||||
default:
|
||||
if ckconfig.ClassifyConfigurationError(err) == commandkit.OutcomeUsage {
|
||||
return commandkit.Usage("Invalid configuration.", explanation.Details...).WithCause(err)
|
||||
}
|
||||
switch {
|
||||
case errors.Is(err, promptkit.ErrCapacityExceeded):
|
||||
message = "Model backend capacity is exhausted."
|
||||
case errors.Is(err, promptkit.ErrLLMGenerate):
|
||||
message = "Model generation failed."
|
||||
case errors.Is(err, promptkit.ErrValidation):
|
||||
message = "The output validation operation failed."
|
||||
case errors.Is(err, promptkit.ErrPromptNotFound):
|
||||
message = "The selected prompt was not found."
|
||||
case errors.Is(err, promptkit.ErrProfileNotFound):
|
||||
message = "The selected profile was not found."
|
||||
case errors.Is(err, promptkit.ErrArtifactLoad):
|
||||
message = "Could not load request input artifacts."
|
||||
case errors.Is(err, promptkit.ErrPromptRender):
|
||||
message = "Could not render the selected prompt."
|
||||
case errors.Is(err, promptkit.ErrInvalidRequest):
|
||||
message = "The prompt request is invalid."
|
||||
case errors.Is(err, promptkit.ErrInvalidConfig):
|
||||
message = "Could not initialize PromptKit configuration."
|
||||
}
|
||||
}
|
||||
return commandkit.Failure(message, explanation.Details...).WithCause(err)
|
||||
}
|
||||
|
||||
func queueDiagnostics(reporter *commandkit.Reporter, diagnostics []commandkit.Diagnostic) {
|
||||
deferred := reporter.AtEnd()
|
||||
for _, diagnostic := range diagnostics {
|
||||
if diagnostic.Write == nil {
|
||||
continue
|
||||
}
|
||||
switch diagnostic.Severity {
|
||||
case commandkit.SeverityInfo:
|
||||
_ = deferred.Info("", diagnostic.Write)
|
||||
case commandkit.SeverityDebug:
|
||||
_ = deferred.Debug("", diagnostic.Write)
|
||||
case commandkit.SeverityProgress:
|
||||
_ = reporter.Progress("", diagnostic.Write)
|
||||
default:
|
||||
_ = deferred.Warn("", diagnostic.Write)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user