Skip to content

feat(plugin-gateway): register the client as a typed container.gatewayClient - #130

Merged
kodiakhq[bot] merged 2 commits into
mainfrom
claude/issue-121-container-client
Sep 26, 2026
Merged

kodiakhq[bot] merged 2 commits into
mainfrom
claude/issue-121-container-client

Conversation

@RedStar071

Copy link
Copy Markdown
Member

🔗 Linked issue

Part of #121 (item 5: container.client stays typed as Client).

🧭 Context

@wolfstar/http-framework types container.client as its base Client. To reach guilds, members, gateway and the other managers, pieces had to call getGatewayClient() or cast. The issue suggests an opt-in augmentation that retypes container.client as GatewayClient. TypeScript doesn't allow that. I tested it in a throwaway consumer against the real @wolfstar/http-framework 5.1.0 and @sapphire/pieces 4.4.1, with TypeScript 7.0.2 and 5.6:

  • With skipLibCheck: false, redeclaring Container.client in a module augmentation fails with TS2717 ("Property 'client' must be of type 'Client', but here has type 'GatewayClient'").
  • With skipLibCheck: true the error is hidden, but the framework's declaration still wins. container.client.guilds is still TS2339, and assigning it to GatewayClient is TS2322.
  • Putting the augmentation in the consumer's own sources behaves the same way.
  • Augmenting Container through "@wolfstar/http-framework" doesn't work either. The framework only re-exports the container value, not the Container type, so the augmentation would declare an unrelated interface.

📚 Description

GatewayClient now registers itself as container.gatewayClient. The property is declared on @sapphire/pieces's Container, the same way plugin-api declares server and plugin-i18next declares i18n. Because it's a new name, it type-checks with and without skipLibCheck, has no cost, and leaves container.client unchanged, so plain Client users are unaffected:

const guild = await this.container.gatewayClient.guilds.fetch(interaction.guildId!);

Like container.client, it holds the most recently constructed client. getGatewayClient() is unchanged.

I rejected one alternative: merging an interface into the framework's Client class. It compiles, but it would claim every plain Client has managers, which isn't true. It would also leak into the root golar typecheck, which checks every package's sources in one program.

Key changes

  • src/util/container.ts: the Container.gatewayClient: GatewayClient augmentation, with a doc comment explaining why container.client can't be retyped.
  • src/GatewayClient.ts: the constructor sets container.gatewayClient = this right after super().
  • @sapphire/pieces is added to dependencies, as in plugin-api and plugin-i18next, so the augmented module resolves from the published .d.ts. knip.json ignores it because knip doesn't count declare module as usage.
  • tsconfig.consumption.json and tests/types/container.ts, wired into the root typecheck script. They assert typed access from a Listener and a Command (the README example), and use @ts-expect-error to check that container.client.guilds is still rejected. I confirmed the check fails (TS2551) when the augmentation is removed.
  • Runtime test: the client registers itself as container.gatewayClient.
  • README ("Listeners") documents the pattern. Changeset: @wolfstar/plugin-gateway minor.

Type of Change

  • New feature (non-breaking change which adds functionality)
  • Bug fix (non-breaking change which fixes an issue)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation change
  • Workflow / CI change

Pre-flight Checklist

  • I have read the Contributing Guidelines (if applicable)
  • My code follows the code style of this project
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes (42 files, 459 tests after merging main)
  • I have updated the documentation accordingly
  • I added a changeset with pnpm changeset

Also checked: pnpm lint, pnpm typecheck (including the new consumption project), and the gateway build (attw and publint clean). A scratch consumer compiled against the built dist passes with skipLibCheck on and off under TypeScript 7.0.2.

🤖 Generated with Claude Code

https://claude.ai/code/session_01RBWEHLtNzWNykJMPqeqqbB


Generated by Claude Code

…ent`

`container.client` is typed by `@wolfstar/http-framework` as the base `Client`, so pieces had to
call `getGatewayClient()` or cast to reach `guilds`, `members`, `gateway` & co.

Retyping it is not possible: a module augmentation redeclaring `Container.client` as
`GatewayClient` fails with TS2717, and under `skipLibCheck` the error is hidden while the
framework's `Client` still wins (checked with TypeScript 7.0.2 and 5.6, from a published `.d.ts`
and from the consumer's own sources).

`GatewayClient` now registers itself as `container.gatewayClient`, declared on the `Container` of
`@sapphire/pieces` like plugin-api's `server` and plugin-i18next's `i18n`. It is a new name, so
it type-checks with and without `skipLibCheck` and leaves `container.client` untouched for plain
clients. A type-level consumption test, wired into `pnpm typecheck`, enforces both.

Refs #121

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01RBWEHLtNzWNykJMPqeqqbB
@coldtea-pr-lens

coldtea-pr-lens Bot commented Sep 26, 2026 •

Copy link
Copy Markdown

◈ PR Lens

🟢 +0 new · 🟠 ~2 changed · 🔴 -0 removed · 0 flows · 11 files · commit 32d5841


Architecture

Architecture diagram for wolfstar-project/plugins at 32d5841

2 components touched across 6 lanes.

Play the interactive walkthrough


Data flow

No data-flow sequence changed in this PR.


View

  • Architecture lens
  • Data flow lens
  • Expand every detail

Tip

Click the link under each diagram to open it on a canvas you can zoom, pan and step through

🪧 More tips
  • Run npx skills add coldteadotai/pr-lens, then tell your coding agent: "Diagram the change you just made with PR Lens and attach it to the pull request."
  • Run npx @coldtea/pr-lens-cli analyze --base origin/main on a branch, then npx @coldtea/pr-lens-cli render .pr-lens/graph.json. Same lenses, your own model key, before the pull request exists
  • Untick Architecture lens or Data flow lens under View to hide a diagram, or tick Expand every detail to open every section. The comment redraws in a few seconds
  • The diagrams are links. Click one to open it on the canvas, then press W or click play to walk through the change
  • Open a diagram on the canvas, then press W or click play to walk through the change one step at a time
  • The CLI's render reads .github/pr-lens.yml and applies your renames, exclusions and lane pins at draw time
  • Set github.comment.collapsed: true in .github/pr-lens.yml to fold the comment behind one View architecture and data flow row. Drawing still runs as before
  • Set github.draw: on-demand in .github/pr-lens.yml and PR Lens stops drawing pull requests on its own. Comment @pr-lens draw on a pull request when you want that one drawn
  • Add .github/workflows/pr-lens.yml with coldteadotai/pr-lens/packages/action@v0 and your model provider's key as its api-key to run PR Lens from your own CI. Any /chat/completions endpoint works
  • Push a commit and the drawing stays, with a note that it is out of date. Tick Redraw in the note to draw the new head
  • Switch GitHub to dark mode and the diagrams follow. The moving dots are this pull request's data in motion

Thanks for using PR Lens! It's built by Coldtea, free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

@wolfstarbot wolfstarbot added the packages:plugin-gateway Changes in plugin-gateway label Sep 26, 2026

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Reviewed changes

Reviewed the full diff: GatewayClient now registers itself as a typed container.gatewayClient, alongside supporting docs, tests, and tooling wiring.

  • container.gatewayClient augmentation (src/util/container.ts): declares gatewayClient: GatewayClient on @sapphire/pieces's Container, matching the existing pattern used by plugin-api's server and plugin-i18next's i18n.
  • GatewayClient constructor: sets container.gatewayClient = this right after super(), next to the framework's own container.client assignment.
  • Type-level consumption test (tests/types/container.ts) + new tsconfig.consumption.json, wired into the root typecheck script: asserts typed access from a Listener/Command, and a @ts-expect-error that container.client still lacks managers.
  • Runtime test: extends the existing container.client assertion to also check container.gatewayClient.
  • knip.json ignores @sapphire/pieces for plugin-gateway, since the only reference is a bare declare module specifier with no import.
  • README + changeset: documents the new access pattern and ships a minor changeset for @wolfstar/plugin-gateway.

I verified the declare module block's shape against plugin-api/plugin-i18next's existing augmentations (identical convention), confirmed GuildManager is actually exported via the ./managers barrel so the type test compiles against real exports, and confirmed the constructor assignment is safe (JS constructors run synchronously to completion, so there's no window where another piece could observe a half-initialized gatewayClient). container.client is correctly left untouched, and getGatewayClient() is unchanged as stated.

No correctness, security, or convention issues found.

Pullfrog  | View workflow run | Using Claude Sonnet | 𝕏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

packages:plugin-gateway Changes in plugin-gateway

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants