@prismshadow/penguin-server · packages/server/src/runtime/organization/service.ts:2878

OrgService

interface

What the organization routes need of the runtime — declared where they consume it, so the route group names one node instead of reaching into a bag. The Agent routes read the two employment views (the list's marks, the delete guard).

API

@Interface()
export abstract class OrgService {
  abstract employments(projectId: string): Promise<Record<string, Employment[]>>;
  abstract employmentCensus(projectId: string): Promise<EmploymentCensus>;
  abstract employersOf(projectId: string, agentId: string): Promise<Employment[]>;
  abstract list(projectId: string): Promise<OrganizationSummary[]>;
  abstract create(
      projectId: string,
      req: OrganizationCreateRequest,
      userId: string,
      /** Who creates it, for the CEO's plugins' server modules; a member who is not the administrator when absent. */
      actor?: ModuleActor,
    ): Promise<OrganizationDetail>;
  abstract detail(projectId: string, orgId: string, userId: string): Promise<OrganizationDetail>;
  abstract delete(projectId: string, orgId: string): Promise<void>;
  abstract patch(
      projectId: string,
      orgId: string,
      req: OrganizationPatchRequest,
      userId: string,
    ): Promise<OrganizationSettings>;
  abstract leave(projectId: string, orgId: string, agentId: string): Promise<void>;
  abstract suggestId(
      projectId: string,
      req: SemanticIdSuggestRequest,
    ): Promise<SemanticIdSuggestResponse>;
  abstract chart(projectId: string, orgId: string): Promise<OrgChartResponse>;
  abstract hire(
      projectId: string,
      orgId: string,
      req: OrgHireRequest,
      /** Who hires, for a new Agent's plugins' server modules; the system when absent. */
      actor?: ModuleActor | null,
    ): Promise<OrgEmployeeItem>;
  abstract employeeAvatar(
      projectId: string,
      orgId: string,
      agentId: string,
    ): Promise<{
      bytes: Buffer;
      mime: string;
      rev: string;
    }>;
  abstract setEmployeeAvatar(
      projectId: string,
      orgId: string,
      agentId: string,
      avatar: string | null,
    ): Promise<OrgEmployeeItem>;
  abstract patchEmployee(
      projectId: string,
      orgId: string,
      agentId: string,
      req: OrgEmployeePatchRequest,
    ): Promise<OrgEmployeeItem>;
  abstract desk(
      projectId: string,
      orgId: string,
      agentId: string,
      opts: {
        renew?: boolean;
      },
    ): Promise<OrgDeskResponse>;
  abstract sessions(projectId: string, orgId: string): Promise<OrgSessionsResponse>;
  abstract calendar(projectId: string, orgId: string): Promise<OrgCalendarResponse>;
  abstract upsertCalendar(
      projectId: string,
      orgId: string,
      agentId: string,
      name: string,
      fields: Omit<OrgCalendarUpsertRequest, "agentId" | "name">,
      opts: {
        create: boolean;
      },
    ): Promise<OrgCalendarWriteResponse>;
  abstract deleteCalendar(
      projectId: string,
      orgId: string,
      agentId: string,
      name: string,
    ): Promise<void>;
  abstract tickets(projectId: string, orgId: string): Promise<OrgTicketsResponse>;
  abstract ticket(projectId: string, orgId: string, ticketId: string): Promise<OrgTicketDetail>;
  abstract createTicket(
      projectId: string,
      orgId: string,
      req: OrgTicketCreateRequest,
      actor: Actor,
    ): Promise<OrgTicketDetail>;
  abstract updateTicket(
      projectId: string,
      orgId: string,
      ticketId: string,
      req: OrgTicketUpdateRequest,
      actor: Actor,
    ): Promise<OrgTicketDetail>;
  abstract moveTicket(
      projectId: string,
      orgId: string,
      ticketId: string,
      status: OrgTicketStatus,
      reason: string | undefined,
      actor: Actor,
    ): Promise<OrgTicketDetail>;
  abstract blockTicket(
      projectId: string,
      orgId: string,
      ticketId: string,
      reason: string,
      by: string | undefined,
      actor: Actor,
    ): Promise<OrgTicketDetail>;
  abstract unblockTicket(
      projectId: string,
      orgId: string,
      ticketId: string,
      actor: Actor,
    ): Promise<OrgTicketDetail>;
  abstract progressTicket(
      projectId: string,
      orgId: string,
      ticketId: string,
      text: string,
      actor: Actor,
    ): Promise<OrgTicketDetail>;
  abstract startTicket(
      projectId: string,
      orgId: string,
      ticketId: string,
      req: {
        agentId?: string;
        message?: string;
        workspace?: string;
      },
      actor: Actor,
    ): Promise<{
      sessionId: string;
    }>;
  abstract attachTicket(
      projectId: string,
      orgId: string,
      ticketId: string,
      sessionId: string,
      actor: Actor,
    ): Promise<OrgTicketDetail>;
  abstract channels(projectId: string, orgId: string, actor: Actor): Promise<OrgChannelsResponse>;
  abstract channel(
      projectId: string,
      orgId: string,
      channelId: string,
      actor: Actor,
    ): Promise<OrgChannelDetail>;
  abstract createChannel(
      projectId: string,
      orgId: string,
      req: OrgChannelCreateRequest,
      actor: Actor,
    ): Promise<OrgChannelItem>;
  abstract patchChannel(
      projectId: string,
      orgId: string,
      channelId: string,
      req: OrgChannelPatchRequest,
      actor: Actor,
    ): Promise<OrgChannelItem>;
  abstract addChannelMember(
      projectId: string,
      orgId: string,
      channelId: string,
      rawPrincipal: string,
      actor: Actor,
    ): Promise<OrgChannelDetail>;
  abstract removeChannelMember(
      projectId: string,
      orgId: string,
      channelId: string,
      rawPrincipal: string,
      actor: Actor,
    ): Promise<void>;
  abstract channelMessages(
      projectId: string,
      orgId: string,
      actor: Actor,
      channelId: string,
      opts: {
        date?: string;
      },
    ): Promise<OrgChannelMessagesResponse>;
  abstract sendChannelMessage(
      projectId: string,
      orgId: string,
      userId: string,
      channelId: string,
      req: OrgChannelMessageSendRequest,
    ): Promise<OrgChannelMessage>;
  abstract markRead(
      projectId: string,
      orgId: string,
      userId: string,
      channelId: string,
      upTo: string,
    ): Promise<void>;
  abstract finance(projectId: string, orgId: string, period?: string): Promise<OrgFinanceResponse>;
  abstract handbook(projectId: string, orgId: string): Promise<string>;
  abstract writeHandbook(projectId: string, orgId: string, content: string): Promise<void>;
  abstract handbookFiles(projectId: string, orgId: string): Promise<OrgHandbookFilesResponse>;
  abstract handbookFile(
      projectId: string,
      orgId: string,
      rel: string,
    ): Promise<OrgHandbookFileResponse>;
  abstract writeHandbookFile(
      projectId: string,
      orgId: string,
      rel: string,
      content: string,
    ): Promise<OrgHandbookFileResponse>;
  abstract deleteHandbookFile(projectId: string, orgId: string, rel: string): Promise<void>;
}

Contract Topology

Static AST wiring across @Module / @Provide / @Use
@Moduleexported by
@Provideprovided by

Members (46)

employments

employments(projectId: string): Promise<Record<string, Employment[]>>

Which organizations of the Project employ which Agents, by Agent id: every chart entry of every organization directory the store lists — paused ones included, since a paused organization keeps every desk reachable — plus each organization's CEO id, which stands even while the chart does not parse (the CEO is the one employee an organization cannot be without, and its id is fixed by the organization's). The Agent list marks employees with it, and an employee's Agent cannot be deleted. A directory removed by hand is not listed, so it employs nobody. A record rather than a Map, since it crosses the service interface; read it with Object.hasOwn, as an Agent id may be any word, constructor included.

