mirror of
https://github.com/openclaw/openclaw.git
synced 2026-02-19 18:39:20 -05:00
refactor(core): extract shared runtime and wizard schemas
This commit is contained in:
@@ -32,19 +32,16 @@ export const WizardNextParamsSchema = Type.Object(
|
||||
{ additionalProperties: false },
|
||||
);
|
||||
|
||||
export const WizardCancelParamsSchema = Type.Object(
|
||||
const WizardSessionIdParamsSchema = Type.Object(
|
||||
{
|
||||
sessionId: NonEmptyString,
|
||||
},
|
||||
{ additionalProperties: false },
|
||||
);
|
||||
|
||||
export const WizardStatusParamsSchema = Type.Object(
|
||||
{
|
||||
sessionId: NonEmptyString,
|
||||
},
|
||||
{ additionalProperties: false },
|
||||
);
|
||||
export const WizardCancelParamsSchema = WizardSessionIdParamsSchema;
|
||||
|
||||
export const WizardStatusParamsSchema = WizardSessionIdParamsSchema;
|
||||
|
||||
export const WizardStepOptionSchema = Type.Object(
|
||||
{
|
||||
@@ -78,35 +75,28 @@ export const WizardStepSchema = Type.Object(
|
||||
{ additionalProperties: false },
|
||||
);
|
||||
|
||||
export const WizardNextResultSchema = Type.Object(
|
||||
{
|
||||
done: Type.Boolean(),
|
||||
step: Type.Optional(WizardStepSchema),
|
||||
status: Type.Optional(WizardRunStatusSchema),
|
||||
error: Type.Optional(Type.String()),
|
||||
},
|
||||
{ additionalProperties: false },
|
||||
);
|
||||
const WizardResultFields = {
|
||||
done: Type.Boolean(),
|
||||
step: Type.Optional(WizardStepSchema),
|
||||
status: Type.Optional(WizardRunStatusSchema),
|
||||
error: Type.Optional(Type.String()),
|
||||
};
|
||||
|
||||
export const WizardNextResultSchema = Type.Object(WizardResultFields, {
|
||||
additionalProperties: false,
|
||||
});
|
||||
|
||||
export const WizardStartResultSchema = Type.Object(
|
||||
{
|
||||
sessionId: NonEmptyString,
|
||||
done: Type.Boolean(),
|
||||
step: Type.Optional(WizardStepSchema),
|
||||
status: Type.Optional(WizardRunStatusSchema),
|
||||
error: Type.Optional(Type.String()),
|
||||
...WizardResultFields,
|
||||
},
|
||||
{ additionalProperties: false },
|
||||
);
|
||||
|
||||
export const WizardStatusResultSchema = Type.Object(
|
||||
{
|
||||
status: Type.Union([
|
||||
Type.Literal("running"),
|
||||
Type.Literal("done"),
|
||||
Type.Literal("cancelled"),
|
||||
Type.Literal("error"),
|
||||
]),
|
||||
status: WizardRunStatusSchema,
|
||||
error: Type.Optional(Type.String()),
|
||||
},
|
||||
{ additionalProperties: false },
|
||||
|
||||
@@ -18,26 +18,7 @@ function shouldEmitRuntimeLog(env: NodeJS.ProcessEnv = process.env): boolean {
|
||||
return typeof maybeMockedLog.mock === "object";
|
||||
}
|
||||
|
||||
export const defaultRuntime: RuntimeEnv = {
|
||||
log: (...args: Parameters<typeof console.log>) => {
|
||||
if (!shouldEmitRuntimeLog()) {
|
||||
return;
|
||||
}
|
||||
clearActiveProgressLine();
|
||||
console.log(...args);
|
||||
},
|
||||
error: (...args: Parameters<typeof console.error>) => {
|
||||
clearActiveProgressLine();
|
||||
console.error(...args);
|
||||
},
|
||||
exit: (code) => {
|
||||
restoreTerminalState("runtime exit", { resumeStdinIfPaused: false });
|
||||
process.exit(code);
|
||||
throw new Error("unreachable"); // satisfies tests when mocked
|
||||
},
|
||||
};
|
||||
|
||||
export function createNonExitingRuntime(): RuntimeEnv {
|
||||
function createRuntimeIo(): Pick<RuntimeEnv, "log" | "error"> {
|
||||
return {
|
||||
log: (...args: Parameters<typeof console.log>) => {
|
||||
if (!shouldEmitRuntimeLog()) {
|
||||
@@ -50,6 +31,21 @@ export function createNonExitingRuntime(): RuntimeEnv {
|
||||
clearActiveProgressLine();
|
||||
console.error(...args);
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
export const defaultRuntime: RuntimeEnv = {
|
||||
...createRuntimeIo(),
|
||||
exit: (code) => {
|
||||
restoreTerminalState("runtime exit", { resumeStdinIfPaused: false });
|
||||
process.exit(code);
|
||||
throw new Error("unreachable"); // satisfies tests when mocked
|
||||
},
|
||||
};
|
||||
|
||||
export function createNonExitingRuntime(): RuntimeEnv {
|
||||
return {
|
||||
...createRuntimeIo(),
|
||||
exit: (code: number): never => {
|
||||
throw new Error(`exit ${code}`);
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user