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:
+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") {
|
||||
|
||||
Reference in New Issue
Block a user