diff --git a/.husky/pre-commit b/.husky/pre-commit index 85e04b30..c90a5bea 100644 --- a/.husky/pre-commit +++ b/.husky/pre-commit @@ -1,2 +1,2 @@ yarn lint-staged -CI=true yarn lint && yarn run test:unit && yarn copyright +CI=true yarn lint && yarn ts:check && yarn run test:unit && yarn copyright diff --git a/.lintstagedrc.json b/.lintstagedrc.json index 325e2b51..7a273a66 100644 --- a/.lintstagedrc.json +++ b/.lintstagedrc.json @@ -1,5 +1,4 @@ { "*.{ts,js}": "eslint --fix", - "*.ts": "tsc-files --noEmit", "*": "prettier --ignore-unknown --write" } diff --git a/eslint.config.js b/eslint.config.js index 5e73ec51..e98a38ae 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -1,6 +1,5 @@ // @ts-check -// @ts-expect-error missing types import eslint from "@eslint/js"; import tseslint from "typescript-eslint"; import prettierConfig from "eslint-config-prettier"; @@ -70,11 +69,26 @@ export default tseslint.config( }, }, { - files: ["examples/**"], + files: ["examples/**/*.ts"], + languageOptions: { + parserOptions: { + project: "./tsconfig.examples.json", + }, + }, rules: { - "no-restricted-imports": "off", "@typescript-eslint/no-unused-vars": "off", "unused-imports/no-unused-vars": "off", + "no-restricted-imports": [ + "error", + { + patterns: [ + { + group: ["@/"], + message: "Use 'bee-agent-framework' instead.", + }, + ], + }, + ], }, }, // @ts-expect-error wrong types diff --git a/examples/agents/bee.ts b/examples/agents/bee.ts index 76094f92..50737d34 100644 --- a/examples/agents/bee.ts +++ b/examples/agents/bee.ts @@ -1,17 +1,17 @@ import "dotenv/config.js"; -import { BeeAgent } from "@/agents/bee/agent.js"; +import { BeeAgent } from "bee-agent-framework/agents/bee/agent"; import { createConsoleReader } from "../helpers/io.js"; -import { FrameworkError } from "@/errors.js"; -import { TokenMemory } from "@/memory/tokenMemory.js"; -import { Logger } from "@/logger/logger.js"; -import { PythonTool } from "@/tools/python/python.js"; -import { LocalPythonStorage } from "@/tools/python/storage.js"; -import { DuckDuckGoSearchTool } from "@/tools/search/duckDuckGoSearch.js"; -import { WikipediaTool } from "@/tools/search/wikipedia.js"; -import { OpenMeteoTool } from "@/tools/weather/openMeteo.js"; +import { FrameworkError } from "bee-agent-framework/errors"; +import { TokenMemory } from "bee-agent-framework/memory/tokenMemory"; +import { Logger } from "bee-agent-framework/logger/logger"; +import { PythonTool } from "bee-agent-framework/tools/python/python"; +import { LocalPythonStorage } from "bee-agent-framework/tools/python/storage"; +import { DuckDuckGoSearchTool } from "bee-agent-framework/tools/search/duckDuckGoSearch"; +import { WikipediaTool } from "bee-agent-framework/tools/search/wikipedia"; +import { OpenMeteoTool } from "bee-agent-framework/tools/weather/openMeteo"; import { dirname } from "node:path"; import { fileURLToPath } from "node:url"; -import { OllamaChatLLM } from "@/adapters/ollama/chat.js"; +import { OllamaChatLLM } from "bee-agent-framework/adapters/ollama/chat"; Logger.root.level = "silent"; // disable internal logs const logger = new Logger({ name: "app", level: "trace" }); diff --git a/examples/agents/bee_reusable.ts b/examples/agents/bee_reusable.ts index 2f315d03..799e0a02 100644 --- a/examples/agents/bee_reusable.ts +++ b/examples/agents/bee_reusable.ts @@ -1,8 +1,8 @@ import "dotenv/config.js"; -import { BeeAgent } from "@/agents/bee/agent.js"; -import { DuckDuckGoSearchTool } from "@/tools/search/duckDuckGoSearch.js"; -import { UnconstrainedMemory } from "@/memory/unconstrainedMemory.js"; -import { OpenAIChatLLM } from "@/adapters/openai/chat.js"; +import { BeeAgent } from "bee-agent-framework/agents/bee/agent"; +import { DuckDuckGoSearchTool } from "bee-agent-framework/tools/search/duckDuckGoSearch"; +import { UnconstrainedMemory } from "bee-agent-framework/memory/unconstrainedMemory"; +import { OpenAIChatLLM } from "bee-agent-framework/adapters/openai/chat"; // We create an agent let agent = new BeeAgent({ diff --git a/examples/agents/simple.ts b/examples/agents/simple.ts index 9566bcbb..af4161f5 100644 --- a/examples/agents/simple.ts +++ b/examples/agents/simple.ts @@ -1,9 +1,9 @@ import "dotenv/config.js"; -import { BeeAgent } from "@/agents/bee/agent.js"; -import { TokenMemory } from "@/memory/tokenMemory.js"; -import { DuckDuckGoSearchTool } from "@/tools/search/duckDuckGoSearch.js"; -import { OllamaChatLLM } from "@/adapters/ollama/chat.js"; -import { OpenMeteoTool } from "@/tools/weather/openMeteo.js"; +import { BeeAgent } from "bee-agent-framework/agents/bee/agent"; +import { TokenMemory } from "bee-agent-framework/memory/tokenMemory"; +import { DuckDuckGoSearchTool } from "bee-agent-framework/tools/search/duckDuckGoSearch"; +import { OllamaChatLLM } from "bee-agent-framework/adapters/ollama/chat"; +import { OpenMeteoTool } from "bee-agent-framework/tools/weather/openMeteo"; const llm = new OllamaChatLLM(); const agent = new BeeAgent({ diff --git a/examples/helpers/setup.ts b/examples/helpers/setup.ts index 3286e2c5..3ca01d34 100644 --- a/examples/helpers/setup.ts +++ b/examples/helpers/setup.ts @@ -1,4 +1,4 @@ import "dotenv/config"; -import { Logger } from "@/logger/logger.js"; +import { Logger } from "bee-agent-framework/logger/logger"; Logger.defaults.pretty = true; diff --git a/examples/llms/chat.ts b/examples/llms/chat.ts index 79d09cab..80c411aa 100644 --- a/examples/llms/chat.ts +++ b/examples/llms/chat.ts @@ -1,8 +1,8 @@ import "dotenv/config.js"; import { createConsoleReader } from "examples/helpers/io.js"; -import { Logger } from "@/logger/logger.js"; -import { BaseMessage, Role } from "@/llms/primitives/message.js"; -import { OllamaChatLLM } from "@/adapters/ollama/chat.js"; +import { Logger } from "bee-agent-framework/logger/logger"; +import { BaseMessage, Role } from "bee-agent-framework/llms/primitives/message"; +import { OllamaChatLLM } from "bee-agent-framework/adapters/ollama/chat"; Logger.root.level = "info"; // or your custom level diff --git a/examples/llms/chatCallback.ts b/examples/llms/chatCallback.ts index 8ccc9b90..d0c320ab 100644 --- a/examples/llms/chatCallback.ts +++ b/examples/llms/chatCallback.ts @@ -1,8 +1,8 @@ import "dotenv/config.js"; import { createConsoleReader } from "examples/helpers/io.js"; -import { Logger } from "@/logger/logger.js"; -import { BaseMessage, Role } from "@/llms/primitives/message.js"; -import { OllamaChatLLM } from "@/adapters/ollama/chat.js"; +import { Logger } from "bee-agent-framework/logger/logger"; +import { BaseMessage, Role } from "bee-agent-framework/llms/primitives/message"; +import { OllamaChatLLM } from "bee-agent-framework/adapters/ollama/chat"; Logger.root.level = "info"; // or your custom level diff --git a/examples/llms/chatStream.ts b/examples/llms/chatStream.ts index 8d779486..e1cafcd6 100644 --- a/examples/llms/chatStream.ts +++ b/examples/llms/chatStream.ts @@ -1,8 +1,8 @@ import "dotenv/config.js"; import { createConsoleReader } from "examples/helpers/io.js"; -import { Logger } from "@/logger/logger.js"; -import { BaseMessage, Role } from "@/llms/primitives/message.js"; -import { OllamaChatLLM } from "@/adapters/ollama/chat.js"; +import { Logger } from "bee-agent-framework/logger/logger"; +import { BaseMessage, Role } from "bee-agent-framework/llms/primitives/message"; +import { OllamaChatLLM } from "bee-agent-framework/adapters/ollama/chat"; Logger.root.level = "info"; // or your custom level diff --git a/examples/llms/providers/bam.ts b/examples/llms/providers/bam.ts index 5e87dad4..ce550c67 100644 --- a/examples/llms/providers/bam.ts +++ b/examples/llms/providers/bam.ts @@ -1,6 +1,6 @@ -import { BaseMessage } from "@/llms/primitives/message.js"; -import { BAMLLM } from "@/adapters/bam/llm.js"; -import { BAMChatLLM } from "@/adapters/bam/chat.js"; +import { BaseMessage } from "bee-agent-framework/llms/primitives/message"; +import { BAMLLM } from "bee-agent-framework/adapters/bam/llm"; +import { BAMChatLLM } from "bee-agent-framework/adapters/bam/chat"; { console.info("===RAW==="); diff --git a/examples/llms/providers/langchain.ts b/examples/llms/providers/langchain.ts index 3bf48067..18c53f48 100644 --- a/examples/llms/providers/langchain.ts +++ b/examples/llms/providers/langchain.ts @@ -3,8 +3,8 @@ // - @langchain/cohere (or any other provider related package that you would like to use) // List of available providers: https://js.langchain.com/v0.2/docs/integrations/chat/ -import { BaseMessage } from "@/llms/primitives/message.js"; -import { LangChainChatLLM } from "@/adapters/langchain/llms/chat.js"; +import { BaseMessage } from "bee-agent-framework/llms/primitives/message"; +import { LangChainChatLLM } from "bee-agent-framework/adapters/langchain/llms/chat"; // @ts-expect-error package not installed import { ChatCohere } from "@langchain/cohere"; diff --git a/examples/llms/providers/ollama.ts b/examples/llms/providers/ollama.ts index 200b1755..1d2fef77 100644 --- a/examples/llms/providers/ollama.ts +++ b/examples/llms/providers/ollama.ts @@ -1,6 +1,6 @@ -import { OllamaLLM } from "@/adapters/ollama/llm.js"; -import { OllamaChatLLM } from "@/adapters/ollama/chat.js"; -import { BaseMessage } from "@/llms/primitives/message.js"; +import { OllamaLLM } from "bee-agent-framework/adapters/ollama/llm"; +import { OllamaChatLLM } from "bee-agent-framework/adapters/ollama/chat"; +import { BaseMessage } from "bee-agent-framework/llms/primitives/message"; { console.info("===RAW==="); diff --git a/examples/llms/providers/openai.ts b/examples/llms/providers/openai.ts index 5b28ecbf..b56d0459 100644 --- a/examples/llms/providers/openai.ts +++ b/examples/llms/providers/openai.ts @@ -1,6 +1,6 @@ import "dotenv/config"; -import { BaseMessage } from "@/llms/primitives/message.js"; -import { OpenAIChatLLM } from "@/adapters/openai/chat.js"; +import { BaseMessage } from "bee-agent-framework/llms/primitives/message"; +import { OpenAIChatLLM } from "bee-agent-framework/adapters/openai/chat"; const llm = new OpenAIChatLLM({ modelId: "gpt-4o", diff --git a/examples/llms/providers/watsonx.ts b/examples/llms/providers/watsonx.ts index da37e574..44cba8b5 100644 --- a/examples/llms/providers/watsonx.ts +++ b/examples/llms/providers/watsonx.ts @@ -1,6 +1,6 @@ import "dotenv/config"; -import { BaseMessage } from "@/llms/primitives/message.js"; -import { WatsonXChatLLM } from "@/adapters/watsonx/chat.js"; +import { BaseMessage } from "bee-agent-framework/llms/primitives/message"; +import { WatsonXChatLLM } from "bee-agent-framework/adapters/watsonx/chat"; const chatLLM = WatsonXChatLLM.fromPreset("meta-llama/llama-3-1-70b-instruct", { apiKey: process.env.WATSONX_API_KEY, diff --git a/examples/llms/providers/watsonx_verbose.ts b/examples/llms/providers/watsonx_verbose.ts index 6ebff6cb..999ac80d 100644 --- a/examples/llms/providers/watsonx_verbose.ts +++ b/examples/llms/providers/watsonx_verbose.ts @@ -1,8 +1,8 @@ import "dotenv/config"; -import { BaseMessage } from "@/llms/primitives/message.js"; -import { WatsonXChatLLM } from "@/adapters/watsonx/chat.js"; -import { WatsonXLLM } from "@/adapters/watsonx/llm.js"; -import { PromptTemplate } from "@/template.js"; +import { BaseMessage } from "bee-agent-framework/llms/primitives/message"; +import { WatsonXChatLLM } from "bee-agent-framework/adapters/watsonx/chat"; +import { WatsonXLLM } from "bee-agent-framework/adapters/watsonx/llm"; +import { PromptTemplate } from "bee-agent-framework/template"; const template = new PromptTemplate({ variables: ["messages"], diff --git a/examples/llms/structured.ts b/examples/llms/structured.ts index 765010ee..4708e16a 100644 --- a/examples/llms/structured.ts +++ b/examples/llms/structured.ts @@ -1,7 +1,7 @@ import "dotenv/config.js"; import { z } from "zod"; -import { BaseMessage, Role } from "@/llms/primitives/message.js"; -import { OllamaChatLLM } from "@/adapters/ollama/chat.js"; +import { BaseMessage, Role } from "bee-agent-framework/llms/primitives/message"; +import { OllamaChatLLM } from "bee-agent-framework/adapters/ollama/chat"; const llm = new OllamaChatLLM(); const response = await llm.generateStructured( diff --git a/examples/llms/text.ts b/examples/llms/text.ts index ccc33a13..2d7fffe9 100644 --- a/examples/llms/text.ts +++ b/examples/llms/text.ts @@ -1,6 +1,6 @@ import "dotenv/config.js"; import { createConsoleReader } from "examples/helpers/io.js"; -import { WatsonXLLM } from "@/adapters/watsonx/llm.js"; +import { WatsonXLLM } from "bee-agent-framework/adapters/watsonx/llm"; const llm = new WatsonXLLM({ modelId: "google/flan-ul2", diff --git a/examples/template.ts b/examples/template.ts index cc77bc7c..d870dc16 100644 --- a/examples/template.ts +++ b/examples/template.ts @@ -1,6 +1,6 @@ -import "examples/helpers/setup.js"; -import { PromptTemplate } from "@/template.js"; -import { Logger } from "@/logger/logger.js"; +import "./helpers/setup.js"; +import { PromptTemplate } from "bee-agent-framework/template"; +import { Logger } from "bee-agent-framework/logger/logger"; const logger = new Logger({ name: "template" }); diff --git a/examples/tools/helloWorld.ts b/examples/tools/helloWorld.ts index a8a3b204..3669fe46 100644 --- a/examples/tools/helloWorld.ts +++ b/examples/tools/helloWorld.ts @@ -4,7 +4,7 @@ import { StringToolOutput, Tool, ToolInput, -} from "@/tools/base.js"; +} from "bee-agent-framework/tools/base"; import { z } from "zod"; type ToolOptions = BaseToolOptions; diff --git a/examples/tools/openLibrary.ts b/examples/tools/openLibrary.ts index 4b28fc37..79d6d0fb 100644 --- a/examples/tools/openLibrary.ts +++ b/examples/tools/openLibrary.ts @@ -5,9 +5,9 @@ import { ToolInput, JSONToolOutput, ToolError, -} from "@/tools/base.js"; +} from "bee-agent-framework/tools/base"; import { z } from "zod"; -import { createURLParams } from "@/internals/fetcher.js"; +import { createURLParams } from "bee-agent-framework/internals/fetcher"; type ToolOptions = BaseToolOptions; type ToolRunOptions = BaseToolRunOptions; @@ -117,7 +117,7 @@ export class OpenLibraryTool extends Tool, options?: ToolRunOptions) { const params = createURLParams(input); - const url = `https://openlibrary.org/search.json?${decodeURIComponent(params.toString())}`; + const url = `https://openlibrary.org/searchon?${decodeURIComponent(params.toString())}`; const response = await fetch(url, { signal: options?.signal, }); diff --git a/examples/tsconfig.json b/examples/tsconfig.json new file mode 100644 index 00000000..e0fca6a2 --- /dev/null +++ b/examples/tsconfig.json @@ -0,0 +1,13 @@ +{ + "extends": "../tsconfig.json", + "compilerOptions": { + "baseUrl": "..", + "rootDir": "..", + "paths": { + "bee-agent-framework/*": ["./src/*.js"], + "@/*": ["./src/*"] + } + }, + "references": [{ "path": "./src" }], + "exclude": ["../tests", "../**/*.test.ts"] +} diff --git a/package.json b/package.json index 42e3528f..a8e89c4b 100644 --- a/package.json +++ b/package.json @@ -54,8 +54,9 @@ "scripts": { "clean": "rimraf dist", "build": "yarn clean && yarn ts:check && tsup", - "ts:check": "tsc --noEmit", - "start:bee": "tsx examples/agents/bee.ts", + "ts:check": "tsc --noEmit && tsc -p tsconfig.examples.json --noEmit", + "start": "tsx --tsconfig tsconfig.examples.json", + "start:bee": "yarn start -- examples/agents/bee.ts", "infra:start-all": "yarn _docker compose up -d", "infra:start-code-interpreter": "yarn _docker compose up bee-code-interpreter", "infra:stop-all": "yarn _docker compose down", @@ -126,6 +127,7 @@ "@swc/core": "^1.7.14", "@types/eslint": "^9.6.1", "@types/eslint-config-prettier": "^6.11.3", + "@types/eslint__js": "^8.42.3", "@types/mustache": "^4", "@types/needle": "^3.3.0", "@types/node": "^20.16.1", @@ -154,7 +156,7 @@ "temp-dir": "^3.0.0", "tsc-files": "^1.1.4", "tsup": "^8.2.4", - "tsx": "^4.17.0", + "tsx": "^4.19.0", "typescript": "^5.5.4", "typescript-eslint": "^8.2.0", "vite-tsconfig-paths": "^5.0.1", diff --git a/tsconfig.examples.json b/tsconfig.examples.json new file mode 100644 index 00000000..4a701427 --- /dev/null +++ b/tsconfig.examples.json @@ -0,0 +1,3 @@ +{ + "extends": "./examples/tsconfig.json" +} diff --git a/tsconfig.json b/tsconfig.json index ac40f78a..e874ce6d 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -29,5 +29,6 @@ "@tests/*": ["./tests/*"] }, "useUnknownInCatchVariables": false - } + }, + "exclude": ["examples"] } diff --git a/vitest.config.ts b/vitest.config.ts index eaf7f3d2..3b98d0ca 100644 --- a/vitest.config.ts +++ b/vitest.config.ts @@ -16,5 +16,9 @@ export default defineConfig({ define: { __LIBRARY_VERSION: JSON.stringify(packageJson.version), }, - plugins: [tsConfigPaths()], + plugins: [ + tsConfigPaths({ + projects: ["tsconfig.json"], + }), + ], }); diff --git a/yarn.lock b/yarn.lock index 07c7dea3..d46cfe81 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1836,7 +1836,7 @@ __metadata: languageName: node linkType: hard -"@types/eslint@npm:^9.6.1": +"@types/eslint@npm:*, @types/eslint@npm:^9.6.1": version: 9.6.1 resolution: "@types/eslint@npm:9.6.1" dependencies: @@ -1846,6 +1846,15 @@ __metadata: languageName: node linkType: hard +"@types/eslint__js@npm:^8.42.3": + version: 8.42.3 + resolution: "@types/eslint__js@npm:8.42.3" + dependencies: + "@types/eslint": "npm:*" + checksum: 10c0/ccc5180b92155929a089ffb03ed62625216dcd5e46dd3197c6f82370ce8b52c7cb9df66c06b0a3017995409e023bc9eafe5a3f009e391960eacefaa1b62d9a56 + languageName: node + linkType: hard + "@types/estree@npm:*, @types/estree@npm:1.0.5, @types/estree@npm:^1.0.0": version: 1.0.5 resolution: "@types/estree@npm:1.0.5" @@ -2508,6 +2517,7 @@ __metadata: "@swc/core": "npm:^1.7.14" "@types/eslint": "npm:^9.6.1" "@types/eslint-config-prettier": "npm:^6.11.3" + "@types/eslint__js": "npm:^8.42.3" "@types/mustache": "npm:^4" "@types/needle": "npm:^3.3.0" "@types/node": "npm:^20.16.1" @@ -2554,7 +2564,7 @@ __metadata: temp-dir: "npm:^3.0.0" tsc-files: "npm:^1.1.4" tsup: "npm:^8.2.4" - tsx: "npm:^4.17.0" + tsx: "npm:^4.19.0" turndown: "npm:^7.2.0" typescript: "npm:^5.5.4" typescript-eslint: "npm:^8.2.0" @@ -8949,9 +8959,9 @@ __metadata: languageName: node linkType: hard -"tsx@npm:^4.17.0": - version: 4.17.0 - resolution: "tsx@npm:4.17.0" +"tsx@npm:^4.19.0": + version: 4.19.0 + resolution: "tsx@npm:4.19.0" dependencies: esbuild: "npm:~0.23.0" fsevents: "npm:~2.3.3" @@ -8961,7 +8971,7 @@ __metadata: optional: true bin: tsx: dist/cli.mjs - checksum: 10c0/ad720b81d6447c7695d24c27947fa1a2b6db9d2ef03216389edd6fa0006aa479bc0d8348a1ac9975a08edef4ce791ff5629a24d8dccbb0987f42e5407785cfa4 + checksum: 10c0/d14463a78067c6db84c677b79b14861de6d7f6fb0ffa5727cc500c4552459e936395a3854ad0112af0fd7b263bcedd62ce3929b036188eb10cd9902a607ffe34 languageName: node linkType: hard