weifuwu 0.60.0 → 0.61.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.
Files changed (38) hide show
  1. package/README.md +23 -7
  2. package/dist/ai/agent.d.ts +29 -1
  3. package/dist/ai/client.d.ts +15 -0
  4. package/dist/ai/index.d.ts +2 -1
  5. package/dist/client/diff.d.ts +15 -0
  6. package/dist/client/hydration.d.ts +13 -0
  7. package/dist/client/index.d.ts +4 -0
  8. package/dist/client/index.js +3 -2214
  9. package/dist/client/middleware/api.d.ts +2 -0
  10. package/dist/client/motion.d.ts +8 -0
  11. package/dist/client/registry.d.ts +34 -0
  12. package/dist/client/render.d.ts +13 -14
  13. package/dist/client/types.d.ts +28 -0
  14. package/dist/client/ui.d.ts +56 -0
  15. package/dist/components/Badge/Badge.d.ts +1 -1
  16. package/dist/components/Button/Button.d.ts +3 -0
  17. package/dist/components/Card/Card.d.ts +2 -0
  18. package/dist/components/Confirm/Confirm.d.ts +8 -1
  19. package/dist/components/Dropdown/Dropdown.d.ts +2 -0
  20. package/dist/components/Icon/Icon.d.ts +19 -0
  21. package/dist/components/Input/Input.d.ts +5 -0
  22. package/dist/components/Modal/Modal.d.ts +2 -0
  23. package/dist/components/PageHeader/PageHeader.d.ts +2 -0
  24. package/dist/components/StatCard/StatCard.d.ts +2 -0
  25. package/dist/components/Table/Table.d.ts +4 -0
  26. package/dist/components/Toast/Toast.d.ts +13 -1
  27. package/dist/components/index.d.ts +2 -0
  28. package/dist/components/index.js +1 -3381
  29. package/dist/components/style.css +282 -134
  30. package/dist/core/router.d.ts +10 -10
  31. package/dist/core/serve.d.ts +1 -1
  32. package/dist/index.d.ts +3 -1
  33. package/dist/index.js +523 -11
  34. package/dist/layout/weifuwu-layout.css +106 -17
  35. package/dist/messager/index.d.ts +107 -0
  36. package/dist/types.d.ts +2 -2
  37. package/dist/user/index.d.ts +3 -2
  38. package/package.json +1 -1
package/README.md CHANGED
@@ -236,8 +236,8 @@ createApp().use(router({ routes })).mount('#root', RouteView, { hydrate: true })
236
236
  | 资源 | CDN 地址 | 说明 |
237
237
  |------|---------|------|
238
238
  | `weifuwu/client` | `https://unpkg.com/weifuwu@latest/dist/client/index.js` | 客户端核心(createApp, h, 路由, 状态管理等) |
239
- | `weifuwu/components` | `https://unpkg.com/weifuwu@latest/dist/components/index.js` | 46 个 UI 组件(Button, Card, Table, Modal 等) |
240
- | 组件样式 | `https://unpkg.com/weifuwu@latest/dist/components/style.css` | 组件 CSS + 115 个主题 Token + 67 个布局原语 |
239
+ | `weifuwu/components` | `https://unpkg.com/weifuwu@latest/dist/components/index.js` | 48 个 UI 组件(Button, Card, Table, Modal, Icon 等) |
240
+ | 组件样式 | `https://unpkg.com/weifuwu@latest/dist/components/style.css` | 组件 CSS + 141 个主题 Token + 67 个布局原语 |
241
241
  | 独立布局系统 | `https://unpkg.com/weifuwu@latest/dist/layout/weifuwu-layout.css` | 仅 CSS 布局,不依赖 JS |
242
242
 
243
243
 
@@ -275,8 +275,8 @@ createApp().use(router({ routes })).mount('#root', RouteView, { hydrate: true })
275
275
  | `weifuwu/client` | **ErrorBoundary** | 错误边界组件 | createApp |
276
276
  | `weifuwu/client` | **lockScroll/trapFocus** | 滚动锁定 / 焦点陷阱工具 | — |
277
277
  | `weifuwu/client` | **popup** | 弹层 fixed 定位工具(`computeFixedPos` / `computeFixedPosRect`) | — |
