-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Expand file tree
/
Copy pathedit_draft.ts
More file actions
162 lines (152 loc) · 4.03 KB
/
Copy pathedit_draft.ts
File metadata and controls
162 lines (152 loc) · 4.03 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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
import type { ToolConfig } from '@/tools/types'
interface GmailEditDraftParams {
accessToken: string
draftId: string
to: string
subject?: string
body: string
contentType?: string
threadId?: string
replyToMessageId?: string
cc?: string
bcc?: string
attachments?: unknown
}
interface GmailEditDraftResponse {
success: boolean
output: {
draftId?: string
messageId?: string
threadId?: string
labelIds?: string[]
}
}
export const gmailEditDraftV2Tool: ToolConfig<GmailEditDraftParams, GmailEditDraftResponse> = {
id: 'gmail_edit_draft_v2',
name: 'Gmail Edit Draft',
description: 'Update an existing Gmail draft in place without deleting and recreating it.',
version: '2.0.0',
oauth: {
required: true,
provider: 'google-email',
},
params: {
accessToken: {
type: 'string',
required: true,
visibility: 'hidden',
description: 'Access token for Gmail API',
},
draftId: {
type: 'string',
required: true,
visibility: 'user-or-llm',
description: 'ID of the draft to update (from Gmail List Drafts or Gmail Get Draft)',
},
to: {
type: 'string',
required: true,
visibility: 'user-or-llm',
description: 'Recipient email address',
},
subject: {
type: 'string',
required: false,
visibility: 'user-or-llm',
description: 'Email subject',
},
body: {
type: 'string',
required: true,
visibility: 'user-or-llm',
description: 'Email body content',
},
contentType: {
type: 'string',
required: false,
visibility: 'user-or-llm',
description: 'Content type for the email body (text or html)',
},
threadId: {
type: 'string',
required: false,
visibility: 'user-or-llm',
description: 'Thread ID to associate the draft with (for threading)',
},
replyToMessageId: {
type: 'string',
required: false,
visibility: 'user-or-llm',
description:
'Gmail message ID to reply to - use the "id" field from Gmail Read results (not the RFC "messageId")',
},
cc: {
type: 'string',
required: false,
visibility: 'user-or-llm',
description: 'CC recipients (comma-separated)',
},
bcc: {
type: 'string',
required: false,
visibility: 'user-or-llm',
description: 'BCC recipients (comma-separated)',
},
attachments: {
type: 'file[]',
required: false,
visibility: 'user-only',
description: 'Files to attach to the email draft',
},
},
request: {
url: '/api/tools/gmail/edit-draft',
method: 'POST',
headers: () => ({
'Content-Type': 'application/json',
}),
body: (params: GmailEditDraftParams) => ({
accessToken: params.accessToken,
draftId: params.draftId?.trim(),
to: params.to,
subject: params.subject,
body: params.body,
contentType: params.contentType || 'text',
threadId: params.threadId,
replyToMessageId: params.replyToMessageId,
cc: params.cc,
bcc: params.bcc,
attachments: params.attachments,
}),
},
transformResponse: async (response: Response) => {
const data = await response.json()
if (!response.ok || !data.success) {
return {
success: false,
output: {},
error: data.error || 'Failed to update draft',
}
}
return {
success: true,
output: {
draftId: data.output?.draftId ?? null,
messageId: data.output?.messageId ?? null,
threadId: data.output?.threadId ?? null,
labelIds: data.output?.labelIds ?? null,
},
}
},
outputs: {
draftId: { type: 'string', description: 'Draft ID', optional: true },
messageId: { type: 'string', description: 'Gmail message ID for the draft', optional: true },
threadId: { type: 'string', description: 'Gmail thread ID', optional: true },
labelIds: {
type: 'array',
items: { type: 'string' },
description: 'Email labels',
optional: true,
},
},
}