mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-03 03:10:23 +00:00
refactor: de-duplicate channel runtime and payload helpers
This commit is contained in:
24
src/plugin-sdk/runtime.ts
Normal file
24
src/plugin-sdk/runtime.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import { format } from "node:util";
|
||||
import type { RuntimeEnv } from "../runtime.js";
|
||||
|
||||
type LoggerLike = {
|
||||
info: (message: string) => void;
|
||||
error: (message: string) => void;
|
||||
};
|
||||
|
||||
export function createLoggerBackedRuntime(params: {
|
||||
logger: LoggerLike;
|
||||
exitError?: (code: number) => Error;
|
||||
}): RuntimeEnv {
|
||||
return {
|
||||
log: (...args) => {
|
||||
params.logger.info(format(...args));
|
||||
},
|
||||
error: (...args) => {
|
||||
params.logger.error(format(...args));
|
||||
},
|
||||
exit: (code: number): never => {
|
||||
throw params.exitError?.(code) ?? new Error(`exit ${code}`);
|
||||
},
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user