Skip to content

ai: resolve ai-sessions URL from per-org service URLs instead of hardcoding#300

Merged
maximelb merged 1 commit into
cli-v2from
cli-v2-ai-url-from-orgurls
May 30, 2026
Merged

ai: resolve ai-sessions URL from per-org service URLs instead of hardcoding#300
maximelb merged 1 commit into
cli-v2from
cli-v2-ai-url-from-orgurls

Conversation

@maximelb

Copy link
Copy Markdown
Contributor

Problem

The AI session CLI/SDK commands (ai start session, ai chat, ai auth claude, ai session list/get/terminate/attach, usage, etc.) hardcoded https://ai.limacharlie.io as the ai-sessions host via _AI_SESSIONS_URL in limacharlie/sdk/ai.py.

The orgs/{oid}/url endpoint already returns a per-org ai entry (lc.SiteURLs.Ai in go-essentials/lc/sites.go) whose value varies by deployment — e.g. the staging site returns ai-staging.limacharlie.io. So the hardcode pointed staging orgs at the production ai-sessions service.

Fix

  • Add AI._get_ai_url() — resolves the host lazily and cached from Organization.get_urls()["ai"], prefixing https:// when the entry lacks a scheme, and falling back to _AI_SESSIONS_URL only when the ai entry is absent. This mirrors the existing lazy/cached pattern in Search._get_search_url().
  • Replace all four alt_root=_AI_SESSIONS_URL uses in ai.py (start_session, _org_request, _user_request) with self._get_ai_url().
  • SessionAttachment (WebSocket attach) now resolves the same per-org host when no explicit base_url override is given, instead of defaulting to the hardcoded constant.

_AI_SESSIONS_URL is kept as the fallback default.

Tests

  • New TestAiUrlResolution: ai entry used + https:// added, existing scheme preserved, fallback when absent, result cached (single get_urls call).
  • New SessionAttachment test: attach URL derives from the org-resolved host when no override is supplied.
  • Updated the mock_org fixture in test_sdk_ai_sessions.py to return {"ai": "ai.limacharlie.io"} so the resolved alt_root matches _AI_SESSIONS_URL (existing assertions unchanged).

All 152 AI-related unit tests pass.

🤖 Generated with Claude Code

…coding

The AI session CLI/SDK commands (start session, chat, auth claude, list/
get/terminate, attach, usage) hardcoded https://ai.limacharlie.io as the
ai-sessions host. The orgs/{oid}/url endpoint already returns a per-org
`ai` entry (lc.SiteURLs.Ai) whose value depends on the deployment -- e.g.
staging orgs return ai-staging.limacharlie.io -- so the hardcode pointed
staging orgs at the production service.

Resolve the host lazily from Organization.get_urls()["ai"] (cached, same
pattern as Search), prefixing https:// when needed and falling back to the
well-known production host only when the entry is absent. SessionAttachment
resolves the same way when no explicit base_url override is given.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@maximelb maximelb requested a review from dzimine-lc May 30, 2026 23:47
@maximelb maximelb marked this pull request as ready for review May 30, 2026 23:47
@maximelb maximelb merged commit 15cb2a6 into cli-v2 May 30, 2026
6 of 7 checks passed
@maximelb maximelb deleted the cli-v2-ai-url-from-orgurls branch May 30, 2026 23:47
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.

1 participant