惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

aimingoo的专栏
aimingoo的专栏
WordPress大学
WordPress大学
阮一峰的网络日志
阮一峰的网络日志
博客园 - 司徒正美
月光博客
月光博客
宝玉的分享
宝玉的分享
Recent Announcements
Recent Announcements
小众软件
小众软件
H
Hackread – Cybersecurity News, Data Breaches, AI and More
美团技术团队
博客园 - 三生石上(FineUI控件)
A
About on SuperTechFans
J
Java Code Geeks
云风的 BLOG
云风的 BLOG
罗磊的独立博客
大猫的无限游戏
大猫的无限游戏
IT之家
IT之家
Vercel News
Vercel News
量子位
Martin Fowler
Martin Fowler
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
V
Visual Studio Blog
腾讯CDC
有赞技术团队
有赞技术团队

Recent Commits to openclaw:main

test: merge chat side-result checks · openclaw/openclaw@ddd2c2a test: merge cron history checks · openclaw/openclaw@f7eb746 test: merge responsive navigation shell checks · openclaw/openclaw@c2e4b47 docs(changelog): add codex oauth fixes · openclaw/openclaw@628e6cd test: merge navigation routing cases · openclaw/openclaw@5d8cecb Tests: mock channel registry bundled fallback · openclaw/openclaw@2b08233 Secrets: avoid broad web search discovery for single plugin config · openclaw/openclaw@a464f59 test: merge config view browser checks · openclaw/openclaw@20cf511 fix(status): align oauth health with runtime · openclaw/openclaw@eed7116 feat: add macOS screen snapshots for monitor preview (#67954) thanks … · openclaw/openclaw@f377db1 fix: report shared auth scopes in hello-ok (#67810) thanks @BunsDev · openclaw/openclaw@0b6c39b Auto-reply: avoid eager bundled route fallback · openclaw/openclaw@3ea1bf4 Tests: narrow session binding contract setup · openclaw/openclaw@54e4e16 fix(macOS): enable undo/redo in webchat composer text input (#34962) · openclaw/openclaw@00951dc Tests: speed up channel setup promotion · openclaw/openclaw@82b529a Docs: refresh agent instructions · openclaw/openclaw@5775fe2 fix(auth): serialize OAuth refresh across agents to fix #26322 (#67876) · openclaw/openclaw@8e79080 test: allow ollama public surface boundary test · openclaw/openclaw@7d4f1a6 Docs: add test performance guardrails · openclaw/openclaw@89706d3 Tests: restore context-engine usage proof · openclaw/openclaw@e4c4f95 Tests: slim context engine runtime coverage · openclaw/openclaw@74c198f ci: retry failed custom checkouts · openclaw/openclaw@0ee5baf test: trim duplicate provider auth onboarding cases · openclaw/openclaw@1ffc02e matrix: fix sessions_spawn --thread subagent session spawning (#67643) · openclaw/openclaw@1ce2596 test: reduce auth choice fixture churn · openclaw/openclaw@857b9cd test: mock health status config boundaries · openclaw/openclaw@9d5ab4a test: mock onboard config io boundary · openclaw/openclaw@299694d test: mock legacy state plugin boundaries · openclaw/openclaw@2713089 test: mock channel install boundaries · openclaw/openclaw@b945248 test: mock doctor preview channel boundaries · openclaw/openclaw@b1a3ad4
fix(github-copilot): preserve encrypted reasoning ids wit...
a410979729-s · 2026-04-25 · via Recent Commits to openclaw:main

@@ -1,21 +1,29 @@

11

import { streamOpenAIResponses, type AssistantMessage, type Model } from "@mariozechner/pi-ai";

22

import { buildCopilotDynamicHeaders } from "openclaw/plugin-sdk/provider-stream-shared";

33

import { describe, expect, it } from "vitest";

4+

import { resolveFirstGithubToken } from "./auth.js";

45

import { wrapCopilotOpenAIResponsesStream } from "./stream.js";

56

import { resolveCopilotApiToken } from "./token.js";

6778

const LIVE =

89

process.env.OPENCLAW_LIVE_TEST === "1" ||

910

process.env.LIVE === "1" ||

1011

process.env.GITHUB_COPILOT_LIVE_TEST === "1";

11-

const GITHUB_TOKEN =

12+

const ENV_GITHUB_TOKEN =

1213

process.env.OPENCLAW_LIVE_GITHUB_COPILOT_TOKEN ??

1314

process.env.COPILOT_GITHUB_TOKEN ??

1415

process.env.GH_TOKEN ??

1516

process.env.GITHUB_TOKEN ??

1617

"";

1718

const LIVE_MODEL_ID = process.env.OPENCLAW_LIVE_GITHUB_COPILOT_MODEL?.trim() || "gpt-5.4";

18-

const describeLive = LIVE && GITHUB_TOKEN.trim().length > 0 ? describe : describe.skip;

19+

const describeLive = LIVE ? describe : describe.skip;

20+21+

type CopilotApiToken = {

22+

token: string;

23+

expiresAt: number;

24+

source: string;

25+

baseUrl: string;

26+

};

19272028

const ZERO_USAGE = {

2129

input: 0,

@@ -99,6 +107,27 @@ function buildReplayAssistantMessage(connectionBoundId: string): AssistantMessag

99107

};

100108

}

