dsh-coding-subscription-oauth 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/CHANGELOG.md +136 -0
- package/CONTRIBUTING.md +109 -0
- package/INSTALL.md +220 -0
- package/LICENSE +19 -0
- package/NOTICE +11 -0
- package/README.de.md +254 -0
- package/README.es.md +254 -0
- package/README.fr.md +254 -0
- package/README.ja.md +254 -0
- package/README.ko.md +254 -0
- package/README.md +286 -0
- package/README.pt-BR.md +254 -0
- package/README.ru.md +254 -0
- package/README.zh-CN.md +271 -0
- package/cordis.patch.yml +13 -0
- package/docs/00-project-rules.md +195 -0
- package/docs/02-architecture.md +132 -0
- package/docs/02-architecture.zh-CN.md +128 -0
- package/lib/adapter.d.ts +24 -0
- package/lib/adapter.d.ts.map +1 -0
- package/lib/alias-adapter.d.ts +43 -0
- package/lib/alias-adapter.d.ts.map +1 -0
- package/lib/auth-routes.d.ts +155 -0
- package/lib/auth-routes.d.ts.map +1 -0
- package/lib/auth.d.ts +29 -0
- package/lib/auth.d.ts.map +1 -0
- package/lib/bin.d.ts +6 -0
- package/lib/bin.d.ts.map +1 -0
- package/lib/bin.js +27591 -0
- package/lib/bin.js.map +7 -0
- package/lib/capability-routes.d.ts +43 -0
- package/lib/capability-routes.d.ts.map +1 -0
- package/lib/capability-runtime.d.ts +56 -0
- package/lib/capability-runtime.d.ts.map +1 -0
- package/lib/capability-settings.d.ts +263 -0
- package/lib/capability-settings.d.ts.map +1 -0
- package/lib/capability-tools.d.ts +50 -0
- package/lib/capability-tools.d.ts.map +1 -0
- package/lib/catalog.d.ts +53 -0
- package/lib/catalog.d.ts.map +1 -0
- package/lib/client.js +3 -0
- package/lib/client.js.map +7 -0
- package/lib/codex-http.d.ts +77 -0
- package/lib/codex-http.d.ts.map +1 -0
- package/lib/codex-images.d.ts +109 -0
- package/lib/codex-images.d.ts.map +1 -0
- package/lib/codex-model-capabilities.d.ts +112 -0
- package/lib/codex-model-capabilities.d.ts.map +1 -0
- package/lib/codex-search.d.ts +96 -0
- package/lib/codex-search.d.ts.map +1 -0
- package/lib/codex-usage.d.ts +79 -0
- package/lib/codex-usage.d.ts.map +1 -0
- package/lib/gateway-anthropic-messages.d.ts +8 -0
- package/lib/gateway-anthropic-messages.d.ts.map +1 -0
- package/lib/gateway-auth.d.ts +22 -0
- package/lib/gateway-auth.d.ts.map +1 -0
- package/lib/gateway-backend.d.ts +62 -0
- package/lib/gateway-backend.d.ts.map +1 -0
- package/lib/gateway-body.d.ts +9 -0
- package/lib/gateway-body.d.ts.map +1 -0
- package/lib/gateway-config.d.ts +24 -0
- package/lib/gateway-config.d.ts.map +1 -0
- package/lib/gateway-http.d.ts +16 -0
- package/lib/gateway-http.d.ts.map +1 -0
- package/lib/gateway-openai-chat.d.ts +8 -0
- package/lib/gateway-openai-chat.d.ts.map +1 -0
- package/lib/gateway-openai-responses.d.ts +8 -0
- package/lib/gateway-openai-responses.d.ts.map +1 -0
- package/lib/gateway-parse.d.ts +10 -0
- package/lib/gateway-parse.d.ts.map +1 -0
- package/lib/gateway-protocol.d.ts +47 -0
- package/lib/gateway-protocol.d.ts.map +1 -0
- package/lib/gateway-routes.d.ts +21 -0
- package/lib/gateway-routes.d.ts.map +1 -0
- package/lib/gateway.d.ts +48 -0
- package/lib/gateway.d.ts.map +1 -0
- package/lib/grok-imagine.d.ts +271 -0
- package/lib/grok-imagine.d.ts.map +1 -0
- package/lib/grok-import.d.ts +21 -0
- package/lib/grok-import.d.ts.map +1 -0
- package/lib/http-json.d.ts +10 -0
- package/lib/http-json.d.ts.map +1 -0
- package/lib/ids.d.ts +33 -0
- package/lib/ids.d.ts.map +1 -0
- package/lib/imagine-routes.d.ts +59 -0
- package/lib/imagine-routes.d.ts.map +1 -0
- package/lib/index.d.ts +69 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +35355 -0
- package/lib/index.js.map +7 -0
- package/lib/invariant.d.ts +9 -0
- package/lib/invariant.d.ts.map +1 -0
- package/lib/invariant.js +14 -0
- package/lib/invariant.js.map +7 -0
- package/lib/kimi-errors.d.ts +13 -0
- package/lib/kimi-errors.d.ts.map +1 -0
- package/lib/media-store.d.ts +130 -0
- package/lib/media-store.d.ts.map +1 -0
- package/lib/oauth-import-routes.d.ts +52 -0
- package/lib/oauth-import-routes.d.ts.map +1 -0
- package/lib/oauth-providers.d.ts +26 -0
- package/lib/oauth-providers.d.ts.map +1 -0
- package/lib/oauth-session.d.ts +40 -0
- package/lib/oauth-session.d.ts.map +1 -0
- package/lib/oauth-sources.d.ts +205 -0
- package/lib/oauth-sources.d.ts.map +1 -0
- package/lib/oauth.d.ts +79 -0
- package/lib/oauth.d.ts.map +1 -0
- package/lib/provider.d.ts +38 -0
- package/lib/provider.d.ts.map +1 -0
- package/lib/proxy.d.ts +17 -0
- package/lib/proxy.d.ts.map +1 -0
- package/lib/redact.d.ts +5 -0
- package/lib/redact.d.ts.map +1 -0
- package/lib/session.d.ts +40 -0
- package/lib/session.d.ts.map +1 -0
- package/lib/store.d.ts +46 -0
- package/lib/store.d.ts.map +1 -0
- package/lib/web-origin.d.ts +10 -0
- package/lib/web-origin.d.ts.map +1 -0
- package/lib/web-routes.d.ts +20 -0
- package/lib/web-routes.d.ts.map +1 -0
- package/package.json +185 -0
- package/patches/dsh-agy@0.1.2.patch +25 -0
- package/scripts/release.mjs +166 -0
- package/scripts/smoke-deployed-routes.mjs +146 -0
- package/scripts/verify-deployed-catalog.mjs +87 -0
- package/src/adapter.ts +282 -0
- package/src/alias-adapter.ts +152 -0
- package/src/auth-routes.ts +871 -0
- package/src/auth.ts +67 -0
- package/src/bin.ts +350 -0
- package/src/capability-routes.ts +275 -0
- package/src/capability-runtime.ts +313 -0
- package/src/capability-settings.ts +657 -0
- package/src/capability-tools.ts +666 -0
- package/src/catalog.ts +271 -0
- package/src/client/GrokBuildSettings.tsx +2221 -0
- package/src/client/index.tsx +37 -0
- package/src/client/locales.ts +421 -0
- package/src/codex-http.ts +447 -0
- package/src/codex-images.ts +485 -0
- package/src/codex-model-capabilities.ts +320 -0
- package/src/codex-search.ts +245 -0
- package/src/codex-usage.ts +263 -0
- package/src/gateway-anthropic-messages.ts +84 -0
- package/src/gateway-auth.ts +100 -0
- package/src/gateway-backend.ts +274 -0
- package/src/gateway-body.ts +49 -0
- package/src/gateway-config.ts +76 -0
- package/src/gateway-http.ts +104 -0
- package/src/gateway-openai-chat.ts +124 -0
- package/src/gateway-openai-responses.ts +53 -0
- package/src/gateway-parse.ts +224 -0
- package/src/gateway-protocol.ts +52 -0
- package/src/gateway-routes.ts +152 -0
- package/src/gateway.ts +242 -0
- package/src/grok-imagine.ts +1627 -0
- package/src/grok-import.ts +151 -0
- package/src/http-json.ts +82 -0
- package/src/ids.ts +45 -0
- package/src/imagine-routes.ts +461 -0
- package/src/index.ts +598 -0
- package/src/invariant.ts +17 -0
- package/src/kimi-errors.ts +26 -0
- package/src/media-store.ts +927 -0
- package/src/oauth-import-routes.ts +314 -0
- package/src/oauth-providers.ts +152 -0
- package/src/oauth-session.ts +183 -0
- package/src/oauth-sources.ts +1104 -0
- package/src/oauth.ts +620 -0
- package/src/provider.ts +128 -0
- package/src/proxy.ts +99 -0
- package/src/redact.ts +72 -0
- package/src/session.ts +218 -0
- package/src/store.ts +217 -0
- package/src/web-origin.ts +60 -0
- package/src/web-routes.ts +75 -0
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Optional Codex image generation/edits against the private ChatGPT backend.
|
|
3
|
+
* Fixed model `gpt-image-2` with `auto` size/quality/background defaults.
|
|
4
|
+
* Always requests `response_format: b64_json`. Only `b64_json` items are
|
|
5
|
+
* accepted after an encoded-size precheck and strict base64/base64url decode.
|
|
6
|
+
* Edit IDs resolve solely from canonical image attachment refs that are
|
|
7
|
+
* visibly present in the current session's top-level message content (max 5).
|
|
8
|
+
*
|
|
9
|
+
* @module dsh-coding-subscription-oauth/codex-images
|
|
10
|
+
*/
|
|
11
|
+
import type { ImageAttachmentRef, ImageMediaType, SaveImageAttachment, StoredImageAttachment } from "@deepseek-ai/dsh-attachment";
|
|
12
|
+
import { type CodexAuthSession, type CodexFetch, type CodexHttpClient } from "./codex-http.js";
|
|
13
|
+
export declare const CODEX_IMAGE_GENERATION_URL = "https://chatgpt.com/backend-api/codex/images/generations";
|
|
14
|
+
export declare const CODEX_IMAGE_EDIT_URL = "https://chatgpt.com/backend-api/codex/images/edits";
|
|
15
|
+
export declare const CODEX_IMAGE_MODEL = "gpt-image-2";
|
|
16
|
+
export declare const CODEX_IMAGE_AUTO = "auto";
|
|
17
|
+
export declare const CODEX_IMAGE_RESPONSE_FORMAT = "b64_json";
|
|
18
|
+
export declare const CODEX_IMAGE_MAX_REFERENCES = 5;
|
|
19
|
+
export declare const CODEX_IMAGE_PROMPT_MAX_LENGTH = 4000;
|
|
20
|
+
export declare const CODEX_IMAGE_CAPABLE_PROVIDERS: readonly ["codex-oauth", "openai-codex", "codex-oauth-fast"];
|
|
21
|
+
export type CodexImageCapableProvider = (typeof CODEX_IMAGE_CAPABLE_PROVIDERS)[number];
|
|
22
|
+
export declare const CODEX_IMAGE_SIZES: readonly ["auto", "1024x1024", "1536x1024", "1024x1536"];
|
|
23
|
+
export type CodexImageSize = (typeof CODEX_IMAGE_SIZES)[number];
|
|
24
|
+
export declare const CODEX_IMAGE_QUALITIES: readonly ["auto", "low", "medium", "high"];
|
|
25
|
+
export type CodexImageQuality = (typeof CODEX_IMAGE_QUALITIES)[number];
|
|
26
|
+
export declare const CODEX_IMAGE_BACKGROUNDS: readonly ["auto", "opaque", "transparent"];
|
|
27
|
+
export type CodexImageBackground = (typeof CODEX_IMAGE_BACKGROUNDS)[number];
|
|
28
|
+
export interface CodexImageAttachmentStore {
|
|
29
|
+
readonly imageLimits: {
|
|
30
|
+
readonly maxImageBytes: number;
|
|
31
|
+
readonly maxImagesPerMessage: number;
|
|
32
|
+
readonly maxMessageImageBytes: number;
|
|
33
|
+
readonly mediaTypes: readonly ImageMediaType[];
|
|
34
|
+
};
|
|
35
|
+
validateImage(input: SaveImageAttachment): Promise<void>;
|
|
36
|
+
saveImage(input: SaveImageAttachment): Promise<ImageAttachmentRef>;
|
|
37
|
+
readImage(ref: ImageAttachmentRef, signal?: AbortSignal): Promise<StoredImageAttachment>;
|
|
38
|
+
}
|
|
39
|
+
export interface CodexDerivedMessage {
|
|
40
|
+
readonly content?: readonly unknown[];
|
|
41
|
+
}
|
|
42
|
+
export interface CodexImageRoute {
|
|
43
|
+
readonly provider?: string;
|
|
44
|
+
readonly model?: string;
|
|
45
|
+
readonly inputModalities?: readonly string[];
|
|
46
|
+
}
|
|
47
|
+
export interface CodexImageSessionContext {
|
|
48
|
+
deriveMessages(): readonly CodexDerivedMessage[];
|
|
49
|
+
route?: CodexImageRoute;
|
|
50
|
+
}
|
|
51
|
+
export interface CodexImageGenerateInput {
|
|
52
|
+
readonly prompt: string;
|
|
53
|
+
readonly n?: number;
|
|
54
|
+
readonly size?: CodexImageSize;
|
|
55
|
+
readonly quality?: CodexImageQuality;
|
|
56
|
+
readonly background?: CodexImageBackground;
|
|
57
|
+
}
|
|
58
|
+
export interface CodexImageEditInput extends CodexImageGenerateInput {
|
|
59
|
+
readonly imageIds: readonly string[];
|
|
60
|
+
}
|
|
61
|
+
export interface CodexImageWarning {
|
|
62
|
+
readonly index: number;
|
|
63
|
+
readonly code: string;
|
|
64
|
+
readonly message: string;
|
|
65
|
+
}
|
|
66
|
+
export interface CodexImageResult {
|
|
67
|
+
readonly operation: "generate" | "edit";
|
|
68
|
+
readonly model: typeof CODEX_IMAGE_MODEL;
|
|
69
|
+
readonly images: readonly ImageAttachmentRef[];
|
|
70
|
+
readonly references: readonly ImageAttachmentRef[];
|
|
71
|
+
readonly warnings: readonly CodexImageWarning[];
|
|
72
|
+
}
|
|
73
|
+
export interface CodexImageControllerOptions {
|
|
74
|
+
readonly auth: CodexAuthSession;
|
|
75
|
+
readonly attachments: CodexImageAttachmentStore;
|
|
76
|
+
readonly session: CodexImageSessionContext;
|
|
77
|
+
readonly http?: CodexHttpClient;
|
|
78
|
+
readonly fetchImpl?: CodexFetch;
|
|
79
|
+
readonly originator?: string;
|
|
80
|
+
readonly userAgent?: string;
|
|
81
|
+
readonly sleep?: (ms: number, signal?: AbortSignal) => Promise<void>;
|
|
82
|
+
readonly now?: () => number;
|
|
83
|
+
}
|
|
84
|
+
export interface CodexImageController {
|
|
85
|
+
generate(input: CodexImageGenerateInput, signal?: AbortSignal): Promise<CodexImageResult>;
|
|
86
|
+
edit(input: CodexImageEditInput, signal?: AbortSignal): Promise<CodexImageResult>;
|
|
87
|
+
}
|
|
88
|
+
/** True only for a Codex OAuth route that explicitly declares image input. */
|
|
89
|
+
export declare function isCodexImageCapableRoute(route: CodexImageRoute | undefined): boolean;
|
|
90
|
+
export declare function assertCodexImageCapableRoute(route: CodexImageRoute | undefined): void;
|
|
91
|
+
/**
|
|
92
|
+
* Collect canonical image attachment refs visibly present in current session
|
|
93
|
+
* message content. Nested tool-results and arbitrary objects are ignored.
|
|
94
|
+
*/
|
|
95
|
+
export declare function collectCanonicalImageRefs(messages: readonly CodexDerivedMessage[]): Map<string, ImageAttachmentRef>;
|
|
96
|
+
/**
|
|
97
|
+
* Resolve edit IDs only against canonical refs visibly present in `deriveMessages()`.
|
|
98
|
+
* Unknown IDs, HTTP URLs, nested-only objects, and more than
|
|
99
|
+
* {@link CODEX_IMAGE_MAX_REFERENCES} are rejected (fail closed).
|
|
100
|
+
*/
|
|
101
|
+
export declare function resolveSessionImageRefs(deriveMessages: () => readonly CodexDerivedMessage[], imageIds: readonly string[]): ImageAttachmentRef[];
|
|
102
|
+
export declare function detectImageMediaType(data: Uint8Array): ImageMediaType | undefined;
|
|
103
|
+
/** Encoded-size precheck. `undefined` means the payload is not valid base64/base64url. */
|
|
104
|
+
export declare function estimateDecodedBase64Bytes(value: string): number | undefined;
|
|
105
|
+
/** Decode standard base64 or base64url. Rejects invalid alphabets and length mismatches. */
|
|
106
|
+
export declare function decodeImageBase64(value: string): Uint8Array | undefined;
|
|
107
|
+
/** Factory for generate/edit controllers. Parent registers tools only when the feature is enabled. */
|
|
108
|
+
export declare function createCodexImageController(options: CodexImageControllerOptions): CodexImageController;
|
|
109
|
+
//# sourceMappingURL=codex-images.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"codex-images.d.ts","sourceRoot":"","sources":["../../src/codex-images.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EACX,kBAAkB,EAClB,cAAc,EACd,mBAAmB,EACnB,qBAAqB,EACrB,MAAM,6BAA6B,CAAC;AAErC,OAAO,EACN,KAAK,gBAAgB,EACrB,KAAK,UAAU,EACf,KAAK,eAAe,EAGpB,MAAM,iBAAiB,CAAC;AAEzB,eAAO,MAAM,0BAA0B,6DAA6D,CAAC;AACrG,eAAO,MAAM,oBAAoB,uDAAuD,CAAC;AACzF,eAAO,MAAM,iBAAiB,gBAAgB,CAAC;AAC/C,eAAO,MAAM,gBAAgB,SAAS,CAAC;AACvC,eAAO,MAAM,2BAA2B,aAAa,CAAC;AACtD,eAAO,MAAM,0BAA0B,IAAI,CAAC;AAC5C,eAAO,MAAM,6BAA6B,OAAO,CAAC;AAElD,eAAO,MAAM,6BAA6B,8DAA+D,CAAC;AAC1G,MAAM,MAAM,yBAAyB,GAAG,CAAC,OAAO,6BAA6B,CAAC,CAAC,MAAM,CAAC,CAAC;AAEvF,eAAO,MAAM,iBAAiB,0DAA2D,CAAC;AAC1F,MAAM,MAAM,cAAc,GAAG,CAAC,OAAO,iBAAiB,CAAC,CAAC,MAAM,CAAC,CAAC;AAEhE,eAAO,MAAM,qBAAqB,4CAA6C,CAAC;AAChF,MAAM,MAAM,iBAAiB,GAAG,CAAC,OAAO,qBAAqB,CAAC,CAAC,MAAM,CAAC,CAAC;AAEvE,eAAO,MAAM,uBAAuB,4CAA6C,CAAC;AAClF,MAAM,MAAM,oBAAoB,GAAG,CAAC,O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EAAE,WAAW,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAAC;IAC1F,IAAI,CAAC,KAAK,EAAE,mBAAmB,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAAC;CAClF;AAID,8EAA8E;AAC9E,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,eAAe,GAAG,SAAS,GAAG,OAAO,CAOpF;AAED,wBAAgB,4BAA4B,CAAC,KAAK,EAAE,eAAe,GAAG,SAAS,GAAG,IAAI,CAIrF;AAaD;;;GAGG;AACH,wBAAgB,yBAAyB,CAAC,QAAQ,EAAE,SAAS,mBAAmB,EAAE,GAAG,GAAG,CAAC,MAAM,EAAE,kBAAkB,CAAC,CAanH;AAMD;;;;GAIG;AACH,wBAAgB,uBAAuB,CACtC,cAAc,EAAE,MAAM,SAAS,mBAAmB,EAAE,EACpD,QAAQ,EAAE,SAAS,MAAM,EAAE,GACzB,kBAAkB,EAAE,CAiCtB;AAMD,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,UAAU,GAAG,cAAc,GAAG,SAAS,CAkBjF;AAUD,0FAA0F;AAC1F,wBAAgB,0BAA0B,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAM5E;AAED,4FAA4F;AAC5F,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,MAAM,GAAG,UAAU,GAAG,SAAS,CAcvE;AAuLD,sGAAsG;AACtG,wBAAgB,0BAA0B,CAAC,OAAO,EAAE,2BAA2B,GAAG,oBAAoB,CAiCrG"}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Live Codex model service-tier cache and composable fast-route payload helpers.
|
|
3
|
+
*
|
|
4
|
+
* Fetches `GET /backend-api/codex/models?client_version=…`, caches `service_tiers`,
|
|
5
|
+
* and never invents eligibility when the live catalog is missing or stale.
|
|
6
|
+
* A stale TTL is unknown: Fast is default-deny until a live, non-stale catalog
|
|
7
|
+
* explicitly lists `priority` for that model. `isEligible` is required and
|
|
8
|
+
* fail-closed — omitting it or returning false injects nothing.
|
|
9
|
+
*
|
|
10
|
+
* Ordinary inference stays unchanged: the unwrapped provider is never mutated.
|
|
11
|
+
* A wrapper may use a distinct profile provider id (`codex-oauth-fast`) while
|
|
12
|
+
* restoring native `model.provider` for the base wire call and the same catalog.
|
|
13
|
+
*
|
|
14
|
+
* @module dsh-coding-subscription-oauth/codex-model-capabilities
|
|
15
|
+
*/
|
|
16
|
+
import { type CodexAuthSession, type CodexFetch, type CodexHttpClient } from "./codex-http.js";
|
|
17
|
+
import { CODEX_OAUTH_FAST_ROUTE } from "./ids.js";
|
|
18
|
+
/** Distinct optional Harness route; parent owns dynamic registration. */
|
|
19
|
+
export { CODEX_OAUTH_FAST_ROUTE };
|
|
20
|
+
export declare const CODEX_MODELS_URL = "https://chatgpt.com/backend-api/codex/models";
|
|
21
|
+
export declare const DEFAULT_CODEX_CLIENT_VERSION = "0.144.0";
|
|
22
|
+
export declare const DEFAULT_CODEX_SERVICE_TIER = "priority";
|
|
23
|
+
export declare const CODEX_ROUTING_HINT_HEADER = "x-codex-routing-hint";
|
|
24
|
+
export interface CodexModelCapability {
|
|
25
|
+
readonly id: string;
|
|
26
|
+
readonly serviceTiers: readonly string[];
|
|
27
|
+
}
|
|
28
|
+
export interface CodexModelCapabilitiesOptions {
|
|
29
|
+
readonly auth: CodexAuthSession;
|
|
30
|
+
readonly http?: CodexHttpClient;
|
|
31
|
+
readonly fetchImpl?: CodexFetch;
|
|
32
|
+
readonly clientVersion?: string;
|
|
33
|
+
readonly originator?: string;
|
|
34
|
+
readonly userAgent?: string;
|
|
35
|
+
readonly sleep?: (ms: number, signal?: AbortSignal) => Promise<void>;
|
|
36
|
+
readonly now?: () => number;
|
|
37
|
+
readonly ttlMs?: number;
|
|
38
|
+
}
|
|
39
|
+
export interface CodexModelCapabilities {
|
|
40
|
+
refresh(signal?: AbortSignal): Promise<readonly CodexModelCapability[]>;
|
|
41
|
+
clear(): void;
|
|
42
|
+
getCached(): readonly CodexModelCapability[] | undefined;
|
|
43
|
+
serviceTiers(modelId: string): readonly string[];
|
|
44
|
+
isPriorityEligible(modelId: string): boolean;
|
|
45
|
+
isTierEligible(modelId: string, tier: string): boolean;
|
|
46
|
+
}
|
|
47
|
+
export type CodexOnPayload = (payload: unknown, model: unknown) => unknown | undefined | Promise<unknown | undefined>;
|
|
48
|
+
export interface CodexFastStreamOptions {
|
|
49
|
+
onPayload?: CodexOnPayload;
|
|
50
|
+
headers?: Record<string, string | null>;
|
|
51
|
+
[key: string]: unknown;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Fast-route composition is default-deny.
|
|
55
|
+
* `isEligible` is required; missing or false means no header and no `service_tier`.
|
|
56
|
+
*/
|
|
57
|
+
export interface CodexFastRoutingOptions {
|
|
58
|
+
readonly isEligible: (modelId: string) => boolean;
|
|
59
|
+
readonly serviceTier?: string;
|
|
60
|
+
/** Distinct profile/route id for the wrapper (e.g. {@link CODEX_OAUTH_FAST_ROUTE}). */
|
|
61
|
+
readonly profileProviderId?: string;
|
|
62
|
+
/** Native provider id restored on `model.provider` before the base wire call. */
|
|
63
|
+
readonly nativeProviderId?: string;
|
|
64
|
+
}
|
|
65
|
+
export interface CodexStreamModel {
|
|
66
|
+
readonly id: string;
|
|
67
|
+
readonly provider?: string;
|
|
68
|
+
readonly [key: string]: unknown;
|
|
69
|
+
}
|
|
70
|
+
/** Structural pi-ai provider face; `never` parameters keep native Provider assignable. */
|
|
71
|
+
export interface CodexStreamableProvider {
|
|
72
|
+
readonly id: string;
|
|
73
|
+
readonly headers?: Record<string, string | null>;
|
|
74
|
+
stream: (model: never, context: never, options?: never) => unknown;
|
|
75
|
+
streamSimple: (model: never, context: never, options?: never) => unknown;
|
|
76
|
+
}
|
|
77
|
+
/** Wrapper face with callable stream methods and a possibly distinct profile id. */
|
|
78
|
+
export type CodexFastWrappedProvider<P extends CodexStreamableProvider> = Omit<P, "id" | "headers" | "stream" | "streamSimple"> & {
|
|
79
|
+
readonly id: string;
|
|
80
|
+
readonly headers?: Record<string, string | null>;
|
|
81
|
+
stream: (model: CodexStreamModel, context: unknown, options?: CodexFastStreamOptions) => unknown;
|
|
82
|
+
streamSimple: (model: CodexStreamModel, context: unknown, options?: CodexFastStreamOptions) => unknown;
|
|
83
|
+
};
|
|
84
|
+
/** Parse the live models envelope. Unknown shapes yield an empty catalog, never a hardcoded fallback. */
|
|
85
|
+
export declare function parseCodexModelCapabilities(value: unknown): CodexModelCapability[];
|
|
86
|
+
export declare function codexModelsUrl(clientVersion: string): string;
|
|
87
|
+
/** Exact per-model Fast header value. Never a bare static `priority`. */
|
|
88
|
+
export declare function codexRoutingHint(modelId: string, tier?: string): string;
|
|
89
|
+
/**
|
|
90
|
+
* Compose an existing `onPayload` with service_tier injection.
|
|
91
|
+
* Does not override a payload that already set `service_tier`.
|
|
92
|
+
* Fail-closed: injection happens only when `isEligible(modelId)` is exactly true.
|
|
93
|
+
*/
|
|
94
|
+
export declare function composeCodexFastOnPayload(inner: CodexOnPayload | undefined, options: CodexFastRoutingOptions): CodexOnPayload;
|
|
95
|
+
/** Merge `x-codex-routing-hint=model=<slug>;tier=<tier>` without dropping existing keys. */
|
|
96
|
+
export declare function composeCodexFastHeaders(headers: Record<string, string | null> | undefined, modelId: string, tier?: string): Record<string, string | null>;
|
|
97
|
+
/** Apply fast-route payload + per-model header composition to one stream-options object. */
|
|
98
|
+
export declare function applyCodexFastStreamOptions<T extends CodexFastStreamOptions>(options: T | undefined, config: CodexFastRoutingOptions, modelId: string): T;
|
|
99
|
+
/**
|
|
100
|
+
* Wrap a pi-ai provider for a future `codex-oauth-fast` route.
|
|
101
|
+
* The original provider object is not mutated. The wrapper may advertise a
|
|
102
|
+
* distinct profile provider id while restoring native `model.provider` so the
|
|
103
|
+
* base wire call and model catalog stay on the native provider.
|
|
104
|
+
*/
|
|
105
|
+
export declare function withCodexFastRouting<P extends CodexStreamableProvider>(provider: P, options: CodexFastRoutingOptions): CodexFastWrappedProvider<P>;
|
|
106
|
+
/**
|
|
107
|
+
* Live `/codex/models` cache. Fetch failures leave ordinary inference alone.
|
|
108
|
+
* Eligibility is false until a live, non-stale catalog explicitly lists the tier.
|
|
109
|
+
* A stale TTL is treated as unknown, not as the last known catalog.
|
|
110
|
+
*/
|
|
111
|
+
export declare function createCodexModelCapabilities(options: CodexModelCapabilitiesOptions): CodexModelCapabilities;
|
|
112
|
+
//# sourceMappingURL=codex-model-capabilities.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"codex-model-capabilities.d.ts","sourceRoot":"","sources":["../../src/codex-model-capabilities.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EACN,KAAK,gBAAgB,EACrB,KAAK,UAAU,EACf,KAAK,eAAe,EAIpB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,sBAAsB,EAAE,MAAM,UAAU,CAAC;AAElD,yEAAyE;AACzE,OAAO,EAAE,sBAAsB,EAAE,CAAC;AAElC,eAAO,MAAM,gBAAgB,iDAAiD,CAAC;AAC/E,eAAO,MAAM,4BAA4B,YAAY,CAAC;AACtD,eAAO,MAAM,0BAA0B,aAAa,CAAC;AACrD,eAAO,MAAM,yBAAyB,yBAAyB,CAAC;AAIhE,MAAM,WAAW,oBAAoB;IACpC,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,YAAY,EAAE,SAAS,MAAM,EAAE,CAAC;CACzC;AAED,MAAM,WAAW,6BAA6B;IAC7C,QAAQ,CAAC,IAAI,EAAE,gBAAgB,CAAC;IAChC,QAAQ,CAAC,IAAI,CAAC,EAAE,eAAe,CAAC;IAChC,QAAQ,CAAC,SAAS,CAAC,EAAE,UAAU,CAAC;IAChC,QAAQ,CAAC,aAAa,CAAC,EAAE,MAAM,CAAC;IAChC,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAC7B,QAAQ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C;AAoBF,yGAAyG;AACzG,wBAAgB,2BAA2B,CAAC,KAAK,EAAE,OAAO,GAAG,oBAAoB,EAAE,CAclF;AAED,wBAAgB,cAAc,CAAC,aAAa,EAAE,MAAM,GAAG,MAAM,CAI5D;AAED,yEAAyE;AACzE,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,SAA6B,GAAG,MAAM,CAE3F;AAmBD;;;;GAIG;AACH,wBAAgB,yBAAyB,CACxC,KAAK,EAAE,cAAc,GAAG,SAAS,EACjC,OAAO,EAAE,uBAAuB,GAC9B,cAAc,CAWhB;AAED,4FAA4F;AAC5F,wBAAgB,uBAAuB,CACtC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC,GAAG,SAAS,EAClD,OAAO,EAAE,MAAM,EACf,IAAI,SAA6B,GAC/B,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC,CAE/B;AAED,4FAA4F;AAC5F,wBAAgB,2BAA2B,CAAC,CAAC,SAAS,sBAAsB,EAC3E,OAAO,EAAE,CAAC,GAAG,SAAS,EACtB,MAAM,EAAE,uBAAuB,EAC/B,OAAO,EAAE,MAAM,GACb,CAAC,CAYH;AAED;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAAC,CAAC,SAAS,uBAAuB,EACrE,QAAQ,EAAE,CAAC,EACX,OAAO,EAAE,uBAAuB,GAC9B,wBAAwB,CAAC,CAAC,CAAC,CAqB7B;AAED;;;;GAIG;AACH,wBAAgB,4BAA4B,CAAC,OAAO,EAAE,6BAA6B,GAAG,sBAAsB,CA8D3G"}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Optional Codex subscription search against the private ChatGPT backend.
|
|
3
|
+
* Default-off: parent registers the returned provider only when the user enables it.
|
|
4
|
+
*
|
|
5
|
+
* @module dsh-coding-subscription-oauth/codex-search
|
|
6
|
+
*/
|
|
7
|
+
import { type CodexAuthSession, type CodexFetch, type CodexHttpClient } from "./codex-http.js";
|
|
8
|
+
/** Stable search-provider id. Parent must not write this into `web.searchProvider` by default. */
|
|
9
|
+
export declare const CODEX_SEARCH_PROVIDER_ID = "codex-oauth-search";
|
|
10
|
+
/** Official Codex standalone search endpoint. */
|
|
11
|
+
export declare const CODEX_SEARCH_URL = "https://chatgpt.com/backend-api/codex/alpha/search";
|
|
12
|
+
export declare const CODEX_SEARCH_CONTEXT_SIZES: readonly ["low", "medium", "high"];
|
|
13
|
+
export type CodexSearchContextSize = (typeof CODEX_SEARCH_CONTEXT_SIZES)[number];
|
|
14
|
+
export declare const CODEX_SEARCH_MODES: readonly ["live", "cached", "indexed"];
|
|
15
|
+
export type CodexSearchMode = (typeof CODEX_SEARCH_MODES)[number];
|
|
16
|
+
export type CodexExternalWebAccess = true | false | "indexed";
|
|
17
|
+
export interface CodexSearchSource {
|
|
18
|
+
readonly url: string;
|
|
19
|
+
readonly title?: string;
|
|
20
|
+
readonly snippet?: string;
|
|
21
|
+
}
|
|
22
|
+
export interface CodexSearchRequest {
|
|
23
|
+
readonly query: string;
|
|
24
|
+
readonly maxResults?: number;
|
|
25
|
+
}
|
|
26
|
+
export interface CodexSearchResult {
|
|
27
|
+
readonly content?: string;
|
|
28
|
+
readonly sources: readonly CodexSearchSource[];
|
|
29
|
+
readonly truncated: boolean;
|
|
30
|
+
}
|
|
31
|
+
export interface CodexSearchRequestBody {
|
|
32
|
+
readonly id: string;
|
|
33
|
+
readonly model: string;
|
|
34
|
+
readonly input: readonly [
|
|
35
|
+
{
|
|
36
|
+
readonly type: "message";
|
|
37
|
+
readonly role: "user";
|
|
38
|
+
readonly content: readonly [{
|
|
39
|
+
readonly type: "input_text";
|
|
40
|
+
readonly text: string;
|
|
41
|
+
}];
|
|
42
|
+
}
|
|
43
|
+
];
|
|
44
|
+
readonly commands: {
|
|
45
|
+
readonly search_query: readonly [{
|
|
46
|
+
readonly q: string;
|
|
47
|
+
}];
|
|
48
|
+
};
|
|
49
|
+
readonly settings: {
|
|
50
|
+
readonly search_context_size: CodexSearchContextSize;
|
|
51
|
+
readonly allowed_callers: readonly ["direct"];
|
|
52
|
+
readonly external_web_access: CodexExternalWebAccess;
|
|
53
|
+
};
|
|
54
|
+
readonly max_output_tokens: number;
|
|
55
|
+
}
|
|
56
|
+
export interface CodexSearchProviderOptions {
|
|
57
|
+
readonly auth: CodexAuthSession;
|
|
58
|
+
readonly http?: CodexHttpClient;
|
|
59
|
+
readonly fetchImpl?: CodexFetch;
|
|
60
|
+
/** Current visible Codex model, or a live resolver for catalog/login changes. */
|
|
61
|
+
readonly model: string | (() => string);
|
|
62
|
+
readonly mode?: CodexSearchMode;
|
|
63
|
+
readonly contextSize?: CodexSearchContextSize;
|
|
64
|
+
readonly maxOutputTokens?: number;
|
|
65
|
+
readonly resolveRequestId?: () => string;
|
|
66
|
+
readonly originator?: string;
|
|
67
|
+
readonly userAgent?: string;
|
|
68
|
+
readonly sleep?: (ms: number, signal?: AbortSignal) => Promise<void>;
|
|
69
|
+
}
|
|
70
|
+
/** Structural `WebSearchProvider` so parent can register without this module importing dsh-web. */
|
|
71
|
+
export interface CodexSearchProvider {
|
|
72
|
+
readonly id: typeof CODEX_SEARCH_PROVIDER_ID;
|
|
73
|
+
available(): boolean;
|
|
74
|
+
search(request: CodexSearchRequest, signal?: AbortSignal): Promise<CodexSearchResult>;
|
|
75
|
+
}
|
|
76
|
+
/** Map configured search mode onto the verified `external_web_access` field. */
|
|
77
|
+
export declare function externalWebAccess(mode: CodexSearchMode): CodexExternalWebAccess;
|
|
78
|
+
/** Accept only citeable http(s) URLs. */
|
|
79
|
+
export declare function citeableHttpUrl(value: unknown): string | undefined;
|
|
80
|
+
/** Reject `<1` / non-finite `maxResults` rather than treating them as unlimited. */
|
|
81
|
+
export declare function assertCodexSearchMaxResults(maxResults: number | undefined): void;
|
|
82
|
+
/**
|
|
83
|
+
* Map the standalone endpoint's forward-compatible result DTOs.
|
|
84
|
+
* Only `type === "text_result"` items with valid http(s) URLs are kept; URLs are de-duplicated.
|
|
85
|
+
*/
|
|
86
|
+
export declare function mapCodexSearchResponse(value: unknown, maxResults?: number): CodexSearchResult;
|
|
87
|
+
export declare function buildCodexSearchRequestBody(query: string, options: {
|
|
88
|
+
id: string;
|
|
89
|
+
model: string;
|
|
90
|
+
mode: CodexSearchMode;
|
|
91
|
+
contextSize: CodexSearchContextSize;
|
|
92
|
+
maxOutputTokens: number;
|
|
93
|
+
}): CodexSearchRequestBody;
|
|
94
|
+
/** Factory for an injectable, default-off Codex search provider. */
|
|
95
|
+
export declare function createCodexSearchProvider(options: CodexSearchProviderOptions): CodexSearchProvider;
|
|
96
|
+
//# sourceMappingURL=codex-search.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"codex-search.d.ts","sourceRoot":"","sources":["../../src/codex-search.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EACN,KAAK,gBAAgB,EACrB,KAAK,UAAU,EACf,KAAK,eAAe,EAIpB,MAAM,iBAAiB,CAAC;AAEzB,kGAAkG;AAClG,eAAO,MAAM,wBAAwB,uBAAuB,CAAC;AAE7D,iDAAiD;AACjD,eAAO,MAAM,gBAAgB,uDAAuD,CAAC;AAErF,eAAO,MAAM,0BAA0B,oCAAqC,CAAC;AAC7E,MAAM,MAAM,sBAAsB,GAAG,CAAC,OAAO,0BAA0B,CAAC,CAAC,MAAM,CAAC,CAAC;AAEjF,eAAO,MAAM,kBAAkB,wCAAyC,CAAC;AACzE,MAAM,MAAM,eAAe,GAAG,CAAC,OAAO,kBAAkB,CAAC,CAAC,MAAM,CAAC,CAAC;AAElE,MAAM,MAAM,sBAAsB,GAAG,IAAI,GAAG,KAAK,GAAG,SAAS,CAAC;AAE9D,MAAM,WAAW,iBAAiB;IACjC,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,OAAO,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;AAED,wBAAgB,2BAA2B,CAC1C,KAAK,EAAE,MAAM,EACb,OAAO,EAAE;IACR,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,eAAe,CAAC;IACtB,WAAW,EAAE,sBAAsB,CAAC;IACpC,eAAe,EAAE,MAAM,CAAC;CACxB,GACC,sBAAsB,CAmBxB;AAED,oEAAoE;AACpE,wBAAgB,yBAAyB,CAAC,OAAO,EAAE,0BAA0B,GAAG,mBAAmB,CAgDlG"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Optional ChatGPT Codex quota reader (`GET /backend-api/wham/usage`).
|
|
3
|
+
* Normalizes unknown/malformed optional fields instead of failing the card.
|
|
4
|
+
*
|
|
5
|
+
* Cache semantics:
|
|
6
|
+
* - A successful `read()` stores the projection until `ttlMs` elapses.
|
|
7
|
+
* - Concurrent non-force `read()` calls share one in-flight GET.
|
|
8
|
+
* - `read({ force: true })` always issues a new GET and never joins an
|
|
9
|
+
* existing in-flight read (forced or not). A later completion of the
|
|
10
|
+
* abandoned in-flight GET cannot overwrite the forced result.
|
|
11
|
+
* - `clear()` drops the stored projection and detaches any in-flight GET so
|
|
12
|
+
* its later completion cannot repopulate the cache.
|
|
13
|
+
*
|
|
14
|
+
* @module dsh-coding-subscription-oauth/codex-usage
|
|
15
|
+
*/
|
|
16
|
+
import { type CodexAuthSession, type CodexFetch, type CodexHttpClient } from "./codex-http.js";
|
|
17
|
+
/** Official ChatGPT rate-limit usage endpoint used by the Codex client. */
|
|
18
|
+
export declare const CODEX_USAGE_URL = "https://chatgpt.com/backend-api/wham/usage";
|
|
19
|
+
export interface CodexRateLimitWindow {
|
|
20
|
+
readonly usedPercent: number;
|
|
21
|
+
readonly remainingPercent: number;
|
|
22
|
+
readonly windowSeconds: number;
|
|
23
|
+
readonly resetsAt?: number;
|
|
24
|
+
}
|
|
25
|
+
export interface CodexRateLimit {
|
|
26
|
+
readonly id: string;
|
|
27
|
+
readonly name?: string;
|
|
28
|
+
readonly windows: readonly CodexRateLimitWindow[];
|
|
29
|
+
}
|
|
30
|
+
export interface CodexCredits {
|
|
31
|
+
readonly unlimited: boolean;
|
|
32
|
+
readonly balance?: string;
|
|
33
|
+
}
|
|
34
|
+
export interface CodexIndividualLimit {
|
|
35
|
+
readonly limit: string;
|
|
36
|
+
readonly used: string;
|
|
37
|
+
readonly remaining?: string;
|
|
38
|
+
readonly remainingPercent: number;
|
|
39
|
+
readonly resetsAt?: number;
|
|
40
|
+
}
|
|
41
|
+
export interface CodexUsage {
|
|
42
|
+
readonly rateLimits: readonly CodexRateLimit[];
|
|
43
|
+
readonly credits?: CodexCredits;
|
|
44
|
+
readonly individualLimit?: CodexIndividualLimit;
|
|
45
|
+
readonly spendControlReached?: boolean;
|
|
46
|
+
readonly resetCredits?: {
|
|
47
|
+
readonly availableCount: number;
|
|
48
|
+
};
|
|
49
|
+
readonly fetchedAt: number;
|
|
50
|
+
}
|
|
51
|
+
export interface CodexUsageReaderOptions {
|
|
52
|
+
readonly auth: CodexAuthSession;
|
|
53
|
+
readonly http?: CodexHttpClient;
|
|
54
|
+
readonly fetchImpl?: CodexFetch;
|
|
55
|
+
readonly originator?: string;
|
|
56
|
+
readonly userAgent?: string;
|
|
57
|
+
readonly sleep?: (ms: number, signal?: AbortSignal) => Promise<void>;
|
|
58
|
+
readonly now?: () => number;
|
|
59
|
+
readonly ttlMs?: number;
|
|
60
|
+
}
|
|
61
|
+
export interface CodexUsageReader {
|
|
62
|
+
read(options?: {
|
|
63
|
+
force?: boolean;
|
|
64
|
+
signal?: AbortSignal;
|
|
65
|
+
}): Promise<CodexUsage>;
|
|
66
|
+
clear(): void;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Reduce an opaque `wham/usage` payload to a secret-free quota projection.
|
|
70
|
+
* Unknown extra fields are ignored; malformed optional buckets are skipped.
|
|
71
|
+
*/
|
|
72
|
+
export declare function normalizeCodexUsage(value: unknown, fetchedAt?: number): CodexUsage;
|
|
73
|
+
/**
|
|
74
|
+
* Cached, injectable usage reader. Failures do not invent quota numbers.
|
|
75
|
+
*
|
|
76
|
+
* See the module doc for `force` / `clear` cache semantics.
|
|
77
|
+
*/
|
|
78
|
+
export declare function createCodexUsageReader(options: CodexUsageReaderOptions): CodexUsageReader;
|
|
79
|
+
//# sourceMappingURL=codex-usage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"codex-usage.d.ts","sourceRoot":"","sources":["../../src/codex-usage.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAGH,OAAO,EACN,KAAK,gBAAgB,EACrB,KAAK,UAAU,EACf,KAAK,eAAe,EAIpB,MAAM,iBAAiB,CAAC;AAEzB,2EAA2E;AAC3E,eAAO,MAAM,eAAe,+CAA+C,CAAC;AAE5E,MAAM,WAAW,oBAAoB;IACpC,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,gBAAgB,EAAE,MAAM,CAAC;IAClC,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;CAC3B;AAED,MAAM,WAAW,cAAc;IAC9B,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,OAAO,EAAE,SAAS,oBAAoB,EAAE,CAAC;CAClD;AAED,MAAM,WAAW,YAAY;IAC5B,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;IAC5B,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED,MAAM,WAAW,oBAAoB;IACpC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IA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BAAmB,CAAC,KAAK,EAAE,OAAO,EAAE,SAAS,SAAa,GAAG,UAAU,CA2CtF;AAED;;;;GAIG;AACH,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,uBAAuB,GAAG,gBAAgB,CAoDzF"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Anthropic Messages API subset for the local gateway.
|
|
3
|
+
* @module dsh-coding-subscription-oauth/gateway-anthropic-messages
|
|
4
|
+
*/
|
|
5
|
+
import type { IncomingMessage, ServerResponse } from "node:http";
|
|
6
|
+
import { type GatewayBackend } from "./gateway-backend.js";
|
|
7
|
+
export declare function handleAnthropicMessages(req: IncomingMessage, res: ServerResponse, backend: GatewayBackend): Promise<void>;
|
|
8
|
+
//# sourceMappingURL=gateway-anthropic-messages.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gateway-anthropic-messages.d.ts","sourceRoot":"","sources":["../../src/gateway-anthropic-messages.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AACjE,OAAO,EAAE,KAAK,cAAc,EAAwB,MAAM,sBAAsB,CAAC;AAIjF,wBAAsB,uBAAuB,CAC5C,GAAG,EAAE,eAAe,EACpB,GAAG,EAAE,cAAc,EACnB,OAAO,EAAE,cAAc,GACrB,OAAO,CAAC,IAAI,CAAC,CAqEf"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Owner-only gateway API key file.
|
|
3
|
+
* @module dsh-coding-subscription-oauth/gateway-auth
|
|
4
|
+
*/
|
|
5
|
+
export declare const GATEWAY_KEY_FILENAME = ".coding-oauth-gateway.json";
|
|
6
|
+
declare const KEY_FORMAT_VERSION = 1;
|
|
7
|
+
export interface GatewayKeyDocument {
|
|
8
|
+
version: typeof KEY_FORMAT_VERSION;
|
|
9
|
+
apiKey: string;
|
|
10
|
+
enabled?: boolean;
|
|
11
|
+
port?: number;
|
|
12
|
+
}
|
|
13
|
+
export declare function gatewayKeyPath(dshHome?: string): string;
|
|
14
|
+
export declare function generateGatewayApiKey(): string;
|
|
15
|
+
export declare function gatewayKeysEqual(left: string, right: string): boolean;
|
|
16
|
+
export declare function maskGatewayApiKey(apiKey: string): string;
|
|
17
|
+
export declare function loadGatewayKeyDocument(path: string): Promise<GatewayKeyDocument | undefined>;
|
|
18
|
+
export declare function loadOrCreateGatewayApiKey(path: string, configured?: string): Promise<string>;
|
|
19
|
+
export declare function persistGatewayApiKey(path: string, apiKey: string): Promise<void>;
|
|
20
|
+
export declare function persistGatewayKeyDocument(path: string, document: GatewayKeyDocument): Promise<void>;
|
|
21
|
+
export {};
|
|
22
|
+
//# sourceMappingURL=gateway-auth.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gateway-auth.d.ts","sourceRoot":"","sources":["../../src/gateway-auth.ts"],"names":[],"mappings":"AAAA;;;GAGG;AASH,eAAO,MAAM,oBAAoB,+BAA+B,CAAC;AACjE,QAAA,MAAM,kBAAkB,IAAI,CAAC;AAE7B,MAAM,WAAW,kBAAkB;IAClC,OAAO,EAAE,OAAO,kBAAkB,CAAC;IACnC,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,IAAI,CAAC,EAAE,MAAM,CAAC;CACd;AAED,wBAAgB,cAAc,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,CAEvD;AAED,wBAAgB,qBAAqB,IAAI,MAAM,CAE9C;AAED,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAIrE;AAED,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAGxD;AAED,wBAAsB,sBAAsB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,kBAAkB,GAAG,SAAS,CAAC,CA0BlG;AAED,wBAAsB,yBAAyB,CAAC,IAAI,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAelG;AAED,wBAAsB,oBAAoB,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAQtF;AAED,wBAAsB,yBAAyB,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,kBAAkB,GAAG,OAAO,CAAC,IAAI,CAAC,CAGzG"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Session-backed model listing and event streaming for the local gateway.
|
|
3
|
+
* @module dsh-coding-subscription-oauth/gateway-backend
|
|
4
|
+
*/
|
|
5
|
+
import type { Api, Context, Message, Model, ThinkingLevel } from "@earendil-works/pi-ai";
|
|
6
|
+
import { type GatewayChatMessage, type GatewayCompletionRequest, type GatewayStreamPart, type GatewayTool } from "./gateway-protocol.js";
|
|
7
|
+
import type { OAuthProviderSession } from "./oauth-session.js";
|
|
8
|
+
import type { GrokBuildSession } from "./session.js";
|
|
9
|
+
export interface GatewayListedModel {
|
|
10
|
+
id: string;
|
|
11
|
+
owned_by: string;
|
|
12
|
+
}
|
|
13
|
+
export interface GatewayBackend {
|
|
14
|
+
listModels(): Promise<readonly GatewayListedModel[]>;
|
|
15
|
+
stream(request: GatewayCompletionRequest): AsyncIterable<GatewayStreamPart>;
|
|
16
|
+
streamText(modelId: string, messages: readonly GatewayChatMessage[]): AsyncIterable<string>;
|
|
17
|
+
}
|
|
18
|
+
export declare class GatewayRequestError extends Error {
|
|
19
|
+
readonly status: number;
|
|
20
|
+
readonly code: string;
|
|
21
|
+
constructor(status: number, code: string, message: string);
|
|
22
|
+
}
|
|
23
|
+
interface OwnedModel {
|
|
24
|
+
owned_by: string;
|
|
25
|
+
model: Model<Api>;
|
|
26
|
+
stream: (model: Model<Api>, context: Context, options?: {
|
|
27
|
+
reasoning?: ThinkingLevel;
|
|
28
|
+
}) => AsyncIterable<{
|
|
29
|
+
type: string;
|
|
30
|
+
delta?: string;
|
|
31
|
+
errorMessage?: string;
|
|
32
|
+
reason?: string;
|
|
33
|
+
toolCall?: {
|
|
34
|
+
id: string;
|
|
35
|
+
name: string;
|
|
36
|
+
arguments?: unknown;
|
|
37
|
+
};
|
|
38
|
+
partial?: {
|
|
39
|
+
content?: readonly {
|
|
40
|
+
type?: string;
|
|
41
|
+
id?: string;
|
|
42
|
+
name?: string;
|
|
43
|
+
}[];
|
|
44
|
+
};
|
|
45
|
+
}>;
|
|
46
|
+
}
|
|
47
|
+
export declare function createSessionGatewayBackend(grok: GrokBuildSession, subscriptions: readonly OAuthProviderSession[]): GatewayBackend;
|
|
48
|
+
export declare function selectOwnedModel(owned: readonly OwnedModel[], modelId: string): OwnedModel;
|
|
49
|
+
export declare function buildGatewayContext(messages: readonly GatewayChatMessage[], tools?: readonly GatewayTool[]): Context;
|
|
50
|
+
export declare function assistantReplay(message: GatewayChatMessage): Message;
|
|
51
|
+
export declare function gatewayErrorEnvelope(error: unknown): {
|
|
52
|
+
status: number;
|
|
53
|
+
body: {
|
|
54
|
+
error: {
|
|
55
|
+
message: string;
|
|
56
|
+
type: string;
|
|
57
|
+
code: string;
|
|
58
|
+
};
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
export {};
|
|
62
|
+
//# sourceMappingURL=gateway-backend.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gateway-backend.d.ts","sourceRoot":"","sources":["../../src/gateway-backend.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,GAAG,EAAE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,aAAa,EAAQ,MAAM,uBAAuB,CAAC;AAC/F,OAAO,EACN,KAAK,kBAAkB,EACvB,KAAK,wBAAwB,EAC7B,KAAK,iBAAiB,EACtB,KAAK,WAAW,EAEhB,MAAM,uBAAu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OAAO,CAAC,EAAE;YAAE,OAAO,CAAC,EAAE,SAAS;gBAAE,IAAI,CAAC,EAAE,MAAM,CAAC;gBAAC,EAAE,CAAC,EAAE,MAAM,CAAC;gBAAC,IAAI,CAAC,EAAE,MAAM,CAAA;aAAE,EAAE,CAAA;SAAE,CAAC;KACjF,CAAC,CAAC;CACH;AAWD,wBAAgB,2BAA2B,CAC1C,IAAI,EAAE,gBAAgB,EACtB,aAAa,EAAE,SAAS,oBAAoB,EAAE,GAC5C,cAAc,CAuDhB;AAED,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,SAAS,UAAU,EAAE,EAAE,OAAO,EAAE,MAAM,GAAG,UAAU,CAQ1F;AAED,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,SAAS,kBAAkB,EAAE,EAAE,KAAK,CAAC,EAAE,SAAS,WAAW,EAAE,GAAG,OAAO,CA4BpH;AAED,wBAAgB,eAAe,CAAC,OAAO,EAAE,kBAAkB,GAAG,OAAO,CA8BpE;AAiED,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,OAAO,GAAG;IACrD,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE;QAAE,KAAK,EAAE;YAAE,OAAO,EAAE,MAAM,CAAC;YAAC,IAAI,EAAE,MAAM,CAAC;YAAC,IAAI,EAAE,MAAM,CAAA;SAAE,CAAA;KAAE,CAAC;CACjE,CAWA"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared JSON body reader for isolated gateway endpoints.
|
|
3
|
+
* @module dsh-coding-subscription-oauth/gateway-body
|
|
4
|
+
*/
|
|
5
|
+
import type { IncomingMessage } from "node:http";
|
|
6
|
+
export declare function readGatewayJsonBody(req: IncomingMessage): Promise<Record<string, unknown>>;
|
|
7
|
+
export declare function writeGatewayJson(res: import("node:http").ServerResponse, status: number, value: unknown): void;
|
|
8
|
+
export declare function beginGatewaySse(res: import("node:http").ServerResponse): void;
|
|
9
|
+
//# sourceMappingURL=gateway-body.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gateway-body.d.ts","sourceRoot":"","sources":["../../src/gateway-body.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAKjD,wBAAsB,mBAAmB,CAAC,GAAG,EAAE,eAAe,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAoBhG;AAED,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,OAAO,WAAW,EAAE,cAAc,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,IAAI,CAQ9G;AAED,wBAAgB,eAAe,CAAC,GAAG,EAAE,OAAO,WAAW,EAAE,cAAc,GAAG,IAAI,CAM7E"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Opt-in local API gateway configuration.
|
|
3
|
+
* @module dsh-coding-subscription-oauth/gateway-config
|
|
4
|
+
*/
|
|
5
|
+
import z from "@deepseek-ai/schemastery";
|
|
6
|
+
export declare const GATEWAY_DEFAULT_BIND = "127.0.0.1";
|
|
7
|
+
export declare const GATEWAY_DEFAULT_PORT = 18080;
|
|
8
|
+
export declare const GATEWAY_MIN_PORT = 1024;
|
|
9
|
+
export declare const GATEWAY_MAX_PORT = 65535;
|
|
10
|
+
export declare const GATEWAY_RANDOM_PORT_MIN = 18100;
|
|
11
|
+
export declare const GATEWAY_RANDOM_PORT_MAX = 18999;
|
|
12
|
+
export interface GatewayConfig {
|
|
13
|
+
readonly enabled: boolean;
|
|
14
|
+
readonly bind: string;
|
|
15
|
+
readonly port: number;
|
|
16
|
+
readonly apiKey?: string;
|
|
17
|
+
readonly rateLimit: number;
|
|
18
|
+
}
|
|
19
|
+
export declare const GatewayConfigSchema: z<Partial<GatewayConfig>>;
|
|
20
|
+
export declare function resolveGatewayConfig(raw?: Partial<GatewayConfig>): GatewayConfig;
|
|
21
|
+
export declare function isLoopbackBind(bind: string): boolean;
|
|
22
|
+
export declare function assertGatewayPort(port: number): number;
|
|
23
|
+
export declare function randomGatewayPort(exclude?: number | readonly number[]): number;
|
|
24
|
+
//# sourceMappingURL=gateway-config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gateway-config.d.ts","sourceRoot":"","sources":["../../src/gateway-config.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,CAAC,MAAM,0BAA0B,CAAC;AAEzC,eAAO,MAAM,oBAAoB,cAAc,CAAC;AAChD,eAAO,MAAM,oBAAoB,QAAS,CAAC;AAC3C,eAAO,MAAM,gBAAgB,OAAO,CAAC;AACrC,eAAO,MAAM,gBAAgB,QAAS,CAAC;AACvC,eAAO,MAAM,uBAAuB,QAAS,CAAC;AAC9C,eAAO,MAAM,uBAAuB,QAAS,CAAC;AAG9C,MAAM,WAAW,aAAa;IAC7B,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;CAC3B;AAED,eAAO,MAAM,mBAAmB,EAAE,CAAC,CAAC,OAAO,CAAC,aAAa,CAAC,CAMxD,CAAC;AAEH,wBAAgB,oBAAoB,CAAC,GAAG,CAAC,EAAE,OAAO,CAAC,aAAa,CAAC,GAAG,aAAa,CAmBhF;AAED,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAEpD;AAED,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAOtD;AAED,wBAAgB,iBAAiB,CAAC,OAAO,GAAE,MAAM,GAAG,SAAS,MAAM,EAAO,GAAG,MAAM,CAUlF"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Isolated node:http server for the opt-in local gateway.
|
|
3
|
+
* @module dsh-coding-subscription-oauth/gateway-http
|
|
4
|
+
*/
|
|
5
|
+
import { type Server } from "node:http";
|
|
6
|
+
import { type GatewayBackend } from "./gateway-backend.js";
|
|
7
|
+
import { type GatewayConfig } from "./gateway-config.js";
|
|
8
|
+
export interface GatewayHttpOptions {
|
|
9
|
+
config: GatewayConfig;
|
|
10
|
+
apiKey: string;
|
|
11
|
+
backend: GatewayBackend;
|
|
12
|
+
}
|
|
13
|
+
export declare function createGatewayHttpServer(options: GatewayHttpOptions): Server;
|
|
14
|
+
export declare function listenGateway(server: Server, config: GatewayConfig): Promise<void>;
|
|
15
|
+
export declare function closeGateway(server: Server): Promise<void>;
|
|
16
|
+
//# sourceMappingURL=gateway-http.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gateway-http.d.ts","sourceRoot":"","sources":["../../src/gateway-http.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAsC,KAAK,MAAM,EAAuB,MAAM,WAAW,CAAC;AAGjG,OAAO,EAAE,KAAK,cAAc,EAAwB,MAAM,sBAAsB,CAAC;AACjF,OAAO,EAAE,KAAK,aAAa,EAAkB,MAAM,qBAAqB,CAAC;AAIzE,MAAM,WAAW,kBAAkB;IAClC,MAAM,EAAE,aAAa,CAAC;IACtB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,cAAc,CAAC;CACxB;AAED,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,kBAAkB,GAAG,MAAM,CAc3E;AAED,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC,CAQlF;AAED,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAO1D"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OpenAI-compatible chat completions for the local gateway.
|
|
3
|
+
* @module dsh-coding-subscription-oauth/gateway-openai-chat
|
|
4
|
+
*/
|
|
5
|
+
import type { IncomingMessage, ServerResponse } from "node:http";
|
|
6
|
+
import { type GatewayBackend } from "./gateway-backend.js";
|
|
7
|
+
export declare function handleOpenAiChatCompletions(req: IncomingMessage, res: ServerResponse, backend: GatewayBackend): Promise<void>;
|
|
8
|
+
//# sourceMappingURL=gateway-openai-chat.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gateway-openai-chat.d.ts","sourceRoot":"","sources":["../../src/gateway-openai-chat.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AACjE,OAAO,EAAE,KAAK,cAAc,EAAwB,MAAM,sBAAsB,CAAC;AAKjF,wBAAsB,2BAA2B,CAChD,GAAG,EAAE,eAAe,EACpB,GAAG,EAAE,cAAc,EACnB,OAAO,EAAE,cAAc,GACrB,OAAO,CAAC,IAAI,CAAC,CAoCf"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OpenAI Responses API subset for the local gateway.
|
|
3
|
+
* @module dsh-coding-subscription-oauth/gateway-openai-responses
|
|
4
|
+
*/
|
|
5
|
+
import type { IncomingMessage, ServerResponse } from "node:http";
|
|
6
|
+
import { type GatewayBackend } from "./gateway-backend.js";
|
|
7
|
+
export declare function handleOpenAiResponses(req: IncomingMessage, res: ServerResponse, backend: GatewayBackend): Promise<void>;
|
|
8
|
+
//# sourceMappingURL=gateway-openai-responses.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gateway-openai-responses.d.ts","sourceRoot":"","sources":["../../src/gateway-openai-responses.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AACjE,OAAO,EAAE,KAAK,cAAc,EAAwB,MAAM,sBAAsB,CAAC;AAIjF,wBAAsB,qBAAqB,CAC1C,GAAG,EAAE,eAAe,EACpB,GAAG,EAAE,cAAc,EACnB,OAAO,EAAE,cAAc,GACrB,OAAO,CAAC,IAAI,CAAC,CAsCf"}
|