|
| 1 | +import type { Static } from "typebox"; |
| 2 | +import { Type } from "typebox"; |
| 3 | +import { closedObject } from "./closed-object.js"; |
| 4 | +import { NonEmptyString } from "./primitives.js"; |
| 5 | + |
| 6 | +/** Projected actor that caused a session node to be created. */ |
| 7 | +export const SessionCreatedActorSchema = closedObject({ |
| 8 | + type: Type.Union([Type.Literal("human"), Type.Literal("agent"), Type.Literal("system")]), |
| 9 | + id: Type.Optional(NonEmptyString), |
| 10 | + label: Type.Optional(NonEmptyString), |
| 11 | +}); |
| 12 | + |
| 13 | +/** Stable Gateway session row fields; mutation envelopes may add null tombstones. */ |
| 14 | +export const SessionRowSchema = Type.Object( |
| 15 | + { |
| 16 | + key: Type.String(), |
| 17 | + sessionId: Type.Optional(Type.String()), |
| 18 | + kind: Type.Union([ |
| 19 | + Type.Literal("direct"), |
| 20 | + Type.Literal("group"), |
| 21 | + Type.Literal("global"), |
| 22 | + Type.Literal("unknown"), |
| 23 | + ]), |
| 24 | + label: Type.Optional(Type.String()), |
| 25 | + displayName: Type.Optional(Type.String()), |
| 26 | + derivedTitle: Type.Optional(Type.String()), |
| 27 | + lastMessagePreview: Type.Optional(Type.String()), |
| 28 | + channel: Type.Optional(Type.String()), |
| 29 | + chatType: Type.Optional( |
| 30 | + Type.Union([Type.Literal("direct"), Type.Literal("group"), Type.Literal("channel")]), |
| 31 | + ), |
| 32 | + updatedAt: Type.Optional(Type.Union([Type.Number(), Type.Null()])), |
| 33 | + archived: Type.Optional(Type.Boolean()), |
| 34 | + archivedAt: Type.Optional(Type.Number()), |
| 35 | + pinned: Type.Optional(Type.Boolean()), |
| 36 | + pinnedAt: Type.Optional(Type.Number()), |
| 37 | + icon: Type.Optional(Type.String()), |
| 38 | + unread: Type.Optional(Type.Boolean()), |
| 39 | + lastReadAt: Type.Optional(Type.Number()), |
| 40 | + lastActivityAt: Type.Optional(Type.Number()), |
| 41 | + lastInteractionAt: Type.Optional(Type.Number()), |
| 42 | + status: Type.Optional( |
| 43 | + Type.Union([ |
| 44 | + Type.Literal("running"), |
| 45 | + Type.Literal("done"), |
| 46 | + Type.Literal("failed"), |
| 47 | + Type.Literal("killed"), |
| 48 | + Type.Literal("timeout"), |
| 49 | + ]), |
| 50 | + ), |
| 51 | + lastRunError: Type.Optional(Type.String()), |
| 52 | + spawnedBy: Type.Optional(Type.String()), |
| 53 | + parentSessionKey: Type.Optional(Type.String()), |
| 54 | + controlOwnerSessionKey: Type.Optional(Type.String()), |
| 55 | + childSessions: Type.Optional(Type.Array(Type.String())), |
| 56 | + forkedFromParent: Type.Optional(Type.Boolean()), |
| 57 | + spawnDepth: Type.Optional(Type.Number()), |
| 58 | + subagentRole: Type.Optional(Type.Union([Type.Literal("orchestrator"), Type.Literal("leaf")])), |
| 59 | + subagentControlScope: Type.Optional( |
| 60 | + Type.Union([Type.Literal("children"), Type.Literal("none")]), |
| 61 | + ), |
| 62 | + swarmGroupId: Type.Optional(Type.String()), |
| 63 | + worktree: Type.Optional( |
| 64 | + Type.Object({ |
| 65 | + id: Type.String(), |
| 66 | + branch: Type.String(), |
| 67 | + repoRoot: Type.String(), |
| 68 | + }), |
| 69 | + ), |
| 70 | + execNode: Type.Optional(Type.String()), |
| 71 | + execCwd: Type.Optional(Type.String()), |
| 72 | + spawnedWorkspaceDir: Type.Optional(Type.String()), |
| 73 | + spawnedCwd: Type.Optional(Type.String()), |
| 74 | + createdVia: Type.Optional( |
| 75 | + Type.Union([ |
| 76 | + Type.Literal("operator"), |
| 77 | + Type.Literal("spawn"), |
| 78 | + Type.Literal("channel"), |
| 79 | + Type.Literal("cron"), |
| 80 | + Type.Literal("talk"), |
| 81 | + Type.Literal("run"), |
| 82 | + Type.Literal("plugin"), |
| 83 | + Type.Literal("internal"), |
| 84 | + ]), |
| 85 | + ), |
| 86 | + createdActor: Type.Optional(SessionCreatedActorSchema), |
| 87 | + createdAt: Type.Optional(Type.Number()), |
| 88 | + forkSource: Type.Optional( |
| 89 | + Type.Object({ |
| 90 | + sessionKey: Type.String(), |
| 91 | + sessionId: Type.String(), |
| 92 | + entryId: Type.Optional(Type.String()), |
| 93 | + }), |
| 94 | + ), |
| 95 | + previousSessionId: Type.Optional(Type.String()), |
| 96 | + inputTokens: Type.Optional(Type.Number()), |
| 97 | + outputTokens: Type.Optional(Type.Number()), |
| 98 | + totalTokens: Type.Optional(Type.Number()), |
| 99 | + totalTokensFresh: Type.Optional(Type.Boolean()), |
| 100 | + contextTokens: Type.Optional(Type.Number()), |
| 101 | + estimatedCostUsd: Type.Optional(Type.Number()), |
| 102 | + model: Type.Optional(Type.String()), |
| 103 | + modelProvider: Type.Optional(Type.String()), |
| 104 | + }, |
| 105 | + { additionalProperties: true }, |
| 106 | +); |
| 107 | + |
| 108 | +export type SessionCreatedActor = Static<typeof SessionCreatedActorSchema>; |
| 109 | +export type SessionRow = Static<typeof SessionRowSchema>; |
0 commit comments