mirror of
https://github.com/harivansh-afk/sandbox-agent.git
synced 2026-04-17 01:04:42 +00:00
repo: push all current workspace changes
This commit is contained in:
parent
252fbdc93b
commit
e7dfff5836
29 changed files with 577 additions and 98 deletions
|
|
@ -11,6 +11,7 @@
|
|||
"test": "vitest run"
|
||||
},
|
||||
"dependencies": {
|
||||
"pino": "^10.3.1",
|
||||
"zod": "^4.1.5"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
|
|
|||
|
|
@ -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";
|
||||
|
|
|
|||
63
foundry/packages/shared/src/logging.ts
Normal file
63
foundry/packages/shared/src/logging.ts
Normal 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),
|
||||
};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue