@humanlayer/fold-xai 0.1.2 → 0.1.3
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/dist/OAuthFlows.d.ts +3 -3
- package/dist/XaiAuth.d.ts +0 -1
- package/dist/XaiModel.d.ts +1 -1
- package/dist/index.js +20 -12
- package/dist/index.js.map +5 -5
- package/package.json +3 -3
package/dist/OAuthFlows.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Effect, Schema } from 'effect';
|
|
1
|
+
import { Crypto, Effect, Schema } from 'effect';
|
|
2
2
|
import { HttpClient } from 'effect/unstable/http';
|
|
3
3
|
import { XaiTokenData } from './AuthStore';
|
|
4
4
|
export declare const XAI_CLIENT_ID = "b1a00492-073a-47ea-816f-4c329264a828";
|
|
@@ -32,7 +32,7 @@ export type XaiPkce = {
|
|
|
32
32
|
readonly verifier: string;
|
|
33
33
|
readonly challenge: string;
|
|
34
34
|
};
|
|
35
|
-
export declare const generateXaiPkce: Effect.Effect<XaiPkce>;
|
|
35
|
+
export declare const generateXaiPkce: Effect.Effect<XaiPkce, never, Crypto.Crypto>;
|
|
36
36
|
/** Build xAI's registered Grok CLI authorization URL. */
|
|
37
37
|
export declare const buildXaiAuthorizeUrl: (pkce: XaiPkce, state: string, nonce: string) => string;
|
|
38
38
|
export type XaiBrowserFlowOptions = {
|
|
@@ -41,5 +41,5 @@ export type XaiBrowserFlowOptions = {
|
|
|
41
41
|
readonly timeoutMs?: number;
|
|
42
42
|
};
|
|
43
43
|
/** Run browser PKCE on xAI's fixed registered 127.0.0.1:56121 callback. */
|
|
44
|
-
export declare const runXaiBrowserFlow: (options: XaiBrowserFlowOptions) => Effect.Effect<XaiTokenData, XaiAuthError,
|
|
44
|
+
export declare const runXaiBrowserFlow: (options: XaiBrowserFlowOptions) => Effect.Effect<XaiTokenData, XaiAuthError, Crypto.Crypto>;
|
|
45
45
|
export {};
|
package/dist/XaiAuth.d.ts
CHANGED
package/dist/XaiModel.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import type { Scope } from 'effect';
|
|
|
4
4
|
import type { LanguageModel } from 'effect/unstable/ai';
|
|
5
5
|
import type { XaiAuthStore } from './AuthStore';
|
|
6
6
|
export declare const XAI_API_URL = "https://api.x.ai/v1";
|
|
7
|
-
export declare const DEFAULT_XAI_MODEL_ID = "grok-4.
|
|
7
|
+
export declare const DEFAULT_XAI_MODEL_ID = "grok-4.6";
|
|
8
8
|
export type XaiModelOptions = {
|
|
9
9
|
readonly model?: string;
|
|
10
10
|
readonly reasoning?: ReasoningLevel;
|
package/dist/index.js
CHANGED
|
@@ -86,7 +86,7 @@ var makeXaiAuthStore = (options) => {
|
|
|
86
86
|
};
|
|
87
87
|
// packages/fold-xai/src/OAuthFlows.ts
|
|
88
88
|
import { createServer } from "node:http";
|
|
89
|
-
import { Clock, Deferred, Duration, Effect as Effect2, Schedule, Schema as Schema2 } from "effect";
|
|
89
|
+
import { Clock, Crypto, Deferred, Duration, Effect as Effect2, Schedule, Schema as Schema2 } from "effect";
|
|
90
90
|
import { HttpClient, HttpClientRequest, HttpClientResponse } from "effect/unstable/http";
|
|
91
91
|
var XAI_CLIENT_ID = "b1a00492-073a-47ea-816f-4c329264a828";
|
|
92
92
|
var XAI_ISSUER = "https://auth.x.ai";
|
|
@@ -196,11 +196,13 @@ var runXaiDeviceFlow = Effect2.fn("fold.xaiAuth.deviceFlow")(function* (options)
|
|
|
196
196
|
return yield* failure("DeviceFlowFailed", "xAI device authorization timed out");
|
|
197
197
|
});
|
|
198
198
|
var CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~";
|
|
199
|
-
var
|
|
200
|
-
var base64Url = (
|
|
201
|
-
var generateXaiPkce = Effect2.
|
|
202
|
-
const
|
|
203
|
-
|
|
199
|
+
var pkceString = (bytes) => Array.from(bytes).map((byte) => CHARS[byte % CHARS.length]).join("");
|
|
200
|
+
var base64Url = (bytes) => Buffer.from(bytes).toString("base64url");
|
|
201
|
+
var generateXaiPkce = Effect2.gen(function* () {
|
|
202
|
+
const crypto = yield* Crypto.Crypto;
|
|
203
|
+
const verifier = pkceString(yield* crypto.randomBytes(64).pipe(Effect2.orDie));
|
|
204
|
+
const challenge = base64Url(yield* crypto.digest("SHA-256", new TextEncoder().encode(verifier)).pipe(Effect2.orDie));
|
|
205
|
+
return { verifier, challenge };
|
|
204
206
|
});
|
|
205
207
|
var buildXaiAuthorizeUrl = (pkce, state, nonce) => {
|
|
206
208
|
const query = new URLSearchParams({
|
|
@@ -218,9 +220,10 @@ var buildXaiAuthorizeUrl = (pkce, state, nonce) => {
|
|
|
218
220
|
return `${XAI_ISSUER}/oauth2/authorize?${query.toString()}`;
|
|
219
221
|
};
|
|
220
222
|
var runXaiBrowserFlow = Effect2.fn("fold.xaiAuth.browserFlow")(function* (options) {
|
|
223
|
+
const crypto = yield* Crypto.Crypto;
|
|
221
224
|
const pkce = yield* generateXaiPkce;
|
|
222
|
-
const state = base64Url(crypto.
|
|
223
|
-
const nonce = base64Url(crypto.
|
|
225
|
+
const state = base64Url(yield* crypto.randomBytes(32).pipe(Effect2.orDie));
|
|
226
|
+
const nonce = base64Url(yield* crypto.randomBytes(32).pipe(Effect2.orDie));
|
|
224
227
|
const code = yield* Effect2.scoped(Effect2.gen(function* () {
|
|
225
228
|
const callback = yield* Deferred.make();
|
|
226
229
|
yield* Effect2.acquireRelease(Effect2.tryPromise({
|
|
@@ -260,6 +263,7 @@ var runXaiBrowserFlow = Effect2.fn("fold.xaiAuth.browserFlow")(function* (option
|
|
|
260
263
|
return yield* exchangeCode(options.client, code, pkce.verifier);
|
|
261
264
|
});
|
|
262
265
|
// packages/fold-xai/src/XaiAuth.ts
|
|
266
|
+
import * as NodeCrypto from "@effect/platform-node/NodeCrypto";
|
|
263
267
|
import { Clock as Clock2, Context as Context2, Effect as Effect3, Option as Option2, Semaphore } from "effect";
|
|
264
268
|
import { HttpClient as HttpClient2, HttpClientError, HttpClientRequest as HttpClientRequest2 } from "effect/unstable/http";
|
|
265
269
|
class XaiAuth extends Context2.Service()("fold/XaiAuth") {
|
|
@@ -295,7 +299,11 @@ var makeXaiAuth = Effect3.fnUntraced(function* (options) {
|
|
|
295
299
|
return {
|
|
296
300
|
get: semaphore.withPermit(get).pipe(Effect3.withSpan("fold.xaiAuth.get")),
|
|
297
301
|
authenticateDevice: semaphore.withPermit(run(runXaiDeviceFlow({ client, onCode: options?.onDeviceCode ?? devicePrompt }))).pipe(Effect3.withSpan("fold.xaiAuth.authenticateDevice")),
|
|
298
|
-
authenticateBrowser: semaphore.withPermit(run(runXaiBrowserFlow({
|
|
302
|
+
authenticateBrowser: semaphore.withPermit(run(runXaiBrowserFlow({
|
|
303
|
+
client,
|
|
304
|
+
onUrl: options?.onBrowserUrl ?? browserPrompt,
|
|
305
|
+
...options?.browser
|
|
306
|
+
}).pipe(Effect3.provide(NodeCrypto.layer)))).pipe(Effect3.withSpan("fold.xaiAuth.authenticateBrowser")),
|
|
299
307
|
logout: semaphore.withPermit(store.clear.pipe(Effect3.mapError(storeError), Effect3.tap(() => Effect3.sync(() => {
|
|
300
308
|
current = Option2.none();
|
|
301
309
|
})))).pipe(Effect3.withSpan("fold.xaiAuth.logout"))
|
|
@@ -309,12 +317,12 @@ var withXaiAuth = (client, auth) => client.pipe(HttpClient2.mapRequestEffect((re
|
|
|
309
317
|
})
|
|
310
318
|
})))));
|
|
311
319
|
// packages/fold-xai/src/XaiModel.ts
|
|
312
|
-
import { OpenAiClient, OpenAiLanguageModel } from "@effect/ai-openai";
|
|
320
|
+
import { OpenAiClient, OpenAiLanguageModel } from "@effect/ai-openai-compat";
|
|
313
321
|
import { customModel, resolveOpenAiReasoning } from "@humanlayer/fold-core";
|
|
314
322
|
import { Context as Context3, Effect as Effect4, Layer as Layer2 } from "effect";
|
|
315
323
|
import { FetchHttpClient, HttpClient as HttpClient3 } from "effect/unstable/http";
|
|
316
324
|
var XAI_API_URL = "https://api.x.ai/v1";
|
|
317
|
-
var DEFAULT_XAI_MODEL_ID = "grok-4.
|
|
325
|
+
var DEFAULT_XAI_MODEL_ID = "grok-4.6";
|
|
318
326
|
var makeXaiLanguageModel = (options) => Effect4.gen(function* () {
|
|
319
327
|
const httpContext = yield* Layer2.build(FetchHttpClient.layer);
|
|
320
328
|
const base = Context3.get(httpContext, HttpClient3.HttpClient);
|
|
@@ -364,4 +372,4 @@ export {
|
|
|
364
372
|
DEFAULT_XAI_MODEL_ID
|
|
365
373
|
};
|
|
366
374
|
|
|
367
|
-
//# debugId=
|
|
375
|
+
//# debugId=9B16DD2CDF62A61964756E2164756E21
|
package/dist/index.js.map
CHANGED
|
@@ -3,11 +3,11 @@
|
|
|
3
3
|
"sources": ["../src/AuthStore.ts", "../src/OAuthFlows.ts", "../src/XaiAuth.ts", "../src/XaiModel.ts"],
|
|
4
4
|
"sourcesContent": [
|
|
5
5
|
"/**\n * File-backed Xai credential store: one provider-keyed JSON document (default `~/.fold/auth.json`)\n * holding OAuth tokens only (D23). Field names are agentlayer-compatible (`access`/`refresh`/`expires`/\n * `accountId`), so existing entries copy across verbatim. Reads degrade to \"no credentials\" on missing\n * or malformed data - the document may hold other providers' entries, so a bad xai entry is skipped,\n * never clobbered; writes merge over the existing document and force `0600` permissions. The FileSystem\n * is a default-or-override seam like fold-agent tools: tests pass an implementation, everyone else gets\n * the Node platform filesystem.\n */\nimport { homedir } from 'node:os'\nimport { dirname, join } from 'node:path'\n\nimport * as NodeFileSystem from '@effect/platform-node/NodeFileSystem'\nimport { Context, Effect, FileSystem, Layer, Option, Schema } from 'effect'\n\n/** Milliseconds before nominal expiry a token is already treated as expired (clanka parity). */\nexport const TOKEN_EXPIRY_BUFFER_MS = 30_000\n\n/** Default location of the fold auth store. */\nexport const defaultAuthStorePath = (): string => join(homedir(), '.fold', 'auth.json')\n\n/** One stored Xai OAuth credential. `expires` is epoch milliseconds for the access token. */\nexport class XaiTokenData extends Schema.Class<XaiTokenData>('fold/XaiTokenData')({\n\ttype: Schema.Literal('oauth'),\n\taccess: Schema.String,\n\trefresh: Schema.String,\n\texpires: Schema.Number,\n\taccountId: Schema.optional(Schema.String),\n}) {\n\t/** True when the token is expired - or within the safety buffer of expiring - at `nowMs`. */\n\tisExpired(nowMs: number): boolean {\n\t\treturn this.expires < nowMs + TOKEN_EXPIRY_BUFFER_MS\n\t}\n}\n\n/** Auth store persistence failure (reads never fail - they degrade to absent credentials). */\nexport class XaiAuthStoreError extends Schema.TaggedError<XaiAuthStoreError>()('XaiAuthStoreError', {\n\treason: Schema.Literals(['WriteFailed']),\n\tmessage: Schema.String,\n\tcause: Schema.optional(Schema.Defect()),\n}) {}\n\n/** The credential store one XaiAuth instance persists through. */\nexport type XaiAuthStore = {\n\t/** Absolute path of the backing JSON document (used in error messages and guidance). */\n\treadonly path: string\n\treadonly load: Effect.Effect<Option.Option<XaiTokenData>>\n\treadonly save: (token: XaiTokenData) => Effect.Effect<XaiTokenData, XaiAuthStoreError>\n\treadonly clear: Effect.Effect<void, XaiAuthStoreError>\n}\n\n/** Options for {@link makeXaiAuthStore}. */\nexport type MakeXaiAuthStoreOptions = {\n\t/** Path of the auth document. Defaults to `~/.fold/auth.json`. */\n\treadonly path?: string\n\t/** Key of this provider's entry in the document. Defaults to `xai`. */\n\treadonly providerId?: string\n\t/** FileSystem implementation override. Defaults to the Node platform filesystem. */\n\treadonly fileSystem?: FileSystem.FileSystem\n}\n\nlet nodeFileSystem: FileSystem.FileSystem | null = null\n\n/** The process-wide Node FileSystem service, built lazily once (layer construction is synchronous). */\nexport const defaultNodeFileSystem = (): FileSystem.FileSystem => {\n\tif (nodeFileSystem === null) {\n\t\tnodeFileSystem = Effect.runSync(\n\t\t\tEffect.scoped(\n\t\t\t\tLayer.build(NodeFileSystem.layer).pipe(\n\t\t\t\t\tEffect.map((context) => Context.get(context, FileSystem.FileSystem)),\n\t\t\t\t),\n\t\t\t),\n\t\t)\n\t}\n\n\treturn nodeFileSystem\n}\n\n/** The auth document is provider-keyed; entries other than ours are opaque and preserved verbatim. */\nconst AuthDocument = Schema.Record(Schema.String, Schema.Unknown)\n\nconst decodeDocument = Schema.decodeUnknownOption(Schema.fromJsonString(AuthDocument))\n\nconst decodeToken = Schema.decodeUnknownOption(XaiTokenData)\n\nconst encodeToken = (token: XaiTokenData): Record<string, unknown> => ({\n\ttype: token.type,\n\taccess: token.access,\n\trefresh: token.refresh,\n\texpires: token.expires,\n\t...(token.accountId === undefined ? {} : { accountId: token.accountId }),\n})\n\n/** Build a file-backed Xai credential store. */\nexport const makeXaiAuthStore = (options?: MakeXaiAuthStoreOptions): XaiAuthStore => {\n\tconst fs = options?.fileSystem ?? defaultNodeFileSystem()\n\tconst path = options?.path ?? defaultAuthStorePath()\n\tconst providerId = options?.providerId ?? 'xai'\n\n\tconst readDocument: Effect.Effect<Record<string, unknown>> = fs.readFileString(path).pipe(\n\t\tEffect.flatMap((content) => {\n\t\t\tconst document = decodeDocument(content)\n\t\t\treturn Option.isSome(document)\n\t\t\t\t? Effect.succeed(document.value)\n\t\t\t\t: Effect.logWarning(`Auth store ${path} is not a JSON object; treating it as empty`).pipe(\n\t\t\t\t\t\tEffect.as<Record<string, unknown>>({}),\n\t\t\t\t\t)\n\t\t}),\n\t\t// A missing (or unreadable) document is simply \"no credentials stored yet\".\n\t\tEffect.catch(() => Effect.succeed<Record<string, unknown>>({})),\n\t)\n\n\tconst writeDocument = (document: Record<string, unknown>): Effect.Effect<void, XaiAuthStoreError> =>\n\t\tEffect.gen(function* () {\n\t\t\tyield* fs.makeDirectory(dirname(path), { recursive: true })\n\t\t\tyield* fs.writeFileString(path, `${JSON.stringify(document, null, 2)}\\n`, { mode: 0o600 })\n\t\t\t// writeFileString's mode only applies on creation; force 0600 on pre-existing documents too.\n\t\t\tyield* fs.chmod(path, 0o600)\n\t\t}).pipe(\n\t\t\tEffect.mapError(\n\t\t\t\t(cause) =>\n\t\t\t\t\tnew XaiAuthStoreError({\n\t\t\t\t\t\treason: 'WriteFailed',\n\t\t\t\t\t\tmessage: `Failed to write the auth store at ${path}`,\n\t\t\t\t\t\tcause,\n\t\t\t\t\t}),\n\t\t\t),\n\t\t)\n\n\tconst load = Effect.gen(function* () {\n\t\tconst document = yield* readDocument\n\t\tconst entry = document[providerId]\n\t\tif (entry === undefined) return Option.none<XaiTokenData>()\n\n\t\tconst token = decodeToken(entry)\n\t\tif (Option.isNone(token)) {\n\t\t\tyield* Effect.logWarning(`Ignoring invalid \"${providerId}\" entry in ${path}`)\n\t\t}\n\n\t\treturn token\n\t}).pipe(Effect.withSpan('fold.xaiAuthStore.load'))\n\n\tconst save = (token: XaiTokenData) =>\n\t\tEffect.gen(function* () {\n\t\t\tconst document = yield* readDocument\n\t\t\tyield* writeDocument({ ...document, [providerId]: encodeToken(token) })\n\t\t\treturn token\n\t\t}).pipe(Effect.withSpan('fold.xaiAuthStore.save'))\n\n\tconst clear = Effect.gen(function* () {\n\t\tconst document = yield* readDocument\n\t\tif (document[providerId] === undefined) return\n\t\tconst { [providerId]: _removed, ...rest } = document\n\t\tyield* writeDocument(rest)\n\t}).pipe(Effect.withSpan('fold.xaiAuthStore.clear'))\n\n\treturn { path, load, save, clear }\n}\n",
|
|
6
|
-
"/** xAI OAuth wire protocol, adapted from opencode's xAI plugin (MIT; see LICENSE-opencode). */\nimport { createServer } from 'node:http'\nimport type { Server } from 'node:http'\n\nimport { Clock, Deferred, Duration, Effect, Schedule, Schema } from 'effect'\nimport { HttpClient, HttpClientRequest, HttpClientResponse } from 'effect/unstable/http'\n\nimport { XaiTokenData } from './AuthStore'\n\nexport const XAI_CLIENT_ID = 'b1a00492-073a-47ea-816f-4c329264a828'\nexport const XAI_ISSUER = 'https://auth.x.ai'\nexport const XAI_SCOPE = 'openid profile email offline_access grok-cli:access api:access'\nexport const XAI_BROWSER_PORT = 56121\nexport const XAI_BROWSER_REDIRECT_URI = `http://127.0.0.1:${XAI_BROWSER_PORT}/callback`\n\nconst TOKEN_PATH = '/oauth2/token'\nconst DEVICE_PATH = '/oauth2/device/code'\nconst DEVICE_GRANT = 'urn:ietf:params:oauth:grant-type:device_code'\nconst DEFAULT_EXPIRY_SECONDS = 3600\nconst DEFAULT_DEVICE_EXPIRY_SECONDS = 300\nconst DEFAULT_POLL_SECONDS = 5\nconst POLL_MARGIN_MS = 3000\n\nexport class XaiAuthError extends Schema.TaggedError<XaiAuthError>()('XaiAuthError', {\n\treason: Schema.Literals([\n\t\t'NotAuthenticated',\n\t\t'RefreshFailed',\n\t\t'TokenExchangeFailed',\n\t\t'DeviceFlowFailed',\n\t\t'BrowserFlowFailed',\n\t\t'StoreFailed',\n\t]),\n\tmessage: Schema.String,\n\tcause: Schema.optional(Schema.Defect()),\n}) {}\n\nconst TokenResponse = Schema.Struct({\n\taccess_token: Schema.String,\n\trefresh_token: Schema.optional(Schema.String),\n\texpires_in: Schema.optional(Schema.Number),\n})\n\nconst DeviceResponse = Schema.Struct({\n\tdevice_code: Schema.String,\n\tuser_code: Schema.String,\n\tverification_uri: Schema.String,\n\tverification_uri_complete: Schema.optional(Schema.String),\n\texpires_in: Schema.optional(Schema.Number),\n\tinterval: Schema.optional(Schema.Number),\n})\n\nconst DeviceError = Schema.Struct({\n\terror: Schema.optional(Schema.String),\n\terror_description: Schema.optional(Schema.String),\n})\n\nconst failure = (reason: XaiAuthError['reason'], message: string, cause?: unknown) =>\n\tnew XaiAuthError({ reason, message, ...(cause === undefined ? {} : { cause }) })\n\nconst tokenData = (payload: typeof TokenResponse.Type, fallbackRefresh?: string) =>\n\tEffect.map(\n\t\tClock.currentTimeMillis,\n\t\t(now) =>\n\t\t\tnew XaiTokenData({\n\t\t\t\ttype: 'oauth',\n\t\t\t\taccess: payload.access_token,\n\t\t\t\trefresh: payload.refresh_token ?? fallbackRefresh ?? '',\n\t\t\t\texpires: now + (payload.expires_in ?? DEFAULT_EXPIRY_SECONDS) * 1000,\n\t\t\t}),\n\t)\n\n/** Scope and harden an HttpClient for xAI's OAuth issuer. */\nexport const makeXaiIssuerClient = (client: HttpClient.HttpClient): HttpClient.HttpClient =>\n\tclient.pipe(\n\t\tHttpClient.mapRequest(HttpClientRequest.prependUrl(XAI_ISSUER)),\n\t\tHttpClient.filterStatusOk,\n\t\tHttpClient.retryTransient({\n\t\t\ttimes: 5,\n\t\t\t// `min` preserves the removed `either` behavior: use whichever infinite schedule wakes sooner.\n\t\t\tschedule: Schedule.min([Schedule.exponential(150), Schedule.spaced(5000)]),\n\t\t}),\n\t)\n\nconst decodeToken = (\n\tresponse: HttpClientResponse.HttpClientResponse,\n\treason: XaiAuthError['reason'],\n\tmessage: string,\n\tfallback?: string,\n) =>\n\tHttpClientResponse.schemaBodyJson(TokenResponse)(response).pipe(\n\t\tEffect.mapError((cause) => failure(reason, message, cause)),\n\t\tEffect.flatMap((payload) => tokenData(payload, fallback)),\n\t)\n\n/** Refresh a stored xAI OAuth credential, preserving rotating or omitted refresh tokens. */\nexport const refreshXaiAccessToken = Effect.fn('fold.xaiAuth.refresh')(function* (\n\tclient: HttpClient.HttpClient,\n\trefresh: string,\n) {\n\tconst response = yield* HttpClientRequest.post(TOKEN_PATH).pipe(\n\t\tHttpClientRequest.bodyUrlParams({\n\t\t\tgrant_type: 'refresh_token',\n\t\t\trefresh_token: refresh,\n\t\t\tclient_id: XAI_CLIENT_ID,\n\t\t}),\n\t\tclient.execute,\n\t\tEffect.mapError((cause) => failure('RefreshFailed', 'Failed to refresh the xAI access token', cause)),\n\t)\n\treturn yield* decodeToken(response, 'RefreshFailed', 'Failed to decode the xAI refresh response', refresh)\n})\n\nconst exchangeCode = Effect.fn('fold.xaiAuth.exchange')(function* (\n\tclient: HttpClient.HttpClient,\n\tcode: string,\n\tverifier: string,\n) {\n\tconst response = yield* HttpClientRequest.post(TOKEN_PATH).pipe(\n\t\tHttpClientRequest.bodyUrlParams({\n\t\t\tgrant_type: 'authorization_code',\n\t\t\tcode,\n\t\t\tredirect_uri: XAI_BROWSER_REDIRECT_URI,\n\t\t\tclient_id: XAI_CLIENT_ID,\n\t\t\tcode_verifier: verifier,\n\t\t}),\n\t\tclient.execute,\n\t\tEffect.mapError((cause) =>\n\t\t\tfailure('TokenExchangeFailed', 'Failed to exchange the xAI authorization code', cause),\n\t\t),\n\t)\n\treturn yield* decodeToken(response, 'TokenExchangeFailed', 'Failed to decode the xAI token response')\n})\n\nexport type XaiDevicePrompt = {\n\treadonly verificationUri: string\n\treadonly userCode: string\n\treadonly browserUrl: string\n}\nexport type XaiDeviceFlowOptions = {\n\treadonly client: HttpClient.HttpClient\n\treadonly onCode: (prompt: XaiDevicePrompt) => Effect.Effect<void>\n}\n\n/** Run RFC 8628 device authorization, including pending/slow_down backoff and expiry. */\nexport const runXaiDeviceFlow = Effect.fn('fold.xaiAuth.deviceFlow')(function* (options: XaiDeviceFlowOptions) {\n\tconst response = yield* HttpClientRequest.post(DEVICE_PATH).pipe(\n\t\tHttpClientRequest.bodyUrlParams({ client_id: XAI_CLIENT_ID, scope: XAI_SCOPE }),\n\t\toptions.client.execute,\n\t\tEffect.mapError((cause) => failure('DeviceFlowFailed', 'Failed to request an xAI device code', cause)),\n\t)\n\tconst device = yield* HttpClientResponse.schemaBodyJson(DeviceResponse)(response).pipe(\n\t\tEffect.mapError((cause) => failure('DeviceFlowFailed', 'Failed to decode the xAI device response', cause)),\n\t)\n\tyield* options.onCode({\n\t\tverificationUri: device.verification_uri,\n\t\tuserCode: device.user_code,\n\t\tbrowserUrl: device.verification_uri_complete ?? device.verification_uri,\n\t})\n\n\tconst started = yield* Clock.currentTimeMillis\n\tconst deadline = started + (device.expires_in ?? DEFAULT_DEVICE_EXPIRY_SECONDS) * 1000\n\tlet delayMs = Math.max(device.interval ?? DEFAULT_POLL_SECONDS, 1) * 1000\n\twhile ((yield* Clock.currentTimeMillis) < deadline) {\n\t\tconst poll = HttpClientRequest.post(TOKEN_PATH).pipe(\n\t\t\tHttpClientRequest.bodyUrlParams({\n\t\t\t\tgrant_type: DEVICE_GRANT,\n\t\t\t\tclient_id: XAI_CLIENT_ID,\n\t\t\t\tdevice_code: device.device_code,\n\t\t\t}),\n\t\t\toptions.client.execute,\n\t\t\tEffect.result,\n\t\t)\n\t\tconst result = yield* poll\n\t\tif (result._tag === 'Success')\n\t\t\treturn yield* decodeToken(result.success, 'DeviceFlowFailed', 'Failed to decode the xAI device token')\n\t\tconst body: typeof DeviceError.Type =\n\t\t\tresult.failure.response === undefined\n\t\t\t\t? {}\n\t\t\t\t: yield* HttpClientResponse.schemaBodyJson(DeviceError)(result.failure.response).pipe(\n\t\t\t\t\t\tEffect.orElseSucceed((): typeof DeviceError.Type => ({})),\n\t\t\t\t\t)\n\t\tif (body.error === 'access_denied' || body.error === 'authorization_denied')\n\t\t\treturn yield* failure('DeviceFlowFailed', 'xAI device authorization was denied')\n\t\tif (body.error === 'expired_token') return yield* failure('DeviceFlowFailed', 'xAI device code expired')\n\t\tif (body.error !== 'authorization_pending' && body.error !== 'slow_down') {\n\t\t\treturn yield* failure(\n\t\t\t\t'DeviceFlowFailed',\n\t\t\t\tbody.error_description ?? body.error ?? 'xAI device token exchange failed',\n\t\t\t)\n\t\t}\n\t\tif (body.error === 'slow_down') delayMs += 5000\n\t\tyield* Effect.sleep(Duration.millis(delayMs + POLL_MARGIN_MS))\n\t}\n\treturn yield* failure('DeviceFlowFailed', 'xAI device authorization timed out')\n})\n\nconst CHARS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~'\nconst random = (length: number): string =>\n\tArray.from(crypto.getRandomValues(new Uint8Array(length)))\n\t\t.map((byte) => CHARS[byte % CHARS.length])\n\t\t.join('')\nconst base64Url = (buffer: ArrayBuffer): string => Buffer.from(buffer).toString('base64url')\n\nexport type XaiPkce = { readonly verifier: string; readonly challenge: string }\nexport const generateXaiPkce: Effect.Effect<XaiPkce> = Effect.promise(async () => {\n\tconst verifier = random(64)\n\treturn { verifier, challenge: base64Url(await crypto.subtle.digest('SHA-256', new TextEncoder().encode(verifier))) }\n})\n\n/** Build xAI's registered Grok CLI authorization URL. */\nexport const buildXaiAuthorizeUrl = (pkce: XaiPkce, state: string, nonce: string): string => {\n\tconst query = new URLSearchParams({\n\t\tresponse_type: 'code',\n\t\tclient_id: XAI_CLIENT_ID,\n\t\tredirect_uri: XAI_BROWSER_REDIRECT_URI,\n\t\tscope: XAI_SCOPE,\n\t\tcode_challenge: pkce.challenge,\n\t\tcode_challenge_method: 'S256',\n\t\tstate,\n\t\tnonce,\n\t\tplan: 'generic',\n\t\treferrer: 'fold',\n\t})\n\treturn `${XAI_ISSUER}/oauth2/authorize?${query.toString()}`\n}\n\nexport type XaiBrowserFlowOptions = {\n\treadonly client: HttpClient.HttpClient\n\treadonly onUrl: (url: string) => Effect.Effect<void>\n\treadonly timeoutMs?: number\n}\n\n/** Run browser PKCE on xAI's fixed registered 127.0.0.1:56121 callback. */\nexport const runXaiBrowserFlow = Effect.fn('fold.xaiAuth.browserFlow')(function* (options: XaiBrowserFlowOptions) {\n\tconst pkce = yield* generateXaiPkce\n\tconst state = base64Url(crypto.getRandomValues(new Uint8Array(32)).buffer)\n\tconst nonce = base64Url(crypto.getRandomValues(new Uint8Array(32)).buffer)\n\tconst code = yield* Effect.scoped(\n\t\tEffect.gen(function* () {\n\t\t\tconst callback = yield* Deferred.make<string, XaiAuthError>()\n\t\t\tyield* Effect.acquireRelease(\n\t\t\t\tEffect.tryPromise({\n\t\t\t\t\ttry: () =>\n\t\t\t\t\t\tnew Promise<Server>((resolve, reject) => {\n\t\t\t\t\t\t\tconst server = createServer((request, response) => {\n\t\t\t\t\t\t\t\tconst url = new URL(request.url ?? '/', XAI_BROWSER_REDIRECT_URI)\n\t\t\t\t\t\t\t\tconst fail = (message: string, status = 400) => {\n\t\t\t\t\t\t\t\t\tEffect.runSync(Deferred.fail(callback, failure('BrowserFlowFailed', message)))\n\t\t\t\t\t\t\t\t\tresponse.writeHead(status, { 'Content-Type': 'text/plain' })\n\t\t\t\t\t\t\t\t\tresponse.end(message)\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tif (url.pathname !== '/callback') return fail('Not found', 404)\n\t\t\t\t\t\t\t\tconst oauthError = url.searchParams.get('error')\n\t\t\t\t\t\t\t\tif (oauthError !== null)\n\t\t\t\t\t\t\t\t\treturn fail(url.searchParams.get('error_description') ?? oauthError, 200)\n\t\t\t\t\t\t\t\tif (url.searchParams.get('state') !== state)\n\t\t\t\t\t\t\t\t\treturn fail('Invalid state - potential CSRF attack')\n\t\t\t\t\t\t\t\tconst received = url.searchParams.get('code')\n\t\t\t\t\t\t\t\tif (received === null) return fail('Missing authorization code')\n\t\t\t\t\t\t\t\tEffect.runSync(Deferred.succeed(callback, received))\n\t\t\t\t\t\t\t\tresponse.writeHead(200, { 'Content-Type': 'text/plain' })\n\t\t\t\t\t\t\t\tresponse.end('xAI authorization successful. Return to fold.')\n\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\tserver.once('error', reject)\n\t\t\t\t\t\t\tserver.listen(XAI_BROWSER_PORT, '127.0.0.1', () => resolve(server))\n\t\t\t\t\t\t}),\n\t\t\t\t\tcatch: (cause) =>\n\t\t\t\t\t\tfailure(\n\t\t\t\t\t\t\t'BrowserFlowFailed',\n\t\t\t\t\t\t\t`Failed to start callback server on port ${XAI_BROWSER_PORT}`,\n\t\t\t\t\t\t\tcause,\n\t\t\t\t\t\t),\n\t\t\t\t}),\n\t\t\t\t(server) => Effect.promise(() => new Promise<void>((resolve) => server.close(() => resolve()))),\n\t\t\t)\n\t\t\tyield* options.onUrl(buildXaiAuthorizeUrl(pkce, state, nonce))\n\t\t\treturn yield* Deferred.await(callback).pipe(\n\t\t\t\tEffect.timeoutOrElse({\n\t\t\t\t\tduration: Duration.millis(options.timeoutMs ?? 300_000),\n\t\t\t\t\torElse: () => Effect.fail(failure('BrowserFlowFailed', 'OAuth callback timed out')),\n\t\t\t\t}),\n\t\t\t)\n\t\t}),\n\t)\n\treturn yield* exchangeCode(options.client, code, pkce.verifier)\n})\n",
|
|
7
|
-
"/** Persistent, single-flight xAI OAuth credential service and authenticated HTTP decorator. */\nimport { Clock, Context, Effect, Option, Semaphore } from 'effect'\nimport { HttpClient, HttpClientError, HttpClientRequest } from 'effect/unstable/http'\n\nimport { makeXaiAuthStore, type XaiAuthStore, type XaiTokenData } from './AuthStore'\nimport type { XaiBrowserFlowOptions, XaiDevicePrompt } from './OAuthFlows'\nimport {\n\tmakeXaiIssuerClient,\n\trefreshXaiAccessToken,\n\trunXaiBrowserFlow,\n\trunXaiDeviceFlow,\n\tXaiAuthError,\n} from './OAuthFlows'\n\nexport type XaiAuthService = {\n\treadonly get: Effect.Effect<XaiTokenData, XaiAuthError>\n\treadonly authenticateDevice: Effect.Effect<XaiTokenData, XaiAuthError>\n\treadonly authenticateBrowser: Effect.Effect<XaiTokenData, XaiAuthError>\n\treadonly logout: Effect.Effect<void, XaiAuthError>\n}\n\nexport class XaiAuth extends Context.Service<XaiAuth, XaiAuthService>()('fold/XaiAuth') {}\n\nexport type MakeXaiAuthOptions = {\n\treadonly store?: XaiAuthStore\n\treadonly onDeviceCode?: (prompt: XaiDevicePrompt) => Effect.Effect<void>\n\treadonly onBrowserUrl?: (url: string) => Effect.Effect<void>\n\treadonly browser?: Pick<XaiBrowserFlowOptions, 'timeoutMs'>\n}\n\nconst devicePrompt = (prompt: XaiDevicePrompt) =>\n\tEffect.log(`Open ${prompt.verificationUri} and enter code: ${prompt.userCode}`)\nconst browserPrompt = (url: string) => Effect.log(`Open this URL to authenticate xAI:\\n${url}`)\n\n/** Construct xAI auth over the ambient HttpClient. Interactive flows are explicit methods. */\nexport const makeXaiAuth = Effect.fnUntraced(function* (options?: MakeXaiAuthOptions) {\n\tconst store = options?.store ?? makeXaiAuthStore()\n\tconst client = makeXaiIssuerClient(yield* HttpClient.HttpClient)\n\tconst semaphore = Semaphore.makeUnsafe(1)\n\tlet current = yield* store.load\n\tconst storeError = (cause: unknown) =>\n\t\tnew XaiAuthError({\n\t\t\treason: 'StoreFailed',\n\t\t\tmessage: `Failed to persist xAI credentials to ${store.path}`,\n\t\t\tcause,\n\t\t})\n\tconst save = (token: XaiTokenData) =>\n\t\tstore.save(token).pipe(\n\t\t\tEffect.mapError(storeError),\n\t\t\tEffect.tap(() =>\n\t\t\t\tEffect.sync(() => {\n\t\t\t\t\tcurrent = Option.some(token)\n\t\t\t\t}),\n\t\t\t),\n\t\t)\n\tconst get = Effect.uninterruptibleMask(\n\t\tEffect.fnUntraced(function* (restore) {\n\t\t\tconst now = yield* Clock.currentTimeMillis\n\t\t\tif (Option.isSome(current) && !current.value.isExpired(now)) return current.value\n\t\t\tif (Option.isNone(current))\n\t\t\t\treturn yield* new XaiAuthError({\n\t\t\t\t\treason: 'NotAuthenticated',\n\t\t\t\t\tmessage: `No xAI OAuth credentials found in ${store.path}`,\n\t\t\t\t})\n\t\t\treturn yield* restore(refreshXaiAccessToken(client, current.value.refresh)).pipe(Effect.flatMap(save))\n\t\t}),\n\t)\n\tconst run = (flow: Effect.Effect<XaiTokenData, XaiAuthError>) =>\n\t\tEffect.uninterruptibleMask((restore) => restore(flow).pipe(Effect.flatMap(save)))\n\treturn {\n\t\tget: semaphore.withPermit(get).pipe(Effect.withSpan('fold.xaiAuth.get')),\n\t\tauthenticateDevice: semaphore\n\t\t\t.withPermit(run(runXaiDeviceFlow({ client, onCode: options?.onDeviceCode ?? devicePrompt })))\n\t\t\t.pipe(Effect.withSpan('fold.xaiAuth.authenticateDevice')),\n\t\tauthenticateBrowser: semaphore\n\t\t\t.withPermit(\n\t\t\t\trun(
|
|
8
|
-
"/** FoldModel factory for xAI's OpenAI-compatible inference API authenticated with OAuth. */\nimport { OpenAiClient, OpenAiLanguageModel } from '@effect/ai-openai'\nimport { customModel, resolveOpenAiReasoning } from '@humanlayer/fold-core'\nimport type { FoldModel, ReasoningLevel } from '@humanlayer/fold-core'\nimport { Context, Effect, Layer } from 'effect'\nimport type { Scope } from 'effect'\nimport type { LanguageModel } from 'effect/unstable/ai'\nimport { FetchHttpClient, HttpClient } from 'effect/unstable/http'\n\nimport type { XaiAuthStore } from './AuthStore'\nimport { makeXaiAuth, withXaiAuth } from './XaiAuth'\n\nexport const XAI_API_URL = 'https://api.x.ai/v1'\nexport const DEFAULT_XAI_MODEL_ID = 'grok-4.
|
|
6
|
+
"/** xAI OAuth wire protocol, adapted from opencode's xAI plugin (MIT; see LICENSE-opencode). */\nimport { createServer } from 'node:http'\nimport type { Server } from 'node:http'\n\nimport { Clock, Crypto, Deferred, Duration, Effect, Schedule, Schema } from 'effect'\nimport { HttpClient, HttpClientRequest, HttpClientResponse } from 'effect/unstable/http'\n\nimport { XaiTokenData } from './AuthStore'\n\nexport const XAI_CLIENT_ID = 'b1a00492-073a-47ea-816f-4c329264a828'\nexport const XAI_ISSUER = 'https://auth.x.ai'\nexport const XAI_SCOPE = 'openid profile email offline_access grok-cli:access api:access'\nexport const XAI_BROWSER_PORT = 56121\nexport const XAI_BROWSER_REDIRECT_URI = `http://127.0.0.1:${XAI_BROWSER_PORT}/callback`\n\nconst TOKEN_PATH = '/oauth2/token'\nconst DEVICE_PATH = '/oauth2/device/code'\nconst DEVICE_GRANT = 'urn:ietf:params:oauth:grant-type:device_code'\nconst DEFAULT_EXPIRY_SECONDS = 3600\nconst DEFAULT_DEVICE_EXPIRY_SECONDS = 300\nconst DEFAULT_POLL_SECONDS = 5\nconst POLL_MARGIN_MS = 3000\n\nexport class XaiAuthError extends Schema.TaggedError<XaiAuthError>()('XaiAuthError', {\n\treason: Schema.Literals([\n\t\t'NotAuthenticated',\n\t\t'RefreshFailed',\n\t\t'TokenExchangeFailed',\n\t\t'DeviceFlowFailed',\n\t\t'BrowserFlowFailed',\n\t\t'StoreFailed',\n\t]),\n\tmessage: Schema.String,\n\tcause: Schema.optional(Schema.Defect()),\n}) {}\n\nconst TokenResponse = Schema.Struct({\n\taccess_token: Schema.String,\n\trefresh_token: Schema.optional(Schema.String),\n\texpires_in: Schema.optional(Schema.Number),\n})\n\nconst DeviceResponse = Schema.Struct({\n\tdevice_code: Schema.String,\n\tuser_code: Schema.String,\n\tverification_uri: Schema.String,\n\tverification_uri_complete: Schema.optional(Schema.String),\n\texpires_in: Schema.optional(Schema.Number),\n\tinterval: Schema.optional(Schema.Number),\n})\n\nconst DeviceError = Schema.Struct({\n\terror: Schema.optional(Schema.String),\n\terror_description: Schema.optional(Schema.String),\n})\n\nconst failure = (reason: XaiAuthError['reason'], message: string, cause?: unknown) =>\n\tnew XaiAuthError({ reason, message, ...(cause === undefined ? {} : { cause }) })\n\nconst tokenData = (payload: typeof TokenResponse.Type, fallbackRefresh?: string) =>\n\tEffect.map(\n\t\tClock.currentTimeMillis,\n\t\t(now) =>\n\t\t\tnew XaiTokenData({\n\t\t\t\ttype: 'oauth',\n\t\t\t\taccess: payload.access_token,\n\t\t\t\trefresh: payload.refresh_token ?? fallbackRefresh ?? '',\n\t\t\t\texpires: now + (payload.expires_in ?? DEFAULT_EXPIRY_SECONDS) * 1000,\n\t\t\t}),\n\t)\n\n/** Scope and harden an HttpClient for xAI's OAuth issuer. */\nexport const makeXaiIssuerClient = (client: HttpClient.HttpClient): HttpClient.HttpClient =>\n\tclient.pipe(\n\t\tHttpClient.mapRequest(HttpClientRequest.prependUrl(XAI_ISSUER)),\n\t\tHttpClient.filterStatusOk,\n\t\tHttpClient.retryTransient({\n\t\t\ttimes: 5,\n\t\t\t// `min` preserves the removed `either` behavior: use whichever infinite schedule wakes sooner.\n\t\t\tschedule: Schedule.min([Schedule.exponential(150), Schedule.spaced(5000)]),\n\t\t}),\n\t)\n\nconst decodeToken = (\n\tresponse: HttpClientResponse.HttpClientResponse,\n\treason: XaiAuthError['reason'],\n\tmessage: string,\n\tfallback?: string,\n) =>\n\tHttpClientResponse.schemaBodyJson(TokenResponse)(response).pipe(\n\t\tEffect.mapError((cause) => failure(reason, message, cause)),\n\t\tEffect.flatMap((payload) => tokenData(payload, fallback)),\n\t)\n\n/** Refresh a stored xAI OAuth credential, preserving rotating or omitted refresh tokens. */\nexport const refreshXaiAccessToken = Effect.fn('fold.xaiAuth.refresh')(function* (\n\tclient: HttpClient.HttpClient,\n\trefresh: string,\n) {\n\tconst response = yield* HttpClientRequest.post(TOKEN_PATH).pipe(\n\t\tHttpClientRequest.bodyUrlParams({\n\t\t\tgrant_type: 'refresh_token',\n\t\t\trefresh_token: refresh,\n\t\t\tclient_id: XAI_CLIENT_ID,\n\t\t}),\n\t\tclient.execute,\n\t\tEffect.mapError((cause) => failure('RefreshFailed', 'Failed to refresh the xAI access token', cause)),\n\t)\n\treturn yield* decodeToken(response, 'RefreshFailed', 'Failed to decode the xAI refresh response', refresh)\n})\n\nconst exchangeCode = Effect.fn('fold.xaiAuth.exchange')(function* (\n\tclient: HttpClient.HttpClient,\n\tcode: string,\n\tverifier: string,\n) {\n\tconst response = yield* HttpClientRequest.post(TOKEN_PATH).pipe(\n\t\tHttpClientRequest.bodyUrlParams({\n\t\t\tgrant_type: 'authorization_code',\n\t\t\tcode,\n\t\t\tredirect_uri: XAI_BROWSER_REDIRECT_URI,\n\t\t\tclient_id: XAI_CLIENT_ID,\n\t\t\tcode_verifier: verifier,\n\t\t}),\n\t\tclient.execute,\n\t\tEffect.mapError((cause) =>\n\t\t\tfailure('TokenExchangeFailed', 'Failed to exchange the xAI authorization code', cause),\n\t\t),\n\t)\n\treturn yield* decodeToken(response, 'TokenExchangeFailed', 'Failed to decode the xAI token response')\n})\n\nexport type XaiDevicePrompt = {\n\treadonly verificationUri: string\n\treadonly userCode: string\n\treadonly browserUrl: string\n}\nexport type XaiDeviceFlowOptions = {\n\treadonly client: HttpClient.HttpClient\n\treadonly onCode: (prompt: XaiDevicePrompt) => Effect.Effect<void>\n}\n\n/** Run RFC 8628 device authorization, including pending/slow_down backoff and expiry. */\nexport const runXaiDeviceFlow = Effect.fn('fold.xaiAuth.deviceFlow')(function* (options: XaiDeviceFlowOptions) {\n\tconst response = yield* HttpClientRequest.post(DEVICE_PATH).pipe(\n\t\tHttpClientRequest.bodyUrlParams({ client_id: XAI_CLIENT_ID, scope: XAI_SCOPE }),\n\t\toptions.client.execute,\n\t\tEffect.mapError((cause) => failure('DeviceFlowFailed', 'Failed to request an xAI device code', cause)),\n\t)\n\tconst device = yield* HttpClientResponse.schemaBodyJson(DeviceResponse)(response).pipe(\n\t\tEffect.mapError((cause) => failure('DeviceFlowFailed', 'Failed to decode the xAI device response', cause)),\n\t)\n\tyield* options.onCode({\n\t\tverificationUri: device.verification_uri,\n\t\tuserCode: device.user_code,\n\t\tbrowserUrl: device.verification_uri_complete ?? device.verification_uri,\n\t})\n\n\tconst started = yield* Clock.currentTimeMillis\n\tconst deadline = started + (device.expires_in ?? DEFAULT_DEVICE_EXPIRY_SECONDS) * 1000\n\tlet delayMs = Math.max(device.interval ?? DEFAULT_POLL_SECONDS, 1) * 1000\n\twhile ((yield* Clock.currentTimeMillis) < deadline) {\n\t\tconst poll = HttpClientRequest.post(TOKEN_PATH).pipe(\n\t\t\tHttpClientRequest.bodyUrlParams({\n\t\t\t\tgrant_type: DEVICE_GRANT,\n\t\t\t\tclient_id: XAI_CLIENT_ID,\n\t\t\t\tdevice_code: device.device_code,\n\t\t\t}),\n\t\t\toptions.client.execute,\n\t\t\tEffect.result,\n\t\t)\n\t\tconst result = yield* poll\n\t\tif (result._tag === 'Success')\n\t\t\treturn yield* decodeToken(result.success, 'DeviceFlowFailed', 'Failed to decode the xAI device token')\n\t\tconst body: typeof DeviceError.Type =\n\t\t\tresult.failure.response === undefined\n\t\t\t\t? {}\n\t\t\t\t: yield* HttpClientResponse.schemaBodyJson(DeviceError)(result.failure.response).pipe(\n\t\t\t\t\t\tEffect.orElseSucceed((): typeof DeviceError.Type => ({})),\n\t\t\t\t\t)\n\t\tif (body.error === 'access_denied' || body.error === 'authorization_denied')\n\t\t\treturn yield* failure('DeviceFlowFailed', 'xAI device authorization was denied')\n\t\tif (body.error === 'expired_token') return yield* failure('DeviceFlowFailed', 'xAI device code expired')\n\t\tif (body.error !== 'authorization_pending' && body.error !== 'slow_down') {\n\t\t\treturn yield* failure(\n\t\t\t\t'DeviceFlowFailed',\n\t\t\t\tbody.error_description ?? body.error ?? 'xAI device token exchange failed',\n\t\t\t)\n\t\t}\n\t\tif (body.error === 'slow_down') delayMs += 5000\n\t\tyield* Effect.sleep(Duration.millis(delayMs + POLL_MARGIN_MS))\n\t}\n\treturn yield* failure('DeviceFlowFailed', 'xAI device authorization timed out')\n})\n\nconst CHARS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~'\nconst pkceString = (bytes: Uint8Array): string =>\n\tArray.from(bytes)\n\t\t.map((byte) => CHARS[byte % CHARS.length])\n\t\t.join('')\nconst base64Url = (bytes: Uint8Array): string => Buffer.from(bytes).toString('base64url')\n\nexport type XaiPkce = { readonly verifier: string; readonly challenge: string }\nexport const generateXaiPkce: Effect.Effect<XaiPkce, never, Crypto.Crypto> = Effect.gen(function* () {\n\tconst crypto = yield* Crypto.Crypto\n\tconst verifier = pkceString(yield* crypto.randomBytes(64).pipe(Effect.orDie))\n\tconst challenge = base64Url(yield* crypto.digest('SHA-256', new TextEncoder().encode(verifier)).pipe(Effect.orDie))\n\treturn { verifier, challenge }\n})\n\n/** Build xAI's registered Grok CLI authorization URL. */\nexport const buildXaiAuthorizeUrl = (pkce: XaiPkce, state: string, nonce: string): string => {\n\tconst query = new URLSearchParams({\n\t\tresponse_type: 'code',\n\t\tclient_id: XAI_CLIENT_ID,\n\t\tredirect_uri: XAI_BROWSER_REDIRECT_URI,\n\t\tscope: XAI_SCOPE,\n\t\tcode_challenge: pkce.challenge,\n\t\tcode_challenge_method: 'S256',\n\t\tstate,\n\t\tnonce,\n\t\tplan: 'generic',\n\t\treferrer: 'fold',\n\t})\n\treturn `${XAI_ISSUER}/oauth2/authorize?${query.toString()}`\n}\n\nexport type XaiBrowserFlowOptions = {\n\treadonly client: HttpClient.HttpClient\n\treadonly onUrl: (url: string) => Effect.Effect<void>\n\treadonly timeoutMs?: number\n}\n\n/** Run browser PKCE on xAI's fixed registered 127.0.0.1:56121 callback. */\nexport const runXaiBrowserFlow = Effect.fn('fold.xaiAuth.browserFlow')(function* (options: XaiBrowserFlowOptions) {\n\tconst crypto = yield* Crypto.Crypto\n\tconst pkce = yield* generateXaiPkce\n\tconst state = base64Url(yield* crypto.randomBytes(32).pipe(Effect.orDie))\n\tconst nonce = base64Url(yield* crypto.randomBytes(32).pipe(Effect.orDie))\n\tconst code = yield* Effect.scoped(\n\t\tEffect.gen(function* () {\n\t\t\tconst callback = yield* Deferred.make<string, XaiAuthError>()\n\t\t\tyield* Effect.acquireRelease(\n\t\t\t\tEffect.tryPromise({\n\t\t\t\t\ttry: () =>\n\t\t\t\t\t\tnew Promise<Server>((resolve, reject) => {\n\t\t\t\t\t\t\tconst server = createServer((request, response) => {\n\t\t\t\t\t\t\t\tconst url = new URL(request.url ?? '/', XAI_BROWSER_REDIRECT_URI)\n\t\t\t\t\t\t\t\tconst fail = (message: string, status = 400) => {\n\t\t\t\t\t\t\t\t\tEffect.runSync(Deferred.fail(callback, failure('BrowserFlowFailed', message)))\n\t\t\t\t\t\t\t\t\tresponse.writeHead(status, { 'Content-Type': 'text/plain' })\n\t\t\t\t\t\t\t\t\tresponse.end(message)\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tif (url.pathname !== '/callback') return fail('Not found', 404)\n\t\t\t\t\t\t\t\tconst oauthError = url.searchParams.get('error')\n\t\t\t\t\t\t\t\tif (oauthError !== null)\n\t\t\t\t\t\t\t\t\treturn fail(url.searchParams.get('error_description') ?? oauthError, 200)\n\t\t\t\t\t\t\t\tif (url.searchParams.get('state') !== state)\n\t\t\t\t\t\t\t\t\treturn fail('Invalid state - potential CSRF attack')\n\t\t\t\t\t\t\t\tconst received = url.searchParams.get('code')\n\t\t\t\t\t\t\t\tif (received === null) return fail('Missing authorization code')\n\t\t\t\t\t\t\t\tEffect.runSync(Deferred.succeed(callback, received))\n\t\t\t\t\t\t\t\tresponse.writeHead(200, { 'Content-Type': 'text/plain' })\n\t\t\t\t\t\t\t\tresponse.end('xAI authorization successful. Return to fold.')\n\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\tserver.once('error', reject)\n\t\t\t\t\t\t\tserver.listen(XAI_BROWSER_PORT, '127.0.0.1', () => resolve(server))\n\t\t\t\t\t\t}),\n\t\t\t\t\tcatch: (cause) =>\n\t\t\t\t\t\tfailure(\n\t\t\t\t\t\t\t'BrowserFlowFailed',\n\t\t\t\t\t\t\t`Failed to start callback server on port ${XAI_BROWSER_PORT}`,\n\t\t\t\t\t\t\tcause,\n\t\t\t\t\t\t),\n\t\t\t\t}),\n\t\t\t\t(server) => Effect.promise(() => new Promise<void>((resolve) => server.close(() => resolve()))),\n\t\t\t)\n\t\t\tyield* options.onUrl(buildXaiAuthorizeUrl(pkce, state, nonce))\n\t\t\treturn yield* Deferred.await(callback).pipe(\n\t\t\t\tEffect.timeoutOrElse({\n\t\t\t\t\tduration: Duration.millis(options.timeoutMs ?? 300_000),\n\t\t\t\t\torElse: () => Effect.fail(failure('BrowserFlowFailed', 'OAuth callback timed out')),\n\t\t\t\t}),\n\t\t\t)\n\t\t}),\n\t)\n\treturn yield* exchangeCode(options.client, code, pkce.verifier)\n})\n",
|
|
7
|
+
"/** Persistent, single-flight xAI OAuth credential service and authenticated HTTP decorator. */\nimport * as NodeCrypto from '@effect/platform-node/NodeCrypto'\nimport { Clock, Context, Effect, Option, Semaphore } from 'effect'\nimport { HttpClient, HttpClientError, HttpClientRequest } from 'effect/unstable/http'\n\nimport { makeXaiAuthStore, type XaiAuthStore, type XaiTokenData } from './AuthStore'\nimport type { XaiBrowserFlowOptions, XaiDevicePrompt } from './OAuthFlows'\nimport {\n\tmakeXaiIssuerClient,\n\trefreshXaiAccessToken,\n\trunXaiBrowserFlow,\n\trunXaiDeviceFlow,\n\tXaiAuthError,\n} from './OAuthFlows'\n\nexport type XaiAuthService = {\n\treadonly get: Effect.Effect<XaiTokenData, XaiAuthError>\n\treadonly authenticateDevice: Effect.Effect<XaiTokenData, XaiAuthError>\n\treadonly authenticateBrowser: Effect.Effect<XaiTokenData, XaiAuthError>\n\treadonly logout: Effect.Effect<void, XaiAuthError>\n}\n\nexport class XaiAuth extends Context.Service<XaiAuth, XaiAuthService>()('fold/XaiAuth') {}\n\nexport type MakeXaiAuthOptions = {\n\treadonly store?: XaiAuthStore\n\treadonly onDeviceCode?: (prompt: XaiDevicePrompt) => Effect.Effect<void>\n\treadonly onBrowserUrl?: (url: string) => Effect.Effect<void>\n\treadonly browser?: Pick<XaiBrowserFlowOptions, 'timeoutMs'>\n}\n\nconst devicePrompt = (prompt: XaiDevicePrompt) =>\n\tEffect.log(`Open ${prompt.verificationUri} and enter code: ${prompt.userCode}`)\nconst browserPrompt = (url: string) => Effect.log(`Open this URL to authenticate xAI:\\n${url}`)\n\n/** Construct xAI auth over the ambient HttpClient. Interactive flows are explicit methods. */\nexport const makeXaiAuth = Effect.fnUntraced(function* (options?: MakeXaiAuthOptions) {\n\tconst store = options?.store ?? makeXaiAuthStore()\n\tconst client = makeXaiIssuerClient(yield* HttpClient.HttpClient)\n\tconst semaphore = Semaphore.makeUnsafe(1)\n\tlet current = yield* store.load\n\tconst storeError = (cause: unknown) =>\n\t\tnew XaiAuthError({\n\t\t\treason: 'StoreFailed',\n\t\t\tmessage: `Failed to persist xAI credentials to ${store.path}`,\n\t\t\tcause,\n\t\t})\n\tconst save = (token: XaiTokenData) =>\n\t\tstore.save(token).pipe(\n\t\t\tEffect.mapError(storeError),\n\t\t\tEffect.tap(() =>\n\t\t\t\tEffect.sync(() => {\n\t\t\t\t\tcurrent = Option.some(token)\n\t\t\t\t}),\n\t\t\t),\n\t\t)\n\tconst get = Effect.uninterruptibleMask(\n\t\tEffect.fnUntraced(function* (restore) {\n\t\t\tconst now = yield* Clock.currentTimeMillis\n\t\t\tif (Option.isSome(current) && !current.value.isExpired(now)) return current.value\n\t\t\tif (Option.isNone(current))\n\t\t\t\treturn yield* new XaiAuthError({\n\t\t\t\t\treason: 'NotAuthenticated',\n\t\t\t\t\tmessage: `No xAI OAuth credentials found in ${store.path}`,\n\t\t\t\t})\n\t\t\treturn yield* restore(refreshXaiAccessToken(client, current.value.refresh)).pipe(Effect.flatMap(save))\n\t\t}),\n\t)\n\tconst run = (flow: Effect.Effect<XaiTokenData, XaiAuthError>) =>\n\t\tEffect.uninterruptibleMask((restore) => restore(flow).pipe(Effect.flatMap(save)))\n\treturn {\n\t\tget: semaphore.withPermit(get).pipe(Effect.withSpan('fold.xaiAuth.get')),\n\t\tauthenticateDevice: semaphore\n\t\t\t.withPermit(run(runXaiDeviceFlow({ client, onCode: options?.onDeviceCode ?? devicePrompt })))\n\t\t\t.pipe(Effect.withSpan('fold.xaiAuth.authenticateDevice')),\n\t\tauthenticateBrowser: semaphore\n\t\t\t.withPermit(\n\t\t\t\trun(\n\t\t\t\t\trunXaiBrowserFlow({\n\t\t\t\t\t\tclient,\n\t\t\t\t\t\tonUrl: options?.onBrowserUrl ?? browserPrompt,\n\t\t\t\t\t\t...options?.browser,\n\t\t\t\t\t}).pipe(Effect.provide(NodeCrypto.layer)),\n\t\t\t\t),\n\t\t\t)\n\t\t\t.pipe(Effect.withSpan('fold.xaiAuth.authenticateBrowser')),\n\t\tlogout: semaphore\n\t\t\t.withPermit(\n\t\t\t\tstore.clear.pipe(\n\t\t\t\t\tEffect.mapError(storeError),\n\t\t\t\t\tEffect.tap(() =>\n\t\t\t\t\t\tEffect.sync(() => {\n\t\t\t\t\t\t\tcurrent = Option.none()\n\t\t\t\t\t\t}),\n\t\t\t\t\t),\n\t\t\t\t),\n\t\t\t)\n\t\t\t.pipe(Effect.withSpan('fold.xaiAuth.logout')),\n\t} satisfies XaiAuthService\n})\n\n/** Inject the current OAuth bearer token into every request without mutating caller headers. */\nexport const withXaiAuth = (client: HttpClient.HttpClient, auth: XaiAuthService): HttpClient.HttpClient =>\n\tclient.pipe(\n\t\tHttpClient.mapRequestEffect((request) =>\n\t\t\tauth.get.pipe(\n\t\t\t\tEffect.map((token) =>\n\t\t\t\t\trequest.pipe(\n\t\t\t\t\t\tHttpClientRequest.bearerToken(token.access),\n\t\t\t\t\t\tHttpClientRequest.setHeader('User-Agent', 'fold/xai-oauth'),\n\t\t\t\t\t),\n\t\t\t\t),\n\t\t\t\tEffect.mapError(\n\t\t\t\t\t(cause) =>\n\t\t\t\t\t\tnew HttpClientError.HttpClientError({\n\t\t\t\t\t\t\treason: new HttpClientError.TransportError({\n\t\t\t\t\t\t\t\trequest,\n\t\t\t\t\t\t\t\tcause,\n\t\t\t\t\t\t\t\tdescription: `xAI authentication failed: ${cause.message}`,\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t}),\n\t\t\t\t),\n\t\t\t),\n\t\t),\n\t)\n",
|
|
8
|
+
"/** FoldModel factory for xAI's OpenAI-compatible inference API authenticated with OAuth. */\nimport { OpenAiClient, OpenAiLanguageModel } from '@effect/ai-openai-compat'\nimport { customModel, resolveOpenAiReasoning } from '@humanlayer/fold-core'\nimport type { FoldModel, ReasoningLevel } from '@humanlayer/fold-core'\nimport { Context, Effect, Layer } from 'effect'\nimport type { Scope } from 'effect'\nimport type { LanguageModel } from 'effect/unstable/ai'\nimport { FetchHttpClient, HttpClient } from 'effect/unstable/http'\n\nimport type { XaiAuthStore } from './AuthStore'\nimport { makeXaiAuth, withXaiAuth } from './XaiAuth'\n\nexport const XAI_API_URL = 'https://api.x.ai/v1'\nexport const DEFAULT_XAI_MODEL_ID = 'grok-4.6'\n\nexport type XaiModelOptions = {\n\treadonly model?: string\n\treadonly reasoning?: ReasoningLevel\n\treadonly providerId?: string\n\treadonly apiUrl?: string\n\treadonly store?: XaiAuthStore\n}\n\n/** Build xAI's stock OpenAI-compatible LanguageModel over the OAuth transport. */\nexport const makeXaiLanguageModel = (\n\toptions: XaiModelOptions,\n): Effect.Effect<LanguageModel.Service, never, Scope.Scope> =>\n\tEffect.gen(function* () {\n\t\tconst httpContext = yield* Layer.build(FetchHttpClient.layer)\n\t\tconst base = Context.get(httpContext, HttpClient.HttpClient)\n\t\tconst auth = yield* makeXaiAuth(options.store === undefined ? {} : { store: options.store }).pipe(\n\t\t\tEffect.provideService(HttpClient.HttpClient, base),\n\t\t)\n\t\tconst clientContext = yield* Layer.build(OpenAiClient.layer({ apiUrl: options.apiUrl ?? XAI_API_URL })).pipe(\n\t\t\tEffect.provideService(HttpClient.HttpClient, withXaiAuth(base, auth)),\n\t\t)\n\t\treturn yield* OpenAiLanguageModel.make({ model: options.model ?? DEFAULT_XAI_MODEL_ID }).pipe(\n\t\t\tEffect.provideService(OpenAiClient.OpenAiClient, Context.get(clientContext, OpenAiClient.OpenAiClient)),\n\t\t)\n\t})\n\n/** Describe an xAI OAuth-backed model compatible with Fold sessions and switching. */\nexport const xaiModel = (options: XaiModelOptions = {}): FoldModel => {\n\tconst level = options.reasoning ?? 'off'\n\treturn customModel({\n\t\tactiveModel: {\n\t\t\tproviderId: options.providerId ?? 'xai',\n\t\t\tproviderKind: 'openai-compatible',\n\t\t\tmodelId: options.model ?? DEFAULT_XAI_MODEL_ID,\n\t\t\trole: null,\n\t\t\trequestedReasoningLevel: level,\n\t\t\treasoning: resolveOpenAiReasoning(level),\n\t\t},\n\t\tmake: makeXaiLanguageModel(options),\n\t})\n}\n"
|
|
9
9
|
],
|
|
10
|
-
"mappings": ";AASA;AACA;AAEA;AACA;AAGO,IAAM,yBAAyB;AAG/B,IAAM,uBAAuB,MAAc,KAAK,QAAQ,GAAG,SAAS,WAAW;AAAA;AAG/E,MAAM,qBAAqB,OAAO,MAAoB,mBAAmB,EAAE;AAAA,EACjF,MAAM,OAAO,QAAQ,OAAO;AAAA,EAC5B,QAAQ,OAAO;AAAA,EACf,SAAS,OAAO;AAAA,EAChB,SAAS,OAAO;AAAA,EAChB,WAAW,OAAO,SAAS,OAAO,MAAM;AACzC,CAAC,EAAE;AAAA,EAEF,SAAS,CAAC,OAAwB;AAAA,IACjC,OAAO,KAAK,UAAU,QAAQ;AAAA;AAEhC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AS,QAAQ,SAAS;AAAA,MAC1B,MAAM;AAAA,MACN,yBAAyB;AAAA,MACzB,WAAW,uBAAuB,KAAK;AAAA,IACxC;AAAA,IACA,MAAM,qBAAqB,OAAO;AAAA,EACnC,CAAC;AAAA;",
|
|
11
|
+
"debugId": "9B16DD2CDF62A61964756E2164756E21",
|
|
12
12
|
"names": []
|
|
13
13
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@humanlayer/fold-xai",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"private": false,
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -19,10 +19,10 @@
|
|
|
19
19
|
"test:watch": "bun vitest"
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@humanlayer/fold-core": "0.1.
|
|
22
|
+
"@humanlayer/fold-core": "0.1.3"
|
|
23
23
|
},
|
|
24
24
|
"peerDependencies": {
|
|
25
|
-
"@effect/ai-openai": "4.0.0-rc.109",
|
|
25
|
+
"@effect/ai-openai-compat": "4.0.0-rc.109",
|
|
26
26
|
"@effect/platform-node": "4.0.0-rc.109",
|
|
27
27
|
"effect": "4.0.0-rc.109"
|
|
28
28
|
},
|