File size: 2,921 Bytes
63bcd5a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4552666
 
 
63bcd5a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4552666
 
 
63bcd5a
 
 
 
 
 
 
 
 
 
 
 
4552666
 
 
63bcd5a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4552666
 
 
63bcd5a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4552666
 
 
63bcd5a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4552666
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
from typing import Dict, Any, List

def normalize(text: str) -> str:
    return str(text).strip().lower()

def merge_lists(old: List[str], new: List[str]) -> List[str]:

    seen = set()

    result = []

    for item in (old or []) + (new or []):

        if not item:
            continue

        key = normalize(item)

        if key not in seen:

            seen.add(key)

            result.append(str(item).strip())

    return result

def update_state(
    state: Dict[str, Any],
    new_data: Dict[str, Any],
    mode: str = "merge"
) -> Dict[str, Any]:

    for key, value in new_data.items():

        if key in ["user_input", "intent"]:
            continue

        if value is None or value == "":
            continue

        
        
        
        if key in [
            "ideas",
            "project_title",
            "description",
            "abstract",
            "category",
            "problem_statement",
            "proposed_solution",
            "methodology",
            "ai_summary"
        ]:

            state[key] = value
            continue

        
        
        
        if key == "features":

            if mode == "replace":
                state[key] = value
            else:
                state[key] = merge_lists(
                    state.get(key, []),
                    value
                )

            continue

        
        
        
        if isinstance(value, list):

            if mode == "replace":

                state[key] = value

            else:

                state[key] = merge_lists(
                    state.get(key, []),
                    value
                )

            continue

        
        
        
        if isinstance(value, str):

            clean_val = value.strip()

            old_val = str(
                state.get(key, "")
            ).strip()

            if (
                mode == "replace"
                or clean_val not in old_val
            ):
                state[key] = (
                    f"{old_val}\n{clean_val}"
                ).strip()

            continue

        
        
        
        state[key] = value

    return state

def reset_for_new_idea(
    state: Dict[str, Any]
) -> Dict[str, Any]:

    return {

        "domain": state.get("domain"),

        "ideas": [],

        "project_title": "",

        "features": [],

        "description": "",

        "abstract": "",

        "technologies": [],

        "keywords": [],

        "category": "",

        "problem_statement": "",

        "proposed_solution": "",

        "objectives": [],

        "future_work": [],

        "methodology": "",

        "ai_summary": "",

        "originality_score": None,

        "context_strength": None
    }

def reset_features_only(
    state: Dict[str, Any]
) -> Dict[str, Any]:

    state["features"] = []

    state["description"] = ""

    return state