feat(coding-agent): add before_provider_headers extension hook (#6350)
* feat(coding-agent): add before_provider_headers extension hook Extensions can already rewrite the request payload through before_provider_request, but there is no way to adjust the outgoing HTTP headers of a provider call. This hook fills that gap for cases like request tracing, session correlation, or tenant routing. Handlers mutate the headers map in place - a null value deletes a header - and the return value is ignored, so a handler cannot accidentally drop auth or attribution headers by forgetting to spread. * docs(coding-agent): document before_provider_headers extension hook Add the before_provider_headers section and lifecycle-diagram entry to extensions.md; drop the now-superseded proposal file.
This commit is contained in:
@@ -294,6 +294,7 @@ user sends prompt ────────────────────
|
||||
│ │ │ │
|
||||
│ ├─► turn_start │ │
|
||||
│ ├─► context (can modify messages) │ │
|
||||
│ ├─► before_provider_headers (can mutate headers) |
|
||||
│ ├─► before_provider_request (can inspect or replace payload)
|
||||
│ ├─► after_provider_response (status + headers, before stream consume)
|
||||
│ │ │ │
|
||||
@@ -643,6 +644,24 @@ pi.on("context", async (event, ctx) => {
|
||||
});
|
||||
```
|
||||
|
||||
#### before_provider_headers
|
||||
|
||||
Fired after the outgoing HTTP headers are assembled. Use it to add, override, or remove request headers.
|
||||
|
||||
Handlers mutate `event.headers` in place. Set a key to a string to add or override it, or to `null` to delete it.
|
||||
|
||||
```typescript
|
||||
pi.on("before_provider_headers", (event, ctx) => {
|
||||
// Add or override — e.g. a session id for gateway tracing/attribution
|
||||
event.headers["x-session-id"] = ctx.sessionManager.getSessionId();
|
||||
|
||||
// Drop a tracking header pi adds for this call
|
||||
event.headers["X-OpenRouter-Title"] = null;
|
||||
});
|
||||
```
|
||||
|
||||
Runs once per provider request; retries reuse the same headers rather than re-firing the hook.
|
||||
|
||||
#### before_provider_request
|
||||
|
||||
Fired after the provider-specific payload is built, right before the request is sent. Handlers run in extension load order. Returning `undefined` keeps the payload unchanged. Returning any other value replaces the payload for later handlers and for the actual request.
|
||||
|
||||
Reference in New Issue
Block a user