mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
feat: session list API (#23202)
<!-- If you have used AI to produce some or all of this PR, please ensure you have read our [AI Contribution guidelines](https://coder.com/docs/about/contributing/AI_CONTRIBUTING) before submitting. --> _Disclaimer:_ _initially_ _produced_ _by_ _Claude_ _Opus_ _4\.6,_ _heavily_ _modified_ _and_ _reviewed_ _by_ _me._ Closes https://github.com/coder/internal/issues/1360 Adds a new `/api/v2/aibridge/sessions` API which returns "sessions". Sessions, as defined in the [RFC](https://www.notion.so/coderhq/AI-Bridge-Sessions-Threads-2ccd579be59280f28021d3baf7472fbe?source=copy_link), are a set of interceptions logically grouped by a session key issued by the client. The API design for this endpoint was done in [this doc](https://github.com/coder/internal/issues/1360). If the client has not provided a session ID, we will revert to the thread root ID, and if that's not present we use the interception's own ID (i.e. a session of a single interception - which is effectively what we show currently in our `/api/v2/aibridge/interceptions` API). The SQL query looks gnarly but it's relatively simple, and seems to perform well (~200ms) even when I import dogfood's `aibridge_*` tables into my workspace. If we need to improve performance on this later we can investigate materialized views, perhaps, but for now I don't think it's warranted. --- _The PR looks large but it's got a lot of generated code; the actual changes aren't huge._
This commit is contained in:
Generated
+28
@@ -75,6 +75,12 @@ export interface AIBridgeListInterceptionsResponse {
|
||||
readonly results: readonly AIBridgeInterception[];
|
||||
}
|
||||
|
||||
// From codersdk/aibridge.go
|
||||
export interface AIBridgeListSessionsResponse {
|
||||
readonly count: number;
|
||||
readonly sessions: readonly AIBridgeSession[];
|
||||
}
|
||||
|
||||
// From codersdk/deployment.go
|
||||
export interface AIBridgeOpenAIConfig {
|
||||
readonly base_url: string;
|
||||
@@ -95,6 +101,28 @@ export interface AIBridgeProxyConfig {
|
||||
readonly allowed_private_cidrs: string;
|
||||
}
|
||||
|
||||
// From codersdk/aibridge.go
|
||||
export interface AIBridgeSession {
|
||||
readonly id: string;
|
||||
readonly initiator: MinimalUser;
|
||||
readonly providers: readonly string[];
|
||||
readonly models: readonly string[];
|
||||
readonly client: string | null;
|
||||
// empty interface{} type, falling back to unknown
|
||||
readonly metadata: Record<string, unknown>;
|
||||
readonly started_at: string;
|
||||
readonly ended_at?: string;
|
||||
readonly threads: number;
|
||||
readonly token_usage_summary: AIBridgeSessionTokenUsageSummary;
|
||||
readonly last_prompt?: string;
|
||||
}
|
||||
|
||||
// From codersdk/aibridge.go
|
||||
export interface AIBridgeSessionTokenUsageSummary {
|
||||
readonly input_tokens: number;
|
||||
readonly output_tokens: number;
|
||||
}
|
||||
|
||||
// From codersdk/aibridge.go
|
||||
export interface AIBridgeTokenUsage {
|
||||
readonly id: string;
|
||||
|
||||
Reference in New Issue
Block a user