mirror of
https://github.com/openai/codex.git
synced 2026-11-12 21:20:34 +00:00
Add usage-limit banner analytics plumbing
This commit is contained in:
@@ -55,7 +55,6 @@ use crate::facts::TurnTokenUsageFact;
|
||||
use crate::reducer::AnalyticsReducer;
|
||||
use crate::reducer::normalize_path_for_skill_id;
|
||||
use crate::reducer::skill_id_for_local_skill;
|
||||
use codex_app_server_protocol::AddCreditsNudgeCreditType;
|
||||
use codex_app_server_protocol::ApprovalsReviewer as AppServerApprovalsReviewer;
|
||||
use codex_app_server_protocol::AskForApproval as AppServerAskForApproval;
|
||||
use codex_app_server_protocol::ClientInfo;
|
||||
@@ -77,6 +76,7 @@ use codex_app_server_protocol::ThreadStartResponse;
|
||||
use codex_app_server_protocol::ThreadStatus as AppServerThreadStatus;
|
||||
use codex_app_server_protocol::TrackUsageLimitBannerAction;
|
||||
use codex_app_server_protocol::TrackUsageLimitBannerParams;
|
||||
use codex_app_server_protocol::UsageLimitBannerType;
|
||||
use codex_app_server_protocol::Turn;
|
||||
use codex_app_server_protocol::TurnCompletedNotification;
|
||||
use codex_app_server_protocol::TurnError as AppServerTurnError;
|
||||
@@ -2421,7 +2421,7 @@ async fn usage_limit_banner_shown_request_emits_credits_event() {
|
||||
request_id: RequestId::Integer(1),
|
||||
params: TrackUsageLimitBannerParams {
|
||||
action: TrackUsageLimitBannerAction::Shown,
|
||||
credit_type: AddCreditsNudgeCreditType::Credits,
|
||||
banner_type: UsageLimitBannerType::WorkspaceMemberCreditsDepleted,
|
||||
},
|
||||
}),
|
||||
},
|
||||
@@ -2457,7 +2457,7 @@ async fn usage_limit_banner_click_request_emits_usage_limit_event() {
|
||||
request_id: RequestId::Integer(1),
|
||||
params: TrackUsageLimitBannerParams {
|
||||
action: TrackUsageLimitBannerAction::CtaClicked,
|
||||
credit_type: AddCreditsNudgeCreditType::UsageLimit,
|
||||
banner_type: UsageLimitBannerType::WorkspaceMemberUsageLimitReached,
|
||||
},
|
||||
}),
|
||||
},
|
||||
|
||||
@@ -19,10 +19,10 @@ use crate::facts::TurnSteerRejectionReason;
|
||||
use crate::facts::TurnSteerResult;
|
||||
use crate::facts::TurnSubmissionType;
|
||||
use crate::now_unix_seconds;
|
||||
use codex_app_server_protocol::AddCreditsNudgeCreditType;
|
||||
use codex_app_server_protocol::CodexErrorInfo;
|
||||
use codex_app_server_protocol::TrackUsageLimitBannerAction;
|
||||
use codex_app_server_protocol::TrackUsageLimitBannerParams;
|
||||
use codex_app_server_protocol::UsageLimitBannerType;
|
||||
use codex_login::default_client::originator;
|
||||
use codex_plugin::PluginTelemetryMetadata;
|
||||
use codex_protocol::approvals::NetworkApprovalProtocol;
|
||||
@@ -593,17 +593,19 @@ pub(crate) fn plugin_state_event_type(state: PluginState) -> &'static str {
|
||||
pub(crate) fn usage_limit_banner_event_request(
|
||||
params: TrackUsageLimitBannerParams,
|
||||
) -> UsageLimitBannerEventRequest {
|
||||
let limit_reason = match params.credit_type {
|
||||
AddCreditsNudgeCreditType::Credits => "credits",
|
||||
AddCreditsNudgeCreditType::UsageLimit => "usage_limit",
|
||||
let limit_reason = match params.banner_type {
|
||||
UsageLimitBannerType::WorkspaceMemberCreditsDepleted => "credits",
|
||||
UsageLimitBannerType::WorkspaceMemberUsageLimitReached => "usage_limit",
|
||||
};
|
||||
let banner_type = match params.credit_type {
|
||||
AddCreditsNudgeCreditType::Credits => "workspace_member_credits_depleted",
|
||||
AddCreditsNudgeCreditType::UsageLimit => "workspace_member_usage_limit_reached",
|
||||
let banner_type = match params.banner_type {
|
||||
UsageLimitBannerType::WorkspaceMemberCreditsDepleted => "workspace_member_credits_depleted",
|
||||
UsageLimitBannerType::WorkspaceMemberUsageLimitReached => {
|
||||
"workspace_member_usage_limit_reached"
|
||||
}
|
||||
};
|
||||
let cta_action = match params.credit_type {
|
||||
AddCreditsNudgeCreditType::Credits => "notify_owner",
|
||||
AddCreditsNudgeCreditType::UsageLimit => "request_increase",
|
||||
let cta_action = match params.banner_type {
|
||||
UsageLimitBannerType::WorkspaceMemberCreditsDepleted => "notify_owner",
|
||||
UsageLimitBannerType::WorkspaceMemberUsageLimitReached => "request_increase",
|
||||
};
|
||||
let cta_action = match params.action {
|
||||
TrackUsageLimitBannerAction::Shown => None,
|
||||
|
||||
+11
-4
@@ -4094,13 +4094,13 @@
|
||||
"action": {
|
||||
"$ref": "#/definitions/TrackUsageLimitBannerAction"
|
||||
},
|
||||
"creditType": {
|
||||
"$ref": "#/definitions/AddCreditsNudgeCreditType"
|
||||
"bannerType": {
|
||||
"$ref": "#/definitions/UsageLimitBannerType"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"action",
|
||||
"creditType"
|
||||
"bannerType"
|
||||
],
|
||||
"type": "object"
|
||||
},
|
||||
@@ -4287,6 +4287,13 @@
|
||||
],
|
||||
"type": "object"
|
||||
},
|
||||
"UsageLimitBannerType": {
|
||||
"enum": [
|
||||
"workspace_member_credits_depleted",
|
||||
"workspace_member_usage_limit_reached"
|
||||
],
|
||||
"type": "string"
|
||||
},
|
||||
"UserInput": {
|
||||
"oneOf": [
|
||||
{
|
||||
@@ -6170,4 +6177,4 @@
|
||||
}
|
||||
],
|
||||
"title": "ClientRequest"
|
||||
}
|
||||
}
|
||||
+11
-4
@@ -16930,13 +16930,13 @@
|
||||
"action": {
|
||||
"$ref": "#/definitions/v2/TrackUsageLimitBannerAction"
|
||||
},
|
||||
"creditType": {
|
||||
"$ref": "#/definitions/v2/AddCreditsNudgeCreditType"
|
||||
"bannerType": {
|
||||
"$ref": "#/definitions/v2/UsageLimitBannerType"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"action",
|
||||
"creditType"
|
||||
"bannerType"
|
||||
],
|
||||
"title": "TrackUsageLimitBannerParams",
|
||||
"type": "object"
|
||||
@@ -17370,6 +17370,13 @@
|
||||
"title": "TurnSteerResponse",
|
||||
"type": "object"
|
||||
},
|
||||
"UsageLimitBannerType": {
|
||||
"enum": [
|
||||
"workspace_member_credits_depleted",
|
||||
"workspace_member_usage_limit_reached"
|
||||
],
|
||||
"type": "string"
|
||||
},
|
||||
"UserInput": {
|
||||
"oneOf": [
|
||||
{
|
||||
@@ -17805,4 +17812,4 @@
|
||||
},
|
||||
"title": "CodexAppServerProtocol",
|
||||
"type": "object"
|
||||
}
|
||||
}
|
||||
+11
-4
@@ -14816,13 +14816,13 @@
|
||||
"action": {
|
||||
"$ref": "#/definitions/TrackUsageLimitBannerAction"
|
||||
},
|
||||
"creditType": {
|
||||
"$ref": "#/definitions/AddCreditsNudgeCreditType"
|
||||
"bannerType": {
|
||||
"$ref": "#/definitions/UsageLimitBannerType"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"action",
|
||||
"creditType"
|
||||
"bannerType"
|
||||
],
|
||||
"title": "TrackUsageLimitBannerParams",
|
||||
"type": "object"
|
||||
@@ -15256,6 +15256,13 @@
|
||||
"title": "TurnSteerResponse",
|
||||
"type": "object"
|
||||
},
|
||||
"UsageLimitBannerType": {
|
||||
"enum": [
|
||||
"workspace_member_credits_depleted",
|
||||
"workspace_member_usage_limit_reached"
|
||||
],
|
||||
"type": "string"
|
||||
},
|
||||
"UserInput": {
|
||||
"oneOf": [
|
||||
{
|
||||
@@ -15690,4 +15697,4 @@
|
||||
},
|
||||
"title": "CodexAppServerProtocolV2",
|
||||
"type": "object"
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -922,4 +922,4 @@
|
||||
],
|
||||
"title": "RawResponseItemCompletedNotification",
|
||||
"type": "object"
|
||||
}
|
||||
}
|
||||
@@ -1452,4 +1452,4 @@
|
||||
],
|
||||
"title": "ThreadResumeParams",
|
||||
"type": "object"
|
||||
}
|
||||
}
|
||||
+10
-10
@@ -1,32 +1,32 @@
|
||||
{
|
||||
"$schema": "http://json-schema.org/draft-07/schema#",
|
||||
"definitions": {
|
||||
"AddCreditsNudgeCreditType": {
|
||||
"enum": [
|
||||
"credits",
|
||||
"usage_limit"
|
||||
],
|
||||
"type": "string"
|
||||
},
|
||||
"TrackUsageLimitBannerAction": {
|
||||
"enum": [
|
||||
"shown",
|
||||
"cta_clicked"
|
||||
],
|
||||
"type": "string"
|
||||
},
|
||||
"UsageLimitBannerType": {
|
||||
"enum": [
|
||||
"workspace_member_credits_depleted",
|
||||
"workspace_member_usage_limit_reached"
|
||||
],
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"properties": {
|
||||
"action": {
|
||||
"$ref": "#/definitions/TrackUsageLimitBannerAction"
|
||||
},
|
||||
"creditType": {
|
||||
"$ref": "#/definitions/AddCreditsNudgeCreditType"
|
||||
"bannerType": {
|
||||
"$ref": "#/definitions/UsageLimitBannerType"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"action",
|
||||
"creditType"
|
||||
"bannerType"
|
||||
],
|
||||
"title": "TrackUsageLimitBannerParams",
|
||||
"type": "object"
|
||||
|
||||
+2
-2
@@ -1,7 +1,7 @@
|
||||
// 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.
|
||||
import type { AddCreditsNudgeCreditType } from "./AddCreditsNudgeCreditType";
|
||||
import type { TrackUsageLimitBannerAction } from "./TrackUsageLimitBannerAction";
|
||||
import type { UsageLimitBannerType } from "./UsageLimitBannerType";
|
||||
|
||||
export type TrackUsageLimitBannerParams = { action: TrackUsageLimitBannerAction, creditType: AddCreditsNudgeCreditType, };
|
||||
export type TrackUsageLimitBannerParams = { action: TrackUsageLimitBannerAction, bannerType: UsageLimitBannerType, };
|
||||
|
||||
@@ -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 UsageLimitBannerType = "workspace_member_credits_depleted" | "workspace_member_usage_limit_reached";
|
||||
@@ -405,6 +405,7 @@ export type { TurnStartedNotification } from "./TurnStartedNotification";
|
||||
export type { TurnStatus } from "./TurnStatus";
|
||||
export type { TurnSteerParams } from "./TurnSteerParams";
|
||||
export type { TurnSteerResponse } from "./TurnSteerResponse";
|
||||
export type { UsageLimitBannerType } from "./UsageLimitBannerType";
|
||||
export type { UserInput } from "./UserInput";
|
||||
export type { WarningNotification } from "./WarningNotification";
|
||||
export type { WebSearchAction } from "./WebSearchAction";
|
||||
|
||||
@@ -1473,7 +1473,7 @@ mod tests {
|
||||
request_id: RequestId::Integer(2),
|
||||
params: v2::TrackUsageLimitBannerParams {
|
||||
action: v2::TrackUsageLimitBannerAction::CtaClicked,
|
||||
credit_type: v2::AddCreditsNudgeCreditType::UsageLimit,
|
||||
banner_type: v2::UsageLimitBannerType::WorkspaceMemberUsageLimitReached,
|
||||
},
|
||||
};
|
||||
assert_eq!(request.id(), &RequestId::Integer(2));
|
||||
@@ -1484,7 +1484,7 @@ mod tests {
|
||||
"id": 2,
|
||||
"params": {
|
||||
"action": "cta_clicked",
|
||||
"creditType": "usage_limit",
|
||||
"bannerType": "workspace_member_usage_limit_reached",
|
||||
},
|
||||
}),
|
||||
serde_json::to_value(&request)?,
|
||||
|
||||
@@ -2255,7 +2255,7 @@ pub struct SendAddCreditsNudgeEmailParams {
|
||||
#[ts(export_to = "v2/")]
|
||||
pub struct TrackUsageLimitBannerParams {
|
||||
pub action: TrackUsageLimitBannerAction,
|
||||
pub credit_type: AddCreditsNudgeCreditType,
|
||||
pub banner_type: UsageLimitBannerType,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq, Eq, JsonSchema, TS)]
|
||||
@@ -2266,6 +2266,14 @@ pub enum TrackUsageLimitBannerAction {
|
||||
CtaClicked,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq, Eq, JsonSchema, TS)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
#[ts(export_to = "v2/", rename_all = "snake_case")]
|
||||
pub enum UsageLimitBannerType {
|
||||
WorkspaceMemberCreditsDepleted,
|
||||
WorkspaceMemberUsageLimitReached,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq, Eq, JsonSchema, TS)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
#[ts(export_to = "v2/", rename_all = "snake_case")]
|
||||
|
||||
@@ -1672,14 +1672,14 @@ Field notes:
|
||||
|
||||
Use `creditType: "credits"` when workspace credits are depleted, or `creditType: "usage_limit"` when the workspace usage limit has been reached. If the owner was already notified recently, the response status is `cooldown_active`.
|
||||
|
||||
### 9) Track the workspace-owner nudge prompt
|
||||
### 9) Track a usage-limit banner
|
||||
|
||||
```json
|
||||
{ "method": "account/usageLimitBanner/track", "id": 9, "params": { "action": "shown", "creditType": "usage_limit" } }
|
||||
{ "method": "account/usageLimitBanner/track", "id": 9, "params": { "action": "shown", "bannerType": "workspace_member_usage_limit_reached" } }
|
||||
{ "id": 9, "result": {} }
|
||||
```
|
||||
|
||||
Use `action: "shown"` when the prompt is displayed, and `action: "cta_clicked"` when the user confirms the prompt.
|
||||
Use `action: "shown"` when the banner is displayed, and `action: "cta_clicked"` when the user confirms it. The current workspace-owner nudge variants are `workspace_member_credits_depleted` and `workspace_member_usage_limit_reached`.
|
||||
|
||||
## Experimental API Opt-in
|
||||
|
||||
|
||||
Reference in New Issue
Block a user