Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/src/ai/agent/api/convert_conversation_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ fn test_server_metadata(
was_summarized: false,
context_window_usage: 0.0,
credits_spent: 0.0,
platform_credits_spent: 0.0,
credits_spent_for_last_block: None,
token_usage: vec![],
tool_usage_metadata: Default::default(),
Expand Down
17 changes: 16 additions & 1 deletion app/src/ai/agent/conversation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -652,8 +652,20 @@ impl AIConversation {
self.conversation_usage_metadata.context_window_usage
}

/// Total credits spent in the conversation, including both LLM inference
/// and platform credits.
pub fn credits_spent(&self) -> f32 {
(self.conversation_usage_metadata.credits_spent * 10.0).round() / 10.0
let total = self.conversation_usage_metadata.credits_spent
+ self.conversation_usage_metadata.platform_credits_spent;
(total * 10.0).round() / 10.0
}

pub fn inference_credits_spent(&self) -> f32 {
self.conversation_usage_metadata.credits_spent
}

pub fn platform_credits_spent(&self) -> f32 {
self.conversation_usage_metadata.platform_credits_spent
}
Comment on lines 657 to 669

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we're rounding credits_spent, should we be doing it for these two adjacent functions too?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kind of unsure. credits_spent is something that gets called by UI code, so it makes sense to round. The other two are for things like communicating about credit usage over session sharing. I'm worried about rounding those + having lossy behavior. I'm gonna leave it like this for now but could be convinced to do something to make it clearer later.


/// Test-only helper that sets the conversation's credit total directly.
Expand All @@ -663,6 +675,7 @@ impl AIConversation {
#[cfg(test)]
pub(crate) fn set_credits_spent_for_test(&mut self, credits: f32) {
self.conversation_usage_metadata.credits_spent = credits;
self.conversation_usage_metadata.platform_credits_spent = 0.0;
}

/// Test-only helper that simulates the root-task upgrade performed by the
Expand Down Expand Up @@ -1881,6 +1894,8 @@ impl AIConversation {
self.conversation_usage_metadata.context_window_usage =
usage_metadata.context_window_usage;
self.conversation_usage_metadata.credits_spent = usage_metadata.credits_spent;
self.conversation_usage_metadata.platform_credits_spent =
usage_metadata.platform_credits_spent;
let llm_preferences = LLMPreferences::as_ref(ctx);
self.conversation_usage_metadata.token_usage =
footer_model_token_usage(&usage_metadata, llm_preferences);
Expand Down
1 change: 1 addition & 0 deletions app/src/ai/agent_conversations_model_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -709,6 +709,7 @@ fn create_server_conversation_metadata(
was_summarized: false,
context_window_usage: 0.0,
credits_spent: 0.0,
platform_credits_spent: 0.0,
credits_spent_for_last_block: None,
token_usage: vec![],
tool_usage_metadata: Default::default(),
Expand Down
1 change: 1 addition & 0 deletions app/src/ai/agent_sdk/artifact_upload_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ fn create_conversation_metadata(
was_summarized: false,
context_window_usage: 0.0,
credits_spent: 0.0,
platform_credits_spent: 0.0,
credits_spent_for_last_block: None,
token_usage: vec![],
tool_usage_metadata: Default::default(),
Expand Down
4 changes: 2 additions & 2 deletions app/src/ai/blocklist/controller/shared_session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -502,8 +502,8 @@ impl BlocklistAIController {
.conversation(&conv_id)
.map(|conversation| stream_finished::ConversationUsageMetadata {
context_window_usage: conversation.context_window_usage(),
credits_spent: conversation.credits_spent(),
platform_credits_spent: 0.0,
credits_spent: conversation.inference_credits_spent(),
platform_credits_spent: conversation.platform_credits_spent(),
summarized: conversation.was_summarized(),
#[allow(deprecated)]
token_usage: conversation
Expand Down
5 changes: 4 additions & 1 deletion app/src/ai/blocklist/history_model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,10 @@ impl AIConversationMetadata {
.metadata_last_updated_ts
.utc()
.naive_utc();
let credits_spent = Some(server_conversation_metadata.usage.credits_spent);
let credits_spent = Some(
server_conversation_metadata.usage.credits_spent
+ server_conversation_metadata.usage.platform_credits_spent,
);
let server_conversation_token = Some(
server_conversation_metadata
.server_conversation_token
Expand Down
2 changes: 1 addition & 1 deletion app/src/ai/blocklist/history_model/conversation_loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,7 @@ impl BlocklistAIHistoryModel {
let credits_spent = conversation_data
.as_ref()
.and_then(|data| data.conversation_usage_metadata.as_ref())
.map(|m| m.credits_spent);
.map(|m| m.credits_spent + m.platform_credits_spent);
let artifacts = conversation_data
.as_ref()
.and_then(|data| data.artifacts_json.as_ref())
Expand Down
1 change: 1 addition & 0 deletions app/src/ai/blocklist/history_model_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,7 @@ fn create_server_metadata(
was_summarized: false,
context_window_usage: 0.0,
credits_spent,
platform_credits_spent: 0.0,
credits_spent_for_last_block: None,
token_usage: vec![],
tool_usage_metadata: Default::default(),
Expand Down
1 change: 1 addition & 0 deletions app/src/ai/blocklist/orchestration_event_streamer_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ fn make_server_metadata_with_harness(
was_summarized: false,
context_window_usage: 0.0,
credits_spent: 0.0,
platform_credits_spent: 0.0,
credits_spent_for_last_block: None,
token_usage: vec![],
tool_usage_metadata: Default::default(),
Expand Down
3 changes: 2 additions & 1 deletion app/src/ai/blocklist/usage/conversation_usage_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ pub enum DisplayMode {

pub struct ConversationUsageInfo {
pub credits_spent: f32,
pub platform_credits_spent: f32,
// Credits spent over the last block, where the block comprises
// all agent outputs since the most recent user input.
pub credits_spent_for_last_block: Option<f32>,
Expand Down Expand Up @@ -299,7 +300,7 @@ impl ConversationUsageView {
let total_credits_value = rollup
.as_ref()
.map(|r| r.total_credits)
.unwrap_or(self.usage_info.credits_spent);
.unwrap_or(self.usage_info.credits_spent + self.usage_info.platform_credits_spent);

if self.display_mode == DisplayMode::Footer
&& self.usage_info.credits_spent_for_last_block.is_some()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ use crate::persistence::model::{ModelTokenUsage, PRIMARY_AGENT_CATEGORY};
fn placeholder_usage_info() -> ConversationUsageInfo {
ConversationUsageInfo {
credits_spent: 0.0,
platform_credits_spent: 0.0,
credits_spent_for_last_block: None,
tool_calls: 0,
models: Vec::new(),
Expand Down
1 change: 1 addition & 0 deletions app/src/pane_group/mod_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,7 @@ fn test_server_conversation_metadata(
was_summarized: false,
context_window_usage: 0.0,
credits_spent: 0.0,
platform_credits_spent: 0.0,
credits_spent_for_last_block: None,
token_usage: vec![],
tool_usage_metadata: Default::default(),
Expand Down
4 changes: 4 additions & 0 deletions app/src/server/server_api/ai.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2904,11 +2904,13 @@ fn convert_usage_metadata(
summarized: bool,
context_window_usage: f64,
credits_spent: f64,
platform_credits_spent: f64,
) -> ConversationUsageMetadata {
ConversationUsageMetadata {
was_summarized: summarized,
context_window_usage: context_window_usage as f32,
credits_spent: credits_spent as f32,
platform_credits_spent: platform_credits_spent as f32,
credits_spent_for_last_block: None,
token_usage: vec![],
tool_usage_metadata: Default::default(),
Expand All @@ -2923,6 +2925,7 @@ impl TryFrom<warp_graphql::ai::AIConversation> for ServerAIConversationMetadata
value.usage.usage_metadata.summarized,
value.usage.usage_metadata.context_window_usage,
value.usage.usage_metadata.credits_spent,
value.usage.usage_metadata.platform_credits_spent,
);
let metadata = value.metadata.try_into()?;
let permissions = value.permissions.try_into()?;
Expand Down Expand Up @@ -2967,6 +2970,7 @@ impl TryFrom<warp_graphql::queries::list_ai_conversations::AIConversationMetadat
value.usage.usage_metadata.summarized,
value.usage.usage_metadata.context_window_usage,
value.usage.usage_metadata.credits_spent,
value.usage.usage_metadata.platform_credits_spent,
);
let metadata = value.metadata.try_into()?;
let permissions = value.permissions.try_into()?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,10 @@ impl UsageHistoryEntry {
))
.finish();

let total_credits =
entry.usage_metadata.credits_spent + entry.usage_metadata.platform_credits_spent;
let credits_spent = Text::new_inline(
format_credits(entry.usage_metadata.credits_spent as f32),
format_credits(total_credits as f32),
appearance.ui_font_family(),
14.,
)
Expand Down
4 changes: 2 additions & 2 deletions app/src/terminal/shared_session/replay_agent_conversations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,8 @@ fn create_finished_event_from_conversation(conversation: &AIConversation) -> Res
let usage_metadata = Some(
api_response_event::stream_finished::ConversationUsageMetadata {
context_window_usage: conversation.context_window_usage(),
credits_spent: conversation.credits_spent(),
platform_credits_spent: 0.0,
credits_spent: conversation.inference_credits_spent(),
platform_credits_spent: conversation.platform_credits_spent(),
summarized: conversation.was_summarized(),
#[allow(deprecated)]
token_usage: conversation
Expand Down
3 changes: 2 additions & 1 deletion app/src/terminal/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6459,7 +6459,8 @@ impl TerminalView {
conversation.wall_to_wall_response_time_since_last_query();

let conversation_usage_info = ConversationUsageInfo {
credits_spent: conversation.credits_spent(),
credits_spent: conversation.inference_credits_spent(),
platform_credits_spent: conversation.platform_credits_spent(),
credits_spent_for_last_block: conversation.credits_spent_for_last_block(),
tool_calls: tool_usage.total_tool_calls(),
models: conversation.token_usage().to_vec(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ fn server_conversation_metadata(
was_summarized: false,
context_window_usage: 0.0,
credits_spent: 0.0,
platform_credits_spent: 0.0,
credits_spent_for_last_block: None,
token_usage: vec![],
tool_usage_metadata: Default::default(),
Expand Down
1 change: 1 addition & 0 deletions app/src/terminal/view/shared_session/view_impl_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -580,6 +580,7 @@ fn server_conversation_metadata(
was_summarized: false,
context_window_usage: 0.0,
credits_spent: 0.0,
platform_credits_spent: 0.0,
credits_spent_for_last_block: None,
token_usage: vec![],
tool_usage_metadata: Default::default(),
Expand Down
2 changes: 2 additions & 0 deletions app/src/workspaces/gql_convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,13 +240,15 @@ impl From<&gql_usage::ConversationUsage> for ConversationUsageInfo {
fn from(gql: &gql_usage::ConversationUsage) -> Self {
let persistence::model::ConversationUsageMetadata {
credits_spent,
platform_credits_spent,
token_usage: models,
tool_usage_metadata: tool,
context_window_usage,
..
} = (&gql.usage_metadata).into();
ConversationUsageInfo {
credits_spent,
platform_credits_spent,
credits_spent_for_last_block: None,
tool_calls: tool.total_tool_calls(),
models,
Expand Down
1 change: 1 addition & 0 deletions crates/graphql/src/api/ai.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,5 +166,6 @@ pub struct ConversationUsage {
pub struct ConversationUsageMetadata {
pub context_window_usage: f64,
pub credits_spent: f64,
pub platform_credits_spent: f64,
pub summarized: bool,
}
3 changes: 3 additions & 0 deletions crates/graphql/src/api/queries/get_conversation_usage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ query GetConversationUsage(
usageMetadata {
contextWindowUsage
creditsSpent
platformCreditsSpent
summarized
tokenUsage { modelId totalTokens }
warpTokenUsage { modelId totalTokens tokenUsageByCategory { category tokens } }
Expand Down Expand Up @@ -114,6 +115,7 @@ pub struct ConversationUsage {
pub struct ConversationUsageMetadata {
pub context_window_usage: f64,
pub credits_spent: f64,
pub platform_credits_spent: f64,
pub summarized: bool,
pub token_usage: Vec<ModelTokenUsage>,
pub warp_token_usage: Vec<TokenUsage>,
Expand Down Expand Up @@ -170,6 +172,7 @@ impl From<&ConversationUsageMetadata> for persistence::model::ConversationUsageM
was_summarized: gql.summarized,
context_window_usage: gql.context_window_usage as f32,
credits_spent: gql.credits_spent as f32,
platform_credits_spent: gql.platform_credits_spent as f32,
credits_spent_for_last_block: None,
token_usage: convert_token_usage(&gql.warp_token_usage, &gql.byok_token_usage),
tool_usage_metadata: (&gql.tool_usage_metadata).into(),
Expand Down
2 changes: 2 additions & 0 deletions crates/persistence/src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1358,6 +1358,8 @@ pub struct ConversationUsageMetadata {
pub context_window_usage: f32,
pub credits_spent: f32,
#[serde(default)]
pub platform_credits_spent: f32,
#[serde(default)]
pub credits_spent_for_last_block: Option<f32>,
#[serde(default)]
pub token_usage: Vec<ModelTokenUsage>,
Expand Down
8 changes: 7 additions & 1 deletion crates/warp_graphql_schema/api/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -790,7 +790,12 @@ type ConversationUsageMetadata {
"""Token usage using a user's API key, keyed by model."""
byokTokenUsage: [TokenUsage!]!
contextWindowUsage: Float!

"""The total number of inference credits spent so far in the conversation"""
creditsSpent: Float!

"""The total number of platform credits spent so far in the conversation."""
platformCreditsSpent: Float!
Comment on lines +793 to +798

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I asked AM and maybe we might be missing adding platformCreditsSpent to a few more places?

impl From<&gql_usage::ConversationUsage> for ConversationUsageInfo {

impl From<&gql_usage::ConversationUsage> for ConversationUsageInfo {
    fn from(gql: &gql_usage::ConversationUsage) -> Self {
        let persistence::model::ConversationUsageMetadata {
            credits_spent,
            token_usage: models,
            tool_usage_metadata: tool,
            context_window_usage,
            ..
        } = (&gql.usage_metadata).into();
        ConversationUsageInfo {
            credits_spent,
            credits_spent_for_last_block: None,
            tool_calls: tool.total_tool_calls(),
            models,
            context_window_usage,
            files_changed: tool.apply_file_diff_stats.files_changed,
            lines_added: tool.apply_file_diff_stats.lines_added,
            lines_removed: tool.apply_file_diff_stats.lines_removed,
            commands_executed: tool.run_command_stats.commands_executed,
        }
    }
}

format_credits(entry.usage_metadata.credits_spent as f32),

  let credits_spent = Text::new_inline(
      format_credits(entry.usage_metadata.credits_spent as f32),
      appearance.ui_font_family(),
      14.,
  )

  let credits_spent = conversation_data
      .as_ref()
      .and_then(|data| data.conversation_usage_metadata.as_ref())
      .map(|m| m.credits_spent);

I didn't put a ton of thought into which spots should be displaying credits spent, total credits spent, but do these seem valid?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, you're right, fixed up those places + 1 more

summarized: Boolean!

"""
Expand Down Expand Up @@ -1379,6 +1384,7 @@ union FreeAvailableModelsResult = FreeAvailableModelsOutput | UserFacingError

type GcpProviderConfig {
projectNumber: String!
serviceAccountEmail: String
workloadIdentityFederationPoolId: String!
workloadIdentityFederationProviderId: String!
}
Expand Down Expand Up @@ -4365,4 +4371,4 @@ enum WriteToPtyAutonomyValue {
ALWAYS_ASK
ASK_ON_FIRST_WRITE
RESPECT_USER_SETTING
}
}
Comment on lines -4368 to +4374

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Unintended removal of the newline?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is what the generation produced. If there was a newline at EOF, it's because someone probably didn't generate it and they hand-edited it or something

16 changes: 14 additions & 2 deletions skills-lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@
"skillPath": ".agents/skills/resolve-merge-conflicts/SKILL.md",
"computedHash": "5376b5692901c624e8f20a5a04aeea5f5a94f5168d29852a8a639aded6408f2e"
},
"respond-to-pr-comments-in-blocklist": {
"source": "warpdotdev/common-skills",
"sourceType": "github",
"skillPath": ".agents/skills/respond-to-pr-comments-in-blocklist/SKILL.md",
"computedHash": "f7408cf90c10397aa9048f14ab985a138641fc1e5f3245e290150437d62875f0"
},
"review-pr": {
"source": "warpdotdev/common-skills",
"sourceType": "github",
Expand All @@ -71,14 +77,20 @@
"source": "warpdotdev/common-skills",
"sourceType": "github",
"skillPath": ".agents/skills/spec-driven-implementation/SKILL.md",
"computedHash": "e334d0f6f0e8fc39055314acad911f36d92d1919372b5e2973cc99d7f8c901b4"
"computedHash": "45793ca1e35b032ddfd2596f2e86fd6f6e938549373bfe4aeb74683486a179e4"
Comment thread
jefflloyd marked this conversation as resolved.
},
"update-skill": {
"source": "warpdotdev/common-skills",
"sourceType": "github",
"skillPath": ".agents/skills/update-skill/SKILL.md",
"computedHash": "1e23c5a5c37ed084eced7fa507031e3cdb8e23f09cd5d004e00efd6f66bf200f"
},
"validate-changes-match-specs": {
"source": "warpdotdev/common-skills",
"sourceType": "github",
"skillPath": ".agents/skills/validate-changes-match-specs/SKILL.md",
"computedHash": "9123fd70ced064bdd773fd8d2baa8d5d5291fef910eb2c028084074b3ac72c27"
},
"write-product-spec": {
"source": "warpdotdev/common-skills",
"sourceType": "github",
Expand All @@ -89,7 +101,7 @@
"source": "warpdotdev/common-skills",
"sourceType": "github",
"skillPath": ".agents/skills/write-tech-spec/SKILL.md",
"computedHash": "3b5eb4ef021112d473984eca28412d372e87d9337ad5d9754f3ad3e01f94d39b"
"computedHash": "c7913bfd1ea2be7ce38d5beb7e923b96f5689f6145250af1d81b985e8be4a882"
}
}
}
Loading