Per-environment auth, correct Codex fast-mode pricing, and several accuracy fixes raised by review. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
28 lines
1008 B
TypeScript
28 lines
1008 B
TypeScript
import { AuthOrchestrationReadScope, EnvironmentHttpApi } from "@t3tools/contracts";
|
|
import * as Effect from "effect/Effect";
|
|
import * as HttpApiBuilder from "effect/unstable/httpapi/HttpApiBuilder";
|
|
|
|
import { annotateEnvironmentRequest, requireEnvironmentScope } from "../auth/http.ts";
|
|
import * as UsageService from "./UsageService.ts";
|
|
|
|
/**
|
|
* Usage is read-only reporting over data the host already has, so it rides the
|
|
* orchestration read scope rather than introducing a new one.
|
|
*/
|
|
export const usageHttpApiLayer = HttpApiBuilder.group(
|
|
EnvironmentHttpApi,
|
|
"usage",
|
|
Effect.fnUntraced(function* (handlers) {
|
|
const usage = yield* UsageService.UsageService;
|
|
|
|
return handlers.handle(
|
|
"snapshot",
|
|
Effect.fn("environment.usage.snapshot")(function* (args) {
|
|
yield* annotateEnvironmentRequest(args.endpoint.name);
|
|
yield* requireEnvironmentScope(AuthOrchestrationReadScope);
|
|
return yield* usage.getSnapshot(args.payload.sinceDate);
|
|
}),
|
|
);
|
|
}),
|
|
);
|