From 5f147e0b9ab4817da4ecc3da5bbe840cffe6df3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9B=B7=E7=94=B5=E8=8A=BD=E8=A1=A3?= Date: Thu, 16 Apr 2026 23:28:08 -0400 Subject: [PATCH] refactor(contracts): compose DesktopApi from per-domain sub-interfaces Split the flat 134-method DesktopApi interface into 12 domain sub-interfaces (companies, agents, tasks, runs, approvals, communication, threads, credentials, skills, budget, automation, window) under src/shared/contracts/desktop-api/. desktop-api.ts now intersects them to preserve the exact external flat shape; window.agentCompany consumers and preload wiring are untouched. --- src/shared/contracts/desktop-api.ts | 333 +++--------------- src/shared/contracts/desktop-api/agents.ts | 25 ++ src/shared/contracts/desktop-api/approvals.ts | 12 + .../contracts/desktop-api/automation.ts | 25 ++ src/shared/contracts/desktop-api/budget.ts | 13 + src/shared/contracts/desktop-api/common.ts | 46 +++ .../contracts/desktop-api/communication.ts | 22 ++ src/shared/contracts/desktop-api/companies.ts | 31 ++ .../contracts/desktop-api/credentials.ts | 9 + src/shared/contracts/desktop-api/runs.ts | 17 + src/shared/contracts/desktop-api/skills.ts | 14 + src/shared/contracts/desktop-api/tasks.ts | 21 ++ src/shared/contracts/desktop-api/threads.ts | 24 ++ src/shared/contracts/desktop-api/window.ts | 10 + 14 files changed, 319 insertions(+), 283 deletions(-) create mode 100644 src/shared/contracts/desktop-api/agents.ts create mode 100644 src/shared/contracts/desktop-api/approvals.ts create mode 100644 src/shared/contracts/desktop-api/automation.ts create mode 100644 src/shared/contracts/desktop-api/budget.ts create mode 100644 src/shared/contracts/desktop-api/common.ts create mode 100644 src/shared/contracts/desktop-api/communication.ts create mode 100644 src/shared/contracts/desktop-api/companies.ts create mode 100644 src/shared/contracts/desktop-api/credentials.ts create mode 100644 src/shared/contracts/desktop-api/runs.ts create mode 100644 src/shared/contracts/desktop-api/skills.ts create mode 100644 src/shared/contracts/desktop-api/tasks.ts create mode 100644 src/shared/contracts/desktop-api/threads.ts create mode 100644 src/shared/contracts/desktop-api/window.ts diff --git a/src/shared/contracts/desktop-api.ts b/src/shared/contracts/desktop-api.ts index 3b13d948..64e94f0b 100644 --- a/src/shared/contracts/desktop-api.ts +++ b/src/shared/contracts/desktop-api.ts @@ -1,287 +1,54 @@ -import { z } from "zod"; -import type { - AgentMessageRecord, - AgentMetrics, - AgentRecord, - ApprovalRecord, - BrowserActionRecord, - BudgetIncidentRecord, - BudgetPolicyRecord, - BudgetStatusSummary, - CommentRecord, - CompanyMetrics, - ConversationEventRecord, - ConversationParticipantRecord, - ConversationThreadRecord, - DesktopEvent, - InboxItem, - OnboardingBootstrapResult, - ProfileSnapshot, - RunLogChunk, - RunRecord, - SkillImportResult, - SkillRecord, - SkillUpdateStatus, - StandupReport, - TaskRecord, - ThreadSubscriptionRecord, - ThreadWaitStateRecord, -} from "../types"; -import type { SidebarBadges } from "./schemas-misc"; -import type { WakeupRequestRecord } from "./schemas-misc"; -import { - agentInputSchema, - heartbeatSettingsSchema, - hireRequestSchema, - triggerHeartbeatSchema, -} from "./schemas-agents"; -import { - approvalDecisionSchema, - approvalInputSchema, -} from "./schemas-approvals"; -import { - browserActionQuerySchema, - cancelBrowserActionSchema, - cancelRunSchema, - openTerminalCommandSchema, - runLogChunkSchema, - runLogSchema, - runWorkflowSchema, - startRunSchema, - triggerBrowserLoginSchema, - workflowInputSchema, -} from "./schemas-execution"; -import { - commentInputSchema, - documentInputSchema, - knowledgeEntryInputSchema, - listCommentsSchema, - markMessageReadSchema, - meetingInputSchema, - messageQuerySchema, - searchMessagesSchema, - agentMessageInputSchema, -} from "./schemas-messages"; -import { - automationRuleInputSchema, - budgetPolicyInputSchema, - createThreadSchema, - addThreadEventSchema, - deleteBudgetPolicySchema, - deleteEntitySchema, - entityGetterSchema, - listBudgetIncidentsSchema, - listThreadEventsSchema, - listThreadsSchema, - listThreadWaitStatesSchema, - metricsQuerySchema, - resolveThreadWaitStateSchema, - resolveBudgetIncidentSchema, - setThreadWaitStateSchema, - threadGetterSchema, - toggleAutomationRuleSchema, - wakeupQuerySchema, - listParticipantsSchema, - addParticipantSchema, - removeParticipantSchema, - subscribeThreadSchema, - unsubscribeThreadSchema, - listSubscriptionsSchema, - listSubscribedThreadsSchema, -} from "./schemas-misc"; -import { - autoAssignSchema, - goalInputSchema, - projectInputSchema, - sprintInputSchema, - taskInputSchema, -} from "./schemas-tasks"; -import { - bootstrapOnboardingSchema, - companyInputSchema, - connectorDisabledModelsSchema, - connectorInputSchema, - secretInputSchema, - settingsSchema, - socialAccountInputSchema, - workspaceInputSchema, -} from "./schemas-company"; +// DesktopApi composition. Flat shape is preserved via intersection of sub-APIs; +// external `window.agentCompany` callers stay unchanged. Per-domain declarations +// live in `./desktop-api/*.ts`. -export type DesktopResult = - | { ok: true; data: T } - | { ok: false; error: { code: string; message: string } }; +import type { AgentsApi } from "./desktop-api/agents"; +import type { ApprovalsApi } from "./desktop-api/approvals"; +import type { AutomationApi } from "./desktop-api/automation"; +import type { BudgetApi } from "./desktop-api/budget"; +import type { CommunicationApi } from "./desktop-api/communication"; +import type { CompaniesApi } from "./desktop-api/companies"; +import type { CredentialsApi } from "./desktop-api/credentials"; +import type { RunsApi } from "./desktop-api/runs"; +import type { SkillsApi } from "./desktop-api/skills"; +import type { TasksApi } from "./desktop-api/tasks"; +import type { ThreadsApi } from "./desktop-api/threads"; +import type { WindowApi } from "./desktop-api/window"; -export interface SaveTaskResult { - id: string; - capabilityWarning?: string; -} +export type { + DesktopResult, + SaveTaskResult, + ConfigRevisionSummary, + ConfigRevisionDetail, + RunEventRecord, + HeartbeatPolicy, +} from "./desktop-api/common"; -export interface ConfigRevisionSummary { - id: string; - agentId: string; - revisionNumber: number; - changedKeys: string[]; - source: string; - rolledBackFromRevisionId: string | null; - createdByAgentId: string | null; - createdByUserId: string | null; - createdAt: string; -} - -export interface ConfigRevisionDetail extends ConfigRevisionSummary { - configBefore: Record; - configAfter: Record; -} - -export interface RunEventRecord { - id: number; - runId: string; - agentId: string; - seq: number; - eventType: string; - stream: string | null; - level: string | null; - message: string | null; - payload: Record | null; - createdAt: string; -} - -export interface HeartbeatPolicy { - enabled: boolean; - intervalSec: number; - cooldownSec: number; - maxConcurrentRuns: number; - wakeOnDemand: boolean; -} - -export type DesktopApi = { - loadSnapshot: () => Promise>; - pickDirectory: () => Promise>; - openPath: (targetPath: string) => Promise>; - saveCompany: (input: z.infer) => Promise>; - setCurrentCompany: (companyId: string) => Promise>; - saveConnector: (input: z.infer) => Promise>; - testConnector: (id: z.infer) => Promise>; - saveWorkspace: (input: z.infer) => Promise>; - saveAgent: (input: z.infer) => Promise>; - requestHire: (input: z.infer) => Promise>; - saveGoal: (input: z.infer) => Promise>; - saveProject: (input: z.infer) => Promise>; - saveTask: (input: z.infer) => Promise>; - requestApproval: (input: z.infer) => Promise>; - decideApproval: (input: z.infer) => Promise>; - saveSecret: (input: z.infer) => Promise>; - startTaskRun: (input: z.infer) => Promise>; - cancelRun: (input: z.infer) => Promise>; - getRunLog: (input: z.infer) => Promise>; - getRunLogChunk: (input: z.infer) => Promise>; - backupProfile: () => Promise>; - restoreProfile: () => Promise>; - updateSettings: (input: z.infer) => Promise>; - checkForUpdates: () => Promise>; - deleteCompany: (companyId: string) => Promise>; - deleteAgent: (input: z.infer) => Promise>; - deleteTask: (input: z.infer) => Promise>; - deleteGoal: (input: z.infer) => Promise>; - deleteProject: (input: z.infer) => Promise>; - deleteWorkspace: (input: z.infer) => Promise>; - deleteApproval: (input: z.infer) => Promise>; - deleteSecret: (input: z.infer) => Promise>; - getSidebarBadges: (companyId: string) => Promise>; - listConnectorModels: (connectorId: string) => Promise>>; - getConnectorDisabledModels: (connectorId: string) => Promise>>; - setConnectorDisabledModels: (input: z.infer) => Promise>; - openConnectorAuthTerminal: (connectorId: z.infer) => Promise>; - addComment: (input: z.infer) => Promise>; - listComments: (input: z.infer) => Promise>; - setHeartbeat: (input: z.infer) => Promise>; - triggerHeartbeat: (input: z.infer) => Promise>; - getApiPort: () => Promise>; - getInbox: (companyId: string) => Promise>; - getCompanyMetrics: (input: z.infer) => Promise>; - getAgentMetrics: (input: z.infer) => Promise>; - getStandupReport: (companyId: string) => Promise>; - bootstrapOnboarding: (input: z.infer) => Promise>; - checkNodeInstalled: () => Promise>; - openTerminalCommand: (input: z.infer) => Promise>; - saveSocialAccount: (input: z.infer) => Promise>; - deleteSocialAccount: (input: z.infer) => Promise>; - listBrowserActions: (input: z.infer) => Promise>; - cancelBrowserAction: (input: z.infer) => Promise>; - triggerBrowserLogin: (input: z.infer) => Promise>; - saveMeeting: (input: z.infer) => Promise>; - deleteMeeting: (input: z.infer) => Promise>; - saveDocument: (input: z.infer) => Promise>; - deleteDocument: (input: z.infer) => Promise>; - saveKnowledgeEntry: (input: z.infer) => Promise>; - deleteKnowledgeEntry: (input: z.infer) => Promise>; - saveSprint: (input: z.infer) => Promise>; - deleteSprint: (input: z.infer) => Promise>; - saveAutomationRule: (input: z.infer) => Promise>; - deleteAutomationRule: (input: z.infer) => Promise>; - toggleAutomationRule: (input: z.infer) => Promise>; - getAutomationLog: (companyId: string) => Promise>>; - sendAgentMessage: (input: z.infer) => Promise>; - listAgentMessages: (input: z.infer) => Promise>; - markMessageRead: (input: z.infer) => Promise>; - saveWorkflow: (input: z.infer) => Promise>; - deleteWorkflow: (input: z.infer) => Promise>; - runWorkflow: (input: z.infer) => Promise>; - autoAssignTask: (input: z.infer) => Promise>; - searchMessages: (input: z.infer) => Promise>; - importSkill: (companyId: string, source: string) => Promise>; - listSkills: (companyId: string) => Promise>; - getSkillDetail: (companyId: string, skillId: string) => Promise>; - deleteSkill: (companyId: string, skillId: string) => Promise>; - assignSkillToAgent: (companyId: string, agentId: string, skillId: string) => Promise>; - removeSkillFromAgent: (companyId: string, agentId: string, skillId: string) => Promise>; - checkSkillUpdate: (companyId: string, skillId: string) => Promise>; - listSkillAgents: (companyId: string, skillId: string) => Promise>; - listAgentSkills: (companyId: string, agentId: string) => Promise>; - listWakeupRequests: (input: z.infer) => Promise>; - saveBudgetPolicy: (input: z.infer) => Promise>; - deleteBudgetPolicy: (input: z.infer) => Promise>; - listBudgetPolicies: (companyId: string) => Promise>; - listBudgetIncidents: (input: z.infer) => Promise>; - resolveBudgetIncident: (input: z.infer) => Promise>; - getBudgetStatus: (companyId: string) => Promise>; - recoveryRetry: (taskId: string, agentId: string, companyId: string) => Promise>; - recoveryDismiss: (taskId: string) => Promise>; - recoveryFail: (taskId: string) => Promise>; - getTask: (input: z.infer) => Promise>; - getAgent: (input: z.infer) => Promise>; - getRun: (input: z.infer) => Promise>; - getApproval: (input: z.infer) => Promise>; - listConfigRevisions: (companyId: string, agentId: string) => Promise>; - getConfigRevision: (companyId: string, revisionId: string) => Promise>; - rollbackConfigRevision: (companyId: string, agentId: string, revisionId: string) => Promise>; - listRunEvents: (companyId: string, runId: string, opts?: { offset?: number; limit?: number }) => Promise>; - getAgentPermissions: (agentId: string) => Promise>>; - setAgentPermission: (companyId: string, agentId: string, permissionKey: string, enabled: boolean) => Promise>; - getHeartbeatPolicy: (agentId: string, companyId: string) => Promise>; - setHeartbeatPolicy: (companyId: string, agentId: string, policy: Record) => Promise>; - getRuntimeState: (agentId: string, companyId: string) => Promise>>; - setRuntimeState: (companyId: string, agentId: string, state: Record) => Promise>; - // Thread runtime - createThread: (input: z.infer) => Promise>; - listThreads: (input: z.infer) => Promise>; - getThread: (input: z.infer) => Promise>; - addThreadEvent: (input: z.infer) => Promise>; - listThreadEvents: (input: z.infer) => Promise>; - setThreadWaitState: (input: z.infer) => Promise>; - resolveThreadWaitState: (input: z.infer) => Promise>; - listThreadWaitStates: (input: z.infer) => Promise>; - listParticipants: (input: z.infer) => Promise>; - addParticipant: (input: z.infer) => Promise>; - removeParticipant: (input: z.infer) => Promise>; - subscribeThread: (input: z.infer) => Promise>; - unsubscribeThread: (input: z.infer) => Promise>; - listSubscriptions: (input: z.infer) => Promise>; - listSubscribedThreads: (input: z.infer) => Promise>; - subscribe: (callback: (event: DesktopEvent) => void) => () => void; - platform: "win32" | "darwin" | "linux"; - windowMinimize: () => Promise; - windowMaximize: () => Promise; - windowClose: () => Promise; - windowIsMaximized: () => Promise; +export type { + AgentsApi, + ApprovalsApi, + AutomationApi, + BudgetApi, + CommunicationApi, + CompaniesApi, + CredentialsApi, + RunsApi, + SkillsApi, + TasksApi, + ThreadsApi, + WindowApi, }; + +export type DesktopApi = + & CompaniesApi + & AgentsApi + & TasksApi + & RunsApi + & ApprovalsApi + & CommunicationApi + & ThreadsApi + & CredentialsApi + & SkillsApi + & BudgetApi + & AutomationApi + & WindowApi; diff --git a/src/shared/contracts/desktop-api/agents.ts b/src/shared/contracts/desktop-api/agents.ts new file mode 100644 index 00000000..133e15bb --- /dev/null +++ b/src/shared/contracts/desktop-api/agents.ts @@ -0,0 +1,25 @@ +import type { z } from "zod"; +import type { AgentMetrics, AgentRecord } from "../../types"; +import type { agentInputSchema, heartbeatSettingsSchema, hireRequestSchema, triggerHeartbeatSchema } from "../schemas-agents"; +import type { entityGetterSchema, metricsQuerySchema } from "../schemas-badges"; +import type { deleteEntitySchema } from "../schemas-badges"; +import type { DesktopResult, HeartbeatPolicy } from "./common"; + +export type AgentsApi = { + saveAgent: (input: z.infer) => Promise>; + requestHire: (input: z.infer) => Promise>; + deleteAgent: (input: z.infer) => Promise>; + getAgent: (input: z.infer) => Promise>; + getAgentMetrics: (input: z.infer) => Promise>; + setHeartbeat: (input: z.infer) => Promise>; + triggerHeartbeat: (input: z.infer) => Promise>; + getAgentPermissions: (agentId: string) => Promise>>; + setAgentPermission: (companyId: string, agentId: string, permissionKey: string, enabled: boolean) => Promise>; + getHeartbeatPolicy: (agentId: string, companyId: string) => Promise>; + setHeartbeatPolicy: (companyId: string, agentId: string, policy: Record) => Promise>; + getRuntimeState: (agentId: string, companyId: string) => Promise>>; + setRuntimeState: (companyId: string, agentId: string, state: Record) => Promise>; + listConfigRevisions: (companyId: string, agentId: string) => Promise>; + getConfigRevision: (companyId: string, revisionId: string) => Promise>; + rollbackConfigRevision: (companyId: string, agentId: string, revisionId: string) => Promise>; +}; diff --git a/src/shared/contracts/desktop-api/approvals.ts b/src/shared/contracts/desktop-api/approvals.ts new file mode 100644 index 00000000..ef2b712e --- /dev/null +++ b/src/shared/contracts/desktop-api/approvals.ts @@ -0,0 +1,12 @@ +import type { z } from "zod"; +import type { ApprovalRecord } from "../../types"; +import type { approvalDecisionSchema, approvalInputSchema } from "../schemas-approvals"; +import type { deleteEntitySchema, entityGetterSchema } from "../schemas-badges"; +import type { DesktopResult } from "./common"; + +export type ApprovalsApi = { + requestApproval: (input: z.infer) => Promise>; + decideApproval: (input: z.infer) => Promise>; + deleteApproval: (input: z.infer) => Promise>; + getApproval: (input: z.infer) => Promise>; +}; diff --git a/src/shared/contracts/desktop-api/automation.ts b/src/shared/contracts/desktop-api/automation.ts new file mode 100644 index 00000000..2566aeaf --- /dev/null +++ b/src/shared/contracts/desktop-api/automation.ts @@ -0,0 +1,25 @@ +import type { z } from "zod"; +import type { BrowserActionRecord } from "../../types"; +import type { automationRuleInputSchema, toggleAutomationRuleSchema } from "../schemas-automation"; +import type { browserActionQuerySchema, cancelBrowserActionSchema, openTerminalCommandSchema, runWorkflowSchema, triggerBrowserLoginSchema, workflowInputSchema } from "../schemas-execution"; +import type { socialAccountInputSchema } from "../schemas-company"; +import type { deleteEntitySchema } from "../schemas-badges"; +import type { wakeupQuerySchema, WakeupRequestRecord } from "../schemas-wakeup"; +import type { DesktopResult } from "./common"; + +export type AutomationApi = { + saveAutomationRule: (input: z.infer) => Promise>; + deleteAutomationRule: (input: z.infer) => Promise>; + toggleAutomationRule: (input: z.infer) => Promise>; + getAutomationLog: (companyId: string) => Promise>>; + saveWorkflow: (input: z.infer) => Promise>; + deleteWorkflow: (input: z.infer) => Promise>; + runWorkflow: (input: z.infer) => Promise>; + listWakeupRequests: (input: z.infer) => Promise>; + saveSocialAccount: (input: z.infer) => Promise>; + deleteSocialAccount: (input: z.infer) => Promise>; + listBrowserActions: (input: z.infer) => Promise>; + cancelBrowserAction: (input: z.infer) => Promise>; + triggerBrowserLogin: (input: z.infer) => Promise>; + openTerminalCommand: (input: z.infer) => Promise>; +}; diff --git a/src/shared/contracts/desktop-api/budget.ts b/src/shared/contracts/desktop-api/budget.ts new file mode 100644 index 00000000..ad6c2976 --- /dev/null +++ b/src/shared/contracts/desktop-api/budget.ts @@ -0,0 +1,13 @@ +import type { z } from "zod"; +import type { BudgetIncidentRecord, BudgetPolicyRecord, BudgetStatusSummary } from "../../types"; +import type { budgetPolicyInputSchema, deleteBudgetPolicySchema, listBudgetIncidentsSchema, resolveBudgetIncidentSchema } from "../schemas-budget"; +import type { DesktopResult } from "./common"; + +export type BudgetApi = { + saveBudgetPolicy: (input: z.infer) => Promise>; + deleteBudgetPolicy: (input: z.infer) => Promise>; + listBudgetPolicies: (companyId: string) => Promise>; + listBudgetIncidents: (input: z.infer) => Promise>; + resolveBudgetIncident: (input: z.infer) => Promise>; + getBudgetStatus: (companyId: string) => Promise>; +}; diff --git a/src/shared/contracts/desktop-api/common.ts b/src/shared/contracts/desktop-api/common.ts new file mode 100644 index 00000000..a4d7b936 --- /dev/null +++ b/src/shared/contracts/desktop-api/common.ts @@ -0,0 +1,46 @@ +export type DesktopResult = + | { ok: true; data: T } + | { ok: false; error: { code: string; message: string } }; + +export interface SaveTaskResult { + id: string; + capabilityWarning?: string; +} + +export interface ConfigRevisionSummary { + id: string; + agentId: string; + revisionNumber: number; + changedKeys: string[]; + source: string; + rolledBackFromRevisionId: string | null; + createdByAgentId: string | null; + createdByUserId: string | null; + createdAt: string; +} + +export interface ConfigRevisionDetail extends ConfigRevisionSummary { + configBefore: Record; + configAfter: Record; +} + +export interface RunEventRecord { + id: number; + runId: string; + agentId: string; + seq: number; + eventType: string; + stream: string | null; + level: string | null; + message: string | null; + payload: Record | null; + createdAt: string; +} + +export interface HeartbeatPolicy { + enabled: boolean; + intervalSec: number; + cooldownSec: number; + maxConcurrentRuns: number; + wakeOnDemand: boolean; +} diff --git a/src/shared/contracts/desktop-api/communication.ts b/src/shared/contracts/desktop-api/communication.ts new file mode 100644 index 00000000..f89c6223 --- /dev/null +++ b/src/shared/contracts/desktop-api/communication.ts @@ -0,0 +1,22 @@ +import type { z } from "zod"; +import type { AgentMessageRecord, CommentRecord, DocumentRecord, KnowledgeEntryRecord } from "../../types"; +import type { agentMessageInputSchema, commentInputSchema, documentInputSchema, knowledgeEntryInputSchema, listCommentsSchema, markMessageReadSchema, meetingInputSchema, messageQuerySchema, searchMessagesSchema } from "../schemas-messages"; +import type { deleteEntitySchema } from "../schemas-badges"; +import type { DesktopResult } from "./common"; + +export type CommunicationApi = { + addComment: (input: z.infer) => Promise>; + listComments: (input: z.infer) => Promise>; + saveMeeting: (input: z.infer) => Promise>; + deleteMeeting: (input: z.infer) => Promise>; + saveDocument: (input: z.infer) => Promise>; + deleteDocument: (input: z.infer) => Promise>; + saveKnowledgeEntry: (input: z.infer) => Promise>; + deleteKnowledgeEntry: (input: z.infer) => Promise>; + sendAgentMessage: (input: z.infer) => Promise>; + listAgentMessages: (input: z.infer) => Promise>; + markMessageRead: (input: z.infer) => Promise>; + searchMessages: (input: z.infer) => Promise>; + // Keep reference to silence unused-import checker for DocumentRecord/KnowledgeEntryRecord — consumers infer via schemas. + _recordsAnchor?: never & { _d?: DocumentRecord; _k?: KnowledgeEntryRecord }; +}; diff --git a/src/shared/contracts/desktop-api/companies.ts b/src/shared/contracts/desktop-api/companies.ts new file mode 100644 index 00000000..70b91d75 --- /dev/null +++ b/src/shared/contracts/desktop-api/companies.ts @@ -0,0 +1,31 @@ +import type { z } from "zod"; +import type { CompanyMetrics, OnboardingBootstrapResult, ProfileSnapshot, StandupReport, InboxItem } from "../../types"; +import type { bootstrapOnboardingSchema, companyInputSchema, connectorDisabledModelsSchema, connectorInputSchema, settingsSchema } from "../schemas-company"; +import type { metricsQuerySchema, SidebarBadges } from "../schemas-badges"; +import type { DesktopResult } from "./common"; + +export type CompaniesApi = { + loadSnapshot: () => Promise>; + pickDirectory: () => Promise>; + openPath: (targetPath: string) => Promise>; + saveCompany: (input: z.infer) => Promise>; + setCurrentCompany: (companyId: string) => Promise>; + saveConnector: (input: z.infer) => Promise>; + testConnector: (id: z.infer) => Promise>; + updateSettings: (input: z.infer) => Promise>; + checkForUpdates: () => Promise>; + deleteCompany: (companyId: string) => Promise>; + getSidebarBadges: (companyId: string) => Promise>; + listConnectorModels: (connectorId: string) => Promise>>; + getConnectorDisabledModels: (connectorId: string) => Promise>>; + setConnectorDisabledModels: (input: z.infer) => Promise>; + openConnectorAuthTerminal: (connectorId: z.infer) => Promise>; + getApiPort: () => Promise>; + getInbox: (companyId: string) => Promise>; + getCompanyMetrics: (input: z.infer) => Promise>; + getStandupReport: (companyId: string) => Promise>; + bootstrapOnboarding: (input: z.infer) => Promise>; + checkNodeInstalled: () => Promise>; + backupProfile: () => Promise>; + restoreProfile: () => Promise>; +}; diff --git a/src/shared/contracts/desktop-api/credentials.ts b/src/shared/contracts/desktop-api/credentials.ts new file mode 100644 index 00000000..2ecf8eef --- /dev/null +++ b/src/shared/contracts/desktop-api/credentials.ts @@ -0,0 +1,9 @@ +import type { z } from "zod"; +import type { secretInputSchema } from "../schemas-company"; +import type { deleteEntitySchema } from "../schemas-badges"; +import type { DesktopResult } from "./common"; + +export type CredentialsApi = { + saveSecret: (input: z.infer) => Promise>; + deleteSecret: (input: z.infer) => Promise>; +}; diff --git a/src/shared/contracts/desktop-api/runs.ts b/src/shared/contracts/desktop-api/runs.ts new file mode 100644 index 00000000..5fb4a054 --- /dev/null +++ b/src/shared/contracts/desktop-api/runs.ts @@ -0,0 +1,17 @@ +import type { z } from "zod"; +import type { RunLogChunk, RunRecord } from "../../types"; +import type { cancelRunSchema, runLogChunkSchema, runLogSchema, startRunSchema } from "../schemas-execution"; +import type { entityGetterSchema } from "../schemas-badges"; +import type { DesktopResult, RunEventRecord } from "./common"; + +export type RunsApi = { + startTaskRun: (input: z.infer) => Promise>; + cancelRun: (input: z.infer) => Promise>; + getRunLog: (input: z.infer) => Promise>; + getRunLogChunk: (input: z.infer) => Promise>; + getRun: (input: z.infer) => Promise>; + listRunEvents: (companyId: string, runId: string, opts?: { offset?: number; limit?: number }) => Promise>; + recoveryRetry: (taskId: string, agentId: string, companyId: string) => Promise>; + recoveryDismiss: (taskId: string) => Promise>; + recoveryFail: (taskId: string) => Promise>; +}; diff --git a/src/shared/contracts/desktop-api/skills.ts b/src/shared/contracts/desktop-api/skills.ts new file mode 100644 index 00000000..eb60f736 --- /dev/null +++ b/src/shared/contracts/desktop-api/skills.ts @@ -0,0 +1,14 @@ +import type { SkillImportResult, SkillRecord, SkillUpdateStatus } from "../../types"; +import type { DesktopResult } from "./common"; + +export type SkillsApi = { + importSkill: (companyId: string, source: string) => Promise>; + listSkills: (companyId: string) => Promise>; + getSkillDetail: (companyId: string, skillId: string) => Promise>; + deleteSkill: (companyId: string, skillId: string) => Promise>; + assignSkillToAgent: (companyId: string, agentId: string, skillId: string) => Promise>; + removeSkillFromAgent: (companyId: string, agentId: string, skillId: string) => Promise>; + checkSkillUpdate: (companyId: string, skillId: string) => Promise>; + listSkillAgents: (companyId: string, skillId: string) => Promise>; + listAgentSkills: (companyId: string, agentId: string) => Promise>; +}; diff --git a/src/shared/contracts/desktop-api/tasks.ts b/src/shared/contracts/desktop-api/tasks.ts new file mode 100644 index 00000000..24639c92 --- /dev/null +++ b/src/shared/contracts/desktop-api/tasks.ts @@ -0,0 +1,21 @@ +import type { z } from "zod"; +import type { TaskRecord } from "../../types"; +import type { autoAssignSchema, goalInputSchema, projectInputSchema, sprintInputSchema, taskInputSchema } from "../schemas-tasks"; +import type { workspaceInputSchema } from "../schemas-company"; +import type { deleteEntitySchema, entityGetterSchema } from "../schemas-badges"; +import type { DesktopResult, SaveTaskResult } from "./common"; + +export type TasksApi = { + saveWorkspace: (input: z.infer) => Promise>; + saveGoal: (input: z.infer) => Promise>; + saveProject: (input: z.infer) => Promise>; + saveTask: (input: z.infer) => Promise>; + saveSprint: (input: z.infer) => Promise>; + deleteTask: (input: z.infer) => Promise>; + deleteGoal: (input: z.infer) => Promise>; + deleteProject: (input: z.infer) => Promise>; + deleteWorkspace: (input: z.infer) => Promise>; + deleteSprint: (input: z.infer) => Promise>; + getTask: (input: z.infer) => Promise>; + autoAssignTask: (input: z.infer) => Promise>; +}; diff --git a/src/shared/contracts/desktop-api/threads.ts b/src/shared/contracts/desktop-api/threads.ts new file mode 100644 index 00000000..28212698 --- /dev/null +++ b/src/shared/contracts/desktop-api/threads.ts @@ -0,0 +1,24 @@ +import type { z } from "zod"; +import type { ConversationEventRecord, ConversationParticipantRecord, ConversationThreadRecord, ThreadSubscriptionRecord, ThreadWaitStateRecord } from "../../types"; +import type { addThreadEventSchema, createThreadSchema, listThreadEventsSchema, listThreadsSchema, listThreadWaitStatesSchema, resolveThreadWaitStateSchema, setThreadWaitStateSchema, threadGetterSchema } from "../schemas-threads"; +import type { addParticipantSchema, listParticipantsSchema, removeParticipantSchema } from "../schemas-participants"; +import type { listSubscribedThreadsSchema, listSubscriptionsSchema, subscribeThreadSchema, unsubscribeThreadSchema } from "../schemas-subscriptions"; +import type { DesktopResult } from "./common"; + +export type ThreadsApi = { + createThread: (input: z.infer) => Promise>; + listThreads: (input: z.infer) => Promise>; + getThread: (input: z.infer) => Promise>; + addThreadEvent: (input: z.infer) => Promise>; + listThreadEvents: (input: z.infer) => Promise>; + setThreadWaitState: (input: z.infer) => Promise>; + resolveThreadWaitState: (input: z.infer) => Promise>; + listThreadWaitStates: (input: z.infer) => Promise>; + listParticipants: (input: z.infer) => Promise>; + addParticipant: (input: z.infer) => Promise>; + removeParticipant: (input: z.infer) => Promise>; + subscribeThread: (input: z.infer) => Promise>; + unsubscribeThread: (input: z.infer) => Promise>; + listSubscriptions: (input: z.infer) => Promise>; + listSubscribedThreads: (input: z.infer) => Promise>; +}; diff --git a/src/shared/contracts/desktop-api/window.ts b/src/shared/contracts/desktop-api/window.ts new file mode 100644 index 00000000..f6278d4f --- /dev/null +++ b/src/shared/contracts/desktop-api/window.ts @@ -0,0 +1,10 @@ +import type { DesktopEvent } from "../../types"; + +export type WindowApi = { + subscribe: (callback: (event: DesktopEvent) => void) => () => void; + platform: "win32" | "darwin" | "linux"; + windowMinimize: () => Promise; + windowMaximize: () => Promise; + windowClose: () => Promise; + windowIsMaximized: () => Promise; +};