refactor: rename cs-ai-agent to agent-desk in SDK and related files

- Updated message types in support-host-bridge.ts to use agent-desk prefix.
- Added new agent-desk-sdk.min.js file with updated functionality.
- Removed old cs-ai-agent-sdk.min.js file.
- Modified build-sdk script to generate agent-desk-sdk.min.js.
- Changed scrollbar class names in main.scss from cs-ai-agent to agent-desk.
This commit is contained in:
mlogclub
2026-05-31 18:46:05 +08:00
parent 101577f163
commit eb04c344a5
14 changed files with 52 additions and 52 deletions
@@ -744,7 +744,7 @@ function WebAccessGuide({ channelId }: { channelId: string }) {
channelId: "${channelId}" channelId: "${channelId}"
}; };
</script> </script>
<script async src="${origin}/sdk/cs-ai-agent-sdk.min.js"></script>` <script async src="${origin}/sdk/agent-desk-sdk.min.js"></script>`
}, [channelId, origin]) }, [channelId, origin])
async function copyText(text: string, successMessage: string) { async function copyText(text: string, successMessage: string) {
@@ -350,7 +350,7 @@ export function ChatPanel() {
const messagesScroll = ( const messagesScroll = (
<div <div
ref={messagesContainerRef} ref={messagesContainerRef}
className="h-full min-h-0 flex-1 overflow-y-auto p-4 cs-ai-agent-scrollbar" className="h-full min-h-0 flex-1 overflow-y-auto p-4 agent-desk-scrollbar"
> >
<div ref={messagesContentRef} className="flex flex-col"> <div ref={messagesContentRef} className="flex flex-col">
{!loading && messages.length > 0 && messagesHasMore ? ( {!loading && messages.length > 0 && messagesHasMore ? (
@@ -446,9 +446,9 @@ export function SharedMessageEditor({
function getEditorClassName(variant: SharedMessageEditorVariant) { function getEditorClassName(variant: SharedMessageEditorVariant) {
if (variant === "customer") { if (variant === "customer") {
return "cs-ai-agent-scrollbar min-h-12 max-h-40 overflow-y-auto px-1.5 py-1 text-sm leading-6 text-foreground outline-none [&_p]:m-0 [&_p+*]:mt-2 [&_.cs-ai-agent-editor-image-wrap]:my-2 [&_.cs-ai-agent-editor-image]:max-h-64 [&_.cs-ai-agent-editor-image]:max-w-full [&_.cs-ai-agent-editor-image]:rounded-lg [&_.cs-ai-agent-editor-image]:object-contain [&_.cs-ai-agent-editor-image-wrap-uploading_.cs-ai-agent-editor-image]:opacity-55" return "agent-desk-scrollbar min-h-12 max-h-40 overflow-y-auto px-1.5 py-1 text-sm leading-6 text-foreground outline-none [&_p]:m-0 [&_p+*]:mt-2 [&_.agent-desk-editor-image-wrap]:my-2 [&_.agent-desk-editor-image]:max-h-64 [&_.agent-desk-editor-image]:max-w-full [&_.agent-desk-editor-image]:rounded-lg [&_.agent-desk-editor-image]:object-contain [&_.agent-desk-editor-image-wrap-uploading_.agent-desk-editor-image]:opacity-55"
} }
return "h-full min-h-12 max-h-[20vh] overflow-y-auto px-1.5 py-1 text-sm leading-6 text-foreground outline-none sm:max-h-none [&_.ProseMirror-focused]:outline-none [&_p]:m-0 [&_p+.cs-ai-agent-editor-image-wrap]:mt-2 [&_.cs-ai-agent-editor-image-wrap]:my-2 [&_.cs-ai-agent-editor-image]:max-h-64 [&_.cs-ai-agent-editor-image]:max-w-full [&_.cs-ai-agent-editor-image]:rounded-md [&_.cs-ai-agent-editor-image]:object-contain [&_.cs-ai-agent-editor-image-wrap-uploading_.cs-ai-agent-editor-image]:opacity-55 [&_p.is-editor-empty:first-child]:before:text-muted-foreground" return "h-full min-h-12 max-h-[20vh] overflow-y-auto px-1.5 py-1 text-sm leading-6 text-foreground outline-none sm:max-h-none [&_.ProseMirror-focused]:outline-none [&_p]:m-0 [&_p+.agent-desk-editor-image-wrap]:mt-2 [&_.agent-desk-editor-image-wrap]:my-2 [&_.agent-desk-editor-image]:max-h-64 [&_.agent-desk-editor-image]:max-w-full [&_.agent-desk-editor-image]:rounded-md [&_.agent-desk-editor-image]:object-contain [&_.agent-desk-editor-image-wrap-uploading_.agent-desk-editor-image]:opacity-55 [&_p.is-editor-empty:first-child]:before:text-muted-foreground"
} }
function getToolbarClassName(variant: SharedMessageEditorVariant) { function getToolbarClassName(variant: SharedMessageEditorVariant) {
+1 -1
View File
@@ -219,7 +219,7 @@ export const SupportChatMessageList = forwardRef<SupportChatMessageListHandle, S
return ( return (
<div <div
ref={containerRef} ref={containerRef}
className="cs-ai-agent-scrollbar flex min-h-0 flex-1 flex-col gap-4 overflow-y-auto px-4 py-4" className="agent-desk-scrollbar flex min-h-0 flex-1 flex-col gap-4 overflow-y-auto px-4 py-4"
> >
<div ref={contentRef} className="flex flex-col gap-4"> <div ref={contentRef} className="flex flex-col gap-4">
{hasMoreOlder && onLoadOlder ? ( {hasMoreOlder && onLoadOlder ? (
+5 -5
View File
@@ -7,7 +7,7 @@ import { useEffect, useMemo, useState } from "react"
import type { CSAgentConfig } from "@/lib/sdk/config-types" import type { CSAgentConfig } from "@/lib/sdk/config-types"
import { useI18n } from "@/i18n/provider" import { useI18n } from "@/i18n/provider"
const STORAGE_KEY = "cs-ai-agent-web-widget-test-config" const STORAGE_KEY = "agent-desk-web-widget-test-config"
const DEFAULT_JWT_TTL_MINUTES = "30" const DEFAULT_JWT_TTL_MINUTES = "30"
const INITIAL_CONFIG: CSAgentConfig = { const INITIAL_CONFIG: CSAgentConfig = {
channelId: "", channelId: "",
@@ -56,7 +56,7 @@ function removeMountedWidget() {
window.CSAgentWidget?.destroy() window.CSAgentWidget?.destroy()
document document
.querySelectorAll( .querySelectorAll(
'[data-cs-ai-agent-widget="launcher"], [data-cs-ai-agent-widget="frame"], [data-cs-ai-agent-widget="script"]' '[data-agent-desk-widget="launcher"], [data-agent-desk-widget="frame"], [data-agent-desk-widget="script"]'
) )
.forEach((node) => node.remove()) .forEach((node) => node.remove())
@@ -72,7 +72,7 @@ function injectWidget(config: CSAgentConfig) {
const script = document.createElement("script") const script = document.createElement("script")
script.async = true script.async = true
script.src = `${window.location.origin}/sdk/cs-ai-agent-sdk.min.js` script.src = `${window.location.origin}/sdk/agent-desk-sdk.min.js`
script.dataset.csAgentWidget = "script" script.dataset.csAgentWidget = "script"
document.body.appendChild(script) document.body.appendChild(script)
} }
@@ -187,8 +187,8 @@ export function SupportWidgetDemo() {
const snippet = useMemo(() => { const snippet = useMemo(() => {
const scriptSrc = origin const scriptSrc = origin
? `${origin}/sdk/cs-ai-agent-sdk.min.js` ? `${origin}/sdk/agent-desk-sdk.min.js`
: "/sdk/cs-ai-agent-sdk.min.js" : "/sdk/agent-desk-sdk.min.js"
const configLines = [` channelId: "${config.channelId || ""}"`] const configLines = [` channelId: "${config.channelId || ""}"`]
if (config.authMode === "jwt") { if (config.authMode === "jwt") {
+2 -2
View File
@@ -15,8 +15,8 @@ export type AuthSession = {
roles: string[] roles: string[]
} }
const SESSION_STORAGE_KEY = "cs-ai-agent-session" const SESSION_STORAGE_KEY = "agent-desk-session"
export const AUTH_SESSION_EXPIRED_EVENT = "cs-ai-agent-auth-expired" export const AUTH_SESSION_EXPIRED_EVENT = "agent-desk-auth-expired"
function hasWindow() { function hasWindow() {
return typeof window !== "undefined" return typeof window !== "undefined"
+9 -9
View File
@@ -30,15 +30,15 @@ export const MessageImageExtension = Image.extend({
return ({ node }) => { return ({ node }) => {
const wrapper = document.createElement("span") const wrapper = document.createElement("span")
wrapper.className = wrapper.className =
"cs-ai-agent-editor-image-wrap relative inline-block max-w-full align-middle" "agent-desk-editor-image-wrap relative inline-block max-w-full align-middle"
const image = document.createElement("img") const image = document.createElement("img")
image.className = "cs-ai-agent-editor-image" image.className = "agent-desk-editor-image"
image.draggable = true image.draggable = true
const overlay = document.createElement("span") const overlay = document.createElement("span")
overlay.className = overlay.className =
"cs-ai-agent-editor-image-loading pointer-events-none absolute inset-0 hidden items-center justify-center rounded-lg bg-background/55 backdrop-blur-[1px]" "agent-desk-editor-image-loading pointer-events-none absolute inset-0 hidden items-center justify-center rounded-lg bg-background/55 backdrop-blur-[1px]"
const spinner = document.createElement("span") const spinner = document.createElement("span")
spinner.className = spinner.className =
@@ -115,10 +115,10 @@ export function markEditorImageUploadedByTitle(
image.setAttribute("data-provider", uploaded.provider) image.setAttribute("data-provider", uploaded.provider)
image.setAttribute("data-storage-key", uploaded.storageKey) image.setAttribute("data-storage-key", uploaded.storageKey)
image.setAttribute("alt", uploaded.filename || image.getAttribute("alt") || "image") image.setAttribute("alt", uploaded.filename || image.getAttribute("alt") || "image")
image.classList.remove("cs-ai-agent-editor-image-uploading") image.classList.remove("agent-desk-editor-image-uploading")
image.removeAttribute("data-uploading") image.removeAttribute("data-uploading")
image.removeAttribute("title") image.removeAttribute("title")
setImageUploading(image.closest(".cs-ai-agent-editor-image-wrap"), false) setImageUploading(image.closest(".agent-desk-editor-image-wrap"), false)
} }
export function setEditorImageUploadingByTitle(editor: Editor, title: string) { export function setEditorImageUploadingByTitle(editor: Editor, title: string) {
@@ -126,9 +126,9 @@ export function setEditorImageUploadingByTitle(editor: Editor, title: string) {
if (!image) { if (!image) {
return return
} }
image.classList.add("cs-ai-agent-editor-image-uploading") image.classList.add("agent-desk-editor-image-uploading")
image.setAttribute("data-uploading", "true") image.setAttribute("data-uploading", "true")
setImageUploading(image.closest(".cs-ai-agent-editor-image-wrap"), true) setImageUploading(image.closest(".agent-desk-editor-image-wrap"), true)
} }
export function buildSendableEditorHTML( export function buildSendableEditorHTML(
@@ -223,8 +223,8 @@ function setImageUploading(wrapper: Element | null, uploading: boolean) {
if (!(wrapper instanceof HTMLElement)) { if (!(wrapper instanceof HTMLElement)) {
return return
} }
wrapper.classList.toggle("cs-ai-agent-editor-image-wrap-uploading", uploading) wrapper.classList.toggle("agent-desk-editor-image-wrap-uploading", uploading)
const overlay = wrapper.querySelector<HTMLElement>(".cs-ai-agent-editor-image-loading") const overlay = wrapper.querySelector<HTMLElement>(".agent-desk-editor-image-loading")
if (overlay) { if (overlay) {
overlay.classList.toggle("hidden", !uploading) overlay.classList.toggle("hidden", !uploading)
overlay.classList.toggle("flex", uploading) overlay.classList.toggle("flex", uploading)
@@ -37,14 +37,14 @@ function createElement(tagName) {
} }
async function loadSdk(config) { async function loadSdk(config) {
const source = await readFile(new URL("./cs-ai-agent-sdk.ts", import.meta.url), "utf8") const source = await readFile(new URL("./agent-desk-sdk.ts", import.meta.url), "utf8")
const compiled = ts.transpileModule(source, { const compiled = ts.transpileModule(source, {
compilerOptions: { compilerOptions: {
target: ts.ScriptTarget.ES2017, target: ts.ScriptTarget.ES2017,
module: ts.ModuleKind.ESNext, module: ts.ModuleKind.ESNext,
importsNotUsedAsValues: ts.ImportsNotUsedAsValues.Remove, importsNotUsedAsValues: ts.ImportsNotUsedAsValues.Remove,
}, },
fileName: "cs-ai-agent-sdk.ts", fileName: "agent-desk-sdk.ts",
}) })
const body = createElement("body") const body = createElement("body")
const sandbox = { const sandbox = {
@@ -62,7 +62,7 @@ async function loadSdk(config) {
document: { document: {
body, body,
currentScript: { currentScript: {
src: "https://chat.example/sdk/cs-ai-agent-sdk.min.js", src: "https://chat.example/sdk/agent-desk-sdk.min.js",
}, },
createElement, createElement,
createElementNS: (_namespace, tagName) => createElement(tagName), createElementNS: (_namespace, tagName) => createElement(tagName),
@@ -57,10 +57,10 @@ function getLauncherText() {
} }
type FrameMessage = type FrameMessage =
| { type: "cs-ai-agent:init"; payload: SupportChatRuntimeConfig } | { type: "agent-desk:init"; payload: SupportChatRuntimeConfig }
| { type: "cs-ai-agent:open" } | { type: "agent-desk:open" }
| { type: "cs-ai-agent:minimize" } | { type: "agent-desk:minimize" }
| { type: "cs-ai-agent:maximized"; payload: { isMaximized: boolean } } | { type: "agent-desk:maximized"; payload: { isMaximized: boolean } }
(function () { (function () {
const DEFAULT_CONFIG: Pick< const DEFAULT_CONFIG: Pick<
@@ -115,7 +115,7 @@ type FrameMessage =
function resolveWidgetBaseUrl(config: NormalizedCSAgentConfig) { function resolveWidgetBaseUrl(config: NormalizedCSAgentConfig) {
const currentScript = document.currentScript as HTMLScriptElement | null const currentScript = document.currentScript as HTMLScriptElement | null
if (currentScript?.src) { if (currentScript?.src) {
return currentScript.src.replace(/\/sdk\/cs-ai-agent-sdk\.min\.js(?:\?.*)?$/, "") return currentScript.src.replace(/\/sdk\/agent-desk-sdk\.min\.js(?:\?.*)?$/, "")
} }
return String(config.widgetBaseUrl || config.baseUrl || window.location.origin).replace(/\/$/, "") return String(config.widgetBaseUrl || config.baseUrl || window.location.origin).replace(/\/$/, "")
} }
@@ -272,7 +272,7 @@ type FrameMessage =
try { try {
state.frame.contentWindow.postMessage(message, state.frameUrl.origin) state.frame.contentWindow.postMessage(message, state.frameUrl.origin)
} catch (error) { } catch (error) {
console.error("[cs-ai-agent-widget] postMessage failed", error) console.error("[agent-desk-widget] postMessage failed", error)
} }
} }
@@ -284,14 +284,14 @@ type FrameMessage =
if (!state.initSent) { if (!state.initSent) {
state.initSent = true state.initSent = true
postToFrame({ postToFrame({
type: "cs-ai-agent:init", type: "agent-desk:init",
payload: state.frameConfig || createFrameConfig(state.config, ""), payload: state.frameConfig || createFrameConfig(state.config, ""),
}) })
} }
postToFrame({ type: state.isOpen ? "cs-ai-agent:open" : "cs-ai-agent:minimize" }) postToFrame({ type: state.isOpen ? "agent-desk:open" : "agent-desk:minimize" })
postToFrame({ postToFrame({
type: "cs-ai-agent:maximized", type: "agent-desk:maximized",
payload: { isMaximized: state.isMaximized }, payload: { isMaximized: state.isMaximized },
}) })
} }
@@ -392,24 +392,24 @@ type FrameMessage =
} }
const data = (event.data || {}) as { type?: string } const data = (event.data || {}) as { type?: string }
if (data.type === "cs-ai-agent:ready") { if (data.type === "agent-desk:ready") {
state.frameReady = true state.frameReady = true
flushFrameState() flushFrameState()
return return
} }
if (data.type === "cs-ai-agent:request-minimize") { if (data.type === "agent-desk:request-minimize") {
state.isOpen = false state.isOpen = false
syncFrameVisibility() syncFrameVisibility()
return return
} }
if (data.type === "cs-ai-agent:request-close") { if (data.type === "agent-desk:request-close") {
destroyFrame() destroyFrame()
return return
} }
if (data.type === "cs-ai-agent:request-toggle-maximize") { if (data.type === "agent-desk:request-toggle-maximize") {
state.isMaximized = !state.isMaximized state.isMaximized = !state.isMaximized
syncFrameVisibility() syncFrameVisibility()
} }
@@ -499,7 +499,7 @@ type FrameMessage =
state.config.baseUrl = widgetBaseUrl state.config.baseUrl = widgetBaseUrl
} }
if (!state.config.channelId) { if (!state.config.channelId) {
console.error("[cs-ai-agent-widget] channelId is required") console.error("[agent-desk-widget] channelId is required")
return return
} }
@@ -548,7 +548,7 @@ type FrameMessage =
syncFrameVisibility() syncFrameVisibility()
}) })
.catch((error) => { .catch((error) => {
console.error("[cs-ai-agent-widget] open failed", error) console.error("[agent-desk-widget] open failed", error)
}) })
} }
+8 -8
View File
@@ -8,14 +8,14 @@ type HostBridgeOptions = {
onMaximizedChange?: (isMaximized: boolean) => void onMaximizedChange?: (isMaximized: boolean) => void
} }
const INIT_MESSAGE_TYPE = "cs-ai-agent:init" const INIT_MESSAGE_TYPE = "agent-desk:init"
const OPEN_MESSAGE_TYPE = "cs-ai-agent:open" const OPEN_MESSAGE_TYPE = "agent-desk:open"
const MINIMIZE_MESSAGE_TYPE = "cs-ai-agent:minimize" const MINIMIZE_MESSAGE_TYPE = "agent-desk:minimize"
const MAXIMIZED_MESSAGE_TYPE = "cs-ai-agent:maximized" const MAXIMIZED_MESSAGE_TYPE = "agent-desk:maximized"
const READY_MESSAGE_TYPE = "cs-ai-agent:ready" const READY_MESSAGE_TYPE = "agent-desk:ready"
const REQUEST_MINIMIZE_MESSAGE_TYPE = "cs-ai-agent:request-minimize" const REQUEST_MINIMIZE_MESSAGE_TYPE = "agent-desk:request-minimize"
const REQUEST_CLOSE_MESSAGE_TYPE = "cs-ai-agent:request-close" const REQUEST_CLOSE_MESSAGE_TYPE = "agent-desk:request-close"
const REQUEST_TOGGLE_MAXIMIZE_MESSAGE_TYPE = "cs-ai-agent:request-toggle-maximize" const REQUEST_TOGGLE_MAXIMIZE_MESSAGE_TYPE = "agent-desk:request-toggle-maximize"
export function bindSupportHostBridge(options: HostBridgeOptions = {}) { export function bindSupportHostBridge(options: HostBridgeOptions = {}) {
if (typeof window === "undefined") { if (typeof window === "undefined") {
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+2 -2
View File
@@ -6,9 +6,9 @@ import ts from "typescript";
const currentDir = path.dirname(fileURLToPath(import.meta.url)); const currentDir = path.dirname(fileURLToPath(import.meta.url));
const rootDir = path.resolve(currentDir, ".."); const rootDir = path.resolve(currentDir, "..");
const source = path.join(rootDir, "lib", "sdk", "cs-ai-agent-sdk.ts"); const source = path.join(rootDir, "lib", "sdk", "agent-desk-sdk.ts");
const targetDir = path.join(rootDir, "public", "sdk"); const targetDir = path.join(rootDir, "public", "sdk");
const target = path.join(targetDir, "cs-ai-agent-sdk.min.js"); const target = path.join(targetDir, "agent-desk-sdk.min.js");
await mkdir(targetDir, { recursive: true }); await mkdir(targetDir, { recursive: true });
const sourceCode = await readFile(source, "utf8"); const sourceCode = await readFile(source, "utf8");
+2 -2
View File
@@ -4,7 +4,7 @@
$thumb: #cbd5e1; $thumb: #cbd5e1;
$thumb-hover: #94a3b8; $thumb-hover: #94a3b8;
.cs-ai-agent-scrollbar { .agent-desk-scrollbar {
scrollbar-width: thin; scrollbar-width: thin;
scrollbar-color: $thumb transparent; scrollbar-color: $thumb transparent;
@@ -29,7 +29,7 @@ $thumb-hover: #94a3b8;
} }
} }
.dark .cs-ai-agent-scrollbar { .dark .agent-desk-scrollbar {
scrollbar-color: hsl(var(--border)) transparent; scrollbar-color: hsl(var(--border)) transparent;
&::-webkit-scrollbar-thumb { &::-webkit-scrollbar-thumb {