Skip to content

fix(inference-billing): fix inference billing when stream is true via API, add drag-and-drop functionality to deployed chat - #1606

Merged
waleedlatif1 merged 2 commits into
stagingfrom
fix/inference-bil
Oct 12, 2025
Merged

fix(inference-billing): fix inference billing when stream is true via API, add drag-and-drop functionality to deployed chat#1606
waleedlatif1 merged 2 commits into
stagingfrom
fix/inference-bil

Conversation

@waleedlatif1

Copy link
Copy Markdown
Collaborator

Summary

fix inference billing when stream is true via API, add drag-and-drop functionality to deployed chat

Type of Change

  • Bug fix
  • New feature

Testing

Tested manually.

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

@vercel

vercelBot commented Oct 12, 2025

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
ProjectDeploymentPreviewCommentsUpdated (UTC)
docsSkippedSkippedOct 12, 2025 2:55am

@greptile-appsgreptile-appsBot left a comment

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.

Greptile Overview

Summary

Fixed inference billing when stream=true by deferring logging completion until after tokenization, and added drag-and-drop file upload to deployed chat interface.

Key Changes:

  • Billing Fix: Deferred loggingSession.safeComplete() call in streaming execution flow to ensure cost/token data from processStreamingBlockLogs() is included in trace spans before logging
  • Drag-and-Drop: Added drag event handlers (onDragEnter, onDragOver, onDragLeave, onDrop) to chat input with visual feedback via dragCounter state and conditional styling
  • Added skipLoggingComplete parameter to executeWorkflow() options and _streamingMetadata field to ExecutionResult for passing logging session through streaming pipeline

The billing fix addresses a timing issue where streaming executions logged incomplete cost data because tokenization happened after logging completion.

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • Both features are well-implemented with clear separation of concerns. The billing fix properly defers logging until after tokenization without affecting non-streaming flows. The drag-and-drop implementation uses standard browser APIs with proper event handling and guards against streaming state. No breaking changes or security issues detected.
  • No files require special attention

Important Files Changed

File Analysis

FilenameScoreOverview
apps/sim/lib/workflows/streaming.ts5/5Added deferred logging completion after tokenization to ensure cost data is calculated before logging
apps/sim/app/api/workflows/[id]/execute/route.ts5/5Added skipLoggingComplete parameter and streaming metadata to defer logging completion until after tokenization
apps/sim/executor/types.ts5/5Added _streamingMetadata to ExecutionResult for passing logging session data to streaming handler
apps/sim/app/chat/components/input/input.tsx5/5Implemented drag-and-drop file upload with visual feedback using drag counter and event handlers

Sequence Diagram

sequenceDiagram
participant Client
participant API as /api/workflows/[id]/execute
participant Execute as executeWorkflow()
participant Streaming as createStreamingResponse()
participant Tokenize as processStreamingBlockLogs()
participant TraceSpans as buildTraceSpans()
participant LogSession as loggingSession
Client->>API: POST with stream=true
API->>Streaming: createStreamingResponse()
Streaming->>Execute: executeWorkflow(skipLoggingComplete: true)
Execute->>Execute: Run workflow execution
Execute->>Execute: Build initial trace spans
Note over Execute,LogSession: Skip logging completion (skipLoggingComplete=true)
Execute->>Execute: Attach _streamingMetadata (loggingSession, processedInput)
Execute-->>Streaming: Return result with _streamingMetadata
Streaming->>Streaming: Update result.logs with streamed content
Streaming->>Tokenize: processStreamingBlockLogs(logs, streamedContent)
Tokenize->>Tokenize: Calculate tokens & cost for streamed content
Tokenize-->>Streaming: Updated logs with cost data
Streaming->>TraceSpans: buildTraceSpans(result)
TraceSpans-->>Streaming: traceSpans with cost data
Streaming->>LogSession: safeComplete(traceSpans, finalOutput)
Note over LogSession: Now includes accurate billing/cost data
LogSession-->>Streaming: Logging complete
Streaming->>Streaming: Clear _streamingMetadata
Streaming-->>Client: Stream response with accurate billing
Loading

4 files reviewed, no comments

Edit Code Review Agent Settings | Greptile

@waleedlatif1
waleedlatif1 merged commit 4729269 into stagingOct 12, 2025
9 checks passed
@waleedlatif1
waleedlatif1 deleted the fix/inference-bil branch October 12, 2025 03:06
waleedlatif1 added a commit that referenced this pull request Oct 12, 2025
… API, add drag-and-drop functionality to deployed chat (#1606)
* fix(inference): fix inference billing when stream is true via API
* add drag-and-drop to deployed chat
waleedlatif1 added a commit that referenced this pull request Oct 12, 2025
… API, add drag-and-drop functionality to deployed chat (#1606)
* fix(inference): fix inference billing when stream is true via API
* add drag-and-drop to deployed chat
waleedlatif1 added a commit that referenced this pull request Oct 12, 2025
* improvement(performance): remove unused source/target indices, add index on snapshot id (#1603)
* fix(blog): rename building to blogs with redirect (#1604)
* improvement(privacy-policy): updated privacy policy for google (#1602)
* updated privacy policy for google
* update terms, privacy, and emails to incl address and update verbiage
* feat(guardrails): added guardrails block/tools and docs (#1605)
* Adding guardrails block
* ack PR comments
* cleanup checkbox in dark mode
* cleanup
* fix supabase tools
* fix(inference-billing): fix inference billing when stream is true via API, add drag-and-drop functionality to deployed chat (#1606)
* fix(inference): fix inference billing when stream is true via API
* add drag-and-drop to deployed chat
* feat(mistal): added mistral as a provider, updated model prices (#1607)
* feat(mistal): added mistral as a provider, updated model prices
* remove the ability for a block to reference its own outluts
* fixed order of responses for guardrails block
* feat(versions): added the ability to rename deployment versions (#1610)
* fix(vulns): fix various vulnerabilities and enhanced code security (#1611)
* fix(vulns): fix SSRF vulnerabilities
* cleanup
* cleanup
* regen docs
* remove unused deps
* fix failing tests
* cleanup
* update deps
* regen bun lock
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

@waleedlatif1