diff --git a/.gitignore b/.gitignore index 77210148..57b1943b 100644 --- a/.gitignore +++ b/.gitignore @@ -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/ diff --git a/package.json b/package.json index 6c6b4742..1cc665c0 100644 --- a/package.json +++ b/package.json @@ -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": { @@ -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", diff --git a/test/packages/README.md b/test/packages/README.md new file mode 100644 index 00000000..5dd6723b --- /dev/null +++ b/test/packages/README.md @@ -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 +``` diff --git a/test/packages/cjs-module/cjs.js b/test/packages/cjs-module/cjs.js new file mode 100644 index 00000000..4e1443cb --- /dev/null +++ b/test/packages/cjs-module/cjs.js @@ -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) +}) diff --git a/test/packages/cjs-module/package.json b/test/packages/cjs-module/package.json new file mode 100644 index 00000000..e2559ecd --- /dev/null +++ b/test/packages/cjs-module/package.json @@ -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:../../.." + } +} \ No newline at end of file diff --git a/test-package/verify.js b/test/packages/esm-module/esm.js similarity index 100% rename from test-package/verify.js rename to test/packages/esm-module/esm.js diff --git a/test-package/package.json b/test/packages/esm-module/package.json similarity index 80% rename from test-package/package.json rename to test/packages/esm-module/package.json index 09ecb4c4..467522fc 100644 --- a/test-package/package.json +++ b/test/packages/esm-module/package.json @@ -5,6 +5,6 @@ "private": true, "description": "Test package to verify SDK works without bundler", "dependencies": { - "@strands-agents/sdk": "file:.." + "@strands-agents/sdk": "file:../../.." } -} +} \ No newline at end of file