refactor: 项目更名 WeKnora → Academy
Build & Publish (dsh-academy) / End-to-end inside dsh (latest, advisory) (push) Skipped
CLI / test (macos-latest / go 1.26) (push) Canceled after 0s
CLI / test (ubuntu-latest / go 1.26) (push) Canceled after 0s
CLI / test (windows-latest / go 1.26) (push) Canceled after 0s
Build and Push Docker Image / build-ui (push) Canceled after 0s
Build and Push Docker Image / build-docreader (push) Canceled after 0s
Build and Push Docker Image / build-sandbox (push) Canceled after 0s
Build and Push Docker Image / build-app (amd64, linux/amd64, ubuntu-latest) (push) Canceled after 0s
Build and Push Docker Image / build-app (arm64, linux/arm64, ubuntu-24.04-arm) (push) Canceled after 0s
Build and Push Docker Image / merge (push) Canceled after 0s
Frontend / Test, type-check, and build (push) Canceled after 0s
Frontend / Docker multi-stage image (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.10) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.11) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.12) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.13) (push) Canceled after 0s
Build & Publish (mcp-server) / Build sdist + wheel (push) Canceled after 0s
Build & Publish (mcp-server) / Publish to PyPI (push) Canceled after 0s
Anydoc / anydoc parser engine (push) Canceled after 0s
App / Format, vet, test, and build (push) Canceled after 0s
DocReader / Python tests and Go client tests (push) Canceled after 0s
Build & Publish (dsh-academy) / Typecheck, test, pack (push) Canceled after 0s
Build & Publish (dsh-academy) / End-to-end inside dsh (pinned) (push) Canceled after 0s
Build & Publish (dsh-academy) / Publish to npm (push) Canceled after 0s
Go Lint Cache / warm lint cache (.) (push) Canceled after 0s
Go Lint Cache / warm lint cache (cli) (push) Canceled after 0s
Go Lint Cache / warm lint cache (client) (push) Canceled after 0s
Helm / chart (push) Canceled after 0s
Build & Publish (dsh-academy) / End-to-end inside dsh (latest, advisory) (push) Skipped
CLI / test (macos-latest / go 1.26) (push) Canceled after 0s
CLI / test (ubuntu-latest / go 1.26) (push) Canceled after 0s
CLI / test (windows-latest / go 1.26) (push) Canceled after 0s
Build and Push Docker Image / build-ui (push) Canceled after 0s
Build and Push Docker Image / build-docreader (push) Canceled after 0s
Build and Push Docker Image / build-sandbox (push) Canceled after 0s
Build and Push Docker Image / build-app (amd64, linux/amd64, ubuntu-latest) (push) Canceled after 0s
Build and Push Docker Image / build-app (arm64, linux/arm64, ubuntu-24.04-arm) (push) Canceled after 0s
Build and Push Docker Image / merge (push) Canceled after 0s
Frontend / Test, type-check, and build (push) Canceled after 0s
Frontend / Docker multi-stage image (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.10) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.11) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.12) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.13) (push) Canceled after 0s
Build & Publish (mcp-server) / Build sdist + wheel (push) Canceled after 0s
Build & Publish (mcp-server) / Publish to PyPI (push) Canceled after 0s
Anydoc / anydoc parser engine (push) Canceled after 0s
App / Format, vet, test, and build (push) Canceled after 0s
DocReader / Python tests and Go client tests (push) Canceled after 0s
Build & Publish (dsh-academy) / Typecheck, test, pack (push) Canceled after 0s
Build & Publish (dsh-academy) / End-to-end inside dsh (pinned) (push) Canceled after 0s
Build & Publish (dsh-academy) / Publish to npm (push) Canceled after 0s
Go Lint Cache / warm lint cache (.) (push) Canceled after 0s
Go Lint Cache / warm lint cache (cli) (push) Canceled after 0s
Go Lint Cache / warm lint cache (client) (push) Canceled after 0s
Helm / chart (push) Canceled after 0s
- 全量替换代码/配置/文档中的项目名(保留上游 GitHub 链接、weixin 文档域名、Docker Hub 镜像名) - 重命名 32 个含项目名的文件/目录;Go module 路径改为 academy(含 client/cli 子模块) - docreader proto 描述符采用等长替换,保持序列化字节布局有效 - Dockerfile.app 构建网络修复: browserskill 离线产物通道、PyPI/apt 国内镜像 - 运行验证: go build ✓ docker compose up ✓ 健康检查 ✓
This commit is contained in:
1 parent
9097ee699d
commit
9058149576
3136 files changed
+18018
-18004
No files matched your search
@@ -1,7 +1,7 @@
|
||||
import type { ModelConfig } from '@/api/model'
|
||||
|
||||
export const WEKNORA_CLOUD_BASE_URL = 'https://weknora.weixin.qq.com'
|
||||
export const WEKNORA_CLOUD_PROVIDER = 'weknoracloud'
|
||||
export const ACADEMY_CLOUD_BASE_URL = 'https://weknora.weixin.qq.com'
|
||||
export const ACADEMY_CLOUD_PROVIDER = 'academycloud'
|
||||
|
||||
export type WkcModelKind = 'chat' | 'embedding' | 'rerank' | 'vllm'
|
||||
|
||||
@@ -21,15 +21,15 @@ export const WKC_MODEL_NAME_BY_KIND: Record<WkcModelKind, string> = {
|
||||
|
||||
export const WKC_MODEL_KINDS: WkcModelKind[] = ['chat', 'embedding', 'rerank', 'vllm']
|
||||
|
||||
export function isWeKnoraCloudModel(model: ModelConfig): boolean {
|
||||
return model.parameters?.provider === WEKNORA_CLOUD_PROVIDER
|
||||
export function isAcademyCloudModel(model: ModelConfig): boolean {
|
||||
return model.parameters?.provider === ACADEMY_CLOUD_PROVIDER
|
||||
}
|
||||
|
||||
/** Returns kinds that already have a WeKnoraCloud model of the matching backend type. */
|
||||
/** Returns kinds that already have a AcademyCloud model of the matching backend type. */
|
||||
export function existingWkcKinds(models: ModelConfig[]): Set<WkcModelKind> {
|
||||
const found = new Set<WkcModelKind>()
|
||||
for (const model of models) {
|
||||
if (!isWeKnoraCloudModel(model)) continue
|
||||
if (!isAcademyCloudModel(model)) continue
|
||||
for (const kind of WKC_MODEL_KINDS) {
|
||||
if (model.type === BACKEND_TYPE_BY_KIND[kind]) {
|
||||
found.add(kind)
|
||||
@@ -47,8 +47,8 @@ export function buildWkcModelConfig(
|
||||
const name = WKC_MODEL_NAME_BY_KIND[kind]
|
||||
const type = BACKEND_TYPE_BY_KIND[kind]
|
||||
const parameters: ModelConfig['parameters'] = {
|
||||
base_url: WEKNORA_CLOUD_BASE_URL,
|
||||
provider: WEKNORA_CLOUD_PROVIDER,
|
||||
base_url: ACADEMY_CLOUD_BASE_URL,
|
||||
provider: ACADEMY_CLOUD_PROVIDER,
|
||||
}
|
||||
|
||||
if (kind === 'embedding' && dimension) {
|
||||
@@ -0,0 +1,62 @@
|
||||
import assert from 'node:assert/strict'
|
||||
import test from 'node:test'
|
||||
|
||||
import { marked } from 'marked'
|
||||
|
||||
import { renderChatMarkdown } from './chatMarkdownRenderer.ts'
|
||||
import { parseAcademyEntityURI, renderAcademyEntityLinks } from './academyEntityLinks.ts'
|
||||
|
||||
const LABELS = { kb: '知识库', doc: '文档', chunk: '片段' }
|
||||
const KB_ID = 'kb-0001'
|
||||
const DOC_ID = '00000001-0000-4000-8000-000000000001'
|
||||
|
||||
test('parseAcademyEntityURI accepts only whole durable URIs', () => {
|
||||
assert.deepEqual(parseAcademyEntityURI(`academy://kb/${KB_ID}`), { kind: 'kb', id: KB_ID })
|
||||
assert.deepEqual(parseAcademyEntityURI(`Academy://DOC/${DOC_ID}`), { kind: 'doc', id: DOC_ID })
|
||||
assert.equal(parseAcademyEntityURI('academy://kb/'), null)
|
||||
assert.equal(parseAcademyEntityURI('academy://user/1'), null)
|
||||
assert.equal(parseAcademyEntityURI(`see academy://kb/${KB_ID}`), null)
|
||||
assert.equal(parseAcademyEntityURI('javascript:alert(1)'), null)
|
||||
})
|
||||
|
||||
test('markdown links to academy URIs keep their text and become entity links', () => {
|
||||
const html = renderAcademyEntityLinks(
|
||||
`<p>存入 <a href="academy://kb/${KB_ID}">每日热榜</a> 即可</p>`,
|
||||
LABELS,
|
||||
)
|
||||
assert.equal(
|
||||
html,
|
||||
'<p>存入 <span class="academy-entity-link" role="link" tabindex="0" title="知识库" ' +
|
||||
`data-entity-kind="kb" data-entity-id="${KB_ID}">每日热榜</span> 即可</p>`,
|
||||
)
|
||||
})
|
||||
|
||||
test('bare academy URIs in prose show the real ID with the kind as tooltip', () => {
|
||||
const html = renderAcademyEntityLinks(`<p>参考 academy://doc/${DOC_ID}。</p>`, LABELS)
|
||||
assert.match(html, new RegExp(`title="文档" data-entity-kind="doc" data-entity-id="${DOC_ID}">${DOC_ID}</span>。`))
|
||||
assert.doesNotMatch(html, /academy:\/\//)
|
||||
})
|
||||
|
||||
test('academy URIs inside code, pre and ordinary links are left alone', () => {
|
||||
const input =
|
||||
`<p><code>academy://kb/${KB_ID}</code></p>` +
|
||||
`<pre><code>academy://kb/${KB_ID}</code></pre>` +
|
||||
`<p><a href="https://example.com">academy://kb/${KB_ID}</a></p>`
|
||||
assert.equal(renderAcademyEntityLinks(input, LABELS), input)
|
||||
})
|
||||
|
||||
test('renderChatMarkdown renders academy links only when labels are supplied', () => {
|
||||
const markdown = `把结果写入 [热榜知识库](academy://kb/${KB_ID}),并参考 academy://doc/${DOC_ID}`
|
||||
const options = {
|
||||
renderer: new marked.Renderer(),
|
||||
escapeMarkdown: (text: string) => text,
|
||||
sanitizeHtml: (html: string) => html,
|
||||
}
|
||||
const plain = renderChatMarkdown(markdown, options)
|
||||
assert.doesNotMatch(plain, /academy-entity-link/)
|
||||
|
||||
const linked = renderChatMarkdown(markdown, { ...options, entityLinkLabels: LABELS })
|
||||
assert.match(linked, new RegExp(`data-entity-kind="kb" data-entity-id="${KB_ID}">热榜知识库</span>`))
|
||||
assert.match(linked, new RegExp(`data-entity-kind="doc" data-entity-id="${DOC_ID}">${DOC_ID}</span>`))
|
||||
assert.doesNotMatch(linked, /href="academy:/)
|
||||
})
|
||||
+18
-18
@@ -1,45 +1,45 @@
|
||||
export type WeKnoraEntityKind = 'kb' | 'doc' | 'chunk'
|
||||
export type AcademyEntityKind = 'kb' | 'doc' | 'chunk'
|
||||
|
||||
export interface WeKnoraEntityRef {
|
||||
kind: WeKnoraEntityKind
|
||||
export interface AcademyEntityRef {
|
||||
kind: AcademyEntityKind
|
||||
id: string
|
||||
}
|
||||
|
||||
export type WeKnoraEntityLinkLabels = Record<WeKnoraEntityKind, string>
|
||||
export type AcademyEntityLinkLabels = Record<AcademyEntityKind, string>
|
||||
|
||||
export const WEKNORA_ENTITY_LINK_CLASS = 'weknora-entity-link'
|
||||
export const ACADEMY_ENTITY_LINK_CLASS = 'academy-entity-link'
|
||||
|
||||
const URI_BODY = '(kb|doc|chunk)/([0-9A-Za-z][0-9A-Za-z_-]*)'
|
||||
const URI_EXACT_RE = new RegExp(`^weknora://${URI_BODY}$`, 'i')
|
||||
const URI_IN_TEXT_RE = new RegExp(`weknora://${URI_BODY}`, 'gi')
|
||||
const URI_EXACT_RE = new RegExp(`^academy://${URI_BODY}$`, 'i')
|
||||
const URI_IN_TEXT_RE = new RegExp(`academy://${URI_BODY}`, 'gi')
|
||||
const HREF_RE = /\bhref\s*=\s*(?:"([^"]*)"|'([^']*)')/i
|
||||
const SKIPPED_TAGS = new Set(['code', 'pre', 'a', 'button', 'svg', 'math'])
|
||||
|
||||
/** Parses a `weknora://kb|doc|chunk/<id>` durable URI emitted by the model-context codec. */
|
||||
export function parseWeKnoraEntityURI(value: string | null | undefined): WeKnoraEntityRef | null {
|
||||
/** Parses a `academy://kb|doc|chunk/<id>` durable URI emitted by the model-context codec. */
|
||||
export function parseAcademyEntityURI(value: string | null | undefined): AcademyEntityRef | null {
|
||||
const match = URI_EXACT_RE.exec((value || '').trim())
|
||||
if (!match) return null
|
||||
return { kind: match[1].toLowerCase() as WeKnoraEntityKind, id: match[2] }
|
||||
return { kind: match[1].toLowerCase() as AcademyEntityKind, id: match[2] }
|
||||
}
|
||||
|
||||
function escapeHtml(text: string): string {
|
||||
return text.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"')
|
||||
}
|
||||
|
||||
function entityOpenTag(ref: WeKnoraEntityRef, labels: WeKnoraEntityLinkLabels): string {
|
||||
return `<span class="${WEKNORA_ENTITY_LINK_CLASS}" role="link" tabindex="0" ` +
|
||||
function entityOpenTag(ref: AcademyEntityRef, labels: AcademyEntityLinkLabels): string {
|
||||
return `<span class="${ACADEMY_ENTITY_LINK_CLASS}" role="link" tabindex="0" ` +
|
||||
`title="${escapeHtml(labels[ref.kind])}" data-entity-kind="${ref.kind}" data-entity-id="${ref.id}">`
|
||||
}
|
||||
|
||||
/**
|
||||
* Turns `weknora://` URIs in rendered chat HTML into clickable entity chips.
|
||||
* Turns `academy://` URIs in rendered chat HTML into clickable entity chips.
|
||||
* Markdown links keep their text; bare URIs in prose show the real ID, since
|
||||
* the model writes them where an ID is meant. The kind label is the tooltip.
|
||||
* Text inside code, pre and ordinary links is left alone. Must run before
|
||||
* DOMPurify, whose URI allowlist would otherwise strip the `weknora:` scheme.
|
||||
* DOMPurify, whose URI allowlist would otherwise strip the `academy:` scheme.
|
||||
*/
|
||||
export function renderWeKnoraEntityLinks(html: string, labels: WeKnoraEntityLinkLabels): string {
|
||||
if (!html || !/weknora:\/\//i.test(html)) return html
|
||||
export function renderAcademyEntityLinks(html: string, labels: AcademyEntityLinkLabels): string {
|
||||
if (!html || !/academy:\/\//i.test(html)) return html
|
||||
const parts = html.split(/(<[^>]*>)/)
|
||||
const skipDepth = new Map<string, number>()
|
||||
let skipping = 0
|
||||
@@ -60,7 +60,7 @@ export function renderWeKnoraEntityLinks(html: string, labels: WeKnoraEntityLink
|
||||
}
|
||||
if (name === 'a' && !closing && skipping === 0) {
|
||||
const hrefMatch = HREF_RE.exec(part)
|
||||
const ref = parseWeKnoraEntityURI(hrefMatch?.[1] ?? hrefMatch?.[2])
|
||||
const ref = parseAcademyEntityURI(hrefMatch?.[1] ?? hrefMatch?.[2])
|
||||
if (ref) {
|
||||
parts[i] = entityOpenTag(ref, labels)
|
||||
entityAnchorOpen = true
|
||||
@@ -82,7 +82,7 @@ export function renderWeKnoraEntityLinks(html: string, labels: WeKnoraEntityLink
|
||||
}
|
||||
if (skipping > 0 || entityAnchorOpen) continue
|
||||
parts[i] = part.replace(URI_IN_TEXT_RE, (_m, kind: string, id: string) => {
|
||||
const ref = { kind: kind.toLowerCase() as WeKnoraEntityKind, id }
|
||||
const ref = { kind: kind.toLowerCase() as AcademyEntityKind, id }
|
||||
return `${entityOpenTag(ref, labels)}${id}</span>`
|
||||
})
|
||||
}
|
||||
@@ -50,8 +50,8 @@ test('getAgentToolIconName maps skill and sandbox file tools', () => {
|
||||
test('getAgentToolIconName maps operation and product-doc tools', () => {
|
||||
assert.equal(getAgentToolIconName('find_operations'), 'task')
|
||||
assert.equal(getAgentToolIconName('run_operation'), 'terminal')
|
||||
assert.equal(getAgentToolIconName('search_weknora_docs'), 'search')
|
||||
assert.equal(getAgentToolIconName('read_weknora_doc'), 'file')
|
||||
assert.equal(getAgentToolIconName('search_academy_docs'), 'search')
|
||||
assert.equal(getAgentToolIconName('read_academy_doc'), 'file')
|
||||
})
|
||||
|
||||
test('getAgentToolIconName maps Wiki tools to semantic search and reading icons', () => {
|
||||
|
||||
@@ -81,10 +81,10 @@ export function getAgentToolIconName(
|
||||
if (toolName === 'open_page' || toolName === 'view_page') {
|
||||
return 'jump'
|
||||
}
|
||||
if (toolName === 'search_weknora_docs') {
|
||||
if (toolName === 'search_academy_docs') {
|
||||
return 'search'
|
||||
}
|
||||
if (toolName === 'read_weknora_doc') {
|
||||
if (toolName === 'read_academy_doc') {
|
||||
return 'file'
|
||||
}
|
||||
return 'file-paste'
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
export function getApiBaseUrl(): string {
|
||||
// LocalHub plugin patch (2026-04-29): respect vite's BASE_URL so that
|
||||
// axios calls work at `/app/weknora/` (LocalHub reverse proxy). Without
|
||||
// axios calls work at `/app/academy/` (LocalHub reverse proxy). Without
|
||||
// this · axios hits `/api/v1/...` at LocalHub root · gets 404 "Cannot
|
||||
// POST". Strip trailing slash so axios doesn't produce `/app/weknora//api/v1/...`.
|
||||
// See: plugins/weknora/patches/api-base-baseurl.patch
|
||||
// POST". Strip trailing slash so axios doesn't produce `/app/academy//api/v1/...`.
|
||||
// See: plugins/academy/patches/api-base-baseurl.patch
|
||||
const base = (import.meta.env.BASE_URL || '/').replace(/\/+$/, '');
|
||||
return base;
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
import { onMounted, onUnmounted } from 'vue'
|
||||
|
||||
export const ASSISTANT_DATA_CHANGE_EVENT = 'weknora:assistant-data-change'
|
||||
export const ASSISTANT_DATA_CHANGE_EVENT = 'academy:assistant-data-change'
|
||||
|
||||
export interface AssistantDataChange {
|
||||
operation: string
|
||||
|
||||
@@ -50,7 +50,7 @@ test('isStreamAuthError matches the class and name-only wrappers', () => {
|
||||
|
||||
test('concurrent 401s share a single refresh call', async () => {
|
||||
const { store } = installBrowser()
|
||||
store.weknora_refresh_token = 'rt-1'
|
||||
store.academy_refresh_token = 'rt-1'
|
||||
let calls = 0
|
||||
let release!: (value: { success: true; data: { token: string; refreshToken: string } }) => void
|
||||
const pending = new Promise<{ success: true; data: { token: string; refreshToken: string } }>(
|
||||
@@ -70,16 +70,16 @@ test('concurrent 401s share a single refresh call', async () => {
|
||||
|
||||
release({ success: true, data: { token: 'access-2', refreshToken: 'rt-2' } })
|
||||
assert.deepEqual(await Promise.all([first, second]), ['access-2', 'access-2'])
|
||||
assert.equal(store.weknora_token, 'access-2')
|
||||
assert.equal(store.weknora_refresh_token, 'rt-2')
|
||||
assert.equal(store.academy_token, 'access-2')
|
||||
assert.equal(store.academy_refresh_token, 'rt-2')
|
||||
assert.equal(calls, 1)
|
||||
})
|
||||
|
||||
test('missing refresh token clears credentials, redirects, and throws an Error', async () => {
|
||||
const { store, location } = installBrowser()
|
||||
store.weknora_token = 'expired'
|
||||
store.weknora_user = '{}'
|
||||
store.weknora_selected_tenant_id = '9'
|
||||
store.academy_token = 'expired'
|
||||
store.academy_user = '{}'
|
||||
store.academy_selected_tenant_id = '9'
|
||||
|
||||
await assert.rejects(
|
||||
() => refreshAccessTokenShared({
|
||||
@@ -90,16 +90,16 @@ test('missing refresh token clears credentials, redirects, and throws an Error',
|
||||
}),
|
||||
(err: unknown) => err instanceof Error && err.message === 'please-relogin',
|
||||
)
|
||||
assert.equal(store.weknora_token, undefined)
|
||||
assert.equal(store.weknora_selected_tenant_id, undefined)
|
||||
assert.equal(store.academy_token, undefined)
|
||||
assert.equal(store.academy_selected_tenant_id, undefined)
|
||||
assert.equal(location.href, '/login')
|
||||
})
|
||||
|
||||
test('a failed refresh clears the newly irrelevant session and redirects', async () => {
|
||||
const { store, location } = installBrowser()
|
||||
store.weknora_refresh_token = 'rt-dead'
|
||||
store.weknora_token = 'expired'
|
||||
store.weknora_selected_tenant_id = '9'
|
||||
store.academy_refresh_token = 'rt-dead'
|
||||
store.academy_token = 'expired'
|
||||
store.academy_selected_tenant_id = '9'
|
||||
|
||||
await assert.rejects(
|
||||
() => refreshAccessTokenShared({
|
||||
@@ -107,8 +107,8 @@ test('a failed refresh clears the newly irrelevant session and redirects', async
|
||||
}),
|
||||
/revoked/,
|
||||
)
|
||||
assert.equal(store.weknora_refresh_token, undefined)
|
||||
assert.equal(store.weknora_selected_tenant_id, undefined)
|
||||
assert.equal(store.academy_refresh_token, undefined)
|
||||
assert.equal(store.academy_selected_tenant_id, undefined)
|
||||
assert.equal(location.href, '/login')
|
||||
})
|
||||
|
||||
@@ -154,8 +154,8 @@ test('embed visitors are not refreshed or redirected', async () => {
|
||||
|
||||
test('a second handshake 401 after a successful refresh does not wipe tokens', async () => {
|
||||
const { store, location } = installBrowser()
|
||||
store.weknora_token = 'expired'
|
||||
store.weknora_refresh_token = 'rt-1'
|
||||
store.academy_token = 'expired'
|
||||
store.academy_refresh_token = 'rt-1'
|
||||
location.href = 'http://localhost/chat'
|
||||
|
||||
await assert.rejects(
|
||||
@@ -179,8 +179,8 @@ test('a second handshake 401 after a successful refresh does not wipe tokens', a
|
||||
}),
|
||||
(err: unknown) => err instanceof Error && err.message === 'please-relogin',
|
||||
)
|
||||
assert.equal(store.weknora_token, 'fresh')
|
||||
assert.equal(store.weknora_refresh_token, 'rt-2')
|
||||
assert.equal(store.academy_token, 'fresh')
|
||||
assert.equal(store.academy_refresh_token, 'rt-2')
|
||||
assert.equal(location.href, 'http://localhost/chat')
|
||||
})
|
||||
|
||||
@@ -203,9 +203,9 @@ test('a superseded send skips the replay', async () => {
|
||||
|
||||
test('forceReloginRedirect does not bounce embed visitors to /login', () => {
|
||||
const { store, location } = installBrowser('/embed/ch-1')
|
||||
store.weknora_token = 'jwt'
|
||||
store.academy_token = 'jwt'
|
||||
forceReloginRedirect()
|
||||
assert.equal(store.weknora_token, undefined)
|
||||
assert.equal(store.academy_token, undefined)
|
||||
assert.equal(location.href, 'http://localhost/embed/ch-1')
|
||||
})
|
||||
|
||||
|
||||
@@ -7,15 +7,15 @@
|
||||
*/
|
||||
|
||||
const AUTH_STORAGE_KEYS = [
|
||||
'weknora_token',
|
||||
'weknora_refresh_token',
|
||||
'weknora_user',
|
||||
'weknora_tenant',
|
||||
'weknora_knowledge_bases',
|
||||
'weknora_current_kb',
|
||||
'weknora_selected_tenant_id',
|
||||
'weknora_selected_tenant_name',
|
||||
'weknora_memberships',
|
||||
'academy_token',
|
||||
'academy_refresh_token',
|
||||
'academy_user',
|
||||
'academy_tenant',
|
||||
'academy_knowledge_bases',
|
||||
'academy_current_kb',
|
||||
'academy_selected_tenant_id',
|
||||
'academy_selected_tenant_name',
|
||||
'academy_memberships',
|
||||
] as const
|
||||
|
||||
let isRefreshing = false
|
||||
@@ -114,7 +114,7 @@ export async function refreshAccessTokenShared(
|
||||
}
|
||||
|
||||
isRefreshing = true
|
||||
const storedRefreshToken = localStorage.getItem('weknora_refresh_token')
|
||||
const storedRefreshToken = localStorage.getItem('academy_refresh_token')
|
||||
|
||||
if (!storedRefreshToken) {
|
||||
clearAuthStorage()
|
||||
@@ -133,9 +133,9 @@ export async function refreshAccessTokenShared(
|
||||
}
|
||||
|
||||
const { token, refreshToken: newRefreshToken } = response.data
|
||||
localStorage.setItem('weknora_token', token)
|
||||
localStorage.setItem('academy_token', token)
|
||||
if (newRefreshToken) {
|
||||
localStorage.setItem('weknora_refresh_token', newRefreshToken)
|
||||
localStorage.setItem('academy_refresh_token', newRefreshToken)
|
||||
}
|
||||
processQueue(null, token)
|
||||
return token
|
||||
|
||||
@@ -4,7 +4,7 @@ import test from 'node:test'
|
||||
import { pairingPageOrigin, preferredDesktopAPIBase } from './browserPairingOrigin.ts'
|
||||
|
||||
test('pairingPageOrigin keeps an http or https page', () => {
|
||||
assert.equal(pairingPageOrigin('https://weknora.example'), 'https://weknora.example')
|
||||
assert.equal(pairingPageOrigin('https://academy.example'), 'https://academy.example')
|
||||
assert.equal(pairingPageOrigin('http://127.0.0.1:8080'), 'http://127.0.0.1:8080')
|
||||
})
|
||||
|
||||
|
||||
@@ -63,8 +63,8 @@ test('every backend catalog operation has a label in every UI locale', () => {
|
||||
test('operation and product-doc tools have dedicated display types', () => {
|
||||
assert.equal(getCatalogToolDisplayType('find_operations'), 'find_operations')
|
||||
assert.equal(getCatalogToolDisplayType('run_operation'), 'run_operation')
|
||||
assert.equal(getCatalogToolDisplayType('search_weknora_docs'), 'search_weknora_docs')
|
||||
assert.equal(getCatalogToolDisplayType('read_weknora_doc'), 'read_weknora_doc')
|
||||
assert.equal(getCatalogToolDisplayType('search_academy_docs'), 'search_academy_docs')
|
||||
assert.equal(getCatalogToolDisplayType('read_academy_doc'), 'read_academy_doc')
|
||||
assert.equal(getCatalogToolDisplayType('web_search'), undefined)
|
||||
})
|
||||
|
||||
@@ -83,14 +83,14 @@ test('titles name the operation, query, or page instead of the raw tool id', ()
|
||||
'agentStream.tools.runOperation:knowledge.get',
|
||||
)
|
||||
assert.equal(
|
||||
getCatalogToolTitle(t, { tool_name: 'search_weknora_docs', arguments: { query: 'Wiki' }, pending: true }),
|
||||
'agentStream.toolStatus.calling agentStream.tools.searchWeKnoraDocs:「Wiki」',
|
||||
getCatalogToolTitle(t, { tool_name: 'search_academy_docs', arguments: { query: 'Wiki' }, pending: true }),
|
||||
'agentStream.toolStatus.calling agentStream.tools.searchAcademyDocs:「Wiki」',
|
||||
)
|
||||
assert.equal(
|
||||
getCatalogToolTitle(t, {
|
||||
tool_name: 'read_weknora_doc', success: false, arguments: { path: '03-features/14-wiki' },
|
||||
tool_name: 'read_academy_doc', success: false, arguments: { path: '03-features/14-wiki' },
|
||||
}),
|
||||
'agentStream.toolStatus.calledFailed agentStream.tools.readWeKnoraDoc:「03-features/14-wiki」',
|
||||
'agentStream.toolStatus.calledFailed agentStream.tools.readAcademyDoc:「03-features/14-wiki」',
|
||||
)
|
||||
assert.equal(getCatalogToolTitle(t, { tool_name: 'web_search' }), '')
|
||||
})
|
||||
|
||||
@@ -3,8 +3,8 @@ import type { ComposerTranslation } from 'vue-i18n'
|
||||
export type CatalogDisplayType =
|
||||
| 'find_operations'
|
||||
| 'run_operation'
|
||||
| 'search_weknora_docs'
|
||||
| 'read_weknora_doc'
|
||||
| 'search_academy_docs'
|
||||
| 'read_academy_doc'
|
||||
|
||||
const PAYLOAD_KEYS = [
|
||||
'operations', 'unavailable',
|
||||
@@ -115,7 +115,7 @@ function numberOrNull(value: unknown): number | null {
|
||||
|
||||
export function getCatalogToolDisplayType(toolName?: string): CatalogDisplayType | undefined {
|
||||
if (toolName === 'find_operations' || toolName === 'run_operation' ||
|
||||
toolName === 'search_weknora_docs' || toolName === 'read_weknora_doc') {
|
||||
toolName === 'search_academy_docs' || toolName === 'read_academy_doc') {
|
||||
return toolName
|
||||
}
|
||||
return undefined
|
||||
@@ -300,12 +300,12 @@ export function getCatalogToolTitle(t: ComposerTranslation, event: ToolEventLike
|
||||
const base = t('agentStream.tools.runOperation')
|
||||
const operation = stringField(args, 'operation') || stringField(data, 'operation')
|
||||
title = operation ? `${base}:${getOperationLabel(t, operation)}` : base
|
||||
} else if (type === 'search_weknora_docs') {
|
||||
const base = t('agentStream.tools.searchWeKnoraDocs')
|
||||
} else if (type === 'search_academy_docs') {
|
||||
const base = t('agentStream.tools.searchAcademyDocs')
|
||||
const detail = stringField(args, 'query') || stringField(args, 'category')
|
||||
title = detail ? `${base}:「${detail}」` : base
|
||||
} else {
|
||||
const base = t('agentStream.tools.readWeKnoraDoc')
|
||||
const base = t('agentStream.tools.readAcademyDoc')
|
||||
const detail = stringField(data, 'section') || stringField(data, 'title') || stringField(args, 'path')
|
||||
title = detail ? `${base}:「${detail}」` : base
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ import {
|
||||
stripIncompleteCitationTag,
|
||||
type CitationKnowledgeRef,
|
||||
} from './citationMarkdown.ts'
|
||||
import { renderWeKnoraEntityLinks, type WeKnoraEntityLinkLabels } from './weknoraEntityLinks.ts'
|
||||
import { renderAcademyEntityLinks, type AcademyEntityLinkLabels } from './academyEntityLinks.ts'
|
||||
|
||||
const STREAMING_IMAGE_PLACEHOLDER =
|
||||
'<span class="streaming-image-loading"><span class="streaming-image-loading__skeleton"></span></span>'
|
||||
@@ -46,8 +46,8 @@ export type RenderChatMarkdownOptions = {
|
||||
cachedMermaidSvgHtml?: CachedMermaidSvgHtml
|
||||
injectCachedMermaidSvg?: (html: string, cachedSvgHtml?: CachedMermaidSvgHtml) => string
|
||||
prepareMarkdown?: (markdown: string, cachedSvgHtml?: CachedMermaidSvgHtml) => string
|
||||
/** Render `weknora://` URIs as clickable entity links with these labels. */
|
||||
entityLinkLabels?: WeKnoraEntityLinkLabels
|
||||
/** Render `academy://` URIs as clickable entity links with these labels. */
|
||||
entityLinkLabels?: AcademyEntityLinkLabels
|
||||
}
|
||||
|
||||
export function configureMarkedForChatMarkdown(): void {
|
||||
@@ -507,7 +507,7 @@ export function renderChatMarkdown(rawMarkdown: unknown, options: RenderChatMark
|
||||
? restoredHtml
|
||||
: collapseStandaloneCitationParagraphs(restoredHtml)
|
||||
const entityHtml = options.entityLinkLabels
|
||||
? renderWeKnoraEntityLinks(citationHtml, options.entityLinkLabels)
|
||||
? renderAcademyEntityLinks(citationHtml, options.entityLinkLabels)
|
||||
: citationHtml
|
||||
const tableWrappedHtml = wrapChatMarkdownTables(entityHtml)
|
||||
const strongTitleHtml = markStandaloneStrongParagraphs(tableWrappedHtml)
|
||||
|
||||
@@ -199,7 +199,7 @@ export function preprocessCitationTags(
|
||||
})
|
||||
}
|
||||
|
||||
const HTML_PLACEHOLDER_RE = /@@WEKNORA_HTML_PLACEHOLDER_(\d+)@@/g
|
||||
const HTML_PLACEHOLDER_RE = /@@ACADEMY_HTML_PLACEHOLDER_(\d+)@@/g
|
||||
|
||||
/** Protect citation HTML from markdown parser; restore after marked.parse. */
|
||||
export function extractCitationHtmlPlaceholders(
|
||||
@@ -210,7 +210,7 @@ export function extractCitationHtmlPlaceholders(
|
||||
const storeHtml = (html: string): string => {
|
||||
const idx = htmlSnippets.length
|
||||
htmlSnippets.push(html)
|
||||
return `@@WEKNORA_HTML_PLACEHOLDER_${idx}@@`
|
||||
return `@@ACADEMY_HTML_PLACEHOLDER_${idx}@@`
|
||||
}
|
||||
|
||||
const content = contentStr
|
||||
|
||||
@@ -81,7 +81,7 @@ async function navigate(
|
||||
return { ...snapshotPage(), return_path: returnPath }
|
||||
}
|
||||
|
||||
const HANDLED_KEY = 'weknora:assistant-page-actions'
|
||||
const HANDLED_KEY = 'academy:assistant-page-actions'
|
||||
// A replayed stream can repeat a prompt long after it ended; the server
|
||||
// rejects the late answer anyway, this only spares the page the work.
|
||||
const STALE_AFTER_SECONDS = 600
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Types into the WeKnora page beside the assistant the way the user would:
|
||||
* Types into the Academy page beside the assistant the way the user would:
|
||||
* native setters plus input events for text, clicks for checkboxes, switches
|
||||
* and TDesign selects. Nothing is saved. A fill applies all its changes or
|
||||
* none, and can be undone from the chat while the fields keep its values.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Reads the WeKnora page beside the assistant the way a screen reader would:
|
||||
* Reads the Academy page beside the assistant the way a screen reader would:
|
||||
* an indented outline of headings, text, tables, buttons and form fields with
|
||||
* their current values. Fields the assistant may fill get a ref (e12) that
|
||||
* stays with the element while it lives. Credentials are never read.
|
||||
|
||||
@@ -50,10 +50,10 @@ const accessState: ProtectedFileAccessState = (() => {
|
||||
const fresh = (): ProtectedFileAccessState => ({ current: TENANT_ACCESS });
|
||||
if (typeof window === 'undefined') return fresh();
|
||||
const scope = window as typeof window & {
|
||||
__weknoraProtectedFileAccessV1__?: ProtectedFileAccessState;
|
||||
__academyProtectedFileAccessV1__?: ProtectedFileAccessState;
|
||||
};
|
||||
scope.__weknoraProtectedFileAccessV1__ ||= fresh();
|
||||
return scope.__weknoraProtectedFileAccessV1__;
|
||||
scope.__academyProtectedFileAccessV1__ ||= fresh();
|
||||
return scope.__academyProtectedFileAccessV1__;
|
||||
})();
|
||||
|
||||
/**
|
||||
@@ -109,18 +109,18 @@ export function isProtectedFileProxyPath(pathname: string): boolean {
|
||||
function tenantRequestHeaders(): Record<string, string> {
|
||||
const headers: Record<string, string> = {};
|
||||
try {
|
||||
const token = (localStorage.getItem('weknora_token') || '').trim();
|
||||
const token = (localStorage.getItem('academy_token') || '').trim();
|
||||
if (token) {
|
||||
headers['Authorization'] = `Bearer ${token}`;
|
||||
}
|
||||
|
||||
const selectedTenantId = (localStorage.getItem('weknora_selected_tenant_id') || '').trim();
|
||||
const selectedTenantId = (localStorage.getItem('academy_selected_tenant_id') || '').trim();
|
||||
if (selectedTenantId) {
|
||||
// Always attach when a selected tenant is set. Same rationale as
|
||||
// utils/request.ts / api/chat/streame.ts: the
|
||||
// "selectedTenantId === defaultTenantId → skip" short-circuit
|
||||
// silently drops the header whenever any code path writes the
|
||||
// active tenant into weknora_tenant, leaving authenticated file
|
||||
// active tenant into academy_tenant, leaving authenticated file
|
||||
// fetches landing on the home tenant.
|
||||
headers['X-Tenant-ID'] = selectedTenantId;
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ export interface LoadedProtectedFile {
|
||||
fileName: string;
|
||||
}
|
||||
|
||||
export const RESOURCE_PREVIEW_EVENT = 'weknora:resource-preview';
|
||||
export const RESOURCE_PREVIEW_EVENT = 'academy:resource-preview';
|
||||
|
||||
export function responseFileName(disposition: string | null, source: string): string {
|
||||
const encoded = disposition?.match(/(?:^|;)\s*filename\*\s*=\s*UTF-8'[^']*'([^;]+)/i)?.[1]?.trim();
|
||||
|
||||
@@ -77,7 +77,7 @@ instance.interceptors.request.use(
|
||||
|
||||
// 嵌入渠道使用 Embed token;勿用本地 JWT 覆盖(否则调试页会 401)
|
||||
if (!isEmbedAuth) {
|
||||
const token = localStorage.getItem('weknora_token');
|
||||
const token = localStorage.getItem('academy_token');
|
||||
if (token) {
|
||||
config.headers["Authorization"] = `Bearer ${token}`;
|
||||
}
|
||||
@@ -89,14 +89,14 @@ instance.interceptors.request.use(
|
||||
// 添加跨空间访问请求头:只要 setSelectedTenant 写过激活空间,
|
||||
// 每个请求都要附 X-Tenant-ID。早期版本会 short-circuit
|
||||
// "selectedTenantId === defaultTenantId 时不附"以减少 header 体积,
|
||||
// 但这条优化会被任何把 weknora_tenant 写成激活空间的代码(OIDC
|
||||
// 但这条优化会被任何把 academy_tenant 写成激活空间的代码(OIDC
|
||||
// 回调、UserMenu loadUserInfo、router hydrate)触发,导致后续请求
|
||||
// 静默丢失 header,前端"切换了"但实际仍跑在 home 空间里——把"切
|
||||
// 换之后只有第一批请求带 X-Tenant-ID"调成永久状态。
|
||||
// 后端 IsTenantAccessible 已经允许 header 指向 home 空间(自家),
|
||||
// 所以无脑附不会引入新风险。
|
||||
if (!isEmbedAuth && !isEmbedPath) {
|
||||
const selectedTenantId = localStorage.getItem('weknora_selected_tenant_id');
|
||||
const selectedTenantId = localStorage.getItem('academy_selected_tenant_id');
|
||||
if (selectedTenantId) {
|
||||
config.headers["X-Tenant-ID"] = selectedTenantId;
|
||||
}
|
||||
|
||||
@@ -240,9 +240,9 @@ type ArtifactBlobState = { blobByKey: Map<string, string>; inflight: Map<string,
|
||||
const artifactBlobState: ArtifactBlobState = (() => {
|
||||
const fresh = (): ArtifactBlobState => ({ blobByKey: new Map(), inflight: new Map() });
|
||||
if (typeof window === 'undefined') return fresh();
|
||||
const scope = window as typeof window & { __weknoraArtifactBlobCacheV1__?: ArtifactBlobState };
|
||||
scope.__weknoraArtifactBlobCacheV1__ ||= fresh();
|
||||
return scope.__weknoraArtifactBlobCacheV1__;
|
||||
const scope = window as typeof window & { __academyArtifactBlobCacheV1__?: ArtifactBlobState };
|
||||
scope.__academyArtifactBlobCacheV1__ ||= fresh();
|
||||
return scope.__academyArtifactBlobCacheV1__;
|
||||
})();
|
||||
|
||||
function blobCacheKey(ctx: ArtifactRefContext, index: number): string {
|
||||
|
||||
@@ -28,7 +28,7 @@ test('round-trips a pid keyed by session', () => {
|
||||
writeStoredPtyId('sess-a', 4321)
|
||||
assert.equal(readStoredPtyId('sess-a'), 4321)
|
||||
assert.equal(readStoredPtyId('sess-b'), null)
|
||||
assert.equal(sandboxPtyStorageKey('sess-a'), 'weknora_sandbox_pty:sess-a')
|
||||
assert.equal(sandboxPtyStorageKey('sess-a'), 'academy_sandbox_pty:sess-a')
|
||||
})
|
||||
|
||||
test('forgets the pid when cleared or invalid', () => {
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
* tab's F5 does not.
|
||||
*/
|
||||
|
||||
const KEY_PREFIX = 'weknora_sandbox_pty:'
|
||||
const KEY_PREFIX = 'academy_sandbox_pty:'
|
||||
|
||||
export function sandboxPtyStorageKey(sessionId: string): string {
|
||||
return `${KEY_PREFIX}${sessionId.trim()}`
|
||||
|
||||
@@ -468,10 +468,10 @@ const protectedFileCacheState = (() => {
|
||||
});
|
||||
if (typeof window === 'undefined') return fresh();
|
||||
const scope = window as typeof window & {
|
||||
__weknoraProtectedFileCacheV4__?: ProtectedFileCacheState;
|
||||
__academyProtectedFileCacheV4__?: ProtectedFileCacheState;
|
||||
};
|
||||
scope.__weknoraProtectedFileCacheV4__ ||= fresh();
|
||||
return scope.__weknoraProtectedFileCacheV4__;
|
||||
scope.__academyProtectedFileCacheV4__ ||= fresh();
|
||||
return scope.__academyProtectedFileCacheV4__;
|
||||
})();
|
||||
|
||||
const protectedFileBlobCache = protectedFileCacheState.blobByRequest;
|
||||
@@ -575,9 +575,9 @@ function applyHydratedProtectedImage(root: ParentNode, sourceURL: string, file:
|
||||
|
||||
function ensureProtectedResourceCardClicks(): void {
|
||||
if (typeof window === 'undefined') return;
|
||||
const scope = window as typeof window & { __weknoraProtectedCardClicks__?: boolean };
|
||||
if (scope.__weknoraProtectedCardClicks__) return;
|
||||
scope.__weknoraProtectedCardClicks__ = true;
|
||||
const scope = window as typeof window & { __academyProtectedCardClicks__?: boolean };
|
||||
if (scope.__academyProtectedCardClicks__) return;
|
||||
scope.__academyProtectedCardClicks__ = true;
|
||||
window.addEventListener('click', (event) => {
|
||||
const target = event.target as Element | null;
|
||||
const link = target?.closest?.('a.protected-resource-card');
|
||||
|
||||
@@ -72,11 +72,11 @@ test('artifacts after a live inject use the persisted assistant ID regardless of
|
||||
const assistant = { id: 'assistant', request_id: 'request', role: 'assistant' }
|
||||
const list = [assistant]
|
||||
const continuation = forkAfterInjectedUser(list, assistant, { id: 'user', role: 'user' }, 'steer')
|
||||
continuation.artifacts = [{ file_name: 'WeKnora-示例文档.docx', index: 3 }]
|
||||
continuation.artifacts = [{ file_name: 'Academy-示例文档.docx', index: 3 }]
|
||||
const items = collectSessionArtifacts(list)
|
||||
assert.equal(items[0]?.messageId, 'assistant')
|
||||
assert.equal(items[0]?.index, 3)
|
||||
assert.equal(items[0]?.file_name, 'WeKnora-示例文档.docx')
|
||||
assert.equal(items[0]?.file_name, 'Academy-示例文档.docx')
|
||||
})
|
||||
|
||||
test('history-split artifacts keep their persisted download address after refresh', () => {
|
||||
|
||||
@@ -61,7 +61,7 @@ export function installTDesignIconOfflineGuard(): void {
|
||||
stub.setAttribute("src", src);
|
||||
// 非标准 MIME 类型会让浏览器跳过脚本的 fetch/执行阶段
|
||||
stub.setAttribute("type", "text/no-load");
|
||||
stub.setAttribute("data-weknora-blocked-cdn", "tdesign-icons");
|
||||
stub.setAttribute("data-academy-blocked-cdn", "tdesign-icons");
|
||||
body.appendChild(stub);
|
||||
});
|
||||
|
||||
@@ -75,7 +75,7 @@ export function installTDesignIconOfflineGuard(): void {
|
||||
stub.setAttribute("href", href);
|
||||
// 不声明 rel="stylesheet",浏览器不会发起样式表请求
|
||||
stub.setAttribute("rel", "preload-blocked");
|
||||
stub.setAttribute("data-weknora-blocked-cdn", "tdesign-icons");
|
||||
stub.setAttribute("data-academy-blocked-cdn", "tdesign-icons");
|
||||
document.head.appendChild(stub);
|
||||
});
|
||||
}
|
||||
@@ -28,7 +28,7 @@ export function navigateAfterTenantSwitch(): void {
|
||||
// 切换成功后的 toast 跨 hard reload 传递:调用方在 reload 前把信息塞进
|
||||
// sessionStorage,App.vue 启动时 consume 一次再弹出。直接在 reload 前调
|
||||
// NotifyPlugin 会被刷掉,根本来不及看清。
|
||||
const PENDING_TOAST_KEY = 'weknora_pending_tenant_switch_toast'
|
||||
const PENDING_TOAST_KEY = 'academy_pending_tenant_switch_toast'
|
||||
|
||||
export interface PendingTenantSwitchToast {
|
||||
name: string
|
||||
|
||||
@@ -1,62 +0,0 @@
|
||||
import assert from 'node:assert/strict'
|
||||
import test from 'node:test'
|
||||
|
||||
import { marked } from 'marked'
|
||||
|
||||
import { renderChatMarkdown } from './chatMarkdownRenderer.ts'
|
||||
import { parseWeKnoraEntityURI, renderWeKnoraEntityLinks } from './weknoraEntityLinks.ts'
|
||||
|
||||
const LABELS = { kb: '知识库', doc: '文档', chunk: '片段' }
|
||||
const KB_ID = 'kb-0001'
|
||||
const DOC_ID = '00000001-0000-4000-8000-000000000001'
|
||||
|
||||
test('parseWeKnoraEntityURI accepts only whole durable URIs', () => {
|
||||
assert.deepEqual(parseWeKnoraEntityURI(`weknora://kb/${KB_ID}`), { kind: 'kb', id: KB_ID })
|
||||
assert.deepEqual(parseWeKnoraEntityURI(`WeKnora://DOC/${DOC_ID}`), { kind: 'doc', id: DOC_ID })
|
||||
assert.equal(parseWeKnoraEntityURI('weknora://kb/'), null)
|
||||
assert.equal(parseWeKnoraEntityURI('weknora://user/1'), null)
|
||||
assert.equal(parseWeKnoraEntityURI(`see weknora://kb/${KB_ID}`), null)
|
||||
assert.equal(parseWeKnoraEntityURI('javascript:alert(1)'), null)
|
||||
})
|
||||
|
||||
test('markdown links to weknora URIs keep their text and become entity links', () => {
|
||||
const html = renderWeKnoraEntityLinks(
|
||||
`<p>存入 <a href="weknora://kb/${KB_ID}">每日热榜</a> 即可</p>`,
|
||||
LABELS,
|
||||
)
|
||||
assert.equal(
|
||||
html,
|
||||
'<p>存入 <span class="weknora-entity-link" role="link" tabindex="0" title="知识库" ' +
|
||||
`data-entity-kind="kb" data-entity-id="${KB_ID}">每日热榜</span> 即可</p>`,
|
||||
)
|
||||
})
|
||||
|
||||
test('bare weknora URIs in prose show the real ID with the kind as tooltip', () => {
|
||||
const html = renderWeKnoraEntityLinks(`<p>参考 weknora://doc/${DOC_ID}。</p>`, LABELS)
|
||||
assert.match(html, new RegExp(`title="文档" data-entity-kind="doc" data-entity-id="${DOC_ID}">${DOC_ID}</span>。`))
|
||||
assert.doesNotMatch(html, /weknora:\/\//)
|
||||
})
|
||||
|
||||
test('weknora URIs inside code, pre and ordinary links are left alone', () => {
|
||||
const input =
|
||||
`<p><code>weknora://kb/${KB_ID}</code></p>` +
|
||||
`<pre><code>weknora://kb/${KB_ID}</code></pre>` +
|
||||
`<p><a href="https://example.com">weknora://kb/${KB_ID}</a></p>`
|
||||
assert.equal(renderWeKnoraEntityLinks(input, LABELS), input)
|
||||
})
|
||||
|
||||
test('renderChatMarkdown renders weknora links only when labels are supplied', () => {
|
||||
const markdown = `把结果写入 [热榜知识库](weknora://kb/${KB_ID}),并参考 weknora://doc/${DOC_ID}`
|
||||
const options = {
|
||||
renderer: new marked.Renderer(),
|
||||
escapeMarkdown: (text: string) => text,
|
||||
sanitizeHtml: (html: string) => html,
|
||||
}
|
||||
const plain = renderChatMarkdown(markdown, options)
|
||||
assert.doesNotMatch(plain, /weknora-entity-link/)
|
||||
|
||||
const linked = renderChatMarkdown(markdown, { ...options, entityLinkLabels: LABELS })
|
||||
assert.match(linked, new RegExp(`data-entity-kind="kb" data-entity-id="${KB_ID}">热榜知识库</span>`))
|
||||
assert.match(linked, new RegExp(`data-entity-kind="doc" data-entity-id="${DOC_ID}">${DOC_ID}</span>`))
|
||||
assert.doesNotMatch(linked, /href="weknora:/)
|
||||
})
|
||||
Reference in new issue
Block a user