feat: let wrappers identify themselves in X-Sonilo-Client - #16
Merged
Conversation
The CLI and video kit build on the SDK, so every call they made reported as sdk-js, making their traffic indistinguishable from direct SDK use in server-side analytics — a split that cannot be recovered retroactively. SoniloClientOptions takes optional clientName/clientVersion, defaulting to sdk-js and the SDK version. The CLI sends cli-js, the video kit sends videokit-js. A caller-supplied client keeps its owner's identity; only the kit's internally constructed default clients are tagged. Also fixes two version bugs found while wiring this up: - version.ts had drifted to 0.4.0 while the package was 0.5.0, so every request under-reported the SDK version. The existing header test compared the header against VERSION itself, so it could not catch this. - `sonilo --version` printed the SDK's VERSION rather than the CLI's. Both constants are now generated from package.json by scripts/sync-versions.mjs, chained onto the root version script so changesets cannot bump one without the other, plus tests asserting they match.
Sapient docs evalsWaiting for the staging docs URL before running evals. Sapient will start the selected PR evals automatically when GitHub reports a successful docs deployment for this PR. This usually happens within 15 minutes. Commit: |
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.
Problem
The dashboard shows CLI calls as SDK (JS). Both first-party wrappers —
sonilo-cliandsonilo-video-kit— construct aSoniloClient, and the SDK hardcodedX-Sonilo-Client: sdk-jswith no way to override it. So CLI and kit traffic was indistinguishable from direct SDK use.CLI and SDK users are different populations (scripts/ops/evaluation vs. product integration), and the split cannot be recovered retroactively — mixed history stays mixed. Catching this before
sonilo-cliis published means its very first release is attributed correctly.This mirrors sonilo-python#12; the two SDKs had the identical hardcoding.
Change
Both options are optional and default to
sdk-js+ the SDK version, so direct SDK use is unchanged.DEFAULT_CLIENT_NAMEis exported for callers that want the default explicitly.X-Sonilo-ClientX-Sonilo-Client-Versionsdk-jssonilo-clicli-jssonilo-video-kitvideokit-jsA caller-supplied client keeps whatever identity its owner gave it — only the kit's internally constructed default clients (
duck.ts,generate.ts) are tagged.Two version bugs found while wiring this up
1.
version.tshad drifted. It read0.4.0while the package was0.5.0, so every request under-reported the SDK version. changesets bumpspackage.jsononly, andversion.tswas hand-maintained, so the two silently diverged at the 0.5.0 release.The existing test could not catch it:
It compares the header to the same constant the header is built from, so it stays green no matter how far
VERSIONdrifts from the published version.2.
sonilo --versionprinted the SDK's version. The CLI importedVERSIONfromsonilo, so it reported what it wraps rather than itself.Fix: all three constants are now generated from their
package.jsonbyscripts/sync-versions.mjs, chained onto the rootversionscript:so changesets cannot bump one without the other. Tests assert each
VERSIONequals itspackage.jsonversion — compared against the file changesets actually writes, not against itself.Required follow-up outside this repo
The dashboard's
RECOGNIZED_CLIENTSis an allowlist that collapses anything unlisted to"direct", so these values must be registered there or the traffic is silently misattributed as Direct rather than showing up as unknown. That change is prepared alongside this PR and addscli-js/videokit-js(plus the Python names), so it can land first and classify this traffic from its first request.Test plan
npm test→ sonilo 127 passed, sonilo-video-kit 137 passed, sonilo-cli 20 passed (5 new)npm run lint(tsc) clean across all three packagesnpm run buildclean0.5.0confirms the drift fix — this reported0.4.0before.)