|
1 | 1 | // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. |
2 | 2 |
|
3 | 3 | import type { RequestInit, RequestInfo, BodyInit } from './internal/builtin-types'; |
4 | | -import type { HTTPMethod, PromiseOrValue, MergedRequestInit } from './internal/types'; |
| 4 | +import type { HTTPMethod, PromiseOrValue, MergedRequestInit, FinalizedRequestInit } from './internal/types'; |
5 | 5 | import { uuid4 } from './internal/utils/uuid'; |
6 | | -import { validatePositiveInteger, isAbsoluteURL, hasOwn } from './internal/utils/values'; |
| 6 | +import { validatePositiveInteger, isAbsoluteURL, safeJSON } from './internal/utils/values'; |
7 | 7 | import { sleep } from './internal/utils/sleep'; |
| 8 | +import { type Logger, type LogLevel, parseLogLevel } from './internal/utils/log'; |
| 9 | +export type { Logger, LogLevel } from './internal/utils/log'; |
8 | 10 | import { castToError, isAbortError } from './internal/errors'; |
9 | 11 | import type { APIResponseProps } from './internal/parse'; |
10 | 12 | import { getPlatformHeaders } from './internal/detect-platform'; |
@@ -126,48 +128,6 @@ import { |
126 | 128 | Usage, |
127 | 129 | } from './resources/messages/messages'; |
128 | 130 |
|
129 | | -const safeJSON = (text: string) => { |
130 | | - try { |
131 | | - return JSON.parse(text); |
132 | | - } catch (err) { |
133 | | - return undefined; |
134 | | - } |
135 | | -}; |
136 | | - |
137 | | -type LogFn = (message: string, ...rest: unknown[]) => void; |
138 | | -export type Logger = { |
139 | | - error: LogFn; |
140 | | - warn: LogFn; |
141 | | - info: LogFn; |
142 | | - debug: LogFn; |
143 | | -}; |
144 | | -export type LogLevel = 'off' | 'error' | 'warn' | 'info' | 'debug'; |
145 | | -const parseLogLevel = ( |
146 | | - maybeLevel: string | undefined, |
147 | | - sourceName: string, |
148 | | - client: BaseAnthropic, |
149 | | -): LogLevel | undefined => { |
150 | | - if (!maybeLevel) { |
151 | | - return undefined; |
152 | | - } |
153 | | - const levels: Record<LogLevel, true> = { |
154 | | - off: true, |
155 | | - error: true, |
156 | | - warn: true, |
157 | | - info: true, |
158 | | - debug: true, |
159 | | - }; |
160 | | - if (hasOwn(levels, maybeLevel)) { |
161 | | - return maybeLevel; |
162 | | - } |
163 | | - loggerFor(client).warn( |
164 | | - `${sourceName} was set to ${JSON.stringify(maybeLevel)}, expected one of ${JSON.stringify( |
165 | | - Object.keys(levels), |
166 | | - )}`, |
167 | | - ); |
168 | | - return undefined; |
169 | | -}; |
170 | | - |
171 | 131 | export interface ClientOptions { |
172 | 132 | /** |
173 | 133 | * Defaults to process.env['ANTHROPIC_API_KEY']. |
@@ -252,8 +212,6 @@ export interface ClientOptions { |
252 | 212 | logger?: Logger | undefined; |
253 | 213 | } |
254 | 214 |
|
255 | | -type FinalizedRequestInit = RequestInit & { headers: Headers }; |
256 | | - |
257 | 215 | export class BaseAnthropic { |
258 | 216 | apiKey: string | null; |
259 | 217 | authToken: string | null; |
|
0 commit comments