Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Test lock files
test/packages/**/package-lock.json

# Build outputs
dist/
build/
Expand Down
26 changes: 13 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,28 @@
],
"exports": {
".": {
"import": "./dist/src/index.js",
"types": "./dist/src/index.d.ts"
"types": "./dist/src/index.d.ts",
"default": "./dist/src/index.js"
},
"./openai": {
"import": "./dist/src/models/openai.js",
"types": "./dist/src/models/openai.d.ts"
"types": "./dist/src/models/openai.d.ts",
"default": "./dist/src/models/openai.js"
},
"./bedrock": {
"import": "./dist/src/models/bedrock.js",
"types": "./dist/src/models/bedrock.d.ts"
"types": "./dist/src/models/bedrock.d.ts",
"default": "./dist/src/models/bedrock.js"
},
"./vended_tools/notebook": {
"import": "./dist/vended_tools/notebook/index.js",
"types": "./dist/vended_tools/notebook/index.d.ts"
"types": "./dist/vended_tools/notebook/index.d.ts",
"default": "./dist/vended_tools/notebook/index.js"
},
"./vended_tools/file_editor": {
"import": "./dist/vended_tools/file_editor/index.js",
"types": "./dist/vended_tools/file_editor/index.d.ts"
"types": "./dist/vended_tools/file_editor/index.d.ts",
"default": "./dist/vended_tools/file_editor/index.js"
},
"./vended_tools/http_request": {
"import": "./dist/vended_tools/http_request/index.js",
"types": "./dist/vended_tools/http_request/index.d.ts"
"types": "./dist/vended_tools/http_request/index.d.ts",
"default": "./dist/vended_tools/http_request/index.js"
}
},
"scripts": {
Expand All @@ -50,7 +50,7 @@
"test:browser:install": "npx playwright install --with-deps chromium",
"test:all": "vitest run --project unit-node --project unit-browser",
"test:all:coverage": "vitest run --coverage --project unit-node --project unit-browser",
"test:package": "npm run build && cd test-package && npm install && node verify.js",
"test:package": "cd test/packages/esm-module && npm install && node esm.js && cd ../cjs-module && npm install && node cjs.js",
"lint": "eslint src tests_integ vended_tools",
"lint:fix": "eslint src tests_integ vended_tools --fix",
"format": "prettier --write src tests_integ vended_tools",
Expand Down
26 changes: 26 additions & 0 deletions test/packages/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Package Import Tests

This directory contains verification tests to ensure `@strands-agents/sdk` can be imported correctly in both ESM and CommonJS module formats.

## Running the Tests

From the root of the project:

```bash
npm run test:package
```

This command builds and installs the SDK locally, then runs both ESM and CJS import tests.

## Test Structure

```
test/packages/
├── esm-module/ # ES Module import test
│ ├── esm.js # Uses `import { ... } from '@strands-agents/sdk'`
│ └── package.json
├── cjs-module/ # CommonJS import test
│ ├── cjs.js # Uses `require('@strands-agents/sdk')`
│ └── package.json
└── README.md
```
62 changes: 62 additions & 0 deletions test/packages/cjs-module/cjs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/**
* Verification script to ensure the built package can be imported without a bundler.
* This script runs in a pure Node.js ES module environment.
*/

const { Agent, BedrockModel, tool } = require('@strands-agents/sdk')
const { z } = require('zod')

console.log('✓ Import from main entry point successful')

// Verify BedrockModel can be instantiated
const model = new BedrockModel({ region: 'us-west-2' })
console.log('✓ BedrockModel instantiation successful')

// Verify basic functionality
const config = model.getConfig()
if (!config) {
throw new Error('BedrockModel config is invalid')
}
console.log('✓ BedrockModel configuration retrieval successful')

// Define a tool
const example_tool = tool({
name: 'get_weather',
description: 'Get the current weather for a specific location.',
inputSchema: z.object({
location: z.string().describe('The city and state, e.g., San Francisco, CA'),
}),
callback: (input) => {
console.log(`\n[WeatherTool] Getting weather for ${input.location}...`)

const fakeWeatherData = {
temperature: '72°F',
conditions: 'sunny',
}

return `The weather in ${input.location} is ${fakeWeatherData.temperature} and ${fakeWeatherData.conditions}.`
},
})
console.log('✓ Tool created successful')

async function main() {
// Verify tool can be called
const response = await example_tool.invoke({ location: 'New York' })
if (response !== `The weather in New York is 72°F and sunny.`) {
throw new Error('Tool returned invalid response')
}

// Verify Agent can be instantiated
const agent = new Agent({
tools: [example_tool],
})

if (agent.tools.length == 0) {
throw new Error('Tool was not correctly added to the agent')
}
}

main().catch((error) => {
console.error(error)
process.exit(1)
})
10 changes: 10 additions & 0 deletions test/packages/cjs-module/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"type": "commonjs",
"name": "test-package",
"version": "1.0.0",
"private": true,
"description": "Test package to verify SDK works with CSJ",
"dependencies": {
"@strands-agents/sdk": "file:../../.."
}
}
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
"private": true,
"description": "Test package to verify SDK works without bundler",
"dependencies": {
"@strands-agents/sdk": "file:.."
"@strands-agents/sdk": "file:../../.."
}
}
}