Skip to content

⭐️⭐️⭐️ Open-source, self-hosted alternative to Linear and Plane. Project management and issue tracking where teams and AI agents work side by side to plan and ship products.

3.6 KB
Raw Blame
import { t } from 'elysia';
import { MAX_CONCURRENT_RUNS } from '#modules/settings/service';
import { TEAM_CREATION } from './service';

export const workspaceParams = t.Object({ workspaceId: t.Numeric() });

export const workspaceManagerParams = t.Object({ workspaceId: t.Numeric(), userId: t.String() });

export const updateWorkspaceBody = t.Object({
  name: t.Optional(t.String({ minLength: 1, maxLength: 60 })),
  color: t.Optional(t.Nullable(t.String({ pattern: '^#[0-9a-fA-F]{6}$' }))),
  // t.UnionEnum defaults to its first value, which would fill in the setting for a
  // request that leaves it out; the update is partial.
  teamCreation: t.Optional(
    t.UnionEnum([...TEAM_CREATION], {
      default: undefined,
      description:
        'Who creates teams: the owner alone, the owner and admins, or anyone in its teams. ' +
        'Only the owner changes it.',
    }),
  ),
  maxConcurrentRuns: t.Optional(
    t.Integer({
      minimum: 0,
      maximum: MAX_CONCURRENT_RUNS,
      description:
        'Runs of its internal agents in flight at once; the rest wait in the queue. 0 sets ' +
        'no limit of its own. At most maxConcurrentRunsCap. Only the owner changes it.',
    }),
  ),
  sharingEnabled: t.Optional(
    t.Boolean({
      description:
        'Whether its projects may have public links. Off closes the links it has until it ' +
        'is on again. Refused while the instance has sharing off.',
    }),
  ),
  sharingTeamsOnly: t.Optional(
    t.Boolean({
      description: 'Whether only the teams in sharingTeamIds may share. Only the owner changes it.',
    }),
  ),
  sharingTeamIds: t.Optional(
    t.Array(t.Integer(), {
      description:
        'The teams of this workspace that may share while sharingTeamsOnly is on. Replaces ' +
        'the list. Only the owner changes it.',
    }),
  ),
});

export const addManagerBody = t.Object({ userId: t.String() });

export const searchQuery = t.Object({
  search: t.Optional(t.String({ description: 'Matches the name or the address.' })),
});

const workspaceRole = t.Union([t.Literal('owner'), t.Literal('admin')]);

export const WorkspaceListResponse = t.Array(
  t.Object({
    id: t.Number(),
    name: t.String(),
    role: t.Nullable(workspaceRole, {
      description: 'Your standing in the workspace; null when you are only in a team of it.',
    }),
    color: t.Nullable(t.String()),
    canCreateTeam: t.Boolean(),
  }),
);

export const WorkspaceResponse = t.Object({
  id: t.Number(),
  name: t.String(),
  role: workspaceRole,
  managerCount: t.Number(),
  color: t.Nullable(t.String()),
  teamCreation: t.UnionEnum([...TEAM_CREATION]),
  maxConcurrentRuns: t.Number(),
  maxConcurrentRunsCap: t.Number({
    description: 'The highest maxConcurrentRuns the instance allows it; 0 when it sets none.',
  }),
  sharingAvailable: t.Boolean({
    description: 'Whether the instance allows public links. Off, the settings below do not apply.',
  }),
  sharingEnabled: t.Boolean(),
  sharingTeamsOnly: t.Boolean(),
  sharingTeams: t.Array(t.Object({ id: t.Number(), name: t.String(), selected: t.Boolean() })),
  deletion: t.UnionEnum(['allowed', 'work'], {
    description:
      'Whether the owner may delete it: work while a team of it holds a project or an AI agent.',
  }),
});

const person = {
  userId: t.String(),
  name: t.String(),
  email: t.String(),
  image: t.Nullable(t.String()),
};

export const WorkspaceManagerListResponse = t.Array(t.Object({ ...person, role: workspaceRole }));

export const WorkspaceCandidateListResponse = t.Array(t.Object(person));

export const scimGroupParams = t.Object({ workspaceId: t.Numeric(), groupId: t.String() });