@paramprojectIdstring
@returnsPromise<Record<string, Employment[]>>

employmentCensus

employmentCensus(projectId: string): Promise<EmploymentCensus>

employments, and the organizations whose org_chart.yaml is missing or does not parse: beyond their CEO, whom they employ is unknown. Deleting an organization with its Agents reads both, and keeps an employee it cannot prove is employed nowhere else.

@paramprojectIdstring
@returnsPromise<EmploymentCensus>

employersOf

employersOf(projectId: string, agentId: string): Promise<Employment[]>

The organizations employing one Agent (see employments); empty when none does.

@paramprojectIdstring
@paramagentIdstring
@returnsPromise<Employment[]>

list

list(projectId: string): Promise<OrganizationSummary[]>
@paramprojectIdstring
@returnsPromise<OrganizationSummary[]>

create

create(projectId: string, req: OrganizationCreateRequest, userId: string, actor?: ModuleActor): Promise<OrganizationDetail>

Creates an organization as one whole: directory and files, the CEO Agent (with the company and orchestration plugins and an employee brief), then the initialization work run on the CEO's desk. Any failure removes what was written; a taken CEO id is a 409 before anything is touched.

@paramprojectIdstring
@paramreqOrganizationCreateRequest
@paramuserIdstring
@paramactor?ModuleActor
@returnsPromise<OrganizationDetail>

detail

detail(projectId: string, orgId: string, userId: string): Promise<OrganizationDetail>
@paramprojectIdstring
@paramorgIdstring
@paramuserIdstring
@returnsPromise<OrganizationDetail>

delete

delete(projectId: string, orgId: string): Promise<void>

Deletes the organization — and ONLY the organization: its directory goes to the Project's trash (store.trash), whole and restorable, and the rows this server derived from it go with it, since a new organization under the same id must not inherit another's read cursors, calendar state or pending notices.

What it had is left exactly as it is: deleting its employees' Agents too is the route's choice, made after this (services/organization-deletion.ts). Here its employees stay Agents of the Project, with everything they learned. Its desk and ticket Sessions stay too, still marked as an organization's (client = org), so they do not spill into development mode's list; with the organization gone no page lists them either, which is the price of not deleting conversations along with a company.

Under the organization's lock, so a pass in flight finishes first and the next one finds no directory — the same state a hand-removed directory always was.

@paramprojectIdstring
@paramorgIdstring
@returnsPromise<void>

patch

patch(projectId: string, orgId: string, req: OrganizationPatchRequest, userId: string): Promise<OrganizationSettings>
@paramprojectIdstring
@paramorgIdstring
@paramreqOrganizationPatchRequest
@paramuserIdstring
@returnsPromise<OrganizationSettings>

leave

leave(projectId: string, orgId: string, agentId: string): Promise<void>

Removes the employee from the tree (subordinates move up to its manager); the Agent and its sessions stay.

@paramprojectIdstring
@paramorgIdstring
@paramagentIdstring
@returnsPromise<void>

suggestId

suggestId(projectId: string, req: SemanticIdSuggestRequest): Promise<SemanticIdSuggestResponse>

A semantic id for a display name (the organization and channel dialogs name the thing first and derive the id): the shared proposal (semantic-id-suggest.ts) with the kind's prefix, the ids the dialog passed in to avoid, and every model dead end recorded as the organization's.

@paramprojectIdstring
@paramreqSemanticIdSuggestRequest
@returnsPromise<SemanticIdSuggestResponse>

chart

chart(projectId: string, orgId: string): Promise<OrgChartResponse>
@paramprojectIdstring
@paramorgIdstring
@returnsPromise<OrgChartResponse>

hire

hire(projectId: string, orgId: string, req: OrgHireRequest, actor?: ModuleActor | null): Promise<OrgEmployeeItem>
@paramprojectIdstring
@paramorgIdstring
@paramreqOrgHireRequest
@paramactor?ModuleActor | null
@returnsPromise<OrgEmployeeItem>

employeeAvatar

employeeAvatar(projectId: string, orgId: string, agentId: string): Promise<{ bytes: Buffer; mime: string; rev: string; }>

The employee's avatar image (organization/avatars.ts); 404 when it has none.

@paramprojectIdstring
@paramorgIdstring
@paramagentIdstring
@returnsPromise<{ bytes: Buffer; mime: string; rev: string; }>

setEmployeeAvatar

setEmployeeAvatar(projectId: string, orgId: string, agentId: string, avatar: string | null): Promise<OrgEmployeeItem>

Sets the employee's avatar from a data URL; null removes it.

@paramprojectIdstring
@paramorgIdstring
@paramagentIdstring
@paramavatarstring | null
@returnsPromise<OrgEmployeeItem>

patchEmployee

patchEmployee(projectId: string, orgId: string, agentId: string, req: OrgEmployeePatchRequest): Promise<OrgEmployeeItem>
@paramprojectIdstring
@paramorgIdstring
@paramagentIdstring
@paramreqOrgEmployeePatchRequest
@returnsPromise<OrgEmployeeItem>

desk

desk(projectId: string, orgId: string, agentId: string, opts: { renew?: boolean; }): Promise<OrgDeskResponse>
@paramprojectIdstring
@paramorgIdstring
@paramagentIdstring
@paramopts{ renew?: boolean; }
@returnsPromise<OrgDeskResponse>

sessions

sessions(projectId: string, orgId: string): Promise<OrgSessionsResponse>
@paramprojectIdstring
@paramorgIdstring
@returnsPromise<OrgSessionsResponse>

calendar

calendar(projectId: string, orgId: string): Promise<OrgCalendarResponse>
@paramprojectIdstring
@paramorgIdstring
@returnsPromise<OrgCalendarResponse>

