mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-12 15:30:39 +00:00
refactor(protocol): dedupe cron/config schemas
This commit is contained in:
@@ -11,7 +11,7 @@ export const ConfigSetParamsSchema = Type.Object(
|
||||
{ additionalProperties: false },
|
||||
);
|
||||
|
||||
export const ConfigApplyParamsSchema = Type.Object(
|
||||
const ConfigApplyLikeParamsSchema = Type.Object(
|
||||
{
|
||||
raw: NonEmptyString,
|
||||
baseHash: Type.Optional(NonEmptyString),
|
||||
@@ -22,16 +22,8 @@ export const ConfigApplyParamsSchema = Type.Object(
|
||||
{ additionalProperties: false },
|
||||
);
|
||||
|
||||
export const ConfigPatchParamsSchema = Type.Object(
|
||||
{
|
||||
raw: NonEmptyString,
|
||||
baseHash: Type.Optional(NonEmptyString),
|
||||
sessionKey: Type.Optional(Type.String()),
|
||||
note: Type.Optional(Type.String()),
|
||||
restartDelayMs: Type.Optional(Type.Integer({ minimum: 0 })),
|
||||
},
|
||||
{ additionalProperties: false },
|
||||
);
|
||||
export const ConfigApplyParamsSchema = ConfigApplyLikeParamsSchema;
|
||||
export const ConfigPatchParamsSchema = ConfigApplyLikeParamsSchema;
|
||||
|
||||
export const ConfigSchemaParamsSchema = Type.Object({}, { additionalProperties: false });
|
||||
|
||||
|
||||
@@ -1,6 +1,24 @@
|
||||
import { Type } from "@sinclair/typebox";
|
||||
import { Type, type TSchema } from "@sinclair/typebox";
|
||||
import { NonEmptyString } from "./primitives.js";
|
||||
|
||||
function cronAgentTurnPayloadSchema(params: { message: TSchema }) {
|
||||
return Type.Object(
|
||||
{
|
||||
kind: Type.Literal("agentTurn"),
|
||||
message: params.message,
|
||||
model: Type.Optional(Type.String()),
|
||||
thinking: Type.Optional(Type.String()),
|
||||
timeoutSeconds: Type.Optional(Type.Integer({ minimum: 1 })),
|
||||
allowUnsafeExternalContent: Type.Optional(Type.Boolean()),
|
||||
deliver: Type.Optional(Type.Boolean()),
|
||||
channel: Type.Optional(Type.String()),
|
||||
to: Type.Optional(Type.String()),
|
||||
bestEffortDeliver: Type.Optional(Type.Boolean()),
|
||||
},
|
||||
{ additionalProperties: false },
|
||||
);
|
||||
}
|
||||
|
||||
export const CronScheduleSchema = Type.Union([
|
||||
Type.Object(
|
||||
{
|
||||
@@ -35,21 +53,7 @@ export const CronPayloadSchema = Type.Union([
|
||||
},
|
||||
{ additionalProperties: false },
|
||||
),
|
||||
Type.Object(
|
||||
{
|
||||
kind: Type.Literal("agentTurn"),
|
||||
message: NonEmptyString,
|
||||
model: Type.Optional(Type.String()),
|
||||
thinking: Type.Optional(Type.String()),
|
||||
timeoutSeconds: Type.Optional(Type.Integer({ minimum: 1 })),
|
||||
allowUnsafeExternalContent: Type.Optional(Type.Boolean()),
|
||||
deliver: Type.Optional(Type.Boolean()),
|
||||
channel: Type.Optional(Type.String()),
|
||||
to: Type.Optional(Type.String()),
|
||||
bestEffortDeliver: Type.Optional(Type.Boolean()),
|
||||
},
|
||||
{ additionalProperties: false },
|
||||
),
|
||||
cronAgentTurnPayloadSchema({ message: NonEmptyString }),
|
||||
]);
|
||||
|
||||
export const CronPayloadPatchSchema = Type.Union([
|
||||
@@ -60,29 +64,19 @@ export const CronPayloadPatchSchema = Type.Union([
|
||||
},
|
||||
{ additionalProperties: false },
|
||||
),
|
||||
Type.Object(
|
||||
{
|
||||
kind: Type.Literal("agentTurn"),
|
||||
message: Type.Optional(NonEmptyString),
|
||||
model: Type.Optional(Type.String()),
|
||||
thinking: Type.Optional(Type.String()),
|
||||
timeoutSeconds: Type.Optional(Type.Integer({ minimum: 1 })),
|
||||
allowUnsafeExternalContent: Type.Optional(Type.Boolean()),
|
||||
deliver: Type.Optional(Type.Boolean()),
|
||||
channel: Type.Optional(Type.String()),
|
||||
to: Type.Optional(Type.String()),
|
||||
bestEffortDeliver: Type.Optional(Type.Boolean()),
|
||||
},
|
||||
{ additionalProperties: false },
|
||||
),
|
||||
cronAgentTurnPayloadSchema({ message: Type.Optional(NonEmptyString) }),
|
||||
]);
|
||||
|
||||
const CronDeliveryBaseProperties = {
|
||||
channel: Type.Optional(Type.Union([Type.Literal("last"), NonEmptyString])),
|
||||
to: Type.Optional(Type.String()),
|
||||
bestEffort: Type.Optional(Type.Boolean()),
|
||||
};
|
||||
|
||||
export const CronDeliverySchema = Type.Object(
|
||||
{
|
||||
mode: Type.Union([Type.Literal("none"), Type.Literal("announce")]),
|
||||
channel: Type.Optional(Type.Union([Type.Literal("last"), NonEmptyString])),
|
||||
to: Type.Optional(Type.String()),
|
||||
bestEffort: Type.Optional(Type.Boolean()),
|
||||
...CronDeliveryBaseProperties,
|
||||
},
|
||||
{ additionalProperties: false },
|
||||
);
|
||||
@@ -90,9 +84,7 @@ export const CronDeliverySchema = Type.Object(
|
||||
export const CronDeliveryPatchSchema = Type.Object(
|
||||
{
|
||||
mode: Type.Optional(Type.Union([Type.Literal("none"), Type.Literal("announce")])),
|
||||
channel: Type.Optional(Type.Union([Type.Literal("last"), NonEmptyString])),
|
||||
to: Type.Optional(Type.String()),
|
||||
bestEffort: Type.Optional(Type.Boolean()),
|
||||
...CronDeliveryBaseProperties,
|
||||
},
|
||||
{ additionalProperties: false },
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user