A Connections page under Settings lists the organisation's forge connections: host, forge type, the reference to the credential (never its value), the external account it belongs to, and the operations each execution identity may perform through it. The chat agent's page registry names the page too.
49 lines
1.4 KiB
TypeScript
49 lines
1.4 KiB
TypeScript
/** The operations the runtime can perform through a connection. */
|
|
export const OPERATIONS = ["clone", "push", "pr"] as const;
|
|
|
|
/** One organisation-owned forge connection, as the document writes it. */
|
|
export interface Connection {
|
|
id: string;
|
|
name: string;
|
|
type: string;
|
|
host: string;
|
|
account: string;
|
|
token: { engine: string; key: string };
|
|
/** Permitted operations per execution identity ID. */
|
|
permits?: Record<string, string[]>;
|
|
}
|
|
|
|
/** permits renders the document's map as rows the page can edit. */
|
|
export const permits = (c: Connection): [string, string[]][] =>
|
|
Object.entries(c.permits ?? {});
|
|
|
|
export function addPermit(c: Connection): void {
|
|
c.permits ??= {};
|
|
c.permits[""] = ["clone"];
|
|
}
|
|
|
|
export function removePermit(c: Connection, id: string): void {
|
|
if (c.permits) delete c.permits[id];
|
|
}
|
|
|
|
// Renaming rebuilds the entry: the identity reference is the map key.
|
|
export function renamePermit(c: Connection, from: string, to: string): void {
|
|
if (!c.permits || from === to) return;
|
|
const operations = c.permits[from];
|
|
delete c.permits[from];
|
|
if (to) c.permits[to] = operations;
|
|
}
|
|
|
|
export function toggleOperation(
|
|
c: Connection,
|
|
id: string,
|
|
operation: string,
|
|
on: boolean,
|
|
): void {
|
|
const current = new Set(c.permits?.[id] ?? []);
|
|
if (on) current.add(operation);
|
|
else current.delete(operation);
|
|
c.permits ??= {};
|
|
c.permits[id] = OPERATIONS.filter((o) => current.has(o));
|
|
}
|