-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add credentials api service to admin ui (#1074)
- adds api routes + credential api service - apis and services are namespaced to allow for reused code between agents, workflows, and threads
- Loading branch information
1 parent
9674669
commit a39f77d
Showing
4 changed files
with
76 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<EntityList<Credential>>({ | ||
url: ApiRoutes.credentials.getCredentialsForEntity(namespace, entityId) | ||
.url, | ||
}); | ||
|
||
return data.items ?? []; | ||
} | ||
getCredentials.key = ( | ||
namespace: CredentialNamespace, | ||
entityId?: Nullish<string> | ||
) => { | ||
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, | ||
}; |