@donglegeyu/company-ui 1.2.43 → 1.2.45

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 (67) hide show
  1. package/dist/cjs/ai-assistant/AiActionGuard/AiActionConfirmModal.d.ts +10 -0
  2. package/dist/cjs/ai-assistant/AiActionGuard/AiActionConfirmModal.js +87 -0
  3. package/dist/cjs/ai-assistant/AiActionGuard/AiActionGuard.d.ts +11 -0
  4. package/dist/cjs/ai-assistant/AiActionGuard/AiActionGuard.js +467 -0
  5. package/dist/cjs/ai-assistant/AiActionGuard/index.d.ts +5 -0
  6. package/dist/cjs/ai-assistant/AiActionGuard/index.js +51 -0
  7. package/dist/cjs/ai-assistant/AiActionGuard/policy.d.ts +23 -0
  8. package/dist/cjs/ai-assistant/AiActionGuard/policy.js +146 -0
  9. package/dist/cjs/ai-assistant/AiActionGuard/types.d.ts +130 -0
  10. package/dist/cjs/ai-assistant/AiActionGuard/types.js +17 -0
  11. package/dist/cjs/ai-assistant/aiDraft.d.ts +60 -0
  12. package/dist/cjs/ai-assistant/aiDraft.js +17 -0
  13. package/dist/cjs/ai-assistant/index.d.ts +2 -0
  14. package/dist/cjs/ai-assistant/index.js +6 -1
  15. package/dist/cjs/shared-components/BaseInfoForm/index.d.ts +7 -2
  16. package/dist/cjs/shared-components/BaseInfoForm/index.js +146 -47
  17. package/dist/cjs/sidebar-config.js +15 -1
  18. package/dist/cjs/template-components/AiAssistantDock/index.d.ts +7 -1
  19. package/dist/cjs/template-components/AiAssistantDock/index.js +9 -6
  20. package/dist/cjs/template-components/DrawerDetailTemplate/index.d.ts +42 -0
  21. package/dist/cjs/template-components/DrawerDetailTemplate/index.js +120 -0
  22. package/dist/cjs/template-components/DrawerDetailTemplate/index.scss +56 -0
  23. package/dist/cjs/template-components/DrawerFormTemplate/index.d.ts +35 -0
  24. package/dist/cjs/template-components/DrawerFormTemplate/index.js +132 -0
  25. package/dist/cjs/template-components/DrawerFormTemplate/index.scss +3 -0
  26. package/dist/cjs/template-components/FilterForm/index.d.ts +6 -1
  27. package/dist/cjs/template-components/FilterForm/index.js +175 -54
  28. package/dist/cjs/template-components/FormPageTemplate/index.d.ts +10 -1
  29. package/dist/cjs/template-components/FormPageTemplate/index.js +109 -1
  30. package/dist/cjs/template-components/SmartListTemplate/index.d.ts +6 -1
  31. package/dist/cjs/template-components/SmartListTemplate/index.js +6 -2
  32. package/dist/cjs/template-components/index.d.ts +4 -0
  33. package/dist/cjs/template-components/index.js +6 -0
  34. package/dist/es/ai-assistant/AiActionGuard/AiActionConfirmModal.d.ts +10 -0
  35. package/dist/es/ai-assistant/AiActionGuard/AiActionConfirmModal.js +58 -0
  36. package/dist/es/ai-assistant/AiActionGuard/AiActionGuard.d.ts +11 -0
  37. package/dist/es/ai-assistant/AiActionGuard/AiActionGuard.js +676 -0
  38. package/dist/es/ai-assistant/AiActionGuard/index.d.ts +5 -0
  39. package/dist/es/ai-assistant/AiActionGuard/index.js +4 -0
  40. package/dist/es/ai-assistant/AiActionGuard/policy.d.ts +23 -0
  41. package/dist/es/ai-assistant/AiActionGuard/policy.js +97 -0
  42. package/dist/es/ai-assistant/AiActionGuard/types.d.ts +130 -0
  43. package/dist/es/ai-assistant/AiActionGuard/types.js +1 -0
  44. package/dist/es/ai-assistant/aiDraft.d.ts +60 -0
  45. package/dist/es/ai-assistant/aiDraft.js +1 -0
  46. package/dist/es/ai-assistant/index.d.ts +2 -0
  47. package/dist/es/ai-assistant/index.js +3 -1
  48. package/dist/es/shared-components/BaseInfoForm/index.d.ts +7 -2
  49. package/dist/es/shared-components/BaseInfoForm/index.js +128 -24
  50. package/dist/es/sidebar-config.js +9 -0
  51. package/dist/es/template-components/AiAssistantDock/index.d.ts +7 -1
  52. package/dist/es/template-components/AiAssistantDock/index.js +13 -1
  53. package/dist/es/template-components/DrawerDetailTemplate/index.d.ts +42 -0
  54. package/dist/es/template-components/DrawerDetailTemplate/index.js +112 -0
  55. package/dist/es/template-components/DrawerDetailTemplate/index.scss +56 -0
  56. package/dist/es/template-components/DrawerFormTemplate/index.d.ts +35 -0
  57. package/dist/es/template-components/DrawerFormTemplate/index.js +149 -0
  58. package/dist/es/template-components/DrawerFormTemplate/index.scss +3 -0
  59. package/dist/es/template-components/FilterForm/index.d.ts +6 -1
  60. package/dist/es/template-components/FilterForm/index.js +165 -7
  61. package/dist/es/template-components/FormPageTemplate/index.d.ts +10 -1
  62. package/dist/es/template-components/FormPageTemplate/index.js +103 -2
  63. package/dist/es/template-components/SmartListTemplate/index.d.ts +6 -1
  64. package/dist/es/template-components/SmartListTemplate/index.js +6 -2
  65. package/dist/es/template-components/index.d.ts +4 -0
  66. package/dist/es/template-components/index.js +2 -0
  67. package/package.json +5 -2
@@ -0,0 +1,146 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // src/ai-assistant/AiActionGuard/policy.ts
20
+ var policy_exports = {};
21
+ __export(policy_exports, {
22
+ AI_ACTION_LABELS: () => AI_ACTION_LABELS,
23
+ AI_ACTION_TYPES: () => AI_ACTION_TYPES,
24
+ DEFAULT_AI_ACTION_POLICY: () => DEFAULT_AI_ACTION_POLICY,
25
+ WRITE_ACTION_TYPES: () => WRITE_ACTION_TYPES,
26
+ createAiActionConfirmRequest: () => createAiActionConfirmRequest,
27
+ isKnownAiAction: () => isKnownAiAction,
28
+ requiresIdempotencyKey: () => requiresIdempotencyKey,
29
+ resolveAiActionDecision: () => resolveAiActionDecision
30
+ });
31
+ module.exports = __toCommonJS(policy_exports);
32
+ var AI_ACTION_TYPES = [
33
+ "navigate",
34
+ "open-record",
35
+ "prefill-filter",
36
+ "backfill",
37
+ "rollback",
38
+ "validate",
39
+ "query",
40
+ "create-draft",
41
+ "explain",
42
+ "export",
43
+ "submit",
44
+ "publish",
45
+ "delete",
46
+ "bulk-update",
47
+ "approve",
48
+ "attachment-download",
49
+ "close-tab",
50
+ "undo"
51
+ ];
52
+ var WRITE_ACTION_TYPES = [
53
+ "submit",
54
+ "publish",
55
+ "delete",
56
+ "bulk-update",
57
+ "approve"
58
+ ];
59
+ var DEFAULT_AI_ACTION_POLICY = {
60
+ // —— 默认放行 ——
61
+ navigate: "allow",
62
+ "open-record": "allow",
63
+ "prefill-filter": "allow",
64
+ backfill: "allow",
65
+ rollback: "allow",
66
+ validate: "allow",
67
+ query: "allow",
68
+ "create-draft": "allow",
69
+ explain: "allow",
70
+ "close-tab": "allow",
71
+ // —— 默认需确认 ——
72
+ export: "confirm",
73
+ "attachment-download": "confirm",
74
+ // —— 默认拒绝 ——
75
+ submit: "deny",
76
+ publish: "deny",
77
+ delete: "deny",
78
+ "bulk-update": "deny",
79
+ approve: "deny",
80
+ undo: "allow"
81
+ };
82
+ var AI_ACTION_LABELS = {
83
+ navigate: "跳转页面",
84
+ "open-record": "打开记录",
85
+ "prefill-filter": "预填筛选条件",
86
+ backfill: "回填表单",
87
+ rollback: "撤回到上版",
88
+ validate: "核验表单",
89
+ query: "查询数据",
90
+ "create-draft": "创建草稿",
91
+ explain: "解释说明",
92
+ export: "导出数据",
93
+ submit: "提交",
94
+ publish: "发布",
95
+ delete: "删除",
96
+ "bulk-update": "批量更新",
97
+ approve: "审批通过",
98
+ "attachment-download": "下载附件",
99
+ "close-tab": "关闭页签",
100
+ undo: "撤销"
101
+ };
102
+ var AI_ACTION_SET = new Set(AI_ACTION_TYPES);
103
+ function isKnownAiAction(action) {
104
+ return AI_ACTION_SET.has(action);
105
+ }
106
+ function requiresIdempotencyKey(action, params) {
107
+ if (WRITE_ACTION_TYPES.includes(action))
108
+ return true;
109
+ return action === "create-draft" && params.persist === true;
110
+ }
111
+ function resolveAiActionDecision(policy, action, params, navigateCount) {
112
+ const override = policy == null ? void 0 : policy[action];
113
+ if (override)
114
+ return override;
115
+ if (!isKnownAiAction(action))
116
+ return "deny";
117
+ if (action === "navigate" && navigateCount >= 1)
118
+ return "confirm";
119
+ if (action === "rollback" && params.hasUnsavedChanges === true)
120
+ return "confirm";
121
+ return DEFAULT_AI_ACTION_POLICY[action] ?? "deny";
122
+ }
123
+ function createAiActionConfirmRequest(action, params, domain, confirmText) {
124
+ const label = AI_ACTION_LABELS[action];
125
+ return {
126
+ action,
127
+ params,
128
+ domain,
129
+ label,
130
+ title: (confirmText == null ? void 0 : confirmText.title) ?? `确认执行「${label}」?`,
131
+ content: (confirmText == null ? void 0 : confirmText.content) ?? `AI 请求执行「${label}」动作,该操作需经你确认后才会继续。`,
132
+ okText: (confirmText == null ? void 0 : confirmText.okText) ?? "确认执行",
133
+ cancelText: (confirmText == null ? void 0 : confirmText.cancelText) ?? "取消"
134
+ };
135
+ }
136
+ // Annotate the CommonJS export names for ESM import in node:
137
+ 0 && (module.exports = {
138
+ AI_ACTION_LABELS,
139
+ AI_ACTION_TYPES,
140
+ DEFAULT_AI_ACTION_POLICY,
141
+ WRITE_ACTION_TYPES,
142
+ createAiActionConfirmRequest,
143
+ isKnownAiAction,
144
+ requiresIdempotencyKey,
145
+ resolveAiActionDecision
146
+ });
@@ -0,0 +1,130 @@
1
+ import type { CSSProperties, ReactNode } from "react";
2
+ /** AI 动作类型(白名单,未知动作一律拒绝) */
3
+ export type AiActionType = "navigate" | "open-record" | "prefill-filter" | "backfill" | "rollback" | "validate" | "query" | "create-draft" | "explain" | "export" | "submit" | "publish" | "delete" | "bulk-update" | "approve" | "attachment-download" | "close-tab" | "undo";
4
+ /** 动作决策 */
5
+ export type AiActionDecision = "allow" | "confirm" | "deny";
6
+ /** 动作参数:已知开关 + 自由业务参数 */
7
+ export interface AiActionParams {
8
+ /** 写类动作幂等键:同一键重复调用不得重复执行 */
9
+ idempotencyKey?: string;
10
+ /** rollback:调用方声明存在未保存的手改时需二次确认 */
11
+ hasUnsavedChanges?: boolean;
12
+ /** create-draft:是否落库(true 时按写类动作要求幂等键) */
13
+ persist?: boolean;
14
+ [key: string]: unknown;
15
+ }
16
+ /** 策略覆盖表:未登记的动作沿用默认策略,默认策略里也没有的一律 deny */
17
+ export type AiActionPolicy = Partial<Record<AiActionType, AiActionDecision>>;
18
+ /** 审计结果 */
19
+ export type AiActionAuditResult = "ok" | "denied" | "cancelled" | "error";
20
+ /** 撤销句柄(run 成功后由组件签发,调用方可用 useAiAction().undo 撤销) */
21
+ export interface AiUndoHandle {
22
+ id: string;
23
+ action: AiActionType;
24
+ label: string;
25
+ }
26
+ /** 审计事件(字段固定,userId / sessionId 均由宿主注入) */
27
+ export interface AiActionAuditEvent {
28
+ action: AiActionType;
29
+ params: AiActionParams;
30
+ domain: string;
31
+ result: AiActionAuditResult;
32
+ userId: string;
33
+ sessionId: string;
34
+ timestamp: number;
35
+ undoHandle?: AiUndoHandle;
36
+ }
37
+ /** 确认请求:内置弹层或宿主自定义确认 UI 的唯一入参 */
38
+ export interface AiActionConfirmRequest {
39
+ action: AiActionType;
40
+ params: AiActionParams;
41
+ domain: string;
42
+ /** 动作中文名 */
43
+ label: string;
44
+ title: string;
45
+ content: string;
46
+ okText: string;
47
+ cancelText: string;
48
+ }
49
+ /** 确认文案覆盖 */
50
+ export interface AiActionConfirmText {
51
+ title?: string;
52
+ content?: string;
53
+ okText?: string;
54
+ cancelText?: string;
55
+ }
56
+ /** 失败原因:denied=策略拒绝 / forbidden=权限不足 / cancelled=用户取消 / error=异常 */
57
+ export type AiActionReason = "denied" | "forbidden" | "cancelled" | "error";
58
+ /** 执行成功结果 */
59
+ export interface AiActionSuccess<T = unknown> {
60
+ ok: true;
61
+ action: AiActionType;
62
+ decision: AiActionDecision;
63
+ data?: T;
64
+ undoHandle?: AiUndoHandle;
65
+ }
66
+ /** 执行失败结果 */
67
+ export interface AiActionFailure {
68
+ ok: false;
69
+ action: AiActionType;
70
+ decision: AiActionDecision;
71
+ reason: AiActionReason;
72
+ message?: string;
73
+ }
74
+ export type AiActionResult<T = unknown> = AiActionSuccess<T> | AiActionFailure;
75
+ /** canRun 前置探测结果(不产生审计) */
76
+ export interface AiActionCanRunResult {
77
+ ok: boolean;
78
+ decision: AiActionDecision;
79
+ reason?: "denied" | "forbidden" | "error";
80
+ message?: string;
81
+ }
82
+ /** 调用方执行回调的返回值:可带回数据与撤销函数 */
83
+ export interface AiActionExecutionResult<T = unknown> {
84
+ data?: T;
85
+ /** 调用方注册撤销函数;成功后由组件签发 undoHandle */
86
+ undo?: () => void | Promise<void>;
87
+ }
88
+ export type AiActionExecutor<T = unknown> = (params: AiActionParams) => AiActionExecutionResult<T> | Promise<AiActionExecutionResult<T>>;
89
+ /** useAiAction() 返回值 */
90
+ export interface UseAiActionValue {
91
+ /** 前置探测:是否允许执行(confirm 视为可执行),每次实时校验权限 */
92
+ canRun: (action: AiActionType, params?: AiActionParams) => Promise<AiActionCanRunResult>;
93
+ /** 执行动作:策略 → 确认 → 实时权限 → 幂等 → 执行 → 审计 */
94
+ run: <T = unknown>(action: AiActionType, params?: AiActionParams, execute?: AiActionExecutor<T>) => Promise<AiActionResult<T>>;
95
+ /** 撤销:同样受策略约束并产生审计 */
96
+ undo: (handle: AiUndoHandle) => Promise<AiActionResult<void>>;
97
+ }
98
+ /** AiActionGuard 属性 */
99
+ export interface AiActionGuardProps {
100
+ /** 策略覆盖(覆盖后不再叠加默认的连续跳转 / 未保存修改动态规则) */
101
+ policy?: AiActionPolicy;
102
+ /** 当前数据域,必须由服务端或宿主注入,不得取自 URL 或用户输入 */
103
+ domain: string;
104
+ /** 每次执行前实时调用,不得缓存结果 */
105
+ checkPermission: (action: AiActionType, params: AiActionParams) => boolean | Promise<boolean>;
106
+ /** 审计回调(每次 run / undo 后调用) */
107
+ onAudit?: (event: AiActionAuditEvent) => void;
108
+ /** 宿主自定义确认 UI;不传则使用内置 AiActionConfirmModal */
109
+ onConfirm?: (request: AiActionConfirmRequest) => Promise<boolean>;
110
+ /** 当前用户 ID,由宿主传入(组件不推断) */
111
+ userId: string;
112
+ /** 会话 ID,缺省由组件按挂载实例生成 */
113
+ sessionId?: string;
114
+ /** 内置确认弹层文案覆盖 */
115
+ confirmText?: AiActionConfirmText;
116
+ children: ReactNode;
117
+ }
118
+ /** AiActionConfirmModal 属性 */
119
+ export interface AiActionConfirmModalProps {
120
+ open: boolean;
121
+ request?: AiActionConfirmRequest;
122
+ title?: string;
123
+ content?: string;
124
+ okText?: string;
125
+ cancelText?: string;
126
+ onOk: () => void;
127
+ onCancel: () => void;
128
+ className?: string;
129
+ style?: CSSProperties;
130
+ }
@@ -0,0 +1,17 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __copyProps = (to, from, except, desc) => {
6
+ if (from && typeof from === "object" || typeof from === "function") {
7
+ for (let key of __getOwnPropNames(from))
8
+ if (!__hasOwnProp.call(to, key) && key !== except)
9
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
10
+ }
11
+ return to;
12
+ };
13
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
14
+
15
+ // src/ai-assistant/AiActionGuard/types.ts
16
+ var types_exports = {};
17
+ module.exports = __toCommonJS(types_exports);
@@ -0,0 +1,60 @@
1
+ import type { AiUndoHandle } from "./AiActionGuard/types";
2
+ /** AI 字段来源 */
3
+ export type AiFieldSource = "ai";
4
+ /** AI 字段标记:标记某个字段的值来自 AI */
5
+ export interface AiFieldMark {
6
+ field: string;
7
+ source: AiFieldSource;
8
+ }
9
+ /** 字段提示(只读校验结果,渲染错误/警告样式,不写入表单数据) */
10
+ export interface AiFieldHint {
11
+ field: string;
12
+ level: "error" | "warning";
13
+ message: string;
14
+ }
15
+ /** 草稿元信息 */
16
+ export interface AiDraftMeta {
17
+ /** 是否由 AI 生成 */
18
+ aiGenerated: boolean;
19
+ /** 草稿版本号 */
20
+ version?: number;
21
+ /** 是否存在未保存的手动修改 */
22
+ dirty?: boolean;
23
+ /** 字段级来源标记;不传时仅展示整体 AI 预填提示,不逐字段标记 */
24
+ fields?: AiFieldMark[];
25
+ }
26
+ /** 表单变更来源 */
27
+ export type AiChangeSource = "user" | "ai";
28
+ /** 表单变更元信息(onChange / onFieldChange 的第二个参数) */
29
+ export interface AiFormChangeMeta {
30
+ /** 本次变更来源:用户手改 / AI 写入 */
31
+ source: AiChangeSource;
32
+ /** 本次变更涉及的字段 */
33
+ changedFields: string[];
34
+ }
35
+ /** AI 筛选调整事件 */
36
+ export interface AiFilterChangeEvent {
37
+ /** apply = AI 应用 / undo = 恢复上一版 */
38
+ type: "apply" | "undo";
39
+ /** 调整后的完整筛选值 */
40
+ values: Record<string, unknown>;
41
+ /** AI 调整的字段 */
42
+ fields: string[];
43
+ /** 上一版筛选值(用于恢复) */
44
+ previous: Record<string, unknown>;
45
+ /** 撤销句柄(可选,结构与 AiActionGuard 签发的一致) */
46
+ undoHandle?: AiUndoHandle;
47
+ }
48
+ /** 草稿历史版本 */
49
+ export interface AiDraftVersion {
50
+ id: string | number;
51
+ /** 版本展示名(如「AI 生成 v2」) */
52
+ label: string;
53
+ createdAt?: number;
54
+ /** 版本来源 */
55
+ source?: "ai" | "user";
56
+ /** 版本摘要(如变更字段说明) */
57
+ summary?: string;
58
+ }
59
+ /** 导出撤销句柄类型,避免使用方重复定义 */
60
+ export type { AiUndoHandle } from "./AiActionGuard/types";
@@ -0,0 +1,17 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __copyProps = (to, from, except, desc) => {
6
+ if (from && typeof from === "object" || typeof from === "function") {
7
+ for (let key of __getOwnPropNames(from))
8
+ if (!__hasOwnProp.call(to, key) && key !== except)
9
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
10
+ }
11
+ return to;
12
+ };
13
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
14
+
15
+ // src/ai-assistant/aiDraft.ts
16
+ var aiDraft_exports = {};
17
+ module.exports = __toCommonJS(aiDraft_exports);
@@ -1,3 +1,5 @@
1
+ export * from "./AiActionGuard";
2
+ export * from "./aiDraft";
1
3
  export type { AiContext, AiMessage, AiMessageRole, AiPageActions, AiPageCapability, AiReference, AiReferenceTab, AiSession, AiSnapshot, AiStreamEvent, AiSuggestion, AiTransport, AiValidateIssue, AiValidateReport, FormPatch, } from "./types";
2
4
  export { AiSessionEngine } from "./AiSessionEngine";
3
5
  export type { AiSessionEngineOptions } from "./AiSessionEngine";
@@ -14,6 +14,7 @@ var __copyProps = (to, from, except, desc) => {
14
14
  }
15
15
  return to;
16
16
  };
17
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
17
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
19
 
19
20
  // src/ai-assistant/index.ts
@@ -25,6 +26,8 @@ __export(ai_assistant_exports, {
25
26
  useAiAssistantContext: () => import_AiAssistantProvider.useAiAssistantContext
26
27
  });
27
28
  module.exports = __toCommonJS(ai_assistant_exports);
29
+ __reExport(ai_assistant_exports, require("./AiActionGuard"), module.exports);
30
+ __reExport(ai_assistant_exports, require("./aiDraft"), module.exports);
28
31
  var import_AiSessionEngine = require("./AiSessionEngine");
29
32
  var import_MockAiTransport = require("./MockAiTransport");
30
33
  var import_AiAssistantProvider = require("./AiAssistantProvider");
@@ -33,5 +36,7 @@ var import_AiAssistantProvider = require("./AiAssistantProvider");
33
36
  AiAssistantProvider,
34
37
  AiSessionEngine,
35
38
  MockAiTransport,
36
- useAiAssistantContext
39
+ useAiAssistantContext,
40
+ ...require("./AiActionGuard"),
41
+ ...require("./aiDraft")
37
42
  });
@@ -1,5 +1,6 @@
1
1
  /// <reference types="react" />
2
2
  import type { FormInstance, FormRule } from "antd";
3
+ import type { AiDraftMeta, AiFieldHint, AiFormChangeMeta } from "../../ai-assistant/aiDraft";
3
4
  import "./index.scss";
4
5
  export type FormFieldValue = string | number | boolean | null | undefined | (string | number)[];
5
6
  export interface FormFieldOption {
@@ -43,8 +44,12 @@ export interface BaseInfoFormProps {
43
44
  fields: FormField[];
44
45
  layout?: "horizontal" | "vertical";
45
46
  labelMaxWidth?: number;
46
- onChange?: (value: FormValues) => void;
47
- onFieldChange?: (field: string, value: FormFieldValue) => void;
47
+ onChange?: (value: FormValues, meta?: AiFormChangeMeta) => void;
48
+ onFieldChange?: (field: string, value: FormFieldValue, meta?: AiFormChangeMeta) => void;
49
+ /** AI 草稿元信息:字段级来源标记 + 未保存态提示 */
50
+ aiDraft?: AiDraftMeta;
51
+ /** 只读字段提示:渲染错误/警告样式,不写入表单数据 */
52
+ fieldHints?: AiFieldHint[];
48
53
  }
49
54
  export interface BaseInfoFormRef {
50
55
  validate: () => Promise<boolean>;
@@ -66,11 +66,80 @@ var isEqualValue = (a, b) => {
66
66
  return a === b;
67
67
  };
68
68
  var BaseInfoForm = (0, import_react.forwardRef)(
69
- ({ value, fields, layout = "horizontal", labelMaxWidth = 8, onChange, onFieldChange }, ref) => {
69
+ ({
70
+ value,
71
+ fields,
72
+ layout = "horizontal",
73
+ labelMaxWidth = 8,
74
+ onChange,
75
+ onFieldChange,
76
+ aiDraft,
77
+ fieldHints
78
+ }, ref) => {
79
+ const { token } = import_antd.theme.useToken();
70
80
  const [form] = import_basic_components.CompanyForm.useForm();
71
81
  const [contentWidth, setContentWidth] = (0, import_react.useState)(1200);
72
82
  const formRef = (0, import_react.useRef)(null);
73
83
  const prevValueRef = (0, import_react.useRef)(value);
84
+ const aiFieldSet = (0, import_react.useMemo)(
85
+ () => new Set(((aiDraft == null ? void 0 : aiDraft.fields) || []).map((mark) => mark.field)),
86
+ [aiDraft == null ? void 0 : aiDraft.fields]
87
+ );
88
+ const hintMap = (0, import_react.useMemo)(() => {
89
+ const map = {};
90
+ (fieldHints || []).forEach((hint) => {
91
+ const current = map[hint.field];
92
+ if (!current || hint.level === "error") {
93
+ map[hint.field] = hint;
94
+ }
95
+ });
96
+ return map;
97
+ }, [fieldHints]);
98
+ const aiTagStyle = {
99
+ marginInlineStart: token.marginXXS,
100
+ padding: `0 ${token.paddingXXS}px`,
101
+ borderRadius: token.borderRadiusSM,
102
+ background: token.colorPrimaryBg,
103
+ color: token.colorPrimary,
104
+ fontSize: token.fontSizeSM,
105
+ lineHeight: token.lineHeightSM,
106
+ fontWeight: "normal",
107
+ verticalAlign: "middle"
108
+ };
109
+ const renderLabel = (field) => aiFieldSet.has(field.name) ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", { children: [
110
+ field.label,
111
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { style: aiTagStyle, title: "该字段由 AI 预填", children: "AI" })
112
+ ] }) : field.label;
113
+ const renderAiDraftBanner = () => {
114
+ if (!aiDraft)
115
+ return null;
116
+ const parts = [];
117
+ if (aiDraft.aiGenerated)
118
+ parts.push("AI 已预填");
119
+ if (aiDraft.version !== void 0)
120
+ parts.push(`v${aiDraft.version}`);
121
+ if (aiDraft.dirty !== void 0)
122
+ parts.push(aiDraft.dirty ? "未保存" : "已保存");
123
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
124
+ "div",
125
+ {
126
+ className: "base-info-form-ai-banner",
127
+ style: {
128
+ display: "flex",
129
+ alignItems: "center",
130
+ gap: token.marginXS,
131
+ marginBottom: token.marginSM,
132
+ padding: `${token.paddingXXS}px ${token.paddingSM}px`,
133
+ borderRadius: token.borderRadius,
134
+ background: token.colorPrimaryBg,
135
+ color: token.colorPrimary,
136
+ fontSize: token.fontSizeSM,
137
+ lineHeight: token.lineHeightSM
138
+ },
139
+ children: parts.map((part) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: part }, part))
140
+ }
141
+ );
142
+ };
74
143
  (0, import_react.useEffect)(() => {
75
144
  const el = formRef.current;
76
145
  if (!el)
@@ -94,6 +163,13 @@ var BaseInfoForm = (0, import_react.forwardRef)(
94
163
  return 8;
95
164
  return 6;
96
165
  };
166
+ const normalizeValue = (val) => {
167
+ const result = {};
168
+ for (const k of Object.keys(val)) {
169
+ result[k] = val[k] === "" ? void 0 : val[k];
170
+ }
171
+ return result;
172
+ };
97
173
  (0, import_react.useEffect)(() => {
98
174
  if (prevValueRef.current !== value) {
99
175
  prevValueRef.current = value;
@@ -105,25 +181,26 @@ var BaseInfoForm = (0, import_react.forwardRef)(
105
181
  diff[k] = v;
106
182
  }
107
183
  }
108
- if (Object.keys(diff).length > 0) {
184
+ const changedFields = Object.keys(diff);
185
+ if (changedFields.length > 0) {
109
186
  form.setFieldsValue(diff);
187
+ if (aiDraft == null ? void 0 : aiDraft.aiGenerated) {
188
+ onChange == null ? void 0 : onChange(normalizeValue(value), { source: "ai", changedFields });
189
+ }
110
190
  }
111
191
  }
112
- }, [value, form]);
113
- const normalizeValue = (val) => {
114
- const result = {};
115
- for (const k of Object.keys(val)) {
116
- result[k] = val[k] === "" ? void 0 : val[k];
117
- }
118
- return result;
119
- };
192
+ }, [value, form, aiDraft == null ? void 0 : aiDraft.aiGenerated, onChange]);
120
193
  const handleValuesChange = (_changedValues, allValues) => {
121
- const key = Object.keys(_changedValues)[0];
194
+ const changedFields = Object.keys(_changedValues);
195
+ const key = changedFields[0];
122
196
  if (key) {
123
197
  const changed = _changedValues[key];
124
- onFieldChange == null ? void 0 : onFieldChange(key, changed === "" ? void 0 : changed);
198
+ onFieldChange == null ? void 0 : onFieldChange(key, changed === "" ? void 0 : changed, {
199
+ source: "user",
200
+ changedFields
201
+ });
125
202
  }
126
- onChange == null ? void 0 : onChange(normalizeValue(allValues));
203
+ onChange == null ? void 0 : onChange(normalizeValue(allValues), { source: "user", changedFields });
127
204
  };
128
205
  (0, import_react.useImperativeHandle)(
129
206
  ref,
@@ -220,52 +297,74 @@ var BaseInfoForm = (0, import_react.forwardRef)(
220
297
  return null;
221
298
  }
222
299
  };
223
- const renderItem = (field) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
224
- import_basic_components.CompanyForm.Item,
225
- {
226
- label: field.label,
227
- name: field.name,
228
- rules: field.rules,
229
- required: field.required,
230
- className: field.type === "textarea" ? "label-top" : void 0,
231
- ...isDateLike(field.type) ? getDateItemProps(field) : null,
232
- children: renderField(field)
233
- }
234
- );
300
+ const renderItem = (field) => {
301
+ const hint = hintMap[field.name];
302
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
303
+ import_basic_components.CompanyForm.Item,
304
+ {
305
+ label: renderLabel(field),
306
+ name: field.name,
307
+ rules: field.rules,
308
+ required: field.required,
309
+ className: field.type === "textarea" ? "label-top" : void 0,
310
+ validateStatus: hint ? hint.level === "error" ? "error" : "warning" : void 0,
311
+ help: hint == null ? void 0 : hint.message,
312
+ ...isDateLike(field.type) ? getDateItemProps(field) : null,
313
+ children: renderField(field)
314
+ }
315
+ );
316
+ };
235
317
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
236
318
  "div",
237
319
  {
238
320
  ref: formRef,
239
321
  className: "base-info-form",
240
322
  style: { ["--company-label-max-width"]: `${labelMaxWidth}em` },
241
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
323
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
242
324
  import_basic_components.CompanyForm,
243
325
  {
244
326
  form,
245
327
  initialValues: normalizeValue(value),
246
328
  layout,
247
329
  onValuesChange: handleValuesChange,
248
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd.Row, { gutter: 24, children: fields.map((field, index) => {
249
- if (field.type === "compact") {
250
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd.Col, { span: getColSpan(), children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_basic_components.CompanyForm.Item, { label: field.label, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd.Space.Compact, { style: { width: "100%" }, children: field.children.map((child) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
251
- import_basic_components.CompanyForm.Item,
252
- {
253
- name: child.name,
254
- noStyle: true,
255
- rules: child.rules,
256
- children: renderField(child)
257
- },
258
- child.name
259
- )) }) }) }, `compact-${index}`);
260
- }
261
- if (field.type === "section") {
262
- return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_antd.Col, { span: 24, children: [
263
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_SectionTitle.default, { title: field.label, description: field.description }),
264
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd.Row, { gutter: 24, children: (field.children || []).map((child) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd.Col, { span: getColSpan(), children: renderItem(child) }, child.name)) })
265
- ] }, `section-${index}`);
266
- }
267
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd.Col, { span: getColSpan(), children: renderItem(field) }, field.name);
268
- }) })
330
+ children: [
331
+ renderAiDraftBanner(),
332
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd.Row, { gutter: 24, children: fields.map((field, index) => {
333
+ if (field.type === "compact") {
334
+ const childHints = field.children.map((child) => hintMap[child.name]).filter((hint) => Boolean(hint));
335
+ const compactHint = childHints.find((hint) => hint.level === "error") || childHints[0];
336
+ const hasAiChild = field.children.some((child) => aiFieldSet.has(child.name));
337
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd.Col, { span: getColSpan(), children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
338
+ import_basic_components.CompanyForm.Item,
339
+ {
340
+ label: hasAiChild ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", { children: [
341
+ field.label,
342
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { style: aiTagStyle, title: "该字段由 AI 预填", children: "AI" })
343
+ ] }) : field.label,
344
+ validateStatus: compactHint ? compactHint.level === "error" ? "error" : "warning" : void 0,
345
+ help: compactHint == null ? void 0 : compactHint.message,
346
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd.Space.Compact, { style: { width: "100%" }, children: field.children.map((child) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
347
+ import_basic_components.CompanyForm.Item,
348
+ {
349
+ name: child.name,
350
+ noStyle: true,
351
+ rules: child.rules,
352
+ children: renderField(child)
353
+ },
354
+ child.name
355
+ )) })
356
+ }
357
+ ) }, `compact-${index}`);
358
+ }
359
+ if (field.type === "section") {
360
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_antd.Col, { span: 24, children: [
361
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_SectionTitle.default, { title: field.label, description: field.description }),
362
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd.Row, { gutter: 24, children: (field.children || []).map((child) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd.Col, { span: getColSpan(), children: renderItem(child) }, child.name)) })
363
+ ] }, `section-${index}`);
364
+ }
365
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd.Col, { span: getColSpan(), children: renderItem(field) }, field.name);
366
+ }) })
367
+ ]
269
368
  }
270
369
  )
271
370
  }