mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 15:58:27 +00:00
refactor(protocol): dedupe cron/config schemas
This commit is contained in:
@@ -11,7 +11,7 @@ export const ConfigSetParamsSchema = Type.Object(
|
|||||||
{ additionalProperties: false },
|
{ additionalProperties: false },
|
||||||
);
|
);
|
||||||
|
|
||||||
export const ConfigApplyParamsSchema = Type.Object(
|
const ConfigApplyLikeParamsSchema = Type.Object(
|
||||||
{
|
{
|
||||||
raw: NonEmptyString,
|
raw: NonEmptyString,
|
||||||
baseHash: Type.Optional(NonEmptyString),
|
baseHash: Type.Optional(NonEmptyString),
|
||||||
@@ -22,16 +22,8 @@ export const ConfigApplyParamsSchema = Type.Object(
|
|||||||
{ additionalProperties: false },
|
{ additionalProperties: false },
|
||||||
);
|
);
|
||||||
|
|
||||||
export const ConfigPatchParamsSchema = Type.Object(
|
export const ConfigApplyParamsSchema = ConfigApplyLikeParamsSchema;
|
||||||
{
|
export const ConfigPatchParamsSchema = ConfigApplyLikeParamsSchema;
|
||||||
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 ConfigSchemaParamsSchema = Type.Object({}, { additionalProperties: false });
|
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";
|
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([
|
export const CronScheduleSchema = Type.Union([
|
||||||
Type.Object(
|
Type.Object(
|
||||||
{
|
{
|
||||||
@@ -35,21 +53,7 @@ export const CronPayloadSchema = Type.Union([
|
|||||||
},
|
},
|
||||||
{ additionalProperties: false },
|
{ additionalProperties: false },
|
||||||
),
|
),
|
||||||
Type.Object(
|
cronAgentTurnPayloadSchema({ message: NonEmptyString }),
|
||||||
{
|
|
||||||
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 },
|
|
||||||
),
|
|
||||||
]);
|
]);
|
||||||
|
|
||||||
export const CronPayloadPatchSchema = Type.Union([
|
export const CronPayloadPatchSchema = Type.Union([
|
||||||
@@ -60,29 +64,19 @@ export const CronPayloadPatchSchema = Type.Union([
|
|||||||
},
|
},
|
||||||
{ additionalProperties: false },
|
{ additionalProperties: false },
|
||||||
),
|
),
|
||||||
Type.Object(
|
cronAgentTurnPayloadSchema({ message: Type.Optional(NonEmptyString) }),
|
||||||
{
|
|
||||||
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 },
|
|
||||||
),
|
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
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(
|
export const CronDeliverySchema = Type.Object(
|
||||||
{
|
{
|
||||||
mode: Type.Union([Type.Literal("none"), Type.Literal("announce")]),
|
mode: Type.Union([Type.Literal("none"), Type.Literal("announce")]),
|
||||||
channel: Type.Optional(Type.Union([Type.Literal("last"), NonEmptyString])),
|
...CronDeliveryBaseProperties,
|
||||||
to: Type.Optional(Type.String()),
|
|
||||||
bestEffort: Type.Optional(Type.Boolean()),
|
|
||||||
},
|
},
|
||||||
{ additionalProperties: false },
|
{ additionalProperties: false },
|
||||||
);
|
);
|
||||||
@@ -90,9 +84,7 @@ export const CronDeliverySchema = Type.Object(
|
|||||||
export const CronDeliveryPatchSchema = Type.Object(
|
export const CronDeliveryPatchSchema = Type.Object(
|
||||||
{
|
{
|
||||||
mode: Type.Optional(Type.Union([Type.Literal("none"), Type.Literal("announce")])),
|
mode: Type.Optional(Type.Union([Type.Literal("none"), Type.Literal("announce")])),
|
||||||
channel: Type.Optional(Type.Union([Type.Literal("last"), NonEmptyString])),
|
...CronDeliveryBaseProperties,
|
||||||
to: Type.Optional(Type.String()),
|
|
||||||
bestEffort: Type.Optional(Type.Boolean()),
|
|
||||||
},
|
},
|
||||||
{ additionalProperties: false },
|
{ additionalProperties: false },
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user