// This file contains the definition of the protocol used for communication between the SB server and clients import { DirectoryEntry, GetManyRequestPayload, GetManyResponsePayload, PutManyRequestPayload, PutManyResponsePayload } from '../dbfs/types.js'; import { ApiToSign, ApiToVerify, AppToSign, AppToVerify, ApplicationSignatureTreeSigned, Signature } from '../signing/constants.js'; import { ApplicationConfiguration, ApplicationPageClonePayload, CreateApplicationPageResponseBody, CreateApplicationPageSocketPayload, GetMultiPageApplicationResponseBody, GetApiResponseBody, IApplicationV2Dto, PageSummary, PostApiBranchCreateResponseBody, PostApplicationBranchCreateResponseBody, PostApplicationCreateRequestBody, RemoteCommitDto, ResponseMeta, ExportedMultiPageApplicationDto, ExportViewMode, ExportedApiV3Dto, ModifyEntitiesPayload, ModifyEntitiesResponse, GetAppBranchLockResponseBody, LockInfo, DegradedMode, CheckpointSkipReason } from '../types'; import { AiChatMessageDto, AiChatMessagePayload, AiPromptCostRequest, AiPromptCostResponse, AiWorkflowEvent, AiResolveAttachmentLeasesRequest, AiResolveAttachmentLeasesResponse, FactCreate, FactDto, FactListQuery, ListFactsResponse, NpmInstallBlockedAuditReport } from '../types/index.js'; import { MethodSchema } from './types.js'; export const serverWsPath = 'v1/rpc-ws'; type ResponseDto = { responseMeta: ResponseMeta; data: T; }; type ServerMethodSchema = MethodSchema>; // the version numbers (e.g. v1, v2, v3) follow the version numbers of the REST API export interface ServerMethods { v1: { echo: ServerMethodSchema<{ message: string }, { message: string }>; public: { application: { component: { register: ServerMethodSchema< { applicationId: string; branchName: string; cliVersion: string; componentEvent: string; components: Record; }, { success: boolean } >; update: ServerMethodSchema< { applicationId: string; branchName?: string; srcFiles: string[]; buildFiles: string[]; registeredComponents: Record; cliVersion: string | undefined; componentBaseUrl: string; signingRequired: boolean; }, { success: boolean } >; }; pushCommit: ServerMethodSchema< { applicationId: string; branchName: string; commitId: string; commitMessage: string; application: Record; page: Record; apis: Record[]; gitState: Record; }, RemoteCommitDto >; }; api: { pushCommit: ServerMethodSchema< { apiId: string; branchName: string; commitId: string; commitMessage: string; apiPb: Record; gitState: Record; skipCommit?: boolean; }, RemoteCommitDto | { updated: Date } >; get: ServerMethodSchema<{ apiId: string; branchName?: string; viewMode: ExportViewMode; commitId?: string }, ExportedApiV3Dto>; }; }; dbfs: { fileContents: { get: ServerMethodSchema<{ hash: string }, { contents: string }>; getByPath: ServerMethodSchema<{ directoryHash: string; path: string }, { contents: string }>; put: ServerMethodSchema<{ contents: string }, { hash: string }>; }; directoryContents: { get: ServerMethodSchema<{ hash: string }, { contents: DirectoryEntry[] }>; getByPath: ServerMethodSchema<{ directoryHash: string; path: string }, { contents: DirectoryEntry[] }>; put: ServerMethodSchema<{ contents: DirectoryEntry[] }, { hash: string }>; }; getMany: ServerMethodSchema; /** * This method is used to put multiple files and directories at once. It is more efficient than calling the put method * for each file and directory. The response is a list of hashes for the items that were put, in the same order as the items * in the request. */ putMany: ServerMethodSchema; }; ai: { chat: { pushMessage: ServerMethodSchema< { applicationId: string; payload: AiChatMessagePayload; version?: number; branchName?: string | null }, { chatmessageId: string } >; getMessages: ServerMethodSchema< { applicationId: string; branchName?: string | null; limit?: number }, { messages: AiChatMessageDto[] } >; new: ServerMethodSchema<{ applicationId: string; branchName?: string | null }, void>; truncateAfterTimestamp: ServerMethodSchema<{ applicationId: string; sinceTimestamp: number }, void>; }; billing: { promptCost: { calculate: ServerMethodSchema; }; workflowSummary: { submit: ServerMethodSchema; }; }; /** * Resolve attachment leases and return fresh signed URLs. * Called by ai-service to refresh attachment leases before sending to LLM. */ resolveAttachmentLeases: ServerMethodSchema; }; fact: { list: ServerMethodSchema; create: ServerMethodSchema; }; audit: { /** * Report a controlled-install `NpmInstallBlocked` so the server can write a * throttled OCSF audit row (APPS-4191 / P6.3). Org + actor are derived from * the authenticated connection; `recorded` is false when the event was * dropped by the per-org or global throttle. */ npmInstallBlocked: ServerMethodSchema; }; }; v2: { application: { create: ServerMethodSchema; clone: ServerMethodSchema<{ applicationId: string }, IApplicationV2Dto>; createBranch: ServerMethodSchema< { applicationId: string; branchName: string; baseBranchName: string }, PostApplicationBranchCreateResponseBody >; page: { clone: ServerMethodSchema< ApplicationPageClonePayload, { page: PageSummary; updated: Date; signature: ApplicationSignatureTreeSigned | null; configuration: ApplicationConfiguration; } >; create: ServerMethodSchema; }; modifyEntities: ServerMethodSchema; }; public: { application: { pushCommit: ServerMethodSchema< { applicationId: string; branchName: string; commitId: string; commitMessage: string; application: Record; pages: Record[]; apis: Record[]; gitState: Record; skipCommit?: boolean; }, RemoteCommitDto | { updated: Date } >; get: ServerMethodSchema< { applicationId: string; viewMode: ExportViewMode; branchName?: string; commitId?: string }, ExportedMultiPageApplicationDto >; }; }; }; v3: { application: { get: ServerMethodSchema<{ applicationId: string; branchName?: string }, GetMultiPageApplicationResponseBody>; liveEditDirectoryContents: { /** * @deprecated Use `v3.application.directoryContents.get` instead. */ get: ServerMethodSchema<{ applicationId: string; branchName?: string }, { hash: string }>; set: ServerMethodSchema< { applicationId: string; branchName?: string; hash: string; source?: string; targetTemplateName?: string; migrationGeneration?: number; }, { hash: string; degradedMode?: DegradedMode; commitId?: string; commitMessage?: string; checkpointSkipped?: CheckpointSkipReason; } >; }; directoryContents: { get: ServerMethodSchema< { applicationId: string; branchName?: string; commitId?: string; viewMode: ExportViewMode; }, // `latestNonDraftCommitId` is the commit the conversation context is // archived under in Bucketeer. The dev-server uses it to restore the // right context on a cold/recycled pod; it is populated for the // live-edit views (EXPORT_LIVE / EXPORT_DRAFT) and omitted for // commit/deployed lookups where it is not meaningful. { hash: string; latestNonDraftCommitId?: string } >; }; draftState: { set: ServerMethodSchema<{ applicationId: string; branchName?: string; hasDraft: boolean }, void>; }; pushCommit: ServerMethodSchema< { applicationId: string; branch?: string; localDirectoryPath: string; commitId: string; commitMessage: string; forcePush?: boolean; gitState: Record; skipCommit?: boolean; directoryHash?: string; }, RemoteCommitDto >; }; api: { createBranch: ServerMethodSchema<{ apiId: string; branchName: string; baseBranchName: string }, PostApiBranchCreateResponseBody>; get: ServerMethodSchema<{ apiId: string; branchName?: string }, GetApiResponseBody>; }; lock: { acquire: ServerMethodSchema<{ applicationId: string; branchName: string; sessionType: string }, GetAppBranchLockResponseBody>; release: ServerMethodSchema<{ applicationId: string; branchName: string; lockId: string }, void>; transfer: ServerMethodSchema< { applicationId: string; fromBranchName: string; toBranchName: string; lockId: string }, GetAppBranchLockResponseBody >; grab: ServerMethodSchema<{ applicationId: string; branchName: string; lockId: string }, GetAppBranchLockResponseBody>; inspect: ServerMethodSchema<{ applicationId: string; branchName: string }, LockInfo>; forceTake: ServerMethodSchema<{ applicationId: string; branchName: string; sessionType: string }, GetAppBranchLockResponseBody>; }; }; } export interface ClientMethods { v1: { signing: { signApplication: MethodSchema<{ branchName: string; toSign: AppToSign }, { signature: Signature }>; signApis: MethodSchema<{ branchName: string; toSign: ApiToSign[] }, { signatures: Signature[] }>; verifyApplication: MethodSchema<{ branchName: string; toVerify: AppToVerify }, { ok: boolean }>; verifyApi: MethodSchema<{ branchName: string; toVerify: ApiToVerify[] }, { ok: boolean }>; }; }; }