mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-19 08:48:37 +00: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 },
|
{ additionalProperties: false },
|
||||||
);
|
);
|
||||||
|
|
||||||
export const WizardCancelParamsSchema = Type.Object(
|
const WizardSessionIdParamsSchema = Type.Object(
|
||||||
{
|
{
|
||||||
sessionId: NonEmptyString,
|
sessionId: NonEmptyString,
|
||||||
},
|
},
|
||||||
{ additionalProperties: false },
|
{ additionalProperties: false },
|
||||||
);
|
);
|
||||||
|
|
||||||
export const WizardStatusParamsSchema = Type.Object(
|
export const WizardCancelParamsSchema = WizardSessionIdParamsSchema;
|
||||||
{
|
|
||||||
sessionId: NonEmptyString,
|
export const WizardStatusParamsSchema = WizardSessionIdParamsSchema;
|
||||||
},
|
|
||||||
{ additionalProperties: false },
|
|
||||||
);
|
|
||||||
|
|
||||||
export const WizardStepOptionSchema = Type.Object(
|
export const WizardStepOptionSchema = Type.Object(
|
||||||
{
|
{
|
||||||
@@ -78,35 +75,28 @@ export const WizardStepSchema = Type.Object(
|
|||||||
{ additionalProperties: false },
|
{ additionalProperties: false },
|
||||||
);
|
);
|
||||||
|
|
||||||
export const WizardNextResultSchema = Type.Object(
|
const WizardResultFields = {
|
||||||
{
|
done: Type.Boolean(),
|
||||||
done: Type.Boolean(),
|
step: Type.Optional(WizardStepSchema),
|
||||||
step: Type.Optional(WizardStepSchema),
|
status: Type.Optional(WizardRunStatusSchema),
|
||||||
status: Type.Optional(WizardRunStatusSchema),
|
error: Type.Optional(Type.String()),
|
||||||
error: Type.Optional(Type.String()),
|
};
|
||||||
},
|
|
||||||
{ additionalProperties: false },
|
export const WizardNextResultSchema = Type.Object(WizardResultFields, {
|
||||||
);
|
additionalProperties: false,
|
||||||
|
});
|
||||||
|
|
||||||
export const WizardStartResultSchema = Type.Object(
|
export const WizardStartResultSchema = Type.Object(
|
||||||
{
|
{
|
||||||
sessionId: NonEmptyString,
|
sessionId: NonEmptyString,
|
||||||
done: Type.Boolean(),
|
...WizardResultFields,
|
||||||
step: Type.Optional(WizardStepSchema),
|
|
||||||
status: Type.Optional(WizardRunStatusSchema),
|
|
||||||
error: Type.Optional(Type.String()),
|
|
||||||
},
|
},
|
||||||
{ additionalProperties: false },
|
{ additionalProperties: false },
|
||||||
);
|
);
|
||||||
|
|
||||||
export const WizardStatusResultSchema = Type.Object(
|
export const WizardStatusResultSchema = Type.Object(
|
||||||
{
|
{
|
||||||
status: Type.Union([
|
status: WizardRunStatusSchema,
|
||||||
Type.Literal("running"),
|
|
||||||
Type.Literal("done"),
|
|
||||||
Type.Literal("cancelled"),
|
|
||||||
Type.Literal("error"),
|
|
||||||
]),
|
|
||||||
error: Type.Optional(Type.String()),
|
error: Type.Optional(Type.String()),
|
||||||
},
|
},
|
||||||
{ additionalProperties: false },
|
{ additionalProperties: false },
|
||||||
|
|||||||
@@ -18,26 +18,7 @@ function shouldEmitRuntimeLog(env: NodeJS.ProcessEnv = process.env): boolean {
|
|||||||
return typeof maybeMockedLog.mock === "object";
|
return typeof maybeMockedLog.mock === "object";
|
||||||
}
|
}
|
||||||
|
|
||||||
export const defaultRuntime: RuntimeEnv = {
|
function createRuntimeIo(): Pick<RuntimeEnv, "log" | "error"> {
|
||||||
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 {
|
|
||||||
return {
|
return {
|
||||||
log: (...args: Parameters<typeof console.log>) => {
|
log: (...args: Parameters<typeof console.log>) => {
|
||||||
if (!shouldEmitRuntimeLog()) {
|
if (!shouldEmitRuntimeLog()) {
|
||||||
@@ -50,6 +31,21 @@ export function createNonExitingRuntime(): RuntimeEnv {
|
|||||||
clearActiveProgressLine();
|
clearActiveProgressLine();
|
||||||
console.error(...args);
|
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 => {
|
exit: (code: number): never => {
|
||||||
throw new Error(`exit ${code}`);
|
throw new Error(`exit ${code}`);
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user