UNPKG

@juspay/neurolink

Version:

The pipe layer of an AI nervous system: one interface connecting provider neurons to your application, across three inference types — generate, stream and decide. `decide` returns typed, calibrated judgements from a non-generative model (~400ms, ~$0.00002

42 lines (41 loc) • 1.51 kB
/** * SessionIdentity — generates unique user_id / session_id values per account * so that Anthropic sees consistent "user" fingerprints even when requests are * spread across multiple accounts. * * The generated metadata matches Claude Code's shape: * {"device_id":"<64 hex>","account_uuid":"<uuid>","session_id":"<uuid>"} */ import { getOrCreateClaudeCodeIdentity, purgeExpiredClaudeCodeIdentities, } from "../../../auth/anthropicOAuth.js"; export function purgeExpiredSessions() { purgeExpiredClaudeCodeIdentities(); } export function createSessionIdentity() { return { name: "session-identity", order: 20, enabled: true, async transformRequest(ctx) { const accountId = ctx.account.id; const identity = getOrCreateClaudeCodeIdentity(accountId, { existingUserId: ctx.request.body.metadata?.user_id, }); const body = { ...ctx.request.body }; // Only set user_id if not already present — in passthrough mode, // oauthFetch.ts owns this field and sets it from the shared helper. if (!body.metadata?.user_id) { body.metadata = { ...body.metadata, user_id: identity.metadataUserId, }; } return { ...ctx, request: { ...ctx.request, body, }, }; }, }; }