ai: resolve ai-sessions URL from per-org service URLs instead of hardcoding#300
Merged
Conversation
…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>
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 AI session CLI/SDK commands (
ai start session,ai chat,ai auth claude,ai session list/get/terminate/attach, usage, etc.) hardcodedhttps://ai.limacharlie.ioas the ai-sessions host via_AI_SESSIONS_URLinlimacharlie/sdk/ai.py.The
orgs/{oid}/urlendpoint already returns a per-orgaientry (lc.SiteURLs.Aiingo-essentials/lc/sites.go) whose value varies by deployment — e.g. the staging site returnsai-staging.limacharlie.io. So the hardcode pointed staging orgs at the production ai-sessions service.Fix
AI._get_ai_url()— resolves the host lazily and cached fromOrganization.get_urls()["ai"], prefixinghttps://when the entry lacks a scheme, and falling back to_AI_SESSIONS_URLonly when theaientry is absent. This mirrors the existing lazy/cached pattern inSearch._get_search_url().alt_root=_AI_SESSIONS_URLuses inai.py(start_session,_org_request,_user_request) withself._get_ai_url().SessionAttachment(WebSocket attach) now resolves the same per-org host when no explicitbase_urloverride is given, instead of defaulting to the hardcoded constant._AI_SESSIONS_URLis kept as the fallback default.Tests
TestAiUrlResolution:aientry used +https://added, existing scheme preserved, fallback when absent, result cached (singleget_urlscall).SessionAttachmenttest: attach URL derives from the org-resolved host when no override is supplied.mock_orgfixture intest_sdk_ai_sessions.pyto return{"ai": "ai.limacharlie.io"}so the resolvedalt_rootmatches_AI_SESSIONS_URL(existing assertions unchanged).All 152 AI-related unit tests pass.
🤖 Generated with Claude Code