# @aws/language-server-runtimes 中文文档

规范地址：https://npmcn.com/package/%40aws/language-server-runtimes/

版本：0\.3\.22
npm 元数据更新时间：2026-10-13T19:20:23.044Z
中文译文更新时间：2026-11-07T15:13:45.664Z
软件包许可：Apache-2\.0

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

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

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

- 包体积（解压后）：579 kB，218 个文件
- TypeScript 类型：未声明
- Node.js 要求：\>=24\.0\.0
- 运行依赖：18 个
- 首次发布：2024-03-04T16:43:08.347Z
- 最新版本发布：2026-10-13T19:20:22.628Z
- 近 30 天下载量：10987（2026-10-08 至 2026-11-06，npm 官方下载统计）
- 已发布版本数：153（近 12 个月 17 个）

## 中文简介

AWS 语言服务器主机运行时间

## 安装

```sh
npm install @aws/language-server-runtimes
```

也可以使用：`pnpm add @aws/language-server-runtimes`、`yarn add @aws/language-server-runtimes`、`bun add @aws/language-server-runtimes`

## README

# 语言服务器运行时间

语言服务器运行时(Language Server Runtimes)是基于JSON-RPC的协议,用于服务器和客户端之间的互动(通常嵌入到开发工具中). JSON-RPC协议沿用了该程序所使用的版本 [LSP 规格 - 3.17](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/),用于兼容性。 支持LSP版本3.17的一个子集(见 [LSP 软件](https://npmcn.com/package/%40aws/language-server-runtimes/README.md#lsp))加上另外一套请求和答复类型(见 [特征](https://npmcn.com/package/%40aws/language-server-runtimes/README.md#features)) (中文(简体) ).

Language Server Runtimes支持一些主机环境,每个主机都有自己的内在传输机制和环境考虑,这也必须支持JSON-RPC的通信. 要了解主机环境之间的差异,请查看 [运行时主机环境](https://npmcn.com/package/%40aws/language-server-runtimes/README.md#runtime-host-environments)。 。 。 .

## 术语

服务器运行时间将提供"Features",指语言服务器运行时间的核心功能(如LSP,日志等). 这些功能将在构建时注入到服务器业务逻辑执行之上. [能力](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#capabilities) 是由 LSP 提供的一组语言特性.

## 项目结构

项目源代码被拆分为下个目录:

-   `/src`: 本目录包含项目的所有源代码.
    -   `/protocol`:JSON-RPC基于Typescription的运行时协议执行,它定义了运行时客户端与运行时客户端之间的通信(例如AWS工具包扩展).
    -   `/runtimes`: 执行由服务器执行者开发的多个运行时间(独立,网络工作)和功能,这些运行时间和功能暴露在运行时间服务器上.
    -   `/server-interface`:定义特性的接口,运行时为运行时服务器执行器提供.
    -   `/testing`:测试服务器执行器的助手.

## 特征

### LSP 软件

服务器运行时间执行起到LSP方法的代理作用,这意味着它支持所有LSP方法. 除此之外,还可以将LSP方法扩展为支持自定义能力.

#### 特性规格

| 方法 | 支助 | 页:1 |
| --- | --- | --- |
| 内置完成 | 对 | 提供服务器的内置补全建议列表 |
| 执行命令 | 对 | 执行服务器提供的自定义命令。 建议服务器在软件包README中记录支持的自定义命令. |

##### LSP 窗口

| 说明 | 方法 | 参数 | 方法类型 | 反应类型 |
| --- | --- | --- | --- | --- |
| 请求检查指定文件的诊断 | `aws/checkDiagnostics` | `CheckDiagnosticsParams` | [请求](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#requestMessage) 服务器到客户端 | `CheckDiagnosticsResult` |

##### LSP 工作空间

| 说明 | 方法 | 参数 | 方法类型 | 反应类型 |
| --- | --- | --- | --- | --- |
| 请求选择工作空间项目( 文件夹, 文件) 并返回选中的项目 | `aws/selectWorkspaceItem` | `SelectWorkspaceItemParams` | [请求](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#requestMessage) 服务器到客户端 | `SelectWorkspaceItemResult` |
| 请求在工作空间程序上打开文件 | `aws/openWorkspaceFile` | `OpenWorkspaceFileParams` | [请求](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#requestMessage) 服务器到客户端 | `OpenWorkspaceFileResult` |
| 为新文件内容打开文件差异发送通知 。 支持新文件、更新文件或删除文件. | `aws/openFileDiff` | `OpenFileDiffParams` | [通知](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#notificationMessage) 服务器到客户端 | 无 |
| 发送通知, 使用文件系统操作将文件从旧路径复制到新路径 . | `aws/didCopyFile` | `CopyFileParams` | [通知](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#notificationMessage) 服务器到客户端 | 无 |
| 发送通知, 内容被写入使用文件系统操作存档 . | `aws/didWriteFile` | `FileParams` | [通知](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#notificationMessage) 服务器到客户端 | 无 |
| 发送通知, 内容被附加到使用文件系统操作存档 . | `aws/didAppendFile` | `FileParams` | [通知](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#notificationMessage) 服务器到客户端 | 无 |
| 发送通知, 使用文件系统操作删除了文件或目录 . | `aws/didRemoveFileOrDirectory` | `FileParams` | [通知](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#notificationMessage) 服务器到客户端 | 无 |
| 发送通知, 目录是使用文件系统操作创建的 . | `aws/didCreateDirectory` | `FileParams` | [通知](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#notificationMessage) 服务器到客户端 | 无 |

##### LSP 扩展

| 方法名称 | 方法 | 参数 | 方法类型 | 反应类型 | 页:1 |
| --- | --- | --- | --- | --- | --- |
| 从服务器获取配置 | `aws/getConfigurationFromServer` | `GetConfigurationFromServerParams` | [请求](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#requestMessage) | `LSPAny` | 从服务器获取指定区域配置 |
| 内置完成 参考 | `aws/textDocument/inlineCompletionWithReferences` | `InlineCompletionWithReferencesParams` | [请求](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#requestMessage) | `InlineCompletionListWithReferences` | 提供服务器的内置补全建议清单,并注明每个建议的参考文献 |
| 在LogInline Complete 会议上的发言 | `aws/logInlineCompletionSessionResults` | `LogInlineCompletionSessionResultsParams` | [通知](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#notificationMessage) | 无 | 记录服务器内置补全建议的结果 |

### 认证

运行时间支持两种类型的证书: [IAM 全权证书](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/Credentials.html) 和 Bearer 令牌(例如 Builder ID) 。 这些全权证书应以简洁文本提供给目的地.

```ts
// IAM Credentials data
export interface IamCredentials {
    accessKeyId: string
    secretAccessKey: string
    sessionToken?: string
}

// Bearer Token data
export interface BearerCredentials {
    token: string
}
```

目的地负责管理资质状态,在状态变化时刷新和更新.

#### 初始化

运行时间默认支持两种类型的证书认证,不需要事先与客户端达成协议或握手. 如果客户端支持特定类型的证书,则相应的LSP `update` 方法可以直接调用。 对于通过纯文本证书不合适的案件(如独立运行时间),可以在发送到服务器前加密(参见 [加密](https://npmcn.com/package/%40aws/language-server-runtimes/README.md#encryption)) (中文(简体) ).

#### 特性规格

下表概述了自定义的LSP方法由服务器支持进行认证:

| 说明 | 方法 | 参数 | 方法类型 | 反应类型 |
| --- | --- | --- | --- | --- |
| 发送 IAM 证书 | `aws/credentials/iam/update` | `UpdateCredentialsPayload` | [请求](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#requestMessage) | [回应](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#responseMessage) |
| 发送守护符 | `aws/credentials/token/update` | `UpdateCredentialsPayload` | [请求](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#requestMessage) | [回应](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#responseMessage) |
| 删除 IAM 证书 | `aws/credentials/iam/delete` | 无 | [通知](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#notificationMessage) | 无 |
| 删除无记名符号 | `aws/credentials/token/delete` | 无 | [通知](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#notificationMessage) | 无 |

```ts
export type Credentials = IamCredentials | BearerCredentials

// Credentials provided to the server by the server's host
export interface UpdateCredentialsPayload {
    // Plaintext IamCredentials/BearerCredentials or JSON blob of encrypted credentials
    data: string | Credentials
    // If the payload is encrypted
    // Defaults to false if undefined or null
    encrypted?: boolean
}
```

##### 获取连接元数据

服务器 Auth 特性支持在服务器中存储额外的 Auth 连接数据. 获取连接元数据是服务器向客户端发送的请求,以获取新的连接信息. 服务器期望客户端提供指定的元数据 `ConnectionMetadata` 接口.

| 说明 | 方法 | 参数 | 方法类型 | 反应类型 |
| --- | --- | --- | --- | --- |
| 获取连接元数据 | `aws/credentials/getConnectionMetadata` | 无 | [请求](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#requestMessage) | `ConnectionMetadata` |

```ts
export interface ConnectionMetadata {
    sso?: SsoProfileData
}

export interface SsoProfileData {
    startUrl?: string
}
```

### 遥测

#### 初始化

运行时间默认支持遥测功能,允许服务器向目的地发送度量衡. 目前正在计划另外在初始化期间和正在进行的会议期间禁用这一特性.

#### 特性规格

遥测通知从服务器发送到客户端,要求客户端登录一个遥测事件. 使用遥测特性的AWS跑时会发出带有指定有效载荷接口的默认LSP遥测通知的计量事件. 遥测通知如下:

| 说明 | 方法 | 参数 | 方法类型 | 反应类型 |
| --- | --- | --- | --- | --- |
| 发送遥测事件 | `telemetry/event` | `MetricEvent` | [通知](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#notificationMessage) | 无 |

```ts
export type MetricEvent = {
    name: string
    data?: any
    result?: ResultType
    errorData?: ErrorData
}
```

### 日志

设计 TBD

#### 初始化

默认运行时间支持日志功能,允许服务器输出日志,日志级别不同.

#### 特性规格

在日志运行时间中设定的日志级别可以由客户端决定,作为初始化请求的一部分,这是第一个 请求由客户端启动到 LSP 服务器。 日志级别可以在服务器启动后动态更新 `workspace/didChangeConfiguration` 来自客户端的通知 - 提醒运行时间通过 LSP 从客户端获取新日志级别 `getConfigurations` 请求.

1.  初始化请求中的参数 : `InitializeParams.initializationOptions.logLevel`
2.  从运行时间到客户端请求日志级的配置请求参数 : `{section: "aws.logLevel"}`

### 聊天

运行时间定义了 Chat 接口,允许运行时间服务器执行器定义聊天事件的处理器,以允许对话体验. 聊天数据类型大多是按下列模式制作的: [我亲爱的](https://github.com/aws/mynah-ui),一个为聊天体验设计的驱动UI库的事件. `mynah-ui` 是建议在目的地使用的 UI 库。 然而 Chat 接口的通用性足以兼容其他 UI 方法

#### 初始化

运行时间默认支持聊天

#### 特性规格

| 说明 | 方法 | 参数 | 方法类型 | 反应类型 |
| --- | --- | --- | --- | --- |
| 发送聊天提示 。 支持将聊天消息内容流到客户端. 响应是可选的 - 此事件只能用来触发聊天提示请求, 然后 `aws/chat/sendChatUpdate` 可用于同步发送聊天更新. | `aws/chat/sendChatPrompt` | `ChatParams` | [请求](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#requestMessage) 客户端到服务器 | `ChatResult` |
| 结束对话 | `aws/chat/endChat` | `EndChatParams` | [请求](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#requestMessage) 客户端到服务器 | `EndChatResult` |
| 发送聊天快速动作 。 响应是可选的 - 此事件只能用来触发聊天快速动作请求, 然后 `aws/chat/sendChatUpdate` 可用于同步发送聊天更新. | `aws/chat/sendChatQuickAction` | `QuickActionParams` | [请求](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#requestMessage) 客户端到服务器 | `ChatResult` |
| 将通用按钮点击请求发送给服务器 。 此事件可用于触发按钮点击动作 。 客户端可以利用响应来确定相关动作是否成功执行. | `aws/chat/buttonClick` | `ButtonClickParams` | [请求](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#requestMessage) 客户端到服务器 | `ButtonClickResult` |
| 发送聊天 UI 准备事件 | `aws/chat/ready` | 无 | [通知](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#notificationMessage) 客户端到服务器 | 无 |
| 发送聊天反馈事件 | `aws/chat/feedback` | `FeedbackParams` | [通知](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#notificationMessage) 客户端到服务器 | 无 |
| 发送标签添加事件 | `aws/chat/tabAdd` | `TabAddParams` | [通知](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#notificationMessage) 客户端到服务器 | 无 |
| 发送活动标签更改事件 | `aws/chat/tabChange` | `TabChangeParams` | [通知](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#notificationMessage) 客户端到服务器 | 无 |
| 发送标签删除事件 | `aws/chat/tabRemove` | `TabRemoveParams` | [通知](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#notificationMessage) 客户端到服务器 | 无 |
| 发送插入到光标位置事件 | `aws/chat/insertToCursorPosition` | `InsertToCursorPositionParams` | [通知](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#notificationMessage) 客户端到服务器 | 无 |
| 发送链接点击事件 | `aws/chat/linkClick` | `LinkClickParams` | [通知](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#notificationMessage) 客户端到服务器 | 无 |
| 发送信息链接点击事件 | `aws/chat/infoLinkClick` | `InfoLinkClickParams` | [通知](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#notificationMessage) 客户端到服务器 | 无 |
| 发送源链接点击事件 | `aws/chat/sourceLinkClick` | `SourceLinkClickParams` | [通知](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#notificationMessage) 客户端到服务器 | 无 |
| 发送后续聊天项目点击事件 | `aws/chat/followUpClick` | `FollowUpClickParams` | [通知](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#notificationMessage) 客户端到服务器 | 无 |
| 如果 `tabId` 如果 `tabId` 未通过。 对于新标签,也可以设置标签状态和内容. | `aws/chat/openTab` | `OpenTabParams` | [请求](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#requestMessage) 服务器到客户端 | `OpenTabResult` |
| 向特定标签发送聊天信息和标签状态更新 。 取决于新的对已有的`messageId` 在内部 `ChatMessage` 信息,将添加或更新批量. | `aws/chat/sendChatUpdate` | `ChatUpdateParams` | [通知](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#notificationMessage) 服务器到客户端 | 无 |
| 发送文件或文件动作点击事件 . | `aws/chat/fileClick` | `FileClickParams` | [通知](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#notificationMessage) 客户端到服务器 | 无 |
| 发送内置聊天提示 。 响应是可选的 - 此事件只能用于触发内置聊天即时请求,然后可以同步发送更新. | `aws/chat/sendInlineChatPrompt` | `InlineChatParams` | [请求](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#requestMessage) 客户端到服务器 | `InlineChatResult` |
| 发送带有用户决定和度量的内置聊天结果通知. | `aws/chat/inlineChatResult` | `InlineChatResultParams` | [通知](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#notificationMessage) 客户端到服务器 | 无 |
| 发送或更新客户可以附加于其快速请求的上下文命令(可通过 `@` (原始内容存档于2017-09-29). In check UI. | `aws/chat/sendContextCommands` | `ContextCommandParams` | [通知](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#notificationMessage) 服务器到客户端 | 无 |
| 发送触发服务器上新的即时或规则创建流的快速事件 . | `aws/chat/createPrompt` | `CreatePromptParams` | [通知](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#notificationMessage) 客户端到服务器 | 无 |
| 发送请求以列出历史中可用的对话框: 如果提供了全部或基于过滤器 。 由于可以使用若干个过滤选项,请求中的过滤器是过滤选项ID与相应值的映射. 预计在前一段提供可能的过滤选项 `listConversations` 在使用过滤器之前得出结果. | `aws/chat/listConversations` | `ListConversationsParams` | [请求](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#requestMessage) 客户端到服务器 | `ListConversationsResult` |
| 发送对话或对话动作点击事件 。 如果没有提供动作,默认动作是"打开". | `aws/chat/conversationClick` | `ConversationClickParams` | [请求](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#requestMessage) 客户端到服务器 | `ConversationClickResult` |
| 发送请求以列出可用的 MCP 服务器: 如果提供了全部或基于过滤器 。 与对话类似,请求中的过滤器是过滤选项ID与相应值的映射. | `aws/chat/listMcpServers` | `ListMcpServersParams` | [请求](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#requestMessage) 客户端到服务器 | `ListMcpServersResult` |
| 发送MCP服务器或MCP服务器动作点击事件. 如果没有提供动作,默认动作是"选择". | `aws/chat/mcpServerClick` | `McpServerClickParams` | [请求](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#requestMessage) 客户端到服务器 | `McpServerClickResult` |
| 发送请求以列出当前聊天标签可用的模式 . | `aws/chat/listAvailableModels` | `ListAvailableModelsParams` | [请求](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#requestMessage) 客户端到服务器 | `ListAvailableModelsResult` |
| 向客户端发送被绑定的上下文 。 被绑定的上下文包含被绑入当前标签的上下文命令 . | `aws/chat/sendPinnedContext` | `PinnedContextParams` | [通知](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#notificationMessage) 服务器到客户端 | 无 |
| 通知服务器, 客户端已经添加了被绑定上下文 . | `aws/chat/pinnedContextAdd` | `PinnedContextParams` | [通知](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#notificationMessage) 客户端到服务器 | 无 |
| 通知服务器被客户端删除了被绑定的上下文 . | `aws/chat/pinnedContextRemove` | `PinnedContextParams` | [通知](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#notificationMessage) 客户端到服务器 | 无 |
| 通知服务器活动编辑器已更改 . | `aws/chat/activeEditorChanged` | `ActiveEditorChangedParams` | [通知](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#notificationMessage) 客户端到服务器 | 无 |
| 发送请求以列出用于特定标签的规则 . | `aws/chat/listRules` | `ListRulesParams` | [请求](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#requestMessage) 客户端到服务器 | `ListRulesResult` |
| 发送规则或规则文件夹点击事件 . | `aws/chat/ruleClick` | `RuleClickParams` | [请求](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#requestMessage) 客户端到服务器 | `RuleClickResult` |
| 发送服务器启动的聊天元数据更新 。 界面设计为未来聊天选项的可扩展性,目前侧重于对开发者配置变化的通知. | `aws/chat/chatOptionsUpdate` | `ChatOptionsUpdateParams` | [通知](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#notificationMessage) 服务器到客户端 | 无 |
| 发送快速输入选项更改 | `aws/chat/promptInputOptionChange` | `PromptInputOptionChangeParams` | [通知](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#notificationMessage) 客户端到服务器 | 无 |
| 发送标签栏动作请求(例如导出). | `aws/chat/tabBarAction` | `TabBarActionParams` | [请求](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#requestMessage) 客户端到服务器 | `TabBarActionResult` |
| 发送请求以获取特定格式的串行聊天内容 . | `aws/chat/getSerializedChat` | `GetSerializedChatParams` | [请求](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#requestMessage) 客户端到服务器 | `GetSerializedChatResult` |
| 发送请求以打开文件对话框以选择文件 . | `aws/chat/openFileDialog` | `OpenFileDialogParams` | [请求](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#requestMessage) 客户端到服务器 | `OpenFileDialogResult` |
| 发送到聊天UI中显示订阅信息 | `aws/chat/subscription/details` | 订阅详情 | [通知](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#notificationMessage) 服务器到客户端 | 无 |
| 发送开始订阅升级 | `aws/chat/subscription/upgrade` | 订阅 上级标签 | [通知](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#notificationMessage) 客户端到服务器 | 无 |

```ts
export interface ChatPrompt {
    prompt?: string
    escapedPrompt?: string
    command?: string
}

interface PartialResultParams {
    partialResultToken?: number | string
}

export interface ChatParams extends PartialResultParams {
    tabId: string
    prompt: ChatPrompt
    cursorState?: CursorState[]
    textDocument?: TextDocumentIdentifier
}
```

完整的聊天参数和结果接口可见于 [聊天时间](https://npmcn.com/package/%40aws/language-server-runtimes/src/protocol/chat.ts)

### 身份管理

身份管理功能旨在集中管理认证和身份相关功能. API包括:

-   列出和管理用户简介和SSO会议
-   获取有效的 SSO 访问令牌, 根据需要处理 PKCE 或设备代码登录流量
-   控制有效SSO标志的寿命和通知
-   无效缓存的 SSO 令牌

#### 特性规格

| 说明 | 方法 | 参数 | 方法类型 | 反应类型 |
| --- | --- | --- | --- | --- |
| 列表简介 | `aws/identity/listProfiles` | `ListProfilesParams` | [请求](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#requestMessage) | `ListProfilesResult` |
| 更新配置 | `aws/identity/updateProfile` | `UpdateProfileParams` | [请求](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#requestMessage) | `UpdateProfileResult` |
| 获取 SSO 令牌 | `aws/identity/getSsoToken` | `GetSsoTokenParams` | [请求](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#requestMessage) | `GetSsoTokenResult` |
| 无效的 SSO 令牌 | `aws/identity/invalidateSsoToken` | `InvalidateSsoTokenParams` | [请求](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#requestMessage) | `InvalidateSsoTokenResult` |
| SSO 令牌已更改 | `aws/identity/ssoTokenChanged` | `SsoTokenChangedParams` | [通知](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#notificationMessage) | 无 |

完整的身份管理参数和结果接口可见于 [身份管理](https://npmcn.com/package/%40aws/language-server-runtimes/src/protocol/identity-management.ts)

#### 客户能力

要求客户端执行支持接收以下请求: 1

-   `window/showDocument`
    
    ```
    client.onRequest<ShowDocumentResult, Error>(
        ShowDocumentRequest.method,
        async (params: ShowDocumentParams) => { ... }
    )
    ```
    
-   `window/showMessageRequest`
    
    ```
    client.onRequest<MessageActionItem | null, Error>(
        ShowMessageRequest.method,
        async (params: ShowMessageRequestParams) => { ... }
    )
    ```
    
-   `onProgress`
    
    ```
    client.onProgress(
        GetSsoTokenProgressType, 
        GetSsoTokenProgressToken,
        async (partialResult: GetSsoTokenProgress) => { 
            // partialResult is likely encrypted
            ...
        }
    )
    ```
    

### 通知

通知功能可以用来向客户发送定制客户端通知. 通知可以包含动作,比如显示 URL,也可以包含后续动作,比如请求客户确认. 当客户端对后续动作作出反应时,预计将从客户端发送到服务器的同步通知,以通知服务器有关此事.

通知应用于需要客户注意的罕见/例外情况(如发生了一些变化或建议采取的行动),但不会阻碍主要流动。 如果发送过多,客户可以决定暂停通知.

考虑使用 LSP [显示信件通知](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#window_showMessage) 相反,如果你的通知不需要采取行动或后续行动.

#### 特性规格

| 说明 | 方法 | 参数 | 方法类型 | 反应类型 |
| --- | --- | --- | --- | --- |
| 向客户显示通知 | `aws/window/showNotification` | `NotificationParams` | [通知](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#notificationMessage) | 无 |
| 将通知后续发送到服务器 | `aws/window/notificationFollowup` | `NotificationFollowupParams` | [通知](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#notificationMessage) | 无 |

### 代理工具

为了创建代理应用程序,服务器可以定义可以被发送到模型后端使用的工具. 工具可以在多个服务器中创建,并在同一运行时间的所有服务器之间共享. 工具使用中没有JSON/RPC组件,工具都保存在运行时内存中.

工具引用可以使用LSP,工作空间或聊天能力与客户端环境互动.

该代理特性使用以下接口:

```ts
export type Agent = {
    /**
     * Add a tool to the local tool repository. Tools with the same name will be overwritten.
     *
     * Tools should be called using `runTool`.
     *
     * @param spec Tool Specification
     * @param handler The async method to execute when the tool is called
     */
    addTool: <T extends InferSchema<S['inputSchema']>, S extends ToolSpec, R>(
        spec: S,
        handler: (input: T, token?: CancellationToken) => Promise<R>
    ) => void

    /**
     * Run a tool by name. This method will lookup the tool in the local tool repository and
     * validate the input against the tool's schema.
     *
     * Throws an error if the tool is not found, or if validation fails.
     *
     * @param toolName The name of the tool to run
     * @param input The input to the tool
     * @returns The result of the tool execution
     */
    runTool: (toolName: string, input: any, token?: CancellationToken) => Promise<any>

    /**
     * Get the list of tools in the local tool repository.
     * @param options Options for the format of the output. Can be either 'bedrock' or 'mcp' (the default)
     * @returns The tool repository in the requested output format
     */
    getTools: <T extends GetToolsOptions>(options?: T) => T extends { format: 'bedrock' } ? BedrockTools : Tools
}
```

一个典型的代理循环会是这样的:

```ts
const AgentServer: Server = ({ chat, agent }) => {

    agent.addTool({
        name: 'use_greeting',
        description: 'A kind greeting to the user'
        inputSchema: {
            type: 'object',
            parameters: {
                name: {
                    type: 'string'
                }
            }
        }
    }, async (input: { name: string }) => {
        return `hello, ${name}`
    })

    chat.onChatPrompt((params: ChatParams) => {
        let currentStep = 0;
        const maxSteps = 5; // Prevent infinite loops
        let finalResponse = '';
        const conversationHistory = [];

        while (currentStep < maxSteps) {
            const response = await invokeModel(conversationHistory, params.prompt.prompt, agent.getTools({format: 'bedrock'})) // or { format: 'mcp' }
            
            // Check if the response includes tool uses
            if (response.tool_use && response.tool_use.length > 0) {
                // Execute each tool use
                const toolResults = await Promise.all(
                    response.tool_use.map((toolUse) => ({
                        toolUseId: toolUse.Id,
                        content: await agent.runTool(toolUse.name, toolUse.input)
                    }))
                )

                // Ensure error handling and validation errors

                // You could also emit partial results here to keep the user informed of progress

                // Add tool results to conversation
                conversationHistory.push({
                    role: "tool",
                    content: JSON.stringify(toolResults)
                })

                // Continue the conversation with tool results
                userInput = `Tool execution results: ${JSON.stringify(toolResults)}. Please continue with the task.`
            } else {
                // No more tool calls needed, return final response
                finalResponse = response.content;
                break;
            }

            currentStep++
        }

        return {
            body: finalResponse
        }
    })

    // disposable
    return () => {
        // Do nothing
    }
}
```

## 运行时主机环境

服务器一般作为进程或网络工作人员运行. 下文详细介绍了如何初始化各类服务器运行时间.

### 服务器初始化流程和特性谈判

Language Server runtimes使用LSP摘要在客户端和服务器之间建立了JSON-RPC连接. 我们使用 `Initialize` LSP生命周期方法为服务器提供初始化选项.

特性将在执行时立即进行配置 `Initialize` 主连接的流量.

客户端会发送 `Initialize` LSP 请求, 带有自定义选项来配置可选特性 [`InitializeParams.initializationOptions`](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#initializeParams) 属性。 在此通过的配置将影响下文所定义的不同能力的执行细节. `initializationOptions` 可以通过运行时间处理,并根据其执行细节来初始化功能. 关于使用哪些选项的信息,请参见每个功能中的Initilization部分.

### 独立服务器

功能和模式可以在启动时通过命令行参数传递给服务器. 独立服务器的执行细节是,它可以从一个特殊的开始 `--set-credentials-encryption-key` 在启动主LSP连接之前输入特殊流程的参数,用于接受加密选项作为参数.

```
server-standalone.exe

# Server options
[--stdio] - uses stdio as the communication channel (https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#implementationConsiderations)
[--set-credentials-encryption-key] - signal to server to invoke a flow for accepting encryption key before starting main server initialisation.

[--version] - server returns its version

...
# We can define extra options, e.g. extra transport modes to provide compatibility with different clients are also possible.
[--pipe] - use pipes (Windows) or socket files (Linux, Mac) as the communication channel. The pipe / socket file name is passed as the next arg or with —pipe=.
[--socket] - uses a socket as the communication channel. The port is passed as next arg or with —port=.
[--node-ipc] - use node IPC communication between the client and the server. This is only supported if both client and server run under node.
```

服务器启动图 :

![Server startup flow diagram](https://npmcn.com/package/%40aws/language-server-runtimes/flow-diagram.png)

#### 加密

运行时支持以stdio作为传输方式通过LSP传输加密证书. 加密选项必须在 LSP 初始化开始前通过 stdin 发送到运行时间 。 目前,运行时间支持使用256位密钥进行AES对称加密.

以下步骤概述了如何启用加密证书:

1.  随机创建256位(32字节)加密密钥.
2.  通过 `--set-credentials-encryption-key` 命令行参数到启动时的服务器进程。 这将向服务器发出客户端想要启用加密的信号,并在接下来的5秒内等待加密选项.
3.  立刻派JSON来 `stdin` ,后面是新行 `/n` 字符,它将向运行时间显示传输结束。 如果LSP初始化继续,加密选项已被验证并保存. 如果客户端在前5秒未能发送加密选项,或者JSON对象无效,则进程会以状态代码10退出.

```json
{
    "version": "1.0",
    "key": "<base64 encoded encryption key>",
    "mode": "JWT"
}
```

4.  在LSP初始化完成后,目的地应当通过LSP发送证书并负责不断更新.

要发送加密的证书 `UpdateCredentialsPayload` 参数应发送到相应的 `aws/credentials/${type}/update` 方法.

`UpdateCredentialsPayload` 规格 :

1.  **\- 加密的**: 设置为 `true` · ;
2.  **\- 数据**: 代表加密的字符串值 [日本](https://www.rfc-editor.org/rfc/rfc7519) 符号 。 加密必须用 `{ alg: 'dir', enc: 'A256GCM' }` 参数。 被加密的有效载荷必须包含带有资质的数据字段.
3.  客户端可以设置 [nbf/ 实例](https://datatracker.ietf.org/doc/html/rfc7519#section-4.1.4) jWT 令牌上的债权,将在运行时验证。 A 类 `clockTolerance` 在核实索赔时,允许60秒.

```json
// JWT payload to be encrypted
{
   "data": <credentials>
}
```

### 网络工人

传统发展

## 警卫

见 [捐款](https://npmcn.com/package/%40aws/language-server-runtimes/CONTRIBUTING.md#security-issue-notifications) 更多信息.

## 许可证

这个项目根据Apache-2.0许可证获得许可证.

## 常见问题

### @aws/language-server-runtimes 是什么？

AWS 语言服务器主机运行时间

### 如何安装 @aws/language-server-runtimes？

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

### @aws/language-server-runtimes 支持 TypeScript 吗？

该包的 package\.json 没有声明类型入口。需要类型提示时，可以在 npm 上查找社区维护的 @types/aws\_\_language-server-runtimes 是否存在。

### @aws/language-server-runtimes 需要什么版本的 Node\.js？

package\.json 的 engines 字段要求 Node\.js \>=24\.0\.0。版本不符时 npm 默认只给出警告，开启 engine-strict 后会拒绝安装。

### @aws/language-server-runtimes 可以商用吗？

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

### @aws/language-server-runtimes 的下载量有多少？

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

### @aws/language-server-runtimes 还在维护吗？

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

