Skip to content

armgit / alook

Public Imported from GitHub
0

Multi-Agent Collaboration for Team and Friends

11.7 KB
Raw Blame
import type { CommunityWsEvent } from "../src/community-ws-events"

const approval = {
  friendshipId: "friendship-1",
  status: "pending" as const,
  waitingOn: "you" as const,
  otherProfile: { id: "user-2", name: "Other", discriminator: "0002", image: null, avatarVersion: 0 },
  botProfile: { id: "bot-1", name: "Bot", discriminator: "0001", image: null, avatarVersion: 0 },
}

const machine = {
  id: "machine-1",
  hostname: "host",
  displayName: "Host",
  platform: "darwin",
  arch: "arm64",
  osRelease: "1",
  daemonVersion: "1",
  lastSeenAt: null,
  status: "online" as const,
  availableRuntimes: [{ id: "codex", status: "healthy" as const }],
  createdAt: "2026-01-01T00:00:00.000Z",
  updatedAt: "2026-01-01T00:00:00.000Z",
}

export const communityResourceChannelFixture = {
  id: "channel-1", type: "text", serverId: "server-1", categoryId: null,
  name: "Channel", topic: "Keep this topic", parentChannelId: null, parentMessageId: null,
  creatorId: "user-1", position: 4, archived: false, createdAt: "2026-01-01T00:00:00.000Z",
  lastMessageAt: null, messageCount: 0,
} as const


export const communityWsEventFixtures = {
  "community:message.create": {
    type: "community:message.create",
    channelId: "channel-1",
    serverId: "server-1",
    profiles: [{ id: "user-1", name: "Author", discriminator: "0001", avatar: null, avatarVersion: 0 }],
    message: {
      id: "message-1", channelId: "channel-1", replyToId: null, clientNonce: null,
      seq: 1,
      authorId: "user-1",
      authorName: "Author",
      authorAvatarVersion: 0,
      content: "hello",
      type: "chat",
      attachments: [{
        id: "attachment-1",
        name: "photo.png", sizeBytes: 2048, width: 640, height: 480,
        url: "/api/community/channels/channel-1/attachments/attachment-1",
        thumbnailUrl: "/api/community/channels/channel-1/attachments/attachment-1/thumbnail",
        contentType: "image/png",
      }],
      createdAt: "2026-01-01T00:00:00.000Z",
    },
  },
  "community:message.updated": {
    type: "community:message.updated",
    channelId: "channel-1",
    messageId: "message-1",
    approval,
  },
  "community:reaction.add": {
    type: "community:reaction.add",
    channelId: "channel-1",
    messageId: "message-1",
    userId: "user-1",
    emoji: "πŸ‘",
  },
  "community:reaction.remove": {
    type: "community:reaction.remove",
    channelId: "channel-1",
    messageId: "message-1",
    userId: "user-1",
    emoji: "πŸ‘",
  },
  "community:pin.add": {
    type: "community:pin.add",
    channelId: "channel-1",
    messageId: "message-1",
  },
  "community:pin.remove": {
    type: "community:pin.remove",
    channelId: "channel-1",
    messageId: "message-1",
  },
  "community:typing.start": {
    type: "community:typing.start",
    channelId: "channel-1",
    userId: "user-1",
  },
  "community:typing.stop": {
    type: "community:typing.stop",
    channelId: "channel-1",
    userId: "user-1",
  },
  "community:channel.child_create": {
    type: "community:channel.child_create",
    parentChannelId: "channel-1",
    channel: { ...communityResourceChannelFixture, id: "thread-1", name: "Thread", type: "thread", parentChannelId: "channel-1", parentMessageId: "message-1" },
  },
  "community:channel.child_update": {
    type: "community:channel.child_update",
    parentChannelId: "channel-1",
    channelId: "thread-1",
    changes: { name: "Renamed" },
  },
  "community:server_rail.changed": { type: "community:server_rail.changed" },
  "community:server.update": {
    type: "community:server.update",
    serverId: "server-1",
    changes: { name: "Server" },
  },
  "community:server.delete": { type: "community:server.delete", serverId: "server-1" },
  "community:channel.create": {
    type: "community:channel.create",
    serverId: "server-1",
    channel: { ...communityResourceChannelFixture, position: 0 },
  },
  "community:channel.update": {
    type: "community:channel.update",
    serverId: "server-1",
    channelId: "channel-1",
    changes: { name: "Channel" },
  },
  "community:channel.delete": {
    type: "community:channel.delete",
    serverId: "server-1",
    channelId: "channel-1",
  },
  "community:channel.reorder": {
    type: "community:channel.reorder",
    serverId: "server-1",
    channels: [{ id: "channel-1", position: 0 }],
  },
  "community:channel.membership.change": {
    type: "community:channel.membership.change", serverId: "server-1", channelId: "channel-1", userId: "user-1", relation: "notify", present: true,
  },
  "community:category.create": {
    type: "community:category.create",
    serverId: "server-1",
    category: { id: "category-1", serverId: "server-1", creatorId: "user-1", name: "Category", position: 0, private: false },
  },
  "community:category.update": {
    type: "community:category.update",
    serverId: "server-1",
    categoryId: "category-1",
    changes: { name: "Category" },
  },
  "community:category.delete": {
    type: "community:category.delete",
    serverId: "server-1",
    categoryId: "category-1",
  },
  "community:category.reorder": {
    type: "community:category.reorder",
    serverId: "server-1",
    categories: [{ id: "category-1", position: 0 }],
  },
  "community:member.join": {
    type: "community:member.join",
    serverId: "server-1",
    member: {
      id: "member-1",
      userId: "user-1",
      name: "Member", avatar: null,
      discriminator: "0001",
      avatarVersion: 0,
      role: "member",
      joinedAt: "2026-01-01T00:00:00.000Z",
    },
  },
  "community:member.leave": {
    type: "community:member.leave",
    serverId: "server-1",
    userId: "user-1",
  },
  "community:member.update": {
    type: "community:member.update",
    serverId: "server-1",
    memberId: "member-1",
    changes: { role: "admin" },
  },
  "community:friend.request": {
    type: "community:friend.request",
    friendship: {
      id: "friendship-1",
      requesterId: "user-1",
      addresseeId: "user-2",
      status: "pending",
      createdAt: "2026-01-01T00:00:00.000Z",
    },
  },
  "community:friend.accept": { type: "community:friend.accept", friendshipId: "friendship-1" },
  "community:friend.reject": { type: "community:friend.reject", friendshipId: "friendship-1" },
  "community:friend.remove": { type: "community:friend.remove", friendshipId: "friendship-1" },
  "community:friend.block": { type: "community:friend.block", userId: "user-1" },
  "community:invite.create": {
    type: "community:invite.create",
    serverId: "server-1",
    invite: { id: "invite-1", token: "token", createdAt: "2026-01-01T00:00:00.000Z" },
  },
  "community:mention.create": {
    type: "community:mention.create",
    userId: "user-1",
    messageId: "message-1",
    authorName: "Author",
  },
  "community:unread.bump": {
    type: "community:unread.bump",
    userId: "user-1",
    channelId: "channel-1",
  },
  "community:read_state.advanced": {
    type: "community:read_state.advanced",
    revision: 1,
    inboxChanged: true,
  },
  "community:inbox.changed": {
    type: "community:inbox.changed",
    revision: 2,
    inboxChanged: true,
    reason: "read_all",
  },
  "community:presence.update": {
    type: "community:presence.update",
    userId: "user-1",
    online: true,
  },
  "community:status.update": {
    type: "community:status.update",
    userId: "user-1",
    statusEmoji: null,
    statusText: null,
  },
  "community:identity.update": {
    type: "community:identity.update",
    userId: "user-1",
    avatar: "/api/community/users/user-1/avatar?v=2",
    avatarVersion: 2,
  },
  "community:profile.update": {
    type: "community:profile.update",
    userId: "user-1",
    name: "Alice",
    discriminator: "0042",
    aboutMe: "Hello",
    bannerColor: null,
    kind: "human",
    ownerUserId: null,
  },
  "community:machine.created": {
    type: "community:machine.created",
    machine,
    tokenId: "token-1",
  },
  "community:machine.status": {
    type: "community:machine.status",
    machineId: "machine-1",
    status: "online",
    lastSeenAt: "2026-01-01T00:00:00.000Z",
  },
  "community:machine.updated": { type: "community:machine.updated", machine },
  "community:bot.pii": { type: "community:bot.pii", machineId: "machine-1", botId: "bot-1", requestId: "request-1", result: { status: "complete", snapshot: { revision: 1, plugins: [{ id: "plugin-1", name: "Email", description: "Redacts emails", enabled: true }] } } },
  "community:runtime.models": { type: "community:runtime.models", machineId: "machine-1", requestId: "request-1", runtimeId: "codex", result: { status: "complete", catalog: null } },
  "community:machine.removed": { type: "community:machine.removed", machineId: "machine-1" },
  "community:bot.audit_event": {
    type: "community:bot.audit_event",
    botId: "bot-1",
    id: "audit-1",
    kind: "thinking",
    payload: { text: "thinking" },
    createdAt: "2026-01-01T00:00:00.000Z",
  },
} satisfies {
  [T in CommunityWsEvent["type"]]: Extract<CommunityWsEvent, { type: T }>
}

