Skip to content

Commit

Permalink
thunk to composition
Browse files Browse the repository at this point in the history
  • Loading branch information
toyamarinyon committed Oct 25, 2024
1 parent 14d51ae commit 01290fa
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import type { GiselleNode } from "../giselle-node/types";
import type { ThunkAction } from "../graph/context";
import type { CompositeAction } from "../graph/context";
import { playgroundModes } from "../graph/types";
import { updateMode } from "../graph/v2/mode";
import { setFlow } from "./action";
import { runAction } from "./server-action";
import { flowStatuses } from "./types";
import { createFlowActionId, createFlowId, resolveActionLayers } from "./utils";

export function runFlow(finalNode: GiselleNode): ThunkAction {
export function runFlow(finalNode: GiselleNode): CompositeAction {
return async (dispatch, getState) => {
const state = getState();
dispatch(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {
updateNodeProperty,
updateNodesUI,
} from "../../../graph/actions";
import { type ThunkAction, useGraph } from "../../../graph/context";
import { type CompositeAction, useGraph } from "../../../graph/context";
import type {
TextContent,
TextContentReference,
Expand All @@ -44,7 +44,7 @@ import { Block } from "./block";
function setTextToPropertyAndOutput(
nodeId: GiselleNodeId,
text: string,
): ThunkAction {
): CompositeAction {
return (dispatch) => {
dispatch(
updateNodeProperty({
Expand Down
14 changes: 7 additions & 7 deletions app/(playground)/p/[agentId]/beta-proto/graph/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ import {
webSearchItemStatus,
webSearchStatus,
} from "../web-search/types";
import type { ThunkAction } from "./context";
import type { CompositeAction } from "./context";
import {
generateArtifactStream,
parseFile,
Expand Down Expand Up @@ -171,7 +171,7 @@ type AddNodesAndConnectArgs = {
};
export const addNodesAndConnect = (
args: AddNodesAndConnectArgs,
): ThunkAction => {
): CompositeAction => {
return (dispatch, getState) => {
const state = getState();
const hasFinalNode = state.graph.nodes.some((node) => node.isFinal);
Expand Down Expand Up @@ -268,7 +268,7 @@ export const selectNodeAndSetPanelTab = (args: {
id: GiselleNodeId;
panelTab: PanelTab;
};
}): ThunkAction => {
}): CompositeAction => {
return (dispatch) => {
dispatch(
selectNode({
Expand Down Expand Up @@ -469,7 +469,7 @@ export const removeArtifact = (
};

export const generateText =
(args: GenerateTextArgs): ThunkAction =>
(args: GenerateTextArgs): CompositeAction =>
async (dispatch, getState) => {
dispatch(
setNodeOutput({
Expand Down Expand Up @@ -815,7 +815,7 @@ type AddSourceToPromptNodeArgs = {
};
export function addSourceToPromptNode(
args: AddSourceToPromptNodeArgs,
): ThunkAction {
): CompositeAction {
return async (dispatch, getState) => {
const state = getState();
const targetPromptNode = state.graph.nodes.find(
Expand Down Expand Up @@ -1053,7 +1053,7 @@ type RemoveSourceFromPromptNodeArgs = {
};
export function removeSourceFromPromptNode(
args: RemoveSourceFromPromptNodeArgs,
): ThunkAction {
): CompositeAction {
return (dispatch, getState) => {
const state = getState();
const targetNode = state.graph.nodes.find(
Expand Down Expand Up @@ -1233,7 +1233,7 @@ export function removeNode(args: RemoveNodeArgs): RemoveNodeAction {
};
}

export function removeSelectedNodesOrFeedback(): ThunkAction {
export function removeSelectedNodesOrFeedback(): CompositeAction {
return (dispatch, getState) => {
const state = getState();
const selectedNodes = state.graph.nodes.filter((node) => node.ui.selected);
Expand Down
4 changes: 2 additions & 2 deletions app/(playground)/p/[agentId]/beta-proto/graph/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import { createContext, useContext } from "react";
import type { GraphAction } from "./actions";
import type { GraphState } from "./types";

export type ThunkAction = (
export type CompositeAction = (
dispatch: EnhancedDispatch,
getState: () => GraphState,
) => void | Promise<void>;
export type EnhancedDispatch = (action: GraphAction | ThunkAction) => void;
export type EnhancedDispatch = (action: GraphAction | CompositeAction) => void;
export type GraphContext = {
state: GraphState;
dispatch: EnhancedDispatch;
Expand Down

0 comments on commit 01290fa

Please sign in to comment.