> ## 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 发布到所有组织。如需根据 plugin 文件夹构建该请求的脚本，请参阅[从 CI 发布上传的插件](https://docs.devinenterprise.com/zh/product-guides/plugins.md#publish-an-uploaded-plugin-from-ci)。

## 权限

需要使用在企业级具有 `ManageAccountPlugins` 权限的[服务用户](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)。

## 行为

* 请求为 JSON 格式，其中的 `files` 列表包含 plugin 的全部文件。每个条目包含相对于插件根目录的 `path` 及其 `content`。文本文件以 UTF-8 文本形式发送；其他文件需将字节进行 Base64 编码后发送，并将 `is_binary` 设为 `true`。整个请求的大小上限为 75 MB。
* plugin ID 取自[插件清单](https://docs.devinenterprise.com/zh/cli/extensibility/plugins/overview.md#manifest)中的 `name`：先转为小写，再将每段连续的其他字符替换为 `-`。文件中必须包含清单。URL 中不包含 ID。
* 如果该作用域下尚无此 ID 的 plugin，上传会创建该 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/enterprise/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/enterprise/plugins/uploads:
    put:
      tags:
        - managed-plugins
      summary: 上传或替换 plugin。
      description: |-
        将上传的文件列表保存为 plugin，名称由其清单指定；如果该 plugin 已存在，则整体替换，
        并要求在企业内使用。
      operationId: handle_put_plugin_upload_v3beta1_enterprise_plugins_uploads_put
      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.