mirror of
https://github.com/openai/codex.git
synced 2026-12-01 00:20:48 +00:00
Resume queued prompts after blocked submit hook
This commit is contained in:
@@ -4493,6 +4493,21 @@
|
||||
}
|
||||
]
|
||||
},
|
||||
"UserPromptSubmitStoppedNotification": {
|
||||
"properties": {
|
||||
"threadId": {
|
||||
"type": "string"
|
||||
},
|
||||
"turnId": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"threadId",
|
||||
"turnId"
|
||||
],
|
||||
"type": "object"
|
||||
},
|
||||
"WarningNotification": {
|
||||
"properties": {
|
||||
"message": {
|
||||
@@ -4969,6 +4984,26 @@
|
||||
"title": "Hook/completedNotification",
|
||||
"type": "object"
|
||||
},
|
||||
{
|
||||
"properties": {
|
||||
"method": {
|
||||
"enum": [
|
||||
"userPromptSubmit/stopped"
|
||||
],
|
||||
"title": "UserPromptSubmit/stoppedNotificationMethod",
|
||||
"type": "string"
|
||||
},
|
||||
"params": {
|
||||
"$ref": "#/definitions/UserPromptSubmitStoppedNotification"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"method",
|
||||
"params"
|
||||
],
|
||||
"title": "UserPromptSubmit/stoppedNotification",
|
||||
"type": "object"
|
||||
},
|
||||
{
|
||||
"properties": {
|
||||
"method": {
|
||||
|
||||
+37
@@ -4042,6 +4042,26 @@
|
||||
"title": "Hook/completedNotification",
|
||||
"type": "object"
|
||||
},
|
||||
{
|
||||
"properties": {
|
||||
"method": {
|
||||
"enum": [
|
||||
"userPromptSubmit/stopped"
|
||||
],
|
||||
"title": "UserPromptSubmit/stoppedNotificationMethod",
|
||||
"type": "string"
|
||||
},
|
||||
"params": {
|
||||
"$ref": "#/definitions/v2/UserPromptSubmitStoppedNotification"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"method",
|
||||
"params"
|
||||
],
|
||||
"title": "UserPromptSubmit/stoppedNotification",
|
||||
"type": "object"
|
||||
},
|
||||
{
|
||||
"properties": {
|
||||
"method": {
|
||||
@@ -17841,6 +17861,23 @@
|
||||
}
|
||||
]
|
||||
},
|
||||
"UserPromptSubmitStoppedNotification": {
|
||||
"$schema": "http://json-schema.org/draft-07/schema#",
|
||||
"properties": {
|
||||
"threadId": {
|
||||
"type": "string"
|
||||
},
|
||||
"turnId": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"threadId",
|
||||
"turnId"
|
||||
],
|
||||
"title": "UserPromptSubmitStoppedNotification",
|
||||
"type": "object"
|
||||
},
|
||||
"Verbosity": {
|
||||
"description": "Controls output length/detail on GPT-5 models via the Responses API. Serialized with lowercase values to match the OpenAI API.",
|
||||
"enum": [
|
||||
|
||||
+37
@@ -11087,6 +11087,26 @@
|
||||
"title": "Hook/completedNotification",
|
||||
"type": "object"
|
||||
},
|
||||
{
|
||||
"properties": {
|
||||
"method": {
|
||||
"enum": [
|
||||
"userPromptSubmit/stopped"
|
||||
],
|
||||
"title": "UserPromptSubmit/stoppedNotificationMethod",
|
||||
"type": "string"
|
||||
},
|
||||
"params": {
|
||||
"$ref": "#/definitions/UserPromptSubmitStoppedNotification"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"method",
|
||||
"params"
|
||||
],
|
||||
"title": "UserPromptSubmit/stoppedNotification",
|
||||
"type": "object"
|
||||
},
|
||||
{
|
||||
"properties": {
|
||||
"method": {
|
||||
@@ -15727,6 +15747,23 @@
|
||||
}
|
||||
]
|
||||
},
|
||||
"UserPromptSubmitStoppedNotification": {
|
||||
"$schema": "http://json-schema.org/draft-07/schema#",
|
||||
"properties": {
|
||||
"threadId": {
|
||||
"type": "string"
|
||||
},
|
||||
"turnId": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"threadId",
|
||||
"turnId"
|
||||
],
|
||||
"title": "UserPromptSubmitStoppedNotification",
|
||||
"type": "object"
|
||||
},
|
||||
"Verbosity": {
|
||||
"description": "Controls output length/detail on GPT-5 models via the Responses API. Serialized with lowercase values to match the OpenAI API.",
|
||||
"enum": [
|
||||
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"$schema": "http://json-schema.org/draft-07/schema#",
|
||||
"properties": {
|
||||
"threadId": {
|
||||
"type": "string"
|
||||
},
|
||||
"turnId": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"threadId",
|
||||
"turnId"
|
||||
],
|
||||
"title": "UserPromptSubmitStoppedNotification",
|
||||
"type": "object"
|
||||
}
|
||||
File diff suppressed because one or more lines are too long
+5
@@ -0,0 +1,5 @@
|
||||
// GENERATED CODE! DO NOT MODIFY BY HAND!
|
||||
|
||||
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
|
||||
|
||||
export type UserPromptSubmitStoppedNotification = { threadId: string, turnId: string, };
|
||||
@@ -426,6 +426,7 @@ export type { TurnStatus } from "./TurnStatus";
|
||||
export type { TurnSteerParams } from "./TurnSteerParams";
|
||||
export type { TurnSteerResponse } from "./TurnSteerResponse";
|
||||
export type { UserInput } from "./UserInput";
|
||||
export type { UserPromptSubmitStoppedNotification } from "./UserPromptSubmitStoppedNotification";
|
||||
export type { WarningNotification } from "./WarningNotification";
|
||||
export type { WebSearchAction } from "./WebSearchAction";
|
||||
export type { WindowsSandboxSetupCompletedNotification } from "./WindowsSandboxSetupCompletedNotification";
|
||||
|
||||
@@ -1383,6 +1383,7 @@ server_notification_definitions! {
|
||||
HookStarted => "hook/started" (v2::HookStartedNotification),
|
||||
TurnCompleted => "turn/completed" (v2::TurnCompletedNotification),
|
||||
HookCompleted => "hook/completed" (v2::HookCompletedNotification),
|
||||
UserPromptSubmitStopped => "userPromptSubmit/stopped" (v2::UserPromptSubmitStoppedNotification),
|
||||
TurnDiffUpdated => "turn/diff/updated" (v2::TurnDiffUpdatedNotification),
|
||||
TurnPlanUpdated => "turn/plan/updated" (v2::TurnPlanUpdatedNotification),
|
||||
ItemStarted => "item/started" (v2::ItemStartedNotification),
|
||||
|
||||
@@ -6775,6 +6775,14 @@ pub struct HookCompletedNotification {
|
||||
pub run: HookRunSummary,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, JsonSchema, TS)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
#[ts(export_to = "v2/")]
|
||||
pub struct UserPromptSubmitStoppedNotification {
|
||||
pub thread_id: String,
|
||||
pub turn_id: String,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, JsonSchema, TS)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
#[ts(export_to = "v2/")]
|
||||
|
||||
@@ -167,7 +167,7 @@ Example with notification opt-out:
|
||||
- `thread/shellCommand` — run a user-initiated `!` shell command against a thread; this runs unsandboxed with full access rather than inheriting the thread sandbox policy. Returns `{}` immediately while progress streams through standard turn/item notifications and any active turn receives the formatted output in its message stream.
|
||||
- `thread/backgroundTerminals/clean` — terminate all running background terminals for a thread (experimental; requires `capabilities.experimentalApi`); returns `{}` when the cleanup request is accepted.
|
||||
- `thread/rollback` — drop the last N turns from the agent’s in-memory context and persist a rollback marker in the rollout so future resumes see the pruned history; returns the updated `thread` (with `turns` populated) on success.
|
||||
- `turn/start` — add user input to a thread and begin Codex generation; responds with the initial `turn` object and streams `turn/started`, `item/*`, and `turn/completed` notifications. Prefer experimental `permissions` profile selection for permission overrides; the legacy `sandboxPolicy` field is still accepted but cannot be combined with `permissions`. For `collaborationMode`, `settings.developer_instructions: null` means "use built-in instructions for the selected mode".
|
||||
- `turn/start` — add user input to a thread and begin Codex generation; responds with the initial `turn` object and streams `turn/started`, `item/*`, and `turn/completed` notifications. If `UserPromptSubmit` hooks stop the turn before it starts, `userPromptSubmit/stopped` reports that aggregate outcome once after all matching handlers finish. Prefer experimental `permissions` profile selection for permission overrides; the legacy `sandboxPolicy` field is still accepted but cannot be combined with `permissions`. For `collaborationMode`, `settings.developer_instructions: null` means "use built-in instructions for the selected mode".
|
||||
- `thread/inject_items` — append raw Responses API items to a loaded thread’s model-visible history without starting a user turn; returns `{}` on success.
|
||||
- `turn/steer` — add user input to an already in-flight regular turn without starting a new turn; returns the active `turnId` that accepted the input. Review and manual compaction turns reject `turn/steer`.
|
||||
- `turn/interrupt` — request cancellation of an in-flight turn by `(thread_id, turn_id)`; success is an empty `{}` response and the turn finishes with `status: "interrupted"`.
|
||||
|
||||
@@ -81,6 +81,7 @@ use codex_app_server_protocol::TurnPlanStep;
|
||||
use codex_app_server_protocol::TurnPlanUpdatedNotification;
|
||||
use codex_app_server_protocol::TurnStartedNotification;
|
||||
use codex_app_server_protocol::TurnStatus;
|
||||
use codex_app_server_protocol::UserPromptSubmitStoppedNotification;
|
||||
use codex_app_server_protocol::WarningNotification;
|
||||
use codex_app_server_protocol::build_file_change_approval_request_item;
|
||||
use codex_app_server_protocol::build_file_change_end_item;
|
||||
@@ -1062,6 +1063,15 @@ pub(crate) async fn apply_bespoke_event_handling(
|
||||
.send_server_notification(ServerNotification::HookCompleted(notification))
|
||||
.await;
|
||||
}
|
||||
EventMsg::UserPromptSubmitStopped(event) => {
|
||||
let notification = UserPromptSubmitStoppedNotification {
|
||||
thread_id: conversation_id.to_string(),
|
||||
turn_id: event.turn_id,
|
||||
};
|
||||
outgoing
|
||||
.send_server_notification(ServerNotification::UserPromptSubmitStopped(notification))
|
||||
.await;
|
||||
}
|
||||
EventMsg::ExitedReviewMode(review_event) => {
|
||||
let review = match review_event.review_output {
|
||||
Some(output) => render_review_output_text(&output),
|
||||
|
||||
@@ -27,6 +27,7 @@ use codex_protocol::protocol::HookRunStatus;
|
||||
use codex_protocol::protocol::HookRunSummary;
|
||||
use codex_protocol::protocol::HookSource;
|
||||
use codex_protocol::protocol::HookStartedEvent;
|
||||
use codex_protocol::protocol::UserPromptSubmitStoppedEvent;
|
||||
use codex_protocol::user_input::UserInput;
|
||||
use serde_json::Value;
|
||||
|
||||
@@ -269,13 +270,23 @@ pub(crate) async fn run_user_prompt_submit_hooks(
|
||||
};
|
||||
let hooks = sess.hooks();
|
||||
let preview_runs = hooks.preview_user_prompt_submit(&request);
|
||||
run_context_injecting_hook(
|
||||
let outcome = run_context_injecting_hook(
|
||||
sess,
|
||||
turn_context,
|
||||
preview_runs,
|
||||
hooks.run_user_prompt_submit(request),
|
||||
)
|
||||
.await
|
||||
.await;
|
||||
if outcome.should_stop {
|
||||
sess.send_event(
|
||||
turn_context,
|
||||
EventMsg::UserPromptSubmitStopped(UserPromptSubmitStoppedEvent {
|
||||
turn_id: turn_context.sub_id.clone(),
|
||||
}),
|
||||
)
|
||||
.await;
|
||||
}
|
||||
outcome
|
||||
}
|
||||
|
||||
pub(crate) async fn inspect_pending_input(
|
||||
|
||||
@@ -1490,6 +1490,7 @@ pub(super) fn realtime_text_for_event(msg: &EventMsg) -> Option<String> {
|
||||
| EventMsg::ItemStarted(_)
|
||||
| EventMsg::HookStarted(_)
|
||||
| EventMsg::HookCompleted(_)
|
||||
| EventMsg::UserPromptSubmitStopped(_)
|
||||
| EventMsg::AgentMessageContentDelta(_)
|
||||
| EventMsg::PlanDelta(_)
|
||||
| EventMsg::ReasoningContentDelta(_)
|
||||
|
||||
@@ -365,6 +365,7 @@ async fn run_codex_tool_session_inner(
|
||||
| EventMsg::ItemCompleted(_)
|
||||
| EventMsg::HookStarted(_)
|
||||
| EventMsg::HookCompleted(_)
|
||||
| EventMsg::UserPromptSubmitStopped(_)
|
||||
| EventMsg::AgentMessageContentDelta(_)
|
||||
| EventMsg::ReasoningContentDelta(_)
|
||||
| EventMsg::ReasoningRawContentDelta(_)
|
||||
|
||||
@@ -1482,6 +1482,7 @@ pub enum EventMsg {
|
||||
ItemCompleted(ItemCompletedEvent),
|
||||
HookStarted(HookStartedEvent),
|
||||
HookCompleted(HookCompletedEvent),
|
||||
UserPromptSubmitStopped(UserPromptSubmitStoppedEvent),
|
||||
|
||||
AgentMessageContentDelta(AgentMessageContentDeltaEvent),
|
||||
PlanDelta(PlanDeltaEvent),
|
||||
@@ -1638,6 +1639,12 @@ pub struct HookCompletedEvent {
|
||||
pub run: HookRunSummary,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq, JsonSchema, TS)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub struct UserPromptSubmitStoppedEvent {
|
||||
pub turn_id: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, Default, Deserialize, Serialize, PartialEq, Eq, JsonSchema, TS)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum RealtimeConversationVersion {
|
||||
|
||||
@@ -275,6 +275,7 @@ pub(crate) fn tool_runtime_trace_event(event: &EventMsg) -> Option<ToolRuntimeTr
|
||||
| EventMsg::ItemCompleted(_)
|
||||
| EventMsg::HookStarted(_)
|
||||
| EventMsg::HookCompleted(_)
|
||||
| EventMsg::UserPromptSubmitStopped(_)
|
||||
| EventMsg::AgentMessageContentDelta(_)
|
||||
| EventMsg::PlanDelta(_)
|
||||
| EventMsg::ReasoningContentDelta(_)
|
||||
@@ -350,6 +351,7 @@ pub(crate) fn wrapped_protocol_event_type(event: &EventMsg) -> Option<&'static s
|
||||
| EventMsg::ItemCompleted(_)
|
||||
| EventMsg::HookStarted(_)
|
||||
| EventMsg::HookCompleted(_)
|
||||
| EventMsg::UserPromptSubmitStopped(_)
|
||||
| EventMsg::AgentMessageContentDelta(_)
|
||||
| EventMsg::PlanDelta(_)
|
||||
| EventMsg::ReasoningContentDelta(_)
|
||||
|
||||
@@ -166,6 +166,7 @@ fn event_msg_persistence_mode(ev: &EventMsg) -> Option<EventPersistenceMode> {
|
||||
| EventMsg::ItemStarted(_)
|
||||
| EventMsg::HookStarted(_)
|
||||
| EventMsg::HookCompleted(_)
|
||||
| EventMsg::UserPromptSubmitStopped(_)
|
||||
| EventMsg::AgentMessageContentDelta(_)
|
||||
| EventMsg::PlanDelta(_)
|
||||
| EventMsg::ReasoningContentDelta(_)
|
||||
|
||||
@@ -65,6 +65,9 @@ pub(super) fn server_notification_thread_target(
|
||||
ServerNotification::HookStarted(notification) => Some(notification.thread_id.as_str()),
|
||||
ServerNotification::TurnCompleted(notification) => Some(notification.thread_id.as_str()),
|
||||
ServerNotification::HookCompleted(notification) => Some(notification.thread_id.as_str()),
|
||||
ServerNotification::UserPromptSubmitStopped(notification) => {
|
||||
Some(notification.thread_id.as_str())
|
||||
}
|
||||
ServerNotification::TurnDiffUpdated(notification) => Some(notification.thread_id.as_str()),
|
||||
ServerNotification::TurnPlanUpdated(notification) => Some(notification.thread_id.as_str()),
|
||||
ServerNotification::ItemStarted(notification) => Some(notification.thread_id.as_str()),
|
||||
|
||||
@@ -50,6 +50,7 @@ impl ThreadEventStore {
|
||||
ThreadBufferedEvent::Request(_)
|
||||
| ThreadBufferedEvent::Notification(ServerNotification::HookStarted(_))
|
||||
| ThreadBufferedEvent::Notification(ServerNotification::HookCompleted(_))
|
||||
| ThreadBufferedEvent::Notification(ServerNotification::UserPromptSubmitStopped(_),)
|
||||
| ThreadBufferedEvent::FeedbackSubmission(_)
|
||||
)
|
||||
}
|
||||
|
||||
@@ -4042,6 +4042,14 @@ impl ChatWidget {
|
||||
self.request_redraw();
|
||||
}
|
||||
|
||||
fn on_user_prompt_submit_stopped(&mut self) {
|
||||
if self.user_turn_pending_start {
|
||||
self.user_turn_pending_start = false;
|
||||
self.maybe_send_next_queued_input();
|
||||
}
|
||||
self.request_redraw();
|
||||
}
|
||||
|
||||
fn flush_completed_hook_output(&mut self) {
|
||||
let Some(completed_cell) = self
|
||||
.active_hook_cell
|
||||
@@ -6255,6 +6263,9 @@ impl ChatWidget {
|
||||
ServerNotification::HookCompleted(notification) => {
|
||||
self.on_hook_completed(notification.run);
|
||||
}
|
||||
ServerNotification::UserPromptSubmitStopped(_) => {
|
||||
self.on_user_prompt_submit_stopped();
|
||||
}
|
||||
ServerNotification::Error(notification) => {
|
||||
if notification.will_retry {
|
||||
if !from_replay {
|
||||
|
||||
@@ -116,6 +116,7 @@ pub(super) use codex_app_server_protocol::TurnStartedNotification;
|
||||
pub(super) use codex_app_server_protocol::TurnStatus as AppServerTurnStatus;
|
||||
pub(super) use codex_app_server_protocol::UserInput;
|
||||
pub(super) use codex_app_server_protocol::UserInput as AppServerUserInput;
|
||||
pub(super) use codex_app_server_protocol::UserPromptSubmitStoppedNotification as AppServerUserPromptSubmitStoppedNotification;
|
||||
pub(super) use codex_app_server_protocol::WarningNotification;
|
||||
pub(super) use codex_config::AppRequirementToml;
|
||||
pub(super) use codex_config::AppsRequirementsToml;
|
||||
|
||||
@@ -170,6 +170,191 @@ async fn live_app_server_turn_completed_clears_working_status_after_answer_item(
|
||||
assert!(chat.bottom_pane.status_widget().is_none());
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn blocked_user_prompt_submit_hook_continues_queued_inputs() {
|
||||
let (mut chat, _rx, mut op_rx) = make_chatwidget_manual(/*model_override*/ None).await;
|
||||
chat.thread_id = Some(ThreadId::new());
|
||||
|
||||
chat.handle_server_notification(
|
||||
ServerNotification::TurnStarted(TurnStartedNotification {
|
||||
thread_id: "thread-1".to_string(),
|
||||
turn: AppServerTurn {
|
||||
id: "turn-1".to_string(),
|
||||
items: Vec::new(),
|
||||
status: AppServerTurnStatus::InProgress,
|
||||
error: None,
|
||||
started_at: Some(0),
|
||||
completed_at: None,
|
||||
duration_ms: None,
|
||||
},
|
||||
}),
|
||||
/*replay_kind*/ None,
|
||||
);
|
||||
|
||||
for text in ["blocked prompt", "allowed prompt"] {
|
||||
chat.bottom_pane
|
||||
.set_composer_text(text.to_string(), Vec::new(), Vec::new());
|
||||
chat.handle_key_event(KeyEvent::new(KeyCode::Tab, KeyModifiers::NONE));
|
||||
}
|
||||
|
||||
chat.handle_server_notification(
|
||||
ServerNotification::TurnCompleted(TurnCompletedNotification {
|
||||
thread_id: "thread-1".to_string(),
|
||||
turn: AppServerTurn {
|
||||
id: "turn-1".to_string(),
|
||||
items: Vec::new(),
|
||||
status: AppServerTurnStatus::Completed,
|
||||
error: None,
|
||||
started_at: Some(0),
|
||||
completed_at: Some(1),
|
||||
duration_ms: Some(1),
|
||||
},
|
||||
}),
|
||||
/*replay_kind*/ None,
|
||||
);
|
||||
|
||||
assert_matches!(
|
||||
next_submit_op(&mut op_rx),
|
||||
Op::UserTurn { items, .. }
|
||||
if items
|
||||
== vec![AppServerUserInput::Text {
|
||||
text: "blocked prompt".to_string(),
|
||||
text_elements: Vec::new(),
|
||||
}]
|
||||
);
|
||||
|
||||
handle_hook_completed_for_turn(
|
||||
&mut chat,
|
||||
Some("turn-2"),
|
||||
hook_run(
|
||||
"user-prompt-submit:0:/tmp/hooks.json",
|
||||
AppServerHookEventName::UserPromptSubmit,
|
||||
AppServerHookRunStatus::Blocked,
|
||||
"checking queued prompt policy",
|
||||
vec![AppServerHookOutputEntry {
|
||||
kind: AppServerHookOutputEntryKind::Feedback,
|
||||
text: "blocked prompt".to_string(),
|
||||
}],
|
||||
),
|
||||
);
|
||||
|
||||
assert_matches!(
|
||||
op_rx.try_recv(),
|
||||
Ok(Op::AddToHistory { text }) if text == "blocked prompt"
|
||||
);
|
||||
assert_matches!(op_rx.try_recv(), Err(TryRecvError::Empty));
|
||||
|
||||
handle_user_prompt_submit_stopped(&mut chat, "turn-2");
|
||||
|
||||
assert_matches!(
|
||||
next_submit_op(&mut op_rx),
|
||||
Op::UserTurn { items, .. }
|
||||
if items
|
||||
== vec![AppServerUserInput::Text {
|
||||
text: "allowed prompt".to_string(),
|
||||
text_elements: Vec::new(),
|
||||
}]
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn blocked_user_prompt_submit_stopped_only_resumes_queue_once_after_multiple_handlers() {
|
||||
let (mut chat, _rx, mut op_rx) = make_chatwidget_manual(/*model_override*/ None).await;
|
||||
chat.thread_id = Some(ThreadId::new());
|
||||
|
||||
chat.handle_server_notification(
|
||||
ServerNotification::TurnStarted(TurnStartedNotification {
|
||||
thread_id: "thread-1".to_string(),
|
||||
turn: AppServerTurn {
|
||||
id: "turn-1".to_string(),
|
||||
items: Vec::new(),
|
||||
status: AppServerTurnStatus::InProgress,
|
||||
error: None,
|
||||
started_at: Some(0),
|
||||
completed_at: None,
|
||||
duration_ms: None,
|
||||
},
|
||||
}),
|
||||
/*replay_kind*/ None,
|
||||
);
|
||||
|
||||
for text in ["blocked prompt", "allowed prompt", "later prompt"] {
|
||||
chat.bottom_pane
|
||||
.set_composer_text(text.to_string(), Vec::new(), Vec::new());
|
||||
chat.handle_key_event(KeyEvent::new(KeyCode::Tab, KeyModifiers::NONE));
|
||||
}
|
||||
|
||||
chat.handle_server_notification(
|
||||
ServerNotification::TurnCompleted(TurnCompletedNotification {
|
||||
thread_id: "thread-1".to_string(),
|
||||
turn: AppServerTurn {
|
||||
id: "turn-1".to_string(),
|
||||
items: Vec::new(),
|
||||
status: AppServerTurnStatus::Completed,
|
||||
error: None,
|
||||
started_at: Some(0),
|
||||
completed_at: Some(1),
|
||||
duration_ms: Some(1),
|
||||
},
|
||||
}),
|
||||
/*replay_kind*/ None,
|
||||
);
|
||||
|
||||
assert_matches!(
|
||||
next_submit_op(&mut op_rx),
|
||||
Op::UserTurn { items, .. }
|
||||
if items
|
||||
== vec![AppServerUserInput::Text {
|
||||
text: "blocked prompt".to_string(),
|
||||
text_elements: Vec::new(),
|
||||
}]
|
||||
);
|
||||
|
||||
for run_id in [
|
||||
"user-prompt-submit:0:/tmp/hooks.json",
|
||||
"user-prompt-submit:1:/tmp/hooks.json",
|
||||
] {
|
||||
handle_hook_completed_for_turn(
|
||||
&mut chat,
|
||||
Some("turn-2"),
|
||||
hook_run(
|
||||
run_id,
|
||||
AppServerHookEventName::UserPromptSubmit,
|
||||
AppServerHookRunStatus::Blocked,
|
||||
"checking queued prompt policy",
|
||||
vec![AppServerHookOutputEntry {
|
||||
kind: AppServerHookOutputEntryKind::Feedback,
|
||||
text: "blocked prompt".to_string(),
|
||||
}],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
assert_matches!(
|
||||
op_rx.try_recv(),
|
||||
Ok(Op::AddToHistory { text }) if text == "blocked prompt"
|
||||
);
|
||||
assert_matches!(op_rx.try_recv(), Err(TryRecvError::Empty));
|
||||
|
||||
handle_user_prompt_submit_stopped(&mut chat, "turn-2");
|
||||
|
||||
assert_matches!(
|
||||
next_submit_op(&mut op_rx),
|
||||
Op::UserTurn { items, .. }
|
||||
if items
|
||||
== vec![AppServerUserInput::Text {
|
||||
text: "allowed prompt".to_string(),
|
||||
text_elements: Vec::new(),
|
||||
}]
|
||||
);
|
||||
assert_matches!(
|
||||
op_rx.try_recv(),
|
||||
Ok(Op::AddToHistory { text }) if text == "allowed prompt"
|
||||
);
|
||||
assert_matches!(op_rx.try_recv(), Err(TryRecvError::Empty));
|
||||
assert_eq!(chat.queued_user_message_texts(), vec!["later prompt"]);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn live_app_server_turn_started_sets_feedback_turn_id() {
|
||||
let (mut chat, mut rx, _op_rx) = make_chatwidget_manual(/*model_override*/ None).await;
|
||||
|
||||
@@ -1539,16 +1539,34 @@ pub(super) fn handle_hook_started(chat: &mut ChatWidget, run: AppServerHookRunSu
|
||||
}
|
||||
|
||||
pub(super) fn handle_hook_completed(chat: &mut ChatWidget, run: AppServerHookRunSummary) {
|
||||
handle_hook_completed_for_turn(chat, /*turn_id*/ None, run);
|
||||
}
|
||||
|
||||
pub(super) fn handle_hook_completed_for_turn(
|
||||
chat: &mut ChatWidget,
|
||||
turn_id: Option<&str>,
|
||||
run: AppServerHookRunSummary,
|
||||
) {
|
||||
chat.handle_server_notification(
|
||||
ServerNotification::HookCompleted(AppServerHookCompletedNotification {
|
||||
thread_id: thread_id(chat),
|
||||
turn_id: None,
|
||||
turn_id: turn_id.map(str::to_string),
|
||||
run,
|
||||
}),
|
||||
/*replay_kind*/ None,
|
||||
);
|
||||
}
|
||||
|
||||
pub(super) fn handle_user_prompt_submit_stopped(chat: &mut ChatWidget, turn_id: &str) {
|
||||
chat.handle_server_notification(
|
||||
ServerNotification::UserPromptSubmitStopped(AppServerUserPromptSubmitStoppedNotification {
|
||||
thread_id: thread_id(chat),
|
||||
turn_id: turn_id.to_string(),
|
||||
}),
|
||||
/*replay_kind*/ None,
|
||||
);
|
||||
}
|
||||
|
||||
pub(super) fn hook_run(
|
||||
run_id: &str,
|
||||
event_name: codex_app_server_protocol::HookEventName,
|
||||
|
||||
Reference in New Issue
Block a user