-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Expand file tree
/
Copy pathbatch_operations.ts
More file actions
86 lines (81 loc) · 2.42 KB
/
Copy pathbatch_operations.ts
File metadata and controls
86 lines (81 loc) · 2.42 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
import type {
AlgoliaBatchOperationsParams,
AlgoliaBatchOperationsResponse,
} from '@/tools/algolia/types'
import type { ToolConfig } from '@/tools/types'
export const batchOperationsTool: ToolConfig<
AlgoliaBatchOperationsParams,
AlgoliaBatchOperationsResponse
> = {
id: 'algolia_batch_operations',
name: 'Algolia Batch Operations',
description:
'Perform batch add, update, partial update, or delete operations on records in an Algolia index',
version: '1.0',
params: {
applicationId: {
type: 'string',
required: true,
visibility: 'user-only',
description: 'Algolia Application ID',
},
apiKey: {
type: 'string',
required: true,
visibility: 'user-only',
description: 'Algolia Admin API Key',
},
indexName: {
type: 'string',
required: true,
visibility: 'user-or-llm',
description: 'Name of the Algolia index',
},
requests: {
type: 'json',
required: true,
visibility: 'user-or-llm',
description:
'Array of batch operations. Each item has "action" (addObject, updateObject, partialUpdateObject, partialUpdateObjectNoCreate, deleteObject, delete, clear) and "body" (the record data; must include objectID for update/delete; use an empty object {} for the index-level delete/clear actions)',
},
},
request: {
url: (params) =>
`https://${params.applicationId}.algolia.net/1/indexes/${encodeURIComponent(params.indexName.trim())}/batch`,
method: 'POST',
headers: (params) => ({
'x-algolia-application-id': params.applicationId,
'x-algolia-api-key': params.apiKey,
'Content-Type': 'application/json',
}),
body: (params) => {
const requests =
typeof params.requests === 'string' ? JSON.parse(params.requests) : params.requests
return { requests }
},
},
transformResponse: async (response) => {
const data = await response.json()
return {
success: true,
output: {
taskID: data.taskID ?? 0,
objectIDs: data.objectIDs ?? [],
},
}
},
outputs: {
taskID: {
type: 'number',
description: 'Algolia task ID for tracking the batch operation',
},
objectIDs: {
type: 'array',
description: 'Array of object IDs affected by the batch operation',
items: {
type: 'string',
description: 'Unique identifier of an affected record',
},
},
},
}