2026-05-23 17:56:07 +00:00
|
|
|
package proposal_generation
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
"fmt"
|
|
|
|
|
"strings"
|
|
|
|
|
|
2026-10-11 01:40:38 +00:00
|
|
|
"gitea.maximumdirect.net/eric/audita/v3/internal/framework/contracts"
|
2026-11-10 20:42:28 +00:00
|
|
|
"gitea.maximumdirect.net/eric/audita/v3/internal/framework/promptcontext"
|
2026-10-11 01:40:38 +00:00
|
|
|
"gitea.maximumdirect.net/eric/audita/v3/internal/framework/stagename"
|
|
|
|
|
"gitea.maximumdirect.net/eric/audita/v3/internal/prompts"
|
2026-05-23 17:56:07 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type ModuleProposalRequest struct {
|
|
|
|
|
ProposalRequest contracts.ProposalRequest
|
|
|
|
|
PromptID string
|
|
|
|
|
}
|
|
|
|
|
|
2026-11-10 20:42:28 +00:00
|
|
|
// ExecuteModuleProposal prepares and runs a module's selected prompt.
|
2026-05-23 17:56:07 +00:00
|
|
|
func ExecuteModuleProposal(ctx context.Context, req ModuleProposalRequest) (contracts.ProposalResult, error) {
|
|
|
|
|
if strings.TrimSpace(req.PromptID) == "" {
|
|
|
|
|
return contracts.ProposalResult{}, fmt.Errorf("prompt ID must not be empty")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sectionIndex := 0
|
|
|
|
|
if req.ProposalRequest.Section != nil {
|
|
|
|
|
sectionIndex = req.ProposalRequest.Section.Index
|
|
|
|
|
}
|
|
|
|
|
|
2026-11-10 17:33:30 +00:00
|
|
|
transcriptDescription := req.ProposalRequest.Settings.Context.Description
|
2026-05-23 17:56:07 +00:00
|
|
|
|
2026-11-10 20:42:28 +00:00
|
|
|
glossary := req.ProposalRequest.GlossaryVariables
|
|
|
|
|
if glossary == nil {
|
|
|
|
|
prepared, err := promptcontext.PrepareGlossaryVariables(req.ProposalRequest.Glossary, req.ProposalRequest.ProtectedTerms)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return contracts.ProposalResult{}, err
|
|
|
|
|
}
|
|
|
|
|
glossary = &prepared
|
|
|
|
|
}
|
|
|
|
|
variables, err := buildProposalVariables(
|
2026-05-23 17:56:07 +00:00
|
|
|
req.ProposalRequest.WorkingTranscript,
|
2026-11-10 20:42:28 +00:00
|
|
|
*glossary,
|
2026-05-23 17:56:07 +00:00
|
|
|
sectionIndex,
|
|
|
|
|
transcriptDescription,
|
|
|
|
|
)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return contracts.ProposalResult{}, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
promptMetadata, ok := prompts.LookupMetadata(req.PromptID)
|
|
|
|
|
if !ok {
|
|
|
|
|
return contracts.ProposalResult{}, fmt.Errorf("unknown prompt ID %q", req.PromptID)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
generated, err := GenerateCandidates(ctx, Request{
|
2026-11-10 17:37:41 +00:00
|
|
|
StageIndex: req.ProposalRequest.StageIndex, StageID: req.ProposalRequest.StageID,
|
2026-09-24 21:48:18 +00:00
|
|
|
ModuleKey: req.ProposalRequest.RunSpec.ModuleKey,
|
|
|
|
|
ModuleInstance: req.ProposalRequest.RunSpec.InstanceName,
|
|
|
|
|
ReplacementPolicy: req.ProposalRequest.RunSpec.ReplacementPolicy,
|
|
|
|
|
WorkingTranscript: req.ProposalRequest.WorkingTranscript,
|
|
|
|
|
Section: req.ProposalRequest.Section,
|
|
|
|
|
PromptID: promptMetadata.PromptID,
|
|
|
|
|
Variables: variables,
|
|
|
|
|
StageName: stagename.ModuleProposal(req.ProposalRequest.RunSpec.InstanceName, sectionIndexPtr(req.ProposalRequest.Section)),
|
|
|
|
|
StartIndex: 0,
|
|
|
|
|
LLMClient: req.ProposalRequest.LLMClient,
|
|
|
|
|
DiagnosticsDir: req.ProposalRequest.DiagnosticsDir,
|
|
|
|
|
ReportDiagnosticError: req.ProposalRequest.ReportDiagnosticError,
|
2026-05-23 17:56:07 +00:00
|
|
|
})
|
|
|
|
|
if err != nil {
|
2026-09-24 17:09:35 +00:00
|
|
|
return contracts.ProposalResult{Operations: generated.Operations}, err
|
2026-05-23 17:56:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return contracts.ProposalResult{
|
2026-09-24 17:09:35 +00:00
|
|
|
Proposals: generated.Corrections,
|
|
|
|
|
Operations: generated.Operations,
|
2026-05-23 17:56:07 +00:00
|
|
|
}, nil
|
|
|
|
|
}
|