Thomas G. Lopes
commited on
Commit
·
6961b4c
1
Parent(s):
e48f39f
reset conversations in default project when saving
Browse files- src/lib/stores/session.ts +4 -41
src/lib/stores/session.ts
CHANGED
@@ -110,39 +110,15 @@ function createSessionStore() {
|
|
110 |
|
111 |
// Override update method to sync with localStorage and URL params
|
112 |
const update: typeof store.update = cb => {
|
113 |
-
// const prevQuery = window.location.search;
|
114 |
-
// const query = new URLSearchParams(window.location.search);
|
115 |
-
// query.delete("modelId");
|
116 |
-
// query.delete("provider");
|
117 |
-
|
118 |
store.update($s => {
|
119 |
const s = cb($s);
|
120 |
|
121 |
-
// Save to localStorage
|
122 |
try {
|
123 |
localStorage.setItem(LOCAL_STORAGE_KEY, JSON.stringify(s));
|
124 |
} catch (e) {
|
125 |
console.error("Failed to save session to localStorage:", e);
|
126 |
}
|
127 |
|
128 |
-
// Update URL query parameters
|
129 |
-
// const modelIds = s.conversations.map(c => c.model.id);
|
130 |
-
// modelIds.forEach(m => query.append("modelId", m));
|
131 |
-
//
|
132 |
-
// const providers = s.conversations.map(c => c.provider ?? "hf-inference");
|
133 |
-
// providers.forEach(p => query.append("provider", p));
|
134 |
-
|
135 |
-
// const newQuery = query.toString();
|
136 |
-
// if (newQuery !== prevQuery.slice(1)) {
|
137 |
-
// window.parent.postMessage(
|
138 |
-
// {
|
139 |
-
// queryString: query.toString(),
|
140 |
-
// },
|
141 |
-
// "https://huggingface.co"
|
142 |
-
// );
|
143 |
-
// goto(`?${query}`, { replaceState: true });
|
144 |
-
// }
|
145 |
-
|
146 |
return s;
|
147 |
});
|
148 |
};
|
@@ -156,22 +132,6 @@ function createSessionStore() {
|
|
156 |
localStorage.removeItem(LOCAL_STORAGE_KEY);
|
157 |
}
|
158 |
|
159 |
-
/**
|
160 |
-
* @deprecated - Use `saveProject` instead
|
161 |
-
*/
|
162 |
-
function addProject(name: string) {
|
163 |
-
const { defaultConversation } = getDefaults();
|
164 |
-
update(s => {
|
165 |
-
const project: Project = {
|
166 |
-
name,
|
167 |
-
id: crypto.randomUUID(),
|
168 |
-
conversations: [defaultConversation],
|
169 |
-
};
|
170 |
-
|
171 |
-
return { ...s, projects: [...s.projects, project], activeProjectId: project.id };
|
172 |
-
});
|
173 |
-
}
|
174 |
-
|
175 |
/**
|
176 |
* Saves a new project with the data inside the default project
|
177 |
*/
|
@@ -179,12 +139,15 @@ function createSessionStore() {
|
|
179 |
update(s => {
|
180 |
const defaultProject = s.projects.find(p => p.id === "default");
|
181 |
if (!defaultProject) return s;
|
|
|
182 |
const project: Project = {
|
183 |
...defaultProject,
|
184 |
name,
|
185 |
id: crypto.randomUUID(),
|
186 |
};
|
187 |
|
|
|
|
|
188 |
return { ...s, projects: [...s.projects, project], activeProjectId: project.id };
|
189 |
});
|
190 |
}
|
@@ -215,7 +178,7 @@ function createSessionStore() {
|
|
215 |
});
|
216 |
}
|
217 |
|
218 |
-
return { ...store, set, update, clearSavedSession,
|
219 |
}
|
220 |
|
221 |
export const session = createSessionStore();
|
|
|
110 |
|
111 |
// Override update method to sync with localStorage and URL params
|
112 |
const update: typeof store.update = cb => {
|
|
|
|
|
|
|
|
|
|
|
113 |
store.update($s => {
|
114 |
const s = cb($s);
|
115 |
|
|
|
116 |
try {
|
117 |
localStorage.setItem(LOCAL_STORAGE_KEY, JSON.stringify(s));
|
118 |
} catch (e) {
|
119 |
console.error("Failed to save session to localStorage:", e);
|
120 |
}
|
121 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
122 |
return s;
|
123 |
});
|
124 |
};
|
|
|
132 |
localStorage.removeItem(LOCAL_STORAGE_KEY);
|
133 |
}
|
134 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
135 |
/**
|
136 |
* Saves a new project with the data inside the default project
|
137 |
*/
|
|
|
139 |
update(s => {
|
140 |
const defaultProject = s.projects.find(p => p.id === "default");
|
141 |
if (!defaultProject) return s;
|
142 |
+
|
143 |
const project: Project = {
|
144 |
...defaultProject,
|
145 |
name,
|
146 |
id: crypto.randomUUID(),
|
147 |
};
|
148 |
|
149 |
+
defaultProject.conversations = [getDefaults().defaultConversation];
|
150 |
+
|
151 |
return { ...s, projects: [...s.projects, project], activeProjectId: project.id };
|
152 |
});
|
153 |
}
|
|
|
178 |
});
|
179 |
}
|
180 |
|
181 |
+
return { ...store, set, update, clearSavedSession, deleteProject, saveProject, updateProject };
|
182 |
}
|
183 |
|
184 |
export const session = createSessionStore();
|