Skip to content

Commit d13bade

Browse files
committed
Fix more issues
1 parent 82390c1 commit d13bade

16 files changed

+1972
-57
lines changed

package-lock.json

Lines changed: 1909 additions & 22 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/cli/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@utcp/cli",
3-
"version": "1.0.11",
3+
"version": "1.0.12",
44
"description": "CLI utilities for UTCP",
55
"main": "dist/index.cjs",
66
"module": "dist/index.js",
@@ -43,7 +43,7 @@
4343
}
4444
},
4545
"dependencies": {
46-
"@utcp/sdk": "^1.0.11"
46+
"@utcp/sdk": "^1.0.15"
4747
},
4848
"devDependencies": {
4949
"bun-types": "latest",

packages/core/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@utcp/sdk",
3-
"version": "1.0.14",
3+
"version": "1.0.15",
44
"description": "Universal Tool Calling Protocol SDK",
55
"main": "dist/index.cjs",
66
"module": "dist/index.js",

packages/core/src/implementations/default_variable_substitutor.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export class DefaultVariableSubstitutor implements VariableSubstitutor {
3636
// --- Search Hierarchy ---
3737

3838
// 1. Check config.variables (highest precedence)
39-
if (config.variables && config.variables[effectiveKey]) {
39+
if (config.variables && effectiveKey in config.variables) {
4040
return config.variables[effectiveKey];
4141
}
4242

@@ -78,7 +78,7 @@ export class DefaultVariableSubstitutor implements VariableSubstitutor {
7878
}
7979

8080
const objString = JSON.stringify(obj);
81-
if (objString.includes('$ref')) {
81+
if (objString && objString.includes('$ref')) {
8282
return obj;
8383
}
8484

@@ -152,8 +152,9 @@ export class DefaultVariableSubstitutor implements VariableSubstitutor {
152152
const varNameInTemplate = match[1] || match[2];
153153

154154
// Apply Python SDK's double underscore namespacing:
155+
// Replaces underscores in namespace with double underscores, then adds single underscore before variable
155156
const effectiveNamespace = namespace ? namespace.replace(/_/g, '__') : undefined;
156-
const prefixedVarName = effectiveNamespace ? `${effectiveNamespace}__${varNameInTemplate}` : varNameInTemplate;
157+
const prefixedVarName = effectiveNamespace ? `${effectiveNamespace}_${varNameInTemplate}` : varNameInTemplate;
157158

158159
variables.push(prefixedVarName);
159160
}

packages/direct-call/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@utcp/direct-call",
3-
"version": "1.0.11",
3+
"version": "1.0.12",
44
"description": "Direct callable functions plugin for UTCP",
55
"main": "dist/index.cjs",
66
"module": "dist/index.js",
@@ -44,7 +44,7 @@
4444
}
4545
},
4646
"dependencies": {
47-
"@utcp/sdk": "^1.0.11"
47+
"@utcp/sdk": "^1.0.15"
4848
},
4949
"devDependencies": {
5050
"bun-types": "latest",

packages/dotenv-loader/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@utcp/dotenv-loader",
3-
"version": "1.0.0",
3+
"version": "1.0.1",
44
"description": "DotEnv Variable Loader plugin for UTCP",
55
"main": "dist/index.cjs",
66
"module": "dist/index.js",
@@ -44,7 +44,7 @@
4444
"zod": "^3.23.8"
4545
},
4646
"peerDependencies": {
47-
"@utcp/sdk": "^1.0.8"
47+
"@utcp/sdk": "^1.0.15"
4848
},
4949
"devDependencies": {
5050
"bun-types": "latest",

packages/file/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@utcp/file",
3-
"version": "1.0.0",
3+
"version": "1.0.1",
44
"description": "File system protocol for UTCP - reads UTCP manuals from local files (Node.js only)",
55
"main": "dist/index.cjs",
66
"module": "dist/index.js",
@@ -43,8 +43,8 @@
4343
}
4444
},
4545
"dependencies": {
46-
"@utcp/sdk": "^1.0.8",
47-
"@utcp/http": "^1.0.7",
46+
"@utcp/sdk": "^1.0.15",
47+
"@utcp/http": "^1.0.13",
4848
"js-yaml": "^4.1.0"
4949
},
5050
"devDependencies": {

packages/http/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@utcp/http",
3-
"version": "1.0.12",
3+
"version": "1.0.13",
44
"description": "HTTP utilities for UTCP",
55
"main": "dist/index.cjs",
66
"module": "dist/index.js",
@@ -43,7 +43,7 @@
4343
}
4444
},
4545
"dependencies": {
46-
"@utcp/sdk": "^1.0.14",
46+
"@utcp/sdk": "^1.0.15",
4747
"axios": "^1.11.0",
4848
"js-yaml": "^4.1.0"
4949
},

