chore: add user details to aibridge interception list endpoint (#20397)

- Adds FK from `aibridge_interceptions.initiator_id` to `users.id`
- This is enforced by deleting any rows that don't have any users. Since
this is an experimental feature AND coder never deletes user rows I
think this is acceptable.
- Adds `name` as a property on `codersdk.MinimalUser`
- This matches the `visible_users` view in the database. I'm unsure why
`name` wasn't already included given that `username` is.
- Adds a new `initiator` field to `codersdk.AIBridgeInterception` which
contains `codersdk.MinimalUser` (ID, username, name, avatar URL)
- Removes `initiator_id` from `codersdk.AIBridgeInterception`
    - Should be fine since we're still in early access
This commit is contained in:
Dean Sheather
2025-10-22 16:18:31 +11:00
committed by GitHub
parent 9da60a9dc5
commit 69c2c40512
30 changed files with 329 additions and 78 deletions
@@ -8,7 +8,7 @@ INSERT INTO
)
VALUES (
'be003e1e-b38f-43bf-847d-928074dd0aa8',
'30095c71-380b-457a-8995-97b8ee6e5307',
'30095c71-380b-457a-8995-97b8ee6e5307', -- admin@coder.com, from 000022_initial_v0.6.6.up.sql
'openai',
'gpt-5',
'2025-09-15 12:45:13.921148+00'
@@ -77,3 +77,82 @@ VALUES (
'{}',
'2025-09-15 12:45:21.674335+00'
);
-- For a later migration, we'll add an invalid interception without a valid
-- initiator_id.
INSERT INTO
aibridge_interceptions (
id,
initiator_id,
provider,
model,
started_at
)
VALUES (
'c6d29c6e-26a3-4137-bb2e-9dfeef3c1c26',
'cab8d56a-8922-4999-81a9-046b43ac1312', -- user does not exist
'openai',
'gpt-5',
'2025-09-15 12:45:13.921148+00'
);
INSERT INTO
aibridge_token_usages (
id,
interception_id,
provider_response_id,
input_tokens,
output_tokens,
metadata,
created_at
)
VALUES (
'5650db6c-0b7c-49e3-bb26-9b2ba0107e11',
'c6d29c6e-26a3-4137-bb2e-9dfeef3c1c26',
'chatcmpl-CG2s28QlpKIoooUtXuLTmGbdtyS1k',
10950,
118,
'{}',
'2025-09-15 12:45:21.674413+00'
);
INSERT INTO
aibridge_user_prompts (
id,
interception_id,
provider_response_id,
prompt,
metadata,
created_at
)
VALUES (
'1e76cb5b-7c34-4160-b604-a4256f856169',
'c6d29c6e-26a3-4137-bb2e-9dfeef3c1c26',
'chatcmpl-CG2s28QlpKIoooUtXuLTmGbdtyS1k',
'how many workspaces do i have',
'{}',
'2025-09-15 12:45:21.674335+00'
);
INSERT INTO
aibridge_tool_usages (
id,
interception_id,
provider_response_id,
tool,
server_url,
input,
injected,
invocation_error,
metadata,
created_at
)
VALUES (
'351b440f-d605-4f37-8ceb-011f0377b695',
'c6d29c6e-26a3-4137-bb2e-9dfeef3c1c26',
'chatcmpl-CG2s28QlpKIoooUtXuLTmGbdtyS1k',
'coder_list_workspaces',
'http://localhost:3000/api/experimental/mcp/http',
'{}',
true,
NULL,
'{}',
'2025-09-15 12:45:21.674413+00'
);