@openhoo/hoopilot 1.2.0 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/codexx.js CHANGED
@@ -3,7 +3,7 @@ import {
3
3
  buildCodexxInvocation,
4
4
  main,
5
5
  verifyCodexxModel
6
- } from "./chunk-JU6F5L34.js";
6
+ } from "./chunk-6ALEIJJM.js";
7
7
  export {
8
8
  buildCodexxInvocation,
9
9
  main,
package/dist/index.d.ts CHANGED
@@ -51,6 +51,8 @@ declare class MetricsRegistry {
51
51
  * the shared upstream connection instead of draining it in the background.
52
52
  */
53
53
  declare function observeResponseUsage(response: Response, fallbackModel: string, onUsage: (model: string, usage: TokenUsage) => void, signal?: AbortSignal, onOutcome?: (extracted: boolean) => void): Response;
54
+ /** Extract and record token usage from an already-buffered response body. */
55
+ declare function recordResponseTextUsage(text: string, isSse: boolean, fallbackModel: string, onUsage: (model: string, usage: TokenUsage) => void, onOutcome?: (extracted: boolean) => void): void;
54
56
 
55
57
  type FetchLike = (input: string | URL | Request, init?: RequestInit) => Promise<Response>;
56
58
  interface Logger {
@@ -79,8 +81,8 @@ interface HoopilotLoggerOptions {
79
81
  base?: LogFields;
80
82
  colorize?: boolean;
81
83
  env?: NodeJS.ProcessEnv;
82
- format?: LogFormat | string;
83
- level?: LogLevel | string;
84
+ format?: LogFormat | (string & {});
85
+ level?: LogLevel | (string & {});
84
86
  stream?: {
85
87
  write(message: string): unknown;
86
88
  };
@@ -103,11 +105,11 @@ interface HoopilotServerOptions extends CopilotAuthOptions {
103
105
  apiKey?: string;
104
106
  host?: string;
105
107
  logger?: HoopilotLogger;
106
- logFormat?: LogFormat | string;
107
- logLevel?: LogLevel | string;
108
+ logFormat?: LogFormat | (string & {});
109
+ logLevel?: LogLevel | (string & {});
108
110
  metrics?: MetricsRegistry;
109
111
  port?: number;
110
- streamingProxyMode?: StreamingProxyMode | string;
112
+ streamingProxyMode?: StreamingProxyMode | (string & {});
111
113
  }
112
114
  interface StartedHoopilotServer {
113
115
  server: Bun.Server<undefined>;
@@ -193,10 +195,28 @@ interface GithubRateLimitSnapshot {
193
195
  retryAfterSeconds?: number;
194
196
  used?: number;
195
197
  }
198
+ /** Request-latency summary for one route, in milliseconds. */
199
+ interface RouteLatency {
200
+ avgMs: number;
201
+ count: number;
202
+ }
203
+ /**
204
+ * Aggregate request-latency summary derived from the duration histogram. `avgMs`
205
+ * is exact; the percentiles are estimated from the histogram buckets (Prometheus-
206
+ * style linear interpolation), so they are approximate.
207
+ */
208
+ interface LatencySnapshot {
209
+ avgMs: number;
210
+ byRoute: Record<string, RouteLatency>;
211
+ count: number;
212
+ p50Ms: number;
213
+ p95Ms: number;
214
+ }
196
215
  /** A point-in-time JSON view of the in-process metrics. */
197
216
  interface MetricsSnapshot {
198
217
  githubRateLimit: Record<string, GithubRateLimitSnapshot>;
199
218
  inFlight: number;
219
+ latency: LatencySnapshot;
200
220
  requests: {
201
221
  byRoute: Record<string, number>;
202
222
  byStatus: Record<string, number>;
@@ -221,6 +241,14 @@ interface MetricsSnapshot {
221
241
  };
222
242
  uptimeSeconds: number;
223
243
  }
244
+ /** JSON body returned by the proxy's `/v1/usage` route. */
245
+ interface UsageResponseBody {
246
+ copilot: CopilotUsage | null;
247
+ copilot_error?: string;
248
+ object: "usage";
249
+ proxy: MetricsSnapshot;
250
+ version: string;
251
+ }
224
252
 
225
253
  interface AnthropicStreamOptions {
226
254
  model: string;
@@ -234,6 +262,7 @@ declare function responsesResponseToAnthropicMessage(response: JsonObject, fallb
234
262
  declare function responsesStreamToAnthropicStream(stream: ReadableStream<Uint8Array>, options: AnthropicStreamOptions): ReadableStream<Uint8Array>;
235
263
  declare function estimateAnthropicMessageTokens(request: JsonObject): JsonObject;
236
264
 
265
+ declare const DEFAULT_COPILOT_API_BASE_URL = "https://api.githubcopilot.com";
237
266
  declare class CopilotAuthError extends Error {
238
267
  constructor(message: string);
239
268
  }
@@ -335,6 +364,9 @@ interface ResponseStreamOptions {
335
364
  model: string;
336
365
  responseId?: string;
337
366
  }
367
+ declare class OpenAICompatibilityError extends Error {
368
+ constructor(message: string);
369
+ }
338
370
  declare function responsesRequestToChatCompletion(request: JsonObject): JsonObject;
339
371
  declare function normalizeChatCompletionRequest(request: JsonObject): JsonObject;
340
372
  declare function completionsRequestToChatCompletion(request: JsonObject): JsonObject;
@@ -367,4 +399,4 @@ declare function extractTokenUsage(usage: unknown): TokenUsage | undefined;
367
399
  declare function createHoopilotHandler(options?: HoopilotServerOptions): (request: Request) => Promise<Response>;
368
400
  declare function startHoopilotServer(options?: HoopilotServerOptions): StartedHoopilotServer;
369
401
 
370
- export { AnthropicCompatibilityError, COPILOT_USAGE_API_VERSION, type CopilotAccess, CopilotAuth, CopilotAuthError, type CopilotAuthOptions, CopilotClient, type CopilotQuota, type CopilotUsage, DEFAULT_GITHUB_API_BASE_URL, DEFAULT_LOG_FORMAT, DEFAULT_LOG_LEVEL, DEFAULT_MODEL, type FetchLike, type GithubRateLimit, type GithubRateLimitSnapshot, type HoopilotLogger, type HoopilotLoggerOptions, type HoopilotServerOptions, type JsonObject, type LogFields, type LogFormat, type LogLevel, type LogMethod, type Logger, MetricsRegistry, type MetricsSnapshot, type ModelTokenTotals, PROMETHEUS_CONTENT_TYPE, type RequestObservation, type StartedHoopilotServer, type TokenUsage, anthropicMessagesToResponsesRequest, applyCopilotHeaders, applyGithubApiHeaders, authStorePath, chatCompletionToCompletion, chatCompletionToResponse, completionStreamFromChatStream, completionsRequestToChatCompletion, createHoopilotHandler, createHoopilotLogger, estimateAnthropicMessageTokens, extractTokenUsage, fallbackModels, githubCopilotDeviceLogin, noopLogger, normalizeChatCompletionRequest, normalizeCopilotUsage, normalizeModelsResponse, normalizeRequestedModel, observeResponseUsage, parseLogFormat, parseLogLevel, parseRateLimitHeaders, readStoredCopilotAuth, responsesCompactionResult, responsesRequestToChatCompletion, responsesResponseToAnthropicMessage, responsesStreamFromChatStream, responsesStreamToAnthropicStream, startHoopilotServer, writeStoredCopilotAuth };
402
+ export { AnthropicCompatibilityError, COPILOT_USAGE_API_VERSION, type CopilotAccess, CopilotAuth, CopilotAuthError, type CopilotAuthOptions, CopilotClient, type CopilotQuota, type CopilotUsage, DEFAULT_COPILOT_API_BASE_URL, DEFAULT_GITHUB_API_BASE_URL, DEFAULT_LOG_FORMAT, DEFAULT_LOG_LEVEL, DEFAULT_MODEL, type FetchLike, type GithubRateLimit, type GithubRateLimitSnapshot, type HoopilotLogger, type HoopilotLoggerOptions, type HoopilotServerOptions, type JsonObject, type LatencySnapshot, type LogFields, type LogFormat, type LogLevel, type LogMethod, type Logger, MetricsRegistry, type MetricsSnapshot, type ModelTokenTotals, OpenAICompatibilityError, PROMETHEUS_CONTENT_TYPE, type RequestObservation, type RouteLatency, type StartedHoopilotServer, type StreamingProxyMode, type TokenUsage, type UsageResponseBody, anthropicMessagesToResponsesRequest, applyCopilotHeaders, applyGithubApiHeaders, authStorePath, chatCompletionToCompletion, chatCompletionToResponse, completionStreamFromChatStream, completionsRequestToChatCompletion, createHoopilotHandler, createHoopilotLogger, estimateAnthropicMessageTokens, extractTokenUsage, fallbackModels, githubCopilotDeviceLogin, noopLogger, normalizeChatCompletionRequest, normalizeCopilotUsage, normalizeModelsResponse, normalizeRequestedModel, observeResponseUsage, parseLogFormat, parseLogLevel, parseRateLimitHeaders, readStoredCopilotAuth, recordResponseTextUsage, responsesCompactionResult, responsesRequestToChatCompletion, responsesResponseToAnthropicMessage, responsesStreamFromChatStream, responsesStreamToAnthropicStream, startHoopilotServer, writeStoredCopilotAuth };