Skip to content

Add SpaceXSI conversation integration - #181709

Draft
jeffglousher wants to merge 8 commits into
home-assistant:devfrom
jeffglousher:codex/spacexai/upstream-initial
Draft

jeffglousher wants to merge 8 commits into
home-assistant:devfrom
jeffglousher:codex/spacexai/upstream-initial

Conversation

@jeffglousher

@jeffglousher jeffglousher commented Sep 9, 2026 •

Copy link
Copy Markdown

Breaking change

None. This adds a new integration.

Proposed change

Add the community-maintained SpaceXSI integration to use Grok as a conversation agent through a subscription.

Setup uses browser-based device authorization and creates one conversation agent per account. Users select a model, instructions, and Home Assistant AI tools. Same-account reauthentication preserves the agent and its settings. No API key or installed CLI is required.

The integration uses Home Assistant's application-credentials and OAuth helpers, shared HTTP sessions, conversation history, and LLM tool interface. Subscription API requests use spacexai-subscription-client==0.1.3.

Validation on a920151 with the released spacexai-subscription-client==0.1.3: all 68 SpaceXSI tests, scoped Ruff and mypy, hassfest, translations, and requirements generation passed locally. GitHub Actions also passed, including prek, mypy, pylint, hassfest, and all ten full-suite test shards.

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New integration (thank you!)
  • New feature (which adds functionality to an existing integration)
  • Deprecation (breaking change to happen in the future)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Additional information

Checklist

  • I understand the code I am submitting and can explain how it works.
  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist
  • I have followed the perfect PR recommendations
  • The code has been formatted using Ruff (ruff format homeassistant tests)
  • Tests have been added to verify that the new code works.
  • Any generated code has been carefully reviewed for correctness and compliance with project standards.

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • The manifest file has all fields filled out correctly.
    Updated and included derived files by running: python3 -m script.hassfest.
  • New or updated dependencies have been added to requirements_all.txt.
    Updated by running python3 -m script.gen_requirements_all.
  • For the updated dependencies a diff between library versions and ideally a link to the changelog/release notes is added to the PR description.

To help with the load of incoming pull requests:

Copilot AI 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.

🟡 Changes recommended

Setup must reject or recover from a configured model that is no longer available.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

Adds a community-maintained SpaceXAI conversation integration using browser OAuth and Grok models.

Changes:

  • Adds OAuth device authorization and token refresh.
  • Adds conversation history, Assist tools, and model selection.
  • Adds metadata, dependency registration, and comprehensive tests.
File summaries
File Description
.strict-typing Enables strict typing.
CODEOWNERS Assigns integration ownership.
homeassistant/components/spacexai/__init__.py Manages setup, OAuth, and runtime data.
homeassistant/components/spacexai/config_flow.py Implements device authorization and agent setup.
homeassistant/components/spacexai/const.py Defines integration defaults.
homeassistant/components/spacexai/conversation.py Implements conversation and tool handling.
homeassistant/components/spacexai/manifest.json Registers integration metadata and dependency.
homeassistant/components/spacexai/quality_scale.yaml Declares quality-scale compliance.
homeassistant/components/spacexai/strings.json Adds configuration and error translations.
homeassistant/generated/config_flows.py Registers the config flow.
homeassistant/generated/integrations.json Adds generated integration metadata.
mypy.ini Enables strict mypy checks.
requirements_all.txt Adds the client dependency.
tests/components/spacexai/__init__.py Adds a setup test helper.
tests/components/spacexai/conftest.py Provides shared fixtures.
tests/components/spacexai/test_config_flow.py Tests OAuth and configuration flows.
tests/components/spacexai/test_conversation.py Tests conversations, tools, and errors.
tests/components/spacexai/test_init.py Tests setup, unloading, and refresh behavior.
Review details
  • Files reviewed: 16/18 changed files
  • Comments generated: 1
  • Review effort level: Balanced

💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Copilot AI review requested due to automatic review settings September 9, 2026 11:43

Copilot AI 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.

🔵 Needs a closer look

The unofficial OAuth integration and cloud-based Assist control path require final human validation.

Review details
  • Files reviewed: 16/18 changed files
  • Comments generated: 0 new
  • Review effort level: Balanced

@github-actions

github-actions Bot commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

Check requirements

Checked at commit d6b69cd.

All requirements checks passed. ✅

