Skip to content

fix(typescript): install the SDK from npm in 02, 03, 05 and 06, and migrate to the 1.x API - #317

Merged
manoj-selvakumar5 merged 4 commits into
strands-agents:mainfrom
schinchli:fix/ts-samples-npm-sdk
Oct 14, 2026
Merged

manoj-selvakumar5 merged 4 commits into
strands-agents:mainfrom
schinchli:fix/ts-samples-npm-sdk

Conversation

@schinchli

Copy link
Copy Markdown
Contributor

Summary

Fixes the other four TypeScript samples listed in #314:

  • 02-custom-tools
  • 03-model-providers
  • 05-agent-state
  • 06-browser-agent

All four depended on the archived strands-agents/sdk-typescript repo, so none of them installed a working SDK. Once moved to the published @strands-agents/sdk 1.19.0, each hit its own breakage from the SDK's pre-1.0 to 1.x API changes. Each is fixed here, and each sample was run end to end.

This PR is independent of #315 (01-first-agent). The two can be reviewed and merged in either order. There is one commit per sample, so they can be reviewed one at a time.

Refs #314

Common change (all four)

Change Why
"@strands-agents/sdk": "^1.19.0" instead of github:strands-agents/sdk-typescript or git+ssh://…sdk-typescript.git The archived repo's main holds a private workspace root (strands 0.0.0), not the SDK, so the import fails. The git+ssh form also needed a GitHub SSH key to install.
"engines": { "node": ">=22" }, README says Node.js 22+ @strands-agents/sdk declares engines.node >=22.0.0. The READMEs said 18 or 20.
Failures exit 1 main().catch(console.error) and the chat loops exited 0 on errors such as invalid AWS credentials.

Per-sample changes

02-custom-tools: appointment booking with SQLite tools

Problem Fix
better-sqlite3 ^11 has no build for current Node, so npm install fails in node-gyp ^13.0.0, which also declares engines.node >=22
zod is imported in AppointmentTools.ts but was never a dependency. It only resolved as a transitive install of the old SDK. Added zod ^4.1.12, the SDK's peer range
Functional bug: the agent doesn't know the date, so "Book … for tomorrow 3pm" never calls create_appointment. The agent asks for the date instead, and the whole demo books nothing. Today's date goes in the system prompt, so relative dates resolve and the tools run
Every reply printed twice: the agent streams it, then console.log("Agent:", …) prints it again printer: false, keeping the sample's labelled Agent: transcript

03-model-providers: the same agent on Bedrock or OpenAI

Problem Fix
@strands-agents/sdk/openai and @strands-agents/sdk/vended_tools/http_request no longer exist, so tsc fails, and npm install fails because prepare runs the build @strands-agents/sdk/models/openai and @strands-agents/sdk/vended-tools/http-request, in the code and the README
OpenAIModel needs the openai package, which the SDK declares as a peer (^6.45.0) Added openai ^6.45.0
rl.question() after input closes throws ERR_USE_AFTER_CLOSE on Ctrl+D or piped input for await (const input of rl), which ends cleanly when input closes

05-agent-state: agent state, persistence and hooks

Problem Fix
state is no longer an AgentConfig field, and agent.state no longer exists appState: { … } in the config, and agent.appState / context.agent.appState in tools and hooks. It is the same StateStore API (get, set, getAll).
agent.hooks.addCallback(Event, cb) no longer exists agent.addHook(Event, cb)
Same readline crash as 03 Same for await fix

06-browser-agent: Vite app running the agent in the browser

Problem Fix
openai ^4 peer-requires zod 3, which conflicts with the SDK's zod 4, so npm install fails with ERESOLVE openai ^6.45.0
@strands-agents/sdk/openai moved @strands-agents/sdk/models/openai, in the code and the README
Silent bug: model deltas now arrive wrapped in a modelStreamUpdateEvent, so event.type === "modelContentBlockDeltaEvent" never matched and every reply rendered "No response received." vite build does not type-check, so the build still passed. Unwrap event.event, in the code and the README snippet
Bedrock model not set, and the README said Claude Sonnet 4 Pinned global.anthropic.claude-sonnet-4-6; README updated

How this was verified

All four were tested from a clean install (rm -rf node_modules package-lock.json && npm install) on Node 26.0, against Amazon Bedrock in us-east-1. Every sample passes tsc --noEmit.

