2025-06-23 17:18:28 -07:00
|
|
|
import React, { createContext, useContext, ReactNode, useState } from "react";
|
2025-05-28 12:26:47 -07:00
|
|
|
import { useStream } from "@langchain/langgraph-sdk/react";
|
|
|
|
|
import {
|
|
|
|
|
uiMessageReducer,
|
|
|
|
|
isUIMessage,
|
|
|
|
|
isRemoveUIMessage,
|
|
|
|
|
type UIMessage,
|
|
|
|
|
type RemoveUIMessage,
|
|
|
|
|
} from "@langchain/langgraph-sdk/react-ui";
|
|
|
|
|
import { useQueryState } from "nuqs";
|
2025-06-18 11:03:39 -07:00
|
|
|
import { useThreadsContext } from "./Thread";
|
feat: Update chat UI to be Open SWE specific (#76) (#91)
* init repo-selector
* add branch selector UI, extend GH hook w branch info
* add reconnectOnMount: true resumeStream, remove repo description from selector, fix styling
* styling repo + branch
* udpate getBranch calls to include targetRepo arg
* format
* add search to repo + branch selectors
* add settings icon link to /github for dev convenience
* add default branch selection
* format
* minor cleanup
* init task list UI demo
* individual task component
* tasks real data
* task visual improvement
* persisting tasks, navigate to thread onClick
* task UI
* TaskSidebar, Navigate to tasks
* org tasks by thread
* group by thread
* improve sidebar, task-list, rm github modal on refresh
* collapse sidebar works when viewing a thread
* remove micro-tasks expansion from threads component, change taskId to taskIndex for persistence + simplicity
* init config sidebar ui
* open and close config sidebar
* add ref for getAllTasks + add graph_id metadata
* format
* create threadItem component
* format
* add threadUtils
* centralize + refactor types
* format
* improve thread status, realtime updates
* fix scroll issue
* remove temperature from config-sidebar
* Change model via sidebar
* fix flashing on updates
* init plan UI
* centralize types
* self CR: refactoring, cleanup, remove comments, add todos
* CR: clean comments + logs, fix repo selector bug
* fix: Update example env file in web (#77)
* disable auto scroll on pageload
* reposelector: use default branch not main master
* remove archived tab temp, default branch listed first in branchSelector dropdown
* auto select first repo
* improve status indicator
* refactor status indicator
* simplify status implementation to use Langgraph
* util moved from provider to thread-utils
* linting, improve task completion logic
* feat: Support followup requests (#60)
* feat: Support followup requests
* cr
* cr
* fix
* account for pr already exists
* remove task provider
* fix: Better prompting and context provided for codebase structure awareness (#85)
* fix: Better prompting and context provided for codebase structure awareness
* cr
* linting + skeleton loader
* fix: branch selector, add github api pagination
* small branch update
* update task completion status realtime
* threadItem stream remove flashing/polling
* feat: Create a shared package (#89)
* feat: Create a shared package
* formatting
* fix: drop passing target repo to getBranchName
* drop docs
* use shared package for config fields in config sidebar
* fix: styling and structure for repo/branch selectors
* fix: use shared types/objects for config fields
* default key for configs
* fix: improved styling for threads
* fix renering num tasks
* disable repo branch selector when chat started
* cr
* cr
* bump deps
* fix: rendering plan in interrupt
* cr
* cr
---------
Co-authored-by: Dylan Boudro <121908331+starmorph@users.noreply.github.com>
2025-06-08 17:29:40 -07:00
|
|
|
import { GraphState, GraphUpdate } from "@open-swe/shared/open-swe/types";
|
2025-06-19 11:53:56 -07:00
|
|
|
import {
|
|
|
|
|
CustomNodeEvent,
|
|
|
|
|
isCustomNodeEvent,
|
|
|
|
|
} from "@open-swe/shared/open-swe/custom-node-events";
|
2025-06-30 16:43:09 -06:00
|
|
|
import { MANAGER_GRAPH_ID } from "@open-swe/shared/constants";
|
2025-05-28 12:26:47 -07:00
|
|
|
|
|
|
|
|
const useTypedStream = useStream<
|
feat: Update chat UI to be Open SWE specific (#76) (#91)
* init repo-selector
* add branch selector UI, extend GH hook w branch info
* add reconnectOnMount: true resumeStream, remove repo description from selector, fix styling
* styling repo + branch
* udpate getBranch calls to include targetRepo arg
* format
* add search to repo + branch selectors
* add settings icon link to /github for dev convenience
* add default branch selection
* format
* minor cleanup
* init task list UI demo
* individual task component
* tasks real data
* task visual improvement
* persisting tasks, navigate to thread onClick
* task UI
* TaskSidebar, Navigate to tasks
* org tasks by thread
* group by thread
* improve sidebar, task-list, rm github modal on refresh
* collapse sidebar works when viewing a thread
* remove micro-tasks expansion from threads component, change taskId to taskIndex for persistence + simplicity
* init config sidebar ui
* open and close config sidebar
* add ref for getAllTasks + add graph_id metadata
* format
* create threadItem component
* format
* add threadUtils
* centralize + refactor types
* format
* improve thread status, realtime updates
* fix scroll issue
* remove temperature from config-sidebar
* Change model via sidebar
* fix flashing on updates
* init plan UI
* centralize types
* self CR: refactoring, cleanup, remove comments, add todos
* CR: clean comments + logs, fix repo selector bug
* fix: Update example env file in web (#77)
* disable auto scroll on pageload
* reposelector: use default branch not main master
* remove archived tab temp, default branch listed first in branchSelector dropdown
* auto select first repo
* improve status indicator
* refactor status indicator
* simplify status implementation to use Langgraph
* util moved from provider to thread-utils
* linting, improve task completion logic
* feat: Support followup requests (#60)
* feat: Support followup requests
* cr
* cr
* fix
* account for pr already exists
* remove task provider
* fix: Better prompting and context provided for codebase structure awareness (#85)
* fix: Better prompting and context provided for codebase structure awareness
* cr
* linting + skeleton loader
* fix: branch selector, add github api pagination
* small branch update
* update task completion status realtime
* threadItem stream remove flashing/polling
* feat: Create a shared package (#89)
* feat: Create a shared package
* formatting
* fix: drop passing target repo to getBranchName
* drop docs
* use shared package for config fields in config sidebar
* fix: styling and structure for repo/branch selectors
* fix: use shared types/objects for config fields
* default key for configs
* fix: improved styling for threads
* fix renering num tasks
* disable repo branch selector when chat started
* cr
* cr
* bump deps
* fix: rendering plan in interrupt
* cr
* cr
---------
Co-authored-by: Dylan Boudro <121908331+starmorph@users.noreply.github.com>
2025-06-08 17:29:40 -07:00
|
|
|
GraphState,
|
2025-05-28 12:26:47 -07:00
|
|
|
{
|
feat: Update chat UI to be Open SWE specific (#76) (#91)
* init repo-selector
* add branch selector UI, extend GH hook w branch info
* add reconnectOnMount: true resumeStream, remove repo description from selector, fix styling
* styling repo + branch
* udpate getBranch calls to include targetRepo arg
* format
* add search to repo + branch selectors
* add settings icon link to /github for dev convenience
* add default branch selection
* format
* minor cleanup
* init task list UI demo
* individual task component
* tasks real data
* task visual improvement
* persisting tasks, navigate to thread onClick
* task UI
* TaskSidebar, Navigate to tasks
* org tasks by thread
* group by thread
* improve sidebar, task-list, rm github modal on refresh
* collapse sidebar works when viewing a thread
* remove micro-tasks expansion from threads component, change taskId to taskIndex for persistence + simplicity
* init config sidebar ui
* open and close config sidebar
* add ref for getAllTasks + add graph_id metadata
* format
* create threadItem component
* format
* add threadUtils
* centralize + refactor types
* format
* improve thread status, realtime updates
* fix scroll issue
* remove temperature from config-sidebar
* Change model via sidebar
* fix flashing on updates
* init plan UI
* centralize types
* self CR: refactoring, cleanup, remove comments, add todos
* CR: clean comments + logs, fix repo selector bug
* fix: Update example env file in web (#77)
* disable auto scroll on pageload
* reposelector: use default branch not main master
* remove archived tab temp, default branch listed first in branchSelector dropdown
* auto select first repo
* improve status indicator
* refactor status indicator
* simplify status implementation to use Langgraph
* util moved from provider to thread-utils
* linting, improve task completion logic
* feat: Support followup requests (#60)
* feat: Support followup requests
* cr
* cr
* fix
* account for pr already exists
* remove task provider
* fix: Better prompting and context provided for codebase structure awareness (#85)
* fix: Better prompting and context provided for codebase structure awareness
* cr
* linting + skeleton loader
* fix: branch selector, add github api pagination
* small branch update
* update task completion status realtime
* threadItem stream remove flashing/polling
* feat: Create a shared package (#89)
* feat: Create a shared package
* formatting
* fix: drop passing target repo to getBranchName
* drop docs
* use shared package for config fields in config sidebar
* fix: styling and structure for repo/branch selectors
* fix: use shared types/objects for config fields
* default key for configs
* fix: improved styling for threads
* fix renering num tasks
* disable repo branch selector when chat started
* cr
* cr
* bump deps
* fix: rendering plan in interrupt
* cr
* cr
---------
Co-authored-by: Dylan Boudro <121908331+starmorph@users.noreply.github.com>
2025-06-08 17:29:40 -07:00
|
|
|
UpdateType: GraphUpdate;
|
2025-05-28 12:26:47 -07:00
|
|
|
CustomEventType: UIMessage | RemoveUIMessage;
|
|
|
|
|
}
|
|
|
|
|
>;
|
|
|
|
|
|
2025-06-19 11:53:56 -07:00
|
|
|
type StreamContextType = ReturnType<typeof useTypedStream> & {
|
|
|
|
|
customEvents: CustomNodeEvent[];
|
|
|
|
|
};
|
2025-05-28 12:26:47 -07:00
|
|
|
const StreamContext = createContext<StreamContextType | undefined>(undefined);
|
|
|
|
|
|
|
|
|
|
async function sleep(ms = 4000) {
|
|
|
|
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-23 17:18:28 -07:00
|
|
|
const StreamSession = ({ children }: { children: ReactNode }) => {
|
2025-05-28 12:26:47 -07:00
|
|
|
const [threadId, setThreadId] = useQueryState("threadId");
|
2025-06-19 11:53:56 -07:00
|
|
|
const [customEvents, setCustomEvents] = useState<CustomNodeEvent[]>([]);
|
|
|
|
|
const { refreshThreads } = useThreadsContext();
|
2025-06-23 17:18:28 -07:00
|
|
|
|
2025-06-30 16:43:09 -06:00
|
|
|
if (!process.env.NEXT_PUBLIC_API_URL) {
|
2025-06-23 17:46:19 -07:00
|
|
|
throw new Error(
|
2025-06-30 16:43:09 -06:00
|
|
|
"NEXT_PUBLIC_API_URL environment variable must be defined.",
|
2025-06-23 17:46:19 -07:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-28 12:26:47 -07:00
|
|
|
const streamValue = useTypedStream({
|
2025-06-23 17:46:19 -07:00
|
|
|
apiUrl: process.env.NEXT_PUBLIC_API_URL,
|
2025-06-30 16:43:09 -06:00
|
|
|
assistantId: MANAGER_GRAPH_ID,
|
feat: Update chat UI to be Open SWE specific (#76) (#91)
* init repo-selector
* add branch selector UI, extend GH hook w branch info
* add reconnectOnMount: true resumeStream, remove repo description from selector, fix styling
* styling repo + branch
* udpate getBranch calls to include targetRepo arg
* format
* add search to repo + branch selectors
* add settings icon link to /github for dev convenience
* add default branch selection
* format
* minor cleanup
* init task list UI demo
* individual task component
* tasks real data
* task visual improvement
* persisting tasks, navigate to thread onClick
* task UI
* TaskSidebar, Navigate to tasks
* org tasks by thread
* group by thread
* improve sidebar, task-list, rm github modal on refresh
* collapse sidebar works when viewing a thread
* remove micro-tasks expansion from threads component, change taskId to taskIndex for persistence + simplicity
* init config sidebar ui
* open and close config sidebar
* add ref for getAllTasks + add graph_id metadata
* format
* create threadItem component
* format
* add threadUtils
* centralize + refactor types
* format
* improve thread status, realtime updates
* fix scroll issue
* remove temperature from config-sidebar
* Change model via sidebar
* fix flashing on updates
* init plan UI
* centralize types
* self CR: refactoring, cleanup, remove comments, add todos
* CR: clean comments + logs, fix repo selector bug
* fix: Update example env file in web (#77)
* disable auto scroll on pageload
* reposelector: use default branch not main master
* remove archived tab temp, default branch listed first in branchSelector dropdown
* auto select first repo
* improve status indicator
* refactor status indicator
* simplify status implementation to use Langgraph
* util moved from provider to thread-utils
* linting, improve task completion logic
* feat: Support followup requests (#60)
* feat: Support followup requests
* cr
* cr
* fix
* account for pr already exists
* remove task provider
* fix: Better prompting and context provided for codebase structure awareness (#85)
* fix: Better prompting and context provided for codebase structure awareness
* cr
* linting + skeleton loader
* fix: branch selector, add github api pagination
* small branch update
* update task completion status realtime
* threadItem stream remove flashing/polling
* feat: Create a shared package (#89)
* feat: Create a shared package
* formatting
* fix: drop passing target repo to getBranchName
* drop docs
* use shared package for config fields in config sidebar
* fix: styling and structure for repo/branch selectors
* fix: use shared types/objects for config fields
* default key for configs
* fix: improved styling for threads
* fix renering num tasks
* disable repo branch selector when chat started
* cr
* cr
* bump deps
* fix: rendering plan in interrupt
* cr
* cr
---------
Co-authored-by: Dylan Boudro <121908331+starmorph@users.noreply.github.com>
2025-06-08 17:29:40 -07:00
|
|
|
reconnectOnMount: true,
|
2025-05-28 12:26:47 -07:00
|
|
|
threadId: threadId ?? null,
|
|
|
|
|
onCustomEvent: (event, options) => {
|
2025-06-19 11:53:56 -07:00
|
|
|
if (isCustomNodeEvent(event)) {
|
|
|
|
|
setCustomEvents((prev) => [...prev, event]);
|
|
|
|
|
}
|
2025-05-28 12:26:47 -07:00
|
|
|
if (isUIMessage(event) || isRemoveUIMessage(event)) {
|
|
|
|
|
options.mutate((prev) => {
|
|
|
|
|
const ui = uiMessageReducer(prev.ui ?? [], event);
|
|
|
|
|
return { ...prev, ui };
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
onThreadId: (id) => {
|
|
|
|
|
setThreadId(id);
|
feat: Update chat UI to be Open SWE specific (#76) (#91)
* init repo-selector
* add branch selector UI, extend GH hook w branch info
* add reconnectOnMount: true resumeStream, remove repo description from selector, fix styling
* styling repo + branch
* udpate getBranch calls to include targetRepo arg
* format
* add search to repo + branch selectors
* add settings icon link to /github for dev convenience
* add default branch selection
* format
* minor cleanup
* init task list UI demo
* individual task component
* tasks real data
* task visual improvement
* persisting tasks, navigate to thread onClick
* task UI
* TaskSidebar, Navigate to tasks
* org tasks by thread
* group by thread
* improve sidebar, task-list, rm github modal on refresh
* collapse sidebar works when viewing a thread
* remove micro-tasks expansion from threads component, change taskId to taskIndex for persistence + simplicity
* init config sidebar ui
* open and close config sidebar
* add ref for getAllTasks + add graph_id metadata
* format
* create threadItem component
* format
* add threadUtils
* centralize + refactor types
* format
* improve thread status, realtime updates
* fix scroll issue
* remove temperature from config-sidebar
* Change model via sidebar
* fix flashing on updates
* init plan UI
* centralize types
* self CR: refactoring, cleanup, remove comments, add todos
* CR: clean comments + logs, fix repo selector bug
* fix: Update example env file in web (#77)
* disable auto scroll on pageload
* reposelector: use default branch not main master
* remove archived tab temp, default branch listed first in branchSelector dropdown
* auto select first repo
* improve status indicator
* refactor status indicator
* simplify status implementation to use Langgraph
* util moved from provider to thread-utils
* linting, improve task completion logic
* feat: Support followup requests (#60)
* feat: Support followup requests
* cr
* cr
* fix
* account for pr already exists
* remove task provider
* fix: Better prompting and context provided for codebase structure awareness (#85)
* fix: Better prompting and context provided for codebase structure awareness
* cr
* linting + skeleton loader
* fix: branch selector, add github api pagination
* small branch update
* update task completion status realtime
* threadItem stream remove flashing/polling
* feat: Create a shared package (#89)
* feat: Create a shared package
* formatting
* fix: drop passing target repo to getBranchName
* drop docs
* use shared package for config fields in config sidebar
* fix: styling and structure for repo/branch selectors
* fix: use shared types/objects for config fields
* default key for configs
* fix: improved styling for threads
* fix renering num tasks
* disable repo branch selector when chat started
* cr
* cr
* bump deps
* fix: rendering plan in interrupt
* cr
* cr
---------
Co-authored-by: Dylan Boudro <121908331+starmorph@users.noreply.github.com>
2025-06-08 17:29:40 -07:00
|
|
|
sleep().then(() => {
|
|
|
|
|
refreshThreads().catch(console.error);
|
|
|
|
|
});
|
2025-05-28 12:26:47 -07:00
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return (
|
2025-06-19 11:53:56 -07:00
|
|
|
<StreamContext.Provider
|
|
|
|
|
value={{
|
|
|
|
|
...streamValue,
|
|
|
|
|
customEvents,
|
|
|
|
|
}}
|
|
|
|
|
>
|
2025-05-28 12:26:47 -07:00
|
|
|
{children}
|
|
|
|
|
</StreamContext.Provider>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
2025-06-23 17:18:28 -07:00
|
|
|
export const StreamProvider: React.FC<{
|
|
|
|
|
children: ReactNode;
|
|
|
|
|
}> = ({ children }) => {
|
|
|
|
|
return <StreamSession>{children}</StreamSession>;
|
2025-05-28 12:26:47 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const useStreamContext = (): StreamContextType => {
|
|
|
|
|
const context = useContext(StreamContext);
|
|
|
|
|
if (context === undefined) {
|
|
|
|
|
throw new Error("useStreamContext must be used within a StreamProvider");
|
|
|
|
|
}
|
|
|
|
|
return context;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default StreamContext;
|