Skip to content

Commit fe34141

Browse files
tanshanshanaltaywtf
andauthored
refactor(config): extract GoogleChat schema into zod-schema.providers-googlechat.ts (#82100)
Merged via squash. Prepared head SHA: 7555272 Co-authored-by: tanshanshan <22539261+tanshanshan@users.noreply.github.com> Co-authored-by: altaywtf <9790196+altaywtf@users.noreply.github.com> Reviewed-by: @altaywtf
1 parent 6cc8244 commit fe34141

4 files changed

Lines changed: 106 additions & 93 deletions

File tree

src/config/zod-schema.providers-core.ts

Lines changed: 0 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import {
2525
MarkdownConfigSchema,
2626
MSTeamsReplyStyleSchema,
2727
ProviderCommandsSchema,
28-
SecretRefSchema,
2928
SecretInputSchema,
3029
ReplyToModeSchema,
3130
RetryConfigSchema,
@@ -891,95 +890,6 @@ export const DiscordConfigSchema = DiscordAccountSchema.extend({
891890
}
892891
});
893892

894-
export const GoogleChatDmSchema = z
895-
.object({
896-
enabled: z.boolean().optional(),
897-
policy: DmPolicySchema.optional().default("pairing"),
898-
allowFrom: z.array(z.union([z.string(), z.number()])).optional(),
899-
})
900-
.strict()
901-
.superRefine((value, ctx) => {
902-
requireOpenAllowFrom({
903-
policy: value.policy,
904-
allowFrom: value.allowFrom,
905-
ctx,
906-
path: ["allowFrom"],
907-
message:
908-
'channels.googlechat.dm.policy="open" requires channels.googlechat.dm.allowFrom to include "*"',
909-
});
910-
requireAllowlistAllowFrom({
911-
policy: value.policy,
912-
allowFrom: value.allowFrom,
913-
ctx,
914-
path: ["allowFrom"],
915-
message:
916-
'channels.googlechat.dm.policy="allowlist" requires channels.googlechat.dm.allowFrom to contain at least one sender ID',
917-
});
918-
});
919-
920-
export const GoogleChatGroupSchema = z
921-
.object({
922-
enabled: z.boolean().optional(),
923-
requireMention: z.boolean().optional(),
924-
botLoopProtection: BotLoopProtectionSchema.optional(),
925-
users: z.array(z.union([z.string(), z.number()])).optional(),
926-
systemPrompt: z.string().optional(),
927-
})
928-
.strict();
929-
930-
export const GoogleChatAccountSchema = z
931-
.object({
932-
name: z.string().optional(),
933-
capabilities: z.array(z.string()).optional(),
934-
enabled: z.boolean().optional(),
935-
configWrites: z.boolean().optional(),
936-
allowBots: z.boolean().optional(),
937-
botLoopProtection: BotLoopProtectionSchema.optional(),
938-
dangerouslyAllowNameMatching: z.boolean().optional(),
939-
requireMention: z.boolean().optional(),
940-
groupPolicy: GroupPolicySchema.optional().default("allowlist"),
941-
groupAllowFrom: z.array(z.union([z.string(), z.number()])).optional(),
942-
groups: z.record(z.string(), GoogleChatGroupSchema.optional()).optional(),
943-
defaultTo: z.string().optional(),
944-
serviceAccount: z
945-
.union([z.string(), z.record(z.string(), z.unknown()), SecretRefSchema])
946-
.optional()
947-
.register(sensitive),
948-
serviceAccountRef: SecretRefSchema.optional().register(sensitive),
949-
serviceAccountFile: z.string().optional(),
950-
audienceType: z.enum(["app-url", "project-number"]).optional(),
951-
audience: z.string().optional(),
952-
appPrincipal: z.string().optional(),
953-
webhookPath: z.string().optional(),
954-
webhookUrl: z.string().optional(),
955-
botUser: z.string().optional(),
956-
historyLimit: z.number().int().min(0).optional(),
957-
dmHistoryLimit: z.number().int().min(0).optional(),
958-
dms: z.record(z.string(), DmConfigSchema.optional()).optional(),
959-
textChunkLimit: z.number().int().positive().optional(),
960-
chunkMode: z.enum(["length", "newline"]).optional(),
961-
blockStreaming: z.boolean().optional(),
962-
blockStreamingCoalesce: BlockStreamingCoalesceSchema.optional(),
963-
mediaMaxMb: z.number().positive().optional(),
964-
replyToMode: ReplyToModeSchema.optional(),
965-
actions: z
966-
.object({
967-
reactions: z.boolean().optional(),
968-
})
969-
.strict()
970-
.optional(),
971-
dm: GoogleChatDmSchema.optional(),
972-
healthMonitor: ChannelHealthMonitorSchema,
973-
typingIndicator: z.enum(["none", "message", "reaction"]).optional(),
974-
responsePrefix: z.string().optional(),
975-
})
976-
.strict();
977-
978-
export const GoogleChatConfigSchema = GoogleChatAccountSchema.extend({
979-
accounts: z.record(z.string(), GoogleChatAccountSchema.optional()).optional(),
980-
defaultAccount: z.string().optional(),
981-
});
982-
983893
export const SlackDmSchema = z
984894
.object({
985895
enabled: z.boolean().optional(),
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
import { z } from "zod";
2+
import { ChannelBotLoopProtectionSchema } from "./zod-schema.channels-config.js";
3+
import { ChannelHealthMonitorSchema } from "./zod-schema.channels.js";
4+
import {
5+
BlockStreamingCoalesceSchema,
6+
DmConfigSchema,
7+
DmPolicySchema,
8+
GroupPolicySchema,
9+
ReplyToModeSchema,
10+
SecretRefSchema,
11+
requireAllowlistAllowFrom,
12+
requireOpenAllowFrom,
13+
} from "./zod-schema.core.js";
14+
import { sensitive } from "./zod-schema.sensitive.js";
15+
16+
export const GoogleChatDmSchema = z
17+
.object({
18+
enabled: z.boolean().optional(),
19+
policy: DmPolicySchema.optional().default("pairing"),
20+
allowFrom: z.array(z.union([z.string(), z.number()])).optional(),
21+
})
22+
.strict()
23+
.superRefine((value, ctx) => {
24+
requireOpenAllowFrom({
25+
policy: value.policy,
26+
allowFrom: value.allowFrom,
27+
ctx,
28+
path: ["allowFrom"],
29+
message:
30+
'channels.googlechat.dm.policy="open" requires channels.googlechat.dm.allowFrom to include "*"',
31+
});
32+
requireAllowlistAllowFrom({
33+
policy: value.policy,
34+
allowFrom: value.allowFrom,
35+
ctx,
36+
path: ["allowFrom"],
37+
message:
38+
'channels.googlechat.dm.policy="allowlist" requires channels.googlechat.dm.allowFrom to contain at least one sender ID',
39+
});
40+
});
41+
42+
export const GoogleChatGroupSchema = z
43+
.object({
44+
enabled: z.boolean().optional(),
45+
requireMention: z.boolean().optional(),
46+
botLoopProtection: ChannelBotLoopProtectionSchema.optional(),
47+
users: z.array(z.union([z.string(), z.number()])).optional(),
48+
systemPrompt: z.string().optional(),
49+
})
50+
.strict();
51+
52+
export const GoogleChatAccountSchema = z
53+
.object({
54+
name: z.string().optional(),
55+
capabilities: z.array(z.string()).optional(),
56+
enabled: z.boolean().optional(),
57+
configWrites: z.boolean().optional(),
58+
allowBots: z.boolean().optional(),
59+
botLoopProtection: ChannelBotLoopProtectionSchema.optional(),
60+
dangerouslyAllowNameMatching: z.boolean().optional(),
61+
requireMention: z.boolean().optional(),
62+
groupPolicy: GroupPolicySchema.optional().default("allowlist"),
63+
groupAllowFrom: z.array(z.union([z.string(), z.number()])).optional(),
64+
groups: z.record(z.string(), GoogleChatGroupSchema.optional()).optional(),
65+
defaultTo: z.string().optional(),
66+
serviceAccount: z
67+
.union([z.string(), z.record(z.string(), z.unknown()), SecretRefSchema])
68+
.optional()
69+
.register(sensitive),
70+
serviceAccountRef: SecretRefSchema.optional().register(sensitive),
71+
serviceAccountFile: z.string().optional(),
72+
audienceType: z.enum(["app-url", "project-number"]).optional(),
73+
audience: z.string().optional(),
74+
appPrincipal: z.string().optional(),
75+
webhookPath: z.string().optional(),
76+
webhookUrl: z.string().optional(),
77+
botUser: z.string().optional(),
78+
historyLimit: z.number().int().min(0).optional(),
79+
dmHistoryLimit: z.number().int().min(0).optional(),
80+
dms: z.record(z.string(), DmConfigSchema.optional()).optional(),
81+
textChunkLimit: z.number().int().positive().optional(),
82+
chunkMode: z.enum(["length", "newline"]).optional(),
83+
blockStreaming: z.boolean().optional(),
84+
blockStreamingCoalesce: BlockStreamingCoalesceSchema.optional(),
85+
mediaMaxMb: z.number().positive().optional(),
86+
replyToMode: ReplyToModeSchema.optional(),
87+
actions: z
88+
.object({
89+
reactions: z.boolean().optional(),
90+
})
91+
.strict()
92+
.optional(),
93+
dm: GoogleChatDmSchema.optional(),
94+
healthMonitor: ChannelHealthMonitorSchema,
95+
typingIndicator: z.enum(["none", "message", "reaction"]).optional(),
96+
responsePrefix: z.string().optional(),
97+
})
98+
.strict();
99+
100+
export const GoogleChatConfigSchema = GoogleChatAccountSchema.extend({
101+
accounts: z.record(z.string(), GoogleChatAccountSchema.optional()).optional(),
102+
defaultAccount: z.string().optional(),
103+
});

src/plugin-sdk/bundled-channel-config-schema.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ export {
2525
export { ToolPolicySchema } from "../config/zod-schema.agent-runtime.js";
2626
export {
2727
DiscordConfigSchema,
28-
GoogleChatConfigSchema,
2928
IMessageConfigSchema,
3029
MSTeamsConfigSchema,
3130
SignalConfigSchema,
3231
SlackConfigSchema,
3332
TelegramConfigSchema,
3433
} from "../config/zod-schema.providers-core.js";
34+
export { GoogleChatConfigSchema } from "../config/zod-schema.providers-googlechat.js";
3535
export { WhatsAppConfigSchema } from "../config/zod-schema.providers-whatsapp.js";

src/plugins/contracts/config-footprint-guardrails.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,12 +179,12 @@ describe("config footprint guardrails", () => {
179179
);
180180
const bundledSchemaExportBlocks = Array.from(
181181
bundledSection.matchAll(
182-
/export \{(?<exports>[^}]*)\} from "\.\.\/config\/zod-schema\.providers-(?:core|whatsapp)\.js";/g,
182+
/export \{(?<exports>[^}]*)\} from "\.\.\/config\/zod-schema\.providers-(?:core|googlechat|whatsapp)\.js";/g,
183183
),
184184
)
185185
.map((match) => match.groups?.exports)
186186
.filter((block): block is string => Boolean(block));
187-
expect(bundledSchemaExportBlocks).toHaveLength(2);
187+
expect(bundledSchemaExportBlocks).toHaveLength(3);
188188
const exportedSchemaNames = Array.from(
189189
bundledSchemaExportBlocks.join("\n").matchAll(/\b([A-Z][A-Za-z0-9]+ConfigSchema)\b/g),
190190
)

0 commit comments

Comments
 (0)