Skip to content

Commit a8223b5

Browse files
authored
Update exports to account for CJS (#316)
* Add test package to verify CJS compatability Currently failing * fix: Update exports to use `default` to support CJS Per #310 we need to specify exports for common-js format; default is the easiest way to do this * Ignore test package lock files --------- Co-authored-by: Mackenzie Zastrow <[email protected]>
1 parent 16060fa commit a8223b5

File tree

7 files changed

+116
-15
lines changed

7 files changed

+116
-15
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ npm-debug.log*
44
yarn-debug.log*
55
yarn-error.log*
66

7+
# Test lock files
8+
test/packages/**/package-lock.json
9+
710
# Build outputs
811
dist/
912
build/

package.json

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,28 +11,28 @@
1111
],
1212
"exports": {
1313
".": {
14-
"import": "./dist/src/index.js",
15-
"types": "./dist/src/index.d.ts"
14+
"types": "./dist/src/index.d.ts",
15+
"default": "./dist/src/index.js"
1616
},
1717
"./openai": {
18-
"import": "./dist/src/models/openai.js",
19-
"types": "./dist/src/models/openai.d.ts"
18+
"types": "./dist/src/models/openai.d.ts",
19+
"default": "./dist/src/models/openai.js"
2020
},
2121
"./bedrock": {
22-
"import": "./dist/src/models/bedrock.js",
23-
"types": "./dist/src/models/bedrock.d.ts"
22+
"types": "./dist/src/models/bedrock.d.ts",
23+
"default": "./dist/src/models/bedrock.js"
2424
},
2525
"./vended_tools/notebook": {
26-
"import": "./dist/vended_tools/notebook/index.js",
27-
"types": "./dist/vended_tools/notebook/index.d.ts"
26+
"types": "./dist/vended_tools/notebook/index.d.ts",
27+
"default": "./dist/vended_tools/notebook/index.js"
2828
},
2929
"./vended_tools/file_editor": {
30-
"import": "./dist/vended_tools/file_editor/index.js",
31-
"types": "./dist/vended_tools/file_editor/index.d.ts"
30+
"types": "./dist/vended_tools/file_editor/index.d.ts",
31+
"default": "./dist/vended_tools/file_editor/index.js"
3232
},
3333
"./vended_tools/http_request": {
34-
"import": "./dist/vended_tools/http_request/index.js",
35-
"types": "./dist/vended_tools/http_request/index.d.ts"
34+
"types": "./dist/vended_tools/http_request/index.d.ts",
35+
"default": "./dist/vended_tools/http_request/index.js"
3636
}
3737
},
3838
"scripts": {
@@ -50,7 +50,7 @@
5050
"test:browser:install": "npx playwright install --with-deps chromium",
5151
"test:all": "vitest run --project unit-node --project unit-browser",
5252
"test:all:coverage": "vitest run --coverage --project unit-node --project unit-browser",
53-
"test:package": "npm run build && cd test-package && npm install && node verify.js",
53+
"test:package": "cd test/packages/esm-module && npm install && node esm.js && cd ../cjs-module && npm install && node cjs.js",
5454
"lint": "eslint src tests_integ vended_tools",
5555
"lint:fix": "eslint src tests_integ vended_tools --fix",
5656
"format": "prettier --write src tests_integ vended_tools",

test/packages/README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Package Import Tests
2+
3+
This directory contains verification tests to ensure `@strands-agents/sdk` can be imported correctly in both ESM and CommonJS module formats.
4+
5+
## Running the Tests
6+
7+
From the root of the project:
8+
9+
```bash
10+
npm run test:package
11+
```
12+
13+
This command builds and installs the SDK locally, then runs both ESM and CJS import tests.
14+
15+
## Test Structure
16+
17+
```
18+
test/packages/
19+
├── esm-module/ # ES Module import test
20+
│ ├── esm.js # Uses `import { ... } from '@strands-agents/sdk'`
21+
│ └── package.json
22+
├── cjs-module/ # CommonJS import test
23+
│ ├── cjs.js # Uses `require('@strands-agents/sdk')`
24+
│ └── package.json
25+
└── README.md
26+
```

test/packages/cjs-module/cjs.js

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/**
2+
* Verification script to ensure the built package can be imported without a bundler.
3+
* This script runs in a pure Node.js ES module environment.
4+
*/
5+
6+
const { Agent, BedrockModel, tool } = require('@strands-agents/sdk')
7+
const { z } = require('zod')
8+
9+
console.log('✓ Import from main entry point successful')
10+
11+
// Verify BedrockModel can be instantiated
12+
const model = new BedrockModel({ region: 'us-west-2' })
13+
console.log('✓ BedrockModel instantiation successful')
14+
15+
// Verify basic functionality
16+
const config = model.getConfig()
17+
if (!config) {
18+
throw new Error('BedrockModel config is invalid')
19+
}
20+
console.log('✓ BedrockModel configuration retrieval successful')
21+
22+
// Define a tool
23+
const example_tool = tool({
24+
name: 'get_weather',
25+
description: 'Get the current weather for a specific location.',
26+
inputSchema: z.object({
27+
location: z.string().describe('The city and state, e.g., San Francisco, CA'),
28+
}),
29+
callback: (input) => {
30+
console.log(`\n[WeatherTool] Getting weather for ${input.location}...`)
31+
32+
const fakeWeatherData = {
33+
temperature: '72°F',
34+
conditions: 'sunny',
35+
}
36+
37+
return `The weather in ${input.location} is ${fakeWeatherData.temperature} and ${fakeWeatherData.conditions}.`
38+
},
39+
})
40+
console.log('✓ Tool created successful')
41+
42+
async function main() {
43+
// Verify tool can be called
44+
const response = await example_tool.invoke({ location: 'New York' })
45+
if (response !== `The weather in New York is 72°F and sunny.`) {
46+
throw new Error('Tool returned invalid response')
47+
}
48+
49+
// Verify Agent can be instantiated
50+
const agent = new Agent({
51+
tools: [example_tool],
52+
})
53+
54+
if (agent.tools.length == 0) {
55+
throw new Error('Tool was not correctly added to the agent')
56+
}
57+
}
58+
59+
main().catch((error) => {
60+
console.error(error)
61+
process.exit(1)
62+
})
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"type": "commonjs",
3+
"name": "test-package",
4+
"version": "1.0.0",
5+
"private": true,
6+
"description": "Test package to verify SDK works with CSJ",
7+
"dependencies": {
8+
"@strands-agents/sdk": "file:../../.."
9+
}
10+
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@
55
"private": true,
66
"description": "Test package to verify SDK works without bundler",
77
"dependencies": {
8-
"@strands-agents/sdk": "file:.."
8+
"@strands-agents/sdk": "file:../../.."
99
}
10-
}
10+
}

0 commit comments

Comments
 (0)