@humanlayer/fold-xai 0.1.9 → 0.1.11

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.
@@ -37,11 +37,7 @@ export type MakeXaiAuthStoreOptions = {
37
37
  readonly path?: string;
38
38
  /** Key of this provider's entry in the document. Defaults to `xai`. */
39
39
  readonly providerId?: string;
40
- /** FileSystem implementation override. Defaults to the Node platform filesystem. */
41
- readonly fileSystem?: FileSystem.FileSystem;
42
40
  };
43
- /** The process-wide Node FileSystem service, built lazily once (layer construction is synchronous). */
44
- export declare const defaultNodeFileSystem: () => FileSystem.FileSystem;
45
41
  /** Build a file-backed Xai credential store. */
46
- export declare const makeXaiAuthStore: (options?: MakeXaiAuthStoreOptions) => XaiAuthStore;
42
+ export declare const makeXaiAuthStore: (options?: MakeXaiAuthStoreOptions) => Effect.Effect<XaiAuthStore, never, FileSystem.FileSystem>;
47
43
  export {};
package/dist/XaiAuth.d.ts CHANGED
@@ -24,7 +24,7 @@ export declare const makeXaiAuth: (options?: MakeXaiAuthOptions | undefined) =>
24
24
  authenticateDevice: Effect.Effect<XaiTokenData, XaiAuthError, never>;
25
25
  authenticateBrowser: Effect.Effect<XaiTokenData, XaiAuthError, never>;
26
26
  logout: Effect.Effect<void, XaiAuthError, never>;
27
- }, never, HttpClient.HttpClient>;
27
+ }, never, import("effect/FileSystem").FileSystem | HttpClient.HttpClient>;
28
28
  /** Inject the current OAuth bearer token into every request without mutating caller headers. */
29
29
  export declare const withXaiAuth: (client: HttpClient.HttpClient, auth: XaiAuthService) => HttpClient.HttpClient;
30
30
  export {};
package/dist/index.js CHANGED
@@ -1,8 +1,7 @@
1
1
  // packages/fold-xai/src/AuthStore.ts
2
2
  import { homedir } from "node:os";
3
3
  import { dirname, join } from "node:path";
4
- import * as NodeFileSystem from "@effect/platform-node/NodeFileSystem";
5
- import { Context, Effect, FileSystem, Layer, Option, Schema } from "effect";
4
+ import { Effect, FileSystem, Option, Schema } from "effect";
6
5
  var TOKEN_EXPIRY_BUFFER_MS = 30000;
7
6
  var defaultAuthStorePath = () => join(homedir(), ".fold", "auth.json");
8
7
 
@@ -24,13 +23,6 @@ class XaiAuthStoreError extends Schema.TaggedError()("XaiAuthStoreError", {
24
23
  cause: Schema.optional(Schema.Defect())
25
24
  }) {
26
25
  }
27
- var nodeFileSystem = null;
28
- var defaultNodeFileSystem = () => {
29
- if (nodeFileSystem === null) {
30
- nodeFileSystem = Effect.runSync(Effect.scoped(Layer.build(NodeFileSystem.layer).pipe(Effect.map((context) => Context.get(context, FileSystem.FileSystem)))));
31
- }
32
- return nodeFileSystem;
33
- };
34
26
  var AuthDocument = Schema.Record(Schema.String, Schema.Unknown);
35
27
  var decodeDocument = Schema.decodeUnknownOption(Schema.fromJsonString(AuthDocument));
36
28
  var decodeToken = Schema.decodeUnknownOption(XaiTokenData);
@@ -41,8 +33,7 @@ var encodeToken = (token) => ({
41
33
  expires: token.expires,
42
34
  ...token.accountId === undefined ? {} : { accountId: token.accountId }
43
35
  });
