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
31 lines · 814 BRaw
1import type { Args, 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 * @returns each post, as it was made
13 */
14export function firstPartySession(
15 on: On,
16 authorization: SessionAuthorization = BEARER,
17) {
18 const posts: Args<'http.fetch'>[] = []
19
20 on('session.id', () => ({ value: 'the-session' }))
21 on('session.model', () => ({ value: 'the-model' }))
22 on('session.authorize', () => ({ value: authorization }))
23
24 on('http.fetch', ($, e) => {
25 posts.push(e)
26
27 return { value: ACCEPTED }
28 })
29
30 return posts
31}