Developer Docs

文档首页

开发文档 · 构建应用

嵌入指南

在生产网站或业务 App 中嵌入 Fellow Widget 的 checklist。

状态:Preview(Interaction) — Widget、短期 Access Token 与 Thread / Run 嵌入链路可用于受控试用;Integration App 的管理与发布能力仍为 Experimental。请按实际 Gateway、Console 与 SDK 版本验证字段和行为。

本指南面向 SDK Widget 嵌入(如官网客服、CRM 内嵌助手),架构如下:

浏览器
  │  FellowChatWidget + access_token

你的后端  /api/.../access-token  (持 fkey_,仅服务端)
  │  POST /api/apps/token

Fellow Gateway  (Integration App 鉴权 + CORS)
  │  Thread / Run

runtimeUserId 的 harness

原则:fkey_ 只在你的服务端;浏览器只用短期 access_token

1. Console · Integration App

说明
Runtime 用户绑定客服/助手使用的 Agent 与 Skills
default_agentRun 未指定 agent 时使用
allowed_origins与浏览器 Origin 完全一致(含 https,无尾斜杠)
scopes至少 threads + runs(含 consent 若需要)

本地开发额外添加:http://localhost:5174(或实际 dev 端口)。

2. 环境变量(部署侧)

变量说明
FELLOW_APP_API_KEYfkey_…仅服务端
FELLOW_APP_IDapp_…,多 App 时建议指定
FELLOW_API_URLGateway API,如 https://app.fellow.work/api(服务端 token 路由读取,经 api_base_url 传给 Widget)
FELLOW_CLIENT_ORIGINallowed_origins 一致(代理场景必填)

3. 后端 Token 交换

const { access_token } = await fellowClient.createAccessToken({
  origin: 'https://your-app.com',
  external_user_id: visitorId, // 同一访客复用 thread
});

access_token 返回给前端;不要返回 fkey_

4. 前端挂载

import { FellowChatWidget } from '@fellow.work/client/react';

// baseUrl 来自服务端 token 交换响应中的 api_base_url(推荐),或直接传入 Gateway 地址
<FellowChatWidget
  baseUrl={apiBaseUrl}
  accessToken={token}
/>

Widget 默认在 Shadow DOM 内自带样式,不要在宿主页面 import @fellow.work/client/ui.css

5. 部署前检查

  • @fellow.work/client 已安装
  • allowed_origins 含生产域名
  • default_agent 在 runtime 用户下可用
  • Gateway 公网可达
  • 服务端 env 已配置 FELLOW_APP_API_KEY

6. Smoke Test

  1. 打开页面 → Widget 按钮出现
  2. 发消息 → Agent 正常回复
  3. 刷新 → 同一 external_user_id 复用 thread
  4. Network:access-token 200;Gateway 请求带 Bearer eyJ…
  5. Console → 接入应用 → 对话列表可见 thread

常见问题

现象排查
Widget 不显示token 交换失败或 origin 不在 allowed_origins
CORS 错误allowed_origins 与请求 Origin 不一致
403 on GatewayScope 不足或 App 已 disabled

相关文档