feat(coding-agent): add provider payload hook
This commit is contained in:
@@ -243,6 +243,7 @@ user sends prompt ────────────────────
|
||||
│ │ │ │
|
||||
│ ├─► turn_start │ │
|
||||
│ ├─► context (can modify messages) │ │
|
||||
│ ├─► before_provider_request (can inspect or replace payload)
|
||||
│ │ │ │
|
||||
│ │ LLM responds, may call tools: │ │
|
||||
│ │ ├─► tool_call (can block) │ │
|
||||
@@ -489,6 +490,21 @@ pi.on("context", async (event, ctx) => {
|
||||
});
|
||||
```
|
||||
|
||||
#### 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.
|
||||
|
||||
```typescript
|
||||
pi.on("before_provider_request", (event, ctx) => {
|
||||
console.log(JSON.stringify(event.payload, null, 2));
|
||||
|
||||
// Optional: replace payload
|
||||
// return { ...event.payload, temperature: 0 };
|
||||
});
|
||||
```
|
||||
|
||||
This is mainly useful for debugging provider serialization and cache behavior.
|
||||
|
||||
### Model Events
|
||||
|
||||
#### model_select
|
||||
@@ -1934,6 +1950,7 @@ All examples in [examples/extensions/](../examples/extensions/).
|
||||
| `dirty-repo-guard.ts` | Warn on dirty git repo | `on("session_before_*")`, `exec` |
|
||||
| `input-transform.ts` | Transform user input | `on("input")` |
|
||||
| `model-status.ts` | React to model changes | `on("model_select")`, `setStatus` |
|
||||
| `provider-payload.ts` | Inspect or patch provider payloads | `on("before_provider_request")` |
|
||||
| `system-prompt-header.ts` | Display system prompt info | `on("agent_start")`, `getSystemPrompt` |
|
||||
| `claude-rules.ts` | Load rules from files | `on("session_start")`, `on("before_agent_start")` |
|
||||
| `file-trigger.ts` | File watcher triggers messages | `sendMessage` |
|
||||
|
||||
Reference in New Issue
Block a user