Skip to content

feat(link): report agent-connected event after project linking#48

Merged
jwfing merged 1 commit intomainfrom
feat/gtm-connected-event
Apr 1, 2026
Merged

feat(link): report agent-connected event after project linking#48
jwfing merged 1 commit intomainfrom
feat/gtm-connected-event

Conversation

@jwfing
Copy link
Copy Markdown
Member

@jwfing jwfing commented Apr 1, 2026

Summary

  • Add reportAgentConnected API call to POST /tracking/v1/agent-connected after successful insforge link
  • Platform login flow: reports project_id with JWT auth
  • OSS/self-hosted flow: parses app_key from --api-base-url (must match {app_key}.{region}.insforge.app format), reports without auth
  • Failures are silently caught to avoid disrupting the link flow

Test plan

  • Verified insforge link --api-url https://api-beta.insforge.dev --api-key ... --api-base-url https://vv6mjd5n.us-test.insforge.app sends request to /tracking/v1/agent-connected with app_key: vv6mjd5n
  • Verify platform login link flow sends project_id correctly
  • Verify non-matching URLs (e.g. *.insforge.dev) do not trigger reporting

🤖 Generated with Claude Code

Note

Report agent-connected event after project linking

  • Adds a new reportAgentConnected function in src/lib/api/platform.ts that POSTs to /tracking/v1/agent-connected with an optional bearer token.
  • Calls reportAgentConnected in src/commands/projects/link.ts after both direct (OSS/self-hosted) and standard cloud linking flows complete successfully.
  • For direct linking, extracts an app_key subdomain from opts.apiBaseUrl; for cloud linking, sends the project_id.
  • All errors from the tracking call are silently ignored so linking is never blocked.

Macroscope summarized b14846c.

Summary by CodeRabbit

  • Chores
    • Enhanced project linking with improved event tracking capabilities for both direct and OAuth-managed connections.

Call POST /tracking/v1/agent-connected after successful link to track
agent connections. Supports both project_id (platform login) and
app_key (OSS/self-hosted, parsed from api-base-url) payloads.
Failures are silently ignored to avoid disrupting the link flow.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 1, 2026

Walkthrough

The pull request adds best-effort event reporting following successful project linking. A new reportAgentConnected function in the platform API layer POSTs agent connection events to a tracking endpoint, invoked from two control paths in the link command: one for direct OSS/self-hosted linking and one for OAuth/managed linking, with failures silently ignored.

Changes

Cohort / File(s) Summary
Project link reporting integration
src/commands/projects/link.ts
Added reportAgentConnected calls after successful project linking in direct OSS/self-hosted and OAuth paths, each wrapped in try/catch to prevent failures from affecting the link operation.
Platform API tracking endpoint
src/lib/api/platform.ts
Added new reportAgentConnected function that POSTs payload containing optional project_id or app_key to the tracking endpoint, with conditional Authorization header but no response validation.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Poem

🐰 A link is made, the agent connects,
We track the moment, what to expect—
With gentle reports sent to the sky,
No fuss if they fail, we let them fly.
Quiet whispers of success we send! 📡

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main change: adding event reporting after project linking, which is the core objective of this PR.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/gtm-connected-event

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/lib/api/platform.ts`:
- Around line 112-129: reportAgentConnected currently always calls
getAccessToken() and may attach a stale JWT; change its signature to accept an
optional flag or token parameter (e.g. reportAgentConnected(payload, apiUrl?,
useAuth = true) or reportAgentConnected(payload, apiUrl?, token?: string)) and
only set the Authorization header when useAuth is true or a non-null token is
provided; update callers (notably link.ts) in the OSS/self-hosted path to pass
useAuth=false (or pass null token) so the tracking request is sent
unauthenticated, and ensure getAccessToken is not invoked when authentication is
disabled.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 44b760f0-02a0-4aa2-a88e-24a2b775c504

📥 Commits

Reviewing files that changed from the base of the PR and between e98908a and b14846c.

📒 Files selected for processing (2)
  • src/commands/projects/link.ts
  • src/lib/api/platform.ts

@jwfing jwfing requested review from CarmenDou and tonychang04 April 1, 2026 20:30
@jwfing jwfing merged commit bbd1bf5 into main Apr 1, 2026
3 checks passed
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