mirror of
https://github.com/farcasclaudiu/openclaw.git
synced 2026-06-29 05:02:04 +03:00
refactor(config): share allow/deny channel policy schema
This commit is contained in:
@@ -0,0 +1,39 @@
|
|||||||
|
import { z } from "zod";
|
||||||
|
|
||||||
|
const AllowDenyActionSchema = z.union([z.literal("allow"), z.literal("deny")]);
|
||||||
|
|
||||||
|
const AllowDenyChatTypeSchema = z
|
||||||
|
.union([
|
||||||
|
z.literal("direct"),
|
||||||
|
z.literal("group"),
|
||||||
|
z.literal("channel"),
|
||||||
|
/** @deprecated Use `direct` instead. Kept for backward compatibility. */
|
||||||
|
z.literal("dm"),
|
||||||
|
])
|
||||||
|
.optional();
|
||||||
|
|
||||||
|
export function createAllowDenyChannelRulesSchema() {
|
||||||
|
return z
|
||||||
|
.object({
|
||||||
|
default: AllowDenyActionSchema.optional(),
|
||||||
|
rules: z
|
||||||
|
.array(
|
||||||
|
z
|
||||||
|
.object({
|
||||||
|
action: AllowDenyActionSchema,
|
||||||
|
match: z
|
||||||
|
.object({
|
||||||
|
channel: z.string().optional(),
|
||||||
|
chatType: AllowDenyChatTypeSchema,
|
||||||
|
keyPrefix: z.string().optional(),
|
||||||
|
})
|
||||||
|
.strict()
|
||||||
|
.optional(),
|
||||||
|
})
|
||||||
|
.strict(),
|
||||||
|
)
|
||||||
|
.optional(),
|
||||||
|
})
|
||||||
|
.strict()
|
||||||
|
.optional();
|
||||||
|
}
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
import { isSafeExecutableValue } from "../infra/exec-safety.js";
|
import { isSafeExecutableValue } from "../infra/exec-safety.js";
|
||||||
|
import { createAllowDenyChannelRulesSchema } from "./zod-schema.allowdeny.js";
|
||||||
import { sensitive } from "./zod-schema.sensitive.js";
|
import { sensitive } from "./zod-schema.sensitive.js";
|
||||||
|
|
||||||
export const ModelApiSchema = z.union([
|
export const ModelApiSchema = z.union([
|
||||||
@@ -376,37 +377,7 @@ export const ExecutableTokenSchema = z
|
|||||||
.string()
|
.string()
|
||||||
.refine(isSafeExecutableValue, "expected safe executable name or path");
|
.refine(isSafeExecutableValue, "expected safe executable name or path");
|
||||||
|
|
||||||
export const MediaUnderstandingScopeSchema = z
|
export const MediaUnderstandingScopeSchema = createAllowDenyChannelRulesSchema();
|
||||||
.object({
|
|
||||||
default: z.union([z.literal("allow"), z.literal("deny")]).optional(),
|
|
||||||
rules: z
|
|
||||||
.array(
|
|
||||||
z
|
|
||||||
.object({
|
|
||||||
action: z.union([z.literal("allow"), z.literal("deny")]),
|
|
||||||
match: z
|
|
||||||
.object({
|
|
||||||
channel: z.string().optional(),
|
|
||||||
chatType: z
|
|
||||||
.union([
|
|
||||||
z.literal("direct"),
|
|
||||||
z.literal("group"),
|
|
||||||
z.literal("channel"),
|
|
||||||
/** @deprecated Use `direct` instead. Kept for backward compatibility. */
|
|
||||||
z.literal("dm"),
|
|
||||||
])
|
|
||||||
.optional(),
|
|
||||||
keyPrefix: z.string().optional(),
|
|
||||||
})
|
|
||||||
.strict()
|
|
||||||
.optional(),
|
|
||||||
})
|
|
||||||
.strict(),
|
|
||||||
)
|
|
||||||
.optional(),
|
|
||||||
})
|
|
||||||
.strict()
|
|
||||||
.optional();
|
|
||||||
|
|
||||||
export const MediaUnderstandingCapabilitiesSchema = z
|
export const MediaUnderstandingCapabilitiesSchema = z
|
||||||
.array(z.union([z.literal("image"), z.literal("audio"), z.literal("video")]))
|
.array(z.union([z.literal("image"), z.literal("audio"), z.literal("video")]))
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import { z } from "zod";
|
|||||||
import { parseByteSize } from "../cli/parse-bytes.js";
|
import { parseByteSize } from "../cli/parse-bytes.js";
|
||||||
import { parseDurationMs } from "../cli/parse-duration.js";
|
import { parseDurationMs } from "../cli/parse-duration.js";
|
||||||
import { ElevatedAllowFromSchema } from "./zod-schema.agent-runtime.js";
|
import { ElevatedAllowFromSchema } from "./zod-schema.agent-runtime.js";
|
||||||
|
import { createAllowDenyChannelRulesSchema } from "./zod-schema.allowdeny.js";
|
||||||
import {
|
import {
|
||||||
GroupChatSchema,
|
GroupChatSchema,
|
||||||
InboundDebounceSchema,
|
InboundDebounceSchema,
|
||||||
@@ -18,36 +19,7 @@ const SessionResetConfigSchema = z
|
|||||||
})
|
})
|
||||||
.strict();
|
.strict();
|
||||||
|
|
||||||
export const SessionSendPolicySchema = z
|
export const SessionSendPolicySchema = createAllowDenyChannelRulesSchema();
|
||||||
.object({
|
|
||||||
default: z.union([z.literal("allow"), z.literal("deny")]).optional(),
|
|
||||||
rules: z
|
|
||||||
.array(
|
|
||||||
z
|
|
||||||
.object({
|
|
||||||
action: z.union([z.literal("allow"), z.literal("deny")]),
|
|
||||||
match: z
|
|
||||||
.object({
|
|
||||||
channel: z.string().optional(),
|
|
||||||
chatType: z
|
|
||||||
.union([
|
|
||||||
z.literal("direct"),
|
|
||||||
z.literal("group"),
|
|
||||||
z.literal("channel"),
|
|
||||||
/** @deprecated Use `direct` instead. Kept for backward compatibility. */
|
|
||||||
z.literal("dm"),
|
|
||||||
])
|
|
||||||
.optional(),
|
|
||||||
keyPrefix: z.string().optional(),
|
|
||||||
})
|
|
||||||
.strict()
|
|
||||||
.optional(),
|
|
||||||
})
|
|
||||||
.strict(),
|
|
||||||
)
|
|
||||||
.optional(),
|
|
||||||
})
|
|
||||||
.strict();
|
|
||||||
|
|
||||||
export const SessionSchema = z
|
export const SessionSchema = z
|
||||||
.object({
|
.object({
|
||||||
|
|||||||
Reference in New Issue
Block a user