Compare commits
1 Commits
main
...
claude-ver
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
dcb11ffb1f |
@ -18,20 +18,6 @@ on GitHub.
|
||||
| [Preview](preview.md) | Experimental features ready for early feedback. |
|
||||
| [Stable](latest.md) | Stable, recommended for general use. |
|
||||
|
||||
## Announcements: v0.44.0 - 2026-05-27
|
||||
|
||||
- **Unified Auto Mode:** Streamlined the automation experience by merging
|
||||
specialized Auto modes into a single, unified mode
|
||||
([#26714](https://github.com/google-gemini/gemini-cli/pull/26714) by
|
||||
@DavidAPierce).
|
||||
- **New Editor Integrations:** Added native support for Sublime Text and Emacs
|
||||
Client ([#21090](https://github.com/google-gemini/gemini-cli/pull/21090) by
|
||||
@alberti42).
|
||||
- **Enhanced TUI Testing:** Introduced `agent-tui` and `tui-tester` skills for
|
||||
programmatic testing and automation of terminal UI applications
|
||||
([#27121](https://github.com/google-gemini/gemini-cli/pull/27121) by
|
||||
@adamfweidman).
|
||||
|
||||
## Announcements: v0.43.0 - 2026-05-22
|
||||
|
||||
- **Surgical Code Edits:** Steered Gemini models to prefer the `edit` tool for
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
# Latest stable release: v0.44.0
|
||||
# Latest stable release: v0.43.0
|
||||
|
||||
Released: May 27, 2026
|
||||
Released: May 22, 2026
|
||||
|
||||
For most users, our latest stable release is the recommended release. Install
|
||||
the latest stable version with:
|
||||
@ -11,211 +11,208 @@ npm install -g @google/gemini-cli
|
||||
|
||||
## Highlights
|
||||
|
||||
- **Unified Auto Mode:** Merged all "Auto" modes into a single, unified Auto
|
||||
mode, simplifying the automation workflow and providing a more consistent
|
||||
experience across tasks.
|
||||
- **Expanded Editor Support:** Native support for Sublime Text and Emacs Client
|
||||
has been added, giving developers more flexibility in their choice of external
|
||||
editors.
|
||||
- **TUI Automation Skills:** New `agent-tui` and `tui-tester` skills enable the
|
||||
programmatic testing and automation of terminal UI (TUI) applications,
|
||||
facilitating robust verification of terminal-based tools.
|
||||
- **Improved UI Performance:** Throttled shell text output and added bounds to
|
||||
the live UI buffer to ensure smooth rendering and stability during high-volume
|
||||
output sessions.
|
||||
- **Stabilized Sandbox Environments:** Explicitly clearing entrypoints when
|
||||
spawning sandbox containers ensures reliable and consistent environment
|
||||
initialization across different Linux distributions.
|
||||
- **Surgical Code Edits:** Gemini models are now steered to prefer the `edit`
|
||||
tool for surgical modifications, leading to faster and more precise code
|
||||
updates.
|
||||
- **Session Portability:** Introduced features to export active sessions to
|
||||
files and import them later via a CLI flag, allowing for easier session
|
||||
sharing and resumption.
|
||||
- **Adaptive Token Estimation:** A new adaptive token calculator provides more
|
||||
accurate content size measurements, optimizing context window usage and
|
||||
reducing API overhead.
|
||||
- **Improved UI Rendering:** Core tools now utilize native `ToolDisplay`
|
||||
properties, fixing various UI rendering issues and improving the experience in
|
||||
ACP-compliant IDEs.
|
||||
- **Enhanced Agent Architecture:** Introduced `LocalSubagentProtocol` and
|
||||
`RemoteSubagentProtocol` behind a unified `AgentProtocol`, laying the
|
||||
groundwork for more complex multi-agent interactions.
|
||||
|
||||
## What's Changed
|
||||
|
||||
- chore(release): bump version to 0.44.0-nightly.20260512.g022e8baef by
|
||||
@gemini-cli-robot in
|
||||
[#26957](https://github.com/google-gemini/gemini-cli/pull/26957)
|
||||
- Changelog for v0.42.0 by @gemini-cli-robot in
|
||||
[#26958](https://github.com/google-gemini/gemini-cli/pull/26958)
|
||||
- Refactor: Eliminate `no-unsafe-return` suppressions via strict type validation
|
||||
by @M-DEV-1 in
|
||||
[#20668](https://github.com/google-gemini/gemini-cli/pull/20668)
|
||||
- Changelog for v0.43.0-preview.0 by @gemini-cli-robot in
|
||||
[#26959](https://github.com/google-gemini/gemini-cli/pull/26959)
|
||||
- feat(core): change agent registration to first-wins and prioritize project by
|
||||
@adamfweidman in
|
||||
[#26953](https://github.com/google-gemini/gemini-cli/pull/26953)
|
||||
- feat(cli): merge Auto modes into a single Auto mode by @DavidAPierce in
|
||||
[#26714](https://github.com/google-gemini/gemini-cli/pull/26714)
|
||||
- fix(core): preserve OAuth refresh tokens during rotation and retrieval by
|
||||
- feat(core): steer model to use edit tool for surgical edits, fix a typo by
|
||||
@aishaneeshah in
|
||||
[#26480](https://github.com/google-gemini/gemini-cli/pull/26480)
|
||||
- docs: clarify Auto Memory proposes memory updates and skills by @SandyTao520
|
||||
in [#26527](https://github.com/google-gemini/gemini-cli/pull/26527)
|
||||
- fix(core): reject numeric project IDs in GOOGLE_CLOUD_PROJECT (#24695) by
|
||||
@Abhijit-2592 in
|
||||
[#26532](https://github.com/google-gemini/gemini-cli/pull/26532)
|
||||
- fix(core): remove unsafe type assertion suppressions in error utils by
|
||||
@himanshu748 in
|
||||
[#19881](https://github.com/google-gemini/gemini-cli/pull/19881)
|
||||
- fix(core): allow redirection in YOLO and AUTO_EDIT modes without sandboxing by
|
||||
@galz10 in [#26542](https://github.com/google-gemini/gemini-cli/pull/26542)
|
||||
- ci(release): build and attach unsigned macOS binaries to releases by @ruomengz
|
||||
in [#26462](https://github.com/google-gemini/gemini-cli/pull/26462)
|
||||
- fix(core): Fix chat corruption bug in context manager. by @joshualitt in
|
||||
[#26534](https://github.com/google-gemini/gemini-cli/pull/26534)
|
||||
- fix(cli): provide JSON output for AgentExecutionStopped in non-interactive
|
||||
mode by @cynthialong0-0 in
|
||||
[#26504](https://github.com/google-gemini/gemini-cli/pull/26504)
|
||||
- feat(evals): add shell command safety evals by @akh64bit in
|
||||
[#26528](https://github.com/google-gemini/gemini-cli/pull/26528)
|
||||
- fix(core): handle invalid custom plans directory gracefully by @cynthialong0-0
|
||||
in [#26560](https://github.com/google-gemini/gemini-cli/pull/26560)
|
||||
- fix(acp): move tool explanation from thought stream to tool call content by
|
||||
@sripasg in [#26554](https://github.com/google-gemini/gemini-cli/pull/26554)
|
||||
- fix(a2a-server): Resolve race condition in tool completion waiting by @kschaab
|
||||
in [#26568](https://github.com/google-gemini/gemini-cli/pull/26568)
|
||||
- fix(cli): randomize sandbox container names by @Kkartik14 in
|
||||
[#26014](https://github.com/google-gemini/gemini-cli/pull/26014)
|
||||
- fix(core): Fix hysteresis in async context management pipelines. by
|
||||
@joshualitt in
|
||||
[#26452](https://github.com/google-gemini/gemini-cli/pull/26452)
|
||||
- Tighten private Auto Memory patch allowlist by @SandyTao520 in
|
||||
[#26535](https://github.com/google-gemini/gemini-cli/pull/26535)
|
||||
- fix(cli): hide read-only settings scopes by @cvan20191 in
|
||||
[#26249](https://github.com/google-gemini/gemini-cli/pull/26249)
|
||||
- fix(ci): preserve executable bit for mac binaries by @ruomengz in
|
||||
[#26600](https://github.com/google-gemini/gemini-cli/pull/26600)
|
||||
- fix(cli): improve mcp list UX in untrusted folders by @Adib234 in
|
||||
[#26457](https://github.com/google-gemini/gemini-cli/pull/26457)
|
||||
- fix(core): prevent silent hang during OAuth auth on headless Linux by
|
||||
@RhysSullivan in
|
||||
[#26571](https://github.com/google-gemini/gemini-cli/pull/26571)
|
||||
- Changelog for v0.42.0-preview.0 by @gemini-cli-robot in
|
||||
[#26537](https://github.com/google-gemini/gemini-cli/pull/26537)
|
||||
- ci: fix Argument list too long in triage workflows by @cocosheng-g in
|
||||
[#26603](https://github.com/google-gemini/gemini-cli/pull/26603)
|
||||
- refactor(cli): migrate core tools to native ToolDisplay property and fix UI
|
||||
rendering by @mbleigh in
|
||||
[#25186](https://github.com/google-gemini/gemini-cli/pull/25186)
|
||||
- don't wrap args unnecessarily by @scidomino in
|
||||
[#26599](https://github.com/google-gemini/gemini-cli/pull/26599)
|
||||
- fix(core): preserve system PATH in Git environment to fix ENOENT (#25034) by
|
||||
@cocosheng-g in
|
||||
[#26924](https://github.com/google-gemini/gemini-cli/pull/26924)
|
||||
- fix(cli): allow keychain auth for --list-sessions and non-interactive mode by
|
||||
[#26587](https://github.com/google-gemini/gemini-cli/pull/26587)
|
||||
- fix(routing): fix resolveClassifierModel argument mismatch in
|
||||
ApprovalModeStrategy by @danielweis in
|
||||
[#26658](https://github.com/google-gemini/gemini-cli/pull/26658)
|
||||
- docs: add vi mode shortcuts and clarify MCP/custom sandbox setup by
|
||||
@chrisjcthomas in
|
||||
[#23853](https://github.com/google-gemini/gemini-cli/pull/23853)
|
||||
- fix(ux): fixed issue with transcribed text not showing after releasing space
|
||||
by @devr0306 in
|
||||
[#26609](https://github.com/google-gemini/gemini-cli/pull/26609)
|
||||
- ci: fix json parsing in scheduled triage workflow by @cocosheng-g in
|
||||
[#26656](https://github.com/google-gemini/gemini-cli/pull/26656)
|
||||
- fix(cli): hide /memory add subcommand when memoryV2 is enabled by @SandyTao520
|
||||
in [#26605](https://github.com/google-gemini/gemini-cli/pull/26605)
|
||||
- fix: prevent false command conflicts when launching from home directory by
|
||||
@Br1an67 in [#23069](https://github.com/google-gemini/gemini-cli/pull/23069)
|
||||
- fix(core): cache model routing decision in LocalAgentExecutor by @akh64bit in
|
||||
[#26548](https://github.com/google-gemini/gemini-cli/pull/26548)
|
||||
- Changelog for v0.42.0-preview.2 by @gemini-cli-robot in
|
||||
[#26597](https://github.com/google-gemini/gemini-cli/pull/26597)
|
||||
- skip broken test by @scidomino in
|
||||
[#26705](https://github.com/google-gemini/gemini-cli/pull/26705)
|
||||
- feat: export session to file and import via flag by @cocosheng-g in
|
||||
[#26514](https://github.com/google-gemini/gemini-cli/pull/26514)
|
||||
- Feat: Add Machine Hostname to CLI interface by @M-DEV-1 in
|
||||
[#25637](https://github.com/google-gemini/gemini-cli/pull/25637)
|
||||
- docs(extensions): refactor releasing guide and add update mechanisms by
|
||||
@ruomengz in [#26595](https://github.com/google-gemini/gemini-cli/pull/26595)
|
||||
- fix(ci): fix maintainer identification in lifecycle manager by @gundermanc in
|
||||
[#26706](https://github.com/google-gemini/gemini-cli/pull/26706)
|
||||
- fix(ui): added quotes around session id in resume tip by @devr0306 in
|
||||
[#26669](https://github.com/google-gemini/gemini-cli/pull/26669)
|
||||
- Changelog for v0.41.0 by @gemini-cli-robot in
|
||||
[#26670](https://github.com/google-gemini/gemini-cli/pull/26670)
|
||||
- refactor(core): agent session protocol changes by @adamfweidman in
|
||||
[#26661](https://github.com/google-gemini/gemini-cli/pull/26661)
|
||||
- fix(context): implement loose boundary policy for gc backstop. by @joshualitt
|
||||
in [#26594](https://github.com/google-gemini/gemini-cli/pull/26594)
|
||||
- fix(core): throw explicit error on dropped tool responses by @aishaneeshah in
|
||||
[#26668](https://github.com/google-gemini/gemini-cli/pull/26668)
|
||||
- fix: resolve "function response turn must come immediately after function
|
||||
call" error by @danielweis in
|
||||
[#26691](https://github.com/google-gemini/gemini-cli/pull/26691)
|
||||
- fix(core): resolve parallel tool call streaming ID collision by @aishaneeshah
|
||||
in [#26646](https://github.com/google-gemini/gemini-cli/pull/26646)
|
||||
- feat(core): add LocalSubagentProtocol behind AgentProtocol by @adamfweidman in
|
||||
[#25302](https://github.com/google-gemini/gemini-cli/pull/25302)
|
||||
- fix(cli): remove noisy theme registration logs from terminal by @JayadityaGit
|
||||
in [#25858](https://github.com/google-gemini/gemini-cli/pull/25858)
|
||||
- ci: implement codebase-aware effort level triage by @cocosheng-g in
|
||||
[#26666](https://github.com/google-gemini/gemini-cli/pull/26666)
|
||||
- feat(acp/core): prefix tool call IDs with tool names to support tool rendering
|
||||
in ACP compliant IDEs. by @sripasg in
|
||||
[#26676](https://github.com/google-gemini/gemini-cli/pull/26676)
|
||||
- fix(mcp): treat GET 404 as 405 in StreamableHTTPClientTransport by @krishdef7
|
||||
in [#24847](https://github.com/google-gemini/gemini-cli/pull/24847)
|
||||
- feat(core): add RemoteSubagentProtocol behind AgentProtocol by @adamfweidman
|
||||
in [#25303](https://github.com/google-gemini/gemini-cli/pull/25303)
|
||||
- feat(context): Improvements to the snapshotter. by @joshualitt in
|
||||
[#26655](https://github.com/google-gemini/gemini-cli/pull/26655)
|
||||
- fix(context): Change snapshotter model config. by @joshualitt in
|
||||
[#26745](https://github.com/google-gemini/gemini-cli/pull/26745)
|
||||
- fix(cli): allow installing extensions from ssh repo by @danielmundi in
|
||||
[#26274](https://github.com/google-gemini/gemini-cli/pull/26274)
|
||||
- fix(cli): prevent duplicate SessionStart systemMessage render by @dimssu in
|
||||
[#25827](https://github.com/google-gemini/gemini-cli/pull/25827)
|
||||
- fix(cli/acp): prevent infinite thought loop in ACP mode by disablig
|
||||
nextSpeakerCheck by @sripasg in
|
||||
[#26874](https://github.com/google-gemini/gemini-cli/pull/26874)
|
||||
- fix(cli): use static tool name in confirmation prompt to avoid parsing errors
|
||||
by @cocosheng-g in
|
||||
[#26866](https://github.com/google-gemini/gemini-cli/pull/26866)
|
||||
- fix(routing): Refactor tool turn handling for the conversation history in
|
||||
NumericalClassifierStrategy to prevent 400 Bad Request by @danielweis in
|
||||
[#26761](https://github.com/google-gemini/gemini-cli/pull/26761)
|
||||
- fix(core): handle malformed projects.json in ProjectRegistry by @cocosheng-g
|
||||
in [#26885](https://github.com/google-gemini/gemini-cli/pull/26885)
|
||||
- fix(ui): added a gutter width to the input prompt width calculation by
|
||||
@devr0306 in [#26882](https://github.com/google-gemini/gemini-cli/pull/26882)
|
||||
- fix: prevent EISDIR crash when customIgnoreFilePaths contains directories
|
||||
(#19868) by @suhaan-24 in
|
||||
[#19898](https://github.com/google-gemini/gemini-cli/pull/19898)
|
||||
- revert 6b9b778d821728427eea07b1b97ba07378137d0b by @danielweis in
|
||||
[#26893](https://github.com/google-gemini/gemini-cli/pull/26893)
|
||||
- Fix/vscode run current file ts by @Neil-N4 in
|
||||
[#22894](https://github.com/google-gemini/gemini-cli/pull/22894)
|
||||
- Allow Enter to select session while in search mode in /resume by @f-pieri in
|
||||
[#21523](https://github.com/google-gemini/gemini-cli/pull/21523)
|
||||
- fix(core): ignore .pak and .rpa game archive formats by default by @Eswar809
|
||||
in [#26884](https://github.com/google-gemini/gemini-cli/pull/26884)
|
||||
- fix(cli): enable adk non-interactive session by @adamfweidman in
|
||||
[#26895](https://github.com/google-gemini/gemini-cli/pull/26895)
|
||||
- fix(cli): restore resume for legacy sessions by @KurodaKayn in
|
||||
[#26577](https://github.com/google-gemini/gemini-cli/pull/26577)
|
||||
- fix: respect explicit model selection after Flash quota exhaustion (#26759) by
|
||||
@cocosheng-g in
|
||||
[#26921](https://github.com/google-gemini/gemini-cli/pull/26921)
|
||||
- fix(core): handle EISDIR on virtual drives in memory discovery by @cocosheng-g
|
||||
in [#26985](https://github.com/google-gemini/gemini-cli/pull/26985)
|
||||
- fix(cli): auto-approve shell redirections in AUTO_EDIT mode by @cocosheng-g in
|
||||
[#27003](https://github.com/google-gemini/gemini-cli/pull/27003)
|
||||
- ci: suppress bot comments during standard triage maintenance by @cocosheng-g
|
||||
in [#27006](https://github.com/google-gemini/gemini-cli/pull/27006)
|
||||
- fix(core): refresh MCP OAuth token usage after re-auth by @sahilkirad in
|
||||
[#26312](https://github.com/google-gemini/gemini-cli/pull/26312)
|
||||
- fix(ui): clamped table column widths by @devr0306 in
|
||||
[#26991](https://github.com/google-gemini/gemini-cli/pull/26991)
|
||||
- fix(core): isolate subagent thread context by @akh64bit in
|
||||
[#26449](https://github.com/google-gemini/gemini-cli/pull/26449)
|
||||
- chore: add execution permission to scripts/review.sh by @scidomino in
|
||||
[#27009](https://github.com/google-gemini/gemini-cli/pull/27009)
|
||||
- fix(core): made context files append instead of replace by @devr0306 in
|
||||
[#26950](https://github.com/google-gemini/gemini-cli/pull/26950)
|
||||
- fix: add system PATH fallback for ripgrep resolution (#26777) by @cocosheng-g
|
||||
in [#26868](https://github.com/google-gemini/gemini-cli/pull/26868)
|
||||
- chore: clean up launched memory features by @SandyTao520 in
|
||||
[#26941](https://github.com/google-gemini/gemini-cli/pull/26941)
|
||||
- fix(core): throttle shell text output and bound live UI buffer by
|
||||
@emersonbusson in
|
||||
[#26955](https://github.com/google-gemini/gemini-cli/pull/26955)
|
||||
- fix(cli): don't crash when an @-mention captures a non-path blob by @ifitisit
|
||||
in [#25980](https://github.com/google-gemini/gemini-cli/pull/25980)
|
||||
- fix(core): ensure stable fallback for restricted preview models by @galz10 in
|
||||
[#26999](https://github.com/google-gemini/gemini-cli/pull/26999)
|
||||
- feat(core): expose RAG snippets to local log file for debugging by @spencer426
|
||||
in [#27016](https://github.com/google-gemini/gemini-cli/pull/27016)
|
||||
- fix(acp/auth): prevent conflicting credentials on enterprise gateways and
|
||||
support optional API keys natively by @sripasg in
|
||||
[#27021](https://github.com/google-gemini/gemini-cli/pull/27021)
|
||||
- fix(core): respect NO_PROXY for network-based MCP servers by @cocosheng-g in
|
||||
[#27012](https://github.com/google-gemini/gemini-cli/pull/27012)
|
||||
- fix(cli): resolve permission denied in sandbox on NixOS and other distros by
|
||||
[#26872](https://github.com/google-gemini/gemini-cli/pull/26872)
|
||||
- feat(context): Introduce adaptive token calculator to more accurately
|
||||
calculate content sizes. by @joshualitt in
|
||||
[#26888](https://github.com/google-gemini/gemini-cli/pull/26888)
|
||||
- chore: update checkout action configuration in workflows by @galz10 in
|
||||
[#26897](https://github.com/google-gemini/gemini-cli/pull/26897)
|
||||
- fix (telemetry): inject quota_project_id to prevent fallback to default oauth
|
||||
client by @TNTCompany in
|
||||
[#26698](https://github.com/google-gemini/gemini-cli/pull/26698)
|
||||
- Exclude extension context from skill extraction agent by @SandyTao520 in
|
||||
[#26879](https://github.com/google-gemini/gemini-cli/pull/26879)
|
||||
- Enable NumericalRouter when using dynamic model configs by @kevinjwang1 in
|
||||
[#26929](https://github.com/google-gemini/gemini-cli/pull/26929)
|
||||
- ci: actively triage missing priority labels and intelligently clean up
|
||||
conflicting labels by @cocosheng-g in
|
||||
[#26865](https://github.com/google-gemini/gemini-cli/pull/26865)
|
||||
- refactor(core): introduce SubagentState enum for progress by @adamfweidman in
|
||||
[#26934](https://github.com/google-gemini/gemini-cli/pull/26934)
|
||||
- fix(ci): replace brittle --no-tag with explicit staging-tmp tag by @scidomino
|
||||
in [#26940](https://github.com/google-gemini/gemini-cli/pull/26940)
|
||||
- Incremental refactor repo agent towards skills-based composition by
|
||||
@gundermanc in
|
||||
[#26717](https://github.com/google-gemini/gemini-cli/pull/26717)
|
||||
- fix(ui): fixed line wrap padding for selection lists by @devr0306 in
|
||||
[#26944](https://github.com/google-gemini/gemini-cli/pull/26944)
|
||||
- fix(core): update read_file schema for v1 compatibility (#22183) by
|
||||
@cocosheng-g in
|
||||
[#27004](https://github.com/google-gemini/gemini-cli/pull/27004)
|
||||
- fix(ui): preserve new line at the end of edit window by @devr0306 in
|
||||
[#27057](https://github.com/google-gemini/gemini-cli/pull/27057)
|
||||
- fix(core): ensure Vertex AI sets hasAccessToPreviewModels and remove
|
||||
aggressive 404 fallback revocation by @galz10 in
|
||||
[#27067](https://github.com/google-gemini/gemini-cli/pull/27067)
|
||||
- fix(core): ensure stable admin settings comparison across IPC to prevent
|
||||
restart loop by @DavidAPierce in
|
||||
[#27066](https://github.com/google-gemini/gemini-cli/pull/27066)
|
||||
- fix(deps): update vulnerable dependencies by @scidomino in
|
||||
[#27062](https://github.com/google-gemini/gemini-cli/pull/27062)
|
||||
- fix(core): resolve EISDIR errors during file processing (#21527) by @ProthamD
|
||||
in [#27041](https://github.com/google-gemini/gemini-cli/pull/27041)
|
||||
- docs(extensions): clarify env var sanitization policy for MCP and ext… by
|
||||
@galz10 in [#22854](https://github.com/google-gemini/gemini-cli/pull/22854)
|
||||
- fix(ui): add ENAMETOOLONG and ENOTDIR to exceptions for file parsing errors by
|
||||
@devr0306 in [#27069](https://github.com/google-gemini/gemini-cli/pull/27069)
|
||||
- fix(cli): explicitly clear entrypoint when spawning sandbox container by
|
||||
@cocosheng-g in
|
||||
[#27059](https://github.com/google-gemini/gemini-cli/pull/27059)
|
||||
- docs: update sandbox image command by @sjhddh in
|
||||
[#26774](https://github.com/google-gemini/gemini-cli/pull/26774)
|
||||
- fix(core): externalize https-proxy-agent to fix proxy support by @sotokisehiro
|
||||
in [#26361](https://github.com/google-gemini/gemini-cli/pull/26361)
|
||||
- security: update dependencies to fix critical and high vulnerabilities by
|
||||
@scidomino in [#27077](https://github.com/google-gemini/gemini-cli/pull/27077)
|
||||
- Fix/web fetch ctrl c abort by @ProthamD in
|
||||
[#24320](https://github.com/google-gemini/gemini-cli/pull/24320)
|
||||
- fix(core): add aliases and thinking config for gemini-3.1 models by
|
||||
@anishs1207 in
|
||||
[#27007](https://github.com/google-gemini/gemini-cli/pull/27007)
|
||||
- fix(core): use hasAccessToPreview for auto model resolution and fix
|
||||
disappearing models by @DavidAPierce in
|
||||
[#27112](https://github.com/google-gemini/gemini-cli/pull/27112)
|
||||
- feat(core): add adk.agentSessionSubagentEnabled flag by @adamfweidman in
|
||||
[#26947](https://github.com/google-gemini/gemini-cli/pull/26947)
|
||||
- fix(core): enforce compile-time exhaustiveness in content-utils by
|
||||
@adamfweidman in
|
||||
[#27207](https://github.com/google-gemini/gemini-cli/pull/27207)
|
||||
- feat(skills): add agent-tui and tui-tester skills by @adamfweidman in
|
||||
[#27121](https://github.com/google-gemini/gemini-cli/pull/27121)
|
||||
- fix(context): Fix snapshot recovery across sessions. by @joshualitt in
|
||||
[#26939](https://github.com/google-gemini/gemini-cli/pull/26939)
|
||||
- fix(core): add unit tests for stableStringify by @devr0306 in
|
||||
[#27212](https://github.com/google-gemini/gemini-cli/pull/27212)
|
||||
- fix(core): prefer pwsh.exe over Windows PowerShell 5.1 (#25859) by @kaluchi in
|
||||
[#25900](https://github.com/google-gemini/gemini-cli/pull/25900)
|
||||
- feat(core): add LocalSessionInvocation by @adamfweidman in
|
||||
[#26665](https://github.com/google-gemini/gemini-cli/pull/26665)
|
||||
- refactor: decouple auto model description and configuration from
|
||||
releaseChannel by @danielweis in
|
||||
[#27227](https://github.com/google-gemini/gemini-cli/pull/27227)
|
||||
- fix(core): prevent isBinary false-positive on Windows PTY streams by
|
||||
@TirthNaik-99 in
|
||||
[#26565](https://github.com/google-gemini/gemini-cli/pull/26565)
|
||||
- fix(cli): Prevent unmapped keys in Vim Normal mode from inserting text into
|
||||
prompt Input. by @Rajeshpatel07 in
|
||||
[#25139](https://github.com/google-gemini/gemini-cli/pull/25139)
|
||||
- fix(a2a-server): Implement default policy loading for parity with CLI by
|
||||
@kschaab in [#27073](https://github.com/google-gemini/gemini-cli/pull/27073)
|
||||
- feat(core): add RemoteSessionInvocation by @adamfweidman in
|
||||
[#26937](https://github.com/google-gemini/gemini-cli/pull/26937)
|
||||
- fix: allow configured MCP servers in non-interactive mode by @cocosheng-g in
|
||||
[#27215](https://github.com/google-gemini/gemini-cli/pull/27215)
|
||||
- fix(core): add exception handling to migrateFromFileStorage by @devr0306 in
|
||||
[#27229](https://github.com/google-gemini/gemini-cli/pull/27229)
|
||||
- fix(cli): bundle ink worker-entry.js by @rmedranollamas in
|
||||
[#27249](https://github.com/google-gemini/gemini-cli/pull/27249)
|
||||
- feat(core): wire AgentSession invocations into agent-tool by @adamfweidman in
|
||||
[#26948](https://github.com/google-gemini/gemini-cli/pull/26948)
|
||||
- fix(core): prevent path traversal in custome command file injection by
|
||||
@ompatel-aiml in
|
||||
[#27234](https://github.com/google-gemini/gemini-cli/pull/27234)
|
||||
- fix(core): respect NO_PROXY in global fetch dispatcher by @cocosheng-g in
|
||||
[#27216](https://github.com/google-gemini/gemini-cli/pull/27216)
|
||||
- fix(core): correctly handle nullable array types in MCP tools by @devr0306 in
|
||||
[#27228](https://github.com/google-gemini/gemini-cli/pull/27228)
|
||||
- fix(cli): preserve proxy-agent named exports in ESM bundle by @ashishch432 in
|
||||
[#27145](https://github.com/google-gemini/gemini-cli/pull/27145)
|
||||
- Proposal: deterministic encoding for child-process I/O by @kaluchi in
|
||||
[#27247](https://github.com/google-gemini/gemini-cli/pull/27247)
|
||||
- feat(cli): add Sublime Text and Emacs Client editors, improve error messages
|
||||
and documentation by @alberti42 in
|
||||
[#21090](https://github.com/google-gemini/gemini-cli/pull/21090)
|
||||
- Changelog for v0.43.0-preview.1 by @gemini-cli-robot in
|
||||
[#27297](https://github.com/google-gemini/gemini-cli/pull/27297)
|
||||
- fix(devtools): bundle devtools package to avoid resolution errors by
|
||||
@rmedranollamas in
|
||||
[#27250](https://github.com/google-gemini/gemini-cli/pull/27250)
|
||||
- fix(cli): integrate PolicyEngine into ACP session to prevent deadlocks
|
||||
(#23507) by @cocosheng-g in
|
||||
[#27252](https://github.com/google-gemini/gemini-cli/pull/27252)
|
||||
- fix: robust ripgrep path resolution and 1p hermetic execution support by
|
||||
@cocosheng-g in
|
||||
[#27253](https://github.com/google-gemini/gemini-cli/pull/27253)
|
||||
- refactor: decouple stored session deletion from ChatRecordingService (#22920)
|
||||
by @yuvrajangadsingh in
|
||||
[#27039](https://github.com/google-gemini/gemini-cli/pull/27039)
|
||||
- fix(core): improve Alpine shell compatibility by @dibyx in
|
||||
[#26770](https://github.com/google-gemini/gemini-cli/pull/26770)
|
||||
- fix(core): generalize MCP compliance fix for tool results by @cocosheng-g in
|
||||
[#27045](https://github.com/google-gemini/gemini-cli/pull/27045)
|
||||
- fix(scripts): scrub CI env vars in dev to keep interactive mode by @Hashaam101
|
||||
in [#27159](https://github.com/google-gemini/gemini-cli/pull/27159)
|
||||
- fix(core): Added date field for the GCal MCP by @devr0306 in
|
||||
[#27251](https://github.com/google-gemini/gemini-cli/pull/27251)
|
||||
- fix(core): centralize path validation to prevent crashes from malformed
|
||||
prompts by @cocosheng-g in
|
||||
[#27211](https://github.com/google-gemini/gemini-cli/pull/27211)
|
||||
- fix(core): prevent SIGHUP kills in PTY environments (WSL2/Kitty/Alacritty) by
|
||||
@ProthamD in [#27267](https://github.com/google-gemini/gemini-cli/pull/27267)
|
||||
- fix(core): dynamic fallback routing for exhausted quota models by @cocosheng-g
|
||||
in [#27315](https://github.com/google-gemini/gemini-cli/pull/27315)
|
||||
- Auto detect pnpm global installation path for macOS and Windows by @tisonkun
|
||||
in [#22748](https://github.com/google-gemini/gemini-cli/pull/22748)
|
||||
- fix(windows): resolve interactive shell arrow-key navigation on Windows by
|
||||
@KumarADITHYA123 in
|
||||
[#23505](https://github.com/google-gemini/gemini-cli/pull/23505)
|
||||
- ci: robust stale issue lifecycle and consolidated triage labels by
|
||||
@cocosheng-g in
|
||||
[#27015](https://github.com/google-gemini/gemini-cli/pull/27015)
|
||||
- fix(context): Ensure last message is processed. by @joshualitt in
|
||||
[#27232](https://github.com/google-gemini/gemini-cli/pull/27232)
|
||||
- chore/release: bump version to 0.44.0-nightly.20260521.g57c42a5c4 by
|
||||
@gemini-cli-robot in
|
||||
[#27324](https://github.com/google-gemini/gemini-cli/pull/27324)
|
||||
- fix(ui): added volta to auto update check by @devr0306 in
|
||||
[#27353](https://github.com/google-gemini/gemini-cli/pull/27353)
|
||||
- perf: optimize issue triage and lifecycle management by @cocosheng-g in
|
||||
[#27346](https://github.com/google-gemini/gemini-cli/pull/27346)
|
||||
[#26922](https://github.com/google-gemini/gemini-cli/pull/26922)
|
||||
- fix(ci): configure git remote with token for authentication by @scidomino in
|
||||
[#26949](https://github.com/google-gemini/gemini-cli/pull/26949)
|
||||
- fix(patch): cherry-pick 85566a7 to release/v0.43.0-preview.0-pr-27073
|
||||
[CONFLICTS] by @gemini-cli-robot in
|
||||
[#27256](https://github.com/google-gemini/gemini-cli/pull/27256)
|
||||
|
||||
**Full Changelog**:
|
||||
https://github.com/google-gemini/gemini-cli/compare/v0.43.0...v0.44.0
|
||||
https://github.com/google-gemini/gemini-cli/compare/v0.42.0...v0.43.0
|
||||
|
||||
@ -175,45 +175,4 @@ describe('EditorSettingsDialog', () => {
|
||||
}
|
||||
expect(frame).toContain('(Also modified');
|
||||
});
|
||||
|
||||
it('emits error feedback only once when preferredEditor is invalid', async () => {
|
||||
const mockEmitFeedback = vi.fn();
|
||||
vi.spyOn(
|
||||
await import('@google/gemini-cli-core').then((m) => m.coreEvents),
|
||||
'emitFeedback',
|
||||
).mockImplementation(mockEmitFeedback);
|
||||
|
||||
const invalidSettings = {
|
||||
forScope: (_scope: string) => ({
|
||||
settings: {
|
||||
general: {
|
||||
preferredEditor: 'invalideditor',
|
||||
},
|
||||
},
|
||||
}),
|
||||
merged: {
|
||||
general: {
|
||||
preferredEditor: 'invalideditor',
|
||||
},
|
||||
},
|
||||
} as unknown as LoadedSettings;
|
||||
|
||||
const { unmount } = await renderWithProvider(
|
||||
<EditorSettingsDialog
|
||||
onSelect={vi.fn()}
|
||||
settings={invalidSettings}
|
||||
onExit={vi.fn()}
|
||||
/>,
|
||||
);
|
||||
|
||||
await waitFor(() => {
|
||||
expect(mockEmitFeedback).toHaveBeenCalledWith(
|
||||
'error',
|
||||
'Editor is not supported: invalideditor',
|
||||
);
|
||||
});
|
||||
|
||||
expect(mockEmitFeedback).toHaveBeenCalledTimes(1);
|
||||
unmount();
|
||||
});
|
||||
});
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
*/
|
||||
|
||||
import type React from 'react';
|
||||
import { useState, useEffect } from 'react';
|
||||
import { useState } from 'react';
|
||||
import { Box, Text } from 'ink';
|
||||
import { theme } from '../semantic-colors.js';
|
||||
import {
|
||||
@ -22,7 +22,6 @@ import {
|
||||
type EditorType,
|
||||
isEditorAvailable,
|
||||
EDITOR_DISPLAY_NAMES,
|
||||
coreEvents,
|
||||
} from '@google/gemini-cli-core';
|
||||
import { useKeypress } from '../hooks/useKeypress.js';
|
||||
|
||||
@ -71,20 +70,10 @@ export function EditorSettingsDialog({
|
||||
(item: EditorDisplay) => item.type === currentPreference,
|
||||
)
|
||||
: 0;
|
||||
const isUnsupportedEditor = editorIndex === -1;
|
||||
if (isUnsupportedEditor) {
|
||||
if (editorIndex === -1) {
|
||||
editorIndex = 0;
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
if (isUnsupportedEditor && currentPreference) {
|
||||
coreEvents.emitFeedback(
|
||||
'error',
|
||||
`Editor is not supported: ${currentPreference}`,
|
||||
);
|
||||
}
|
||||
}, [isUnsupportedEditor, currentPreference]);
|
||||
|
||||
const scopeItems: Array<{
|
||||
label: string;
|
||||
value: LoadableSettingScope;
|
||||
|
||||
@ -60,6 +60,12 @@ exports[`InputPrompt > Highlighting and Cursor Display > single-line scenarios >
|
||||
────────────────────────────────────────────────────────────────────────────────────────────────────"
|
||||
`;
|
||||
|
||||
exports[`InputPrompt > Highlighting and Cursor Display > single-line scenarios > should display cursor correctly 'at the end of the line' 2`] = `
|
||||
"────────────────────────────────────────────────────────────────────────────────────────────────────
|
||||
> hello
|
||||
────────────────────────────────────────────────────────────────────────────────────────────────────"
|
||||
`;
|
||||
|
||||
exports[`InputPrompt > Highlighting and Cursor Display > single-line scenarios > should display cursor correctly 'for multi-byte unicode characters' 1`] = `
|
||||
"────────────────────────────────────────────────────────────────────────────────────────────────────
|
||||
> hello 👍 world
|
||||
|
||||
@ -134,5 +134,4 @@ export const WITTY_LOADING_PHRASES = [
|
||||
'Constructing additional pylons',
|
||||
'New line? That’s Ctrl+J.',
|
||||
'Releasing the HypnoDrones',
|
||||
'Pushing the button, Frank.',
|
||||
];
|
||||
|
||||
@ -30,6 +30,10 @@ import { determineSurface } from '../utils/surface.js';
|
||||
import { RecordingContentGenerator } from './recordingContentGenerator.js';
|
||||
import { getVersion, resolveModel } from '../../index.js';
|
||||
import type { LlmRole } from '../telemetry/llmRole.js';
|
||||
import {
|
||||
VertexAiContentGeneratorRouter,
|
||||
VertexAnthropicContentGenerator,
|
||||
} from './vertexAnthropicContentGenerator.js';
|
||||
|
||||
/**
|
||||
* Interface abstracting the core functionalities for generating content and counting tokens.
|
||||
@ -374,7 +378,23 @@ export async function createContentGenerator(
|
||||
},
|
||||
}),
|
||||
});
|
||||
return new LoggingContentGenerator(googleGenAI.models, gcConfig);
|
||||
const contentGenerator =
|
||||
config.authType === AuthType.USE_VERTEX_AI
|
||||
? new VertexAiContentGeneratorRouter(
|
||||
googleGenAI.models,
|
||||
new VertexAnthropicContentGenerator({
|
||||
projectId:
|
||||
process.env['GOOGLE_CLOUD_PROJECT'] ||
|
||||
process.env['GOOGLE_CLOUD_PROJECT_ID'] ||
|
||||
undefined,
|
||||
location: process.env['GOOGLE_CLOUD_LOCATION'] || undefined,
|
||||
baseUrl,
|
||||
headers,
|
||||
proxy: proxyUrl,
|
||||
}),
|
||||
)
|
||||
: googleGenAI.models;
|
||||
return new LoggingContentGenerator(contentGenerator, gcConfig);
|
||||
}
|
||||
throw new Error(
|
||||
`Error creating contentGenerator: Unsupported authType: ${config.authType}`,
|
||||
|
||||
916
packages/core/src/core/vertexAnthropicContentGenerator.test.ts
Normal file
916
packages/core/src/core/vertexAnthropicContentGenerator.test.ts
Normal file
@ -0,0 +1,916 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2026 Google LLC
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import {
|
||||
FunctionCallingConfigMode,
|
||||
GenerateContentResponse,
|
||||
ThinkingLevel,
|
||||
} from '@google/genai';
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
import { LlmRole } from '../telemetry/llmRole.js';
|
||||
import type { ContentGenerator } from './contentGenerator.js';
|
||||
import {
|
||||
isClaudeVertexModel,
|
||||
VertexAiContentGeneratorRouter,
|
||||
VertexAnthropicContentGenerator,
|
||||
} from './vertexAnthropicContentGenerator.js';
|
||||
|
||||
const mockAuth = {
|
||||
getClient: vi.fn(async () => ({
|
||||
getRequestHeaders: vi.fn(async () => ({
|
||||
Authorization: 'Bearer test-token',
|
||||
})),
|
||||
})),
|
||||
};
|
||||
|
||||
function sseResponse(chunks: unknown[]): Response {
|
||||
const body = chunks
|
||||
.map((chunk) => `data: ${JSON.stringify(chunk)}\n\n`)
|
||||
.join('');
|
||||
return new Response(
|
||||
new ReadableStream({
|
||||
start(controller) {
|
||||
controller.enqueue(new TextEncoder().encode(body));
|
||||
controller.close();
|
||||
},
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
describe('isClaudeVertexModel', () => {
|
||||
it('detects Claude Vertex model IDs', () => {
|
||||
expect(isClaudeVertexModel('claude-opus-4-8')).toBe(true);
|
||||
expect(
|
||||
isClaudeVertexModel('publishers/anthropic/models/claude-sonnet-4-6'),
|
||||
).toBe(true);
|
||||
expect(isClaudeVertexModel('gemini-2.5-pro')).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('VertexAiContentGeneratorRouter', () => {
|
||||
it('routes Claude models to the Claude generator and other models to Gemini', async () => {
|
||||
const geminiResponse = new GenerateContentResponse();
|
||||
const claudeResponse = new GenerateContentResponse();
|
||||
const geminiGenerator = {
|
||||
generateContent: vi.fn(async () => geminiResponse),
|
||||
} as unknown as ContentGenerator;
|
||||
const claudeGenerator = {
|
||||
generateContent: vi.fn(async () => claudeResponse),
|
||||
} as unknown as ContentGenerator;
|
||||
|
||||
const router = new VertexAiContentGeneratorRouter(
|
||||
geminiGenerator,
|
||||
claudeGenerator,
|
||||
);
|
||||
|
||||
await expect(
|
||||
router.generateContent(
|
||||
{ model: 'claude-opus-4-8', contents: 'hello' },
|
||||
'prompt-id',
|
||||
LlmRole.MAIN,
|
||||
),
|
||||
).resolves.toBe(claudeResponse);
|
||||
await expect(
|
||||
router.generateContent(
|
||||
{ model: 'gemini-2.5-pro', contents: 'hello' },
|
||||
'prompt-id',
|
||||
LlmRole.MAIN,
|
||||
),
|
||||
).resolves.toBe(geminiResponse);
|
||||
|
||||
expect(claudeGenerator.generateContent).toHaveBeenCalledOnce();
|
||||
expect(geminiGenerator.generateContent).toHaveBeenCalledOnce();
|
||||
});
|
||||
});
|
||||
|
||||
describe('VertexAnthropicContentGenerator', () => {
|
||||
it('converts Gemini requests and Anthropic SSE chunks', async () => {
|
||||
const fetchFn = vi.fn(async (_input: string | URL, _init?: RequestInit) =>
|
||||
sseResponse([
|
||||
{
|
||||
type: 'message_start',
|
||||
message: {
|
||||
id: 'msg_1',
|
||||
model: 'claude-opus-4-8',
|
||||
usage: { input_tokens: 7 },
|
||||
},
|
||||
},
|
||||
{
|
||||
type: 'content_block_delta',
|
||||
index: 0,
|
||||
delta: { type: 'text_delta', text: 'hello' },
|
||||
},
|
||||
{
|
||||
type: 'content_block_start',
|
||||
index: 1,
|
||||
content_block: {
|
||||
type: 'tool_use',
|
||||
id: 'toolu_1',
|
||||
name: 'read_file',
|
||||
input: {},
|
||||
},
|
||||
},
|
||||
{
|
||||
type: 'content_block_delta',
|
||||
index: 1,
|
||||
delta: {
|
||||
type: 'input_json_delta',
|
||||
partial_json: '{"path":"a.txt"}',
|
||||
},
|
||||
},
|
||||
{ type: 'content_block_stop', index: 1 },
|
||||
{
|
||||
type: 'message_delta',
|
||||
delta: { stop_reason: 'tool_use' },
|
||||
usage: { output_tokens: 3 },
|
||||
},
|
||||
{ type: 'message_stop' },
|
||||
]),
|
||||
);
|
||||
const generator = new VertexAnthropicContentGenerator({
|
||||
projectId: 'my-project',
|
||||
location: 'global',
|
||||
auth: mockAuth,
|
||||
fetchFn,
|
||||
});
|
||||
|
||||
const stream = await generator.generateContentStream(
|
||||
{
|
||||
model: 'claude-opus-4-8',
|
||||
contents: [
|
||||
{ role: 'user', parts: [{ text: 'hi' }] },
|
||||
{
|
||||
role: 'model',
|
||||
parts: [
|
||||
{
|
||||
functionCall: {
|
||||
id: 'toolu_prev',
|
||||
name: 'read_file',
|
||||
args: { path: 'old.txt' },
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
role: 'user',
|
||||
parts: [
|
||||
{
|
||||
functionResponse: {
|
||||
id: 'toolu_prev',
|
||||
name: 'read_file',
|
||||
response: { output: 'old contents' },
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
config: {
|
||||
systemInstruction: 'system prompt',
|
||||
maxOutputTokens: 123,
|
||||
topP: 0.95,
|
||||
topK: 40,
|
||||
tools: [
|
||||
{
|
||||
functionDeclarations: [
|
||||
{
|
||||
name: 'read_file',
|
||||
description: 'Read a file',
|
||||
parametersJsonSchema: {
|
||||
type: 'object',
|
||||
properties: { path: { type: 'string' } },
|
||||
required: ['path'],
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
toolConfig: {
|
||||
functionCallingConfig: {
|
||||
mode: FunctionCallingConfigMode.ANY,
|
||||
allowedFunctionNames: ['read_file'],
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
'prompt-id',
|
||||
LlmRole.MAIN,
|
||||
);
|
||||
|
||||
const chunks: GenerateContentResponse[] = [];
|
||||
for await (const chunk of stream) {
|
||||
chunks.push(chunk);
|
||||
}
|
||||
|
||||
expect(fetchFn).toHaveBeenCalledWith(
|
||||
'https://aiplatform.googleapis.com/v1/projects/my-project/locations/global/publishers/anthropic/models/claude-opus-4-8:streamRawPredict',
|
||||
expect.objectContaining({
|
||||
method: 'POST',
|
||||
headers: expect.objectContaining({
|
||||
Authorization: 'Bearer test-token',
|
||||
'Content-Type': 'application/json',
|
||||
}),
|
||||
}),
|
||||
);
|
||||
|
||||
const body = JSON.parse(
|
||||
(fetchFn.mock.calls[0]?.[1] as RequestInit).body as string,
|
||||
) as Record<string, unknown>;
|
||||
expect(body).toMatchObject({
|
||||
anthropic_version: 'vertex-2023-10-16',
|
||||
system: 'system prompt',
|
||||
max_tokens: 123,
|
||||
stream: true,
|
||||
tool_choice: { type: 'tool', name: 'read_file' },
|
||||
});
|
||||
expect(body).not.toHaveProperty('model');
|
||||
expect(body).not.toHaveProperty('top_p');
|
||||
expect(body).not.toHaveProperty('top_k');
|
||||
expect(body['tools']).toEqual([
|
||||
{
|
||||
name: 'read_file',
|
||||
description: 'Read a file',
|
||||
input_schema: {
|
||||
type: 'object',
|
||||
properties: { path: { type: 'string' } },
|
||||
required: ['path'],
|
||||
},
|
||||
},
|
||||
]);
|
||||
expect(body['messages']).toEqual([
|
||||
{ role: 'user', content: [{ type: 'text', text: 'hi' }] },
|
||||
{
|
||||
role: 'assistant',
|
||||
content: [
|
||||
{
|
||||
type: 'tool_use',
|
||||
id: 'toolu_prev',
|
||||
name: 'read_file',
|
||||
input: { path: 'old.txt' },
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
role: 'user',
|
||||
content: [
|
||||
{
|
||||
type: 'tool_result',
|
||||
tool_use_id: 'toolu_prev',
|
||||
content: 'old contents',
|
||||
},
|
||||
],
|
||||
},
|
||||
]);
|
||||
|
||||
expect(chunks[0].candidates?.[0]?.content?.parts?.[0]?.text).toBe('hello');
|
||||
expect(chunks[1].functionCalls).toEqual([
|
||||
{ id: 'toolu_1', name: 'read_file', args: { path: 'a.txt' } },
|
||||
]);
|
||||
expect(chunks[2].candidates?.[0]?.finishReason).toBe('STOP');
|
||||
expect(chunks[2].usageMetadata).toMatchObject({
|
||||
promptTokenCount: 7,
|
||||
candidatesTokenCount: 3,
|
||||
totalTokenCount: 10,
|
||||
});
|
||||
});
|
||||
|
||||
it('uses adaptive thinking for Claude Opus 4.8 and omits unsupported sampling parameters', async () => {
|
||||
const fetchFn = vi.fn(
|
||||
async (_input: string | URL, _init?: RequestInit) =>
|
||||
new Response(
|
||||
JSON.stringify({
|
||||
id: 'msg_1',
|
||||
model: 'claude-opus-4-8',
|
||||
content: [{ type: 'text', text: 'hello' }],
|
||||
stop_reason: 'end_turn',
|
||||
}),
|
||||
),
|
||||
);
|
||||
const generator = new VertexAnthropicContentGenerator({
|
||||
projectId: 'my-project',
|
||||
location: 'global',
|
||||
auth: mockAuth,
|
||||
fetchFn,
|
||||
});
|
||||
|
||||
await generator.generateContent(
|
||||
{
|
||||
model: 'claude-opus-4-8',
|
||||
contents: 'hi',
|
||||
config: {
|
||||
temperature: 1,
|
||||
thinkingConfig: {
|
||||
includeThoughts: true,
|
||||
thinkingBudget: 8192,
|
||||
},
|
||||
},
|
||||
},
|
||||
'prompt-id',
|
||||
LlmRole.MAIN,
|
||||
);
|
||||
|
||||
const body = JSON.parse(
|
||||
(fetchFn.mock.calls[0]?.[1] as RequestInit).body as string,
|
||||
) as Record<string, unknown>;
|
||||
expect(body['thinking']).toEqual({
|
||||
type: 'adaptive',
|
||||
display: 'summarized',
|
||||
});
|
||||
expect(body['max_tokens']).toBe(128_000);
|
||||
expect(body['thinking']).not.toHaveProperty('budget_tokens');
|
||||
expect(body).not.toHaveProperty('temperature');
|
||||
});
|
||||
|
||||
it('uses max output defaults only for Claude Opus 4 models', async () => {
|
||||
const fetchFn = vi.fn(
|
||||
async (_input: string | URL, _init?: RequestInit) =>
|
||||
new Response(
|
||||
JSON.stringify({
|
||||
id: 'msg_1',
|
||||
model: 'claude-opus-4-8',
|
||||
content: [{ type: 'text', text: 'hello' }],
|
||||
stop_reason: 'end_turn',
|
||||
}),
|
||||
),
|
||||
);
|
||||
const generator = new VertexAnthropicContentGenerator({
|
||||
projectId: 'my-project',
|
||||
location: 'global',
|
||||
auth: mockAuth,
|
||||
fetchFn,
|
||||
});
|
||||
|
||||
for (const model of [
|
||||
'claude-opus-4-8',
|
||||
'claude-opus-4-5@20251101',
|
||||
'claude-opus-4-1@20250805',
|
||||
'claude-sonnet-4-6',
|
||||
]) {
|
||||
await generator.generateContent(
|
||||
{ model, contents: 'hi' },
|
||||
'prompt-id',
|
||||
LlmRole.MAIN,
|
||||
);
|
||||
}
|
||||
|
||||
const bodies = fetchFn.mock.calls.map(
|
||||
(call) =>
|
||||
JSON.parse((call[1] as RequestInit).body as string) as Record<
|
||||
string,
|
||||
unknown
|
||||
>,
|
||||
);
|
||||
expect(bodies.map((body) => body['max_tokens'])).toEqual([
|
||||
128_000, 64_000, 32_000, 8192,
|
||||
]);
|
||||
});
|
||||
|
||||
it('maps Gemini thinking levels to Claude effort and keeps tool choice compatible with thinking', async () => {
|
||||
const fetchFn = vi.fn(
|
||||
async (_input: string | URL, _init?: RequestInit) =>
|
||||
new Response(
|
||||
JSON.stringify({
|
||||
id: 'msg_1',
|
||||
model: 'claude-opus-4-8',
|
||||
content: [{ type: 'text', text: 'hello' }],
|
||||
stop_reason: 'end_turn',
|
||||
}),
|
||||
),
|
||||
);
|
||||
const generator = new VertexAnthropicContentGenerator({
|
||||
projectId: 'my-project',
|
||||
location: 'global',
|
||||
auth: mockAuth,
|
||||
fetchFn,
|
||||
});
|
||||
|
||||
await generator.generateContent(
|
||||
{
|
||||
model: 'claude-opus-4-8',
|
||||
contents: 'hi',
|
||||
config: {
|
||||
thinkingConfig: {
|
||||
thinkingLevel: ThinkingLevel.LOW,
|
||||
},
|
||||
tools: [
|
||||
{
|
||||
functionDeclarations: [
|
||||
{
|
||||
name: 'read_file',
|
||||
parametersJsonSchema: { type: 'object' },
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
toolConfig: {
|
||||
functionCallingConfig: {
|
||||
mode: FunctionCallingConfigMode.ANY,
|
||||
allowedFunctionNames: ['read_file'],
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
'prompt-id',
|
||||
LlmRole.MAIN,
|
||||
);
|
||||
|
||||
const body = JSON.parse(
|
||||
(fetchFn.mock.calls[0]?.[1] as RequestInit).body as string,
|
||||
) as Record<string, unknown>;
|
||||
expect(body['thinking']).toEqual({ type: 'adaptive' });
|
||||
expect(body['output_config']).toEqual({ effort: 'low' });
|
||||
expect(body['tool_choice']).toEqual({ type: 'auto' });
|
||||
});
|
||||
|
||||
it('keeps manual thinking budgets for older Claude models', async () => {
|
||||
const fetchFn = vi.fn(
|
||||
async (_input: string | URL, _init?: RequestInit) =>
|
||||
new Response(
|
||||
JSON.stringify({
|
||||
id: 'msg_1',
|
||||
model: 'claude-sonnet-4-5',
|
||||
content: [{ type: 'text', text: 'hello' }],
|
||||
stop_reason: 'end_turn',
|
||||
}),
|
||||
),
|
||||
);
|
||||
const generator = new VertexAnthropicContentGenerator({
|
||||
projectId: 'my-project',
|
||||
location: 'global',
|
||||
auth: mockAuth,
|
||||
fetchFn,
|
||||
});
|
||||
|
||||
await generator.generateContent(
|
||||
{
|
||||
model: 'claude-sonnet-4-5',
|
||||
contents: 'hi',
|
||||
config: {
|
||||
maxOutputTokens: 5000,
|
||||
thinkingConfig: {
|
||||
includeThoughts: true,
|
||||
thinkingBudget: 4096,
|
||||
},
|
||||
},
|
||||
},
|
||||
'prompt-id',
|
||||
LlmRole.MAIN,
|
||||
);
|
||||
|
||||
const body = JSON.parse(
|
||||
(fetchFn.mock.calls[0]?.[1] as RequestInit).body as string,
|
||||
) as Record<string, unknown>;
|
||||
expect(body['thinking']).toEqual({
|
||||
type: 'enabled',
|
||||
budget_tokens: 4096,
|
||||
display: 'summarized',
|
||||
});
|
||||
expect(body['max_tokens']).toBe(5120);
|
||||
});
|
||||
|
||||
it('round-trips Claude thinking signatures on tool-use turns', async () => {
|
||||
const fetchFn = vi
|
||||
.fn()
|
||||
.mockResolvedValueOnce(
|
||||
sseResponse([
|
||||
{
|
||||
type: 'message_start',
|
||||
message: { id: 'msg_1', model: 'claude-opus-4-8' },
|
||||
},
|
||||
{
|
||||
type: 'content_block_start',
|
||||
index: 0,
|
||||
content_block: { type: 'thinking', thinking: '', signature: '' },
|
||||
},
|
||||
{
|
||||
type: 'content_block_delta',
|
||||
index: 0,
|
||||
delta: {
|
||||
type: 'thinking_delta',
|
||||
thinking: 'I should call the tool.',
|
||||
},
|
||||
},
|
||||
{
|
||||
type: 'content_block_delta',
|
||||
index: 0,
|
||||
delta: { type: 'signature_delta', signature: 'sig_old' },
|
||||
},
|
||||
{
|
||||
type: 'content_block_delta',
|
||||
index: 0,
|
||||
delta: { type: 'signature_delta', signature: 'sig_abc' },
|
||||
},
|
||||
{ type: 'content_block_stop', index: 0 },
|
||||
{
|
||||
type: 'content_block_start',
|
||||
index: 1,
|
||||
content_block: {
|
||||
type: 'redacted_thinking',
|
||||
data: 'opaque_redacted_data',
|
||||
},
|
||||
},
|
||||
{ type: 'content_block_stop', index: 1 },
|
||||
{
|
||||
type: 'content_block_start',
|
||||
index: 2,
|
||||
content_block: {
|
||||
type: 'tool_use',
|
||||
id: 'toolu_1',
|
||||
name: 'read_file',
|
||||
input: {},
|
||||
},
|
||||
},
|
||||
{
|
||||
type: 'content_block_delta',
|
||||
index: 2,
|
||||
delta: {
|
||||
type: 'input_json_delta',
|
||||
partial_json: '{"path":"a.txt"}',
|
||||
},
|
||||
},
|
||||
{ type: 'content_block_stop', index: 2 },
|
||||
{ type: 'message_delta', delta: { stop_reason: 'tool_use' } },
|
||||
]),
|
||||
)
|
||||
.mockResolvedValueOnce(
|
||||
new Response(
|
||||
JSON.stringify({
|
||||
id: 'msg_2',
|
||||
model: 'claude-opus-4-8',
|
||||
content: [{ type: 'text', text: 'done' }],
|
||||
stop_reason: 'end_turn',
|
||||
}),
|
||||
),
|
||||
);
|
||||
const generator = new VertexAnthropicContentGenerator({
|
||||
projectId: 'my-project',
|
||||
location: 'global',
|
||||
auth: mockAuth,
|
||||
fetchFn,
|
||||
});
|
||||
|
||||
const stream = await generator.generateContentStream(
|
||||
{
|
||||
model: 'claude-opus-4-8',
|
||||
contents: 'hi',
|
||||
},
|
||||
'prompt-id',
|
||||
LlmRole.MAIN,
|
||||
);
|
||||
const chunks: GenerateContentResponse[] = [];
|
||||
for await (const chunk of stream) {
|
||||
chunks.push(chunk);
|
||||
}
|
||||
|
||||
const toolPart = chunks
|
||||
.flatMap((chunk) => chunk.candidates?.[0]?.content?.parts ?? [])
|
||||
.find((part) => part.functionCall);
|
||||
const thoughtSignature = (toolPart as { thoughtSignature?: string })
|
||||
.thoughtSignature;
|
||||
expect(thoughtSignature).toMatch(/^claude_thinking:/);
|
||||
|
||||
await generator.generateContent(
|
||||
{
|
||||
model: 'claude-opus-4-8',
|
||||
contents: [
|
||||
{
|
||||
role: 'model',
|
||||
parts: [toolPart!],
|
||||
},
|
||||
{
|
||||
role: 'user',
|
||||
parts: [
|
||||
{
|
||||
functionResponse: {
|
||||
id: 'toolu_1',
|
||||
name: 'read_file',
|
||||
response: { output: 'contents' },
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
'prompt-id',
|
||||
LlmRole.MAIN,
|
||||
);
|
||||
|
||||
const body = JSON.parse(
|
||||
(fetchFn.mock.calls[1]?.[1] as RequestInit).body as string,
|
||||
) as Record<string, Array<{ content: unknown[] }>>;
|
||||
expect(body['messages'][0]?.content).toEqual([
|
||||
{
|
||||
type: 'thinking',
|
||||
thinking: 'I should call the tool.',
|
||||
signature: 'sig_abc',
|
||||
},
|
||||
{
|
||||
type: 'redacted_thinking',
|
||||
data: 'opaque_redacted_data',
|
||||
},
|
||||
{
|
||||
type: 'tool_use',
|
||||
id: 'toolu_1',
|
||||
name: 'read_file',
|
||||
input: { path: 'a.txt' },
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
it('handles a full JSON message on the streaming endpoint', async () => {
|
||||
const fetchFn = vi.fn(
|
||||
async (_input: string | URL, _init?: RequestInit) =>
|
||||
new Response(
|
||||
JSON.stringify({
|
||||
id: 'msg_json',
|
||||
type: 'message',
|
||||
model: 'claude-opus-4-8',
|
||||
content: [{ type: 'text', text: 'complete response' }],
|
||||
stop_reason: 'end_turn',
|
||||
usage: { input_tokens: 5, output_tokens: 2 },
|
||||
}),
|
||||
{ headers: { 'Content-Type': 'application/json' } },
|
||||
),
|
||||
);
|
||||
const generator = new VertexAnthropicContentGenerator({
|
||||
projectId: 'my-project',
|
||||
location: 'global',
|
||||
auth: mockAuth,
|
||||
fetchFn,
|
||||
});
|
||||
|
||||
const stream = await generator.generateContentStream(
|
||||
{
|
||||
model: 'claude-opus-4-8',
|
||||
contents: [{ role: 'user', parts: [{ text: 'hi' }] }],
|
||||
},
|
||||
'prompt-id',
|
||||
LlmRole.MAIN,
|
||||
);
|
||||
|
||||
const chunks: GenerateContentResponse[] = [];
|
||||
for await (const chunk of stream) {
|
||||
chunks.push(chunk);
|
||||
}
|
||||
|
||||
const body = JSON.parse(
|
||||
(fetchFn.mock.calls[0]?.[1] as RequestInit).body as string,
|
||||
) as Record<string, unknown>;
|
||||
expect(body['stream']).toBe(true);
|
||||
expect(chunks).toHaveLength(1);
|
||||
expect(chunks[0].candidates?.[0]?.content?.parts?.[0]?.text).toBe(
|
||||
'complete response',
|
||||
);
|
||||
expect(chunks[0].candidates?.[0]?.finishReason).toBe('STOP');
|
||||
expect(chunks[0].usageMetadata).toMatchObject({
|
||||
promptTokenCount: 5,
|
||||
candidatesTokenCount: 2,
|
||||
totalTokenCount: 7,
|
||||
});
|
||||
});
|
||||
|
||||
it('sanitizes Claude tool names and maps tool calls back to Gemini names', async () => {
|
||||
const geminiToolName = 'mcp.read/file:custom';
|
||||
const claudeToolName = 'mcp_read_file_custom';
|
||||
const fetchFn = vi.fn(async (_input: string | URL, _init?: RequestInit) =>
|
||||
sseResponse([
|
||||
{
|
||||
type: 'message_start',
|
||||
message: { id: 'msg_2', model: 'claude-opus-4-8' },
|
||||
},
|
||||
{
|
||||
type: 'content_block_start',
|
||||
index: 0,
|
||||
content_block: {
|
||||
type: 'tool_use',
|
||||
id: 'toolu_2',
|
||||
name: claudeToolName,
|
||||
input: {},
|
||||
},
|
||||
},
|
||||
{
|
||||
type: 'content_block_delta',
|
||||
index: 0,
|
||||
delta: {
|
||||
type: 'input_json_delta',
|
||||
partial_json: '{"path":"b.txt"}',
|
||||
},
|
||||
},
|
||||
{ type: 'content_block_stop', index: 0 },
|
||||
{ type: 'message_delta', delta: { stop_reason: 'tool_use' } },
|
||||
]),
|
||||
);
|
||||
const generator = new VertexAnthropicContentGenerator({
|
||||
projectId: 'my-project',
|
||||
location: 'global',
|
||||
auth: mockAuth,
|
||||
fetchFn,
|
||||
});
|
||||
|
||||
const stream = await generator.generateContentStream(
|
||||
{
|
||||
model: 'claude-opus-4-8',
|
||||
contents: [
|
||||
{ role: 'user', parts: [{ text: 'call the tool' }] },
|
||||
{
|
||||
role: 'model',
|
||||
parts: [
|
||||
{
|
||||
functionCall: {
|
||||
id: 'toolu_prev',
|
||||
name: geminiToolName,
|
||||
args: { path: 'old.txt' },
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
config: {
|
||||
tools: [
|
||||
{
|
||||
functionDeclarations: [
|
||||
{
|
||||
name: geminiToolName,
|
||||
parametersJsonSchema: {
|
||||
type: 'object',
|
||||
properties: { path: { type: 'string' } },
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
toolConfig: {
|
||||
functionCallingConfig: {
|
||||
mode: FunctionCallingConfigMode.ANY,
|
||||
allowedFunctionNames: [geminiToolName],
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
'prompt-id',
|
||||
LlmRole.MAIN,
|
||||
);
|
||||
|
||||
const chunks: GenerateContentResponse[] = [];
|
||||
for await (const chunk of stream) {
|
||||
chunks.push(chunk);
|
||||
}
|
||||
|
||||
const body = JSON.parse(
|
||||
(fetchFn.mock.calls[0]?.[1] as RequestInit).body as string,
|
||||
) as Record<string, unknown>;
|
||||
expect(body['tools']).toEqual([
|
||||
{
|
||||
name: claudeToolName,
|
||||
input_schema: {
|
||||
type: 'object',
|
||||
properties: { path: { type: 'string' } },
|
||||
},
|
||||
},
|
||||
]);
|
||||
expect(body['tool_choice']).toEqual({
|
||||
type: 'tool',
|
||||
name: claudeToolName,
|
||||
});
|
||||
expect(body['messages']).toEqual([
|
||||
{ role: 'user', content: [{ type: 'text', text: 'call the tool' }] },
|
||||
{
|
||||
role: 'assistant',
|
||||
content: [
|
||||
{
|
||||
type: 'tool_use',
|
||||
id: 'toolu_prev',
|
||||
name: claudeToolName,
|
||||
input: { path: 'old.txt' },
|
||||
},
|
||||
],
|
||||
},
|
||||
]);
|
||||
expect(chunks[0].functionCalls).toEqual([
|
||||
{ id: 'toolu_2', name: geminiToolName, args: { path: 'b.txt' } },
|
||||
]);
|
||||
});
|
||||
|
||||
it('normalizes tool input schemas for Anthropic JSON Schema validation', async () => {
|
||||
const fetchFn = vi.fn(
|
||||
async (_input: string | URL, _init?: RequestInit) =>
|
||||
new Response(
|
||||
JSON.stringify({
|
||||
id: 'msg_3',
|
||||
content: [],
|
||||
stop_reason: 'end_turn',
|
||||
}),
|
||||
{ headers: { 'Content-Type': 'application/json' } },
|
||||
),
|
||||
);
|
||||
const generator = new VertexAnthropicContentGenerator({
|
||||
projectId: 'my-project',
|
||||
location: 'global',
|
||||
auth: mockAuth,
|
||||
fetchFn,
|
||||
});
|
||||
|
||||
await generator.generateContent(
|
||||
{
|
||||
model: 'claude-opus-4-8',
|
||||
contents: [{ role: 'user', parts: [{ text: 'hi' }] }],
|
||||
config: {
|
||||
tools: [
|
||||
{
|
||||
functionDeclarations: [
|
||||
{
|
||||
name: 'schema_tool',
|
||||
parametersJsonSchema: {
|
||||
$schema: 'http://json-schema.org/draft-07/schema#',
|
||||
$ref: '#/definitions/Root',
|
||||
definitions: {
|
||||
Root: {
|
||||
type: 'OBJECT',
|
||||
propertyOrdering: ['meta', 'maybeTags'],
|
||||
properties: {
|
||||
meta: {
|
||||
type: 'OBJECT',
|
||||
additionalProperties: { type: 'STRING' },
|
||||
},
|
||||
maybeTags: {
|
||||
type: 'ARRAY',
|
||||
items: { type: 'STRING' },
|
||||
nullable: true,
|
||||
},
|
||||
union: {
|
||||
oneOf: [{ type: 'STRING' }, { type: 'INTEGER' }],
|
||||
},
|
||||
},
|
||||
required: [],
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
'prompt-id',
|
||||
LlmRole.MAIN,
|
||||
);
|
||||
|
||||
const body = JSON.parse(
|
||||
(fetchFn.mock.calls[0]?.[1] as RequestInit).body as string,
|
||||
) as Record<string, unknown>;
|
||||
expect(body['tools']).toEqual([
|
||||
{
|
||||
name: 'schema_tool',
|
||||
input_schema: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
meta: {
|
||||
type: 'object',
|
||||
additionalProperties: { type: 'string' },
|
||||
},
|
||||
maybeTags: {
|
||||
type: ['array', 'null'],
|
||||
items: { type: 'string' },
|
||||
},
|
||||
union: {
|
||||
oneOf: [{ type: 'string' }, { type: 'integer' }],
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
it('uses the count-tokens rawPredict endpoint', async () => {
|
||||
const fetchFn = vi.fn(
|
||||
async (_input: string | URL, _init?: RequestInit) =>
|
||||
new Response(JSON.stringify({ input_tokens: 42 }), {
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
}),
|
||||
);
|
||||
const generator = new VertexAnthropicContentGenerator({
|
||||
projectId: 'my-project',
|
||||
location: 'us-east5',
|
||||
auth: mockAuth,
|
||||
fetchFn,
|
||||
});
|
||||
|
||||
await expect(
|
||||
generator.countTokens({
|
||||
model: 'claude-opus-4-8',
|
||||
contents: [{ role: 'user', parts: [{ text: 'hello' }] }],
|
||||
}),
|
||||
).resolves.toEqual({ totalTokens: 42 });
|
||||
|
||||
expect(fetchFn.mock.calls[0]?.[0]).toBe(
|
||||
'https://us-east5-aiplatform.googleapis.com/v1/projects/my-project/locations/us-east5/publishers/anthropic/models/count-tokens:rawPredict',
|
||||
);
|
||||
const body = JSON.parse(
|
||||
(fetchFn.mock.calls[0]?.[1] as RequestInit).body as string,
|
||||
) as Record<string, unknown>;
|
||||
expect(body['model']).toBe('claude-opus-4-8');
|
||||
expect(body).not.toHaveProperty('max_tokens');
|
||||
});
|
||||
});
|
||||
1775
packages/core/src/core/vertexAnthropicContentGenerator.ts
Normal file
1775
packages/core/src/core/vertexAnthropicContentGenerator.ts
Normal file
File diff suppressed because it is too large
Load Diff
@ -186,6 +186,153 @@ describe('convertSessionToClientHistory', () => {
|
||||
]);
|
||||
});
|
||||
|
||||
it('should not duplicate explicit tool response turns on resume', () => {
|
||||
const toolResponse = {
|
||||
functionResponse: {
|
||||
id: 'toolu_1',
|
||||
name: 'web_fetch',
|
||||
response: { output: 'page content' },
|
||||
},
|
||||
};
|
||||
const messages: ConversationRecord['messages'] = [
|
||||
{
|
||||
id: 'msg1',
|
||||
type: 'user',
|
||||
timestamp: '2024-01-01T10:00:00Z',
|
||||
content: 'Fetch this page',
|
||||
},
|
||||
{
|
||||
id: 'msg2',
|
||||
type: 'gemini',
|
||||
timestamp: '2024-01-01T10:01:00Z',
|
||||
content: [
|
||||
{ text: 'Let me fetch it.' },
|
||||
{
|
||||
functionCall: {
|
||||
id: 'toolu_1',
|
||||
name: 'web_fetch',
|
||||
args: { url: 'https://example.com' },
|
||||
},
|
||||
},
|
||||
],
|
||||
toolCalls: [
|
||||
{
|
||||
id: 'toolu_1',
|
||||
name: 'web_fetch',
|
||||
args: { url: 'https://example.com' },
|
||||
status: CoreToolCallStatus.Success,
|
||||
timestamp: '2024-01-01T10:01:05Z',
|
||||
result: [toolResponse],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
id: 'msg3',
|
||||
type: 'user',
|
||||
timestamp: '2024-01-01T10:01:06Z',
|
||||
content: [toolResponse],
|
||||
},
|
||||
];
|
||||
|
||||
const history = convertSessionToClientHistory(messages);
|
||||
|
||||
expect(history.map((h) => h.content)).toEqual([
|
||||
{ role: 'user', parts: [{ text: 'Fetch this page' }] },
|
||||
{
|
||||
role: 'model',
|
||||
parts: [
|
||||
{ text: 'Let me fetch it.' },
|
||||
{
|
||||
functionCall: {
|
||||
id: 'toolu_1',
|
||||
name: 'web_fetch',
|
||||
args: { url: 'https://example.com' },
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
{ role: 'user', parts: [toolResponse] },
|
||||
]);
|
||||
});
|
||||
|
||||
it('should deduplicate grouped tool results stored on multiple tool calls', () => {
|
||||
const groupedResults = [
|
||||
{
|
||||
functionResponse: {
|
||||
id: 'call1',
|
||||
name: 'read_file',
|
||||
response: { output: 'file contents' },
|
||||
},
|
||||
},
|
||||
{
|
||||
functionResponse: {
|
||||
id: 'call2',
|
||||
name: 'list_files',
|
||||
response: { output: 'file.txt' },
|
||||
},
|
||||
},
|
||||
];
|
||||
const messages: ConversationRecord['messages'] = [
|
||||
{
|
||||
id: 'msg1',
|
||||
type: 'user',
|
||||
timestamp: '2024-01-01T10:00:00Z',
|
||||
content: 'Inspect the project',
|
||||
},
|
||||
{
|
||||
id: 'msg2',
|
||||
type: 'gemini',
|
||||
timestamp: '2024-01-01T10:01:00Z',
|
||||
content: 'I will inspect it.',
|
||||
toolCalls: [
|
||||
{
|
||||
id: 'call1',
|
||||
name: 'read_file',
|
||||
args: { path: 'README.md' },
|
||||
status: CoreToolCallStatus.Success,
|
||||
timestamp: '2024-01-01T10:01:05Z',
|
||||
result: groupedResults,
|
||||
},
|
||||
{
|
||||
id: 'call2',
|
||||
name: 'list_files',
|
||||
args: { dir: '.' },
|
||||
status: CoreToolCallStatus.Success,
|
||||
timestamp: '2024-01-01T10:01:06Z',
|
||||
result: groupedResults,
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
const history = convertSessionToClientHistory(messages);
|
||||
|
||||
expect(history.map((h) => h.content)).toEqual([
|
||||
{ role: 'user', parts: [{ text: 'Inspect the project' }] },
|
||||
{
|
||||
role: 'model',
|
||||
parts: [
|
||||
{ text: 'I will inspect it.' },
|
||||
{
|
||||
functionCall: {
|
||||
id: 'call1',
|
||||
name: 'read_file',
|
||||
args: { path: 'README.md' },
|
||||
},
|
||||
},
|
||||
{
|
||||
functionCall: {
|
||||
id: 'call2',
|
||||
name: 'list_files',
|
||||
args: { dir: '.' },
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
{ role: 'user', parts: groupedResults },
|
||||
]);
|
||||
});
|
||||
|
||||
it('should preserve multi-modal parts (inlineData)', () => {
|
||||
const messages: ConversationRecord['messages'] = [
|
||||
{
|
||||
|
||||
@ -94,6 +94,65 @@ function ensurePartArray(content: PartListUnion): Part[] {
|
||||
return [content];
|
||||
}
|
||||
|
||||
function collectExplicitFunctionResponseIds(
|
||||
messages: ConversationRecord['messages'],
|
||||
): Set<string> {
|
||||
const ids = new Set<string>();
|
||||
for (const msg of messages) {
|
||||
if (msg.type !== 'user') {
|
||||
continue;
|
||||
}
|
||||
|
||||
for (const part of ensurePartArray(msg.content)) {
|
||||
const id = part.functionResponse?.id;
|
||||
if (id) {
|
||||
ids.add(id);
|
||||
}
|
||||
}
|
||||
}
|
||||
return ids;
|
||||
}
|
||||
|
||||
function appendFunctionResponseParts(
|
||||
target: Part[],
|
||||
parts: Part[],
|
||||
explicitResponseIds: ReadonlySet<string>,
|
||||
generatedResponseIds: Set<string>,
|
||||
): void {
|
||||
const partsToAppend: Part[] = [];
|
||||
const idsToMark: string[] = [];
|
||||
let hasFunctionResponse = false;
|
||||
let hasNewFunctionResponse = false;
|
||||
|
||||
for (const part of parts) {
|
||||
const id = part.functionResponse?.id;
|
||||
if (!part.functionResponse) {
|
||||
partsToAppend.push(part);
|
||||
continue;
|
||||
}
|
||||
|
||||
hasFunctionResponse = true;
|
||||
if (id && (explicitResponseIds.has(id) || generatedResponseIds.has(id))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
partsToAppend.push(part);
|
||||
hasNewFunctionResponse = true;
|
||||
if (id) {
|
||||
idsToMark.push(id);
|
||||
}
|
||||
}
|
||||
|
||||
if (hasFunctionResponse && !hasNewFunctionResponse) {
|
||||
return;
|
||||
}
|
||||
|
||||
target.push(...partsToAppend);
|
||||
for (const id of idsToMark) {
|
||||
generatedResponseIds.add(id);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts session/conversation data into Gemini client history formats.
|
||||
*/
|
||||
@ -101,6 +160,7 @@ export function convertSessionToClientHistory(
|
||||
messages: ConversationRecord['messages'],
|
||||
): HistoryTurn[] {
|
||||
const clientHistory: HistoryTurn[] = [];
|
||||
const explicitResponseIds = collectExplicitFunctionResponseIds(messages);
|
||||
|
||||
for (const msg of messages) {
|
||||
if (msg.type === 'info' || msg.type === 'error' || msg.type === 'warning') {
|
||||
@ -180,12 +240,18 @@ export function convertSessionToClientHistory(
|
||||
// 4. Generate tool response turns
|
||||
if (msg.toolCalls && msg.toolCalls.length > 0) {
|
||||
const functionResponseParts: Part[] = [];
|
||||
const generatedResponseIds = new Set<string>();
|
||||
for (const toolCall of msg.toolCalls) {
|
||||
if (toolCall.result) {
|
||||
let responseData: Part;
|
||||
|
||||
if (typeof toolCall.result === 'string') {
|
||||
responseData = {
|
||||
if (
|
||||
explicitResponseIds.has(toolCall.id) ||
|
||||
generatedResponseIds.has(toolCall.id)
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
|
||||
functionResponseParts.push({
|
||||
functionResponse: {
|
||||
id: toolCall.id,
|
||||
name: toolCall.name,
|
||||
@ -193,15 +259,16 @@ export function convertSessionToClientHistory(
|
||||
output: toolCall.result,
|
||||
},
|
||||
},
|
||||
};
|
||||
} else if (Array.isArray(toolCall.result)) {
|
||||
functionResponseParts.push(...ensurePartArray(toolCall.result));
|
||||
continue;
|
||||
});
|
||||
generatedResponseIds.add(toolCall.id);
|
||||
} else {
|
||||
responseData = toolCall.result;
|
||||
appendFunctionResponseParts(
|
||||
functionResponseParts,
|
||||
ensurePartArray(toolCall.result),
|
||||
explicitResponseIds,
|
||||
generatedResponseIds,
|
||||
);
|
||||
}
|
||||
|
||||
functionResponseParts.push(responseData);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user