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,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Package-owned invariant companion for `dsh-coding-subscription-oauth`.
|
|
3
|
+
* @module dsh-coding-subscription-oauth/invariant
|
|
4
|
+
*/
|
|
5
|
+
import type { Context } from "@deepseek-ai/cordis";
|
|
6
|
+
export declare const name = "grok-build-invariant";
|
|
7
|
+
export declare const inject: string[];
|
|
8
|
+
export declare const apply: (ctx: Context) => Promise<() => void>;
|
|
9
|
+
//# sourceMappingURL=invariant.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"invariant.d.ts","sourceRoot":"","sources":["../../src/invariant.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAKnD,eAAO,MAAM,IAAI,yBAAyB,CAAC;AAC3C,eAAO,MAAM,MAAM,UAAiB,CAAC;AAIrC,eAAO,MAAM,KAAK,GAAI,KAAK,OAAO,KAAG,OAAO,CAAC,MAAM,IAAI,CACS,CAAC"}
|
package/lib/invariant.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/** dsh-coding-subscription-oauth invariant entry */
|
|
2
|
+
|
|
3
|
+
// src/invariant.ts
|
|
4
|
+
var PACKAGE_NAME = "dsh-coding-subscription-oauth";
|
|
5
|
+
var name = "grok-build-invariant";
|
|
6
|
+
var inject = ["invariants"];
|
|
7
|
+
var install = () => {
|
|
8
|
+
};
|
|
9
|
+
var apply = (ctx) => Promise.resolve(ctx.invariants.register(PACKAGE_NAME, install));
|
|
10
|
+
export {
|
|
11
|
+
apply,
|
|
12
|
+
inject,
|
|
13
|
+
name
|
|
14
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/invariant.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * Package-owned invariant companion for `dsh-coding-subscription-oauth`.\n * @module dsh-coding-subscription-oauth/invariant\n */\n\nimport type { Context } from \"@deepseek-ai/cordis\";\nimport type { InvariantInstaller } from \"@deepseek-ai/dsh-invariants\";\n\nconst PACKAGE_NAME = \"dsh-coding-subscription-oauth\";\n\nexport const name = \"grok-build-invariant\";\nexport const inject = [\"invariants\"];\n\nconst install: InvariantInstaller = () => {};\n\nexport const apply = (ctx: Context): Promise<() => void> =>\n\tPromise.resolve(ctx.invariants.register(PACKAGE_NAME, install));\n"],
|
|
5
|
+
"mappings": ";;;AAQA,IAAM,eAAe;AAEd,IAAM,OAAO;AACb,IAAM,SAAS,CAAC,YAAY;AAEnC,IAAM,UAA8B,MAAM;AAAC;AAEpC,IAAM,QAAQ,CAAC,QACrB,QAAQ,QAAQ,IAAI,WAAW,SAAS,cAAc,OAAO,CAAC;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Kimi Code error remapping.
|
|
3
|
+
* @module dsh-coding-subscription-oauth/kimi-errors
|
|
4
|
+
*/
|
|
5
|
+
export declare function isMisclassifiedContextWindowError(detail: string): boolean;
|
|
6
|
+
export declare function remapAuthFailureIfContextOverflow(failure: {
|
|
7
|
+
message: string;
|
|
8
|
+
code: string;
|
|
9
|
+
}): {
|
|
10
|
+
message: string;
|
|
11
|
+
code: string;
|
|
12
|
+
};
|
|
13
|
+
//# sourceMappingURL=kimi-errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"kimi-errors.d.ts","sourceRoot":"","sources":["../../src/kimi-errors.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAYH,wBAAgB,iCAAiC,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAEzE;AAED,wBAAgB,iCAAiC,CAAC,OAAO,EAAE;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAAG;IAC9F,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;CACb,CAGA"}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Owner-private content-addressed store for Grok Imagine video artifacts.
|
|
3
|
+
* Public identifiers are opaque; callers never receive a filesystem path,
|
|
4
|
+
* content hash, or a signed upstream URL.
|
|
5
|
+
* @module dsh-coding-subscription-oauth/media-store
|
|
6
|
+
*/
|
|
7
|
+
/** Hard ceiling for one artifact and for aggregate stored object bytes. */
|
|
8
|
+
export declare const MEDIA_STORE_MAX_BYTES: number;
|
|
9
|
+
/** Hard ceiling for artifact retention. Callers cannot raise this. */
|
|
10
|
+
export declare const MEDIA_STORE_RETENTION_MS: number;
|
|
11
|
+
export declare const MEDIA_STORE_DIR_MODE = 448;
|
|
12
|
+
export declare const MEDIA_STORE_FILE_MODE = 384;
|
|
13
|
+
export declare const MEDIA_STORE_INDEX_VERSION = 1;
|
|
14
|
+
export declare const MEDIA_STORE_INDEX_MAX_BYTES: number;
|
|
15
|
+
/** Opaque public id: 32 lowercase hex characters. */
|
|
16
|
+
export declare const MEDIA_ARTIFACT_ID_PATTERN: RegExp;
|
|
17
|
+
export declare const IMAGINE_MEDIA_ROUTE_PREFIX = "/plugins/dsh-grok-build/imagine/media/";
|
|
18
|
+
declare const TRUSTED_IMAGINE: unique symbol;
|
|
19
|
+
export type MediaStoreVideoType = "video/mp4" | "video/webm";
|
|
20
|
+
export type MediaStoreErrorCode = "INVALID_ID" | "INVALID_INPUT" | "TOO_LARGE" | "NOT_FOUND" | "EXPIRED" | "CORRUPT" | "UNSUPPORTED_TYPE" | "FORBIDDEN";
|
|
21
|
+
export declare class MediaStoreError extends Error {
|
|
22
|
+
readonly code: MediaStoreErrorCode;
|
|
23
|
+
constructor(code: MediaStoreErrorCode, message: string, options?: {
|
|
24
|
+
cause?: unknown;
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
export interface MediaArtifactMeta {
|
|
28
|
+
/** Opaque public identifier. Never a path, hash, or bearer URL. */
|
|
29
|
+
artifactId: string;
|
|
30
|
+
mediaType: MediaStoreVideoType;
|
|
31
|
+
bytes: number;
|
|
32
|
+
createdAt: number;
|
|
33
|
+
expiresAt: number;
|
|
34
|
+
name?: string;
|
|
35
|
+
}
|
|
36
|
+
export interface SaveMediaInput {
|
|
37
|
+
data: Uint8Array;
|
|
38
|
+
mediaType: MediaStoreVideoType;
|
|
39
|
+
name?: string;
|
|
40
|
+
}
|
|
41
|
+
export interface StoredMedia {
|
|
42
|
+
meta: MediaArtifactMeta;
|
|
43
|
+
data: Uint8Array;
|
|
44
|
+
}
|
|
45
|
+
export interface MediaCleanupReport {
|
|
46
|
+
expiredArtifacts: number;
|
|
47
|
+
removedObjects: number;
|
|
48
|
+
}
|
|
49
|
+
export interface MediaStoreOptions {
|
|
50
|
+
now?: () => number;
|
|
51
|
+
/** Per-artifact ceiling, capped at {@link MEDIA_STORE_MAX_BYTES}. */
|
|
52
|
+
maxBytes?: number;
|
|
53
|
+
/** Aggregate unique-object ceiling, capped at {@link MEDIA_STORE_MAX_BYTES}. */
|
|
54
|
+
maxTotalBytes?: number;
|
|
55
|
+
retentionMs?: number;
|
|
56
|
+
randomId?: () => string;
|
|
57
|
+
}
|
|
58
|
+
export interface MediaDownloadHeaders {
|
|
59
|
+
"Content-Type": string;
|
|
60
|
+
"Content-Length": string;
|
|
61
|
+
"Content-Disposition": string;
|
|
62
|
+
"Cache-Control": string;
|
|
63
|
+
"X-Content-Type-Options": "nosniff";
|
|
64
|
+
}
|
|
65
|
+
export interface MediaDownloadView {
|
|
66
|
+
meta: MediaArtifactMeta;
|
|
67
|
+
body: Uint8Array;
|
|
68
|
+
headers: MediaDownloadHeaders;
|
|
69
|
+
}
|
|
70
|
+
/** Runtime token proving a route already authorized this download. */
|
|
71
|
+
export interface TrustedImagineAuthz {
|
|
72
|
+
readonly [TRUSTED_IMAGINE]: true;
|
|
73
|
+
}
|
|
74
|
+
export interface CreateTrustedImagineAuthzInput {
|
|
75
|
+
readonly remoteAddress?: string;
|
|
76
|
+
readonly authorized?: boolean;
|
|
77
|
+
}
|
|
78
|
+
/** Reject anything that is not a 32-char lowercase hex artifact id. */
|
|
79
|
+
export declare function parseMediaArtifactId(value: string): string | undefined;
|
|
80
|
+
export declare function isSafeMediaArtifactId(value: string): boolean;
|
|
81
|
+
/** Trusted same-origin path for one stored video artifact. */
|
|
82
|
+
export declare function imagineMediaPath(artifactId: string): string;
|
|
83
|
+
/** Extract a safe artifact id from a same-origin media route. */
|
|
84
|
+
export declare function parseImagineMediaPath(pathname: string): string | undefined;
|
|
85
|
+
export declare function mediaDownloadHeaders(meta: MediaArtifactMeta): MediaDownloadHeaders;
|
|
86
|
+
/** Loopback-only peer check for the parent route gate. */
|
|
87
|
+
export declare function isTrustedImaginePeer(remoteAddress: string | undefined): boolean;
|
|
88
|
+
/** Build a runtime authz token. Raw objects are not accepted by openTrusted helpers. */
|
|
89
|
+
export declare function createTrustedImagineAuthz(input: CreateTrustedImagineAuthzInput): TrustedImagineAuthz;
|
|
90
|
+
export declare function assertTrustedImagineAuthz(authz: TrustedImagineAuthz): void;
|
|
91
|
+
/**
|
|
92
|
+
* Content-addressed video store. Directories are 0700; objects and index
|
|
93
|
+
* documents are 0600. Public lookup uses an opaque id, never the digest.
|
|
94
|
+
*/
|
|
95
|
+
export declare class MediaStore {
|
|
96
|
+
readonly root: string;
|
|
97
|
+
readonly maxBytes: number;
|
|
98
|
+
readonly maxTotalBytes: number;
|
|
99
|
+
retentionMs: number;
|
|
100
|
+
private readonly now;
|
|
101
|
+
private readonly randomId;
|
|
102
|
+
private tail;
|
|
103
|
+
private retentionReconciled;
|
|
104
|
+
constructor(root: string, options?: MediaStoreOptions);
|
|
105
|
+
/**
|
|
106
|
+
* Apply a live retention ceiling under the store lock. Lowering it rewrites
|
|
107
|
+
* existing index expiries and deletes newly expired objects before resolving;
|
|
108
|
+
* raising it affects only artifacts saved after this call.
|
|
109
|
+
*/
|
|
110
|
+
applyRetentionMs(retentionMs: number): Promise<MediaCleanupReport>;
|
|
111
|
+
save(input: SaveMediaInput): Promise<MediaArtifactMeta>;
|
|
112
|
+
lookup(artifactId: string): Promise<MediaArtifactMeta | undefined>;
|
|
113
|
+
read(artifactId: string): Promise<StoredMedia>;
|
|
114
|
+
delete(artifactId: string): Promise<boolean>;
|
|
115
|
+
cleanup(): Promise<MediaCleanupReport>;
|
|
116
|
+
/** Trusted same-origin download primitive. Never returns an upstream URL. */
|
|
117
|
+
openDownload(artifactId: string, authz: TrustedImagineAuthz): Promise<MediaDownloadView>;
|
|
118
|
+
private effectiveExpiresAt;
|
|
119
|
+
private effectiveMeta;
|
|
120
|
+
private runExclusive;
|
|
121
|
+
private saveUnlocked;
|
|
122
|
+
private deleteUnlocked;
|
|
123
|
+
private cleanupUnlocked;
|
|
124
|
+
private readIndex;
|
|
125
|
+
private removeObjectIfUnreferenced;
|
|
126
|
+
}
|
|
127
|
+
/** Open a trusted same-origin download. Requires an explicit authz token. */
|
|
128
|
+
export declare function openTrustedMediaDownload(store: MediaStore, artifactId: string, authz: TrustedImagineAuthz): Promise<MediaDownloadView>;
|
|
129
|
+
export {};
|
|
130
|
+
//# sourceMappingURL=media-store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"media-store.d.ts","sourceRoot":"","sources":["../../src/media-store.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAQH,2EAA2E;AAC3E,eAAO,MAAM,qBAAqB,QAAoB,CAAC;AAEvD,sEAAsE;AACtE,eAAO,MAAM,wBAAwB,QAA0B,CAAC;AAEhE,eAAO,MAAM,oBAAoB,MAAQ,CAAC;AAC1C,eAAO,MAAM,qBAAqB,MAAQ,CAAC;AAC3C,eAAO,MAAM,yBAAyB,IAAI,CAAC;AAC3C,eAAO,MAAM,2BAA2B,QAAY,CAAC;AAErD,qDAAqD;AACrD,eAAO,MAAM,yBAAyB,QAAmB,CAAC;AAE1D,eAAO,MAAM,0BAA0B,2CAA2C,CAAC;AAGnF,QAAA,MAAM,eAAe,eAA8D,CAAC;AAEpF,MAAM,MAAM,mBAAmB,GAAG,WAAW,GAAG,YAAY,CAAC;AAE7D,MAAM,MAAM,mBAAmB,GAC5B,YAAY,GACZ,eAAe,GACf,WAAW,GACX,WAAW,GACX,SAAS,GACT,SAAS,GACT,kBAAkB,GAClB,WAAW,CAAC;AAEf,qBAAa,eAAgB,SAAQ,KAAK;IACzC,QAAQ,CAAC,IAAI,EAAE,mBAAmB,CAAC;gBAEvB,IAAI,EAAE,mBAAmB,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;QAA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IACG,gBAAgB,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,kBAAkB,CAAC;IAwBlE,IAAI,CAAC,KAAK,EAAE,cAAc,GAAG,OAAO,CAAC,iBAAiB,CAAC;IAIvD,MAAM,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,iBAAiB,GAAG,SAAS,CAAC;IAQlE,IAAI,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC;IAyB9C,MAAM,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAI5C,OAAO,IAAI,OAAO,CAAC,kBAAkB,CAAC;IAa5C,6EAA6E;IACvE,YAAY,CAAC,UAAU,EAAE,MAAM,EAAE,KAAK,EAAE,mBAAmB,GAAG,OAAO,CAAC,iBAAiB,CAAC;IAU9F,OAAO,CAAC,kBAAkB;IAI1B,OAAO,CAAC,aAAa;IAIrB,OAAO,CAAC,YAAY;YASN,YAAY;YAgFZ,cAAc;YAkBd,eAAe;YA6Cf,SAAS;YAmBT,0BAA0B;CAgBxC;AAED,6EAA6E;AAC7E,wBAAsB,wBAAwB,CAC7C,KAAK,EAAE,UAAU,EACjB,UAAU,EAAE,MAAM,EAClB,KAAK,EAAE,mBAAmB,GACxB,OAAO,CAAC,iBAAiB,CAAC,CAM5B"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Same-origin Web API for allowlisted CLI OAuth source discovery and
|
|
3
|
+
* two-phase import into destination stores. Preview tickets live only in the
|
|
4
|
+
* process-local session; `peekPreview` supplies ticket.kind as the destination
|
|
5
|
+
* authority before the store lock. Persist happens inside that lock.
|
|
6
|
+
* @module dsh-coding-subscription-oauth/oauth-import-routes
|
|
7
|
+
*/
|
|
8
|
+
import type { IncomingMessage, ServerResponse } from "node:http";
|
|
9
|
+
import { type OAuthImportCommitAction, type OAuthImportSessionOptions, type OAuthSourceCredential, type OAuthSourceDiscovery, type OAuthSourceKind, type OAuthSourcePathOptions } from "./oauth-sources.js";
|
|
10
|
+
export declare const OAUTH_IMPORT_SOURCES_PATH = "/plugins/dsh-grok-build/oauth/sources";
|
|
11
|
+
export declare const OAUTH_IMPORT_PREVIEW_PATH = "/plugins/dsh-grok-build/oauth/sources/preview";
|
|
12
|
+
export declare const OAUTH_IMPORT_COMMIT_PATH = "/plugins/dsh-grok-build/oauth/sources/commit";
|
|
13
|
+
export declare const OAUTH_IMPORT_CANCEL_PATH = "/plugins/dsh-grok-build/oauth/sources/cancel";
|
|
14
|
+
export interface OAuthImportRouteContext {
|
|
15
|
+
webServer: {
|
|
16
|
+
register(route: {
|
|
17
|
+
kind: "exact";
|
|
18
|
+
path: string;
|
|
19
|
+
handler: (request: IncomingMessage, response: ServerResponse) => void | Promise<void>;
|
|
20
|
+
}): () => void;
|
|
21
|
+
};
|
|
22
|
+
effect?(setup: () => () => void | Promise<void>, label?: string): void;
|
|
23
|
+
}
|
|
24
|
+
export interface OAuthImportDestinationStore {
|
|
25
|
+
readonly filename: string;
|
|
26
|
+
modify(providerId: string, fn: (current: OAuthSourceCredential | undefined) => Promise<OAuthSourceCredential | undefined>): Promise<OAuthSourceCredential | undefined>;
|
|
27
|
+
}
|
|
28
|
+
export interface OAuthImportDestination {
|
|
29
|
+
providerId: string;
|
|
30
|
+
store: OAuthImportDestinationStore;
|
|
31
|
+
}
|
|
32
|
+
export type OAuthImportDestinations = {
|
|
33
|
+
[K in OAuthSourceKind]: OAuthImportDestination;
|
|
34
|
+
};
|
|
35
|
+
export interface OAuthImportAppliedEvent {
|
|
36
|
+
kind: OAuthSourceKind;
|
|
37
|
+
action: Extract<OAuthImportCommitAction, "imported" | "overwritten">;
|
|
38
|
+
}
|
|
39
|
+
export interface OAuthImportRouteOptions extends OAuthImportSessionOptions, OAuthSourcePathOptions {
|
|
40
|
+
onImported?: (event: OAuthImportAppliedEvent) => void | Promise<void>;
|
|
41
|
+
}
|
|
42
|
+
export interface OAuthImportSourcesResponse {
|
|
43
|
+
sources: OAuthSourceDiscovery[];
|
|
44
|
+
}
|
|
45
|
+
export interface OAuthImportCancelResult {
|
|
46
|
+
ok: true;
|
|
47
|
+
cancelled: boolean;
|
|
48
|
+
}
|
|
49
|
+
/** Register same-origin CLI source import routes when the Web server is composed. */
|
|
50
|
+
export declare function registerOAuthImportRoutes(ctx: OAuthImportRouteContext, destinations: OAuthImportDestinations, options?: OAuthImportRouteOptions): () => void;
|
|
51
|
+
export declare function oauthImportErrorStatus(error: unknown): number;
|
|
52
|
+
//# sourceMappingURL=oauth-import-routes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"oauth-import-routes.d.ts","sourceRoot":"","sources":["../../src/oauth-import-routes.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAEjE,OAAO,EAIN,KAAK,uBAAuB,EAI5B,KAAK,yBAAyB,EAC9B,KAAK,qBAAqB,EAC1B,KAAK,oBAAoB,EAGzB,KAAK,eAAe,EACpB,KAAK,sBAAsB,EAC3B,MAAM,oBAAoB,CAAC;AAK5B,eAAO,MAAM,yBAAyB,0CAA0C,CAAC;AACjF,eAAO,MAAM,yBAAyB,kDAAkD,CAAC;AACzF,eAAO,MAAM,wBAAwB,iDAAiD,CAAC;AACvF,eAAO,MAAM,wBAAwB,iDAAiD,CAAC;AAEvF,MAAM,WAAW,uBAAuB;IACvC,SAAS,EAAE;QACV,QAAQ,CAAC,KAAK,EAAE;YACf,IAAI,EAAE,OAAO,CAAC;YACd,IAAI,EAAE,MAAM,CAAC;YACb,OAAO,EAAE,CAAC,OAAO,EAAE,eAAe,EAAE,QAAQ,EAAE,cAAc,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;SACtF,GAAG,MAAM,IAAI,CAAC;KACf,CAAC;IACF,MAAM,CAAC,CAAC,KAAK,EAAE,MAAM,MAAM,IAAI,GAAG,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/**
|
|
2
|
+
* Native pi-ai OAuth providers and their stable Harness route aliases.
|
|
3
|
+
* @module dsh-coding-subscription-oauth/oauth-providers
|
|
4
|
+
*/
|
|
5
|
+
import type { Api, Provider } from "@earendil-works/pi-ai";
|
|
6
|
+
import { type CodingOAuthProviderSlug } from "./ids.js";
|
|
7
|
+
export type SubscriptionProviderSlug = Exclude<CodingOAuthProviderSlug, "grok">;
|
|
8
|
+
export type SubscriptionLoginMethod = "browser" | "device";
|
|
9
|
+
export interface OAuthProviderDefinition {
|
|
10
|
+
slug: SubscriptionProviderSlug;
|
|
11
|
+
route: string;
|
|
12
|
+
nativeProviderId: string;
|
|
13
|
+
displayName: string;
|
|
14
|
+
authFilename: string;
|
|
15
|
+
modelsCacheFilename: string;
|
|
16
|
+
loginMethods: readonly SubscriptionLoginMethod[];
|
|
17
|
+
recommendedLoginMethod: SubscriptionLoginMethod;
|
|
18
|
+
providerFactory(): Provider<Api>;
|
|
19
|
+
requestProvider(selectedIds?: readonly string[]): Provider<Api>;
|
|
20
|
+
}
|
|
21
|
+
export declare const CODEX_OAUTH_PROVIDER: OAuthProviderDefinition;
|
|
22
|
+
export declare const KIMI_CODE_OAUTH_PROVIDER: OAuthProviderDefinition;
|
|
23
|
+
export declare const CLAUDE_CODE_OAUTH_PROVIDER: OAuthProviderDefinition;
|
|
24
|
+
export declare const OAUTH_PROVIDER_DEFINITIONS: readonly [OAuthProviderDefinition, OAuthProviderDefinition, OAuthProviderDefinition];
|
|
25
|
+
export declare function oauthProviderDefinition(slug: string): OAuthProviderDefinition | undefined;
|
|
26
|
+
//# sourceMappingURL=oauth-providers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"oauth-providers.d.ts","sourceRoot":"","sources":["../../src/oauth-providers.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,GAAG,EAAc,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAIvE,OAAO,EASN,KAAK,uBAAuB,EAK5B,MAAM,UAAU,CAAC;AAElB,MAAM,MAAM,wBAAwB,GAAG,OAAO,CAAC,uBAAuB,EAAE,MAAM,CAAC,CAAC;AAChF,MAAM,MAAM,uBAAuB,GAAG,SAAS,GAAG,QAAQ,CAAC;AAE3D,MAAM,WAAW,uBAAuB;IACvC,IAAI,EAAE,wBAAwB,CAAC;IAC/B,KAAK,EAAE,MAAM,CAAC;IACd,gBAAgB,EAAE,MAAM,CAAC;IACzB,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC;IACrB,mBAAmB,EAAE,MAAM,CAAC;IAC5B,YAAY,EAAE,SAAS,uBAAuB,EAAE,CAAC;IACjD,sBAAsB,EAAE,uBAAuB,CAAC;IAChD,eAAe,IAAI,QAAQ,CAAC,GAAG,CAAC,CAAC;IACjC,eAAe,CAAC,WAAW,CAAC,EAAE,SAAS,MAAM,EAAE,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAC;CAChE;AA6DD,eAAO,MAAM,oBAAoB,EAAE,uBAYlC,CAAC;AAEF,eAAO,MAAM,wBAAwB,EAAE,uBActC,CAAC;AAEF,eAAO,MAAM,0BAA0B,EAAE,uBAWxC,CAAC;AAEF,eAAO,MAAM,0BAA0B,sFAI7B,CAAC;AAEX,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,MAAM,GAAG,uBAAuB,GAAG,SAAS,CAEzF"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Persistent OAuth session and static model selection for one subscription provider.
|
|
3
|
+
* @module dsh-coding-subscription-oauth/oauth-session
|
|
4
|
+
*/
|
|
5
|
+
import type { Api, AuthInteraction, Credential, Model, MutableModels, OAuthCredential, Provider } from "@earendil-works/pi-ai";
|
|
6
|
+
import type { OAuthProviderDefinition } from "./oauth-providers.js";
|
|
7
|
+
import { OAuthCredentialFileStore } from "./store.js";
|
|
8
|
+
export declare function oauthModelsCachePath(basename: string, dshHome?: string): string;
|
|
9
|
+
export interface OAuthProviderStatus {
|
|
10
|
+
authenticated: boolean;
|
|
11
|
+
expiresAt?: number;
|
|
12
|
+
}
|
|
13
|
+
export declare class OAuthProviderSession {
|
|
14
|
+
readonly definition: OAuthProviderDefinition;
|
|
15
|
+
readonly store: OAuthCredentialFileStore;
|
|
16
|
+
readonly models: MutableModels;
|
|
17
|
+
private readonly catalog;
|
|
18
|
+
private readonly cacheFile;
|
|
19
|
+
private selectedIds;
|
|
20
|
+
constructor(definition: OAuthProviderDefinition, onCatalogChange?: () => void, store?: OAuthCredentialFileStore, cacheFile?: string);
|
|
21
|
+
private onCatalogChange;
|
|
22
|
+
availableModels(): Model<Api>[];
|
|
23
|
+
selectedModelIds(): string[] | undefined;
|
|
24
|
+
visibleModels(): Model<Api>[];
|
|
25
|
+
provider(): Provider;
|
|
26
|
+
loadCachedModels(): Promise<void>;
|
|
27
|
+
setSelectedModels(ids: readonly string[]): Promise<void>;
|
|
28
|
+
status(): Promise<OAuthProviderStatus>;
|
|
29
|
+
login(interaction: AuthInteraction): Promise<Credential>;
|
|
30
|
+
resolveAccessToken(): Promise<string | undefined>;
|
|
31
|
+
/**
|
|
32
|
+
* Backdate the stored token's expiry so the next `getAuth()` refreshes.
|
|
33
|
+
* Called after an upstream 401 rejected a locally-valid token.
|
|
34
|
+
*/
|
|
35
|
+
invalidateAccessToken(): Promise<void>;
|
|
36
|
+
storedCredential(): Promise<OAuthCredential | undefined>;
|
|
37
|
+
logout(): Promise<void>;
|
|
38
|
+
private writeCache;
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=oauth-session.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"oauth-session.d.ts","sourceRoot":"","sources":["../../src/oauth-session.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAMH,OAAO,KAAK,EACX,GAAG,EACH,eAAe,EACf,UAAU,EACV,KAAK,EACL,aAAa,EACb,eAAe,EACf,QAAQ,EACR,MAAM,uBAAuB,CA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AAI,OAAO,CAAC,IAAI,CAAC;IAItC,gBAAgB,IAAI,OAAO,CAAC,eAAe,GAAG,SAAS,CAAC;IAKxD,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC;YAaf,UAAU;CAWxB"}
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Allowlisted CLI OAuth source discovery, hardened reads, exact parsers, and
|
|
3
|
+
* two-phase preview/commit primitives. The HTTP routes and destination stores
|
|
4
|
+
* stay outside this module so the parent can wire them later.
|
|
5
|
+
* @module dsh-coding-subscription-oauth/oauth-sources
|
|
6
|
+
*/
|
|
7
|
+
import { type CodingOAuthProviderSlug } from "./ids.js";
|
|
8
|
+
/** Hard ceiling for a CLI source or destination document. */
|
|
9
|
+
export declare const OAUTH_SOURCE_MAX_BYTES: number;
|
|
10
|
+
/** In-memory preview tickets are one-use and live five minutes. */
|
|
11
|
+
export declare const OAUTH_IMPORT_PREVIEW_TTL_MS: number;
|
|
12
|
+
/** Bound credential-bearing preview material retained by one process. */
|
|
13
|
+
export declare const OAUTH_IMPORT_MAX_PREVIEW_TICKETS = 32;
|
|
14
|
+
export type OAuthSourceKind = CodingOAuthProviderSlug;
|
|
15
|
+
export declare const OAUTH_SOURCE_KINDS: readonly ["grok", "codex", "kimi", "claude"];
|
|
16
|
+
export type OAuthImportConflict = "none" | "same_credential" | "same_account" | "different_account" | "unknown_account" | "unreadable_destination" | "unsafe_destination";
|
|
17
|
+
export type OAuthImportPreviewAction = "import" | "reuse" | "overwrite" | "blocked";
|
|
18
|
+
export type OAuthImportCommitAction = "imported" | "unchanged" | "overwritten";
|
|
19
|
+
export type OAuthSourceErrorCode = "not_found" | "unsafe_source" | "too_large" | "invalid_document" | "unsupported" | "preview_expired" | "preview_invalid" | "source_changed" | "destination_changed" | "confirm_required" | "unsafe_destination";
|
|
20
|
+
export type OAuthSourceUnavailableReason = "missing" | "unsafe" | "invalid" | "too_large";
|
|
21
|
+
export type OAuthDestinationStatus = "missing" | "readable" | "unreadable" | "unsafe";
|
|
22
|
+
export interface OAuthSourceCredential {
|
|
23
|
+
type: "oauth";
|
|
24
|
+
access: string;
|
|
25
|
+
refresh: string;
|
|
26
|
+
expires: number;
|
|
27
|
+
accountId?: string;
|
|
28
|
+
}
|
|
29
|
+
export interface OAuthSourceSpec {
|
|
30
|
+
kind: OAuthSourceKind;
|
|
31
|
+
envHome: "GROK_HOME" | "CODEX_HOME" | "KIMI_SHARE_DIR" | "CLAUDE_CONFIG_DIR";
|
|
32
|
+
defaultDir: string;
|
|
33
|
+
relativeFile: string;
|
|
34
|
+
providerId: string;
|
|
35
|
+
}
|
|
36
|
+
export interface OAuthSourcePathOptions {
|
|
37
|
+
env?: NodeJS.Dict<string>;
|
|
38
|
+
home?: string;
|
|
39
|
+
}
|
|
40
|
+
export interface OAuthSourceFileIdentity {
|
|
41
|
+
dev: number;
|
|
42
|
+
ino: number;
|
|
43
|
+
size: number;
|
|
44
|
+
uid: number;
|
|
45
|
+
mode: number;
|
|
46
|
+
}
|
|
47
|
+
export interface HardenedOAuthSourceRead {
|
|
48
|
+
path: string;
|
|
49
|
+
text: string;
|
|
50
|
+
identity: OAuthSourceFileIdentity;
|
|
51
|
+
}
|
|
52
|
+
export interface OAuthSourceDiscovery {
|
|
53
|
+
kind: OAuthSourceKind;
|
|
54
|
+
displayPath: string;
|
|
55
|
+
available: boolean;
|
|
56
|
+
expiresAt?: number;
|
|
57
|
+
reason?: OAuthSourceUnavailableReason;
|
|
58
|
+
}
|
|
59
|
+
export interface OAuthSourceProbe {
|
|
60
|
+
kind: OAuthSourceKind;
|
|
61
|
+
available: boolean;
|
|
62
|
+
displayPath: string;
|
|
63
|
+
expiresAt?: number;
|
|
64
|
+
reason?: OAuthSourceUnavailableReason;
|
|
65
|
+
}
|
|
66
|
+
export interface OAuthImportDestinationView {
|
|
67
|
+
path?: string;
|
|
68
|
+
status?: OAuthDestinationStatus;
|
|
69
|
+
credential?: OAuthSourceCredential;
|
|
70
|
+
revision?: string;
|
|
71
|
+
}
|
|
72
|
+
export interface OAuthDestinationInspection {
|
|
73
|
+
status: OAuthDestinationStatus;
|
|
74
|
+
identity?: OAuthSourceFileIdentity;
|
|
75
|
+
/** Internal. Never serialize this field to a client. */
|
|
76
|
+
credential?: OAuthSourceCredential;
|
|
77
|
+
/** Internal digest of unreadable dest bytes. Never serialize this field to a client. */
|
|
78
|
+
payloadMac?: string;
|
|
79
|
+
}
|
|
80
|
+
export interface OAuthImportPreview {
|
|
81
|
+
previewId: string;
|
|
82
|
+
kind: OAuthSourceKind;
|
|
83
|
+
displayPath: string;
|
|
84
|
+
expiresAt: number;
|
|
85
|
+
ticketExpiresAt: number;
|
|
86
|
+
conflict: OAuthImportConflict;
|
|
87
|
+
action: OAuthImportPreviewAction;
|
|
88
|
+
warnings: string[];
|
|
89
|
+
confirmOverwriteRequired: boolean;
|
|
90
|
+
}
|
|
91
|
+
export interface OAuthImportCommitResult {
|
|
92
|
+
action: OAuthImportCommitAction;
|
|
93
|
+
displayPath: string;
|
|
94
|
+
expiresAt: number;
|
|
95
|
+
warnings: string[];
|
|
96
|
+
}
|
|
97
|
+
export interface OAuthImportSessionOptions {
|
|
98
|
+
now?: () => number;
|
|
99
|
+
ttlMs?: number;
|
|
100
|
+
}
|
|
101
|
+
export interface OAuthImportPreviewInput extends OAuthSourcePathOptions {
|
|
102
|
+
kind: OAuthSourceKind;
|
|
103
|
+
destination?: OAuthImportDestinationView;
|
|
104
|
+
}
|
|
105
|
+
export interface OAuthImportCommitInput extends OAuthSourcePathOptions {
|
|
106
|
+
previewId: string;
|
|
107
|
+
/** When set, must match the ticket kind; a mismatch does not consume the ticket. */
|
|
108
|
+
kind?: OAuthSourceKind;
|
|
109
|
+
confirmOverwrite?: boolean;
|
|
110
|
+
destination?: OAuthImportDestinationView;
|
|
111
|
+
}
|
|
112
|
+
/** Secret-free preview claim used to route a ticket to its destination store. */
|
|
113
|
+
export interface OAuthImportPreviewClaim {
|
|
114
|
+
kind: OAuthSourceKind;
|
|
115
|
+
ticketExpiresAt: number;
|
|
116
|
+
}
|
|
117
|
+
/** Stable allowlist metadata for parent route/store wiring. */
|
|
118
|
+
export declare const OAUTH_SOURCE_SPECS: readonly OAuthSourceSpec[];
|
|
119
|
+
/** Secret-free failure from discovery, parse, preview, or commit. */
|
|
120
|
+
export declare class OAuthSourceError extends Error {
|
|
121
|
+
readonly code: OAuthSourceErrorCode;
|
|
122
|
+
constructor(code: OAuthSourceErrorCode, message: string);
|
|
123
|
+
}
|
|
124
|
+
export declare function isOAuthSourceError(error: unknown): error is OAuthSourceError;
|
|
125
|
+
export declare function isOAuthSourceKind(value: string): value is OAuthSourceKind;
|
|
126
|
+
export declare function oauthSourceSpec(kind: OAuthSourceKind): OAuthSourceSpec;
|
|
127
|
+
export declare function oauthSourceProviderId(kind: OAuthSourceKind): string;
|
|
128
|
+
/** Resolve one allowlisted CLI auth document. Env/home are injectable for tests. */
|
|
129
|
+
export declare function resolveOAuthSourcePath(kind: OAuthSourceKind, options?: OAuthSourcePathOptions): string;
|
|
130
|
+
/**
|
|
131
|
+
* Client-safe display path. Never returns an absolute filesystem location.
|
|
132
|
+
* Env overrides render as `$GROK_HOME/auth.json`; defaults as `~/.grok/auth.json`.
|
|
133
|
+
*/
|
|
134
|
+
export declare function oauthSourceDisplayPath(kind: OAuthSourceKind, options?: OAuthSourcePathOptions): string;
|
|
135
|
+
export declare function oauthImportRequiresConfirm(conflict: OAuthImportConflict): boolean;
|
|
136
|
+
export declare function oauthImportPreviewAction(conflict: OAuthImportConflict): OAuthImportPreviewAction;
|
|
137
|
+
/**
|
|
138
|
+
* lstat → O_NOFOLLOW open → fstat. Rejects symlinks, non-regular files, non-owner
|
|
139
|
+
* files, group/other access, TOCTOU identity changes, and payloads over 64KiB.
|
|
140
|
+
* POSIX fails closed if O_NOFOLLOW or the process uid is unavailable. Windows
|
|
141
|
+
* skips POSIX uid/mode owner checks but still applies identity and size limits.
|
|
142
|
+
* Never chmod()s or writes the path.
|
|
143
|
+
*/
|
|
144
|
+
export declare function readHardenedOAuthSourceFile(filename: string): Promise<HardenedOAuthSourceRead>;
|
|
145
|
+
/** Inspect a destination store file with the same hardened reader. Never follows dest. */
|
|
146
|
+
export declare function inspectOAuthDestinationFile(filename: string): Promise<OAuthDestinationInspection>;
|
|
147
|
+
export declare function parseOAuthSourceDocument(kind: OAuthSourceKind, text: string): OAuthSourceCredential;
|
|
148
|
+
/**
|
|
149
|
+
* Grok CLI scope map. Selects the auth.x.ai OIDC entry (`key` + `refresh_token`).
|
|
150
|
+
* Expiry must be a valid RFC3339 `expires_at`. Multiple matching entries pick
|
|
151
|
+
* the latest valid expiry.
|
|
152
|
+
*/
|
|
153
|
+
export declare function parseGrokCliAuthDocument(text: string): OAuthSourceCredential;
|
|
154
|
+
/**
|
|
155
|
+
* Codex CLI `tokens` object. Requires id/access/refresh, JWT `exp` in seconds.
|
|
156
|
+
* Account id prefers official `tokens.account_id`, then top-level `account_id`
|
|
157
|
+
* for compatibility, then the full ChatGPT account id from the access JWT.
|
|
158
|
+
* Rejects API-key documents.
|
|
159
|
+
*/
|
|
160
|
+
export declare function parseCodexCliAuthDocument(text: string): OAuthSourceCredential;
|
|
161
|
+
/** Kimi Code CLI document. Snake_case `access_token` / `refresh_token` / `expires_at` seconds. */
|
|
162
|
+
export declare function parseKimiCliAuthDocument(text: string): OAuthSourceCredential;
|
|
163
|
+
/** Claude Code CLI document. `claudeAiOauth` camelCase `accessToken` / `refreshToken` / `expiresAt` ms. */
|
|
164
|
+
export declare function parseClaudeCliAuthDocument(text: string): OAuthSourceCredential;
|
|
165
|
+
export declare function probeOAuthSource(kind: OAuthSourceKind, options?: OAuthSourcePathOptions): Promise<OAuthSourceProbe>;
|
|
166
|
+
export declare function discoverOAuthSources(options?: OAuthSourcePathOptions): Promise<OAuthSourceDiscovery[]>;
|
|
167
|
+
/**
|
|
168
|
+
* In-memory two-phase import controller. Preview IDs are random, one-use, and
|
|
169
|
+
* expire after five minutes. `peekPreview` exposes only kind + ticket expiry so
|
|
170
|
+
* routes can bind a destination without a second ticket map. HMAC fingerprints
|
|
171
|
+
* and persist material stay internal.
|
|
172
|
+
*/
|
|
173
|
+
export declare class OAuthImportSession {
|
|
174
|
+
#private;
|
|
175
|
+
constructor(options?: OAuthImportSessionOptions);
|
|
176
|
+
discover(options?: OAuthSourcePathOptions): Promise<OAuthSourceDiscovery[]>;
|
|
177
|
+
/**
|
|
178
|
+
* Secret-free peek. Does not consume a live ticket. An expired ticket is
|
|
179
|
+
* deleted and reported as {@link OAuthSourceError} `preview_expired` once.
|
|
180
|
+
*/
|
|
181
|
+
peekPreview(previewId: string): OAuthImportPreviewClaim;
|
|
182
|
+
preview(input: OAuthImportPreviewInput): Promise<OAuthImportPreview>;
|
|
183
|
+
/**
|
|
184
|
+
* Consume the preview, reopen the allowlisted source, and compare the
|
|
185
|
+
* destination revision. Call this from inside the destination store lock.
|
|
186
|
+
* Use {@link OAuthImportCommitOutcome.takePersist} for the write material.
|
|
187
|
+
*/
|
|
188
|
+
commit(input: OAuthImportCommitInput): Promise<OAuthImportCommitOutcome>;
|
|
189
|
+
cancel(previewId: string): boolean;
|
|
190
|
+
}
|
|
191
|
+
/** Public commit result plus hidden persist material. */
|
|
192
|
+
export declare class OAuthImportCommitOutcome {
|
|
193
|
+
#private;
|
|
194
|
+
readonly result: OAuthImportCommitResult;
|
|
195
|
+
constructor(result: OAuthImportCommitResult, persist: OAuthSourceCredential | undefined);
|
|
196
|
+
/** Internal. Write this through the destination store; omit to keep dest canonical. */
|
|
197
|
+
takePersist(): OAuthSourceCredential | undefined;
|
|
198
|
+
toJSON(): OAuthImportCommitResult;
|
|
199
|
+
}
|
|
200
|
+
export declare function createOAuthImportSession(options?: OAuthImportSessionOptions): OAuthImportSession;
|
|
201
|
+
export declare function classifyOAuthImportConflict(incoming: OAuthSourceCredential, destination: {
|
|
202
|
+
status?: OAuthDestinationStatus;
|
|
203
|
+
credential?: OAuthSourceCredential;
|
|
204
|
+
}): OAuthImportConflict;
|
|
205
|
+
//# sourceMappingURL=oauth-sources.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"oauth-sources.d.ts","sourceRoot":"","sources":["../../src/oauth-sources.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAOH,OAAO,EAGN,KAAK,uBAAuB,EAG5B,MAAM,UAAU,CAAC;AAElB,6DAA6D;AAC7D,eAAO,MAAM,sBAAsB,QAAY,CAAC;AAEhD,mEAAmE;AACnE,eAAO,MAAM,2BAA2B,QAAgB,CAAC;AAEzD,yEAAyE;AACzE,eAAO,MAAM,gCAAgC,KAAK,CAAC;AAuCnD,MAAM,MAAM,eAAe,GAAG,uBAAuB,CAAC;AAEtD,eAAO,MAAM,kBAAkB,8CAAoF,CAAC;AAEpH,MAAM,MAAM,mBAAmB,GAC5B,MAAM,GACN,iBAAiB,GACjB,cAAc,GACd,mBAAmB,GACnB,iBAAiB,GACjB,wBAAwB,GACxB,oBAAoB,CAAC;AAExB,MAAM,MAAM,wBAAwB,GAAG,QAAQ,GAAG,OAAO,GAAG,WAAW,GAAG,SAAS,CAAC;AACpF,MAAM,MAAM,uBAAuB,GAAG,UAAU,GAAG,WAAW,GAAG,aAAa,CAAC;AAE/E,MAAM,MAAM,oBAAoB,GAC7B,WAAW,GACX,eAAe,GACf,WAAW,GACX,kBAAkB,GAClB,aAAa,GACb,iBAAiB,GACjB,iBAAiB,GACjB,gBAAgB,GAChB,qBAAqB,GACrB,kBAAkB,GAClB,oBAAoB,CAAC;AAExB,MAAM,MAAM,4BAA4B,GAAG,SAAS,GAAG,QAAQ,GAAG,SAAS,GAAG,WAAW,CAAC;AAC1F,MAAM,MAAM,sBAAsB,GAAG,SAAS,GAAG,UAAU,GAAG,YAAY,GAAG,QAAQ,CAAC;AAEtF,MAAM,WAAW,qBAAqB;IACrC,IAAI,EAAE,OAAO,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC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C,OAAO,GAAE,yBAA8B,GAAG,kBAAkB,CAEpG;AAED,wBAAgB,2BAA2B,CAC1C,QAAQ,EAAE,qBAAqB,EAC/B,WAAW,EAAE;IAAE,MAAM,CAAC,EAAE,sBAAsB,CAAC;IAAC,UAAU,CAAC,EAAE,qBAAqB,CAAA;CAAE,GAClF,mBAAmB,CAarB"}
|
package/lib/oauth.d.ts
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Grok Build OAuth authorization-code + PKCE flow (primary login path).
|
|
3
|
+
*
|
|
4
|
+
* Mirrors the official Grok CLI: OIDC discovery, S256 PKCE, dual-channel code
|
|
5
|
+
* capture (loopback listener + manual paste), form POST token exchange.
|
|
6
|
+
* The device-code flow remains the fallback (see auth.ts / bin.ts).
|
|
7
|
+
* @module dsh-coding-subscription-oauth/oauth
|
|
8
|
+
*/
|
|
9
|
+
import type { OAuthCredential } from "@earendil-works/pi-ai";
|
|
10
|
+
/** OIDC issuer for both Grok CLI and Grok Build. */
|
|
11
|
+
export declare const GROK_BUILD_OAUTH_ISSUER = "https://auth.x.ai";
|
|
12
|
+
/**
|
|
13
|
+
* Public client id known to work for the device flow; reused as the default
|
|
14
|
+
* for the authorization-code flow until the official CLI's own id is
|
|
15
|
+
* confirmed (T2.1). Override with GROK_OAUTH2_CLIENT_ID.
|
|
16
|
+
*/
|
|
17
|
+
export declare const GROK_BUILD_OAUTH_CLIENT_ID = "b1a00492-073a-47ea-816f-4c329264a828";
|
|
18
|
+
/** Scopes the official CLI requests (grok-cli:access = CLI inference pass). */
|
|
19
|
+
export declare const GROK_BUILD_OAUTH_SCOPE = "openid profile email offline_access grok-cli:access api:access";
|
|
20
|
+
/** Default loopback port observed for the official CLI (codex-app-transfer). */
|
|
21
|
+
export declare const GROK_BUILD_OAUTH_DEFAULT_PORT = 56121;
|
|
22
|
+
export type GrokBuildOAuthErrorCode = "discovery" | "loopback" | "state_mismatch" | "token_exchange" | "cancelled" | "timeout";
|
|
23
|
+
/** OAuth failure with a stable, secret-free machine code. */
|
|
24
|
+
export declare class GrokBuildOAuthError extends Error {
|
|
25
|
+
readonly code: GrokBuildOAuthErrorCode;
|
|
26
|
+
constructor(code: GrokBuildOAuthErrorCode, message: string);
|
|
27
|
+
}
|
|
28
|
+
export interface GrokBuildOAuthParams {
|
|
29
|
+
issuer: string;
|
|
30
|
+
clientId: string;
|
|
31
|
+
scope: string;
|
|
32
|
+
/** Loopback port for the redirect URI; falls forward on EADDRINUSE. */
|
|
33
|
+
port: number;
|
|
34
|
+
/** Optional xAI extension parameter. */
|
|
35
|
+
referrer?: string;
|
|
36
|
+
}
|
|
37
|
+
/** Resolve OAuth parameters from overrides then GROK_OAUTH2_* env vars. */
|
|
38
|
+
export declare function resolveOAuthParams(overrides?: Partial<GrokBuildOAuthParams>): GrokBuildOAuthParams;
|
|
39
|
+
interface DiscoveryDocument {
|
|
40
|
+
issuer: string;
|
|
41
|
+
authorization_endpoint: string;
|
|
42
|
+
token_endpoint: string;
|
|
43
|
+
}
|
|
44
|
+
export interface DiscoveryFetchOptions {
|
|
45
|
+
/** Loopback-only test override: permit `http://127.0.0.1`/`http://[::1]` issuers. */
|
|
46
|
+
readonly allowInsecureLoopbackIssuer?: boolean;
|
|
47
|
+
}
|
|
48
|
+
/** Fetch (and cache for the process) the issuer's discovery document. */
|
|
49
|
+
export declare function discoverOAuthEndpoints(issuer: string, signal?: AbortSignal, options?: DiscoveryFetchOptions): Promise<DiscoveryDocument>;
|
|
50
|
+
/** Generate an S256 PKCE verifier/challenge pair (Web Crypto compatible). */
|
|
51
|
+
export declare function generatePkce(): {
|
|
52
|
+
verifier: string;
|
|
53
|
+
challenge: string;
|
|
54
|
+
};
|
|
55
|
+
/** Build the authorization URL for one login attempt. */
|
|
56
|
+
export declare function buildAuthorizeUrl(endpoints: DiscoveryDocument, params: GrokBuildOAuthParams, redirectUri: string, challenge: string, state: string, nonce: string): string;
|
|
57
|
+
/** Exchange a refresh token for a fresh credential (rotation-tolerant). */
|
|
58
|
+
export declare function refreshGrokBuildToken(refreshToken: string, overrides?: Partial<GrokBuildOAuthParams>, signal?: AbortSignal, discoveryOptions?: DiscoveryFetchOptions): Promise<OAuthCredential>;
|
|
59
|
+
export interface PkceLoginCallbacks {
|
|
60
|
+
/** Invoked with the authorization URL to display/open for the user. */
|
|
61
|
+
onAuthorizeUrl(url: string): void;
|
|
62
|
+
/**
|
|
63
|
+
* Manual-paste channel: resolve with the code (or full redirect URL) the
|
|
64
|
+
* user pasted. Return undefined to disable this channel. Rejects on cancel.
|
|
65
|
+
*/
|
|
66
|
+
awaitCode?: (signal: AbortSignal) => Promise<string | undefined>;
|
|
67
|
+
signal?: AbortSignal;
|
|
68
|
+
timeoutMs?: number;
|
|
69
|
+
}
|
|
70
|
+
/** Extract a bare code from user input that may be a full redirect URL. */
|
|
71
|
+
export declare function extractCode(input: string): string;
|
|
72
|
+
/**
|
|
73
|
+
* Run the authorization-code + PKCE login. The code arrives via the loopback
|
|
74
|
+
* listener or the manual-paste channel, whichever wins. The caller persists
|
|
75
|
+
* the returned credential (store.modify under the file lock).
|
|
76
|
+
*/
|
|
77
|
+
export declare function loginGrokBuildPkce(callbacks: PkceLoginCallbacks, overrides?: Partial<GrokBuildOAuthParams & DiscoveryFetchOptions>): Promise<OAuthCredential>;
|
|
78
|
+
export {};
|
|
79
|
+
//# sourceMappingURL=oauth.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"oauth.d.ts","sourceRoot":"","sources":["../../src/oauth.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAMH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAI7D,oDAAoD;AACpD,eAAO,MAAM,uBAAuB,sBAAsB,CAAC;AAY3D;;;;GAIG;AACH,eAAO,MAAM,0BAA0B,yCAAyC,CAAC;AAEjF,+EAA+E;AAC/E,eAAO,MAAM,sBAAsB,mEAAmE,CAAC;AAEvG,gFAAgF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