fix: move OpenAI key to secret installation parameter [AIS-295] - #11202
Open
Tyler Pina (tylerpina) wants to merge 17 commits into
Open
fix: move OpenAI key to secret installation parameter [AIS-295]#11202Tyler Pina (tylerpina) wants to merge 17 commits into
Tyler Pina (tylerpina) wants to merge 17 commits into
Conversation
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…IS-295] Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…IS-295] Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
… list [AIS-295] Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Replace AI class usage in useAI.tsx with sdk.cma.appActionCall.createWithResponse - Delete src/utils/aiApi/ directory (index.ts, aiHelpers.ts, handleAiApiErrors.ts) — no longer needed - Remove key/validateApiKey/apiError from useSidebarParameters — key is now a Secret and unreadable in browser - Remove apiError prop from DisplaySidebarWarning and Sidebar — key validation happens at generation time via App Action - Update related specs for new interfaces - Fix GeneratedTextPanel.tsx error type narrowing for unknown error from App Action Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Remove `key` from parameter mocks (initParameters, happyPathParameter, generateRandomParameters), delete orphaned AiMock and baseUrl files, fix stale vi.mock calls in panel specs, and cast sdk.cma as any in useAI.spec.ts to allow appActionCall assignment. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
The randomApiKey variable was only used to populate the key field in the return object, which was already removed. It is now dead code. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Replace unsafe (sdk.cma as any) casts with explicit type annotations to satisfy @typescript-eslint/no-explicit-any lint rule. Change messages parameter type from Symbol (256-char limit) to Text to accommodate JSON-stringified system prompts. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Wiz Scan Summary
To detect these findings earlier in the dev lifecycle, try the Wiz Code extension for VS Code, JetBrains, or Visual Studio. |
Replace hardcoded definition ids in the new upsert-actions and upsert-actions:test scripts with DEFINITIONS_APP_DEF_ID and DEV_TESTING_APP_DEF_ID env vars, matching the org-id/token env var pattern the deploy scripts already use. Also picks up the build/functions copy and openai proxy secret-param fixes. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Use DEFINITIONS_APP_DEF_ID env var in the deploy script and remove the deploy:test / upsert-actions:test variants; the env-var-driven scripts cover the test org by swapping in the appropriate values. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
The lockfile pinned @contentful/app-scripts and node-apps-toolkit to npm.pkg.github.com download URLs (baked in from a local install with a GitHub Packages token). CI has no such token, so npm ci failed with E401 Unauthorized. Both packages are published to the public registry with identical integrity hashes, so repoint the resolved URLs there. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
The newly added @contentful/app-scripts dependency pulls in esbuild,
whose install script must be explicitly allowlisted. allow-scripts
failed CI ("dependencies without configuration"). Add
@contentful/app-scripts>esbuild to lavamoat.allowScripts, matching
the entry other apps in the monorepo already use.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
CI checks changed files against the master merge-base with prettier@2.8.8. Format the six flagged files (line-wrapping only, no logic changes). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Since the OpenAI proxy fix removed token-by-token streaming, the generating state left an empty textarea. Replace it with Forma 36's SkeletonContainer/SkeletonBodyText — the grey pulsing lines used elsewhere in Contentful — so the wait for the full response reads as in-progress. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
sendStopSignal was a no-op. The proxy App Action is a single blocking call with no server-side cancel, so wire the button to a client-side abort: race the call against an AbortController signal, discard any late-arriving response, and drop back to the input view. A user stop is treated as a cancellation (GenerationAbortedError), not an error, so no error UI is shown. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…AIS-295] The proxy App Action collapses every OpenAI failure (429s included) into a generic Error with no status code, so the `error.status === 429` rate-limit branch could never match. Drop the dead branch along with its now-orphaned deps: the Hyperlink/ExternalLinkIcon imports, the `error` destructure, the `errorLink` style, and the three unused rateLimit* strings in errorMessages. 429s now show the default generate error. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
ParametersMissingWarning had no production import — only its own spec referenced it. Delete the component and its test. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
AIS-295
Summary
functions/openai-proxy.ts) that reads the OpenAI API key server-side viacontext.appInstallationParametersand proxies chat completion requests to OpenAI — the key never touches browser-side codecontentful-app-manifest.jsonwith an App Action (openaiProxyAction) so the Dialog location calls the function viasdk.cma.appActionCall.createWithResponseinstead of calling OpenAI directlykeyfromAppInstallationParametersand all browser-readable state; config screenAPIKeycomponent becomes write-only (admin can set a new key but can't read the current one back);Modeldropdown uses a hardcoded list instead of fetching via the key; sidebar key-validation removedTest plan
npm testpasses (55/55)npm run lintpasses (0 errors, 0 warnings)npx tsc --noEmitcleannpm run build:functionsemitsbuild/functions/openai-proxy.js3iszK8Gl7aaxLvxGyCOhgAprod,7sjBFUzBxj1fRrI0eUBwLctest) to declarekeyas"type": "Secret"via CMA or Contentful UIsdk.parameters.installation.keyreturns***in browser consolenpm run deploy:test) and confirm App Action invocation succeeds end-to-end in a test spaceNotes
Secrettype declaration (Task 6 in the plan) must be applied separately before deploy — without it, the key is still plaintext in the browser even after this code lands.AbortControllersignal, any late-arriving response is discarded, and the UI returns to the input view (a user stop is treated as a cancellation, not an error). The proxy call itself can't be terminated server-side — App Actions can't signal a running invocation and OpenAI's chat-completions API has no cancel endpoint — so the OpenAI request still completes/bills in the background.GeneratedTextPanel(the proxy collapses all OpenAI failures into a genericErrorwith no status code, so the branch could never match — 429s now show the default generate error) and its orphaned deps, plus the unusedParametersMissingWarningcomponent.Generated with Claude Code