-
Notifications
You must be signed in to change notification settings - Fork 49
feat: flatten tool call records #25
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
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
7f458f7
feat: flatten tool call records
kermanx 5bdefce
Merge branch 'main' into codex/flatten-toolcall-wire-migration
kermanx 62e9836
fix: restrict legacy tool call migration
kermanx af0755c
Merge branch 'main' into codex/flatten-toolcall-wire-migration
kermanx 5c185b3
fix
kermanx 939a840
Merge branch 'codex/flatten-toolcall-wire-migration' of https://githu…
kermanx d5497c0
Merge branch 'main' into codex/flatten-toolcall-wire-migration
kermanx 41e2f34
fix
kermanx 134493c
fix: remove migration-legacy from flatten changeset
kermanx 7c8a2a6
fix: scope tool-call wire migration
kermanx 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,7 @@ | ||
| --- | ||
| "@moonshot-ai/kosong": minor | ||
| "@moonshot-ai/agent-core": minor | ||
| "@moonshot-ai/kimi-code": minor | ||
| --- | ||
|
|
||
| Flatten tool call data by inlining tool names and arguments at the top level, and limit legacy record migration so it only rewrites matching tool call payloads. | ||
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
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
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
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
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 |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| import type { WireMigration, WireMigrationRecord } from './index'; | ||
|
|
||
| /** | ||
| * Wire records before v1.1 used a nested `function` wrapper for each tool call: | ||
| * { function: { name: 'xxx', arguments: 'yyy' } } | ||
| * v1.1 flattens it to: | ||
| * { name: 'xxx', arguments: 'yyy' } | ||
| */ | ||
| interface LegacyToolCall { | ||
| type: 'function'; | ||
| id: string; | ||
| function: { | ||
| name?: string; | ||
| arguments?: string | null; | ||
| }; | ||
| } | ||
|
|
||
| function isLegacyToolCall(v: unknown): v is LegacyToolCall { | ||
| if (!isRecord(v)) return false; | ||
| return v['type'] === 'function' && typeof v['id'] === 'string' && isRecord(v['function']); | ||
| } | ||
|
|
||
| function migrateToolCall(v: LegacyToolCall): unknown { | ||
| const { function: fn, ...rest } = v; | ||
| return { | ||
| ...rest, | ||
| name: fn.name, | ||
| arguments: fn.arguments, | ||
|
kermanx marked this conversation as resolved.
|
||
| }; | ||
| } | ||
|
|
||
| function isRecord(value: unknown): value is Record<string, unknown> { | ||
| return typeof value === 'object' && value !== null && !Array.isArray(value); | ||
| } | ||
|
|
||
| export const migrateV1_0ToV1_1: WireMigration = { | ||
| sourceVersion: '1.0', | ||
| targetVersion: '1.1', | ||
| migrateRecord(record: WireMigrationRecord): WireMigrationRecord { | ||
| if (record.type !== 'context.append_message') return record; | ||
|
|
||
| const message = record['message'] as { | ||
| readonly toolCalls: readonly unknown[]; | ||
| }; | ||
|
|
||
| let changed = false; | ||
| const toolCalls = message.toolCalls.map((toolCall) => { | ||
| if (!isLegacyToolCall(toolCall)) return toolCall; | ||
| changed = true; | ||
| return migrateToolCall(toolCall); | ||
| }); | ||
|
|
||
| if (!changed) return record; | ||
|
|
||
| return { | ||
| ...record, | ||
| message: { | ||
| ...message, | ||
| toolCalls, | ||
| }, | ||
| }; | ||
| }, | ||
| }; | ||
Oops, something went wrong.
Oops, something went wrong.
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.