upsertCalendar

upsertCalendar(projectId: string, orgId: string, agentId: string, name: string, fields: Omit<OrgCalendarUpsertRequest, "agentId" | "name">, opts: { create: boolean; }): Promise<OrgCalendarWriteResponse>
@paramprojectIdstring
@paramorgIdstring
@paramagentIdstring
@paramnamestring
@paramfieldsOmit<OrgCalendarUpsertRequest, "agentId" | "name">
@paramopts{ create: boolean; }
@returnsPromise<OrgCalendarWriteResponse>

deleteCalendar

deleteCalendar(projectId: string, orgId: string, agentId: string, name: string): Promise<void>
@paramprojectIdstring
@paramorgIdstring
@paramagentIdstring
@paramnamestring
@returnsPromise<void>

tickets

tickets(projectId: string, orgId: string): Promise<OrgTicketsResponse>
@paramprojectIdstring
@paramorgIdstring
@returnsPromise<OrgTicketsResponse>

ticket

ticket(projectId: string, orgId: string, ticketId: string): Promise<OrgTicketDetail>
@paramprojectIdstring
@paramorgIdstring
@paramticketIdstring
@returnsPromise<OrgTicketDetail>

createTicket

createTicket(projectId: string, orgId: string, req: OrgTicketCreateRequest, actor: Actor): Promise<OrgTicketDetail>
@paramprojectIdstring
@paramorgIdstring
@paramreqOrgTicketCreateRequest
@paramactorActor
@returnsPromise<OrgTicketDetail>

updateTicket

updateTicket(projectId: string, orgId: string, ticketId: string, req: OrgTicketUpdateRequest, actor: Actor): Promise<OrgTicketDetail>
@paramprojectIdstring
@paramorgIdstring
@paramticketIdstring
@paramreqOrgTicketUpdateRequest
@paramactorActor
@returnsPromise<OrgTicketDetail>

moveTicket

moveTicket(projectId: string, orgId: string, ticketId: string, status: OrgTicketStatus, reason: string | undefined, actor: Actor): Promise<OrgTicketDetail>
@paramprojectIdstring
@paramorgIdstring
@paramticketIdstring
@paramstatusOrgTicketStatus
@paramreasonstring | undefined
@paramactorActor
@returnsPromise<OrgTicketDetail>

blockTicket

blockTicket(projectId: string, orgId: string, ticketId: string, reason: string, by: string | undefined, actor: Actor): Promise<OrgTicketDetail>
@paramprojectIdstring
@paramorgIdstring
@paramticketIdstring
@paramreasonstring
@parambystring | undefined
@paramactorActor
@returnsPromise<OrgTicketDetail>

unblockTicket

unblockTicket(projectId: string, orgId: string, ticketId: string, actor: Actor): Promise<OrgTicketDetail>
@paramprojectIdstring
@paramorgIdstring
@paramticketIdstring
@paramactorActor
@returnsPromise<OrgTicketDetail>

progressTicket

progressTicket(projectId: string, orgId: string, ticketId: string, text: string, actor: Actor): Promise<OrgTicketDetail>
@paramprojectIdstring
@paramorgIdstring
@paramticketIdstring
@paramtextstring
@paramactorActor
@returnsPromise<OrgTicketDetail>

startTicket

startTicket(projectId: string, orgId: string, ticketId: string, req: { agentId?: string; message?: string; workspace?: string; }, actor: Actor): Promise<{ sessionId: string; }>

Opens a ticket session. Who may open one is the ticket's own rule: a person may open a session for any ticket, naming the employee with agentId; an employee may open one only for a ticket it owns. A desk that wants a colleague's ticket worked assigns it and lets that desk pick it up in its next sweep — an assignment is how work moves between employees, and a session opened around it leaves the owner with work it never saw. The owner may still pass agentId to enlist a colleague on its OWN ticket, which is how a request for help in a channel is answered.

@paramprojectIdstring
@paramorgIdstring
@paramticketIdstring
@paramreq{ agentId?: string; message?: string; workspace?: string; }
@paramactorActor
@returnsPromise<{ sessionId: string; }>

attachTicket

attachTicket(projectId: string, orgId: string, ticketId: string, sessionId: string, actor: Actor): Promise<OrgTicketDetail>
@paramprojectIdstring
@paramorgIdstring
@paramticketIdstring
@paramsessionIdstring
@paramactorActor
@returnsPromise<OrgTicketDetail>

channels

channels(projectId: string, orgId: string, actor: Actor): Promise<OrgChannelsResponse>

People are the board and see every channel; an employee sees the channels it belongs to.

