hiwork-knowledge 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +79 -0
- package/cordis.patch.yml +8 -0
- package/lib/client.js +175 -0
- package/lib/index.js +14 -0
- package/lib/types/client/KnowledgeView.d.ts +13 -0
- package/lib/types/client/contracts.d.ts +100 -0
- package/lib/types/client/index.d.ts +12 -0
- package/lib/types/client/locales.d.ts +23 -0
- package/lib/types/client/styles.d.ts +4 -0
- package/lib/types/index.d.ts +22 -0
- package/package.json +79 -0
package/README.md
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
# hiwork-knowledge
|
|
2
|
+
|
|
3
|
+
HiWork 的**知识库**插件。本阶段只提供入口与占位页:中央内容区出现「知识库」菜单项,
|
|
4
|
+
点开是一句占位文案(此处对接海普知识库相关内容),真正的知识库能力(海普对接、
|
|
5
|
+
检索、索引)后续在 `KnowledgeView` 的占位区域落地。
|
|
6
|
+
|
|
7
|
+
- 包名 / bundle id:`hiwork-knowledge`
|
|
8
|
+
- client 插件名:`hiwork-knowledge-client`
|
|
9
|
+
- 中央页 feature:`id = knowledge`,`order = 30`(排在「新会话」与定时任务 20 之后)
|
|
10
|
+
|
|
11
|
+
## 目录
|
|
12
|
+
|
|
13
|
+
```
|
|
14
|
+
src/
|
|
15
|
+
index.ts Host 入口(本阶段只声明插件名 + 启动日志)
|
|
16
|
+
client/
|
|
17
|
+
index.ts Web 入口:注册 feature / 设置页降级
|
|
18
|
+
KnowledgeView.tsx 知识库页(占位)
|
|
19
|
+
locales.ts 命名空间 hiwork-knowledge 的 zh/en 词典
|
|
20
|
+
contracts.ts 宿主 client 能力的结构契约(type-only)
|
|
21
|
+
styles.ts / styles.css 样式注入
|
|
22
|
+
scripts/
|
|
23
|
+
host-build.mjs Host 产物自包含打包(esbuild)
|
|
24
|
+
client-build.mjs Client 产物闭包工厂打包(esbuild)
|
|
25
|
+
tests/ 入口、视图、feature 注册、打包契约
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## 入口
|
|
29
|
+
|
|
30
|
+
| 项 | 值 |
|
|
31
|
+
| --- | --- |
|
|
32
|
+
| feature id | `knowledge` |
|
|
33
|
+
| order | `30` |
|
|
34
|
+
| 菜单文案 | `知识库`(跟随语言切换,词典键 `view.title`) |
|
|
35
|
+
| 图标 | 内联 SVG(书本),侧栏折叠成图标栏时只显示它 |
|
|
36
|
+
| render | 复用 `KnowledgeView`,不依赖 `FeatureRenderContext` |
|
|
37
|
+
|
|
38
|
+
注册走 `hiwork-core` 的 `hiworkFeatureCenter` 服务(结构契约见
|
|
39
|
+
`src/client/contracts.ts`,运行时**不** import `hiwork-core`,符合 DSH client
|
|
40
|
+
模块表「feature 插件之间禁止 runtime-import」的约束)。
|
|
41
|
+
|
|
42
|
+
## 独立安装降级
|
|
43
|
+
|
|
44
|
+
没有 `hiwork-core` 时(或它尚未加载),本插件注册设置页分区
|
|
45
|
+
`settings.section#knowledge`;`hiwork-core` 后到时立刻撤下该分区并切成中央 feature,
|
|
46
|
+
保证同一功能不会同时出现两个主入口。
|
|
47
|
+
|
|
48
|
+
## client bundle 纯度
|
|
49
|
+
|
|
50
|
+
`src/client/**` 对 `@deepseek-ai/*` 只允许 `import type`(打包时被擦除),运行时只
|
|
51
|
+
import `react` / `react/jsx-runtime`。`tests/packaging.spec.ts` 会在构建后扫描
|
|
52
|
+
`lib/client.js` 的 `require` 说明符,越界即失败。
|
|
53
|
+
|
|
54
|
+
## 命令
|
|
55
|
+
|
|
56
|
+
| 命令 | 作用 |
|
|
57
|
+
| --- | --- |
|
|
58
|
+
| `pnpm typecheck` | 严格类型检查 |
|
|
59
|
+
| `pnpm build` | 构建 `lib/index.js`(Host)与 `lib/client.js`(Web) |
|
|
60
|
+
| `pnpm test` | Vitest(DOM 用例首行 `// @vitest-environment jsdom`) |
|
|
61
|
+
| `pnpm verify` | typecheck → build → test(提交前跑这个) |
|
|
62
|
+
|
|
63
|
+
## 本地试用(不打包桌面端)
|
|
64
|
+
|
|
65
|
+
```bash
|
|
66
|
+
pnpm build && pnpm pack # 产出 hiwork-knowledge-0.1.0.tgz
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
在 DSH profile(如 `~/.dsh/profiles/web`)的 `package.json` 里加依赖
|
|
70
|
+
`"hiwork-knowledge": "file:<绝对路径>/hiwork-knowledge-0.1.0.tgz"`,并在
|
|
71
|
+
`dsh.profile.bundles` 追加 `"hiwork-knowledge"`,然后 `pnpm install --force`
|
|
72
|
+
并重启 `dsh web`(Host 半边变化必须重启,只改 client 时刷新页面即可)。
|
|
73
|
+
|
|
74
|
+
## 后续
|
|
75
|
+
|
|
76
|
+
- 接海普知识库:在 Host 半边注册检索/索引服务,client 通过 `ctx.connection.rpc` 取数;
|
|
77
|
+
页面把 `KnowledgeView` 的占位区域替换为真实列表/搜索。
|
|
78
|
+
- 打包进桌面端:在 `hiwork-desktop/src/bundled-plugins.ts` 增加本地 archive 条目
|
|
79
|
+
(与 `hiwork-automation` 同一 vendor tarball 流程)。
|
package/cordis.patch.yml
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
# hiwork-knowledge bundle:叠加进 profile 后同时挂载 Host 半边并发布 Web 客户端。
|
|
2
|
+
# 用法:profile 的 package.json 依赖本包,dsh.profile.bundles 追加 "hiwork-knowledge"。
|
|
3
|
+
#
|
|
4
|
+
# 知识库后端(检索/索引)尚未接入,本阶段 Host 半边没有运行预算,只负责让 bundle
|
|
5
|
+
# 能被加载;配置项留空以便后续按需追加。
|
|
6
|
+
- insert:
|
|
7
|
+
- id: hiwork-knowledge
|
|
8
|
+
name: 'hiwork-knowledge'
|
package/lib/client.js
ADDED
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
window.__ModuleLoader__.load({ id: "hiwork-knowledge", factory: (require) => { var module = { exports: {} }; var exports = module.exports;
|
|
2
|
+
"use strict";
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name2 in all)
|
|
9
|
+
__defProp(target, name2, { get: all[name2], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
+
|
|
21
|
+
// src/client/index.ts
|
|
22
|
+
var index_exports = {};
|
|
23
|
+
__export(index_exports, {
|
|
24
|
+
apply: () => apply,
|
|
25
|
+
inject: () => inject,
|
|
26
|
+
name: () => name
|
|
27
|
+
});
|
|
28
|
+
module.exports = __toCommonJS(index_exports);
|
|
29
|
+
var import_react2 = require("react");
|
|
30
|
+
|
|
31
|
+
// src/client/KnowledgeView.tsx
|
|
32
|
+
var import_react = require("react");
|
|
33
|
+
function KnowledgeView(props) {
|
|
34
|
+
const { t, closeSettings } = props;
|
|
35
|
+
return (0, import_react.createElement)(
|
|
36
|
+
"section",
|
|
37
|
+
{ className: "hiwork-knowledge-view", "aria-label": t("view.title") },
|
|
38
|
+
(0, import_react.createElement)(
|
|
39
|
+
"header",
|
|
40
|
+
{ className: "hiwork-knowledge-header" },
|
|
41
|
+
(0, import_react.createElement)(
|
|
42
|
+
"div",
|
|
43
|
+
{ className: "hiwork-knowledge-heading" },
|
|
44
|
+
(0, import_react.createElement)("h1", { className: "hiwork-knowledge-title" }, t("view.title")),
|
|
45
|
+
(0, import_react.createElement)("p", { className: "hiwork-knowledge-subtitle" }, t("view.subtitle"))
|
|
46
|
+
),
|
|
47
|
+
closeSettings === void 0 ? null : (0, import_react.createElement)(
|
|
48
|
+
"button",
|
|
49
|
+
{ type: "button", className: "hiwork-knowledge-button", onClick: closeSettings },
|
|
50
|
+
t("view.close")
|
|
51
|
+
)
|
|
52
|
+
),
|
|
53
|
+
(0, import_react.createElement)(
|
|
54
|
+
"div",
|
|
55
|
+
{ className: "hiwork-knowledge-placeholder", "data-hiwork-knowledge-placeholder": "" },
|
|
56
|
+
t("view.placeholder")
|
|
57
|
+
)
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// src/client/locales.ts
|
|
62
|
+
var NS = "hiwork-knowledge";
|
|
63
|
+
var zh = {
|
|
64
|
+
"view.title": "\u77E5\u8BC6\u5E93",
|
|
65
|
+
"view.subtitle": "\u6D77\u666E\u77E5\u8BC6\u5E93\u5BF9\u63A5\u5165\u53E3",
|
|
66
|
+
"view.placeholder": "\u6B64\u5904\u5BF9\u63A5\u6D77\u666E\u77E5\u8BC6\u5E93\u76F8\u5173\u5185\u5BB9",
|
|
67
|
+
"view.close": "\u5173\u95ED\u8BBE\u7F6E"
|
|
68
|
+
};
|
|
69
|
+
var en = {
|
|
70
|
+
"view.title": "Knowledge Base",
|
|
71
|
+
"view.subtitle": "HiWork knowledge base integration",
|
|
72
|
+
"view.placeholder": "HiWork knowledge base content will be integrated here.",
|
|
73
|
+
"view.close": "Close settings"
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
// src/client/styles.css
|
|
77
|
+
var styles_default = "/*\n * hiwork-knowledge \u9875\u9762\u6837\u5F0F\u3002\n *\n * \u4E2D\u592E\u533A\u63A5\u7BA1\u65F6\uFF08`[data-hiwork-feature-root]`\uFF09\u9875\u9762\u6839\u8981\u81EA\u5DF1\u5360\u6EE1\u5269\u4F59\u9AD8\u5EA6\u5E76\u6EDA\u52A8\uFF1B\n * \u964D\u7EA7\u5230\u8BBE\u7F6E\u9875\u5206\u533A\u65F6\uFF08\u6CA1\u6709\u8BE5\u5C5E\u6027\uFF09\u6309\u666E\u901A\u8BBE\u7F6E\u9875\u5185\u5BB9\u6392\u7248\u3002\n */\n.hiwork-knowledge-view {\n display: flex;\n flex-direction: column;\n gap: 12px;\n padding: 4px 0 24px;\n color: var(--dsw-alias-label-primary, #0f1115);\n}\n[data-hiwork-feature-root] .hiwork-knowledge-view {\n flex: 1;\n min-height: 0;\n padding: 20px 24px 32px;\n overflow-y: auto;\n}\n.hiwork-knowledge-header {\n display: flex;\n align-items: flex-start;\n justify-content: space-between;\n gap: 12px;\n}\n.hiwork-knowledge-heading {\n display: flex;\n flex-direction: column;\n gap: 4px;\n}\n.hiwork-knowledge-title {\n margin: 0;\n font-size: 16px;\n font-weight: 600;\n line-height: 24px;\n}\n.hiwork-knowledge-subtitle {\n margin: 0;\n color: var(--dsw-alias-label-secondary, #61666b);\n font-size: 12px;\n line-height: 18px;\n}\n.hiwork-knowledge-button {\n padding: 6px 12px;\n border: 1px solid var(--dsw-alias-border-l2, rgba(15, 17, 21, 0.1));\n border-radius: 8px;\n background: transparent;\n color: var(--dsw-alias-label-primary, #0f1115);\n font-size: 13px;\n cursor: pointer;\n}\n.hiwork-knowledge-button:hover {\n background: var(--dsw-alias-interactive-bg-hover, rgba(15, 17, 21, 0.06));\n}\n.hiwork-knowledge-placeholder {\n display: flex;\n align-items: center;\n justify-content: center;\n min-height: 240px;\n padding: 24px;\n border: 1px dashed var(--dsw-alias-border-l2, rgba(15, 17, 21, 0.15));\n border-radius: 12px;\n color: var(--dsw-alias-label-secondary, #61666b);\n font-size: 14px;\n line-height: 22px;\n text-align: center;\n}\n";
|
|
78
|
+
|
|
79
|
+
// src/client/styles.ts
|
|
80
|
+
var KNOWLEDGE_STYLE_ID = "hiwork-knowledge-styles";
|
|
81
|
+
function installStyles() {
|
|
82
|
+
if (typeof document === "undefined") return () => {
|
|
83
|
+
};
|
|
84
|
+
if (document.getElementById(KNOWLEDGE_STYLE_ID) !== null) return () => {
|
|
85
|
+
};
|
|
86
|
+
const style = document.createElement("style");
|
|
87
|
+
style.id = KNOWLEDGE_STYLE_ID;
|
|
88
|
+
style.textContent = styles_default;
|
|
89
|
+
document.head.appendChild(style);
|
|
90
|
+
let removed = false;
|
|
91
|
+
return () => {
|
|
92
|
+
if (removed) return;
|
|
93
|
+
removed = true;
|
|
94
|
+
style.remove();
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// src/client/index.ts
|
|
99
|
+
var name = "hiwork-knowledge-client";
|
|
100
|
+
var inject = ["slots", "locale"];
|
|
101
|
+
var FEATURE_CENTER_SERVICE = "hiworkFeatureCenter";
|
|
102
|
+
var FEATURE_ID = "knowledge";
|
|
103
|
+
var FEATURE_ORDER = 30;
|
|
104
|
+
var SETTINGS_SECTION_ID = "knowledge";
|
|
105
|
+
var FEATURE_ICON = '<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg" aria-hidden="true"><path d="M3.2 3.1c1.5-.5 3.2-.3 4.8.8 1.6-1.1 3.3-1.3 4.8-.8v8.6c-1.5-.5-3.2-.3-4.8.8-1.6-1.1-3.3-1.3-4.8-.8V3.1Z" stroke="currentColor" stroke-width="1.4" stroke-linejoin="round"/><path d="M8 3.9v8.6" stroke="currentColor" stroke-width="1.4" stroke-linecap="round"/></svg>';
|
|
106
|
+
function coreFace(ctx) {
|
|
107
|
+
const value = ctx.get?.(FEATURE_CENTER_SERVICE);
|
|
108
|
+
if (value === void 0 || value === null) return void 0;
|
|
109
|
+
return value;
|
|
110
|
+
}
|
|
111
|
+
function apply(ctx) {
|
|
112
|
+
ctx.effect(() => ctx.locale.register(NS, { zh, en }), "hiwork-knowledge: locale");
|
|
113
|
+
const t = ctx.locale.bind(NS);
|
|
114
|
+
ctx.effect(() => installStyles(), "hiwork-knowledge: styles");
|
|
115
|
+
let coreSeen = false;
|
|
116
|
+
let featureDispose;
|
|
117
|
+
let settingsDispose;
|
|
118
|
+
const disposeFallback = () => {
|
|
119
|
+
settingsDispose?.();
|
|
120
|
+
settingsDispose = void 0;
|
|
121
|
+
};
|
|
122
|
+
const registerFeature = (scope, face) => {
|
|
123
|
+
if (coreSeen) return;
|
|
124
|
+
coreSeen = true;
|
|
125
|
+
disposeFallback();
|
|
126
|
+
scope.effect(() => {
|
|
127
|
+
const dispose = face.featureRegistry.register({
|
|
128
|
+
id: FEATURE_ID,
|
|
129
|
+
label: () => t("view.title"),
|
|
130
|
+
icon: FEATURE_ICON,
|
|
131
|
+
order: FEATURE_ORDER,
|
|
132
|
+
render: () => (0, import_react2.createElement)(KnowledgeView, { t })
|
|
133
|
+
});
|
|
134
|
+
featureDispose = dispose;
|
|
135
|
+
return () => {
|
|
136
|
+
featureDispose = void 0;
|
|
137
|
+
dispose();
|
|
138
|
+
};
|
|
139
|
+
}, "hiwork-knowledge: feature center");
|
|
140
|
+
};
|
|
141
|
+
const installFallback = () => {
|
|
142
|
+
if (coreSeen) return;
|
|
143
|
+
const settingsOptions = {
|
|
144
|
+
name: "settings.section",
|
|
145
|
+
id: SETTINGS_SECTION_ID,
|
|
146
|
+
order: 20,
|
|
147
|
+
label: () => t("view.title"),
|
|
148
|
+
inject: () => ({ t })
|
|
149
|
+
};
|
|
150
|
+
ctx.slots.inject("settings.section", () => {
|
|
151
|
+
if (coreSeen) return () => {
|
|
152
|
+
};
|
|
153
|
+
const dispose = ctx.slots.register(
|
|
154
|
+
settingsOptions,
|
|
155
|
+
(props) => (0, import_react2.createElement)(KnowledgeView, {
|
|
156
|
+
t: props.t ?? t,
|
|
157
|
+
...props.closeSettings === void 0 ? {} : { closeSettings: props.closeSettings }
|
|
158
|
+
})
|
|
159
|
+
);
|
|
160
|
+
settingsDispose = dispose;
|
|
161
|
+
return () => {
|
|
162
|
+
settingsDispose = void 0;
|
|
163
|
+
dispose();
|
|
164
|
+
};
|
|
165
|
+
});
|
|
166
|
+
};
|
|
167
|
+
const installed = coreFace(ctx);
|
|
168
|
+
if (installed !== void 0) registerFeature(ctx, installed);
|
|
169
|
+
else installFallback();
|
|
170
|
+
ctx.inject?.([FEATURE_CENTER_SERVICE], (scope) => {
|
|
171
|
+
const face = coreFace(scope);
|
|
172
|
+
if (face !== void 0) registerFeature(scope, face);
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
return module.exports; } });
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
var name = "hiwork-knowledge";
|
|
3
|
+
var inject = [];
|
|
4
|
+
function apply(ctx) {
|
|
5
|
+
ctx.effect(() => {
|
|
6
|
+
ctx.logger.info("hiwork-knowledge: host half ready (knowledge backend not wired yet)");
|
|
7
|
+
return () => void 0;
|
|
8
|
+
}, "hiwork-knowledge: host half");
|
|
9
|
+
}
|
|
10
|
+
export {
|
|
11
|
+
apply,
|
|
12
|
+
inject,
|
|
13
|
+
name
|
|
14
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 知识库页。
|
|
3
|
+
*
|
|
4
|
+
* 本阶段只渲染页面骨架 + 一句占位文案:真正的知识库能力(海普对接、检索、索引)
|
|
5
|
+
* 落地后替换 `placeholder` 区域即可,页面外壳、菜单注册与生命周期都不需要改动。
|
|
6
|
+
*/
|
|
7
|
+
import { type ReactElement } from 'react';
|
|
8
|
+
import type { KnowledgeViewProps } from './contracts.js';
|
|
9
|
+
/**
|
|
10
|
+
* 知识库占位页。
|
|
11
|
+
* @param props - 翻译函数与可选的关闭回调。
|
|
12
|
+
*/
|
|
13
|
+
export declare function KnowledgeView(props: KnowledgeViewProps): ReactElement;
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* client 半边的**类型专用**宿主契约。
|
|
3
|
+
*
|
|
4
|
+
* 只声明本插件真正消费的 DSH client 能力,不引入任何运行时依赖:
|
|
5
|
+
* - `@deepseek-ai/*` 官方包在 `src/client/**` 里只允许 `import type`(打包时被擦除);
|
|
6
|
+
* - 插件的 client 入口拿到的是结构兼容的宿主上下文,本文件是它唯一的形状来源;
|
|
7
|
+
* - 所有成员都按“可选能力”建模:宿主版本差异只会让某块 UI 降级,不会让整页崩掉。
|
|
8
|
+
*/
|
|
9
|
+
import type { ComponentType, ReactNode } from 'react';
|
|
10
|
+
/** `ctx.slots.register` 的注册选项(label 用函数以便跟随语言切换)。 */
|
|
11
|
+
export interface SlotRegisterOptions {
|
|
12
|
+
name: string;
|
|
13
|
+
id?: string;
|
|
14
|
+
order?: number;
|
|
15
|
+
locale?: string;
|
|
16
|
+
label?: () => string;
|
|
17
|
+
icon?: string;
|
|
18
|
+
/** 宿主合成到组件属性上的注入面(本插件用它传 `t`)。 */
|
|
19
|
+
inject?: () => object;
|
|
20
|
+
}
|
|
21
|
+
/** 宿主语言服务:注册命名空间词典 + 绑定翻译函数。 */
|
|
22
|
+
export interface ClientLocale {
|
|
23
|
+
register(namespace: string, dictionaries: {
|
|
24
|
+
readonly zh: Record<string, string>;
|
|
25
|
+
readonly en: Record<string, string>;
|
|
26
|
+
}): () => void;
|
|
27
|
+
bind(namespace: string): (key: string, params?: Record<string, unknown>) => string;
|
|
28
|
+
}
|
|
29
|
+
/** 宿主插槽服务:`inject` 声明插槽、`register` 挂组件。 */
|
|
30
|
+
export interface ClientSlots {
|
|
31
|
+
inject(name: string, register: () => void | (() => void)): void;
|
|
32
|
+
register(options: SlotRegisterOptions, component: ComponentType<any>): () => void;
|
|
33
|
+
entries?(name: string): readonly unknown[];
|
|
34
|
+
entriesOfSlot?(name: string): readonly unknown[];
|
|
35
|
+
subscribe?(name: string, listener: () => void): () => void;
|
|
36
|
+
}
|
|
37
|
+
/** client 插件拿到的宿主上下文(结构兼容 DSH 0.1.2-rc.1 client Context)。 */
|
|
38
|
+
export interface ClientContext {
|
|
39
|
+
effect(factory: () => void | (() => void), label?: string): void;
|
|
40
|
+
locale: ClientLocale;
|
|
41
|
+
slots: ClientSlots;
|
|
42
|
+
/**
|
|
43
|
+
* 可选:按服务名读取(cordis `ctx.get`)。
|
|
44
|
+
*
|
|
45
|
+
* 用于探测 `hiwork-core` 是否已经提供 Feature Center;未注入的服务不能直接点访问
|
|
46
|
+
* (cordis 代理会抛 `cannot get property ... without inject`)。
|
|
47
|
+
*/
|
|
48
|
+
get?(name: string): unknown;
|
|
49
|
+
/**
|
|
50
|
+
* 可选:cordis 可选服务注入(`ctx.inject(deps, callback)`)。
|
|
51
|
+
*
|
|
52
|
+
* `hiwork-core` 后于本插件加载时,服务一出现就回调;缺 `hiwork-core` 时回调永不
|
|
53
|
+
* 触发,本插件保持独立可用的设置页降级入口。
|
|
54
|
+
*/
|
|
55
|
+
inject?(deps: readonly string[], callback: (scope: ClientContext) => void): unknown;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* `hiwork-core` 提供的 Feature Center 面(cordis 服务名 `hiworkFeatureCenter`)。
|
|
59
|
+
*
|
|
60
|
+
* 结构契约:本插件不在运行时 import `hiwork-core`(DSH client 模块表禁止 feature
|
|
61
|
+
* 插件之间互相 runtime-import),只按服务名读取;字段与 `hiwork-core` 的
|
|
62
|
+
* `HiWorkCoreClientFace` / `HiWorkFeature` 一一对应。
|
|
63
|
+
*/
|
|
64
|
+
export interface HiWorkCoreFace {
|
|
65
|
+
readonly featureRegistry: HiWorkFeatureRegistry;
|
|
66
|
+
readonly openFeature: (id: string) => boolean;
|
|
67
|
+
readonly openNativeSession: (sessionId: string) => void;
|
|
68
|
+
readonly openNativeHome: () => void;
|
|
69
|
+
}
|
|
70
|
+
/** 扩展注册表(本插件只用到 `register`)。 */
|
|
71
|
+
export interface HiWorkFeatureRegistry {
|
|
72
|
+
register(feature: HiWorkFeature): () => void;
|
|
73
|
+
list(): readonly HiWorkFeature[];
|
|
74
|
+
activeId(): string | null;
|
|
75
|
+
open(id: string): boolean;
|
|
76
|
+
openNative(): void;
|
|
77
|
+
subscribe(listener: () => void): () => void;
|
|
78
|
+
}
|
|
79
|
+
/** 一个中央页扩展入口。 */
|
|
80
|
+
export interface HiWorkFeature {
|
|
81
|
+
readonly id: string;
|
|
82
|
+
readonly label: () => string;
|
|
83
|
+
readonly icon?: string;
|
|
84
|
+
readonly order?: number;
|
|
85
|
+
readonly render: (context: HiWorkFeatureRenderContext) => ReactNode;
|
|
86
|
+
}
|
|
87
|
+
/** 扩展渲染上下文:只含导航能力,业务状态仍由本插件持有。 */
|
|
88
|
+
export interface HiWorkFeatureRenderContext {
|
|
89
|
+
readonly openNativeSession: (sessionId: string) => void;
|
|
90
|
+
readonly openNativeHome: () => void;
|
|
91
|
+
}
|
|
92
|
+
/** 翻译函数:`t(key, params)`,未命中时宿主回退到 key 本身。 */
|
|
93
|
+
export type Translate = (key: string, params?: Record<string, unknown>) => string;
|
|
94
|
+
/** 知识库页组件属性。 */
|
|
95
|
+
export interface KnowledgeViewProps {
|
|
96
|
+
/** 本插件命名空间(`hiwork-knowledge`)的翻译函数。 */
|
|
97
|
+
t: Translate;
|
|
98
|
+
/** 关闭设置面板(降级到设置页分区时由宿主提供)。 */
|
|
99
|
+
closeSettings?: () => void;
|
|
100
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { ClientContext } from './contracts.js';
|
|
2
|
+
/** DSH client 插件名。 */
|
|
3
|
+
export declare const name = "hiwork-knowledge-client";
|
|
4
|
+
/** 必需的 client 服务。 */
|
|
5
|
+
export declare const inject: string[];
|
|
6
|
+
/**
|
|
7
|
+
* 挂载 Web 半边。
|
|
8
|
+
* @param ctx - client 插件上下文。
|
|
9
|
+
*/
|
|
10
|
+
export declare function apply(ctx: ClientContext): void;
|
|
11
|
+
/** 便于验收脚本按导出面断言。 */
|
|
12
|
+
export type { KnowledgeViewProps } from './contracts.js';
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `hiwork-knowledge` 命名空间的双语词典(zh / en 键集完全一致)。
|
|
3
|
+
*
|
|
4
|
+
* 约定:
|
|
5
|
+
* - 页面里所有用户可见文案都必须来自这里,组件内不写死中英文;
|
|
6
|
+
* - `en` 的类型是 `Record<KnowledgeLocaleKey, string>`,少一个键就是编译错误。
|
|
7
|
+
*/
|
|
8
|
+
/** 宿主 locale 服务注册时使用的命名空间。 */
|
|
9
|
+
export declare const NS = "hiwork-knowledge";
|
|
10
|
+
export declare const zh: {
|
|
11
|
+
'view.title': string;
|
|
12
|
+
'view.subtitle': string;
|
|
13
|
+
'view.placeholder': string;
|
|
14
|
+
'view.close': string;
|
|
15
|
+
};
|
|
16
|
+
export declare const en: {
|
|
17
|
+
'view.title': string;
|
|
18
|
+
'view.subtitle': string;
|
|
19
|
+
'view.placeholder': string;
|
|
20
|
+
'view.close': string;
|
|
21
|
+
};
|
|
22
|
+
/** 词典键(zh 为基准,en 必须键集一致)。 */
|
|
23
|
+
export type KnowledgeLocaleKey = keyof typeof zh;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `hiwork-knowledge` 的 Host 入口。
|
|
3
|
+
*
|
|
4
|
+
* 知识库后端(索引 / 检索 / 海普对接)尚未落地,本阶段 Host 半边只做两件事:
|
|
5
|
+
* - 声明插件名,让 profile 的 bundle 能正常加载(没有 Host 半边,client 半边不会发布);
|
|
6
|
+
* - 打一条启动日志,方便排查「插件到底装上没有」。
|
|
7
|
+
*
|
|
8
|
+
* 所有贡献都登记在 `ctx.effect` 的清理函数里,卸载幂等。
|
|
9
|
+
*
|
|
10
|
+
* 打包注意:桌面端补种插件时会清空 profile 的 `node_modules/@deepseek-ai/*`,
|
|
11
|
+
* 因此 `lib/index.js` 必须自包含;本文件对官方包只做 **type-only** import。
|
|
12
|
+
*/
|
|
13
|
+
import type { Context } from '@deepseek-ai/cordis';
|
|
14
|
+
/** DSH 插件名(与 `cordis.patch.yml` 的 bundle id 一致)。 */
|
|
15
|
+
export declare const name = "hiwork-knowledge";
|
|
16
|
+
/** 本阶段不依赖任何 Host 服务;接入知识库后端时在此追加。 */
|
|
17
|
+
export declare const inject: readonly string[];
|
|
18
|
+
/**
|
|
19
|
+
* 挂载 Host 半边。
|
|
20
|
+
* @param ctx - cordis 上下文。
|
|
21
|
+
*/
|
|
22
|
+
export declare function apply(ctx: Context): void;
|
package/package.json
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "hiwork-knowledge",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "HiWork 知识库插件:在中央内容区提供「知识库」入口(当前为对接海普知识库的占位页)。",
|
|
5
|
+
"license": "UNLICENSED",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"packageManager": "pnpm@10.28.1",
|
|
8
|
+
"main": "lib/index.js",
|
|
9
|
+
"types": "lib/types/index.d.ts",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"types": "./lib/types/index.d.ts",
|
|
13
|
+
"default": "./lib/index.js"
|
|
14
|
+
},
|
|
15
|
+
"./client": {
|
|
16
|
+
"types": "./lib/types/client/index.d.ts",
|
|
17
|
+
"default": "./lib/client.js"
|
|
18
|
+
},
|
|
19
|
+
"./cordis.patch.yml": "./cordis.patch.yml",
|
|
20
|
+
"./package.json": "./package.json"
|
|
21
|
+
},
|
|
22
|
+
"files": [
|
|
23
|
+
"lib",
|
|
24
|
+
"cordis.patch.yml",
|
|
25
|
+
"README.md"
|
|
26
|
+
],
|
|
27
|
+
"engines": {
|
|
28
|
+
"node": "^22.19.0 || >=24.0.0"
|
|
29
|
+
},
|
|
30
|
+
"dsh": {
|
|
31
|
+
"bundle": {
|
|
32
|
+
"patch": "./cordis.patch.yml"
|
|
33
|
+
},
|
|
34
|
+
"client": {
|
|
35
|
+
"platform": "web",
|
|
36
|
+
"inject": [
|
|
37
|
+
"@deepseek-ai/dsh-client-locale",
|
|
38
|
+
"@deepseek-ai/dsh-client-ui-settings",
|
|
39
|
+
"@deepseek-ai/dsh-client-ui-slots"
|
|
40
|
+
]
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
"scripts": {
|
|
44
|
+
"typecheck": "tsc --noEmit",
|
|
45
|
+
"build:host": "tsc -p tsconfig.build.json && node scripts/host-build.mjs",
|
|
46
|
+
"build:client": "tsc -p tsconfig.client-build.json && node scripts/client-build.mjs",
|
|
47
|
+
"build": "pnpm build:host && pnpm build:client",
|
|
48
|
+
"test": "vitest run",
|
|
49
|
+
"check": "pnpm typecheck && pnpm test && pnpm build",
|
|
50
|
+
"verify": "pnpm typecheck && pnpm build && pnpm test"
|
|
51
|
+
},
|
|
52
|
+
"peerDependencies": {
|
|
53
|
+
"@deepseek-ai/cordis": ">=4.0.1 <5.0.0",
|
|
54
|
+
"@deepseek-ai/dsh-client-locale": ">=0.1.0-rc.5 <0.2.0",
|
|
55
|
+
"@deepseek-ai/dsh-client-ui-settings": ">=0.1.0-rc.5 <0.2.0",
|
|
56
|
+
"@deepseek-ai/dsh-client-ui-slots": ">=0.1.0-rc.5 <0.2.0",
|
|
57
|
+
"react": "^18.2.0"
|
|
58
|
+
},
|
|
59
|
+
"peerDependenciesMeta": {
|
|
60
|
+
"react": {
|
|
61
|
+
"optional": true
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
"devDependencies": {
|
|
65
|
+
"@deepseek-ai/cordis": "4.0.2",
|
|
66
|
+
"@deepseek-ai/dsh-client-locale": "0.1.2-rc.1",
|
|
67
|
+
"@deepseek-ai/dsh-client-ui-settings": "0.1.2-rc.1",
|
|
68
|
+
"@deepseek-ai/dsh-client-ui-slots": "0.1.2-rc.1",
|
|
69
|
+
"@types/node": "^22.0.0",
|
|
70
|
+
"@types/react": "~18.3.1",
|
|
71
|
+
"@types/react-dom": "~18.3.0",
|
|
72
|
+
"esbuild": "^0.25.0",
|
|
73
|
+
"jsdom": "^26.0.0",
|
|
74
|
+
"react": "^18.3.1",
|
|
75
|
+
"react-dom": "^18.3.1",
|
|
76
|
+
"typescript": "^5.9.0",
|
|
77
|
+
"vitest": "^3.2.0"
|
|
78
|
+
}
|
|
79
|
+
}
|