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:
@@ -744,7 +744,7 @@ function WebAccessGuide({ channelId }: { channelId: string }) {
|
||||
channelId: "${channelId}"
|
||||
};
|
||||
</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])
|
||||
|
||||
async function copyText(text: string, successMessage: string) {
|
||||
|
||||
@@ -350,7 +350,7 @@ export function ChatPanel() {
|
||||
const messagesScroll = (
|
||||
<div
|
||||
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">
|
||||
{!loading && messages.length > 0 && messagesHasMore ? (
|
||||
|
||||
@@ -446,9 +446,9 @@ export function SharedMessageEditor({
|
||||
|
||||
function getEditorClassName(variant: SharedMessageEditorVariant) {
|
||||
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) {
|
||||
|
||||
@@ -219,7 +219,7 @@ export const SupportChatMessageList = forwardRef<SupportChatMessageListHandle, S
|
||||
return (
|
||||
<div
|
||||
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">
|
||||
{hasMoreOlder && onLoadOlder ? (
|
||||
|
||||
@@ -7,7 +7,7 @@ import { useEffect, useMemo, useState } from "react"
|
||||
import type { CSAgentConfig } from "@/lib/sdk/config-types"
|
||||
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 INITIAL_CONFIG: CSAgentConfig = {
|
||||
channelId: "",
|
||||
@@ -56,7 +56,7 @@ function removeMountedWidget() {
|
||||
window.CSAgentWidget?.destroy()
|
||||
document
|
||||
.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())
|
||||
|
||||
@@ -72,7 +72,7 @@ function injectWidget(config: CSAgentConfig) {
|
||||
|
||||
const script = document.createElement("script")
|
||||
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"
|
||||
document.body.appendChild(script)
|
||||
}
|
||||
@@ -187,8 +187,8 @@ export function SupportWidgetDemo() {
|
||||
|
||||
const snippet = useMemo(() => {
|
||||
const scriptSrc = origin
|
||||
? `${origin}/sdk/cs-ai-agent-sdk.min.js`
|
||||
: "/sdk/cs-ai-agent-sdk.min.js"
|
||||
? `${origin}/sdk/agent-desk-sdk.min.js`
|
||||
: "/sdk/agent-desk-sdk.min.js"
|
||||
|
||||
const configLines = [` channelId: "${config.channelId || ""}"`]
|
||||
if (config.authMode === "jwt") {
|
||||
|
||||
+2
-2
@@ -15,8 +15,8 @@ export type AuthSession = {
|
||||
roles: string[]
|
||||
}
|
||||
|
||||
const SESSION_STORAGE_KEY = "cs-ai-agent-session"
|
||||
export const AUTH_SESSION_EXPIRED_EVENT = "cs-ai-agent-auth-expired"
|
||||
const SESSION_STORAGE_KEY = "agent-desk-session"
|
||||
export const AUTH_SESSION_EXPIRED_EVENT = "agent-desk-auth-expired"
|
||||
|
||||
function hasWindow() {
|
||||
return typeof window !== "undefined"
|
||||
|
||||
@@ -30,15 +30,15 @@ export const MessageImageExtension = Image.extend({
|
||||
return ({ node }) => {
|
||||
const wrapper = document.createElement("span")
|
||||
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")
|
||||
image.className = "cs-ai-agent-editor-image"
|
||||
image.className = "agent-desk-editor-image"
|
||||
image.draggable = true
|
||||
|
||||
const overlay = document.createElement("span")
|
||||
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")
|
||||
spinner.className =
|
||||
@@ -115,10 +115,10 @@ export function markEditorImageUploadedByTitle(
|
||||
image.setAttribute("data-provider", uploaded.provider)
|
||||
image.setAttribute("data-storage-key", uploaded.storageKey)
|
||||
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("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) {
|
||||
@@ -126,9 +126,9 @@ export function setEditorImageUploadingByTitle(editor: Editor, title: string) {
|
||||
if (!image) {
|
||||
return
|
||||
}
|
||||
image.classList.add("cs-ai-agent-editor-image-uploading")
|
||||
image.classList.add("agent-desk-editor-image-uploading")
|
||||
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(
|
||||
@@ -223,8 +223,8 @@ function setImageUploading(wrapper: Element | null, uploading: boolean) {
|
||||
if (!(wrapper instanceof HTMLElement)) {
|
||||
return
|
||||
}
|
||||
wrapper.classList.toggle("cs-ai-agent-editor-image-wrap-uploading", uploading)
|
||||
const overlay = wrapper.querySelector<HTMLElement>(".cs-ai-agent-editor-image-loading")
|
||||
wrapper.classList.toggle("agent-desk-editor-image-wrap-uploading", uploading)
|
||||
const overlay = wrapper.querySelector<HTMLElement>(".agent-desk-editor-image-loading")
|
||||
if (overlay) {
|
||||
overlay.classList.toggle("hidden", !uploading)
|
||||
overlay.classList.toggle("flex", uploading)
|
||||
|
||||
@@ -37,14 +37,14 @@ function createElement(tagName) {
|
||||
}
|
||||
|
||||
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, {
|
||||
compilerOptions: {
|
||||
target: ts.ScriptTarget.ES2017,
|
||||
module: ts.ModuleKind.ESNext,
|
||||
importsNotUsedAsValues: ts.ImportsNotUsedAsValues.Remove,
|
||||
},
|
||||
fileName: "cs-ai-agent-sdk.ts",
|
||||
fileName: "agent-desk-sdk.ts",
|
||||
})
|
||||
const body = createElement("body")
|
||||
const sandbox = {
|
||||
@@ -62,7 +62,7 @@ async function loadSdk(config) {
|
||||
document: {
|
||||
body,
|
||||
currentScript: {
|
||||
src: "https://chat.example/sdk/cs-ai-agent-sdk.min.js",
|
||||
src: "https://chat.example/sdk/agent-desk-sdk.min.js",
|
||||
},
|
||||
createElement,
|
||||
createElementNS: (_namespace, tagName) => createElement(tagName),
|
||||
@@ -57,10 +57,10 @@ function getLauncherText() {
|
||||
}
|
||||
|
||||
type FrameMessage =
|
||||
| { type: "cs-ai-agent:init"; payload: SupportChatRuntimeConfig }
|
||||
| { type: "cs-ai-agent:open" }
|
||||
| { type: "cs-ai-agent:minimize" }
|
||||
| { type: "cs-ai-agent:maximized"; payload: { isMaximized: boolean } }
|
||||
| { type: "agent-desk:init"; payload: SupportChatRuntimeConfig }
|
||||
| { type: "agent-desk:open" }
|
||||
| { type: "agent-desk:minimize" }
|
||||
| { type: "agent-desk:maximized"; payload: { isMaximized: boolean } }
|
||||
|
||||
(function () {
|
||||
const DEFAULT_CONFIG: Pick<
|
||||
@@ -115,7 +115,7 @@ type FrameMessage =
|
||||
function resolveWidgetBaseUrl(config: NormalizedCSAgentConfig) {
|
||||
const currentScript = document.currentScript as HTMLScriptElement | null
|
||||
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(/\/$/, "")
|
||||
}
|
||||
@@ -272,7 +272,7 @@ type FrameMessage =
|
||||
try {
|
||||
state.frame.contentWindow.postMessage(message, state.frameUrl.origin)
|
||||
} 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) {
|
||||
state.initSent = true
|
||||
postToFrame({
|
||||
type: "cs-ai-agent:init",
|
||||
type: "agent-desk:init",
|
||||
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({
|
||||
type: "cs-ai-agent:maximized",
|
||||
type: "agent-desk:maximized",
|
||||
payload: { isMaximized: state.isMaximized },
|
||||
})
|
||||
}
|
||||
@@ -392,24 +392,24 @@ type FrameMessage =
|
||||
}
|
||||
|
||||
const data = (event.data || {}) as { type?: string }
|
||||
if (data.type === "cs-ai-agent:ready") {
|
||||
if (data.type === "agent-desk:ready") {
|
||||
state.frameReady = true
|
||||
flushFrameState()
|
||||
return
|
||||
}
|
||||
|
||||
if (data.type === "cs-ai-agent:request-minimize") {
|
||||
if (data.type === "agent-desk:request-minimize") {
|
||||
state.isOpen = false
|
||||
syncFrameVisibility()
|
||||
return
|
||||
}
|
||||
|
||||
if (data.type === "cs-ai-agent:request-close") {
|
||||
if (data.type === "agent-desk:request-close") {
|
||||
destroyFrame()
|
||||
return
|
||||
}
|
||||
|
||||
if (data.type === "cs-ai-agent:request-toggle-maximize") {
|
||||
if (data.type === "agent-desk:request-toggle-maximize") {
|
||||
state.isMaximized = !state.isMaximized
|
||||
syncFrameVisibility()
|
||||
}
|
||||
@@ -499,7 +499,7 @@ type FrameMessage =
|
||||
state.config.baseUrl = widgetBaseUrl
|
||||
}
|
||||
if (!state.config.channelId) {
|
||||
console.error("[cs-ai-agent-widget] channelId is required")
|
||||
console.error("[agent-desk-widget] channelId is required")
|
||||
return
|
||||
}
|
||||
|
||||
@@ -548,7 +548,7 @@ type FrameMessage =
|
||||
syncFrameVisibility()
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error("[cs-ai-agent-widget] open failed", error)
|
||||
console.error("[agent-desk-widget] open failed", error)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -8,14 +8,14 @@ type HostBridgeOptions = {
|
||||
onMaximizedChange?: (isMaximized: boolean) => void
|
||||
}
|
||||
|
||||
const INIT_MESSAGE_TYPE = "cs-ai-agent:init"
|
||||
const OPEN_MESSAGE_TYPE = "cs-ai-agent:open"
|
||||
const MINIMIZE_MESSAGE_TYPE = "cs-ai-agent:minimize"
|
||||
const MAXIMIZED_MESSAGE_TYPE = "cs-ai-agent:maximized"
|
||||
const READY_MESSAGE_TYPE = "cs-ai-agent:ready"
|
||||
const REQUEST_MINIMIZE_MESSAGE_TYPE = "cs-ai-agent:request-minimize"
|
||||
const REQUEST_CLOSE_MESSAGE_TYPE = "cs-ai-agent:request-close"
|
||||
const REQUEST_TOGGLE_MAXIMIZE_MESSAGE_TYPE = "cs-ai-agent:request-toggle-maximize"
|
||||
const INIT_MESSAGE_TYPE = "agent-desk:init"
|
||||
const OPEN_MESSAGE_TYPE = "agent-desk:open"
|
||||
const MINIMIZE_MESSAGE_TYPE = "agent-desk:minimize"
|
||||
const MAXIMIZED_MESSAGE_TYPE = "agent-desk:maximized"
|
||||
const READY_MESSAGE_TYPE = "agent-desk:ready"
|
||||
const REQUEST_MINIMIZE_MESSAGE_TYPE = "agent-desk:request-minimize"
|
||||
const REQUEST_CLOSE_MESSAGE_TYPE = "agent-desk:request-close"
|
||||
const REQUEST_TOGGLE_MAXIMIZE_MESSAGE_TYPE = "agent-desk:request-toggle-maximize"
|
||||
|
||||
export function bindSupportHostBridge(options: HostBridgeOptions = {}) {
|
||||
if (typeof window === "undefined") {
|
||||
|
||||
Vendored
+1
File diff suppressed because one or more lines are too long
-1
File diff suppressed because one or more lines are too long
@@ -6,9 +6,9 @@ import ts from "typescript";
|
||||
|
||||
const currentDir = path.dirname(fileURLToPath(import.meta.url));
|
||||
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 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 });
|
||||
const sourceCode = await readFile(source, "utf8");
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
$thumb: #cbd5e1;
|
||||
$thumb-hover: #94a3b8;
|
||||
|
||||
.cs-ai-agent-scrollbar {
|
||||
.agent-desk-scrollbar {
|
||||
scrollbar-width: thin;
|
||||
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;
|
||||
|
||||
&::-webkit-scrollbar-thumb {
|
||||
|
||||
Reference in New Issue
Block a user