278
- | `weifuwu/components` | **47 个组件** | Button/Table/Modal/Confirm/Toast/... + `confirm()` / `toast()` 命令式中间件 | weifuwu/client |
279
- | `weifuwu/layout` | **CSS 布局** | 67 个布局原语 + 115 个主题 Token(也支持 `weifuwu/layout/style.css`) | — |
278
+ | `weifuwu/components` | **48 个组件** | Button/Table/Modal/Confirm/Toast/... + `confirm()` / `toast()` 命令式中间件 | weifuwu/client |
279
+ | `weifuwu/layout` | **CSS 布局** | 67 个布局原语 + 141 个主题 Token(也支持 `weifuwu/layout/style.css`) | — |
280
280
 
281
281
  ---
282
282
 
@@ -2450,7 +2450,7 @@ props 变化 ──────────────────────
2450
2450
 
2451
2451
  # 布局系统 (`weifuwu/layout`)
2452
2452
 
2453
- 纯 CSS 布局原语 + 工具类 + 115 个主题 Token。不绑定任何 JS 框架。
2453
+ 纯 CSS 布局原语 + 工具类 + 141 个主题 Token。不绑定任何 JS 框架。
2454
2454
 
2455
2455
  > **学习路径与命名规范**:见 [`docs/style-guide.md`](./docs/style-guide.md)——统一语法 `wf-<域>-<名>`、三档学习(组件 → 10 核心原语 → 完整速查)、场景速查、变量定制。
2456
2456
 
@@ -2547,7 +2547,7 @@ app.get('/layout.css', (req, ctx) => ctx.ui.css('weifuwu/layout'))
2547
2547
  | `wf-truncate` | 单行省略(ellipsis) |
2548
2548
  | `wf-line-clamp-2/3` | 多行截断 |
2549
2549
 
2550
- ## 115 个主题 Token
2550
+ ## 141 个主题 Token
2551
2551
 
2552
2552
  **双层结构**:原始层(Primitive,色值只定义一次,品牌/暗色调校改这里)+ 语义层(Semantic,组件消费)。
2553
2553
 
@@ -2567,6 +2567,11 @@ app.get('/layout.css', (req, ctx) => ctx.ui.css('weifuwu/layout'))
2567
2567
  --wf-color-error / --wf-color-error-bg
2568
2568
  --wf-color-info / --wf-color-info-bg
2569
2569
 
2570
+ /* 语义文字色(P2):浅底可读 700 级,文字用 -text、填充用 500 级 */
2571
+ --wf-color-primary-text / --wf-color-success-text / --wf-color-warning-text / --wf-color-error-text / --wf-color-info-text
2572
+ --wf-color-on-brand /* 实心品牌/语义底上的文字与图标 */
2573
+ --wf-overlay /* 浮层遮罩(Modal/Drawer),暗色自动加深 */
2574
+
2570
2575
  /* 文字色 */
2571
2576
  --wf-color-text / --wf-color-text-secondary / --wf-color-text-tertiary / --wf-color-text-disabled
2572
2577
 
@@ -2579,7 +2584,7 @@ app.get('/layout.css', (req, ctx) => ctx.ui.css('weifuwu/layout'))
2579
2584
  /* 字体 */
2580
2585
  --wf-font-sans / --wf-font-mono
2581
2586
 
2582
- /* 字号: xs sm base lg xl 2xl 3xl 4xl 5xl */
2587
+ /* 字号: xs sm base lg xl 2xl 3xl 4xl 5xl display */
2583
2588
  --wf-font-size-*
2584
2589
 
2585
2590
  /* 字重: normal medium semibold bold */
@@ -2603,6 +2608,17 @@ app.get('/layout.css', (req, ctx) => ctx.ui.css('weifuwu/layout'))
2603
2608
  /* 阴影: sm md lg */
2604
2609
  --wf-shadow-*
2605
2610
 
2611
+ /* 动效(P0):时长阶梯/缓动曲线/位移量,全站动效统一引用 */
2612
+ --wf-dur-fast / --wf-dur-base / --wf-dur-slow
2613
+ --wf-ease-out / --wf-ease-in / --wf-ease-snap
2614
+ --wf-motion-sm / --wf-motion-md / --wf-motion-lg
2615
+
2616
+ /* 表头/分组标题(P5):CJK 感知,默认 none/0,英文可覆盖 */
2617
+ --wf-heading-case / --wf-heading-tracking
2618
+
2619
+ /* 数字(P5):tabular-nums 防宽度抖动(wf-nums 工具类) */
2620
+ --wf-nums
2621
+
2606
2622
  /* 其他 */
2607
2623
  --wf-border-width / --wf-focus-ring
2608
2624
  --wf-transition-duration / --wf-transition-timing
@@ -14,7 +14,7 @@
14
14
  */
15
15
  import { type WfEmitter } from './sse.ts';
16
16
  import type { AiClient } from './client.ts';
17
- import type { ChatMessage } from './types.ts';
17
+ import type { ChatMessage, WfUsage } from './types.ts';
18
18
  export interface ToolContext {
19
19
  /** 工具执行声道:emit('wf:tool_progress', ...) 或 emit('x:*', ...) */
20
20
  emit: WfEmitter;
@@ -43,8 +43,36 @@ export interface AgentRunOptions {
43
43
  signal?: AbortSignal;
44
44
  traceId?: string;
45
45
  }
46
+ /** agent 执行步骤(结构化结果用,协议 wf:step/wf:tool_result 的汇总) */
47
+ export interface AgentStep {
48
+ type: 'llm' | 'tool_call' | 'tool_result';
49
+ content?: string;
50
+ toolCall?: {
51
+ id: string;
52
+ name: string;
53
+ arguments: string;
54
+ };
55
+ toolResult?: string;
56
+ }
57
+ /** 结构化运行结果(非流式服务编排用;流式场景走 stream/SSE 的 wf:* 事件) */
58
+ export interface AgentRunResult {
59
+ content: string;
60
+ steps: AgentStep[];
61
+ usage?: WfUsage;
62
+ }
46
63
  export interface AgentRunner {
47
64
  /** 运行 agent → SSE Response(wf: 协议事件流),路由直接 return */
48
65
  run: (messages: ChatMessage[], options?: AgentRunOptions) => Response;
66
+ /**
67
+ * 事件流模式:wf:* 事件打到自定义 emitter(SSE 只是默认实现)。
68
+ * 应用层可把事件接到 WS/回调/自有协议(协议适配器)——不绑死传输通道。
69
+ */
70
+ stream: (messages: ChatMessage[], options?: {
71
+ emit: WfEmitter;
72
+ signal?: AbortSignal;
73
+ traceId?: string;
74
+ }) => Promise<void>;
75
+ /** 结构化结果模式:收集 wf:* 事件 → AgentRunResult(非流式服务编排用) */
76
+ runToResult: (messages: ChatMessage[], options?: AgentRunOptions) => Promise<AgentRunResult>;
49
77
  }
50
78
  export declare function createAgent(client: AiClient, config: AgentConfig): AgentRunner;
@@ -57,6 +57,17 @@ export interface AiClientOptions {
57
57
  baseUrl: string;
58
58
  apiKey: string;
59
59
  defaultModel: string;
60
+ /** embedding provider 配置(可选;未配时 embed/embedMany 抛 AiError('unsupported')) */
61
+ embedding?: AiEmbeddingOptions;
62
+ }
63
+ /** embedding provider 配置——默认参数与 DashScope compatible-mode 对齐(DeepSeek 无 embedding API) */
64
+ export interface AiEmbeddingOptions {
65
+ /** 默认读 DASHSCOPE_API_KEY */
66
+ apiKey?: string;
67
+ /** 默认 'https://dashscope.aliyuncs.com/compatible-mode/v1' */
68
+ baseUrl?: string;
69
+ /** 默认读 DASHSCOPE_EMBEDDING_MODEL,回退 'text-embedding-v4' */
70
+ defaultModel?: string;
60
71
  }
61
72
  /** 单轮 LLM 流式调用的聚合结果(agent 循环用) */
62
73
  export interface StreamFinishResult {
@@ -96,6 +107,10 @@ export interface AiClient {
96
107
  name: string;
97
108
  args: Record<string, unknown>;
98
109
  }, emit: WfEmitter, timeoutMs?: number): Promise<WfApprovalResponse>;
110
+ /** 单文本嵌入(知识库/语义检索;需 ai({ embedding }) 配置,未配抛 AiError) */
111
+ embed(text: string): Promise<number[]>;
112
+ /** 批量文本嵌入(按输入顺序返回) */
113
+ embedMany(texts: string[]): Promise<number[][]>;
99
114
  }
