mirror of
https://github.com/nestriness/nestri.git
synced 2026-11-18 21:19:50 +02:00
Phase 1 of decision 0085, the api piece (see .nestri contract
window-streams).
A box run (session) now holds launches: one game or app each. Billing,
allowance and the free weekend still count sessions; nothing about
limits changes. session_box_active_unique stays.
- Migration 0027: launch table (id lch_..., session_id, game_id, state
requested|running|ended|failed, first, time_started, time_stopped,
time_stop_requested, end_reason, error_message). Backfills a first
launch for every run that has not stopped.
- POST /session: same request; the response data gains launches (the
first launch).
- POST /session/{id}/launch {gameId}: 201 with the launch. Same library
check as POST /session. 409 unless the run is starting or live and not
being stopped.
- POST /session/{id}/launch/{launchId}/stop: marks the launch; host gets
launch.stop until it reports it over. A launch in a run no host has
claimed ends at once.
- POST /session/{id}/launch/{launchId}/state (host, run's claimToken):
running | ended | failed, optional endReason/errorMessage.
- When the last launch is over, the run is stopped through the same path
as POST /session/{id}/stop. A run ending ends every launch in it.
- GET /session/{id} gains launches.
- GET /machine/jobs: session.start gains launchId (the first launch);
new kinds launch.start and launch.stop. Agents skip unknown kinds, so
old hosts behave as before.
Tests: apps/api 203 pass (new test/launch.test.ts), packages/core 256
pass, against the local test Postgres.
213 lines
5.1 KiB
TypeScript
213 lines
5.1 KiB
TypeScript
import { Identifier } from './id.js';
|
|
|
|
export namespace Examples {
|
|
// The width is taken from the generator rather than typed out. Counting
|
|
// twenty-six of anything by eye is a thing people get wrong once and then
|
|
// never look at again — this was one short, which made every documented id
|
|
// a value the schema that published it would reject.
|
|
export const Id = (prefix: keyof typeof Identifier.prefixes) =>
|
|
`${Identifier.prefixes[prefix]}_${'X'.repeat(Identifier.LENGTH)}`;
|
|
|
|
export const User = {
|
|
id: Id('user'),
|
|
name: 'John Doe',
|
|
email: 'johndoe@example.com',
|
|
emailVerified: true,
|
|
image: 'https://cdn.discordapp.com/avatars/xxxxxxx/xxxxxxx.png'
|
|
};
|
|
|
|
export const LinkedAccount = {
|
|
id: Id('linkedAccount'),
|
|
userId: Id('user'),
|
|
provider: 'steam',
|
|
providerAccountId: '76561197960287930',
|
|
profile: { personaname: 'John Doe', avatarfull: 'https://avatars.steamstatic.com/xxxx.jpg' }
|
|
};
|
|
|
|
export const Organisation = {
|
|
id: Id('organisation'),
|
|
name: 'Initech',
|
|
slug: 'initech',
|
|
domain: 'initech.example',
|
|
domainVerified: true
|
|
};
|
|
|
|
export const Team = {
|
|
id: Id('team'),
|
|
name: 'The A Team',
|
|
slug: 'the-a-team',
|
|
ownerId: Id('user'),
|
|
organisationId: null,
|
|
billingEmail: 'billing@example.com',
|
|
plan: 'free',
|
|
subscriptionStatus: 'active',
|
|
metadata: null
|
|
};
|
|
|
|
export const Member = {
|
|
id: Id('teamMember'),
|
|
teamId: Id('team'),
|
|
userId: Id('user'),
|
|
role: 'owner' as const
|
|
};
|
|
|
|
export const Fingerprint = {
|
|
id: Id('userFingerprint'),
|
|
userId: Id('user'),
|
|
fingerprint: 'a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4',
|
|
name: 'MacBook Air',
|
|
lastSeen: '2026-07-28T12:00:00.000Z'
|
|
};
|
|
|
|
export const PairingCode = {
|
|
id: Id('pairingCode'),
|
|
code: 'NESSH-7F2Q',
|
|
targetUserId: Id('user'),
|
|
newFingerprint: null,
|
|
expiresAt: '2026-07-28T12:10:00.000Z',
|
|
claimedAt: null,
|
|
isClaimed: false
|
|
};
|
|
|
|
export const Game = {
|
|
id: Id('game'),
|
|
steamAppId: 730,
|
|
slug: 'counter-strike-2',
|
|
name: 'Counter-Strike 2',
|
|
aliases: 'cs2 csgo',
|
|
type: 'game',
|
|
clientIcon: '5aad412d01a9b91ba0379f0b35f4eb0b69d9db08',
|
|
icon: 'f92b09dab91f1d1738f72fe0dd9be18dcc2901f9',
|
|
shortDescription: 'For 25 years...',
|
|
description: 'For over two decades...',
|
|
developers: ['Valve'],
|
|
publishers: ['Valve'],
|
|
primaryGenre: 'Action',
|
|
genres: ['Action', 'FPS'],
|
|
categories: ['Multi-player', 'Steam Achievements'],
|
|
oslist: ['windows', 'linux'],
|
|
sizeDownload: 35000000000,
|
|
sizeOnDisk: 40000000000,
|
|
controllerSupport: 'partial',
|
|
steamDeckCompat: 'perfect',
|
|
reviewScorePercent: 86,
|
|
reviewCount: 1500000,
|
|
metacriticScore: 89,
|
|
steamChangeNumber: 24605165,
|
|
publicBuildId: 12345678,
|
|
releaseDate: '2012-08-21T00:00:00.000Z',
|
|
timeEnriched: '2026-07-29T12:00:00.000Z'
|
|
};
|
|
|
|
export const Library = {
|
|
id: Id('userLibrary'),
|
|
userId: Id('user'),
|
|
gameId: Id('game'),
|
|
playtime2w: 3600,
|
|
playtimeForever: 150000,
|
|
lastPlayed: '2026-07-28T12:00:00.000Z'
|
|
};
|
|
|
|
export const Depot = {
|
|
id: Id('gameDepot'),
|
|
gameId: Id('game'),
|
|
depotId: 731,
|
|
branch: 'public',
|
|
steamManifestId: '3183503801510301321',
|
|
steamBuildId: 12345678,
|
|
installedManifestId: '3183503801510301321',
|
|
installedBuildId: 12345678,
|
|
sizeDownload: 1000,
|
|
sizeOnDisk: 2000,
|
|
status: 'complete' as const,
|
|
errorMessage: null,
|
|
oslist: 'linux'
|
|
};
|
|
|
|
export const AccessToken = {
|
|
id: Id('accessToken'),
|
|
ownerUserId: Id('user'),
|
|
teamId: null,
|
|
name: 'living-room-box',
|
|
expiresAt: null,
|
|
lastUsed: '2026-07-28T12:00:00.000Z'
|
|
};
|
|
|
|
export const Machine = {
|
|
id: Id('machine'),
|
|
ownerUserId: Id('user'),
|
|
teamId: Id('team'),
|
|
label: 'living-room-box',
|
|
slug: 'amber-otter-4821',
|
|
lastSeen: '2026-07-28T12:00:00.000Z',
|
|
endpointId: 'a'.repeat(64)
|
|
};
|
|
|
|
export const SteamEnrolment = {
|
|
machineId: Id('machine'),
|
|
userId: Id('user'),
|
|
steamId: '76561197960287930',
|
|
state: 'enrolled' as const,
|
|
enrolledAt: '2026-07-28T12:00:00.000Z',
|
|
lastOkAt: null,
|
|
revokedAt: null
|
|
};
|
|
|
|
export const Box = {
|
|
id: Id('box'),
|
|
userId: Id('user'),
|
|
machineId: Id('machine'),
|
|
label: 'living room',
|
|
tier: 'sm' as const,
|
|
state: 'created' as const,
|
|
stopReason: null,
|
|
stopClean: null,
|
|
gpu: 'NVIDIA GeForce RTX 3060',
|
|
host: 'm7k2q9',
|
|
fleet: false
|
|
};
|
|
|
|
export const Session = {
|
|
id: Id('session'),
|
|
boxId: Id('box'),
|
|
gameId: Id('game'),
|
|
linkedAccountId: Id('linkedAccount'),
|
|
state: 'live' as const,
|
|
ticket: 'nodeaaqf…',
|
|
// Shaped like the real thing so the docs do not teach a shorter one,
|
|
// and obviously not one.
|
|
claimToken: '00000000000000000000000000000000',
|
|
timeClaimed: '2026-07-28T11:59:30.000Z',
|
|
timeStarted: '2026-07-28T12:00:00.000Z',
|
|
timeStopped: null,
|
|
errorMessage: null,
|
|
endReason: null
|
|
};
|
|
|
|
export const Launch = {
|
|
id: Id('launch'),
|
|
gameId: Id('game'),
|
|
state: 'running' as const
|
|
};
|
|
|
|
export const GameDownload = {
|
|
id: Id('gameDownload'),
|
|
hostId: Id('machine'),
|
|
gameId: Id('game'),
|
|
status: 'downloading' as const,
|
|
progressBytes: 1073741824,
|
|
totalBytes: 5000000000,
|
|
timeStarted: '2026-07-28T12:00:00.000Z',
|
|
timeCompleted: null,
|
|
errorMessage: null,
|
|
gpu: 'NVIDIA GeForce RTX 3060'
|
|
};
|
|
|
|
export const WaitlistEntry = {
|
|
id: Id('waitlistEntry'),
|
|
email: 'johndoe@example.com',
|
|
source: 'machines',
|
|
timeCreated: '2026-07-28T12:00:00.000Z'
|
|
};
|
|
}
|