-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature: Managing Agent Usage counter from backend #293
Merged
alashchev17
merged 14 commits into
alpha
from
feat/managing-agent-usage-counter-on-backend
Jan 20, 2025
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
5fef401
feat: sending new header of last user message id on /v1/chat & storin…
alashchev17 789c2ff
wip: cut off enableSend
alashchev17 bd651a2
fix: fixed types and tests
alashchev17 70422d8
fix: sending last user message id within body of request, not as header
alashchev17 4f73633
rework
reymondzzzz 0b87a96
wip: receiving agent usage counter from backend, using those values i…
alashchev17 157acff
Merge branch 'alpha' into feat/managing-agent-usage-counter-on-backend
alashchev17 58ab9f8
feat: refactored useAgentUsage hook, created middleware for chatRespo…
alashchev17 ca95dce
Merge branch 'alpha' into feat/managing-agent-usage-counter-on-backend
alashchev17 650e7eb
fix: created separate action for initial set of data, removed outdate…
alashchev17 fae089f
fix: disabling agentic models for free users in other modes, not agent
alashchev17 f5376a3
fix: adjusted UserSurvey test & made proper type guarding for User type
alashchev17 348ee56
chore: fixed npm run types
alashchev17 4921ced
fix: adjusted mocks for pro/non-pro users
alashchev17 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,18 +6,18 @@ import { Theme } from "../../components/Theme"; | |
import { AgentUsage } from "./AgentUsage"; | ||
import { nonProUser } from "../../__fixtures__/msw"; | ||
|
||
const items = Array.from({ length: 100 }).map(() => ({ | ||
user: "[email protected]", | ||
time: Date.now(), | ||
})); | ||
|
||
const Template: React.FC = () => { | ||
const store = setUpStore({ | ||
tour: { | ||
type: "finished", | ||
}, | ||
agentUsage: { | ||
items, | ||
agent_usage: 5, | ||
agent_max_usage_amount: 20, | ||
_persist: { | ||
rehydrated: true, | ||
version: 1, | ||
}, | ||
}, | ||
config: { | ||
apiKey: "foo", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,45 @@ | ||
import { createSlice, PayloadAction } from "@reduxjs/toolkit"; | ||
|
||
export type AgentUsageItem = { | ||
time: number; | ||
user: string; | ||
export type AgentUsageMeta = { | ||
agent_usage: null | number; // null if plan is PRO or ROBOT | ||
agent_max_usage_amount: number; // maximum amount of agent usage allowed per UTC day for users with FREE plan | ||
}; | ||
|
||
const initialState: { items: AgentUsageItem[] } = { items: [] }; | ||
|
||
const oneDay = 24 * 60 * 60 * 1000; | ||
const initialState: AgentUsageMeta = { | ||
alashchev17 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
agent_usage: null, | ||
agent_max_usage_amount: 20, | ||
}; | ||
|
||
export const agentUsageSlice = createSlice({ | ||
name: "agentUsage", | ||
initialState, | ||
reducers: { | ||
addAgentUsageItem: (state, action: PayloadAction<{ user: string }>) => { | ||
const now = Date.now(); | ||
const todaysItems = state.items.filter( | ||
(item) => item.time + oneDay > now, | ||
); | ||
const item = { time: now, user: action.payload.user }; | ||
state.items = [...todaysItems, item]; | ||
updateAgentUsage: ( | ||
state, | ||
action: PayloadAction<AgentUsageMeta["agent_usage"]>, | ||
) => { | ||
state.agent_usage = action.payload; | ||
}, | ||
updateMaxAgentUsageAmount: (state, action: PayloadAction<number>) => { | ||
state.agent_max_usage_amount = action.payload; | ||
}, | ||
setInitialAgentUsage: (state, action: PayloadAction<AgentUsageMeta>) => { | ||
const { agent_max_usage_amount, agent_usage } = action.payload; | ||
state.agent_usage = agent_usage; | ||
state.agent_max_usage_amount = agent_max_usage_amount; | ||
}, | ||
}, | ||
|
||
selectors: { | ||
selectAgentUsageItems: (state) => { | ||
return state.items; | ||
}, | ||
selectAgentUsage: (state) => state.agent_usage, | ||
selectMaxAgentUsageAmount: (state) => state.agent_max_usage_amount, | ||
}, | ||
}); | ||
|
||
export const { addAgentUsageItem } = agentUsageSlice.actions; | ||
export const { selectAgentUsageItems } = agentUsageSlice.selectors; | ||
export const { | ||
updateAgentUsage, | ||
updateMaxAgentUsageAmount, | ||
setInitialAgentUsage, | ||
} = agentUsageSlice.actions; | ||
export const { selectAgentUsage, selectMaxAgentUsageAmount } = | ||
agentUsageSlice.selectors; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i didn't know
_persist
could be added like that.