{
  "repo": "tidbcloud/message-service",
  "binary": "api",
  "binary_path": "cmd/api/main.go",
  "dependencies": {
    "ChatBotService.ChatBot": {
      "infrastructure": {
        "mysql": {
          "conditions": ["Always"],
          "operations": [
            {
              "operation": "SELECT",
              "trigger": "Get existing session records by session_id and created_by",
              "conditions": ["req.SessionID != ''"],
              "implementation": "dao.GetBotInteractRecordBySessionIDCreatedBy(req.SessionID, createdBy)"
            },
            {
              "operation": "INSERT",
              "trigger": "Save chat interaction record",
              "conditions": ["Always"],
              "implementation": "dao.CreateBotInteractRecord(record)"
            }
          ]
        }
      },
      "services": [
        {
          "name": "dataapi-svc",
          "target_repo": "tidbcloud/dataservices",
          "target_interface": "DataAPIService.GetClusterMeta",
          "operation_type": "grpc_unary",
          "conditions": ["req.BotType in ['chat2sql', '']", "req.Database == ''"],
          "operations": [
            {
              "operation": "gRPC GetClusterMeta",
              "trigger": "Get cluster metadata for database guessing",
              "conditions": ["chat2sql or default (empty BotType) mode without database specified"],
              "implementation": "grpc.GetClusterMeta(ctx, &dataapi.GetClusterMetaReq{ProjectId: projectID, ClusterId: clusterID})"
            }
          ]
        },
        {
          "name": "dataapi-svc",
          "target_repo": "tidbcloud/dataservices",
          "target_interface": "DataAPIService.GetDatabaseMeta",
          "operation_type": "grpc_unary",
          "conditions": ["req.Database != ''", "req.BotType in ['chat2sql', 'chat2chart', '']"],
          "operations": [
            {
              "operation": "gRPC GetDatabaseMeta",
              "trigger": "Get database table metadata for SQL generation",
              "conditions": ["database specified"],
              "implementation": "grpc.GetDatabaseMeta(ctx, &dataapi.GetDatabaseMetaReq{ProjectId: projectID, ClusterId: clusterID, Database: database})"
            }
          ]
        },
        {
          "name": "openai-api",
          "target_interface": "POST /v1/completions",
          "operation_type": "http_post",
          "conditions": ["Always"],
          "operations": [
            {
              "operation": "HTTP POST /v1/completions",
              "trigger": "Generate SQL/Chart completion using OpenAI API",
              "conditions": ["Always"],
              "implementation": "httpclient.PostWithHeader(conf.OpenAIEndpoint + '/v1/completions', param, &headers)"
            }
          ]
        }
      ]
    }
  }
}