Sample Test Result
02 npx tsx src/index.ts The agent booked "Agent fun" for tomorrow 15:00, then moved it to DC. The SQLite row after the run is {"date":"2026-10-01 15:00","location":"DC","title":"Agent fun"}.
03 Bedrock: "What time is it in Tokyo?" then "What is the weather in Paris right now?", then exit current_time and http_request (Open-Meteo) both answered, exit 0. Piped input without exit also ends cleanly.
03 OpenAI with an invalid key Reaches OpenAI and returns 401 Incorrect API key, exit 1 (no real OpenAI key was available)
05 Session 1 adds 2 mice and a laptop and sets the payment method; session 2 is a new process that asks what's in the cart Session 2 printed "Loaded 5 previous messages" and answered from saved state: 2 × Mouse, 1 × Laptop ($1,057), credit card
06 npm run build && vite preview, driven with Playwright in Chromium, using Bedrock with short-lived STS credentials Connected, streamed a correct reply, no page errors
02, 03, 05 Invalid AWS credentials Exit 1

Notes for reviewers

  • Scope kept small. Each fix targets what broke, and the samples' structure, tools and prompts are unchanged. The one behaviour change is 02 getting today's date, which the demo needs in order to do what its README describes.
  • The OpenAI path in 03 and 06 is type-checked, and 03 was shown to reach OpenAI. It was not run with a real key.
  • Lockfiles stay git-ignored, per repo convention.

Shashank Chinchli added 4 commits September 30, 2026 06:57
…e booking flow work

Depend on @strands-agents/sdk ^1.19.0 instead of the archived GitHub repo, and on better-sqlite3 ^13 (11.x does not build on current Node) and zod (imported directly, previously only transitive). Give the agent today's date so it can resolve "tomorrow" and actually call create_appointment; without it the agent asked for the date and never booked. Turn off the agent's own printer so each labelled reply prints once, exit 1 on failure, and document Node.js 22+.

Refs strands-agents#314
…te moved imports

Depend on @strands-agents/sdk ^1.19.0 and its openai ^6.45 peer. OpenAIModel and httpRequest moved to @strands-agents/sdk/models/openai and @strands-agents/sdk/vended-tools/http-request. Read chat input with for-await so the loop ends cleanly when input closes instead of throwing ERR_USE_AFTER_CLOSE, exit 1 on failure, and document Node.js 22+.

Refs strands-agents#314
…to appState and addHook

Depend on @strands-agents/sdk ^1.19.0. Agent state is now appState (config and agent.appState), and hooks are registered with agent.addHook(Event, callback) instead of agent.hooks.addCallback. Read chat input with for-await so the loop ends cleanly when input closes, exit 1 on failure, and document Node.js 22+.

Refs strands-agents#314
…reaming

Depend on @strands-agents/sdk ^1.19.0 and openai ^6.45 (openai 4.x peer-requires zod 3, which conflicts with the SDK's zod 4 and fails npm install). Update the OpenAIModel import path. Model deltas now arrive inside modelStreamUpdateEvent, so the old check never matched and every reply showed "No response received."; unwrap the event. Pin the Bedrock model and document Node.js 22+.

Refs strands-agents#314
@schinchli

Copy link
Copy Markdown
Contributor Author

@mvangara10 @yonib05 this follows up #315 and fixes the other four TypeScript samples from #314. They all need the npm SDK, and each also needed a small 1.x API migration.

There is one commit per sample, and the description has a table for each one showing what broke, the fix, and how I tested it end to end. Two of the fixes are for bugs that fail silently: 02 never booked an appointment, and 06 showed "No response received." for every reply.

@manoj-selvakumar5
manoj-selvakumar5 merged commit 317e9b6 into strands-agents:main Oct 14, 2026
1 check passed
@github-actions

Copy link
Copy Markdown

Latest scan for commit: d9d3fc3 | Updated: 2026-10-14 22:56:47 UTC

✅ Security Scan Report (PR Files Only)

Scanned Files

  • typescript/01-learn/02-custom-tools/README.md
  • typescript/01-learn/02-custom-tools/package.json
  • typescript/01-learn/02-custom-tools/src/index.ts
  • typescript/01-learn/03-model-providers/README.md
  • typescript/01-learn/03-model-providers/package.json
  • typescript/01-learn/03-model-providers/src/agent.ts
  • typescript/01-learn/03-model-providers/src/index.ts
  • typescript/01-learn/05-agent-state/README.md
  • typescript/01-learn/05-agent-state/package.json
  • typescript/01-learn/05-agent-state/src/agent.ts
  • ... and 4 more files

Security Scan Results

Critical High Medium Low Info
0 0 0 0 0

Threshold: High

No security issues detected in your changes. Great job!

This scan only covers files changed in this PR.

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