Skip to content

Commit 01e0db5

Browse files
authored
feat: ai tool header (#76)
1 parent 6497198 commit 01e0db5

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

nodes/Apify/resources/genericFunctions.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ type IApiRequestOptions = IRequestOptions & { uri?: string };
1818

1919
/**
2020
* Make an API request to Apify
21-
*
2221
*/
2322
export async function apiRequest(
2423
this: IHookFunctions | IExecuteFunctions | ILoadOptionsFunctions,
@@ -29,15 +28,21 @@ export async function apiRequest(
2928
const query = qs || {};
3029
const endpoint = `https://api.apify.com${uri}`;
3130

31+
const headers: Record<string, string> = {
32+
'x-apify-integration-platform': 'n8n',
33+
};
34+
35+
if (isUsedAsAiTool(this.getNode().type)) {
36+
headers['x-apify-integration-ai-tool'] = 'true';
37+
}
38+
3239
const options: IRequestOptions = {
3340
json: true,
3441
...rest,
3542
method,
3643
qs: query,
3744
url: endpoint,
38-
headers: {
39-
'x-apify-integration-platform': 'n8n',
40-
},
45+
headers,
4146
};
4247

4348
if (method === 'GET') {
@@ -256,3 +261,8 @@ export function customBodyParser(input: string | object) {
256261
return input;
257262
}
258263
}
264+
265+
export function isUsedAsAiTool(nodeType: string): boolean {
266+
const parts = nodeType.split('.');
267+
return parts[parts.length - 1] === 'apifyTool';
268+
}

0 commit comments

Comments
 (0)