Package Old New No Advisories Not Yanked Repo Public CI Upload Release Pipeline Security PR Link Async Safe
spacexai-subscription-client — 0.1.1 ✅ ✅ ✅ ✅ ✅ ☑️ ✅ ✅
📦 spacexai-subscription-client: 0.1.1
  • No Advisories: ✅ No active advisories reported by PyPI for version 0.1.1.
  • Not Yanked: ✅ Version 0.1.1 is a live (non-yanked) release.
  • Repo Public: ✅ https://github.com/jeffglousher/spacexai-subscription-client is publicly accessible.
  • CI Upload: ✅ Trusted Publisher attestation found (GitHub).
  • Release Pipeline: ✅ OIDC via Trusted Publisher attestation (GitHub); automated CI upload verified by PyPI.
  • Security: ☑️ Baseline scan found nothing obvious in pyproject.toml, __init__.py, client.py, const.py, errors.py, models.py. This is not a security review — only the cheap checks were run.
  • PR Link: ✅ PR description links to the source repository at https://github.com/jeffglousher/spacexai-subscription-client (release, source, and changelog links included).
  • Async Safe: ✅ New dependency reviewed in full at v0.1.1. All network I/O uses aiohttp/httpx/openai async clients, delays use await asyncio.sleep(...), and no sync-blocking patterns (requests, time.sleep, sync sockets, blocking file/DB I/O, subprocess) were found in any async def body.

Generated by Check requirements (AW) · copilot · auto · 34.7 AIC · ⌖ 8.03 AIC · ⊞ 13.7K · ◷

Copilot AI review requested due to automatic review settings September 9, 2026 12:13
@jeffglousher
jeffglousher marked this pull request as ready for review September 9, 2026 12:14
@github-actions

github-actions Bot commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

Check requirements

Checked at commit 51d5dcb.

All requirements checks passed. ✅

Package Old New No Advisories Not Yanked Repo Public CI Upload Release Pipeline Security PR Link Async Safe
spacexai-subscription-client — 0.1.1 ✅ ✅ ✅ ✅ ✅ ☑️ ✅ ✅
📦 spacexai-subscription-client: 0.1.1
  • No Advisories: ✅ No active advisories reported by PyPI for version 0.1.1.
  • Not Yanked: ✅ Version 0.1.1 is a live (non-yanked) release.
  • Repo Public: ✅ https://github.com/jeffglousher/spacexai-subscription-client is publicly accessible.
  • CI Upload: ✅ Trusted Publisher attestation found (GitHub).
  • Release Pipeline: ✅ OIDC via Trusted Publisher attestation (GitHub); automated CI upload verified by PyPI.
  • Security: ☑️ Baseline scan found nothing obvious in pyproject.toml, __init__.py, client.py, const.py. This is not a security review — only the cheap checks were run.
  • PR Link: ✅ PR description links to the source repository at https://github.com/jeffglousher/spacexai-subscription-client/tree/v0.1.1.
  • Async Safe: ✅ Sole async def surface (client.py) uses aiohttp and the openai async SDK exclusively; no blocking HTTP, file, subprocess, or sleep calls found on the request path.

Generated by Check requirements (AW) · copilot · auto · 40.2 AIC · ⌖ 7.83 AIC · ⊞ 13.7K · ◷

Copilot AI 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.

🔵 Needs a closer look

The unofficial OAuth integration and cloud-based Assist control path require final human validation.

Review details
  • Files reviewed: 16/18 changed files
  • Comments generated: 0 new
  • Review effort level: Balanced

Comment on lines +50 to +59
def oauth_implementation(hass: HomeAssistant) -> LocalOAuth2Implementation:
"""Return the public OAuth implementation used by Grok CLI."""
return LocalOAuth2Implementation(
hass=hass,
domain=DOMAIN,
client_id=GROK_CLI_OAUTH_CLIENT_ID,
client_secret="",
authorize_url=AUTHORIZE_URL,
token_url=TOKEN_URL,
)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

why isn't this in application_credentials.py

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

It mostly came from borrowing the idea from Hermes Agent and then trying to split what was necessary between the library and the HA side. I missed this, but it can be collapsed. Thanks—I’ll follow up with the code.

Comment on lines +50 to +57
@override
async def async_step_user(
self, user_input: dict[str, Any] | None = None
) -> ConfigFlowResult:
"""Start device authorization."""
return await self.async_step_device()

