Conversation
📝 WalkthroughSummary by CodeRabbit
WalkthroughAdds server-side context compaction to GenAIApp.Chat: new state fields (compaction_enabled, compaction_threshold), two public methods (enableCompaction, setCompactionThreshold) with validation, propagation into OpenAI/Gemini payloads, and inclusion in Chat serialization and README docs. Changes
Sequence Diagram(s)sequenceDiagram
participant Client as Client
participant Chat as GenAIApp.Chat
participant Serializer as Chat._toJson
participant API as OpenAI/Gemini API
Client->>Chat: enableCompaction(true)\nsetCompactionThreshold(10000)
Chat-->>Chat: set compaction_enabled\nset compaction_threshold
Client->>Chat: prepare/send message
Chat->>Serializer: _toJson() (includes compaction fields)
Chat->>API: _buildOpenAIPayload() / _buildGeminiPayload()\n(adds context_management when enabled)
API-->>Chat: response
Chat-->>Client: deliver response
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes 🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
📝 Coding Plan
Comment Tip CodeRabbit can suggest fixes for GitHub Check annotations.Configure the |
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@README.md`:
- Line 162: The README states the default compaction threshold is 200000 but the
code initializes compaction_threshold to 10000; pick one and make them
consistent: either update the README text to state the actual default
(compaction_threshold = 10000) or change the initialization of the
compaction_threshold variable in src/code.gs to 200000 so it matches the README;
ensure you update the single source of truth (variable compaction_threshold and
any comments or docs referencing its default) so both docs and code reflect the
same value.
- Around line 166-167: Add a blank line after the preceding fenced code block so
the heading "### Give a web page as a knowledge base (optional)" is separated by
an empty line (fixing markdownlint MD031); update the README.md by inserting a
single empty line between the closing ``` code fence and that heading.
In `@src/code.gs`:
- Around line 346-349: The setCompactionThreshold method currently assigns any
value to compaction_threshold; add input validation in setCompactionThreshold to
ensure the provided threshold is a number and >= 1000 (the API-required
minimum). If the value is invalid (non-numeric, NaN, less than 1000), throw or
return an error (e.g., throw new Error or return this with no-op) with a clear
message and do not assign compaction_threshold; otherwise assign and return
this. Update the function named setCompactionThreshold and the
compaction_threshold assignment accordingly so callers cannot set invalid
thresholds.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: d0851e1f-1aff-4234-8c3b-86707fbb78ba
📒 Files selected for processing (2)
README.mdsrc/code.gs
There was a problem hiding this comment.
Actionable comments posted: 1
♻️ Duplicate comments (1)
README.md (1)
462-463:⚠️ Potential issue | 🟡 MinorFix the documented default threshold in the Chat reference.
This section still says
200000, but the implementation default is10000, and the usage example above already documents10000. The mismatch will mislead consumers of the public API.📝 Proposed fix
- `setCompactionThreshold(threshold)`: Set the compaction threshold (`200000` by default). + `setCompactionThreshold(threshold)`: Set the compaction threshold (`10000` by default).🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@README.md` around lines 462 - 463, Update the README Chat reference to match the implementation default: change the documented default for setCompactionThreshold from `200000` to `10000` so it aligns with the actual behavior; specifically edit the lines mentioning `enableCompaction(enabled)` and `setCompactionThreshold(threshold)` to reflect `10000` as the default for setCompactionThreshold and ensure the usage example and descriptive text are consistent with the function names `enableCompaction` and `setCompactionThreshold`.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/code.gs`:
- Around line 337-339: The enableCompaction function currently coerces inputs
via Boolean(enabled) which treats strings like "false" as true; change it to
require a real boolean by checking typeof enabled === "boolean" and assign
compaction_enabled = enabled directly (do not coerce). If the check fails, throw
a TypeError (or explicitly return/error) with a clear message so callers using
string-based config don't accidentally enable compaction; update the function
named enableCompaction and the variable compaction_enabled accordingly.
---
Duplicate comments:
In `@README.md`:
- Around line 462-463: Update the README Chat reference to match the
implementation default: change the documented default for setCompactionThreshold
from `200000` to `10000` so it aligns with the actual behavior; specifically
edit the lines mentioning `enableCompaction(enabled)` and
`setCompactionThreshold(threshold)` to reflect `10000` as the default for
setCompactionThreshold and ensure the usage example and descriptive text are
consistent with the function names `enableCompaction` and
`setCompactionThreshold`.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: 77caba5d-5b3c-4a0d-8950-548349f429a2
📒 Files selected for processing (2)
README.mdsrc/code.gs
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@README.md`:
- Around line 152-155: The review points out that compaction_enabled and
compaction_threshold are being passed into _buildGeminiPayload() via
advancedParametersObject but are not used there; either remove these keys from
the Gemini path or implement support for them in _buildGeminiPayload() so Gemini
receives/handles compaction_enabled and compaction_threshold consistently with
_buildOpenAIPayload(); also update documentation to state that
setCompactionThreshold() enforces a minimum threshold of 1000 tokens (>= 1000)
so callers know the validation rule and avoid runtime errors.
- Around line 157-159: Update the README example and API reference to document
setCompactionThreshold's validation: in the example where
GenAIApp.newChat().setCompactionThreshold(120000) is shown, add an inline
comment noting the method enforces a minimum value of 1000 and rejects
non-finite numbers; in the API reference entry for setCompactionThreshold,
explicitly state the parameter must be a finite number with a minimum allowed
value of 1000 (matching the runtime guards in setCompactionThreshold).
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
…enAIApp into compaction-support
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@README.md`:
- Around line 462-463: Update the README entry for setCompactionThreshold to
match the action-phrase style used elsewhere: change the line for
setCompactionThreshold(threshold) to start with "Set" (e.g.,
"setCompactionThreshold(threshold): Set the compaction threshold (`10000` by
default, minimum `1000`; finite numbers only).") so it is consistent with
enableCompaction(enabled) and other method descriptions; locate the existing
string for setCompactionThreshold in README.md and replace its wording
accordingly.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
| - `enableCompaction(enabled)`: Enable/disable OpenAI Responses API server-side compaction (`false` by default). | ||
| - `setCompactionThreshold(threshold)`: (`10000` by default, minimum `1000`; finite numbers only). |
There was a problem hiding this comment.
🧹 Nitpick | 🔵 Trivial
Make setCompactionThreshold entry consistent with the reference style.
Line 463 currently omits the action phrase used by other methods. Consider: “setCompactionThreshold(threshold): Set the compaction threshold (10000 by default, minimum 1000; finite numbers only).”
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@README.md` around lines 462 - 463, Update the README entry for
setCompactionThreshold to match the action-phrase style used elsewhere: change
the line for setCompactionThreshold(threshold) to start with "Set" (e.g.,
"setCompactionThreshold(threshold): Set the compaction threshold (`10000` by
default, minimum `1000`; finite numbers only).") so it is consistent with
enableCompaction(enabled) and other method descriptions; locate the existing
string for setCompactionThreshold in README.md and replace its wording
accordingly.
The changes add server-side context compaction functionality to the Chat class. Two new public methods (enableCompaction() and setCompactionThreshold()) allow configuration of this feature. The implementation introduces state variables to track settings and modifies both OpenAI and Gemini payload builders to conditionally include context management configurations when enabled.