feat: add scoped history and artifacts
This commit is contained in:
@@ -181,8 +181,8 @@ const toLegacyMessages = (messages: UIMessage[]) =>
|
||||
];
|
||||
});
|
||||
|
||||
const createFallbackUserUiMessage = (content: string): UIMessage => ({
|
||||
id: `user-${Date.now().toString(36)}`,
|
||||
const createFallbackUserUiMessage = (content: string, id?: string): UIMessage => ({
|
||||
id: id ?? `user-${randomUUID()}`,
|
||||
role: "user",
|
||||
parts: [{ type: "text", text: content }],
|
||||
});
|
||||
@@ -326,6 +326,9 @@ export const registerChatStreamRoute = (
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (input.tjwater.topic_id && !await sessionMetadataStore.topics.get(authContext, input.tjwater.topic_id)) {
|
||||
res.status(404).json({ message: "主题不存在" }); return;
|
||||
}
|
||||
const requestedSessionId = resolveRequestedStreamSessionId({
|
||||
sessionId: parsed.data.session_id,
|
||||
promptText,
|
||||
@@ -403,6 +406,7 @@ export const registerChatStreamRoute = (
|
||||
projectId,
|
||||
projectKey,
|
||||
sessionId: binding.sessionId,
|
||||
topicId: existingSessionRecord?.topicId ?? input.tjwater.topic_id,
|
||||
userId,
|
||||
});
|
||||
const activeSessionRecord = await sessionMetadataStore.touch(ensuredSessionRecord);
|
||||
@@ -454,6 +458,10 @@ export const registerChatStreamRoute = (
|
||||
toSessionUiStateContext(activeSessionRecord),
|
||||
);
|
||||
const persistedUiMessages = toUiMessages(initialSessionState?.messages);
|
||||
if (input.tjwater.client_message_id && persistedUiMessages.some((message) => message.id === input.tjwater.client_message_id)) {
|
||||
res.status(409).json({ message: "client_message_id already exists in this conversation" });
|
||||
return;
|
||||
}
|
||||
let executionPlanHistory = initialSessionState?.executionPlans ?? readExecutionPlans(initialSessionState?.messages ?? []);
|
||||
const visiblePersistedMessages = sessionPurpose === "task_collaboration"
|
||||
? toCollaborationMessages(persistedUiMessages)
|
||||
@@ -466,7 +474,7 @@ export const registerChatStreamRoute = (
|
||||
? visibleRequestMessages
|
||||
: [
|
||||
...visiblePersistedMessages,
|
||||
createFallbackUserUiMessage(promptText),
|
||||
createFallbackUserUiMessage(promptText, input.tjwater.client_message_id),
|
||||
];
|
||||
let latestUiMessages = requestMessages;
|
||||
const baseMessages = toLegacyMessages(requestMessages);
|
||||
|
||||
Reference in New Issue
Block a user