import { randomBytes } from 'node:crypto';
const ALPHABET = '0123456789abcdefghijklmnopqrstuvwxyz';
const ALPHABET_LEN = ALPHABET.length;
const MAX_UNIFORM_BYTE = Math.floor(256 / ALPHABET_LEN) * ALPHABET_LEN;
function generateId(prefix, length = 12) {
    let suffix = '';
    let remaining = length;
    while (remaining > 0) {
        const bytes = randomBytes(remaining + 8);
        for (const byte of bytes) {
            if (remaining <= 0)
                break;
            if (byte < MAX_UNIFORM_BYTE) {
                suffix += ALPHABET[byte % ALPHABET_LEN];
                remaining--;
            }
        }
    }
    return `${prefix}${suffix}`;
}
export function generateProjectId() {
    return generateId('prj_');
}
export function generateThreadId() {
    return generateId('thd_');
}
export function generateRunId() {
    return generateId('run_');
}
export function generateMessageId() {
    return generateId('msg_');
}
export function generateSessionId() {
    return generateId('ses_');
}
export function generateToolCallId() {
    return generateId('call_', 8);
}
export function generateActivityId() {
    return generateId('act_');
}
export function generateTaskId() {
    return generateId('task_');
}
export function generatePlanId() {
    return generateId('plan_');
}
export function generateKnowledgeBaseId() {
    return generateId('kb_');
}
export function generateDocumentId() {
    return generateId('doc_');
}
export function generateChunkId() {
    return generateId('chk_');
}
export function generateConnectorId() {
    return generateId('conn_');
}
export function generateConnectorInstanceId() {
    return generateId('ci_');
}
export function generateTenantId() {
    return generateId('tnt_');
}
export function generateCredentialId() {
    return generateId('cred_');
}
export function generateExecutionContextId() {
    return generateId('ectx_');
}
export function generateMCPServerId() {
    return generateId('mcp_');
}
export function generateMCPClientId() {
    return generateId('mcpc_');
}
export function generateMCPSessionId() {
    return generateId('mcps_');
}
export function generateEnvironmentId() {
    return generateId('env_');
}
export function generateCheckpointId() {
    return generateId('cp_');
}
export function generateAdvisoryId() {
    return generateId('adv_');
}
export function generateAdvisoryCallId() {
    return generateId('advc_');
}
export function generateEmergencySaveId() {
    return generateId('esave_');
}
export function generateMemoryId() {
    return generateId('mem_');
}
export function generatePluginId() {
    return generateId('plg_');
}
export function generateSandboxId() {
    return generateId('sbx_');
}
export function generateWorkspaceId() {
    return generateId('wsp_');
}
export function generateSubSessionId() {
    return generateId('sub_');
}
export function generateSummaryId() {
    return generateId('sum_');
}
export function generateHandoffId() {
    return generateId('hof_');
}
export function generateDeliverableId() {
    return generateId('del_');
}
function parseId(raw, prefix, typeName) {
    if (!raw.startsWith(prefix)) {
        throw new Error(`Invalid ${typeName}: expected "${prefix}" prefix, got "${raw}"`);
    }
    return raw;
}
export function parseProjectId(raw) {
    return parseId(raw, 'prj_', 'ProjectId');
}
export function parseRunId(raw) {
    return parseId(raw, 'run_', 'RunId');
}
export function parseConnectorInstanceId(raw) {
    return parseId(raw, 'ci_', 'ConnectorInstanceId');
}
export function parsePluginId(raw) {
    return parseId(raw, 'plg_', 'PluginId');
}
export function parseSandboxId(raw) {
    return parseId(raw, 'sbx_', 'SandboxId');
}
//# sourceMappingURL=id.js.map