🚧 implement first version of SessionState reducer
This commit is contained in:
parent
129c811811
commit
cac32bf5eb
15 changed files with 409 additions and 125 deletions
19
extensions/vscode/schema/ContextItemId.d.ts
vendored
Normal file
19
extensions/vscode/schema/ContextItemId.d.ts
vendored
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
/* eslint-disable */
|
||||
/**
|
||||
* This file was automatically generated by json-schema-to-typescript.
|
||||
* DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
|
||||
* and run json-schema-to-typescript to regenerate this file.
|
||||
*/
|
||||
|
||||
export type ContextItemId = ContextItemId1;
|
||||
export type ProviderTitle = string;
|
||||
export type ItemId = string;
|
||||
|
||||
/**
|
||||
* A ContextItemId is a unique identifier for a ContextItem.
|
||||
*/
|
||||
export interface ContextItemId1 {
|
||||
provider_title: ProviderTitle;
|
||||
item_id: ItemId;
|
||||
[k: string]: unknown;
|
||||
}
|
||||
61
extensions/vscode/schema/SessionUpdate.d.ts
vendored
Normal file
61
extensions/vscode/schema/SessionUpdate.d.ts
vendored
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
/* eslint-disable */
|
||||
/**
|
||||
* This file was automatically generated by json-schema-to-typescript.
|
||||
* DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
|
||||
* and run json-schema-to-typescript to regenerate this file.
|
||||
*/
|
||||
|
||||
export type SessionUpdate = SessionUpdate1;
|
||||
export type Index = number;
|
||||
export type Update = SetStep | DeltaStep;
|
||||
export type StepType = string;
|
||||
export type Name = string;
|
||||
export type Description = string;
|
||||
export type Hide = boolean;
|
||||
export type Depth = number;
|
||||
export type Title = string;
|
||||
export type Message = string;
|
||||
export type Observations = Observation[];
|
||||
export type Logs = string[];
|
||||
export type Name1 = string;
|
||||
export type Description1 = string;
|
||||
export type Observations1 = Observation[];
|
||||
export type Logs1 = string[];
|
||||
export type Stop = boolean;
|
||||
|
||||
export interface SessionUpdate1 {
|
||||
index: Index;
|
||||
update: Update;
|
||||
stop?: Stop;
|
||||
[k: string]: unknown;
|
||||
}
|
||||
export interface SetStep {
|
||||
step_type?: StepType;
|
||||
name?: Name;
|
||||
description?: Description;
|
||||
params?: Params;
|
||||
hide?: Hide;
|
||||
depth?: Depth;
|
||||
error?: ContinueError;
|
||||
observations?: Observations;
|
||||
logs?: Logs;
|
||||
[k: string]: unknown;
|
||||
}
|
||||
export interface Params {
|
||||
[k: string]: unknown;
|
||||
}
|
||||
export interface ContinueError {
|
||||
title: Title;
|
||||
message: Message;
|
||||
[k: string]: unknown;
|
||||
}
|
||||
export interface Observation {
|
||||
[k: string]: unknown;
|
||||
}
|
||||
export interface DeltaStep {
|
||||
name?: Name1;
|
||||
description?: Description1;
|
||||
observations?: Observations1;
|
||||
logs?: Logs1;
|
||||
[k: string]: unknown;
|
||||
}
|
||||
|
|
@ -1,4 +1,5 @@
|
|||
import { ContextItem, ContextItemId } from "../schema/FullState";
|
||||
import { ContextItem } from "../schema/ContextItem";
|
||||
import { ContextItemId } from "../schema/ContextItemId";
|
||||
|
||||
abstract class AbstractContinueGUIClientProtocol {
|
||||
abstract sendMainInput(input: string): void;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
import { ContextItem, ContextItemId } from "../schema/FullState";
|
||||
import { ContextItem } from "../schema/ContextItem";
|
||||
import { ContextItemId } from "../schema/ContextItemId";
|
||||
import { SessionUpdate } from "../schema/SessionUpdate";
|
||||
import AbstractContinueGUIClientProtocol from "./AbstractContinueGUIClientProtocol";
|
||||
import { Messenger, SocketIOMessenger, WebsocketMessenger } from "./messenger";
|
||||
import { Messenger, SocketIOMessenger } from "./messenger";
|
||||
import { VscodeMessenger } from "./vscodeMessenger";
|
||||
|
||||
class ContinueGUIClientProtocol extends AbstractContinueGUIClientProtocol {
|
||||
|
|
@ -85,9 +87,7 @@ class ContinueGUIClientProtocol extends AbstractContinueGUIClientProtocol {
|
|||
|
||||
onStepUpdate(callback: (update: SessionUpdate) => void) {
|
||||
this.messenger?.onMessageType("step_update", (data: SessionUpdate) => {
|
||||
if (data.update) {
|
||||
callback(data.update);
|
||||
}
|
||||
callback(data);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,11 +0,0 @@
|
|||
import { RootStore } from "../store";
|
||||
|
||||
const selectChatMessages = (state: RootStore) => {
|
||||
return state.chat.messages;
|
||||
};
|
||||
|
||||
const selectIsStreaming = (state: RootStore) => {
|
||||
return state.chat.isStreaming;
|
||||
};
|
||||
|
||||
export { selectChatMessages, selectIsStreaming };
|
||||
|
|
@ -1,93 +0,0 @@
|
|||
import { createSlice } from "@reduxjs/toolkit";
|
||||
import { ChatMessage, RootStore } from "../store";
|
||||
|
||||
export const chatSlice = createSlice({
|
||||
name: "chat",
|
||||
initialState: {
|
||||
messages: [],
|
||||
isStreaming: false,
|
||||
} as RootStore["chat"],
|
||||
reducers: {
|
||||
addMessage: (
|
||||
state,
|
||||
action: {
|
||||
type: string;
|
||||
payload: ChatMessage;
|
||||
}
|
||||
) => {
|
||||
return {
|
||||
...state,
|
||||
messages: [...state.messages, action.payload],
|
||||
};
|
||||
},
|
||||
setIsStreaming: (state, action) => {
|
||||
return {
|
||||
...state,
|
||||
isStreaming: action.payload,
|
||||
};
|
||||
},
|
||||
streamUpdate: (state, action) => {
|
||||
if (!state.isStreaming) {
|
||||
return {
|
||||
...state,
|
||||
messages: [
|
||||
...state.messages,
|
||||
{
|
||||
role: "assistant",
|
||||
content: action.payload,
|
||||
},
|
||||
],
|
||||
isStreaming: true,
|
||||
};
|
||||
} else {
|
||||
let lastMessage = state.messages[state.messages.length - 1];
|
||||
if (lastMessage.role !== "assistant") {
|
||||
return {
|
||||
...state,
|
||||
messages: [
|
||||
...state.messages,
|
||||
{
|
||||
role: "assistant",
|
||||
content: action.payload,
|
||||
},
|
||||
],
|
||||
isStreaming: true,
|
||||
};
|
||||
}
|
||||
return {
|
||||
...state,
|
||||
messages: [
|
||||
...state.messages.slice(0, state.messages.length - 1),
|
||||
{
|
||||
...lastMessage,
|
||||
content: lastMessage.content + action.payload,
|
||||
},
|
||||
],
|
||||
isStreaming: true,
|
||||
};
|
||||
}
|
||||
},
|
||||
closeStream: (state) => {
|
||||
return {
|
||||
...state,
|
||||
isStreaming: false,
|
||||
};
|
||||
},
|
||||
clearChat: (state) => {
|
||||
return {
|
||||
...state,
|
||||
messages: [],
|
||||
isStreaming: false,
|
||||
};
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
export const {
|
||||
addMessage,
|
||||
streamUpdate,
|
||||
closeStream,
|
||||
clearChat,
|
||||
setIsStreaming,
|
||||
} = chatSlice.actions;
|
||||
export default chatSlice.reducer;
|
||||
|
|
@ -1,5 +1,4 @@
|
|||
import { createSlice } from "@reduxjs/toolkit";
|
||||
import { FullState } from "../../schema/FullState";
|
||||
import { ContextItem } from "../../schema/ContextItem";
|
||||
|
||||
const TEST_TIMELINE = [
|
||||
|
|
|
|||
74
gui/src/redux/slices/sessionStateReducer.ts
Normal file
74
gui/src/redux/slices/sessionStateReducer.ts
Normal file
|
|
@ -0,0 +1,74 @@
|
|||
import { createSlice } from "@reduxjs/toolkit";
|
||||
import { SessionState, StepDescription } from "../../schema/SessionState";
|
||||
import { SessionUpdate } from "../../schema/SessionUpdate";
|
||||
import { ContextItem } from "../../schema/ContextItem";
|
||||
|
||||
export interface SessionFullState {
|
||||
history: StepDescription[];
|
||||
context_items: ContextItem[];
|
||||
active: boolean;
|
||||
}
|
||||
|
||||
export const sessionStateSlice = createSlice({
|
||||
name: "sessionState",
|
||||
initialState: {
|
||||
history: [],
|
||||
context_items: [],
|
||||
active: false,
|
||||
},
|
||||
reducers: {
|
||||
processSessionUpdate: (
|
||||
state: SessionFullState,
|
||||
{ payload }: { payload: SessionUpdate }
|
||||
) => {
|
||||
let active = state.active;
|
||||
if (typeof payload.stop === "boolean") {
|
||||
active = !payload.stop;
|
||||
}
|
||||
|
||||
let step: StepDescription | undefined = undefined;
|
||||
|
||||
if (payload.index > state.history.length) {
|
||||
// Partial above to allow here
|
||||
step = {
|
||||
...(payload.update as StepDescription),
|
||||
};
|
||||
} else if (payload.delta === true) {
|
||||
step = {
|
||||
...state.history[payload.index],
|
||||
};
|
||||
if (payload.update.name) {
|
||||
step.name += payload.update.name;
|
||||
}
|
||||
if (payload.update.description) {
|
||||
step.description += payload.update.description;
|
||||
}
|
||||
if (payload.update.observations) {
|
||||
step.observations.push(...payload.update.observations);
|
||||
}
|
||||
if (payload.update.logs) {
|
||||
step.logs.push(...payload.update.logs);
|
||||
}
|
||||
} else if (payload.delta === false) {
|
||||
step = {
|
||||
...state.history[payload.index],
|
||||
...payload.update,
|
||||
};
|
||||
}
|
||||
|
||||
let history = [...state.history];
|
||||
if (step) {
|
||||
history[payload.index] = step;
|
||||
}
|
||||
|
||||
return {
|
||||
...state,
|
||||
history,
|
||||
active,
|
||||
};
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
export const { processSessionUpdate } = sessionStateSlice.actions;
|
||||
export default sessionStateSlice.reducer;
|
||||
|
|
@ -1,11 +1,13 @@
|
|||
import { configureStore } from "@reduxjs/toolkit";
|
||||
import chatReducer from "./slices/chatSlice";
|
||||
import configReducer from "./slices/configSlice";
|
||||
import miscReducer from "./slices/miscSlice";
|
||||
import uiStateReducer from "./slices/uiStateSlice";
|
||||
import { FullState } from "../schema/FullState";
|
||||
import { RangeInFile } from "../schema/RangeInFile";
|
||||
import serverStateReducer from "./slices/serverStateReducer";
|
||||
import { SessionState } from "../schema/SessionState";
|
||||
import sessionStateReducer, {
|
||||
SessionFullState,
|
||||
} from "./slices/sessionStateReducer";
|
||||
|
||||
export interface ChatMessage {
|
||||
role: "system" | "user" | "assistant";
|
||||
|
|
@ -22,10 +24,6 @@ export interface RootStore {
|
|||
vscMediaUrl: string | undefined;
|
||||
dataSwitchOn: boolean | undefined;
|
||||
};
|
||||
chat: {
|
||||
messages: ChatMessage[];
|
||||
isStreaming: boolean;
|
||||
};
|
||||
misc: {
|
||||
highlightedCode: RangeInFile | undefined;
|
||||
takenAction: boolean;
|
||||
|
|
@ -39,16 +37,16 @@ export interface RootStore {
|
|||
dialogMessage: string | JSX.Element;
|
||||
dialogEntryOn: boolean;
|
||||
};
|
||||
serverState: FullState;
|
||||
sessionState: SessionFullState;
|
||||
}
|
||||
|
||||
const store = configureStore({
|
||||
reducer: {
|
||||
chat: chatReducer,
|
||||
config: configReducer,
|
||||
misc: miscReducer,
|
||||
uiState: uiStateReducer,
|
||||
serverState: serverStateReducer,
|
||||
sessionState: sessionStateReducer,
|
||||
},
|
||||
});
|
||||
|
||||
|
|
|
|||
19
gui/src/schema/ContextItemId.d.ts
vendored
Normal file
19
gui/src/schema/ContextItemId.d.ts
vendored
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
/* eslint-disable */
|
||||
/**
|
||||
* This file was automatically generated by json-schema-to-typescript.
|
||||
* DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
|
||||
* and run json-schema-to-typescript to regenerate this file.
|
||||
*/
|
||||
|
||||
export type ContextItemId = ContextItemId1;
|
||||
export type ProviderTitle = string;
|
||||
export type ItemId = string;
|
||||
|
||||
/**
|
||||
* A ContextItemId is a unique identifier for a ContextItem.
|
||||
*/
|
||||
export interface ContextItemId1 {
|
||||
provider_title: ProviderTitle;
|
||||
item_id: ItemId;
|
||||
[k: string]: unknown;
|
||||
}
|
||||
61
gui/src/schema/SessionUpdate.d.ts
vendored
Normal file
61
gui/src/schema/SessionUpdate.d.ts
vendored
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
/* eslint-disable */
|
||||
/**
|
||||
* This file was automatically generated by json-schema-to-typescript.
|
||||
* DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
|
||||
* and run json-schema-to-typescript to regenerate this file.
|
||||
*/
|
||||
|
||||
export type SessionUpdate = SessionUpdate1;
|
||||
export type Index = number;
|
||||
export type Update = SetStep | DeltaStep;
|
||||
export type StepType = string;
|
||||
export type Name = string;
|
||||
export type Description = string;
|
||||
export type Hide = boolean;
|
||||
export type Depth = number;
|
||||
export type Title = string;
|
||||
export type Message = string;
|
||||
export type Observations = Observation[];
|
||||
export type Logs = string[];
|
||||
export type Name1 = string;
|
||||
export type Description1 = string;
|
||||
export type Observations1 = Observation[];
|
||||
export type Logs1 = string[];
|
||||
export type Stop = boolean;
|
||||
|
||||
export interface SessionUpdate1 {
|
||||
index: Index;
|
||||
update: Update;
|
||||
stop?: Stop;
|
||||
[k: string]: unknown;
|
||||
}
|
||||
export interface SetStep {
|
||||
step_type?: StepType;
|
||||
name?: Name;
|
||||
description?: Description;
|
||||
params?: Params;
|
||||
hide?: Hide;
|
||||
depth?: Depth;
|
||||
error?: ContinueError;
|
||||
observations?: Observations;
|
||||
logs?: Logs;
|
||||
[k: string]: unknown;
|
||||
}
|
||||
export interface Params {
|
||||
[k: string]: unknown;
|
||||
}
|
||||
export interface ContinueError {
|
||||
title: Title;
|
||||
message: Message;
|
||||
[k: string]: unknown;
|
||||
}
|
||||
export interface Observation {
|
||||
[k: string]: unknown;
|
||||
}
|
||||
export interface DeltaStep {
|
||||
name?: Name1;
|
||||
description?: Description1;
|
||||
observations?: Observations1;
|
||||
logs?: Logs1;
|
||||
[k: string]: unknown;
|
||||
}
|
||||
25
schema/json/ContextItemId.json
Normal file
25
schema/json/ContextItemId.json
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
{
|
||||
"title": "ContextItemId",
|
||||
"$ref": "#/definitions/continuedev__core__main__ContextItemId",
|
||||
"definitions": {
|
||||
"continuedev__core__main__ContextItemId": {
|
||||
"title": "ContextItemId",
|
||||
"description": "A ContextItemId is a unique identifier for a ContextItem.",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"provider_title": {
|
||||
"title": "Provider Title",
|
||||
"type": "string"
|
||||
},
|
||||
"item_id": {
|
||||
"title": "Item Id",
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"provider_title",
|
||||
"item_id"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
133
schema/json/SessionUpdate.json
Normal file
133
schema/json/SessionUpdate.json
Normal file
|
|
@ -0,0 +1,133 @@
|
|||
{
|
||||
"title": "SessionUpdate",
|
||||
"$ref": "#/definitions/continuedev__core__main__SessionUpdate",
|
||||
"definitions": {
|
||||
"ContinueError": {
|
||||
"title": "ContinueError",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"title": {
|
||||
"title": "Title",
|
||||
"type": "string"
|
||||
},
|
||||
"message": {
|
||||
"title": "Message",
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"title",
|
||||
"message"
|
||||
]
|
||||
},
|
||||
"Observation": {
|
||||
"title": "Observation",
|
||||
"type": "object",
|
||||
"properties": {}
|
||||
},
|
||||
"SetStep": {
|
||||
"title": "SetStep",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"step_type": {
|
||||
"title": "Step Type",
|
||||
"type": "string"
|
||||
},
|
||||
"name": {
|
||||
"title": "Name",
|
||||
"type": "string"
|
||||
},
|
||||
"description": {
|
||||
"title": "Description",
|
||||
"type": "string"
|
||||
},
|
||||
"params": {
|
||||
"title": "Params",
|
||||
"type": "object"
|
||||
},
|
||||
"hide": {
|
||||
"title": "Hide",
|
||||
"type": "boolean"
|
||||
},
|
||||
"depth": {
|
||||
"title": "Depth",
|
||||
"type": "integer"
|
||||
},
|
||||
"error": {
|
||||
"$ref": "#/definitions/ContinueError"
|
||||
},
|
||||
"observations": {
|
||||
"title": "Observations",
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/Observation"
|
||||
}
|
||||
},
|
||||
"logs": {
|
||||
"title": "Logs",
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"DeltaStep": {
|
||||
"title": "DeltaStep",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"name": {
|
||||
"title": "Name",
|
||||
"type": "string"
|
||||
},
|
||||
"description": {
|
||||
"title": "Description",
|
||||
"type": "string"
|
||||
},
|
||||
"observations": {
|
||||
"title": "Observations",
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/Observation"
|
||||
}
|
||||
},
|
||||
"logs": {
|
||||
"title": "Logs",
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"continuedev__core__main__SessionUpdate": {
|
||||
"title": "SessionUpdate",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"index": {
|
||||
"title": "Index",
|
||||
"type": "integer"
|
||||
},
|
||||
"update": {
|
||||
"title": "Update",
|
||||
"anyOf": [
|
||||
{
|
||||
"$ref": "#/definitions/SetStep"
|
||||
},
|
||||
{
|
||||
"$ref": "#/definitions/DeltaStep"
|
||||
}
|
||||
]
|
||||
},
|
||||
"stop": {
|
||||
"title": "Stop",
|
||||
"type": "boolean"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"index",
|
||||
"update"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -131,8 +131,6 @@ UpdateStep = Union[SetStep, DeltaStep]
|
|||
|
||||
|
||||
class StepDescription(BaseModel):
|
||||
# Can this just be a Step? If the step is already included...
|
||||
# Totally! It should be right??
|
||||
step_type: str
|
||||
name: str
|
||||
description: str
|
||||
|
|
|
|||
|
|
@ -3,8 +3,8 @@ import os
|
|||
from pydantic import schema_json_of
|
||||
|
||||
from ..core.config import ContinueConfig
|
||||
from ..core.context import ContextItem
|
||||
from ..core.main import SessionInfo, SessionState
|
||||
from ..core.context import ContextItem, ContextItemId
|
||||
from ..core.main import SessionInfo, SessionState, SessionUpdate
|
||||
from ..core.models import Models
|
||||
from ..libs.llm.base import LLM
|
||||
from .filesystem import FileEdit, RangeInFile
|
||||
|
|
@ -15,9 +15,9 @@ MODELS_TO_GENERATE = (
|
|||
[Position, Range, Traceback, TracebackFrame]
|
||||
+ [RangeInFile, FileEdit]
|
||||
+ [FileEditWithFullContents]
|
||||
+ [SessionInfo, SessionState]
|
||||
+ [SessionInfo, SessionState, SessionUpdate]
|
||||
+ [ContinueConfig]
|
||||
+ [ContextItem]
|
||||
+ [ContextItem, ContextItemId]
|
||||
+ [Models]
|
||||
+ [LLM]
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue