fix: lazy-load ai package to honor optional peer dependency#337
Closed
fix: lazy-load ai package to honor optional peer dependency#337
ai package to honor optional peer dependency#337Conversation
…ort crash Co-authored-by: glebedel <10488548+glebedel@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix ai peer dependency issue causing crashes on load
fix: lazy-load Mar 19, 2026
ai package to honor optional peer dependency
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
aiwas declared as an optional peer dependency but a static top-level import intool.tscaused an immediate crash on module load whenaiwasn't installed — before any SDK methods were called.Changes
src/tool.ts: Convertimport { jsonSchema } from 'ai'toimport type(erased at compile time, no runtime cost)toClaudeAgentSdkTool(): Replace directjsonSchema()call withtryImport('ai', ...), consistent with the existing pattern intoAISDK()Original prompt
📱 Kick off Copilot coding agent tasks wherever you are with GitHub Mobile, available on iOS and Android.
Summary by cubic
Fixes crashes when importing
@stackone/aiwithoutaiinstalled by removing the top‑level runtime import and loadingaionly insidetoClaudeAgentSdkTool. You can now import the package withoutaiunless you use the Claude Agent SDK adapter.import { jsonSchema } from 'ai'toimport typeonly.aiviatryImportinsideBaseTool.toClaudeAgentSdkTool().aiis needed.Written for commit f51049c. Summary will update on new commits.