Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion openwiki/operations/credentials-and-updates.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ The file stores provider configuration and API keys:
- `OPENWIKI_PROVIDER_RETRY_ATTEMPTS` — optional positive integer retry count for transient provider request failures; defaults to 3 when unset
- Provider API keys: `OPENROUTER_API_KEY`, `OPENAI_API_KEY`, `OPENAI_COMPATIBLE_API_KEY`, `ANTHROPIC_API_KEY`, `BASETEN_API_KEY`, `FIREWORKS_API_KEY`, `GEMINI_API_KEY`, `NEBIUS_API_KEY`
- ChatGPT OAuth tokens (for the `openai-chatgpt` provider): `OPENAI_CHATGPT_ACCESS_TOKEN`, `OPENAI_CHATGPT_REFRESH_TOKEN`, `OPENAI_CHATGPT_EXPIRES_AT`, `OPENAI_CHATGPT_ACCOUNT_ID`, `OPENAI_CHATGPT_EMAIL`, `OPENAI_CHATGPT_PLAN`
- xAI Grok subscription OAuth tokens (for the `xai-grok` provider): `XAI_GROK_ACCESS_TOKEN`, `XAI_GROK_REFRESH_TOKEN`, `XAI_GROK_EXPIRES_AT`. Login uses xAI’s public Grok CLI OAuth client (PKCE, no client secret) against `auth.x.ai`; chat calls go to `https://api.x.ai/v1`. Tokens are never logged. Client id/scopes may change without an official OpenWiki app registration.
- Connector OAuth credentials: `OPENWIKI_GMAIL_ACCESS_TOKEN`, `OPENWIKI_GMAIL_REFRESH_TOKEN`, `OPENWIKI_GOOGLE_CLIENT_ID`, `OPENWIKI_GOOGLE_CLIENT_SECRET`, `OPENWIKI_NOTION_MCP_ACCESS_TOKEN`, `OPENWIKI_NOTION_MCP_CLIENT_ID`, `OPENWIKI_NOTION_MCP_REFRESH_TOKEN`, `OPENWIKI_SLACK_USER_TOKEN`, `OPENWIKI_SLACK_CLIENT_ID`, `OPENWIKI_SLACK_CLIENT_SECRET`, `OPENWIKI_X_ACCESS_TOKEN`, `OPENWIKI_X_CLIENT_ID`, `OPENWIKI_X_CLIENT_SECRET`, `OPENWIKI_X_REFRESH_TOKEN`
- Base URLs: `ANTHROPIC_BASE_URL` (optional — routes the anthropic provider at an Anthropic-compatible endpoint other than the default API), `OPENAI_COMPATIBLE_BASE_URL` (required by the openai-compatible provider, which has no default endpoint), and `OPENAI_BASE_URL` (optional — overrides the openai provider's default endpoint)
- AWS Bedrock credentials: `BEDROCK_AWS_ACCESS_KEY_ID`, `BEDROCK_AWS_SECRET_ACCESS_KEY`, `BEDROCK_AWS_REGION` (all required by the bedrock provider)
Expand Down Expand Up @@ -74,7 +75,7 @@ queries.
`src/credentials.tsx` provides the interactive bootstrap flow when required:

- prompts for a provider (arrow-key selection menu),
- prompts for the provider's API key (skipped for the gemini-enterprise provider, which prompts for a required Google Cloud project ID and an optional location instead; skipped for the bedrock provider, which prompts for AWS access key ID, secret access key, and region instead),
- prompts for the provider's API key (skipped for OAuth providers such as `openai-chatgpt` and `xai-grok`, which run a browser login instead; skipped for the gemini-enterprise provider, which prompts for a required Google Cloud project ID and an optional location instead; skipped for the bedrock provider, which prompts for AWS access key ID, secret access key, and region instead),
- prompts for a model choice (arrow-key selection from the provider's model list, or a custom model ID),
- optionally prompts for a LangSmith key,
- writes the results with restrictive file permissions,
Expand Down
3 changes: 2 additions & 1 deletion openwiki/quickstart.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ OpenWiki is a TypeScript CLI that writes and maintains documentation for a repos

- Launches an interactive Ink-based terminal app for chatting with the OpenWiki agent.
- Supports one-shot documentation runs with `--init`, `--update`, and `--print`.
- Supports multiple model providers — OpenAI (default, API key or ChatGPT OAuth login), OpenRouter, Anthropic, Gemini (AI Studio), Gemini Enterprise (Vertex AI, keyless via Google ADC), AWS Bedrock, Nebius Token Factory, Baseten, Fireworks, NVIDIA NIM, and any OpenAI-compatible gateway — each with their own credentials and model list (Gemini Enterprise uses Google ADC instead of an API key; Bedrock uses AWS access/secret keys and region).
- Supports multiple model providers — OpenAI (default, API key or ChatGPT OAuth login), Grok (xAI subscription OAuth), OpenRouter, Anthropic, Gemini (AI Studio), Gemini Enterprise (Vertex AI, keyless via Google ADC), AWS Bedrock, Nebius Token Factory, Baseten, Fireworks, NVIDIA NIM, and any OpenAI-compatible gateway — each with their own credentials and model list (Gemini Enterprise uses Google ADC instead of an API key; Bedrock uses AWS access/secret keys and region).
- Uses a DeepAgents local shell backend with virtual filesystem paths rooted at the target repository.
- Creates or refreshes documentation under the target repository's `openwiki/` directory.
- Auto-exits after successful `--init` or `--update` runs in an interactive terminal, so the CLI works as both a one-shot and interactive tool.
Expand All @@ -39,6 +39,7 @@ OpenWiki is a TypeScript CLI that writes and maintains documentation for a repos
- `src/agent/types.ts` — shared agent types (`OpenWikiCommand`, `RunContext`, `UpdateMetadata`, run options/events).
- `src/agent/docs-only-backend.ts` — `OpenWikiLocalShellBackend`, extends DeepAgents `LocalShellBackend` with docs-only write guards and output-mode awareness.
- `src/agent/openai-chatgpt-oauth.ts` — ChatGPT OAuth flow, token persistence, and refresh logic for the `openai-chatgpt` provider.
- `src/agent/xai-grok-oauth.ts` — xAI Grok subscription OAuth (browser PKCE), token persistence, and refresh for the `xai-grok` provider.
- `src/auth/oauth.ts` — generic OAuth runner for connector providers (Gmail, Notion, Slack, X).
- `src/auth/providers.ts` — connector OAuth provider configs (scopes, token URLs, env-key mappings).
- `src/auth/configure.ts` — `openwiki auth configure <provider>` flow for creating local connector configs.
Expand Down
29 changes: 29 additions & 0 deletions src/agent/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ import {
readCodexTokensFromEnv,
refreshChatGptTokens,
} from "./openai-chatgpt-oauth.js";
import {
ensureFreshXaiGrokTokens,
readXaiGrokTokensFromEnv,
XAI_API_BASE_URL,
XAI_GROK_LOGIN_INCOMPLETE_MESSAGE,
} from "./xai-grok-oauth.js";
import { createSystemPrompt, createUserPrompt } from "./prompt.js";
import { syncBundledSkills } from "./skills.js";
import {
Expand Down Expand Up @@ -188,6 +194,11 @@ export async function runOpenWikiAgent(
emitDebug(options, "chatgpt.token=fresh");
}

if (provider === "xai-grok") {
await ensureFreshXaiGrokTokens();
emitDebug(options, "xai-grok.token=fresh");
}

modelId = resolveModelId(options, provider);
emitDebug(options, `model=${modelId}`);
const providerRetryAttempts = resolveProviderRetryAttempts();
Expand Down Expand Up @@ -733,6 +744,24 @@ export function createModel(
});
}

if (provider === "xai-grok") {
// Already refreshed by `ensureFreshXaiGrokTokens()` before the run started.
const tokens = readXaiGrokTokensFromEnv();

if (!tokens) {
throw new Error(XAI_GROK_LOGIN_INCOMPLETE_MESSAGE);
}

return new ChatOpenAI({
apiKey: tokens.access,
model: modelId,
...retryOptions,
configuration: {
baseURL: XAI_API_BASE_URL,
},
});
}

if (provider === "openrouter") {
const providerOnly = resolveOpenRouterProviderOnly();

Expand Down
Loading