diff --git a/src/const.ts b/src/const.ts index 580ba91a9..9ee6e6d1b 100644 --- a/src/const.ts +++ b/src/const.ts @@ -66,34 +66,15 @@ export const defaults = { ], }; -const SKYFIRE_MIN_CHARGE_USD = 5.0; -const SKYFIRE_SELLER_ID = process.env.SKYFIRE_SELLER_SERVICE_ID; - -export const SKYFIRE_TOOL_INSTRUCTIONS = `To run the Actor, you need to provide a Skyfire PAY JWT token in the \`skyfire-pay-id\` input property. You first need to create the Skyfire PAY token by calling the \`create-pay-token\` tool from the Skyfire MCP server and then provide the created JWT token in the \`skyfire-pay-id\` input property when calling Actor tool. IMPORTANT: The value you pass to \`skyfire-pay-id\` must be the JWT token string itself (it starts with "ey"), NOT an ID or UUID. The Skyfire PAY token is used for billing purposes and needs to be charged with at least ${SKYFIRE_MIN_CHARGE_USD} USD.${SKYFIRE_SELLER_ID ? ` The Skyfire seller ID for Apify MCP server is "${SKYFIRE_SELLER_ID}".` : ''} When retrieving Actor output using the \`get-actor-output\` tool, you also need to provide the same Skyfire PAY JWT token (starting with "ey") in the \`skyfire-pay-id\` input property.`; - -export const SKYFIRE_PAY_ID_PROPERTY_DESCRIPTION = `Skyfire PAY JWT token used for billing purposes. This must be the JWT token string returned by the create-pay-token tool (starts with "ey"), NOT a token ID or UUID.`; - -export const SKYFIRE_README_CONTENT = `The Apify MCP Server allows clients to interact with Apify Actors, storage, and documentation. Before running any Apify Actor, you need to set up a Skyfire PAY token for billing purposes. To set up the PAY token you need to use the create-pay-token tool from the Skyfire MCP server. The PAY token must be charged with a minimum of ${SKYFIRE_MIN_CHARGE_USD} USD to be valid.${SKYFIRE_SELLER_ID ? ` The Skyfire seller ID for Apify MCP server is "${SKYFIRE_SELLER_ID}".` : ''} When running an Actor using the call-actor tool, you must provide the Skyfire PAY JWT token in the \`skyfire-pay-id\` input property. IMPORTANT: The value for \`skyfire-pay-id\` must be the actual JWT token string (starting with "ey") returned by the create-pay-token tool, NOT a token ID or UUID. Similarly, when retrieving Actor output using the get-actor-output tool, you must also provide the same Skyfire PAY JWT token (starting with "ey") in the \`skyfire-pay-id\` input property.`; - -/** - * Set of internal tool names that require Skyfire PAY token ID in Skyfire mode. - * These tools interact with Actor runs, datasets, or key-value stores and need billing support. - */ -export const SKYFIRE_ENABLED_TOOLS = new Set([ - HelperTools.ACTOR_CALL, - HelperTools.ACTOR_OUTPUT_GET, - HelperTools.ACTOR_RUNS_GET, - HelperTools.ACTOR_RUNS_LOG, - HelperTools.ACTOR_RUNS_ABORT, - HelperTools.DATASET_GET, - HelperTools.DATASET_GET_ITEMS, - HelperTools.DATASET_SCHEMA_GET, - HelperTools.KEY_VALUE_STORE_GET, - HelperTools.KEY_VALUE_STORE_KEYS_GET, - HelperTools.KEY_VALUE_STORE_RECORD_GET, -]); - -export const CALL_ACTOR_MCP_MISSING_TOOL_NAME_MSG = `When calling an MCP server Actor, you must specify the tool name in the actor parameter as "{actorName}:{toolName}" in the "actor" input property.`; +// Cache +export const ACTOR_CACHE_MAX_SIZE = 500; +export const ACTOR_CACHE_TTL_SECS = 30 * 60; // 30 minutes +export const APIFY_DOCS_CACHE_MAX_SIZE = 500; +export const APIFY_DOCS_CACHE_TTL_SECS = 60 * 60; // 1 hour +export const MCP_SERVER_CACHE_MAX_SIZE = 500; +export const MCP_SERVER_CACHE_TTL_SECS = 30 * 60; // 30 minutes +export const USER_CACHE_MAX_SIZE = 200; +export const USER_CACHE_TTL_SECS = 60 * 60; // 1 hour export const ACTOR_PRICING_MODEL = { /** Rental Actors */ diff --git a/src/payments/const.ts b/src/payments/const.ts new file mode 100644 index 000000000..48bfeafce --- /dev/null +++ b/src/payments/const.ts @@ -0,0 +1,28 @@ +import { HelperTools } from '../const.js'; + +const SKYFIRE_MIN_CHARGE_USD = 5.0; +const SKYFIRE_SELLER_ID = process.env.SKYFIRE_SELLER_SERVICE_ID; + +export const SKYFIRE_TOOL_INSTRUCTIONS = `To run the Actor, you need to provide a Skyfire PAY JWT token in the \`skyfire-pay-id\` input property. You first need to create the Skyfire PAY token by calling the \`create-pay-token\` tool from the Skyfire MCP server and then provide the created JWT token in the \`skyfire-pay-id\` input property when calling Actor tool. IMPORTANT: The value you pass to \`skyfire-pay-id\` must be the JWT token string itself (it starts with "ey"), NOT an ID or UUID. The Skyfire PAY token is used for billing purposes and needs to be charged with at least ${SKYFIRE_MIN_CHARGE_USD} USD.${SKYFIRE_SELLER_ID ? ` The Skyfire seller ID for Apify MCP server is "${SKYFIRE_SELLER_ID}".` : ''} When retrieving Actor output using the \`get-actor-output\` tool, you also need to provide the same Skyfire PAY JWT token (starting with "ey") in the \`skyfire-pay-id\` input property.`; + +export const SKYFIRE_PAY_ID_PROPERTY_DESCRIPTION = `Skyfire PAY JWT token used for billing purposes. This must be the JWT token string returned by the create-pay-token tool (starts with "ey"), NOT a token ID or UUID.`; + +export const SKYFIRE_README_CONTENT = `The Apify MCP Server allows clients to interact with Apify Actors, storage, and documentation. Before running any Apify Actor, you need to set up a Skyfire PAY token for billing purposes. To set up the PAY token you need to use the create-pay-token tool from the Skyfire MCP server. The PAY token must be charged with a minimum of ${SKYFIRE_MIN_CHARGE_USD} USD to be valid.${SKYFIRE_SELLER_ID ? ` The Skyfire seller ID for Apify MCP server is "${SKYFIRE_SELLER_ID}".` : ''} When running an Actor using the call-actor tool, you must provide the Skyfire PAY JWT token in the \`skyfire-pay-id\` input property. IMPORTANT: The value for \`skyfire-pay-id\` must be the actual JWT token string (starting with "ey") returned by the create-pay-token tool, NOT a token ID or UUID. Similarly, when retrieving Actor output using the get-actor-output tool, you must also provide the same Skyfire PAY JWT token (starting with "ey") in the \`skyfire-pay-id\` input property.`; + +/** + * Set of internal tool names that require Skyfire PAY token ID in Skyfire mode. + * These tools interact with Actor runs, datasets, or key-value stores and need billing support. + */ +export const SKYFIRE_ENABLED_TOOLS = new Set([ + HelperTools.ACTOR_CALL, + HelperTools.ACTOR_OUTPUT_GET, + HelperTools.ACTOR_RUNS_GET, + HelperTools.ACTOR_RUNS_LOG, + HelperTools.ACTOR_RUNS_ABORT, + HelperTools.DATASET_GET, + HelperTools.DATASET_GET_ITEMS, + HelperTools.DATASET_SCHEMA_GET, + HelperTools.KEY_VALUE_STORE_GET, + HelperTools.KEY_VALUE_STORE_KEYS_GET, + HelperTools.KEY_VALUE_STORE_RECORD_GET, +]); diff --git a/src/payments/skyfire.ts b/src/payments/skyfire.ts index 99916dbd7..c192a3d84 100644 --- a/src/payments/skyfire.ts +++ b/src/payments/skyfire.ts @@ -1,11 +1,11 @@ +import type { ToolEntry } from '../types.js'; +import { redactSkyfirePayId } from '../utils/logging.js'; +import { cloneToolEntry } from '../utils/tools.js'; import { SKYFIRE_PAY_ID_PROPERTY_DESCRIPTION, SKYFIRE_README_CONTENT, SKYFIRE_TOOL_INSTRUCTIONS, -} from '../const.js'; -import type { ToolEntry } from '../types.js'; -import { redactSkyfirePayId } from '../utils/logging.js'; -import { cloneToolEntry } from '../utils/tools.js'; +} from './const.js'; import type { PaymentHeaders, PaymentProvider } from './types.js'; const SKYFIRE_PAY_ID_KEY = 'skyfire-pay-id'; diff --git a/src/tools/core/call_actor_common.ts b/src/tools/core/call_actor_common.ts index 124915b5b..5ba898ca1 100644 --- a/src/tools/core/call_actor_common.ts +++ b/src/tools/core/call_actor_common.ts @@ -8,7 +8,6 @@ import log from '@apify/log'; import { ApifyClient } from '../../apify_client.js'; import { APIFY_ERROR_TYPE_FULL_PERMISSION_NOT_APPROVED, - CALL_ACTOR_MCP_MISSING_TOOL_NAME_MSG, FAILURE_CATEGORY, HelperTools, TOOL_STATUS, @@ -31,6 +30,8 @@ import { fixActorNameInputAndLog, getActorsAsTools } from './actor_tools_factory const RAG_WEB_BROWSER_TOOL = actorNameToToolName('apify/rag-web-browser'); +export const CALL_ACTOR_MCP_MISSING_TOOL_NAME_MSG = `When calling an MCP server Actor, you must specify the tool name in the actor parameter as "{actorName}:{toolName}" in the "actor" input property.`; + /** Shared MCP server instructions — identical in both modes. */ export const CALL_ACTOR_MCP_SERVER_SECTION = `For MCP server Actors: - Use fetch-actor-details with output={ mcpTools: true } to list available tools diff --git a/src/utils/tools.ts b/src/utils/tools.ts index 28447ff85..afb23288f 100644 --- a/src/utils/tools.ts +++ b/src/utils/tools.ts @@ -1,9 +1,9 @@ +import { type HelperTools } from '../const.js'; import { - type HelperTools, SKYFIRE_ENABLED_TOOLS, SKYFIRE_PAY_ID_PROPERTY_DESCRIPTION, SKYFIRE_TOOL_INSTRUCTIONS, -} from '../const.js'; +} from '../payments/const.js'; import type { CallDiagnostics, HelperTool, ToolBase, ToolEntry, ToolInputSchema } from '../types.js'; import { ServerMode } from '../types.js'; import { fixZodSchemaRequired } from './ajv.js'; diff --git a/tests/integration/suite.ts b/tests/integration/suite.ts index d17b87372..86db4d3da 100644 --- a/tests/integration/suite.ts +++ b/tests/integration/suite.ts @@ -6,14 +6,14 @@ import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it } from import { ApifyClient } from '../../src/apify_client.js'; import { - CALL_ACTOR_MCP_MISSING_TOOL_NAME_MSG, defaults, HelperTools, RAG_WEB_BROWSER, SERVER_MODE_AUTO_DETECTION_ENABLED, - SKYFIRE_ENABLED_TOOLS, } from '../../src/const.js'; +import { SKYFIRE_ENABLED_TOOLS } from '../../src/payments/const.js'; import { RESOURCE_MIME_TYPE } from '../../src/resources/widgets.js'; +import { CALL_ACTOR_MCP_MISSING_TOOL_NAME_MSG } from '../../src/tools/core/call_actor_common.js'; // Import tools from getCategoryTools instead of directly to avoid circular dependency during module initialization import { getCategoryTools, getDefaultTools } from '../../src/tools/index.js'; import { callActorOutputSchema } from '../../src/tools/structured_output_schemas.js'; diff --git a/tests/unit/resources.service.test.ts b/tests/unit/resources.service.test.ts index 9bd8d3b2b..7d36028da 100644 --- a/tests/unit/resources.service.test.ts +++ b/tests/unit/resources.service.test.ts @@ -1,6 +1,6 @@ import { describe, expect, it, vi } from 'vitest'; -import { SKYFIRE_README_CONTENT } from '../../src/const.js'; +import { SKYFIRE_README_CONTENT } from '../../src/payments/const.js'; import { resolvePaymentProvider } from '../../src/payments/index.js'; import type { PaymentProvider } from '../../src/payments/types.js'; import { createResourceService } from '../../src/resources/resource_service.js'; diff --git a/tests/unit/tools.skyfire.test.ts b/tests/unit/tools.skyfire.test.ts index 53100baaf..67f150f4c 100644 --- a/tests/unit/tools.skyfire.test.ts +++ b/tests/unit/tools.skyfire.test.ts @@ -10,12 +10,12 @@ */ import { describe, expect, it, vi } from 'vitest'; +import { HelperTools } from '../../src/const.js'; import { - HelperTools, SKYFIRE_ENABLED_TOOLS, SKYFIRE_PAY_ID_PROPERTY_DESCRIPTION, SKYFIRE_TOOL_INSTRUCTIONS, -} from '../../src/const.js'; +} from '../../src/payments/const.js'; import type { ActorMcpTool, ActorTool, HelperTool, ToolEntry } from '../../src/types.js'; import { applySkyfireAugmentation, cloneToolEntry } from '../../src/utils/tools.js';