mirror of
https://github.com/stablyai/orca.git
synced 2026-09-26 16:02:43 +00:00
* chore(dead-code): drop 2k lines of unreachable exports and orphan modules Ran knip across every build entry (main, preload, renderer, popout, web, cli, relay, workers, forked sidecars, config scripts) and removed what no entry graph can reach. - 11 orphan modules nothing imported, plus one test that only covered them - 159 unused exports/types, with their now-dead helpers, imports and tests Each candidate was verified against dynamic references before deletion. 42 knip hits were false positives and are kept: shared modules consumed by the mobile/ workspace, the src/shared/plugins/** public API, vendored shadcn primitives, and relay wire-protocol constants held for compatibility. Adds knip.json + `pnpm audit:dead-code` so this stays measurable. Verified: pnpm typecheck, pnpm lint, and 2081 tests across the 73 affected test files all pass. * chore(dead-code): move knip config under config/ Root-level additions are blocked by the root directory guard. Co-authored-by: Orca <help@stably.ai> --------- Co-authored-by: Orca <help@stably.ai>
121 lines
3.7 KiB
TypeScript
121 lines
3.7 KiB
TypeScript
import { z } from 'zod'
|
|
import { PAIRING_OFFER_VERSION, type PairingOffer } from './pairing'
|
|
|
|
export const RuntimeAccessEndpointSchema = z.object({
|
|
id: z.string().min(1),
|
|
kind: z.literal('websocket'),
|
|
label: z.string().min(1),
|
|
endpoint: z.string().min(1),
|
|
deviceToken: z.string().min(1),
|
|
publicKeyB64: z.string().min(1)
|
|
})
|
|
|
|
export const PublicRuntimeAccessEndpointSchema = RuntimeAccessEndpointSchema.omit({
|
|
deviceToken: true,
|
|
publicKeyB64: true
|
|
})
|
|
|
|
export type PublicRuntimeAccessEndpoint = z.infer<typeof PublicRuntimeAccessEndpointSchema>
|
|
|
|
export const RuntimeEnvironmentSourceSchema = z.enum(['manual', 'ephemeral-vm'])
|
|
export type RuntimeEnvironmentSource = z.infer<typeof RuntimeEnvironmentSourceSchema>
|
|
|
|
export const KnownRuntimeEnvironmentSchema = z.object({
|
|
id: z.string().min(1),
|
|
name: z.string().min(1),
|
|
createdAt: z.number().finite(),
|
|
updatedAt: z.number().finite(),
|
|
pairingRevision: z.number().finite().optional(),
|
|
lastUsedAt: z.number().finite().nullable(),
|
|
runtimeId: z.string().min(1).nullable(),
|
|
source: RuntimeEnvironmentSourceSchema.optional(),
|
|
connectionDependency: z.literal('ssh-tunnel').optional(),
|
|
endpoints: z.array(RuntimeAccessEndpointSchema).min(1),
|
|
preferredEndpointId: z.string().min(1)
|
|
})
|
|
|
|
export type KnownRuntimeEnvironment = z.infer<typeof KnownRuntimeEnvironmentSchema>
|
|
|
|
export type PublicKnownRuntimeEnvironment = Omit<KnownRuntimeEnvironment, 'endpoints'> & {
|
|
endpoints: PublicRuntimeAccessEndpoint[]
|
|
}
|
|
|
|
export function redactRuntimeEnvironment(
|
|
environment: KnownRuntimeEnvironment
|
|
): PublicKnownRuntimeEnvironment {
|
|
return {
|
|
...environment,
|
|
endpoints: environment.endpoints.map(
|
|
({ deviceToken: _deviceToken, publicKeyB64: _key, ...rest }) => rest
|
|
)
|
|
}
|
|
}
|
|
|
|
export const RuntimeEnvironmentStoreSchema = z.object({
|
|
version: z.literal(1),
|
|
environments: z.array(KnownRuntimeEnvironmentSchema)
|
|
})
|
|
|
|
export type RuntimeEnvironmentStore = z.infer<typeof RuntimeEnvironmentStoreSchema>
|
|
|
|
export function createEnvironmentFromPairingOffer(args: {
|
|
id: string
|
|
name: string
|
|
now: number
|
|
offer: PairingOffer
|
|
runtimeId?: string | null
|
|
source?: RuntimeEnvironmentSource
|
|
connectionDependency?: 'ssh-tunnel'
|
|
}): KnownRuntimeEnvironment {
|
|
const endpointId = `ws-${args.id}`
|
|
return KnownRuntimeEnvironmentSchema.parse({
|
|
id: args.id,
|
|
name: args.name,
|
|
createdAt: args.now,
|
|
updatedAt: args.now,
|
|
pairingRevision: args.now,
|
|
lastUsedAt: null,
|
|
runtimeId: args.runtimeId ?? null,
|
|
...(args.source ? { source: args.source } : {}),
|
|
...(args.connectionDependency ? { connectionDependency: args.connectionDependency } : {}),
|
|
endpoints: [
|
|
{
|
|
id: endpointId,
|
|
kind: 'websocket',
|
|
label: 'WebSocket',
|
|
endpoint: args.offer.endpoint,
|
|
deviceToken: args.offer.deviceToken,
|
|
publicKeyB64: args.offer.publicKeyB64
|
|
}
|
|
],
|
|
preferredEndpointId: endpointId
|
|
})
|
|
}
|
|
|
|
export function isEphemeralVmRuntimeEnvironment(
|
|
environment: Pick<PublicKnownRuntimeEnvironment, 'source'>
|
|
): boolean {
|
|
return environment.source === 'ephemeral-vm'
|
|
}
|
|
|
|
export function isUserManagedRuntimeEnvironment(
|
|
environment: Pick<PublicKnownRuntimeEnvironment, 'source'>
|
|
): boolean {
|
|
return !isEphemeralVmRuntimeEnvironment(environment)
|
|
}
|
|
|
|
export function getPreferredPairingOffer(environment: KnownRuntimeEnvironment): PairingOffer {
|
|
const endpoint =
|
|
environment.endpoints.find((entry) => entry.id === environment.preferredEndpointId) ??
|
|
environment.endpoints[0]
|
|
if (!endpoint) {
|
|
throw new Error(`Environment ${environment.name} has no access endpoints`)
|
|
}
|
|
return {
|
|
v: PAIRING_OFFER_VERSION,
|
|
endpoint: endpoint.endpoint,
|
|
deviceToken: endpoint.deviceToken,
|
|
publicKeyB64: endpoint.publicKeyB64
|
|
}
|
|
}
|