-
Notifications
You must be signed in to change notification settings - Fork 673
Implement AI "stop" -- in the client, open ai responses/chat, and gemini backends #2704
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
d1013fc
f2d8ad9
e5a7460
d157666
f60ef02
91cc8f0
f51674b
6db7c33
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -7,9 +7,9 @@ import { globalStore } from "./jotaiStore"; | |||||||||||||
| import * as WOS from "./wos"; | ||||||||||||||
|
|
||||||||||||||
| const tabModelCache = new Map<string, TabModel>(); | ||||||||||||||
| const activeTabIdAtom = atom<string>(null) as PrimitiveAtom<string>; | ||||||||||||||
| export const activeTabIdAtom = atom<string>(null) as PrimitiveAtom<string>; | ||||||||||||||
|
|
||||||||||||||
| class TabModel { | ||||||||||||||
| export class TabModel { | ||||||||||||||
| tabId: string; | ||||||||||||||
| tabAtom: Atom<Tab>; | ||||||||||||||
| tabNumBlocksAtom: Atom<number>; | ||||||||||||||
|
|
@@ -40,7 +40,7 @@ class TabModel { | |||||||||||||
| } | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| function getTabModelByTabId(tabId: string): TabModel { | ||||||||||||||
| export function getTabModelByTabId(tabId: string): TabModel { | ||||||||||||||
| let model = tabModelCache.get(tabId); | ||||||||||||||
| if (model == null) { | ||||||||||||||
| model = new TabModel(tabId); | ||||||||||||||
|
|
@@ -49,22 +49,24 @@ function getTabModelByTabId(tabId: string): TabModel { | |||||||||||||
| return model; | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| function getActiveTabModel(): TabModel | null { | ||||||||||||||
| export function getActiveTabModel(): TabModel | null { | ||||||||||||||
| const activeTabId = globalStore.get(activeTabIdAtom); | ||||||||||||||
| if (activeTabId == null) { | ||||||||||||||
| return null; | ||||||||||||||
| } | ||||||||||||||
| return getTabModelByTabId(activeTabId); | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| const TabModelContext = createContext<TabModel | undefined>(undefined); | ||||||||||||||
| export const TabModelContext = createContext<TabModel | undefined>(undefined); | ||||||||||||||
|
|
||||||||||||||
| function useTabModel(): TabModel { | ||||||||||||||
| export function useTabModel(): TabModel { | ||||||||||||||
| const model = useContext(TabModelContext); | ||||||||||||||
| if (model == null) { | ||||||||||||||
| throw new Error("useTabModel must be used within a TabModelProvider"); | ||||||||||||||
| } | ||||||||||||||
| return model; | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| export { activeTabIdAtom, getActiveTabModel, getTabModelByTabId, TabModel, TabModelContext, useTabModel }; | ||||||||||||||
| export function maybeUseTabModel(): TabModel { | ||||||||||||||
| return useContext(TabModelContext); | ||||||||||||||
| } | ||||||||||||||
|
Comment on lines
+70
to
+72
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Return type should include
🔎 Proposed fix-export function maybeUseTabModel(): TabModel {
+export function maybeUseTabModel(): TabModel | undefined {
return useContext(TabModelContext);
}📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: wavetermdev/waveterm
Length of output: 618
🏁 Script executed:
rg "maybeUseTabModel|useTabModel" --type=tsx --type=ts -B 2 -A 5Repository: wavetermdev/waveterm
Length of output: 91
🏁 Script executed:
Repository: wavetermdev/waveterm
Length of output: 96
🏁 Script executed:
cat -n frontend/app/aipanel/aipanel.tsx | head -100Repository: wavetermdev/waveterm
Length of output: 4887
🏁 Script executed:
Repository: wavetermdev/waveterm
Length of output: 2567
🏁 Script executed:
rg "export function maybeUseTabModel|function maybeUseTabModel" -A 8 -B 2Repository: wavetermdev/waveterm
Length of output: 315
🏁 Script executed:
Repository: wavetermdev/waveterm
Length of output: 1442
🏁 Script executed:
cat -n frontend/app/store/tab-model.ts | head -50Repository: wavetermdev/waveterm
Length of output: 2011
🏁 Script executed:
rg "TabModelContext" -B 5 -A 3 frontend/app/store/tab-model.tsRepository: wavetermdev/waveterm
Length of output: 526
Fix return type annotation and add null-safety check for tabModel.
The
maybeUseTabModel()function has an incorrect return type annotation. It's declared to returnTabModel(line 9 import), but the actual implementation returnsuseContext(TabModelContext)where the context is typed asTabModel | undefinedwith anundefineddefault value.This creates a type safety issue at line 282:
If the component is used outside a
TabModelProvider,tabModelwill beundefinedat runtime, causing a crash.Required fixes:
maybeUseTabModel()return type toTabModel | undefined(or useuseTabModel()which properly throws)tabModel.tabIdon line 282, or use optional chaining:body.tabid = tabModel?.tabId;🤖 Prompt for AI Agents