diff --git a/crush.json b/crush.json new file mode 100644 index 0000000..368dcad --- /dev/null +++ b/crush.json @@ -0,0 +1,11 @@ +{ + "mcp": { + "ssh": { + "command": "ssh-mcp", + "args": [ + "--allowed-hosts=terebithia,prattle" + ], + "type": "stdio" + } + } +} diff --git a/server/db/queries/pool_keys.sql b/server/db/queries/pool_keys.sql index 90b7957..45754fa 100644 --- a/server/db/queries/pool_keys.sql +++ b/server/db/queries/pool_keys.sql @@ -81,6 +81,8 @@ WHERE id = ?4; -- All users with their pool key stats (if any). -- Users without keys appear with zero contributions. -- private_reservation_micros = sum(max_micros - shared_micros) for active keys. +-- today_micros capped at shared_micros: a key whose credit limit dropped (e.g. +-- $1000->$50) can't report more pool spend than its current contribution. SELECT u.id AS user_id, u.display_name, @@ -88,7 +90,7 @@ SELECT COUNT(pk.id) AS key_count, COALESCE(SUM(CASE WHEN pk.active = 1 THEN pk.shared_micros ELSE 0 END), 0) AS daily_limit_micros, COALESCE(SUM(CASE WHEN pk.active = 1 THEN pk.max_micros - pk.shared_micros ELSE 0 END), 0) AS private_reservation_micros, - COALESCE(SUM(CASE WHEN pk.active = 1 THEN pk.today_micros ELSE 0 END), 0) AS today_micros, + COALESCE(SUM(CASE WHEN pk.active = 1 THEN MIN(pk.today_micros, pk.shared_micros) ELSE 0 END), 0) AS today_micros, COALESCE(SUM(pk.total_micros), 0) AS total_micros, COALESCE(SUM(pk.request_count), 0) AS request_count FROM users u diff --git a/server/internal/store/pool_keys.sql.go b/server/internal/store/pool_keys.sql.go index b109edf..d559211 100644 --- a/server/internal/store/pool_keys.sql.go +++ b/server/internal/store/pool_keys.sql.go @@ -134,7 +134,7 @@ SELECT COUNT(pk.id) AS key_count, COALESCE(SUM(CASE WHEN pk.active = 1 THEN pk.shared_micros ELSE 0 END), 0) AS daily_limit_micros, COALESCE(SUM(CASE WHEN pk.active = 1 THEN pk.max_micros - pk.shared_micros ELSE 0 END), 0) AS private_reservation_micros, - COALESCE(SUM(CASE WHEN pk.active = 1 THEN pk.today_micros ELSE 0 END), 0) AS today_micros, + COALESCE(SUM(CASE WHEN pk.active = 1 THEN MIN(pk.today_micros, pk.shared_micros) ELSE 0 END), 0) AS today_micros, COALESCE(SUM(pk.total_micros), 0) AS total_micros, COALESCE(SUM(pk.request_count), 0) AS request_count FROM users u @@ -159,6 +159,8 @@ type ListPoolAllocationsRow struct { // All users with their pool key stats (if any). // Users without keys appear with zero contributions. // private_reservation_micros = sum(max_micros - shared_micros) for active keys. +// today_micros capped at shared_micros: a key whose credit limit dropped (e.g. +// $1000->$50) can't report more pool spend than its current contribution. func (q *Queries) ListPoolAllocations(ctx context.Context) ([]ListPoolAllocationsRow, error) { rows, err := q.db.QueryContext(ctx, listPoolAllocations) if err != nil { diff --git a/server/internal/store/querier.go b/server/internal/store/querier.go index 5afcc43..5c091d6 100644 --- a/server/internal/store/querier.go +++ b/server/internal/store/querier.go @@ -55,7 +55,6 @@ type Querier interface { GetModelPrice(ctx context.Context, model string) (ModelPrice, error) GetPoolKey(ctx context.Context, id string) (PoolKey, error) GetSession(ctx context.Context, arg GetSessionParams) (Session, error) - GetRunningStreamForConversation(ctx context.Context, conversationID string) (Stream, error) GetStream(ctx context.Context, id string) (Stream, error) GetStreamByIdempotencyKey(ctx context.Context, arg GetStreamByIdempotencyKeyParams) (Stream, error) GetUserByEmail(ctx context.Context, email string) (User, error) @@ -101,6 +100,8 @@ type Querier interface { // All users with their pool key stats (if any). // Users without keys appear with zero contributions. // private_reservation_micros = sum(max_micros - shared_micros) for active keys. + // today_micros capped at shared_micros: a key whose credit limit dropped (e.g. + // $1000->$50) can't report more pool spend than its current contribution. ListPoolAllocations(ctx context.Context) ([]ListPoolAllocationsRow, error) // All keys (for the pool management page). Includes inactive and other users' keys. ListPoolKeys(ctx context.Context) ([]ListPoolKeysRow, error)