export const requiredFixturePaths = {
  "community:message.create": ["channelId"],
  "community:message.updated": ["approval"],
  "community:reaction.add": ["emoji"],
  "community:reaction.remove": ["emoji"],
  "community:pin.add": ["messageId"],
  "community:pin.remove": ["messageId"],
  "community:typing.start": ["userId"],
  "community:typing.stop": ["userId"],
  "community:channel.child_create": ["channel"],
  "community:channel.child_update": ["changes"],
  "community:server.update": ["changes"],
  "community:server_rail.changed": [],
  "community:server.delete": ["serverId"],
  "community:channel.create": ["channel"],
  "community:channel.update": ["changes"],
  "community:channel.delete": ["channelId"],
  "community:channel.reorder": ["channels"],
  "community:channel.membership.change": ["relation"],
  "community:category.create": ["category"],
  "community:category.update": ["changes"],
  "community:category.delete": ["categoryId"],
  "community:category.reorder": ["categories"],
  "community:member.join": ["member"],
  "community:member.leave": ["userId"],
  "community:member.update": ["changes"],
  "community:friend.request": ["friendship"],
  "community:friend.accept": ["friendshipId"],
  "community:friend.reject": ["friendshipId"],
  "community:friend.remove": ["friendshipId"],
  "community:friend.block": ["userId"],
  "community:invite.create": ["invite"],
  "community:mention.create": ["messageId"],
  "community:unread.bump": ["channelId"],
  "community:read_state.advanced": ["revision"],
  "community:inbox.changed": ["reason"],
  "community:presence.update": ["online"],
  "community:status.update": ["statusText"],
  "community:identity.update": ["avatarVersion"],
  "community:profile.update": ["name"],
  "community:machine.created": ["machine"],
  "community:machine.status": ["lastSeenAt"],
  "community:machine.updated": ["machine"],
  "community:runtime.models": ["requestId"],
  "community:bot.pii": ["requestId"],
  "community:machine.removed": ["machineId"],
  "community:bot.audit_event": ["payload"],
} satisfies Record<CommunityWsEvent["type"], readonly [] | readonly [string, ...string[]]>


export const communityResourceMessageFixture = {
  ...communityWsEventFixtures["community:message.create"],
  message: {
    id: "message-1", channelId: "channel-1", seq: 1, authorId: "user-1", authorName: "Author",
    authorAvatar: null, authorAvatarVersion: 0, type: "chat", content: "Γ© πŸ˜€", replyToId: null,
    clientNonce: null, createdAt: "2026-01-01T00:00:00.000Z",
    attachments: [
      { id: "attachment-2", name: "unknown.bin", url: "/file", thumbnailUrl: null, contentType: null, sizeBytes: null, width: null, height: null },
      { id: "attachment-1", name: "photo.png", url: "/photo", thumbnailUrl: "/thumbnail", contentType: "image/png", sizeBytes: 2048, width: 640, height: 480 },
    ],
    embeds: [null, { title: "Card", fields: [null, { name: "Key", value: "Value" }] }, { raw: "unknown" }],
  },
} as const