History

fix: honor provider environment homes

t3-code[bot] committed 2 months ago

Commit 42d46691 parent 29ab4d43 files · +35 −11Browse files

Unified · Split

3 files
  1. apps/server/src/usage/UsageService.test.ts +22 −3
  2. apps/server/src/usage/UsageService.ts +10 −2
  3. apps/web/src/components/usage/UsagePage.tsx +3 −6
apps/server/src/usage/UsageService.test.ts+22−3
@@ -1,5 +1,10 @@
11 import * as NodeServices from "@effect/platform-node/NodeServices";
2−import { ProviderDriverKind, ProviderInstanceId, type UsageDay } from "@t3tools/contracts";
2+import {
3+ ProviderDriverKind,
4+ ProviderInstanceEnvironmentVariableName,
5+ ProviderInstanceId,
6+ type UsageDay,
7+} from "@t3tools/contracts";
38 import { expect, it } from "@effect/vitest";
49 import * as Effect from "effect/Effect";
510 import * as Layer from "effect/Layer";
@@ -85,12 +90,26 @@ it.layer(NodeServices.layer)("UsageService", (it) => { · 79 unmodified lines
8590 [ProviderInstanceId.make("codex-work")]: {
8691 driver: ProviderDriverKind.make("codex"),
8792 enabled: true,
88− config: { homePath: "/virtual/codex-work" },
93+ config: {},
94+ environment: [
95+ {
96+ name: ProviderInstanceEnvironmentVariableName.make("CODEX_HOME"),
97+ value: "/virtual/codex-work",
98+ sensitive: false,
99+ },
100+ ],
89101 },
90102 [ProviderInstanceId.make("codex-work-copy")]: {
91103 driver: ProviderDriverKind.make("codex"),
92104 enabled: true,
93− config: { homePath: "/virtual/codex-work" },
105+ config: {},
106+ environment: [
107+ {
108+ name: ProviderInstanceEnvironmentVariableName.make("CODEX_HOME"),
109+ value: "/virtual/codex-work",
110+ sensitive: false,
111+ },
112+ ],
94113 },
95114 },
96115 }),
apps/server/src/usage/UsageService.ts+10−2
@@ -41,6 +41,7 @@ import { ServerConfig } from "../config.ts"; · 40 unmodified lines
4141 import * as ServerSettings from "../serverSettings.ts";
4242 import { resolveClaudeHomePath } from "../provider/Drivers/ClaudeHome.ts";
4343 import { resolveCodexHomeLayout } from "../provider/Drivers/CodexHomeLayout.ts";
44+import { mergeProviderInstanceEnvironment } from "../provider/ProviderInstanceEnvironment.ts";
4445 import { UsageAggregator } from "./usageAggregation.ts";
4546 import { parseRateTable, type RateTable } from "./usagePricing.ts";
4647 import {
@@ -236,7 +237,10 @@ export const make = Effect.gen(function* () { · 189 unmodified lines
236237 )) {
237238 const config = decodeClaudeSettings(instance.config ?? {});
238239 if (Option.isNone(config)) continue;
239− const claudeHome = yield* resolveClaudeHomePath(config.value);
240+ const processEnv = mergeProviderInstanceEnvironment(instance.environment);
241+ const claudeHome = yield* resolveClaudeHomePath({
242+ homePath: config.value.homePath || processEnv.CLAUDE_CONFIG_DIR || "",
243+ });
240244 addDir("claude", yield* resolveClaudeTranscriptDir(claudeHome));
241245 }
242246
@@ -246,7 +250,11 @@ export const make = Effect.gen(function* () { · 3 unmodified lines
246250 )) {
247251 const config = decodeCodexSettings(instance.config ?? {});
248252 if (Option.isNone(config)) continue;
249− const codexLayout = yield* resolveCodexHomeLayout(config.value);
253+ const processEnv = mergeProviderInstanceEnvironment(instance.environment);
254+ const codexLayout = yield* resolveCodexHomeLayout({
255+ ...config.value,
256+ homePath: config.value.homePath || processEnv.CODEX_HOME || "",
257+ });
250258 addDir("codex", path.join(codexLayout.sharedHomePath, "sessions"));
251259 }
252260 return dirs;
apps/web/src/components/usage/UsagePage.tsx+3−6
@@ -62,9 +62,6 @@ export function UsagePage() { · 61 unmodified lines
6262 }
6363 return PROVIDER_ORDER.filter((provider) => enabled.has(provider));
6464 }, [environments, merged.staleEnvironments]);
65− const skeletonProviders = environments.some((environment) => environment.summary !== null)
66− ? providers
67− : PROVIDER_ORDER;
6865
6966 // Hold the content until every environment is terminal. Rendering merged
7067 // totals while devices are still answering makes every number on the page
@@ -217,7 +214,7 @@ export function UsagePage() { · 146 unmodified lines
217214 {settling ? (
218215 <>
219216 {environments.length > 1 ? <UsageDeviceStrip environments={environments} /> : null}
220− <UsageSkeleton providers={skeletonProviders} />
217+ <UsageSkeleton />
221218 </>
222219 ) : (
223220 <>
@@ -591,7 +588,7 @@ function UsageDeviceStrip({ · 367 unmodified lines
591588 * Static stand-in with the loaded page's shape. No shimmer; blocks fill in
592589 * exactly once when the last device answers.
593590 */
594−function UsageSkeleton({ providers }: { readonly providers: readonly UsageProviderKind[] }) {
591+function UsageSkeleton() {
595592 return (
596593 <>
597594 <section className="grid gap-6 lg:grid-cols-[minmax(0,16rem)_minmax(0,1fr)]">
@@ -600,7 +597,7 @@ function UsageSkeleton({ providers }: { readonly providers: readonly UsageProvid · 2 unmodified lines
600597 <div className="h-10 w-36 rounded-sm bg-muted" />
601598 <div className="h-4 w-32 rounded-sm bg-muted" />
602599 </div>
603− {providers.map((provider) => (
600+ {PROVIDER_ORDER.map((provider) => (
604601 <div key={provider} className="flex flex-col gap-1">
605602 <div className="flex min-h-5 items-center justify-between gap-4">
606603 <span className="flex items-center gap-2">

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t