diff --git a/ui/admin/app/lib/model/credentials.ts b/ui/admin/app/lib/model/credentials.ts new file mode 100644 index 000000000..cc1ab03e7 --- /dev/null +++ b/ui/admin/app/lib/model/credentials.ts @@ -0,0 +1,14 @@ +export const CredentialNamespace = { + Threads: "threads", + Agents: "agents", + Workflows: "workflows", +} as const; +export type CredentialNamespace = + (typeof CredentialNamespace)[keyof typeof CredentialNamespace]; + +export type Credential = { + contextID: string; + name: string; + envVars: string[]; + expiresAt?: string; // date +}; diff --git a/ui/admin/app/lib/model/primitives.ts b/ui/admin/app/lib/model/primitives.ts index 498a51d9f..8b3e57c20 100644 --- a/ui/admin/app/lib/model/primitives.ts +++ b/ui/admin/app/lib/model/primitives.ts @@ -12,3 +12,5 @@ export type EntityMeta< metadata?: TMetadata; type?: string; }; + +export type EntityList = { items: Nullish }; diff --git a/ui/admin/app/lib/routers/apiRoutes.ts b/ui/admin/app/lib/routers/apiRoutes.ts index 389a6a1c3..9681921c1 100644 --- a/ui/admin/app/lib/routers/apiRoutes.ts +++ b/ui/admin/app/lib/routers/apiRoutes.ts @@ -1,6 +1,7 @@ import queryString from "query-string"; import { mutate } from "swr"; +import { CredentialNamespace } from "~/lib/model/credentials"; import { KnowledgeFileNamespace, KnowledgeSourceNamespace, @@ -167,6 +168,17 @@ export const ApiRoutes = { getEnv: (entityId: string) => buildUrl(`/agents/${entityId}/env`), updateEnv: (entityId: string) => buildUrl(`/agents/${entityId}/env`), }, + credentials: { + getCredentialsForEntity: ( + namespace: CredentialNamespace, + entityId: string + ) => buildUrl(`/${namespace}/${entityId}/credentials`), + deleteCredential: ( + namespace: CredentialNamespace, + entityId: string, + credentialId: string + ) => buildUrl(`/${namespace}/${entityId}/credentials/${credentialId}`), + }, threads: { base: () => buildUrl("/threads"), getById: (threadId: string) => buildUrl(`/threads/${threadId}`), diff --git a/ui/admin/app/lib/service/api/credentialApiService.ts b/ui/admin/app/lib/service/api/credentialApiService.ts new file mode 100644 index 000000000..a364ace8f --- /dev/null +++ b/ui/admin/app/lib/service/api/credentialApiService.ts @@ -0,0 +1,48 @@ +import { Credential, CredentialNamespace } from "~/lib/model/credentials"; +import { EntityList } from "~/lib/model/primitives"; +import { ApiRoutes } from "~/lib/routers/apiRoutes"; +import { request } from "~/lib/service/api/primitives"; + +async function getCredentials( + namespace: CredentialNamespace, + entityId: string +) { + const { data } = await request>({ + url: ApiRoutes.credentials.getCredentialsForEntity(namespace, entityId) + .url, + }); + + return data.items ?? []; +} +getCredentials.key = ( + namespace: CredentialNamespace, + entityId?: Nullish +) => { + if (!entityId) return null; + + return { + url: ApiRoutes.credentials.getCredentialsForEntity(namespace, entityId) + .path, + entityId, + namespace, + }; +}; + +async function deleteCredential( + namespace: CredentialNamespace, + entityId: string, + credentialId: string +) { + await request({ + url: ApiRoutes.credentials.deleteCredential( + namespace, + entityId, + credentialId + ).url, + }); +} + +export const CredentialApiService = { + getCredentials, + deleteCredential, +};