@ui-code-agent/capability-pack 0.1.70 → 0.1.72
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS-static.md +100 -15
- package/AGENTS.md +49 -25
- package/SKILL.md +13 -11
- package/package.json +2 -1
- package/specs/auth-recovery.md +20 -1
- package/specs/code-style.md +1 -0
- package/specs/data-area-markers.md +119 -11
- package/specs/data-config-conversation.md +24 -0
- package/specs/data-config-conversion.md +252 -0
- package/specs/data-config-loading.md +66 -0
- package/specs/data-configuration-accepted.md +144 -0
- package/specs/data-configuration-editing.md +44 -0
- package/specs/data-configuration-empty.md +1 -1
- package/specs/data-configuration-revision.md +76 -0
- package/specs/data-configuration.md +128 -187
- package/specs/data-conversion-loading.md +90 -29
- package/specs/data-implementation/contact.md +3 -0
- package/specs/data-implementation/cowork.md +3 -2
- package/specs/data-implementation/document.md +124 -7
- package/specs/data-implementation/group.md +12 -5
- package/specs/data-implementation/list-pagination.md +99 -0
- package/specs/data-implementation/list.md +26 -0
- package/specs/data-implementation/mail-list.md +13 -7
- package/specs/data-implementation/meeting.md +5 -1
- package/specs/data-implementation/official-document.md +3 -0
- package/specs/data-implementation/placard.md +3 -0
- package/specs/data-implementation/stat.md +6 -2
- package/specs/data-implementation/workflow.md +251 -20
- package/specs/data-implementation.md +23 -33
- package/specs/data-integration.md +127 -274
- package/specs/data-plan.template.json +22 -16
- package/specs/data-review.md +236 -0
- package/specs/data-sources.md +10 -7
- package/specs/design-reference.md +1 -1
- package/specs/design-style.md +5 -2
- package/specs/designer-editable.md +219 -0
- package/specs/page-delivery.md +50 -32
- package/specs/page-revision.md +185 -0
- package/specs/portal-page.md +9 -9
- package/specs/portal-references/catalog.md +24 -31
- package/specs/static-first.md +185 -0
- package/specs/xiaoe-html.md +407 -0
- package/static-html/xiaoe-assistant.js +244 -0
- package/specs/portal-references/full-captures/pc-portal-asset-management.png +0 -0
- package/specs/portal-references/full-captures/pc-portal-ecode.png +0 -0
- package/specs/portal-references/full-captures/pc-portal-info-security.png +0 -0
- package/specs/portal-references/full-captures/pc-portal-jingqiaotong.png +0 -0
- package/specs/portal-references/full-captures/pc-portal-jiuchuihui.png +0 -0
- package/specs/portal-references/full-captures/pc-portal-job.png +0 -0
- package/specs/portal-references/full-captures/pc-portal-knowledge.png +0 -0
- package/specs/portal-references/full-captures/pc-portal-marketing.png +0 -0
- package/specs/portal-references/full-captures/pc-portal-organization.png +0 -0
- package/specs/portal-references/full-captures/pc-portal-party-government.png +0 -0
- package/specs/portal-references/full-captures/pc-portal-project.png +0 -0
- package/specs/portal-references/full-captures/pc-portal-sales-report.png +0 -0
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ui-code-agent managed integration. Customize the page, not this file.
|
|
3
|
+
* @typedef {{baseUrl: string, userToken: string}} XiaoeSession
|
|
4
|
+
* @typedef {'loading'|'ready'|'login-required'|'error'|'closed'} XiaoeStatus
|
|
5
|
+
* @typedef {'session.changed'|'message.completed'|'error'} XiaoeEvent
|
|
6
|
+
* @typedef {{ok: boolean, error?: unknown}} CommandResult
|
|
7
|
+
* @typedef {{id: string, name: string, [key: string]: unknown}} Attachment
|
|
8
|
+
* @typedef {{setValue: (text: string) => void, insertTextAtCursor: (text: string) => void, getText: () => string, setFiles: (files: Attachment[]) => void, getFiles: () => Attachment[]}} XiaoeInput
|
|
9
|
+
* @typedef {{send: () => Promise<CommandResult>, stop: () => Promise<CommandResult>}} XiaoeSessionControls
|
|
10
|
+
* @typedef {Record<string, any>} XiaoeClient
|
|
11
|
+
* @typedef {{ready: Promise<void>, client?: XiaoeClient, input: XiaoeInput, session: XiaoeSessionControls, getPlugins: () => object[], invoke: (command: string, payload?: unknown) => Promise<unknown>, on: (event: XiaoeEvent, callback: (payload: any) => void) => () => void, unmount: () => void}} XiaoeHandle
|
|
12
|
+
* @typedef {{mode?: 'basic', locale?: 'zh-CN'|'en-US', messages?: Record<string, string>, theme?: string|object, pcSender?: object, plugins?: object[], components?: object, defaultSenderPlugins?: boolean, defaultSenderPluginOptions?: object, showHeader?: boolean, userInfo?: object, isolation?: object, className?: string, style?: object}} XiaoeOptions
|
|
13
|
+
* @typedef {XiaoeOptions & {onReady?: (client: XiaoeClient) => void, onError?: (error: Error) => void, onConversationChange?: (id: string) => void, onStatus?: (status: XiaoeStatus) => void, getSession?: (options: {signal: AbortSignal}) => Promise<XiaoeSession>, configure?: (context: {runtime: Record<string, any>, signal: AbortSignal}) => XiaoeOptions|Promise<XiaoeOptions>}} AssistantOptions
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
/** @param {string} message @param {string} code */
|
|
17
|
+
function failure(message, code = 'XIAOE_CONNECTION_FAILED') {
|
|
18
|
+
return Object.assign(new Error(message), { code })
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** @param {XiaoeSession} session @returns {XiaoeSession} */
|
|
22
|
+
function validateSession(session) {
|
|
23
|
+
let url
|
|
24
|
+
try {
|
|
25
|
+
url = new URL(session?.baseUrl)
|
|
26
|
+
} catch {
|
|
27
|
+
throw failure('小 e 服务地址格式错误')
|
|
28
|
+
}
|
|
29
|
+
if (!['http:', 'https:'].includes(url.protocol) || url.search || url.hash || url.username || url.password) {
|
|
30
|
+
throw failure('小 e 服务地址格式错误')
|
|
31
|
+
}
|
|
32
|
+
const userToken = typeof session?.userToken === 'string' ? session.userToken.trim() : ''
|
|
33
|
+
if (!userToken) throw failure('当前账号未取得小 e 登录凭证')
|
|
34
|
+
return { baseUrl: url.href.replace(/\/+$/, ''), userToken }
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** Get a fresh connection from the current E10 environment. Never persist credentials.
|
|
38
|
+
* @param {{signal?: AbortSignal}} options
|
|
39
|
+
* @returns {Promise<XiaoeSession>}
|
|
40
|
+
*/
|
|
41
|
+
export async function getXiaoeSession({ signal } = {}) {
|
|
42
|
+
/** @param {string} endpoint @param {object} body */
|
|
43
|
+
async function post(endpoint, body) {
|
|
44
|
+
let response
|
|
45
|
+
try {
|
|
46
|
+
response = await fetch(endpoint, {
|
|
47
|
+
method: 'POST', credentials: 'include', cache: 'no-store', signal,
|
|
48
|
+
headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(body),
|
|
49
|
+
})
|
|
50
|
+
} catch {
|
|
51
|
+
if (signal?.aborted) throw signal.reason
|
|
52
|
+
throw failure('连接失败,请检查网络后重试')
|
|
53
|
+
}
|
|
54
|
+
if (response.status === 401) throw failure('请先登录当前 E10 环境后重试', 'XIAOE_LOGIN_REQUIRED')
|
|
55
|
+
if (!response.ok) throw failure('获取小 e 连接失败,请稍后重试')
|
|
56
|
+
let result
|
|
57
|
+
try { result = await response.json() } catch { throw failure('小 e 连接响应格式异常') }
|
|
58
|
+
if (result?.status !== true) throw failure('获取小 e 连接失败,请检查当前账号配置')
|
|
59
|
+
return result.data
|
|
60
|
+
}
|
|
61
|
+
const [config, userToken] = await Promise.all([
|
|
62
|
+
post('/api/ai/application/setting/getAiAuthConfig', { modelType: 99 }),
|
|
63
|
+
post('/api/ai/application/chat/generateUserToken', {}),
|
|
64
|
+
])
|
|
65
|
+
return validateSession({ baseUrl: config?.chatApi, userToken })
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** @typedef {{load: (baseUrl: string) => Promise<Record<string, any>>, mount: (target: HTMLElement, options: XiaoeOptions & XiaoeSession & {renderMode: string, onError: () => void, onConversationChange: (id: string) => void}) => XiaoeHandle}} HtmlSdk */
|
|
69
|
+
const sdkWindow = /** @type {Window & typeof globalThis & {XiaoeSDK?: HtmlSdk}} */ (window)
|
|
70
|
+
/** @type {Promise<HtmlSdk>|undefined} */
|
|
71
|
+
let sdkLoading
|
|
72
|
+
let loadedBaseUrl = ''
|
|
73
|
+
/** @type {{close: () => void}|undefined} */
|
|
74
|
+
let active
|
|
75
|
+
|
|
76
|
+
/** @param {string} baseUrl @returns {Promise<HtmlSdk>} */
|
|
77
|
+
function loadSdk(baseUrl) {
|
|
78
|
+
if (loadedBaseUrl && loadedBaseUrl !== baseUrl) {
|
|
79
|
+
return Promise.reject(failure('切换小 e 服务后请重新加载页面'))
|
|
80
|
+
}
|
|
81
|
+
if (!sdkLoading) {
|
|
82
|
+
if (sdkWindow.XiaoeSDK) return Promise.reject(failure('请移除重复加载的小 e SDK 脚本后刷新页面'))
|
|
83
|
+
loadedBaseUrl = baseUrl
|
|
84
|
+
sdkLoading = new Promise((resolve, reject) => {
|
|
85
|
+
const script = document.createElement('script')
|
|
86
|
+
const timer = setTimeout(() => finish(failure('小 e SDK 加载超时,请重试')), 30000)
|
|
87
|
+
/** @param {Error} [error] */
|
|
88
|
+
function finish(error) {
|
|
89
|
+
clearTimeout(timer)
|
|
90
|
+
script.onload = script.onerror = null
|
|
91
|
+
if (error) { script.remove(); reject(error) }
|
|
92
|
+
else if (sdkWindow.XiaoeSDK?.mount) resolve(sdkWindow.XiaoeSDK)
|
|
93
|
+
else { script.remove(); reject(failure('小 e SDK 入口不可用')) }
|
|
94
|
+
}
|
|
95
|
+
// Keep the external SDK URL out of the publisher's static resource rewriting.
|
|
96
|
+
script.src = [baseUrl, 'app-chat', 'sdk', 'xiaoe-sdk'].join('/') + '.js'
|
|
97
|
+
script.onload = () => finish()
|
|
98
|
+
script.onerror = () => finish(failure('小 e SDK 加载失败,请重试'))
|
|
99
|
+
document.head.appendChild(script)
|
|
100
|
+
}).catch(error => { sdkLoading = undefined; throw error })
|
|
101
|
+
}
|
|
102
|
+
return sdkLoading
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/** @template T @param {Promise<T>} promise @param {AbortSignal} signal @returns {Promise<T>} */
|
|
106
|
+
function cancellable(promise, signal) {
|
|
107
|
+
return new Promise((resolve, reject) => {
|
|
108
|
+
const cancel = () => reject(signal.reason)
|
|
109
|
+
if (signal.aborted) { promise.catch(() => {}); reject(signal.reason); return }
|
|
110
|
+
signal.addEventListener('abort', cancel, { once: true })
|
|
111
|
+
promise.then(resolve, reject).finally(() => signal.removeEventListener('abort', cancel))
|
|
112
|
+
})
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/** @param {HTMLElement} container @param {AssistantOptions} options */
|
|
116
|
+
export function createXiaoeAssistant(container, options = {}) {
|
|
117
|
+
if (!(container instanceof HTMLElement)) throw failure('请提供小 e 容器元素')
|
|
118
|
+
const sdkKeys = ['mode', 'locale', 'messages', 'theme', 'pcSender', 'plugins', 'components', 'defaultSenderPlugins', 'defaultSenderPluginOptions', 'showHeader', 'userInfo', 'isolation', 'className', 'style']
|
|
119
|
+
const allowed = new Set([...sdkKeys, 'onReady', 'onError', 'onConversationChange', 'onStatus', 'getSession', 'configure'])
|
|
120
|
+
if (Object.keys(options).some(key => !allowed.has(key))) throw failure('存在未支持的小 e HTML 配置,请查阅接入手册')
|
|
121
|
+
const { onStatus, getSession = getXiaoeSession, configure, onReady, onError, onConversationChange, ...sdkOptions } = options
|
|
122
|
+
/** @type {AbortController|undefined} */
|
|
123
|
+
let attempt
|
|
124
|
+
/** @type {XiaoeHandle|undefined} */
|
|
125
|
+
let handle
|
|
126
|
+
let ready = false
|
|
127
|
+
let closed = false
|
|
128
|
+
/** @type {Set<() => void>} */
|
|
129
|
+
const subscriptions = new Set()
|
|
130
|
+
/** @param {XiaoeStatus} status */
|
|
131
|
+
const status = status => onStatus?.(status)
|
|
132
|
+
function cleanup() {
|
|
133
|
+
ready = false
|
|
134
|
+
attempt?.abort(new DOMException('已关闭小 e', 'AbortError'))
|
|
135
|
+
attempt = undefined
|
|
136
|
+
for (const off of subscriptions) off()
|
|
137
|
+
subscriptions.clear()
|
|
138
|
+
handle?.unmount()
|
|
139
|
+
handle = undefined
|
|
140
|
+
if (active === assistant) active = undefined
|
|
141
|
+
}
|
|
142
|
+
function currentHandle() {
|
|
143
|
+
if (!ready || !handle) throw failure('请先打开小 e 并等待就绪', closed ? 'XIAOE_SDK_UNMOUNTED' : 'XIAOE_SDK_NOT_READY')
|
|
144
|
+
return handle
|
|
145
|
+
}
|
|
146
|
+
/** Bind operations to this mount so saved controls cannot operate a replacement instance. */
|
|
147
|
+
function controls() {
|
|
148
|
+
const expected = currentHandle()
|
|
149
|
+
return () => {
|
|
150
|
+
if (handle !== expected) throw failure('小 e 实例已关闭', 'XIAOE_SDK_UNMOUNTED')
|
|
151
|
+
return currentHandle()
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
const assistant = {
|
|
155
|
+
get client() { return ready ? handle?.client : undefined },
|
|
156
|
+
get input() {
|
|
157
|
+
const get = controls()
|
|
158
|
+
return {
|
|
159
|
+
/** @param {string} text */
|
|
160
|
+
setValue: text => get().input.setValue(text),
|
|
161
|
+
/** @param {string} text */
|
|
162
|
+
insertTextAtCursor: text => get().input.insertTextAtCursor(text),
|
|
163
|
+
getText: () => get().input.getText(),
|
|
164
|
+
/** @param {Attachment[]} files */
|
|
165
|
+
setFiles: files => get().input.setFiles(files),
|
|
166
|
+
getFiles: () => get().input.getFiles(),
|
|
167
|
+
}
|
|
168
|
+
},
|
|
169
|
+
get session() {
|
|
170
|
+
const get = controls()
|
|
171
|
+
return { send: async () => get().session.send(), stop: async () => get().session.stop() }
|
|
172
|
+
},
|
|
173
|
+
getPlugins() { return ready ? handle.getPlugins() : [] },
|
|
174
|
+
/** @param {string} command @param {unknown} [payload] */
|
|
175
|
+
async invoke(command, payload) { return currentHandle().invoke(command, payload) },
|
|
176
|
+
/** @param {XiaoeEvent} event @param {(payload: any) => void} callback */
|
|
177
|
+
on(event, callback) {
|
|
178
|
+
const expected = currentHandle()
|
|
179
|
+
const unsubscribe = expected.on(event, payload => {
|
|
180
|
+
if (handle === expected && ready) callback(payload)
|
|
181
|
+
})
|
|
182
|
+
const off = () => { unsubscribe(); subscriptions.delete(off) }
|
|
183
|
+
subscriptions.add(off)
|
|
184
|
+
return off
|
|
185
|
+
},
|
|
186
|
+
async open() {
|
|
187
|
+
if (active && active !== assistant) active.close()
|
|
188
|
+
cleanup()
|
|
189
|
+
closed = false
|
|
190
|
+
active = assistant
|
|
191
|
+
const current = new AbortController()
|
|
192
|
+
attempt = current
|
|
193
|
+
let failed = false
|
|
194
|
+
const timer = setTimeout(() => current.abort(failure('小 e 初始化超时,请重试')), 60000)
|
|
195
|
+
status('loading')
|
|
196
|
+
try {
|
|
197
|
+
if (!container.isConnected || !container.getClientRects().length || container.clientHeight <= 0) {
|
|
198
|
+
throw failure('请先显示小 e 容器并设置高度')
|
|
199
|
+
}
|
|
200
|
+
const session = validateSession(await cancellable(getSession({ signal: current.signal }), current.signal))
|
|
201
|
+
const sdk = await cancellable(loadSdk(session.baseUrl), current.signal)
|
|
202
|
+
let configured = {}
|
|
203
|
+
if (configure) {
|
|
204
|
+
const runtime = await cancellable(sdk.load(session.baseUrl), current.signal)
|
|
205
|
+
if (attempt !== current) return false
|
|
206
|
+
configured = await cancellable(Promise.resolve(configure({ runtime, signal: current.signal })), current.signal)
|
|
207
|
+
if (!configured || typeof configured !== 'object' || Array.isArray(configured) || Object.keys(configured).some(key => !sdkKeys.includes(key))) {
|
|
208
|
+
throw failure('configure 只能返回小 e 公开配置')
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
if (attempt !== current) return false
|
|
212
|
+
handle = sdk.mount(container, {
|
|
213
|
+
...sdkOptions, ...configured, ...session, renderMode: 'shadow-root',
|
|
214
|
+
onError() {
|
|
215
|
+
if (attempt !== current) return
|
|
216
|
+
failed = true
|
|
217
|
+
ready = false
|
|
218
|
+
status('error')
|
|
219
|
+
onError?.(failure('小 e 连接失败,请重试'))
|
|
220
|
+
},
|
|
221
|
+
onConversationChange(id) { if (attempt === current) onConversationChange?.(id) },
|
|
222
|
+
})
|
|
223
|
+
await cancellable(handle.ready, current.signal)
|
|
224
|
+
if (attempt !== current || failed) return false
|
|
225
|
+
ready = true
|
|
226
|
+
status('ready')
|
|
227
|
+
if (attempt !== current) return false
|
|
228
|
+
onReady?.(handle.client)
|
|
229
|
+
return attempt === current
|
|
230
|
+
} catch (error) {
|
|
231
|
+
if (attempt !== current) return false
|
|
232
|
+
cleanup()
|
|
233
|
+
const login = error?.code === 'XIAOE_LOGIN_REQUIRED'
|
|
234
|
+
status(login ? 'login-required' : 'error')
|
|
235
|
+
if (!failed) onError?.(failure(login ? '请先登录当前 E10 环境后重试' : '小 e 连接失败,请重试', login ? 'XIAOE_LOGIN_REQUIRED' : 'XIAOE_CONNECTION_FAILED'))
|
|
236
|
+
return false
|
|
237
|
+
} finally { clearTimeout(timer) }
|
|
238
|
+
},
|
|
239
|
+
close() { closed = true; cleanup(); status('closed') },
|
|
240
|
+
}
|
|
241
|
+
return assistant
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
window.addEventListener('pagehide', () => active?.close())
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|