用途:用于把 ibl.ai 智能体嵌入外部网站,并通过平台 API 配置其嵌入/小组件设置与鉴权。
接口约定:基础地址 https://api.iblai.app;每个请求带请求头 Authorization: Api-Token $IBLAI_API_KEY。路径变量 {org}=$IBLAI_ORG、{username}=$IBLAI_USERNAME、{mentor}=智能体唯一 id。未连通时先运行 /iblai-api-login 填充 IBLAI_ORG、IBLAI_USERNAME、IBLAI_API_KEY。
读取:GET …/mentors/{mentor}/public-settings/ 获取当前嵌入设置;GET …/mentors/{mentor}/settings/ 获取自定义 CSS/JS;GET …/mentors/{mentor}/sharable-link 获取分享链接令牌(404 表示尚无);SSO 提供商从 https://learn.iblai.app/ibl-auth/get-provider-slug/?platform_key={org}&username={username} 读取。
写入:嵌入设置统一通过 PUT …/mentors/{mentor}/settings/ 以 multipart/form-data 提交,只发送变更字段,未发送的字段保持不变。可用字段包括 allow_anonymous、custom_css、website_url、mode(default|advanced)、is_context_aware、mentor_visibility、embed_show_attachment、embed_show_voice_call、embed_show_voice_record、show_catalogue、starter_prompts(guided_prompt|suggested_prompt)、sso、sso_provider、auto_open、slug、safety_disclaimer。高级样式仅提交 custom_css,高级脚本提交 custom_javascript。示例: curl -X PUT "https://api.iblai.app/dm/api/ai-mentor/orgs/$IBLAI_ORG/users/$IBLAI_USERNAME/mentors/$MENTOR/settings/" -H "Authorization: Api-Token $IBLAI_API_KEY" -F "allow_anonymous=true" -F "embed_show_attachment=true"
分享与重定向:POST …/mentors/{mentor}/sharable-link(空请求体)创建或重新生成分享链接;PUT 同路径以 {"enabled": true|false} 启用/禁用;POST https://api.iblai.app/dm/api/core/orgs/{org}/redirect-tokens/ 以 {"url", "mentor_unique_id"} 生成重定向令牌。这两类写操作会对外发布,需先与用户确认。
后端令牌预置:为避免 SSO 登录弹窗,可在自有后端用组织的 Platform API Token(服务器到服务器,切勿暴露在浏览器 JS 中)调用 POST https://api.iblai.app/dm/api/core/consolidated-token/provision/,请求体含 username、email、name(可选)、platform_key(须等于 Api-Token 所属组织);成功返回 axd_token、dm_token、edx_jwt_token 三个 {token, expires}。错误:403(邮箱与用户名指向不同用户、platform_key 不符或触达每用户令牌上限)、503 带 Retry-After(新用户尚未同步,原样重发)。该接口受组织级开关 ENABLE_PLATFORM_CONSOLIDATED_PROXY_PROVISIONING 控制,未启用时返回 404。组织/平台记录可通过 GET https://api.iblai.app/dm/api/core/users/platforms/?username={username}&platform_key={org} 获取,需用返回的 key、org、is_admin、username。
组装 ibl-data:在后端构建该 JSON(内含新签令牌)并交给嵌入组件,其会像 Auth SPA 一样写入 localStorage。axd_token、dm_token、edx_jwt_token 及其 expires 来自 /provision;userData 为 data.user 的 JSON 字符串;tenant 取自 /users/platforms 的 key;current_tenant 为 {"key"} 的 JSON 字符串;tenants 为 [{ key, name: org, is_admin, username }] 的 JSON 字符串。传递方式二选一:在 iframe src 上以 URL 编码的 ibl-data= 查询参数附加,或对已加载 iframe 发送 postMessage { type: "MENTOR:AUTH_UPDATE", authData: JSON.stringify(iblData) }。
限制:SSO 提供商读取使用 LMS 主机 learn.iblai.app,非 api.iblai.app;GET sharable-link 的 404 仅表示尚无分享链接,需 POST 创建;/provision 可能创建真实用户与凭据,需先确认;后端令牌预置需要组织启用相应开关,并依赖 ibl.ai 侧配置,未提供时相关能力暂不可用。