mirror of
https://github.com/stablyai/orca.git
synced 2026-10-31 09:07:40 +00:00
* feat(connectors): connector seam lifecycle, conversation links and start behind experimentalConnectors (B2b-1) * feat(agent-write): opt-in launch cancel, approval wait and binding fence on the shared writer executeAgentLaunch takes an optional signal; sendTerminalAgentPrompt (and sendAgentTurn) take optional onPermission: 'wait' and expectedBinding. No existing caller sets them, so every current path is unchanged. * fix(agent-write): keep the default writer path main's; fence cancel and real submit boundary Only opted-in writes take the submit layer, so default timing and the leaf re-read are unchanged. Cancellation is rechecked before a structured-refusal terminal fallback, and an opted-in launch learns Enter from an onSubmitWritten callback at the write itself, OMP's combined frame included. * fix(connectors): pass the seam's signal to the launch, read links from each host's rows, and keep delivery ids on orchestration's durable receipts (B2b-1) * fix(agent-launch): a cancel after a failed startup spawn recovers the created workspace * fix(connectors): keep an unknown receipt once the launch published, and restore local-only metadata ownership (B2b-1) * fix(connectors): classify connector RPCs as host-owned; CLI start output claims a start only when definite
143 lines
5.6 KiB
TypeScript
143 lines
5.6 KiB
TypeScript
import type { FolderWorkspace } from './folder-workspace-types'
|
|
import type { ProjectGroup } from './project-group-types'
|
|
import { isTuiAgent } from './tui-agent-config'
|
|
import { normalizeStoredTaskSourceContext } from './task-source-context'
|
|
import { normalizeWorkspaceLinkedItem } from './workspace-linked-item'
|
|
import { isWorkspaceLinkedItemSourceContextMatch } from './workspace-linked-item-source-context'
|
|
import { normalizeWorkspaceCreatorProvenance } from './workspace-creator-provenance'
|
|
import { getWorkspaceAttachments } from './workspace-attachments'
|
|
import { isSmartTier } from './sidebar-list/sort-stamps'
|
|
|
|
export function normalizeFolderWorkspaceName(
|
|
name: string | null | undefined,
|
|
fallback = 'Untitled workspace'
|
|
): string {
|
|
const trimmed = typeof name === 'string' ? name.trim() : ''
|
|
return trimmed.length > 0 ? trimmed : fallback
|
|
}
|
|
|
|
export function normalizeFolderWorkspaces(
|
|
value: unknown,
|
|
projectGroups: readonly ProjectGroup[]
|
|
): FolderWorkspace[] {
|
|
if (!Array.isArray(value)) {
|
|
return []
|
|
}
|
|
const folderGroups = new Map<string, ProjectGroup>()
|
|
for (const group of projectGroups) {
|
|
if (group.parentPath) {
|
|
folderGroups.set(group.id, group)
|
|
}
|
|
}
|
|
|
|
const workspaces: FolderWorkspace[] = []
|
|
const seen = new Set<string>()
|
|
for (const candidate of value) {
|
|
if (!candidate || typeof candidate !== 'object') {
|
|
continue
|
|
}
|
|
const raw = candidate as Partial<FolderWorkspace>
|
|
if (
|
|
typeof raw.id !== 'string' ||
|
|
raw.id.trim().length === 0 ||
|
|
seen.has(raw.id) ||
|
|
typeof raw.projectGroupId !== 'string' ||
|
|
!folderGroups.has(raw.projectGroupId)
|
|
) {
|
|
continue
|
|
}
|
|
const group = folderGroups.get(raw.projectGroupId)
|
|
const folderPath =
|
|
typeof raw.folderPath === 'string' && raw.folderPath.trim().length > 0
|
|
? raw.folderPath
|
|
: group?.parentPath
|
|
if (!folderPath) {
|
|
continue
|
|
}
|
|
const now = Date.now()
|
|
const linkedTask = normalizeWorkspaceLinkedItem(raw.linkedTask)
|
|
const linkedTaskSourceContext = normalizeStoredTaskSourceContext(raw.linkedTaskSourceContext)
|
|
const creatorProvenance = normalizeWorkspaceCreatorProvenance(raw.creatorProvenance)
|
|
seen.add(raw.id)
|
|
// Why: `executionHostId` is deliberately NOT persisted. It is a fetch-time renderer
|
|
// stamp that can name a `runtime:*` authority the desktop store does not own, and it
|
|
// carries no generation to fence on. `connectionId` below is the durable pin main projects from.
|
|
workspaces.push({
|
|
id: raw.id,
|
|
projectGroupId: raw.projectGroupId,
|
|
name: normalizeFolderWorkspaceName(raw.name),
|
|
folderPath,
|
|
connectionId:
|
|
typeof raw.connectionId === 'string'
|
|
? raw.connectionId
|
|
: raw.connectionId === null
|
|
? null
|
|
: (group?.connectionId ?? null),
|
|
...(creatorProvenance ? { creatorProvenance } : {}),
|
|
linkedTask,
|
|
...(raw.linkedItems !== undefined
|
|
? {
|
|
linkedItems: getWorkspaceAttachments({
|
|
linkedItems: raw.linkedItems,
|
|
linkedWorkItem: linkedTask,
|
|
linkedTaskSourceContext
|
|
})
|
|
}
|
|
: {}),
|
|
linkedTaskSourceContext: isWorkspaceLinkedItemSourceContextMatch(
|
|
linkedTask,
|
|
linkedTaskSourceContext
|
|
)
|
|
? linkedTaskSourceContext
|
|
: null,
|
|
comment: typeof raw.comment === 'string' ? raw.comment : '',
|
|
isArchived: raw.isArchived === true,
|
|
isUnread: raw.isUnread === true,
|
|
isPinned: raw.isPinned === true,
|
|
sortOrder:
|
|
typeof raw.sortOrder === 'number' && Number.isFinite(raw.sortOrder) ? raw.sortOrder : now,
|
|
...(typeof raw.manualOrder === 'number' && Number.isFinite(raw.manualOrder)
|
|
? { manualOrder: raw.manualOrder }
|
|
: {}),
|
|
...(typeof raw.workspaceStatus === 'string' && raw.workspaceStatus.trim().length > 0
|
|
? { workspaceStatus: raw.workspaceStatus }
|
|
: {}),
|
|
...(isTuiAgent(raw.createdWithAgent) ? { createdWithAgent: raw.createdWithAgent } : {}),
|
|
...(raw.pendingFirstAgentMessageRename === true
|
|
? { pendingFirstAgentMessageRename: true }
|
|
: {}),
|
|
...(typeof raw.firstAgentMessageRenameError === 'string'
|
|
? { firstAgentMessageRenameError: raw.firstAgentMessageRenameError }
|
|
: raw.firstAgentMessageRenameError === null
|
|
? { firstAgentMessageRenameError: null }
|
|
: {}),
|
|
lastActivityAt:
|
|
typeof raw.lastActivityAt === 'number' && Number.isFinite(raw.lastActivityAt)
|
|
? raw.lastActivityAt
|
|
: 0,
|
|
...(isSmartTier(raw.smartTier) &&
|
|
typeof raw.smartAt === 'number' &&
|
|
Number.isFinite(raw.smartAt)
|
|
? { smartTier: raw.smartTier, smartAt: raw.smartAt }
|
|
: {}),
|
|
...(typeof raw.lastTerminalUseAt === 'number' && Number.isFinite(raw.lastTerminalUseAt)
|
|
? { lastTerminalUseAt: raw.lastTerminalUseAt }
|
|
: {}),
|
|
createdAt:
|
|
typeof raw.createdAt === 'number' && Number.isFinite(raw.createdAt) ? raw.createdAt : now,
|
|
updatedAt:
|
|
typeof raw.updatedAt === 'number' && Number.isFinite(raw.updatedAt) ? raw.updatedAt : now,
|
|
// Legacy read: unreleased #14112 builds wrote notes inline. Canonical home is
|
|
// PersistedState.folderWorkspaceDiffComments.
|
|
...(Array.isArray(raw.diffComments) ? { diffComments: raw.diffComments } : {}),
|
|
// Entries are validated where they are read (external-conversation-links.ts).
|
|
...(Array.isArray(raw.externalConversations)
|
|
? { externalConversations: raw.externalConversations }
|
|
: {})
|
|
})
|
|
}
|
|
return workspaces.sort(
|
|
(left, right) => right.sortOrder - left.sortOrder || left.name.localeCompare(right.name)
|
|
)
|
|
}
|