feat: enhance logging capabilities and update query options in sdk-typescript

- Introduced a new logging system with adjustable log levels (debug, info, warn, error).
- Updated query options to include a logLevel parameter for controlling verbosity.
- Refactored existing code to utilize the new logging system for better error handling and debugging.
- Cleaned up unused code and improved the structure of the SDK.
This commit is contained in:
mingholy.lmh
2025-11-26 21:37:40 +08:00
parent 49dc84ac0e
commit 769a438fa4
16 changed files with 552 additions and 143 deletions

View File

@@ -0,0 +1,95 @@
/**
* @license
* Copyright 2025 Qwen Team
* SPDX-License-Identifier: Apache-2.0
*/
import { execSync } from 'node:child_process';
import { rmSync, mkdirSync, existsSync, cpSync } from 'node:fs';
import { join, dirname } from 'node:path';
import { fileURLToPath } from 'node:url';
import esbuild from 'esbuild';
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
const rootDir = join(__dirname, '..');
rmSync(join(rootDir, 'dist'), { recursive: true, force: true });
mkdirSync(join(rootDir, 'dist'), { recursive: true });
execSync('tsc --project tsconfig.build.json', {
stdio: 'inherit',
cwd: rootDir,
});
try {
execSync(
'npx dts-bundle-generator -o dist/index.d.ts src/index.ts --no-check',
{
stdio: 'inherit',
cwd: rootDir,
},
);
const dirsToRemove = ['mcp', 'query', 'transport', 'types', 'utils'];
for (const dir of dirsToRemove) {
const dirPath = join(rootDir, 'dist', dir);
if (existsSync(dirPath)) {
rmSync(dirPath, { recursive: true, force: true });
}
}
} catch (error) {
console.warn(
'Could not bundle type definitions, keeping separate .d.ts files',
error.message,
);
}
await esbuild.build({
entryPoints: [join(rootDir, 'src', 'index.ts')],
bundle: true,
format: 'esm',
platform: 'node',
target: 'node18',
outfile: join(rootDir, 'dist', 'index.mjs'),
external: ['@modelcontextprotocol/sdk'],
sourcemap: false,
minify: true,
minifyWhitespace: true,
minifyIdentifiers: true,
minifySyntax: true,
legalComments: 'none',
keepNames: false,
treeShaking: true,
});
await esbuild.build({
entryPoints: [join(rootDir, 'src', 'index.ts')],
bundle: true,
format: 'cjs',
platform: 'node',
target: 'node18',
outfile: join(rootDir, 'dist', 'index.cjs'),
external: ['@modelcontextprotocol/sdk'],
sourcemap: false,
minify: true,
minifyWhitespace: true,
minifyIdentifiers: true,
minifySyntax: true,
legalComments: 'none',
keepNames: false,
treeShaking: true,
});
const filesToCopy = ['README.md', 'LICENSE'];
for (const file of filesToCopy) {
const sourcePath = join(rootDir, '..', '..', file);
const targetPath = join(rootDir, 'dist', file);
if (existsSync(sourcePath)) {
try {
cpSync(sourcePath, targetPath);
} catch (error) {
console.warn(`Could not copy ${file}:`, error.message);
}
}
}