-
Notifications
You must be signed in to change notification settings - Fork 215
Expand file tree
/
Copy pathactor_search.ts
More file actions
64 lines (57 loc) · 2.29 KB
/
Copy pathactor_search.ts
File metadata and controls
64 lines (57 loc) · 2.29 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
/**
* Shared utility for searching Actors via `GET /v2/store`.
*
* `GET /v2/store` returns only `[FREE, PAY_PER_EVENT]` Actors by default
* (apify-core's `AGENT_SAFE_PRICING_MODELS`) and additionally drops Actors
* that fail safety checks (KYC, full-permission low-usage, etc.) — so no
* MCP-side rental over-fetch / filter is needed.
*/
import { ApifyClient } from '../apify_client.js';
import type { PaymentProvider } from '../payments/types.js';
import type { ActorStoreList } from '../types.js';
export type SearchActorsByKeywordsOptions = {
search: string;
apifyToken: string;
limit: number;
offset?: number;
allowsAgenticUsers?: boolean;
/** API rejects values above `MAX_LIMIT_WITH_INPUT_SCHEMA` (apify-core cap). */
includeInputSchema?: boolean;
};
export type SearchAgentSafeActorsOptions = {
keywords: string;
apifyToken: string;
limit: number;
offset: number;
paymentProvider?: PaymentProvider;
};
export async function searchActorsByKeywords(
options: SearchActorsByKeywordsOptions,
): Promise<ActorStoreList[]> {
const { search, apifyToken, limit, offset, allowsAgenticUsers, includeInputSchema } = options;
const client = new ApifyClient({ token: apifyToken });
const storeClient = client.store();
if (allowsAgenticUsers !== undefined) storeClient.params = { ...storeClient.params, allowsAgenticUsers };
if (includeInputSchema !== undefined) storeClient.params = { ...storeClient.params, includeInputSchema };
const results = await storeClient.list({ search, limit, offset });
return results.items as ActorStoreList[];
}
/**
* Preset around `searchActorsByKeywords` for the agent-facing search tool:
* always sets `includeInputSchema=true` and forwards `allowsAgenticUsers`
* when a `paymentProvider` is in play. The public arg schema caps `limit`
* at apify-core's hard cap (`MAX_LIMIT_WITH_INPUT_SCHEMA`).
*/
export async function searchAgentSafeActors(
options: SearchAgentSafeActorsOptions,
): Promise<ActorStoreList[]> {
const { keywords, apifyToken, limit, offset, paymentProvider } = options;
return searchActorsByKeywords({
search: keywords,
apifyToken,
limit,
offset,
allowsAgenticUsers: paymentProvider ? true : undefined,
includeInputSchema: true,
});
}