web接入扣子私有化智能体

上一篇开源版扣子私有化部署,扣子已经部署到我们自己服务器上了,现在还有几个问题要解决。

  • 接入私有大模型(上一篇已解决)
  • 发布后能独立被其他Web嵌入,比如做个智能客服被嵌入其他网站
  • 能使用其他官网插件
  • 能自己开发插件
  • 能接入其他智能体

这篇文章讲第二点自己的智能体如何被其他web直接调用,有两种方式直接后端api和前端嵌入web页面。

对应发布时的 APIChat SDK

开发规范

原文 github.com/coze-dev/co...

Chat SDK

原文 github.com/coze-dev/co...

php 复制代码
new CozeWebSDK.WebChatClient({
  /**
  * Agent or app settings
  * for agent
  * @param config.bot_id - Agent ID.
  * for app
  * @param config.type - To integrate a Coze app, you must set the value to app.
  * @param config.isIframe - Whether to use the iframe method to open the chat box
  * @param config.appInfo.appId - AI app ID.
  * @param config.appInfo.workflowId - Workflow or chatflow ID.
  */
  config: {
    type: 'bot',
    bot_id: 'xxxx',
    isIframe: false,
  },
  /**
  * The auth property is used to configure the authentication method.
  * @param type - Authentication method, default type is 'unauth', which means no authentication is required; it is recommended to set it to 'token', which means authentication is done through PAT (Personal Access Token) or OAuth.
  * @param token - When the type is set to 'token', you need to configure the PAT (Personal Access Token) or OAuth access key.
  * @param onRefreshToken - When the access key expires, a new key can be set as needed.
  */
  auth: {
    type: 'token',
    token: 'xxxx',
    onRefreshToken: async () => 'token'
  },
  /**
  * The userInfo parameter is used to set the display of agent user information in the chat box.
  * @param userInfo.id - ID of the agent user.
  * @param userInfo.url - URL address of the user's avatar.
  * @param userInfo.nickname - Nickname of the agent user.
  */
  userInfo: {
    id: 'user',
    url: 'https://lf-coze-web-cdn.coze.cn/obj/eden-cn/lm-lgvj/ljhwZthlaukjlkulzlp/coze/coze-logo.png',
    nickname: 'User',
  },
  ui: {
    /**
    * The ui.base parameter is used to add the overall UI effect of the chat window.
    * @param base.icon - Application icon URL.
    * @param base.layout - Layout style of the agent chat box window, which can be set as 'pc' or'mobile'.
    * @param base.lang - System language of the agent, which can be set as 'en' or 'zh-CN'.
    * @param base.zIndex - The z-index of the chat box.
    */
    base: {
      icon: 'https://lf-coze-web-cdn.coze.cn/obj/eden-cn/lm-lgvj/ljhwZthlaukjlkulzlp/coze/chatsdk-logo.png',
      layout: 'pc',
      lang: 'en',
      zIndex: 1000
    },
    /**
    * Controls whether to display the top title bar and the close button
    * @param header.isShow - Whether to display the top title bar.
    * @param header.isNeedClose - Whether to display the close button.
    */
    header: {
      isShow: true,
      isNeedClose: true,
    },
    /**
    * Controls whether to display the floating ball at the bottom right corner of the page.
    */
    asstBtn: {
      isNeed: true
    },
    /**
    * The ui.footer parameter is used to add the footer of the chat window.
    * @param footer.isShow - Whether to display the bottom copy module.
    * @param footer.expressionText - The text information displayed at the bottom.
    * @param footer.linkvars - The link copy and link address in the footer.
    */
    footer: {
      isShow: true,
      expressionText: 'Powered by ...',
    },
    /**
    * Control the UI and basic capabilities of the chat box.
    * @param chatBot.title - The title of the chatbox
    * @param chatBot.uploadable - Whether file uploading is supported.
    * @param chatBot.width - The width of the agent window on PC is measured in px, default is 460.
    * @param chatBot.el - Container for setting the placement of the chat box (Element).
    */
    chatBot: {
      title: 'Coze Bot',
      uploadable: true,
      width: 390,
    },
  },
});

开发环境

环境要求: docker、go(≥1.24)、make、node(>=22) 、npm、rush

安装nvm和node22+

bash 复制代码
# 0.  安装nvm
curl -fsSL https://gitee.com/edazh/nvm/raw/master/install.sh | bash

# 1. 先删除可能冲突的镜像配置(若之前加过其他镜像)
sed -i '/NVM_NODEJS_ORG_MIRROR/d' ~/.bashrc

# 2. 重新添加淘宝镜像(更稳定,支持版本查询)
echo 'export NVM_NODEJS_ORG_MIRROR=https://mirrors.aliyun.com/nodejs-release/' >> ~/.bashrc

# 3. 激活配置(必须执行,让镜像生效)
source ~/.bashrc

# 4. 安装22的最新版
nvm install 22

下载coze-studio源码

bash 复制代码
# 下载源码
git clone https://github.com/coze-dev/coze-studio.git

# 安装环境
npm install -g pnpm rush

# 安装docker
yum makecache
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
yum install -y gcc gcc-c++ make yum-utils device-mapper-persistent-data lvm2
yum install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
systemctl enable docker
systemctl start docker

# 安装golang最新版,我安了是 1.24.6
dnf install -y epel-release
dnf install -y golang
go version

调试步骤

  1. 首次在本地启动调试时,需要执行以下命令:

    bash 复制代码
    # 确保 docker 是正常运行的
    make debug
  2. 后面修改代码保存,直接重新编译启动coze-server服务,执行以下命令即可:

    go 复制代码
    make server
  3. 除上述外,如果还需要调试前端代码,重新打开Terminal 程序,启动前端工程:

    bash 复制代码
    bash scripts/setup_fe.sh
    cd frontend/apps/coze-studio
    npm run dev

发布私有化Chat Sdk页面

安装图上修改源码服务器地址,重新build chat sdk代码

效果

样式有问题,错位了,自己在 index.html中手动增加点样式吧

css 复制代码
.semi-avatar-circle {
        border-radius: 50%;
    }
    .semi-avatar-small {
        border-radius: 3px;
        width: 32px;
        height: 32px;
    }
    
    .semi-avatar {
        white-space: nowrap;
        text-align: center;
        vertical-align: middle;
        justify-content: center;
        align-items: center;
        display: inline-flex;
        position: relative;
        overflow: hidden;
    }
    .semi-avatar>img {
        -o-object-fit: cover;
        object-fit: cover;
        width: 100%;
        height: 100%;
        display: block;
    }
    .semi-upload-hidden-input, .semi-upload-hidden-input-replace {
        display: none;
    }
相关推荐
老陈聊架构17 小时前
『AI辅助Skill』掌握三大AI设计Skill:前端独立完成产品设计全流程
前端·人工智能·claude·skill
Ulyanov18 小时前
从桌面到云端:构建Web三维战场指挥系统
开发语言·前端·python·tkinter·pyvista·gui开发
cypking18 小时前
二、前端Java后端对比指南
java·开发语言·前端
糠帅傅蓝烧牛肉面18 小时前
单实例多MCP聚合服务:两种实现方案深度对比
前端·docker·ai
JosieBook18 小时前
【Vue】12 Vue技术—— Vue 事件修饰符详解:掌握事件处理的高级技巧
前端·javascript·vue.js
艾斯特_19 小时前
Echarts常用配置项及解释
前端·javascript·echarts
m0_5027249519 小时前
飞书真机调试
开发语言·前端·javascript
我只会写Bug啊20 小时前
复制可用!纯前端基于 Geolocation API 实现经纬度获取与地图可视化
前端·高德地图·地图·百度地图·经纬度
刘一说20 小时前
Vue3 模块语法革命:移除过滤器(Filters)的深度解析与迁移指南
前端·vue.js·js
lkbhua莱克瓦2421 小时前
JavaScript核心语法
开发语言·前端·javascript·笔记·html·ecmascript·javaweb