@pure01fx/dsh-openai-codex-auth 0.5.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/lib/index.d.ts ADDED
@@ -0,0 +1,128 @@
1
+ /** Native OpenAI Codex OAuth login for DeepSeek Harness. */
2
+ import { Context, Service } from '@deepseek-ai/cordis';
3
+ import z from '@deepseek-ai/schemastery';
4
+ import { type IncomingMessage } from 'node:http';
5
+ import type { WebServer } from '@deepseek-ai/dsh-host-webserver';
6
+ /** Persisted OAuth credential. */
7
+ export interface OpenAICodexCredential {
8
+ access: string;
9
+ refresh: string;
10
+ expires: number;
11
+ accountId: string;
12
+ }
13
+ /** Plugin configuration. */
14
+ export interface Config {
15
+ path?: string;
16
+ dshHome?: string;
17
+ }
18
+ interface UsageWindow {
19
+ usedPercent: number;
20
+ windowSeconds?: number;
21
+ resetAt?: number;
22
+ }
23
+ interface UsageSummary {
24
+ planType?: string;
25
+ primary?: UsageWindow;
26
+ secondary?: UsageWindow;
27
+ limitReached?: boolean;
28
+ resetCredits?: number;
29
+ fetchedAt: number;
30
+ }
31
+ interface WebRuntimeValues {
32
+ lanAddresses: string[];
33
+ trustedHosts: string[];
34
+ }
35
+ interface DeviceAuthorization {
36
+ deviceAuthId: string;
37
+ userCode: string;
38
+ intervalSeconds: number;
39
+ expiresAt: number;
40
+ }
41
+ interface DeviceTokenCode {
42
+ authorizationCode: string;
43
+ codeVerifier: string;
44
+ }
45
+ interface ParsedDevicePoll {
46
+ status: 'pending' | 'slow_down' | 'complete' | 'failed';
47
+ value?: DeviceTokenCode;
48
+ message?: string;
49
+ }
50
+ /** Reduce the OpenAI response to the stable fields displayed by the Web card. */
51
+ export declare function normalizeUsage(value: unknown): UsageSummary;
52
+ declare function parseAuthority(authority: string | undefined): URL | undefined;
53
+ declare function isLoopbackHostname(hostname: string): boolean;
54
+ declare function isTrustedHost(authority: string | undefined, trustedHosts: readonly string[]): boolean;
55
+ declare function isTrustedBrowserRequest(request: IncomingMessage, trustedHosts: readonly string[]): boolean;
56
+ declare function browserCallbackUrl(authority: string | undefined, _fallbackPort: number): string | undefined;
57
+ declare function callbackHostMatches(authority: string | undefined, redirectUri: string): boolean;
58
+ declare function startDeviceAuthorization(signal?: AbortSignal): Promise<DeviceAuthorization>;
59
+ declare function parseDevicePollResponse(response: Response): Promise<ParsedDevicePoll>;
60
+ declare function pollDeviceAuthorization(device: DeviceAuthorization, signal?: AbortSignal): Promise<DeviceTokenCode>;
61
+ export declare const internals: {
62
+ parseAuthority: typeof parseAuthority;
63
+ isLoopbackHostname: typeof isLoopbackHostname;
64
+ isTrustedHost: typeof isTrustedHost;
65
+ isTrustedBrowserRequest: typeof isTrustedBrowserRequest;
66
+ browserCallbackUrl: typeof browserCallbackUrl;
67
+ callbackHostMatches: typeof callbackHostMatches;
68
+ startDeviceAuthorization: typeof startDeviceAuthorization;
69
+ parseDevicePollResponse: typeof parseDevicePollResponse;
70
+ pollDeviceAuthorization: typeof pollDeviceAuthorization;
71
+ };
72
+ declare module '@deepseek-ai/cordis' {
73
+ interface Context {
74
+ openaiCodexAuth: OpenAICodexAuth;
75
+ webServer: WebServer;
76
+ webRuntime: WebRuntimeValues;
77
+ }
78
+ }
79
+ /** DSH service providing device-code/browser login, logout, and automatically refreshed bearer tokens. */
80
+ export declare class OpenAICodexAuth extends Service {
81
+ static Config: z<Config>;
82
+ static inject: string[];
83
+ private readonly filename;
84
+ private readonly csrf;
85
+ private usageCache;
86
+ private usageError;
87
+ private usageRefresh;
88
+ private usageGeneration;
89
+ private readonly codexTurns;
90
+ private loginFlow;
91
+ private startingDevice;
92
+ private startingBrowser;
93
+ private lastLoginError;
94
+ constructor(ctx: Context, config: Config);
95
+ private markCodexTurn;
96
+ private consumeCodexTurn;
97
+ private performUsageRefresh;
98
+ private refreshUsage;
99
+ private assertCredentialWritable;
100
+ private storeCredentialToken;
101
+ /** Return a valid bearer token, refreshing and persisting it when near expiry. */
102
+ bearerToken(signal?: AbortSignal): Promise<string | undefined>;
103
+ private finishCredential;
104
+ private finishAuthorizationCode;
105
+ private settleFlow;
106
+ private beginDeviceLogin;
107
+ private createDeviceLogin;
108
+ private beginBrowserLogin;
109
+ private createBrowserLogin;
110
+ private cancelLogin;
111
+ private logout;
112
+ private status;
113
+ private fetchUsage;
114
+ private write;
115
+ private sendJson;
116
+ private sendText;
117
+ private trustedManagementRequest;
118
+ private requireCsrf;
119
+ private handleStatus;
120
+ private handleDeviceStart;
121
+ private handleBrowserStart;
122
+ private handleBrowserPrepare;
123
+ private handleBrowserComplete;
124
+ private handleCallback;
125
+ private handleCancel;
126
+ private handleLogout;
127
+ }
128
+ export default OpenAICodexAuth;