Repository navigation
Conversation
|
The following comment was made by an LLM, it may be inaccurate: |
There was a problem hiding this comment.
The fix works. Over a plain-HTTP LAN origin (isSecureContext false, no crypto.randomUUID), the base shows "Failed to send command – crypto.randomUUID is not a function" for /btw. With this branch the side question tab opens (screenshots below; the answer itself fails here only because the sandbox has no model credentials). I built packages/app, ran the CLI from source on 0.0.0.0 in both checkouts and ran the issue's reproduction script in Chromium. The new test passes, and tsgo -b in packages/gui-extensions is clean.
Public API: unchanged.
The line that matters is crypto.randomUUID?.() ?? Math.random().toString(16).slice(2), which matches the fallback in packages/app/src/runtime/persistence/uuid.ts. Please cut the rest so this stays a one-line fix:
- The lazy
@opencode/ui/toastimport only exists so the unit test can load the module. It saves nothing in the bundle, becausebtw/panel.tsxin the same extension already imports@opencode/ui/toaststatically. It is also written as the inlineimport().then(...)chain that the rootAGENTS.mdsays to avoid. model.test.ts(86 lines with a hand-built context stub) can be dropped.packages/gui-extensions/AGENTS.mdkeeps unit tests for pure logic and leaves UI behaviour to the app e2e suites, and this fix doesn't need a test. Dropping it also removes the reason for the toast change.
| showToast({ title: ctx.t("question.required") }) | ||
| // Loaded lazily: the toast UI is heavy and only needed for this branch, | ||
| // and a static import would pull client-only UI code into unit tests. | ||
| void import("@opencode/ui/toast").then(({ showToast }) => showToast({ title: ctx.t("question.required") })) |
There was a problem hiding this comment.
This only exists so model.test.ts can import the module. It doesn't help the bundle, because btw/panel.tsx imports @opencode/ui/toast statically, and the root AGENTS.md asks to avoid inline import(...).then(...) chains. Please keep the original static import and drop the test, so the PR is just the randomUUID line.
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
The /btw command generated its chat id with crypto.randomUUID(), which is undefined outside secure contexts. Opening the web UI over plain HTTP (e.g. a LAN IP) made every /btw submission throw "crypto.randomUUID is not a function" and surface a "Failed to send command" toast. Fall back to a non-cryptographic id in that case, matching the existing fallback in packages/app/src/runtime/persistence/uuid.ts.
9e778da to
aa603b1
Compare
|
Thanks for the empirical validation and the sharp read. You're right on both counts: |


Issue for this PR
Closes #55777
Type of change
What does this PR do?
Serving the web UI over plain HTTP on a LAN IP means
isSecureContextis false, socrypto.randomUUIDisundefinedeven thoughcryptoitself exists.ask()inpackages/gui-extensions/src/btw/model.tscalledcrypto.randomUUID()directly and threwTypeError: crypto.randomUUID is not a functionbefore anything else ran, surfacing as the generic "Failed to send command" toast. The naive fix location (packages/app/src/runtime/persistence/uuid.ts) already had an insecure-context fallback — this call site was the unguarded one.Fix:
const id = crypto.randomUUID?.() ?? Math.random().toString(16).slice(2)— mirrors the existing app-side fallback, no new strings.Test-env side fix only:
model.tsstatically imported@opencode/ui/toast(solid-sonner), which throws at import time under bun's server-side test runtime, wheremock.modulecannot intercept the package specifier. The toast import is now lazy, in the empty-question branch only (per this repo's dynamic-import pattern in AGENTS.md). No production behavior change.How did you verify your code works?
packages/gui-extensions/src/btw/model.test.ts(2 tests): the insecure-context test fails pre-fix with the issue's exactTypeError, passes post-fix; secure-context control passes both ways. 2/2 green.bun run lint: 0 errors.tsgo -bon@opencode/gui-extensions,@opencode/core, and@opencode/cli: 0 errors. (The repo's pre-push hook runs a full-monorepo turbo typecheck which SIGKILLs the tsgo binary on this machine, so I verified package-by-package instead.)Screenshots / recordings
Not a visual change; n/a.
Checklist
If you do not follow this template your PR will be automatically rejected.
Added by the opencode bot (AI-generated).
Related: #46168, #48144, #50988