-
Notifications
You must be signed in to change notification settings - Fork 26
Add SDK exports as library + fix dependencies #105
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add SDK exports as library + fix dependencies #105
Conversation
…lidateCLioptions into app folder
…tly use core/index.js for better separation
WalkthroughThis update introduces a centralized export structure ("barrel" files) throughout the core modules, consolidates logger imports, and updates TypeScript and build configurations for improved module resolution and typing. The build process transitions from Changes
Sequence Diagram(s)sequenceDiagram
participant Consumer as Consumer Module
participant CoreIndex as src/core/index.ts
participant Submodules as {logger, utils, ai, config, client, settings}
Consumer->>CoreIndex: import {...} from '@core/index.js'
CoreIndex->>Submodules: re-export all public APIs
Submodules-->>CoreIndex: expose module exports
CoreIndex-->>Consumer: provide unified API surface
sequenceDiagram
participant Dev as Developer
participant Build as Build System (tsup)
participant Output as dist/
participant Consumer as Consumer Project
Dev->>Build: Run build script (tsup)
Build->>Output: Generate CJS/ESM bundles, types, maps
Consumer->>Output: import from core/app entry points
Output-->>Consumer: Provide correct module format and typings
Poem
Note ⚡️ AI Code Reviews for VS Code, Cursor, WindsurfCodeRabbit now has a plugin for VS Code, Cursor and Windsurf. This brings AI code reviews directly in the code editor. Each commit is reviewed immediately, finding bugs before the PR is raised. Seamless context handoff to your AI code agent ensures that you can easily incorporate review feedback. Note ⚡️ Faster reviews with cachingCodeRabbit now supports caching for code and dependencies, helping speed up reviews. This means quicker feedback, reduced wait times, and a smoother review experience overall. Cached data is encrypted and stored securely. This feature will be automatically enabled for all accounts on May 16th. To opt out, configure ✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
…okie and undici dependneices for discord/telegram
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 3
🧹 Nitpick comments (13)
src/app/utils/options.ts (1)
2-3
: Combine duplicate imports from the same module.Currently, you have two separate imports from
@core/index.js
:import { logger } from '@core/index.js'; import { getSupportedProviders } from '@core/index.js';For clarity and to reduce duplication, merge them into one:
-import { logger } from '@core/index.js'; -import { getSupportedProviders } from '@core/index.js'; +import { logger, getSupportedProviders } from '@core/index.js';src/core/ai/llm/messages/manager.ts (1)
7-7
: Use the@core
alias instead of a relative path forlogger
.To keep imports consistent across the project (as seen in
src/app
), switch the relative import to the alias:-import { logger } from '../../../logger/index.js'; +import { logger } from '@core/logger';src/core/ai/llm/services/anthropic.ts (1)
5-5
: Use the@core
alias instead of a relative path forlogger
.Align this import with the centralized barrel exports:
-import { logger } from '../../../logger/index.js'; +import { logger } from '@core/logger';src/core/ai/llm/tokenizer/openai.ts (1)
3-3
: Use the@core
alias instead of a relative path forlogger
.For uniformity and clarity:
-import { logger } from '../../../logger/index.js'; +import { logger } from '@core/logger';src/core/ai/systemPrompt/manager.ts (1)
8-8
: Use the@core
alias instead of a relative path forlogger
.To maintain consistency with the rest of the codebase:
-import { logger } from '../../logger/index.js'; +import { logger } from '@core/logger';src/app/api/a2a.ts (1)
2-3
: Nit: Combine type and value imports.
For brevity and clarity, you can merge these into one statement:import { logger, type AgentCard } from '@core/index.js';src/app/api/mcp_handler.ts (1)
5-6
: Nit: Consolidate type imports.
Consider grouping all type-only imports and separating value imports:import type { AgentCard, SaikiAgent } from '@core/index.js'; import { logger } from '@core/index.js';This adheres to TS best practices and enhances readability.
Also applies to: 9-9
src/app/api/server.ts (1)
6-13
: Nit: Group and reorder imports from@core
.
For better import hygiene, separate type-only imports and consolidate values:import type { AgentCard } from '@core/index.js'; import { logger, createAgentCard, SaikiAgent } from '@core/index.js';Also, grouping all
@core
imports together makes the dependency structure clearer.src/app/web/server.ts (1)
2-4
: Nit: Consolidate@core
imports.
You can merge these into grouped statements for clarity:import { logger, resolvePackagePath, SaikiAgent } from '@core/index.js'; import type { AgentCard } from '@core/index.js';This streamlines the import section and separates types from values.
Also applies to: 6-7
tsconfig.json (1)
18-20
: Evaluate necessity ofDOM
library and declaration options.
Enabling"declaration"
and"declarationMap"
is essential for distributing typings. However, including the"DOM"
lib may introduce unnecessary browser globals if your core modules run only in Node. Consider removing"DOM"
if it isn’t required by your runtime or tests.src/core/utils/service-initializer.ts (1)
96-100
: Conditional application of CLI overrides.The code now conditionally applies CLI overrides only when they're provided, which is a logical consequence of making the
cliArgs
parameter optional. This makes the function more robust.This could be slightly simplified using optional chaining:
- const configManager = new ConfigManager(rawConfig); - if (cliArgs) { - configManager.overrideCLI(cliArgs); - } + const configManager = new ConfigManager(rawConfig); + cliArgs && configManager.overrideCLI(cliArgs);src/TESTING.md (2)
12-12
: Add language specifiers to fenced code blocks
Fenced code blocks at these positions have no language hint, which hinders readability and triggers markdownlint MD040. Please update as follows (usetext
for plain output andbash
for shell commands):- ``` + ```text // for output-only blocks (e.g., the tarball name)- ``` + ```bash // for shell command snippetsRepeat for lines 82, 88, and 95.
Also applies to: 82-82, 88-88, 95-95
🧰 Tools
🪛 markdownlint-cli2 (0.17.2)
12-12: Fenced code blocks should have a language specified
null(MD040, fenced-code-language)
77-77
: Fix grammatical number agreement
The sentence at line 77 should read “No errors mean that …” instead of “No errors means …”:- No errors means your `"types"` export is wired up correctly. + No errors mean that your `"types"` export is wired up correctly.🧰 Tools
🪛 LanguageTool
[grammar] ~77-~77: You should probably use “mean”.
Context: ...ash npx tsc ``` No errors means your"types"
export is wired up corre...(AGREEMENT_SENT_START)
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
Cache: Disabled due to data retention organization setting
Knowledge Base: Disabled due to data retention organization setting
⛔ Files ignored due to path filters (1)
package-lock.json
is excluded by!**/package-lock.json
📒 Files selected for processing (44)
package.json
(2 hunks)src/TESTING.md
(1 hunks)src/app/api/a2a.ts
(1 hunks)src/app/api/mcp_handler.ts
(1 hunks)src/app/api/server.ts
(1 hunks)src/app/cli/cli-subscriber.ts
(1 hunks)src/app/cli/cli.ts
(1 hunks)src/app/discord/bot.ts
(1 hunks)src/app/index.ts
(1 hunks)src/app/telegram/bot.ts
(1 hunks)src/app/utils/options.ts
(1 hunks)src/app/web/server.ts
(1 hunks)src/core/ai/agent/SaikiAgent.ts
(1 hunks)src/core/ai/agent/index.ts
(1 hunks)src/core/ai/index.ts
(1 hunks)src/core/ai/llm/index.ts
(1 hunks)src/core/ai/llm/messages/factory.ts
(1 hunks)src/core/ai/llm/messages/formatters/anthropic.ts
(1 hunks)src/core/ai/llm/messages/formatters/factory.ts
(1 hunks)src/core/ai/llm/messages/index.ts
(1 hunks)src/core/ai/llm/messages/manager.ts
(1 hunks)src/core/ai/llm/registry.ts
(1 hunks)src/core/ai/llm/services/anthropic.ts
(1 hunks)src/core/ai/llm/services/factory.ts
(1 hunks)src/core/ai/llm/services/index.ts
(1 hunks)src/core/ai/llm/services/openai.ts
(1 hunks)src/core/ai/llm/services/vercel.ts
(1 hunks)src/core/ai/llm/tokenizer/openai.ts
(1 hunks)src/core/ai/systemPrompt/manager.ts
(1 hunks)src/core/client/index.ts
(1 hunks)src/core/client/manager.ts
(1 hunks)src/core/client/mcp-client.ts
(1 hunks)src/core/client/tool-confirmation/cli-confirmation-provider.ts
(1 hunks)src/core/config/index.ts
(1 hunks)src/core/config/loader.ts
(1 hunks)src/core/config/manager.ts
(1 hunks)src/core/index.ts
(1 hunks)src/core/logger/index.ts
(1 hunks)src/core/logger/logger.test.ts
(1 hunks)src/core/settings/index.ts
(1 hunks)src/core/utils/index.ts
(1 hunks)src/core/utils/service-initializer.ts
(2 hunks)tsconfig.json
(1 hunks)tsup.config.ts
(1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
src/core/utils/service-initializer.ts (3)
src/core/config/types.ts (1)
CLIConfigOverrides
(17-17)src/core/config/loader.ts (1)
loadConfigFile
(36-63)src/core/config/manager.ts (1)
ConfigManager
(18-156)
🪛 LanguageTool
src/TESTING.md
[grammar] ~77-~77: You should probably use “mean”.
Context: ...ash npx tsc ``` No errors means your "types"
export is wired up corre...
(AGREEMENT_SENT_START)
🪛 markdownlint-cli2 (0.17.2)
src/TESTING.md
12-12: Fenced code blocks should have a language specified
null
(MD040, fenced-code-language)
82-82: Fenced code blocks should have a language specified
null
(MD040, fenced-code-language)
88-88: Fenced code blocks should have a language specified
null
(MD040, fenced-code-language)
95-95: Fenced code blocks should have a language specified
null
(MD040, fenced-code-language)
🔇 Additional comments (43)
src/core/config/loader.ts (1)
6-6
: Import path updated for centralized logger module
The import oflogger
has been refactored to point to the new barrel at../logger/index.js
, aligning with the modular restructuring. Ensure thatsrc/core/logger/index.ts
correctly re-exports thelogger
instance.src/core/ai/llm/messages/factory.ts (1)
7-7
: Aligned logger import to new barrel file
Updated thelogger
import path to use../../../logger/index.js
, consistent with the centralized logger export. Confirm that no residual imports remain referencing the old path.src/core/client/tool-confirmation/cli-confirmation-provider.ts (1)
2-2
: CLI logger import path updated
Thelogger
import now points to the new../../logger/index.js
barrel file. Verify that other client modules have undergone the same update for consistency.src/core/ai/llm/registry.ts (1)
1-1
: Central logger import applied
Import path forlogger
has been redirected to../../logger/index.js
. This matches the new structure—ensure the logger barrel exports the same API as before.src/core/ai/agent/SaikiAgent.ts (1)
9-9
: Updated logger import in SaikiAgent
Switched thelogger
import to../../logger/index.js
to use the centralized barrel module. Confirm that the barrel aggregates the appropriate logging interfaces.src/core/ai/llm/messages/formatters/factory.ts (1)
5-5
: Import path correctly aligned with new barrel.
Thelogger
import now points to the centralizedsrc/core/logger/index.js
, matching your refactoring across core modules.src/app/cli/cli-subscriber.ts (1)
1-1
: Switched to alias import for centralized logger.
Using@core/index.js
clarifies the origin of the logger utility and leverages the new barrel file. Ensure yourtsconfig.json
and build config (tsup.config.ts
) resolve this alias correctly.src/core/logger/logger.test.ts (1)
2-2
: Updated test to use barrel export.
ImportingLogger
andlogger
from../logger/index.js
keeps tests in sync with the reorganized core logger module.src/core/ai/llm/services/factory.ts (1)
4-4
: Centralized logger import updated.
Switching to'../../../logger/index.js'
aligns with the new core directory structure and barrel exports. No logic changes here.src/core/client/manager.ts (1)
3-3
: Consistent import for centralized logger.
The import path forlogger
has been updated to the new barrel file location (src/core/logger/index.ts
), aligning with the project-wide refactoring for centralized and cleaner imports.src/core/ai/llm/messages/formatters/anthropic.ts (1)
3-3
: Aligned logger import to new barrel.
Thelogger
import now points to the centralizedsrc/core/logger/index.js
barrel, ensuring consistency with other modules and simplifying maintenance.src/core/client/mcp-client.ts (1)
6-6
: Updated logger import path.
This change synchronizes the import oflogger
with the new barrel atsrc/core/logger/index.js
, matching the updated module layout.src/core/ai/llm/services/vercel.ts (1)
3-3
: Standardized logger import.
The import oflogger
is redirected to the centralizedsrc/core/logger/index.js
barrel, in line with the codebase-wide import restructuring.src/core/config/manager.ts (1)
2-2
: Centralized logger import applied.
Switching toimport { logger } from '../logger/index.js'
ensures this module uses the new barrel file for logging utilities, fostering uniform import patterns.src/app/api/a2a.ts (1)
2-3
: Refactored imports to use the@core
alias.
Switching from relative paths to the centralized barrel file improves maintainability and consistency across the codebase.src/app/api/mcp_handler.ts (1)
5-6
: Centralized core imports via@core
alias.
Adopting the barrel export forAgentCard
,logger
, andSaikiAgent
aligns with your modularization goals.Also applies to: 9-9
src/app/api/server.ts (1)
6-13
: Refactored to use@core
barrel exports.
All core entities (logger
,AgentCard
,createAgentCard
,SaikiAgent
) now pull from the centralized module, which improves modularity.src/app/web/server.ts (1)
2-4
: Updated core imports to use the alias.
Switching to the@core
barrel forlogger
,resolvePackagePath
,AgentCard
, andSaikiAgent
enhances consistency with the new module structure.Also applies to: 6-7
src/core/ai/agent/index.ts (1)
1-2
: Simple, effective barrel file implementation.This barrel file exports everything from the SaikiAgent module, allowing consumers to import from the directory level rather than specific files. This pattern simplifies imports across the codebase and aligns with the PR objectives.
src/core/ai/llm/services/index.ts (1)
1-2
: Clean barrel file implementation.This barrel file appropriately exports all types from the types.js module, contributing to the centralized export structure being established. This implementation follows the same pattern as other barrel files in the PR.
src/app/cli/cli.ts (1)
3-5
: Import paths successfully updated to use the path alias.The imports have been correctly migrated from relative paths to the
@core/index.js
path alias. This change aligns with the PR objective to implement path aliases for cleaner imports.Note that both logger and SaikiAgent are now imported from the same location, which simplifies the import structure.
src/core/logger/index.ts (1)
1-2
: Effective barrel file implementation for the logger module.This barrel file exports all contents from logger.js, creating a centralized entry point for the logger functionality. This change supports the PR's goal of improving module organization and enabling library exports.
src/core/utils/index.ts (1)
1-2
: Clean and effective barrel file implementation!This barrel file properly re-exports from path.js and service-initializer.js, creating a centralized entry point that simplifies imports. This approach aligns with the PR objective of exposing core functionality as a library while maintaining a clean export structure.
src/core/ai/llm/messages/index.ts (1)
1-2
: Well-structured barrel file for LLM messages!This barrel file correctly re-exports from manager.js and types.js, creating a clean entry point for messages functionality. This consolidation makes imports more maintainable for library consumers.
src/core/ai/index.ts (1)
1-2
: Solid hierarchical export structure!This barrel file properly aggregates exports from the agent and llm submodules, creating a clean hierarchical export structure that simplifies library imports. This implementation supports both the ESM and CJS export strategy outlined in the PR objectives.
src/app/discord/bot.ts (2)
4-4
: Good addition of HTTP protocol supportAdding the http module import allows the downloadFileAsBase64 function to handle both HTTP and HTTPS protocols, making the file download functionality more robust and versatile.
5-5
: Proper implementation of @core path aliasThe import for SaikiAgent has been updated to use the new @core path alias instead of relative paths, which aligns with the PR's goal of implementing path aliases for cleaner imports and better separation of concerns.
src/core/settings/index.ts (1)
1-1
: Approve barrel export for settings types.
The new barrel file correctly re-exports all types from./types.js
, aligning with the centralized import strategy and simplifying downstream imports.src/core/config/index.ts (1)
1-3
: Approve barrel exports for config submodules.
This index consolidates exports fromagentCard.js
,schemas.js
, andtypes.js
into a single entry point, improving modularity and import clarity.src/core/ai/llm/index.ts (1)
1-5
: Approve barrel exports for LLM module.
Exports forerrors.js
,registry.js
,types.js
,messages/index.js
, andservices/index.js
are correctly centralized, making LLM-related APIs easier to consume.tsconfig.json (1)
7-11
: Approve addition of baseUrl and path aliases.
Introducing"baseUrl": "."
and path mappings for@app/*
and@core/*
enables cleaner, alias-based imports across the codebase.src/core/client/index.ts (1)
1-3
: Approve barrel exports for client submodules.
Aggregating exports frommanager.js
,mcp-client.js
, andtypes.js
into a single index improves import ergonomics and aligns with the overall barrel-file strategy.src/core/index.ts (1)
1-6
: Well-structured barrel file for core module exports.This clean barrel file efficiently re-exports all essential functionality from core submodules, creating a centralized entry point that aligns with the PR objective of exposing Saiki functionality as a library.
src/app/index.ts (2)
5-14
: Consolidated imports using centralized core module.The imports have been effectively consolidated from multiple relative paths into a single import from the centralized
@core/index.js
. This approach improves maintainability and establishes clear boundaries between app and core modules.
19-19
: Updated import path for options utilities.The import path for option utilities has been correctly moved from core module to app module, aligning with the PR's objective to separate CLI options code from core functionality.
tsup.config.ts (1)
1-21
: Well-structured build configuration for dual module formats.This tsup configuration properly implements the build settings needed for:
- Core module (CJS+ESM) with declaration files and proper bundling
- App module (ESM only) without bundling
The configuration ensures that chalk and boxen are bundled with the core library, and shims are enabled for both build targets. This setup aligns perfectly with the PR objective of supporting both CommonJS and ECMAScript module imports.
src/core/utils/service-initializer.ts (2)
31-31
: Updated logger import to use new barrel file.The logger import has been correctly updated to use the new barrel file structure, consistent with the overall refactoring.
90-91
: Made CLI arguments optional for more flexible service initialization.Making the CLI arguments optional is a good improvement that enhances flexibility when programmatically creating agent services.
package.json (5)
4-7
: Engines field to enforce Node.js and npm versions
The newengines
section correctly requires Node.js >=20.0.0 and npm >=8.3.0, matching your build tools (tsup
) and ensuringoverrides
support.
16-23
: Validate theexports
configuration
Theexports
field correctly exposes the package for CJS (require
), ESM (import
), and TypeScript (types
), following dual-package best practices.
27-27
: Update build script to usetsup
Switching thebuild
script fromtsc
tonpm run clean && tsup && npm run copy-client
aligns with your new bundler. Ensure yourtsup.config.ts
covers bothcore
andapp
targets.
99-99
: Pintsup
indevDependencies
Adding"tsup": "^8.4.0"
is required for the updated build process.
106-110
: Closelint-staged
and addoverrides
Thelint-staged
config is now properly closed, and theoverrides
section pinstough-cookie
andundici
to address known vulnerabilities—good catch.
This PR exposes core saiki functionality as part of the @truffle-ai/saiki package as a library.
This means that users who install @truffle-ai/saiki now get both the CLI commands and the library for use in programs.
Other changes:
Added support for both commonjs (Older js versions) and ESM based imports. This is useful for older projects
Added tsup.config.ts which defines the build logic for ESM v/s CJS
Added exports field in package.json which defines the actual library exports
Moved cli options code from core to app
Added path aliases @core and @app for cross functional exports (if files in app need to import from core, they can
import x from @core/index.js
Updated all files in app directory to import from @core/index.js for better modularity and clear separation of concerns
Added new
index.ts
files incore
directory to simplify imports and add better sub-directory separationAdded src/TESTING.md which describes how to locally test both code exports and the saiki CLI locally while developing.
Tested cjs/esm imports in a separate file (followed TESTING.md)
Tested saiki CLI works correctly (followed TESTING.md)
Pinned dependencies for 2 libraries via 'overrides' section in package.json because of vulnerabilities with discord and telegram dependencies
Added
engine
section in package.json which warns end users installing saiki that their node version is not supported, if they are below node 20 or below npm 8 - useful for users trying to install saiki on old node versionsSDK exports now include necessary functions/classes/types to use saiki programmatically
next steps:
bump up saiki version and publish the new version post this PR
Summary by CodeRabbit
New Features
Refactor
Style
Chores