@openhoo/hoopilot 2.1.5 → 2.1.7

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-4ZG5QEYJ.js";
6
+ } from "./chunk-2GLKVNAA.js";
7
7
  export {
8
8
  buildCodexxInvocation,
9
9
  main,
package/dist/index.d.ts CHANGED
@@ -12,7 +12,7 @@ declare class MetricsRegistry {
12
12
  now?: () => number;
13
13
  });
14
14
  /** Mark a request as started; pair with exactly one {@link observe}. */
15
- startRequest(): void;
15
+ startRequest(route?: string): void;
16
16
  /** Record a completed request and clear its in-flight slot. */
17
17
  observe(observation: RequestObservation): void;
18
18
  /**
@@ -35,24 +35,10 @@ declare class MetricsRegistry {
35
35
  */
36
36
  recordGithubRateLimit(rateLimit: GithubRateLimit | undefined): void;
37
37
  /** A JSON-friendly view of the current counters. */
38
- snapshot(now?: () => number): MetricsSnapshot;
38
+ snapshot(nowOrOptions?: (() => number) | MetricsSnapshotOptions): MetricsSnapshot;
39
39
  /** Render the Prometheus text exposition format (version 0.0.4). */
40
40
  renderPrometheus(now?: () => number): string;
41
41
  }
42
- /**
43
- * Wrap `response`'s body so the client receives unchanged bytes while the same
44
- * read pass extracts token usage. Returns a new Response carrying the observed
45
- * body and the original status/headers. Usage extraction never throws into the
46
- * client stream: a parse failure or an aborted client simply yields no usage.
47
- * When the body is absent the response is returned untouched.
48
- *
49
- * Pass the request's `signal` so a client disconnect cancels the observer
50
- * branch; combined with the runtime cancelling the client branch, that releases
51
- * the shared upstream connection instead of draining it in the background.
52
- */
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;
56
42
 
57
43
  type FetchLike = (input: string | URL | Request, init?: RequestInit) => Promise<Response>;
58
44
  interface Logger {
@@ -243,6 +229,12 @@ interface MetricsSnapshot {
243
229
  };
244
230
  uptimeSeconds: number;
245
231
  }
232
+ /** Options for deriving a JSON metrics snapshot without changing raw counters. */
233
+ interface MetricsSnapshotOptions {
234
+ excludeRoutes?: readonly string[];
235
+ excludeUpstreamPaths?: readonly string[];
236
+ now?: () => number;
237
+ }
246
238
  /** JSON body returned by the proxy's `/v1/usage` route. */
247
239
  interface UsageResponseBody {
248
240
  copilot: CopilotUsage | null;
@@ -252,18 +244,6 @@ interface UsageResponseBody {
252
244
  version: string;
253
245
  }
254
246
 
255
- interface AnthropicStreamOptions {
256
- model: string;
257
- messageId?: string;
258
- }
259
- declare class AnthropicCompatibilityError extends Error {
260
- constructor(message: string);
261
- }
262
- declare function anthropicMessagesToResponsesRequest(request: JsonObject): JsonObject;
263
- declare function responsesResponseToAnthropicMessage(response: JsonObject, fallbackModel: string): JsonObject;
264
- declare function responsesStreamToAnthropicStream(stream: ReadableStream<Uint8Array>, options: AnthropicStreamOptions): ReadableStream<Uint8Array>;
265
- declare function estimateAnthropicMessageTokens(request: JsonObject): JsonObject;
266
-
267
247
  declare const DEFAULT_COPILOT_API_BASE_URL = "https://api.githubcopilot.com";
268
248
  declare class CopilotAuthError extends Error {
269
249
  constructor(message: string);
@@ -339,6 +319,9 @@ declare class CopilotClient {
339
319
  */
340
320
  declare function normalizeCopilotUsage(body: unknown): CopilotUsage;
341
321
 
322
+ /** Default model Hoopilot uses when a client does not supply one. */
323
+ declare const DEFAULT_MODEL = "gpt-5.5";
324
+
342
325
  interface GithubCopilotDeviceLoginOptions {
343
326
  clientId?: string;
344
327
  domain?: string;
@@ -361,44 +344,7 @@ declare function createHoopilotLogger(options?: HoopilotLoggerOptions): Hoopilot
361
344
  declare function parseLogFormat(value: string | undefined): LogFormat;
362
345
  declare function parseLogLevel(value: string | undefined): LogLevel;
363
346
 
364
- declare const DEFAULT_MODEL = "gpt-4.1";
365
- interface ResponseStreamOptions {
366
- model: string;
367
- responseId?: string;
368
- }
369
- declare class OpenAICompatibilityError extends Error {
370
- constructor(message: string);
371
- }
372
- declare function responsesRequestToChatCompletion(request: JsonObject): JsonObject;
373
- declare function normalizeChatCompletionRequest(request: JsonObject): JsonObject;
374
- declare function completionsRequestToChatCompletion(request: JsonObject): JsonObject;
375
- declare function normalizeRequestedModel(model: unknown): string;
376
- declare function chatCompletionToResponse(completion: JsonObject, responseId?: string): JsonObject;
377
- /**
378
- * Reduce a Copilot `/responses` result into the `{ output }` document Codex's
379
- * remote-compaction client (`POST /responses/compact`) deserializes. Codex keeps
380
- * only assistant/user message items from `output` and discards everything else,
381
- * so a Responses `output` array passes through verbatim; when the upstream only
382
- * exposes `output_text` (or, for a stream it did not honor `stream: false` on,
383
- * `output_text` deltas) a single assistant message is synthesized instead. The
384
- * input may be a unary JSON body or an SSE stream, so both framings are handled.
385
- */
386
- declare function responsesCompactionResult(upstreamText: string, isSse: boolean): JsonObject;
387
- declare function chatCompletionToCompletion(completion: JsonObject): JsonObject;
388
- declare function completionStreamFromChatStream(chatStream: ReadableStream<Uint8Array>): ReadableStream<Uint8Array>;
389
- declare function normalizeModelsResponse(upstream: unknown): JsonObject;
390
- declare function fallbackModels(): Array<JsonObject>;
391
- declare function responsesStreamFromChatStream(chatStream: ReadableStream<Uint8Array>, options: ResponseStreamOptions): ReadableStream<Uint8Array>;
392
- /**
393
- * Normalize an upstream `usage` object into {@link TokenUsage}. Accepts both the
394
- * Chat Completions shape (`prompt_tokens`/`completion_tokens`) and the Responses
395
- * shape (`input_tokens`/`output_tokens`), and pulls nested reasoning/cached
396
- * details when present. Returns undefined when no token counts are available so
397
- * callers can distinguish "no usage reported" from "zero tokens".
398
- */
399
- declare function extractTokenUsage(usage: unknown): TokenUsage | undefined;
400
-
401
347
  declare function createHoopilotHandler(options?: HoopilotServerOptions): (request: Request) => Promise<Response>;
402
348
  declare function startHoopilotServer(options?: HoopilotServerOptions): StartedHoopilotServer;
403
349
 
404
- 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 };
350
+ export { 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, PROMETHEUS_CONTENT_TYPE, type RequestObservation, type RouteLatency, type StartedHoopilotServer, type StreamingProxyMode, type TokenUsage, type UsageResponseBody, applyCopilotHeaders, applyGithubApiHeaders, authStorePath, createHoopilotHandler, createHoopilotLogger, githubCopilotDeviceLogin, noopLogger, normalizeCopilotUsage, parseLogFormat, parseLogLevel, parseRateLimitHeaders, readStoredCopilotAuth, startHoopilotServer, writeStoredCopilotAuth };