Skip to content

Commit de3b55c

Browse files
alliscodeBen ThomasCopilot
authored
feat(hub): add Copilot connection administration (#232)
## Why Hub needs one deployment-level Copilot connection that administrators can verify and control without storing the operator's token. The rebuilt Hub retained the page but did not have real APIs, durable state, fresh authorization, or audit behavior behind it. ## What changes Administrators can inspect, connect, recheck, and disconnect Copilot through `/settings/copilot`. Each change requires explicit confirmation and fresh authorization through the current GitHub, Entra, or local session provider. Hub checks `REPLICA_COPILOT_TOKEN` through the Copilot SDK, stores only its digest and connection provenance, and rejects stale overlapping changes. Losing the connector's final effective administrator source disconnects the connection in the same authority transaction. No rebuilt Hub product feature consumes the connection yet. ## Storybook screenshots **Hub/Pages/Security/Copilot / Not Connected — dark theme, 1280×720** ![Copilot Not Connected story in dark theme](https://github.com/user-attachments/assets/36d110ef-2e0a-4889-a3eb-2d6fe5c43a14) **Hub/Pages/Security/Copilot / No Token — dark theme, 1280×720** ![Copilot No Token story in dark theme](https://github.com/user-attachments/assets/5a29493f-a785-4d89-bcd8-02b24c1ee2f1) **Hub/Pages/Security/Copilot / Connected — dark theme, 1280×720** ![Copilot Connected story in dark theme](https://github.com/user-attachments/assets/a718e3ae-0b02-4e17-8406-a4fbcffc02b1) **Hub/Pages/Security/Copilot / Refused — dark theme, 1280×720** ![Copilot Refused story in dark theme](https://github.com/user-attachments/assets/49ae21ab-f1e2-4b55-bc5d-58c2c7f4b88e) **Hub/Pages/Security/Copilot / Access Removed — dark theme, 1280×720** ![Copilot Access Removed story in dark theme](https://github.com/user-attachments/assets/49119d8b-38fa-403b-b620-75cbc22fb86b) ![Copilot connected settings on rebased candidate bc98a97](https://github.com/user-attachments/assets/e2f6e459-5978-4b40-b7a4-8a5daf7f533d) --------- Co-authored-by: Ben Thomas <bentho@Bens-MacBook-Pro.local> Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
1 parent a072eec commit de3b55c

78 files changed

Lines changed: 2336 additions & 658 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎hub/client/application/hub/copilot-connection-contracts/index.ts‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,28 @@ export const copilotConnectionStatusSchema = z
1717
verifiedAt: z.iso.datetime({ offset: true }).nullable(),
1818
})
1919
.strict()
20+
21+
export const copilotAuthorizationStartResponseSchema = z
22+
.object({
23+
authorizationId: z.uuid(),
24+
authorizationUrl: z.url({ protocol: /^https?$/ }),
25+
expiresAt: z.iso.datetime({ offset: true }),
26+
})
27+
.strict()
28+
29+
export const copilotAuthorizationResponseSchema = z
30+
.object({
31+
authorization: z
32+
.object({
33+
expiresAt: z.iso.datetime({ offset: true }),
34+
operation: z.enum(["CONNECT_COPILOT", "DISCONNECT_COPILOT"]),
35+
verifiedAt: z.iso.datetime({ offset: true }),
36+
})
37+
.strict(),
38+
})
39+
.strict()
40+
41+
export const copilotContinuationResponseSchema = z.union([
42+
z.object({ connectionId: z.uuid() }).strict(),
43+
z.object({ disconnected: z.literal(true) }).strict(),
44+
])
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { requestJson } from "../request-json"
2+
import { z } from "zod"
3+
4+
export function cancelCopilotAuthorization(request: Request, authorizationId: string) {
5+
return requestJson(
6+
new URL("/api/copilot-connection/authorizations/cancel", request.url),
7+
z.undefined(),
8+
{
9+
body: JSON.stringify({ authorizationId }),
10+
method: "POST",
11+
signal: request.signal,
12+
},
13+
)
14+
}

‎hub/client/application/hub/requests/change-copilot-connection/index.ts‎

Lines changed: 0 additions & 18 deletions
This file was deleted.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { copilotContinuationResponseSchema } from "@application/hub/copilot-connection-contracts"
2+
3+
import { requestJson } from "../request-json"
4+
5+
export function continueCopilotAuthorization(
6+
request: Request,
7+
input: {
8+
authorizationId: string
9+
operation: "CONNECT_COPILOT" | "DISCONNECT_COPILOT"
10+
},
11+
) {
12+
return requestJson(
13+
new URL("/api/copilot-connection/authorizations/continue", request.url),
14+
copilotContinuationResponseSchema,
15+
{
16+
body: JSON.stringify(input),
17+
method: "POST",
18+
signal: request.signal,
19+
},
20+
)
21+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { copilotAuthorizationResponseSchema } from "@application/hub/copilot-connection-contracts"
2+
3+
import { requestJson } from "../request-json"
4+
5+
export function getCopilotAuthorization(request: Request, authorizationId: string) {
6+
return requestJson(
7+
new URL(`/api/copilot-connection/authorizations/${authorizationId}`, request.url),
8+
copilotAuthorizationResponseSchema,
9+
{ signal: request.signal },
10+
)
11+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { copilotAuthorizationStartResponseSchema } from "@application/hub/copilot-connection-contracts"
2+
3+
import { requestJson } from "../request-json"
4+
5+
export function startCopilotAuthorization(
6+
request: Request,
7+
input: {
8+
confirmed: true
9+
operation: "CONNECT_COPILOT" | "DISCONNECT_COPILOT"
10+
},
11+
) {
12+
return requestJson(
13+
new URL("/api/copilot-connection/authorizations/start", request.url),
14+
copilotAuthorizationStartResponseSchema,
15+
{
16+
body: JSON.stringify(input),
17+
method: "POST",
18+
signal: request.signal,
19+
},
20+
)
21+
}

0 commit comments

Comments
 (0)