browser-credentials.ts 587 B

1234567891011121314151617
  1. import type { Context } from '@deepseek-ai/cordis'
  2. /** Provide an in-memory credential-record owner for a mounted Connection plugin. */
  3. export function provideBrowserCredentials(ctx: Context): void {
  4. const records = new Map<unknown, unknown>()
  5. ctx.provide('credentials', {
  6. async modifyRecord(
  7. key: unknown,
  8. mutate: (current: unknown) => Promise<unknown>,
  9. ): Promise<unknown> {
  10. const current = records.get(key)
  11. const next = await mutate(current)
  12. if (next !== undefined) records.set(key, next)
  13. return next ?? current
  14. },
  15. } as never)
  16. }