@howaboua/pi-durable-openai-responses 0.0.0-stage → 0.10.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.
Files changed (59) hide show
  1. package/LICENSE +21 -0
  2. package/NOTICE +82 -0
  3. package/README.md +109 -2
  4. package/dist/activation.d.ts +12 -0
  5. package/dist/activation.js +6443 -0
  6. package/dist/cache-keepalive.d.ts +28 -0
  7. package/dist/completion.d.ts +15 -0
  8. package/dist/configuration-updates.d.ts +6 -0
  9. package/dist/constrained-sampling.d.ts +17 -0
  10. package/dist/index.d.ts +58 -0
  11. package/dist/index.js +6403 -0
  12. package/dist/lifecycle.d.ts +12 -0
  13. package/dist/lite-images.d.ts +14 -0
  14. package/dist/openai-codex/constants.d.ts +20 -0
  15. package/dist/openai-codex/continuation-diagnostics.d.ts +26 -0
  16. package/dist/openai-codex/daybreak.d.ts +7 -0
  17. package/dist/openai-codex/device-code.d.ts +21 -0
  18. package/dist/openai-codex/diagnostic-failure.d.ts +3 -0
  19. package/dist/openai-codex/errors.d.ts +14 -0
  20. package/dist/openai-codex/header-record.d.ts +1 -0
  21. package/dist/openai-codex/headers.d.ts +9 -0
  22. package/dist/openai-codex/model-catalog.d.ts +2 -0
  23. package/dist/openai-codex/node-runtime.d.ts +8 -0
  24. package/dist/openai-codex/oauth.d.ts +2 -0
  25. package/dist/openai-codex/recovery-budget.d.ts +37 -0
  26. package/dist/openai-codex/request-body.d.ts +5 -0
  27. package/dist/openai-codex/request-serialization.d.ts +6 -0
  28. package/dist/openai-codex/responses-lite-model.d.ts +6 -0
  29. package/dist/openai-codex/responses-lite-tools.d.ts +2 -0
  30. package/dist/openai-codex/responses-lite.d.ts +18 -0
  31. package/dist/openai-codex/session-continuity.d.ts +29 -0
  32. package/dist/openai-codex/sse-request.d.ts +4 -0
  33. package/dist/openai-codex/sse.d.ts +14 -0
  34. package/dist/openai-codex/stream-events.d.ts +23 -0
  35. package/dist/openai-codex/transport-recovery.d.ts +29 -0
  36. package/dist/openai-codex/transport-state.d.ts +28 -0
  37. package/dist/openai-codex/turn-state.d.ts +14 -0
  38. package/dist/openai-codex/types.d.ts +250 -0
  39. package/dist/openai-codex/usage.d.ts +12 -0
  40. package/dist/openai-codex/websocket-connection.d.ts +14 -0
  41. package/dist/openai-codex/websocket-continuation.d.ts +3 -0
  42. package/dist/openai-codex/websocket-parser.d.ts +3 -0
  43. package/dist/openai-codex/websocket-session-cache.d.ts +14 -0
  44. package/dist/openai-codex/websocket-stream.d.ts +16 -0
  45. package/dist/openai-codex/websocket.d.ts +4 -0
  46. package/dist/openai-codex/worker-websocket.d.ts +3 -0
  47. package/dist/openai-responses/compaction-v2-feature.d.ts +3 -0
  48. package/dist/openai-responses/message-history.d.ts +4 -0
  49. package/dist/openai-responses/native-items.d.ts +48 -0
  50. package/dist/openai-responses/oauth.d.ts +3 -0
  51. package/dist/openai-responses/remote-delivery-protocol.d.ts +10 -0
  52. package/dist/openai-responses/shared.d.ts +32 -0
  53. package/dist/openai-responses/signatures.d.ts +7 -0
  54. package/dist/openai-responses/stream.d.ts +5 -0
  55. package/dist/openai-responses/tool-history.d.ts +2 -0
  56. package/dist/preparation.d.ts +7 -0
  57. package/dist/prewarm.d.ts +13 -0
  58. package/dist/protocol.d.ts +10 -0
  59. package/package.json +64 -5
