MCPcopy Create free account
hub / github.com/anomalyco/opencode / applyUsage

Function applyUsage

packages/core/src/session/projector.ts:90–110  ·  view source on GitHub ↗
(
  db: DatabaseService,
  sessionID: (typeof SessionV1.Event.MessageUpdated.Type)["data"]["sessionID"],
  value: Usage,
  sign = 1,
)

Source from the content-addressed store, hash-verified

88}
89
90function applyUsage(
91 db: DatabaseService,
92 sessionID: (typeof SessionV1.Event.MessageUpdated.Type)["data"]["sessionID"],
93 value: Usage,
94 sign = 1,
95) {
96 return db
97 .update(SessionTable)
98 .set({
99 cost: sql`${SessionTable.cost} + ${value.cost * sign}`,
100 tokens_input: sql`${SessionTable.tokens_input} + ${value.tokens.input * sign}`,
101 tokens_output: sql`${SessionTable.tokens_output} + ${value.tokens.output * sign}`,
102 tokens_reasoning: sql`${SessionTable.tokens_reasoning} + ${value.tokens.reasoning * sign}`,
103 tokens_cache_read: sql`${SessionTable.tokens_cache_read} + ${value.tokens.cache.read * sign}`,
104 tokens_cache_write: sql`${SessionTable.tokens_cache_write} + ${value.tokens.cache.write * sign}`,
105 time_updated: sql`${SessionTable.time_updated}`,
106 })
107 .where(eq(SessionTable.id, sessionID))
108 .run()
109 .pipe(Effect.orDie)
110}
111
112function run(db: DatabaseService, event: SessionEvent.Event) {
113 return Effect.gen(function* () {

Callers 1

projector.tsFile · 0.85

Calls 5

eqFunction · 0.85
updateMethod · 0.65
runMethod · 0.45
whereMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected