Repository navigation
feat(api): closed sets are enums; attempt, model-list and probe reasons are coded - #174
Merged
Merged
Conversation
…ns are coded Fields whose value comes from a fixed set were `String` on the wire, so the desktop UI had to narrow them by hand. They are enums now, with the same wire words, and export to TypeScript as string-literal unions: - Guard: SecurityEventView.guard, SecurityEventsQuery.guard - GroupKind: GroupView.kind, GroupInput.kind - ModelListStatus: ProviderView.model_status, ProviderModelsView.status - TakesEffect: DetectedClient/KeySynced/AdoptResponse.takes_effect - AttemptOutcome: AttemptView.outcome - RuleAction: SecurityRuleView.action/default_action, ActionSave.action, CustomRuleSave.action, SecurityTestHit.action, and the action of the ContentMatched / ToolCallFlagged events - ScanLevel: ScanFinding.level; FindingLevel: FindingView.level - L1Step / L1Peer / L1SkipReason: L1Stage.step/peer, L1Skip.reason (tw-gateway's l1 now uses these instead of its own copies) Three reasons that reached the UI as English strings are `Msg` now: - AttemptView.error is the same coded message the hop reports to the client (the separate English sentence per hop is gone) - ProviderView.model_error / ProviderModelsView.error: new gw.models.* codes; failures from the probe carry its gw.probe.* code - ProviderTestResult.error: new gw.probe.* codes for timeout, connect, rejected key and other request failures (reqwest's text as `detail`), and control.provider_test.* for the OAuth cases An unknown group strategy is now a request-body error, so control.group.unknown_strategy is gone. CONTROL_API_VERSION is 14; the stored routing JSON changed shape, so the request store SCHEMA is 19. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
fylorn
force-pushed
the
feat/api-closed-sets-coded-reasons
branch
from
September 24, 2026 09:32
6383a65 to
4ada23f
Compare
This was referenced Sep 24, 2026
Merged
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Found while the desktop UI adopted the generated types: several fields are
Stringon the wire but only ever carry a fixed set of words, so the UI narrows them by hand; and three reasons reach the Chinese UI as English sentences because they are plain strings, notMsg.Closed sets → enums (same wire words)
A small
slug_enum!macro in tw-api declares each set once: serde renames keep the wire strings, ts-rs exports a string-literal union, andslug()/from_slug()/ALLserve storage and path building.GuardSecurityEventView.guard,SecurityEventsQuery.guardGroupKindGroupView.kind,GroupInput.kindModelListStatusProviderView.model_status,ProviderModelsView.statusTakesEffectDetectedClient/KeySynced/AdoptResponse.takes_effectAttemptOutcomeAttemptView.outcomeRuleActionSecurityRuleView.action/default_action,ActionSave.action,CustomRuleSave.action,SecurityTestHit.action,Event::ContentMatched.action,Event::ToolCallFlagged.actionScanLevel/FindingLevelScanFinding.level/FindingView.levelL1Step/L1Peer/L1SkipReasonL1Stage.step/.peer,L1Skip.reason(tw-gateway'sl1uses these instead of its own copies)tw-control's private
Guardenum is replaced bytw_api::Guard; engine/adopt/scan enums map to the contract ones through exhaustivematches.Reasons →
MsgAttemptView.error: the per-hop English sentence is gone; a failed hop carries the same coded message the hop reports to the client (gw.route.protocol_mismatch,gw.convert.failed,gw.credentials.failed,gw.upstream.*, …). WebSocket hops too.ProviderView.model_error/ProviderModelsView.error: newgw.models.{credentials,check_failed,no_endpoint,unrecognized,empty}; a failed probe passes its own code through.ProviderTestResult.error: newgw.probe.{timeout,connect,key_rejected,request_failed}(reqwest's text is thedetailargument),control.provider_test.{oauth_unsaved,credentials}; config and credential errors pass their existing codedMsg.Removed:
control.group.unknown_strategy(an unknown strategy is now a request-body error).msg-codes.txtupdated.Versions
CONTROL_API_VERSION13 → 14 (three fields changed from string to object).SCHEMA18 → 19: the stored routing JSON carriesMsgerrors now.Tests: a wire round-trip test for every enum; model-list, provider-test, security and WebSocket tests assert codes instead of English text.
cargo fmt, clippy (--all-targetsand--lib), workspace tests, and thetsfeature steps (clippy, tests, export,tsc --strict) pass locally.🤖 Generated with Claude Code