Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
515 changes: 430 additions & 85 deletions apps/desktop/src/main/__tests__/runtime-host-oauth-ipc-main.test.ts

Large diffs are not rendered by default.

26 changes: 0 additions & 26 deletions apps/desktop/src/main/oauth-connection-identities.ts

This file was deleted.

37 changes: 34 additions & 3 deletions apps/desktop/src/main/runtime-host-account-connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,18 @@ export async function synchronizeRuntimeHostAccountConnection(
providerType,
);
if (!connection) throw new Error('Account Connection is missing');
return synchronizeRuntimeHostAccountConnectionById(client, connection.connectionId);
}

export async function synchronizeRuntimeHostAccountConnectionById(
client: RuntimeHostAccountConnectionClient,
connectionId: string,
): Promise<void> {
const connection = findRuntimeHostAccountConnectionById(
await client.loadConnectionCatalog(),
connectionId,
);
if (!connection) throw new Error('Account Connection is missing');
// Discovery is best effort. Selecting a default must not depend on it: a
// connection whose inventory came from the curated fallback still has usable
// models, and leaving `defaultTarget` empty makes every later operation that
Expand All @@ -117,7 +129,7 @@ export async function synchronizeRuntimeHostAccountConnection(
await client.fetchConnectionModels(connection.connectionId).catch(() => undefined);
const catalog = await client.loadConnectionCatalog();
if (catalog.defaultTarget !== null) return;
const updated = findRuntimeHostAccountConnection(catalog, providerType);
const updated = findRuntimeHostAccountConnectionById(catalog, connectionId);
const modelId = updated?.enabledModelIds[0];
if (!updated || !modelId) return;
const selected = await client.setDefaultConnectionTarget(catalog.revision, {
Expand Down Expand Up @@ -158,6 +170,18 @@ export async function disableRuntimeHostAccountConnection(
providerType,
);
if (!connection) return;
return disableRuntimeHostAccountConnectionById(client, connection.connectionId);
}

export async function disableRuntimeHostAccountConnectionById(
client: RuntimeHostAccountConnectionClient,
connectionId: string,
): Promise<void> {
const connection = findRuntimeHostAccountConnectionById(
await client.loadConnectionCatalog(),
connectionId,
);
if (!connection) return;
const credential = await client.queryCredential(runtimeHostAccountCredential(connection));
if (credential?.configured) {
const removed = await client.deleteCredential({
Expand All @@ -171,9 +195,9 @@ export async function disableRuntimeHostAccountConnection(
throw new Error(`Unable to remove account credential: ${removed.kind}`);
}
}
const latest = findRuntimeHostAccountConnection(
const latest = findRuntimeHostAccountConnectionById(
await client.loadConnectionCatalog(),
providerType,
connectionId,
);
if (!latest?.enabled) return;
const disabled = await client.updateConnection(
Expand All @@ -192,6 +216,13 @@ export function findRuntimeHostAccountConnection(
return catalog.connections.find((connection) => connection.providerType === providerType);
}

export function findRuntimeHostAccountConnectionById(
catalog: ConnectionCatalogSnapshot,
connectionId: string,
): ConnectionCatalogEntry | undefined {
return catalog.connections.find((connection) => connection.connectionId === connectionId);
}

export function runtimeHostAccountCredential(
connection: ConnectionCatalogEntry,
): CredentialLocator {
Expand Down
4 changes: 2 additions & 2 deletions apps/desktop/src/main/runtime-host-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -479,9 +479,9 @@ export class DesktopRuntimeHostClient {

startOAuthLogin(
attemptId: string,
connectionId: string,
target: OperationInput<"oauth.login.start">["target"],
): Promise<OperationOutput<"oauth.login.start">> {
return this.request("oauth.login.start", { attemptId, connectionId });
return this.request("oauth.login.start", { attemptId, target });
}

queryOAuthLogin(
Expand Down
Loading