Add durable prompt execution state records
This commit is contained in:
@@ -27,13 +27,19 @@ type FilesystemStore struct {
|
||||
}
|
||||
|
||||
type ArtifactPaths struct {
|
||||
ModuleSnapshot string `json:"moduleSnapshot"`
|
||||
Metadata string `json:"metadata"`
|
||||
DataPackage string `json:"dataPackage"`
|
||||
Preflight string `json:"preflight"`
|
||||
Notification string `json:"notification,omitempty"`
|
||||
RenderedReport string `json:"renderedReport,omitempty"`
|
||||
GeneratedTextRaw string `json:"generatedTextRaw,omitempty"`
|
||||
ModuleSnapshot string `json:"moduleSnapshot"`
|
||||
Metadata string `json:"metadata"`
|
||||
DataPackage string `json:"dataPackage"`
|
||||
Preparation string `json:"preparation,omitempty"`
|
||||
Execution string `json:"execution,omitempty"`
|
||||
// Preflight is retained for the temporary Scriptorium write path. Remove it
|
||||
// with that integration's cutover.
|
||||
Preflight string `json:"preflight"`
|
||||
Notification string `json:"notification,omitempty"`
|
||||
RenderedReport string `json:"renderedReport,omitempty"`
|
||||
GeneratedTextRaw string `json:"generatedTextRaw,omitempty"`
|
||||
// GeneratedTextResult is retained for the temporary Scriptorium write path.
|
||||
// Remove it with that integration's cutover.
|
||||
GeneratedTextResult string `json:"generatedTextResult,omitempty"`
|
||||
GeneratedText string `json:"generatedText,omitempty"`
|
||||
RenderContext string `json:"renderContext,omitempty"`
|
||||
@@ -95,6 +101,8 @@ func (s *FilesystemStore) Paths(resolved report.Resolved) (ArtifactPaths, error)
|
||||
ModuleSnapshot: s.join(s.snapshotsDir, group, validDate, "modules."+metadata.RunID+".json"),
|
||||
Metadata: s.join(s.snapshotsDir, group, validDate, "metadata."+metadata.RunID+".json"),
|
||||
DataPackage: s.join(s.dataPackagesDir, group, validDate, "data_package."+metadata.RunID+".yaml"),
|
||||
Preparation: s.join(s.preflightDir, group, validDate, "prompt_preparation."+metadata.RunID+".json"),
|
||||
Execution: s.join(s.snapshotsDir, group, validDate, "prompt_execution."+metadata.RunID+".json"),
|
||||
Preflight: s.join(s.preflightDir, group, validDate, "render."+metadata.RunID+".json"),
|
||||
Notification: s.join(s.notificationsDir, group, validDate, "distributor."+metadata.RunID+".json"),
|
||||
RenderedReport: s.join(s.reportsDir, group, validDate, "report."+metadata.RunID+".md"),
|
||||
@@ -131,6 +139,30 @@ func (s *FilesystemStore) SavePreflight(_ context.Context, resolved report.Resol
|
||||
}, artifact)
|
||||
}
|
||||
|
||||
func (s *FilesystemStore) SavePromptPreparation(_ context.Context, resolved report.Resolved, artifact PromptPreparationArtifact) (string, error) {
|
||||
if artifact.SchemaVersion == "" {
|
||||
artifact.SchemaVersion = PromptPreparationSchemaVersion
|
||||
}
|
||||
if err := artifact.Validate(); err != nil {
|
||||
return "", err
|
||||
}
|
||||
return s.saveResolvedJSON(resolved, func(paths ArtifactPaths) string {
|
||||
return paths.Preparation
|
||||
}, artifact)
|
||||
}
|
||||
|
||||
func (s *FilesystemStore) SavePromptExecution(_ context.Context, resolved report.Resolved, artifact PromptExecutionArtifact) (string, error) {
|
||||
if artifact.SchemaVersion == "" {
|
||||
artifact.SchemaVersion = PromptExecutionSchemaVersion
|
||||
}
|
||||
if err := artifact.Validate(); err != nil {
|
||||
return "", err
|
||||
}
|
||||
return s.saveResolvedJSON(resolved, func(paths ArtifactPaths) string {
|
||||
return paths.Execution
|
||||
}, artifact)
|
||||
}
|
||||
|
||||
func (s *FilesystemStore) SaveDistributorNotification(_ context.Context, resolved report.Resolved, artifact DistributorNotificationArtifact) (string, error) {
|
||||
if artifact.SchemaVersion == "" {
|
||||
artifact.SchemaVersion = DistributorNotificationSchemaVersion
|
||||
@@ -227,20 +259,8 @@ func (s *FilesystemStore) PrepareRenderedReport(_ context.Context, resolved repo
|
||||
}
|
||||
|
||||
func (s *FilesystemStore) SaveMetadata(_ context.Context, metadata Metadata) (string, error) {
|
||||
if metadata.RunID == "" {
|
||||
return "", fmt.Errorf("metadata run id is required")
|
||||
}
|
||||
if metadata.ModuleSnapshotPath == "" {
|
||||
return "", fmt.Errorf("metadata module snapshot path is required")
|
||||
}
|
||||
if metadata.DataPackagePath == "" {
|
||||
return "", fmt.Errorf("metadata data package path is required")
|
||||
}
|
||||
if metadata.PreflightPath == "" {
|
||||
return "", fmt.Errorf("metadata preflight path is required")
|
||||
}
|
||||
if metadata.MetadataPath == "" {
|
||||
return "", fmt.Errorf("metadata path is required")
|
||||
if err := metadata.Validate(); err != nil {
|
||||
return "", err
|
||||
}
|
||||
if err := fileutil.WriteJSONAtomic(metadata.MetadataPath, metadata); err != nil {
|
||||
return "", err
|
||||
@@ -413,6 +433,34 @@ func (s *FilesystemStore) LoadGeneratedTextResult(_ context.Context, path string
|
||||
return readJSON(path, target)
|
||||
}
|
||||
|
||||
func (s *FilesystemStore) LoadPromptPreparation(_ context.Context, path string) (PromptPreparationArtifact, error) {
|
||||
if path == "" {
|
||||
return PromptPreparationArtifact{}, fmt.Errorf("prompt preparation path is required")
|
||||
}
|
||||
var artifact PromptPreparationArtifact
|
||||
if err := readJSON(path, &artifact); err != nil {
|
||||
return PromptPreparationArtifact{}, err
|
||||
}
|
||||
if err := artifact.Validate(); err != nil {
|
||||
return PromptPreparationArtifact{}, err
|
||||
}
|
||||
return artifact, nil
|
||||
}
|
||||
|
||||
func (s *FilesystemStore) LoadPromptExecution(_ context.Context, path string) (PromptExecutionArtifact, error) {
|
||||
if path == "" {
|
||||
return PromptExecutionArtifact{}, fmt.Errorf("prompt execution path is required")
|
||||
}
|
||||
var artifact PromptExecutionArtifact
|
||||
if err := readJSON(path, &artifact); err != nil {
|
||||
return PromptExecutionArtifact{}, err
|
||||
}
|
||||
if err := artifact.Validate(); err != nil {
|
||||
return PromptExecutionArtifact{}, err
|
||||
}
|
||||
return artifact, nil
|
||||
}
|
||||
|
||||
func (s *FilesystemStore) LoadRenderContext(_ context.Context, path string, target any) error {
|
||||
if path == "" {
|
||||
return fmt.Errorf("render context path is required")
|
||||
@@ -428,6 +476,7 @@ func (s *FilesystemStore) reportRecord(path string) (ReportRecord, error) {
|
||||
if err := readJSON(path, &metadata); err != nil {
|
||||
return ReportRecord{}, err
|
||||
}
|
||||
metadata.MetadataPath = path
|
||||
return ReportRecord{
|
||||
RunID: metadata.RunID,
|
||||
ReportID: metadata.ReportID,
|
||||
|
||||
Reference in New Issue
Block a user