Skip to content

Commit 38cfae9

Browse files
authored
PIR: Add state engine models for email flexibility (#8233)
Task/Issue URL: https://app.asana.com/1/137249556945/project/72649045549333/task/1213886961787938?focus=true ### Description Adds state engine models for email flexibility. ### Steps to test this PR Will be testable on upstream PRs once whole feature is finished. ### UI changes No UI changes <!-- CURSOR_SUMMARY --> --- > [!NOTE] > **Low Risk** > Model and empty handler only; no polling, transitions, or user-facing behavior until later steps. > > **Overview** > Introduces **scaffolding** in the PIR actions runner state engine for polling and storing **email-derived fields** during broker steps, parallel to the existing captcha await flow. > > `PirActionsRunnerStateEngine` gains `emailExtractedData` on `State`, events `EmailDataReceived` and `RetryAwaitEmailData`, and side effect `AwaitEmailData` (broker, address, attempt id, extract fields, polling/timeout, attempt). `PirActionsRunner` routes `AwaitEmailData` to a new `handleAwaitEmailData` that is **not implemented yet** (TODO for a later step / `EmailDataResolver`). > > No runtime behavior change until follow-up work wires transitions and polling. > > <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 9e478a8. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup> <!-- /CURSOR_SUMMARY -->
1 parent 41b64c8 commit 38cfae9

2 files changed

Lines changed: 33 additions & 0 deletions

File tree

pir/pir-impl/src/main/java/com/duckduckgo/pir/impl/common/PirActionsRunner.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,7 @@ class RealPirActionsRunner @AssistedInject constructor(
271271
}
272272

273273
is AwaitCaptchaSolution -> handleAwaitCaptchaSolution(effect)
274+
is SideEffect.AwaitEmailData -> handleAwaitEmailData(effect)
274275
}
275276
}
276277

@@ -358,6 +359,10 @@ class RealPirActionsRunner @AssistedInject constructor(
358359
}
359360
}
360361

362+
private suspend fun handleAwaitEmailData(effect: SideEffect.AwaitEmailData) {
363+
// TODO: Implement in step 5 — poll for email data via EmailDataResolver
364+
}
365+
361366
private suspend fun handleGetCaptchaSolution(effect: GetCaptchaSolution) =
362367
withContext(dispatcherProvider.io()) {
363368
nativeBrokerActionHandler

pir/pir-impl/src/main/java/com/duckduckgo/pir/impl/common/actions/PirActionsRunnerStateEngine.kt

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ interface PirActionsRunnerStateEngine {
5656
val preseeding: Boolean = false,
5757
val actionRetryCount: Int = 0,
5858
val generatedEmailData: GeneratedEmailData? = null,
59+
val emailExtractedData: Map<String, String> = emptyMap(),
5960
val attemptId: String = "",
6061
val stageStatus: PirStageStatus,
6162
)
@@ -137,6 +138,21 @@ interface PirActionsRunnerStateEngine {
137138
data class ConditionExpectationSucceeded(
138139
val conditionActions: List<BrokerAction>,
139140
) : Event()
141+
142+
data class EmailDataReceived(
143+
val emailExtractedData: Map<String, String>,
144+
) : Event()
145+
146+
data class RetryAwaitEmailData(
147+
val actionId: String,
148+
val brokerName: String,
149+
val emailAddress: String,
150+
val attemptId: String,
151+
val extractFields: List<String>,
152+
val pollingIntervalSeconds: Int,
153+
val maxTimeoutSeconds: Int,
154+
val attempt: Int,
155+
) : Event()
140156
}
141157

142158
/**
@@ -181,6 +197,18 @@ interface PirActionsRunnerStateEngine {
181197
) : SideEffect(),
182198
BrokerActionSideEffect
183199

200+
data class AwaitEmailData(
201+
override val actionId: String,
202+
val brokerName: String,
203+
val emailAddress: String,
204+
val attemptId: String,
205+
val extractFields: List<String>,
206+
val pollingIntervalSeconds: Int,
207+
val maxTimeoutSeconds: Int = 60,
208+
val attempt: Int = 0,
209+
) : SideEffect(),
210+
BrokerActionSideEffect
211+
184212
data class LoadUrl(
185213
val url: String,
186214
) : SideEffect()

0 commit comments

Comments
 (0)