-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Expand file tree
/
Copy pathcreate_idea.ts
More file actions
114 lines (106 loc) · 2.76 KB
/
Copy pathcreate_idea.ts
File metadata and controls
114 lines (106 loc) · 2.76 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
import {
BUFFER_API_URL,
BUFFER_IDEA_SELECTION,
type BufferCreateIdeaParams,
type BufferIdeaResponse,
bufferHeaders,
IDEA_OUTPUT_PROPERTIES,
mapBufferIdea,
parseBufferGraphQLResponse,
} from '@/tools/buffer/types'
import type { ToolConfig } from '@/tools/types'
const CREATE_IDEA_MUTATION = `
mutation CreateIdea($input: CreateIdeaInput!) {
createIdea(input: $input) {
__typename
... on Idea {
${BUFFER_IDEA_SELECTION}
}
... on IdeaResponse {
idea {
${BUFFER_IDEA_SELECTION}
}
}
... on MutationError {
message
}
}
}
`
export const bufferCreateIdeaTool: ToolConfig<BufferCreateIdeaParams, BufferIdeaResponse> = {
id: 'buffer_create_idea',
name: 'Buffer Create Idea',
description: 'Save a content idea to a Buffer organization for later drafting and scheduling',
version: '1.0.0',
params: {
apiKey: {
type: 'string',
required: true,
visibility: 'user-only',
description: 'Buffer API key',
},
organizationId: {
type: 'string',
required: true,
visibility: 'user-or-llm',
description: 'Buffer organization ID (find it with the Get Account operation)',
},
text: {
type: 'string',
required: true,
visibility: 'user-or-llm',
description: 'Text content of the idea',
},
title: {
type: 'string',
required: false,
visibility: 'user-or-llm',
description: 'Optional title for the idea',
},
groupId: {
type: 'string',
required: false,
visibility: 'user-or-llm',
description: 'Optional idea group (board column) to place the idea in',
},
},
request: {
url: BUFFER_API_URL,
method: 'POST',
headers: (params) => bufferHeaders(params.apiKey),
body: (params) => {
const content: Record<string, unknown> = { text: params.text }
if (params.title) content.title = params.title
const input: Record<string, unknown> = {
organizationId: params.organizationId,
content,
}
if (params.groupId) input.group = { groupId: params.groupId }
return {
query: CREATE_IDEA_MUTATION,
variables: { input },
}
},
},
transformResponse: async (response: Response) => {
const data = await parseBufferGraphQLResponse(response)
const result = data.createIdea
const idea = result?.__typename === 'Idea' ? result : result?.idea
if (!idea?.id) {
throw new Error(result?.message || 'Failed to create idea')
}
return {
success: true,
output: {
idea: mapBufferIdea(idea),
},
}
},
outputs: {
idea: {
type: 'object',
description: 'The created idea',
properties: IDEA_OUTPUT_PROPERTIES,
},
},
}