Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions apps/amp/src/data-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,9 @@ function convertLedgerEventToUsageEvent(
*/
async function loadThreadFile(filePath: string): Promise<ParsedThread | null> {
const readResult = await Result.try({
try: readFile(filePath, 'utf-8'),
catch: (error) => error,
immediate: true,
try: async () => readFile(filePath, 'utf-8'),
catch: (error: unknown) => error,
});

if (Result.isFailure(readResult)) {
Expand Down
15 changes: 5 additions & 10 deletions apps/ccusage/scripts/generate-json-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,9 @@ function createConfigSchemaJson() {
*/
async function runFormat(files: string[]) {
return Result.try({
try: $`pnpm exec oxfmt ${files}`,
catch: (error) => error,
immediate: true,
try: async () => $`pnpm exec oxfmt ${files}`,
catch: (error: unknown) => error,
});
}

Expand Down Expand Up @@ -256,10 +257,7 @@ async function generateJsonSchema() {
const schemaJson = JSON.stringify(schemaObject, null, '\t');

await Result.pipe(
Result.try({
try: writeFile(SCHEMA_FILENAME, schemaJson),
safe: true,
}),
writeFile(SCHEMA_FILENAME, schemaJson),
Result.inspectError((error) => {
logger.error(`Failed to write ${SCHEMA_FILENAME}:`, error);
process.exit(1);
Expand All @@ -272,10 +270,7 @@ async function generateJsonSchema() {

// Run format on the root schema file that was changed
await Result.pipe(
Result.try({
try: runFormat([SCHEMA_FILENAME]),
safe: true,
}),
runFormat([SCHEMA_FILENAME]),
Result.inspectError((error) => {
logger.error('Failed to format generated files:', error);
process.exit(1);
Expand Down
5 changes: 3 additions & 2 deletions apps/ccusage/src/_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ export function unreachable(value: never): never {
export async function getFileModifiedTime(filePath: string): Promise<number> {
return Result.pipe(
Result.try({
try: stat(filePath),
catch: (error) => error,
immediate: true,
try: async () => stat(filePath),
catch: (error: unknown) => error,
}),
Result.map((stats) => stats.mtime.getTime()),
Result.unwrap(0), // Default to 0 if file doesn't exist or can't be accessed
Expand Down
10 changes: 6 additions & 4 deletions apps/codex/src/data-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,9 @@ export async function loadTokenUsageEvents(options: LoadOptions = {}): Promise<L
for (const dir of sessionDirs) {
const directoryPath = path.resolve(dir);
const statResult = await Result.try({
try: stat(directoryPath),
catch: (error) => error,
immediate: true,
try: async () => stat(directoryPath),
catch: (error: unknown) => error,
});

if (Result.isFailure(statResult)) {
Expand All @@ -226,8 +227,9 @@ export async function loadTokenUsageEvents(options: LoadOptions = {}): Promise<L
const normalizedSessionPath = relativeSessionPath.split(path.sep).join('/');
const sessionId = normalizedSessionPath.replace(/\.jsonl$/i, '');
const fileContentResult = await Result.try({
try: readFile(file, 'utf8'),
catch: (error) => error,
immediate: true,
try: async () => readFile(file, 'utf8'),
catch: (error: unknown) => error,
});

if (Result.isFailure(fileContentResult)) {
Expand Down
11 changes: 7 additions & 4 deletions packages/internal/src/pricing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,9 @@ export class LiteLLMPricingFetcher implements Disposable {
this.logger.warn('Fetching latest model pricing from LiteLLM...');
return Result.pipe(
Result.try({
try: fetch(this.url),
catch: (error) =>
immediate: true,
try: async () => fetch(this.url),
catch: (error: unknown) =>
new Error('Failed to fetch model pricing from LiteLLM', { cause: error }),
}),
Result.andThrough((response) => {
Expand All @@ -167,8 +168,10 @@ export class LiteLLMPricingFetcher implements Disposable {
}),
Result.andThen(async (response) =>
Result.try({
try: response.json() as Promise<Record<string, unknown>>,
catch: (error) => new Error('Failed to parse pricing data', { cause: error }),
immediate: true,
try: async () => response.json() as Promise<Record<string, unknown>>,
catch: (error: unknown) =>
new Error('Failed to parse pricing data', { cause: error }),
}),
),
Result.map((data) => {
Expand Down
61 changes: 32 additions & 29 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions pnpm-workspace.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ catalogs:
'@hono/mcp': ^0.1.5
'@hono/node-server': ^1.19.7
'@modelcontextprotocol/sdk': ^1.24.3
'@praha/byethrow': ^0.6.3
'@praha/byethrow': ^0.9.0
'@ryoppippi/limo': jsr:^0.2.2
'@std/async': jsr:^1.0.14
ansi-escapes: ^7.0.0
Expand All @@ -49,7 +49,7 @@ catalogs:
es-toolkit: ^1.39.10
fast-sort: ^3.4.1
get-stdin: ^9.0.0
gunshi: ^0.26.3
gunshi: ^0.27.5
hono: ^4.9.2
nano-spawn: ^1.0.3
p-limit: ^7.1.0
Expand Down
Loading