44
- var makeXaiAuthStore = (options) => {
45
- const fs = options?.fileSystem ?? defaultNodeFileSystem();
36
+ var makeXaiAuthStore = (options) => Effect.map(FileSystem.FileSystem, (fs) => {
46
37
  const path = options?.path ?? defaultAuthStorePath();
47
38
  const providerId = options?.providerId ?? "xai";
48
39
  const readDocument = fs.readFileString(path).pipe(Effect.flatMap((content) => {
@@ -83,10 +74,10 @@ var makeXaiAuthStore = (options) => {
83
74
  yield* writeDocument(rest);
84
75
  }).pipe(Effect.withSpan("fold.xaiAuthStore.clear"));
85
76
  return { path, load, save, clear };
86
- };
77
+ });
87
78
  // packages/fold-xai/src/OAuthFlows.ts
88
79
  import { createServer } from "node:http";
89
- import { Clock, Crypto, Deferred, Duration, Effect as Effect2, Schedule, Schema as Schema2 } from "effect";
80
+ import { Clock, Crypto, Deferred, Duration, Effect as Effect2, Result, Schedule, Schema as Schema2 } from "effect";
90
81
  import { HttpClient, HttpClientRequest, HttpClientResponse } from "effect/unstable/http";
91
82
  var XAI_CLIENT_ID = "b1a00492-073a-47ea-816f-4c329264a828";
92
83
  var XAI_ISSUER = "https://auth.x.ai";
@@ -179,7 +170,7 @@ var runXaiDeviceFlow = Effect2.fn("fold.xaiAuth.deviceFlow")(function* (options)
179
170
  device_code: device.device_code
180
171
  }), options.client.execute, Effect2.result);
181
172
  const result = yield* poll;
182
- if (result._tag === "Success")
173
+ if (Result.isSuccess(result))
183
174
  return yield* decodeToken2(result.success, "DeviceFlowFailed", "Failed to decode the xAI device token");
184
175
  const body = result.failure.response === undefined ? {} : yield* HttpClientResponse.schemaBodyJson(DeviceError)(result.failure.response).pipe(Effect2.orElseSucceed(() => ({})));
185
176
  if (body.error === "access_denied" || body.error === "authorization_denied")
@@ -264,15 +255,15 @@ var runXaiBrowserFlow = Effect2.fn("fold.xaiAuth.browserFlow")(function* (option
264
255
  });
265
256
  // packages/fold-xai/src/XaiAuth.ts
266
257
  import * as NodeCrypto from "@effect/platform-node/NodeCrypto";
267
- import { Clock as Clock2, Context as Context2, Effect as Effect3, Option as Option2, Semaphore } from "effect";
258
+ import { Clock as Clock2, Context, Effect as Effect3, Option as Option2, Semaphore } from "effect";
268
259
  import { HttpClient as HttpClient2, HttpClientError, HttpClientRequest as HttpClientRequest2 } from "effect/unstable/http";
269
- class XaiAuth extends Context2.Service()("fold/XaiAuth") {
260
+ class XaiAuth extends Context.Service()("fold/XaiAuth") {
270
261
  }
271
262
  var devicePrompt = (prompt) => Effect3.log(`Open ${prompt.verificationUri} and enter code: ${prompt.userCode}`);
272
263
  var browserPrompt = (url) => Effect3.log(`Open this URL to authenticate xAI:
273
264
  ${url}`);
274
265
  var makeXaiAuth = Effect3.fnUntraced(function* (options) {
275
- const store = options?.store ?? makeXaiAuthStore();
266
+ const store = options?.store ?? (yield* makeXaiAuthStore());
276
267
  const client = makeXaiIssuerClient(yield* HttpClient2.HttpClient);
277
268
  const semaphore = Semaphore.makeUnsafe(1);
278
269
  let current = yield* store.load;
@@ -318,18 +309,19 @@ var withXaiAuth = (client, auth) => client.pipe(HttpClient2.mapRequestEffect((re
318
309
  })))));
319
310
  // packages/fold-xai/src/XaiModel.ts
320
311
  import { OpenAiClient, OpenAiLanguageModel } from "@effect/ai-openai-compat";
312
+ import * as NodeFileSystem from "@effect/platform-node/NodeFileSystem";
321
313
  import { customModel, resolveOpenAiReasoning } from "@humanlayer/fold-core";
