mirror of
https://github.com/coder/coder.git
synced 2026-06-02 20:48:20 +00:00
e00e85765b
This PR merges code from `coder/aibridge` repository into `coder/coder`. It was split into 4 PRs for easier review but stacked PRs will need to be merged into this PR so all checks pass. * https://github.com/coder/coder/pull/24190 -> raw code copy (this PR, before merging PRs on top of it, it was just 1 commit: https://github.com/coder/coder/commit/70d33f33200c7e77df910957595715f81f9bec24) * https://github.com/coder/coder/pull/24570 -> update imports in `coder/coder` to use copied code * https://github.com/coder/coder/pull/24586 -> linter fixes and CI integration (also added README.md) * https://github.com/coder/coder/pull/24571 -> added exclude to scripts/check_emdash.sh check Original PR message (before PR squash): Moves coder/aibridge code into coder/coder repository. Omitted files: - `go.mod`, `go.sum`, `.gitignore`, `.github/workflows/ci.yml,` `Makefile`, `LICENSE`, `README.md` (modified README.md is added later) - `.github`, `example`, `buildinfo,` `scripts` directories Simple verification script (will list omitted files) ``` tmp=$(mktemp -d) echo "$tmp" git clone --depth=1 https://github.com/coder/aibridge "$tmp/aibridge" git clone --depth=1 --branch pb/aibridge-code-move https://github.com/coder/coder "$tmp/coder" diff -rq --exclude=.git "$tmp/aibridge" "$tmp/coder/aibridge" # rm -rf "$tmp" ```
41 lines
1.6 KiB
Go
41 lines
1.6 KiB
Go
package intercept
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/google/uuid"
|
|
"go.opentelemetry.io/otel/attribute"
|
|
|
|
"cdr.dev/slog/v3"
|
|
"github.com/coder/coder/v2/aibridge/mcp"
|
|
"github.com/coder/coder/v2/aibridge/recorder"
|
|
)
|
|
|
|
// Interceptor describes a (potentially) stateful interaction with an AI provider.
|
|
type Interceptor interface {
|
|
// ID returns the unique identifier for this interception.
|
|
ID() uuid.UUID
|
|
// Setup injects some required dependencies. This MUST be called before using the interceptor
|
|
// to process requests.
|
|
Setup(logger slog.Logger, rec recorder.Recorder, mcpProxy mcp.ServerProxier)
|
|
// Model returns the model in use for this [Interceptor].
|
|
Model() string
|
|
// ProcessRequest handles the HTTP request.
|
|
ProcessRequest(w http.ResponseWriter, r *http.Request) error
|
|
// Specifies whether an interceptor handles streaming or not.
|
|
Streaming() bool
|
|
// TraceAttributes returns tracing attributes for this [Interceptor]
|
|
TraceAttributes(*http.Request) []attribute.KeyValue
|
|
// Credential returns the credential metadata for this interception.
|
|
Credential() CredentialInfo
|
|
// CorrelatingToolCallID returns the ID of a tool call result submitted
|
|
// in the request, if present. This is used to correlate the current
|
|
// interception back to the previous interception that issued those tool
|
|
// calls. If multiple tool use results are present, we use the last one
|
|
// (most recent). Both Anthropic's /v1/messages and OpenAI's /v1/responses
|
|
// require that ALL tool results are submitted for tool choices returned
|
|
// by the model, so any single tool call ID is sufficient to identify the
|
|
// parent interception.
|
|
CorrelatingToolCallID() *string
|
|
}
|