mirror of
https://github.com/Routstr/routstrd.git
synced 2026-07-30 15:46:14 +00:00
feat: configure raw request response logging
This commit is contained in:
@@ -48,6 +48,7 @@ type DaemonDeps = {
|
||||
routstrPubkey?: string;
|
||||
providerManager: ProviderManager;
|
||||
refundClient: any;
|
||||
requestResponseLogDir?: string;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -303,6 +304,7 @@ export function createDaemonRequestHandler(deps: {
|
||||
usageTrackingDriver: UsageTrackingDriver;
|
||||
providerManager: ProviderManager;
|
||||
refundClient: any;
|
||||
requestResponseLogDir?: string;
|
||||
}) {
|
||||
return async function handler(req: IncomingMessage, res: ServerResponse) {
|
||||
const host = req.headers.host || "localhost";
|
||||
@@ -1274,6 +1276,9 @@ export function createDaemonRequestHandler(deps: {
|
||||
sdkStore: deps.store,
|
||||
providerManager: deps.providerManager,
|
||||
logger: reqLogger,
|
||||
...(deps.requestResponseLogDir
|
||||
? { requestResponseLogDir: deps.requestResponseLogDir }
|
||||
: {}),
|
||||
...(deps.routstrPubkey ? { routstrPubkey: deps.routstrPubkey } : {}),
|
||||
});
|
||||
|
||||
|
||||
+16
-1
@@ -11,7 +11,13 @@ import {
|
||||
// (SDK 0.3.7+ browser-safe entrypoint split).
|
||||
import { ModelManager } from "@routstr/sdk/bun";
|
||||
import type { SdkLogger } from "@routstr/sdk";
|
||||
import { CONFIG_DIR, DB_PATH, SOCKET_PATH, PID_FILE } from "../utils/config";
|
||||
import {
|
||||
CONFIG_DIR,
|
||||
DB_PATH,
|
||||
SOCKET_PATH,
|
||||
PID_FILE,
|
||||
REQUEST_RESPONSE_LOGS_DIR,
|
||||
} from "../utils/config";
|
||||
import { logger } from "../utils/logger";
|
||||
|
||||
|
||||
@@ -49,6 +55,11 @@ async function main(): Promise<void> {
|
||||
|
||||
const port = args.port;
|
||||
const provider = args.provider || config.provider;
|
||||
const requestResponseLogDir =
|
||||
process.env.ROUTSTRD_REQUEST_RESPONSE_LOG_DIR ||
|
||||
(config.requestResponseLogging?.enabled
|
||||
? config.requestResponseLogging.dir || REQUEST_RESPONSE_LOGS_DIR
|
||||
: undefined);
|
||||
|
||||
await ensureDirs();
|
||||
|
||||
@@ -133,6 +144,7 @@ async function main(): Promise<void> {
|
||||
usageTrackingDriver,
|
||||
providerManager,
|
||||
refundClient,
|
||||
requestResponseLogDir,
|
||||
}),
|
||||
);
|
||||
|
||||
@@ -242,6 +254,9 @@ async function main(): Promise<void> {
|
||||
|
||||
server.listen(port, async () => {
|
||||
logger.log(`Routstr daemon listening on http://localhost:${port}/v1`);
|
||||
if (requestResponseLogDir) {
|
||||
logger.log(`Raw request/response logs: ${requestResponseLogDir}`);
|
||||
}
|
||||
|
||||
// Start the recurring model refresh job after initial bootstrap
|
||||
void ensureProvidersBootstrapped()
|
||||
|
||||
@@ -6,6 +6,7 @@ export const PID_FILE = process.env.ROUTSTRD_PID || `${CONFIG_DIR}/routstrd.pid`
|
||||
export const DB_PATH = `${CONFIG_DIR}/routstr.db`;
|
||||
export const CONFIG_FILE = `${CONFIG_DIR}/config.json`;
|
||||
export const LOGS_DIR = `${CONFIG_DIR}/logs`;
|
||||
export const REQUEST_RESPONSE_LOGS_DIR = `${CONFIG_DIR}/request-response-logs`;
|
||||
|
||||
/** NWC auto-refill configuration */
|
||||
export interface NwcAutoRefillConfig {
|
||||
@@ -34,6 +35,13 @@ export interface RoutstrdConfig {
|
||||
provider: string | null;
|
||||
cocodPath: string | null;
|
||||
mode?: "xcashu" | "apikeys";
|
||||
/** Raw upstream request/response logging. Disabled by default because logs can contain sensitive prompts, outputs, and auth/payment headers. */
|
||||
requestResponseLogging?: {
|
||||
/** Enable raw request/response file logging. */
|
||||
enabled?: boolean;
|
||||
/** Root log directory. SDK writes requests/*.json and responses/*.jsonl below this directory. Defaults to ~/.routstrd/request-response-logs. */
|
||||
dir?: string;
|
||||
};
|
||||
daemonUrl?: string;
|
||||
/** URL of the auth proxy (routstrd-auth) for management endpoints (npubs, clients, usage).
|
||||
* Defaults to daemonUrl or localhost:{port} if not set. */
|
||||
|
||||
Reference in New Issue
Block a user