@@ -0,0 +1,28 @@
1
+ import type { Api, Model } from "@earendil-works/pi-ai";
2
+ import type { CodexDiagnosticsSink, CodexPrewarmResult, ResponsesBody } from "./openai-codex/types.ts";
3
+ import type { PrewarmOptions } from "./prewarm.ts";
4
+ export interface CacheKeepalivePolicy {
5
+ /** Astra, Sol and Terra. Default false. */
6
+ cacheKeepalive?: boolean;
7
+ /** Default 25. */
8
+ cacheKeepaliveIntervalMinutes?: 25 | 55;
9
+ /** Luna duration cap. Default 0, disabled. */
10
+ lunaCacheKeepaliveMinutes?: 0 | 5 | 10 | 15;
11
+ /** Default 2.5. */
12
+ lunaCacheKeepaliveIntervalMinutes?: 2.5 | 4.5;
13
+ }
14
+ export type CacheKeepaliveOptions = Omit<PrewarmOptions, "mode"> & {
15
+ policy: CacheKeepalivePolicy;
16
+ /** Recheck idle, quota, credentials and prepared snapshot identity synchronously. */
17
+ isCurrent: () => boolean;
18
+ /** Account for generated usage, including a result arriving during cancellation. */
19
+ onResult: (result: CodexPrewarmResult) => void | Promise<void>;
20
+ onError: (error: unknown) => void | Promise<void>;
21
+ };
22
+ /** Provider-owned timers and tasks. Hosts supply authority, never an inferred transcript. */
23
+ export declare function createCacheKeepalive(warm: (model: Model<Api>, body: ResponsesBody, options: PrewarmOptions) => Promise<CodexPrewarmResult | undefined>, getDiagnostics: (sessionId: string) => CodexDiagnosticsSink | undefined): {
24
+ cancel: (sessionId: string) => void | undefined;
25
+ drain(sessionId?: string): Promise<void>;
26
+ close(): void;
27
+ arm(model: Model<Api>, body: ResponsesBody, options: CacheKeepaliveOptions): () => void;
28
+ };
@@ -0,0 +1,15 @@
1
+ /** Ephemeral transport evidence. Contains no authentication headers or credentials. */
2
+ export interface CompletionObservation {
3
+ responseId: string;
4
+ provider: string;
5
+ api: string;
6
+ model: string;
7
+ sessionId: string | undefined;
8
+ /** HTTP-equivalent endpoint, including when the request used WebSockets. */
9
+ url: string;
10
+ transport: "sse" | "websocket";
11
+ /** Exact sent JSON, including the WebSocket event envelope. */
12
+ requestBody: string;
13
+ canonicalSubscription: boolean;
14
+ }
15
+ export type CompletionObserver = (observation: CompletionObservation) => void;
@@ -0,0 +1,6 @@
1
+ /** Run after replay too: native checkpoints can restore an update at the tail. */
2
+ export declare function normalizeCodexConfigurationUpdates<T extends {
3
+ input: unknown[];
4
+ model?: string | undefined;
5
+ [key: string]: unknown;
6
+ }>(body: T): T;
@@ -0,0 +1,17 @@
1
+ import type { Tool } from "@earendil-works/pi-ai";
2
+ export declare function getJsonSchemaToolParameters(tool: Tool, strict: boolean | undefined): Tool["parameters"];
3
+ export declare function resolveJsonSchemaStrictSampling(tool: Tool, supportsStrictMode: boolean): boolean | undefined;
4
+ export interface GrammarConstrainedSampling {
5
+ format: "lark" | "regex";
6
+ definition: string;
7
+ inputProperty: string;
8
+ }
9
+ export interface GrammarToolInputJsonBuffer {
10
+ input: string;
11
+ started: boolean;
12
+ closed: boolean;
13
+ }
14
+ export declare function getGrammarToolInput(toolName: string, arguments_: Record<string, unknown>, inputProperty: string): string;
15
+ export declare function appendGrammarToolInputJsonDelta(buffer: GrammarToolInputJsonBuffer, inputProperty: string, nextInput: string, close: boolean): string | undefined;
16
+ export declare function resolveGrammarConstrainedSampling(tool: Tool, supportsOpenAIGrammarTools: boolean): GrammarConstrainedSampling | undefined;
17
+ export declare function createGrammarToolInputProperties(tools: Tool[] | undefined, supportsOpenAIGrammarTools: boolean): ReadonlyMap<string, string>;
@@ -0,0 +1,58 @@
1
+ import { type Api, type Context, type Model, type Provider, type Transport } from "@earendil-works/pi-ai";
2
+ import { type CacheKeepaliveOptions } from "./cache-keepalive.ts";
3
+ import type { CompletionObserver } from "./completion.ts";
4
+ export type { CompletionObservation, CompletionObserver, } from "./completion.ts";
5
+ import { type CodexCompactionReplayDecision, type CodexDiagnosticsSink, type CodexPrewarmResult, type ResponsesBody } from "./openai-codex/types.ts";
6
+ import { type PrewarmOptions } from "./prewarm.ts";
7
+ import { type WebSocketFallback, type WebSocketRuntime } from "./protocol.ts";
8
+ export type { CacheKeepaliveOptions, CacheKeepalivePolicy, } from "./cache-keepalive.ts";
9
+ export type { CodexDiagnosticsEvent, CodexDiagnosticsSink, CodexPrewarmResult, OpenAICodexStreamOptions, ResponsesBody, } from "./openai-codex/types.ts";
10
+ export type { PrewarmOptions } from "./prewarm.ts";
11
+ type ResponsesApi = "openai-codex-responses" | "openai-responses";
12
+ export interface OpenAIResponsesProviderOptions<TApi extends ResponsesApi = "openai-codex-responses"> {
13
+ /** Codex remains the default. Direct uses ordinary OpenAI Responses auth and catalog. */
14
+ mode?: TApi extends "openai-responses" ? "direct" : "codex";
15
+ /** workerd uses native authenticated fetch Upgrade, with no Node proxy routing. */
16
+ runtime?: WebSocketRuntime;
17
+ /** Direct is WebSocket-only. Codex keeps its existing SSE recovery unless explicitly disabled. */
18
+ websocketFallback?: WebSocketFallback;
19
+ id?: string;
20
+ baseUrl?: string;
21
+ models?: readonly Model<TApi>[];
22
+ /** Auto enables Lite for supported models with grammar-constrained tools. */
23
+ responsesLite?: boolean | "auto";
24
+ /** Codex account eligibility. Undefined makes no catalog request. */
25
+ daybreak?: boolean;
26
+ transport?: Transport;
27
+ /** Explicitly upgrade plain WebSockets to cached continuation. Default false. */
28
+ forceCachedWebSockets?: boolean;
29
+ originator?: string;
30
+ diagnostics?: CodexDiagnosticsSink;
31
+ /** Select once per request by native session ID, never by cache affinity. Overrides diagnostics. */
32
+ getDiagnostics?: (sessionId: string | undefined) => CodexDiagnosticsSink | undefined;
33
+ /** Opt-in ephemeral evidence of an actually completed sent request. */
34
+ onCompletion?: CompletionObserver;
35
+ /** Trusted host preparation, after provider conversion and before serialization. */
36
+ onPreparedRequest?: (body: ResponsesBody, model: Model<Api>) => void;
37
+ }
38
+ export interface OpenAIResponsesProvider<TApi extends ResponsesApi = "openai-codex-responses"> extends Provider<TApi> {
39
+ prewarm(model: Model<Api>, context: Context, options: PrewarmOptions): Promise<CodexPrewarmResult | undefined>;
40
+ /** Warm an authoritative final payload already prepared by the host. */
41
+ prewarmPrepared(model: Model<Api>, body: ResponsesBody, options: PrewarmOptions): Promise<CodexPrewarmResult | undefined>;
42
+ /** Opt-in billable idle refresh of a host-authoritative final prepared snapshot. */
43
+ armCacheKeepalive(model: Model<Api>, body: ResponsesBody, options: CacheKeepaliveOptions): () => void;
44
+ /** A validated snapshot for host-owned native checkpoint requests. Input excludes Lite's request prefix. */
45
+ getCanonicalRequest(model: Model<Api>, sessionId: string, apiKey: string, reconstructedInput: readonly unknown[]): {
46
+ body?: ResponsesBody;
47
+ decision: CodexCompactionReplayDecision;
48
+ };
49
+ resetSession(sessionId: string): Promise<void>;
50
+ close(): Promise<void>;
51
+ }
52
+ /** Register with the host's Models collection, not the Durable tool registry. */
53
+ export declare function createOpenAIResponsesProvider(options: OpenAIResponsesProviderOptions<"openai-responses"> & {
54
+ mode: "direct";
55
+ }): OpenAIResponsesProvider<"openai-responses">;
56
+ export declare function createOpenAIResponsesProvider(options?: OpenAIResponsesProviderOptions<"openai-codex-responses"> & {
57
+ mode?: "codex";
58
+ }): OpenAIResponsesProvider<"openai-codex-responses">;