AI 代码指标与追踪

更新时间:
复制 MD 格式

AI 代码统计、成员排名、仓库与扩展名、提交归因及 Commit/Change 明细与导出。

文档说明

本文包含两类接口:AI 代码指标(聚合统计、排名、仓库与扩展名等)与 AI 代码追踪(Commit / Change 明细与 CSV 导出)。二者分页方式不同,请注意各节说明。调用前请完成 获取 API Key,并阅读 约定与规范

权限要求

  • 使用有效的 API Key(Authorization: Bearer)。

  • API Key 必须关联到目标组织。

概述

AI 代码指标 API 提供组织级别的 AI 辅助编码统计数据,包括代码统计概览、每日趋势、成员排名、仓库列表和文件扩展名统计。

主要功能

  • 统计概览: 提交代码中 AI 贡献的总量和占比

  • 每日趋势: 按天查看 AI 代码占比、Agent 代码分语言统计、Tab 补全接受率

  • 成员排名: 按 AI 代码贡献量排名成员

  • 仓库列表: 列出有 AI 代码活动的仓库

  • 文件扩展名: 按文件类型统计 AI 代码指标

  • 提交详情: 获取提交级别的 AI 代码归因详情(文件级行范围注解)

通用查询参数

以下参数适用于所有 AI Code 接口(各接口的必填性见具体说明):

参数

类型

说明

start_date

string

开始时间,支持 RFC 3339 格式或 Unix 毫秒时间戳

end_date

string

结束时间,支持 RFC 3339 格式或 Unix 毫秒时间戳

repo_name

string

按仓库名称过滤

primary_branch_only

string

设为 true 仅统计主分支

user_id

string

按用户 ID 过滤

file_extensions

string

