@utcp/http 1.0.12 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -4105,7 +4105,8 @@ var HttpCallTemplateSchema = external_exports.object({
4105
4105
  return new import_sdk.AuthSerializer().validateDict(val);
4106
4106
  }
4107
4107
  return val;
4108
- }).describe("Authentication configuration for generated tools")
4108
+ }).describe("Authentication configuration for generated tools"),
4109
+ allowed_communication_protocols: external_exports.array(external_exports.string()).optional().describe("Optional list of allowed communication protocol types for tools within this manual.")
4109
4110
  });
4110
4111
  var HttpCallTemplateSerializer = class extends import_sdk2.Serializer {
4111
4112
  toDict(obj) {
@@ -4119,7 +4120,8 @@ var HttpCallTemplateSerializer = class extends import_sdk2.Serializer {
4119
4120
  auth_tools: obj.auth_tools ? new import_sdk.AuthSerializer().toDict(obj.auth_tools) : null,
4120
4121
  headers: obj.headers,
4121
4122
  body_field: obj.body_field,
4122
- header_fields: obj.header_fields
4123
+ header_fields: obj.header_fields,
4124
+ allowed_communication_protocols: obj.allowed_communication_protocols
4123
4125
  };
4124
4126
  }
4125
4127
  validateDict(obj) {
@@ -4146,7 +4148,8 @@ var StreamableHttpCallTemplateSchema = external_exports.object({
4146
4148
  auth: import_sdk3.AuthSchema.optional().describe("Optional authentication configuration."),
4147
4149
  headers: external_exports.record(external_exports.string(), external_exports.string()).optional().describe("Optional static headers to include in requests."),
4148
4150
  body_field: external_exports.string().nullable().optional().describe("The name of the single input field to be sent as the request body."),
4149
- header_fields: external_exports.array(external_exports.string()).nullable().optional().describe("List of input fields to be sent as request headers.")
4151
+ header_fields: external_exports.array(external_exports.string()).nullable().optional().describe("List of input fields to be sent as request headers."),
4152
+ allowed_communication_protocols: external_exports.array(external_exports.string()).optional().describe("Optional list of allowed communication protocol types for tools within this manual.")
4150
4153
  });
4151
4154
  var StreamableHttpCallTemplateSerializer = class extends import_sdk4.Serializer {
4152
4155
  /**
@@ -4165,7 +4168,8 @@ var StreamableHttpCallTemplateSerializer = class extends import_sdk4.Serializer
4165
4168
  auth: obj.auth,
4166
4169
  headers: obj.headers,
4167
4170
  body_field: obj.body_field,
4168
- header_fields: obj.header_fields
4171
+ header_fields: obj.header_fields,
4172
+ allowed_communication_protocols: obj.allowed_communication_protocols
4169
4173
  };
4170
4174
  }
4171
4175
  /**
@@ -4195,7 +4199,8 @@ var SseCallTemplateSchema = external_exports.object({
4195
4199
  auth: import_sdk5.AuthSchema.optional().describe("Optional authentication configuration."),
4196
4200
  headers: external_exports.record(external_exports.string(), external_exports.string()).optional().describe("Optional static headers for the initial connection."),
4197
4201
  body_field: external_exports.string().nullable().optional().describe("The name of the single input field to be sent as the request body."),
4198
- header_fields: external_exports.array(external_exports.string()).nullable().optional().describe("List of input fields to be sent as request headers for the initial connection.")
4202
+ header_fields: external_exports.array(external_exports.string()).nullable().optional().describe("List of input fields to be sent as request headers for the initial connection."),
4203
+ allowed_communication_protocols: external_exports.array(external_exports.string()).optional().describe("Optional list of allowed communication protocol types for tools within this manual.")
4199
4204
  });
4200
4205
  var SseCallTemplateSerializer = class extends import_sdk6.Serializer {
4201
4206
  /**
@@ -4213,7 +4218,8 @@ var SseCallTemplateSerializer = class extends import_sdk6.Serializer {
4213
4218
  auth: obj.auth,
4214
4219
  headers: obj.headers,
4215
4220
  body_field: obj.body_field,
4216
- header_fields: obj.header_fields
4221
+ header_fields: obj.header_fields,
4222
+ allowed_communication_protocols: obj.allowed_communication_protocols
4217
4223
  };
4218
4224
  }
4219
4225
  /**
@@ -4241,6 +4247,7 @@ var import_sdk8 = require("@utcp/sdk");
4241
4247
  var OpenApiConverter = class {
4242
4248
  spec;
4243
4249
  spec_url;
4250
+ base_url;
4244
4251
  auth_tools;
4245
4252
  placeholder_counter = 0;
4246
4253
  call_template_name;
@@ -4248,14 +4255,16 @@ var OpenApiConverter = class {
4248
4255
  * Initializes the OpenAPI converter.
4249
4256
  *
4250
4257
  * @param openapi_spec Parsed OpenAPI specification as a dictionary.
4251
- * @param options Optional settings including spec_url, call_template_name, and auth_tools.
4258
+ * @param options Optional settings including spec_url, call_template_name, auth_tools, and baseUrl.
4252
4259
  * - specUrl: URL where the specification was retrieved from.
4253
4260
  * - callTemplateName: Custom name for the call_template if spec title not provided.
4254
4261
  * - authTools: Optional auth configuration for generated tools.
4262
+ * - baseUrl: Optional base URL override for all API endpoints.
4255
4263
  */
4256
4264
  constructor(openapi_spec, options) {
4257
4265
  this.spec = openapi_spec;
4258
4266
  this.spec_url = options?.specUrl;
4267
+ this.base_url = options?.baseUrl;
4259
4268
  this.auth_tools = options?.authTools;
4260
4269
  this.placeholder_counter = 0;
4261
4270
  let callTemplateName = options?.callTemplateName;
@@ -4290,10 +4299,15 @@ var OpenApiConverter = class {
4290
4299
  this.placeholder_counter = 0;
4291
4300
  const tools = [];
4292
4301
  let baseUrl = "/";
4293
- const servers = this.spec.servers;
4294
- if (servers && Array.isArray(servers) && servers.length > 0 && servers[0].url) {
4295
- baseUrl = servers[0].url;
4296
- } else if (this.spec_url) {
4302
+ if (this.base_url) {
4303
+ baseUrl = this.base_url;
4304
+ } else if (this.spec.servers && Array.isArray(this.spec.servers) && this.spec.servers.length > 0 && this.spec.servers[0].url) {
4305
+ baseUrl = this.spec.servers[0].url;
4306
+ } else if (this.spec.host) {
4307
+ const scheme = this.spec.schemes?.[0] || "https";
4308
+ const basePath = this.spec.basePath || "";
4309
+ baseUrl = `${scheme}://${this.spec.host}${basePath}`;
4310
+ } else if (this.spec_url && (this.spec_url.startsWith("http://") || this.spec_url.startsWith("https://"))) {
4297
4311
  try {
4298
4312
  const parsedUrl = new URL(this.spec_url);
4299
4313
  baseUrl = `${parsedUrl.protocol}//${parsedUrl.host}`;
@@ -4301,7 +4315,7 @@ var OpenApiConverter = class {
4301
4315
  console.error(`[OpenApiConverter] Invalid spec_url provided: ${this.spec_url}`);
4302
4316
  }
4303
4317
  } else {
4304
- console.warn("[OpenApiConverter] No server info or spec URL provided. Using fallback base URL: '/'");
4318
+ console.warn("[OpenApiConverter] No server info found in OpenAPI spec. Using fallback base URL: '/'. Tools may not work correctly without a valid base URL.");
4305
4319
  }
4306
4320
  const paths = this.spec.paths || {};
4307
4321
  for (const [path, pathItem] of Object.entries(paths)) {
@@ -4871,11 +4885,12 @@ var HttpCommunicationProtocol = class {
4871
4885
  if (!apiKeyAuth.api_key) {
4872
4886
  throw new Error("API key for ApiKeyAuth is empty.");
4873
4887
  }
4874
- if (apiKeyAuth.location === "header") {
4888
+ const location = apiKeyAuth.location || "header";
4889
+ if (location === "header") {
4875
4890
  requestConfig.headers = { ...requestConfig.headers, [apiKeyAuth.var_name]: apiKeyAuth.api_key };
4876
- } else if (apiKeyAuth.location === "query") {
4891
+ } else if (location === "query") {
4877
4892
  requestConfig.params = { ...requestConfig.params, [apiKeyAuth.var_name]: apiKeyAuth.api_key };
4878
- } else if (apiKeyAuth.location === "cookie") {
4893
+ } else if (location === "cookie") {
4879
4894
  cookies[apiKeyAuth.var_name] = apiKeyAuth.api_key;
4880
4895
  }
4881
4896
  } else if (httpCallTemplate.auth.auth_type === "basic") {
@@ -5016,11 +5031,12 @@ var StreamableHttpCommunicationProtocol = class {
5016
5031
  if ("api_key" in provider.auth) {
5017
5032
  const apiKeyAuth = provider.auth;
5018
5033
  if (apiKeyAuth.api_key) {
5019
- if (apiKeyAuth.location === "header") {
5034
+ const location = apiKeyAuth.location || "header";
5035
+ if (location === "header") {
5020
5036
  headers[apiKeyAuth.var_name] = apiKeyAuth.api_key;
5021
- } else if (apiKeyAuth.location === "query") {
5037
+ } else if (location === "query") {
5022
5038
  queryParams[apiKeyAuth.var_name] = apiKeyAuth.api_key;
5023
- } else if (apiKeyAuth.location === "cookie") {
5039
+ } else if (location === "cookie") {
5024
5040
  cookies[apiKeyAuth.var_name] = apiKeyAuth.api_key;
5025
5041
  }
5026
5042
  } else {
@@ -5147,11 +5163,12 @@ var SseCommunicationProtocol = class {
5147
5163
  if ("api_key" in provider.auth) {
5148
5164
  const apiKeyAuth = provider.auth;
5149
5165
  if (apiKeyAuth.api_key) {
5150
- if (apiKeyAuth.location === "header") {
5166
+ const location = apiKeyAuth.location || "header";
5167
+ if (location === "header") {
5151
5168
  headers[apiKeyAuth.var_name] = apiKeyAuth.api_key;
5152
- } else if (apiKeyAuth.location === "query") {
5169
+ } else if (location === "query") {
5153
5170
  queryParams[apiKeyAuth.var_name] = apiKeyAuth.api_key;
5154
- } else if (apiKeyAuth.location === "cookie") {
5171
+ } else if (location === "cookie") {
5155
5172
  cookies[apiKeyAuth.var_name] = apiKeyAuth.api_key;
5156
5173
  }
5157
5174
  } else {