agentlang
Version:
The easiest way to build the most reliable AI agents - enterprise-grade teams of AI agents that collaborate with each other and humans
61 lines (47 loc) • 1.37 kB
text/typescript
import { AppConfig } from '../state.js';
// TODO: AdminUserId must be dynamically set based on auth-service-config and a valid admin-login
export const AdminUserId = '00000000-0000-0000-0000-000000000000';
export function isAuthEnabled(): boolean {
if (AppConfig?.auth?.enabled == true) {
return true;
} else {
return false;
}
}
export let InternalRbacEnabled = false;
export function isRbacEnabled(): boolean {
return InternalRbacEnabled || (isAuthEnabled() && AppConfig?.rbac?.enabled == true);
}
export async function callWithRbac(f: Function): Promise<void> {
const old = InternalRbacEnabled;
InternalRbacEnabled = true;
try {
await f();
} finally {
InternalRbacEnabled = old;
}
}
export type ActiveSessionInfo = {
sessionId: string;
userId: string;
};
export const AdminSession: ActiveSessionInfo = {
sessionId: crypto.randomUUID(),
userId: AdminUserId,
};
export const BypassSession = AdminSession;
export const NoSession: ActiveSessionInfo = {
sessionId: 'nil',
userId: 'nil',
};
export function isNoSession(sess: ActiveSessionInfo): boolean {
return sess == NoSession;
}
const LocalEnv = new Map<string, string>();
export function setLocalEnv(k: string, v: string): string {
LocalEnv.set(k, v);
return v;
}
export function getLocalEnv(k: string): string | undefined {
return LocalEnv.get(k);
}