Skip to content

Conversation

@ryoppippi
Copy link
Contributor

@ryoppippi ryoppippi commented Oct 7, 2025

Summary

  • Move both ai and openai to peerDependenciesMeta with optional: true
  • Use dynamic import for AI SDK with proper error handling
  • Update all toAISDK() calls to async/await
  • Support both AI SDK v4 and v5 with backward compatibility

Changes

  • AI SDK: toAISDK() now uses dynamic import and throws a clear error if AI SDK is not installed
  • OpenAI SDK: Already type-only import, no runtime dependency
  • All examples and tests updated to await toAISDK()
  • Type imports remain (removed at compile time)
  • Add execution metadata support for AI SDK v5

Migration Guide

AI SDK (optional)

Install if you use toAISDK():

npm install ai@4.x  # or ai@5.x

Update your code:

// Before
const tools = tool.toAISDK()

// After
const tools = await tool.toAISDK()

OpenAI SDK (optional)

Install if you use toOpenAI():

npm install openai@5.x  # or openai@6.x

No code changes needed - toOpenAI() remains synchronous.

Breaking Changes

  • toAISDK() is now async and returns a Promise
  • Both ai and openai are now optional peer dependencies

Copilot AI review requested due to automatic review settings October 7, 2025 14:30
Copy link

Copilot AI left a 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'
Copy link

Copilot AI Oct 7, 2025

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.

Suggested change
'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'

Copilot uses AI. Check for mistakes.
@pkg-pr-new
Copy link

pkg-pr-new bot commented Oct 7, 2025

Open in StackBlitz

npm i https://pkg.pr.new/StackOneHQ/stackone-ai-node/@stackone/ai@112

commit: 26af072

Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a 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 &quot;AI SDK is not installed&quot;, 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": {
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot Oct 7, 2025

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 @@
-    &quot;ai&quot;: &quot;4.x&quot;,
     &quot;openai&quot;: &quot;4.x|5.x&quot;
   },
+  &quot;peerDependenciesOptional&quot;: {
+    &quot;ai&quot;: &quot;4.x&quot;
+  },
</file context>

✅ Addressed in 26af072

}),
},
};
} catch {
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot Oct 7, 2025

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 &quot;AI SDK is not installed&quot;, 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(
+        &#39;AI SDK is not installed. Please install it with: npm install ai@4.x or bun add ai@4.x&#39;
</file context>

✅ Addressed in ef5efc1

@ryoppippi ryoppippi requested a review from a team October 7, 2025 14:49
- 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
@ryoppippi ryoppippi changed the title feat: make AI SDK an optional peer dependency feat: make AI SDK and OpenAI SDK optional peer dependencies Oct 9, 2025
@ryoppippi ryoppippi merged commit e745640 into main Oct 9, 2025
6 checks passed
@ryoppippi ryoppippi deleted the optional-ai-sdk branch October 9, 2025 18:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants