import type {
  AgentProfile,
  AuthUser,
  Automation,
  AutomationInvocation,
  AutomationInvocationPage,
  Environment,
  EnvironmentRevision,
  Skill,
  Snippet,
} from '../api.js';
import type { StaticDemoSession } from './types.js';

const createdAt = '2026-06-12T14:00:00.000Z';
const updatedAt = '2026-07-18T16:30:00.000Z';

export const demoCurrentUser: AuthUser = {
  id: 'demo-user-1',
  username: 'user1',
  displayName: 'user1',
  role: 'admin',
};

export const demoUsers: AuthUser[] = [
  demoCurrentUser,
  { id: 'demo-user-2', username: 'user2', displayName: 'user2', role: 'member' },
  { id: 'demo-user-3', username: 'user3', displayName: 'user3', role: 'viewer' },
];

export const demoAgentProfiles: AgentProfile[] = [
  {
    id: 'builtin:general',
    source: 'builtin',
    name: 'General',
    description: 'General-purpose software engineering agent.',
    instructions:
      'Work autonomously toward the requested outcome. Read enough context to understand the relevant ownership path and constraints, prefer the smallest correct change, preserve existing conventions, and verify work in proportion to its risk.',
    revision: 'builtin:general:v1',
    supportedInvocations: ['agent', 'subagent'],
    enabled: true,
  },
  {
    id: 'builtin:reviewer',
    source: 'builtin',
    name: 'Reviewer',
    description: 'Independent code review and verification.',
    instructions:
      'Establish the intended behavior, then inspect the relevant changes and surrounding code. Report actionable correctness, security, data-integrity, contract, and test findings with specific evidence.',
    revision: 'builtin:reviewer:v1',
    supportedInvocations: ['agent', 'subagent'],
    enabled: true,
  },
  {
    id: 'builtin:adversary',
    source: 'builtin',
    name: 'Adversary',
    description: 'Adversarial review that stress-tests assumptions and implementation choices.',
    instructions:
      'Try to construct realistic failure cases across edge conditions, partial failures, security boundaries, concurrency, data integrity, resource lifecycle, and external API contracts.',
    revision: 'builtin:adversary:v1',
    supportedInvocations: ['agent', 'subagent'],
    enabled: true,
  },
  {
    id: 'builtin:codebase-researcher',
    source: 'builtin',
    name: 'Codebase Researcher',
    description: 'Read-oriented codebase reconnaissance.',
    instructions:
      'Investigate the local codebase by behavior and data flow. Identify the source of truth, important callers and consumers, relevant tests, and boundaries where behavior changes or state crosses layers.',
    revision: 'builtin:codebase-researcher:v1',
    supportedInvocations: ['agent', 'subagent'],
    enabled: true,
  },
  {
    id: 'builtin:external-codebase-researcher',
    source: 'builtin',
    name: 'External Codebase Researcher',
    description: 'Research external codebases and documentation.',
    instructions:
      'Research external codebases and primary documentation. Prefer authoritative repository source, official documentation, release notes, and commit history over secondary summaries.',
    revision: 'builtin:external-codebase-researcher:v1',
    supportedInvocations: ['agent', 'subagent'],
    enabled: true,
  },
];

export const demoEnvironments: Environment[] = [
  {
    id: 'demo-environment-product',
    name: 'Deputies product workspace',
    currentRevisionId: 'demo-environment-product-revision-3',
    currentRevisionNumber: 3,
    repositories: [
      {
        id: 'demo-environment-product-repo-app',
        provider: 'github',
        owner: 'acme',
        repo: 'deputies',
        branch: 'main',
        primary: true,
        position: 0,
      },
      {
        id: 'demo-environment-product-repo-docs',
        provider: 'github',
        owner: 'acme',
        repo: 'developer-docs',
        branch: 'main',
        primary: false,
        position: 1,
      },
    ],
    canManage: false,
    createdAt,
    updatedAt,
  },
  {
    id: 'demo-environment-api',
    name: 'API and SDKs',
    currentRevisionId: 'demo-environment-api-revision-2',
    currentRevisionNumber: 2,
    repositories: [
      {
        id: 'demo-environment-api-repo',
        provider: 'github',
        owner: 'acme',
        repo: 'public-api',
        branch: 'main',
        primary: true,
        position: 0,
      },
      {
        id: 'demo-environment-sdk-repo',
        provider: 'github',
        owner: 'acme',
        repo: 'typescript-sdk',
        branch: 'main',
        primary: false,
        position: 1,
      },
    ],
    canManage: false,
    createdAt,
    updatedAt: '2026-07-16T11:20:00.000Z',
  },
];

const demoEnvironmentRevisions: Record<string, EnvironmentRevision[]> = {
  'demo-environment-product': [
    {
      id: 'demo-environment-product-revision-3',
      environmentId: 'demo-environment-product',
      revisionNumber: 3,
      repositories: demoEnvironments[0]!.repositories.map(({ id: _id, ...repository }) => repository),
      actorType: 'user',
      actorUserId: demoCurrentUser.id,
      createdAt: updatedAt,
    },
    {
      id: 'demo-environment-product-revision-2',
      environmentId: 'demo-environment-product',
      revisionNumber: 2,
      repositories: [
        { provider: 'github', owner: 'acme', repo: 'deputies', branch: 'main', primary: true, position: 0 },
      ],
      actorType: 'user',
      actorUserId: demoCurrentUser.id,
      createdAt: '2026-07-02T10:15:00.000Z',
    },
  ],
  'demo-environment-api': [
    {
      id: 'demo-environment-api-revision-2',
      environmentId: 'demo-environment-api',
      revisionNumber: 2,
      repositories: demoEnvironments[1]!.repositories.map(({ id: _id, ...repository }) => repository),
      actorType: 'user',
      createdAt: '2026-07-16T11:20:00.000Z',
    },
  ],
};

export function loadDemoEnvironmentRevisions(environmentId: string): Promise<EnvironmentRevision[]> {
  return Promise.resolve(demoEnvironmentRevisions[environmentId] ?? []);
}

export const demoAutomations: Automation[] = [
  {
    id: 'demo-automation-release-readiness',
    kind: 'scheduled',
    name: 'Release readiness report',
    prompt:
      'Review changes merged since the previous release. Summarize user-facing changes, migration risks, failing checks, and anything that should block the next release.',
    scheduleCron: '0 14 * * 1-5',
    profileId: 'builtin:general',
    scheduleTimezone: 'UTC',
    enabled: true,
    environmentId: 'demo-environment-product',
    environmentRevisionPolicy: 'follow_latest',
    context: { model: 'anthropic/claude-sonnet-4-5', reasoningLevel: 'high' },
    nextInvocationAt: '2026-07-21T14:00:00.000Z',
    canManage: false,
    createdAt,
    updatedAt,
  },
  {
    id: 'demo-automation-dependency-health',
    kind: 'scheduled',
    name: 'Weekly dependency health',
    prompt:
      'Audit dependencies for security advisories, breaking releases, and stale packages. Propose a prioritized update plan with verification steps.',
    scheduleCron: '0 9 * * 1',
    profileId: 'builtin:general',
    scheduleTimezone: 'UTC',
    enabled: true,
    environmentId: 'demo-environment-product',
    environmentRevisionPolicy: 'pinned',
    environmentRevisionId: 'demo-environment-product-revision-3',
    environmentRevisionNumber: 3,
    context: { model: 'openai-codex/gpt-5.3-codex', reasoningLevel: 'high' },
    nextInvocationAt: '2026-07-27T09:00:00.000Z',
    canManage: false,
    createdAt,
    updatedAt: '2026-07-17T09:00:00.000Z',
  },
  {
    id: 'demo-automation-docs-freshness',
    kind: 'scheduled',
    name: 'Documentation freshness check',
    prompt:
      'Compare recently changed product behavior with the developer documentation. Open a session with concrete documentation updates for any drift you find.',
    scheduleCron: '30 16 * * 5',
    profileId: 'builtin:general',
    scheduleTimezone: 'UTC',
    enabled: false,
    environmentId: 'demo-environment-product',
    environmentRevisionPolicy: 'follow_latest',
    context: { model: 'anthropic/claude-sonnet-4-5', reasoningLevel: 'medium' },
    canManage: false,
    createdAt,
    updatedAt: '2026-07-10T16:30:00.000Z',
  },
];

const demoAutomationInvocations: Record<string, AutomationInvocation[]> = {
  'demo-automation-release-readiness': [
    {
      id: 'demo-invocation-release-3',
      automationId: 'demo-automation-release-readiness',
      trigger: 'scheduled',
      status: 'created',
      createdAt: '2026-07-18T14:00:00.000Z',
      completedAt: '2026-07-18T14:08:00.000Z',
      scheduledAt: '2026-07-18T14:00:00.000Z',
      sessionStatus: 'completed',
      sessionTitle: 'Release readiness report — July 18',
      messageStatus: 'completed',
      metadata: {},
    },
    {
      id: 'demo-invocation-release-2',
      automationId: 'demo-automation-release-readiness',
      trigger: 'scheduled',
      status: 'created',
      createdAt: '2026-07-17T14:00:00.000Z',
      completedAt: '2026-07-17T14:06:00.000Z',
      scheduledAt: '2026-07-17T14:00:00.000Z',
      sessionStatus: 'completed',
      messageStatus: 'completed',
      metadata: {},
    },
    {
      id: 'demo-invocation-release-1',
      automationId: 'demo-automation-release-readiness',
      trigger: 'scheduled',
      status: 'skipped',
      reason: 'A previous invocation was still active.',
      createdAt: '2026-07-16T14:00:00.000Z',
      scheduledAt: '2026-07-16T14:00:00.000Z',
      metadata: {},
    },
  ],
  'demo-automation-dependency-health': [
    {
      id: 'demo-invocation-dependencies-1',
      automationId: 'demo-automation-dependency-health',
      trigger: 'scheduled',
      status: 'created',
      createdAt: '2026-07-13T09:00:00.000Z',
      completedAt: '2026-07-13T09:12:00.000Z',
      sessionStatus: 'completed',
      messageStatus: 'completed',
      metadata: {},
    },
  ],
  'demo-automation-docs-freshness': [],
};

demoAutomations[0]!.lastInvocation = demoAutomationInvocations['demo-automation-release-readiness']![0]!;
demoAutomations[1]!.lastInvocation = demoAutomationInvocations['demo-automation-dependency-health']![0]!;

export function loadDemoAutomationInvocations(input: { automationId: string }): Promise<AutomationInvocationPage> {
  return Promise.resolve({ invocations: demoAutomationInvocations[input.automationId] ?? [] });
}

export const demoSkills: Skill[] = [
  {
    id: 'demo-skill-review-change',
    name: 'review-change',
    description: 'Review a change for correctness, security, and maintainability.',
    body: `# Review a change

Inspect the implementation and its tests before forming a conclusion.

## Review priorities

1. Confirm the change matches the stated intent.
2. Look for correctness, security, and data-loss risks.
3. Check boundaries, failure paths, and concurrency behavior.
4. Report findings with file and line references.
5. Ignore style-only comments unless they obscure a defect.`,
    currentRevisionId: 'demo-skill-review-change-revision-4',
    currentRevisionNumber: 4,
    autoLoad: false,
    enabled: true,
    source: 'managed',
    provenance: { kind: 'managed' },
    canManage: false,
    createdAt,
    updatedAt,
  },
  {
    id: 'demo-skill-release-notes',
    name: 'release-notes',
    description: 'Draft concise, customer-facing release notes from merged changes.',
    body: `# Draft release notes

Group changes by customer outcome. Lead with benefits, call out breaking changes clearly, and omit internal implementation details unless users must act on them.`,
    currentRevisionId: 'demo-skill-release-notes-revision-2',
    currentRevisionNumber: 2,
    autoLoad: false,
    enabled: true,
    source: 'managed',
    provenance: { kind: 'managed' },
    canManage: false,
    createdAt,
    updatedAt: '2026-07-14T13:00:00.000Z',
  },
  {
    id: 'demo-skill-security-baseline',
    name: 'security-baseline',
    description: 'Apply the organization security checklist to every review.',
    body: `# Security baseline

Check authentication and authorization boundaries, secret handling, input validation, dependency risk, and auditability.`,
    currentRevisionId: 'demo-skill-security-baseline-revision-3',
    currentRevisionNumber: 3,
    autoLoad: true,
    enabled: true,
    source: 'managed',
    provenance: { kind: 'managed' },
    canManage: false,
    createdAt,
    updatedAt: '2026-07-15T08:45:00.000Z',
  },
];

export const demoSnippets: Snippet[] = [
  {
    id: 'demo-snippet-review-pr',
    createdByUserId: demoCurrentUser.id,
    name: 'review-pr',
    body: 'Review this pull request. Focus on correctness and regressions, then suggest the smallest safe fixes for high-confidence findings.',
    createdAt,
    updatedAt,
  },
  {
    id: 'demo-snippet-write-tests',
    createdByUserId: demoCurrentUser.id,
    name: 'write-tests',
    body: 'Add focused tests for this behavior. Cover the happy path, the most important boundary condition, and the failure mode that would be hardest to diagnose in production.',
    createdAt,
    updatedAt: '2026-07-16T15:10:00.000Z',
  },
  {
    id: 'demo-snippet-explain',
    createdByUserId: demoCurrentUser.id,
    name: 'explain',
    body: 'Explain how this subsystem works, including the request flow, ownership boundaries, persistence model, and the safest extension points.',
    createdAt,
    updatedAt: '2026-07-11T12:20:00.000Z',
  },
];

export const demoShowcaseSessions: StaticDemoSession[] = [
  {
    session: {
      id: 'demo-session-workspace-changes',
      status: 'idle',
      title: 'Prioritize starred sessions',
      spawnDepth: 0,
      directChildCount: 0,
      createdByUserId: demoCurrentUser.id,
      context: {
        model: 'openai-codex/gpt-5.5',
        branch: 'feature/starred-sessions',
        repository: { provider: 'github', owner: 'acme', repo: 'deputies' },
      },
      tags: ['frontend', 'sessions'],
      starred: true,
      createdAt: '2026-07-29T15:20:00.000Z',
      updatedAt: '2026-07-29T15:31:00.000Z',
      lastActivityAt: '2026-07-29T15:31:00.000Z',
    },
    messages: [
      {
        id: 'demo-message-workspace-changes',
        sessionId: 'demo-session-workspace-changes',
        sequence: 1,
        status: 'completed',
        steering: false,
        prompt:
          'Update apps/web/src/components/app-panels/session-sidebar.tsx so starred sessions are shown before the rest, while preserving the existing activity order within each group. Add focused coverage in apps/web/src/app.test.tsx.',
        createdAt: '2026-07-29T15:20:02.000Z',
        authorUserId: demoCurrentUser.id,
        authorName: 'user1',
      },
    ],
    events: [
      {
        id: 21001,
        sessionId: 'demo-session-workspace-changes',
        sequence: 1,
        type: 'message_started',
        payload: { batchSize: 1, sequences: [1] },
        createdAt: '2026-07-29T15:20:02.100Z',
        runId: 'demo-run-workspace-changes',
        messageId: 'demo-message-workspace-changes',
      },
      {
        id: 21002,
        sessionId: 'demo-session-workspace-changes',
        sequence: 2,
        type: 'tool_started',
        payload: {
          toolName: 'apply_patch',
          toolCallId: 'demo-tool-session-sidebar-patch',
          args: {
            files: ['apps/web/src/components/app-panels/session-sidebar.tsx', 'apps/web/src/app.test.tsx'],
          },
        },
        createdAt: '2026-07-29T15:25:00.000Z',
        runId: 'demo-run-workspace-changes',
        messageId: 'demo-message-workspace-changes',
      },
      {
        id: 21003,
        sessionId: 'demo-session-workspace-changes',
        sequence: 3,
        type: 'tool_finished',
        payload: {
          toolName: 'apply_patch',
          toolCallId: 'demo-tool-session-sidebar-patch',
          isError: false,
          result: 'Updated session ordering and added focused coverage.',
        },
        createdAt: '2026-07-29T15:25:02.000Z',
        runId: 'demo-run-workspace-changes',
        messageId: 'demo-message-workspace-changes',
      },
      {
        id: 21004,
        sessionId: 'demo-session-workspace-changes',
        sequence: 4,
        type: 'agent_response_final',
        payload: {
          text: 'Starred sessions now appear first without changing activity order inside either group. I added a focused sidebar test and verified the web test suite passes.',
        },
        createdAt: '2026-07-29T15:30:59.000Z',
        runId: 'demo-run-workspace-changes',
        messageId: 'demo-message-workspace-changes',
      },
      {
        id: 21005,
        sessionId: 'demo-session-workspace-changes',
        sequence: 5,
        type: 'message_completed',
        payload: { sequence: 1 },
        createdAt: '2026-07-29T15:31:00.000Z',
        runId: 'demo-run-workspace-changes',
        messageId: 'demo-message-workspace-changes',
      },
    ],
    artifacts: [],
    externalResources: [],
    callbacks: [],
    services: [],
    workspaceChanges: {
      changes: {
        source: 'live',
        sandboxRuntimeId: 'demo-runtime-workspace-changes',
        observedAt: '2026-07-29T15:31:00.000Z',
        repositories: [
          {
            id: 'deputies',
            owner: 'acme',
            name: 'deputies',
            isPrimary: true,
            branch: 'feature/starred-sessions',
            headOid: '5ec9f1317f6fbc3f8de0d44a7d0c745f62426d5a',
            status: 'ready',
            complete: true,
            truncated: false,
            files: [
              {
                id: 'session-sidebar',
                path: 'apps/web/src/components/app-panels/session-sidebar.tsx',
                worktreeChange: 'modified',
              },
              {
                id: 'app-test',
                path: 'apps/web/src/app.test.tsx',
                worktreeChange: 'modified',
              },
            ],
          },
        ],
      },
      patches: [
        {
          repositoryId: 'deputies',
          fileId: 'session-sidebar',
          path: 'apps/web/src/components/app-panels/session-sidebar.tsx',
          layer: 'worktree',
          patch:
            'diff --git a/apps/web/src/components/app-panels/session-sidebar.tsx b/apps/web/src/components/app-panels/session-sidebar.tsx\nindex 8f4da31..f113aed 100644\n--- a/apps/web/src/components/app-panels/session-sidebar.tsx\n+++ b/apps/web/src/components/app-panels/session-sidebar.tsx\n@@ -386,7 +386,11 @@ function SessionList(props: SessionListProps) {\n-  const visibleSessions = props.sessions.filter(matchesFilters);\n+  const visibleSessions = props.sessions\n+    .filter(matchesFilters)\n+    .sort((left, right) =>\n+      left.starred === right.starred ? 0 : left.starred ? -1 : 1,\n+    );\n \n   return visibleSessions.map((session) => (\n     <SessionRow key={session.id} session={session} />\n',
          truncated: false,
          binary: false,
          observedAt: '2026-07-29T15:31:00.000Z',
        },
        {
          repositoryId: 'deputies',
          fileId: 'app-test',
          path: 'apps/web/src/app.test.tsx',
          layer: 'worktree',
          patch:
            "diff --git a/apps/web/src/app.test.tsx b/apps/web/src/app.test.tsx\nindex 28c73e1..26d480a 100644\n--- a/apps/web/src/app.test.tsx\n+++ b/apps/web/src/app.test.tsx\n@@ -1632,6 +1632,14 @@ it('renders sessions in the sidebar', async () => {\n   expect(screen.getByRole('button', { name: /Recent session/ })).toBeInTheDocument();\n });\n \n+it('shows starred sessions before more recent unstarred sessions', async () => {\n+  mockApi({ sessions: [recentSession, { ...olderSession, starred: true }] });\n+  render(<App />);\n+\n+  const rows = await screen.findAllByRole('button', { name: /session/i });\n+  expect(rows[0]).toHaveAccessibleName(/Older session/);\n+});\n+\n it('keeps new-session action available from the sidebar on mobile', async () => {\n   mockApi();\n   render(<App />);\n",
          truncated: false,
          binary: false,
          observedAt: '2026-07-29T15:31:00.000Z',
        },
      ],
    },
  },
  {
    session: {
      id: 'd7d24550-4804-45d5-9df8-da26e079e796',
      status: 'idle',
      title: 'Artifact Support',
      spawnDepth: 0,
      directChildCount: 0,
      createdByUserId: 'demo-user-2',
      context: {
        model: 'openai-codex/gpt-5.5',
        branch: 'main',
        repository: { provider: 'github', owner: 'acme', repo: 'deputies' },
      },
      tags: ['artifacts', 'media'],
      starred: true,
      createdAt: '2026-05-19T14:49:24.212Z',
      updatedAt: '2026-05-19T14:53:15.034Z',
      lastActivityAt: '2026-05-19T14:53:15.034Z',
    },
    messages: [
      {
        id: '83b34b34-0b39-4ad3-9740-c2796256953e',
        sessionId: 'd7d24550-4804-45d5-9df8-da26e079e796',
        sequence: 1,
        status: 'completed',
        steering: false,
        prompt: 'please generate a fun image and store it as an artifact',
        createdAt: '2026-05-19T14:49:24.276Z',
        authorUserId: demoCurrentUser.id,
        authorName: 'user1',
      },
      {
        id: 'f04cf73b-70de-42a7-94b3-41a37542f32c',
        sessionId: 'd7d24550-4804-45d5-9df8-da26e079e796',
        sequence: 2,
        status: 'completed',
        steering: false,
        prompt: 'Now use remotion to generate a short video and attach it as an artifact as well.',
        createdAt: '2026-05-19T14:51:34.017Z',
        authorUserId: demoCurrentUser.id,
        authorName: 'user1',
      },
    ],
    events: [
      {
        id: 9435,
        sessionId: 'd7d24550-4804-45d5-9df8-da26e079e796',
        sequence: 1,
        type: 'message_started',
        payload: { batchSize: 1, sequences: [1] },
        createdAt: '2026-05-19T14:49:24.300Z',
        runId: 'demo-run-artifact-image',
        messageId: '83b34b34-0b39-4ad3-9740-c2796256953e',
      },
      {
        id: 9436,
        sessionId: 'd7d24550-4804-45d5-9df8-da26e079e796',
        sequence: 2,
        type: 'sandbox_starting',
        payload: { provider: 'daytona' },
        createdAt: '2026-05-19T14:49:24.500Z',
        runId: 'demo-run-artifact-image',
        messageId: '83b34b34-0b39-4ad3-9740-c2796256953e',
      },
      {
        id: 9437,
        sessionId: 'd7d24550-4804-45d5-9df8-da26e079e796',
        sequence: 3,
        type: 'sandbox_ready',
        payload: { provider: 'daytona', created: true },
        createdAt: '2026-05-19T14:49:29.100Z',
        runId: 'demo-run-artifact-image',
        messageId: '83b34b34-0b39-4ad3-9740-c2796256953e',
      },
      {
        id: 9438,
        sessionId: 'd7d24550-4804-45d5-9df8-da26e079e796',
        sequence: 4,
        type: 'tool_started',
        payload: {
          toolName: 'painter',
          toolCallId: 'demo-tool-painter',
          args: { prompt: 'A cosmic cat riding a disco rocket through a colorful star field.' },
        },
        createdAt: '2026-05-19T14:49:35.000Z',
        runId: 'demo-run-artifact-image',
        messageId: '83b34b34-0b39-4ad3-9740-c2796256953e',
      },
      {
        id: 9439,
        sessionId: 'd7d24550-4804-45d5-9df8-da26e079e796',
        sequence: 5,
        type: 'tool_finished',
        payload: {
          toolName: 'painter',
          toolCallId: 'demo-tool-painter',
          isError: false,
          result: 'Generated cosmic-cat-disco-rocket.svg.',
        },
        createdAt: '2026-05-19T14:50:38.900Z',
        runId: 'demo-run-artifact-image',
        messageId: '83b34b34-0b39-4ad3-9740-c2796256953e',
      },
      {
        id: 9440,
        sessionId: 'd7d24550-4804-45d5-9df8-da26e079e796',
        sequence: 6,
        type: 'artifact_created',
        payload: { artifact: { id: 'e599a9f8-68f0-4eac-821b-75806aac5424', type: 'image' } },
        createdAt: '2026-05-19T14:50:39.681Z',
        runId: 'demo-run-artifact-image',
        messageId: '83b34b34-0b39-4ad3-9740-c2796256953e',
      },
      {
        id: 9441,
        sessionId: 'd7d24550-4804-45d5-9df8-da26e079e796',
        sequence: 7,
        type: 'run_completed',
        payload: { model: 'openai-codex/gpt-5.5', usage: { totalTokens: 4280 } },
        createdAt: '2026-05-19T14:50:41.700Z',
        runId: 'demo-run-artifact-image',
        messageId: '83b34b34-0b39-4ad3-9740-c2796256953e',
      },
      {
        id: 9442,
        sessionId: 'd7d24550-4804-45d5-9df8-da26e079e796',
        sequence: 8,
        type: 'agent_response_final',
        payload: { text: 'Done — I generated a fun image and attached it as an artifact.' },
        createdAt: '2026-05-19T14:50:41.849Z',
        runId: 'demo-run-artifact-image',
        messageId: '83b34b34-0b39-4ad3-9740-c2796256953e',
      },
      {
        id: 9443,
        sessionId: 'd7d24550-4804-45d5-9df8-da26e079e796',
        sequence: 9,
        type: 'message_completed',
        payload: { sequence: 1 },
        createdAt: '2026-05-19T14:50:41.900Z',
        runId: 'demo-run-artifact-image',
        messageId: '83b34b34-0b39-4ad3-9740-c2796256953e',
      },
      {
        id: 9617,
        sessionId: 'd7d24550-4804-45d5-9df8-da26e079e796',
        sequence: 10,
        type: 'message_started',
        payload: { batchSize: 1, sequences: [2] },
        createdAt: '2026-05-19T14:51:34.100Z',
        runId: 'demo-run-artifact-video',
        messageId: 'f04cf73b-70de-42a7-94b3-41a37542f32c',
      },
      {
        id: 9618,
        sessionId: 'd7d24550-4804-45d5-9df8-da26e079e796',
        sequence: 11,
        type: 'sandbox_ready',
        payload: { provider: 'daytona', created: false },
        createdAt: '2026-05-19T14:51:34.400Z',
        runId: 'demo-run-artifact-video',
        messageId: 'f04cf73b-70de-42a7-94b3-41a37542f32c',
      },
      {
        id: 9619,
        sessionId: 'd7d24550-4804-45d5-9df8-da26e079e796',
        sequence: 12,
        type: 'tool_started',
        payload: {
          toolName: 'shell',
          toolCallId: 'demo-tool-remotion',
          args: { command: 'pnpm exec remotion render src/index.ts CosmicCat out/cosmic-cat.mp4' },
        },
        createdAt: '2026-05-19T14:51:42.000Z',
        runId: 'demo-run-artifact-video',
        messageId: 'f04cf73b-70de-42a7-94b3-41a37542f32c',
      },
      {
        id: 9620,
        sessionId: 'd7d24550-4804-45d5-9df8-da26e079e796',
        sequence: 13,
        type: 'tool_finished',
        payload: {
          toolName: 'shell',
          toolCallId: 'demo-tool-remotion',
          isError: false,
          result: 'Rendered 180 frames to out/cosmic-cat.mp4.',
        },
        createdAt: '2026-05-19T14:53:11.900Z',
        runId: 'demo-run-artifact-video',
        messageId: 'f04cf73b-70de-42a7-94b3-41a37542f32c',
      },
      {
        id: 9621,
        sessionId: 'd7d24550-4804-45d5-9df8-da26e079e796',
        sequence: 14,
        type: 'artifact_created',
        payload: { artifact: { id: 'a7d3c11b-3e20-4715-a2ea-7104db99fb65', type: 'video' } },
        createdAt: '2026-05-19T14:53:12.582Z',
        runId: 'demo-run-artifact-video',
        messageId: 'f04cf73b-70de-42a7-94b3-41a37542f32c',
      },
      {
        id: 9622,
        sessionId: 'd7d24550-4804-45d5-9df8-da26e079e796',
        sequence: 15,
        type: 'run_completed',
        payload: { model: 'openai-codex/gpt-5.5', usage: { totalTokens: 6912 } },
        createdAt: '2026-05-19T14:53:14.900Z',
        runId: 'demo-run-artifact-video',
        messageId: 'f04cf73b-70de-42a7-94b3-41a37542f32c',
      },
      {
        id: 9623,
        sessionId: 'd7d24550-4804-45d5-9df8-da26e079e796',
        sequence: 16,
        type: 'agent_response_final',
        payload: { text: 'Done — I generated a short Remotion MP4 and attached it as an artifact as well.' },
        createdAt: '2026-05-19T14:53:15.030Z',
        runId: 'demo-run-artifact-video',
        messageId: 'f04cf73b-70de-42a7-94b3-41a37542f32c',
      },
      {
        id: 9624,
        sessionId: 'd7d24550-4804-45d5-9df8-da26e079e796',
        sequence: 17,
        type: 'message_completed',
        payload: { sequence: 2 },
        createdAt: '2026-05-19T14:53:15.100Z',
        runId: 'demo-run-artifact-video',
        messageId: 'f04cf73b-70de-42a7-94b3-41a37542f32c',
      },
    ],
    artifacts: [
      {
        id: 'e599a9f8-68f0-4eac-821b-75806aac5424',
        sessionId: 'd7d24550-4804-45d5-9df8-da26e079e796',
        type: 'image',
        payload: {
          storage: 'internal',
          fileName: 'cosmic-cat-disco-rocket.svg',
          sizeBytes: 4499,
          contentType: 'image/svg+xml',
          staticDemo: {
            contentType: 'image/svg+xml',
            fileName: 'cosmic-cat-disco-rocket.svg',
            url: '/static-demo/demo/artifacts/e599a9f8-68f0-4eac-821b-75806aac5424/cosmic-cat-disco-rocket.svg',
          },
        },
        createdAt: '2026-05-19T14:50:39.681Z',
        title: 'Cosmic Cat Disco Rocket',
        url: '/static-demo/demo/artifacts/e599a9f8-68f0-4eac-821b-75806aac5424/cosmic-cat-disco-rocket.svg',
        runId: 'demo-run-artifact-image',
        messageId: '83b34b34-0b39-4ad3-9740-c2796256953e',
      },
      {
        id: 'a7d3c11b-3e20-4715-a2ea-7104db99fb65',
        sessionId: 'd7d24550-4804-45d5-9df8-da26e079e796',
        type: 'video',
        payload: {
          storage: 'internal',
          fileName: 'cosmic-cat-disco-rocket-remotion.mp4',
          sizeBytes: 1366872,
          contentType: 'video/mp4',
          staticDemo: {
            contentType: 'video/mp4',
            fileName: 'cosmic-cat-disco-rocket-remotion.mp4',
            url: '/static-demo/demo/artifacts/a7d3c11b-3e20-4715-a2ea-7104db99fb65/cosmic-cat-disco-rocket-remotion.mp4',
          },
        },
        createdAt: '2026-05-19T14:53:12.582Z',
        title: 'Cosmic Cat Disco Rocket Remotion Video',
        url: '/static-demo/demo/artifacts/a7d3c11b-3e20-4715-a2ea-7104db99fb65/cosmic-cat-disco-rocket-remotion.mp4',
        runId: 'demo-run-artifact-video',
        messageId: 'f04cf73b-70de-42a7-94b3-41a37542f32c',
      },
    ],
    externalResources: [],
    callbacks: [],
    services: [],
  },
  {
    session: {
      id: 'demo-session-release-parent',
      status: 'idle',
      title: 'Prepare the next release',
      spawnDepth: 0,
      directChildCount: 1,
      createdByUserId: demoCurrentUser.id,
      context: {
        model: 'anthropic/claude-sonnet-4-5',
        branch: 'main',
        repository: { provider: 'github', owner: 'acme', repo: 'deputies' },
      },
      tags: ['release', 'review'],
      starred: true,
      createdAt: '2026-07-18T13:30:00.000Z',
      updatedAt: '2026-07-18T14:12:00.000Z',
      lastActivityAt: '2026-07-18T14:12:00.000Z',
    },
    messages: [
      {
        id: 'demo-message-release-parent',
        sessionId: 'demo-session-release-parent',
        sequence: 1,
        status: 'completed',
        steering: false,
        prompt:
          'Review the changes merged since the last release and prepare a concise readiness report. Delegate the authentication changes for a focused review.',
        createdAt: '2026-07-18T13:30:05.000Z',
        authorUserId: demoCurrentUser.id,
        authorName: 'user1',
        context: {
          skills: ['review-change', 'release-notes'],
          skillRefs: [
            {
              id: 'demo-skill-review-change',
              name: 'review-change',
              revisionId: 'demo-skill-review-change-revision-4',
            },
            {
              id: 'demo-skill-release-notes',
              name: 'release-notes',
              revisionId: 'demo-skill-release-notes-revision-2',
            },
          ],
        },
      },
    ],
    events: [
      {
        id: 20001,
        sessionId: 'demo-session-release-parent',
        sequence: 1,
        type: 'message_started',
        payload: { batchSize: 1, sequences: [1] },
        createdAt: '2026-07-18T13:30:05.100Z',
        runId: 'demo-run-release-parent',
        messageId: 'demo-message-release-parent',
      },
      {
        id: 20002,
        sessionId: 'demo-session-release-parent',
        sequence: 2,
        type: 'sandbox_starting',
        payload: { provider: 'daytona' },
        createdAt: '2026-07-18T13:30:05.300Z',
        runId: 'demo-run-release-parent',
        messageId: 'demo-message-release-parent',
      },
      {
        id: 20003,
        sessionId: 'demo-session-release-parent',
        sequence: 3,
        type: 'sandbox_ready',
        payload: { provider: 'daytona', created: true },
        createdAt: '2026-07-18T13:30:10.000Z',
        runId: 'demo-run-release-parent',
        messageId: 'demo-message-release-parent',
      },
      {
        id: 20004,
        sessionId: 'demo-session-release-parent',
        sequence: 4,
        type: 'skills_loaded',
        payload: {
          skills: [
            { name: 'review-change', ownerGroupName: 'Platform engineering' },
            { name: 'release-notes', source: 'personal' },
          ],
          shadowed: [],
          diagnostics: [],
        },
        createdAt: '2026-07-18T13:30:10.200Z',
        runId: 'demo-run-release-parent',
        messageId: 'demo-message-release-parent',
      },
      {
        id: 20005,
        sessionId: 'demo-session-release-parent',
        sequence: 5,
        type: 'skill_invoked',
        payload: { name: 'release-notes', trigger: 'user', source: 'personal' },
        createdAt: '2026-07-18T13:30:11.000Z',
        runId: 'demo-run-release-parent',
        messageId: 'demo-message-release-parent',
      },
      {
        id: 20006,
        sessionId: 'demo-session-release-parent',
        sequence: 6,
        type: 'tool_started',
        payload: {
          toolName: 'shell',
          toolCallId: 'demo-tool-release-log',
          args: { command: 'git log --oneline v1.8.0..HEAD' },
        },
        createdAt: '2026-07-18T13:31:00.000Z',
        runId: 'demo-run-release-parent',
        messageId: 'demo-message-release-parent',
      },
      {
        id: 20007,
        sessionId: 'demo-session-release-parent',
        sequence: 7,
        type: 'tool_finished',
        payload: {
          toolName: 'shell',
          toolCallId: 'demo-tool-release-log',
          isError: false,
          result: '18 commits: 6 features, 4 fixes, 8 maintenance changes.',
        },
        createdAt: '2026-07-18T13:31:01.000Z',
        runId: 'demo-run-release-parent',
        messageId: 'demo-message-release-parent',
      },
      {
        id: 20008,
        sessionId: 'demo-session-release-parent',
        sequence: 8,
        type: 'tool_started',
        payload: {
          toolName: 'task',
          toolCallId: 'demo-tool-auth-review',
          prompt: 'Perform a focused security review of the authentication changes.',
        },
        createdAt: '2026-07-18T13:34:00.000Z',
        runId: 'demo-run-release-parent',
        messageId: 'demo-message-release-parent',
      },
      {
        id: 20009,
        sessionId: 'demo-session-release-parent',
        sequence: 9,
        type: 'tool_finished',
        payload: {
          toolName: 'task',
          toolCallId: 'demo-tool-auth-review',
          isError: false,
          result: 'Child session completed with no release blockers.',
        },
        createdAt: '2026-07-18T13:58:01.000Z',
        runId: 'demo-run-release-parent',
        messageId: 'demo-message-release-parent',
      },
      {
        id: 20010,
        sessionId: 'demo-session-release-parent',
        sequence: 10,
        type: 'run_completed',
        payload: { model: 'anthropic/claude-sonnet-4-5', usage: { totalTokens: 18340 } },
        createdAt: '2026-07-18T14:11:59.500Z',
        runId: 'demo-run-release-parent',
        messageId: 'demo-message-release-parent',
      },
      {
        id: 20011,
        sessionId: 'demo-session-release-parent',
        sequence: 11,
        type: 'agent_response_final',
        payload: {
          text: 'Release readiness looks good overall. I grouped the customer-facing changes, identified one authentication area for deeper verification, and delegated that review to a child session.',
        },
        createdAt: '2026-07-18T14:12:00.000Z',
        runId: 'demo-run-release-parent',
        messageId: 'demo-message-release-parent',
      },
      {
        id: 20012,
        sessionId: 'demo-session-release-parent',
        sequence: 12,
        type: 'message_completed',
        payload: { sequence: 1 },
        createdAt: '2026-07-18T14:12:00.100Z',
        runId: 'demo-run-release-parent',
        messageId: 'demo-message-release-parent',
      },
    ],
    artifacts: [],
    externalResources: [],
    callbacks: [],
    services: [],
  },
  {
    session: {
      id: 'demo-session-release-child',
      status: 'idle',
      title: 'Verify authentication changes',
      parentSessionId: 'demo-session-release-parent',
      spawnDepth: 1,
      directChildCount: 0,
      createdByUserId: demoCurrentUser.id,
      context: {
        model: 'openai-codex/gpt-5.3-codex',
        branch: 'main',
        repository: { provider: 'github', owner: 'acme', repo: 'deputies' },
      },
      tags: ['review', 'security', 'sub-session'],
      createdAt: '2026-07-18T13:34:00.000Z',
      updatedAt: '2026-07-18T13:58:00.000Z',
      lastActivityAt: '2026-07-18T13:58:00.000Z',
    },
    messages: [
      {
        id: 'demo-message-release-child',
        sessionId: 'demo-session-release-child',
        sequence: 1,
        status: 'completed',
        steering: false,
        prompt:
          'Perform a focused security review of the authentication changes. Check authorization boundaries, session handling, and failure paths.',
        createdAt: '2026-07-18T13:34:05.000Z',
        authorUserId: demoCurrentUser.id,
        authorName: 'Prepare the next release',
        source: 'sub_session',
        context: {
          skills: ['security-baseline'],
          skillRefs: [
            {
              id: 'demo-skill-security-baseline',
              name: 'security-baseline',
              revisionId: 'demo-skill-security-baseline-revision-3',
            },
          ],
        },
      },
    ],
    events: [
      {
        id: 20101,
        sessionId: 'demo-session-release-child',
        sequence: 1,
        type: 'message_started',
        payload: { batchSize: 1, sequences: [1] },
        createdAt: '2026-07-18T13:34:05.100Z',
        runId: 'demo-run-release-child',
        messageId: 'demo-message-release-child',
      },
      {
        id: 20102,
        sessionId: 'demo-session-release-child',
        sequence: 2,
        type: 'sandbox_ready',
        payload: { provider: 'daytona', created: false },
        createdAt: '2026-07-18T13:34:05.500Z',
        runId: 'demo-run-release-child',
        messageId: 'demo-message-release-child',
      },
      {
        id: 20103,
        sessionId: 'demo-session-release-child',
        sequence: 3,
        type: 'skills_loaded',
        payload: {
          skills: [{ name: 'security-baseline', ownerGroupName: 'Security' }],
          shadowed: [],
          diagnostics: [],
        },
        createdAt: '2026-07-18T13:34:05.700Z',
        runId: 'demo-run-release-child',
        messageId: 'demo-message-release-child',
      },
      {
        id: 20104,
        sessionId: 'demo-session-release-child',
        sequence: 4,
        type: 'skill_invoked',
        payload: { name: 'security-baseline', trigger: 'user', ownerGroupName: 'Security' },
        createdAt: '2026-07-18T13:34:06.000Z',
        runId: 'demo-run-release-child',
        messageId: 'demo-message-release-child',
      },
      {
        id: 20105,
        sessionId: 'demo-session-release-child',
        sequence: 5,
        type: 'tool_started',
        payload: {
          toolName: 'shell',
          toolCallId: 'demo-tool-auth-tests',
          args: { command: 'pnpm test --filter authentication' },
        },
        createdAt: '2026-07-18T13:47:00.000Z',
        runId: 'demo-run-release-child',
        messageId: 'demo-message-release-child',
      },
      {
        id: 20106,
        sessionId: 'demo-session-release-child',
        sequence: 6,
        type: 'tool_finished',
        payload: {
          toolName: 'shell',
          toolCallId: 'demo-tool-auth-tests',
          isError: false,
          result: '12 authentication tests passed, including expired credentials and concurrent refresh attempts.',
        },
        createdAt: '2026-07-18T13:47:18.000Z',
        runId: 'demo-run-release-child',
        messageId: 'demo-message-release-child',
      },
      {
        id: 20107,
        sessionId: 'demo-session-release-child',
        sequence: 7,
        type: 'run_completed',
        payload: { model: 'openai-codex/gpt-5.3-codex', usage: { totalTokens: 11240 } },
        createdAt: '2026-07-18T13:57:59.500Z',
        runId: 'demo-run-release-child',
        messageId: 'demo-message-release-child',
      },
      {
        id: 20108,
        sessionId: 'demo-session-release-child',
        sequence: 8,
        type: 'agent_response_final',
        payload: {
          text: 'The authentication changes preserve authorization boundaries and rotate sessions correctly. I added focused coverage for expired credentials and concurrent refresh attempts; no release blocker remains.',
        },
        createdAt: '2026-07-18T13:58:00.000Z',
        runId: 'demo-run-release-child',
        messageId: 'demo-message-release-child',
      },
      {
        id: 20109,
        sessionId: 'demo-session-release-child',
        sequence: 9,
        type: 'message_completed',
        payload: { sequence: 1 },
        createdAt: '2026-07-18T13:58:00.100Z',
        runId: 'demo-run-release-child',
        messageId: 'demo-message-release-child',
      },
    ],
    artifacts: [],
    externalResources: [],
    callbacks: [],
    services: [],
  },
];
