Repository navigation
feat(plugin): add "Sign in with ChatGPT" LLM provider - #2617
jeff-ang92 wants to merge 3 commits into
Conversation
Adds a `chatgpt` provider to memos-local-plugin that runs summarizer and skill-evolver calls on the user's ChatGPT plan via OpenAI's Sign in with ChatGPT (OAuth PKCE, Responses API with store:false and stream:true). Falls back to the block's openai_compatible settings on usage limits, eligibility, auth or network failures. - core/llm/chatgpt-auth.ts: PKCE sign-in, ID token verification, owner-only token storage, lock-guarded refresh, stable host ID - core/llm/providers/chatgpt.ts: Responses streaming, 401 refresh, bounded 5xx retry, pause windows, fallback - scripts/chatgpt-login.mjs: sign in, --status, --models - config schema, client registry, skillEvolver wiring, log channel, model-test route, viewer dropdowns, docs, vitest coverage Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
🤖 Open Code ReviewTarget: PR #2617 🔍 OpenCodeReview found 20 issue(s) in this PR.
1.
|
- auth: tolerate corrupt token files, owner-checked refresh lock, folders chmod 700 (files 600), warn when owner-only access fails, JWKS status + strict kid matching, typed JWK, host-id temp cleanup, never print the ID token in the sign-in URL, keep models without a visibility field - provider: no pause for local sign-in states, no fallback without a fallback target, shared fallback gate, error mapping helper - wiring: l3Llm gets chatgpt + fallback inheritance; inherit the main llm endpoint/key only from OpenAI-compatible providers - schema: ChatGptProviderConfig derived from the schema; reasoningEffort reuses the reasoning effort union - settings: Test checks the ChatGPT sign-in; per-card hint; shared hint style; login script rejects unknown args and exits 1 without the plan scope - tests for each behaviour change Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Addressed the Open Code Review findings in d184491:
|
- wiring: inherit the main llm endpoint/key only as a pair - config: chatgpt defaults so llm/l3Llm/skillEvolver.chatgpt load without "unknown config key" warnings - provider: fall back only on ChatGPT outcomes (local bugs surface), map body read errors to ChatGPT failures, pause after a failure that follows streamed text - auth: ignore callbacks without this sign-in's state, default scopes when the token response omits them, report a busy callback port, bounded lock wait, document the id_token_hint argv limit - login script: reject empty --file= and --status with --models - tests for each behaviour change Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Second review round addressed in 7543d33:
|
Description
Adds a
chatgptLLM provider toapps/memos-local-pluginso MemOS can run its summarizer and skill-evolver calls on the user's own ChatGPT plan, using OpenAI's Sign in with ChatGPT for open-source and locally hosted apps. No API key is needed for the ChatGPT path. If ChatGPT is unavailable (usage limit, not eligible, signed out, network), the call falls back to the OpenAI-compatible settings already in the same config block (for example OpenRouter), so nothing stops working.How it works
core/llm/chatgpt-auth.ts— OAuth authorization code + PKCE (S256) with a loopback callback on 127.0.0.1. First sign-in registers throughdynamic_agent_clientand saves the issuedclient_id. Scopes includeoffline_accessandchatgpt.tokens.use.direct. The ID token is verified (RS256 against OpenAI's JWKS, plus iss/aud/exp/nonce). Tokens are stored owner-only (POSIXchmod 600, Windowsicacls) at~/.config/memos-local/chatgpt-oauth.json(override withMEMOS_CHATGPT_TOKEN_FILEorchatgpt.tokenFile). Refresh runs under a cross-process file lock, so several MemOS processes rotate the refresh token only once. Terminal refresh errors clear the tokens but keep theclient_id. Transient errors leave the file untouched. A stable opaqueext_agent_host_id(urn:uuid:<v4>) is created once before sign-in. Nothing logs or throws a token.core/llm/providers/chatgpt.ts— callsPOST /v1/responseswithstore: falseandstream: true, and counts a call as successful only onresponse.completed. System messages go intoinstructions.temperatureandmax_output_tokensare not sent, because this route does not accept them. JSON mode asks fortext.format: json_object; if the route rejects it, the provider drops it once and relies on the facade's JSON hint and parser. A 401 triggers one forced refresh and retry. 5xx errors retry with bounded backoff that respects the call deadline. A usage limit pauses ChatGPT for 30 minutes, "not eligible" for 6 hours and auth failures for 10 minutes; calls in that window go straight to the fallback.stream()falls back only if no text has reached the caller yet. Withchatgpt.fallback: false, errors map tollm_rate_limited,llm_timeoutorllm_unavailable.scripts/chatgpt-login.mjs—node scripts/chatgpt-login.mjssigns in;--statusshows sign-in state;--modelslists the plan's models. It never prints tokens.Wiring
core/llm/types.ts,client.ts,index.ts: newchatgptprovider name,ChatGptProviderConfig,makeProviderFor("chatgpt")and exports.core/config/schema.ts:provider: chatgptplus an optionalchatgpt:block (model,fallback,tokenFile,reasoningEffort) onllmandskillEvolver.core/pipeline/memory-core.ts: passesskillEvolver.chatgptthrough. A chatgpt skill evolver with a blankendpointorapiKeyreuses the mainllmblock's for its fallback; other providers are unchanged.core/logger/channels.ts:llm.chatgptchannel.server/routes/models.ts: the Settings "Test" button no longer throws "unsupported chat provider" forchatgpt. As withhostandbedrock, there is nothing to probe from the form.viewer:chatgptadded to the Summarizer and Skill Evolver provider dropdowns, with a short hint (EN and ZH) explaining sign-in and the fallback fields.package.jsonfiles: shipsscripts/chatgpt-login.mjs.core/llm/README.mdprovider table anddocs/CONFIG-ADVANCED.mdsection.Config example:
No new dependencies. Existing providers and configs are unaffected unless
provider: chatgptis chosen.Related Issue (Required): None (new feature, no prior issue)
Type of change
How Has This Been Tested?
Unit Test
Test Script Or Test Steps (please provide)
New:
tests/unit/llm/chatgpt-provider.test.ts(14 tests) covers the request body, streaming,response.completedgating,response.failed/response.incomplete/ cut streams, the 401 refresh-and-retry, bounded 503 retry, the usage-limit pause and its expiry, JSON-mode downgrade, the realLlmClient.completeJsonfacade,stream()fallback before the first delta, the not-signed-in fallback,makeProviderForand config-schema acceptance.New:
tests/unit/llm/chatgpt-auth.test.ts(8 tests) covers refresh near expiry with two parallel callers (one refresh, both tokens rotated), no network for a fresh token,invalid_grantclearing tokens while keepingclient_id, transient errors leaving the file untouched, the missing file, the missing plan scope, and host-ID creation and reuse with format checks.Extended:
tests/unit/pipeline/bootstrap-llm-config.test.ts(+2) checks thatskillEvolver.chatgptis passed through, and that the mainllmendpoint and key are inherited only forprovider: chatgpt.All use mocked
fetchand SSE streams and synthetic token files. No network, no real credentials.npm run lint(tsc --noEmit) and the viewer type check (tsc -p tsconfig.viewer.json --noEmit) are clean.vitest run tests/uniton Windows: 1614 passed, 43 failed, 12 skipped. Upstreammainat3a16e5fon the same machine gives 1590 passed, 43 failed, 12 skipped. The 43 failures are identical before and after this change (Windows-specific path, install-script and local-embedding tests).Checklist
🤖 Generated with Claude Code