aebee77843
Built the missing piece that connects the ksp-bridge to a real KSP instance via kRPC. This adds a typed service client on top of the existing KRPCClient, plus the SpaceCenter-specific extraction logic that pulls the universe state from a running KSP save. @kerbal-rt/krpc-client - types.ts — runtime representation of kRPC Type descriptors (TypeCode enum, KrpcType interface, decodeKrpcType, typeName) - decoder.ts — kRPC value codec: primitive decode/encode, class refs, enums, collections (LIST/SET/TUPLE/DICTIONARY), system messages (STATUS/SERVICES/STREAM/EVENT/PROCEDURE_CALL). 34 unit tests. - services.ts — ServiceCache built from KRPC.GetServices() response. Lookup by (service, procedure), enum value/name resolution. 12 tests. - service-client.ts — KrpcServices: high-level invoke-by-name client. loadServices() helper to connect + load catalog. 9 integration tests with a mock kRPC server. - schema.ts — added Set/Dictionary/Event/Expression types so the decoder can handle system messages without external .proto files. Also fixed a bug where 'STREAM' was being encoded as 0 due to protobufjs's nested-enum string lookup. ksp-bridge - extract.ts — the actual SpaceCenter calls. ~280 procedure calls per poll for a typical KSP save (UT, bodies, vessels, then per-body and per-vessel class methods in parallel). Build the UniverseSnapshot. - krpc-adapter.ts — rewrote to use KrpcServices (typed) instead of the stub extract function. Supports an optional injected services for testing. - bridge.ts — uses the new ExtractedState type and buildSnapshot. - index.ts — connects to kRPC; falls back to mock mode if no server. - convert.ts — backward-compat shim, re-exports from extract.ts. The ksp-bridge can now talk to a real KSP install. We do NOT need the kRPC mod's .proto files on disk — the server's GetServices() response is the source of truth for type info. Documented the full list of procedures we call, the kRPC value encoding, and the new architecture in ksp/README.md. Tests: 119 total, all green. Typecheck and build clean across all 11 projects. Bonus: fixed an integer-overflow bug in the krpc-client connect() handshake (was passing 'RPC'/'STREAM' strings to protobufjs; its nested-enum string lookup silently encodes as 0, which made the stream handshake send the wrong type. Switched to numeric codes.)
59 lines
1.7 KiB
TypeScript
59 lines
1.7 KiB
TypeScript
/**
|
|
* @kerbal-rt/krpc-client — TypeScript client for the kRPC protobuf
|
|
* protocol used by the Kerbal Space Program kRPC mod.
|
|
*
|
|
* Provides:
|
|
* - KRPCClient: high-level wrapper with connect/invoke/addStream/close
|
|
* - sendMessage / recvMessage / recvRawMessage / encodeVarint / decodeVarint:
|
|
* low-level wire-format helpers
|
|
* - KRPC namespace: protobufjs types for the kRPC meta-protocol
|
|
* - KrpcType / TypeCode: runtime representation of kRPC type descriptors
|
|
* - decodeValue / encodeValue: kRPC value codec (primitives, classes,
|
|
* enums, collections, system messages)
|
|
* - ServiceCache: a Type index built from KRPC.GetServices()
|
|
* - KrpcServices: high-level invoke-by-name client
|
|
*
|
|
* For the service-specific types (SpaceCenter.Vessel, Orbit, etc.) we do
|
|
* NOT need to load the kRPC mod's .proto files. The server's
|
|
* GetServices() response contains everything we need to encode/decode
|
|
* values. See ./service-client.ts for the details.
|
|
*/
|
|
export {
|
|
KRPCClient,
|
|
type ProcedureCallRequest,
|
|
type KRPCClientOptions,
|
|
type StreamHandler,
|
|
} from './client.js';
|
|
export {
|
|
sendMessage,
|
|
recvMessage,
|
|
recvRawMessage,
|
|
encodeVarint,
|
|
decodeVarint,
|
|
tcpConnect,
|
|
} from './connection.js';
|
|
export { KRPC, encodeMessage, decodeMessage, MESSAGE_TYPES } from './schema.js';
|
|
export {
|
|
TypeCode,
|
|
decodeKrpcType,
|
|
typeName,
|
|
type KrpcType,
|
|
type TypeCodeValue,
|
|
type RawKrpcTypeMessage,
|
|
} from './types.js';
|
|
export {
|
|
decodeValue,
|
|
encodeValue,
|
|
decodeDouble,
|
|
decodeFloat,
|
|
decodeSint32,
|
|
decodeUint32,
|
|
decodeUint64,
|
|
decodeBool,
|
|
decodeString,
|
|
decodeBytes,
|
|
type DecodedValue,
|
|
} from './decoder.js';
|
|
export { ServiceCache } from './services.js';
|
|
export { KrpcServices, loadServices, type KrpcInvokeError } from './service-client.js';
|