File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -15,6 +15,7 @@ import {logger} from '../utils/core/logger.js';
1515import { addProxyToFetchOptions } from '../utils/core/proxyUtils.js' ;
1616import { saveUsageToFile } from '../utils/core/usageLogger.js' ;
1717import { isDevMode , getDevUserId } from '../utils/core/devMode.js' ;
18+ import { getVersionHeader } from '../utils/core/version.js' ;
1819
1920export interface AnthropicOptions {
2021 model : string ;
@@ -561,7 +562,7 @@ export async function* createStreamingAnthropicCompletion(
561562 'x-api-key' : config . apiKey ,
562563 Authorization : `Bearer ${ config . apiKey } ` ,
563564 'anthropic-version' : '2023-06-01' ,
564- 'x-snow' : 'true' ,
565+ 'x-snow' : getVersionHeader ( ) ,
565566 ...customHeaders ,
566567 } ;
567568
Original file line number Diff line number Diff line change @@ -17,6 +17,7 @@ import type {
1717} from './types.js' ;
1818import { addProxyToFetchOptions } from '../utils/core/proxyUtils.js' ;
1919import { saveUsageToFile } from '../utils/core/usageLogger.js' ;
20+ import { getVersionHeader } from '../utils/core/version.js' ;
2021
2122export type {
2223 ChatMessage ,
@@ -429,7 +430,7 @@ export async function* createStreamingChatCompletion(
429430 headers : {
430431 'Content-Type' : 'application/json' ,
431432 Authorization : `Bearer ${ config . apiKey } ` ,
432- 'x-snow' : 'true' ,
433+ 'x-snow' : getVersionHeader ( ) ,
433434 ...customHeaders ,
434435 } ,
435436 body : JSON . stringify ( requestBody ) ,
Original file line number Diff line number Diff line change 11import { loadCodebaseConfig } from '../utils/config/codebaseConfig.js' ;
22import { addProxyToFetchOptions } from '../utils/core/proxyUtils.js' ;
3+ import { getVersionHeader } from '../utils/core/version.js' ;
34
45export interface EmbeddingOptions {
56 model ?: string ;
@@ -101,7 +102,7 @@ export async function createEmbeddings(
101102 // Build headers - only include Authorization if API key is provided
102103 const headers : Record < string , string > = {
103104 'Content-Type' : 'application/json' ,
104- 'x-snow' : 'true' ,
105+ 'x-snow' : getVersionHeader ( ) ,
105106 } ;
106107 if ( apiKey ) {
107108 headers [ 'Authorization' ] = `Bearer ${ apiKey } ` ;
Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ import {
1111import type { ChatMessage , ChatCompletionTool , UsageInfo } from './types.js' ;
1212import { addProxyToFetchOptions } from '../utils/core/proxyUtils.js' ;
1313import { saveUsageToFile } from '../utils/core/usageLogger.js' ;
14+ import { getVersionHeader } from '../utils/core/version.js' ;
1415
1516export interface GeminiOptions {
1617 model : string ;
@@ -459,7 +460,7 @@ export async function* createStreamingGeminiCompletion(
459460 headers : {
460461 'Content-Type' : 'application/json' ,
461462 Authorization : `Bearer ${ config . apiKey } ` ,
462- 'x-snow' : 'true' ,
463+ 'x-snow' : getVersionHeader ( ) ,
463464 ...customHeaders ,
464465 } ,
465466 body : JSON . stringify ( requestBody ) ,
Original file line number Diff line number Diff line change @@ -16,6 +16,7 @@ import type {
1616} from './types.js' ;
1717import { addProxyToFetchOptions } from '../utils/core/proxyUtils.js' ;
1818import { saveUsageToFile } from '../utils/core/usageLogger.js' ;
19+ import { getVersionHeader } from '../utils/core/version.js' ;
1920export interface ResponseOptions {
2021 model : string ;
2122 messages : ChatMessage [ ] ;
@@ -488,7 +489,7 @@ export async function* createStreamingResponse(
488489 headers : {
489490 'Content-Type' : 'application/json' ,
490491 Authorization : `Bearer ${ config . apiKey } ` ,
491- 'x-snow' : 'true' ,
492+ 'x-snow' : getVersionHeader ( ) ,
492493 ...( options . prompt_cache_key && {
493494 conversation_id : options . prompt_cache_key ,
494495 session_id : options . prompt_cache_key ,
Original file line number Diff line number Diff line change 1+ import { readFileSync } from 'fs' ;
2+ import { join , dirname } from 'path' ;
3+ import { fileURLToPath } from 'url' ;
4+
5+ let cachedVersion : string = '' ;
6+
7+ /**
8+ * Get the current package version
9+ * Reads from package.json and caches the result
10+ * After bundling, all code is in bundle/cli.mjs, so we need to go up one level
11+ */
12+ export function getPackageVersion ( ) : string {
13+ if ( cachedVersion ) {
14+ return cachedVersion ;
15+ }
16+
17+ try {
18+ // In bundled code, __filename points to bundle/cli.mjs
19+ // So we need to go up one level to reach package.json
20+ const currentDir = dirname ( fileURLToPath ( import . meta. url ) ) ;
21+ const packageJsonPath = join ( currentDir , '../package.json' ) ;
22+ const packageJson = JSON . parse ( readFileSync ( packageJsonPath , 'utf-8' ) ) ;
23+ cachedVersion = packageJson . version || '1.0.0' ;
24+ return cachedVersion ;
25+ } catch ( error ) {
26+ // Fallback version if reading fails
27+ console . error ( 'Failed to read version from package.json:' , error ) ;
28+ cachedVersion = '1.0.0' ;
29+ return cachedVersion ;
30+ }
31+ }
32+
33+ /**
34+ * Get version header value for API requests
35+ * Returns version in format: v1.0.0
36+ */
37+ export function getVersionHeader ( ) : string {
38+ return `v${ getPackageVersion ( ) } ` ;
39+ }
You can’t perform that action at this time.
0 commit comments