@paramprojectIdstring
@paramorgIdstring
@paramactorActor
@returnsPromise<OrgChannelsResponse>

channel

channel(projectId: string, orgId: string, channelId: string, actor: Actor): Promise<OrgChannelDetail>
@paramprojectIdstring
@paramorgIdstring
@paramchannelIdstring
@paramactorActor
@returnsPromise<OrgChannelDetail>

createChannel

createChannel(projectId: string, orgId: string, req: OrgChannelCreateRequest, actor: Actor): Promise<OrgChannelItem>

A new channel holds exactly its creator; everyone else arrives by invitation (people may also join).

@paramprojectIdstring
@paramorgIdstring
@paramreqOrgChannelCreateRequest
@paramactorActor
@returnsPromise<OrgChannelItem>

patchChannel

patchChannel(projectId: string, orgId: string, channelId: string, req: OrgChannelPatchRequest, actor: Actor): Promise<OrgChannelItem>
@paramprojectIdstring
@paramorgIdstring
@paramchannelIdstring
@paramreqOrgChannelPatchRequest
@paramactorActor
@returnsPromise<OrgChannelItem>

addChannelMember

addChannelMember(projectId: string, orgId: string, channelId: string, rawPrincipal: string, actor: Actor): Promise<OrgChannelDetail>

Any member invites; a person may also join by itself, an employee may not.

@paramprojectIdstring
@paramorgIdstring
@paramchannelIdstring
@paramrawPrincipalstring
@paramactorActor
@returnsPromise<OrgChannelDetail>

removeChannelMember

removeChannelMember(projectId: string, orgId: string, channelId: string, rawPrincipal: string, actor: Actor): Promise<void>

A member removes itself; a person may remove anyone. Removing a non-member changes nothing.

@paramprojectIdstring
@paramorgIdstring
@paramchannelIdstring
@paramrawPrincipalstring
@paramactorActor
@returnsPromise<void>

channelMessages

channelMessages(projectId: string, orgId: string, actor: Actor, channelId: string, opts: { date?: string; }): Promise<OrgChannelMessagesResponse>
@paramprojectIdstring
@paramorgIdstring
@paramactorActor
@paramchannelIdstring
@paramopts{ date?: string; }
@returnsPromise<OrgChannelMessagesResponse>

sendChannelMessage

sendChannelMessage(projectId: string, orgId: string, userId: string, channelId: string, req: OrgChannelMessageSendRequest): Promise<OrgChannelMessage>
@paramprojectIdstring
@paramorgIdstring
@paramuserIdstring
@paramchannelIdstring
@paramreqOrgChannelMessageSendRequest
@returnsPromise<OrgChannelMessage>

markRead

markRead(projectId: string, orgId: string, userId: string, channelId: string, upTo: string): Promise<void>
@paramprojectIdstring
@paramorgIdstring
@paramuserIdstring
@paramchannelIdstring
@paramupTostring
@returnsPromise<void>

finance

finance(projectId: string, orgId: string, period?: string): Promise<OrgFinanceResponse>
@paramprojectIdstring
@paramorgIdstring
@paramperiod?string
@returnsPromise<OrgFinanceResponse>

handbook

handbook(projectId: string, orgId: string): Promise<string>
@paramprojectIdstring
@paramorgIdstring
@returnsPromise<string>

writeHandbook

writeHandbook(projectId: string, orgId: string, content: string): Promise<void>
@paramprojectIdstring
@paramorgIdstring
@paramcontentstring
@returnsPromise<void>

handbookFiles

handbookFiles(projectId: string, orgId: string): Promise<OrgHandbookFilesResponse>

The handbook directory is the company's knowledge base; the index is listed first.

@paramprojectIdstring
@paramorgIdstring
@returnsPromise<OrgHandbookFilesResponse>

handbookFile

handbookFile(projectId: string, orgId: string, rel: string): Promise<OrgHandbookFileResponse>
@paramprojectIdstring
@paramorgIdstring
@paramrelstring
@returnsPromise<OrgHandbookFileResponse>

writeHandbookFile

writeHandbookFile(projectId: string, orgId: string, rel: string, content: string): Promise<OrgHandbookFileResponse>
@paramprojectIdstring
@paramorgIdstring
@paramrelstring
@paramcontentstring
@returnsPromise<OrgHandbookFileResponse>

deleteHandbookFile

deleteHandbookFile(projectId: string, orgId: string, rel: string): Promise<void>

The index stays: it is what every trigger tells the employee to read.

@paramprojectIdstring
@paramorgIdstring
@paramrelstring
@returnsPromise<void>