packages/http/src/http_communication_protocol.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -243,11 +243,13 @@ export class HttpCommunicationProtocol implements CommunicationProtocol {
243243
if (!apiKeyAuth.api_key) {
244244
throw new Error("API key for ApiKeyAuth is empty.");
245245
}
246-
if (apiKeyAuth.location === 'header') {
246+
// Default to 'header' if location is not specified
247+
const location = apiKeyAuth.location || 'header';
248+
if (location === 'header') {
247249
requestConfig.headers = { ...requestConfig.headers, [apiKeyAuth.var_name]: apiKeyAuth.api_key };
248-
} else if (apiKeyAuth.location === 'query') {
250+
} else if (location === 'query') {
249251
requestConfig.params = { ...requestConfig.params, [apiKeyAuth.var_name]: apiKeyAuth.api_key };
250-
} else if (apiKeyAuth.location === 'cookie') {
252+
} else if (location === 'cookie') {
251253
cookies[apiKeyAuth.var_name] = apiKeyAuth.api_key;
252254
}
253255
} else if (httpCallTemplate.auth.auth_type === 'basic') {

packages/http/src/openapi_converter.ts

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ export interface OpenApiConverterOptions {
3333
specUrl?: string;
3434
callTemplateName?: string;
3535
authTools?: Auth;
36+
baseUrl?: string;
3637
}
3738

3839
/**
@@ -47,6 +48,7 @@ export interface OpenApiConverterOptions {
4748
export class OpenApiConverter {
4849
private spec: Record<string, any>;
4950
private spec_url: string | undefined;
51+
private base_url: string | undefined;
5052
private auth_tools: Auth | undefined;
5153
private placeholder_counter: number = 0;
5254
private call_template_name: string;
@@ -55,14 +57,16 @@ export class OpenApiConverter {
5557
* Initializes the OpenAPI converter.
5658
*
5759
* @param openapi_spec Parsed OpenAPI specification as a dictionary.
58-
* @param options Optional settings including spec_url, call_template_name, and auth_tools.
60+
* @param options Optional settings including spec_url, call_template_name, auth_tools, and baseUrl.
5961
* - specUrl: URL where the specification was retrieved from.
6062
* - callTemplateName: Custom name for the call_template if spec title not provided.
6163
* - authTools: Optional auth configuration for generated tools.
64+
* - baseUrl: Optional base URL override for all API endpoints.
6265
*/
6366
constructor(openapi_spec: Record<string, any>, options?: OpenApiConverterOptions) {
6467
this.spec = openapi_spec;
6568
this.spec_url = options?.specUrl;
69+
this.base_url = options?.baseUrl;
6670
this.auth_tools = options?.authTools;
6771
this.placeholder_counter = 0;
6872

@@ -105,18 +109,30 @@ export class OpenApiConverter {
105109
const tools: Tool[] = [];
106110
let baseUrl = '/';
107111

108-
const servers = this.spec.servers;
109-
if (servers && Array.isArray(servers) && servers.length > 0 && servers[0].url) {
110-
baseUrl = servers[0].url;
111-
} else if (this.spec_url) {
112+
// 1. Explicit baseUrl option (highest priority)
113+
if (this.base_url) {
114+
baseUrl = this.base_url;
115+
}
116+
// 2. OpenAPI 3.0 servers field
117+
else if (this.spec.servers && Array.isArray(this.spec.servers) && this.spec.servers.length > 0 && this.spec.servers[0].url) {
118+
baseUrl = this.spec.servers[0].url;
119+
}
120+
// 3. OpenAPI 2.0 host and basePath fields
121+
else if (this.spec.host) {
122+
const scheme = this.spec.schemes?.[0] || 'https';
123+
const basePath = this.spec.basePath || '';
124+
baseUrl = `${scheme}://${this.spec.host}${basePath}`;
125+
}
126+
// 4. Fallback to spec_url ONLY if it's an HTTP/HTTPS URL
127+
else if (this.spec_url && (this.spec_url.startsWith('http://') || this.spec_url.startsWith('https://'))) {
112128
try {
113129
const parsedUrl = new URL(this.spec_url);
114130
baseUrl = `${parsedUrl.protocol}//${parsedUrl.host}`;
115131
} catch (e) {
116132
console.error(`[OpenApiConverter] Invalid spec_url provided: ${this.spec_url}`);
117133
}
118134
} else {
119-
console.warn("[OpenApiConverter] No server info or spec URL provided. Using fallback base URL: '/'");
135+
console.warn("[OpenApiConverter] No server info found in OpenAPI spec. Using fallback base URL: '/'. Tools may not work correctly without a valid base URL.");
120136
}
121137

122138
const paths = this.spec.paths || {};

0 commit comments

Comments
 (0)