Repository navigation
fix(server-utils): Keep Workers AI streamed tool calls that have no index #25835
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
Open
pcbeingused333
wants to merge
3
commits into
getsentry:develop
Choose a base branch
from
pcbeingused333:fix/workers-ai-stream-tool-calls-without-index
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
b403a7a
fix(server-utils): Keep Workers AI streamed tool calls that have no i…
pcbeingused333 2725da7
fix(server-utils): Match Workers AI streamed tool calls to OpenAI han…
pcbeingused333 b2fade5
fix(server-utils): share streamed tool call identity handling
pcbeingused333 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| interface ToolCallKeyState { | ||
| calls: Map<string, { id?: string }>; | ||
| keyByIndex: Map<number, string>; | ||
| lastKey?: string; | ||
| } | ||
|
|
||
| /** | ||
| * Find the key of the call a tool call delta belongs to. A numeric `index` groups deltas, except that a different | ||
| * non-empty `id` arriving on an index that is already taken opens a new call (a known `id` continues its own call). | ||
| * Some providers omit the index and send each parallel call whole: a known `id` continues that call, a new `id` (or | ||
| * a name without an id) starts a new call, and anything else continues the latest one. | ||
| */ | ||
| export function getToolCallKey( | ||
| toolCall: { index?: number | null; id?: string }, | ||
| name: string | undefined, | ||
| accumulator: ToolCallKeyState, | ||
| ): string { | ||
| const { calls } = accumulator; | ||
| const findById = (id: string): string | undefined => { | ||
| for (const [key, call] of calls) { | ||
| if (call.id === id) return key; | ||
| } | ||
| return undefined; | ||
| }; | ||
|
|
||
| if (typeof toolCall.index === 'number') { | ||
| const key = accumulator.keyByIndex.get(toolCall.index) ?? `index-${toolCall.index}`; | ||
| const known = toolCall.id ? findById(toolCall.id) : undefined; | ||
| if (known !== undefined) { | ||
| accumulator.keyByIndex.set(toolCall.index, known); | ||
| return known; | ||
| } | ||
| const existingId = calls.get(key)?.id; | ||
| if (existingId && toolCall.id && existingId !== toolCall.id) { | ||
| const next = findById(toolCall.id) ?? `index-${toolCall.index}-${calls.size}`; | ||
| accumulator.keyByIndex.set(toolCall.index, next); | ||
| return next; | ||
| } | ||
| return key; | ||
| } | ||
| if (toolCall.id) { | ||
| const known = findById(toolCall.id); | ||
| if (known !== undefined) { | ||
| return known; | ||
| } | ||
| } | ||
| if (toolCall.id || name || accumulator.lastKey === undefined) { | ||
| return `no-index-${calls.size}`; | ||
| } | ||
| return accumulator.lastKey; | ||
| } |
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
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
m: the new tests still only check
gen_ai.response.tool_calls. can one of them assertgen_ai.output.messagestoo, since that's what the product reads? also missingindex: nulland an id that continues a call without an index. #25622's tests port over almost as is.