@galaxycore/ai-chat 0.6.0 → 0.8.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.
@@ -36,7 +36,7 @@ mkdir -p artifacts
36
36
  npm pack --pack-destination artifacts
37
37
 
38
38
  # 消费项目:替换为真实文件的绝对路径
39
- npm install /absolute/path/to/galaxycore-ai-chat-0.6.0.tgz
39
+ npm install /absolute/path/to/galaxycore-ai-chat-0.7.0.tgz
40
40
  npm install ai@^7.0.137 @ai-sdk/react@^4.0.140
41
41
  ```
42
42
 
@@ -53,12 +53,12 @@ npm run check
53
53
  npm pack --dry-run
54
54
  mkdir -p artifacts
55
55
  npm pack --pack-destination artifacts
56
- tar -tzf artifacts/galaxycore-ai-chat-0.6.0.tgz
56
+ tar -tzf artifacts/galaxycore-ai-chat-0.7.0.tgz
57
57
  ```
58
58
 
59
59
  `check` 执行类型检查、组件与网关测试、库构建和可部署示例构建;示例构建包含文档站。`prepack` 构建库,`prepublishOnly` 执行完整检查。tarball 应包含公开 JS 入口、声明、CSS、README 和文档,不应包含模型凭据、认证配置或业务数据。
60
60
 
61
- 检查根入口及 `headless`、`markdown`、`ag-ui`、`context`、`gateway`、`appearance`、`voice`、`styles.css` 子入口。React 与 AI SDK 应保持 peer dependency,Markdown 默认启用并保留独立入口。
61
+ 检查根入口及 `headless`、`markdown`、`ag-ui`、`context`、`gateway`、`appearance`、`voice`、`targeting`、`styles.css` 子入口。React 与 AI SDK 应保持 peer dependency,Markdown 默认启用并保留独立入口。
62
62
 
63
63
  在独立 Vite React 消费项目中安装 tarball,验证类型、样式、流式消息与停止;需要 Next.js 时另外验证客户端边界及 SSR 构建。不要只依赖仓库开发 alias 的演示结果。每次发布记录实际使用的 Node、React 和 AI SDK 版本,以及通过的消费测试,见 [验证记录](validation.md)。
64
64
 
@@ -85,12 +85,12 @@ CI 构建和测试步骤无需发布凭据。发布 job 可使用 CI secret 注
85
85
 
86
86
  ## 版本与发布
87
87
 
88
- 当前组件版本为 `0.6.0`,网关版本为 `0.2.0`,两者独立升级。0.x 阶段,修复使用 patch,新增功能和未冻结接口调整使用 minor,并在 changelog 说明兼容性。稳定 API 后再发布 1.0。
88
+ 当前组件版本为 `0.7.0`,网关版本为 `0.2.0`,两者独立升级。0.x 阶段,修复使用 patch,新增功能和未冻结接口调整使用 minor,并在 changelog 说明兼容性。稳定 API 后再发布 1.0。
89
89
 
90
90
  下面以 npmjs.org 公开发布为例。命令会实际上传产物,应在完成验收后由发布负责人执行;发布私有 registry 时替换地址,并按该服务调整可见性参数:
91
91
 
92
92
  ```sh
93
- npm publish ./artifacts/galaxycore-ai-chat-0.6.0.tgz \
93
+ npm publish ./artifacts/galaxycore-ai-chat-0.7.0.tgz \
94
94
  --access public --tag latest \
95
95
  --registry=https://registry.npmjs.org/
96
96
  ```
@@ -98,7 +98,7 @@ npm publish ./artifacts/galaxycore-ai-chat-0.6.0.tgz \
98
98
  使用 tarball 发布时,先显式执行完整检查,不依赖源仓库的生命周期脚本一定被触发。`latest` 是不指定版本安装时使用的标签,不代表 API 已冻结。需要独立试用通道时,可以采用预发布版本及 `next` 标签。发布后检查远端版本和完整性:
99
99
 
