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
File renamed without changes.
@@ -1,12 +1,12 @@
|
||||
# @wxg-prc-cpg/dsh-weknora
|
||||
# @wxg-prc-cpg/dsh-academy
|
||||
|
||||
English | [简体中文](./README_CN.md)
|
||||
|
||||
[npm](https://www.npmjs.com/package/@wxg-prc-cpg/dsh-weknora)
|
||||
[npm](https://www.npmjs.com/package/@wxg-prc-cpg/dsh-academy)
|
||||
|
||||
A [DeepSeek Harness](https://github.com/deepseek-ai/deepseek-harness) (`dsh`) plugin that gives the harness agent
|
||||
first-class access to a [WeKnora](https://github.com/Tencent/WeKnora) knowledge base: hybrid retrieval, full document
|
||||
reading, and WeKnora's own composed answers with citations.
|
||||
first-class access to a [Academy](https://github.com/Tencent/WeKnora) knowledge base: hybrid retrieval, full document
|
||||
reading, and Academy's own composed answers with citations.
|
||||
|
||||
dsh ships no retrieval, embedding or knowledge-base capability of its own — its search tools (`grep`, `glob`) read the
|
||||
workspace, and `web_search` reads the internet. This plugin fills that gap with your organization's documents.
|
||||
@@ -15,19 +15,19 @@ workspace, and `web_search` reads the internet. This plugin fills that gap with
|
||||
|
||||
```sh
|
||||
# from npm (recommended: installs prebuilt code, no build permission needed)
|
||||
dsh plugin --profile web add @wxg-prc-cpg/dsh-weknora
|
||||
dsh plugin --profile web add @wxg-prc-cpg/dsh-academy
|
||||
|
||||
# or from a checkout of this repository
|
||||
dsh plugin --profile web add ./packages/dsh-weknora
|
||||
dsh plugin --profile web add ./packages/dsh-academy
|
||||
```
|
||||
|
||||
Then point it at your deployment. The shipped configuration layer reads environment variables, so the quickest start is:
|
||||
|
||||
```sh
|
||||
export WEKNORA_BASE_URL=https://weknora.example.com # or http://localhost:8080
|
||||
export WEKNORA_API_KEY=sk-... # a WeKnora API key with `retrieve` (+ `chat` for ask)
|
||||
export WEKNORA_KNOWLEDGE_BASE_IDS=kb-123,kb-456 # optional default scope
|
||||
export WEKNORA_RESOURCE_URLS=public # default; `handle` keeps internal file refs
|
||||
export ACADEMY_BASE_URL=https://academy.example.com # or http://localhost:8080
|
||||
export ACADEMY_API_KEY=sk-... # a Academy API key with `retrieve` (+ `chat` for ask)
|
||||
export ACADEMY_KNOWLEDGE_BASE_IDS=kb-123,kb-456 # optional default scope
|
||||
export ACADEMY_RESOURCE_URLS=public # default; `handle` keeps internal file refs
|
||||
dsh web
|
||||
```
|
||||
|
||||
@@ -35,19 +35,19 @@ For anything beyond that, override the row from your profile's `cordis.patch.yml
|
||||
(`$DSH_HOME/profiles/<name>/cordis.patch.yml`):
|
||||
|
||||
```yaml
|
||||
- id: weknora
|
||||
- id: academy
|
||||
config:
|
||||
baseUrl: https://weknora.example.com
|
||||
apiKey: !!js process.env.WEKNORA_API_KEY
|
||||
baseUrl: https://academy.example.com
|
||||
apiKey: !!js process.env.ACADEMY_API_KEY
|
||||
knowledgeBaseIds:
|
||||
- kb-product-docs
|
||||
agentId: '' # a WeKnora custom agent id makes `weknora_ask` use the ReAct pipeline
|
||||
agentId: '' # a Academy custom agent id makes `academy_ask` use the ReAct pipeline
|
||||
maxResults: 8
|
||||
maxChunkChars: 1200
|
||||
requestTimeoutMs: 30000
|
||||
chatTimeoutMs: 300000
|
||||
resourceUrls: handle # default is `public` so cited images are directly loadable; `handle` keeps internal refs
|
||||
toolPrefix: weknora # rename the tools, e.g. to mount two deployments side by side
|
||||
toolPrefix: academy # rename the tools, e.g. to mount two deployments side by side
|
||||
tools:
|
||||
listKnowledgeBases: true
|
||||
search: true
|
||||
@@ -62,24 +62,24 @@ Mounting two deployments is two rows with two prefixes:
|
||||
|
||||
```yaml
|
||||
- insert:
|
||||
- id: weknora-internal
|
||||
name: "@wxg-prc-cpg/dsh-weknora"
|
||||
- id: academy-internal
|
||||
name: "@wxg-prc-cpg/dsh-academy"
|
||||
config: { baseUrl: https://kb.internal.example.com, toolPrefix: internal_kb }
|
||||
- id: weknora-public
|
||||
name: "@wxg-prc-cpg/dsh-weknora"
|
||||
- id: academy-public
|
||||
name: "@wxg-prc-cpg/dsh-academy"
|
||||
config: { baseUrl: https://kb.public.example.com, toolPrefix: public_kb }
|
||||
```
|
||||
|
||||
## Tools
|
||||
|
||||
| Tool | WeKnora endpoint | What the model gets |
|
||||
| Tool | Academy endpoint | What the model gets |
|
||||
|---|---|---|
|
||||
| `weknora_list_knowledge_bases` | `GET /knowledge-bases` | Knowledge base names and ids, to report what exists or to narrow a later search |
|
||||
| `weknora_search` | `POST /knowledge-search` + `GET /knowledge/search` | Ranked passages verbatim, each with a `knowledge_id`, score and chunk index, plus any document the query names |
|
||||
| `weknora_read_document` | `GET /chunks/:knowledge_id` + `GET /knowledge/:id` | One document's passages reassembled in order, led by its title and summary, with paging |
|
||||
| `weknora_ask` | `POST /sessions` + `POST /knowledge-chat/:id` or `POST /agent-chat/:id` | WeKnora's own answer, its citations, the server-side tools it used, and a resumable `session_id` |
|
||||
| `academy_list_knowledge_bases` | `GET /knowledge-bases` | Knowledge base names and ids, to report what exists or to narrow a later search |
|
||||
| `academy_search` | `POST /knowledge-search` + `GET /knowledge/search` | Ranked passages verbatim, each with a `knowledge_id`, score and chunk index, plus any document the query names |
|
||||
| `academy_read_document` | `GET /chunks/:knowledge_id` + `GET /knowledge/:id` | One document's passages reassembled in order, led by its title and summary, with paging |
|
||||
| `academy_ask` | `POST /sessions` + `POST /knowledge-chat/:id` or `POST /agent-chat/:id` | Academy's own answer, its citations, the server-side tools it used, and a resumable `session_id` |
|
||||
|
||||
`weknora_search` is the workhorse: it returns the source text for the agent to reason over, which keeps the agent's own
|
||||
`academy_search` is the workhorse: it returns the source text for the agent to reason over, which keeps the agent's own
|
||||
reasoning auditable. It answers two questions the model cannot always tell apart — *where is this discussed* and *where
|
||||
is the document called X* — by matching passage content and document names in the same call. A query that reads like a
|
||||
title additionally reports the documents it names, so a document whose wording differs from its own title is still
|
||||
@@ -87,40 +87,40 @@ reachable.
|
||||
|
||||
Scope works without configuration. An unscoped call is refused by the retrieval endpoint and answered from nothing by
|
||||
the RAG one, so when `knowledgeBaseIds` is empty the plugin resolves every knowledge base the credential can see and
|
||||
uses all of them, resolving that list once per process and sharing it between `weknora_search` and `weknora_ask`.
|
||||
uses all of them, resolving that list once per process and sharing it between `academy_search` and `academy_ask`.
|
||||
Making the model choose first would be worse: knowledge bases are frequently named too poorly to choose between.
|
||||
|
||||
`weknora_ask` delegates the whole question to WeKnora. Reserve it for broad or synthesis questions spanning many
|
||||
`academy_ask` delegates the whole question to Academy. Reserve it for broad or synthesis questions spanning many
|
||||
documents, where retrieving passages yourself would take several rounds — it runs another model server-side, so it is
|
||||
slow, and it returns a conclusion rather than the evidence behind it. With `agentId` set it leaves the scope alone: a
|
||||
custom agent resolves its own from its KB selection mode, and ids sent from here would override that.
|
||||
|
||||
`weknora_read_document` exists because retrieval returns fragments: once a passage looks right, the agent usually needs
|
||||
`academy_read_document` exists because retrieval returns fragments: once a passage looks right, the agent usually needs
|
||||
its neighbours. Every search hit carries the `knowledge_id` that call needs, and page 1 leads with the document's title
|
||||
and WeKnora's generated summary so a long document can be judged without paging through it.
|
||||
and Academy's generated summary so a long document can be judged without paging through it.
|
||||
|
||||
In [Code Mode](https://github.com/deepseek-ai/deepseek-harness/blob/master/packages/core/tools/README.md) the same tools
|
||||
are available as `await tools.weknora_search({ query })`, which is a good fit for multi-hop retrieval: one program can
|
||||
are available as `await tools.academy_search({ query })`, which is a good fit for multi-hop retrieval: one program can
|
||||
fan out across ten sub-questions without ten model round trips.
|
||||
|
||||
## Permissions and data flow
|
||||
|
||||
The plugin only reads. It never writes to WeKnora: no ingestion, no chunk edits, no deletion. A WeKnora API key scoped
|
||||
to `retrieve` is enough for three of the four tools; `weknora_ask` additionally needs `chat`, because it creates a
|
||||
The plugin only reads. It never writes to Academy: no ingestion, no chunk edits, no deletion. A Academy API key scoped
|
||||
to `retrieve` is enough for three of the four tools; `academy_ask` additionally needs `chat`, because it creates a
|
||||
session and streams an answer.
|
||||
|
||||
The key is sent as `X-API-Key`. Set `tenantId` as well if you use a platform-scoped key, which needs `X-Tenant-ID` to
|
||||
select a workspace. Errors are reported with the HTTP status and WeKnora's own reason, never with the key.
|
||||
select a workspace. Errors are reported with the HTTP status and Academy's own reason, never with the key.
|
||||
|
||||
Passage content is clipped to `maxChunkChars` before it reaches the model, so one oversized document cannot eat the
|
||||
context window. The clip is reported to the model (`truncated: true`) instead of silently hiding text.
|
||||
|
||||
With the default `resourceUrls: public`, WeKnora rewrites cited `resource://` figures into directly loadable `http(s)`
|
||||
With the default `resourceUrls: public`, Academy rewrites cited `resource://` figures into directly loadable `http(s)`
|
||||
URLs. Copy those Markdown images into the assistant reply and the dsh web UI will render the picture. A
|
||||
knowledge-base-restricted API key cannot receive public URLs (WeKnora answers 403); the plugin retries that call in
|
||||
knowledge-base-restricted API key cannot receive public URLs (Academy answers 403); the plugin retries that call in
|
||||
handle mode and keeps using handles afterwards.
|
||||
|
||||
The shipped configuration layer also reads `WEKNORA_RESOURCE_URLS` (`public` or `handle`).
|
||||
The shipped configuration layer also reads `ACADEMY_RESOURCE_URLS` (`public` or `handle`).
|
||||
|
||||
## Configuration reference
|
||||
|
||||
@@ -130,13 +130,13 @@ The shipped configuration layer also reads `WEKNORA_RESOURCE_URLS` (`public` or
|
||||
| `apiKey` | unset | `X-API-Key`; unset means an unauthenticated deployment |
|
||||
| `tenantId` | unset | `X-Tenant-ID`, required for platform-scoped keys |
|
||||
| `knowledgeBaseIds` | `[]` | Default scope when a call names none; empty means every knowledge base the credential can see |
|
||||
| `agentId` | unset | Sends `weknora_ask` to the ReAct pipeline |
|
||||
| `agentId` | unset | Sends `academy_ask` to the ReAct pipeline |
|
||||
| `maxResults` | `8` | Also the ceiling for `max_results` and for cited references |
|
||||
| `maxChunkChars` | `1200` | Per-passage character budget |
|
||||
| `requestTimeoutMs` | `30000` | Retrieval and document reads |
|
||||
| `chatTimeoutMs` | `300000` | `weknora_ask`, which waits on WeKnora's own model calls |
|
||||
| `resourceUrls` | `public` | `public` returns directly loadable file URLs; `handle` keeps internal `resource://` refs. A knowledge-base-restricted API key is retried as `handle`. Override with `WEKNORA_RESOURCE_URLS`. |
|
||||
| `toolPrefix` | `weknora` | Tool-name prefix, `^[a-z][a-z0-9_]*$` |
|
||||
| `chatTimeoutMs` | `300000` | `academy_ask`, which waits on Academy's own model calls |
|
||||
| `resourceUrls` | `public` | `public` returns directly loadable file URLs; `handle` keeps internal `resource://` refs. A knowledge-base-restricted API key is retried as `handle`. Override with `ACADEMY_RESOURCE_URLS`. |
|
||||
| `toolPrefix` | `academy` | Tool-name prefix, `^[a-z][a-z0-9_]*$` |
|
||||
| `tools.*` | all `true` | Register fewer tools to spend fewer prompt tokens |
|
||||
|
||||
## Development
|
||||
@@ -148,7 +148,7 @@ npm run typecheck
|
||||
```
|
||||
|
||||
The end-to-end check installs the package into a throwaway dsh profile, boots the headless profile against a mock
|
||||
WeKnora backend and a deterministic OpenAI-compatible model, and asserts that the harness really called the tools and
|
||||
Academy backend and a deterministic OpenAI-compatible model, and asserts that the harness really called the tools and
|
||||
answered from what they returned:
|
||||
|
||||
```sh
|
||||
@@ -161,17 +161,17 @@ dsh needs a Node build with zstd support (Node ≥ 22.15 or ≥ 24) for its sess
|
||||
because `dsh plugin add` installs into the profile through pnpm and the profile it writes keeps its settings in
|
||||
`pnpm-workspace.yaml`. The plugin itself runs on Node ≥ 20.11 and needs neither.
|
||||
|
||||
`test/fixtures/api-contract.json` records every WeKnora call this plugin makes. `test/contract.test.mjs` asserts the
|
||||
plugin still emits exactly those calls, and `contract/contract_test.go` asserts WeKnora's real Go request and response
|
||||
`test/fixtures/api-contract.json` records every Academy call this plugin makes. `test/contract.test.mjs` asserts the
|
||||
plugin still emits exactly those calls, and `contract/contract_test.go` asserts Academy's real Go request and response
|
||||
types still accept and serve them — so a rename on either side fails CI instead of a user's agent.
|
||||
|
||||
## Compatibility
|
||||
|
||||
Verified against dsh `0.1.0-rc.8` and WeKnora `0.8.0`. dsh is in developer preview and states that breaking changes
|
||||
Verified against dsh `0.1.0-rc.8` and Academy `0.8.0`. dsh is in developer preview and states that breaking changes
|
||||
will happen; this package deliberately has **no runtime dependencies** and hands `ctx.tools.register()` a plain object,
|
||||
so it does not pin any harness package version. If a harness release changes the tool-definition contract, open an issue
|
||||
against this repository.
|
||||
|
||||
## License
|
||||
|
||||
MIT, same as WeKnora and dsh.
|
||||
MIT, same as Academy and dsh.
|
||||
@@ -1,11 +1,11 @@
|
||||
# @wxg-prc-cpg/dsh-weknora
|
||||
# @wxg-prc-cpg/dsh-academy
|
||||
|
||||
[English](./README.md) | 简体中文
|
||||
|
||||
[npm](https://www.npmjs.com/package/@wxg-prc-cpg/dsh-weknora)
|
||||
[npm](https://www.npmjs.com/package/@wxg-prc-cpg/dsh-academy)
|
||||
|
||||
一个 [DeepSeek Harness](https://github.com/deepseek-ai/deepseek-harness)(`dsh`)插件,让 harness 里的 Agent 直接用上
|
||||
[WeKnora](https://github.com/Tencent/WeKnora) 知识库:混合检索、按文档通读、以及 WeKnora 自己带引用的成稿答案。
|
||||
[Academy](https://github.com/Tencent/WeKnora) 知识库:混合检索、按文档通读、以及 Academy 自己带引用的成稿答案。
|
||||
|
||||
dsh 本身没有任何检索、向量或知识库能力——它的 `grep`、`glob` 只看工作区文件,`web_search` 只看互联网。这个插件把缺的这一
|
||||
块换成你自己的文档。
|
||||
@@ -14,38 +14,38 @@ dsh 本身没有任何检索、向量或知识库能力——它的 `grep`、`gl
|
||||
|
||||
```sh
|
||||
# 从 npm 安装(推荐:装到的是构建产物,用户无需授权执行构建脚本)
|
||||
dsh plugin --profile web add @wxg-prc-cpg/dsh-weknora
|
||||
dsh plugin --profile web add @wxg-prc-cpg/dsh-academy
|
||||
|
||||
# 或者从本仓库的检出目录安装
|
||||
dsh plugin --profile web add ./packages/dsh-weknora
|
||||
dsh plugin --profile web add ./packages/dsh-academy
|
||||
```
|
||||
|
||||
然后把它指向你的部署。插件自带的配置层会读环境变量,所以最快的起步方式是:
|
||||
|
||||
```sh
|
||||
export WEKNORA_BASE_URL=https://weknora.example.com # 或 http://localhost:8080
|
||||
export WEKNORA_API_KEY=sk-... # 需要 `retrieve` 能力(用 ask 还需要 `chat`)
|
||||
export WEKNORA_KNOWLEDGE_BASE_IDS=kb-123,kb-456 # 可选的默认知识库范围
|
||||
export WEKNORA_RESOURCE_URLS=public # 默认;改成 `handle` 则保留内部文件引用
|
||||
export ACADEMY_BASE_URL=https://academy.example.com # 或 http://localhost:8080
|
||||
export ACADEMY_API_KEY=sk-... # 需要 `retrieve` 能力(用 ask 还需要 `chat`)
|
||||
export ACADEMY_KNOWLEDGE_BASE_IDS=kb-123,kb-456 # 可选的默认知识库范围
|
||||
export ACADEMY_RESOURCE_URLS=public # 默认;改成 `handle` 则保留内部文件引用
|
||||
dsh web
|
||||
```
|
||||
|
||||
超出这个范围的配置,在 profile 自己的 `cordis.patch.yml`(`$DSH_HOME/profiles/<name>/cordis.patch.yml`)里覆盖这一行:
|
||||
|
||||
```yaml
|
||||
- id: weknora
|
||||
- id: academy
|
||||
config:
|
||||
baseUrl: https://weknora.example.com
|
||||
apiKey: !!js process.env.WEKNORA_API_KEY
|
||||
baseUrl: https://academy.example.com
|
||||
apiKey: !!js process.env.ACADEMY_API_KEY
|
||||
knowledgeBaseIds:
|
||||
- kb-product-docs
|
||||
agentId: '' # 填 WeKnora 自定义 Agent id,`weknora_ask` 就走 ReAct 流水线
|
||||
agentId: '' # 填 Academy 自定义 Agent id,`academy_ask` 就走 ReAct 流水线
|
||||
maxResults: 8
|
||||
maxChunkChars: 1200
|
||||
requestTimeoutMs: 30000
|
||||
chatTimeoutMs: 300000
|
||||
resourceUrls: handle # 默认是 `public`,引用里的图片给可直接加载的直链;`handle` 保留内部引用
|
||||
toolPrefix: weknora # 重命名工具,例如同时挂两个部署时
|
||||
toolPrefix: academy # 重命名工具,例如同时挂两个部署时
|
||||
tools:
|
||||
listKnowledgeBases: true
|
||||
search: true
|
||||
@@ -60,57 +60,57 @@ patch 是整块替换该行的 `config`,所以要保留的字段需要一并
|
||||
|
||||
```yaml
|
||||
- insert:
|
||||
- id: weknora-internal
|
||||
name: "@wxg-prc-cpg/dsh-weknora"
|
||||
- id: academy-internal
|
||||
name: "@wxg-prc-cpg/dsh-academy"
|
||||
config: { baseUrl: https://kb.internal.example.com, toolPrefix: internal_kb }
|
||||
- id: weknora-public
|
||||
name: "@wxg-prc-cpg/dsh-weknora"
|
||||
- id: academy-public
|
||||
name: "@wxg-prc-cpg/dsh-academy"
|
||||
config: { baseUrl: https://kb.public.example.com, toolPrefix: public_kb }
|
||||
```
|
||||
|
||||
## 工具
|
||||
|
||||
| 工具 | WeKnora 接口 | 模型拿到什么 |
|
||||
| 工具 | Academy 接口 | 模型拿到什么 |
|
||||
|---|---|---|
|
||||
| `weknora_list_knowledge_bases` | `GET /knowledge-bases` | 知识库名称与 id,用于说明有哪些库,或为后续检索缩小范围 |
|
||||
| `weknora_search` | `POST /knowledge-search` + `GET /knowledge/search` | 原文片段与排序,每条带 `knowledge_id`、得分、分块序号,外加查询点名的文档 |
|
||||
| `weknora_read_document` | `GET /chunks/:knowledge_id` + `GET /knowledge/:id` | 单个文档按序拼回的正文,开头给出标题与摘要,支持翻页 |
|
||||
| `weknora_ask` | `POST /sessions` + `POST /knowledge-chat/:id` 或 `POST /agent-chat/:id` | WeKnora 自己的答案、引用、服务端用过的工具,以及可续聊的 `session_id` |
|
||||
| `academy_list_knowledge_bases` | `GET /knowledge-bases` | 知识库名称与 id,用于说明有哪些库,或为后续检索缩小范围 |
|
||||
| `academy_search` | `POST /knowledge-search` + `GET /knowledge/search` | 原文片段与排序,每条带 `knowledge_id`、得分、分块序号,外加查询点名的文档 |
|
||||
| `academy_read_document` | `GET /chunks/:knowledge_id` + `GET /knowledge/:id` | 单个文档按序拼回的正文,开头给出标题与摘要,支持翻页 |
|
||||
| `academy_ask` | `POST /sessions` + `POST /knowledge-chat/:id` 或 `POST /agent-chat/:id` | Academy 自己的答案、引用、服务端用过的工具,以及可续聊的 `session_id` |
|
||||
|
||||
`weknora_search` 是主力:它把原文交给 Agent 自己推理,Agent 的结论因此是可审计的。它在同一次调用里同时匹配片段内容和
|
||||
`academy_search` 是主力:它把原文交给 Agent 自己推理,Agent 的结论因此是可审计的。它在同一次调用里同时匹配片段内容和
|
||||
文档名,因为模型常常分不清自己要找的是「哪里讲了这件事」还是「那份叫 X 的文档在哪」。当查询读起来像个标题时,结果里会额外
|
||||
列出被点名的文档——这样即便某份文档的正文用词与标题完全不同,也依然够得着。
|
||||
|
||||
范围不需要配置。没有指定知识库的调用,检索接口会直接拒绝,RAG 接口则会在什么都没检索到的情况下作答,因此当
|
||||
`knowledgeBaseIds` 为空时,插件会自己解析出该凭据可见的全部知识库并一并使用;这份清单每个进程只解析一次,且由
|
||||
`weknora_search` 与 `weknora_ask` 共用。让模型先去挑反而更糟:知识库的命名往往糟糕到无从选择。
|
||||
`academy_search` 与 `academy_ask` 共用。让模型先去挑反而更糟:知识库的命名往往糟糕到无从选择。
|
||||
|
||||
`weknora_ask` 把整个问题委派给 WeKnora。它适合跨多篇文档、需要综合的宽泛问题,也就是自己检索要来回好几轮的场景;它在服务端
|
||||
`academy_ask` 把整个问题委派给 Academy。它适合跨多篇文档、需要综合的宽泛问题,也就是自己检索要来回好几轮的场景;它在服务端
|
||||
再跑一个模型,所以慢,而且返回的是结论而非支撑结论的证据。配了 `agentId` 时它不会自己填范围:自定义 Agent 会按自己的知识库
|
||||
选择模式在服务端解析范围,从这里传 id 反而会把它覆盖掉。
|
||||
|
||||
`weknora_read_document` 的存在是因为检索返回的是碎片:一旦某个片段看起来对,Agent 通常还需要它的上下文。每条检索结果都带
|
||||
着这次调用需要的 `knowledge_id`;第一页会先给出文档标题和 WeKnora 生成的摘要,长文档不必翻完才知道自己拿到的是什么。
|
||||
`academy_read_document` 的存在是因为检索返回的是碎片:一旦某个片段看起来对,Agent 通常还需要它的上下文。每条检索结果都带
|
||||
着这次调用需要的 `knowledge_id`;第一页会先给出文档标题和 Academy 生成的摘要,长文档不必翻完才知道自己拿到的是什么。
|
||||
|
||||
在 [Code Mode](https://github.com/deepseek-ai/deepseek-harness/blob/master/packages/core/tools/README.md) 下,同样的工具
|
||||
可以写成 `await tools.weknora_search({ query })`,特别适合多跳检索:一段程序里扇出十个子问题,而不是十次模型往返。
|
||||
可以写成 `await tools.academy_search({ query })`,特别适合多跳检索:一段程序里扇出十个子问题,而不是十次模型往返。
|
||||
|
||||
## 权限与数据流
|
||||
|
||||
插件只读。它不会写 WeKnora:不入库、不改分块、不删除。四个工具里有三个只需要 `retrieve` 能力的 API Key;`weknora_ask`
|
||||
插件只读。它不会写 Academy:不入库、不改分块、不删除。四个工具里有三个只需要 `retrieve` 能力的 API Key;`academy_ask`
|
||||
额外需要 `chat`,因为它要创建会话并流式取回答案。
|
||||
|
||||
Key 通过 `X-API-Key` 发送。如果用的是平台级 API Key,还需要配 `tenantId`,它会作为 `X-Tenant-ID` 选择工作空间。报错信息
|
||||
只包含 HTTP 状态码和 WeKnora 自己给出的原因,不会带上 Key。
|
||||
只包含 HTTP 状态码和 Academy 自己给出的原因,不会带上 Key。
|
||||
|
||||
片段内容在进入模型前会按 `maxChunkChars` 截断,避免一份超大文档吃掉整个上下文窗口;截断这件事会明确告知模型
|
||||
(`truncated: true`),而不是悄悄丢文本。
|
||||
|
||||
默认 `resourceUrls: public` 时,WeKnora 会把片段里的 `resource://` 图改写成可直接加载的 http(s) 直链——把这些 Markdown
|
||||
图片写进回复,dsh 网页端就会把图画出来。限定知识库的 API Key 拿不到直链(WeKnora 会 403),插件会把这次调用改回
|
||||
默认 `resourceUrls: public` 时,Academy 会把片段里的 `resource://` 图改写成可直接加载的 http(s) 直链——把这些 Markdown
|
||||
图片写进回复,dsh 网页端就会把图画出来。限定知识库的 API Key 拿不到直链(Academy 会 403),插件会把这次调用改回
|
||||
handle 模式,之后也一直用 handle。
|
||||
|
||||
配置层还会读 `WEKNORA_RESOURCE_URLS`(`public` 或 `handle`)。
|
||||
配置层还会读 `ACADEMY_RESOURCE_URLS`(`public` 或 `handle`)。
|
||||
|
||||
## 配置项
|
||||
|
||||
@@ -120,13 +120,13 @@ handle 模式,之后也一直用 handle。
|
||||
| `apiKey` | 未设置 | `X-API-Key`;不设表示部署无鉴权 |
|
||||
| `tenantId` | 未设置 | `X-Tenant-ID`,平台级 Key 必填 |
|
||||
| `knowledgeBaseIds` | `[]` | 调用未指定范围时的默认值;留空表示检索该凭据可见的全部知识库 |
|
||||
| `agentId` | 未设置 | 让 `weknora_ask` 走 ReAct 流水线 |
|
||||
| `agentId` | 未设置 | 让 `academy_ask` 走 ReAct 流水线 |
|
||||
| `maxResults` | `8` | 同时是 `max_results` 与引用条数的上限 |
|
||||
| `maxChunkChars` | `1200` | 单个片段的字符预算 |
|
||||
| `requestTimeoutMs` | `30000` | 检索与读文档 |
|
||||
| `chatTimeoutMs` | `300000` | `weknora_ask`,要等 WeKnora 自己的模型调用 |
|
||||
| `resourceUrls` | `public` | `public` 返回可直接加载的文件直链;`handle` 保留内部 `resource://` 引用。限定知识库的 API Key 会自动回退到 `handle`。可用 `WEKNORA_RESOURCE_URLS` 覆盖。 |
|
||||
| `toolPrefix` | `weknora` | 工具名前缀,需匹配 `^[a-z][a-z0-9_]*$` |
|
||||
| `chatTimeoutMs` | `300000` | `academy_ask`,要等 Academy 自己的模型调用 |
|
||||
| `resourceUrls` | `public` | `public` 返回可直接加载的文件直链;`handle` 保留内部 `resource://` 引用。限定知识库的 API Key 会自动回退到 `handle`。可用 `ACADEMY_RESOURCE_URLS` 覆盖。 |
|
||||
| `toolPrefix` | `academy` | 工具名前缀,需匹配 `^[a-z][a-z0-9_]*$` |
|
||||
| `tools.*` | 全部 `true` | 少注册几个工具就少占几分 prompt |
|
||||
|
||||
## 开发
|
||||
@@ -137,7 +137,7 @@ npm test # 先构建,再跑单元测试与契约测试
|
||||
npm run typecheck
|
||||
```
|
||||
|
||||
端到端检查会把这个包装进一个临时 dsh profile,用 mock 的 WeKnora 后端和一个确定性的 OpenAI 兼容模型启动 headless
|
||||
端到端检查会把这个包装进一个临时 dsh profile,用 mock 的 Academy 后端和一个确定性的 OpenAI 兼容模型启动 headless
|
||||
profile,并断言 harness 真的调用了工具、并且答案来自工具返回的内容:
|
||||
|
||||
```sh
|
||||
@@ -149,16 +149,16 @@ DSH_BIN=/path/to/dsh node test/e2e/run-in-dsh.mjs # 或者复用已有安装
|
||||
dsh 的会话持久化需要带 zstd 的 Node(≥ 22.15 或 ≥ 24),并且 `PATH` 上要有 pnpm ≥ 10——`dsh plugin add` 通过 pnpm 装进
|
||||
profile,而它写出的 profile 把设置放在 `pnpm-workspace.yaml` 里。插件自身只要求 Node ≥ 20.11,两者都不需要。
|
||||
|
||||
`test/fixtures/api-contract.json` 记录了本插件发出的每一个 WeKnora 调用。`test/contract.test.mjs` 断言插件仍然只发这些
|
||||
调用,`contract/contract_test.go` 断言 WeKnora 真实的 Go 请求/响应类型仍然接受并提供这些字段——任何一侧改名都会在 CI 挂掉,
|
||||
`test/fixtures/api-contract.json` 记录了本插件发出的每一个 Academy 调用。`test/contract.test.mjs` 断言插件仍然只发这些
|
||||
调用,`contract/contract_test.go` 断言 Academy 真实的 Go 请求/响应类型仍然接受并提供这些字段——任何一侧改名都会在 CI 挂掉,
|
||||
而不是在用户的 Agent 里挂掉。
|
||||
|
||||
## 兼容性
|
||||
|
||||
已针对 dsh `0.1.0-rc.8` 与 WeKnora `0.8.0` 验证。dsh 处于 developer preview 并明确会有破坏性变更;本包因此**没有任何运行
|
||||
已针对 dsh `0.1.0-rc.8` 与 Academy `0.8.0` 验证。dsh 处于 developer preview 并明确会有破坏性变更;本包因此**没有任何运行
|
||||
时依赖**,交给 `ctx.tools.register()` 的只是一个普通对象,不锁定任何 harness 包版本。如果 harness 的工具定义契约发生变化,
|
||||
请在本仓库提 issue。
|
||||
|
||||
## 许可
|
||||
|
||||
MIT,与 WeKnora 和 dsh 一致。
|
||||
MIT,与 Academy 和 dsh 一致。
|
||||
+6
-6
@@ -1,10 +1,10 @@
|
||||
// Package contract asserts that the WeKnora API surface the dsh-weknora plugin
|
||||
// Package contract asserts that the Academy API surface the dsh-academy plugin
|
||||
// speaks still exists on this server: the request bodies it sends must decode
|
||||
// into the real handler request structs with no unknown fields, and the response
|
||||
// fields it reads must still be produced by the real response types.
|
||||
//
|
||||
// The fixture is shared with the plugin's own JavaScript tests
|
||||
// (packages/dsh-weknora/test/contract.test.mjs), which assert that the plugin
|
||||
// (packages/dsh-academy/test/contract.test.mjs), which assert that the plugin
|
||||
// still emits exactly these calls. Together the two sides catch a rename on
|
||||
// either side at CI time instead of inside a user's agent.
|
||||
package contract
|
||||
@@ -16,8 +16,8 @@ import (
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/Tencent/WeKnora/internal/handler/session"
|
||||
"github.com/Tencent/WeKnora/internal/types"
|
||||
"academy/internal/handler/session"
|
||||
"academy/internal/types"
|
||||
)
|
||||
|
||||
type contractCall struct {
|
||||
@@ -172,7 +172,7 @@ func TestResponseFieldsThePluginReadsStillExist(t *testing.T) {
|
||||
ID: "doc-1",
|
||||
Title: "检索流程.md",
|
||||
FileName: "检索流程.md",
|
||||
Description: "讲解 WeKnora 混合检索的召回与阈值。",
|
||||
Description: "讲解 Academy 混合检索的召回与阈值。",
|
||||
KnowledgeBaseID: "kb-product",
|
||||
KnowledgeBaseName: "Product docs",
|
||||
},
|
||||
@@ -215,7 +215,7 @@ func TestResponseFieldsThePluginReadsStillExist(t *testing.T) {
|
||||
}
|
||||
for _, field := range fields {
|
||||
if _, ok := asMap[field]; !ok {
|
||||
t.Errorf("%s no longer serializes %q, which dsh-weknora reads", typeName, field)
|
||||
t.Errorf("%s no longer serializes %q, which dsh-academy reads", typeName, field)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,13 +2,13 @@
|
||||
# Override the row from the profile's own cordis.patch.yml to point the plugin
|
||||
# at your deployment; every field is documented in README.md.
|
||||
- insert:
|
||||
- id: weknora
|
||||
- id: academy
|
||||
# Must be the published package name — the loader imports this specifier.
|
||||
# Quoted because YAML reserves a leading '@' in plain scalars.
|
||||
name: "@wxg-prc-cpg/dsh-weknora"
|
||||
name: "@wxg-prc-cpg/dsh-academy"
|
||||
config:
|
||||
baseUrl: !!js process.env.WEKNORA_BASE_URL ?? 'http://localhost:8080/api/v1'
|
||||
apiKey: !!js process.env.WEKNORA_API_KEY
|
||||
knowledgeBaseIds: !!js (process.env.WEKNORA_KNOWLEDGE_BASE_IDS ?? '').split(',').filter(Boolean)
|
||||
agentId: !!js process.env.WEKNORA_AGENT_ID
|
||||
resourceUrls: !!js process.env.WEKNORA_RESOURCE_URLS || 'public'
|
||||
baseUrl: !!js process.env.ACADEMY_BASE_URL ?? 'http://localhost:8080/api/v1'
|
||||
apiKey: !!js process.env.ACADEMY_API_KEY
|
||||
knowledgeBaseIds: !!js (process.env.ACADEMY_KNOWLEDGE_BASE_IDS ?? '').split(',').filter(Boolean)
|
||||
agentId: !!js process.env.ACADEMY_AGENT_ID
|
||||
resourceUrls: !!js process.env.ACADEMY_RESOURCE_URLS || 'public'
|
||||
+2
-2
@@ -1,11 +1,11 @@
|
||||
{
|
||||
"name": "@wxg-prc-cpg/dsh-weknora",
|
||||
"name": "@wxg-prc-cpg/dsh-academy",
|
||||
"version": "0.1.0",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "@wxg-prc-cpg/dsh-weknora",
|
||||
"name": "@wxg-prc-cpg/dsh-academy",
|
||||
"version": "0.1.0",
|
||||
"license": "MIT",
|
||||
"devDependencies": {
|
||||
@@ -1,28 +1,28 @@
|
||||
{
|
||||
"name": "@wxg-prc-cpg/dsh-weknora",
|
||||
"name": "@wxg-prc-cpg/dsh-academy",
|
||||
"version": "0.1.0",
|
||||
"publishConfig": {
|
||||
"access": "public",
|
||||
"registry": "https://registry.npmjs.org/"
|
||||
},
|
||||
"description": "WeKnora knowledge retrieval tools for DeepSeek Harness (dsh): semantic search, document reading and RAG/agent answers over your own knowledge bases.",
|
||||
"description": "Academy knowledge retrieval tools for DeepSeek Harness (dsh): semantic search, document reading and RAG/agent answers over your own knowledge bases.",
|
||||
"keywords": [
|
||||
"dsh",
|
||||
"dsh-plugin",
|
||||
"deepseek-harness",
|
||||
"cordis",
|
||||
"weknora",
|
||||
"academy",
|
||||
"rag",
|
||||
"retrieval",
|
||||
"knowledge-base"
|
||||
],
|
||||
"license": "MIT",
|
||||
"author": "WeKnora",
|
||||
"homepage": "https://github.com/Tencent/WeKnora/tree/main/packages/dsh-weknora",
|
||||
"author": "Academy",
|
||||
"homepage": "https://github.com/Tencent/WeKnora/tree/main/packages/dsh-academy",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/Tencent/WeKnora.git",
|
||||
"directory": "packages/dsh-weknora"
|
||||
"directory": "packages/dsh-academy"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/Tencent/WeKnora/issues"
|
||||
@@ -1,8 +1,8 @@
|
||||
/** Minimal WeKnora REST client: JSON endpoints plus the SSE chat streams. */
|
||||
/** Minimal Academy REST client: JSON endpoints plus the SSE chat streams. */
|
||||
|
||||
import type { ResolvedConfig } from './config.ts'
|
||||
|
||||
/** One retrieval hit, as returned by WeKnora's `SearchResult`. */
|
||||
/** One retrieval hit, as returned by Academy's `SearchResult`. */
|
||||
export interface SearchResult {
|
||||
id?: string
|
||||
content?: string
|
||||
@@ -61,12 +61,12 @@ export interface StreamedAnswer {
|
||||
}
|
||||
|
||||
/** Raised for any non-2xx response or transport failure, with the key redacted. */
|
||||
export class WeknoraApiError extends Error {
|
||||
export class AcademyApiError extends Error {
|
||||
readonly status: number | undefined
|
||||
|
||||
constructor(message: string, status?: number) {
|
||||
super(message)
|
||||
this.name = 'WeknoraApiError'
|
||||
this.name = 'AcademyApiError'
|
||||
this.status = status
|
||||
}
|
||||
}
|
||||
@@ -87,7 +87,7 @@ function snippet(body: string): string {
|
||||
return collapsed.length > 300 ? `${collapsed.slice(0, 300)}…` : collapsed
|
||||
}
|
||||
|
||||
/** Extract a human-readable reason from WeKnora's error envelope. */
|
||||
/** Extract a human-readable reason from Academy's error envelope. */
|
||||
function reasonOf(body: string): string {
|
||||
try {
|
||||
const parsed = JSON.parse(body) as { error?: { message?: string } | string, message?: string }
|
||||
@@ -109,7 +109,7 @@ function deadline(signal: AbortSignal, timeoutMs: number): AbortSignal {
|
||||
return AbortSignal.any([signal, AbortSignal.timeout(timeoutMs)])
|
||||
}
|
||||
|
||||
export class WeknoraClient {
|
||||
export class AcademyClient {
|
||||
/**
|
||||
* A knowledge-base-restricted API key rejects `resource_urls=public` with
|
||||
* 403. After the first such refusal this client stays on handle mode so
|
||||
@@ -143,7 +143,7 @@ export class WeknoraClient {
|
||||
}
|
||||
|
||||
private isPublicModeForbidden(error: unknown): boolean {
|
||||
return error instanceof WeknoraApiError
|
||||
return error instanceof AcademyApiError
|
||||
&& this.config.resourceUrls === 'public'
|
||||
&& !this.publicModeBlocked
|
||||
&& error.status === 403
|
||||
@@ -179,16 +179,16 @@ export class WeknoraClient {
|
||||
signal: deadline(signal, this.config.requestTimeoutMs),
|
||||
})
|
||||
} catch (cause) {
|
||||
throw new WeknoraApiError(`${init.method} ${path} failed: ${describeTransportFailure(cause, signal)}`)
|
||||
throw new AcademyApiError(`${init.method} ${path} failed: ${describeTransportFailure(cause, signal)}`)
|
||||
}
|
||||
const text = await response.text()
|
||||
if (!response.ok) {
|
||||
throw new WeknoraApiError(`${init.method} ${path} failed with HTTP ${response.status}: ${reasonOf(text)}`, response.status)
|
||||
throw new AcademyApiError(`${init.method} ${path} failed with HTTP ${response.status}: ${reasonOf(text)}`, response.status)
|
||||
}
|
||||
try {
|
||||
return JSON.parse(text) as Envelope<T>
|
||||
} catch {
|
||||
throw new WeknoraApiError(`${init.method} ${path} returned a non-JSON body: ${snippet(text)}`, response.status)
|
||||
throw new AcademyApiError(`${init.method} ${path} returned a non-JSON body: ${snippet(text)}`, response.status)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -230,7 +230,7 @@ export class WeknoraClient {
|
||||
return Array.isArray(envelope.data) ? envelope.data : []
|
||||
}
|
||||
|
||||
/** A document's metadata, including the generated summary WeKnora stores as `description`. */
|
||||
/** A document's metadata, including the generated summary Academy stores as `description`. */
|
||||
async getDocument(knowledgeId: string, signal: AbortSignal): Promise<DocumentRecord> {
|
||||
const envelope = await this.fetchJson<DocumentRecord>(
|
||||
`/knowledge/${encodeURIComponent(knowledgeId)}`,
|
||||
@@ -266,7 +266,7 @@ export class WeknoraClient {
|
||||
}, signal)
|
||||
const id = envelope.data?.id
|
||||
if (typeof id !== 'string' || id === '') {
|
||||
throw new WeknoraApiError('POST /sessions returned no session id')
|
||||
throw new AcademyApiError('POST /sessions returned no session id')
|
||||
}
|
||||
return id
|
||||
}
|
||||
@@ -305,23 +305,23 @@ export class WeknoraClient {
|
||||
signal: combined,
|
||||
})
|
||||
} catch (cause) {
|
||||
throw new WeknoraApiError(`POST ${path} failed: ${describeTransportFailure(cause, signal)}`)
|
||||
throw new AcademyApiError(`POST ${path} failed: ${describeTransportFailure(cause, signal)}`)
|
||||
}
|
||||
}
|
||||
let response = await open()
|
||||
if (!response.ok) {
|
||||
const text = await response.text()
|
||||
const error = new WeknoraApiError(`POST ${path} failed with HTTP ${response.status}: ${reasonOf(text)}`, response.status)
|
||||
const error = new AcademyApiError(`POST ${path} failed with HTTP ${response.status}: ${reasonOf(text)}`, response.status)
|
||||
if (!this.isPublicModeForbidden(error)) throw error
|
||||
this.publicModeBlocked = true
|
||||
response = await open()
|
||||
}
|
||||
if (!response.ok) {
|
||||
const text = await response.text()
|
||||
throw new WeknoraApiError(`POST ${path} failed with HTTP ${response.status}: ${reasonOf(text)}`, response.status)
|
||||
throw new AcademyApiError(`POST ${path} failed with HTTP ${response.status}: ${reasonOf(text)}`, response.status)
|
||||
}
|
||||
if (response.body === null) {
|
||||
throw new WeknoraApiError(`POST ${path} returned no response body`)
|
||||
throw new AcademyApiError(`POST ${path} returned no response body`)
|
||||
}
|
||||
return await assembleStream(response.body, input.sessionId, path, signal)
|
||||
}
|
||||
@@ -336,7 +336,7 @@ function describeTransportFailure(cause: unknown, callerSignal: AbortSignal): st
|
||||
return cause instanceof Error ? cause.message : String(cause)
|
||||
}
|
||||
|
||||
/** One decoded `data:` payload of the WeKnora stream. */
|
||||
/** One decoded `data:` payload of the Academy stream. */
|
||||
interface StreamEvent {
|
||||
response_type?: string
|
||||
content?: string
|
||||
@@ -346,7 +346,7 @@ interface StreamEvent {
|
||||
}
|
||||
|
||||
/**
|
||||
* Consume WeKnora's `text/event-stream` and assemble the parts a tool result
|
||||
* Consume Academy's `text/event-stream` and assemble the parts a tool result
|
||||
* needs: the answer text, its citations, and the tool names the agent used.
|
||||
* Server-side `error` events become a thrown failure so the model is never
|
||||
* handed a silently empty answer.
|
||||
@@ -391,7 +391,7 @@ async function assembleStream(
|
||||
}
|
||||
break
|
||||
case 'error':
|
||||
throw new WeknoraApiError(`POST ${path} streamed an error: ${event.content ?? 'unknown error'}`)
|
||||
throw new AcademyApiError(`POST ${path} streamed an error: ${event.content ?? 'unknown error'}`)
|
||||
case 'complete':
|
||||
completed = true
|
||||
break
|
||||
@@ -415,17 +415,17 @@ async function assembleStream(
|
||||
}
|
||||
if (!completed && buffer !== '') consumeLine(buffer.replace(/\r$/, ''))
|
||||
} catch (cause) {
|
||||
if (cause instanceof WeknoraApiError) throw cause
|
||||
throw new WeknoraApiError(`POST ${path} stream failed: ${describeTransportFailure(cause, callerSignal)}`)
|
||||
if (cause instanceof AcademyApiError) throw cause
|
||||
throw new AcademyApiError(`POST ${path} stream failed: ${describeTransportFailure(cause, callerSignal)}`)
|
||||
} finally {
|
||||
await reader.cancel().catch(() => undefined)
|
||||
}
|
||||
|
||||
// WeKnora ends every answer with a `complete` event. Without it the stream was
|
||||
// Academy ends every answer with a `complete` event. Without it the stream was
|
||||
// cut short, and handing the model the partial text would present a truncated
|
||||
// answer as a whole one.
|
||||
if (!completed) {
|
||||
throw new WeknoraApiError(`POST ${path} ended before WeKnora completed the answer; `
|
||||
throw new AcademyApiError(`POST ${path} ended before Academy completed the answer; `
|
||||
+ `${answer.join('').length} character(s) had streamed`)
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ export interface ToolToggles {
|
||||
|
||||
/** User-supplied configuration, as written in a Cordis patch row. */
|
||||
export interface Config {
|
||||
/** WeKnora API root, with or without the `/api/v1` suffix. */
|
||||
/** Academy API root, with or without the `/api/v1` suffix. */
|
||||
baseUrl?: string
|
||||
/** Tenant or platform API key, sent as `X-API-Key`. */
|
||||
apiKey?: string
|
||||
@@ -18,7 +18,7 @@ export interface Config {
|
||||
tenantId?: string
|
||||
/** Default knowledge-base scope when a call names none. */
|
||||
knowledgeBaseIds?: string[]
|
||||
/** Default custom agent for `weknora_ask`; omitted uses the RAG pipeline. */
|
||||
/** Default custom agent for `academy_ask`; omitted uses the RAG pipeline. */
|
||||
agentId?: string
|
||||
/** Default and maximum number of chunks a search returns. */
|
||||
maxResults?: number
|
||||
@@ -29,7 +29,7 @@ export interface Config {
|
||||
/** Timeout for a streamed answer, which includes model and tool time. */
|
||||
chatTimeoutMs?: number
|
||||
/**
|
||||
* `public` asks WeKnora for directly loadable file URLs in answers and
|
||||
* `public` asks Academy for directly loadable file URLs in answers and
|
||||
* citations (the default: dsh can render `https://` Markdown images, not
|
||||
* `resource://` handles). `handle` keeps the internal references.
|
||||
*/
|
||||
@@ -63,13 +63,13 @@ const DEFAULTS = {
|
||||
requestTimeoutMs: 30_000,
|
||||
chatTimeoutMs: 300_000,
|
||||
resourceUrls: 'public',
|
||||
toolPrefix: 'weknora',
|
||||
toolPrefix: 'academy',
|
||||
} as const
|
||||
|
||||
/** Thrown when a patch row configures this plugin in a way it cannot serve. */
|
||||
export class ConfigError extends Error {
|
||||
constructor(violations: string[]) {
|
||||
super(`dsh-weknora configuration is invalid:\n - ${violations.join('\n - ')}`)
|
||||
super(`dsh-academy configuration is invalid:\n - ${violations.join('\n - ')}`)
|
||||
this.name = 'ConfigError'
|
||||
}
|
||||
}
|
||||
@@ -78,7 +78,7 @@ const API_ROOT = /\/api\/v\d+$/
|
||||
const TOOL_PREFIX = /^[a-z][a-z0-9_]*$/
|
||||
|
||||
/**
|
||||
* Normalize a WeKnora base URL to an API root. Both `https://kb.example.com`
|
||||
* Normalize a Academy base URL to an API root. Both `https://kb.example.com`
|
||||
* and `https://kb.example.com/api/v1` are accepted, because a deployment's
|
||||
* documented address is usually the bare origin.
|
||||
*/
|
||||
File renamed without changes.
@@ -1,22 +1,22 @@
|
||||
/**
|
||||
* dsh-weknora: a DeepSeek Harness plugin that gives the agent retrieval,
|
||||
* document reading and composed answers from a WeKnora knowledge base.
|
||||
* @module dsh-weknora
|
||||
* dsh-academy: a DeepSeek Harness plugin that gives the agent retrieval,
|
||||
* document reading and composed answers from a Academy knowledge base.
|
||||
* @module dsh-academy
|
||||
*/
|
||||
|
||||
import { WeknoraClient } from './client.ts'
|
||||
import { AcademyClient } from './client.ts'
|
||||
import { resolveConfig } from './config.ts'
|
||||
import type { HarnessContext } from './harness.ts'
|
||||
import { createTools } from './tools.ts'
|
||||
|
||||
export const name = 'dsh-weknora'
|
||||
export const name = 'dsh-academy'
|
||||
|
||||
/** Cordis waits for the tool registry before applying this plugin. */
|
||||
export const inject = ['tools'] as const
|
||||
|
||||
export type { Config } from './config.ts'
|
||||
export { ConfigError, normalizeBaseUrl, resolveConfig } from './config.ts'
|
||||
export { WeknoraApiError, WeknoraClient } from './client.ts'
|
||||
export { AcademyApiError, AcademyClient } from './client.ts'
|
||||
export { createTools } from './tools.ts'
|
||||
|
||||
/**
|
||||
@@ -27,11 +27,11 @@ export { createTools } from './tools.ts'
|
||||
*/
|
||||
export function apply(ctx: HarnessContext, config: unknown): void {
|
||||
const resolved = resolveConfig(config as never)
|
||||
const client = new WeknoraClient(resolved)
|
||||
const client = new AcademyClient(resolved)
|
||||
const registered: string[] = []
|
||||
for (const definition of createTools(client, resolved)) {
|
||||
ctx.tools.register(definition)
|
||||
registered.push(definition.name)
|
||||
}
|
||||
ctx.logger?.info(`dsh-weknora: registered ${registered.join(', ')} against ${resolved.baseUrl}`)
|
||||
ctx.logger?.info(`dsh-academy: registered ${registered.join(', ')} against ${resolved.baseUrl}`)
|
||||
}
|
||||
File renamed without changes.
@@ -1,6 +1,6 @@
|
||||
/** The model-facing tools this plugin contributes to `ctx.tools`. */
|
||||
|
||||
import type { ChunkRecord, DocumentRecord, SearchResult, WeknoraClient } from './client.ts'
|
||||
import type { ChunkRecord, DocumentRecord, SearchResult, AcademyClient } from './client.ts'
|
||||
import type { ResolvedConfig } from './config.ts'
|
||||
import type { JsonSchemaNode, TextContentBlock, ToolDefinition } from './harness.ts'
|
||||
import { clip, describeScope, formatScore } from './render.ts'
|
||||
@@ -119,7 +119,7 @@ function projectHit(result: SearchResult, rank: number, maxChunkChars: number):
|
||||
|
||||
/**
|
||||
* Keep the by-name matches worth showing: inside the scope the caller asked
|
||||
* for, and not already represented by a passage hit. WeKnora's by-name search
|
||||
* for, and not already represented by a passage hit. Academy's by-name search
|
||||
* spans the whole tenant, so the scope filter is what stops a narrowed call
|
||||
* from reporting documents outside it.
|
||||
*/
|
||||
@@ -153,13 +153,13 @@ function projectNamedDocuments(
|
||||
}
|
||||
|
||||
/** Assemble the four tool definitions for one configured deployment. */
|
||||
export function createTools(client: WeknoraClient, config: ResolvedConfig): ToolDefinition[] {
|
||||
export function createTools(client: AcademyClient, config: ResolvedConfig): ToolDefinition[] {
|
||||
const name = (suffix: string): string => `${config.toolPrefix}_${suffix}`
|
||||
const scopeNote = config.knowledgeBaseIds.length > 0
|
||||
? ` Searches knowledge base(s) ${config.knowledgeBaseIds.join(', ')} unless you name others.`
|
||||
: ' Searches every knowledge base this credential can see unless you narrow it with knowledge_base_ids.'
|
||||
|
||||
// An unscoped call reaches WeKnora as a refusal on the retrieval route and as
|
||||
// An unscoped call reaches Academy as a refusal on the retrieval route and as
|
||||
// an answer grounded in nothing on the RAG route, so an unconfigured
|
||||
// deployment resolves the full visible set once and reuses it. Making the
|
||||
// model pick a scope first is worse: knowledge bases are often named too
|
||||
@@ -188,7 +188,7 @@ export function createTools(client: WeknoraClient, config: ResolvedConfig): Tool
|
||||
if (config.tools.listKnowledgeBases) {
|
||||
definitions.push({
|
||||
name: name('list_knowledge_bases'),
|
||||
description: 'List the WeKnora knowledge bases this deployment can retrieve from, with their ids. '
|
||||
description: 'List the Academy knowledge bases this deployment can retrieve from, with their ids. '
|
||||
+ `${name('search')} already spans them all, so reach for this only to report what is available or to `
|
||||
+ 'narrow a later search to one of them.',
|
||||
parameters: { type: 'object', properties: {}, additionalProperties: false },
|
||||
@@ -218,7 +218,7 @@ export function createTools(client: WeknoraClient, config: ResolvedConfig): Tool
|
||||
},
|
||||
render: (_args, value) => {
|
||||
const result = value as KnowledgeBasesValue
|
||||
if (result.count === 0) return text('No knowledge base is available to this WeKnora credential.')
|
||||
if (result.count === 0) return text('No knowledge base is available to this Academy credential.')
|
||||
const lines = result.knowledge_bases.map(kb => {
|
||||
const description = kb.description === '' ? '' : ` — ${kb.description}`
|
||||
return `- ${kb.name} (id: ${kb.id})${description}`
|
||||
@@ -243,7 +243,7 @@ export function createTools(client: WeknoraClient, config: ResolvedConfig): Tool
|
||||
if (config.tools.search) {
|
||||
definitions.push({
|
||||
name: name('search'),
|
||||
description: 'Search WeKnora knowledge bases and return the matching passages verbatim (hybrid vector + keyword '
|
||||
description: 'Search Academy knowledge bases and return the matching passages verbatim (hybrid vector + keyword '
|
||||
+ 'retrieval, no model summarization). Use this to ground an answer in the organization\'s own documents, and '
|
||||
+ 'also to locate a document by name — a query that reads like a title additionally returns the documents it '
|
||||
+ 'names.' + scopeNote
|
||||
@@ -313,7 +313,7 @@ export function createTools(client: WeknoraClient, config: ResolvedConfig): Tool
|
||||
`- ${document.title} · knowledge_id: ${document.knowledge_id} · in ${document.knowledge_base}`).join('\n')
|
||||
if (result.count === 0) {
|
||||
if (named === '') {
|
||||
return text(`Nothing in WeKnora matched "${result.query}" `
|
||||
return text(`Nothing in Academy matched "${result.query}" `
|
||||
+ `(searched: ${describeScope(result.knowledge_base_ids)}). `
|
||||
+ 'Try a differently worded query, or widen the knowledge base scope.')
|
||||
}
|
||||
@@ -335,16 +335,16 @@ export function createTools(client: WeknoraClient, config: ResolvedConfig): Tool
|
||||
knowledgeIds,
|
||||
exec.signal,
|
||||
)
|
||||
// Fail here rather than let WeKnora answer 400: the model can act on a
|
||||
// Fail here rather than let Academy answer 400: the model can act on a
|
||||
// message naming the argument to supply, not on a transport error.
|
||||
if (knowledgeBaseIds.length === 0 && knowledgeIds.length === 0) {
|
||||
throw new Error(`${toolName}: this WeKnora credential can see no knowledge base, so there is `
|
||||
throw new Error(`${toolName}: this Academy credential can see no knowledge base, so there is `
|
||||
+ 'nothing to search. Check the deployment\'s API key scope.')
|
||||
}
|
||||
const limit = boundedIntArg(args, 'max_results', config.maxResults, config.maxResults)
|
||||
const [hits, named] = await Promise.all([
|
||||
client.search({ query, knowledgeBaseIds, knowledgeIds }, exec.signal),
|
||||
// By-name matching is an enrichment, and older WeKnora builds may not
|
||||
// By-name matching is an enrichment, and older Academy builds may not
|
||||
// route it. Losing it must not cost the model its passages.
|
||||
client.findDocuments({ keyword: query, limit }, exec.signal).catch(() => []),
|
||||
])
|
||||
@@ -363,7 +363,7 @@ export function createTools(client: WeknoraClient, config: ResolvedConfig): Tool
|
||||
if (config.tools.readDocument) {
|
||||
definitions.push({
|
||||
name: name('read_document'),
|
||||
description: 'Read a WeKnora document\'s stored passages in order, reassembled into text. '
|
||||
description: 'Read a Academy document\'s stored passages in order, reassembled into text. '
|
||||
+ `Use it after ${name('search')} when one passage is not enough context; page through long documents.`,
|
||||
parameters: {
|
||||
type: 'object',
|
||||
@@ -455,7 +455,7 @@ export function createTools(client: WeknoraClient, config: ResolvedConfig): Tool
|
||||
const pipeline = config.agentId === undefined ? 'RAG' : 'agent'
|
||||
definitions.push({
|
||||
name: name('ask'),
|
||||
description: `Ask WeKnora a question and get its own composed answer with citations (${pipeline} pipeline runs `
|
||||
description: `Ask Academy a question and get its own composed answer with citations (${pipeline} pipeline runs `
|
||||
+ 'server-side: query rewriting, retrieval, reranking and summarization). Reserve it for broad or '
|
||||
+ 'synthesis questions whose answer spans many documents, where retrieving passages yourself would take '
|
||||
+ `several rounds. For anything you can answer from specific passages, prefer ${name('search')}: it is far `
|
||||
@@ -466,8 +466,8 @@ export function createTools(client: WeknoraClient, config: ResolvedConfig): Tool
|
||||
query: { type: 'string', description: 'The question to answer.' },
|
||||
knowledge_base_ids: { ...STRING_ARRAY, description: 'Restrict retrieval to these knowledge base ids.' },
|
||||
agent_id: { type: 'string', description: 'Custom agent id; selects the server-side ReAct pipeline.' },
|
||||
session_id: { type: 'string', description: 'Continue an earlier WeKnora session instead of starting one.' },
|
||||
web_search: { type: 'boolean', description: 'Let WeKnora also search the web, when its deployment allows it.' },
|
||||
session_id: { type: 'string', description: 'Continue an earlier Academy session instead of starting one.' },
|
||||
web_search: { type: 'boolean', description: 'Let Academy also search the web, when its deployment allows it.' },
|
||||
},
|
||||
required: ['query'],
|
||||
additionalProperties: false,
|
||||
@@ -503,15 +503,15 @@ export function createTools(client: WeknoraClient, config: ResolvedConfig): Tool
|
||||
const result = value as AskValue
|
||||
const parts: string[] = []
|
||||
parts.push(result.answer === ''
|
||||
? 'WeKnora returned an empty answer. Retry with a more specific question, or retrieve passages instead.'
|
||||
? 'Academy returned an empty answer. Retry with a more specific question, or retrieve passages instead.'
|
||||
: result.answer)
|
||||
if (result.references.length > 0) {
|
||||
const cited = result.references.map((reference, index) =>
|
||||
`[${index + 1}] ${reference.document} · chunk ${reference.chunk_index} · knowledge_id: ${reference.knowledge_id}`)
|
||||
parts.push(`Citations:\n${cited.join('\n')}`)
|
||||
}
|
||||
if (result.tool_calls.length > 0) parts.push(`WeKnora tools used: ${result.tool_calls.join(', ')}`)
|
||||
parts.push(`WeKnora session: ${result.session_id} (pass session_id to ask a follow-up in context)`)
|
||||
if (result.tool_calls.length > 0) parts.push(`Academy tools used: ${result.tool_calls.join(', ')}`)
|
||||
parts.push(`Academy session: ${result.session_id} (pass session_id to ask a follow-up in context)`)
|
||||
return text(parts.join('\n\n'))
|
||||
},
|
||||
},
|
||||
@@ -528,7 +528,7 @@ export function createTools(client: WeknoraClient, config: ResolvedConfig): Tool
|
||||
? await resolveScope(requested, [], exec.signal)
|
||||
: requested.length > 0 ? requested : config.knowledgeBaseIds
|
||||
if (agentId === undefined && knowledgeBaseIds.length === 0) {
|
||||
throw new Error(`${toolName}: this WeKnora credential can see no knowledge base, so there is `
|
||||
throw new Error(`${toolName}: this Academy credential can see no knowledge base, so there is `
|
||||
+ 'nothing to answer from. Check the deployment\'s API key scope.')
|
||||
}
|
||||
const webSearch = argRecord(args)['web_search'] === true
|
||||
+8
-8
@@ -1,18 +1,18 @@
|
||||
import assert from 'node:assert/strict'
|
||||
import { after, test } from 'node:test'
|
||||
|
||||
import { WeknoraApiError, WeknoraClient } from '../dist/client.js'
|
||||
import { AcademyApiError, AcademyClient } from '../dist/client.js'
|
||||
import { resolveConfig } from '../dist/config.js'
|
||||
import { startMockWeknora } from './helpers/mock-weknora.mjs'
|
||||
import { startMockAcademy } from './helpers/mock-academy.mjs'
|
||||
|
||||
const never = new AbortController().signal
|
||||
|
||||
/** Start a mock backend and a client wired to it, closed after the test file. */
|
||||
async function harness(overrides = {}, mockOptions = {}) {
|
||||
const mock = await startMockWeknora(mockOptions)
|
||||
const mock = await startMockAcademy(mockOptions)
|
||||
after(() => mock.close())
|
||||
const config = resolveConfig({ baseUrl: mock.url, ...overrides })
|
||||
return { mock, client: new WeknoraClient(config), config }
|
||||
return { mock, client: new AcademyClient(config), config }
|
||||
}
|
||||
|
||||
test('lists knowledge bases and sends the API key header', async () => {
|
||||
@@ -25,7 +25,7 @@ test('lists knowledge bases and sends the API key header', async () => {
|
||||
test('a rejected credential surfaces the status and the server reason', async () => {
|
||||
const { client } = await harness({ apiKey: 'wrong-key' }, { apiKey: 'right-key' })
|
||||
await assert.rejects(client.listKnowledgeBases(never), error => {
|
||||
assert.ok(error instanceof WeknoraApiError)
|
||||
assert.ok(error instanceof AcademyApiError)
|
||||
assert.equal(error.status, 401)
|
||||
assert.match(error.message, /HTTP 401: invalid api key/)
|
||||
return true
|
||||
@@ -125,7 +125,7 @@ test('a stream that ends before completing becomes a failed call', async () => {
|
||||
{ sessionId: 's1', query: '默认的检索阈值是多少', knowledgeBaseIds: ['kb-product'], agentId: undefined, webSearch: false },
|
||||
never,
|
||||
),
|
||||
/ended before WeKnora completed the answer/,
|
||||
/ended before Academy completed the answer/,
|
||||
)
|
||||
})
|
||||
|
||||
@@ -137,6 +137,6 @@ test('caller cancellation aborts an in-flight call', async () => {
|
||||
})
|
||||
|
||||
test('an unreachable backend reports a transport failure', async () => {
|
||||
const client = new WeknoraClient(resolveConfig({ baseUrl: 'http://127.0.0.1:1/api/v1', requestTimeoutMs: 1000 }))
|
||||
await assert.rejects(client.listKnowledgeBases(never), WeknoraApiError)
|
||||
const client = new AcademyClient(resolveConfig({ baseUrl: 'http://127.0.0.1:1/api/v1', requestTimeoutMs: 1000 }))
|
||||
await assert.rejects(client.listKnowledgeBases(never), AcademyApiError)
|
||||
})
|
||||
+1
-1
@@ -14,7 +14,7 @@ test('an empty config resolves to documented defaults', () => {
|
||||
const config = resolveConfig(undefined)
|
||||
assert.equal(config.baseUrl, 'http://localhost:8080/api/v1')
|
||||
assert.equal(config.maxResults, 8)
|
||||
assert.equal(config.toolPrefix, 'weknora')
|
||||
assert.equal(config.toolPrefix, 'academy')
|
||||
assert.equal(config.resourceUrls, 'public')
|
||||
assert.deepEqual(config.knowledgeBaseIds, [])
|
||||
assert.deepEqual(config.tools, { listKnowledgeBases: true, search: true, readDocument: true, ask: true })
|
||||
+18
-18
@@ -1,7 +1,7 @@
|
||||
/**
|
||||
* The plugin side of the API contract: the calls this package makes must stay
|
||||
* exactly the ones recorded in test/fixtures/api-contract.json, which
|
||||
* contract/contract_test.go checks against WeKnora's real Go request and
|
||||
* contract/contract_test.go checks against Academy's real Go request and
|
||||
* response types. Change a request body and both sides tell you.
|
||||
*/
|
||||
|
||||
@@ -11,10 +11,10 @@ import { dirname, join } from 'node:path'
|
||||
import { after, test } from 'node:test'
|
||||
import { fileURLToPath } from 'node:url'
|
||||
|
||||
import { WeknoraClient } from '../dist/client.js'
|
||||
import { AcademyClient } from '../dist/client.js'
|
||||
import { resolveConfig } from '../dist/config.js'
|
||||
import { createTools } from '../dist/tools.js'
|
||||
import { startMockWeknora } from './helpers/mock-weknora.mjs'
|
||||
import { startMockAcademy } from './helpers/mock-academy.mjs'
|
||||
|
||||
const here = dirname(fileURLToPath(import.meta.url))
|
||||
const fixture = JSON.parse(await readFile(join(here, 'fixtures', 'api-contract.json'), 'utf8'))
|
||||
@@ -22,22 +22,22 @@ const exec = { signal: new AbortController().signal }
|
||||
|
||||
/** Replay every documented call against the mock and record what went out. */
|
||||
async function replayCalls() {
|
||||
const mock = await startMockWeknora()
|
||||
const mock = await startMockAcademy()
|
||||
after(() => mock.close())
|
||||
|
||||
const ragConfig = resolveConfig({ baseUrl: mock.url, knowledgeBaseIds: ['kb-product'] })
|
||||
const ragTools = new Map(createTools(new WeknoraClient(ragConfig), ragConfig).map(tool => [tool.name, tool]))
|
||||
await ragTools.get('weknora_list_knowledge_bases').execute({}, exec)
|
||||
await ragTools.get('weknora_search').execute({ query: '默认的检索阈值是多少' }, exec)
|
||||
await ragTools.get('weknora_read_document').execute(
|
||||
const ragTools = new Map(createTools(new AcademyClient(ragConfig), ragConfig).map(tool => [tool.name, tool]))
|
||||
await ragTools.get('academy_list_knowledge_bases').execute({}, exec)
|
||||
await ragTools.get('academy_search').execute({ query: '默认的检索阈值是多少' }, exec)
|
||||
await ragTools.get('academy_read_document').execute(
|
||||
{ knowledge_id: 'doc-retrieval-pipeline', page: 1, page_size: 5 },
|
||||
exec,
|
||||
)
|
||||
await ragTools.get('weknora_ask').execute({ query: '默认的检索阈值是多少' }, exec)
|
||||
await ragTools.get('academy_ask').execute({ query: '默认的检索阈值是多少' }, exec)
|
||||
|
||||
const agentConfig = resolveConfig({ baseUrl: mock.url, agentId: 'agent-42' })
|
||||
const agentAsk = createTools(new WeknoraClient(agentConfig), agentConfig)
|
||||
.find(tool => tool.name === 'weknora_ask')
|
||||
const agentAsk = createTools(new AcademyClient(agentConfig), agentConfig)
|
||||
.find(tool => tool.name === 'academy_ask')
|
||||
await agentAsk.execute({ query: '部署方式', session_id: 's1', web_search: true }, exec)
|
||||
|
||||
return mock.requests.map(request => ({
|
||||
@@ -53,7 +53,7 @@ const observed = await replayCalls()
|
||||
/** Order-insensitive key: a tool that fires two calls at once may land either way round. */
|
||||
const callKey = call => `${call.method} ${call.path} ${JSON.stringify(call.query)} ${JSON.stringify(call.body)}`
|
||||
|
||||
test('the plugin makes exactly the documented WeKnora calls', () => {
|
||||
test('the plugin makes exactly the documented Academy calls', () => {
|
||||
const expected = fixture.calls.map(call => ({
|
||||
method: call.method,
|
||||
path: call.path,
|
||||
@@ -81,10 +81,10 @@ test('the fixture covers every endpoint the plugin touches', () => {
|
||||
})
|
||||
|
||||
test('every stream event the plugin handles is declared in the fixture', async () => {
|
||||
const mock = await startMockWeknora()
|
||||
const mock = await startMockAcademy()
|
||||
after(() => mock.close())
|
||||
const config = resolveConfig({ baseUrl: mock.url, agentId: 'agent-42' })
|
||||
const client = new WeknoraClient(config)
|
||||
const client = new AcademyClient(config)
|
||||
const answer = await client.ask(
|
||||
{ sessionId: 's1', query: '默认的检索阈值是多少', knowledgeBaseIds: [], agentId: 'agent-42', webSearch: false },
|
||||
exec.signal,
|
||||
@@ -100,10 +100,10 @@ test('every stream event the plugin handles is declared in the fixture', async (
|
||||
})
|
||||
|
||||
test('the plugin only reads response fields the fixture declares', async () => {
|
||||
const mock = await startMockWeknora()
|
||||
const mock = await startMockAcademy()
|
||||
after(() => mock.close())
|
||||
const config = resolveConfig({ baseUrl: mock.url })
|
||||
const client = new WeknoraClient(config)
|
||||
const client = new AcademyClient(config)
|
||||
// A backend that serves nothing but the declared fields must still produce a
|
||||
// complete tool result, which is what "these are the fields we depend on" means.
|
||||
const declared = new Set(fixture.responseFieldsRead['types.SearchResult'])
|
||||
@@ -111,8 +111,8 @@ test('the plugin only reads response fields the fixture declares', async () => {
|
||||
const trimmed = results.map(result => Object.fromEntries(
|
||||
Object.entries(result).filter(([key]) => declared.has(key)),
|
||||
))
|
||||
const tools = createTools(new WeknoraClient(config), config)
|
||||
const search = tools.find(tool => tool.name === 'weknora_search')
|
||||
const tools = createTools(new AcademyClient(config), config)
|
||||
const search = tools.find(tool => tool.name === 'academy_search')
|
||||
// Feed the trimmed shape back through the projection the tool uses.
|
||||
const projected = search.output.render({ query: '混合检索' }, {
|
||||
query: '混合检索',
|
||||
+4
-4
@@ -14,7 +14,7 @@ import { createServer } from 'node:http'
|
||||
/** Emit one OpenAI streaming chunk. */
|
||||
function chunk(response, model, delta, finishReason = null) {
|
||||
const payload = {
|
||||
id: 'chatcmpl-weknora-e2e',
|
||||
id: 'chatcmpl-academy-e2e',
|
||||
object: 'chat.completion.chunk',
|
||||
created: Math.floor(Date.now() / 1000),
|
||||
model,
|
||||
@@ -76,8 +76,8 @@ function calledTools(messages) {
|
||||
* @returns the base URL (with `/v1`), the recorded requests, and a close function.
|
||||
*/
|
||||
export async function startFakeModel(options = {}) {
|
||||
const searchTool = options.searchTool ?? 'weknora_search'
|
||||
const readTool = options.readTool ?? 'weknora_read_document'
|
||||
const searchTool = options.searchTool ?? 'academy_search'
|
||||
const readTool = options.readTool ?? 'academy_read_document'
|
||||
const requests = []
|
||||
|
||||
const server = createServer((request, response) => {
|
||||
@@ -125,7 +125,7 @@ export async function startFakeModel(options = {}) {
|
||||
// Answer strictly from what the tools returned, so the transcript proves
|
||||
// the retrieved bytes reached the model rather than a canned string.
|
||||
const grounding = results.join('\n').replace(/\s+/g, ' ').trim().slice(0, 400)
|
||||
streamText(response, body.model, `根据 WeKnora 知识库检索结果回答:${grounding}`)
|
||||
streamText(response, body.model, `根据 Academy 知识库检索结果回答:${grounding}`)
|
||||
})
|
||||
})
|
||||
|
||||
+37
-37
@@ -2,7 +2,7 @@
|
||||
/**
|
||||
* End-to-end check inside a real DeepSeek Harness install: install this package
|
||||
* into a throwaway dsh profile with `dsh plugin add`, boot the headless profile
|
||||
* against a fake OpenAI-compatible model and a mock WeKnora backend, and assert
|
||||
* against a fake OpenAI-compatible model and a mock Academy backend, and assert
|
||||
* that the harness agent loop actually called the tools and answered from what
|
||||
* they returned.
|
||||
*
|
||||
@@ -12,7 +12,7 @@
|
||||
* B. a profile patch that overrides the row, including a renamed tool prefix,
|
||||
* which also proves configuration reaches the plugin.
|
||||
* C. a row with no knowledge base scope, where the plugin resolves the full
|
||||
* visible set itself — WeKnora refuses an unscoped search.
|
||||
* visible set itself — Academy refuses an unscoped search.
|
||||
*
|
||||
* Usage:
|
||||
* node test/e2e/run-in-dsh.mjs # installs dsh into a cache dir
|
||||
@@ -34,13 +34,13 @@ import { dirname, join, resolve } from 'node:path'
|
||||
import { fileURLToPath } from 'node:url'
|
||||
|
||||
import { startFakeModel } from './fake-model.mjs'
|
||||
import { startMockWeknora } from '../helpers/mock-weknora.mjs'
|
||||
import { startMockAcademy } from '../helpers/mock-academy.mjs'
|
||||
|
||||
const packageDir = resolve(dirname(fileURLToPath(import.meta.url)), '../..')
|
||||
const installDir = process.env.DSH_INSTALL_DIR ?? join(tmpdir(), 'dsh-e2e-install')
|
||||
const dshSpec = process.env.DSH_PACKAGE_SPEC ?? '@deepseek-ai/dsh@latest'
|
||||
const API_KEY = 'e2e-api-key'
|
||||
const QUESTION = 'WeKnora 的默认检索阈值是多少?请查知识库后回答。'
|
||||
const QUESTION = 'Academy 的默认检索阈值是多少?请查知识库后回答。'
|
||||
const transcript = []
|
||||
|
||||
function log(line) {
|
||||
@@ -90,20 +90,20 @@ function modelPatchRows(modelUrl) {
|
||||
return [
|
||||
{
|
||||
id: 'agent-default-model',
|
||||
config: { provider: 'weknora-e2e', model: 'weknora-e2e-model' },
|
||||
config: { provider: 'academy-e2e', model: 'academy-e2e-model' },
|
||||
},
|
||||
{
|
||||
id: 'llm-pi-ai',
|
||||
config: {
|
||||
providers: {
|
||||
'weknora-e2e': {
|
||||
displayName: 'WeKnora e2e gateway',
|
||||
apiKeyEnv: 'WEKNORA_E2E_MODEL_KEY',
|
||||
'academy-e2e': {
|
||||
displayName: 'Academy e2e gateway',
|
||||
apiKeyEnv: 'ACADEMY_E2E_MODEL_KEY',
|
||||
api: 'openai-completions',
|
||||
baseURL: modelUrl,
|
||||
models: [{
|
||||
id: 'weknora-e2e-model',
|
||||
name: 'WeKnora e2e model',
|
||||
id: 'academy-e2e-model',
|
||||
name: 'Academy e2e model',
|
||||
contextWindow: 65536,
|
||||
maxTokens: 4096,
|
||||
}],
|
||||
@@ -116,13 +116,13 @@ function modelPatchRows(modelUrl) {
|
||||
|
||||
/**
|
||||
* Boot the headless profile once and assert the whole path: the harness offered
|
||||
* the tools, the tools reached WeKnora, the retrieved passages reached the
|
||||
* the tools, the tools reached Academy, the retrieved passages reached the
|
||||
* model, and the printed answer is grounded in them.
|
||||
*/
|
||||
async function scenario(options) {
|
||||
const { label, dsh, home, env, patch, prefix, weknora, autoScope = false } = options
|
||||
const { label, dsh, home, env, patch, prefix, academy, autoScope = false } = options
|
||||
const model = await startFakeModel({ searchTool: `${prefix}_search`, readTool: `${prefix}_read_document` })
|
||||
const requestsBefore = weknora.requests.length
|
||||
const requestsBefore = academy.requests.length
|
||||
try {
|
||||
await writeFile(
|
||||
join(home, 'profiles', 'headless', 'cordis.patch.yml'),
|
||||
@@ -131,7 +131,7 @@ async function scenario(options) {
|
||||
|
||||
const dump = await run(dsh, ['--profile', 'headless', '--dump-config'], { env })
|
||||
assert.equal(dump.code, 0, `--dump-config must succeed:\n${dump.stderr}`)
|
||||
assert.match(dump.stdout, /name: ["']?@wxg-prc-cpg\/dsh-weknora/, 'the composed tree must mount the plugin')
|
||||
assert.match(dump.stdout, /name: ["']?@wxg-prc-cpg\/dsh-academy/, 'the composed tree must mount the plugin')
|
||||
|
||||
log(`\n=== ${label} ===`)
|
||||
log(`$ dsh --profile headless "${QUESTION}"`)
|
||||
@@ -146,12 +146,12 @@ async function scenario(options) {
|
||||
assert.ok(offered.includes(`${prefix}_${suffix}`), `${prefix}_${suffix} must appear in the model's tool schemas`)
|
||||
}
|
||||
|
||||
const calls = weknora.requests.slice(requestsBefore)
|
||||
const calls = academy.requests.slice(requestsBefore)
|
||||
const paths = calls.map(request => request.path)
|
||||
log(`# WeKnora received: ${paths.join(', ')}`)
|
||||
log(`# Academy received: ${paths.join(', ')}`)
|
||||
assert.ok(paths.includes('/api/v1/knowledge-search'), 'search must reach the retrieval endpoint')
|
||||
if (autoScope) {
|
||||
// WeKnora rejects an unscoped retrieval, so with nothing configured the
|
||||
// Academy rejects an unscoped retrieval, so with nothing configured the
|
||||
// plugin has to resolve the full visible set itself — the model asked a
|
||||
// plain question and never named a knowledge base.
|
||||
assert.ok(
|
||||
@@ -168,7 +168,7 @@ async function scenario(options) {
|
||||
}
|
||||
assert.ok(paths.some(path => path.startsWith('/api/v1/chunks/')), 'read_document must reach the chunk endpoint')
|
||||
assert.equal(
|
||||
weknora.requests.slice(requestsBefore).every(request => request.headers['x-api-key'] === API_KEY),
|
||||
academy.requests.slice(requestsBefore).every(request => request.headers['x-api-key'] === API_KEY),
|
||||
true,
|
||||
'every call must carry the configured API key',
|
||||
)
|
||||
@@ -178,7 +178,7 @@ async function scenario(options) {
|
||||
assert.match(toolResults, /knowledge_id: doc-retrieval-pipeline/, 'search hits must carry a usable knowledge_id')
|
||||
assert.match(boot.stdout, /0\.5/, 'the printed answer must carry the retrieved threshold')
|
||||
|
||||
log(`# PASS (${label}): ${prefix}_search and ${prefix}_read_document ran inside dsh against WeKnora, `
|
||||
log(`# PASS (${label}): ${prefix}_search and ${prefix}_read_document ran inside dsh against Academy, `
|
||||
+ 'and the answer came from the retrieved passages.')
|
||||
} finally {
|
||||
await model.close()
|
||||
@@ -190,18 +190,18 @@ async function main() {
|
||||
throw new Error('build the package first: npm run build')
|
||||
}
|
||||
|
||||
const weknora = await startMockWeknora({ apiKey: API_KEY })
|
||||
const home = await mkdtemp(join(tmpdir(), 'dsh-weknora-home-'))
|
||||
const academy = await startMockAcademy({ apiKey: API_KEY })
|
||||
const home = await mkdtemp(join(tmpdir(), 'dsh-academy-home-'))
|
||||
const dsh = await resolveDsh()
|
||||
const env = {
|
||||
DSH_HOME: home,
|
||||
WEKNORA_E2E_MODEL_KEY: 'not-a-real-key',
|
||||
WEKNORA_BASE_URL: weknora.url,
|
||||
WEKNORA_API_KEY: API_KEY,
|
||||
WEKNORA_KNOWLEDGE_BASE_IDS: 'kb-product',
|
||||
ACADEMY_E2E_MODEL_KEY: 'not-a-real-key',
|
||||
ACADEMY_BASE_URL: academy.url,
|
||||
ACADEMY_API_KEY: API_KEY,
|
||||
ACADEMY_KNOWLEDGE_BASE_IDS: 'kb-product',
|
||||
}
|
||||
|
||||
log(`# mock WeKnora ${weknora.url}`)
|
||||
log(`# mock Academy ${academy.url}`)
|
||||
log(`# DSH_HOME ${home}`)
|
||||
log(`# dsh launcher ${dsh}`)
|
||||
|
||||
@@ -214,12 +214,12 @@ async function main() {
|
||||
const manifest = JSON.parse(await readFile(join(home, 'profiles', 'headless', 'package.json'), 'utf8'))
|
||||
log(`# profile bundles: ${JSON.stringify(manifest.dsh.profile.bundles)}`)
|
||||
assert.ok(
|
||||
manifest.dsh.profile.bundles.includes('@wxg-prc-cpg/dsh-weknora'),
|
||||
manifest.dsh.profile.bundles.includes('@wxg-prc-cpg/dsh-academy'),
|
||||
'the bundle must join the profile layer list',
|
||||
)
|
||||
|
||||
// A. The shipped bundle patch, configured only by environment variables.
|
||||
await scenario({ label: 'A · shipped bundle defaults from env', dsh, home, env, weknora, patch: [], prefix: 'weknora' })
|
||||
await scenario({ label: 'A · shipped bundle defaults from env', dsh, home, env, academy, patch: [], prefix: 'academy' })
|
||||
|
||||
// B. A profile override, which also renames the tools.
|
||||
await scenario({
|
||||
@@ -227,12 +227,12 @@ async function main() {
|
||||
dsh,
|
||||
home,
|
||||
env,
|
||||
weknora,
|
||||
academy,
|
||||
prefix: 'kb',
|
||||
patch: [{
|
||||
id: 'weknora',
|
||||
id: 'academy',
|
||||
config: {
|
||||
baseUrl: weknora.url,
|
||||
baseUrl: academy.url,
|
||||
apiKey: API_KEY,
|
||||
knowledgeBaseIds: ['kb-product'],
|
||||
toolPrefix: 'kb',
|
||||
@@ -243,24 +243,24 @@ async function main() {
|
||||
})
|
||||
|
||||
// C. No configured scope at all, which is what the quickstart's optional
|
||||
// WEKNORA_KNOWLEDGE_BASE_IDS leaves behind.
|
||||
// ACADEMY_KNOWLEDGE_BASE_IDS leaves behind.
|
||||
await scenario({
|
||||
label: 'C · no configured scope, resolved by the plugin',
|
||||
dsh,
|
||||
home,
|
||||
env,
|
||||
weknora,
|
||||
prefix: 'weknora',
|
||||
academy,
|
||||
prefix: 'academy',
|
||||
autoScope: true,
|
||||
patch: [{
|
||||
id: 'weknora',
|
||||
config: { baseUrl: weknora.url, apiKey: API_KEY },
|
||||
id: 'academy',
|
||||
config: { baseUrl: academy.url, apiKey: API_KEY },
|
||||
}],
|
||||
})
|
||||
|
||||
log('\n# ALL SCENARIOS PASSED')
|
||||
} finally {
|
||||
await weknora.close()
|
||||
await academy.close()
|
||||
const logPath = process.env.DSH_E2E_LOG
|
||||
if (logPath !== undefined) await writeFile(logPath, `${transcript.join('\n')}\n`)
|
||||
if (process.env.DSH_E2E_KEEP_HOME === undefined) await rm(home, { recursive: true, force: true })
|
||||
+10
-10
@@ -1,13 +1,13 @@
|
||||
{
|
||||
"$comment": [
|
||||
"The exact WeKnora API calls this plugin makes, and the response fields it reads.",
|
||||
"The exact Academy API calls this plugin makes, and the response fields it reads.",
|
||||
"test/contract.test.mjs asserts the plugin still emits these calls;",
|
||||
"contract/contract_test.go asserts the WeKnora server still accepts them and still",
|
||||
"contract/contract_test.go asserts the Academy server still accepts them and still",
|
||||
"serves those response fields, so a rename on either side fails CI instead of a user's agent."
|
||||
],
|
||||
"calls": [
|
||||
{
|
||||
"tool": "weknora_list_knowledge_bases",
|
||||
"tool": "academy_list_knowledge_bases",
|
||||
"method": "GET",
|
||||
"path": "/api/v1/knowledge-bases",
|
||||
"query": { "resource_urls": "public" },
|
||||
@@ -15,7 +15,7 @@
|
||||
"goRequestType": null
|
||||
},
|
||||
{
|
||||
"tool": "weknora_search",
|
||||
"tool": "academy_search",
|
||||
"method": "POST",
|
||||
"path": "/api/v1/knowledge-search",
|
||||
"query": { "resource_urls": "public" },
|
||||
@@ -26,7 +26,7 @@
|
||||
"goRequestType": "session.SearchKnowledgeRequest"
|
||||
},
|
||||
{
|
||||
"tool": "weknora_search",
|
||||
"tool": "academy_search",
|
||||
"method": "GET",
|
||||
"path": "/api/v1/knowledge/search",
|
||||
"query": { "keyword": "默认的检索阈值是多少", "limit": "8", "resource_urls": "public" },
|
||||
@@ -34,7 +34,7 @@
|
||||
"goRequestType": null
|
||||
},
|
||||
{
|
||||
"tool": "weknora_read_document",
|
||||
"tool": "academy_read_document",
|
||||
"method": "GET",
|
||||
"path": "/api/v1/chunks/doc-retrieval-pipeline",
|
||||
"query": { "page": "1", "page_size": "5", "resource_urls": "public" },
|
||||
@@ -42,7 +42,7 @@
|
||||
"goRequestType": "types.Pagination"
|
||||
},
|
||||
{
|
||||
"tool": "weknora_read_document",
|
||||
"tool": "academy_read_document",
|
||||
"method": "GET",
|
||||
"path": "/api/v1/knowledge/doc-retrieval-pipeline",
|
||||
"query": { "resource_urls": "public" },
|
||||
@@ -50,7 +50,7 @@
|
||||
"goRequestType": null
|
||||
},
|
||||
{
|
||||
"tool": "weknora_ask",
|
||||
"tool": "academy_ask",
|
||||
"method": "POST",
|
||||
"path": "/api/v1/sessions",
|
||||
"query": { "resource_urls": "public" },
|
||||
@@ -60,7 +60,7 @@
|
||||
"goRequestType": "session.CreateSessionRequest"
|
||||
},
|
||||
{
|
||||
"tool": "weknora_ask",
|
||||
"tool": "academy_ask",
|
||||
"method": "POST",
|
||||
"path": "/api/v1/knowledge-chat/session-mock-1",
|
||||
"query": { "resource_urls": "public" },
|
||||
@@ -72,7 +72,7 @@
|
||||
"goRequestType": "session.CreateKnowledgeQARequest"
|
||||
},
|
||||
{
|
||||
"tool": "weknora_ask",
|
||||
"tool": "academy_ask",
|
||||
"method": "POST",
|
||||
"path": "/api/v1/agent-chat/s1",
|
||||
"query": { "resource_urls": "public" },
|
||||
File renamed without changes.
+12
-12
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* A stand-in WeKnora backend used by the unit tests and by the end-to-end run
|
||||
* A stand-in Academy backend used by the unit tests and by the end-to-end run
|
||||
* inside dsh. It speaks the same routes, envelopes and SSE event types as the
|
||||
* real server (see internal/handler/session/qa.go and internal/types/chat.go),
|
||||
* so a test failure here means the plugin, not the fixture, drifted.
|
||||
@@ -10,12 +10,12 @@ import { createServer } from 'node:http'
|
||||
const DOCUMENTS = [
|
||||
{
|
||||
knowledge_id: 'doc-retrieval-pipeline',
|
||||
knowledge_title: 'WeKnora 检索流程.md',
|
||||
knowledge_title: 'Academy 检索流程.md',
|
||||
knowledge_base_id: 'kb-product',
|
||||
// WeKnora stores the generated summary in `description`, not `summary`.
|
||||
description: '讲解 WeKnora 混合检索的召回、阈值与父子分块回溯。',
|
||||
// Academy stores the generated summary in `description`, not `summary`.
|
||||
description: '讲解 Academy 混合检索的召回、阈值与父子分块回溯。',
|
||||
chunks: [
|
||||
'WeKnora 的混合检索先做向量召回,再做关键词召回,最后交给 rerank 模型统一排序。',
|
||||
'Academy 的混合检索先做向量召回,再做关键词召回,最后交给 rerank 模型统一排序。',
|
||||
'默认的 vector_threshold 是 0.5,keyword_threshold 是 0.3,可以在知识库配置里按库调整。',
|
||||
'父子分块开启后,命中子块会回溯父块,把更完整的上下文交给生成模型。',
|
||||
],
|
||||
@@ -31,11 +31,11 @@ const DOCUMENTS = [
|
||||
},
|
||||
{
|
||||
knowledge_id: 'doc-deployment',
|
||||
knowledge_title: 'WeKnora 部署手册.md',
|
||||
knowledge_title: 'Academy 部署手册.md',
|
||||
knowledge_base_id: 'kb-ops',
|
||||
description: '单机与 Kubernetes 部署方式,以及可选的向量库后端。',
|
||||
chunks: [
|
||||
'WeKnora 支持 docker compose 单机部署,也提供 Helm chart 用于 Kubernetes。',
|
||||
'Academy 支持 docker compose 单机部署,也提供 Helm chart 用于 Kubernetes。',
|
||||
'向量库可以选择 pgvector、Milvus、Qdrant、Weaviate、OpenSearch 等后端。',
|
||||
],
|
||||
},
|
||||
@@ -63,14 +63,14 @@ DOCUMENTS.push({
|
||||
})
|
||||
|
||||
const KNOWLEDGE_BASES = [
|
||||
{ id: 'kb-product', name: 'Product docs', description: 'WeKnora 产品与检索文档' },
|
||||
{ id: 'kb-product', name: 'Product docs', description: 'Academy 产品与检索文档' },
|
||||
{ id: 'kb-ops', name: 'Ops runbooks', description: '部署与运维手册' },
|
||||
]
|
||||
|
||||
const ARCH_HANDLE = 'resource://AbCdEfGhIjKlMnOpQrStUv'
|
||||
const ARCH_PUBLIC = 'https://cdn.example.com/architecture.png'
|
||||
|
||||
/** Mirror WeKnora's `resource_urls=public` rewrite of `resource://` handles. */
|
||||
/** Mirror Academy's `resource_urls=public` rewrite of `resource://` handles. */
|
||||
function rewriteResources(value, publicMode) {
|
||||
if (!publicMode) return value
|
||||
return JSON.parse(JSON.stringify(value).replaceAll(ARCH_HANDLE, ARCH_PUBLIC))
|
||||
@@ -141,10 +141,10 @@ function answerFor(query, results) {
|
||||
* @param options.streamError - make the chat routes stream an `error` event.
|
||||
* @param options.streamTruncated - end the chat stream mid-answer, with no `complete`.
|
||||
* @param options.forbidPublicResourceUrls - reject `resource_urls=public` with the
|
||||
* 403 WeKnora returns for a knowledge-base-restricted API key.
|
||||
* 403 Academy returns for a knowledge-base-restricted API key.
|
||||
* @returns the base URL, the recorded requests, and a close function.
|
||||
*/
|
||||
export async function startMockWeknora(options = {}) {
|
||||
export async function startMockAcademy(options = {}) {
|
||||
const requests = []
|
||||
// Paths forced to fail, so a test can prove the plugin degrades rather than
|
||||
// breaks when a deployment does not serve one of the optional routes.
|
||||
@@ -309,7 +309,7 @@ export async function startMockWeknora(options = {}) {
|
||||
}
|
||||
// The RAG route retrieves only what the request scopes: a session holds
|
||||
// no knowledge base of its own (CreateSessionRequest carries none), so
|
||||
// WeKnora has no default to fall back on and answers from nothing.
|
||||
// Academy has no default to fall back on and answers from nothing.
|
||||
// Retrieving here anyway would hide an unscoped ask from the tests. The
|
||||
// agent route does have a server-side default, its KBSelectionMode.
|
||||
const scoped = (body.knowledge_base_ids ?? []).length > 0 || (body.knowledge_ids ?? []).length > 0
|
||||
+57
-57
@@ -1,22 +1,22 @@
|
||||
import assert from 'node:assert/strict'
|
||||
import { after, test } from 'node:test'
|
||||
|
||||
import { WeknoraClient } from '../dist/client.js'
|
||||
import { AcademyClient } from '../dist/client.js'
|
||||
import { resolveConfig } from '../dist/config.js'
|
||||
import { apply } from '../dist/index.js'
|
||||
import { createTools } from '../dist/tools.js'
|
||||
import { assertLosslessJson, assertSupportedSchema, validate } from './helpers/json-schema.mjs'
|
||||
import { startMockWeknora, ARCH_HANDLE, ARCH_PUBLIC } from './helpers/mock-weknora.mjs'
|
||||
import { startMockAcademy, ARCH_HANDLE, ARCH_PUBLIC } from './helpers/mock-academy.mjs'
|
||||
|
||||
const never = new AbortController().signal
|
||||
const exec = { signal: never }
|
||||
|
||||
/** Build the tools against a live mock backend. */
|
||||
async function toolset(overrides = {}) {
|
||||
const mock = await startMockWeknora()
|
||||
const mock = await startMockAcademy()
|
||||
after(() => mock.close())
|
||||
const config = resolveConfig({ baseUrl: mock.url, ...overrides })
|
||||
const tools = createTools(new WeknoraClient(config), config)
|
||||
const tools = createTools(new AcademyClient(config), config)
|
||||
return { mock, config, byName: new Map(tools.map(tool => [tool.name, tool])), tools }
|
||||
}
|
||||
|
||||
@@ -44,23 +44,23 @@ test('every declared schema stays inside the supported subset', async () => {
|
||||
test('the default composition registers exactly the four documented tools', async () => {
|
||||
const { tools } = await toolset()
|
||||
assert.deepEqual(tools.map(tool => tool.name).sort(), [
|
||||
'weknora_ask',
|
||||
'weknora_list_knowledge_bases',
|
||||
'weknora_read_document',
|
||||
'weknora_search',
|
||||
'academy_ask',
|
||||
'academy_list_knowledge_bases',
|
||||
'academy_read_document',
|
||||
'academy_search',
|
||||
])
|
||||
})
|
||||
|
||||
test('list_knowledge_bases renders ids the model can pass back', async () => {
|
||||
const { byName } = await toolset()
|
||||
const { value, text } = await call(byName.get('weknora_list_knowledge_bases'), {})
|
||||
const { value, text } = await call(byName.get('academy_list_knowledge_bases'), {})
|
||||
assert.equal(value.count, 2)
|
||||
assert.match(text, /Product docs \(id: kb-product\)/)
|
||||
})
|
||||
|
||||
test('search returns ranked passages carrying their knowledge_id', async () => {
|
||||
const { byName } = await toolset({ knowledgeBaseIds: ['kb-product'] })
|
||||
const { value, text } = await call(byName.get('weknora_search'), { query: '默认的检索阈值是多少' })
|
||||
const { value, text } = await call(byName.get('academy_search'), { query: '默认的检索阈值是多少' })
|
||||
assert.ok(value.count > 0)
|
||||
assert.equal(value.results[0].rank, 1)
|
||||
assert.ok(value.results[0].knowledge_id.startsWith('doc-'))
|
||||
@@ -70,47 +70,47 @@ test('search returns ranked passages carrying their knowledge_id', async () => {
|
||||
|
||||
test('search respects max_results and the configured ceiling', async () => {
|
||||
const { byName } = await toolset({ maxResults: 2, knowledgeBaseIds: ['kb-product'] })
|
||||
const wide = await call(byName.get('weknora_search'), { query: '检索 部署 向量 阈值' })
|
||||
const wide = await call(byName.get('academy_search'), { query: '检索 部署 向量 阈值' })
|
||||
assert.ok(wide.value.count <= 2)
|
||||
const narrow = await call(byName.get('weknora_search'), { query: '检索 部署 向量 阈值', max_results: 1 })
|
||||
const narrow = await call(byName.get('academy_search'), { query: '检索 部署 向量 阈值', max_results: 1 })
|
||||
assert.equal(narrow.value.count, 1)
|
||||
})
|
||||
|
||||
test('search falls back to the configured knowledge base scope', async () => {
|
||||
const { byName, mock } = await toolset({ knowledgeBaseIds: ['kb-ops'] })
|
||||
await call(byName.get('weknora_search'), { query: '部署 方式' })
|
||||
await call(byName.get('academy_search'), { query: '部署 方式' })
|
||||
assert.deepEqual(mock.requests.at(-1).body.knowledge_base_ids, ['kb-ops'])
|
||||
})
|
||||
|
||||
test('an empty result set tells the model what to try next', async () => {
|
||||
const { byName } = await toolset({ knowledgeBaseIds: ['kb-product'] })
|
||||
const { value, text } = await call(byName.get('weknora_search'), { query: '量子纠缠咖啡机保修期' })
|
||||
const { value, text } = await call(byName.get('academy_search'), { query: '量子纠缠咖啡机保修期' })
|
||||
assert.equal(value.count, 0)
|
||||
assert.match(text, /Nothing in WeKnora matched/)
|
||||
assert.match(text, /Nothing in Academy matched/)
|
||||
})
|
||||
|
||||
test('search rejects a missing query before touching the network', async () => {
|
||||
const { byName } = await toolset()
|
||||
await assert.rejects(byName.get('weknora_search').execute({}, exec), /"query" is required/)
|
||||
await assert.rejects(byName.get('academy_search').execute({}, exec), /"query" is required/)
|
||||
})
|
||||
|
||||
// WeKnora answers 400 when a retrieval names no knowledge base, document or
|
||||
// Academy answers 400 when a retrieval names no knowledge base, document or
|
||||
// tag. Rather than make the model choose a scope it has no basis to choose,
|
||||
// an unconfigured deployment searches everything the credential can see.
|
||||
test('search spans every visible knowledge base when none is configured', async () => {
|
||||
const { byName, mock } = await toolset()
|
||||
const { value } = await call(byName.get('weknora_search'), { query: '默认的检索阈值是多少' })
|
||||
const { value } = await call(byName.get('academy_search'), { query: '默认的检索阈值是多少' })
|
||||
assert.deepEqual(value.knowledge_base_ids, ['kb-product', 'kb-ops'])
|
||||
const retrieval = mock.requests.find(request => request.path === '/api/v1/knowledge-search')
|
||||
assert.deepEqual(retrieval.body.knowledge_base_ids, ['kb-product', 'kb-ops'])
|
||||
assert.match(byName.get('weknora_search').description, /every knowledge base this credential can see/)
|
||||
assert.match(byName.get('academy_search').description, /every knowledge base this credential can see/)
|
||||
})
|
||||
|
||||
// A deployment can hold dozens of knowledge bases; spelling every id out on
|
||||
// every search would cost more context than the passages themselves.
|
||||
test('a wide scope is named by count rather than spelled out', async () => {
|
||||
const { byName } = await toolset({ knowledgeBaseIds: ['kb-a', 'kb-b', 'kb-c', 'kb-d'] })
|
||||
const { value, text } = await call(byName.get('weknora_search'), { query: '默认的检索阈值是多少' })
|
||||
const { value, text } = await call(byName.get('academy_search'), { query: '默认的检索阈值是多少' })
|
||||
assert.match(text, /searched: 4 knowledge bases/)
|
||||
assert.doesNotMatch(text, /kb-a/)
|
||||
assert.deepEqual(value.knowledge_base_ids, ['kb-a', 'kb-b', 'kb-c', 'kb-d'], 'the ids stay in the canonical value')
|
||||
@@ -118,15 +118,15 @@ test('a wide scope is named by count rather than spelled out', async () => {
|
||||
|
||||
test('the resolved full scope is fetched once and reused', async () => {
|
||||
const { byName, mock } = await toolset()
|
||||
await call(byName.get('weknora_search'), { query: '混合检索 向量' })
|
||||
await call(byName.get('weknora_search'), { query: '部署 方式' })
|
||||
await call(byName.get('academy_search'), { query: '混合检索 向量' })
|
||||
await call(byName.get('academy_search'), { query: '部署 方式' })
|
||||
const listings = mock.requests.filter(request => request.path === '/api/v1/knowledge-bases')
|
||||
assert.equal(listings.length, 1, 'resolving the scope must not re-list on every search')
|
||||
})
|
||||
|
||||
test('knowledge_ids alone is a scope WeKnora accepts', async () => {
|
||||
test('knowledge_ids alone is a scope Academy accepts', async () => {
|
||||
const { byName, mock } = await toolset()
|
||||
await call(byName.get('weknora_search'), {
|
||||
await call(byName.get('academy_search'), {
|
||||
query: '默认的检索阈值是多少',
|
||||
knowledge_ids: ['doc-retrieval-pipeline'],
|
||||
})
|
||||
@@ -137,16 +137,16 @@ test('knowledge_ids alone is a scope WeKnora accepts', async () => {
|
||||
|
||||
test('a configured default scope is used verbatim', async () => {
|
||||
const { byName, mock } = await toolset({ knowledgeBaseIds: ['kb-product'] })
|
||||
await call(byName.get('weknora_search'), { query: '默认的检索阈值是多少' })
|
||||
await call(byName.get('academy_search'), { query: '默认的检索阈值是多少' })
|
||||
assert.equal(mock.requests.some(request => request.path === '/api/v1/knowledge-bases'), false)
|
||||
assert.match(byName.get('weknora_search').description, /Searches knowledge base\(s\) kb-product/)
|
||||
assert.match(byName.get('academy_search').description, /Searches knowledge base\(s\) kb-product/)
|
||||
})
|
||||
|
||||
// A document nobody quotes is still the document the user asked for by name,
|
||||
// which is exactly what passage retrieval on its own cannot find.
|
||||
test('a query naming a document finds it even with no passage match', async () => {
|
||||
const { byName } = await toolset({ knowledgeBaseIds: ['kb-ops'] })
|
||||
const { value, text } = await call(byName.get('weknora_search'), { query: '灰度发布检查单' })
|
||||
const { value, text } = await call(byName.get('academy_search'), { query: '灰度发布检查单' })
|
||||
assert.equal(value.count, 0)
|
||||
assert.deepEqual(value.documents.map(document => document.knowledge_id), ['doc-release-checklist'])
|
||||
assert.match(text, /No passage matched "灰度发布检查单", but its name matches document/)
|
||||
@@ -155,20 +155,20 @@ test('a query naming a document finds it even with no passage match', async () =
|
||||
|
||||
test('by-name matches stay inside the scope the call asked for', async () => {
|
||||
const { byName } = await toolset({ knowledgeBaseIds: ['kb-product'] })
|
||||
const { value } = await call(byName.get('weknora_search'), { query: '灰度发布检查单' })
|
||||
const { value } = await call(byName.get('academy_search'), { query: '灰度发布检查单' })
|
||||
assert.deepEqual(value.documents, [], 'a document in kb-ops must not surface in a kb-product search')
|
||||
})
|
||||
|
||||
test('a passage hit is not repeated in the by-name section', async () => {
|
||||
const { byName } = await toolset({ knowledgeBaseIds: ['kb-product', 'kb-ops'] })
|
||||
const { value } = await call(byName.get('weknora_search'), { query: 'WeKnora 检索流程' })
|
||||
const { value } = await call(byName.get('academy_search'), { query: 'Academy 检索流程' })
|
||||
const passages = new Set(value.results.map(hit => hit.knowledge_id))
|
||||
assert.equal(value.documents.some(document => passages.has(document.knowledge_id)), false)
|
||||
})
|
||||
|
||||
test('long passages are clipped and marked truncated', async () => {
|
||||
const { byName } = await toolset({ maxChunkChars: 20, knowledgeBaseIds: ['kb-product'] })
|
||||
const { value, text } = await call(byName.get('weknora_search'), { query: '混合检索 向量 关键词' })
|
||||
const { value, text } = await call(byName.get('academy_search'), { query: '混合检索 向量 关键词' })
|
||||
assert.ok(value.results[0].truncated)
|
||||
assert.ok(value.results[0].content.length <= 21)
|
||||
assert.match(text, /passage truncated/)
|
||||
@@ -176,7 +176,7 @@ test('long passages are clipped and marked truncated', async () => {
|
||||
|
||||
test('read_document reassembles passages in order and reports paging', async () => {
|
||||
const { byName } = await toolset({ maxChunkChars: 4000 })
|
||||
const first = await call(byName.get('weknora_read_document'), {
|
||||
const first = await call(byName.get('academy_read_document'), {
|
||||
knowledge_id: 'doc-retrieval-pipeline',
|
||||
page: 1,
|
||||
page_size: 2,
|
||||
@@ -185,7 +185,7 @@ test('read_document reassembles passages in order and reports paging', async ()
|
||||
assert.equal(first.value.returned_chunks, 2)
|
||||
assert.equal(first.value.has_more, true)
|
||||
assert.match(first.text, /request page 2/)
|
||||
const second = await call(byName.get('weknora_read_document'), {
|
||||
const second = await call(byName.get('academy_read_document'), {
|
||||
knowledge_id: 'doc-retrieval-pipeline',
|
||||
page: 2,
|
||||
page_size: 2,
|
||||
@@ -194,24 +194,24 @@ test('read_document reassembles passages in order and reports paging', async ()
|
||||
})
|
||||
|
||||
// A long document costs many pages to identify from its passages alone, so
|
||||
// page 1 carries the title and WeKnora's generated summary.
|
||||
// page 1 carries the title and Academy's generated summary.
|
||||
test('read_document leads with the document title and summary', async () => {
|
||||
const { byName } = await toolset()
|
||||
const { value, text } = await call(byName.get('weknora_read_document'), {
|
||||
const { value, text } = await call(byName.get('academy_read_document'), {
|
||||
knowledge_id: 'doc-retrieval-pipeline',
|
||||
page: 1,
|
||||
page_size: 2,
|
||||
})
|
||||
assert.equal(value.title, 'WeKnora 检索流程.md')
|
||||
assert.equal(value.title, 'Academy 检索流程.md')
|
||||
assert.match(value.summary, /混合检索/)
|
||||
assert.match(text, /Document WeKnora 检索流程\.md \(doc-retrieval-pipeline\)/)
|
||||
assert.match(text, /Document Academy 检索流程\.md \(doc-retrieval-pipeline\)/)
|
||||
assert.match(text, /Summary: /)
|
||||
})
|
||||
|
||||
test('read_document still returns text when the metadata call fails', async () => {
|
||||
const { byName, mock } = await toolset()
|
||||
mock.fail('/api/v1/knowledge/doc-retrieval-pipeline', 500)
|
||||
const { value } = await call(byName.get('weknora_read_document'), { knowledge_id: 'doc-retrieval-pipeline' })
|
||||
const { value } = await call(byName.get('academy_read_document'), { knowledge_id: 'doc-retrieval-pipeline' })
|
||||
assert.equal(value.title, '')
|
||||
assert.equal(value.summary, '')
|
||||
assert.ok(value.content.length > 0, 'losing the metadata must not cost the model the document')
|
||||
@@ -219,17 +219,17 @@ test('read_document still returns text when the metadata call fails', async () =
|
||||
|
||||
test('read_document leads with the title and summary, and only on page 1', async () => {
|
||||
const { byName, mock } = await toolset({ maxChunkChars: 4000 })
|
||||
const first = await call(byName.get('weknora_read_document'), {
|
||||
const first = await call(byName.get('academy_read_document'), {
|
||||
knowledge_id: 'doc-retrieval-pipeline',
|
||||
page: 1,
|
||||
page_size: 2,
|
||||
})
|
||||
assert.equal(first.value.title, 'WeKnora 检索流程.md')
|
||||
assert.match(first.text, /^Document WeKnora 检索流程\.md \(doc-retrieval-pipeline\)/)
|
||||
assert.match(first.text, /Summary: 讲解 WeKnora 混合检索/)
|
||||
assert.equal(first.value.title, 'Academy 检索流程.md')
|
||||
assert.match(first.text, /^Document Academy 检索流程\.md \(doc-retrieval-pipeline\)/)
|
||||
assert.match(first.text, /Summary: 讲解 Academy 混合检索/)
|
||||
|
||||
const before = mock.requests.length
|
||||
const second = await call(byName.get('weknora_read_document'), {
|
||||
const second = await call(byName.get('academy_read_document'), {
|
||||
knowledge_id: 'doc-retrieval-pipeline',
|
||||
page: 2,
|
||||
page_size: 2,
|
||||
@@ -246,14 +246,14 @@ test('read_document leads with the title and summary, and only on page 1', async
|
||||
test('read_document surfaces a backend 404 as a failed call', async () => {
|
||||
const { byName } = await toolset()
|
||||
await assert.rejects(
|
||||
byName.get('weknora_read_document').execute({ knowledge_id: 'missing-doc' }, exec),
|
||||
byName.get('academy_read_document').execute({ knowledge_id: 'missing-doc' }, exec),
|
||||
/HTTP 404/,
|
||||
)
|
||||
})
|
||||
|
||||
test('ask returns the composed answer, citations and a resumable session', async () => {
|
||||
const { byName, mock } = await toolset()
|
||||
const { value, text } = await call(byName.get('weknora_ask'), { query: '默认的检索阈值是多少' })
|
||||
const { value, text } = await call(byName.get('academy_ask'), { query: '默认的检索阈值是多少' })
|
||||
assert.equal(value.pipeline, 'rag')
|
||||
assert.equal(value.session_id, 'session-mock-1')
|
||||
assert.ok(value.references.length > 0)
|
||||
@@ -264,18 +264,18 @@ test('ask returns the composed answer, citations and a resumable session', async
|
||||
|
||||
test('ask reuses a given session instead of creating one', async () => {
|
||||
const { byName, mock } = await toolset()
|
||||
await call(byName.get('weknora_ask'), { query: '部署方式', session_id: 'session-existing' })
|
||||
await call(byName.get('academy_ask'), { query: '部署方式', session_id: 'session-existing' })
|
||||
assert.equal(mock.requests.some(request => request.path === '/api/v1/sessions'), false)
|
||||
assert.equal(mock.requests.at(-1).path, '/api/v1/knowledge-chat/session-existing')
|
||||
})
|
||||
|
||||
// The RAG pipeline retrieves only what the request scopes, so an unconfigured
|
||||
// deployment must resolve the visible set for ask exactly as it does for search.
|
||||
// Otherwise the quickstart's optional WEKNORA_KNOWLEDGE_BASE_IDS leaves ask
|
||||
// Otherwise the quickstart's optional ACADEMY_KNOWLEDGE_BASE_IDS leaves ask
|
||||
// answering from nothing while search works.
|
||||
test('ask resolves its own scope when none is configured', async () => {
|
||||
const { byName, mock } = await toolset()
|
||||
const { value, text } = await call(byName.get('weknora_ask'), { query: '默认的检索阈值是多少' })
|
||||
const { value, text } = await call(byName.get('academy_ask'), { query: '默认的检索阈值是多少' })
|
||||
const chat = mock.requests.find(request => request.path.startsWith('/api/v1/knowledge-chat/'))
|
||||
assert.deepEqual(chat.body.knowledge_base_ids, ['kb-product', 'kb-ops'])
|
||||
assert.ok(value.references.length > 0, 'an unconfigured ask must still retrieve')
|
||||
@@ -284,15 +284,15 @@ test('ask resolves its own scope when none is configured', async () => {
|
||||
|
||||
test('ask reuses the scope search already resolved', async () => {
|
||||
const { byName, mock } = await toolset()
|
||||
await call(byName.get('weknora_search'), { query: '混合检索 向量' })
|
||||
await call(byName.get('weknora_ask'), { query: '默认的检索阈值是多少' })
|
||||
await call(byName.get('academy_search'), { query: '混合检索 向量' })
|
||||
await call(byName.get('academy_ask'), { query: '默认的检索阈值是多少' })
|
||||
const listings = mock.requests.filter(request => request.path === '/api/v1/knowledge-bases')
|
||||
assert.equal(listings.length, 1, 'search and ask must share the resolved scope')
|
||||
})
|
||||
|
||||
test('a configured scope reaches ask without a listing call', async () => {
|
||||
const { byName, mock } = await toolset({ knowledgeBaseIds: ['kb-product'] })
|
||||
await call(byName.get('weknora_ask'), { query: '默认的检索阈值是多少' })
|
||||
await call(byName.get('academy_ask'), { query: '默认的检索阈值是多少' })
|
||||
assert.equal(mock.requests.some(request => request.path === '/api/v1/knowledge-bases'), false)
|
||||
const chat = mock.requests.find(request => request.path.startsWith('/api/v1/knowledge-chat/'))
|
||||
assert.deepEqual(chat.body.knowledge_base_ids, ['kb-product'])
|
||||
@@ -302,7 +302,7 @@ test('a configured scope reaches ask without a listing call', async () => {
|
||||
// ids sent from here would override that as an explicit @mention.
|
||||
test('an agent-pipeline ask leaves the scope to the server', async () => {
|
||||
const { byName, mock } = await toolset({ agentId: 'agent-42' })
|
||||
await call(byName.get('weknora_ask'), { query: '部署方式有哪些' })
|
||||
await call(byName.get('academy_ask'), { query: '部署方式有哪些' })
|
||||
assert.equal(mock.requests.some(request => request.path === '/api/v1/knowledge-bases'), false)
|
||||
const chat = mock.requests.find(request => request.path.startsWith('/api/v1/agent-chat/'))
|
||||
assert.equal(chat.body.knowledge_base_ids, undefined)
|
||||
@@ -310,10 +310,10 @@ test('an agent-pipeline ask leaves the scope to the server', async () => {
|
||||
|
||||
test('a configured agent id switches ask to the agent pipeline', async () => {
|
||||
const { byName } = await toolset({ agentId: 'agent-42' })
|
||||
const { value, text } = await call(byName.get('weknora_ask'), { query: '部署方式有哪些' })
|
||||
const { value, text } = await call(byName.get('academy_ask'), { query: '部署方式有哪些' })
|
||||
assert.equal(value.pipeline, 'agent')
|
||||
assert.deepEqual(value.tool_calls, ['knowledge_search'])
|
||||
assert.match(text, /WeKnora tools used: knowledge_search/)
|
||||
assert.match(text, /Academy tools used: knowledge_search/)
|
||||
})
|
||||
|
||||
test('apply registers into ctx.tools and honours the prefix and toggles', () => {
|
||||
@@ -334,12 +334,12 @@ test('apply registers into ctx.tools and honours the prefix and toggles', () =>
|
||||
|
||||
test('apply fails the plugin load on an invalid row', () => {
|
||||
const ctx = { tools: { register: () => () => undefined } }
|
||||
assert.throws(() => apply(ctx, { baseUrl: 'ftp://kb.example.com' }), /dsh-weknora configuration is invalid/)
|
||||
assert.throws(() => apply(ctx, { baseUrl: 'ftp://kb.example.com' }), /dsh-academy configuration is invalid/)
|
||||
})
|
||||
|
||||
test('search rewrites cited figures to public URLs in passage content', async () => {
|
||||
const { byName } = await toolset({ knowledgeBaseIds: ['kb-product'] })
|
||||
const { value, text } = await call(byName.get('weknora_search'), { query: '系统架构图' })
|
||||
const { value, text } = await call(byName.get('academy_search'), { query: '系统架构图' })
|
||||
const hit = value.results.find(result => result.knowledge_id === 'doc-architecture')
|
||||
assert.ok(hit, 'the architecture document must be in the ranked hits')
|
||||
assert.ok(hit.content.includes(``))
|
||||
@@ -348,14 +348,14 @@ test('search rewrites cited figures to public URLs in passage content', async ()
|
||||
|
||||
test('ask copies public figure URLs from the retrieved passages', async () => {
|
||||
const { byName } = await toolset({ knowledgeBaseIds: ['kb-product'] })
|
||||
const { value, text } = await call(byName.get('weknora_ask'), { query: '系统架构图长什么样' })
|
||||
const { value, text } = await call(byName.get('academy_ask'), { query: '系统架构图长什么样' })
|
||||
assert.ok(value.answer.includes(``))
|
||||
assert.ok(text.includes(``))
|
||||
})
|
||||
|
||||
test('handle mode keeps internal resource handles instead of public URLs', async () => {
|
||||
const { byName } = await toolset({ knowledgeBaseIds: ['kb-product'], resourceUrls: 'handle' })
|
||||
const { value } = await call(byName.get('weknora_search'), { query: '系统架构图' })
|
||||
const { value } = await call(byName.get('academy_search'), { query: '系统架构图' })
|
||||
const hit = value.results.find(result => result.knowledge_id === 'doc-architecture')
|
||||
assert.ok(hit.content.includes(``))
|
||||
})
|
||||
File renamed without changes.
File renamed without changes.
Reference in new issue
Block a user