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.

2.4 KB
Raw Blame
import { z } from 'zod'
import {
  PushAgentStateSchema,
  PushNotificationSourceSchema
} from './device-registration-messages.js'
import { PUSH_LIMITS } from './push-limits.js'
import { OpaqueIdSchema, SequenceSchema } from './wire-scalars.js'

export const PushNotificationSchema = z
  .object({
    // Absent for terminal-bell; printable ASCII only because desktop URL-encoded IDs become APNs collapse headers.
    notificationId: z
      .string()
      .min(1)
      .max(2048)
      .regex(/^[\x20-\x7e]+$/)
      .optional(),
    notificationSeq: SequenceSchema,
    notificationEpoch: OpaqueIdSchema,
    source: PushNotificationSourceSchema,
    sound: z.boolean().optional(),
    kind: z.enum(['alert', 'dismiss']).optional(),
    expiresAt: z.number().int().positive().optional(),
    agentState: PushAgentStateSchema.nullable(),
    title: z.string().min(1).max(PUSH_LIMITS.titleMaxChars),
    body: z.string().max(PUSH_LIMITS.bodyMaxChars),
    worktreeId: z.string().min(1).max(2048).optional(),
    paneKey: z.string().min(1).max(2048).optional(),
    // The workspace's server; mirrors the app's runtime host id (cannot import src/shared).
    executionHost: z
      .string()
      .max(2048)
      .regex(/^runtime:[^|\s]+$/)
      .optional()
  })
  .strict()
  .refine(
    (notification) => notification.kind !== 'dismiss' || Boolean(notification.notificationId),
    { message: 'dismiss requires notificationId' }
  )
  .refine(
    (notification) => new TextEncoder().encode(JSON.stringify(notification)).byteLength <= 3000,
    {
      message: 'notification exceeds provider payload budget'
    }
  )

export const PushSendRequestSchema = z
  .object({
    v: z.literal(1),
    // Deduped before the gateway sees it so a repeated id cannot reserve quota twice.
    registrationIds: z
      .array(OpaqueIdSchema)
      .min(1)
      .max(PUSH_LIMITS.maxRegistrationIdsPerSend)
      .transform((ids) => [...new Set(ids)]),
    notification: PushNotificationSchema
  })
  .strict()

export const PushSendStatusSchema = z.enum(['queued', 'dead', 'rate_limited', 'error'])

export const PushSendResultSchema = z
  .object({ registrationId: OpaqueIdSchema, status: PushSendStatusSchema })
  .strict()

export type PushNotification = z.infer<typeof PushNotificationSchema>
export type PushSendRequest = z.infer<typeof PushSendRequestSchema>
export type PushSendStatus = z.infer<typeof PushSendStatusSchema>
export type PushSendResult = z.infer<typeof PushSendResultSchema>