mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-29 15:52:36 +01:00
fix(apps): show the selected ChatGPT workspace on permissions (#22023)
## Thinking Path > - Paperclip helps people manage AI agents and their access to external accounts. > - Apps permissions shows the provider account behind a saved AI connection. > - One OpenAI email can have both a personal workspace and a business workspace. > - The current page shows the email but does not show the selected ChatGPT workspace. > - This pull request reads the provider name for the saved workspace ID through the existing account identity endpoint. > - People can identify the account that their agents will use before they change its access. ## Linked Issues or Issue Description **What existing behavior does this improve?** The Connected account section on the Apps permissions page for OpenAI subscription connections. **Current behavior** The page shows the saved email. It cannot distinguish two ChatGPT workspaces that use that email. The account identity endpoint supports only Anthropic profiles. **Proposed behavior** Show the selected ChatGPT workspace name beside the email. Show Personal workspace when OpenAI returns the personal type without a name. Show an unavailable state when the provider cannot supply a name. **Reason and benefit** People must know which provider workspace an agent will use. Paperclip personal or shared access does not identify that workspace. **Breaking changes** None. The change uses the existing safe identity response and requires no database migration. No related open or closed pull request was found with `OpenAI workspace in:title`. This change improves the existing Connected Apps and AI Accounts items in ROADMAP.md. ## What Changed - Add a provider module for OpenAI's Codex accounts endpoint. Match the saved workspace ID in both supported response formats. Do not choose the first or default account. - Use the existing credential audience, company access, audit, timeout, and response-size controls. Keep provider IDs, bearer tokens, and other workspace names out of the response. - Enable the OpenAI subscription account lookup on Permissions. Keep the saved email and account controls when the lookup fails. Skip API keys and routed connections. - Add provider, UI, and authenticated route tests. Update the AI Connections documentation with the upstream protocol sources. ## Verification - Linux x64, Node v25.9.0, source checkout. Provider responses use test fixtures. - Red: the new provider and UI regression cases failed before the fix. The page did not show the workspace and the service returned unsupported. - Green: `pnpm exec vitest run server/src/services/ai-account-identity.test.ts ui/src/components/ai-connections/AiConnectionAccountDetails.test.tsx` — 41 tests passed. - Green: `pnpm exec vitest run server/src/__tests__/ai-connections.test.ts -t 'identity only for an authorized credential'` — 2 tests passed. These tests check both providers, company and audience denial, invalid grants, agent denial, provider denial, and revoked credentials. - `git diff --check` passed. - `pnpm verify` returned exit 2 because the documentation change requires broader CI coverage. No full local suite was run. Final-revision CI passed, as linked below. - The first preflight could not install because the existing lockfile omitted the server's PostHog dependency. A local install with `--no-frozen-lockfile` prepared dependencies. The lockfile was restored and is not part of this change. The route suite also needed the existing plugin SDK and Runner TypeScript builds before it could load; it passed after those builds. - No live OpenAI account lookup or staging deployment was performed. - Final head `47b0e10ee5707e6615ca56d518fbd0d03f0fb341`: [PR CI attempt 2](https://github.com/paperclipai/paperclip/actions/runs/44118848278) passed, including [typecheck](https://github.com/paperclipai/paperclip/actions/runs/44118848278/job/134175539941), [build](https://github.com/paperclipai/paperclip/actions/runs/44118848278/job/134175461467), [browser CI](https://github.com/paperclipai/paperclip/actions/runs/44118848278/job/134175467287), and [final verification](https://github.com/paperclipai/paperclip/actions/runs/44118848278/job/134185142615). Four jobs interrupted by runner shutdowns passed on retry. - [Greptile](https://github.com/paperclipai/paperclip/pull/22023#issuecomment-6953183751) and [Paperclip review](https://github.com/paperclipai/paperclip/pull/22023#issuecomment-6953104317): 5/5 on the same head, no findings or open review threads. ## Risks - The workspace lookup uses the same private provider endpoint as upstream Codex. Older credentials or provider changes can make names unavailable. The page keeps the saved email and account controls in that case. - The provider protocol stays in the OpenAI identity module. The connection service only selects the existing credential, and the UI consumes the existing normalized labels. ## Model Used OpenAI GPT-6 in Codex, with tool use and code execution. ## Checklist - [x] I have included a thinking path that traces from project context to this change - [x] I have specified the model used (with version and capability details) - [x] I have checked ROADMAP.md and confirmed this PR does not duplicate planned core work - [x] I have searched GitHub for duplicate or related PRs and linked them above - [x] I have either (a) linked existing issues with `Fixes: #` / `Closes #` / `Refs #` OR (b) described the issue in-PR following the relevant issue template - [x] I have not referenced internal/instance-local Paperclip issues or links (only public GitHub `#NNN` / `github.com/paperclipai/paperclip` URLs) - [x] My branch name describes the change (e.g. `docs/...`, `fix/...`) and contains no internal Paperclip ticket id or instance-derived details - [x] I have run tests locally and they pass - [x] I have added or updated tests where applicable - [x] I have updated relevant documentation to reflect my changes - [x] I have considered and documented any risks above - [x] All Paperclip CI gates are green - [x] Greptile is 5/5 with no open P2s, recommendations, or follow-ups - [x] I will address all Greptile and reviewer comments before requesting merge Co-authored-by: Paperclip <noreply@paperclip.ing>
This commit is contained in:
1 parent
7f1f0eef67
commit
9c776cdf39
8 files changed
+167
-23
No files matched your search
@@ -164,11 +164,22 @@ denying profile access; in that case the screen explains that Anthropic did not
|
||||
permit reading the account email. A profile denial does not mark a connected
|
||||
credential as disconnected.
|
||||
|
||||
OpenAI subscription connections also show the selected **ChatGPT workspace**.
|
||||
The lookup uses OpenAI's Codex accounts endpoint and matches the workspace ID
|
||||
saved with that connection. It does not select the first or default workspace,
|
||||
or infer a workspace from an email or Paperclip access. A personal workspace
|
||||
without a provider name shows **Personal workspace** only when OpenAI reports
|
||||
its type. Missing names, ambiguous matches, and denied lookups show an unavailable
|
||||
state while keeping the saved email and connection controls. API keys and routed
|
||||
connections do not use this lookup.
|
||||
The endpoint and response formats follow OpenAI's [Codex backend client](https://github.com/openai/codex/blob/58627e6feac9f69cbbb405d85f4f7343eca75a35/codex-rs/backend-client/src/client.rs#L525)
|
||||
and [account response types](https://github.com/openai/codex/blob/58627e6feac9f69cbbb405d85f4f7343eca75a35/codex-rs/backend-client/src/types.rs#L130).
|
||||
|
||||
`GET /api/companies/:companyId/ai-connections/:connectionId/identity?grantId=...`
|
||||
checks company membership, connection-management authority, and the selected
|
||||
credential's human audience before opening the credential. The response contains
|
||||
only safe account labels and bounded status messages. The Anthropic profile read
|
||||
has a 15-second headers/body deadline and no redirects. It runs separately from
|
||||
only safe account labels and bounded status messages. The provider profile reads
|
||||
have a 15-second headers/body deadline and no redirects. Each runs separately from
|
||||
the account/grants reads, so profile loading or failure cannot block account
|
||||
maintenance. The UI reuses an observation for five minutes, scoped to the company,
|
||||
connection, grant, and grant update time. Reconnect requires a new observation.
|
||||
|
||||
@@ -1556,11 +1556,14 @@ console.log(JSON.stringify({ type: "result", subtype: "success", result: "hello"
|
||||
} finally { fetchSpy.mockRestore(); }
|
||||
});
|
||||
|
||||
it("reads provider identity only for an authorized credential and preserves connected state when profile access is denied", async () => {
|
||||
const owner = "identity-owner";
|
||||
it.each(["anthropic", "openai"] as const)("reads %s identity only for an authorized credential and preserves connected state when profile access is denied", async provider => {
|
||||
const owner = `identity-owner-${provider}`;
|
||||
await db.insert(companyMemberships).values({ companyId, principalId: owner, principalType: "user", status: "active", membershipRole: "member" });
|
||||
const account = await service.save(companyId, owner, { provider: "anthropic", method: "subscription", ownership: "personal", name: "Identity account", loginSessionId: "fixture", agentIds: [], allAgents: true }, "identity-selected-secret");
|
||||
const fetchSpy = vi.spyOn(globalThis, "fetch").mockResolvedValue(Response.json({ account: { email: "avery@example.test", uuid: "private-account-id" }, organization: { name: "Example team", uuid: "private-org-id" } }));
|
||||
const credential = provider === "openai" ? JSON.stringify({ tokens: { access_token: "identity-selected-secret", account_id: "private-account-id" } }) : "identity-selected-secret";
|
||||
const account = await service.save(companyId, owner, { provider, method: "subscription", ownership: "personal", name: "Identity account", loginSessionId: "fixture", agentIds: [], allAgents: true }, credential);
|
||||
const profile = provider === "openai" ? { accounts: [{ id: "private-account-id", name: "Example team", structure: "workspace" }] }
|
||||
: { account: { email: "avery@example.test", uuid: "private-account-id" }, organization: { name: "Example team", uuid: "private-org-id" } };
|
||||
const fetchSpy = vi.spyOn(globalThis, "fetch").mockResolvedValue(Response.json(profile));
|
||||
const app = express();
|
||||
app.use((req, _res, next) => {
|
||||
req.actor = req.header("x-test-anonymous") ? { type: "none" }
|
||||
@@ -1575,8 +1578,8 @@ console.log(JSON.stringify({ type: "result", subtype: "success", result: "hello"
|
||||
const result = await request(app).get(url);
|
||||
expect(result.status).toBe(200);
|
||||
expect(result.headers["cache-control"]).toBe("no-store");
|
||||
expect(result.body).toMatchObject({ ...account, status: "available", accountLabel: "avery@example.test", organizationLabel: "Example team" });
|
||||
expect(fetchSpy).toHaveBeenCalledWith("https://api.anthropic.com/api/oauth/profile", expect.objectContaining({ headers: expect.objectContaining({ Authorization: "Bearer identity-selected-secret" }) }));
|
||||
expect(result.body).toMatchObject({ ...account, status: "available", accountLabel: provider === "openai" ? null : "avery@example.test", organizationLabel: "Example team" });
|
||||
expect(fetchSpy).toHaveBeenCalledWith(provider === "openai" ? "https://chatgpt.com/backend-api/wham/accounts/check" : "https://api.anthropic.com/api/oauth/profile", expect.objectContaining({ headers: expect.objectContaining({ Authorization: "Bearer identity-selected-secret" }) }));
|
||||
for (const value of ["identity-selected-secret", "private-account-id", "private-org-id"]) expect(JSON.stringify(result.body)).not.toContain(value);
|
||||
fetchSpy.mockReset();
|
||||
expect((await request(app).get(url).set("x-test-user", "bob")).status).toBe(404);
|
||||
|
||||
@@ -40,11 +40,71 @@ describe("AI account identity", () => {
|
||||
it("does not call a provider for API keys or other sign-in methods", async () => {
|
||||
const request = fixture({});
|
||||
expect((await probeAiAccountIdentity({ provider: "anthropic", method: "api_key" }, "", request)).errorCode).toBe("unsupported");
|
||||
expect((await probeAiAccountIdentity({ provider: "openai", method: "subscription" }, "", request)).errorCode).toBe("unsupported");
|
||||
expect((await probeAiAccountIdentity({ provider: "google", method: "subscription" }, "", request)).errorCode).toBe("unsupported");
|
||||
expect(request).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("aborts a stalled real response body while unrelated requests remain responsive", async () => {
|
||||
const openai = { provider: "openai", method: "subscription" } as const;
|
||||
const openaiCredential = JSON.stringify({ tokens: { access_token: "selected-openai-bearer", account_id: "selected-workspace" } });
|
||||
|
||||
it("reads the selected OpenAI workspace rather than the default or first workspace", async () => {
|
||||
const request = fixture({ default_account_id: "other-workspace", accounts: {
|
||||
"other-workspace": { account: { account_id: "other-workspace", name: "Other team", structure: "workspace" } },
|
||||
"selected-workspace": { account: { account_id: "selected-workspace", name: "Example business", structure: "workspace", private_field: "private-provider-data" } },
|
||||
} });
|
||||
const result = await probeAiAccountIdentity(openai, openaiCredential, request);
|
||||
expect(result).toMatchObject({ status: "available", organizationLabel: "Example business" });
|
||||
expect(request).toHaveBeenCalledWith("https://chatgpt.com/backend-api/wham/accounts/check", expect.objectContaining({
|
||||
redirect: "error", signal: expect.any(AbortSignal),
|
||||
headers: { Authorization: "Bearer selected-openai-bearer", "ChatGPT-Account-Id": "selected-workspace" },
|
||||
}));
|
||||
for (const value of ["selected-openai-bearer", "selected-workspace", "private-provider-data", "Other team"]) {
|
||||
expect(JSON.stringify(result)).not.toContain(value);
|
||||
}
|
||||
});
|
||||
|
||||
it("supports the provider's list response and legacy saved credentials", async () => {
|
||||
const result = await probeAiAccountIdentity(openai, JSON.stringify({ accessToken: "selected-openai-bearer", accountId: "selected-workspace" }),
|
||||
fixture({ accounts: [{ id: "selected-workspace", name: "Example business", structure: "workspace" }] }));
|
||||
expect(result).toMatchObject({ status: "available", organizationLabel: "Example business" });
|
||||
});
|
||||
|
||||
it("identifies a personal workspace when OpenAI supplies its type without a name", async () => {
|
||||
expect(await probeAiAccountIdentity(openai, openaiCredential, fixture({ accounts: {
|
||||
"selected-workspace": { account: { account_id: "selected-workspace", structure: "personal" } },
|
||||
} }))).toMatchObject({ status: "available", organizationLabel: "Personal workspace" });
|
||||
});
|
||||
|
||||
it.each([
|
||||
{},
|
||||
{ accounts: [{ id: "other-workspace", name: "Other team" }] },
|
||||
{ accounts: [{ id: "selected-workspace", name: "First" }, { id: "selected-workspace", name: "Second" }] },
|
||||
{ accounts: { "selected-workspace": { account: { account_id: "other-workspace", name: "Wrong team" } } } },
|
||||
{ accounts: [{ id: "selected-workspace", name: "Deactivated team", is_deactivated: true }] },
|
||||
{ accounts: [{ id: "selected-workspace", name: "Unsafe\nname" }] },
|
||||
{ accounts: [{ id: "selected-workspace", name: "x".repeat(255) }] },
|
||||
{ accounts: [{ id: "selected-workspace", structure: "workspace" }] },
|
||||
])("does not guess the OpenAI workspace from an incomplete or ambiguous response %j", async profile => {
|
||||
expect(await probeAiAccountIdentity(openai, openaiCredential, fixture(profile))).toMatchObject({
|
||||
status: "unavailable", errorCode: "invalid_response", organizationLabel: null,
|
||||
});
|
||||
});
|
||||
|
||||
it.each(["", "not-json", "{}", JSON.stringify({ tokens: { access_token: "bearer" } })])("does not make an unscoped OpenAI request for %s", async credential => {
|
||||
const request = fixture({});
|
||||
expect(await probeAiAccountIdentity(openai, credential, request)).toMatchObject({ status: "unavailable", errorCode: "authentication_required" });
|
||||
expect(request).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it.each([401, 403, 429, 500])("reports OpenAI HTTP %s without leaking details or naming another provider", async status => {
|
||||
const result = await probeAiAccountIdentity(openai, openaiCredential, fixture({ error: "private-provider-error" }, status));
|
||||
expect(result.status).toBe(status === 401 || status === 403 ? "unavailable" : "error");
|
||||
expect(result.organizationLabel).toBeNull();
|
||||
expect(result.message).not.toContain("Anthropic");
|
||||
expect(JSON.stringify(result)).not.toContain("private-provider-error");
|
||||
});
|
||||
|
||||
it.each([metadata, openai])("aborts a stalled $provider response body while unrelated requests remain responsive", async provider => {
|
||||
const server = createServer((req, res) => {
|
||||
if (req.url === "/profile") { res.writeHead(200, { "Content-Type": "application/json" }); res.flushHeaders(); }
|
||||
else res.end("responsive");
|
||||
@@ -57,7 +117,7 @@ describe("AI account identity", () => {
|
||||
const timeout = AbortSignal.timeout.bind(AbortSignal);
|
||||
const deadline = vi.spyOn(AbortSignal, "timeout").mockImplementation(() => timeout(100));
|
||||
try {
|
||||
const pending = probeAiAccountIdentity(metadata, "selected-credential", (_url, init) => fetch(`${origin}/profile`, init));
|
||||
const pending = probeAiAccountIdentity(provider, provider.provider === "openai" ? openaiCredential : "selected-credential", (_url, init) => fetch(`${origin}/profile`, init));
|
||||
expect(await (await fetch(`${origin}/unrelated`)).text()).toBe("responsive");
|
||||
const result = await pending;
|
||||
expect(result.status).toBe("error");
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import type { AiConnectionAccountIdentity, AiConnectionMetadata } from "@paperclipai/shared";
|
||||
import { readUsage } from "./ai-connection-usage.js";
|
||||
import { readOpenAiAccountIdentity } from "./openai-account-identity.js";
|
||||
|
||||
type Observation = Omit<AiConnectionAccountIdentity, "connectionId" | "grantId">;
|
||||
type FailureCode = NonNullable<Observation["errorCode"]>;
|
||||
@@ -23,10 +24,13 @@ export async function probeAiAccountIdentity(
|
||||
request: typeof fetch = fetch,
|
||||
): Promise<Observation> {
|
||||
const base = { checkedAt: new Date().toISOString(), accountLabel: null, organizationLabel: null };
|
||||
if (metadata.provider !== "anthropic" || metadata.method !== "subscription" || metadata.routing) {
|
||||
if (!["anthropic", "openai"].includes(metadata.provider) || metadata.method !== "subscription" || metadata.routing) {
|
||||
return { ...base, status: "unavailable", errorCode: "unsupported", message: messages.unsupported };
|
||||
}
|
||||
try {
|
||||
if (metadata.provider === "openai") {
|
||||
return { ...base, ...await readOpenAiAccountIdentity(credential, request) };
|
||||
}
|
||||
const profile = await readUsage("https://api.anthropic.com/api/oauth/profile", {
|
||||
Authorization: `Bearer ${credential}`, "anthropic-beta": "oauth-2025-04-20",
|
||||
}, request);
|
||||
@@ -38,6 +42,11 @@ export async function probeAiAccountIdentity(
|
||||
} catch (error) {
|
||||
const code = object(error).code;
|
||||
const errorCode: FailureCode = typeof code === "string" && Object.hasOwn(messages, code) ? code as FailureCode : "provider_unavailable";
|
||||
return { ...base, status: errorCode === "authentication_required" || errorCode === "permission_denied" ? "unavailable" : "error", errorCode, message: messages[errorCode] };
|
||||
const message = metadata.provider === "openai"
|
||||
? errorCode === "invalid_response" ? "OpenAI did not return the selected workspace name."
|
||||
: errorCode === "permission_denied" ? "OpenAI did not permit this connection to read the workspace name."
|
||||
: messages[errorCode].replace("Anthropic", "OpenAI")
|
||||
: messages[errorCode];
|
||||
return { ...base, status: errorCode === "authentication_required" || errorCode === "permission_denied" ? "unavailable" : "error", errorCode, message };
|
||||
}
|
||||
}
|
||||
@@ -263,7 +263,7 @@ export function aiConnectionService(db: Db) {
|
||||
errorCode: "connection_unavailable", message: "Reconnect or enable this connection to check its account details." };
|
||||
}
|
||||
// Unsupported methods must not open their credentials just to report this limit.
|
||||
const value = metadata.provider === "anthropic" && metadata.method === "subscription" && !metadata.routing
|
||||
const value = ["anthropic", "openai"].includes(metadata.provider) && metadata.method === "subscription" && !metadata.routing
|
||||
? await credential(row, 0, { actorType: "user", actorId: userId, ...audit, responsibleUserId: userId }) : "";
|
||||
return { ...identity, ...await probeAiAccountIdentity(metadata, value) };
|
||||
}
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
import type { AiConnectionAccountIdentity } from "@paperclipai/shared";
|
||||
import { readUsage } from "./ai-connection-usage.js";
|
||||
|
||||
const object = (value: unknown): Record<string, unknown> => value && typeof value === "object" && !Array.isArray(value) ? value as Record<string, unknown> : {};
|
||||
const label = (value: unknown): string | null => typeof value === "string" && value.trim().length > 0
|
||||
&& value.length <= 254 && !/[\u0000-\u001f\u007f]/.test(value) ? value.trim() : null;
|
||||
class AuthenticationRequired extends Error {
|
||||
readonly code = "authentication_required";
|
||||
constructor() { super("authentication_required"); }
|
||||
}
|
||||
|
||||
export async function readOpenAiAccountIdentity(
|
||||
credential: string,
|
||||
request: typeof fetch,
|
||||
): Promise<Pick<AiConnectionAccountIdentity, "status" | "accountLabel" | "organizationLabel" | "errorCode" | "message">> {
|
||||
let auth: Record<string, unknown>;
|
||||
try { auth = object(JSON.parse(credential)); }
|
||||
catch { throw new AuthenticationRequired(); }
|
||||
const tokens = object(auth.tokens);
|
||||
const accessToken = tokens.access_token ?? auth.accessToken;
|
||||
const accountId = label(tokens.account_id ?? auth.accountId);
|
||||
if (typeof accessToken !== "string" || !accessToken.trim() || accessToken.length > 32768
|
||||
|| /[\u0000-\u0020\u007f]/.test(accessToken) || !accountId) throw new AuthenticationRequired();
|
||||
|
||||
const profile = await readUsage("https://chatgpt.com/backend-api/wham/accounts/check", {
|
||||
Authorization: `Bearer ${accessToken}`, "ChatGPT-Account-Id": accountId,
|
||||
}, request);
|
||||
const accounts: Record<string, unknown>[] = Array.isArray(profile.accounts) ? profile.accounts.map(object)
|
||||
: Object.values(object(profile.accounts)).map(value => {
|
||||
const account = object(object(value).account);
|
||||
return { ...account, id: account.account_id };
|
||||
});
|
||||
const matches = accounts.filter(account => account.id === accountId);
|
||||
const selected = matches.length === 1 ? matches[0] : undefined;
|
||||
const organizationLabel = selected && selected.is_deactivated !== true
|
||||
? label(selected.name) ?? (selected.name == null && selected.structure === "personal" ? "Personal workspace" : null)
|
||||
: null;
|
||||
if (!organizationLabel) return { status: "unavailable", accountLabel: null, organizationLabel: null,
|
||||
errorCode: "invalid_response", message: "OpenAI did not return the selected workspace name." };
|
||||
return { status: "available", accountLabel: null, organizationLabel };
|
||||
}
|
||||
@@ -78,6 +78,25 @@ it("shows the provider email and organization separately from the Paperclip owne
|
||||
expect(identityCalls()[0][0]).toBe("/api/companies/company/ai-connections/connection/identity?grantId=grant");
|
||||
});
|
||||
|
||||
it.each(["Example business", "Personal workspace"])("shows the selected OpenAI workspace %s with the saved email", async workspace => {
|
||||
observation = { ...known, accountLabel: null, organizationLabel: workspace };
|
||||
await render({ ...account, provider: "openai", accountLabel: "avery@example.test" });
|
||||
expect(host.textContent).toContain("avery@example.test");
|
||||
expect(host.textContent).toContain(workspace);
|
||||
expect(host.textContent).toContain("ChatGPT workspace");
|
||||
expect(host.textContent).toContain("Personal · Sam");
|
||||
expect(identityCalls()).toHaveLength(1);
|
||||
});
|
||||
|
||||
it("explains an unavailable OpenAI workspace without guessing from the email or Paperclip access", async () => {
|
||||
observation = { ...known, status: "unavailable", accountLabel: null, organizationLabel: null,
|
||||
errorCode: "invalid_response", message: "OpenAI did not return the selected workspace name." };
|
||||
await render({ ...account, provider: "openai", accountLabel: "avery@example.test" });
|
||||
expect(host.textContent).toContain("avery@example.test");
|
||||
expect(host.textContent).toContain("ChatGPT workspaceNot available");
|
||||
expect(host.textContent).toContain("OpenAI did not return the selected workspace name.");
|
||||
});
|
||||
|
||||
it("explains profile permission denial while preserving connected account controls", async () => {
|
||||
observation = { ...known, status: "unavailable", accountLabel: null, organizationLabel: null, errorCode: "permission_denied", message: "Anthropic did not permit this connection to read the account email." };
|
||||
await render(account, grant, true);
|
||||
@@ -110,17 +129,17 @@ it("keeps maintenance controls visible during a stalled lookup and recovers only
|
||||
expect(fetchMock.mock.calls.length - identityCalls().length).toBe(ordinaryCalls);
|
||||
});
|
||||
|
||||
it("does not show the previous credential's identity after the selected grant changes", async () => {
|
||||
await render();
|
||||
it.each(["anthropic", "openai"] as const)("does not show the previous %s credential's identity after the selected grant changes", async provider => {
|
||||
await render({ ...account, provider });
|
||||
expect(host.textContent).toContain("avery@example.test");
|
||||
blocked = true;
|
||||
await render({ ...account, grantId: "other-grant" }, { ...grant, id: "other-grant" });
|
||||
await render({ ...account, provider, grantId: "other-grant" }, { ...grant, id: "other-grant" });
|
||||
expect(host.textContent).not.toContain("avery@example.test");
|
||||
expect(host.textContent).toContain("Checking account details…");
|
||||
});
|
||||
|
||||
it("uses saved labels for unsupported methods without opening an identity request", async () => {
|
||||
await render({ ...account, method: "api_key", accountLabel: "billing@example.test", ownership: "shared" });
|
||||
it.each(["anthropic", "openai"] as const)("uses saved labels for %s API keys without opening an identity request", async provider => {
|
||||
await render({ ...account, provider, method: "api_key", accountLabel: "billing@example.test", ownership: "shared" });
|
||||
expect(host.textContent).toContain("billing@example.test");
|
||||
expect(host.textContent).toContain("Company shared");
|
||||
expect(identityCalls()).toHaveLength(0);
|
||||
|
||||
@@ -11,7 +11,8 @@ export function AiConnectionAccountDetails({ account, grant }: {
|
||||
account: AiManagedConnectionSummary;
|
||||
grant: ConnectionGrant;
|
||||
}) {
|
||||
const canLookUp = account.provider === "anthropic" && account.method === "subscription" && account.status === "connected";
|
||||
const isChatGpt = account.provider === "openai" && account.method === "subscription" && !account.routing;
|
||||
const canLookUp = !account.routing && (account.provider === "anthropic" || isChatGpt) && account.method === "subscription" && account.status === "connected";
|
||||
const identity = useQuery({
|
||||
queryKey: ["ai-account-identity", account.companyId, account.id, grant.id, grant.updatedAt],
|
||||
queryFn: ({ signal }) => aiConnectionsApi.accountIdentity(account.companyId, account.id, grant.id, { signal }),
|
||||
@@ -28,9 +29,9 @@ export function AiConnectionAccountDetails({ account, grant }: {
|
||||
<dl className="grid grid-cols-2 gap-3 text-sm">
|
||||
<dt className="text-muted-foreground">{AI_PROVIDERS[account.provider].name} account</dt>
|
||||
<dd className="break-words">{accountLabel ?? "Not available"}</dd>
|
||||
{identity.data?.organizationLabel && <>
|
||||
<dt className="text-muted-foreground">Organization</dt>
|
||||
<dd className="break-words">{identity.data.organizationLabel}</dd>
|
||||
{(isChatGpt || identity.data?.organizationLabel) && <>
|
||||
<dt className="text-muted-foreground">{isChatGpt ? "ChatGPT workspace" : "Organization"}</dt>
|
||||
<dd className="break-words">{identity.data?.organizationLabel ?? (identity.isPending && canLookUp ? "Checking…" : "Not available")}</dd>
|
||||
</>}
|
||||
<dt className="text-muted-foreground">Sign-in method</dt>
|
||||
<dd>{aiMethodLabel(account.provider, account.method)}</dd>
|
||||
|
||||
Reference in new issue
Block a user