-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Add AI SDK data chunk ID and tool approval types #3760
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+79
−5
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
6c6e56f
Add missing AI SDK data chunk fields for reconciliation
bendrucker fe6ef6b
Emit ToolApprovalRequestChunk for deferred tool approvals
bendrucker b29d8a7
Use public all_messages() API instead of private _state
bendrucker 70d6f6d
Use UUID for tool approval request approval_id
bendrucker 152d198
Scope PR to types + finish_reason only
bendrucker File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,6 +16,9 @@ | |
| ProviderMetadata = dict[str, dict[str, JSONValue]] | ||
| """Provider metadata.""" | ||
|
|
||
| FinishReason = Literal['stop', 'length', 'content-filter', 'tool-calls', 'error', 'other', 'unknown'] | None | ||
| """Reason why the model finished generating.""" | ||
|
|
||
|
|
||
| class BaseChunk(CamelBaseModel, ABC): | ||
| """Abstract base class for response SSE events.""" | ||
|
|
@@ -145,6 +148,21 @@ class ToolOutputErrorChunk(BaseChunk): | |
| dynamic: bool | None = None | ||
|
|
||
|
|
||
| class ToolApprovalRequestChunk(BaseChunk): | ||
| """Tool approval request chunk for human-in-the-loop approval.""" | ||
|
|
||
| type: Literal['tool-approval-request'] = 'tool-approval-request' | ||
| approval_id: str | ||
| tool_call_id: str | ||
|
|
||
|
|
||
| class ToolOutputDeniedChunk(BaseChunk): | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we ever receive (the part version) of this, and should we handle it? We'll likely need it for https://ai.pydantic.dev/deferred-tools/#human-in-the-loop-tool-approval |
||
| """Tool output denied chunk when user denies tool execution.""" | ||
|
|
||
| type: Literal['tool-output-denied'] = 'tool-output-denied' | ||
| tool_call_id: str | ||
|
|
||
|
|
||
| class SourceUrlChunk(BaseChunk): | ||
| """Source URL chunk.""" | ||
|
|
||
|
|
@@ -178,7 +196,9 @@ class DataChunk(BaseChunk): | |
| """Data chunk with dynamic type.""" | ||
|
|
||
| type: Annotated[str, Field(pattern=r'^data-')] | ||
| id: str | None = None | ||
| data: Any | ||
| transient: bool | None = None | ||
|
|
||
|
|
||
| class StartStepChunk(BaseChunk): | ||
|
|
@@ -205,6 +225,7 @@ class FinishChunk(BaseChunk): | |
| """Finish chunk.""" | ||
|
|
||
| type: Literal['finish'] = 'finish' | ||
| finish_reason: FinishReason = None | ||
bendrucker marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| message_metadata: Any | None = None | ||
|
|
||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.