Files
model-platform/frontend/app/services/api/boundApi.ts
T

353 lines
10 KiB
TypeScript

import type {
CursorListParams,
CursorPage,
Employee,
} from "./_shared";
import type {
listScripts,
countScripts,
createScript,
uploadScript,
setScriptLock,
updateScript,
deleteScript,
getLatestScriptVersion,
publishScriptVersion,
ScriptItem,
Visibility,
LatestVersion,
StableVersion,
} from "./scripts";
import type {
listResources,
deleteResource,
fetchResourceContentFile,
fetchResourcePreview,
createResourceUpload,
uploadResourceBytes,
bindResourceUpload,
listWorkspaceDirectories,
createWorkspaceDirectory,
deleteWorkspaceDirectory,
ResourceItem,
ResourcePreviewPayload,
WorkspaceDirectory,
} from "./resources";
import type {
acquireFileLock,
heartbeatFileLock,
releaseFileLock,
releaseFileLockOnUnload,
createJupyterAccessTicket,
ActiveEditSession,
FileLockSession,
JupyterAccessTicket,
} from "./fileLocks";
import type {
listSchedules,
getSchedule,
createSchedule,
updateSchedule,
deleteSchedule,
listScheduleArtifacts,
hideScheduleArtifact,
Schedule,
ScheduleArtifact,
CronPreview,
ScheduleRunDetail,
ScheduleRunSummary,
ScheduleNodeRunArtifacts,
} from "./schedules";
import type {
createScheduleNode,
updateScheduleNode,
deleteScheduleNode,
createScheduleEdge,
deleteScheduleEdge,
validateSchedule,
previewCron,
runScheduleNow,
listScheduleRuns,
getScheduleRun,
getScheduleNodeRunArtifacts,
DagValidation,
} from "./scheduleGraph";
import type {
listPlatformEmployees,
createPlatformEmployee,
updatePlatformEmployee,
deletePlatformEmployee,
} from "./platformEmployees";
import type {
listPlatformRoles,
getPlatformRole,
listPlatformPermissions,
createPlatformRole,
updatePlatformRole,
deletePlatformRole,
updatePlatformRolePermissions,
Role,
PlatformPermission,
RoleCreatePayload,
RoleUpdatePayload,
} from "./platformRoles";
import type {
listEmployees,
createEmployee,
updateEmployee,
deleteEmployee,
} from "./employees";
import type {
listWorkspaces,
createWorkspace,
updateWorkspace,
deleteWorkspace,
Workspace,
WorkspaceCreatePayload,
WorkspaceUpdatePayload,
} from "./workspaces";
import type {
listWorkspaceMembers,
addWorkspaceMember,
updateWorkspaceMember,
deleteWorkspaceMember,
WorkspaceMember,
WorkspaceMemberAddPayload,
WorkspaceMemberUpdatePayload,
} from "./workspaceMembers";
// Workspace-bound API surface.
//
// `useApi()` in ~/context/AuthContext returns an object where every
// function has had its first `workspaceId` argument pre-filled. The
// type below lets consumers import the bound type without depending
// on the raw functions. Keep this last in the file so the type
// references all the exports above.
// ----------------------------------------------------------------------------
export type WorkspaceBoundApi = {
listScripts: (
parentPath?: Parameters<typeof listScripts>[1],
ownerUserId?: Parameters<typeof listScripts>[2],
) => Promise<ScriptItem[]>;
countScripts: () => Promise<number>;
listResources: (
parentPath?: Parameters<typeof listResources>[1],
opts?: Parameters<typeof listResources>[2],
) => Promise<ResourceItem[]>;
createScript: (
input: Parameters<typeof createScript>[1],
) => Promise<ScriptItem>;
uploadScript: (
file: File,
parentPath?: string,
visibility?: Visibility,
) => Promise<ScriptItem>;
createResourceUpload: (
body: Parameters<typeof createResourceUpload>[1],
) => Promise<{ upload_id: string; upload_path: string }>;
uploadResourceBytes: (
uploadId: string,
fileBytes: ArrayBuffer | Blob,
contentType: string,
) => Promise<{ storage_object_id: string }>;
bindResourceUpload: (
uploadId: string,
body: Parameters<typeof bindResourceUpload>[2],
) => Promise<ResourceItem>;
deleteResource: (
resourceId: string,
) => Promise<{ resource_id: string; status: string }>;
fetchResourceContentFile: (
resourceId: string,
fileName: string,
signal?: AbortSignal,
) => Promise<File>;
fetchResourcePreview: (
resourceId: string,
input?: { limit?: number },
signal?: AbortSignal,
) => Promise<ResourcePreviewPayload>;
updateScript: (
scriptId: string,
input: Parameters<typeof updateScript>[2],
) => Promise<ScriptItem>;
deleteScript: (
scriptId: string,
) => Promise<{ script_id: string; status: string; versions_preserved: boolean }>;
setScriptLock: (
scriptId: string,
isLocked: boolean,
) => Promise<ScriptItem>;
listWorkspaceDirectories: (
parentPath?: Parameters<typeof listWorkspaceDirectories>[1],
ownerUserId?: Parameters<typeof listWorkspaceDirectories>[2],
) => Promise<WorkspaceDirectory[]>;
createWorkspaceDirectory: (
directoryName: string,
parentPath?: string,
) => Promise<WorkspaceDirectory>;
deleteWorkspaceDirectory: (
path: string,
) => Promise<{
path: string;
status: string;
deleted_scripts: number;
versions_preserved: boolean;
}>;
acquireFileLock: (
script: ScriptItem,
) => Promise<ActiveEditSession>;
heartbeatFileLock: (
session: ActiveEditSession,
) => Promise<FileLockSession>;
releaseFileLock: (
session: ActiveEditSession,
) => Promise<FileLockSession>;
releaseFileLockOnUnload: (session: ActiveEditSession) => void;
createJupyterAccessTicket: (
session: ActiveEditSession,
) => Promise<JupyterAccessTicket>;
getLatestScriptVersion: (scriptId: string) => Promise<LatestVersion | null>;
publishScriptVersion: (
input: Parameters<typeof publishScriptVersion>[1],
) => Promise<StableVersion>;
listSchedules: () => Promise<Schedule[]>;
getSchedule: (scheduleId: string) => Promise<Schedule>;
createSchedule: (
input: Parameters<typeof createSchedule>[1],
) => Promise<Schedule>;
updateSchedule: (
scheduleId: string,
input: Parameters<typeof updateSchedule>[2],
) => Promise<Schedule>;
deleteSchedule: (
scheduleId: string,
workflowVersion: number,
) => Promise<{ schedule_id: string; deleted: boolean; workflow_version: number }>;
listScheduleArtifacts: () => Promise<ScheduleArtifact[]>;
hideScheduleArtifact: (
versionsId: string,
) => Promise<{
versions_id: string;
deleted: boolean;
artifact_preserved: boolean;
}>;
listEmployees: () => Promise<Employee[]>;
listPlatformEmployees: (
input?: CursorListParams,
) => Promise<CursorPage<Employee>>;
createEmployee: (
input: Parameters<typeof createEmployee>[1],
) => Promise<Employee>;
createPlatformEmployee: (
input: {
username: string;
display_name: string;
email?: string | undefined;
password: string;
role_code?: "admin" | "developer";
},
) => Promise<Employee>;
updateEmployee: (
userId: string,
input: Parameters<typeof updateEmployee>[2],
) => Promise<Employee>;
updatePlatformEmployee: (
userId: string,
input: {
display_name?: string;
email?: string | null;
role_code?: "admin" | "developer";
status?: "active" | "disabled" | "locked";
},
) => Promise<Employee>;
deleteEmployee: (
userId: string,
) => Promise<{ user_id: string; deleted: boolean }>;
deletePlatformEmployee: (
userId: string,
) => Promise<{ user_id: string; deleted: boolean }>;
resetPlatformEmployeePassword: (
userId: string,
newPassword: string,
) => Promise<{ user_id: string; password_reset: boolean }>;
listPlatformRoles: () => Promise<Role[]>;
getPlatformRole: (roleCode: string) => Promise<Role>;
listPlatformPermissions: () => Promise<PlatformPermission[]>;
createPlatformRole: (input: RoleCreatePayload) => Promise<Role>;
updatePlatformRole: (
roleCode: string,
input: RoleUpdatePayload,
) => Promise<Role>;
deletePlatformRole: (
roleCode: string,
) => Promise<{ role_code: string; deleted: boolean }>;
updatePlatformRolePermissions: (
roleCode: string,
permissionCodes: string[],
) => Promise<Role>;
createScheduleNode: (
scheduleId: string,
input: Parameters<typeof createScheduleNode>[2],
) => Promise<Schedule>;
updateScheduleNode: (
scheduleId: string,
nodeId: string,
input: Parameters<typeof updateScheduleNode>[3],
) => Promise<Schedule>;
deleteScheduleNode: (
scheduleId: string,
nodeId: string,
workflowVersion: number,
options?: { delete_execution_history?: boolean },
) => Promise<Schedule>;
createScheduleEdge: (
scheduleId: string,
input: Parameters<typeof createScheduleEdge>[2],
) => Promise<Schedule>;
deleteScheduleEdge: (
scheduleId: string,
edgeId: string,
workflowVersion: number,
) => Promise<Schedule>;
validateSchedule: (
scheduleId: string,
) => Promise<DagValidation & { schedule_id: string; workflow_version: number }>;
previewCron: (
input: Parameters<typeof previewCron>[1],
) => Promise<CronPreview>;
runScheduleNow: (scheduleId: string) => Promise<ScheduleRunDetail>;
listScheduleRuns: (
input?: Parameters<typeof listScheduleRuns>[1],
) => Promise<ScheduleRunSummary[]>;
getScheduleRun: (runId: string) => Promise<ScheduleRunDetail>;
getScheduleNodeRunArtifacts: (
runId: string,
nodeRunId: string,
) => Promise<ScheduleNodeRunArtifacts>;
// Workspace (Project) Management - 系统管理接口
listWorkspaces: (
input?: CursorListParams,
) => Promise<CursorPage<Workspace>>;
createWorkspace: (input: WorkspaceCreatePayload) => Promise<Workspace>;
updateWorkspace: (
workspaceId: string,
input: WorkspaceUpdatePayload,
) => Promise<Workspace>;
deleteWorkspace: (workspaceId: string) => Promise<{ workspace_id: string; deleted: boolean }>;
listWorkspaceMembers: (workspaceId: string) => Promise<WorkspaceMember[]>;
addWorkspaceMember: (
workspaceId: string,
input: WorkspaceMemberAddPayload,
) => Promise<WorkspaceMember>;
updateWorkspaceMember: (
workspaceId: string,
userId: string,
input: WorkspaceMemberUpdatePayload,
) => Promise<WorkspaceMember>;
deleteWorkspaceMember: (
workspaceId: string,
userId: string,
) => Promise<{ user_id: string; deleted: boolean }>;
};