|
|
|
@@ -50,7 +50,7 @@ import {
|
|
|
|
|
parseWorkspace,
|
|
|
|
|
parseWorkspaceActivityResponse,
|
|
|
|
|
} from "./parsers";
|
|
|
|
|
import { machineGitDiffUrl, messageUrl } from "./urls";
|
|
|
|
|
import { machineGitDiffPath, messagePath } from "./urls";
|
|
|
|
|
|
|
|
|
|
const machinePrefix = (machineId = "local") => `api/machines/${encodeURIComponent(machineId)}`;
|
|
|
|
|
|
|
|
|
@@ -64,20 +64,20 @@ function sessionCwd(session: SessionLookup): string | undefined {
|
|
|
|
|
return typeof session === "string" ? undefined : session.cwd;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function sessionBaseUrl(session: SessionLookup, machineId = "local"): string {
|
|
|
|
|
function sessionBasePath(session: SessionLookup, machineId = "local"): string {
|
|
|
|
|
return `${machinePrefix(machineId)}/sessions/${encodeURIComponent(sessionId(session))}`;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function sessionUrl(session: SessionLookup, endpoint: string, machineId = "local"): string {
|
|
|
|
|
return `${sessionBaseUrl(session, machineId)}/${endpoint}`;
|
|
|
|
|
function sessionPath(session: SessionLookup, endpoint: string, machineId = "local"): string {
|
|
|
|
|
return `${sessionBasePath(session, machineId)}/${endpoint}`;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function sessionQueryUrl(session: SessionLookup, endpoint: string, machineId = "local"): string {
|
|
|
|
|
return `${sessionUrl(session, endpoint, machineId)}${sessionQuery(session)}`;
|
|
|
|
|
function sessionQueryPath(session: SessionLookup, endpoint: string, machineId = "local"): string {
|
|
|
|
|
return `${sessionPath(session, endpoint, machineId)}${sessionQuery(session)}`;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function sessionBaseQueryUrl(session: SessionLookup, machineId = "local"): string {
|
|
|
|
|
return `${sessionBaseUrl(session, machineId)}${sessionQuery(session)}`;
|
|
|
|
|
function sessionBaseQueryPath(session: SessionLookup, machineId = "local"): string {
|
|
|
|
|
return `${sessionBasePath(session, machineId)}${sessionQuery(session)}`;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function sessionQuery(session: SessionLookup): string {
|
|
|
|
@@ -100,13 +100,13 @@ function sessionBulkMutationRef(session: SessionLookup): SessionBulkMutationRef
|
|
|
|
|
return cwd === undefined || cwd === "" ? { id } : { id, cwd };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function piWebStatusUrl(machineId: string): string {
|
|
|
|
|
function piWebStatusPath(machineId: string): string {
|
|
|
|
|
return machineId === "local" ? "api/pi-web/status" : `${machinePrefix(machineId)}/pi-web/status`;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const piWebApi = {
|
|
|
|
|
piWebStatus: (machineId = "local") => request(piWebStatusUrl(machineId), parsePiWebStatusResponse),
|
|
|
|
|
checkForUpdates: (machineId = "local") => request(`${piWebStatusUrl(machineId)}?refresh=1`, parsePiWebStatusResponse, { cache: "no-store" }),
|
|
|
|
|
piWebStatus: (machineId = "local") => request(piWebStatusPath(machineId), parsePiWebStatusResponse),
|
|
|
|
|
checkForUpdates: (machineId = "local") => request(`${piWebStatusPath(machineId)}?refresh=1`, parsePiWebStatusResponse, { cache: "no-store" }),
|
|
|
|
|
piWebRuntime: () => request("api/pi-web/runtime", parsePiWebRuntimeResponse),
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
@@ -118,41 +118,41 @@ export const machinesApi = {
|
|
|
|
|
runtime: (machineId: string) => request(`api/machines/${encodeURIComponent(machineId)}/runtime`, parseMachineRuntime),
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
function configUrl(machineId?: string): string {
|
|
|
|
|
function configPath(machineId?: string): string {
|
|
|
|
|
return machineId === undefined ? "api/config" : `${machinePrefix(machineId)}/config`;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function pluginsUrl(machineId?: string): string {
|
|
|
|
|
function pluginsPath(machineId?: string): string {
|
|
|
|
|
return machineId === undefined ? "api/plugins" : `${machinePrefix(machineId)}/plugins`;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const configApi = {
|
|
|
|
|
config: (machineId?: string) => request(configUrl(machineId), parsePiWebConfigResponse),
|
|
|
|
|
saveConfig: (config: PiWebConfigValues, machineId?: string) => request(configUrl(machineId), parsePiWebConfigResponse, { method: "PUT", body: JSON.stringify({ config }) }),
|
|
|
|
|
config: (machineId?: string) => request(configPath(machineId), parsePiWebConfigResponse),
|
|
|
|
|
saveConfig: (config: PiWebConfigValues, machineId?: string) => request(configPath(machineId), parsePiWebConfigResponse, { method: "PUT", body: JSON.stringify({ config }) }),
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const pluginsApi = {
|
|
|
|
|
plugins: (machineId?: string) => request(pluginsUrl(machineId), parsePiWebPluginsResponse),
|
|
|
|
|
plugins: (machineId?: string) => request(pluginsPath(machineId), parsePiWebPluginsResponse),
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
function piPackageUrl(endpoint = "", machineId?: string): string {
|
|
|
|
|
const baseUrl = machineId === undefined ? "api/pi-packages" : `${machinePrefix(machineId)}/pi-packages`;
|
|
|
|
|
return endpoint === "" ? baseUrl : `${baseUrl}/${endpoint}`;
|
|
|
|
|
function piPackagePath(endpoint = "", machineId?: string): string {
|
|
|
|
|
const basePath = machineId === undefined ? "api/pi-packages" : `${machinePrefix(machineId)}/pi-packages`;
|
|
|
|
|
return endpoint === "" ? basePath : `${basePath}/${endpoint}`;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const piPackagesApi = {
|
|
|
|
|
packages: (machineId?: string) => request(piPackageUrl("", machineId), parsePiPackagesResponse),
|
|
|
|
|
packages: (machineId?: string) => request(piPackagePath("", machineId), parsePiPackagesResponse),
|
|
|
|
|
install: (source: string, machineId?: string) => {
|
|
|
|
|
const body: PiPackageInstallRequest = { source };
|
|
|
|
|
return request(piPackageUrl("install", machineId), parsePiPackageMutationResponse, { method: "POST", body: JSON.stringify(body) });
|
|
|
|
|
return request(piPackagePath("install", machineId), parsePiPackageMutationResponse, { method: "POST", body: JSON.stringify(body) });
|
|
|
|
|
},
|
|
|
|
|
remove: (source: string, scope?: PiPackageScope, machineId?: string) => {
|
|
|
|
|
const body: PiPackageRemoveRequest = scope === undefined ? { source } : { source, scope };
|
|
|
|
|
return request(piPackageUrl("remove", machineId), parsePiPackageMutationResponse, { method: "POST", body: JSON.stringify(body) });
|
|
|
|
|
return request(piPackagePath("remove", machineId), parsePiPackageMutationResponse, { method: "POST", body: JSON.stringify(body) });
|
|
|
|
|
},
|
|
|
|
|
update: (source?: string, machineId?: string) => {
|
|
|
|
|
const body: PiPackageUpdateRequest | undefined = source === undefined ? undefined : { source };
|
|
|
|
|
return request(piPackageUrl("update", machineId), parsePiPackageMutationResponse, { method: "POST", ...(body === undefined ? {} : { body: JSON.stringify(body) }) });
|
|
|
|
|
return request(piPackagePath("update", machineId), parsePiPackageMutationResponse, { method: "POST", ...(body === undefined ? {} : { body: JSON.stringify(body) }) });
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
@@ -168,7 +168,7 @@ export const projectsApi = {
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const workspacesApi = {
|
|
|
|
|
workspaces: (projectId: string, machineId = "local") => request(`${machinePrefix(machineId)}/projects/${projectId}/workspaces`, arrayOf(parseWorkspace)),
|
|
|
|
|
workspaces: (projectId: string, machineId = "local") => request(`${machinePrefix(machineId)}/projects/${encodeURIComponent(projectId)}/workspaces`, arrayOf(parseWorkspace)),
|
|
|
|
|
deleteWorkspace: (projectId: string, workspaceId: string, machineId = "local") => request(`${machinePrefix(machineId)}/projects/${encodeURIComponent(projectId)}/workspaces/${encodeURIComponent(workspaceId)}`, parseTerminalCommandRun, { method: "DELETE" }),
|
|
|
|
|
workspaceTree: (projectId: string, workspaceId: string, path = "", machineId = "local") => request(`${machinePrefix(machineId)}/projects/${encodeURIComponent(projectId)}/workspaces/${encodeURIComponent(workspaceId)}/tree?path=${encodeURIComponent(path)}`, parseFileTreeResponse),
|
|
|
|
|
workspaceFile: (projectId: string, workspaceId: string, path: string, machineId = "local") => request(`${machinePrefix(machineId)}/projects/${encodeURIComponent(projectId)}/workspaces/${encodeURIComponent(workspaceId)}/file?path=${encodeURIComponent(path)}`, parseFileContentResponse),
|
|
|
|
@@ -207,28 +207,28 @@ export const sessionsApi = {
|
|
|
|
|
cleanup: (input: SessionCleanupRequest, machineId = "local") => request(`${machinePrefix(machineId)}/sessions/cleanup`, parseSessionCleanupExecuteResponse, { method: "POST", body: JSON.stringify(input) }),
|
|
|
|
|
archiveMany: (sessions: readonly SessionLookup[], machineId = "local") => request(`${machinePrefix(machineId)}/sessions/bulk/archive`, parseSessionBulkArchiveResponse, { method: "POST", body: sessionBulkMutationBody(sessions) }),
|
|
|
|
|
deleteArchivedMany: (sessions: readonly SessionLookup[], machineId = "local") => request(`${machinePrefix(machineId)}/sessions/bulk/delete-archived`, parseSessionBulkDeleteArchivedResponse, { method: "POST", body: sessionBulkMutationBody(sessions) }),
|
|
|
|
|
messages: (session: SessionLookup, options?: { limit?: number; before?: number }, machineId = "local") => request(messageUrl(session, options, machineId), parseMessagePage),
|
|
|
|
|
status: (session: SessionLookup, machineId = "local") => request(sessionQueryUrl(session, "status", machineId), parseSessionStatus),
|
|
|
|
|
models: (session: SessionLookup, machineId = "local") => request(sessionQueryUrl(session, "models", machineId), parseModelSelectionResponse),
|
|
|
|
|
setModel: (session: SessionLookup, provider: string, modelId: string, machineId = "local") => request(sessionUrl(session, "model", machineId), parseSessionStatus, { method: "POST", body: sessionBody(session, { provider, modelId }) }),
|
|
|
|
|
cycleModel: (session: SessionLookup, direction: "forward" | "backward", machineId = "local") => request(sessionUrl(session, "model/cycle", machineId), parseSessionStatus, { method: "POST", body: sessionBody(session, { direction }) }),
|
|
|
|
|
thinkingLevels: (session: SessionLookup, machineId = "local") => request(sessionQueryUrl(session, "thinking-levels", machineId), parseThinkingLevelsResponse),
|
|
|
|
|
setThinkingLevel: (session: SessionLookup, level: string, machineId = "local") => request(sessionUrl(session, "thinking-level", machineId), parseSessionStatus, { method: "POST", body: sessionBody(session, { level }) }),
|
|
|
|
|
cycleThinkingLevel: (session: SessionLookup, machineId = "local") => request(sessionUrl(session, "thinking-level/cycle", machineId), parseSessionStatus, { method: "POST", body: sessionBody(session) }),
|
|
|
|
|
commands: (session: SessionLookup, machineId = "local") => request(sessionQueryUrl(session, "commands", machineId), arrayOf(parseSlashCommand)),
|
|
|
|
|
prompt: (session: SessionLookup, text: string, streamingBehavior?: "steer" | "followUp", machineId = "local", attachments?: PromptAttachment[]) => request(sessionUrl(session, "prompt", machineId), parseAccepted, { method: "POST", body: sessionBody(session, { text, ...(streamingBehavior === undefined ? {} : { streamingBehavior }), ...(attachments !== undefined && attachments.length > 0 ? { attachments } : {}) }) }),
|
|
|
|
|
saveAttachments: (session: SessionLookup, attachments: PromptAttachment[], machineId = "local", folder?: string) => request(sessionUrl(session, "attachments", machineId), parseSavedAttachments, { method: "POST", body: sessionBody(session, { attachments, ...(folder === undefined ? {} : { folder }) }) }),
|
|
|
|
|
shell: (session: SessionLookup, text: string, machineId = "local") => request(sessionUrl(session, "shell", machineId), parseAccepted, { method: "POST", body: sessionBody(session, { text }) }),
|
|
|
|
|
runCommand: (session: SessionLookup, text: string, machineId = "local") => request(sessionUrl(session, "commands/run", machineId), parseCommandResult, { method: "POST", body: sessionBody(session, { text }) }),
|
|
|
|
|
respondToCommand: (session: SessionLookup, requestId: string, value: string, machineId = "local") => request(sessionUrl(session, "commands/respond", machineId), parseCommandResult, { method: "POST", body: sessionBody(session, { requestId, value }) }),
|
|
|
|
|
abort: (session: SessionLookup, machineId = "local") => request(sessionUrl(session, "abort", machineId), parseAborted, { method: "POST", body: sessionBody(session) }),
|
|
|
|
|
stop: (session: SessionLookup, machineId = "local") => request(sessionUrl(session, "stop", machineId), parseStopped, { method: "POST", body: sessionBody(session) }),
|
|
|
|
|
archive: (session: SessionLookup, machineId = "local") => request(sessionUrl(session, "archive", machineId), parseArchived, { method: "POST", body: sessionBody(session) }),
|
|
|
|
|
archiveWithDescendants: (session: SessionLookup, machineId = "local") => request(sessionUrl(session, "archive-tree", machineId), parseArchived, { method: "POST", body: sessionBody(session) }),
|
|
|
|
|
restore: (session: SessionLookup, machineId = "local") => request(sessionUrl(session, "restore", machineId), parseRestored, { method: "POST", body: sessionBody(session) }),
|
|
|
|
|
deleteArchived: (session: SessionLookup, machineId = "local") => request(sessionBaseQueryUrl(session, machineId), parseDeleted, { method: "DELETE" }),
|
|
|
|
|
detachParent: (session: SessionLookup, machineId = "local") => request(sessionUrl(session, "detach-parent", machineId), parseDetached, { method: "POST", body: sessionBody(session) }),
|
|
|
|
|
reloadSession: (session: SessionLookup, machineId = "local") => request(sessionUrl(session, "reload", machineId), parseReloaded, { method: "POST", body: sessionBody(session) }),
|
|
|
|
|
messages: (session: SessionLookup, options?: { limit?: number; before?: number }, machineId = "local") => request(messagePath(session, options, machineId), parseMessagePage),
|
|
|
|
|
status: (session: SessionLookup, machineId = "local") => request(sessionQueryPath(session, "status", machineId), parseSessionStatus),
|
|
|
|
|
models: (session: SessionLookup, machineId = "local") => request(sessionQueryPath(session, "models", machineId), parseModelSelectionResponse),
|
|
|
|
|
setModel: (session: SessionLookup, provider: string, modelId: string, machineId = "local") => request(sessionPath(session, "model", machineId), parseSessionStatus, { method: "POST", body: sessionBody(session, { provider, modelId }) }),
|
|
|
|
|
cycleModel: (session: SessionLookup, direction: "forward" | "backward", machineId = "local") => request(sessionPath(session, "model/cycle", machineId), parseSessionStatus, { method: "POST", body: sessionBody(session, { direction }) }),
|
|
|
|
|
thinkingLevels: (session: SessionLookup, machineId = "local") => request(sessionQueryPath(session, "thinking-levels", machineId), parseThinkingLevelsResponse),
|
|
|
|
|
setThinkingLevel: (session: SessionLookup, level: string, machineId = "local") => request(sessionPath(session, "thinking-level", machineId), parseSessionStatus, { method: "POST", body: sessionBody(session, { level }) }),
|
|
|
|
|
cycleThinkingLevel: (session: SessionLookup, machineId = "local") => request(sessionPath(session, "thinking-level/cycle", machineId), parseSessionStatus, { method: "POST", body: sessionBody(session) }),
|
|
|
|
|
commands: (session: SessionLookup, machineId = "local") => request(sessionQueryPath(session, "commands", machineId), arrayOf(parseSlashCommand)),
|
|
|
|
|
prompt: (session: SessionLookup, text: string, streamingBehavior?: "steer" | "followUp", machineId = "local", attachments?: PromptAttachment[]) => request(sessionPath(session, "prompt", machineId), parseAccepted, { method: "POST", body: sessionBody(session, { text, ...(streamingBehavior === undefined ? {} : { streamingBehavior }), ...(attachments !== undefined && attachments.length > 0 ? { attachments } : {}) }) }),
|
|
|
|
|
saveAttachments: (session: SessionLookup, attachments: PromptAttachment[], machineId = "local", folder?: string) => request(sessionPath(session, "attachments", machineId), parseSavedAttachments, { method: "POST", body: sessionBody(session, { attachments, ...(folder === undefined ? {} : { folder }) }) }),
|
|
|
|
|
shell: (session: SessionLookup, text: string, machineId = "local") => request(sessionPath(session, "shell", machineId), parseAccepted, { method: "POST", body: sessionBody(session, { text }) }),
|
|
|
|
|
runCommand: (session: SessionLookup, text: string, machineId = "local") => request(sessionPath(session, "commands/run", machineId), parseCommandResult, { method: "POST", body: sessionBody(session, { text }) }),
|
|
|
|
|
respondToCommand: (session: SessionLookup, requestId: string, value: string, machineId = "local") => request(sessionPath(session, "commands/respond", machineId), parseCommandResult, { method: "POST", body: sessionBody(session, { requestId, value }) }),
|
|
|
|
|
abort: (session: SessionLookup, machineId = "local") => request(sessionPath(session, "abort", machineId), parseAborted, { method: "POST", body: sessionBody(session) }),
|
|
|
|
|
stop: (session: SessionLookup, machineId = "local") => request(sessionPath(session, "stop", machineId), parseStopped, { method: "POST", body: sessionBody(session) }),
|
|
|
|
|
archive: (session: SessionLookup, machineId = "local") => request(sessionPath(session, "archive", machineId), parseArchived, { method: "POST", body: sessionBody(session) }),
|
|
|
|
|
archiveWithDescendants: (session: SessionLookup, machineId = "local") => request(sessionPath(session, "archive-tree", machineId), parseArchived, { method: "POST", body: sessionBody(session) }),
|
|
|
|
|
restore: (session: SessionLookup, machineId = "local") => request(sessionPath(session, "restore", machineId), parseRestored, { method: "POST", body: sessionBody(session) }),
|
|
|
|
|
deleteArchived: (session: SessionLookup, machineId = "local") => request(sessionBaseQueryPath(session, machineId), parseDeleted, { method: "DELETE" }),
|
|
|
|
|
detachParent: (session: SessionLookup, machineId = "local") => request(sessionPath(session, "detach-parent", machineId), parseDetached, { method: "POST", body: sessionBody(session) }),
|
|
|
|
|
reloadSession: (session: SessionLookup, machineId = "local") => request(sessionPath(session, "reload", machineId), parseReloaded, { method: "POST", body: sessionBody(session) }),
|
|
|
|
|
authProviders: (options?: { mode?: "login" | "logout"; authType?: "oauth" | "api_key"; machineId?: string }) => {
|
|
|
|
|
const params = new URLSearchParams();
|
|
|
|
|
if (options?.mode !== undefined) params.set("mode", options.mode);
|
|
|
|
@@ -314,7 +314,7 @@ export const filesApi = {
|
|
|
|
|
|
|
|
|
|
export const gitApi = {
|
|
|
|
|
gitStatus: (projectId: string, workspaceId: string, machineId = "local") => request(`${machinePrefix(machineId)}/projects/${encodeURIComponent(projectId)}/workspaces/${encodeURIComponent(workspaceId)}/git/status`, parseGitStatusResponse),
|
|
|
|
|
gitDiff: (projectId: string, workspaceId: string, options?: { path?: string; staged?: boolean }, machineId = "local") => request(machineGitDiffUrl(machineId, projectId, workspaceId, options), parseGitDiffResponse),
|
|
|
|
|
gitDiff: (projectId: string, workspaceId: string, options?: { path?: string; staged?: boolean }, machineId = "local") => request(machineGitDiffPath(machineId, projectId, workspaceId, options), parseGitDiffResponse),
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const api = {
|
|
|
|
|