Skip to content

Store client session ID and expose new API #1336

@dannykopping

Description

@dannykopping

Depends on coder/aibridge#166

Store recorded client session ID, and use it to expose a new API which will allow listing interceptions by session.

Sessions are sets of interceptions (or threads (#1338)).
If a session ID is not present for an interception, the individual interception should be treated as a session with a single interception and the session ID = interception ID.

Acceptance criteria:

  • Migration to add new column
  • Proto updated to include client session ID
  • InsertAIBridgeInterception updated to include client session ID
  • Added API endpoints with same filters as /api/v2/aibridge/interceptions (plus session ID), and pagination
    • GET /api/v2/aibridge/interceptions/by-session
    • GET /api/v2/aibridge/sessions/:id/interceptions (just an alias for GET /api/v2/aibridge/interceptions/by-session?session-id={id}, displaying only a single session - no list)
      • Database queries added to facilitate these
  • Tests added

GET /api/v2/aibridge/interceptions/by-session

Just returns an aggregation of each interception.

Hit GET /api/v2/aibridge/sessions/:id/interceptions for the full output.

{
    "count": 99,
    "sessions": [
        {
            "session_id": "session_id|interception_id",
            "interceptions": [
                {
                    "id": "497f6eca-6276-4993-bfeb-53cbbbba6f08",
                    "api_key_id": "string",
                    "started_at": "2019-08-24T14:15:22Z",
                    "ended_at": "2019-08-24T14:15:22Z",
                    "provider": "string",
                    "models": ["string", "string"],
                    "prompt": "string",
                    "initiator": {
                        "avatar_url": "http://example.com",
                        "id": "497f6eca-6276-4993-bfeb-53cbbbba6f08",
                        "name": "string",
                        "username": "string"
                    },
                    "tokens_total": {
                        "input": 123, // input + cache reads
                        "output": 456
                    },
                    "tool_calls_total": 5
                }
            ]
        }
    ]
}
GET /api/v2/aibridge/sessions/:id/interceptions
{
    "count": 5,
    "session_id": "session_id|interception_id",
    "interception": {
        "api_key_id": "string",
        "ended_at": "2019-08-24T14:15:22Z",
        "id": "497f6eca-6276-4993-bfeb-53cbbbba6f08",
        "initiator": {
            "avatar_url": "http://example.com",
            "id": "497f6eca-6276-4993-bfeb-53cbbbba6f08",
            "name": "string",
            "username": "string"
        },
        "metadata": {
            "property1": null,
            "property2": null
        },
        "model": "string",
        "provider": "string",
        "started_at": "2019-08-24T14:15:22Z",
        "token_usages": [
            {
                "created_at": "2019-08-24T14:15:22Z",
                "id": "497f6eca-6276-4993-bfeb-53cbbbba6f08",
                "input_tokens": 0,
                "interception_id": "34d9b688-63ad-46f4-88b5-665c1e7f7824",
                "metadata": {
                    "property1": null,
                    "property2": null
                },
                "output_tokens": 0,
                "provider_response_id": "string"
            }
        ],
        "tool_usages": [
            {
                "created_at": "2019-08-24T14:15:22Z",
                "id": "497f6eca-6276-4993-bfeb-53cbbbba6f08",
                "injected": true,
                "input": "string",
                "interception_id": "34d9b688-63ad-46f4-88b5-665c1e7f7824",
                "invocation_error": "string",
                "metadata": {
                    "property1": null,
                    "property2": null
                },
                "provider_response_id": "string",
                "server_url": "string",
                "tool": "string"
            }
        ],
        "user_prompts": [
            {
                "created_at": "2019-08-24T14:15:22Z",
                "id": "497f6eca-6276-4993-bfeb-53cbbbba6f08",
                "interception_id": "34d9b688-63ad-46f4-88b5-665c1e7f7824",
                "metadata": {
                    "property1": null,
                    "property2": null
                },
                "prompt": "string",
                "provider_response_id": "string"
            }
        ]
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions