@pactor-app/chat 1.1.0 → 1.2.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 CHANGED
@@ -21,7 +21,7 @@ import '@pactor-app/chat/styles.css';
21
21
  ## 示例
22
22
 
23
23
  ```tsx
24
- import { createShadcnComponentRegistry } from '@pactor-app/ui/components';
24
+ import { createComponentRegistry } from '@pactor-app/ui/components';
25
25
  import {
26
26
  ChatView,
27
27
  ConversationStore,
@@ -31,7 +31,7 @@ import {
31
31
 
32
32
  const store = new ConversationStore();
33
33
  // Safe Registry:LLM 生成的 DSL 只渲染白名单内的组件
34
- const safeRegistry = createSafeRegistry(createShadcnComponentRegistry(), [
34
+ const safeRegistry = createSafeRegistry(createComponentRegistry(), [
35
35
  'Statistic',
36
36
  'Card',
37
37
  ]);
@@ -78,6 +78,7 @@ driver.complete();
78
78
  - **`<AppShell sidebar brand? locationKey? className?>`**:应用外壳——侧栏插槽 + 主区。桌面(≥768px)侧栏与主区 flex 同行;移动端(<768px)侧栏退出文档流变为覆盖抽屉(遮罩 + 顶栏菜单按钮 + `brand` 品牌区),断点由 CSS 媒体查询表达,JS 只管开合。抽屉打开时 Escape / 遮罩点击关闭;`locationKey` 变化(路由 / 会话切换)渲染期自动关闭;移动端关闭时侧栏容器 `inert`。侧栏内容经 `useSidebarDrawer()` 取 `{ close }`(壳外返回 null),导航后可关闭抽屉。
79
79
  - **`registerChatLayout(layoutRegistry)`**:注册 `chat` 布局(header 标题区 + ChatView 区,V1 无会话历史侧栏),`resolveLayout(registry, 'chat')` 命中。
80
80
  - **`Chat` / `registerChatComponent(registry)`**:一等 DSL 聊天工作区组件,见下节。
81
+ - **`createChatComponentRegistry()`**:便捷工厂——创建含全部内置组件 + Chat / ChatShell 的组件注册表,直接作为 `createPactorApplication` 的 `componentRegistry` 选项。
81
82
  - **`createChatWorkspace(services)`**:React 直连路径的工作区工厂(内部与 Chat 共用同一组合),见下文「DSL 页面:createChatWorkspace」。
82
83
 
83
84
  ## Chat:一等 DSL 组件
package/dist/index.cjs CHANGED
@@ -45,6 +45,7 @@ __export(index_exports, {
45
45
  applyChatEvent: () => applyChatEvent,
46
46
  buildChatScope: () => buildChatScope,
47
47
  collectMessageText: () => collectMessageText,
48
+ createChatComponentRegistry: () => createChatComponentRegistry,
48
49
  createChatId: () => createChatId,
49
50
  createChatRuntime: () => createChatRuntime,
50
51
  createChatWorkspace: () => createChatWorkspace,
@@ -4188,6 +4189,11 @@ function registerChatComponent(registry) {
4188
4189
  }
4189
4190
  registerChatShellComponent(registry);
4190
4191
  }
4192
+ function createChatComponentRegistry() {
4193
+ const registry = (0, import_components12.createComponentRegistry)();
4194
+ registerChatComponent(registry);
4195
+ return registry;
4196
+ }
4191
4197
 
4192
4198
  // src/view/ChatLayout.tsx
4193
4199
  var import_jsx_runtime22 = require("react/jsx-runtime");
@@ -4230,6 +4236,7 @@ function registerChatLayout(layoutRegistry) {
4230
4236
  applyChatEvent,
4231
4237
  buildChatScope,
4232
4238
  collectMessageText,
4239
+ createChatComponentRegistry,
4233
4240
  createChatId,
4234
4241
  createChatRuntime,
4235
4242
  createChatWorkspace,
package/dist/index.d.cts CHANGED
@@ -1016,6 +1016,20 @@ declare const CHAT_COMPONENT_TYPE = "Chat";
1016
1016
  * 一并注册,同样不覆盖已有同名类型。
1017
1017
  */
1018
1018
  declare function registerChatComponent(registry: Registry<unknown>): void;
1019
+ /**
1020
+ * 便捷工厂:创建含全部内置组件 + Chat / ChatShell 的组件注册表,
1021
+ * 直接作为 createPactorApplication 的 componentRegistry 选项:
1022
+ *
1023
+ * ```ts
1024
+ * import { createChatComponentRegistry } from '@pactor-app/chat';
1025
+ *
1026
+ * createPactorApplication({
1027
+ * appId: 'my-chat',
1028
+ * componentRegistry: createChatComponentRegistry,
1029
+ * });
1030
+ * ```
1031
+ */
1032
+ declare function createChatComponentRegistry(): Registry<unknown>;
1019
1033
 
1020
1034
  /**
1021
1035
  * ChatShell(spec: chat-dsl-component / ChatShell 外壳组件,设计决策 D6):
@@ -1463,7 +1477,7 @@ declare const CHAT_LAYOUT_TYPE = "chat";
1463
1477
  * 结构化 LayoutRegistry(兼容 @pactor-app/ui layout 层的 LayoutRegistry =
1464
1478
  * Registry<LayoutComponent>):结构化类型声明,调用方传入 ui layout 层
1465
1479
  * 的注册表即天然兼容(历史为零依赖约定而设;chat-icon-convergence 起
1466
- * chat 正式依赖 ui kit,本结构化声明保留以收窄本文件的 API 面)。
1480
+ * chat 正式依赖 @pactor-app/ui,本结构化声明保留以收窄本文件的 API 面)。
1467
1481
  */
1468
1482
  interface ChatLayoutRegistry {
1469
1483
  has(name: string): boolean;
@@ -1472,4 +1486,4 @@ interface ChatLayoutRegistry {
1472
1486
  /** 注册 chat 布局(已注册时不覆盖,与 createLayoutRegistry 约定一致) */
1473
1487
  declare function registerChatLayout(layoutRegistry: ChatLayoutRegistry): void;
1474
1488
 
1475
- export { ActivityTrace, type ActivityTraceProps, AppShell, type AppShellProps, ArtifactPanel, type ArtifactPanelProps, type ArtifactPatch, ArtifactStore, type BuiltinMessageAction, CHAT_COMPONENT_TYPE, CHAT_DENIED_TYPE, CHAT_LAYOUT_TYPE, CHAT_SHELL_COMPONENT_TYPE, type CapabilityActionDeps, type CapabilityHandler, Chat, type ChatArtifact, type ChatAttachment, type ChatCapabilityRegistry, type ChatConfirm, type ChatConfirmRequest, type ChatContextItem, type ChatContextSource, ChatDenied, type ChatEvent, type ChatHeaderAction, type ChatInput, ChatLayout, type ChatLayoutProps, type ChatLayoutRegistry, type ChatMenuItem, type ChatMessage, type ChatMessageAction, type ChatModelOption, type ChatPart, type ChatPermissionChecker, type ChatProps, type ChatRole, type ChatRuntime, type ChatScope, type ChatServices, ChatServicesProvider, ChatShell, type ChatShellProps, ChatSidebarMenu, type ChatSuggestion, type ChatTransport, type ChatTurnResult, ChatView, type ChatViewProps, type ChatWorkspaceProps, type ChatWorkspaceServices, Composer, type ComposerProps, ConversationStore, type CreateChatRuntimeOptions, DEFAULT_CHAT_GREETING, EmptyState, type EmptyStateProps, type ManualChatDriver, MessageActions, type MessageActionsProps, MessageBubble, type MessageBubbleProps, type MessagePatch, type MessageStatus, type PartPatch, type PartRef, PartRenderer, type PartRendererProps, type PartStatus, type RunChatTurnOptions, type StreamingMode, type ToolCallStatus, type ToolTraceEntry, type UseChatAutoScrollOptions, type UseChatAutoScrollResult, type UseSmoothStreamTextOptions, applyChatEvent, buildChatScope, collectMessageText, createChatId, createChatRuntime, createChatWorkspace, createManualDriver, createSafeRegistry, detectStreamingMode, guardChatDsl, pairToolTraces, registerCapabilityAction, registerChatComponent, registerChatLayout, registerChatShellComponent, runChatTurn, runRegenerateTurn, useChatAutoScroll, useChatServices, useSidebarDrawer, useSmoothStreamText };
1489
+ export { ActivityTrace, type ActivityTraceProps, AppShell, type AppShellProps, ArtifactPanel, type ArtifactPanelProps, type ArtifactPatch, ArtifactStore, type BuiltinMessageAction, CHAT_COMPONENT_TYPE, CHAT_DENIED_TYPE, CHAT_LAYOUT_TYPE, CHAT_SHELL_COMPONENT_TYPE, type CapabilityActionDeps, type CapabilityHandler, Chat, type ChatArtifact, type ChatAttachment, type ChatCapabilityRegistry, type ChatConfirm, type ChatConfirmRequest, type ChatContextItem, type ChatContextSource, ChatDenied, type ChatEvent, type ChatHeaderAction, type ChatInput, ChatLayout, type ChatLayoutProps, type ChatLayoutRegistry, type ChatMenuItem, type ChatMessage, type ChatMessageAction, type ChatModelOption, type ChatPart, type ChatPermissionChecker, type ChatProps, type ChatRole, type ChatRuntime, type ChatScope, type ChatServices, ChatServicesProvider, ChatShell, type ChatShellProps, ChatSidebarMenu, type ChatSuggestion, type ChatTransport, type ChatTurnResult, ChatView, type ChatViewProps, type ChatWorkspaceProps, type ChatWorkspaceServices, Composer, type ComposerProps, ConversationStore, type CreateChatRuntimeOptions, DEFAULT_CHAT_GREETING, EmptyState, type EmptyStateProps, type ManualChatDriver, MessageActions, type MessageActionsProps, MessageBubble, type MessageBubbleProps, type MessagePatch, type MessageStatus, type PartPatch, type PartRef, PartRenderer, type PartRendererProps, type PartStatus, type RunChatTurnOptions, type StreamingMode, type ToolCallStatus, type ToolTraceEntry, type UseChatAutoScrollOptions, type UseChatAutoScrollResult, type UseSmoothStreamTextOptions, applyChatEvent, buildChatScope, collectMessageText, createChatComponentRegistry, createChatId, createChatRuntime, createChatWorkspace, createManualDriver, createSafeRegistry, detectStreamingMode, guardChatDsl, pairToolTraces, registerCapabilityAction, registerChatComponent, registerChatLayout, registerChatShellComponent, runChatTurn, runRegenerateTurn, useChatAutoScroll, useChatServices, useSidebarDrawer, useSmoothStreamText };
package/dist/index.d.ts CHANGED
@@ -1016,6 +1016,20 @@ declare const CHAT_COMPONENT_TYPE = "Chat";
1016
1016
  * 一并注册,同样不覆盖已有同名类型。
1017
1017
  */
1018
1018
  declare function registerChatComponent(registry: Registry<unknown>): void;
1019
+ /**
1020
+ * 便捷工厂:创建含全部内置组件 + Chat / ChatShell 的组件注册表,
1021
+ * 直接作为 createPactorApplication 的 componentRegistry 选项:
1022
+ *
1023
+ * ```ts
1024
+ * import { createChatComponentRegistry } from '@pactor-app/chat';
1025
+ *
1026
+ * createPactorApplication({
1027
+ * appId: 'my-chat',
1028
+ * componentRegistry: createChatComponentRegistry,
1029
+ * });
1030
+ * ```
1031
+ */
1032
+ declare function createChatComponentRegistry(): Registry<unknown>;
1019
1033
 
1020
1034
  /**
1021
1035
  * ChatShell(spec: chat-dsl-component / ChatShell 外壳组件,设计决策 D6):
@@ -1463,7 +1477,7 @@ declare const CHAT_LAYOUT_TYPE = "chat";
1463
1477
  * 结构化 LayoutRegistry(兼容 @pactor-app/ui layout 层的 LayoutRegistry =
1464
1478
  * Registry<LayoutComponent>):结构化类型声明,调用方传入 ui layout 层
1465
1479
  * 的注册表即天然兼容(历史为零依赖约定而设;chat-icon-convergence 起
1466
- * chat 正式依赖 ui kit,本结构化声明保留以收窄本文件的 API 面)。
1480
+ * chat 正式依赖 @pactor-app/ui,本结构化声明保留以收窄本文件的 API 面)。
1467
1481
  */
1468
1482
  interface ChatLayoutRegistry {
1469
1483
  has(name: string): boolean;
@@ -1472,4 +1486,4 @@ interface ChatLayoutRegistry {
1472
1486
  /** 注册 chat 布局(已注册时不覆盖,与 createLayoutRegistry 约定一致) */
1473
1487
  declare function registerChatLayout(layoutRegistry: ChatLayoutRegistry): void;
1474
1488
 
1475
- export { ActivityTrace, type ActivityTraceProps, AppShell, type AppShellProps, ArtifactPanel, type ArtifactPanelProps, type ArtifactPatch, ArtifactStore, type BuiltinMessageAction, CHAT_COMPONENT_TYPE, CHAT_DENIED_TYPE, CHAT_LAYOUT_TYPE, CHAT_SHELL_COMPONENT_TYPE, type CapabilityActionDeps, type CapabilityHandler, Chat, type ChatArtifact, type ChatAttachment, type ChatCapabilityRegistry, type ChatConfirm, type ChatConfirmRequest, type ChatContextItem, type ChatContextSource, ChatDenied, type ChatEvent, type ChatHeaderAction, type ChatInput, ChatLayout, type ChatLayoutProps, type ChatLayoutRegistry, type ChatMenuItem, type ChatMessage, type ChatMessageAction, type ChatModelOption, type ChatPart, type ChatPermissionChecker, type ChatProps, type ChatRole, type ChatRuntime, type ChatScope, type ChatServices, ChatServicesProvider, ChatShell, type ChatShellProps, ChatSidebarMenu, type ChatSuggestion, type ChatTransport, type ChatTurnResult, ChatView, type ChatViewProps, type ChatWorkspaceProps, type ChatWorkspaceServices, Composer, type ComposerProps, ConversationStore, type CreateChatRuntimeOptions, DEFAULT_CHAT_GREETING, EmptyState, type EmptyStateProps, type ManualChatDriver, MessageActions, type MessageActionsProps, MessageBubble, type MessageBubbleProps, type MessagePatch, type MessageStatus, type PartPatch, type PartRef, PartRenderer, type PartRendererProps, type PartStatus, type RunChatTurnOptions, type StreamingMode, type ToolCallStatus, type ToolTraceEntry, type UseChatAutoScrollOptions, type UseChatAutoScrollResult, type UseSmoothStreamTextOptions, applyChatEvent, buildChatScope, collectMessageText, createChatId, createChatRuntime, createChatWorkspace, createManualDriver, createSafeRegistry, detectStreamingMode, guardChatDsl, pairToolTraces, registerCapabilityAction, registerChatComponent, registerChatLayout, registerChatShellComponent, runChatTurn, runRegenerateTurn, useChatAutoScroll, useChatServices, useSidebarDrawer, useSmoothStreamText };
1489
+ export { ActivityTrace, type ActivityTraceProps, AppShell, type AppShellProps, ArtifactPanel, type ArtifactPanelProps, type ArtifactPatch, ArtifactStore, type BuiltinMessageAction, CHAT_COMPONENT_TYPE, CHAT_DENIED_TYPE, CHAT_LAYOUT_TYPE, CHAT_SHELL_COMPONENT_TYPE, type CapabilityActionDeps, type CapabilityHandler, Chat, type ChatArtifact, type ChatAttachment, type ChatCapabilityRegistry, type ChatConfirm, type ChatConfirmRequest, type ChatContextItem, type ChatContextSource, ChatDenied, type ChatEvent, type ChatHeaderAction, type ChatInput, ChatLayout, type ChatLayoutProps, type ChatLayoutRegistry, type ChatMenuItem, type ChatMessage, type ChatMessageAction, type ChatModelOption, type ChatPart, type ChatPermissionChecker, type ChatProps, type ChatRole, type ChatRuntime, type ChatScope, type ChatServices, ChatServicesProvider, ChatShell, type ChatShellProps, ChatSidebarMenu, type ChatSuggestion, type ChatTransport, type ChatTurnResult, ChatView, type ChatViewProps, type ChatWorkspaceProps, type ChatWorkspaceServices, Composer, type ComposerProps, ConversationStore, type CreateChatRuntimeOptions, DEFAULT_CHAT_GREETING, EmptyState, type EmptyStateProps, type ManualChatDriver, MessageActions, type MessageActionsProps, MessageBubble, type MessageBubbleProps, type MessagePatch, type MessageStatus, type PartPatch, type PartRef, PartRenderer, type PartRendererProps, type PartStatus, type RunChatTurnOptions, type StreamingMode, type ToolCallStatus, type ToolTraceEntry, type UseChatAutoScrollOptions, type UseChatAutoScrollResult, type UseSmoothStreamTextOptions, applyChatEvent, buildChatScope, collectMessageText, createChatComponentRegistry, createChatId, createChatRuntime, createChatWorkspace, createManualDriver, createSafeRegistry, detectStreamingMode, guardChatDsl, pairToolTraces, registerCapabilityAction, registerChatComponent, registerChatLayout, registerChatShellComponent, runChatTurn, runRegenerateTurn, useChatAutoScroll, useChatServices, useSidebarDrawer, useSmoothStreamText };
package/dist/index.js CHANGED
@@ -3847,7 +3847,7 @@ function createChatWorkspace(services) {
3847
3847
  }
3848
3848
 
3849
3849
  // src/view/Chat.tsx
3850
- import { Icon as Icon11, RailTooltip } from "@pactor-app/ui/components";
3850
+ import { createComponentRegistry, Icon as Icon11, RailTooltip } from "@pactor-app/ui/components";
3851
3851
  import { Fragment as Fragment10, useEffect as useEffect10, useRef as useRef13 } from "react";
3852
3852
 
3853
3853
  // src/view/chrome/menu.tsx
@@ -4144,6 +4144,11 @@ function registerChatComponent(registry) {
4144
4144
  }
4145
4145
  registerChatShellComponent(registry);
4146
4146
  }
4147
+ function createChatComponentRegistry() {
4148
+ const registry = createComponentRegistry();
4149
+ registerChatComponent(registry);
4150
+ return registry;
4151
+ }
4147
4152
 
4148
4153
  // src/view/ChatLayout.tsx
4149
4154
  import { jsx as jsx22, jsxs as jsxs14 } from "react/jsx-runtime";
@@ -4185,6 +4190,7 @@ export {
4185
4190
  applyChatEvent,
4186
4191
  buildChatScope,
4187
4192
  collectMessageText,
4193
+ createChatComponentRegistry,
4188
4194
  createChatId,
4189
4195
  createChatRuntime,
4190
4196
  createChatWorkspace,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pactor-app/chat",
3
- "version": "1.1.0",
3
+ "version": "1.2.0",
4
4
  "description": "Pactor chat: AI message rendering protocol (message model, streaming reducer, safe registry, capability action) and chat runtime view (ChatView / MessageBubble / PartRenderer / Composer / chat layout)",
5
5
  "keywords": [
6
6
  "pactor",
@@ -49,11 +49,11 @@
49
49
  "access": "public"
50
50
  },
51
51
  "dependencies": {
52
- "@pactor-app/ui": "1.1.0",
53
- "@pactor-app/permission": "1.1.0",
54
- "@pactor-app/markdown": "1.1.0",
55
- "@pactor-app/core": "1.1.0",
56
- "@pactor-app/runtime": "1.1.0"
52
+ "@pactor-app/core": "1.2.0",
53
+ "@pactor-app/markdown": "1.2.0",
54
+ "@pactor-app/permission": "1.2.0",
55
+ "@pactor-app/runtime": "1.2.0",
56
+ "@pactor-app/ui": "1.2.0"
57
57
  },
58
58
  "peerDependencies": {
59
59
  "react": ">=18"
package/styles.css CHANGED
@@ -68,7 +68,6 @@
68
68
  height: 100%;
69
69
  gap: 12px;
70
70
  color: var(--pactor-chat-fg);
71
- background: var(--pactor-chat-bg);
72
71
  font-size: 14px;
73
72
  line-height: 1.6;
74
73
  }
@@ -183,7 +182,6 @@
183
182
  width: 100%;
184
183
  max-width: var(--pactor-chat-content-width);
185
184
  margin-inline: auto;
186
- background: var(--pactor-chat-bg);
187
185
  color: var(--pactor-chat-fg);
188
186
  font-size: 14px;
189
187
  line-height: 1.6;
@@ -314,6 +312,7 @@
314
312
  width: 100%;
315
313
  min-height: 0;
316
314
  overflow: hidden;
315
+ background: var(--pactor-chat-bg);
317
316
  }
318
317
 
319
318
  /* 面板打开时 host 内的直子:AppShell 填满剩余空间;workspace 只缩不伸,
@@ -620,7 +619,8 @@
620
619
 
621
620
 
622
621
  /* 消息滚动区:overflow-anchor none 配合 useChatAutoScroll(防浏览器
623
- 滚动锚定与贴底跟随互相拉扯);上下 mask 渐隐 + 6px 细滚动条 */
622
+ 滚动锚定与贴底跟随互相拉扯);上下 mask 渐隐 + 6px 细滚动条;
623
+ 顶部留 24px 内边距(与 mask 渐隐带同宽,首条消息不贴顶) */
624
624
  .pactor-chat-messages {
625
625
  position: relative;
626
626
  flex: 1;
@@ -630,7 +630,7 @@
630
630
  display: flex;
631
631
  flex-direction: column;
632
632
  gap: 16px;
633
- padding: 4px 2px;
633
+ padding: 24px 2px 4px;
634
634
  scrollbar-width: thin;
635
635
  scrollbar-color: var(--pactor-chat-border) transparent;
636
636
  -webkit-mask-image: linear-gradient(