File tree Expand file tree Collapse file tree 3 files changed +18
-4
lines changed Expand file tree Collapse file tree 3 files changed +18
-4
lines changed Original file line number Diff line number Diff line change @@ -961,14 +961,16 @@ export const ensurePresent = <T>(value: T | null | undefined): T => {
961
961
/**
962
962
* Read an environment variable.
963
963
*
964
+ * Trims beginning and trailing whitespace.
965
+ *
964
966
* Will return undefined if the environment variable doesn't exist or cannot be accessed.
965
967
*/
966
968
export const readEnv = ( env : string ) : string | undefined => {
967
969
if ( typeof process !== 'undefined' ) {
968
- return process . env ?. [ env ] ?? undefined ;
970
+ return process . env ?. [ env ] ?. trim ( ) ?? undefined ;
969
971
}
970
972
if ( typeof Deno !== 'undefined' ) {
971
- return Deno . env ?. get ?.( env ) ;
973
+ return Deno . env ?. get ?.( env ) ?. trim ( ) ;
972
974
}
973
975
return undefined ;
974
976
} ;
Original file line number Diff line number Diff line change @@ -104,7 +104,7 @@ export class Anthropic extends Core.APIClient {
104
104
apiKey,
105
105
authToken,
106
106
...opts ,
107
- baseURL : baseURL ?? `https://api.anthropic.com` ,
107
+ baseURL : baseURL || `https://api.anthropic.com` ,
108
108
} ;
109
109
110
110
super ( {
Original file line number Diff line number Diff line change @@ -140,7 +140,7 @@ describe('instantiate client', () => {
140
140
} ) ;
141
141
142
142
afterEach ( ( ) => {
143
- process . env [ 'SINK_BASE_URL ' ] = undefined ;
143
+ process . env [ 'ANTHROPIC_BASE_URL ' ] = undefined ;
144
144
} ) ;
145
145
146
146
test ( 'explicit option' , ( ) => {
@@ -153,6 +153,18 @@ describe('instantiate client', () => {
153
153
const client = new Anthropic ( { apiKey : 'my-anthropic-api-key' } ) ;
154
154
expect ( client . baseURL ) . toEqual ( 'https://example.com/from_env' ) ;
155
155
} ) ;
156
+
157
+ test ( 'empty env variable' , ( ) => {
158
+ process . env [ 'ANTHROPIC_BASE_URL' ] = '' ; // empty
159
+ const client = new Anthropic ( { apiKey : 'my-anthropic-api-key' } ) ;
160
+ expect ( client . baseURL ) . toEqual ( 'https://api.anthropic.com' ) ;
161
+ } ) ;
162
+
163
+ test ( 'blank env variable' , ( ) => {
164
+ process . env [ 'ANTHROPIC_BASE_URL' ] = ' ' ; // blank
165
+ const client = new Anthropic ( { apiKey : 'my-anthropic-api-key' } ) ;
166
+ expect ( client . baseURL ) . toEqual ( 'https://api.anthropic.com' ) ;
167
+ } ) ;
156
168
} ) ;
157
169
158
170
test ( 'maxRetries option is correctly set' , ( ) => {
You can’t perform that action at this time.
0 commit comments