Skip to content

armgit / orca

Public Imported from GitHub
0

Orca is the place for working with a fleet of agents (e.g. Grok Bot, Claude Code). Run any coding agent with your own subscription. Available on desktop, mobile and remote runtime.

1.4 KB
Raw Blame
// Main records window-owned emulator tabs under the window’s IDs; the emulator itself remains in the window.

import { applied, refuse, type Applied } from './workspace-layout-command-steps'
import type { CommandOf, LayoutContext } from './workspace-layout-command-types'
import { drawnTabOpen, withSendersGroup } from './workspace-layout-content-commands'
import type { WorkspaceLayoutModel } from './workspace-layout-model'
import { placeContentTab } from './workspace-layout-tab-commands'

export function openSimulatorTab(
  model: WorkspaceLayoutModel,
  command: CommandOf<'openSimulatorTab'>,
  context: LayoutContext
): Applied {
  const key = command.workspace
  // Only a layout-owner window sends this command, so a taken id is always refused.
  const drawn = drawnTabOpen(model, key, command.tabId, (tab) => tab.kind === 'simulator', true)
  if (drawn) {
    return drawn
  }
  const workspace = model.workspaces[key]
  if (
    command.groupId &&
    workspace?.groups.length &&
    !workspace.groups.some((entry) => entry.id === command.groupId)
  ) {
    return refuse('group_not_found')
  }
  const tab = {
    id: command.tabId,
    entityId: command.tabId,
    kind: 'simulator' as const,
    createdAt: command.createdAt ?? context.now(),
    customTitle: null,
    color: null
  }
  const target = withSendersGroup(model, key, command.groupId)
  return applied(placeContentTab(target, key, tab, command, context).model, { tabId: tab.id })
}