kbot esm 2/3

This commit is contained in:
lovebird 2025-02-20 18:22:14 +01:00
parent b75fe64e3d
commit e41a3eee77
38 changed files with 132 additions and 130 deletions

View File

@ -1,11 +1,12 @@
{
"name": "@plastichub/code-bot",
"version": "0.3.4",
"name": "@polymech/kbot-d",
"version": "0.3.5",
"type": "module",
"publishConfig": {
"access": "public"
},
"bin": {
"kbotd": "./main.js"
"kbot-d": "./main.js"
},
"scripts": {
"build": "tsc",
@ -20,25 +21,22 @@
"exe:lnx": "cd dist && nexe -i main_node.js -o kbot --build --temp=../../temp-kbot --verbose"
},
"dependencies": {
"@astrojs/ts-plugin": "1.10.4",
"@gradio/client": "1.12.0",
"@plastichub/core": "file:../core",
"@plastichub/fs": "^0.13.40",
"@plastichub/osr-ai-tools": "file:../osr-ai-tools",
"@plastichub/osr-commons": "file:../osr-commons",
"@plastichub/osr-log": "file:../osr-log",
"@polymech/ai-tools": "file:../ai-tools",
"@polymech/core": "file:../core",
"@polymech/fs": "file:../fs",
"@polymech/log": "file:../log",
"axios": "1.7.9",
"chalk": "4.0.0",
"deepmerge-ts": "7.1.4",
"emojilib": "4.0.1",
"env-var": "7.5.0",
"free-astro-components": "1.1.1",
"glob": "11.0.1",
"marked": "14.1.4",
"marked-terminal": "7.2.1",
"mime-types": "2.1.35",
"openai": "4.84.0",
"p-map": "^4.0.0",
"openai": "4.85.3",
"p-map": "7.0.3",
"tslog": "^4.9.3",
"yargs": "17.7.2",
"zod": "3.24.1"
@ -65,6 +63,7 @@
"code-review"
],
"devDependencies": {
"@repo/typescript-config": "file:../typescript-config",
"@types/node": "22.10.2",
"@typescript-eslint/eslint-plugin": "^6.21.0",
"@typescript-eslint/parser": "^6.21.0",

View File

@ -5,7 +5,7 @@ import { createClient } from '../client'
import * as fs from 'fs'
vi.mock('fs')
vi.mock('@plastichub/osr-commons', () => ({
vi.mock('@polymech/osr-commons', () => ({
CONFIG_DEFAULT: () => ({
openrouter: { key: 'default-openrouter-key' },
openai: { key: 'default-openai-key' }

View File

@ -1,15 +1,15 @@
import { describe, it, expect, vi, beforeEach } from 'vitest'
import {resolve_package_path, template_path, load } from '../templates'
import { sync as exists } from '@plastichub/fs/exists'
import { sync as read } from '@plastichub/fs/read'
import { filesEx as include } from '@plastichub/osr-commons/_glob'
import { sync as exists } from '@polymech/fs/exists'
import { sync as read } from '@polymech/fs/read'
import { filesEx as include } from '@polymech/commons/_glob'
import * as path from 'path'
import { logger } from '../'
vi.mock('@plastichub/fs/exists')
vi.mock('@plastichub/fs/read')
vi.mock('@plastichub/osr-commons/_glob')
vi.mock('@plastichub/osr-commons', () => ({
vi.mock('@polymech/fs/exists')
vi.mock('@polymech/fs/read')
vi.mock('@polymech/commons/_glob')
vi.mock('@polymech/osr-commons', () => ({
resolve: vi.fn((path) => path),
substitute: vi.fn((x, y) => y)
}))

View File

@ -2,9 +2,9 @@ import path from 'path'
import OpenAI from 'openai'
//import { ChatCompletion, ChatCompletionMessage, ChatCompletionMessageParam } from 'openai/resources'
//import { } from 'openai/resources'
import { ICollector } from '@plastichub/osr-ai-tools/types'
import { winstonLogger, } from '@plastichub/osr-log'
import { resolve } from '@plastichub/osr-commons'
import { ICollector } from '@polymech/osr-ai-tools/types'
import { winstonLogger, } from '@polymech/osr-log'
import { resolve } from '@polymech/osr-commons'
import { RunnableFunctionWithParse } from 'openai/lib/RunnableFunction'
import { IKBotOptions } from './zod_types'

View File

@ -1,12 +1,12 @@
import path from 'path'
import { sync as read } from '@plastichub/fs/read'
import { sync as write } from '@plastichub/fs/write'
import { sync as exists } from '@plastichub/fs/exists'
import { sync as read } from '@polymech/fs/read'
import { sync as write } from '@polymech/fs/write'
import { sync as exists } from '@polymech/fs/exists'
import { logger } from '../'
import { fetchOpenAIModels } from '../models/openai'
import { fetchOpenRouterModels, OpenRouterModel } from '../models/openrouter'
import { CONFIG_DEFAULT } from '@plastichub/osr-commons'
import { CONFIG_DEFAULT } from '@polymech/osr-commons'
import { arch } from 'os'
export const build = async () => {

View File

@ -1,9 +1,9 @@
import path from 'path'
import { sync as write } from '@plastichub/fs/write'
import { sync as write } from '@polymech/fs/write'
import { logger, module_root } from '..'
import { fetchOpenAIModels } from '../models/openai'
import { fetchOpenRouterModels } from '../models/openrouter'
import { CONFIG_DEFAULT } from '@plastichub/osr-commons'
import { CONFIG_DEFAULT } from '@polymech/osr-commons'
export const fetch = async () => {

View File

@ -1,6 +1,6 @@
import { BaseHandler } from './base-handler'
import * as path from 'path'
import { sync as read } from '@plastichub/fs/read'
import { sync as read } from '@polymech/fs/read'
import { createClient } from '../../client'
import { logger } from '../../index'
import { toFile } from 'openai'

View File

@ -2,7 +2,7 @@ import { IHandler } from './base-handler'
import { TextHandler } from './text-handler'
import { AudioHandler } from './audio-handler'
import { ImageHandler } from './image-handler'
import { sync as exists } from '@plastichub/fs/exists'
import { sync as exists } from '@polymech/fs/exists'
import * as path from 'path'
import { IKBotOptions } from '../../zod_types'

View File

@ -1,5 +1,5 @@
import { BaseHandler } from './base-handler';
import { sync as read } from '@plastichub/fs/read';
import { sync as read } from '@polymech/fs/read';
import * as path from 'path';
export class TextHandler extends BaseHandler {

View File

@ -2,7 +2,7 @@ import { marked } from 'marked'
import { markedTerminal } from 'marked-terminal'
import { OptionsSchema } from '../zod_schema'
import { getDefaultValue, getDescription } from '@plastichub/osr-commons'
import { getDefaultValue, getDescription } from '@polymech/osr-commons'
import { z } from 'zod'
export const help = () => {

View File

@ -1,6 +1,6 @@
import { sync as dir } from '@plastichub/fs/dir'
import { sync as exists } from '@plastichub/fs/exists'
import { sync as write } from '@plastichub/fs/write'
import { sync as dir } from '@polymech/fs/dir'
import { sync as exists } from '@polymech/fs/exists'
import { sync as write } from '@polymech/fs/write'
import * as path from 'path'
import { IKBotTask } from '../types'
import { Logger } from 'tslog'

View File

@ -1,5 +1,5 @@
import * as path from 'path'
import { sync as read } from '@plastichub/fs/read'
import { sync as exists } from '@plastichub/fs/exists'
import { sync as read } from '@polymech/fs/read'
import { sync as exists } from '@polymech/fs/exists'
import { Logger } from 'tslog'
import { logger } from '../'

View File

@ -3,8 +3,8 @@ import OpenAI from 'openai'
import { marked } from 'marked'
import { markedTerminal } from 'marked-terminal'
import * as path from 'path'
import { sync as write } from '@plastichub/fs/write'
import { resolve } from '@plastichub/osr-commons'
import { sync as write } from '@polymech/fs/write'
import { resolve } from '@polymech/osr-commons'
import { logger } from '../'
import { dumpAsScript } from '../utils/script'
import { applyFilters, Filter } from '../filters'

View File

@ -1,8 +1,8 @@
import { globSync } from 'glob'
import * as path from 'path'
import { forward_slash } from '@plastichub/osr-commons'
import { forward_slash } from '@polymech/osr-commons'
import { logger } from '../'
import { IKBotTask } from '@plastichub/osr-ai-tools/types'
import { IKBotTask } from '@polymech/osr-ai-tools/types'
export const runEach = async (opts: IKBotTask, processRun: (args: IKBotTask) => Promise<any>) => {
const ret = []

View File

@ -1,11 +1,11 @@
import * as path from 'path'
import { hasMagic } from 'glob'
import { sync as dir } from '@plastichub/fs/dir'
import { sync as exists } from '@plastichub/fs/exists'
import { sync as write } from '@plastichub/fs/write'
import { sync as read } from '@plastichub/fs/read'
import { forward_slash, resolve, isFile, isFolder, pathInfoEx } from '@plastichub/osr-commons'
import { isArray, isString } from '@plastichub/core/primitives'
import { sync as dir } from '@polymech/fs/dir'
import { sync as exists } from '@polymech/fs/exists'
import { sync as write } from '@polymech/fs/write'
import { sync as read } from '@polymech/fs/read'
import { forward_slash, resolve, isFile, isFolder, pathInfoEx } from '@polymech/osr-commons'
import { isArray, isString } from '@polymech/core/primitives'
import { ChatCompletionToolRunnerParams } from 'openai/lib/ChatCompletionRunner'
import { ChatCompletionMessageParam } from 'openai/resources/index.mjs'
import { logger } from '../'
@ -23,7 +23,7 @@ import { EMode } from '../zod_schema'
import { runCompletion } from './run-completion'
import { runTools } from './run-tools'
import { runAssistant } from './run-assistant'
import { IKBotTask } from '@plastichub/osr-ai-tools/types'
import { IKBotTask } from '@polymech/osr-ai-tools/types'
import { all } from '../models'
export const processRun = async (opts: IKBotTask) => {

View File

@ -1,9 +1,9 @@
import * as fs from 'fs'
import * as path from 'path'
import { CONFIG_DEFAULT, resolve } from '@plastichub/osr-commons'
import { CONFIG_DEFAULT, resolve } from '@polymech/osr-commons'
import { logger } from './index'
import { sync as exists } from '@plastichub/fs/exists'
import { sync as read } from '@plastichub/fs/read'
import { sync as exists } from '@polymech/fs/exists'
import { sync as read } from '@polymech/fs/read'
import { IKBotOptions } from './zod_types'
import { env_vars } from './utils/env'
export const loadConfig = (options: IKBotOptions) => {

View File

@ -1,4 +1,4 @@
import { isString } from '@plastichub/core/primitives'
import { isString } from '@polymech/core/primitives'
import { logger } from './'
export type Filter = (json: string) => any

View File

@ -1,8 +1,8 @@
import path from 'path'
import { Logger } from 'tslog'
import { createLogger } from '@plastichub/osr-log'
import { CONFIG_DEFAULT, get_var } from '@plastichub/osr-commons'
import { createLogger } from '@polymech/osr-log'
import { CONFIG_DEFAULT, get_var } from '@polymech/osr-commons'
import { MODULE_NAME } from './constants'
export const logger: Logger<unknown> = createLogger('llm-tools')
export { run } from './commands/run'

View File

@ -3,10 +3,10 @@ import yargs from 'yargs'
import { hideBin } from 'yargs/helpers'
import { run } from './commands/run'
import { Logger } from 'tslog'
import { createLogger } from '@plastichub/osr-log'
import { createLogger } from '@polymech/osr-log'
import { OptionsSchema, types } from './zod_schema'
import { IKBotTask } from './types'
import { toYargs } from '@plastichub/osr-commons'
import { toYargs } from '@polymech/osr-commons'
import helpCommand from './commands/help'
import { examples } from './commands/examples'
import { init } from './commands/init'

View File

@ -1,5 +1,5 @@
import { isString } from '@plastichub/core/primitives'
import { sync as read } from '@plastichub/fs/read'
import { isString } from '@polymech/core/primitives'
import { sync as read } from '@polymech/fs/read'
import { logger } from '..'
import { deepmerge as merge } from 'deepmerge-ts'
export const deepMerge = async (target: string, source: any) => {

View File

@ -1,6 +1,6 @@
import * as path from 'path'
import { base64 } from './source'
import { sync as read } from '@plastichub/fs/read'
import { sync as read } from '@polymech/fs/read'
import { ChatCompletionUserMessageParam } from 'openai/resources/index.mjs'
export type IHandlerResult = ChatCompletionUserMessageParam &

View File

@ -1,15 +1,15 @@
import { z } from 'zod'
import chalk from 'chalk'
import * as path from 'path'
import { resolve } from '@plastichub/osr-commons'
import { sync as read } from '@plastichub/fs/read'
import { sync as exists } from '@plastichub/fs/exists'
import { resolve } from '@polymech/osr-commons'
import { sync as read } from '@polymech/fs/read'
import { sync as exists } from '@polymech/fs/exists'
import { logger, module_root } from '../index'
import { CACHE_PATH as OPENROUTER_CACHE_PATH, CachedModels as OpenRouterCachedModels, fetchOpenRouterModels, listModelsAsStrings as listOpenRouterModelsAsStrings } from './openrouter'
import { CACHE_PATH as OPENAI_CACHE_PATH, CachedModels as OpenAICachedModels, listModelsAsStrings as listOpenAIModelsAsStrings } from './openai'
import { fetchOpenAIModels } from '../models/openai'
import { CONFIG_DEFAULT } from '@plastichub/osr-commons'
import { CONFIG_DEFAULT } from '@polymech/osr-commons'
import { models as OpenAIModels } from './cache/openai'
import { models as OpenRouterModels } from './cache/openrouter'

View File

@ -2,10 +2,10 @@ import { OpenAI } from 'openai'
import * as fs from 'fs'
import * as path from 'path'
import { logger } from '../index'
import { sync as dir } from '@plastichub/fs/dir'
import { sync as exists } from '@plastichub/fs/exists'
import { sync as read } from '@plastichub/fs/read'
import { sync as write } from '@plastichub/fs/write'
import { sync as dir } from '@polymech/fs/dir'
import { sync as exists } from '@polymech/fs/exists'
import { sync as read } from '@polymech/fs/read'
import { sync as write } from '@polymech/fs/write'
interface OpenAIModel {
id: string;

View File

@ -1,10 +1,10 @@
import axios from 'axios'
import * as path from 'path';
import { logger } from '../index'
import { sync as dir } from '@plastichub/fs/dir'
import { sync as exists } from '@plastichub/fs/exists'
import { sync as read } from '@plastichub/fs/read'
import { sync as write } from '@plastichub/fs/write'
import { sync as dir } from '@polymech/fs/dir'
import { sync as exists } from '@polymech/fs/exists'
import { sync as read } from '@polymech/fs/read'
import { sync as write } from '@polymech/fs/write'
interface ModelPricing {
prompt: number;

View File

@ -1,8 +1,8 @@
import { IKBotTask } from "./types"
import { isFile, resolve } from '@plastichub/osr-commons'
import { sync as exists } from '@plastichub/fs/exists'
import { isFile, resolve } from '@polymech/osr-commons'
import { sync as exists } from '@polymech/fs/exists'
import * as path from 'node:path'
import { IProfile, parseProfile } from '@plastichub/osr-commons/profile'
import { IProfile, parseProfile } from '@polymech/commons/profile'
import { env_vars } from './utils/env'
const testPath = (profilePath: string) => {

View File

@ -1,9 +1,9 @@
import { IKBotTask } from '@plastichub/osr-ai-tools/types'
import { IKBotTask } from '@polymech/osr-ai-tools/types'
import { resolveQuery } from './utils/input'
import { ChatCompletionMessageParam } from 'openai/resources/index.mjs'
import { sync as read } from '@plastichub/fs/read'
import { sync as exists } from '@plastichub/fs/exists'
import { resolve } from '@plastichub/osr-commons'
import { sync as read } from '@polymech/fs/read'
import { sync as exists } from '@polymech/fs/exists'
import { resolve } from '@polymech/osr-commons'
import * as path from 'path'
import { env_vars } from './utils/env'
import { PREFERENCES_FILE_NAME } from './constants'

View File

@ -1,11 +1,11 @@
import * as path from 'path'
import * as fs from 'fs'
import { sync as read } from '@plastichub/fs/read'
import { sync as dir } from '@plastichub/fs/dir'
import { createItem as toNode } from '@plastichub/fs/inspect'
import { INode } from '@plastichub/fs/interfaces'
import { sync as exists } from '@plastichub/fs/exists'
import { isFile, forward_slash } from '@plastichub/osr-commons'
import { sync as read } from '@polymech/fs/read'
import { sync as dir } from '@polymech/fs/dir'
import { createItem as toNode } from '@polymech/fs/inspect'
import { INode } from '@polymech/fs/interfaces'
import { sync as exists } from '@polymech/fs/exists'
import { isFile, forward_slash } from '@polymech/osr-commons'
import { logger } from './index'
import { lookup } from 'mime-types'
import { globSync } from 'glob'

View File

@ -1,10 +1,10 @@
import { ChatCompletionMessageParam } from "openai/resources/chat/completions"
import { resolve } from '@plastichub/osr-commons'
import { } from '@plastichub/osr-commons/config'
import { sync as exists } from '@plastichub/fs/exists'
import { resolve } from '@polymech/osr-commons'
import { } from '@polymech/commons/config'
import { sync as exists } from '@polymech/fs/exists'
import * as path from 'node:path'
import { tools as defaultTools } from "@plastichub/osr-ai-tools/lib/tools/tools"
import { tools as defaultTools } from "@polymech/osr-ai-tools/lib/tools/tools"
import { logger } from './index'
import { IKBotOptions } from './zod_types'
import { RunnableToolFunctionWithParse } from "openai/lib/RunnableFunction"

View File

@ -6,7 +6,7 @@ export type onMessage = (category: string, name: string, args: any, result?: any
import { IKBotOptions } from './zod_types'
import OpenAI from 'openai'
import { ICollector } from '@plastichub/osr-ai-tools/types'
import { ICollector } from '@polymech/osr-ai-tools/types'
export interface IKBotTask extends IKBotOptions
{

View File

@ -1,13 +1,13 @@
import { describe, it, expect, vi, beforeEach } from 'vitest'
import { readProjectFiles } from '../file'
import { sync as dir } from '@plastichub/fs/dir'
import { sync as exists } from '@plastichub/fs/exists'
import { filesEx } from '@plastichub/osr-commons/_glob'
import { sync as dir } from '@polymech/fs/dir'
import { sync as exists } from '@polymech/fs/exists'
import { filesEx } from '@polymech/commons/_glob'
vi.mock('@plastichub/fs/dir')
vi.mock('@plastichub/fs/exists')
vi.mock('@plastichub/osr-commons/_glob')
vi.mock('@plastichub/fs/read')
vi.mock('@polymech/fs/dir')
vi.mock('@polymech/fs/exists')
vi.mock('@polymech/commons/_glob')
vi.mock('@polymech/fs/read')
vi.mock('path', async () => {
const actual = await vi.importActual('path')
return {

View File

@ -1,12 +1,12 @@
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'
import { resolveQuery, readStdin } from '../input'
import { detectAndHandle } from '../../commands/handlers'
import { sync as exists } from '@plastichub/fs/exists'
import { sync as read } from '@plastichub/fs/read'
import { sync as exists } from '@polymech/fs/exists'
import { sync as read } from '@polymech/fs/read'
import * as path from 'path'
vi.mock('@plastichub/fs/exists')
vi.mock('@plastichub/fs/read')
vi.mock('@polymech/fs/exists')
vi.mock('@polymech/fs/read')
vi.mock('../../commands/handlers')
vi.mock('path', async () => {
const actual = await vi.importActual('path')

View File

@ -1,9 +1,9 @@
import { describe, it, expect, vi, beforeAll, afterAll } from 'vitest'
import { dumpAsScript } from '../script'
import { sync as write } from '@plastichub/fs/write'
import { sync as write } from '@polymech/fs/write'
import * as path from 'path'
vi.mock('@plastichub/fs/write')
vi.mock('@polymech/fs/write')
vi.mock('path', async () => {
const actual = await vi.importActual('path')
return {

View File

@ -1,4 +1,4 @@
import { isString } from '@plastichub/core/primitives'
import { isString } from '@polymech/core/primitives'
export const flatten = (value: string | string[] | undefined): string[] => {
let initialArray: string[]

View File

@ -1,7 +1,7 @@
import * as path from 'path'
import { sync as exists } from '@plastichub/fs/exists'
import { sync as read } from '@plastichub/fs/read'
import { resolve, isFile } from '@plastichub/osr-commons'
import { sync as exists } from '@polymech/fs/exists'
import { sync as read } from '@polymech/fs/read'
import { resolve, isFile } from '@polymech/osr-commons'
import { detectAndHandle } from '../commands/handlers'
import { logger } from '../index'
import { IKBotOptions } from '../zod_types'

View File

@ -1,6 +1,6 @@
import * as path from 'path'
import { sync as write } from '@plastichub/fs/write'
import { resolve } from '@plastichub/osr-commons'
import { sync as write } from '@polymech/fs/write'
import { resolve } from '@polymech/osr-commons'
import { IKBotOptions } from '../zod_types'
export const dumpAsScript = async (opts: IKBotOptions) => {

View File

@ -1,16 +1,16 @@
import * as path from 'path'
import { pathInfoEx, resolve } from '@plastichub/osr-commons'
import { resolveConfig } from '@plastichub/core'
import { isString } from '@plastichub/core/primitives'
import { pathInfo, DEFAULT_ROOTS, DEFAULT_VARS } from '@plastichub/osr-commons'
import { pathInfoEx, resolve } from '@polymech/osr-commons'
import { resolveConfig } from '@polymech/core'
import { isString } from '@polymech/core/primitives'
import { pathInfo, DEFAULT_ROOTS, DEFAULT_VARS } from '@polymech/osr-commons'
import * as fs from 'fs'
import { sync as read } from '@plastichub/fs/read'
import { sync as dir } from '@plastichub/fs/dir'
import { createItem as toNode } from '@plastichub/fs/inspect'
import { INode } from '@plastichub/fs/interfaces'
import { sync as exists } from '@plastichub/fs/exists'
import { isFile, forward_slash } from '@plastichub/osr-commons'
import { sync as read } from '@polymech/fs/read'
import { sync as dir } from '@polymech/fs/dir'
import { createItem as toNode } from '@polymech/fs/inspect'
import { INode } from '@polymech/fs/interfaces'
import { sync as exists } from '@polymech/fs/exists'
import { isFile, forward_slash } from '@polymech/osr-commons'
import { logger } from './index'
import { lookup } from 'mime-types'
import { globSync } from 'glob'

View File

@ -2,10 +2,10 @@ import { z } from 'zod'
import * as path from 'path'
import chalk from 'chalk'
import * as env from 'env-var'
import { sync as writeFS } from '@plastichub/fs/write'
import { resolve } from '@plastichub/osr-commons'
import { generate_interfaces, write, ZodMetaMap } from '@plastichub/osr-commons'
import { isString } from '@plastichub/core/primitives'
import { sync as writeFS } from '@polymech/fs/write'
import { resolve } from '@polymech/osr-commons'
import { generate_interfaces, write, ZodMetaMap } from '@polymech/osr-commons'
import { isString } from '@polymech/core/primitives'
import { API_PREFIX, LOGGING_DIRECTORY, PREFERENCES_FILE_NAME } from './constants'

View File

@ -1,11 +1,7 @@
{
"extends": "../typescript-config/base.json",
"compilerOptions": {
"target": "ES2020",
"module": "CommonJS",
"esModuleInterop": true,
"strict": false,
"skipLibCheck": true,
"outDir": "./",
"outDir": "./dist-in",
"rootDir": "src",
"lib": [
"es2015",
@ -18,7 +14,9 @@
"importHelpers": false,
"inlineSourceMap": true
},
"exclude":["node_modules/**/*"],
"exclude": [
"node_modules/**/*"
],
"filesGlob": [
"./src/**/*.ts"
],
@ -26,4 +24,9 @@
"src/main.ts",
"src/index.ts"
],
"paths": {
"@/*": [
"src/*"
]
}
}