@tnnevol/dsh-codex-auth 0.1.0-rc.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/lib/index.d.ts ADDED
@@ -0,0 +1,126 @@
1
+ import { CODEX_AUTH_LOGIN_PATH, CODEX_AUTH_LOGOUT_PATH, CODEX_AUTH_SETTINGS_NAMESPACE, CODEX_AUTH_STATUS_PATH } from "./auth-paths.js";
2
+ import { a as CODEX_AUTH_FILENAME, c as codexAuthPath, i as logoutCodex, n as codexAuthStatus, o as CODEX_PROVIDER, r as loginCodex, s as CodexCredentialStore, t as CodexAuthStatus } from "./auth-BBBeI24-.js";
3
+ import { CredentialProvider } from "@deepseek-ai/dsh-credentials";
4
+ import { AttachmentStore } from "@deepseek-ai/dsh-attachment";
5
+ import { PiAiAdapter } from "@deepseek-ai/dsh-llm-pi-ai";
6
+ import { Context } from "@deepseek-ai/cordis";
7
+ import { IncomingMessage } from "node:http";
8
+ //#region src/credential-mirror.d.ts
9
+ /** Credential reference exposed to the official `llm-pi-ai` model settings UI. */
10
+ declare const CODEX_API_KEY_ENV = "OPENAI_CODEX_AUTH_TOKEN";
11
+ declare const CODEX_API_KEY_REF: import("@deepseek-ai/dsh-credentials").CredentialRef;
12
+ /**
13
+ * Makes the plugin-owned OAuth token visible to the generic dsh adapter.
14
+ *
15
+ * `llm-pi-ai` deliberately resolves named credentials through `ctx.credentials`
16
+ * on every request. The OAuth document remains the source of truth; this class
17
+ * only mirrors the short-lived access token so the official Models page can
18
+ * show its configured state and the generic adapter can send Codex requests.
19
+ */
20
+ declare class CodexCredentialMirror {
21
+ private readonly credentials;
22
+ private readonly store;
23
+ private readonly models;
24
+ private operation;
25
+ constructor(credentials: CredentialProvider, store: CodexCredentialStore);
26
+ /** Refresh OAuth when needed, then update the generic dsh credential seam. */
27
+ sync(): Promise<void>;
28
+ /** Remove the mirrored token after the plugin-owned account signs out. */
29
+ clear(): Promise<void>;
30
+ private syncNow;
31
+ }
32
+ //#endregion
33
+ //#region src/adapter.d.ts
34
+ /** Keep the Codex stream open while the provider is still producing output. */
35
+ declare const CODEX_STREAM_IDLE_TIMEOUT_MS = 300000;
36
+ /** Create the dsh LLM adapter for the provider-native OpenAI Codex catalog. */
37
+ declare function createCodexAdapter(credentials: CodexCredentialStore, resolveAttachments: () => AttachmentStore | undefined): PiAiAdapter;
38
+ //#endregion
39
+ //#region src/usage.d.ts
40
+ interface CodexUsageWindow {
41
+ remainingPercent?: number;
42
+ limitWindowSeconds?: number;
43
+ resetAfterSeconds?: number;
44
+ resetAt?: number;
45
+ }
46
+ interface CodexUsageCredits {
47
+ hasCredits?: boolean;
48
+ unlimited?: boolean;
49
+ balance?: string;
50
+ }
51
+ /** Deliberately excludes the OAuth token and other upstream response fields. */
52
+ interface CodexUsage {
53
+ planType?: string;
54
+ allowed?: boolean;
55
+ limitReached?: boolean;
56
+ primaryWindow?: CodexUsageWindow;
57
+ secondaryWindow?: CodexUsageWindow;
58
+ credits?: CodexUsageCredits;
59
+ }
60
+ /** Normalize the evolving private WHAM response into a small UI-safe shape. */
61
+ declare function normalizeCodexUsagePayload(value: unknown): CodexUsage;
62
+ /** Resolves OAuth (including refresh) before making the quota request. */
63
+ declare class CodexUsageService {
64
+ private readonly store;
65
+ private readonly models;
66
+ private operation;
67
+ constructor(store: CodexCredentialStore);
68
+ read(): Promise<CodexUsage | undefined>;
69
+ private readNow;
70
+ }
71
+ //#endregion
72
+ //#region src/auth-routes.d.ts
73
+ type CodexWebAuthStatus = {
74
+ status: 'signed-out';
75
+ } | {
76
+ status: 'signing-in';
77
+ } | {
78
+ status: 'signed-in';
79
+ expiresAt?: Date;
80
+ } | {
81
+ status: 'error';
82
+ message: string;
83
+ };
84
+ /** One-time code generated by the Codex device authorization flow. */
85
+ interface CodexLoginChallenge {
86
+ type: 'device_code';
87
+ userCode: string;
88
+ verificationUri: string;
89
+ intervalSeconds?: number;
90
+ expiresInSeconds?: number;
91
+ }
92
+ /** Owns one device-code login operation and prevents duplicate auth requests. */
93
+ declare class CodexWebAuth {
94
+ private readonly store;
95
+ private readonly challengeTimeoutMs;
96
+ private readonly mirror?;
97
+ private state;
98
+ private operation;
99
+ private cancellation;
100
+ private challenge;
101
+ private challengeWaiters;
102
+ private challengeTimer;
103
+ constructor(store: CodexCredentialStore, challengeTimeoutMs?: number, mirror?: CodexCredentialMirror | undefined);
104
+ status(): Promise<CodexWebAuthStatus>;
105
+ signIn(): Promise<CodexLoginChallenge>;
106
+ signOut(): Promise<void>;
107
+ dispose(): Promise<void>;
108
+ private start;
109
+ private onEvent;
110
+ private rejectChallenge;
111
+ private clearChallengeTimer;
112
+ private cancelSignIn;
113
+ }
114
+ /** Protect mutating routes while allowing the NAS app's loopback proxy. */
115
+ declare function trustedRequest(req: IncomingMessage): boolean;
116
+ /** Register the auth endpoints when the DSH Web server is available. */
117
+ declare function registerCodexAuthRoutes(ctx: Context, store: CodexCredentialStore, mirror?: CodexCredentialMirror): void;
118
+ //#endregion
119
+ //#region src/index.d.ts
120
+ /** Stable Host bundle name. */
121
+ declare const name = "dsh-codex-auth-plugin";
122
+ /** Host services required by the routes, settings card, and credential mirror. */
123
+ declare const inject: string[];
124
+ declare function apply(ctx: Context): void;
125
+ //#endregion
126
+ export { CODEX_API_KEY_ENV, CODEX_API_KEY_REF, CODEX_AUTH_FILENAME, CODEX_AUTH_LOGIN_PATH, CODEX_AUTH_LOGOUT_PATH, CODEX_AUTH_SETTINGS_NAMESPACE, CODEX_AUTH_STATUS_PATH, CODEX_PROVIDER, CODEX_STREAM_IDLE_TIMEOUT_MS, type CodexAuthStatus, CodexCredentialMirror, CodexCredentialStore, type CodexLoginChallenge, CodexUsageService, CodexWebAuth, type CodexWebAuthStatus, apply, codexAuthPath, codexAuthStatus, createCodexAdapter, inject, loginCodex, logoutCodex, name, normalizeCodexUsagePayload, registerCodexAuthRoutes, trustedRequest };