100
115
  export declare function createAiClient(opts: AiClientOptions): AiClient;
101
116
  /** 审批默认超时:5 分钟 */
@@ -29,6 +29,8 @@
29
29
  import type { Context, Middleware } from '../types.ts';
30
30
  import { type AiClient, type AiClientOptions } from './client.ts';
31
31
  import { type AgentConfig, type AgentRunner } from './agent.ts';
32
+ export type { AiEmbeddingOptions } from './client.ts';
33
+ export type { AgentRunResult, AgentStep, AgentTool, AgentConfig, AgentRunner, ToolContext } from './agent.ts';
32
34
  export interface AiOptions extends Partial<AiClientOptions> {
33
35
  }
34
36
  export interface AiInjected {
@@ -51,4 +53,3 @@ export type { WfStreamEvent, WfMessageStart, WfToken, WfUsage, WfDone, WfError,
51
53
  export type { WfEmitter } from './sse.ts';
52
54
  export { AiError } from './client.ts';
53
55
  export type { AiClient, ChatResponse } from './client.ts';
54
- export type { AgentConfig, AgentTool, AgentRunner, ToolContext } from './agent.ts';
@@ -0,0 +1,15 @@
1
+ /**
2
+ * weifuwu/client 增量 diff — patchValue 及全部 diff 辅助
3
+ *
4
+ * 从 render.ts 拆出(P2 结构拆分)。依赖方向:
5
+ * diff.ts → render.ts(renderValue/mountComponent/patchPortal/renderPortal)
6
+ * diff.ts → registry.ts(callRefCleanup)
7
+ * render.ts 不依赖 diff.ts(单向,无环)
8
+ */
9
+ import type { WfuiContext } from './types.ts';
10
+ export declare function patchValue(parent: Node, oldNode: Node | null, oldInput: any, newInput: any, ctx: WfuiContext): Node | null;
11
+ export declare function patchProps(el: Element, oldProps: any, newProps: any): void;
12
+ /** 为无 key 的子节点自动分配位置 key,确保 keyed diff 正确性 */
13
+ export declare function ensureKeys(oldChildren: any[], newChildren: any[]): void;
14
+ export declare function normalize(children: any): any[];
15
+ export declare function patchKeyedChildren(parent: Node, oldChildren: any[], newChildren: any[], ctx: WfuiContext): void;
@@ -0,0 +1,13 @@
1
+ /**
2
+ * weifuwu/client Hydration(游标收养)— 收养服务端 HTML,不重建 DOM
3
+ *
4
+ * 从 render.ts 拆出(P2 结构拆分)。依赖:render.ts(flattenChildren/SVG 常量)、
5
+ * diff.ts(patchProps)、registry.ts(idRegistry/nextComponentId/resolveAsyncFactory)。
6
+ */
7
+ import type { VNode } from './vnode.ts';
8
+ import type { WfuiContext } from './types.ts';
9
+ /**
10
+ * Hydration 挂载入口:收养 container 内现有服务端 HTML。
11
+ * 渲染完收尾:删除服务端有、客户端没有的残留 DOM。
12
+ */
13
+ export declare function hydrateVNode(container: Element, vnode: VNode, ctx: WfuiContext): Promise<void>;
@@ -42,6 +42,10 @@ export { i18n } from './i18n.ts';
42
42
  export type { I18nOptions, I18nState, I18nInjected } from './i18n.ts';
43
43
  export { lockScroll, unlockScroll } from './scroll-lock.ts';
44
44
  export { trapFocus } from './focus-trap.ts';
45
+ export { mountVNode, callRefCleanup, clearAsyncComponentCache } from './render.ts';
46
+ export { hydrateVNode } from './hydration.ts';
47
+ export { patchValue } from './diff.ts';
48
+ export { animateOut } from './motion.ts';
45
49
  export { computeFixedPos, computeFixedPosRect } from './popup.ts';
46
50
  export type { FixedPos, Placement } from './popup.ts';
47
51
  export { zhCN } from './locale/zh_CN.ts';