Skip to content

Fix: Use public base URL in Use In Code SDK snippets - #653

Draft
bhaveshpatel640 wants to merge 4 commits into
mainfrom
AGE-2147
Draft

Fix: Use public base URL in Use In Code SDK snippets#653
bhaveshpatel640 wants to merge 4 commits into
mainfrom
AGE-2147

Conversation

@bhaveshpatel640

@bhaveshpatel640 bhaveshpatel640 commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

Summary

Use In Code snippets used the request origin (in-cluster Service DNS). They now use PUBLIC_BASE_URL via getPublicBaseUrl().

Closes AGE-2147

Changes

  • Code-snippet baseUrl from getPublicBaseUrl()
  • Unit test asserts base_url

How was this tested?

  • pnpm --filter @truefoundry/trueforge test -- tests/unit/apis/agents.test.ts

Checklist

  • I have read the contributing guidelines
  • pnpm build, pnpm test, pnpm typecheck, pnpm lint:ci, and pnpm format:check pass locally
  • Tests added/updated where it makes sense
  • No hand-edits to generated code (packages/trueforge-sdk, .github/fern/openapi/openapi.json, docs/openapi.json) — fork PRs omit SDK regen; maintainers regenerate after merge
  • Docs / .env.example updated if configuration or behavior changed

Note

Low Risk
Changes only how snippet base_url is 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_url for sample code.

The GET /{agent_id}/code-snippets endpoint accepts an optional base_url query parameter. When present, that value is used; otherwise the server derives the URL from the request origin and, when set, the PUBLIC_BASE_URL pathname (e.g. browser origin plus /trueforge path segment). OpenAPI/query schemas document the new parameter.

The UI harness adapter passes the resolved public host as base_url when calling the internal snippets API (via resolveTrueForgeBaseUrl), 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.

@changeset-bot

changeset-bot Bot commented Sep 9, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 596173e

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@truefoundry/trueforge Patch
@truefoundry/trueforge-ui Patch

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

Comment thread packages/trueforge/src/apis/agents.ts Outdated
data: buildAgentCodeSnippets({
agentName: record.name,
baseUrl: new URL(c.req.url).origin,
baseUrl: getPublicBaseUrl(),

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.

This throws if PUBLIC_BASE_URL is set to ''
How are we dealing with that?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed it using PUBLIC_BASE_URL and fall back to the request origin, when it's ''

@chiragjn chiragjn Sep 9, 2026

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.

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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.

cursor[bot]

This comment was marked as outdated.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

❌ 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.

Comment thread .github/fern/openapi/openapi.json
@bhaveshpatel640
bhaveshpatel640 marked this pull request as draft September 9, 2026 18:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants