@howaboua/pi-durable-openai-responses 0.0.0-stage → 0.9.1
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/LICENSE +21 -0
- package/NOTICE +82 -0
- package/README.md +109 -2
- package/dist/cache-keepalive.d.ts +28 -0
- package/dist/completion.d.ts +15 -0
- package/dist/configuration-updates.d.ts +6 -0
- package/dist/constrained-sampling.d.ts +17 -0
- package/dist/index.d.ts +58 -0
- package/dist/index.js +6403 -0
- package/dist/lifecycle.d.ts +12 -0
- package/dist/lite-images.d.ts +14 -0
- package/dist/openai-codex/constants.d.ts +20 -0
- package/dist/openai-codex/continuation-diagnostics.d.ts +26 -0
- package/dist/openai-codex/daybreak.d.ts +7 -0
- package/dist/openai-codex/device-code.d.ts +21 -0
- package/dist/openai-codex/diagnostic-failure.d.ts +3 -0
- package/dist/openai-codex/errors.d.ts +14 -0
- package/dist/openai-codex/header-record.d.ts +1 -0
- package/dist/openai-codex/headers.d.ts +9 -0
- package/dist/openai-codex/model-catalog.d.ts +2 -0
- package/dist/openai-codex/node-runtime.d.ts +8 -0
- package/dist/openai-codex/oauth.d.ts +2 -0
- package/dist/openai-codex/recovery-budget.d.ts +37 -0
- package/dist/openai-codex/request-body.d.ts +5 -0
- package/dist/openai-codex/request-serialization.d.ts +6 -0
- package/dist/openai-codex/responses-lite-model.d.ts +6 -0
- package/dist/openai-codex/responses-lite-tools.d.ts +2 -0
- package/dist/openai-codex/responses-lite.d.ts +18 -0
- package/dist/openai-codex/session-continuity.d.ts +29 -0
- package/dist/openai-codex/sse-request.d.ts +4 -0
- package/dist/openai-codex/sse.d.ts +14 -0
- package/dist/openai-codex/stream-events.d.ts +23 -0
- package/dist/openai-codex/transport-recovery.d.ts +29 -0
- package/dist/openai-codex/transport-state.d.ts +28 -0
- package/dist/openai-codex/turn-state.d.ts +14 -0
- package/dist/openai-codex/types.d.ts +250 -0
- package/dist/openai-codex/usage.d.ts +12 -0
- package/dist/openai-codex/websocket-connection.d.ts +14 -0
- package/dist/openai-codex/websocket-continuation.d.ts +3 -0
- package/dist/openai-codex/websocket-parser.d.ts +3 -0
- package/dist/openai-codex/websocket-session-cache.d.ts +14 -0
- package/dist/openai-codex/websocket-stream.d.ts +16 -0
- package/dist/openai-codex/websocket.d.ts +4 -0
- package/dist/openai-codex/worker-websocket.d.ts +3 -0
- package/dist/openai-responses/compaction-v2-feature.d.ts +3 -0
- package/dist/openai-responses/message-history.d.ts +4 -0
- package/dist/openai-responses/native-items.d.ts +48 -0
- package/dist/openai-responses/oauth.d.ts +3 -0
- package/dist/openai-responses/remote-delivery-protocol.d.ts +10 -0
- package/dist/openai-responses/shared.d.ts +32 -0
- package/dist/openai-responses/signatures.d.ts +7 -0
- package/dist/openai-responses/stream.d.ts +5 -0
- package/dist/openai-responses/tool-history.d.ts +2 -0
- package/dist/preparation.d.ts +7 -0
- package/dist/prewarm.d.ts +13 -0
- package/dist/protocol.d.ts +10 -0
- package/package.json +43 -5
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { AssistantMessage } from "@earendil-works/pi-ai";
|
|
2
|
+
/** Owns cancellation and turn affinity independently of the physical socket cache. */
|
|
3
|
+
export declare function createRequestLifecycle(): {
|
|
4
|
+
assertAvailable: (sessionId: string | undefined) => void;
|
|
5
|
+
begin(sessionId: string | undefined, signal: AbortSignal | undefined): {
|
|
6
|
+
signal: AbortSignal;
|
|
7
|
+
turnState: import("./openai-codex/turn-state.ts").CodexTurnState;
|
|
8
|
+
finish(output?: AssistantMessage): void;
|
|
9
|
+
};
|
|
10
|
+
reset(sessionId: string, clear: () => void | Promise<void>): Promise<void>;
|
|
11
|
+
close(clear: () => void | Promise<void>): Promise<void>;
|
|
12
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
interface ResizeImageOptions {
|
|
2
|
+
maxWidth: number;
|
|
3
|
+
maxHeight: number;
|
|
4
|
+
maxBytes: number;
|
|
5
|
+
}
|
|
6
|
+
interface ResizedImage {
|
|
7
|
+
data: string;
|
|
8
|
+
mimeType: string;
|
|
9
|
+
width: number;
|
|
10
|
+
height: number;
|
|
11
|
+
}
|
|
12
|
+
/** Native, byte-only capability. No filesystem access or provider-specific image dependency. */
|
|
13
|
+
export declare function resizeImage(bytes: Uint8Array, mimeType: string, options: ResizeImageOptions, signal?: AbortSignal): Promise<ResizedImage | undefined>;
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export declare const DEFAULT_CODEX_BASE_URL = "https://chatgpt.com/backend-api";
|
|
2
|
+
export declare const JWT_CLAIM_PATH = "https://api.openai.com/auth";
|
|
3
|
+
export declare const DEFAULT_STREAM_MAX_RETRIES = 5;
|
|
4
|
+
export declare const MAX_STREAM_MAX_RETRIES = 100;
|
|
5
|
+
export declare const DEFAULT_STREAM_IDLE_TIMEOUT_MS = 300000;
|
|
6
|
+
export declare const DEFAULT_TRANSPORT_RECOVERY_BUDGET_MS = 300000;
|
|
7
|
+
export declare const MAX_WEBSOCKET_RECOVERY_RETRIES = 3;
|
|
8
|
+
export declare const INITIAL_STREAM_RETRY_DELAY_MS = 200;
|
|
9
|
+
export declare const DEFAULT_MAX_RETRY_DELAY_MS = 60000;
|
|
10
|
+
export declare const DEFAULT_OVERLOAD_INITIAL_RETRY_DELAY_MS = 30000;
|
|
11
|
+
export declare const DEFAULT_OVERLOAD_RETRY_DELAY_MS = 60000;
|
|
12
|
+
export declare const DEFAULT_OVERLOAD_RECOVERY_BUDGET_MS = 180000;
|
|
13
|
+
export declare const DEFAULT_RATE_LIMIT_RECOVERY_BUDGET_MS = 180000;
|
|
14
|
+
export declare const DEFAULT_SSE_HEADER_TIMEOUT_MS = 20000;
|
|
15
|
+
export declare const DEFAULT_WEBSOCKET_CONNECT_TIMEOUT_MS = 15000;
|
|
16
|
+
export declare const DEFAULT_WEBSOCKET_CLOSE_TIMEOUT_MS = 5000;
|
|
17
|
+
export declare const CODEX_RESPONSE_STATUSES: Set<string>;
|
|
18
|
+
export declare const OPENAI_BETA_RESPONSES_WEBSOCKETS = "responses_websockets=2026-02-06";
|
|
19
|
+
export declare const WEBSOCKET_MESSAGE_TOO_BIG_CLOSE_CODE = 1009;
|
|
20
|
+
export declare const OPENAI_PROMPT_CACHE_KEY_MAX_LENGTH = 64;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export declare const WEBSOCKET_REQUEST_CHANGE_REASONS: {
|
|
2
|
+
readonly model: "model_changed";
|
|
3
|
+
readonly instructions: "instructions_changed";
|
|
4
|
+
readonly tools: "tools_changed";
|
|
5
|
+
readonly tool_choice: "tool_choice_changed";
|
|
6
|
+
readonly parallel_tool_calls: "parallel_tool_calls_changed";
|
|
7
|
+
readonly reasoning: "reasoning_changed";
|
|
8
|
+
readonly store: "store_changed";
|
|
9
|
+
readonly stream: "stream_changed";
|
|
10
|
+
readonly include: "include_changed";
|
|
11
|
+
readonly service_tier: "service_tier_changed";
|
|
12
|
+
readonly prompt_cache_key: "prompt_cache_key_changed";
|
|
13
|
+
readonly text: "text_changed";
|
|
14
|
+
readonly temperature: "temperature_changed";
|
|
15
|
+
readonly access_programs: "access_programs_changed";
|
|
16
|
+
};
|
|
17
|
+
declare const WEBSOCKET_CONTINUATION_DECISIONS: readonly ["disabled", "no_session_cache_entry", "no_continuation", "body_mismatch", "input_shorter_than_baseline", "input_prefix_mismatch", "missing_previous_response_id", "delta", ...("access_programs_changed" | "include_changed" | "instructions_changed" | "model_changed" | "parallel_tool_calls_changed" | "prompt_cache_key_changed" | "reasoning_changed" | "service_tier_changed" | "store_changed" | "stream_changed" | "temperature_changed" | "text_changed" | "tool_choice_changed" | "tools_changed")[]];
|
|
18
|
+
export type WebSocketContinuationDecision = (typeof WEBSOCKET_CONTINUATION_DECISIONS)[number];
|
|
19
|
+
declare const RESPONSE_ITEM_TYPES: readonly ["additional_tools", "message", "agent_message", "reasoning", "local_shell_call", "function_call", "function_call_output", "custom_tool_call", "custom_tool_call_output", "tool_search_call", "tool_search_output", "web_search_call", "image_generation_call", "compaction", "context_compaction", "configuration_update", "compaction_trigger", "other", "none"];
|
|
20
|
+
type ResponseItemType = (typeof RESPONSE_ITEM_TYPES)[number];
|
|
21
|
+
export interface WebSocketContinuationMismatch {
|
|
22
|
+
previousItemType: ResponseItemType;
|
|
23
|
+
currentItemType: ResponseItemType;
|
|
24
|
+
}
|
|
25
|
+
export declare function continuationItemType(item: unknown): ResponseItemType;
|
|
26
|
+
export {};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Api, Model } from "@earendil-works/pi-ai";
|
|
2
|
+
import type { OpenAICodexStreamOptions, ResponsesBody } from "./types.ts";
|
|
3
|
+
/** One provider owns eligibility evidence. No credentials are retained in cache keys. */
|
|
4
|
+
export declare function createDaybreakAccessResolver(originator: string): {
|
|
5
|
+
clear(): void;
|
|
6
|
+
apply(model: Model<Api>, body: ResponsesBody, options: OpenAICodexStreamOptions, enabled: boolean): Promise<ResponsesBody>;
|
|
7
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export type OAuthDeviceCodePollResult<T> = {
|
|
2
|
+
status: "pending";
|
|
3
|
+
} | {
|
|
4
|
+
status: "slow_down";
|
|
5
|
+
intervalSeconds?: number;
|
|
6
|
+
} | {
|
|
7
|
+
status: "failed";
|
|
8
|
+
message: string;
|
|
9
|
+
} | {
|
|
10
|
+
status: "complete";
|
|
11
|
+
value: T;
|
|
12
|
+
};
|
|
13
|
+
type OAuthDeviceCodePollOptions<T> = {
|
|
14
|
+
intervalSeconds?: number;
|
|
15
|
+
expiresInSeconds?: number;
|
|
16
|
+
waitBeforeFirstPoll?: boolean;
|
|
17
|
+
poll: () => Promise<OAuthDeviceCodePollResult<T>>;
|
|
18
|
+
signal?: AbortSignal;
|
|
19
|
+
};
|
|
20
|
+
export declare function pollOAuthDeviceCodeFlow<T>(options: OAuthDeviceCodePollOptions<T>): Promise<T>;
|
|
21
|
+
export {};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { CodexDiagnosticsFailure, CodexDiagnosticsSink } from "./types.ts";
|
|
2
|
+
export declare function codexDiagnosticsFailure(error: unknown): CodexDiagnosticsFailure;
|
|
3
|
+
export declare function noThrowCodexDiagnosticsSink(sink: CodexDiagnosticsSink | undefined): CodexDiagnosticsSink | undefined;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { AssistantMessage } from "@earendil-works/pi-ai";
|
|
2
|
+
export declare class NonRetryableProviderError extends Error {
|
|
3
|
+
}
|
|
4
|
+
export declare function codexErrorMessage(code: string | undefined, message: string | undefined): string | undefined;
|
|
5
|
+
/** Capture server advice before reading the body or notifying response hooks. */
|
|
6
|
+
export declare function codexRetryAfterDeadline(headers: Headers): number | undefined;
|
|
7
|
+
export declare function isTerminalRateLimitError(errorText: string): boolean;
|
|
8
|
+
export declare function isRetryableStreamStatus(status: number): boolean;
|
|
9
|
+
export declare function createErrorMessage(message: AssistantMessage, error: unknown, aborted: boolean): AssistantMessage;
|
|
10
|
+
export declare function parseErrorResponse(response: Response, signal?: AbortSignal): Promise<{
|
|
11
|
+
message: string;
|
|
12
|
+
friendlyMessage?: string | undefined;
|
|
13
|
+
code?: string | undefined;
|
|
14
|
+
}>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function headersToRecord(headers: Headers): Record<string, string>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ResponsesBody } from "./types.ts";
|
|
2
|
+
export { headersToRecord } from "./header-record.ts";
|
|
3
|
+
type ProviderHeaders = Record<string, string | null>;
|
|
4
|
+
export declare function extractAccountId(token: string): string;
|
|
5
|
+
export declare function resolveCodexUrl(baseUrl: string | undefined): string;
|
|
6
|
+
export declare function resolveCodexWebSocketUrl(baseUrl: string | undefined): string;
|
|
7
|
+
export declare function createCodexRequestId(): string;
|
|
8
|
+
export declare function buildSSEHeaders(modelHeaders: Record<string, string> | undefined, additionalHeaders: ProviderHeaders | undefined, accountId: string, token: string, sessionId: string | undefined, responsesLite?: boolean, originator?: string, routingRequest?: Pick<ResponsesBody, "model" | "service_tier">): Headers;
|
|
9
|
+
export declare function buildWebSocketHeaders(modelHeaders: Record<string, string> | undefined, additionalHeaders: ProviderHeaders | undefined, accountId: string, token: string, requestId: string, originator?: string, routingRequest?: Pick<ResponsesBody, "model" | "service_tier">): Headers;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { NonRetryableProviderError } from "./errors.ts";
|
|
2
|
+
import type { OpenAICodexStreamOptions } from "./types.ts";
|
|
3
|
+
export declare function codexStreamMaxRetries(options: OpenAICodexStreamOptions | undefined): number;
|
|
4
|
+
export declare function retryAdviceRecoveryBudgetError(error: unknown): NonRetryableProviderError;
|
|
5
|
+
export declare class CodexRecoveryBudget {
|
|
6
|
+
private overloadRetryCount;
|
|
7
|
+
private adviceStartedAt;
|
|
8
|
+
private adviceController;
|
|
9
|
+
private adviceTimer;
|
|
10
|
+
private readonly callerSignal;
|
|
11
|
+
private readonly maxRetryDelayMs;
|
|
12
|
+
recoveryDeadlineAt: number | undefined;
|
|
13
|
+
recoveryController: AbortController | undefined;
|
|
14
|
+
private recoveryTimer;
|
|
15
|
+
constructor(callerSignal?: AbortSignal, maxRetryDelayMs?: number);
|
|
16
|
+
close(): void;
|
|
17
|
+
signal: () => {
|
|
18
|
+
signal: AbortSignal;
|
|
19
|
+
cleanup: () => void;
|
|
20
|
+
} | undefined;
|
|
21
|
+
start: (freshWindow?: boolean) => void;
|
|
22
|
+
deadlineError: () => NonRetryableProviderError;
|
|
23
|
+
private adviceExpired;
|
|
24
|
+
expired: () => boolean;
|
|
25
|
+
planRetry: (error: unknown, retryCount: number) => {
|
|
26
|
+
overload: boolean;
|
|
27
|
+
serverDirected: boolean;
|
|
28
|
+
adviceBudgetExhausted: boolean;
|
|
29
|
+
delayMs: number | undefined;
|
|
30
|
+
};
|
|
31
|
+
waitBeforeRetry: (error: unknown, retryCount: number, plan?: {
|
|
32
|
+
overload: boolean;
|
|
33
|
+
serverDirected: boolean;
|
|
34
|
+
adviceBudgetExhausted: boolean;
|
|
35
|
+
delayMs: number | undefined;
|
|
36
|
+
}, switchingOnExpiry?: boolean) => Promise<void>;
|
|
37
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { type Api, type Model, type TranscriptContext } from "@earendil-works/pi-ai";
|
|
2
|
+
import type { ResponsesMode } from "../protocol.ts";
|
|
3
|
+
import type { OpenAICodexStreamOptions, ResponsesBody } from "./types.ts";
|
|
4
|
+
export declare function resolveCodexTranscript<TApi extends Api>(model: Model<TApi>, context: TranscriptContext): TranscriptContext;
|
|
5
|
+
export declare function buildRequestBody<TApi extends Api>(model: Model<TApi>, context: TranscriptContext, options?: OpenAICodexStreamOptions, mode?: ResponsesMode): ResponsesBody;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export declare const RESPONSES_LITE_HEADER = "x-openai-internal-codex-responses-lite";
|
|
2
|
+
export interface ResponsesLiteCompatibleBody {
|
|
3
|
+
model: string;
|
|
4
|
+
input: unknown[];
|
|
5
|
+
instructions?: string | undefined;
|
|
6
|
+
tools?: unknown[] | undefined;
|
|
7
|
+
parallel_tool_calls?: boolean | undefined;
|
|
8
|
+
reasoning?: unknown | undefined;
|
|
9
|
+
client_metadata?: Record<string, string> | undefined;
|
|
10
|
+
[key: string]: unknown;
|
|
11
|
+
}
|
|
12
|
+
export declare function isResponsesLiteRequest(body: ResponsesLiteCompatibleBody): boolean;
|
|
13
|
+
export declare function prepareResponsesLiteRequestImages<TBody extends ResponsesLiteCompatibleBody>(body: TBody, signal?: AbortSignal): Promise<TBody>;
|
|
14
|
+
export declare function applyResponsesLiteRequest<TBody extends ResponsesLiteCompatibleBody>(body: TBody): TBody;
|
|
15
|
+
export declare function namespaceExistingResponsesLiteRequest<TBody extends ResponsesLiteCompatibleBody>(body: TBody): TBody;
|
|
16
|
+
export declare function applyResponsesLiteWebSocketMetadata<TBody extends ResponsesLiteCompatibleBody>(body: TBody): TBody & {
|
|
17
|
+
client_metadata: Record<string, string>;
|
|
18
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { CodexTransportState } from "./transport-state.ts";
|
|
2
|
+
import type { CanonicalHistoryDecision, CodexCompactionReplayDecision, ResponsesBody } from "./types.ts";
|
|
3
|
+
export type CanonicalSessionToken = {
|
|
4
|
+
laneIdentity: symbol;
|
|
5
|
+
requestSequence: number;
|
|
6
|
+
};
|
|
7
|
+
export declare function recordCanonicalSessionResponse(transportState: CodexTransportState, args: {
|
|
8
|
+
sessionId?: string | undefined;
|
|
9
|
+
url: string;
|
|
10
|
+
accountId: string;
|
|
11
|
+
requestBody: ResponsesBody;
|
|
12
|
+
reconstructedRequestBody?: ResponsesBody | undefined;
|
|
13
|
+
responseItems: readonly unknown[];
|
|
14
|
+
token?: CanonicalSessionToken | undefined;
|
|
15
|
+
}): void;
|
|
16
|
+
export declare function captureCanonicalSessionToken(transportState: CodexTransportState, sessionId: string | undefined): CanonicalSessionToken | undefined;
|
|
17
|
+
export declare function validateCanonicalSessionRequest(transportState: CodexTransportState, sessionId: string | undefined, url: string, accountId: string, preparedBody: ResponsesBody): CanonicalHistoryDecision | undefined;
|
|
18
|
+
export declare function resolveCanonicalCompactionPromptInput(transportState: CodexTransportState, sessionId: string, model: string, identity?: {
|
|
19
|
+
url: string;
|
|
20
|
+
accountId: string;
|
|
21
|
+
} | undefined, reconstructedInput?: readonly unknown[] | undefined): {
|
|
22
|
+
input?: unknown[] | undefined;
|
|
23
|
+
decision: CodexCompactionReplayDecision;
|
|
24
|
+
};
|
|
25
|
+
export declare function canonicalCompactionRequestBody(transportState: CodexTransportState, sessionId: string, model: string, identity: {
|
|
26
|
+
url: string;
|
|
27
|
+
accountId: string;
|
|
28
|
+
}): ResponsesBody | undefined;
|
|
29
|
+
export declare function clearCanonicalSessions(transportState: CodexTransportState, sessionId?: string): void;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { Api, Model } from "@earendil-works/pi-ai";
|
|
2
|
+
import { type CodexTurnState } from "./turn-state.ts";
|
|
3
|
+
import type { OpenAICodexStreamOptions } from "./types.ts";
|
|
4
|
+
export declare function openCodexSSE<TApi extends Api>(model: Model<TApi>, body: string | Uint8Array, baseHeaders: Headers, options: OpenAICodexStreamOptions | undefined, turnState: CodexTurnState | undefined, onRetryableResponse: () => AbortSignal | undefined): Promise<Response>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { StreamEventShape } from "./types.ts";
|
|
2
|
+
export declare function compressRequestBodyZstd(bodyJson: string): Uint8Array | null;
|
|
3
|
+
export declare function sleep(ms: number, signal: AbortSignal | undefined): Promise<void>;
|
|
4
|
+
export declare function normalizeTimeoutMs(value: number | undefined, optionName: string): number | undefined;
|
|
5
|
+
export declare function combineAbortSignals(signals: Array<AbortSignal | undefined>): {
|
|
6
|
+
signal: AbortSignal;
|
|
7
|
+
cleanup: () => void;
|
|
8
|
+
};
|
|
9
|
+
export declare function createSSEHeaderTimeout(timeoutMs: number): {
|
|
10
|
+
signal: AbortSignal;
|
|
11
|
+
clear: () => void;
|
|
12
|
+
error: () => Error | undefined;
|
|
13
|
+
};
|
|
14
|
+
export declare function parseSSE(response: Response, signal?: AbortSignal, idleTimeoutMs?: number): AsyncIterable<StreamEventShape>;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { Api, AssistantMessage, AssistantMessageEventStream, Model } from "@earendil-works/pi-ai";
|
|
2
|
+
import type { OpenAICodexStreamOptions, StreamEventShape } from "./types.ts";
|
|
3
|
+
export declare class CodexProtocolError extends Error {
|
|
4
|
+
constructor(message: string, options?: {
|
|
5
|
+
cause?: unknown;
|
|
6
|
+
});
|
|
7
|
+
}
|
|
8
|
+
/** A completed generation must not be replayed to recover a host observer. */
|
|
9
|
+
export declare function runCodexCompletionObserver(kind: "output item" | "usage" | "completion", observe: () => void | Promise<void>): Promise<void>;
|
|
10
|
+
export declare function isRetryableCodexStreamError(error: unknown): boolean;
|
|
11
|
+
export declare function isCodexApiError(error: unknown): boolean;
|
|
12
|
+
export declare function codexStreamRetryDelay(error: unknown): number | undefined;
|
|
13
|
+
export declare function createCodexHttpError(message: string, code: string | undefined, status: number, retryAfter?: number): Error;
|
|
14
|
+
export declare function isCodexOverloadError(error: unknown): boolean;
|
|
15
|
+
export declare function isCodexRateLimitError(error: unknown): boolean;
|
|
16
|
+
export declare function codexOverloadRetryDelay(error: unknown, retryCount: number, waitedMs: number): number | undefined;
|
|
17
|
+
export declare function assertSuccessfulCodexOutput(output: AssistantMessage): asserts output is AssistantMessage & {
|
|
18
|
+
stopReason: "stop" | "length" | "toolUse";
|
|
19
|
+
};
|
|
20
|
+
export declare function assertSuccessfulCodexStatus(status: string | undefined): asserts status is "completed";
|
|
21
|
+
export declare function mapCodexEvents(events: AsyncIterable<StreamEventShape>, output?: AssistantMessage, onProviderStreamEvent?: (event: StreamEventShape) => void | Promise<void>): AsyncIterable<StreamEventShape>;
|
|
22
|
+
export declare function processMappedCodexResponsesStream<TApi extends Api>(events: AsyncIterable<StreamEventShape>, output: AssistantMessage, stream: AssistantMessageEventStream, model: Model<TApi>, options: OpenAICodexStreamOptions | undefined): Promise<void>;
|
|
23
|
+
export declare function processCodexResponsesStream<TApi extends Api>(events: AsyncIterable<StreamEventShape>, output: AssistantMessage, stream: AssistantMessageEventStream, model: Model<TApi>, options: OpenAICodexStreamOptions | undefined): Promise<void>;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { type Api, type AssistantMessage, type AssistantMessageEventStream, type Model, type TranscriptContext, type Transport } from "@earendil-works/pi-ai";
|
|
2
|
+
import type { CompletionObserver } from "../completion.ts";
|
|
3
|
+
import { type WebSocketFallback } from "../protocol.ts";
|
|
4
|
+
import type { CodexTransportState } from "./transport-state.ts";
|
|
5
|
+
import { type CodexTurnState } from "./turn-state.ts";
|
|
6
|
+
import type { BeforeCodexRequestSend, CodexDiagnosticsSink, CodexProviderStreamOptions, CodexUsageRecorder, OpenAICodexStreamOptions, ResponsesBody } from "./types.ts";
|
|
7
|
+
export interface CodexProviderRuntimeConfig {
|
|
8
|
+
websocketFallback?: WebSocketFallback;
|
|
9
|
+
forceCachedWebSockets?: boolean;
|
|
10
|
+
originator?: string;
|
|
11
|
+
responsesLite?: boolean;
|
|
12
|
+
}
|
|
13
|
+
export interface CodexTransportRecoveryDependencies {
|
|
14
|
+
usageModel(model: Model<Api>, modelId: string): Model<Api>;
|
|
15
|
+
onCompletion?: CompletionObserver | undefined;
|
|
16
|
+
canonicalSubscription?: boolean;
|
|
17
|
+
transportState: CodexTransportState;
|
|
18
|
+
getConfig?: () => CodexProviderRuntimeConfig | undefined;
|
|
19
|
+
useResponsesLite?: (model: Model<Api>) => boolean;
|
|
20
|
+
turnState?: CodexTurnState | undefined;
|
|
21
|
+
onPreparedPayload?: ((payload: ResponsesBody) => void) | undefined;
|
|
22
|
+
beforeRequestSend?: BeforeCodexRequestSend | undefined;
|
|
23
|
+
onStreamSettled?: (output: AssistantMessage) => void;
|
|
24
|
+
getDiagnostics?: (() => CodexDiagnosticsSink | undefined) | undefined;
|
|
25
|
+
recordUsage?: CodexUsageRecorder | undefined;
|
|
26
|
+
prepareRequestBody: <TApi extends Api>(model: Model<TApi>, context: TranscriptContext, options: OpenAICodexStreamOptions | undefined, responsesLite: boolean) => Promise<ResponsesBody>;
|
|
27
|
+
}
|
|
28
|
+
export declare function getEffectiveCodexTransport(transportState: CodexTransportState, transport: Transport | undefined, config: Pick<CodexProviderRuntimeConfig, "forceCachedWebSockets"> | undefined, sessionId?: string | undefined): Transport;
|
|
29
|
+
export declare function createCodexTransportStream<TApi extends Api>(model: Model<TApi>, context: TranscriptContext, options: CodexProviderStreamOptions | undefined, deps: CodexTransportRecoveryDependencies): AssistantMessageEventStream;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { ResponsesMode, WebSocketRuntime } from "../protocol.ts";
|
|
2
|
+
import type { ResponsesBody, SessionWebSocketCacheEntry, WebSocketLike } from "./types.ts";
|
|
3
|
+
interface CanonicalSessionLane {
|
|
4
|
+
identity: symbol;
|
|
5
|
+
requestSequence: number;
|
|
6
|
+
}
|
|
7
|
+
export interface CanonicalSessionState {
|
|
8
|
+
accountId: string;
|
|
9
|
+
url: string;
|
|
10
|
+
requestBody: ResponsesBody;
|
|
11
|
+
reconstructedRequestInput: readonly unknown[];
|
|
12
|
+
responseItems: readonly unknown[];
|
|
13
|
+
}
|
|
14
|
+
/** One provider instance owns its physical sockets and logical continuation lanes. */
|
|
15
|
+
export interface CodexTransportState {
|
|
16
|
+
mode: ResponsesMode;
|
|
17
|
+
runtime: WebSocketRuntime;
|
|
18
|
+
websocketSessionCache: Map<string, Map<string, SessionWebSocketCacheEntry>>;
|
|
19
|
+
websocketPreparations: Map<string, Set<AbortController>>;
|
|
20
|
+
websocketSseFallbackSessions: Set<string>;
|
|
21
|
+
canonicalSessions: Map<string, CanonicalSessionState>;
|
|
22
|
+
canonicalSessionLanes: Map<string, CanonicalSessionLane>;
|
|
23
|
+
sockets: Map<WebSocketLike, string | undefined>;
|
|
24
|
+
socketClosures: Map<Promise<void>, string | undefined>;
|
|
25
|
+
connections: Map<AbortController, string | undefined>;
|
|
26
|
+
}
|
|
27
|
+
export declare function createCodexTransportState(mode?: ResponsesMode, runtime?: WebSocketRuntime): CodexTransportState;
|
|
28
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export declare const CODEX_TURN_STATE_HEADER = "x-codex-turn-state";
|
|
2
|
+
export interface CodexTurnState {
|
|
3
|
+
current(): string | undefined;
|
|
4
|
+
capture(value: string | null | undefined): void;
|
|
5
|
+
capturePrewarm(value: string | null | undefined): void;
|
|
6
|
+
beginTurn(): void;
|
|
7
|
+
reset(): void;
|
|
8
|
+
}
|
|
9
|
+
export declare function withCodexTurnState<T extends {
|
|
10
|
+
client_metadata?: Record<string, unknown> | undefined;
|
|
11
|
+
}>(body: T, turnState: CodexTurnState | undefined): T;
|
|
12
|
+
export declare function withCodexTurnStateHeader(headers: Headers, turnState: CodexTurnState | undefined): Headers;
|
|
13
|
+
export declare function createCodexTurnState(): CodexTurnState;
|
|
14
|
+
export declare function extractCodexTurnStateFromWebSocketEvent(event: unknown): string | undefined;
|