Skip to content

Add code agent hub#879

Draft
xingsy97 wants to merge 23 commits intomainfrom
chat/demo/copilot
Draft

Add code agent hub#879
xingsy97 wants to merge 23 commits intomainfrom
chat/demo/copilot

Conversation

@xingsy97
Copy link
Copy Markdown
Collaborator

@xingsy97 xingsy97 commented Apr 8, 2026

No description provided.

Comment thread sdk/webpubsub-chat-client/examples/code-agent-hub/web-server.js Fixed
Comment thread sdk/webpubsub-chat-client/examples/code-agent-hub/web-server.js Fixed
Comment on lines +352 to +363
app.get('/auth/login', (req, res) => {
if (!OAUTH_ENABLED) return res.status(404).json({ error: oauthUnavailableMessage() });
const state = crypto.randomBytes(16).toString('hex');
req.session.oauthState = state;
const params = new URLSearchParams({
client_id: GITHUB_CLIENT_ID,
redirect_uri: `${req.protocol}://${req.get('host')}/auth/callback`,
scope: 'read:user',
state,
});
res.redirect(`https://github.com/login/oauth/authorize?${params}`);
});
Comment on lines +366 to +404
app.get('/auth/callback', async (req, res) => {
if (!OAUTH_ENABLED) return res.status(404).json({ error: oauthUnavailableMessage() });
const { code, state } = req.query;
if (!code || !state || state !== req.session.oauthState) {
return res.status(400).send('Invalid OAuth callback. <a href="/">Go back</a>');
}
delete req.session.oauthState;
try {
// Exchange code for access token
const tokenRes = await fetch('https://github.com/login/oauth/access_token', {
method: 'POST',
headers: { 'Content-Type': 'application/json', Accept: 'application/json' },
body: JSON.stringify({
client_id: GITHUB_CLIENT_ID,
client_secret: GITHUB_CLIENT_SECRET,
code,
}),
});
const tokenData = await tokenRes.json();
if (tokenData.error) throw new Error(tokenData.error_description || tokenData.error);
// Fetch user profile
const userRes = await fetch('https://api.github.com/user', {
headers: { Authorization: `Bearer ${tokenData.access_token}`, Accept: 'application/json' },
});
if (!userRes.ok) throw new Error(`GitHub API error: ${userRes.status}`);
const user = await userRes.json();
req.session.user = {
id: String(user.id),
login: user.login,
name: user.name || user.login,
avatar: user.avatar_url,
};
console.log(`[Auth] GitHub login: ${user.login}`);
res.redirect('/');
} catch (err) {
console.error('[Auth] OAuth error:', err.message);
res.status(500).send(`Login failed: ${err.message}. <a href="/">Go back</a>`);
}
});
Comment thread sdk/webpubsub-chat-client/examples/code-agent-hub/web-server.js Fixed
Comment on lines +1287 to +1297
app.use(session({
secret: process.env.SESSION_SECRET || crypto.randomBytes(32).toString('hex'),
resave: false,
saveUninitialized: false,
cookie: {
secure: process.env.NODE_ENV === 'production',
httpOnly: true,
maxAge: 24 * 60 * 60 * 1000,
sameSite: 'lax',
},
}));
Comment thread sdk/webpubsub-chat-client/examples/code-agent-hub/web-server.js Fixed
Comment thread sdk/webpubsub-chat-client/examples/code-agent-hub/web-server.js Fixed
Comment thread sdk/webpubsub-chat-client/examples/code-agent-hub/web-server.js Fixed

async function runCommandOrThrow(command, args = []) {
const launch = resolveSpawnLaunch(command, args);
const child = spawn(launch.command, launch.args, { stdio: 'inherit', shell: false });
Comment on lines +329 to +333
const child = spawn(resolvedLaunch.command, resolvedLaunch.args, {
stdio: ['pipe', 'pipe', 'pipe'],
env: { ...process.env, ...(ACP_AGENTS[agentName]?.env || {}) },
shell: false,
});
@xingsy97 xingsy97 force-pushed the chat/demo/copilot branch from cf5072f to 0363b55 Compare April 13, 2026 09:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants