Repository navigation
Expand file tree
/
Copy pathschema.ts
More file actions
126 lines (114 loc) · 5.46 KB
/
Copy pathschema.ts
File metadata and controls
126 lines (114 loc) · 5.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
import type { ConfigFieldMeta } from "@tokenring-ai/app/config/metadata";
import { fromEnv, secret, sourcedValue, type WithResolvedSecrets } from "@tokenring-ai/secrets/secret";
import { z } from "zod";
export const GoogleAccountGmailSchema = z.object({
description: z
.string()
.default("Gmail")
.meta({ description: "Display name for this account's Gmail integration" } satisfies ConfigFieldMeta),
});
export const GoogleAccountCalendarSchema = z.object({
description: z
.string()
.default("Google Calendar")
.meta({ description: "Display name for this account's calendar integration" } satisfies ConfigFieldMeta),
calendarId: z
.string()
.default("primary")
.meta({ description: 'Calendar ID to use ("primary" for the account\'s main calendar)' } satisfies ConfigFieldMeta),
});
export const GoogleAccountDriveSchema = z.object({
description: z
.string()
.default("Google Drive filesystem")
.meta({ description: "Display name for this account's Drive filesystem" } satisfies ConfigFieldMeta),
rootFolderId: z
.string()
.default("root")
.meta({ advanced: true, description: "Drive folder ID treated as the filesystem root" } satisfies ConfigFieldMeta),
});
export const GoogleAccountSchema = z.object({
email: z.email().meta({ description: "Google account email address" } satisfies ConfigFieldMeta),
gmail: GoogleAccountGmailSchema.exactOptional().meta({ label: "Gmail" } satisfies ConfigFieldMeta),
calendar: GoogleAccountCalendarSchema.exactOptional().meta({ label: "Calendar" } satisfies ConfigFieldMeta),
drive: GoogleAccountDriveSchema.exactOptional().meta({ label: "Drive" } satisfies ConfigFieldMeta),
});
export const GoogleStoredTokenSchema = z.object({
refreshToken: z
.string()
.exactOptional()
.meta({ sensitive: true, description: "OAuth refresh token (obtained via login)" } satisfies ConfigFieldMeta),
accessToken: z
.string()
.exactOptional()
.meta({ sensitive: true, description: "OAuth access token (obtained via login)" } satisfies ConfigFieldMeta),
expiryDate: z.number().exactOptional(),
grantedScopes: z.array(z.string()).exactOptional(),
profile: z
.object({
email: z.string().nullable().exactOptional(),
family_name: z.string().nullable().exactOptional(),
gender: z.string().nullable().exactOptional(),
given_name: z.string().nullable().exactOptional(),
hd: z.string().nullable().exactOptional(),
id: z.string().nullable().exactOptional(),
link: z.string().nullable().exactOptional(),
locale: z.string().nullable().exactOptional(),
name: z.string().nullable().exactOptional(),
picture: z.string().nullable().exactOptional(),
verified_email: z.boolean().nullable().exactOptional(),
})
.exactOptional(),
});
export const GoogleAgentOptionsSchema = z
.object({
account: z
.string()
.exactOptional()
.meta({ description: "Google account new agents use by default" } satisfies ConfigFieldMeta),
})
.default({});
export const GoogleConfigSchema = z
.object({
clientId: sourcedValue({ description: "Google OAuth client ID" } satisfies ConfigFieldMeta).default(fromEnv("GOOGLE_CLIENT_ID")),
clientSecret: secret({ description: "Google OAuth client secret" } satisfies ConfigFieldMeta).default(fromEnv("GOOGLE_CLIENT_SECRET")),
accounts: z
.record(z.string(), GoogleAccountSchema)
.default({})
.meta({ label: "Accounts", description: "Connected Google accounts, keyed by name" } satisfies ConfigFieldMeta),
agentDefaults: GoogleAgentOptionsSchema.default({}).meta({ label: "Agent Defaults" } satisfies ConfigFieldMeta),
})
.meta({ label: "Google", description: "Google OAuth, Gmail, Calendar, and Drive integration settings" } satisfies ConfigFieldMeta);
export const GmailEmailProviderOptionsSchema = z.object({
description: z.string(),
account: z.string(),
});
export const GoogleCalendarProviderOptionsSchema = z.object({
description: z.string(),
account: z.string(),
calendarId: z.string().default("primary"),
});
export const GoogleDriveFileSystemProviderOptionsSchema = z.object({
description: z.string().default("Google Drive filesystem"),
account: z.string(),
rootFolderId: z.string().default("root"),
});
export type GoogleConfig = z.input<typeof GoogleConfigSchema>;
export type ParsedGoogleConfig = z.output<typeof GoogleConfigSchema>;
/** Config as handed to the service, with OAuth client secrets already resolved. */
export type ResolvedGoogleConfig = Omit<WithResolvedSecrets<ParsedGoogleConfig, "clientId" | "clientSecret">, "clientId" | "clientSecret"> & {
clientId?: string | undefined;
clientSecret?: string | undefined;
};
export type GoogleAccount = z.input<typeof GoogleAccountSchema>;
export type GoogleStoredToken = z.input<typeof GoogleStoredTokenSchema>;
export type GmailEmailProviderOptions = z.input<typeof GmailEmailProviderOptionsSchema>;
export type GoogleCalendarProviderOptions = z.input<typeof GoogleCalendarProviderOptionsSchema>;
export type GoogleDriveFileSystemProviderOptions = z.input<typeof GoogleDriveFileSystemProviderOptionsSchema>;
export type GoogleAccountEmail = z.input<typeof GoogleAccountGmailSchema>;
export type GoogleAccountCalendar = z.input<typeof GoogleAccountCalendarSchema>;
export type GoogleAccountDrive = z.input<typeof GoogleAccountDriveSchema>;
export const GooglePackageConfigSchema = z.object({
google: GoogleConfigSchema.prefault({}),
});
export type GooglePackageConfig = z.input<typeof GooglePackageConfigSchema>;