-
Couldn't load subscription status.
- Fork 2
feat: make AI SDK and OpenAI SDK optional peer dependencies #112
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
Conversation
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.
Pull Request Overview
Makes the AI SDK an optional peer dependency by moving it to peerDependenciesOptional and implementing dynamic imports with proper error handling for when the AI SDK is not installed.
- Move AI SDK from required to optional peer dependency in package.json
- Convert
toAISDK()methods to async with dynamic imports and error handling - Update all usage sites to use async/await pattern
Reviewed Changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| package.json | Moves AI SDK from peerDependencies to peerDependenciesOptional |
| src/tool.ts | Implements async toAISDK() with dynamic import and error handling |
| src/tests/tool.spec.ts | Updates test cases to use async/await for toAISDK() calls |
| src/tests/meta-tools.spec.ts | Updates test cases to use async/await for toAISDK() calls |
| src/tests/json-schema.spec.ts | Updates test cases to use async/await for toAISDK() calls |
| examples/planning.ts | Updates example to use async/await for toAISDK() call |
| examples/meta-tools.ts | Updates example to use async/await for toAISDK() call |
| examples/human-in-the-loop.ts | Updates example to use async/await for toAISDK() call |
| examples/ai-sdk-integration.ts | Updates example to use async/await for toAISDK() call |
| README.md | Updates documentation examples to use async/await for toAISDK() calls |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
src/tool.ts
Outdated
| }; | ||
| } catch { | ||
| throw new StackOneError( | ||
| 'AI SDK is not installed. Please install it with: npm install ai@4.x or bun add ai@4.x' |
Copilot
AI
Oct 7, 2025
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.
The error message suggests installing 'ai@4.x' but the package.json specifies '4.x' which could include major version 4 with any minor/patch version. Consider being more specific about the supported version range or use a more precise version specification.
| 'AI SDK is not installed. Please install it with: npm install ai@4.x or bun add ai@4.x' | |
| 'AI SDK is not installed. Please install it with: npm install ai@^4.2.0 or bun add ai@^4.2.0' |
commit: |
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.
2 issues found across 10 files
Prompt for AI agents (all 2 issues)
Understand the root cause of the following 2 issues and fix them.
<file name="package.json">
<violation number="1" location="package.json:64">
`peerDependenciesOptional` is not a recognized package.json field. npm will ignore this block, so `ai` stops being declared as a peer dependency altogether. Keep `ai` in `peerDependencies` and mark it optional via `peerDependenciesMeta.optional: true` instead.</violation>
</file>
<file name="src/tool.ts">
<violation number="1" location="src/tool.ts:144">
This catch block converts every import failure into "AI SDK is not installed", so real runtime errors inside the AI SDK (when it is installed) will be misreported and harder to debug. Please only wrap the missing-module case and rethrow other errors.</violation>
</file>
React with 👍 or 👎 to teach cubic. Mention @cubic-dev-ai to give feedback, ask questions, or re-run the review.
package.json
Outdated
| "ai": "4.x", | ||
| "openai": "4.x|5.x" | ||
| }, | ||
| "peerDependenciesOptional": { |
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.
peerDependenciesOptional is not a recognized package.json field. npm will ignore this block, so ai stops being declared as a peer dependency altogether. Keep ai in peerDependencies and mark it optional via peerDependenciesMeta.optional: true instead.
Prompt for AI agents
Address the following comment on package.json at line 64:
<comment>`peerDependenciesOptional` is not a recognized package.json field. npm will ignore this block, so `ai` stops being declared as a peer dependency altogether. Keep `ai` in `peerDependencies` and mark it optional via `peerDependenciesMeta.optional: true` instead.</comment>
<file context>
@@ -59,9 +59,11 @@
- "ai": "4.x",
"openai": "4.x|5.x"
},
+ "peerDependenciesOptional": {
+ "ai": "4.x"
+ },
</file context>
✅ Addressed in 26af072
| }), | ||
| }, | ||
| }; | ||
| } catch { |
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.
This catch block converts every import failure into "AI SDK is not installed", so real runtime errors inside the AI SDK (when it is installed) will be misreported and harder to debug. Please only wrap the missing-module case and rethrow other errors.
Prompt for AI agents
Address the following comment on src/tool.ts at line 144:
<comment>This catch block converts every import failure into "AI SDK is not installed", so real runtime errors inside the AI SDK (when it is installed) will be misreported and harder to debug. Please only wrap the missing-module case and rethrow other errors.</comment>
<file context>
@@ -114,29 +114,38 @@ export class BaseTool {
+ }),
+ },
+ };
+ } catch {
+ throw new StackOneError(
+ 'AI SDK is not installed. Please install it with: npm install ai@4.x or bun add ai@4.x'
</file context>
✅ Addressed in ef5efc1
- Move 'ai' from peerDependencies to peerDependenciesOptional - Use dynamic import for AI SDK in toAISDK() method - Add proper error handling when AI SDK is not installed - Update all toAISDK() calls to be async with await - Keep type imports for ToolSet (removed at compile time)
- Move both ai and openai to peerDependenciesMeta with optional: true - Update from deprecated peerDependenciesOptional to peerDependenciesMeta - openai is already type-only import, no runtime dependency
80b52ee to
26af072
Compare
Summary
aiandopenaitopeerDependenciesMetawithoptional: truetoAISDK()calls to async/awaitChanges
toAISDK()now uses dynamic import and throws a clear error if AI SDK is not installedawait toAISDK()Migration Guide
AI SDK (optional)
Install if you use
toAISDK():npm install ai@4.x # or ai@5.xUpdate your code:
OpenAI SDK (optional)
Install if you use
toOpenAI():npm install openai@5.x # or openai@6.xNo code changes needed -
toOpenAI()remains synchronous.Breaking Changes
toAISDK()is now async and returns a Promiseaiandopenaiare now optional peer dependencies