Skip to content

Conversation

@mattapperson
Copy link
Collaborator

No description provided.

mattapperson and others added 4 commits November 5, 2025 10:44
Implements a new client.getResponse() method that provides flexible ways to consume streaming responses:

- await response.text - Get complete text
- await response.message - Get complete AssistantMessage
- response.textStream - Stream text deltas
- response.newMessagesStream - Stream incremental AssistantMessage updates
- response.reasoningStream - Stream reasoning deltas
- response.toolStream - Stream tool call deltas
- response.fullResponsesStream - Stream all raw events
- response.fullChatStream - Stream in chat-compatible format

All consumption patterns support both concurrent and sequential access, allowing users to mix and match approaches as needed.

Key implementation details:
- ReusableReadableStream enables multiple concurrent consumers without blocking
- ResponseWrapper provides lazy initialization with cached promises
- Stream transformers convert ResponsesAPI events to different formats
- Returns AssistantMessage type for consistency with chat API

Tests: 19 passing, 1 skipped (model unavailable)
Convert all getter properties that return promises/iterators into
explicit methods with get*() naming for better API clarity and
consistency.

Changes:
- response.text → response.getText()
- response.message → response.getMessage()
- response.textStream → response.getTextStream()
- response.newMessagesStream → response.getNewMessagesStream()
- response.fullResponsesStream → response.getFullResponsesStream()
- response.reasoningStream → response.getReasoningStream()
- response.toolStream → response.getToolStream()
- response.fullChatStream → response.getFullChatStream()

Updated all test files, examples, and JSDoc documentation to reflect
the new API. All 20 e2e tests pass successfully.
- Added TurnContext type with numberOfTurns (1-indexed), messageHistory, model/models
- Updated tool execute function signatures to accept optional context parameter
- Context is built in response-wrapper.ts during tool execution loop
- Updated all tests and examples to demonstrate context usage
- Context parameter is optional for backward compatibility
- Exported TurnContext type in public API

This allows tools to access conversation state including turn number,
message history, and model information during execution.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Changed MaxToolRounds type to accept (context: TurnContext) => boolean
- Removed old 3-parameter function signature for simplicity
- Function receives full TurnContext with numberOfTurns, messageHistory, model/models
- Returns true to allow another turn, false to stop execution
- Updated examples to demonstrate the new function signature
- Simplified implementation logic in response-wrapper.ts

This provides more context to the maxToolRounds function and makes
the API more consistent with tool execute functions.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
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