repo: push all current workspace changes

This commit is contained in:
Nathan Flurry 2026-03-13 01:12:43 -07:00
parent 252fbdc93b
commit e7dfff5836
29 changed files with 577 additions and 98 deletions

View file

@ -11,6 +11,7 @@
"test": "vitest run"
},
"dependencies": {
"pino": "^10.3.1",
"zod": "^4.1.5"
},
"devDependencies": {

View file

@ -1,5 +1,6 @@
export * from "./app-shell.js";
export * from "./contracts.js";
export * from "./config.js";
export * from "./logging.js";
export * from "./workbench.js";
export * from "./workspace.js";

View file

@ -0,0 +1,63 @@
import { pino, type Logger, type LoggerOptions } from "pino";
export interface FoundryLoggerOptions {
service: string;
bindings?: Record<string, unknown>;
level?: string;
}
type ProcessLike = {
env?: Record<string, string | undefined>;
};
function resolveEnvVar(name: string): string | undefined {
const value = (globalThis as { process?: ProcessLike }).process?.env?.[name];
if (typeof value !== "string") {
return undefined;
}
const trimmed = value.trim();
return trimmed.length > 0 ? trimmed : undefined;
}
function defaultLevel(): string {
return resolveEnvVar("FOUNDRY_LOG_LEVEL") ?? resolveEnvVar("LOG_LEVEL") ?? resolveEnvVar("RIVET_LOG_LEVEL") ?? "info";
}
function isBrowserRuntime(): boolean {
return typeof window !== "undefined" && typeof document !== "undefined";
}
export function createFoundryLogger(options: FoundryLoggerOptions): Logger {
const browser = isBrowserRuntime();
const loggerOptions: LoggerOptions = {
level: options.level ?? defaultLevel(),
base: {
service: options.service,
...(options.bindings ?? {}),
},
};
if (browser) {
loggerOptions.browser = {
asObject: true,
};
} else {
loggerOptions.timestamp = pino.stdTimeFunctions.isoTime;
}
return pino(loggerOptions);
}
export function createErrorContext(error: unknown): { errorMessage: string; errorStack?: string } {
if (error instanceof Error) {
return {
errorMessage: error.message,
errorStack: error.stack,
};
}
return {
errorMessage: String(error),
};
}