Skip to content

feat: Integrate into New API#312

Merged
tbphp merged 2 commits intodevfrom
feat-new-api-integration
Oct 7, 2025
Merged

feat: Integrate into New API#312
tbphp merged 2 commits intodevfrom
feat-new-api-integration

Conversation

@tbphp
Copy link
Owner

@tbphp tbphp commented Oct 6, 2025

关联 Issue / Related Issue

Closes #

变更内容 / Change Content

  • Bug 修复 / Bug fix
  • 新功能 / New feature
  • 其他改动 / Other changes

自查清单 / Checklist

  • 我已在本地测试过我的变更。 / I have tested my changes locally.
  • 我已更新了必要的文档。 / I have updated the necessary documentation.

Summary by CodeRabbit

  • New Features
    • Added GET /integration/info endpoint to list accessible integration groups (name, display name, channel type, and connection path).
    • Supports fetching info for a specific group or all groups; requires a valid proxy key.
  • Refactor
    • Updated proxy routing to be group-aware and introduced a dispatcher to handle integration info requests earlier in the request flow, improving route clarity and behavior.

@tbphp tbphp added this to the v1.3.0 milestone Oct 6, 2025
@tbphp tbphp self-assigned this Oct 6, 2025
@tbphp tbphp added the enhancement New feature or request label Oct 6, 2025
@tbphp
Copy link
Owner Author

tbphp commented Oct 6, 2025

@coderabbitai review this pr.

@coderabbitai
Copy link

coderabbitai bot commented Oct 6, 2025

@tbphp: I'll review the PR now. Let me analyze the changes and provide feedback.

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai
Copy link

coderabbitai bot commented Oct 6, 2025

Walkthrough

Adds a new integration info endpoint and supporting types, introduces a middleware dispatcher to route integration-info requests before proxy auth, and updates router wiring to register the new endpoint and integrate the dispatcher within group-aware proxy routes.

Changes

