何时设置客户端信息
当您的 SDK 应用程序对应于某个独立的产品、服务或集成,且其运行时活动应持续归因于该产品、服务或集成时,请设置客户端信息。
对于脚本、一次性工具和不代表独立应用程序的作业,请不要设置客户端信息。 然后,运行时保留其默认属性。
客户端信息有四个可选字符串字段。 设置你知道的字段并省略其余字段。 仅当至少有一个字段的值非空时,SDK 才会在 server.connect 握手中包含客户端信息。
| 领域 | Example | Meaning |
|---|---|---|
applicationName | "vscode" | 使用 SDK 的应用程序的名称 |
application | "1.124.2" | 使用 SDK 的应用程序版本 |
integrationName | "copilot-chat" | 使用 SDK 的扩展、插件或其他应用程序子部件的名称 |
integration | "0.54.0" | 该扩展、插件或应用程序子部件的版本 |
对于没有不同集成的独立应用程序,请仅设置应用程序字段。 例如,开发者门户可以将 applicationName 设为 "acme-developer-portal",并将 applicationVersion 设为 "2.4.0",同时将这两个集成字段保留为未设置。
SDK 在建立连接时发送客户端信息一次。 该身份在该连接的整个生命周期内有效。
配置客户端信息
创建客户端时传递客户端信息:
TypeScript
import { CopilotClient } from "@github/copilot-sdk";
const client = new CopilotClient({
clientInfo: {
applicationName: "vscode",
applicationVersion: "1.124.2",
integrationName: "copilot-chat",
integrationVersion: "0.54.0",
},
});
await client.start();
Python
from copilot import CopilotClient
client = CopilotClient(
client_info={
"application_name": "vscode",
"application_version": "1.124.2",
"integration_name": "copilot-chat",
"integration_version": "0.54.0",
},
)
await client.start()
Go
client := copilot.NewClient(&copilot.ClientOptions{
ClientInfo: &copilot.ClientInfo{
ApplicationName: "vscode",
ApplicationVersion: "1.124.2",
IntegrationName: "copilot-chat",
IntegrationVersion: "0.54.0",
},
})
if err := client.Start(ctx); err != nil {
return err
}
.NET
using GitHub.Copilot;
await using var client = new CopilotClient(new CopilotClientOptions
{
ClientInfo = new CopilotClientInfo
{
ApplicationName = "vscode",
ApplicationVersion = "1.124.2",
IntegrationName = "copilot-chat",
IntegrationVersion = "0.54.0",
},
});
await client.StartAsync();
Java
var options = new CopilotClientOptions()
.setClientInfo(new ClientInfo()
.setApplicationName("vscode")
.setApplicationVersion("1.124.2")
.setIntegrationName("copilot-chat")
.setIntegrationVersion("0.54.0"));
var client = new CopilotClient(options);
client.start().get();
Rust
use github_copilot_sdk::{Client, ClientInfo, ClientOptions};
let client = Client::start(
ClientOptions::new().with_client_info(
ClientInfo::new()
.with_application_name("vscode")
.with_application_version("1.124.2")
.with_integration_name("copilot-chat")
.with_integration_version("0.54.0"),
),
)
.await?;
备注
- 客户端信息仅供参考。 运行时可以忽略与预期格式不匹配的值,例如无效的版本字符串。
- 设置客户端信息会更改运行时对其遥测属性的方式。 它不会更改运行时记录的内容。
- 如果每个字段都未设置或为空,SDK 会从握手中省略客户端信息,运行时会保留其默认属性。