322
- import { Context as Context3, Effect as Effect4, Layer as Layer2 } from "effect";
314
+ import { Context as Context2, Effect as Effect4, Layer } from "effect";
323
315
  import { FetchHttpClient, HttpClient as HttpClient3 } from "effect/unstable/http";
324
316
  var XAI_API_URL = "https://api.x.ai/v1";
325
317
  var DEFAULT_XAI_MODEL_ID = "grok-4.6";
326
318
  var makeXaiLanguageModel = (options) => Effect4.gen(function* () {
327
- const httpContext = yield* Layer2.build(FetchHttpClient.layer);
328
- const base = Context3.get(httpContext, HttpClient3.HttpClient);
319
+ const httpContext = yield* Layer.build(FetchHttpClient.layer);
320
+ const base = Context2.get(httpContext, HttpClient3.HttpClient);
329
321
  const auth = yield* makeXaiAuth(options.store === undefined ? {} : { store: options.store }).pipe(Effect4.provideService(HttpClient3.HttpClient, base));
330
- const clientContext = yield* Layer2.build(OpenAiClient.layer({ apiUrl: options.apiUrl ?? XAI_API_URL })).pipe(Effect4.provideService(HttpClient3.HttpClient, withXaiAuth(base, auth)));
331
- return yield* OpenAiLanguageModel.make({ model: options.model ?? DEFAULT_XAI_MODEL_ID }).pipe(Effect4.provideService(OpenAiClient.OpenAiClient, Context3.get(clientContext, OpenAiClient.OpenAiClient)));
332
- });
322
+ const clientContext = yield* Layer.build(OpenAiClient.layer({ apiUrl: options.apiUrl ?? XAI_API_URL })).pipe(Effect4.provideService(HttpClient3.HttpClient, withXaiAuth(base, auth)));
323
+ return yield* OpenAiLanguageModel.make({ model: options.model ?? DEFAULT_XAI_MODEL_ID }).pipe(Effect4.provideService(OpenAiClient.OpenAiClient, Context2.get(clientContext, OpenAiClient.OpenAiClient)));
324
+ }).pipe(Effect4.provide(NodeFileSystem.layer));
333
325
  var xaiModel = (options = {}) => {
334
326
  const level = options.reasoning ?? "off";
335
327
  return customModel({
@@ -355,7 +347,6 @@ export {
355
347
  makeXaiAuthStore,
356
348
  makeXaiAuth,
357
349
  generateXaiPkce,
358
- defaultNodeFileSystem,
359
350
  defaultAuthStorePath,
360
351
  buildXaiAuthorizeUrl,
361
352
  XaiTokenData,
@@ -372,4 +363,4 @@ export {
372
363
  DEFAULT_XAI_MODEL_ID
373
364
  };
374
365
 
375
- //# debugId=9B16DD2CDF62A61964756E2164756E21
366
+ //# debugId=6FEA9BA75294388164756E2164756E21
package/dist/index.js.map CHANGED
@@ -2,12 +2,12 @@
2
2
  "version": 3,
3
3
  "sources": ["../src/AuthStore.ts", "../src/OAuthFlows.ts", "../src/XaiAuth.ts", "../src/XaiModel.ts"],
4
4
  "sourcesContent": [
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, 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"
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 { Effect, FileSystem, 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}\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 = (\n\toptions?: MakeXaiAuthStoreOptions,\n): Effect.Effect<XaiAuthStore, never, FileSystem.FileSystem> =>\n\tEffect.map(FileSystem.FileSystem, (fs) => {\n\t\tconst path = options?.path ?? defaultAuthStorePath()\n\t\tconst providerId = options?.providerId ?? 'xai'\n\n\t\tconst readDocument: Effect.Effect<Record<string, unknown>> = fs.readFileString(path).pipe(\n\t\t\tEffect.flatMap((content) => {\n\t\t\t\tconst document = decodeDocument(content)\n\t\t\t\treturn Option.isSome(document)\n\t\t\t\t\t? Effect.succeed(document.value)\n\t\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\t\tEffect.as<Record<string, unknown>>({}),\n\t\t\t\t\t\t)\n\t\t\t}),\n\t\t\t// A missing (or unreadable) document is simply \"no credentials stored yet\".\n\t\t\tEffect.catch(() => Effect.succeed<Record<string, unknown>>({})),\n\t\t)\n\n\t\tconst writeDocument = (document: Record<string, unknown>): Effect.Effect<void, XaiAuthStoreError> =>\n\t\t\tEffect.gen(function* () {\n\t\t\t\tyield* fs.makeDirectory(dirname(path), { recursive: true })\n\t\t\t\tyield* fs.writeFileString(path, `${JSON.stringify(document, null, 2)}\\n`, { mode: 0o600 })\n\t\t\t\t// writeFileString's mode only applies on creation; force 0600 on pre-existing documents too.\n\t\t\t\tyield* fs.chmod(path, 0o600)\n\t\t\t}).pipe(\n\t\t\t\tEffect.mapError(\n\t\t\t\t\t(cause) =>\n\t\t\t\t\t\tnew XaiAuthStoreError({\n\t\t\t\t\t\t\treason: 'WriteFailed',\n\t\t\t\t\t\t\tmessage: `Failed to write the auth store at ${path}`,\n\t\t\t\t\t\t\tcause,\n\t\t\t\t\t\t}),\n\t\t\t\t),\n\t\t\t)\n\n\t\tconst load = Effect.gen(function* () {\n\t\t\tconst document = yield* readDocument\n\t\t\tconst entry = document[providerId]\n\t\t\tif (entry === undefined) return Option.none<XaiTokenData>()\n\n\t\t\tconst token = decodeToken(entry)\n\t\t\tif (Option.isNone(token)) {\n\t\t\t\tyield* Effect.logWarning(`Ignoring invalid \"${providerId}\" entry in ${path}`)\n\t\t\t}\n\n\t\t\treturn token\n\t\t}).pipe(Effect.withSpan('fold.xaiAuthStore.load'))\n\n\t\tconst save = (token: XaiTokenData) =>\n\t\t\tEffect.gen(function* () {\n\t\t\t\tconst document = yield* readDocument\n\t\t\t\tyield* writeDocument({ ...document, [providerId]: encodeToken(token) })\n\t\t\t\treturn token\n\t\t\t}).pipe(Effect.withSpan('fold.xaiAuthStore.save'))\n\n\t\tconst clear = Effect.gen(function* () {\n\t\t\tconst document = yield* readDocument\n\t\t\tif (document[providerId] === undefined) return\n\t\t\tconst { [providerId]: _removed, ...rest } = document\n\t\t\tyield* writeDocument(rest)\n\t\t}).pipe(Effect.withSpan('fold.xaiAuthStore.clear'))\n\n\t\treturn { path, load, save, clear }\n\t})\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, Crypto, Deferred, Duration, Effect, Result, 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.isSuccess(result))\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 ?? (yield* 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 * as NodeFileSystem from '@effect/platform-node/NodeFileSystem'\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}).pipe(Effect.provide(NodeFileSystem.layer))\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;AAAA;AAGO,MAAM,0BAA0B,OAAO,YAA+B,EAAE,qBAAqB;AAAA,EACnG,QAAQ,OAAO,SAAS,CAAC,aAAa,CAAC;AAAA,EACvC,SAAS,OAAO;AAAA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": "6FEA9BA75294388164756E2164756E21",
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.9",
3
+ "version": "0.1.11",
4
4
  "private": false,
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -19,7 +19,7 @@
19
19
  "test:watch": "bun vitest"
20
20
  },
21
21
  "dependencies": {
22
- "@humanlayer/fold-core": "0.1.9"
22
+ "@humanlayer/fold-core": "0.1.11"
23
23
  },
24
24
  "peerDependencies": {
25
25
  "@effect/ai-openai-compat": "4.0.0-rc.109",