Cohort / File(s) Summary
Integration info handler
internal/handler/integration_handler.go
Adds IntegrationGroupInfo and IntegrationInfoResponse types; implements Server.GetIntegrationInfo handling query validation, scope (single/all groups), permission checks, effective channel resolution, path building, aggregation, and response.
Proxy dispatcher middleware
internal/middleware/middleware.go
Adds ProxyRouteDispatcher(serverHandler) middleware to intercept “integration info” requests pre-auth and invoke serverHandler.GetIntegrationInfo; otherwise passes through.
Router updates
internal/router/router.go
Updates registerProxyRoutes signature to receive serverHandler; mounts ProxyRouteDispatcher on /proxy/:group_name; shifts proxy binding to /*path; exposes GET /integration/info via serverHandler.GetIntegrationInfo.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor Client
  participant Router
  participant ServerHandler as ServerHandler
  participant GroupMgr as GroupManager/Service
  note over Client,Router: Public integration info endpoint

  Client->>Router: GET /integration/info?proxy_key=...
  Router->>ServerHandler: GetIntegrationInfo(ctx)
  ServerHandler->>GroupMgr: Resolve scope (group/all), list groups
  ServerHandler->>GroupMgr: Check permissions per group
  ServerHandler-->>Router: 200 {data:[IntegrationGroupInfo...]} or 4xx/5xx
  Router-->>Client: Response
Loading
sequenceDiagram
  autonumber
  actor Client
  participant Router
  participant Middleware as ProxyRouteDispatcher
  participant ServerHandler as ServerHandler
  participant Proxy as Proxy Handler
  note over Client,Middleware: Proxy path with dispatcher

  Client->>Router: GET /proxy/:group_name/*path
  Router->>Middleware: Invoke
  alt path == "/api/integration/info"
    Middleware->>ServerHandler: GetIntegrationInfo(ctx)
    Middleware-->>Client: Response (aborts chain)
  else Forward
    Middleware->>Proxy: Next handler
    Proxy-->>Client: Proxied response
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

I twitch my whiskers, routes align,
A secret path before the sign.
Groups assemble, keys in tow,
Channels whisper where to go.
I thump—“Info!”—swift and bright,
Proxy pauses, shares the light.
Then hop along into the night.

Pre-merge checks and finishing touches

❌ Failed checks (1 warning, 1 inconclusive)
Check name Status Explanation Resolution
Description Check ⚠️ Warning The pull request description is incomplete against the repository template: the related issue number is left blank, the detailed change content section contains no description of the new endpoint and middleware logic, and the documentation update checkbox remains unchecked despite adding new public API functionality. Please fill in the issue reference under “关联 Issue,” describe in detail the introduction of the integration info endpoint, helper functions, and middleware in the “Change Content” section, and update the necessary documentation then mark it as completed in the checklist.
Title Check ❓ Inconclusive The title “feat: Integrate into New API” is vague and does not clearly convey the primary changes introduced, such as the addition of the integration info endpoint and the proxy route dispatcher middleware. It lacks specificity about what is being integrated or how the new API surfaces these features. Please update the title to succinctly summarize the main functionality, for example “feat: add integration info endpoint and proxy route dispatcher,” so that reviewers can immediately understand the core change.
✅ Passed checks (1 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed Docstring coverage is 88.89% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat-new-api-integration

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

Copy link

@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

🧹 Nitpick comments (4)
internal/middleware/middleware.go (1)

174-185: Guard dispatcher by HTTP method to avoid intercepting non-GET requests

Currently any verb to /proxy/:group_name/api/integration/info is intercepted. Restrict to GET for consistency with the public route.

 func ProxyRouteDispatcher(serverHandler interface{ GetIntegrationInfo(*gin.Context) }) gin.HandlerFunc {
   return func(c *gin.Context) {
-    if c.Param("path") == "/api/integration/info" {
+    if c.Request.Method == "GET" && c.Param("path") == "/api/integration/info" {
       serverHandler.GetIntegrationInfo(c)
       c.Abort()
       return
     }
 
     c.Next()
   }
 }
internal/handler/integration_handler.go (3)

36-48: Prefer c.Param("group_name") when available; fall back to path parsing

More robust in proxy context and avoids string splitting pitfalls.

- path := c.Request.URL.Path
- isGroupSpecific := strings.HasPrefix(path, "/proxy/")
+ path := c.Request.URL.Path
+ isGroupSpecific := strings.HasPrefix(path, "/proxy/")
@@
- if isGroupSpecific {
-   parts := strings.Split(strings.TrimPrefix(path, "/proxy/"), "/")
-   if len(parts) == 0 || parts[0] == "" {
+ if isGroupSpecific {
+   groupName := c.Param("group_name")
+   if groupName == "" {
+     parts := strings.Split(strings.TrimPrefix(path, "/proxy/"), "/")
+     if len(parts) == 0 || parts[0] == "" {
+       response.Error(c, app_errors.NewAPIError(app_errors.ErrValidation, "Invalid group path"))
+       return
+     }
+     groupName = parts[0]
+   }
-   }
-
-   groupName := parts[0]
+   // groupName now set

21-26: Remove unused IntegrationInfoResponse type

It’s not used; keep code lean.


130-143: Return consistent absolute paths to simplify clients

In group-specific cases, returning "" (openai) or a bare validationEndpoint (custom) is inconsistent. Recommend always returning an absolute path clients can call directly.

-func buildPath(isGroupSpecific bool, groupName string, channelType string, validationEndpoint string) string {
-  if channelType == "custom" {
-    if isGroupSpecific {
-      return validationEndpoint
-    }
-    return "/proxy/" + groupName + validationEndpoint
-  }
-
-  if isGroupSpecific {
-    return ""
-  }
-  return "/proxy/" + groupName
-}
+func buildPath(isGroupSpecific bool, groupName string, channelType string, validationEndpoint string) string {
+  base := "/proxy/" + groupName
+  if channelType == "custom" && validationEndpoint != "" {
+    return base + validationEndpoint
+  }
+  return base
+}
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 65a932f and 05dfa04.

📒 Files selected for processing (3)
  • internal/handler/integration_handler.go (1 hunks)
  • internal/middleware/middleware.go (1 hunks)
  • internal/router/router.go (3 hunks)
🔇 Additional comments (3)
internal/router/router.go (2)

103-104: Public endpoint addition looks good

Exposing GET /api/integration/info on the public API is consistent with the handler’s auth model.


172-184: Confirm middleware order is intentional (dispatcher before ProxyAuth)

Placing ProxyRouteDispatcher before ProxyAuth bypasses proxy auth for this one route and relies on the handler’s key check. Confirm this is desired and covered in threat modeling.

internal/handler/integration_handler.go (1)

90-96: Consider ErrUnauthorized for invalid key

The “invalid or unauthorized proxy key” case may better map to ErrUnauthorized than ErrValidation. Align with API semantics.

Copy link
Owner Author

@tbphp tbphp left a comment

Choose a reason for hiding this comment

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

Code reviewed.

@tbphp tbphp merged commit d2990ed into dev Oct 7, 2025
1 check passed
@tbphp tbphp deleted the feat-new-api-integration branch October 7, 2025 02:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant