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.3 KB
Raw Blame
import type { Page } from '@stablyai/playwright-test'

type TypingDiagnosticWindow = Window & {
  __orcaTypingDiagnostic?: {
    start: () => string
    stop: () => string
    report: () => unknown
  }
}

/** Runs the shipped renderer probe beside the bench: it splits the renderer-side phases the PTY sidecar cannot see. */
export async function withInAppTypingDiagnostic<T>(
  page: Page,
  enabled: boolean,
  run: () => Promise<T>
): Promise<{ result: T; report: unknown }> {
  if (!enabled) {
    return { result: await run(), report: null }
  }
  const started = await page.evaluate(() => {
    const target: TypingDiagnosticWindow = window
    return target.__orcaTypingDiagnostic?.start() ?? null
  })
  if (started === null) {
    return { result: await run(), report: { available: false } }
  }
  try {
    const result = await run()
    const report = await page.evaluate(() => {
      const target: TypingDiagnosticWindow = window
      target.__orcaTypingDiagnostic?.stop()
      return target.__orcaTypingDiagnostic?.report() ?? null
    })
    return { result, report }
  } finally {
    await page
      .evaluate(() => {
        const target: TypingDiagnosticWindow = window
        target.__orcaTypingDiagnostic?.stop()
      })
      .catch(() => undefined)
  }
}