async def async_step_device(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

why do we split this?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I was trying to keep it simple and separate concerns, but that’s a better idea. I’ll collapse the steps.

Comment on lines +162 to +172
return self.async_show_form(
step_id="conversation",
data_schema=vol.Schema(
{
vol.Required(CONF_MODEL): SelectSelector(
SelectSelectorConfig(
options=self._models,
mode=SelectSelectorMode.DROPDOWN,
sort=True,
)
),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

why don't you use subentries so you can add multiple models for the same account

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I do want better capabilities and have been working on more, but I was trying to keep the first PR very simple. Could we leave the extra agents for a follow-up?

from homeassistant.const import CONF_LLM_HASS_API, CONF_PROMPT
from homeassistant.helpers import llm

DOMAIN = "spacexai"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

isn't it like x_ai?

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.

It's SpaceXSI now 😂

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

It’s been a moving target. Looks like the current branding guidelines now say SpaceXSI.

@home-assistant
home-assistant Bot marked this pull request as draft October 14, 2026 20:56
@home-assistant

Copy link
Copy Markdown
Contributor

Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍

Learn more about our pull request process.

@jeffglousher jeffglousher changed the title Add SpaceXAI conversation integration Add SpaceXSI conversation integration Oct 24, 2026
Copilot AI balanced review requested due to automatic review settings October 24, 2026 17:17

Copilot AI 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.

🔵 Needs a closer look

The unofficial subscription OAuth path still needs human validation of live sign-in and reauthentication on the current revision.

No open issues 🎉

Review effort: Balanced

@github-actions

Copy link
Copy Markdown
Contributor

Check requirements

Checked at commit 9ee4053.

All requirements checks passed. ✅

Package Old New No Advisories Not Yanked Repo Public CI Upload Release Pipeline Security PR Link Async Safe
spacexai-subscription-client — 0.1.1 ✅ ✅ ✅ ✅ ✅ ☑️ ✅ ✅
📦 spacexai-subscription-client: 0.1.1
  • No Advisories: ✅ No active advisories reported by PyPI for version 0.1.1.
  • Not Yanked: ✅ Version 0.1.1 is a live (non-yanked) release.
  • Repo Public: ✅ https://github.com/jeffglousher/spacexai-subscription-client is publicly accessible.
  • CI Upload: ✅ Trusted Publisher attestation found (GitHub).
  • Release Pipeline: ✅ OIDC via Trusted Publisher attestation (GitHub); automated CI upload verified by PyPI.
  • Security: ☑️ Baseline scan found nothing obvious in __init__.py, client.py, const.py, errors.py, models.py, and pyproject.toml. All network calls target auth.x.ai/cli-chat-proxy.grok.com, consistent with the package's stated purpose (unofficial Grok/SpaceXAI OAuth client). No execution of network-sourced data, no filesystem access outside the HA integration's documented API, no secret exfiltration patterns, and no obfuscated code. This is not a security review — only the cheap checks were run.
  • PR Link: ✅ PR description links to the source repository (release and source tree at v0.1.1): https://github.com/jeffglousher/spacexai-subscription-client/releases/tag/v0.1.1
  • Async Safe: ✅ No blocking calls found. The entire source tree (new package) uses aiohttp/httpx async clients and asyncio.sleep for device-code polling backoff; no sync HTTP, time.sleep, blocking file/DB I/O, or subprocess calls appear in any async def body or its helpers.

Generated by Check requirements (AW) · copilot · auto · 37 AIC · ⌖ 7.7 AIC · ⊞ 5K · ◷

@jeffglousher
jeffglousher force-pushed the codex/spacexai/upstream-initial branch from 9ee4053 to dd28564 Compare October 27, 2026 12:07
Copilot AI balanced review requested due to automatic review settings October 27, 2026 12:07
@jeffglousher
jeffglousher force-pushed the codex/spacexai/upstream-initial branch from cb70784 to 434bdba Compare October 27, 2026 12:19

Copilot AI 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.

🟡 Changes recommended

Tool-result serialization drops the independent error flag, making failed and successful calls with identical data indistinguishable to the provider.

1 open issue
2 resolved since last review

Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings October 27, 2026 12:22
@jeffglousher
jeffglousher force-pushed the codex/spacexai/upstream-initial branch from 434bdba to 7fc5f85 Compare October 27, 2026 12:25

Copilot AI 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.

🔵 Needs a closer look

Live sign-in, token refresh, and same-account reauthentication require human validation because mocked tests cannot establish provider compatibility with the unofficial API and third-party OAuth client.

1 open issue

Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings October 27, 2026 12:27

Copilot AI 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.

🔵 Needs a closer look

Provider compatibility remains unverified for the unofficial subscription API and reused Grok CLI OAuth client, requiring maintainer end-to-end validation of live sign-in, same-account reauthentication, and token refresh.

1 open issue

Review effort: Balanced

@jeffglousher
jeffglousher force-pushed the codex/spacexai/upstream-initial branch from 7fc5f85 to 7247149 Compare October 28, 2026 01:58
Copilot AI balanced review requested due to automatic review settings October 28, 2026 01:58

Copilot AI 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.

🔵 Needs a closer look

The current revision needs human validation of live sign-in, token refresh, and same-account reauthentication against the unofficial subscription API, which mocked integration tests cannot establish.

1 open issue

Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings October 30, 2026 14:18

Copilot AI 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.

🔵 Needs a closer look

Human validation is needed because mocked tests do not establish provider support for the third-party CLI OAuth client or compatibility with live refresh-token rotation.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings November 2, 2026 14:16

Copilot AI 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.

🟡 Changes recommended

The PR description references dependency version 0.1.2 while the manifest and requirements pin 0.1.3, leaving validation of the shipped version unclear.

1 open issue

Review effort: Balanced

"integration_type": "service",
"iot_class": "cloud_polling",
"quality_scale": "bronze",
"requirements": ["spacexai-subscription-client==0.1.3"]
Copilot AI balanced review requested due to automatic review settings November 3, 2026 03:18

Copilot AI 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.

🔵 Needs a closer look

Human validation is needed because the new subscription client is unavailable for inspection or end-to-end verification, leaving its provider API contract and Grok public OAuth device authorization unverified beyond mocked tests.

1 open issue

Review effort: Balanced

This branch has not been deployed

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants