mirror of
https://github.com/langbot-app/LangBot.git
synced 2026-08-08 20:30:59 +00:00
e3832ca536
Co-authored-by: dadachann <185672915+dadachann@users.noreply.github.com>
21 lines
661 B
Python
21 lines
661 B
Python
from __future__ import annotations
|
|
|
|
import uuid
|
|
|
|
|
|
_INSTANCE_PREFIX = 'instance_'
|
|
_WORKSPACE_IDENTITY_NAMESPACE = uuid.UUID('8ea04f29-8528-4cc3-bb28-30a838c89d76')
|
|
|
|
|
|
def workspace_uuid_from_instance_id(instance_id: str) -> str:
|
|
"""Return the stable OSS Workspace UUID for a persisted instance identity."""
|
|
value = instance_id.strip()
|
|
if not value:
|
|
raise ValueError('LangBot instance identity is empty')
|
|
|
|
candidate = value[len(_INSTANCE_PREFIX) :] if value.startswith(_INSTANCE_PREFIX) else value
|
|
try:
|
|
return str(uuid.UUID(candidate))
|
|
except ValueError:
|
|
return str(uuid.uuid5(_WORKSPACE_IDENTITY_NAMESPACE, value))
|