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

# 上传或替换 plugin。

> 将上传的文件列表保存为 plugin，名称由其清单指定；如果该 plugin 已存在，则整体替换，
并要求在此作用域内使用。

将 plugin 的文件上传到组织，以创建该 plugin，或将其替换为新版本。可通过此接口从 CI 发布 plugin，无需在 [Customize](https://docs.devinenterprise.com/zh/product-guides/plugins.md) 中手动上传 `.zip` 文件。如需从 plugin 文件夹构建请求的脚本，请参阅[从 CI 发布上传的插件](https://docs.devinenterprise.com/zh/product-guides/plugins.md#publish-an-uploaded-plugin-from-ci)。

## 权限

需要使用在组织级别具有 `ManageOrgPlugins` 权限的[服务用户](https://docs.devinenterprise.com/zh/api-reference/v3/service-users/members-service-users.md)或[个人访问令牌](https://docs.devinenterprise.com/zh/api-reference/personal-access-tokens.md)。正在运行的 Devin 会话所使用的令牌会被拒绝。

## 行为

* 请求为 JSON 格式，其中的 `files` 列表包含 plugin 的全部文件。每个条目包含相对于 plugin 根目录的 `path` 及其 `content`。文本文件以 UTF-8 文本形式发送。其他文件需将字节进行 Base64 编码后发送，并将 `is_binary` 设为 `true`。整个请求的大小上限为 75 MB。
* plugin ID 取自[plugin 清单](https://docs.devinenterprise.com/zh/cli/extensibility/plugins/overview.md#manifest)中的 `name`：先转换为小写，再将其中每一段连续的其他字符替换为 `-`。文件中必须包含清单。URL 中不包含 ID。
* 如果此作用域下不存在该 ID 的 plugin，上传时会创建它；否则，此次上传将成为该 plugin 的下一个版本：其文件与请求中的文件完全一致，较早的版本仍保留在 **Version history** 中。
* 如果组织的清单中尚未列出该 plugin，则会将其以必需项的形式添加到清单中，从而为组织内的所有人安装。已列出的 plugin 则保留其当前条目。
* 上传会直接替换已存储的 plugin，不会检查最后修改者是谁。为避免覆盖你尚未看到的更改，请发送 `revision_token`，其值为上一次上传返回的值：如果 plugin 在此之后发生过更改，上传将被拒绝并返回 `409`。
* API 不接受 `.zip` 文件。请先解压 plugin，再发送其中的文件。
* 新会话会加载已上传的版本。正在运行的会话则继续使用启动时加载的内容。

## 状态代码

* `201`：此次上传创建了一个新的 plugin。如果意外收到 `201`，通常说明清单中的 `name` 已更改。

* `200`：此次上传用新版本替换了现有的 plugin。

* `400`：某个路径不安全或重复，二进制内容不是有效的 base64，或者文件超出了文件数量或总大小限额。

* `403`：调用方缺少相应权限或使用的是会话令牌，该账户已禁用上传的插件，或者该 ID 为 Devin 保留。

* `409`：该 ID 所属的 plugin 无法通过上传替换，或者请求中携带了 `revision_token`，但该 plugin 在该修订版本之后已发生变更。


## OpenAPI

````yaml zh/v3-openapi.yaml PUT /v3beta1/organizations/{org_id}/plugins/uploads
openapi: 3.1.0
info:
  description: 采用 Service User 身份验证和 RBAC 的 Devin v3 API
  title: Devin API v3
  version: 3.0.0
servers: []
security:
  - bearerAuth: []
paths:
  /v3beta1/organizations/{org_id}/plugins/uploads:
    put:
      tags:
        - managed-plugins
      summary: 上传或替换 plugin。
      description: |-
        将上传的文件列表保存为 plugin，名称由其清单指定；如果该 plugin 已存在，则整体替换，
        并要求在此作用域内使用。
      operationId: >-
        handle_put_org_plugin_upload_v3beta1_organizations__org_id__plugins_uploads_put
      parameters:
        - description: 组织 ID（前缀：org-）
          in: path
          name: org_id
          required: true
          schema:
            example: org-abc123def456
            title: Org Id
            type: string
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/PluginUploadRequest'
        required: true
      responses:
        '200':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/PluginUploadResponse'
          description: 成功响应
        '201':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/PluginUploadResponse'
          description: 本次上传已创建 plugin。
        '401':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ProblemDetail'
          description: 未授权
        '403':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ProblemDetail'
          description: 禁止访问
        '404':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ProblemDetail'
          description: 未找到
        '409':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ProblemDetail'
          description: 冲突
        '410':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ProblemDetail'
          description: 已失效
        '422':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ProblemDetail'
          description: 无法处理的内容
        '429':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ProblemDetail'
          description: 请求过多
components:
  schemas:
    PluginUploadRequest:
      properties:
        files:
          description: plugin 的所有文件，以完整目录树的形式提供。
          items:
            $ref: '#/components/schemas/PluginUploadFile'
          maxItems: 100000
          minItems: 1
          title: Files
          type: array
        revision_token:
          anyOf:
            - type: string
            - type: 'null'
          description: 仅当 plugin 仍处于此修订版本时才上传。
          title: Revision Token
      required:
        - files
      title: PluginUploadRequest
      type: object
    PluginUploadResponse:
      properties:
        name:
          description: plugin 的显示名称。
          title: Name
          type: string
        plugin_id:
          description: plugin 的 ID，取自其清单中的名称。
          title: Plugin Id
          type: string
        revision_token:
          description: 此次上传保存后对应的修订版本。
          title: Revision Token
          type: string
      required:
        - plugin_id
        - name
        - revision_token
      title: PluginUploadResponse
      type: object
    ProblemDetail:
      description: >-
        v3 API 的 RFC 9457 application/problem+json 错误响应体。


        detail 沿用自旧版 {"detail": ...} 响应体，以保持向后兼容；其他成员字段为新增字段。errors
        包含字段级验证失败信息（仅 422）。
      properties:
        detail:
          anyOf:
            - type: string
            - type: 'null'
          description: 针对此次具体情况的、便于人理解的说明。
          title: Detail
        error_code:
          anyOf:
            - type: string
            - type: 'null'
          description: 因操作被阻止而拒绝请求时返回的机器可读代码（例如 "user_frozen"、"migrated_session"）。
          title: Error Code
        errors:
          anyOf:
            - items:
                additionalProperties: true
                type: object
              type: array
            - type: 'null'
          description: 字段级验证错误（仅适用于 422 响应）。
          title: Errors
        instance:
          anyOf:
            - type: string
            - type: 'null'
          description: 此次出现对应的 URI 引用（请求路径）。
          title: Instance
        status:
          description: HTTP 状态码。
          title: Status
          type: integer
        title:
          description: 对问题类型的简短、便于理解的概述。
          title: Title
          type: string
        type:
          default: about:blank
          description: 用于标识问题类型的 URI 引用。
          title: Type
          type: string
      required:
        - title
        - status
      title: ProblemDetail
      type: object
    PluginUploadFile:
      properties:
        content:
          description: 文件的 UTF-8 文本内容；当 `is_binary` 为真时，则为文件字节的 base64 编码。
          title: Content
          type: string
        is_binary:
          default: false
          description: '`content` 是否经过 base64 编码。'
          title: Is Binary
          type: boolean
        path:
          description: 文件相对于插件根目录的路径。
          title: Path
          type: string
      required:
        - path
        - content
      title: PluginUploadFile
      type: object
  securitySchemes:
    bearerAuth:
      description: 服务用户凭据（前缀：cog_）
      scheme: bearer
      type: http

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.