Notify callers from the prepared execution snapshot

This commit is contained in:
2026-11-14 17:39:17 +00:00
parent 4cc5a55579
commit 79699acbb9
5 changed files with 95 additions and 2 deletions

View File

@@ -166,7 +166,7 @@ func (r *Runner) Run(ctx context.Context, req domain.RunRequest) (*domain.RunRes
}
directAPIKey := state.effectiveModel.APIKey
return r.executePreparedRun(ctx, operation.run, operation.capture, operation.parent, directAPIKey, state.transientRetries, runID, start, func(
return r.executePreparedRun(ctx, operation.run, req.OnPrepared, operation.capture, operation.parent, directAPIKey, state.transientRetries, runID, start, func(
ctx context.Context,
artifact *domain.Artifact,
attemptsUsed int,
@@ -186,6 +186,7 @@ type preparedValidationFunc func(
func (r *Runner) executePreparedRun(
ctx context.Context,
prepared *domain.PreparedRun,
onPrepared func(context.Context, *domain.PreparedRun),
capture bool,
parent *domain.Exchange,
directAPIKey string,
@@ -194,6 +195,15 @@ func (r *Runner) executePreparedRun(
start time.Time,
validateArtifact preparedValidationFunc,
) (*domain.RunResult, error) {
if onPrepared != nil {
if err := ctx.Err(); err != nil {
return nil, wrapGenerationError(err)
}
onPrepared(ctx, prepared)
if err := ctx.Err(); err != nil {
return nil, wrapGenerationError(err)
}
}
executionTarget := prepared.EffectiveModelParams
executionTarget.APIKey = directAPIKey
genResp, err := r.llm.Generate(ctx, newGenerationRequest(