@sinch/mcp
Version:
Sinch MCP server
79 lines • 4.28 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.setTemplateRegion = exports.setConversationRegion = exports.getConversationAppId = exports.getConversationService = void 0;
const sdk_client_1 = require("@sinch/sdk-client");
const conversation_1 = require("@sinch/conversation");
const process_1 = __importDefault(require("process"));
const types_1 = require("../../../types");
const utils_1 = require("../../../utils");
const getConversationService = (toolName) => {
const projectId = process_1.default.env.PROJECT_ID;
const keyId = process_1.default.env.KEY_ID;
const keySecret = process_1.default.env.KEY_SECRET;
if (!projectId || !keyId || !keySecret) {
return new types_1.PromptResponse('Missing env vars: PROJECT_ID, KEY_ID, KEY_SECRET.');
}
const conversationService = new conversation_1.ConversationService({});
const authenticationPlugin = new sdk_client_1.Oauth2TokenRequest(keyId, keySecret);
const additionalHeadersPlugin = new sdk_client_1.AdditionalHeadersRequest({
headers: (0, sdk_client_1.buildHeader)('User-Agent', (0, utils_1.formatUserAgent)(toolName, projectId)),
});
const fetcher = new sdk_client_1.ApiFetchClient({
projectId,
requestPlugins: [
authenticationPlugin,
additionalHeadersPlugin,
],
});
const templateFetcher = new sdk_client_1.ApiFetchClient({
projectId,
requestPlugins: [
authenticationPlugin,
additionalHeadersPlugin,
],
});
// Remove the VersionRequest plugin, as we override the user-agent header
fetcher.apiClientOptions.requestPlugins?.shift();
templateFetcher.apiClientOptions.requestPlugins?.shift();
// Replace the region placeholder with US by default
fetcher.apiClientOptions.hostname
= sdk_client_1.CONVERSATION_HOSTNAME.replace(sdk_client_1.REGION_PATTERN, `${sdk_client_1.ConversationRegion.UNITED_STATES}.`);
templateFetcher.apiClientOptions.hostname
= sdk_client_1.CONVERSATION_TEMPLATES_HOSTNAME.replace(sdk_client_1.REGION_PATTERN, `${sdk_client_1.ConversationRegion.UNITED_STATES}.`);
conversationService.lazyConversationClient.apiFetchClient = fetcher;
conversationService.lazyConversationTemplateClient.apiFetchClient = templateFetcher;
return conversationService;
};
exports.getConversationService = getConversationService;
const getConversationAppId = (appId) => {
if (!appId) {
appId = process_1.default.env.CONVERSATION_APP_ID;
if (!appId) {
return new types_1.PromptResponse('The "CONVERSATION_APP_ID" is not set in the environment variables and the "appId" property is not provided.');
}
}
return appId;
};
exports.getConversationAppId = getConversationAppId;
const setConversationRegion = (promptRegion, conversationService) => {
const region = promptRegion ?? process_1.default.env.CONVERSATION_REGION ?? sdk_client_1.ConversationRegion.UNITED_STATES;
conversationService.lazyConversationClient.sharedConfig.conversationRegion = region;
const formattedRegion = region !== '' ? `${region}.` : '';
conversationService.lazyConversationClient.apiFetchClient.apiClientOptions.hostname
= (0, sdk_client_1.formatRegionalizedHostname)(sdk_client_1.CONVERSATION_HOSTNAME, formattedRegion);
return region;
};
exports.setConversationRegion = setConversationRegion;
const setTemplateRegion = (promptRegion, conversationService) => {
const region = promptRegion ?? process_1.default.env.CONVERSATION_REGION ?? sdk_client_1.ConversationRegion.UNITED_STATES;
conversationService.lazyConversationTemplateClient.sharedConfig.conversationRegion = region;
const formattedRegion = region !== '' ? `${region}.` : '';
conversationService.lazyConversationTemplateClient.apiFetchClient.apiClientOptions.hostname
= (0, sdk_client_1.formatRegionalizedHostname)(sdk_client_1.CONVERSATION_TEMPLATES_HOSTNAME, formattedRegion);
return region;
};
exports.setTemplateRegion = setTemplateRegion;
//# sourceMappingURL=conversation-service-helper.js.map