Skip to content

Commit 4e3e77e

Browse files
jirispilkaclaude
andauthored
refactor: Move Skyfire constants to src/payments/ (issue #643 phase 4) (#807)
refactor: Move Skyfire and call-actor constants out of src/const.ts (issue #643 phase 4) - New file src/payments/const.ts holds all Skyfire constants: SKYFIRE_MIN_CHARGE_USD, SKYFIRE_SELLER_ID, SKYFIRE_TOOL_INSTRUCTIONS, SKYFIRE_PAY_ID_PROPERTY_DESCRIPTION, SKYFIRE_README_CONTENT, SKYFIRE_ENABLED_TOOLS. - CALL_ACTOR_MCP_MISSING_TOOL_NAME_MSG moves to its only production consumer src/tools/core/call_actor_common.ts. - Update consumers in src/payments/skyfire.ts, src/utils/tools.ts, src/tools/core/call_actor_common.ts, and the unit/integration tests that reference these constants. Co-authored-by: Claude <noreply@anthropic.com>
1 parent 532f157 commit 4e3e77e

8 files changed

Lines changed: 50 additions & 40 deletions

File tree

src/const.ts

Lines changed: 9 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -66,34 +66,15 @@ export const defaults = {
6666
],
6767
};
6868

69-
const SKYFIRE_MIN_CHARGE_USD = 5.0;
70-
const SKYFIRE_SELLER_ID = process.env.SKYFIRE_SELLER_SERVICE_ID;
71-
72-
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.`;
73-
74-
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.`;
75-
76-
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.`;
77-
78-
/**
79-
* Set of internal tool names that require Skyfire PAY token ID in Skyfire mode.
80-
* These tools interact with Actor runs, datasets, or key-value stores and need billing support.
81-
*/
82-
export const SKYFIRE_ENABLED_TOOLS = new Set([
83-
HelperTools.ACTOR_CALL,
84-
HelperTools.ACTOR_OUTPUT_GET,
85-
HelperTools.ACTOR_RUNS_GET,
86-
HelperTools.ACTOR_RUNS_LOG,
87-
HelperTools.ACTOR_RUNS_ABORT,
88-
HelperTools.DATASET_GET,
89-
HelperTools.DATASET_GET_ITEMS,
90-
HelperTools.DATASET_SCHEMA_GET,
91-
HelperTools.KEY_VALUE_STORE_GET,
92-
HelperTools.KEY_VALUE_STORE_KEYS_GET,
93-
HelperTools.KEY_VALUE_STORE_RECORD_GET,
94-
]);
95-
96-
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.`;
69+
// Cache
70+
export const ACTOR_CACHE_MAX_SIZE = 500;
71+
export const ACTOR_CACHE_TTL_SECS = 30 * 60; // 30 minutes
72+
export const APIFY_DOCS_CACHE_MAX_SIZE = 500;
73+
export const APIFY_DOCS_CACHE_TTL_SECS = 60 * 60; // 1 hour
74+
export const MCP_SERVER_CACHE_MAX_SIZE = 500;
75+
export const MCP_SERVER_CACHE_TTL_SECS = 30 * 60; // 30 minutes
76+
export const USER_CACHE_MAX_SIZE = 200;
77+
export const USER_CACHE_TTL_SECS = 60 * 60; // 1 hour
9778

9879
export const ACTOR_PRICING_MODEL = {
9980
/** Rental Actors */

src/payments/const.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { HelperTools } from '../const.js';
2+
3+
const SKYFIRE_MIN_CHARGE_USD = 5.0;
4+
const SKYFIRE_SELLER_ID = process.env.SKYFIRE_SELLER_SERVICE_ID;
5+
6+
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.`;
7+
8+
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.`;
9+
10+
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.`;
11+
12+
/**
13+
* Set of internal tool names that require Skyfire PAY token ID in Skyfire mode.
14+
* These tools interact with Actor runs, datasets, or key-value stores and need billing support.
15+
*/
16+
export const SKYFIRE_ENABLED_TOOLS = new Set([
17+
HelperTools.ACTOR_CALL,
18+
HelperTools.ACTOR_OUTPUT_GET,
19+
HelperTools.ACTOR_RUNS_GET,
20+
HelperTools.ACTOR_RUNS_LOG,
21+
HelperTools.ACTOR_RUNS_ABORT,
22+
HelperTools.DATASET_GET,
23+
HelperTools.DATASET_GET_ITEMS,
24+
HelperTools.DATASET_SCHEMA_GET,
25+
HelperTools.KEY_VALUE_STORE_GET,
26+
HelperTools.KEY_VALUE_STORE_KEYS_GET,
27+
HelperTools.KEY_VALUE_STORE_RECORD_GET,
28+
]);

src/payments/skyfire.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1+
import type { ToolEntry } from '../types.js';
2+
import { redactSkyfirePayId } from '../utils/logging.js';
3+
import { cloneToolEntry } from '../utils/tools.js';
14
import {
25
SKYFIRE_PAY_ID_PROPERTY_DESCRIPTION,
36
SKYFIRE_README_CONTENT,
47
SKYFIRE_TOOL_INSTRUCTIONS,
5-
} from '../const.js';
6-
import type { ToolEntry } from '../types.js';
7-
import { redactSkyfirePayId } from '../utils/logging.js';
8-
import { cloneToolEntry } from '../utils/tools.js';
8+
} from './const.js';
99
import type { PaymentHeaders, PaymentProvider } from './types.js';
1010

1111
const SKYFIRE_PAY_ID_KEY = 'skyfire-pay-id';

src/tools/core/call_actor_common.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import log from '@apify/log';
88
import { ApifyClient } from '../../apify_client.js';
99
import {
1010
APIFY_ERROR_TYPE_FULL_PERMISSION_NOT_APPROVED,
11-
CALL_ACTOR_MCP_MISSING_TOOL_NAME_MSG,
1211
FAILURE_CATEGORY,
1312
HelperTools,
1413
TOOL_STATUS,
@@ -31,6 +30,8 @@ import { fixActorNameInputAndLog, getActorsAsTools } from './actor_tools_factory
3130

3231
const RAG_WEB_BROWSER_TOOL = actorNameToToolName('apify/rag-web-browser');
3332

33+
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.`;
34+
3435
/** Shared MCP server instructions — identical in both modes. */
3536
export const CALL_ACTOR_MCP_SERVER_SECTION = `For MCP server Actors:
3637
- Use fetch-actor-details with output={ mcpTools: true } to list available tools

src/utils/tools.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1+
import { type HelperTools } from '../const.js';
12
import {
2-
type HelperTools,
33
SKYFIRE_ENABLED_TOOLS,
44
SKYFIRE_PAY_ID_PROPERTY_DESCRIPTION,
55
SKYFIRE_TOOL_INSTRUCTIONS,
6-
} from '../const.js';
6+
} from '../payments/const.js';
77
import type { CallDiagnostics, HelperTool, ToolBase, ToolEntry, ToolInputSchema } from '../types.js';
88
import { ServerMode } from '../types.js';
99
import { fixZodSchemaRequired } from './ajv.js';

tests/integration/suite.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it } from
66

77
import { ApifyClient } from '../../src/apify_client.js';
88
import {
9-
CALL_ACTOR_MCP_MISSING_TOOL_NAME_MSG,
109
defaults,
1110
HelperTools,
1211
RAG_WEB_BROWSER,
1312
SERVER_MODE_AUTO_DETECTION_ENABLED,
14-
SKYFIRE_ENABLED_TOOLS,
1513
} from '../../src/const.js';
14+
import { SKYFIRE_ENABLED_TOOLS } from '../../src/payments/const.js';
1615
import { RESOURCE_MIME_TYPE } from '../../src/resources/widgets.js';
16+
import { CALL_ACTOR_MCP_MISSING_TOOL_NAME_MSG } from '../../src/tools/core/call_actor_common.js';
1717
// Import tools from getCategoryTools instead of directly to avoid circular dependency during module initialization
1818
import { getCategoryTools, getDefaultTools } from '../../src/tools/index.js';
1919
import { callActorOutputSchema } from '../../src/tools/structured_output_schemas.js';

tests/unit/resources.service.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { describe, expect, it, vi } from 'vitest';
22

3-
import { SKYFIRE_README_CONTENT } from '../../src/const.js';
3+
import { SKYFIRE_README_CONTENT } from '../../src/payments/const.js';
44
import { resolvePaymentProvider } from '../../src/payments/index.js';
55
import type { PaymentProvider } from '../../src/payments/types.js';
66
import { createResourceService } from '../../src/resources/resource_service.js';

tests/unit/tools.skyfire.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@
1010
*/
1111
import { describe, expect, it, vi } from 'vitest';
1212

13+
import { HelperTools } from '../../src/const.js';
1314
import {
14-
HelperTools,
1515
SKYFIRE_ENABLED_TOOLS,
1616
SKYFIRE_PAY_ID_PROPERTY_DESCRIPTION,
1717
SKYFIRE_TOOL_INSTRUCTIONS,
18-
} from '../../src/const.js';
18+
} from '../../src/payments/const.js';
1919
import type { ActorMcpTool, ActorTool, HelperTool, ToolEntry } from '../../src/types.js';
2020
import { applySkyfireAugmentation, cloneToolEntry } from '../../src/utils/tools.js';
2121

0 commit comments

Comments
 (0)