mono/packages/kbot/src/index.ts

82 lines
2.5 KiB
TypeScript

import { platform } from 'node:process'
import path from 'node:path'
import { Logger, ILogObj } from 'tslog'
const isWindows = platform === 'win32'
import { get_var } from '@polymech/commons'
import { MODULE_NAME } from './constants.js'
import { IKBotTask } from '@polymech/ai-tools'
import { createLogger } from '@polymech/log'
export const logger = createLogger('llm-tools') as unknown as Logger<ILogObj>
let _logger: Logger<ILogObj> = logger
export const getLogger = (options: IKBotTask): Logger<ILogObj> => {
if (_logger) {
return _logger
}
const logLevelMap: Record<string, number> = {
'silly': 0,
'trace': 1,
'debug': 2,
'info': 3,
'warn': 4,
'error': 5,
'fatal': 6
}
let minLevel = logLevelMap['info']
if (options.logLevel) {
if (typeof options.logLevel === 'string') {
const levelStr = options.logLevel as string
minLevel = logLevelMap[levelStr.toLowerCase()] || logLevelMap['info']
} else {
minLevel = options.logLevel
}
}
_logger = new Logger<ILogObj>({
name: MODULE_NAME,
minLevel,
hideLogPositionForProduction: true,
maskPlaceholder: '***',
prettyLogTemplate: "{{logLevelName}}\t[{{filePathWithLine}}{{name}}]\t",
})
return _logger
}
export { run } from './commands/run.js'
export { complete_options, complete_messages, complete_params } from './commands/run.js'
export const module_root = () => path.resolve(path.join(get_var(isWindows ? 'HOMEPATH' : 'HOME'), `.${MODULE_NAME}`))
export const assistant_supported: Record<string, string> = {
".c": "text/x-c",
".cpp": "text/x-c++",
".cs": "text/x-csharp",
".css": "text/css",
".doc": "application/msword",
".docx": "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
".go": "text/x-golang",
".html": "text/html",
".java": "text/x-java",
".js": "text/javascript",
".json": "application/json",
".md": "text/markdown",
".pdf": "application/pdf",
".php": "text/x-php",
".pptx": "application/vnd.openxmlformats-officedocument.presentationml.presentation",
".py": "text/x-python",
".rb": "text/x-ruby",
".sh": "application/x-sh",
".tex": "text/x-tex",
".ts": "application/typescript",
".txt": "text/plain"
}
export * from './types.js'
export * from './zod_types.js'
export * from './zod_schema.js'
export { E_OPENAI_MODEL } from './models/cache/openai-models.js'
export { E_OPENROUTER_MODEL } from './models/cache/openrouter-models.js'
export { E_OPENROUTER_MODEL_FREE } from './models/cache/openrouter-models-free.js'
export type { IKBotTask } from '@polymech/ai-tools'