101109110+

async function resolveGithubTokenCandidates(): Promise<Array<{ source: string; token: string }>> {

111+

const candidates: Array<{ source: string; token: string }> = [];

112+

const envToken = ENV_GITHUB_TOKEN.trim();

113+

if (envToken) {

114+

candidates.push({ source: "env", token: envToken });

115+

}

116+117+

const profileEnv = {

118+

...process.env,

119+

COPILOT_GITHUB_TOKEN: "",

120+

GH_TOKEN: "",

121+

GITHUB_TOKEN: "",

122+

};

123+

const profile = await resolveFirstGithubToken({ env: profileEnv });

124+

const profileToken = profile.githubToken.trim();

125+

if (profileToken && !candidates.some((candidate) => candidate.token === profileToken)) {

126+

candidates.push({ source: "auth-profile", token: profileToken });

127+

}

128+

return candidates;

129+

}

130+102131

function extractText(response: unknown): string {

103132

const content = (response as { content?: Array<{ type?: string; text?: string }> }).content;

104133

if (!Array.isArray(content)) {

@@ -114,22 +143,37 @@ function extractText(response: unknown): string {

114143

describeLive("github-copilot connection-bound Responses IDs live", () => {

115144

it("rewrites replayed connection-bound item IDs before sending to Copilot", async () => {

116145

logProgress("start");

117-

let token;

118-

try {

119-

logProgress("exchanging GitHub token for Copilot token");

120-

token = await withTimeout(

121-

"Copilot token exchange",

122-

resolveCopilotApiToken({

123-

githubToken: GITHUB_TOKEN,

124-

fetchImpl: fetchWithTimeout,

125-

}),

126-

15_000,

127-

);

128-

} catch (error) {

129-

logProgress(`skip (${error instanceof Error ? error.message : String(error)})`);

130-

return;

146+

const candidates = await resolveGithubTokenCandidates();

147+

if (candidates.length === 0) {

148+

throw new Error("No GitHub Copilot token found in env or auth profile");

149+

}

150+151+

let token: CopilotApiToken | undefined;

152+

const failures: string[] = [];

153+

for (const candidate of candidates) {

154+

try {

155+

logProgress(`exchanging ${candidate.source} GitHub token for Copilot token`);

156+

token = await withTimeout(

157+

"Copilot token exchange",

158+

resolveCopilotApiToken({

159+

githubToken: candidate.token,

160+

fetchImpl: fetchWithTimeout,

161+

}),

162+

15_000,

163+

);

164+

logProgress(

165+

`token ok via ${candidate.source} (${token.source.startsWith("cache:") ? "cache" : "fetched"})`,

166+

);

167+

break;

168+

} catch (error) {

169+

const message = error instanceof Error ? error.message : String(error);

170+

failures.push(`${candidate.source}: ${message}`);

171+

logProgress(`token exchange failed via ${candidate.source} (${message})`);

172+

}

173+

}

174+

if (!token) {

175+

throw new Error(`Copilot token exchange failed for all candidates: ${failures.join("; ")}`);

131176

}

132-

logProgress(`token ok (${token.source.startsWith("cache:") ? "cache" : "fetched"})`);

133177134178

const model = buildModel(token.baseUrl);

135179

const staleId = Buffer.from(`copilot-${"x".repeat(24)}`).toString("base64");