hiwork-core 0.0.35 → 0.0.38
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/lib/browser-login.js +42 -16
- package/lib/client.js +61 -119
- package/lib/identity-context.js +50 -0
- package/lib/index.js +176 -70
- package/lib/types/browser-login.d.ts +10 -1
- package/lib/types/client/daily-data.d.ts +31 -3
- package/lib/types/client/menu-preferences.d.ts +4 -3
- package/lib/types/client/styles.d.ts +5 -4
- package/lib/types/client/user-badge.d.ts +7 -2
- package/lib/types/identity-context.d.ts +54 -0
- package/lib/types/index.d.ts +29 -3
- package/lib/types/provision-session.d.ts +2 -0
- package/package.json +26 -25
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { InjectFace
|
|
1
|
+
import type { InjectFace } from '@deepseek-ai/dsh-client-ui-slots';
|
|
2
2
|
import { type AiRouterCardFace } from './controller.ts';
|
|
3
3
|
import { type PluginUpdatesStore } from './plugin-updates.ts';
|
|
4
4
|
/**
|
|
@@ -19,6 +19,11 @@ import { type PluginUpdatesStore } from './plugin-updates.ts';
|
|
|
19
19
|
export interface PluginUpdatesFace {
|
|
20
20
|
pluginUpdates: PluginUpdatesStore;
|
|
21
21
|
}
|
|
22
|
-
export type UserBadgeProps =
|
|
22
|
+
export type UserBadgeProps = InjectFace<AiRouterCardFace & PluginUpdatesFace> & {
|
|
23
|
+
/** `settings.launcher` 槽位的渲染参数(ui-settings-general 的 SettingsRoot 下发)。 */
|
|
24
|
+
readonly wide: boolean | undefined;
|
|
25
|
+
/** 打开设置弹窗(壳拥有 open 状态);分区直达由 selectSettingsSection 补齐。 */
|
|
26
|
+
readonly openSettings: () => void;
|
|
27
|
+
};
|
|
23
28
|
/** 底部账号信息行(宽栏 / 折叠栏共用;插件更新提示卡片也由它渲染,见下)。 */
|
|
24
29
|
export declare function UserBadge(props: UserBadgeProps): import("react").JSX.Element | null;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 登录身份的 runtime context 贡献(`hiwork:identity`):把「当前登录人是谁」送进
|
|
3
|
+
* AI 上下文,供 skill / 会话按人表述与个性化使用(spec
|
|
4
|
+
* `docs/superpowers/specs/2026-10-09-identity-runtime-context-design.md`)。
|
|
5
|
+
*
|
|
6
|
+
* 设计要点(与 `src/identity.ts` 同构):
|
|
7
|
+
* - **cordis-free 纯模块**:注册走结构化的 {@link SystemPromptPort} 窄端口,调用方
|
|
8
|
+
* (index.ts)传真实 `ctx.systemPrompt`;单测直接伪造。真实 PromptContext.text
|
|
9
|
+
* 接受 `(AssembleContext) => string`,本模块的 `() => string` 结构兼容(忽略入参);
|
|
10
|
+
* - **空串 = 不贡献**(DSH 原生语义):未登录、bundle 层关闭(`identityContext: false`)、
|
|
11
|
+
* 读失败一律返回空串——零暴露,且绝不向组装层抛异常;
|
|
12
|
+
* - **每次组装现读**:text 是每次求值的 provider,登录 / 登出 / 换号在下一步即时反映,
|
|
13
|
+
* 不缓存旧身份;
|
|
14
|
+
* - **身份文本不是凭证**:上下文里的身份只作展示 / 个性化 / 按人表述用,鉴权一律在
|
|
15
|
+
* 通道层(loopback RPC 带网关会话、MCP 断言→mint)。文案末尾那句限定语是对模型的
|
|
16
|
+
* 引导,不是防线;
|
|
17
|
+
* - **字段最小化**:只用 `username`(工号)与 `displayName`(姓名),归一化口径与
|
|
18
|
+
* identity.ts 的 textOrUndefined 一致(裁空白、空白串视同缺省)。keys / subject /
|
|
19
|
+
* 团队一律不进上下文。
|
|
20
|
+
*/
|
|
21
|
+
import type { IdentityState } from './identity.ts';
|
|
22
|
+
/** runtime context 贡献名(DSH 侧 snapshot 按名归并,改动即破坏对齐面)。 */
|
|
23
|
+
export declare const IDENTITY_CONTEXT_NAME = "hiwork:identity";
|
|
24
|
+
/** 排在 sandbox:policy(110) / approval:policy(115) 之前——身份是最外层的环境事实。 */
|
|
25
|
+
export declare const IDENTITY_CONTEXT_ORDER = 105;
|
|
26
|
+
/**
|
|
27
|
+
* 渲染身份上下文一行:已登录输出 `HiWork 登录身份:姓名(工号 工号)。<限定语>`,
|
|
28
|
+
* displayName 缺省回退 `工号 <工号>`;**未登录(username 缺省 / 空白 / 非字符串)或
|
|
29
|
+
* state 缺失一律空串**——半份身份(只有 displayName)也不输出,姓名不得单独泄漏。
|
|
30
|
+
*/
|
|
31
|
+
export declare function renderIdentityContextText(state: IdentityState | undefined): string;
|
|
32
|
+
/** `ctx.systemPrompt.context` 的最小端口(结构兼容 DSH 的 SystemPrompt,便于单测伪造)。 */
|
|
33
|
+
export interface SystemPromptPort {
|
|
34
|
+
/** 注册一条 runtime context 贡献;返回注销函数(或任何可注销值,见 registerIdentityContext)。 */
|
|
35
|
+
context(contribution: {
|
|
36
|
+
name: string;
|
|
37
|
+
order: number;
|
|
38
|
+
text: () => string;
|
|
39
|
+
}): unknown;
|
|
40
|
+
}
|
|
41
|
+
/** 注册侧依赖:登录态现读 + bundle 层开关 + 日志出口。 */
|
|
42
|
+
export interface IdentityContextDeps {
|
|
43
|
+
/** 读一次当前登录态(与 hiworkIdentity 同一数据源;每次组装都会调用)。 */
|
|
44
|
+
current(): IdentityState;
|
|
45
|
+
/** bundle 层固定开关(缺省开);关闭时贡献空文本。 */
|
|
46
|
+
enabled(): boolean;
|
|
47
|
+
/** Host 日志出口(只记错误类型,不记身份字段)。 */
|
|
48
|
+
log?(message: string): void;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* 注册身份 runtime context 贡献;返回 disposer(交给 `ctx.effect` 管理生命周期)。
|
|
52
|
+
* 读失败收敛为空串并记一笔,绝不向组装层抛——身份上下文缺席只应意味着「未登录」。
|
|
53
|
+
*/
|
|
54
|
+
export declare function registerIdentityContext(systemPrompt: SystemPromptPort, deps: IdentityContextDeps): () => void;
|
package/lib/types/index.d.ts
CHANGED
|
@@ -19,7 +19,8 @@ export declare const name = "hiwork-core";
|
|
|
19
19
|
* (`ctx.web.registerSearchProvider`,见 `src/web-search.ts`;dsh-base 基座先于本
|
|
20
20
|
* 插件挂载 dsh-web);`agents` 是根 Agent 注册表——`image_generate` 工具要挂在根 Agent
|
|
21
21
|
* 上(`ctx.agents.roots()` / `agent/created`,见 `src/tools.ts`;与 knowledge 的
|
|
22
|
-
* `inject`
|
|
22
|
+
* `inject` 同源);`systemPrompt` 承载登录身份的 runtime context 贡献
|
|
23
|
+
* (`hiwork:identity`,见 `src/identity-context.ts`);其余三项是既有登录 / 供给依赖。
|
|
23
24
|
*/
|
|
24
25
|
export declare const inject: string[];
|
|
25
26
|
/** 侧栏菜单偏好的解析值(client 侧 `MenuPreferences` 的同一份形状)。 */
|
|
@@ -44,6 +45,11 @@ export declare const MenuConfig: z<MenuConfigValue>;
|
|
|
44
45
|
/** 插件配置 + 运行时状态字段(全部可选;写操作按此 schema 校验)。 */
|
|
45
46
|
export interface Config {
|
|
46
47
|
baseURL?: string;
|
|
48
|
+
/**
|
|
49
|
+
* 身份上下文开关(bundle 层固定配置,缺省开):把当前登录人(工号 + 姓名)以
|
|
50
|
+
* runtime context 贡献暴露进 AI 上下文;关闭时贡献空文本(零暴露)。
|
|
51
|
+
*/
|
|
52
|
+
identityContext?: boolean;
|
|
47
53
|
keyId?: string;
|
|
48
54
|
username?: string;
|
|
49
55
|
displayName?: string;
|
|
@@ -114,12 +120,13 @@ export declare const Config: z<Config>;
|
|
|
114
120
|
/**
|
|
115
121
|
* apply 收到的运行时 config:volatile 字段是稳定引用(schemastery 解析期包装,值为
|
|
116
122
|
* undefined 时引用依然存在),随 profile 变更被框架原地更新——持有引用、每次现取,
|
|
117
|
-
* 绝不缓存 `.get()` 的结果。baseURL 仍是普通组合层配置。
|
|
123
|
+
* 绝不缓存 `.get()` 的结果。baseURL 与 identityContext 仍是普通组合层配置。
|
|
118
124
|
*/
|
|
119
125
|
export type RuntimeConfig = {
|
|
120
126
|
baseURL?: string;
|
|
127
|
+
identityContext?: boolean;
|
|
121
128
|
} & {
|
|
122
|
-
[K in Exclude<keyof Config, 'baseURL'>]?: Volatile<Config[K]>;
|
|
129
|
+
[K in Exclude<keyof Config, 'baseURL' | 'identityContext'>]?: Volatile<Config[K]>;
|
|
123
130
|
};
|
|
124
131
|
/**
|
|
125
132
|
* settings.mutate 的路径操作(rc.2 的 dsh-settings 不再导出 `SettingsPathOp` 类型,
|
|
@@ -133,6 +140,25 @@ export type SettingsPathOp = {
|
|
|
133
140
|
op: 'unset';
|
|
134
141
|
path: readonly string[];
|
|
135
142
|
};
|
|
143
|
+
/** 失败是否是「事务内写」——调用方据此判断轮询上下文已被 HMR 事务污染(见 apply)。 */
|
|
144
|
+
export declare function isHmrNestedWriteError(error: unknown): boolean;
|
|
145
|
+
/**
|
|
146
|
+
* 写一个命名空间(= profile entry id)。
|
|
147
|
+
*
|
|
148
|
+
* 每次尝试都重读 `describe()` 取最新 revision;可重试错误在截止时间前带退避重试,超时后
|
|
149
|
+
* 抛出**真实**错误——不降级成「conflicted repeatedly」,免得把根因从日志里抹掉。
|
|
150
|
+
* 退避上限 1s:命名空间注册与 HMR 事务都在秒级内收敛,重试代价可忽略。
|
|
151
|
+
*
|
|
152
|
+
* @param settings - settings 服务。
|
|
153
|
+
* @param ns - 命名空间(profile entry id)。
|
|
154
|
+
* @param ops - 路径操作。
|
|
155
|
+
* @param opts - 重试窗口与退避(单测用来把窗口压到毫秒级)。
|
|
156
|
+
*/
|
|
157
|
+
export declare function writeNamespace(settings: SettingsForms, ns: string, ops: SettingsPathOp[], opts?: {
|
|
158
|
+
deadlineMs?: number;
|
|
159
|
+
minBackoffMs?: number;
|
|
160
|
+
maxBackoffMs?: number;
|
|
161
|
+
}): Promise<void>;
|
|
136
162
|
/** 校正默认模型要用到的 llm 注册表部分(便于单测注入假实现)。 */
|
|
137
163
|
export interface LlmRouteRegistry {
|
|
138
164
|
listProviders(): readonly {
|
|
@@ -37,6 +37,8 @@ export interface AiRouterStatePort {
|
|
|
37
37
|
/** ai-router 命名空间解析后的值(相关字段)。 */
|
|
38
38
|
export interface AiRouterNamespaceValue {
|
|
39
39
|
baseURL?: string;
|
|
40
|
+
/** 身份上下文开关(bundle 层固定配置,缺省开);关闭时 `hiwork:identity` 贡献空文本。 */
|
|
41
|
+
identityContext?: boolean;
|
|
40
42
|
keyId?: string;
|
|
41
43
|
username?: string;
|
|
42
44
|
/** 登录账号的显示名(网关 LDAP displayName,如中文名);缺省时 UI 回退 username。 */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hiwork-core",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.38",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "HiWork 企业统一登录与模型自动供给插件(ai-router 网关登录,Web 表单,无 CLI 认证)",
|
|
6
6
|
"license": "UNLICENSED",
|
|
@@ -42,33 +42,34 @@
|
|
|
42
42
|
},
|
|
43
43
|
"peerDependencies": {
|
|
44
44
|
"@deepseek-ai/cordis": "~4.0.4",
|
|
45
|
-
"@deepseek-ai/dsh-client-ui-layout": ">=0.1.0-rc.5 <0.2.0"
|
|
45
|
+
"@deepseek-ai/dsh-client-ui-layout": ">=0.1.0-rc.5 <0.2.0 || >=0.2.0-rc.1 <0.3.0"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
48
|
"@deepseek-ai/cordis": "4.0.4",
|
|
49
49
|
"@deepseek-ai/cordis-plugin-loader": "1.0.5",
|
|
50
|
-
"@deepseek-ai/dsh-agent-default-model": "0.
|
|
51
|
-
"@deepseek-ai/dsh-api-remotes": "0.
|
|
52
|
-
"@deepseek-ai/dsh-app-boot": "0.
|
|
53
|
-
"@deepseek-ai/dsh-attachment": "0.
|
|
54
|
-
"@deepseek-ai/dsh-client-store": "0.
|
|
55
|
-
"@deepseek-ai/dsh-client-ui-chat": "0.
|
|
56
|
-
"@deepseek-ai/dsh-client-ui-conversation": "0.
|
|
57
|
-
"@deepseek-ai/dsh-client-ui-primitives": "0.
|
|
58
|
-
"@deepseek-ai/dsh-client-ui-renderer": "0.
|
|
59
|
-
"@deepseek-ai/dsh-client-ui-session": "0.
|
|
60
|
-
"@deepseek-ai/dsh-client-ui-settings": "0.
|
|
61
|
-
"@deepseek-ai/dsh-client-ui-sidebar": "0.
|
|
62
|
-
"@deepseek-ai/dsh-client-ui-slots": "0.
|
|
63
|
-
"@deepseek-ai/dsh-config-editor": "0.
|
|
64
|
-
"@deepseek-ai/dsh-credentials": "0.
|
|
65
|
-
"@deepseek-ai/dsh-credentials-local": "0.
|
|
66
|
-
"@deepseek-ai/dsh-llm": "0.
|
|
67
|
-
"@deepseek-ai/dsh-llm-pi-ai": "0.
|
|
68
|
-
"@deepseek-ai/dsh-settings": "0.
|
|
69
|
-
"@deepseek-ai/dsh-
|
|
70
|
-
"@deepseek-ai/dsh-
|
|
71
|
-
"@deepseek-ai/dsh-
|
|
50
|
+
"@deepseek-ai/dsh-agent-default-model": "0.2.0-rc.1",
|
|
51
|
+
"@deepseek-ai/dsh-api-remotes": "0.2.0-rc.1",
|
|
52
|
+
"@deepseek-ai/dsh-app-boot": "0.2.0-rc.1",
|
|
53
|
+
"@deepseek-ai/dsh-attachment": "0.2.0-rc.1",
|
|
54
|
+
"@deepseek-ai/dsh-client-store": "0.2.0-rc.1",
|
|
55
|
+
"@deepseek-ai/dsh-client-ui-chat": "0.2.0-rc.1",
|
|
56
|
+
"@deepseek-ai/dsh-client-ui-conversation": "0.2.0-rc.1",
|
|
57
|
+
"@deepseek-ai/dsh-client-ui-primitives": "0.2.0-rc.1",
|
|
58
|
+
"@deepseek-ai/dsh-client-ui-renderer": "0.2.0-rc.1",
|
|
59
|
+
"@deepseek-ai/dsh-client-ui-session": "0.2.0-rc.1",
|
|
60
|
+
"@deepseek-ai/dsh-client-ui-settings": "0.2.0-rc.1",
|
|
61
|
+
"@deepseek-ai/dsh-client-ui-sidebar": "0.2.0-rc.1",
|
|
62
|
+
"@deepseek-ai/dsh-client-ui-slots": "0.2.0-rc.1",
|
|
63
|
+
"@deepseek-ai/dsh-config-editor": "0.2.0-rc.1",
|
|
64
|
+
"@deepseek-ai/dsh-credentials": "0.2.0-rc.1",
|
|
65
|
+
"@deepseek-ai/dsh-credentials-local": "0.2.0-rc.1",
|
|
66
|
+
"@deepseek-ai/dsh-llm": "0.2.0-rc.1",
|
|
67
|
+
"@deepseek-ai/dsh-llm-pi-ai": "0.2.0-rc.1",
|
|
68
|
+
"@deepseek-ai/dsh-settings": "0.2.0-rc.1",
|
|
69
|
+
"@deepseek-ai/dsh-system-prompt": "0.2.0-rc.1",
|
|
70
|
+
"@deepseek-ai/dsh-tools": "0.2.0-rc.1",
|
|
71
|
+
"@deepseek-ai/dsh-web": "0.2.0-rc.1",
|
|
72
|
+
"@deepseek-ai/dsh-workspace": "0.2.0-rc.1",
|
|
72
73
|
"@deepseek-ai/schemastery": "3.18.4",
|
|
73
74
|
"@types/node": "^22",
|
|
74
75
|
"@types/react": "^18",
|
|
@@ -81,7 +82,7 @@
|
|
|
81
82
|
"typescript": "^5",
|
|
82
83
|
"vitest": "^3",
|
|
83
84
|
"yaml": "^2.8.1",
|
|
84
|
-
"@deepseek-ai/dsh-client-ui-layout": "0.
|
|
85
|
+
"@deepseek-ai/dsh-client-ui-layout": "0.2.0-rc.1"
|
|
85
86
|
},
|
|
86
87
|
"scripts": {
|
|
87
88
|
"typecheck": "tsc --noEmit",
|