diff --git a/.release-please-manifest.json b/.release-please-manifest.json index c8d2b69..c72360c 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1,3 +1,3 @@ { - "packages/react": "0.1.0" + "packages/react": "0.2.0" } diff --git a/MIGRATION.md b/MIGRATION.md new file mode 100644 index 0000000..9d9e8be --- /dev/null +++ b/MIGRATION.md @@ -0,0 +1,98 @@ +# Migration Guide + +## 0.1 to 0.2 + +`@deepgram/react` 0.2.0 adds runtime Voice Agent controls and updates the package for `@deepgram/agents` 0.1.2 and `@deepgram/sdk` 5.9.0. + +Install the new release: + +```bash +npm install @deepgram/react@^0.2.0 +``` + +### Handle the `thinking` mode + +`AgentMode` now includes `"thinking"`. Update exhaustive mode switches and any mode-to-label maps. + +```ts +switch (mode) { + case "idle": + case "listening": + case "thinking": + case "speaking": + break; +} +``` + +### Update typed context and hook wrappers + +`AgentContextValue` and hook result types now include required members for the new controls and state. Components that consume the hooks do not need a source change, but typed mocks, wrappers, and objects that implement these interfaces must provide the new members. + +### Keep the client-tool unsubscribe function + +`registerClientTool()` now returns an unsubscribe function. Existing calls that ignore its return value still work. Store and call the result when registering outside a component lifecycle: + +```tsx +import { useAgentContext } from "@deepgram/react"; + +function MapControls() { + const { registerClientTool } = useAgentContext(); + const unregister = registerClientTool("get_location", () => { + return JSON.stringify({ latitude: 0, longitude: 0 }); + }); + + // Later, when the handler is no longer needed: + unregister(); +} +``` + +`useAgentClientTool()` remains the preferred option inside React components and unregisters automatically on unmount. + +### Treat standalone `start()` as a fresh session + +`useDeepgramAgent().start()` now clears `conversation` before connecting. Keep any transcript that must survive a restart outside the hook, or restore it after the new session starts. + +Manual `start()` calls reject on failure. Handle the returned promise: + +```tsx +import { useAgentControls } from "@deepgram/react"; + +function ConnectButton() { + const { start } = useAgentControls(); + + async function handleStart() { + try { + await start(); + } catch (error) { + console.error("Failed to start the Voice Agent", error); + } + } + + return ; +} +``` + +Automatic start failures, including microphone failures during auto-start and reconnect, call `onSdkError` when it is provided. + +### Use the new runtime controls + +Use the controls from `useAgentControls()`, `useAgentConversation()`, or `useDeepgramAgent()` to update a connected agent without recreating the provider: + +```tsx +import { useAgentControls } from "@deepgram/react"; + +function TakeoverButton() { + const { sendAgentMessage, updatePrompt } = useAgentControls(); + + function takeOver() { + updatePrompt("Keep responses concise."); + sendAgentMessage("I will take it from here.", "interrupt"); + } + + return ; +} +``` + +Use `onListenUpdated`, `onPromptUpdated`, `onSpeakUpdated`, and `onThinkUpdated` on `AgentProvider` or `useDeepgramAgent()` to observe the matching server confirmation. + +See the [package README](packages/react/README.md) for the complete API surface. diff --git a/README.md b/README.md index 40e47d9..c87b8cb 100644 --- a/README.md +++ b/README.md @@ -70,7 +70,7 @@ function VoiceAgent() { | `useAgentSession` | Direct access to the underlying `AgentSession` (escape hatch) | | `useDeepgramAgent` | Standalone hook -- no provider needed | -See the [package README](packages/react/README.md) for full API documentation. +See the [package README](packages/react/README.md) for full API documentation. See the [migration guide](MIGRATION.md) when upgrading from 0.1 to 0.2. ## Related Packages @@ -84,6 +84,7 @@ See the [package README](packages/react/README.md) for full API documentation. - [Deepgram Voice Agent docs](https://developers.deepgram.com/docs/voice-agent) - [API reference](https://developers.deepgram.com/reference) +- [Migration guide](MIGRATION.md) - [`@deepgram/ui` -- pre-built components](https://github.com/deepgram/ui) ## Development diff --git a/packages/react/CHANGELOG.md b/packages/react/CHANGELOG.md index da6892f..b06c1e0 100644 --- a/packages/react/CHANGELOG.md +++ b/packages/react/CHANGELOG.md @@ -1,5 +1,30 @@ # Changelog +## [0.2.0](https://github.com/deepgram/react/compare/react-v0.1.0...react-v0.2.0) (2026-09-10) + + +### ⚠ BREAKING CHANGES + +* **react:** `AgentMode` now includes `"thinking"`. +* **react:** Public context and hook result types add required members for the new agent controls and state. +* **react:** `registerClientTool()` now returns an unsubscribe function. +* **react:** `useDeepgramAgent().start()` begins a fresh session and clears `conversation`. + +### Features + +* **react:** Add `"thinking"` mode and `isThinking` state. +* **react:** Add `sendAgentMessage()` with `"default"`, `"queue"`, and `"interrupt"` behavior. +* **react:** Add `updateListen()`, `updateThink()`, `updateSpeak()`, and `updatePrompt()` for runtime agent settings changes. +* **react:** Add typed callbacks for protocol notifications, including settings update confirmations. +* **react:** Expose the new controls and state through `AgentProvider`, focused hooks, and `useDeepgramAgent`. + + +### Bug Fixes + +* **react:** Harden starts, stops, reconnects, and StrictMode replay so canceled or failed sessions cannot retain stale microphone, playback, or client-tool resources. +* **react:** Report automatic start failures, including microphone failures during auto-start and reconnect, through `onSdkError` or `console.error` when no callback is set. Manual `start()` rejects instead. +* **react:** Publish portable declarations that resolve agent types from `@deepgram/agents` in consumer projects. + ## 0.1.0 (2026-04-30) diff --git a/packages/react/README.md b/packages/react/README.md index 85e1de0..32ca692 100644 --- a/packages/react/README.md +++ b/packages/react/README.md @@ -288,6 +288,10 @@ export type { }; ``` +## Migration + +See the [0.1 to 0.2 migration guide](https://github.com/deepgram/react/blob/main/MIGRATION.md) when upgrading an existing integration. + ## License MIT diff --git a/packages/react/package.json b/packages/react/package.json index d48807d..c5b999b 100644 --- a/packages/react/package.json +++ b/packages/react/package.json @@ -1,6 +1,6 @@ { "name": "@deepgram/react", - "version": "0.1.0", + "version": "0.2.0", "description": "React hooks and components for @deepgram/agents", "type": "module", "main": "dist/index.cjs",