feat: initial schemas and sample convos
This commit is contained in:
parent
d9195c5f95
commit
f36172615f
3
misc/typia-proof-of-concept/.gitignore
vendored
Normal file
3
misc/typia-proof-of-concept/.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
/dist
|
||||
/node_modules
|
||||
/yarn.lock
|
20
package.json
Normal file
20
package.json
Normal file
@ -0,0 +1,20 @@
|
||||
{
|
||||
"name": "schemas",
|
||||
"version": "1.0.0",
|
||||
"main": "dist/index.js",
|
||||
"license": "MIT",
|
||||
"devDependencies": {
|
||||
"@types/node": "^20.11.30",
|
||||
"ts-node": "^10.9.2",
|
||||
"ts-patch": "^3.1.2",
|
||||
"typescript": "5.4.2"
|
||||
},
|
||||
"dependencies": {
|
||||
"typia": "^5.5.7"
|
||||
},
|
||||
"scripts": {
|
||||
"prepare": "ts-patch install && typia patch",
|
||||
"compile": "tsc",
|
||||
"cr": "tsc && node dist/index.js"
|
||||
}
|
||||
}
|
180
src/index.ts
Normal file
180
src/index.ts
Normal file
@ -0,0 +1,180 @@
|
||||
import { AcaDefect, AcaFuelLow, AcaHeadingToBase, Message, MissileToOwnshipDetected, RequestApprovalToAttack } from "./schema";
|
||||
|
||||
const samples: Array<Message> = [
|
||||
// example convo 1: high priority, low threat, no collateral
|
||||
{
|
||||
id: 0,
|
||||
priority: 8,
|
||||
kind: "RequestApprovalToAttack",
|
||||
data: {
|
||||
target: {
|
||||
location: { lat: 48.600045, lng: 11.607559 },
|
||||
threatLevel: 0.2,
|
||||
type: "RS-12",
|
||||
},
|
||||
collateralDamage: "none",
|
||||
detectedByAca: 4,
|
||||
attackWeapon: {
|
||||
type: "ewSuppression",
|
||||
load: 0.6,
|
||||
},
|
||||
choiceWeight: 0.5,
|
||||
},
|
||||
} satisfies RequestApprovalToAttack,
|
||||
|
||||
// example convo 2: low priority, low threat, no collateral, weapons low
|
||||
{
|
||||
id: 0,
|
||||
priority: 2,
|
||||
kind: "RequestApprovalToAttack",
|
||||
data: {
|
||||
target: {
|
||||
location: { lat: 48.648044, lng: 11.594554 },
|
||||
threatLevel: 0.25,
|
||||
type: "RS-10",
|
||||
},
|
||||
collateralDamage: "none",
|
||||
detectedByAca: 2,
|
||||
attackWeapon: {
|
||||
type: "kinetic",
|
||||
load: 0.1,
|
||||
},
|
||||
choiceWeight: -0.2,
|
||||
},
|
||||
} satisfies RequestApprovalToAttack,
|
||||
|
||||
// fuel low on aca
|
||||
{
|
||||
id: 0,
|
||||
priority: 5,
|
||||
kind: "AcaFuelLow",
|
||||
data: {
|
||||
acaId: 5,
|
||||
fuelLevel: 0.1,
|
||||
}
|
||||
} satisfies AcaFuelLow,
|
||||
|
||||
// example convo 3: low priority, low threat, no collateral
|
||||
{
|
||||
id: 0,
|
||||
priority: 3,
|
||||
kind: "RequestApprovalToAttack",
|
||||
data: {
|
||||
target: {
|
||||
location: { lat: 48.630549, lng: 11.583752 },
|
||||
threatLevel: 0.15,
|
||||
type: "AR-5",
|
||||
},
|
||||
collateralDamage: "none",
|
||||
detectedByAca: 1,
|
||||
attackWeapon: {
|
||||
type: "ewSuppression",
|
||||
load: 0.8,
|
||||
},
|
||||
choiceWeight: 0.3,
|
||||
},
|
||||
} satisfies RequestApprovalToAttack,
|
||||
|
||||
// aca that previously send low fuel is now heading to base
|
||||
{
|
||||
id: 0,
|
||||
priority: 5,
|
||||
kind: "AcaHeadingToBase",
|
||||
data: {
|
||||
acaId: 5,
|
||||
reason: "fuelLow",
|
||||
}
|
||||
} satisfies AcaHeadingToBase,
|
||||
|
||||
// example convo 4: low priority, high threat, no collateral
|
||||
{
|
||||
id: 0,
|
||||
priority: 3,
|
||||
kind: "RequestApprovalToAttack",
|
||||
data: {
|
||||
target: {
|
||||
location: { lat: 48.607569, lng: 11.582834 },
|
||||
threatLevel: 0.9,
|
||||
type: "RS-12",
|
||||
},
|
||||
collateralDamage: "none",
|
||||
detectedByAca: 2,
|
||||
attackWeapon: {
|
||||
type: "ewSuppression",
|
||||
load: 0.7,
|
||||
},
|
||||
choiceWeight: 0,
|
||||
},
|
||||
} satisfies RequestApprovalToAttack,
|
||||
|
||||
// example convo 5: missile heading towards ownship, weapons low on aca
|
||||
{
|
||||
id: 0,
|
||||
priority: 10,
|
||||
kind: "MissileToOwnshipDetected",
|
||||
data: {
|
||||
missileLocation: { lat: 48.603579, lng: 11.592345 },
|
||||
survivability: 0.8,
|
||||
detectedByAca: 1,
|
||||
acaAttackWeapon: {
|
||||
type: "veryIntimidatingWeaponName",
|
||||
load: 0.2,
|
||||
},
|
||||
choiceWeight: 1,
|
||||
},
|
||||
} satisfies MissileToOwnshipDetected,
|
||||
|
||||
// defect on aca
|
||||
{
|
||||
id: 0,
|
||||
priority: 7,
|
||||
kind: "AcaDefect",
|
||||
data: {
|
||||
acaId: 1,
|
||||
message: "A screw came loose mid-flight.",
|
||||
},
|
||||
} satisfies AcaDefect,
|
||||
|
||||
// example convo 6: high priority, low threat, possible collateral
|
||||
{
|
||||
id: 0,
|
||||
priority: 8,
|
||||
kind: "RequestApprovalToAttack",
|
||||
data: {
|
||||
target: {
|
||||
location: { lat: 48.599382, lng: 11.593753 },
|
||||
threatLevel: 0.1,
|
||||
type: "DRDX-1",
|
||||
},
|
||||
collateralDamage: "complex",
|
||||
detectedByAca: 3,
|
||||
attackWeapon: {
|
||||
type: "kinetic",
|
||||
load: 0.5,
|
||||
},
|
||||
choiceWeight: -0.6,
|
||||
},
|
||||
} satisfies RequestApprovalToAttack,
|
||||
|
||||
// example convo 7: high priority, low threat, no collateral, detected by ownship
|
||||
{
|
||||
id: 0,
|
||||
priority: 7,
|
||||
kind: "RequestApprovalToAttack",
|
||||
data: {
|
||||
target: {
|
||||
location: { lat: 48.599382, lng: 11.593753 },
|
||||
threatLevel: 0.15,
|
||||
type: "DRDX-1",
|
||||
},
|
||||
collateralDamage: "none",
|
||||
attackWeapon: {
|
||||
type: "kinetic",
|
||||
load: 0.5,
|
||||
},
|
||||
choiceWeight: 0.4,
|
||||
},
|
||||
} satisfies RequestApprovalToAttack,
|
||||
];
|
||||
|
||||
console.log(samples);
|
67
src/schema.ts
Normal file
67
src/schema.ts
Normal file
@ -0,0 +1,67 @@
|
||||
import { tags } from "typia";
|
||||
|
||||
|
||||
/* messages *******************************************************************/
|
||||
|
||||
export type Message = RequestApprovalToAttack | AcaFuelLow | MissileToOwnshipDetected | AcaDefect | AcaHeadingToBase;
|
||||
|
||||
export type BaseMessage<TKind extends string, TData extends object> = {
|
||||
id: Id,
|
||||
priority: Priority,
|
||||
kind: TKind,
|
||||
data: TData,
|
||||
};
|
||||
|
||||
export type RequestApprovalToAttack = BaseMessage<"RequestApprovalToAttack", {
|
||||
target: Target,
|
||||
collateralDamage: "none" | "simple" | "complex",
|
||||
detectedByAca?: Id,
|
||||
attackWeapon: Weapon,
|
||||
choiceWeight: Range<-1, 1>, // specifies which choice option to prefer, -1: deny, 1: approve
|
||||
}>;
|
||||
|
||||
export type MissileToOwnshipDetected = BaseMessage<"MissileToOwnshipDetected", {
|
||||
missileLocation: GeoPoint,
|
||||
survivability: Range<0, 1>,
|
||||
detectedByAca?: Id,
|
||||
acaAttackWeapon?: Weapon,
|
||||
choiceWeight: Range<-1, 1>, // specifies which choice option to prefer, -1: avoid, 1: intervene
|
||||
}>
|
||||
|
||||
export type AcaFuelLow = BaseMessage<"AcaFuelLow", {
|
||||
acaId: Id,
|
||||
fuelLevel: Range<0, 1>,
|
||||
}>;
|
||||
|
||||
export type AcaDefect = BaseMessage<"AcaDefect", {
|
||||
acaId: Id,
|
||||
message: string,
|
||||
}>
|
||||
|
||||
export type AcaHeadingToBase = BaseMessage<"AcaHeadingToBase", {
|
||||
acaId: Id,
|
||||
reason?: "fuelLow" | "weaponsLow",
|
||||
}>
|
||||
|
||||
|
||||
/* utility types **************************************************************/
|
||||
|
||||
export type Id = number & tags.Type<"uint64">;
|
||||
export type Priority = number & tags.Type<"uint32"> & tags.Maximum<10>;
|
||||
export type Range<From extends number, To extends number> = number & tags.Type<"float"> & tags.Minimum<From> & tags.Maximum<To>;
|
||||
|
||||
export type Target = {
|
||||
location: GeoPoint,
|
||||
threatLevel: Range<0, 1>,
|
||||
type: string,
|
||||
};
|
||||
|
||||
export type GeoPoint = {
|
||||
lat: Range<-90, 90>,
|
||||
lng: Range<-180, 180>,
|
||||
};
|
||||
|
||||
export type Weapon = {
|
||||
type: string,
|
||||
load: Range<0, 1>,
|
||||
};
|
21
tsconfig.json
Normal file
21
tsconfig.json
Normal file
@ -0,0 +1,21 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "es2016",
|
||||
"module": "commonjs",
|
||||
"esModuleInterop": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"strict": true,
|
||||
"skipLibCheck": true,
|
||||
"rootDir": "src/",
|
||||
"outDir": "dist/",
|
||||
"strictNullChecks": true,
|
||||
"plugins": [
|
||||
{
|
||||
"transform": "typia/lib/transform"
|
||||
}
|
||||
]
|
||||
},
|
||||
"include": [
|
||||
"src/"
|
||||
]
|
||||
}
|
Loading…
Reference in New Issue
Block a user