Use real IDE authoring session
CI / python (push) Has been cancelled
CI / rust (push) Has been cancelled

This commit is contained in:
2026-05-16 20:14:38 +03:00
parent 5b26c67947
commit 3b37a217a8
2 changed files with 67 additions and 23 deletions
+47 -4
View File
@@ -389,6 +389,7 @@ export type AuthoringSemanticDiffPreviewRequest = {
source_path?: string | null;
task_id?: string | null;
session_id?: string | null;
user_id?: string | null;
};
export type AuthoringSemanticDiffPreview = {
@@ -581,6 +582,12 @@ export type AuthoringChangeSummary = {
production_applied: boolean;
};
export type AuthoringSessionContext = {
user_id: string;
task_id: string;
session_id: string;
};
export function resolveApiUrl(hostHeader?: string | null) {
const configuredUrl = process.env.SFERA_API_URL ?? process.env.NEXT_PUBLIC_SFERA_API_URL;
if (configuredUrl) {
@@ -686,6 +693,39 @@ async function postOptionalJson<T>(apiUrl: string, path: string, body: unknown,
}
}
function ideAuthoringSessionContext(projectId: string): AuthoringSessionContext {
const safeProjectId = projectId.replace(/[^A-Za-z0-9_.-]/g, "-");
return {
user_id: "ide.developer",
task_id: `task.ide.${safeProjectId}`,
session_id: `session.ide.${safeProjectId}`
};
}
export async function ensureAuthoringSession(projectId: string, apiUrl = resolveApiUrl()): Promise<AuthoringSessionContext> {
const context = ideAuthoringSessionContext(projectId);
await postJson(apiUrl, "/collaboration/users", {
user_id: context.user_id,
display_name: "SFERA IDE"
});
await postJson(apiUrl, `/security/users/${encodeURIComponent(context.user_id)}/roles/developer`, {});
await postJson(apiUrl, "/collaboration/tasks", {
task_id: context.task_id,
project_id: projectId,
title: "SFERA IDE authoring",
status: "IN_PROGRESS",
assignee_user_id: context.user_id
});
await postJson(apiUrl, "/collaboration/sessions", {
session: {
session_id: context.session_id,
task_id: context.task_id,
user_id: context.user_id
}
});
return context;
}
export async function getDashboardData(apiUrl = resolveApiUrl()) {
const [health, summary, snapshots, neo4j, aiUsage, aiPolicy] = await Promise.all([
getJson<Health>(apiUrl, "/health"),
@@ -874,6 +914,9 @@ export async function getProjectWorkspaceData(projectId: string, apiUrl = resolv
: "";
const editorSelectedObject = selectedObjectName ?? snapshotModule?.qualified_name ?? null;
const editorSelectedRoutine = selectedModuleRoutine ?? selectedRoutineName ?? null;
const authoringSession = selectedObjectName && authoringSourceText
? await ensureAuthoringSession(projectId, apiUrl).catch(() => null)
: null;
const authoringPreview = needsObjectPanels && selectedObjectName && authoringSourceText
? await postOptionalJson<AuthoringCompletionPreview | null>(
apiUrl,
@@ -883,8 +926,7 @@ export async function getProjectWorkspaceData(projectId: string, apiUrl = resolv
routine_name: selectedModuleRoutine,
source_path: selectedObjectModule?.source_path ?? null,
source_text: authoringSourceText,
task_id: "task.preview",
session_id: "session.preview"
user_id: authoringSession?.user_id ?? null
},
null
)
@@ -900,8 +942,9 @@ export async function getProjectWorkspaceData(projectId: string, apiUrl = resolv
original_text: authoringSourceText,
proposed_text: authoringProposedText,
source_path: selectedObjectModule?.source_path ?? null,
task_id: "task.preview",
session_id: "session.preview"
task_id: authoringSession?.task_id ?? null,
session_id: authoringSession?.session_id ?? null,
user_id: authoringSession?.user_id ?? null
},
null
)