spacehub

surshar / claude-code

Claude Code is an agentic coding tool that lives in your terminal, understands your codebase, and helps you code faster by executing routine tasks, explaining complex code, and handling git workflows - all through natural language commands.

Built by Anthropic · github.com/anthropics

claude-code / mods / telemetry / tests / fixtures / first-party-session.ts
33 lines · 933 BRaw
1import type { Args, HttpResponse, On, SessionAuthorization } from 'claude-code'
2
3import { ACCEPTED } from './accepted.js'
4import { BEARER } from './bearer.js'
5
6/**
7 * Answers what the telemetry plugin reads of a session signed in first
8 * party, and keeps each post the ingest accepts.
9 *
10 * @param on the test's `on`
11 * @param authorization the credential the session holds
12 * @param answer what the ingest answers each post; accepted by default
13 * @returns each post, as it was made
14 */
15export function firstPartySession(
16 on: On,
17 authorization: SessionAuthorization = BEARER,
18 answer: HttpResponse = ACCEPTED,
19) {
20 const posts: Args<'http.fetch'>[] = []
21
22 on('session.id', () => ({ value: 'the-session' }))
23 on('session.model', () => ({ value: 'the-model' }))
24 on('session.authorize', () => ({ value: authorization }))
25
26 on('http.fetch', ($, e) => {
27 posts.push(e)
28
29 return { value: answer }
30 })
31
32 return posts
33}