按文件扩展名过滤,逗号分隔(如 .go,.ts

API 列表

1. 获取 AI 代码统计概览

GET /v1/organizations/{organization_id}/ai-code/stats/overview

获取组织 AI 代码的整体统计数据。start_dateend_date 均为必填,且时间范围不超过 90 天。

成功响应 (200 OK)

{
  "committedTotalLinesEdit": 50000,
  "committedAiLinesEdit": 15000,
  "acceptedLinesEdit": 18000,
  "aiShareRate": 30.0,
  "agentEditCount": 1200,
  "tabCompletionCount": 5600,
  "messageCount": 3400
}

响应字段说明

字段

类型

说明

committedTotalLinesEdit

int64

已提交代码总编辑行数(新增 + 删除)

committedAiLinesEdit

int64

已提交代码中 AI 编辑行数

acceptedLinesEdit

int64

已接受的 AI 编辑行数

aiShareRate

float64

AI 代码占比(百分比)

agentEditCount

int64

Agent 编辑次数

tabCompletionCount

int64

Tab 补全次数

messageCount

int64

对话消息数

2. 获取 AI 代码每日趋势

GET /v1/organizations/{organization_id}/ai-code/stats/daily-trend

获取 AI 代码的每日趋势数据,包含三组数据:AI 代码占比趋势、按语言分布趋势、Tab 补全接受率趋势。

成功响应 (200 OK)

{
  "items": [
    {
      "date": "2025-06-01T00:00:00Z",
      "aiLinesAdded": 500,
      "otherLinesAdded": 1500,
      "aiShareRate": 25.0,
      "commitCount": 30
    }
  ],
  "extItems": [
    {
      "date": "2025-06-01T00:00:00Z",
      "fileExtension": ".go",
      "totalLinesAdded": 800,
      "aiLinesAdded": 300
    }
  ],
  "nextItems": [
    {
      "date": "2025-06-01T00:00:00Z",
      "nextSuggestedCount": 200,
      "nextAcceptedCount": 120,
      "nextAcceptRate": 60.0
    }
  ]
}

响应字段说明

items[] - AI 代码占比趋势

字段

类型

说明

date

string

日期(ISO 8601)

aiLinesAdded

int64

AI 新增行数

otherLinesAdded

int64

非 AI 新增行数

aiShareRate

float64

AI 代码占比(百分比)

commitCount

int64

提交次数

extItems[] - Agent 代码按语言分布趋势

字段

类型

说明

fileExtension

string

文件扩展名

totalLinesAdded

int64

总新增行数

aiLinesAdded

int64

AI 新增行数

nextItems[] - Tab 补全接受率趋势

字段

类型

说明

nextSuggestedCount

int64

建议次数

nextAcceptedCount

int64

接受次数

nextAcceptRate

float64

接受率(百分比)

3. 获取成员 AI 代码排名

GET /v1/organizations/{organization_id}/ai-code/stats/member-ranking

获取组织成员按 AI 代码贡献量的排名。额外支持 limit 参数(默认 10)。

成功响应 (200 OK)

{
  "items": [
    {
      "userId": "user_abc123",
      "email": "zhangsan@example.com",
      "displayName": "张三",
      "totalLinesAdded": 5000,
      "aiLinesAdded": 2000,
      "aiShareRate": 40.0,
      "commitCount": 50
    }
  ]
}

响应字段说明

字段

类型

说明

items[].userId

string

用户 ID

items[].email

string

成员邮箱(可能为空)

items[].displayName

string

成员显示名(可能为空)

items[].totalLinesAdded

int64

总新增行数

items[].aiLinesAdded

int64

AI 新增行数

items[].aiShareRate

float64

AI 代码占比(百分比)

items[].commitCount

int64

提交次数

4. 列出仓库

GET /v1/organizations/{organization_id}/ai-code/repos

列出组织中有 AI 代码活动的仓库。支持 query(按名称搜索)、page(页码,从 1 开始)、per_page(每页条数,最大 100)。

成功响应 (200 OK)

{
  "repos": [
    {
      "repoName": "my-project",
      "commitCount": 120,
      "totalLinesAdded": 8000
    }
  ],
  "totalCount": 42,
  "page": 1,
  "perPage": 30
}

响应字段说明

字段

类型

说明

repos[].repoName

string

仓库名称

repos[].commitCount

int64

提交次数

repos[].totalLinesAdded

int64

总新增行数

totalCount

int32

总仓库数

5. 列出文件扩展名

GET /v1/organizations/{organization_id}/ai-code/file-extensions

列出组织中有 AI 代码活动的文件扩展名统计。

成功响应 (200 OK)

{
  "fileExtensions": [
    {
      "extension": ".go",
      "changeCount": 500,
      "totalLinesAdded": 12000,
      "aiShareRate": 35.5
    }
  ]
}

响应字段说明

字段

类型

说明

fileExtensions[].extension

string

文件扩展名

fileExtensions[].changeCount

int64

变更次数

fileExtensions[].totalLinesAdded

int64

总新增行数

fileExtensions[].aiShareRate

float64

AI 代码占比(百分比)

6. 获取提交 AI 归因详情

POST /v1/organizations/{organization_id}/ai-code-tracking/commits/detail

批量获取提交级别的 AI 代码归因详情,包含文件级的行范围注解。

请求体 (JSON)

字段

类型

必填

说明

commitHashes

string[]

提交哈希列表,最多 50 个

branch

string

分支名称(用于限定查询范围)

成功响应 (200 OK)

{
  "success": true,
  "data": {
    "commits": [
      {
        "commitHash": "abc123def456",
        "rangeAnnotations": [
          {
            "filePath": "src/main.go",
            "groups": [
              {
                "conversationId": "session-001",
                "source": "AGENT",
                "productType": "ide",
                "type": "added",
                "ranges": [
                  { "start": 47, "end": 48 },
                  { "start": 55, "end": 60 }
                ]
              }
            ]
          }
        ]
      }
    ]
  }
}

响应字段说明

字段

类型

说明

success

boolean

请求是否成功

data.commits[].commitHash

string

提交哈希

data.commits[].rangeAnnotations[].filePath

string

文件路径

groups[].conversationId

string

AI 会话 ID

groups[].source

string

来源:AGENTNEXTQUESTINLINECHAT

groups[].productType

string

产品类型(如 ide

groups[].type

string

类型:addeddeleted

groups[].ranges[].start / end

int32

行范围起止行号

AI 代码追踪 API

AI 代码指标(聚合统计)之外,本节提供 Commit / Change 级别的明细查询与 CSV 导出。鉴权方式与上文相同。

两层数据模型

层级

含义

来源

可用过滤维度

Commit

Git 提交

代码仓库(已推送到远程)

时间、用户、仓库

Change

IDE 内的 AI 代码编辑事件

来自 IDE 客户端的上报

时间、用户、source

Change 是尚未 git commit 的 IDE 内事件,因此不具有 repoName / branchName 维度。

分页方式

Tracking API 使用偏移量分页page + pageSize),不同于其他接口常用的游标分页。响应包含 totalItems / totalPages

追踪 API 列表

1. 列出 Commit 明细

GET /v1/organizations/{organization_id}/ai-code-tracking/commits

逐条列出提交级 AI 代码统计数据,按提交时间倒序排列。额外支持 repoName 过滤。

成功响应 (200 OK)

{
  "success": true,
  "data": {
    "items": [
      {
        "commitHash": "a1b2c3d4e5f6",
        "userId": "550e8400-e29b-41d4-a716-446655440000",
        "userEmail": "zhangsan@example.com",
        "repoName": "my-project",
        "branchName": "main",
        "isPrimaryBranch": true,
        "totalLinesAdded": 120,
        "totalLinesDeleted": 30,
        "ideNextLinesAdded": 40,
        "ideNextLinesDeleted": 10,
        "ideAgentLinesAdded": 50,
        "ideAgentLinesDeleted": 15,
        "nonAiLinesAdded": 15,
        "nonAiLinesDeleted": 3,
        "message": "feat: add user login",
        "commitTs": "2025-06-15T10:30:00Z",
        "createdAt": "2025-06-15T10:35:00Z"
      }
    ],
    "pagination": {
      "currentPage": 1,
      "pageSize": 100,
      "totalItems": 256,
      "totalPages": 3
    }
  }
}

每条 commit 记录包含 12 对 linesAdded / linesDeleted 列,按「产品 x 场景」交叉拆解 AI 代码行,包括:ideNext、pluginNext、ideAgent、pluginAgent、cliAgent、ideQuest、ideInlineChat、jbInlineChat、nonAi。

2. 导出 Commit CSV

GET /v1/organizations/{organization_id}/ai-code-tracking/commits/export

以流式 CSV 格式导出 commit 数据。调用方无需自行翻页。

  • Content-Type: text/csv; charset=utf-8

  • Content-Disposition: attachment; filename="ai-code-commits.csv"

3. 列出 Change 明细

GET /v1/organizations/{organization_id}/ai-code-tracking/changes

逐条列出 IDE 内 AI 代码编辑事件(仅 action=suggested 的记录),按事件时间倒序排列。额外支持 source 过滤(可选值:AGENTNEXTQUESTINLINECHAT)。

成功响应 (200 OK)

{
  "success": true,
  "data": {
    "items": [
      {
        "changeId": "chg_abc123",
        "userId": "550e8400-e29b-41d4-a716-446655440000",
        "userEmail": "zhangsan@example.com",
        "source": "AGENT",
        "model": "efficient",
        "totalLinesAdded": 45,
        "totalLinesDeleted": 12,
        "metadata": [
          {
            "fileName": "main.go",
            "fileExtension": ".go",
            "linesAdded": 30,
            "linesDeleted": 8
          }
        ],
        "createdAt": "2025-06-15T10:28:00Z"
      }
    ],
    "pagination": {
      "currentPage": 1,
      "pageSize": 100,
      "totalItems": 1024,
      "totalPages": 11
    }
  }
}

响应字段说明

字段

类型

说明

changeId

string

变更事件唯一标识

userId

string

用户 UUID

userEmail

string

用户邮箱(可能为空)

source

string

使用场景:NEXTAGENTQUESTINLINECHAT

model

string

模型级别(可能为空)

totalLinesAdded

integer

总新增行数

totalLinesDeleted

integer

总删除行数

metadata[]

array

文件级别变更明细(可能为空)

createdAt

string

事件时间(ISO 8601)

4. 导出 Change CSV

GET /v1/organizations/{organization_id}/ai-code-tracking/changes/export

以流式 CSV 格式导出 change 数据。CSV 导出为扁平格式,不包含 metadata

  • Content-Type: text/csv; charset=utf-8

  • Content-Disposition: attachment; filename="ai-code-changes.csv"

CSV 列头:

changeId,userId,userEmail,source,model,totalLinesAdded,totalLinesDeleted,createdAt

使用示例

获取统计概览

curl -X GET "https://api.qoder.com.cn/v1/organizations/org_xxx/ai-code/stats/overview?start_date=2025-06-01T00:00:00Z&end_date=2025-06-30T23:59:59Z" \
  -H "Authorization: Bearer <api_key>"

获取每日趋势

curl -X GET "https://api.qoder.com.cn/v1/organizations/org_xxx/ai-code/stats/daily-trend?start_date=2025-06-01T00:00:00Z&end_date=2025-06-30T23:59:59Z&repo_name=my-project&primary_branch_only=true" \
  -H "Authorization: Bearer <api_key>"

获取成员排名

curl -X GET "https://api.qoder.com.cn/v1/organizations/org_xxx/ai-code/stats/member-ranking?start_date=2025-06-01T00:00:00Z&end_date=2025-06-30T23:59:59Z&limit=20" \
  -H "Authorization: Bearer <api_key>"

搜索仓库

curl -X GET "https://api.qoder.com.cn/v1/organizations/org_xxx/ai-code/repos?query=my-project" \
  -H "Authorization: Bearer <api_key>"

获取提交 AI 归因详情

curl -X POST "https://api.qoder.com.cn/v1/organizations/org_xxx/ai-code-tracking/commits/detail" \
  -H "Authorization: Bearer <api_key>" \
  -H "Content-Type: application/json" \
  -d '{"commitHashes": ["abc123def456", "789ghi012jkl"], "branch": "main"}'

查询 commit 明细

curl -X GET "https://api.qoder.com.cn/v1/organizations/org_xxx/ai-code-tracking/commits?startDate=2025-06-01T00:00:00Z&endDate=2025-06-30T23:59:59Z&repoName=my-project&pageSize=50" \
  -H "Authorization: Bearer <api_key>"

导出 commit CSV

curl -X GET "https://api.qoder.com.cn/v1/organizations/org_xxx/ai-code-tracking/commits/export?startDate=2025-06-01T00:00:00Z" \
  -H "Authorization: Bearer <api_key>" \
  -o ai-code-commits.csv

查询 change 明细

curl -X GET "https://api.qoder.com.cn/v1/organizations/org_xxx/ai-code-tracking/changes?startDate=2025-06-01T00:00:00Z&source=QUEST&pageSize=50" \
  -H "Authorization: Bearer <api_key>"

导出 change CSV

curl -X GET "https://api.qoder.com.cn/v1/organizations/org_xxx/ai-code-tracking/changes/export?startDate=2025-06-01T00:00:00Z" \
  -H "Authorization: Bearer <api_key>" \
  -o ai-code-changes.csv

错误码

错误码

HTTP 状态码

说明

BadRequest

400

请求参数无效(如 start_date / end_date 缺失、时间范围超过 90 天、commitHashes 为空或超过 50)

Unauthorized

401

API Key 缺失或无效

Forbidden

403

无权限访问该组织

InternalError

500

服务器内部错误

错误响应结构见 约定与规范 中的「错误响应」一节。