feat(ui): reconcile backup UI changes with current routing and interaction features
This commit is contained in:
@@ -8,7 +8,8 @@ import type {
|
||||
Approval,
|
||||
AgentConfigRevision,
|
||||
} from "@paperclip/shared";
|
||||
import { api } from "./client";
|
||||
import { isUuidLike, normalizeAgentUrlKey } from "@paperclip/shared";
|
||||
import { ApiError, api } from "./client";
|
||||
|
||||
export interface AgentKey {
|
||||
id: string;
|
||||
@@ -44,37 +45,78 @@ export interface AgentHireResponse {
|
||||
approval: Approval | null;
|
||||
}
|
||||
|
||||
function withCompanyScope(path: string, companyId?: string) {
|
||||
if (!companyId) return path;
|
||||
const separator = path.includes("?") ? "&" : "?";
|
||||
return `${path}${separator}companyId=${encodeURIComponent(companyId)}`;
|
||||
}
|
||||
|
||||
function agentPath(id: string, companyId?: string, suffix = "") {
|
||||
return withCompanyScope(`/agents/${encodeURIComponent(id)}${suffix}`, companyId);
|
||||
}
|
||||
|
||||
export const agentsApi = {
|
||||
list: (companyId: string) => api.get<Agent[]>(`/companies/${companyId}/agents`),
|
||||
org: (companyId: string) => api.get<OrgNode[]>(`/companies/${companyId}/org`),
|
||||
listConfigurations: (companyId: string) =>
|
||||
api.get<Record<string, unknown>[]>(`/companies/${companyId}/agent-configurations`),
|
||||
get: (id: string) => api.get<Agent>(`/agents/${id}`),
|
||||
getConfiguration: (id: string) => api.get<Record<string, unknown>>(`/agents/${id}/configuration`),
|
||||
listConfigRevisions: (id: string) =>
|
||||
api.get<AgentConfigRevision[]>(`/agents/${id}/config-revisions`),
|
||||
getConfigRevision: (id: string, revisionId: string) =>
|
||||
api.get<AgentConfigRevision>(`/agents/${id}/config-revisions/${revisionId}`),
|
||||
rollbackConfigRevision: (id: string, revisionId: string) =>
|
||||
api.post<Agent>(`/agents/${id}/config-revisions/${revisionId}/rollback`, {}),
|
||||
get: async (id: string, companyId?: string) => {
|
||||
try {
|
||||
return await api.get<Agent>(agentPath(id, companyId));
|
||||
} catch (error) {
|
||||
// Backward-compat fallback: if backend shortname lookup reports ambiguity,
|
||||
// resolve using company agent list while ignoring terminated agents.
|
||||
if (
|
||||
!(error instanceof ApiError) ||
|
||||
error.status !== 409 ||
|
||||
!companyId ||
|
||||
isUuidLike(id)
|
||||
) {
|
||||
throw error;
|
||||
}
|
||||
|
||||
const urlKey = normalizeAgentUrlKey(id);
|
||||
if (!urlKey) throw error;
|
||||
|
||||
const agents = await api.get<Agent[]>(`/companies/${companyId}/agents`);
|
||||
const matches = agents.filter(
|
||||
(agent) => agent.status !== "terminated" && normalizeAgentUrlKey(agent.urlKey) === urlKey,
|
||||
);
|
||||
if (matches.length !== 1) throw error;
|
||||
return api.get<Agent>(agentPath(matches[0]!.id, companyId));
|
||||
}
|
||||
},
|
||||
getConfiguration: (id: string, companyId?: string) =>
|
||||
api.get<Record<string, unknown>>(agentPath(id, companyId, "/configuration")),
|
||||
listConfigRevisions: (id: string, companyId?: string) =>
|
||||
api.get<AgentConfigRevision[]>(agentPath(id, companyId, "/config-revisions")),
|
||||
getConfigRevision: (id: string, revisionId: string, companyId?: string) =>
|
||||
api.get<AgentConfigRevision>(agentPath(id, companyId, `/config-revisions/${revisionId}`)),
|
||||
rollbackConfigRevision: (id: string, revisionId: string, companyId?: string) =>
|
||||
api.post<Agent>(agentPath(id, companyId, `/config-revisions/${revisionId}/rollback`), {}),
|
||||
create: (companyId: string, data: Record<string, unknown>) =>
|
||||
api.post<Agent>(`/companies/${companyId}/agents`, data),
|
||||
hire: (companyId: string, data: Record<string, unknown>) =>
|
||||
api.post<AgentHireResponse>(`/companies/${companyId}/agent-hires`, data),
|
||||
update: (id: string, data: Record<string, unknown>) => api.patch<Agent>(`/agents/${id}`, data),
|
||||
updatePermissions: (id: string, data: { canCreateAgents: boolean }) =>
|
||||
api.patch<Agent>(`/agents/${id}/permissions`, data),
|
||||
pause: (id: string) => api.post<Agent>(`/agents/${id}/pause`, {}),
|
||||
resume: (id: string) => api.post<Agent>(`/agents/${id}/resume`, {}),
|
||||
terminate: (id: string) => api.post<Agent>(`/agents/${id}/terminate`, {}),
|
||||
remove: (id: string) => api.delete<{ ok: true }>(`/agents/${id}`),
|
||||
listKeys: (id: string) => api.get<AgentKey[]>(`/agents/${id}/keys`),
|
||||
createKey: (id: string, name: string) => api.post<AgentKeyCreated>(`/agents/${id}/keys`, { name }),
|
||||
revokeKey: (agentId: string, keyId: string) => api.delete<{ ok: true }>(`/agents/${agentId}/keys/${keyId}`),
|
||||
runtimeState: (id: string) => api.get<AgentRuntimeState>(`/agents/${id}/runtime-state`),
|
||||
taskSessions: (id: string) => api.get<AgentTaskSession[]>(`/agents/${id}/task-sessions`),
|
||||
resetSession: (id: string, taskKey?: string | null) =>
|
||||
api.post<void>(`/agents/${id}/runtime-state/reset-session`, { taskKey: taskKey ?? null }),
|
||||
update: (id: string, data: Record<string, unknown>, companyId?: string) =>
|
||||
api.patch<Agent>(agentPath(id, companyId), data),
|
||||
updatePermissions: (id: string, data: { canCreateAgents: boolean }, companyId?: string) =>
|
||||
api.patch<Agent>(agentPath(id, companyId, "/permissions"), data),
|
||||
pause: (id: string, companyId?: string) => api.post<Agent>(agentPath(id, companyId, "/pause"), {}),
|
||||
resume: (id: string, companyId?: string) => api.post<Agent>(agentPath(id, companyId, "/resume"), {}),
|
||||
terminate: (id: string, companyId?: string) => api.post<Agent>(agentPath(id, companyId, "/terminate"), {}),
|
||||
remove: (id: string, companyId?: string) => api.delete<{ ok: true }>(agentPath(id, companyId)),
|
||||
listKeys: (id: string, companyId?: string) => api.get<AgentKey[]>(agentPath(id, companyId, "/keys")),
|
||||
createKey: (id: string, name: string, companyId?: string) =>
|
||||
api.post<AgentKeyCreated>(agentPath(id, companyId, "/keys"), { name }),
|
||||
revokeKey: (agentId: string, keyId: string, companyId?: string) =>
|
||||
api.delete<{ ok: true }>(agentPath(agentId, companyId, `/keys/${encodeURIComponent(keyId)}`)),
|
||||
runtimeState: (id: string, companyId?: string) =>
|
||||
api.get<AgentRuntimeState>(agentPath(id, companyId, "/runtime-state")),
|
||||
taskSessions: (id: string, companyId?: string) =>
|
||||
api.get<AgentTaskSession[]>(agentPath(id, companyId, "/task-sessions")),
|
||||
resetSession: (id: string, taskKey?: string | null, companyId?: string) =>
|
||||
api.post<void>(agentPath(id, companyId, "/runtime-state/reset-session"), { taskKey: taskKey ?? null }),
|
||||
adapterModels: (type: string) => api.get<AdapterModel[]>(`/adapters/${type}/models`),
|
||||
testEnvironment: (
|
||||
companyId: string,
|
||||
@@ -85,7 +127,7 @@ export const agentsApi = {
|
||||
`/companies/${companyId}/adapters/${type}/test-environment`,
|
||||
data,
|
||||
),
|
||||
invoke: (id: string) => api.post<HeartbeatRun>(`/agents/${id}/heartbeat/invoke`, {}),
|
||||
invoke: (id: string, companyId?: string) => api.post<HeartbeatRun>(agentPath(id, companyId, "/heartbeat/invoke"), {}),
|
||||
wakeup: (
|
||||
id: string,
|
||||
data: {
|
||||
@@ -95,6 +137,8 @@ export const agentsApi = {
|
||||
payload?: Record<string, unknown> | null;
|
||||
idempotencyKey?: string | null;
|
||||
},
|
||||
) => api.post<HeartbeatRun | { status: "skipped" }>(`/agents/${id}/wakeup`, data),
|
||||
loginWithClaude: (id: string) => api.post<ClaudeLoginResult>(`/agents/${id}/claude-login`, {}),
|
||||
companyId?: string,
|
||||
) => api.post<HeartbeatRun | { status: "skipped" }>(agentPath(id, companyId, "/wakeup"), data),
|
||||
loginWithClaude: (id: string, companyId?: string) =>
|
||||
api.post<ClaudeLoginResult>(agentPath(id, companyId, "/claude-login"), {}),
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user