@hokan/hello 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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 huyongle
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,9 @@
1
+ # @hokan/hello 的 bundle patch —— 本功能包贡献的一行。
2
+ # 单独安装本包(dsh plugin add @hokan/hello)或经伞形包 dsh-hokan 引用均可。
3
+
4
+ - insert:
5
+ - id: hokan-hello
6
+ name: '@hokan/hello'
7
+ disabled: true
8
+ config:
9
+ greeting: 補完
package/lib/client.js ADDED
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+ // 行 config 下发路由(与宿主侧 @hokan/core 的 ROUTE_PREFIX 对应,运行时隔离各自定义)。
3
+ const CONFIG_ROUTE = '/dsh-hokan/hello/config.json';
4
+ // 停靠位排序值:排在常规内容之后。
5
+ const DOCK_ORDER = 960;
6
+ // trace 开关:config 拉取后更新(拉取本身无法提前感知开关)。
7
+ let traceEnabled = false;
8
+ // 浏览器侧轨迹:与宿主同格式的 JSON 行,console.debug 输出(DevTools 过滤 hokan-trace)。
9
+ function traceEvent(event, detail) {
10
+ if (!traceEnabled)
11
+ return;
12
+ console.debug('hokan-trace ' + JSON.stringify({ timestamp: new Date().toISOString(), scope: 'hokan:hello.client', event, detail }));
13
+ }
14
+ // 拉取本行 config;失败回退空配置。
15
+ async function fetchConfig() {
16
+ const response = await fetch(CONFIG_ROUTE);
17
+ if (!response.ok)
18
+ return {};
19
+ const payload = (await response.json());
20
+ return payload.config ?? {};
21
+ }
22
+ // 问候文字元素。
23
+ function renderGreeting(React, config) {
24
+ const greeting = config.greeting ?? '補完';
25
+ return React.createElement('span', { style: { color: '#8a8f98', fontSize: '11px', padding: '0 8px', userSelect: 'none' }, title: 'dsh-hokan · hello' }, greeting + ' · hokan');
26
+ }
27
+ window.__ModuleLoader__.load({
28
+ id: '@hokan/hello',
29
+ factory: (require) => {
30
+ const React = require('react');
31
+ return {
32
+ name: 'hokan-hello',
33
+ inject: ['slots'],
34
+ apply(context) {
35
+ context.effect(() => {
36
+ let active = true;
37
+ const startedAt = performance.now();
38
+ fetchConfig()
39
+ .then((config) => {
40
+ if (!active)
41
+ return;
42
+ traceEnabled = config.trace?.enabled === true;
43
+ traceEvent('config.fetched', { durationMs: Math.round((performance.now() - startedAt) * 100) / 100 });
44
+ context.slots.inject('conversation.composer.dock', function* () {
45
+ yield context.slots.register({ name: 'conversation.composer.dock', id: 'hokan-hello', order: DOCK_ORDER }, () => renderGreeting(React, config));
46
+ });
47
+ traceEvent('slots.registered', { slot: 'conversation.composer.dock' });
48
+ })
49
+ .catch((error) => {
50
+ context.logger.error(error);
51
+ });
52
+ return () => {
53
+ active = false;
54
+ };
55
+ }, 'hokan-hello: client');
56
+ },
57
+ };
58
+ },
59
+ });
package/lib/index.js ADDED
@@ -0,0 +1,30 @@
1
+ import { createTracer, serveRowConfig } from '@hokan/core';
2
+ // Cordis 插件名(行 id 与之对应:hokan-hello)。
3
+ export const name = 'hokan-hello';
4
+ // 需要宿主注入的服务:Web 路由注册。
5
+ export const inject = ['webServer'];
6
+ /**
7
+ * 从行 config 创建 tracer;logger 存在则进宿主日志,否则退回 console。
8
+ *
9
+ * @param context 宿主插件上下文
10
+ * @param config 行配置
11
+ * @returns Tracer
12
+ */
13
+ function tracerFrom(context, config) {
14
+ return createTracer({
15
+ scope: 'hokan:hello',
16
+ enabled: config?.trace?.enabled === true,
17
+ slowMs: config?.trace?.slowMs,
18
+ sink: { write: (entry) => { context.logger?.debug?.('hokan-trace ' + JSON.stringify(entry)); } },
19
+ });
20
+ }
21
+ /**
22
+ * hello 功能行宿主半侧:注册 config 下发路由(带 trace 计时)。
23
+ *
24
+ * @param context 宿主插件上下文
25
+ * @param config 行配置
26
+ */
27
+ export function apply(context, config) {
28
+ const tracer = tracerFrom(context, config);
29
+ context.effect(() => serveRowConfig(context, { featureId: 'hello', config, tracer }), 'hokan-hello: config route');
30
+ }
package/package.json ADDED
@@ -0,0 +1,53 @@
1
+ {
2
+ "name": "@hokan/hello",
3
+ "version": "0.1.0",
4
+ "description": "dsh-hokan 示例功能行:输入区停靠位问候(安装自检用)",
5
+ "type": "module",
6
+ "main": "lib/index.js",
7
+ "exports": {
8
+ ".": "./lib/index.js",
9
+ "./client": "./lib/client.js",
10
+ "./cordis.patch.yml": "./cordis.patch.yml",
11
+ "./package.json": "./package.json"
12
+ },
13
+ "files": [
14
+ "lib",
15
+ "cordis.patch.yml"
16
+ ],
17
+ "dsh": {
18
+ "bundle": {
19
+ "patch": "./cordis.patch.yml"
20
+ },
21
+ "client": {
22
+ "platform": "web",
23
+ "inject": [
24
+ "slots"
25
+ ]
26
+ }
27
+ },
28
+ "dependencies": {
29
+ "@hokan/core": "0.1.0"
30
+ },
31
+ "peerDependencies": {
32
+ "react": "^18.2.0"
33
+ },
34
+ "peerDependenciesMeta": {
35
+ "react": {
36
+ "optional": true
37
+ }
38
+ },
39
+ "license": "MIT",
40
+ "repository": {
41
+ "type": "git",
42
+ "url": "git+https://github.com/YuluoY/dsh-hokan.git",
43
+ "directory": "packages/hello"
44
+ },
45
+ "publishConfig": {
46
+ "access": "public"
47
+ },
48
+ "scripts": {
49
+ "build": "tsc -p tsconfig.json && tsc -p tsconfig.client.json",
50
+ "typecheck": "tsc -p tsconfig.json --noEmit && tsc -p tsconfig.client.json --noEmit",
51
+ "dev": "tsc -p tsconfig.json --watch & tsc -p tsconfig.client.json --watch"
52
+ }
53
+ }