feat(knowledge): add Live sync option to KB connectors + fix embedding billing#3916
feat(knowledge): add Live sync option to KB connectors + fix embedding billing#3916waleedlatif1 merged 12 commits intostagingfrom
Conversation
…nterprise users Adds a "Live" (every 5 min) sync frequency option gated to Max and Enterprise plan users. Includes client-side badge + disabled state, shared sync intervals constant, and server-side plan validation on both POST and PATCH connector routes.
Adds billing tracking to the KB embedding pipeline, which was previously generating OpenAI API calls with no cost recorded. Token counts are now captured from the actual API response and recorded via recordUsage after successful embedding insertion. BYOK workspaces are excluded from billing. Applies to all execution paths: direct, BullMQ, and Trigger.dev.
…n modelName - Use calculateCost() from @/providers/utils instead of inline formula, consistent with how LLM billing works throughout the platform - Return modelName from GenerateEmbeddingsResult so billing uses the actual model (handles custom Azure deployments) instead of a hardcoded fallback string - Fix docs-chunker.ts empty-path fallback to satisfy full GenerateEmbeddingsResult type
PR SummaryMedium Risk Overview Enforces the same gate server-side by rejecting connector Fixes embedding billing by extending Reviewed by Cursor Bugbot for commit 80e97aa. Configure here. |
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
Greptile SummaryThis PR adds a "Live" (every 5 minutes) sync option to Knowledge Base connector modals, gated behind Max/Enterprise plan access both client-side (disabled button + Key changes:
Confidence Score: 5/5Safe to merge — no critical or blocking issues found; all three previous P1 concerns have been addressed. All three P1 findings from the prior review round (billing metadata discarded in DocsChunker, isBYOK/modelName overwritten per batch, silent billing miss for Azure custom deployment names) have been resolved. The billing flow is well-structured, the server-side plan gate is consistent between POST and PATCH, the DB migration is correct, and tests were updated to cover the new usage field in mock responses. No files require special attention. Important Files Changed
Sequence DiagramsequenceDiagram
participant UI as Connector Modal
participant API as POST /connectors
participant Sub as hasLiveSyncAccess
participant DB as Database
participant Embed as generateEmbeddings
participant Billing as recordUsage
UI->>API: POST { syncIntervalMinutes: 5 }
API->>Sub: hasLiveSyncAccess(userId)
Sub-->>API: true/false
alt not Max/Enterprise
API-->>UI: 403 Live sync requires Max
else allowed
API->>DB: Insert connector
API-->>UI: 201 Created
end
Note over DB,Billing: Background: processDocumentAsync
DB->>Embed: generateEmbeddings(texts, model, workspaceId)
Embed-->>DB: { embeddings, totalTokens, isBYOK, modelName }
DB->>DB: Insert embeddings + mark completed (transaction)
alt !isBYOK && totalTokens > 0 && userId
DB->>Billing: recordUsage({ cost, tokens })
Billing->>Billing: checkAndBillOverageThreshold(userId)
end
Reviews (4): Last reviewed commit: "fix(knowledge): call checkAndBillOverage..." | Re-trigger Greptile |
...orkspace/[workspaceId]/knowledge/[id]/components/add-connector-modal/add-connector-modal.tsx
Outdated
Show resolved
Hide resolved
…onfig once per document
|
@greptile |
|
@cursor review |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit 144b056. Configure here.
|
@greptile |
|
@cursor review |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit e92e3c9. Configure here.
|
@greptile |
|
@cursor review |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit 80e97aa. Configure here.
…g billing (simstudioai#3916) * feat(knowledge): add Live sync option to KB connector modal for Max/Enterprise users Adds a "Live" (every 5 min) sync frequency option gated to Max and Enterprise plan users. Includes client-side badge + disabled state, shared sync intervals constant, and server-side plan validation on both POST and PATCH connector routes. * fix(knowledge): record embedding usage cost for KB document processing Adds billing tracking to the KB embedding pipeline, which was previously generating OpenAI API calls with no cost recorded. Token counts are now captured from the actual API response and recorded via recordUsage after successful embedding insertion. BYOK workspaces are excluded from billing. Applies to all execution paths: direct, BullMQ, and Trigger.dev. * fix(knowledge): simplify embedding billing — use calculateCost, return modelName - Use calculateCost() from @/providers/utils instead of inline formula, consistent with how LLM billing works throughout the platform - Return modelName from GenerateEmbeddingsResult so billing uses the actual model (handles custom Azure deployments) instead of a hardcoded fallback string - Fix docs-chunker.ts empty-path fallback to satisfy full GenerateEmbeddingsResult type * fix(knowledge): remove dev bypass from hasLiveSyncAccess * chore(knowledge): rename sync-intervals to consts, fix stale TSDoc comment * improvement(knowledge): extract MaxBadge component, capture billing config once per document * fix(knowledge): add knowledge-base to usage_log_source enum, fix docs-chunker type * fix(knowledge): generate migration for knowledge-base usage_log_source enum value * fix(knowledge): add knowledge-base to usage_log_source enum via drizzle-kit * fix(knowledge): fix search embedding test mocks, parallelize billing lookups * fix(knowledge): warn when embedding model has no pricing entry * fix(knowledge): call checkAndBillOverageThreshold after embedding usage
…g billing (#3916) * feat(knowledge): add Live sync option to KB connector modal for Max/Enterprise users Adds a "Live" (every 5 min) sync frequency option gated to Max and Enterprise plan users. Includes client-side badge + disabled state, shared sync intervals constant, and server-side plan validation on both POST and PATCH connector routes. * fix(knowledge): record embedding usage cost for KB document processing Adds billing tracking to the KB embedding pipeline, which was previously generating OpenAI API calls with no cost recorded. Token counts are now captured from the actual API response and recorded via recordUsage after successful embedding insertion. BYOK workspaces are excluded from billing. Applies to all execution paths: direct, BullMQ, and Trigger.dev. * fix(knowledge): simplify embedding billing — use calculateCost, return modelName - Use calculateCost() from @/providers/utils instead of inline formula, consistent with how LLM billing works throughout the platform - Return modelName from GenerateEmbeddingsResult so billing uses the actual model (handles custom Azure deployments) instead of a hardcoded fallback string - Fix docs-chunker.ts empty-path fallback to satisfy full GenerateEmbeddingsResult type * fix(knowledge): remove dev bypass from hasLiveSyncAccess * chore(knowledge): rename sync-intervals to consts, fix stale TSDoc comment * improvement(knowledge): extract MaxBadge component, capture billing config once per document * fix(knowledge): add knowledge-base to usage_log_source enum, fix docs-chunker type * fix(knowledge): generate migration for knowledge-base usage_log_source enum value * fix(knowledge): add knowledge-base to usage_log_source enum via drizzle-kit * fix(knowledge): fix search embedding test mocks, parallelize billing lookups * fix(knowledge): warn when embedding model has no pricing entry * fix(knowledge): call checkAndBillOverageThreshold after embedding usage
Summary
Type of Change
Testing
Tested manually
Checklist