feat: add timestamp and forking
This commit is contained in:
@@ -198,11 +198,43 @@ export const useAgents = async () => {
|
||||
});
|
||||
}
|
||||
|
||||
const forkTopic = async (topicId: string, messageId: string): Promise<string | null> => {
|
||||
try {
|
||||
const result = await $fetch<{ ok: boolean; topicId: string; name: string }>(`/api/topic/${topicId}/fork`, {
|
||||
method: 'POST',
|
||||
body: { messageId },
|
||||
});
|
||||
|
||||
if (result.ok) {
|
||||
const agent = agents.value.find(a => a.topics.some(t => t.id === topicId));
|
||||
if (agent) {
|
||||
const newTopic: Topic = {
|
||||
id: result.topicId,
|
||||
name: result.name,
|
||||
agentId: agent.id,
|
||||
userId: agent.userId,
|
||||
renaming: false,
|
||||
createdAt: new Date(),
|
||||
};
|
||||
agents.value = agents.value.map(a =>
|
||||
a.id === agent.id ? { ...a, topics: [newTopic, ...a.topics] } as AgentWithTopics : a
|
||||
);
|
||||
}
|
||||
return result.topicId;
|
||||
}
|
||||
return null;
|
||||
} catch (error) {
|
||||
console.error('Failed to fork topic:', error);
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
return {
|
||||
agents,
|
||||
refresh,
|
||||
createAgent,
|
||||
createTopic,
|
||||
forkTopic,
|
||||
getAgent,
|
||||
patchAgentLocally,
|
||||
patchTopicLocally,
|
||||
|
||||
Reference in New Issue
Block a user