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;
    }
相关推荐
咬人喵喵5 分钟前
14 类圣诞核心 SVG 交互方案拆解(附案例 + 资源)
开发语言·前端·javascript
问君能有几多愁~18 分钟前
C++ 日志实现
java·前端·c++
咬人喵喵19 分钟前
CSS 盒子模型:万物皆是盒子
前端·css
2401_8603195226 分钟前
DevUI组件库实战:从入门到企业级应用的深度探索,如何快速应用各种组件
前端·前端框架
韩曙亮1 小时前
【Web APIs】元素滚动 scroll 系列属性 ② ( 右侧固定侧边栏 )
前端·javascript·bom·window·web apis·pageyoffset
珑墨1 小时前
【浏览器】页面加载原理详解
前端·javascript·c++·node.js·edge浏览器
LYFlied1 小时前
在AI时代,前端开发者如何构建全栈开发视野与核心竞争力
前端·人工智能·后端·ai·全栈
用户47949283569152 小时前
我只是给Typescript提个 typo PR,为什么还要签协议?
前端·后端·开源
程序员爱钓鱼2 小时前
Next.js SSR 项目生产部署全攻略
前端·next.js·trae
程序员爱钓鱼2 小时前
使用Git 实现Hugo热更新部署方案(零停机、自动上线)
前端·next.js·trae