> ## Documentation Index
> Fetch the complete documentation index at: https://docs.qoder.com/llms.txt
> Use this file to discover all available pages before exploring further.

# AI 代码指标与追踪

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

## 文档说明

本文包含两类接口：**AI 代码指标**（聚合统计、排名、仓库与扩展名等）与 **AI 代码追踪**（Commit / Change 明细与 CSV 导出）。二者分页方式不同，请注意各节说明。调用前请完成 **[获取 API Key](/zh/account/teams/openapi/get-api-key)**，并阅读 **[约定与规范](/zh/account/teams/openapi/conventions)**。

### 权限要求

* 使用有效的 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 代码的整体统计数据。

#### 路径参数

| 参数                | 类型     | 必填 | 说明    |
| ----------------- | ------ | -- | ----- |
| `organization_id` | string | 是  | 组织 ID |

#### 查询参数

见「通用查询参数」，其中：

| 参数           | 必填 | 说明   |
| ------------ | -- | ---- |
| `start_date` | 是  | 开始时间 |
| `end_date`   | 是  | 结束时间 |

> `start_date` 和 `end_date` 均为必填，且时间范围不超过 90 天。

#### 成功响应 (200 OK)

```json theme={null}
{
  "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 补全接受率趋势。

#### 路径参数

| 参数                | 类型     | 必填 | 说明    |
| ----------------- | ------ | -- | ----- |
| `organization_id` | string | 是  | 组织 ID |

#### 查询参数

见「通用查询参数」，其中：

| 参数           | 必填 | 说明   |
| ------------ | -- | ---- |
| `start_date` | 是  | 开始时间 |
| `end_date`   | 是  | 结束时间 |

> `start_date` 和 `end_date` 均为必填，且时间范围不超过 90 天。

#### 成功响应 (200 OK)

```json theme={null}
{
  "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 代码占比趋势（Chart 1）

| 字段                | 类型      | 说明           |
| ----------------- | ------- | ------------ |
| `date`            | string  | 日期（ISO 8601） |
| `aiLinesAdded`    | int64   | AI 新增行数      |
| `otherLinesAdded` | int64   | 非 AI 新增行数    |
| `aiShareRate`     | float64 | AI 代码占比（百分比） |
| `commitCount`     | int64   | 提交次数         |

**extItems\[ ]** - Agent 代码按语言分布趋势（Chart 2）

| 字段                | 类型     | 说明           |
| ----------------- | ------ | ------------ |
| `date`            | string | 日期（ISO 8601） |
| `fileExtension`   | string | 文件扩展名        |
| `totalLinesAdded` | int64  | 总新增行数        |
| `aiLinesAdded`    | int64  | AI 新增行数      |

**nextItems\[ ]** - Tab 补全接受率趋势（Chart 3）

| 字段                   | 类型      | 说明           |
| -------------------- | ------- | ------------ |
| `date`               | string  | 日期（ISO 8601） |
| `nextSuggestedCount` | int64   | 建议次数         |
| `nextAcceptedCount`  | int64   | 接受次数         |
| `nextAcceptRate`     | float64 | 接受率（百分比）     |

***

### 3. 获取成员 AI 代码排名

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

获取组织成员按 AI 代码贡献量的排名。

#### 路径参数

| 参数                | 类型     | 必填 | 说明    |
| ----------------- | ------ | -- | ----- |
| `organization_id` | string | 是  | 组织 ID |

#### 查询参数

见「通用查询参数」，其中：

| 参数           | 必填 | 说明   |
| ------------ | -- | ---- |
| `start_date` | 是  | 开始时间 |
| `end_date`   | 是  | 结束时间 |

> `start_date` 和 `end_date` 均为必填，且时间范围不超过 90 天。

额外支持：

| 参数      | 类型      | 必填 | 默认值 | 说明       |
| ------- | ------- | -- | --- | -------- |
| `limit` | integer | 否  | 10  | 返回的最大成员数 |

#### 成功响应 (200 OK)

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

#### 响应字段说明

| 字段                        | 类型      | 说明           |
| ------------------------- | ------- | ------------ |
| `items`                   | array   | 成员排名列表       |
| `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 代码活动的仓库。

#### 路径参数

| 参数                | 类型     | 必填 | 说明    |
| ----------------- | ------ | -- | ----- |
| `organization_id` | string | 是  | 组织 ID |

#### 查询参数

| 参数           | 类型      | 必填 | 默认值 | 说明          |
| ------------ | ------- | -- | --- | ----------- |
| `start_date` | string  | 否  | —   | 开始时间        |
| `end_date`   | string  | 否  | —   | 结束时间        |
| `query`      | string  | 否  | —   | 按仓库名称搜索     |
| `page`       | integer | 否  | 1   | 页码（从 1 开始）  |
| `per_page`   | integer | 否  | 30  | 每页条数，最大 100 |

#### 成功响应 (200 OK)

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

#### 响应字段说明

| 字段                        | 类型     | 说明    |
| ------------------------- | ------ | ----- |
| `repos`                   | array  | 仓库列表  |
| `repos[].repoName`        | string | 仓库名称  |
| `repos[].commitCount`     | int64  | 提交次数  |
| `repos[].totalLinesAdded` | int64  | 总新增行数 |
| `totalCount`              | int32  | 总仓库数  |
| `page`                    | int32  | 当前页码  |
| `perPage`                 | int32  | 每页条数  |

***

### 5. 列出文件扩展名

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

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

#### 路径参数

| 参数                | 类型     | 必填 | 说明    |
| ----------------- | ------ | -- | ----- |
| `organization_id` | string | 是  | 组织 ID |

#### 查询参数

| 参数           | 类型     | 必填 | 说明   |
| ------------ | ------ | -- | ---- |
| `start_date` | string | 否  | 开始时间 |
| `end_date`   | string | 否  | 结束时间 |

#### 成功响应 (200 OK)

```json theme={null}
{
  "fileExtensions": [
    {
      "extension": ".go",
      "changeCount": 500,
      "totalLinesAdded": 12000,
      "aiShareRate": 35.5
    }
  ]
}
```

#### 响应字段说明

| 字段                                 | 类型      | 说明           |
| ---------------------------------- | ------- | ------------ |
| `fileExtensions`                   | array   | 文件扩展名列表      |
| `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 代码归因详情，包含文件级的行范围注解。

#### 路径参数

| 参数                | 类型     | 必填 | 说明    |
| ----------------- | ------ | -- | ----- |
| `organization_id` | string | 是  | 组织 ID |

#### 请求体 (JSON)

| 字段             | 类型        | 必填 | 说明             |
| -------------- | --------- | -- | -------------- |
| `commitHashes` | string\[] | 是  | 提交哈希列表，最多 50 个 |
| `branch`       | string    | 否  | 分支名称（用于限定查询范围） |

#### 请求示例

```json theme={null}
{
  "commitHashes": ["abc123def456", "789ghi012jkl"],
  "branch": "main"
}
```

#### 成功响应 (200 OK)

```json theme={null}
{
  "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 }
                ]
              }
            ]
          }
        ]
      },
      {
        "commitHash": "789ghi012jkl",

        "rangeAnnotations": []

      }
    ]
  }
}
```

#### 响应字段说明

| 字段                                                          | 类型      | 说明                                     |
| ----------------------------------------------------------- | ------- | -------------------------------------- |
| `success`                                                   | boolean | 请求是否成功                                 |
| `data.commits`                                              | array   | 提交详情列表（保持请求顺序）                         |
| `data.commits[].commitHash`                                 | string  | 提交哈希                                   |
| `data.commits[].rangeAnnotations`                           | array   | 文件级 AI 归因注解                            |
| `data.commits[].rangeAnnotations[].filePath`                | string  | 文件路径                                   |
| `data.commits[].rangeAnnotations[].groups`                  | array   | AI 会话贡献分组                              |
| `data.commits[].rangeAnnotations[].groups[].conversationId` | string  | AI 会话 ID                               |
| `data.commits[].rangeAnnotations[].groups[].source`         | string  | 来源：`AGENT`、`NEXT`、`QUEST`、`INLINECHAT` |
| `data.commits[].rangeAnnotations[].groups[].productType`    | string  | 产品类型（小写，如 `ide`）                       |
| `data.commits[].rangeAnnotations[].groups[].type`           | string  | 类型：`added`（新增）、`deleted`（删除）           |
| `data.commits[].rangeAnnotations[].groups[].ranges`         | array   | 行范围列表                                  |
| `data.commits[].rangeAnnotations[].groups[].ranges[].start` | int32   | 起始行号                                   |
| `data.commits[].rangeAnnotations[].groups[].ranges[].end`   | int32   | 结束行号                                   |

***

## 使用示例

### 获取统计概览

```bash theme={null}
curl -X GET "https://api.qoder.com/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>"
```

### 获取每日趋势（指定仓库和主分支）

```bash theme={null}
curl -X GET "https://api.qoder.com/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>"
```

### 获取成员排名（前 20）

```bash theme={null}
curl -X GET "https://api.qoder.com/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>"
```

### 搜索仓库

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

### 获取文件扩展名统计

```bash theme={null}
curl -X GET "https://api.qoder.com/v1/organizations/org_xxx/ai-code/file-extensions?start_date=2025-06-01T00:00:00Z" \
  -H "Authorization: Bearer <api_key>"
```

### 获取提交 AI 归因详情

```bash theme={null}
curl -X POST "https://api.qoder.com/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"}'
```

***

## 错误码

| 错误码             | HTTP 状态码 | 说明                                                                         |
| --------------- | -------- | -------------------------------------------------------------------------- |
| `BadRequest`    | 400      | 请求参数无效（如 `start_date` / `end_date` 缺失、时间范围超过 90 天、`commitHashes` 为空或超过 50） |
| `Unauthorized`  | 401      | API Key 缺失或无效                                                              |
| `Forbidden`     | 403      | 无权限访问该组织                                                                   |
| `InternalError` | 500      | 服务器内部错误                                                                    |

错误响应结构见 [约定与规范](/zh/account/teams/openapi/conventions) 中的「错误响应」一节。

***

## AI 代码追踪 API

在 **AI 代码指标**（聚合统计）之外，本节提供 **Commit / Change** 级别的明细查询与 **CSV 导出**。鉴权方式与上文相同：`Authorization: Bearer <api_key>`。

使用前请确认组织已开通与控制台一致的 **AI 代码数据分析** 能力；若未开通或无权访问，接口可能返回 403 等错误，以实际响应为准。字段与枚举以**线上接口与 OpenAPI 定义**为准，本文仅作说明。

## 追踪能力说明

AI 代码追踪 API 提供 commit 级别和 change 级别的逐条明细查询与 CSV 导出能力，是对上文 **AI 代码指标**（聚合统计）的补充。

### 两层数据模型

| 层级         | 含义               | 来源                         | 可用过滤维度       |
| ---------- | ---------------- | -------------------------- | ------------ |
| **Commit** | Git 提交           | 代码仓库（已推送到远程）               | 时间、用户、仓库     |
| **Change** | IDE 内的 AI 代码编辑事件 | 来自 IDE 客户端的上报（尚未形成 Git 提交） | 时间、用户、source |

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

### 产品 x 场景交叉分解（Commit 级别）

每条 commit 记录包含 **12 对** `linesAdded / linesDeleted` 列，按「产品 x 场景」交叉拆解 AI 代码行：

| 字段前缀            | 产品            | 场景            |
| --------------- | ------------- | ------------- |
| `ideNext`       | IDE (VS Code) | Tab 补全 (next) |
| `pluginNext`    | JetBrains 插件  | Tab 补全 (next) |
| `ideAgent`      | IDE (VS Code) | Agent         |
| `pluginAgent`   | JetBrains 插件  | Agent         |
| `cliAgent`      | CLI           | Agent         |
| `ideQuest`      | IDE (VS Code) | Quest         |
| `ideInlineChat` | IDE (VS Code) | Inline Chat   |
| `jbInlineChat`  | JetBrains 插件  | Inline Chat   |
| `nonAi`         | —             | 无法归类的非 AI 行   |

### 主要功能

* **Commit 明细查询**: 逐条列出提交级 AI 代码统计（含产品 x 场景拆解）

* **Commit CSV 导出**: 流式导出全部 commit 数据

* **Change 明细查询**: 逐条列出 IDE 内 AI 代码编辑事件（支持按 `source` 过滤）

* **Change CSV 导出**: 流式导出全部 change 数据

* **用户邮箱**: 列表与导出中会尽量填充 `userEmail`（若数据中存在）

* **按邮箱筛选**: 支持通过 `userEmail` 查询参数定位用户

### 分页方式

Tracking API 使用**偏移量分页**（`page` + `pageSize`），不同于其他接口常用的游标分页。响应包含 `totalItems` / `totalPages`，便于分页展示。

***

## 通用查询参数

以下参数适用于所有 Tracking 接口：

| 参数          | 类型      | 必填 | 默认值  | 说明                                                                     |
| ----------- | ------- | -- | ---- | ---------------------------------------------------------------------- |
| `startDate` | string  | 否  | —    | 开始时间，支持 RFC 3339 格式或 Unix 毫秒时间戳。未传时由服务端按产品策略约束可查范围（例如最长约 90 天），以实际行为为准 |
| `endDate`   | string  | 否  | 当前时间 | 结束时间，支持 RFC 3339 格式或 Unix 毫秒时间戳                                        |
| `userId`    | string  | 否  | —    | 按用户 UUID 过滤                                                            |
| `userEmail` | string  | 否  | —    | 按用户邮箱过滤（服务端会解析为对应的用户标识）                                                |
| `page`      | integer | 否  | 1    | 页码（从 1 开始）                                                             |
| `pageSize`  | integer | 否  | 100  | 每页条数，最大 200                                                            |

> `userId` 和 `userEmail` 同时提供时，`userId` 优先。

***

## API 列表

### 1. 列出 Commit 明细

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

逐条列出提交级 AI 代码统计数据，按提交时间倒序排列。每条记录包含产品 x 场景的交叉拆解。

#### 路径参数

| 参数                | 类型     | 必填 | 说明    |
| ----------------- | ------ | -- | ----- |
| `organization_id` | string | 是  | 组织 ID |

#### 查询参数

见「通用查询参数」，额外支持：

| 参数         | 类型     | 必填 | 说明      |
| ---------- | ------ | -- | ------- |
| `repoName` | string | 否  | 按仓库名称过滤 |

#### 成功响应 (200 OK)

```json theme={null}
{
  "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,
        "pluginNextLinesAdded": 0,
        "pluginNextLinesDeleted": 0,
        "ideAgentLinesAdded": 50,
        "ideAgentLinesDeleted": 15,
        "pluginAgentLinesAdded": 0,
        "pluginAgentLinesDeleted": 0,
        "cliAgentLinesAdded": 0,
        "cliAgentLinesDeleted": 0,
        "ideQuestLinesAdded": 10,
        "ideQuestLinesDeleted": 0,
        "ideInlineChatLinesAdded": 5,
        "ideInlineChatLinesDeleted": 2,
        "jbInlineChatLinesAdded": 0,
        "jbInlineChatLinesDeleted": 0,
        "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
    }
  }
}
```

#### 响应字段说明

**success** - `true` 表示请求成功

**data.items\[ ]** - Commit 明细列表

| 字段                          | 类型      | 说明                         |
| --------------------------- | ------- | -------------------------- |
| `commitHash`                | string  | Git commit SHA             |
| `userId`                    | string  | 用户 UUID                    |
| `userEmail`                 | string  | 用户邮箱（可能为空）                 |
| `repoName`                  | string  | 仓库名称                       |
| `branchName`                | string  | 分支名称                       |
| `isPrimaryBranch`           | boolean | 是否为主分支                     |
| `totalLinesAdded`           | integer | 总新增行数                      |
| `totalLinesDeleted`         | integer | 总删除行数                      |
| `ideNextLinesAdded`         | integer | IDE Tab 补全新增行数             |
| `ideNextLinesDeleted`       | integer | IDE Tab 补全删除行数             |
| `pluginNextLinesAdded`      | integer | JetBrains 插件 Tab 补全新增行数    |
| `pluginNextLinesDeleted`    | integer | JetBrains 插件 Tab 补全删除行数    |
| `ideAgentLinesAdded`        | integer | IDE Agent 新增行数             |
| `ideAgentLinesDeleted`      | integer | IDE Agent 删除行数             |
| `pluginAgentLinesAdded`     | integer | JetBrains 插件 Agent 新增行数    |
| `pluginAgentLinesDeleted`   | integer | JetBrains 插件 Agent 删除行数    |
| `cliAgentLinesAdded`        | integer | CLI Agent 新增行数             |
| `cliAgentLinesDeleted`      | integer | CLI Agent 删除行数             |
| `ideQuestLinesAdded`        | integer | IDE Quest 新增行数             |
| `ideQuestLinesDeleted`      | integer | IDE Quest 删除行数             |
| `ideInlineChatLinesAdded`   | integer | IDE Inline Chat 新增行数       |
| `ideInlineChatLinesDeleted` | integer | IDE Inline Chat 删除行数       |
| `jbInlineChatLinesAdded`    | integer | JetBrains Inline Chat 新增行数 |
| `jbInlineChatLinesDeleted`  | integer | JetBrains Inline Chat 删除行数 |
| `nonAiLinesAdded`           | integer | 非 AI 新增行数                  |
| `nonAiLinesDeleted`         | integer | 非 AI 删除行数                  |
| `message`                   | string  | 提交信息（可能为空）                 |
| `commitTs`                  | string  | 提交时间（ISO 8601）             |
| `createdAt`                 | string  | 记录创建时间（ISO 8601）           |

**data.pagination** - 分页信息

| 字段            | 类型      | 说明   |
| ------------- | ------- | ---- |
| `currentPage` | integer | 当前页码 |
| `pageSize`    | integer | 每页条数 |
| `totalItems`  | integer | 总记录数 |
| `totalPages`  | integer | 总页数  |

***

### 2. 导出 Commit CSV

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

以流式 CSV 格式导出 commit 数据。导出过程由服务端自动完成分页聚合，**调用方无需自行翻页**。

#### 路径参数

| 参数                | 类型     | 必填 | 说明    |
| ----------------- | ------ | -- | ----- |
| `organization_id` | string | 是  | 组织 ID |

#### 查询参数

见「通用查询参数」，额外支持：

| 参数         | 类型     | 必填 | 说明      |
| ---------- | ------ | -- | ------- |
| `repoName` | string | 否  | 按仓库名称过滤 |

#### 成功响应 (200 OK)

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

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

CSV 列头（注意 CSV 保留 `userName`，JSON 响应中已移除）：

```plaintext theme={null}
commitHash,userId,userEmail,userName,repoName,branchName,isPrimaryBranch,
totalLinesAdded,totalLinesDeleted,
ideNextLinesAdded,ideNextLinesDeleted,pluginNextLinesAdded,pluginNextLinesDeleted,
ideAgentLinesAdded,ideAgentLinesDeleted,pluginAgentLinesAdded,pluginAgentLinesDeleted,
cliAgentLinesAdded,cliAgentLinesDeleted,ideQuestLinesAdded,ideQuestLinesDeleted,
ideInlineChatLinesAdded,ideInlineChatLinesDeleted,jbInlineChatLinesAdded,jbInlineChatLinesDeleted,
nonAiLinesAdded,nonAiLinesDeleted,message,commitTs,createdAt
```

***

### 3. 列出 Change 明细

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

逐条列出 IDE 内 AI 代码编辑事件（仅 `action=suggested` 的记录），按事件时间倒序排列。

> Change 是尚未 git commit 的 IDE 内事件，因此**不支持** `repoName` 过滤。

#### 路径参数

| 参数                | 类型     | 必填 | 说明    |
| ----------------- | ------ | -- | ----- |
| `organization_id` | string | 是  | 组织 ID |

#### 查询参数

见「通用查询参数」，额外支持：

| 参数       | 类型     | 必填 | 说明                                              |
| -------- | ------ | -- | ----------------------------------------------- |
| `source` | string | 否  | 按使用场景过滤，可选值：`AGENT`、`NEXT`、`QUEST`、`INLINECHAT` |

#### 成功响应 (200 OK)

```json theme={null}
{
  "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
          },
          {
            "fileName": "utils.go",
            "fileExtension": ".go",
            "linesAdded": 15,
            "linesDeleted": 4
          }
        ],
        "createdAt": "2025-06-15T10:28:00Z"
      }
    ],
    "pagination": {
      "currentPage": 1,
      "pageSize": 100,
      "totalItems": 1024,
      "totalPages": 11
    }
  }
}
```

#### 响应字段说明

**success** - `true` 表示请求成功

**data.items\[ ]** - Change 明细列表

| 字段                         | 类型      | 说明                                           |
| -------------------------- | ------- | -------------------------------------------- |
| `changeId`                 | string  | 变更事件唯一标识                                     |
| `userId`                   | string  | 用户 UUID                                      |
| `userEmail`                | string  | 用户邮箱（可能为空）                                   |
| `source`                   | string  | 使用场景（大写）：`NEXT`、`AGENT`、`QUEST`、`INLINECHAT` |
| `model`                    | string  | 模型级别：`lite`、`efficient`、`auto`（可能为空）         |
| `totalLinesAdded`          | integer | 总新增行数                                        |
| `totalLinesDeleted`        | integer | 总删除行数                                        |
| `metadata`                 | array   | 文件级别变更明细（可能为空）                               |
| `metadata[].fileName`      | string  | 文件名                                          |
| `metadata[].fileExtension` | string  | 文件扩展名                                        |
| `metadata[].linesAdded`    | integer | 文件新增行数                                       |
| `metadata[].linesDeleted`  | integer | 文件删除行数                                       |
| `createdAt`                | string  | 事件时间（ISO 8601）                               |

**data.pagination** - 分页信息

| 字段            | 类型      | 说明   |
| ------------- | ------- | ---- |
| `currentPage` | integer | 当前页码 |
| `pageSize`    | integer | 每页条数 |
| `totalItems`  | integer | 总记录数 |
| `totalPages`  | integer | 总页数  |

***

### 4. 导出 Change CSV

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

以流式 CSV 格式导出 change 数据。导出过程由服务端自动完成分页聚合，**调用方无需自行翻页**。

> CSV 导出为扁平格式，不包含 `metadata`（文件级明细）。

#### 路径参数

| 参数                | 类型     | 必填 | 说明    |
| ----------------- | ------ | -- | ----- |
| `organization_id` | string | 是  | 组织 ID |

#### 查询参数

见「通用查询参数」，额外支持：

| 参数       | 类型     | 必填 | 说明                                              |
| -------- | ------ | -- | ----------------------------------------------- |
| `source` | string | 否  | 按使用场景过滤，可选值：`AGENT`、`NEXT`、`QUEST`、`INLINECHAT` |

#### 成功响应 (200 OK)

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

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

CSV 列头：

```plaintext theme={null}
changeId,userId,userEmail,source,model,totalLinesAdded,totalLinesDeleted,createdAt
```

***

## 使用示例

### 查询 commit 明细（按仓库过滤）

```bash theme={null}
curl -X GET "https://api.qoder.com/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

```bash theme={null}
curl -X GET "https://api.qoder.com/v1/organizations/org_xxx/ai-code-tracking/commits?startDate=2025-06-01T00:00:00Z&userEmail=zhangsan@example.com" \
  -H "Authorization: Bearer <api_key>"
```

### 导出 commit CSV

```bash theme={null}
curl -X GET "https://api.qoder.com/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 明细（按 source 过滤）

```bash theme={null}
curl -X GET "https://api.qoder.com/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

```bash theme={null}
curl -X GET "https://api.qoder.com/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 状态码 | 说明                                               |
| --------------- | -------- | ------------------------------------------------ |
| `Unauthorized`  | 401      | API Key 缺失或无效                                    |
| `Forbidden`     | 403      | 无权限访问该组织                                         |
| `BadRequest`    | 400      | 请求参数无效（如 `organization_id` / `userId` 不是合法 UUID） |
| `InternalError` | 500      | 服务器内部错误                                          |

错误响应结构见 [约定与规范](/zh/account/teams/openapi/conventions) 中的「错误响应」一节。
