Fix: Use public base URL in Use In Code SDK snippets - #653
Fix: Use public base URL in Use In Code SDK snippets#653bhaveshpatel640 wants to merge 4 commits into
Conversation
🦋 Changeset detectedLatest commit: 596173e The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
a6cf912 to
f5c5edf
Compare
| data: buildAgentCodeSnippets({ | ||
| agentName: record.name, | ||
| baseUrl: new URL(c.req.url).origin, | ||
| baseUrl: getPublicBaseUrl(), |
There was a problem hiding this comment.
This throws if PUBLIC_BASE_URL is set to ''
How are we dealing with that?
There was a problem hiding this comment.
Fixed it using PUBLIC_BASE_URL and fall back to the request origin, when it's ''
There was a problem hiding this comment.
actually the way it is implemented will seem odd for SaaS tenants, the public url config is not tenant specific, so all tenants will see the same url - is that okay?
Only other solution I can think is to
new URL(<pathname-from-public-base-url>, new URL(c.req.url).origin).href
There was a problem hiding this comment.
Can we take an optional baseUrl on the code-snippets request from the FE?
If it's omitted, we fall back to request origin + path from PUBLIC_BASE_URL. FE can then pass the real tenant/public host and avoid *.svc.cluster.local.
6ab1a7b to
e66c044
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 1a19635. Configure here.
16f4711 to
ac2cf51
Compare

Summary
Use In Code snippets used the request origin (in-cluster Service DNS). They now use
PUBLIC_BASE_URLviagetPublicBaseUrl().Closes AGE-2147
Changes
baseUrlfromgetPublicBaseUrl()base_urlHow was this tested?
pnpm --filter @truefoundry/trueforge test -- tests/unit/apis/agents.test.tsChecklist
pnpm build,pnpm test,pnpm typecheck,pnpm lint:ci, andpnpm format:checkpass locallypackages/trueforge-sdk,.github/fern/openapi/openapi.json,docs/openapi.json) — fork PRs omit SDK regen; maintainers regenerate after merge.env.exampleupdated if configuration or behavior changedNote
Low Risk
Changes only how snippet
base_urlis computed and documented; no auth or data-path changes, with optional query input validated as a URL.Overview
Use In Code SDK snippets no longer embed the raw request origin (often in-cluster service DNS). The code-snippets API now resolves a public
base_urlfor sample code.The GET
/{agent_id}/code-snippetsendpoint accepts an optionalbase_urlquery parameter. When present, that value is used; otherwise the server derives the URL from the request origin and, when set, thePUBLIC_BASE_URLpathname (e.g. browser origin plus/trueforgepath segment). OpenAPI/query schemas document the new parameter.The UI harness adapter passes the resolved public host as
base_urlwhen calling the internal snippets API (viaresolveTrueForgeBaseUrl), so browser-facing URLs flow through instead of backend-only hosts. Unit tests cover default derivation and query override.Reviewed by Cursor Bugbot for commit ac2cf51. Bugbot is set up for automated code reviews on this repo. Configure here.