Skip to content

fix(proxy): register pi in AGENT_PREFIX_RE - #1195

Merged
Maxwell-Code07 merged 2 commits into
TencentCloud:feat/server_teamfrom
san-tian:fix/pi-agent-prefix-re
Sep 3, 2026
Merged

fix(proxy): register pi in AGENT_PREFIX_RE#1195
Maxwell-Code07 merged 2 commits into
TencentCloud:feat/server_teamfrom
san-tian:fix/pi-agent-prefix-re

Conversation

@san-tian

Copy link
Copy Markdown
Contributor

Summary

Follow-up to #1126 (first-class Pi adapter). That PR added the pi agent adapter but left AGENT_PREFIX_RE without pi, so /pi/{spaceId}/v1/... requests are not prefix-stripped and cost-guard / analyse markers on /pi paths are not recognized (whitelist matching misses).

This PR is the minimal change:

  • Add pi to the AGENT_PREFIX_RE alternation (one line)
  • Add vitest tests covering:
    • /pi/v1/messages and /pi/{spaceId}/v1/... normalization
    • cost-guard / analyse markers on /pi paths
    • whitelist endpoint matching for /pi paths
    • regression for existing agent prefixes (claude-code, codebuddy)

Test

cd MemoryProxy && npx vitest run src/routes/__tests__/whitelist.test.ts
# 13 passed

Supersedes #1062.

The first-class pi adapter (TencentCloud#1126) handles /pi/{spaceId}/v1/... requests,
but AGENT_PREFIX_RE still lacks "pi", so cost-guard / analyse markers on
/pi paths are not recognized and whitelist matching misses. Add "pi" to
the agent alternation and cover normalization + marker + whitelist-matching
paths with vitest tests.

Signed-off-by: san-tian <admin@macaron.xin>
@Maxwell-Code07

Copy link
Copy Markdown
Collaborator

Thank you so much for your attention and contribution! We will arrange an internal review for this PR shortly, and all feedback will be shared right here in the discussion.

@L2ncE L2ncE left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM. Verified the 13 tests fail on the pre-fix regex, and /ping-style prefixes can't false-positive. Thanks for splitting just the gap out of #1062.

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.

3 participants