(
options: EnrichMetadataOptions = {},
)
| 691 | * @returns Promise resolving to enriched metadata object |
| 692 | */ |
| 693 | export async function getEventMetadata( |
| 694 | options: EnrichMetadataOptions = {}, |
| 695 | ): Promise<EventMetadata> { |
| 696 | const model = options.model ? String(options.model) : getMainLoopModel() |
| 697 | const betas = |
| 698 | typeof options.betas === 'string' |
| 699 | ? options.betas |
| 700 | : getModelBetas(model).join(',') |
| 701 | const [envContext, repoRemoteHash] = await Promise.all([ |
| 702 | buildEnvContext(), |
| 703 | getRepoRemoteHash(), |
| 704 | ]) |
| 705 | const processMetrics = buildProcessMetrics() |
| 706 | |
| 707 | const metadata: EventMetadata = { |
| 708 | model, |
| 709 | sessionId: getSessionId(), |
| 710 | userType: process.env.USER_TYPE || '', |
| 711 | ...(betas.length > 0 ? { betas: betas } : {}), |
| 712 | envContext, |
| 713 | ...(process.env.CLAUDE_CODE_ENTRYPOINT && { |
| 714 | entrypoint: process.env.CLAUDE_CODE_ENTRYPOINT, |
| 715 | }), |
| 716 | ...(process.env.CLAUDE_AGENT_SDK_VERSION && { |
| 717 | agentSdkVersion: process.env.CLAUDE_AGENT_SDK_VERSION, |
| 718 | }), |
| 719 | isInteractive: String(getIsInteractive()), |
| 720 | clientType: getClientType(), |
| 721 | ...(processMetrics && { processMetrics }), |
| 722 | sweBenchRunId: process.env.SWE_BENCH_RUN_ID || '', |
| 723 | sweBenchInstanceId: process.env.SWE_BENCH_INSTANCE_ID || '', |
| 724 | sweBenchTaskId: process.env.SWE_BENCH_TASK_ID || '', |
| 725 | // Swarm/team agent identification |
| 726 | // Priority: AsyncLocalStorage context (subagents) > env vars (swarm teammates) |
| 727 | ...getAgentIdentification(), |
| 728 | // Subscription tier for DAU-by-tier analytics |
| 729 | ...(getSubscriptionType() && { |
| 730 | subscriptionType: getSubscriptionType()!, |
| 731 | }), |
| 732 | // Assistant mode tag — lives outside memoized buildEnvContext() because |
| 733 | // setKairosActive() runs at main.tsx:~1648, after the first event may |
| 734 | // have already fired and memoized the env. Read fresh per-event instead. |
| 735 | ...(feature('KAIROS') && getKairosActive() |
| 736 | ? { kairosActive: true as const } |
| 737 | : {}), |
| 738 | // Repo remote hash for joining with server-side repo bundle data |
| 739 | ...(repoRemoteHash && { rh: repoRemoteHash }), |
| 740 | } |
| 741 | |
| 742 | return metadata |
| 743 | } |
| 744 | |
| 745 | |
| 746 | /** |
no test coverage detected