# @aws/chat-client 中文文档

规范地址：https://npmcn.com/package/%40aws/chat-client/

版本：0\.1\.58
npm 元数据更新时间：2026-10-08T23:12:17.882Z
中文译文更新时间：2026-11-07T19:09:20.741Z
软件包许可：Apache-2\.0

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40aws/chat-client
原文对照：https://npmcn.com/package/%40aws/chat-client/?lang=original
项目主页：https://github.com/Amazon-Q-Developer/language-servers#readme
源码仓库：https://github.com/Amazon-Q-Developer/language-servers

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：7.8 MB，108 个文件
- 模块格式：CommonJS
- TypeScript 类型：包内自带
- 运行依赖：4 个
- 首次发布：2024-10-09T15:26:08.287Z
- 最新版本发布：2026-10-08T23:12:17.433Z
- 近 30 天下载量：3053（2026-10-08 至 2026-11-06，npm 官方下载统计）
- 已发布版本数：63（近 12 个月 17 个）

## 中文简介

AWS 聊天客户端

## 安装

```sh
npm install @aws/chat-client
```

也可以使用：`pnpm add @aws/chat-client`、`yarn add @aws/chat-client`、`bun add @aws/chat-client`

## README

# QChat 客户端

此软件包包含一个Q语言服务器的聊天客户端,可以嵌入到网页视图中. 用这个 [迈纳维](https://github.com/aws/mynah-ui) 生成基于网络的聊天界面.

## 通讯

聊天客户端通过主机应用程序( 如 IDE 扩展) 进行通信 `postMessage` 访问网页视图的请求 :

-   当主机应用程序发送请求时,客户端会处理消息并发送给UI
-   当一个事件在 UI 中被触发时,客户端会通过 `postMessage` 创建聊天客户端的主机应用程序

### 主办环境

网页视图由不同的IDE主机所嵌入,它们使用不同的浏览器引擎并不同地加载聊天资产. 因此 `event.origin` 在入境时观察到 `postMessage` 事件为 **没有** 整个主机的制服 :

| 东道主 | 渲染引擎 | 资产计划 | `window.location.origin` / 输入 `event.origin` | 信件传送桥 |
| --- | --- | --- | --- | --- |
| VS 代码 | 铬网络视图 | `vscode-webview://` | `vscode-webview://<id>` (非HTTP) (韩语) | `acquireVsCodeApi().postMessage` |
| 喷气管 | 常设理事会 | `https://toolkitasset` | `https://toolkitasset` (同样来源) | JCEF JS查询桥+ `postMessage` |
| 视觉工作室 | 边缘 Webview2 | 服务主机 | 依赖主机 | `window.chrome.webview.postMessage` |
| Eclipse (窗户) | 边缘 Webview2 | HTML 通过 `Browser.setText()` | 空 `""` 或者说 `"null"` (不透明来源) | 输入主机 `window.postMessage` |
| Eclipse (macOS / Linux) (英语) | WebKit / WebKitGTK 网络设备 | 本地资产服务器 | HTTP( S) 同源 | 输入主机 `window.postMessage` |
| SageMaker 尤皮特拉布 | 浏览器(铬 / Firefox / Safari) | 同域线框架 | 原产地 | `window.postMessage` |

由于来源不统一,入境消息处理器在防御上验证它:它只拒绝一个真实的HTTP(S)交叉发端消息并允许空出, `"null"`,以及 `file://` 来源,由合法主机生产(例如Windows上的Eclipse,其中) `Browser.setText()`\-被注射的HTML有不透明的来源). 对入境信件处理或来源验证的任何更改 **必须对上面每个主机环境进行验证** ——见: `handleInboundMessage` JSDoc 输入 [`src/client/chat.ts`](https://npmcn.com/package/%40aws/chat-client/src/client/chat.ts)。 。 。 .

## 使用量

要使用聊天客户端, 将它嵌入您的应用程序中的网页视图并处理 `postMessage` 视需要进行沟通。 聊天客户端基于入境(从目的地到聊天客户端)和出境事件(从聊天客户端到目的地). 活动包括: `command` 财务报告和审定财务报表 `params`数字 :

```
interface SomeEvent {
    command: string;
    params: SomeOptions;
}
```

### 入境事件

| 名称 | 说明 | 命令 | 段落 |
| --- | --- | --- | --- |
| 发送ChatPrompt 响应 | 为发送ChatPrompt请求提供响应 | `aws/chat/sendChatPrompt` | [聊天结果](https://github.com/aws/language-server-runtimes/blob/10e67de47600f20bf090ce8ec0ea318038a387f2/types/chat.ts#L77C18-L77C28) |
| 打开 Tab 请求 | 请求打开标签( 如果没有则创建标签) `tabId` (已提供) | `aws/chat/openTab` | 请求ID - 在网页视图和 vscode 客户端之间共享的ID, [打开TabParams](https://github.com/aws/language-server-runtimes/blob/10e67de47600f20bf090ce8ec0ea318038a387f2/types/chat.ts#L200) |
| 发送到Prompt | 请求将选中内容发送到快速 | `sendToPrompt` | [发送到PromptParams](https://github.com/aws/language-server-runtimes/blob/fe2669c34479d4925f2bdbe5527417ea8aed6c39/chat-client-ui-types/src/uiContracts.ts#L50C18-L50C36) |
| 一般命令 | 请求执行通用命令 | `genericCommand` | [通用指挥](https://github.com/aws/language-server-runtimes/blob/fe2669c34479d4925f2bdbe5527417ea8aed6c39/chat-client-ui-types/src/uiContracts.ts#L76) |
| 错误 | 请求显示聊天 UI 错误 | `errorMessage` | [错误](https://github.com/aws/language-server-runtimes/blob/fe2669c34479d4925f2bdbe5527417ea8aed6c39/chat-client-ui-types/src/uiContracts.ts#L88C18-L88C29) |
| 聊天选项 | 配置聊天启动选项 | `chatOptions` | [聊天选项](https://github.com/aws/language-server-runtimes/blob/main/types/chat.ts#L127) |
| 聊天更新日期 | 更新已存在的聊天信息 | `aws/chat/sendChatUpdate` | [聊天更新](https://github.com/aws/language-server-runtimes/blob/112feba70219a98a12f13727d67c540205fa9c9f/types/chat.ts#L355) |
| 上下文命令 | 向 UI 发送上下文命令 | `aws/chat/sendContextCommands` | [上下文指挥](https://github.com/aws/language-server-runtimes/blob/112feba70219a98a12f13727d67c540205fa9c9f/types/chat.ts#L393) |
| 列表集合响应 | 向UI提供历史对话列表 | `aws/chat/listConversations` | [列表汇编](https://github.com/aws/language-server-runtimes/blob/112feba70219a98a12f13727d67c540205fa9c9f/types/chat.ts#L478) |
| 对话 Click 响应 | 对对话框点击或动作提供响应, 指定动作执行结果 | `aws/chat/conversationClick` | [对话 ClickResult](https://github.com/aws/language-server-runtimes/blob/112feba70219a98a12f13727d67c540205fa9c9f/types/chat.ts#L512) |
| 获得序列化 聊天请求 | 请求进行串行聊天 | `aws/chat/getSerializedChat` | [获取序列化的ChatParams](https://github.com/aws/language-server-runtimes/blob/112feba70219a98a12f13727d67c540205fa9c9f/types/chat.ts#L550) |
| 聊天选项更新 | 从服务器发送聊天选项更新请求 | `aws/chat/chatOptionsUpdate` | [聊天选项更新图片](https://github.com/aws/language-server-runtimes/blob/112feba70219a98a12f13727d67c540205fa9c9f/types/chat.ts#L365) |
| 规则响应 | 向UI提供工作空间规则清单 | `aws/chat/listRules` | [列表规则](https://github.com/aws/language-server-runtimes/blob/0d9d55751bd977e82ded0906d31dbfd8bf027893/types/chat.ts#540) |
| 规则点击的响应 | 提供规则点击或动作的响应,指定动作执行结果 | `aws/chat/ruleClick` | [规则克结果](https://github.com/aws/language-server-runtimes/blob/0d9d55751bd977e82ded0906d31dbfd8bf027893/types/chat.ts#572) |
| 添加选中的 Files 连接 | 请求将选中的文件添加到上下文 | `aws/chat/openFileDialog` | [OpenFileDialog 最终版本](https://github.com/aws/language-server-runtimes/blob/0d9d55751bd977e82ded0906d31dbfd8bf027893/types/chat.ts#450) |
| 发送 Pinned 连接 | 向用户界面发送已绑定的上下文信息 | `aws/chat/sendPinnedContext` | [剪接连接](https://github.com/aws/language-server-runtimes/blob/0d9d55751bd977e82ded0906d31dbfd8bf027893/types/chat.ts#L433) |

### 外部事件

| 名称 | 说明 | 命令 | 段落 |
| --- | --- | --- | --- |
| 打开 Tab 响应 | 对打开的Tab 请求提供响应 | `aws/chat/openTab` | 请求ID - 在网页视图和 vscode 客户端之间共享的ID, [微信公众号](https://github.com/aws/language-server-runtimes/blob/10e67de47600f20bf090ce8ec0ea318038a387f2/chat-client-ui-types/src/uiContracts.ts#L129) 与 `result` 类型 [打开标签](https://github.com/aws/language-server-runtimes/blob/main/types/chat.ts#L201) |
| 已确认 | 通知目的地,法律免责声明得到用户的承认 | `disclaimerAcknowledged` | 不详 |
| 发送ChatPrompt | 向服务器发送聊天提示 | `aws/chat/sendChatPrompt` | [恰克帕拉姆斯语Name](https://github.com/aws/language-server-runtimes/blob/112feba70219a98a12f13727d67c540205fa9c9f/types/chat.ts#L87) |
| 发送快速行动命令 | 发送快速行动命令 | `aws/chat/quickAction` | [快速行动图像](https://github.com/aws/language-server-runtimes/blob/112feba70219a98a12f13727d67c540205fa9c9f/types/chat.ts#L261) |
| 选项卡已添加 | 添加标签时通知 | `aws/chat/tabAdd` | [标签](https://github.com/aws/language-server-runtimes/blob/112feba70219a98a12f13727d67c540205fa9c9f/types/chat.ts#L288) |
| 选项卡已更改 | 更改标签时通知 | `aws/chat/tabChange` | [标签](https://github.com/aws/language-server-runtimes/blob/112feba70219a98a12f13727d67c540205fa9c9f/types/chat.ts#L290) |
| 选项卡已删除 | 删除标签时通知 | `aws/chat/tabRemove` | [移动标签](https://github.com/aws/language-server-runtimes/blob/112feba70219a98a12f13727d67c540205fa9c9f/types/chat.ts#L292) |
| 插入目录选项 | 请求在光标位置插入代码 | `insertToCursorPosition` | [插入主页](https://github.com/aws/language-server-runtimes/blob/112feba70219a98a12f13727d67c540205fa9c9f/types/chat.ts#L294) |
| 复制到剪贴板 | 请求复制代码到剪贴板 | `copyToClipboard` | [复制代码ToClipboardParams](https://github.com/aws/language-server-runtimes/blob/112feba70219a98a12f13727d67c540205fa9c9f/chat-client-ui-types/src/uiContracts.ts#L142) |
| 认证后续点击 | 单击认证后续时通知 | `authFollowUpClicked` | [自动跟踪并点出标签](https://github.com/aws/language-server-runtimes/blob/112feba70219a98a12f13727d67c540205fa9c9f/chat-client-ui-types/src/uiContracts.ts#L84) |
| 跟踪点击 | 点击后续建议时通知 | `aws/chat/followUpClick` | [后续 ClickParams](https://github.com/aws/language-server-runtimes/blob/112feba70219a98a12f13727d67c540205fa9c9f/types/chat.ts#L320) |
| 发送回信 | 发送用户反馈 | `aws/chat/feedback` | [反馈](https://github.com/aws/language-server-runtimes/blob/112feba70219a98a12f13727d67c540205fa9c9f/types/chat.ts#L278) |
| 链接点击 | 点击链接时通知 | `aws/chat/linkClick` | [链接ClickParams](https://github.com/aws/language-server-runtimes/blob/112feba70219a98a12f13727d67c540205fa9c9f/types/chat.ts#L312) |
| 源代码 LinkClick | 点击源链接时通知 | `aws/chat/sourceLinkClick` | [源代码 LinkClickParams](https://github.com/aws/language-server-runtimes/blob/112feba70219a98a12f13727d67c540205fa9c9f/types/chat.ts#L316) |
| 信息链接点击 | 点击信息链接时通知 | `aws/chat/infoLinkClick` | [InfoLinkClickParams 信息链接](https://github.com/aws/language-server-runtimes/blob/112feba70219a98a12f13727d67c540205fa9c9f/types/chat.ts#L307) |
| 准备 | 当UI准备好时通知 | `aws/chat/ready` | 不详 |
| 聊天 Prompt 选项已确认 | 确认聊天提示选项时通知 | `chatPromptOptionAcknowledged` | [ChatPrompt 选项已确认的Params](https://github.com/aws/language-server-runtimes/blob/112feba70219a98a12f13727d67c540205fa9c9f/chat-client-ui-types/src/uiContracts.ts#L107C18-L107C52) |
| 创建Prompt | 请求创建快速 | `aws/chat/createPrompt` | [创建PromptParams 程序](https://github.com/aws/language-server-runtimes/blob/112feba70219a98a12f13727d67c540205fa9c9f/types/chat.ts#L397) |
| 文件点击 | 单击文件时通知 | `aws/chat/fileClick` | [文件 ClickParams 图像](https://github.com/aws/language-server-runtimes/blob/112feba70219a98a12f13727d67c540205fa9c9f/types/chat.ts#L371) |
| 列表汇编 | 请求列出带有过滤器的对话 | `aws/chat/listConversations` | [列表组合标签](https://github.com/aws/language-server-runtimes/blob/112feba70219a98a12f13727d67c540205fa9c9f/types/chat.ts#L463) |
| 对话点击 | 点击对话时通知 | `aws/chat/conversationClick` | [对话 ClickParams](https://github.com/aws/language-server-runtimes/blob/112feba70219a98a12f13727d67c540205fa9c9f/types/chat.ts#L507) |
| 选项卡行动作 | 当需要标签栏动作时通知 | `aws/chat/tabBarAction` | [Tab 对话框](https://github.com/aws/language-server-runtimes/blob/112feba70219a98a12f13727d67c540205fa9c9f/types/chat.ts#L541) |
| 获得序列化 聊天响应 | 提供响应以获取序列化 聊天请求 | `aws/chat/getSerializedChat` | [获得序列化 聊天结果](https://github.com/aws/language-server-runtimes/blob/112feba70219a98a12f13727d67c540205fa9c9f/types/chat.ts#L554) |
| 停止聊天响应 | 请求停止当前聊天响应 | `stopChatResponse` | [停止响应](https://github.com/aws/language-server-runtimes/blob/8c9cac765137ca9f3ab08d6a79e6edac768f2c04/chat-client-ui-types/src/uiContracts.ts#L123) |
| 发送按钮ClickEvent | 发送按钮点击事件 | `aws/chat/buttonClick` | [按钮ClickParams](https://github.com/aws/language-server-runtimes/blob/112feba70219a98a12f13727d67c540205fa9c9f/types/chat.ts#L339) |
| 打开位置 | 打开设置的请求 | `openSettings` | [打开设置](https://github.com/aws/language-server-runtimes/blob/8c9cac765137ca9f3ab08d6a79e6edac768f2c04/chat-client-ui-types/src/uiContracts.ts#L165) |
| 规则点击 | 点击规则时通知 | `aws/chat/ruleClick` | [规则ClickParams](https://github.com/aws/language-server-runtimes/blob/0d9d55751bd977e82ded0906d31dbfd8bf027893/types/chat.ts#L566) |
| 列表规则 | 请求列出工作空间规则 | `aws/chat/listRules` | [列表规则](https://github.com/aws/language-server-runtimes/blob/0d9d55751bd977e82ded0906d31dbfd8bf027893/types/chat.ts#536) |
| 已打开 | 请求增加标注上下文 | `aws/chat/addPinnedContext` | [剪接连接](https://github.com/aws/language-server-runtimes/blob/0d9d55751bd977e82ded0906d31dbfd8bf027893/types/chat.ts#433) |
| 已删除 | 请求去除粘贴上下文 | `aws/chat/removePinnedContext` | [剪接连接](https://github.com/aws/language-server-runtimes/blob/0d9d55751bd977e82ded0906d31dbfd8bf027893/types/chat.ts#433) |
| 在 OpenFile DialogClick 上打开 | 打开文件对话框的请求 | `openFileDialog` | [打开FileDialogParams](https://github.com/aws/language-server-runtimes/blob/0d9d55751bd977e82ded0906d31dbfd8bf027893/types/chat.ts#444) |
| 已打开 | 文件被丢弃时通知 | `filesDropped` | [文件已删除](https://github.com/aws/language-server-runtimes/blob/8c9cac765137ca9f3ab08d6a79e6edac768f2c04/chat-client-ui-types/src/uiContracts.ts#L169) |
| 提示输入选项变化 | 当快速输入选项更改时通知 | `aws/chat/promptInputOptionChange` | [快速输入选项变化参数](https://github.com/aws/language-server-runtimes/blob/112feba70219a98a12f13727d67c540205fa9c9f/types/chat.ts#L558) |

### 配置

当创建网络视图内部的聊天时, 配置可以作为明确的参数被传递, 例如 :

```
amazonQChat.createChat(acquireVsCodeApi(), configuration);
```

配置值 :

```
// Configures quick actions
quickActionCommands?: QuickActionCommandGroup[]

// Configures chat client not to show legal disclaimer as it has already been acknowledged before
disclaimerAcknowledged?: boolean
```

## 常见问题

### @aws/chat-client 是什么？

AWS 聊天客户端

### 如何安装 @aws/chat-client？

在项目目录运行 npm install @aws/chat-client，或使用 pnpm add / yarn add / bun add。

### @aws/chat-client 支持 TypeScript 吗？

支持。包内自带 TypeScript 类型声明（package\.json 声明了 types 入口），安装后即可获得类型提示，无需再安装 @types 包。

### @aws/chat-client 支持 ESM 还是 CommonJS？

以 CommonJS 形式发布，可以直接 require\(\)；在 ES Module 项目中也可以用 import 引入（Node\.js 会把 module\.exports 作为默认导出）。

### @aws/chat-client 可以商用吗？

@aws/chat-client 使用 Apache-2\.0 许可。宽松许可：允许商业使用、修改和再分发，并附带明确的专利授权；分发时需保留许可与 NOTICE 文件，修改过的文件要注明改动。以上为概括，不构成法律意见，请以许可原文为准。

### @aws/chat-client 的下载量有多少？

根据 npm 官方下载统计，@aws/chat-client 在 2026/10/08 – 2026/11/06 这 30 天内被下载 3,053 次，日均约 102 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入，适合横向比较热度，不能直接等同于使用人数。

### @aws/chat-client 还在维护吗？

最新版本 0\.1\.58 发布于 2026/10/09（29 天前）；至今共发布 63 个版本，其中过去 12 个月发布了 17 个；首次发布于 2024/10/09。发布频率只是参考信号：功能稳定的工具可能很少需要更新，建议结合源码仓库的 issue 和提交记录判断。