100
100
  ```sh
101
- npm view @galaxycore/ai-chat@0.6.0 version dist.integrity \
101
+ npm view @galaxycore/ai-chat@0.7.0 version dist.integrity \
102
102
  --registry=https://registry.npmjs.org/
103
103
  npm dist-tag ls @galaxycore/ai-chat \
104
104
  --registry=https://registry.npmjs.org/
package/docs/streaming.md CHANGED
@@ -25,7 +25,7 @@ const chat = useAiChat({ transport });
25
25
  ## 滚动与阅读
26
26
 
27
27
  - 在底部阅读时,新内容继续进入可见区域。
28
- - 主动向上查看历史时,暂停自动跟随;新内容仍然正常生成。
28
+ - 滚轮、触摸、键盘或滚动条主动向上查看历史时,暂停自动跟随。Markdown 重排和消息区尺寸变化期间继续跟随。
29
29
  - 主动发送新消息时,回到底部并恢复跟随;流式回答过程中仍可再次上滑阅读。
30
30
  - 内容不足一屏时,向上滑动不会误暂停后续内容的跟随。
31
31
  - 点击“回到底部”恢复跟随。
@@ -36,6 +36,32 @@ const chat = useAiChat({ transport });
36
36
 
37
37
  操作系统的“减少动态效果”偏好优先于视觉平滑效果。平滑展示不是网络缓冲,也不会让模型更快响应;较长的服务端停顿仍然需要等待实际数据。
38
38
 
39
+ ### 定位消息内容
40
+
41
+ `ChatPanel`、`ChatMessages` 和 `AiChat` 都可以接收 `scrollRef`。宿主可以传入消息区内的元素或文字 `Range`,用于定位搜索命中、引用或正在朗读的句子。
42
+
43
+ ```tsx
44
+ import { useRef } from 'react';
45
+ import { ChatPanel, type AiChatController, type ChatScrollHandle } from '@galaxycore/ai-chat';
46
+
47
+ function Conversation({ chat, match }: { chat: AiChatController; match: Element | Range | null }) {
48
+ const scrollRef = useRef<ChatScrollHandle>(null);
49
+ return (
50
+ <ChatPanel
51
+ chat={chat}
52
+ scrollRef={scrollRef}
53
+ headerActions={
54
+ <button type="button" disabled={!match} onClick={() => match && scrollRef.current?.reveal(match)}>
55
+ 显示匹配内容
56
+ </button>
57
+ }
58
+ />
59
+ );
60
+ }
61
+ ```
62
+
63
+ `reveal` 只滚动当前面板的消息区。目标已完整可见、已卸载或属于其他面板时返回 `false`。如果滚动位置发生变化,返回 `true` 并暂停跟随。普通目标尽量居中,超过视口高度的目标从顶部显示。发送新消息、滚动到底部或使用“回到最新”可以恢复跟随。调用方负责决定何时定位,以及如何高亮文字和读取历史。
64
+
39
65
  ## Markdown 与工具
40
66
 
41
67
  通过 `renderText={MarkdownResponse}` 使用流式 Markdown。文字、工具活动和工具后的回答保持消息中的顺序。模型凭据、工具执行、服务端停止与会话恢复仍然由网关负责,具体见 [网关接入](./gateway.md)。
@@ -1,5 +1,18 @@
1
1
  # 0.4.0 发布验收 · 2026-10-13
2
2
 
3
+ ## 0.7.0 — 消息滚动与定位 (2026-11-23)
4
+
5
+ - 流式回复在布局重排时继续跟随最新消息,用户主动向上滚动时暂停跟随。宿主可通过 `scrollRef` 定位消息区中的元素或文字范围。
6
+ - `npm run check` 在 Node 24.22.1 下通过。组件 204 项、网关 11 项、示例服务 9 项测试通过,类型、组件库、工作台、文档站和服务构建均通过。
7
+ - 发布包在独立的 React 19 / AI SDK 7 Vite 项目中验收。Chromium 验证了原生滚动条拖动和文字范围定位。公开版本、标签和完整性见 `artifacts/npm-publication-0.7.json`。
8
+
9
+ ## 0.6.0 — 页面指向 (2026-11-23)
10
+
11
+ - 新增可选页面指向:划选文字、双击段落、拖选图片区域可以变成聊天上下文引用。公开入口是 `useChatTargeting`、`ChatTargetingOverlay`、`toChatContextItem` 和 `/targeting`。不挂载时,原有发送和界面保持不变。
12
+ - Node 24.22.1 下 `npm run check` 通过:组件 200 项、网关 11 项、示例服务 9 项;类型检查、组件库、文档站、工作台和示例服务构建通过。
13
+ - `0.6.0` tarball 含 61 个文件,没有环境文件或凭据。本地包与 registry 完整性一致。
14
+ - 已公开发布到 npmjs.org,`latest` 为 `0.6.0`。记录见 `artifacts/npm-publication-0.6.json`。网关仍是 `0.2.0`,本轮没有重发。
15
+
3
16
  ## 0.5.0 — Default Markdown (2026-10-20)
4
17
 
5
18
  - Assistant text uses the existing safe Streamdown renderer by default; user input remains literal and host renderers retain precedence. Streamdown is installed as a runtime dependency.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@galaxycore/ai-chat",
3
- "version": "0.6.0",
3
+ "version": "0.8.0",
4
4
  "description": "Composable React AI chat for GalaxyCore, powered by Vercel AI SDK",
5
5
  "type": "module",
6
6
  "license": "UNLICENSED",
@@ -1,116 +0,0 @@
1
- "use client";
2
- import { useChat } from "@ai-sdk/react";
3
- //#region src/use-ai-chat.ts
4
- /** Preserves the SDK's typed contract and throttles visual stream updates to 25 fps. */
5
- function useAiChat(options = {}) {
6
- const chat = useChat({
7
- throttle: 40,
8
- ...options
9
- });
10
- return {
11
- ...chat,
12
- isBusy: chat.status === "submitted" || chat.status === "streaming"
13
- };
14
- }
15
- //#endregion
16
- //#region src/labels.ts
17
- const zhCN = {
18
- title: "AI 助手",
19
- assistant: "助手",
20
- user: "你",
21
- placeholder: "输入消息,与 AI 一起探索",
22
- send: "发送消息",
23
- stop: "停止生成",
24
- attach: "添加附件",
25
- removeAttachment: "移除附件",
26
- uploading: "上传中",
27
- uploadFailed: "附件上传失败,请重新添加",
28
- tooManyFiles: "附件数量超过限制",
29
- fileTooLarge: "文件大小超过限制",
30
- fileNotAccepted: "不支持此文件类型",
31
- emptyTitle: "有什么可以帮你?",
32
- emptyDescription: "整理思路、理解资料,或从一个问题开始。",
33
- thinking: "正在思考",
34
- reasoning: "思考过程",
35
- sources: "参考来源",
36
- copy: "复制回答",
37
- copied: "已复制",
38
- regenerate: "重新生成",
39
- retry: "重试",
40
- error: "暂时无法完成回答,请重试。",
41
- dismiss: "关闭提示",
42
- jumpToLatest: "回到最新消息",
43
- approve: "允许",
44
- reject: "拒绝",
45
- tool: "工具调用",
46
- toolInput: "输入",
47
- toolOutput: "结果",
48
- toolPending: "准备中",
49
- toolRunning: "执行中",
50
- toolComplete: "已完成",
51
- toolFailed: "执行失败",
52
- toolDenied: "已拒绝",
53
- toolApproval: "等待你的确认",
54
- toolWaiting: "等待结果",
55
- toolDetails: "展开详情",
56
- toolHideDetails: "收起详情",
57
- suggestions: "接下来可以",
58
- composerHint: "Enter 发送 · Shift + Enter 换行",
59
- unsupportedPart: "此内容需要自定义渲染器",
60
- disclaimer: "AI 生成的内容可能不准确,请核实重要信息。"
61
- };
62
- const enUS = {
63
- title: "AI assistant",
64
- assistant: "Assistant",
65
- user: "You",
66
- placeholder: "Ask a question or explore an idea",
67
- send: "Send message",
68
- stop: "Stop generating",
69
- attach: "Attach files",
70
- removeAttachment: "Remove attachment",
71
- uploading: "Uploading",
72
- uploadFailed: "Upload failed. Please attach the file again.",
73
- tooManyFiles: "Too many attachments",
74
- fileTooLarge: "File exceeds the size limit",
75
- fileNotAccepted: "File type is not supported",
76
- emptyTitle: "How can I help?",
77
- emptyDescription: "Make sense of your documents, explore ideas, or start with a question.",
78
- thinking: "Thinking",
79
- reasoning: "Reasoning",
80
- sources: "Sources",
81
- copy: "Copy response",
82
- copied: "Copied",
83
- regenerate: "Regenerate",
84
- retry: "Retry",
85
- error: "Unable to complete the response. Please try again.",
86
- dismiss: "Dismiss",
87
- jumpToLatest: "Jump to latest",
88
- approve: "Approve",
89
- reject: "Deny",
90
- tool: "Tool call",
91
- toolInput: "Input",
92
- toolOutput: "Result",
93
- toolPending: "Preparing",
94
- toolRunning: "Running",
95
- toolComplete: "Completed",
96
- toolFailed: "Failed",
97
- toolDenied: "Denied",
98
- toolApproval: "Waiting for your approval",
99
- toolWaiting: "Awaiting result",
100
- toolDetails: "Show details",
101
- toolHideDetails: "Hide details",
102
- suggestions: "Suggested next steps",
103
- composerHint: "Enter to send · Shift + Enter for a new line",
104
- unsupportedPart: "This content requires a custom renderer",
105
- disclaimer: "AI can make mistakes. Verify important information."
106
- };
107
- function resolveLabels(overrides) {
108
- return {
109
- ...zhCN,
110
- ...overrides
111
- };
112
- }
113
- //#endregion
114
- export { useAiChat as i, resolveLabels as n, zhCN as r, enUS as t };
115
-
116
- //# sourceMappingURL=labels-BM5o9a9K.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"labels-BM5o9a9K.js","names":[],"sources":["../src/use-ai-chat.ts","../src/labels.ts"],"sourcesContent":["\"use client\";\n\nimport { useChat } from '@ai-sdk/react';\nimport type { UIMessage } from 'ai';\nimport type { AiChatController, AiChatOptions } from './types';\n\n/** Preserves the SDK's typed contract and throttles visual stream updates to 25 fps. */\nexport function useAiChat<M extends UIMessage = UIMessage>(options: AiChatOptions<M> = {}): AiChatController<M> {\n const chat = useChat<M>({ throttle: 40, ...options });\n return { ...chat, isBusy: chat.status === 'submitted' || chat.status === 'streaming' };\n}\n","import type { ChatLabels } from './types';\n\nexport const zhCN: Required<ChatLabels> = {\n title: 'AI 助手', assistant: '助手', user: '你', placeholder: '输入消息,与 AI 一起探索',\n send: '发送消息', stop: '停止生成', attach: '添加附件', removeAttachment: '移除附件',\n uploading: '上传中', uploadFailed: '附件上传失败,请重新添加', tooManyFiles: '附件数量超过限制',\n fileTooLarge: '文件大小超过限制', fileNotAccepted: '不支持此文件类型',\n emptyTitle: '有什么可以帮你?', emptyDescription: '整理思路、理解资料,或从一个问题开始。',\n thinking: '正在思考', reasoning: '思考过程', sources: '参考来源', copy: '复制回答', copied: '已复制',\n regenerate: '重新生成', retry: '重试', error: '暂时无法完成回答,请重试。', dismiss: '关闭提示',\n jumpToLatest: '回到最新消息', approve: '允许', reject: '拒绝', tool: '工具调用', toolInput: '输入',\n toolOutput: '结果', toolPending: '准备中', toolRunning: '执行中', toolComplete: '已完成',\n toolFailed: '执行失败', toolDenied: '已拒绝', toolApproval: '等待你的确认',\n toolWaiting: '等待结果', toolDetails: '展开详情', toolHideDetails: '收起详情',\n suggestions: '接下来可以', composerHint: 'Enter 发送 · Shift + Enter 换行',\n unsupportedPart: '此内容需要自定义渲染器', disclaimer: 'AI 生成的内容可能不准确,请核实重要信息。',\n};\n\nexport const enUS: Required<ChatLabels> = {\n title: 'AI assistant', assistant: 'Assistant', user: 'You', placeholder: 'Ask a question or explore an idea',\n send: 'Send message', stop: 'Stop generating', attach: 'Attach files', removeAttachment: 'Remove attachment',\n uploading: 'Uploading', uploadFailed: 'Upload failed. Please attach the file again.', tooManyFiles: 'Too many attachments',\n fileTooLarge: 'File exceeds the size limit', fileNotAccepted: 'File type is not supported',\n emptyTitle: 'How can I help?', emptyDescription: 'Make sense of your documents, explore ideas, or start with a question.',\n thinking: 'Thinking', reasoning: 'Reasoning', sources: 'Sources', copy: 'Copy response', copied: 'Copied',\n regenerate: 'Regenerate', retry: 'Retry', error: 'Unable to complete the response. Please try again.', dismiss: 'Dismiss',\n jumpToLatest: 'Jump to latest', approve: 'Approve', reject: 'Deny', tool: 'Tool call', toolInput: 'Input',\n toolOutput: 'Result', toolPending: 'Preparing', toolRunning: 'Running', toolComplete: 'Completed',\n toolFailed: 'Failed', toolDenied: 'Denied', toolApproval: 'Waiting for your approval',\n toolWaiting: 'Awaiting result', toolDetails: 'Show details', toolHideDetails: 'Hide details',\n suggestions: 'Suggested next steps', composerHint: 'Enter to send · Shift + Enter for a new line',\n unsupportedPart: 'This content requires a custom renderer', disclaimer: 'AI can make mistakes. Verify important information.',\n};\n\nexport function resolveLabels(overrides?: Partial<ChatLabels>): Required<ChatLabels> {\n return { ...zhCN, ...overrides };\n}\n"],"mappings":";;;;AAOA,SAAgB,UAA2C,UAA4B,CAAC,GAAwB;CAC9G,MAAM,OAAO,QAAW;EAAE,UAAU;EAAI,GAAG;CAAQ,CAAC;CACpD,OAAO;EAAE,GAAG;EAAM,QAAQ,KAAK,WAAW,eAAe,KAAK,WAAW;CAAY;AACvF;;;ACRA,MAAa,OAA6B;CACxC,OAAO;CAAS,WAAW;CAAM,MAAM;CAAK,aAAa;CACzD,MAAM;CAAQ,MAAM;CAAQ,QAAQ;CAAQ,kBAAkB;CAC9D,WAAW;CAAO,cAAc;CAAgB,cAAc;CAC9D,cAAc;CAAY,iBAAiB;CAC3C,YAAY;CAAY,kBAAkB;CAC1C,UAAU;CAAQ,WAAW;CAAQ,SAAS;CAAQ,MAAM;CAAQ,QAAQ;CAC5E,YAAY;CAAQ,OAAO;CAAM,OAAO;CAAiB,SAAS;CAClE,cAAc;CAAU,SAAS;CAAM,QAAQ;CAAM,MAAM;CAAQ,WAAW;CAC9E,YAAY;CAAM,aAAa;CAAO,aAAa;CAAO,cAAc;CACxE,YAAY;CAAQ,YAAY;CAAO,cAAc;CACrD,aAAa;CAAQ,aAAa;CAAQ,iBAAiB;CAC3D,aAAa;CAAS,cAAc;CACpC,iBAAiB;CAAe,YAAY;AAC9C;AAEA,MAAa,OAA6B;CACxC,OAAO;CAAgB,WAAW;CAAa,MAAM;CAAO,aAAa;CACzE,MAAM;CAAgB,MAAM;CAAmB,QAAQ;CAAgB,kBAAkB;CACzF,WAAW;CAAa,cAAc;CAAgD,cAAc;CACpG,cAAc;CAA+B,iBAAiB;CAC9D,YAAY;CAAmB,kBAAkB;CACjD,UAAU;CAAY,WAAW;CAAa,SAAS;CAAW,MAAM;CAAiB,QAAQ;CACjG,YAAY;CAAc,OAAO;CAAS,OAAO;CAAsD,SAAS;CAChH,cAAc;CAAkB,SAAS;CAAW,QAAQ;CAAQ,MAAM;CAAa,WAAW;CAClG,YAAY;CAAU,aAAa;CAAa,aAAa;CAAW,cAAc;CACtF,YAAY;CAAU,YAAY;CAAU,cAAc;CAC1D,aAAa;CAAmB,aAAa;CAAgB,iBAAiB;CAC9E,aAAa;CAAwB,cAAc;CACnD,iBAAiB;CAA2C,YAAY;AAC1E;AAEA,SAAgB,cAAc,WAAuD;CACnF,OAAO;EAAE,GAAG;EAAM,GAAG;CAAU;AACjC"}