@gamekits/ai-core 0.1.0-alpha.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/composition/create-ai-module.d.ts +5 -0
- package/dist/composition/create-ai-module.d.ts.map +1 -0
- package/dist/composition/create-ai-runtime.d.ts +4 -0
- package/dist/composition/create-ai-runtime.d.ts.map +1 -0
- package/dist/composition/index.d.ts +4 -0
- package/dist/composition/index.d.ts.map +1 -0
- package/dist/composition/options.d.ts +48 -0
- package/dist/composition/options.d.ts.map +1 -0
- package/dist/composition/registry.d.ts +4 -0
- package/dist/composition/registry.d.ts.map +1 -0
- package/dist/composition/runtime-config.d.ts +26 -0
- package/dist/composition/runtime-config.d.ts.map +1 -0
- package/dist/contracts/agent-binding.d.ts +9 -0
- package/dist/contracts/agent-binding.d.ts.map +1 -0
- package/dist/contracts/agent-context.d.ts +21 -0
- package/dist/contracts/agent-context.d.ts.map +1 -0
- package/dist/contracts/blackboard-value.d.ts +5 -0
- package/dist/contracts/blackboard-value.d.ts.map +1 -0
- package/dist/contracts/clone-binding.d.ts +3 -0
- package/dist/contracts/clone-binding.d.ts.map +1 -0
- package/dist/contracts/clone-runtime-value.d.ts +3 -0
- package/dist/contracts/clone-runtime-value.d.ts.map +1 -0
- package/dist/contracts/errors.d.ts +8 -0
- package/dist/contracts/errors.d.ts.map +1 -0
- package/dist/contracts/index.d.ts +10 -0
- package/dist/contracts/index.d.ts.map +1 -0
- package/dist/contracts/intent.d.ts +42 -0
- package/dist/contracts/intent.d.ts.map +1 -0
- package/dist/contracts/navigation-access.d.ts +16 -0
- package/dist/contracts/navigation-access.d.ts.map +1 -0
- package/dist/contracts/navigation-queries.d.ts +3 -0
- package/dist/contracts/navigation-queries.d.ts.map +1 -0
- package/dist/contracts/physics-queries.d.ts +3 -0
- package/dist/contracts/physics-queries.d.ts.map +1 -0
- package/dist/contracts/shared-fact-queries.d.ts +7 -0
- package/dist/contracts/shared-fact-queries.d.ts.map +1 -0
- package/dist/contracts/world-read-model.d.ts +9 -0
- package/dist/contracts/world-read-model.d.ts.map +1 -0
- package/dist/controller/agent-context-factory.d.ts +23 -0
- package/dist/controller/agent-context-factory.d.ts.map +1 -0
- package/dist/controller/agent-state.d.ts +29 -0
- package/dist/controller/agent-state.d.ts.map +1 -0
- package/dist/controller/create-agent-state.d.ts +12 -0
- package/dist/controller/create-agent-state.d.ts.map +1 -0
- package/dist/controller/create-ai-handle.d.ts +8 -0
- package/dist/controller/create-ai-handle.d.ts.map +1 -0
- package/dist/controller/goal-controller.d.ts +21 -0
- package/dist/controller/goal-controller.d.ts.map +1 -0
- package/dist/controller/index.d.ts +3 -0
- package/dist/controller/index.d.ts.map +1 -0
- package/dist/controller/runtime.d.ts +29 -0
- package/dist/controller/runtime.d.ts.map +1 -0
- package/dist/create-ai-runtime-Cd-h8AF9.js +1867 -0
- package/dist/decision/cooldowns.d.ts +2 -0
- package/dist/decision/cooldowns.d.ts.map +1 -0
- package/dist/decision/goal-scoring.d.ts +12 -0
- package/dist/decision/goal-scoring.d.ts.map +1 -0
- package/dist/decision/goal-selection.d.ts +17 -0
- package/dist/decision/goal-selection.d.ts.map +1 -0
- package/dist/decision/index.d.ts +3 -0
- package/dist/decision/index.d.ts.map +1 -0
- package/dist/decision/utility-curve.d.ts +4 -0
- package/dist/decision/utility-curve.d.ts.map +1 -0
- package/dist/decision/utility.d.ts +47 -0
- package/dist/decision/utility.d.ts.map +1 -0
- package/dist/definition/agent-definition-compiler.d.ts +12 -0
- package/dist/definition/agent-definition-compiler.d.ts.map +1 -0
- package/dist/definition/agent-definition.d.ts +12 -0
- package/dist/definition/agent-definition.d.ts.map +1 -0
- package/dist/definition/ai-data-types.d.ts +16 -0
- package/dist/definition/ai-data-types.d.ts.map +1 -0
- package/dist/definition/clone-definitions.d.ts +9 -0
- package/dist/definition/clone-definitions.d.ts.map +1 -0
- package/dist/definition/compiled-agent-definition.d.ts +23 -0
- package/dist/definition/compiled-agent-definition.d.ts.map +1 -0
- package/dist/definition/goal-definition.d.ts +14 -0
- package/dist/definition/goal-definition.d.ts.map +1 -0
- package/dist/definition/index.d.ts +6 -0
- package/dist/definition/index.d.ts.map +1 -0
- package/dist/definition/sensor-definition.d.ts +8 -0
- package/dist/definition/sensor-definition.d.ts.map +1 -0
- package/dist/definition/task-definition.d.ts +10 -0
- package/dist/definition/task-definition.d.ts.map +1 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +205 -0
- package/dist/memory/blackboard.d.ts +24 -0
- package/dist/memory/blackboard.d.ts.map +1 -0
- package/dist/memory/index.d.ts +3 -0
- package/dist/memory/index.d.ts.map +1 -0
- package/dist/observability/index.d.ts +3 -0
- package/dist/observability/index.d.ts.map +1 -0
- package/dist/observability/snapshot-projection.d.ts +17 -0
- package/dist/observability/snapshot-projection.d.ts.map +1 -0
- package/dist/observability/snapshot.d.ts +32 -0
- package/dist/observability/snapshot.d.ts.map +1 -0
- package/dist/observability/trace-recorder.d.ts +17 -0
- package/dist/observability/trace-recorder.d.ts.map +1 -0
- package/dist/observability/trace-store.d.ts +15 -0
- package/dist/observability/trace-store.d.ts.map +1 -0
- package/dist/observability/trace.d.ts +29 -0
- package/dist/observability/trace.d.ts.map +1 -0
- package/dist/perception/index.d.ts +3 -0
- package/dist/perception/index.d.ts.map +1 -0
- package/dist/perception/perception-controller.d.ts +27 -0
- package/dist/perception/perception-controller.d.ts.map +1 -0
- package/dist/perception/perception-fact.d.ts +12 -0
- package/dist/perception/perception-fact.d.ts.map +1 -0
- package/dist/perception/perception-memory.d.ts +8 -0
- package/dist/perception/perception-memory.d.ts.map +1 -0
- package/dist/perception/sensor-sampler.d.ts +8 -0
- package/dist/perception/sensor-sampler.d.ts.map +1 -0
- package/dist/persistence/checkpoint-compatibility.d.ts +4 -0
- package/dist/persistence/checkpoint-compatibility.d.ts.map +1 -0
- package/dist/persistence/checkpoint-projection.d.ts +5 -0
- package/dist/persistence/checkpoint-projection.d.ts.map +1 -0
- package/dist/persistence/checkpoint-validation.d.ts +3 -0
- package/dist/persistence/checkpoint-validation.d.ts.map +1 -0
- package/dist/persistence/checkpoint.d.ts +30 -0
- package/dist/persistence/checkpoint.d.ts.map +1 -0
- package/dist/persistence/index.d.ts +3 -0
- package/dist/persistence/index.d.ts.map +1 -0
- package/dist/persistence/restore-binding.d.ts +4 -0
- package/dist/persistence/restore-binding.d.ts.map +1 -0
- package/dist/persistence/restore-task-state.d.ts +4 -0
- package/dist/persistence/restore-task-state.d.ts.map +1 -0
- package/dist/persistence/save-contributor.d.ts +15 -0
- package/dist/persistence/save-contributor.d.ts.map +1 -0
- package/dist/scheduler/decision-scheduler.d.ts +20 -0
- package/dist/scheduler/decision-scheduler.d.ts.map +1 -0
- package/dist/scheduler/due-work.d.ts +8 -0
- package/dist/scheduler/due-work.d.ts.map +1 -0
- package/dist/scheduler/index.d.ts +2 -0
- package/dist/scheduler/index.d.ts.map +1 -0
- package/dist/scheduler/reclassify-agent.d.ts +13 -0
- package/dist/scheduler/reclassify-agent.d.ts.map +1 -0
- package/dist/scheduler/scheduler-class.d.ts +7 -0
- package/dist/scheduler/scheduler-class.d.ts.map +1 -0
- package/dist/scheduler/timing.d.ts +3 -0
- package/dist/scheduler/timing.d.ts.map +1 -0
- package/dist/task/clone-task-state.d.ts +3 -0
- package/dist/task/clone-task-state.d.ts.map +1 -0
- package/dist/task/index.d.ts +2 -0
- package/dist/task/index.d.ts.map +1 -0
- package/dist/task/task-controller.d.ts +41 -0
- package/dist/task/task-controller.d.ts.map +1 -0
- package/dist/task/task-executor.d.ts +37 -0
- package/dist/task/task-executor.d.ts.map +1 -0
- package/dist/testing/index.d.ts +3 -0
- package/dist/testing/index.d.ts.map +1 -0
- package/dist/testing/index.js +126 -0
- package/dist/testing/memory-runtime-fixture.d.ts +17 -0
- package/dist/testing/memory-runtime-fixture.d.ts.map +1 -0
- package/dist/testing/runtime-conformance.d.ts +14 -0
- package/dist/testing/runtime-conformance.d.ts.map +1 -0
- package/package.json +39 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cooldowns.d.ts","sourceRoot":"","sources":["../../src/decision/cooldowns.ts"],"names":[],"mappings":"AAAA,wBAAgB,oBAAoB,CAAC,SAAS,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI,CAM1F"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { AiAgentReadContext } from "../contracts/agent-context";
|
|
2
|
+
import type { AiGoalDefinition } from "../definition/goal-definition";
|
|
3
|
+
import type { AiGoalScore, AiUtilityInputResolver } from "./utility";
|
|
4
|
+
export type ScoreAiGoalsOptions = {
|
|
5
|
+
goals: readonly AiGoalDefinition[];
|
|
6
|
+
context: AiAgentReadContext;
|
|
7
|
+
cooldowns: ReadonlyMap<string, number>;
|
|
8
|
+
elapsed: number;
|
|
9
|
+
resolveInput(id: string): AiUtilityInputResolver | undefined;
|
|
10
|
+
};
|
|
11
|
+
export declare function scoreAiGoals(options: ScoreAiGoalsOptions): AiGoalScore[];
|
|
12
|
+
//# sourceMappingURL=goal-scoring.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"goal-scoring.d.ts","sourceRoot":"","sources":["../../src/decision/goal-scoring.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AACrE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AAEtE,OAAO,KAAK,EAAE,WAAW,EAAE,sBAAsB,EAAE,MAAM,WAAW,CAAC;AAErE,MAAM,MAAM,mBAAmB,GAAG;IAChC,KAAK,EAAE,SAAS,gBAAgB,EAAE,CAAC;IACnC,OAAO,EAAE,kBAAkB,CAAC;IAC5B,SAAS,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACvC,OAAO,EAAE,MAAM,CAAC;IAChB,YAAY,CAAC,EAAE,EAAE,MAAM,GAAG,sBAAsB,GAAG,SAAS,CAAC;CAC9D,CAAC;AAEF,wBAAgB,YAAY,CAAC,OAAO,EAAE,mBAAmB,GAAG,WAAW,EAAE,CAkCxE"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { AiGoalScore } from "./utility";
|
|
2
|
+
export type AiGoalDecisionReason = "initial" | "unchanged" | "commitment-active" | "switch-threshold" | "interrupt-policy" | "no-eligible-goal" | "higher-score" | "current-ineligible";
|
|
3
|
+
export type AiGoalDecision = {
|
|
4
|
+
action: "select" | "keep" | "clear";
|
|
5
|
+
reason: AiGoalDecisionReason;
|
|
6
|
+
candidate: AiGoalScore | undefined;
|
|
7
|
+
current: AiGoalScore | undefined;
|
|
8
|
+
};
|
|
9
|
+
export declare function selectAiGoal(options: {
|
|
10
|
+
scores: readonly AiGoalScore[];
|
|
11
|
+
currentGoalId: string | undefined;
|
|
12
|
+
committedUntil: number | undefined;
|
|
13
|
+
elapsed: number;
|
|
14
|
+
switchThreshold: number;
|
|
15
|
+
canInterrupt: boolean;
|
|
16
|
+
}): AiGoalDecision;
|
|
17
|
+
//# sourceMappingURL=goal-selection.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"goal-selection.d.ts","sourceRoot":"","sources":["../../src/decision/goal-selection.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAE7C,MAAM,MAAM,oBAAoB,GAC5B,SAAS,GACT,WAAW,GACX,mBAAmB,GACnB,kBAAkB,GAClB,kBAAkB,GAClB,kBAAkB,GAClB,cAAc,GACd,oBAAoB,CAAC;AAEzB,MAAM,MAAM,cAAc,GAAG;IAC3B,MAAM,EAAE,QAAQ,GAAG,MAAM,GAAG,OAAO,CAAC;IACpC,MAAM,EAAE,oBAAoB,CAAC;IAC7B,SAAS,EAAE,WAAW,GAAG,SAAS,CAAC;IACnC,OAAO,EAAE,WAAW,GAAG,SAAS,CAAC;CAClC,CAAC;AAEF,wBAAgB,YAAY,CAAC,OAAO,EAAE;IACpC,MAAM,EAAE,SAAS,WAAW,EAAE,CAAC;IAC/B,aAAa,EAAE,MAAM,GAAG,SAAS,CAAC;IAClC,cAAc,EAAE,MAAM,GAAG,SAAS,CAAC;IACnC,OAAO,EAAE,MAAM,CAAC;IAChB,eAAe,EAAE,MAAM,CAAC;IACxB,YAAY,EAAE,OAAO,CAAC;CACvB,GAAG,cAAc,CAyCjB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/decision/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,OAAO,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utility-curve.d.ts","sourceRoot":"","sources":["../../src/decision/utility-curve.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAEhD,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,cAAc,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAgBjF;AA6BD,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAEzD"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { AiAgentReadContext } from "../contracts/agent-context";
|
|
2
|
+
export type AiUtilityCurve = {
|
|
3
|
+
type: "linear";
|
|
4
|
+
min?: number | undefined;
|
|
5
|
+
max?: number | undefined;
|
|
6
|
+
} | {
|
|
7
|
+
type: "inverse";
|
|
8
|
+
min?: number | undefined;
|
|
9
|
+
max?: number | undefined;
|
|
10
|
+
} | {
|
|
11
|
+
type: "step";
|
|
12
|
+
threshold: number;
|
|
13
|
+
below?: number | undefined;
|
|
14
|
+
above?: number | undefined;
|
|
15
|
+
} | {
|
|
16
|
+
type: "power";
|
|
17
|
+
exponent: number;
|
|
18
|
+
min?: number | undefined;
|
|
19
|
+
max?: number | undefined;
|
|
20
|
+
} | {
|
|
21
|
+
type: "points";
|
|
22
|
+
points: Array<{
|
|
23
|
+
x: number;
|
|
24
|
+
y: number;
|
|
25
|
+
}>;
|
|
26
|
+
};
|
|
27
|
+
export type AiConsiderationDefinition = {
|
|
28
|
+
input: string;
|
|
29
|
+
curve: AiUtilityCurve;
|
|
30
|
+
weight?: number | undefined;
|
|
31
|
+
};
|
|
32
|
+
export type AiUtilityInputResolver = {
|
|
33
|
+
id: string;
|
|
34
|
+
read(context: AiAgentReadContext, consideration: AiConsiderationDefinition): number;
|
|
35
|
+
};
|
|
36
|
+
export type AiGoalScore = {
|
|
37
|
+
goalId: string;
|
|
38
|
+
score: number;
|
|
39
|
+
eligible: boolean;
|
|
40
|
+
considerations: Array<{
|
|
41
|
+
input: string;
|
|
42
|
+
raw: number;
|
|
43
|
+
curved: number;
|
|
44
|
+
weight: number;
|
|
45
|
+
}>;
|
|
46
|
+
};
|
|
47
|
+
//# sourceMappingURL=utility.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utility.d.ts","sourceRoot":"","sources":["../../src/decision/utility.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAErE,MAAM,MAAM,cAAc,GACtB;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,GAAG,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAAC,GAAG,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;CAAE,GACtE;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,GAAG,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAAC,GAAG,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;CAAE,GACvE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;CAAE,GAC3F;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAC;IAAC,GAAG,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAAC,GAAG,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;CAAE,GACvF;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,MAAM,EAAE,KAAK,CAAC;QAAE,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,CAAA;CAAE,CAAC;AAEhE,MAAM,MAAM,yBAAyB,GAAG;IACtC,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,cAAc,CAAC;IACtB,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CAC7B,CAAC;AAEF,MAAM,MAAM,sBAAsB,GAAG;IACnC,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,CAAC,OAAO,EAAE,kBAAkB,EAAE,aAAa,EAAE,yBAAyB,GAAG,MAAM,CAAC;CACrF,CAAC;AAEF,MAAM,MAAM,WAAW,GAAG;IACxB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,OAAO,CAAC;IAClB,cAAc,EAAE,KAAK,CAAC;QACpB,KAAK,EAAE,MAAM,CAAC;QACd,GAAG,EAAE,MAAM,CAAC;QACZ,MAAM,EAAE,MAAM,CAAC;QACf,MAAM,EAAE,MAAM,CAAC;KAChB,CAAC,CAAC;CACJ,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { DataRegistry } from "@gamekits/data";
|
|
2
|
+
import type { AiDefinitionRuntimeRegistries, CompiledAiAgentDefinition } from "./compiled-agent-definition";
|
|
3
|
+
export type AiAgentDefinitionCompiler = {
|
|
4
|
+
compile(definitionId: string): CompiledAiAgentDefinition;
|
|
5
|
+
size(): number;
|
|
6
|
+
clear(): void;
|
|
7
|
+
};
|
|
8
|
+
export declare function createAiAgentDefinitionCompiler(options: {
|
|
9
|
+
dataRegistry: DataRegistry;
|
|
10
|
+
registries: AiDefinitionRuntimeRegistries;
|
|
11
|
+
}): AiAgentDefinitionCompiler;
|
|
12
|
+
//# sourceMappingURL=agent-definition-compiler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent-definition-compiler.d.ts","sourceRoot":"","sources":["../../src/definition/agent-definition-compiler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAUlD,OAAO,KAAK,EACV,6BAA6B,EAC7B,yBAAyB,EAC1B,MAAM,6BAA6B,CAAC;AAKrC,MAAM,MAAM,yBAAyB,GAAG;IACtC,OAAO,CAAC,YAAY,EAAE,MAAM,GAAG,yBAAyB,CAAC;IACzD,IAAI,IAAI,MAAM,CAAC;IACf,KAAK,IAAI,IAAI,CAAC;CACf,CAAC;AAEF,wBAAgB,+BAA+B,CAAC,OAAO,EAAE;IACvD,YAAY,EAAE,YAAY,CAAC;IAC3B,UAAU,EAAE,6BAA6B,CAAC;CAC3C,GAAG,yBAAyB,CA2F5B"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { DataRef } from "@gamekits/data";
|
|
2
|
+
export type AiAgentDefinition = {
|
|
3
|
+
id: string;
|
|
4
|
+
sensors: Array<DataRef<"ai.sensor">>;
|
|
5
|
+
goals: Array<DataRef<"ai.goal">>;
|
|
6
|
+
decisionIntervalMs: number;
|
|
7
|
+
memoryLimit: number;
|
|
8
|
+
blackboardLimit?: number | undefined;
|
|
9
|
+
schedulerClass?: string | undefined;
|
|
10
|
+
tags?: string[] | undefined;
|
|
11
|
+
};
|
|
12
|
+
//# sourceMappingURL=agent-definition.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent-definition.d.ts","sourceRoot":"","sources":["../../src/definition/agent-definition.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAE7C,MAAM,MAAM,iBAAiB,GAAG;IAC9B,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,KAAK,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC;IACrC,KAAK,EAAE,KAAK,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC;IACjC,kBAAkB,EAAE,MAAM,CAAC;IAC3B,WAAW,EAAE,MAAM,CAAC;IACpB,eAAe,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACrC,cAAc,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACpC,IAAI,CAAC,EAAE,MAAM,EAAE,GAAG,SAAS,CAAC;CAC7B,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { DataTypeDefinition } from "@gamekits/data";
|
|
2
|
+
import type { AiAgentDefinition } from "./agent-definition";
|
|
3
|
+
import type { AiGoalDefinition } from "./goal-definition";
|
|
4
|
+
import type { AiSensorDefinition } from "./sensor-definition";
|
|
5
|
+
import type { AiTaskDefinition } from "./task-definition";
|
|
6
|
+
export declare const AI_AGENT_TYPE = "ai.agent";
|
|
7
|
+
export declare const AI_SENSOR_TYPE = "ai.sensor";
|
|
8
|
+
export declare const AI_GOAL_TYPE = "ai.goal";
|
|
9
|
+
export declare const AI_TASK_TYPE = "ai.task";
|
|
10
|
+
export type AiDataTypeDefinition = DataTypeDefinition<AiAgentDefinition> | DataTypeDefinition<AiSensorDefinition> | DataTypeDefinition<AiGoalDefinition> | DataTypeDefinition<AiTaskDefinition>;
|
|
11
|
+
export declare function createAiDataTypes(): AiDataTypeDefinition[];
|
|
12
|
+
export declare function createAiAgentDataType(): DataTypeDefinition<AiAgentDefinition>;
|
|
13
|
+
export declare function createAiSensorDataType(): DataTypeDefinition<AiSensorDefinition>;
|
|
14
|
+
export declare function createAiGoalDataType(): DataTypeDefinition<AiGoalDefinition>;
|
|
15
|
+
export declare function createAiTaskDataType(): DataTypeDefinition<AiTaskDefinition>;
|
|
16
|
+
//# sourceMappingURL=ai-data-types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ai-data-types.d.ts","sourceRoot":"","sources":["../../src/definition/ai-data-types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAIV,kBAAkB,EACnB,MAAM,eAAe,CAAC;AAEvB,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAC5D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAC1D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAC9D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAE1D,eAAO,MAAM,aAAa,aAAa,CAAC;AACxC,eAAO,MAAM,cAAc,cAAc,CAAC;AAC1C,eAAO,MAAM,YAAY,YAAY,CAAC;AACtC,eAAO,MAAM,YAAY,YAAY,CAAC;AAEtC,MAAM,MAAM,oBAAoB,GAC5B,kBAAkB,CAAC,iBAAiB,CAAC,GACrC,kBAAkB,CAAC,kBAAkB,CAAC,GACtC,kBAAkB,CAAC,gBAAgB,CAAC,GACpC,kBAAkB,CAAC,gBAAgB,CAAC,CAAC;AAEzC,wBAAgB,iBAAiB,IAAI,oBAAoB,EAAE,CAO1D;AAED,wBAAgB,qBAAqB,IAAI,kBAAkB,CAAC,iBAAiB,CAAC,CAkD7E;AAED,wBAAgB,sBAAsB,IAAI,kBAAkB,CAAC,kBAAkB,CAAC,CA6B/E;AAED,wBAAgB,oBAAoB,IAAI,kBAAkB,CAAC,gBAAgB,CAAC,CAmF3E;AAED,wBAAgB,oBAAoB,IAAI,kBAAkB,CAAC,gBAAgB,CAAC,CA0C3E"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { AiAgentDefinition } from "./agent-definition";
|
|
2
|
+
import type { AiGoalDefinition } from "./goal-definition";
|
|
3
|
+
import type { AiSensorDefinition } from "./sensor-definition";
|
|
4
|
+
import type { AiTaskDefinition } from "./task-definition";
|
|
5
|
+
export declare function cloneAiAgentDefinition(definition: AiAgentDefinition): AiAgentDefinition;
|
|
6
|
+
export declare function cloneAiSensorDefinition(sensor: AiSensorDefinition): AiSensorDefinition;
|
|
7
|
+
export declare function cloneAiGoalDefinition(goal: AiGoalDefinition): AiGoalDefinition;
|
|
8
|
+
export declare function cloneAiTaskDefinition(task: AiTaskDefinition): AiTaskDefinition;
|
|
9
|
+
//# sourceMappingURL=clone-definitions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"clone-definitions.d.ts","sourceRoot":"","sources":["../../src/definition/clone-definitions.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAC5D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAC1D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAC9D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAE1D,wBAAgB,sBAAsB,CAAC,UAAU,EAAE,iBAAiB,GAAG,iBAAiB,CAOvF;AAED,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,kBAAkB,GAAG,kBAAkB,CAMtF;AAED,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,gBAAgB,GAAG,gBAAgB,CAa9E;AAED,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,gBAAgB,GAAG,gBAAgB,CAM9E"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { AiUtilityInputResolver } from "../decision/utility";
|
|
2
|
+
import type { AiSensorSampler } from "../perception/sensor-sampler";
|
|
3
|
+
import type { AiSchedulerClass } from "../scheduler/scheduler-class";
|
|
4
|
+
import type { AiTaskExecutor } from "../task/task-executor";
|
|
5
|
+
import type { AiAgentDefinition } from "./agent-definition";
|
|
6
|
+
import type { AiGoalDefinition } from "./goal-definition";
|
|
7
|
+
import type { AiSensorDefinition } from "./sensor-definition";
|
|
8
|
+
import type { AiTaskDefinition } from "./task-definition";
|
|
9
|
+
export type CompiledAiAgentDefinition = {
|
|
10
|
+
definition: AiAgentDefinition;
|
|
11
|
+
sensors: AiSensorDefinition[];
|
|
12
|
+
goals: AiGoalDefinition[];
|
|
13
|
+
goalsById: Map<string, AiGoalDefinition>;
|
|
14
|
+
tasksById: Map<string, AiTaskDefinition>;
|
|
15
|
+
schedulerClass: AiSchedulerClass;
|
|
16
|
+
};
|
|
17
|
+
export type AiDefinitionRuntimeRegistries = {
|
|
18
|
+
sensors: ReadonlyMap<string, AiSensorSampler>;
|
|
19
|
+
inputs: ReadonlyMap<string, AiUtilityInputResolver>;
|
|
20
|
+
tasks: ReadonlyMap<string, AiTaskExecutor>;
|
|
21
|
+
schedulerClasses: ReadonlyMap<string, AiSchedulerClass>;
|
|
22
|
+
};
|
|
23
|
+
//# sourceMappingURL=compiled-agent-definition.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compiled-agent-definition.d.ts","sourceRoot":"","sources":["../../src/definition/compiled-agent-definition.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAClE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AACpE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AACrE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAC5D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAC1D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAC9D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAE1D,MAAM,MAAM,yBAAyB,GAAG;IACtC,UAAU,EAAE,iBAAiB,CAAC;IAC9B,OAAO,EAAE,kBAAkB,EAAE,CAAC;IAC9B,KAAK,EAAE,gBAAgB,EAAE,CAAC;IAC1B,SAAS,EAAE,GAAG,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAC;IACzC,SAAS,EAAE,GAAG,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAC;IACzC,cAAc,EAAE,gBAAgB,CAAC;CAClC,CAAC;AAEF,MAAM,MAAM,6BAA6B,GAAG;IAC1C,OAAO,EAAE,WAAW,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;IAC9C,MAAM,EAAE,WAAW,CAAC,MAAM,EAAE,sBAAsB,CAAC,CAAC;IACpD,KAAK,EAAE,WAAW,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;IAC3C,gBAAgB,EAAE,WAAW,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAC;CACzD,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { DataRef } from "@gamekits/data";
|
|
2
|
+
import type { AiConsiderationDefinition } from "../decision/utility";
|
|
3
|
+
export type AiGoalDefinition = {
|
|
4
|
+
id: string;
|
|
5
|
+
task: DataRef<"ai.task">;
|
|
6
|
+
considerations: AiConsiderationDefinition[];
|
|
7
|
+
weight?: number | undefined;
|
|
8
|
+
minScore?: number | undefined;
|
|
9
|
+
commitmentMs?: number | undefined;
|
|
10
|
+
switchThreshold?: number | undefined;
|
|
11
|
+
cooldownMs?: number | undefined;
|
|
12
|
+
tags?: string[] | undefined;
|
|
13
|
+
};
|
|
14
|
+
//# sourceMappingURL=goal-definition.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"goal-definition.d.ts","sourceRoot":"","sources":["../../src/definition/goal-definition.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,qBAAqB,CAAC;AAErE,MAAM,MAAM,gBAAgB,GAAG;IAC7B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,OAAO,CAAC,SAAS,CAAC,CAAC;IACzB,cAAc,EAAE,yBAAyB,EAAE,CAAC;IAC5C,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC5B,QAAQ,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC9B,YAAY,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAClC,eAAe,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACrC,UAAU,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAChC,IAAI,CAAC,EAAE,MAAM,EAAE,GAAG,SAAS,CAAC;CAC7B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/definition/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,oBAAoB,CAAC;AACnC,cAAc,mBAAmB,CAAC;AAClC,cAAc,qBAAqB,CAAC;AACpC,cAAc,mBAAmB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sensor-definition.d.ts","sourceRoot":"","sources":["../../src/definition/sensor-definition.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,kBAAkB,GAAG;IAC/B,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,CAAC;IAC3C,IAAI,CAAC,EAAE,MAAM,EAAE,GAAG,SAAS,CAAC;CAC7B,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export type AiTaskInterruptPolicy = "always" | "safe-point" | "never";
|
|
2
|
+
export type AiTaskDefinition = {
|
|
3
|
+
id: string;
|
|
4
|
+
executor: string;
|
|
5
|
+
interruptPolicy?: AiTaskInterruptPolicy | undefined;
|
|
6
|
+
timeoutMs?: number | undefined;
|
|
7
|
+
args?: Record<string, unknown> | undefined;
|
|
8
|
+
tags?: string[] | undefined;
|
|
9
|
+
};
|
|
10
|
+
//# sourceMappingURL=task-definition.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"task-definition.d.ts","sourceRoot":"","sources":["../../src/definition/task-definition.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,qBAAqB,GAAG,QAAQ,GAAG,YAAY,GAAG,OAAO,CAAC;AAEtE,MAAM,MAAM,gBAAgB,GAAG;IAC7B,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,EAAE,MAAM,CAAC;IACjB,eAAe,CAAC,EAAE,qBAAqB,GAAG,SAAS,CAAC;IACpD,SAAS,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC/B,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,CAAC;IAC3C,IAAI,CAAC,EAAE,MAAM,EAAE,GAAG,SAAS,CAAC;CAC7B,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export * from "./composition";
|
|
2
|
+
export * from "./contracts";
|
|
3
|
+
export * from "./controller";
|
|
4
|
+
export * from "./decision";
|
|
5
|
+
export * from "./definition";
|
|
6
|
+
export * from "./observability";
|
|
7
|
+
export * from "./perception";
|
|
8
|
+
export * from "./persistence";
|
|
9
|
+
export * from "./scheduler";
|
|
10
|
+
export * from "./task";
|
|
11
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,QAAQ,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
import { _ as createAiError, a as AI_SENSOR_TYPE, c as createAiDataTypes, d as createAiTaskDataType, f as evaluateAiUtilityCurve, g as AiError, h as createAiNavigationQueries, i as AI_GOAL_TYPE, l as createAiGoalDataType, m as createAiPhysicsQueries, n as AI_TRACE_KINDS, o as AI_TASK_TYPE, p as createAiSharedFactQueries, r as AI_AGENT_TYPE, s as createAiAgentDataType, t as createAiRuntime, u as createAiSensorDataType, v as createAiWorldReadModel } from "./create-ai-runtime-Cd-h8AF9.js";
|
|
2
|
+
import { defineGameModule } from "@gamekits/core";
|
|
3
|
+
//#region src/controller/create-ai-handle.ts
|
|
4
|
+
const handleStates = /* @__PURE__ */ new WeakMap();
|
|
5
|
+
function createAiHandle(options = {}) {
|
|
6
|
+
const state = {
|
|
7
|
+
id: options.id ?? "ai.handle",
|
|
8
|
+
runtime: void 0,
|
|
9
|
+
ownerId: void 0
|
|
10
|
+
};
|
|
11
|
+
const handle = {
|
|
12
|
+
bind(binding) {
|
|
13
|
+
requireBoundRuntime(state, "bind").bind(binding);
|
|
14
|
+
},
|
|
15
|
+
unbind(agentId, reason) {
|
|
16
|
+
requireBoundRuntime(state, "unbind").unbind(agentId, reason);
|
|
17
|
+
},
|
|
18
|
+
hasAgent(agentId) {
|
|
19
|
+
return requireBoundRuntime(state, "hasAgent").hasAgent(agentId);
|
|
20
|
+
},
|
|
21
|
+
observe(agentId, facts) {
|
|
22
|
+
requireBoundRuntime(state, "observe").observe(agentId, facts);
|
|
23
|
+
},
|
|
24
|
+
setBlackboard(agentId, key, value) {
|
|
25
|
+
requireBoundRuntime(state, "setBlackboard").setBlackboard(agentId, key, value);
|
|
26
|
+
},
|
|
27
|
+
deleteBlackboard(agentId, key) {
|
|
28
|
+
requireBoundRuntime(state, "deleteBlackboard").deleteBlackboard(agentId, key);
|
|
29
|
+
},
|
|
30
|
+
setSchedulerClass(agentId, schedulerClassId) {
|
|
31
|
+
requireBoundRuntime(state, "setSchedulerClass").setSchedulerClass(agentId, schedulerClassId);
|
|
32
|
+
},
|
|
33
|
+
getAgent(agentId) {
|
|
34
|
+
return requireBoundRuntime(state, "getAgent").getAgent(agentId);
|
|
35
|
+
},
|
|
36
|
+
listAgents() {
|
|
37
|
+
return requireBoundRuntime(state, "listAgents").listAgents();
|
|
38
|
+
},
|
|
39
|
+
scoreGoals(agentId) {
|
|
40
|
+
return requireBoundRuntime(state, "scoreGoals").scoreGoals(agentId);
|
|
41
|
+
},
|
|
42
|
+
captureCheckpoint() {
|
|
43
|
+
return requireBoundRuntime(state, "captureCheckpoint").captureCheckpoint();
|
|
44
|
+
},
|
|
45
|
+
restoreCheckpoint(checkpoint, options) {
|
|
46
|
+
requireBoundRuntime(state, "restoreCheckpoint").restoreCheckpoint(checkpoint, options);
|
|
47
|
+
},
|
|
48
|
+
snapshot() {
|
|
49
|
+
return requireBoundRuntime(state, "snapshot").snapshot();
|
|
50
|
+
},
|
|
51
|
+
traces() {
|
|
52
|
+
return requireBoundRuntime(state, "traces").traces();
|
|
53
|
+
},
|
|
54
|
+
isBound() {
|
|
55
|
+
return state.runtime !== void 0;
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
handleStates.set(handle, state);
|
|
59
|
+
return handle;
|
|
60
|
+
}
|
|
61
|
+
function bindAiHandle(handle, runtime, ownerId) {
|
|
62
|
+
const state = requireHandleState(handle);
|
|
63
|
+
if (state.runtime !== void 0) throw createAiError("ai.handle_bound", "AI handle is already bound", {
|
|
64
|
+
handleId: state.id,
|
|
65
|
+
ownerId: state.ownerId,
|
|
66
|
+
nextOwnerId: ownerId
|
|
67
|
+
});
|
|
68
|
+
state.runtime = runtime;
|
|
69
|
+
state.ownerId = ownerId;
|
|
70
|
+
}
|
|
71
|
+
function unbindAiHandle(handle, ownerId) {
|
|
72
|
+
const state = requireHandleState(handle);
|
|
73
|
+
if (state.runtime === void 0) return;
|
|
74
|
+
if (state.ownerId !== ownerId) throw createAiError("ai.handle_owner_mismatch", "AI handle owner mismatch", {
|
|
75
|
+
handleId: state.id,
|
|
76
|
+
ownerId: state.ownerId,
|
|
77
|
+
nextOwnerId: ownerId
|
|
78
|
+
});
|
|
79
|
+
state.runtime = void 0;
|
|
80
|
+
state.ownerId = void 0;
|
|
81
|
+
}
|
|
82
|
+
function requireHandleState(handle) {
|
|
83
|
+
const state = handleStates.get(handle);
|
|
84
|
+
if (state === void 0) throw createAiError("ai.handle_invalid", "AI handle must be created with createAiHandle");
|
|
85
|
+
return state;
|
|
86
|
+
}
|
|
87
|
+
function requireBoundRuntime(state, operation) {
|
|
88
|
+
if (state.runtime === void 0) throw createAiError("ai.handle_unbound", "AI handle is not bound to a runtime", {
|
|
89
|
+
handleId: state.id,
|
|
90
|
+
operation
|
|
91
|
+
});
|
|
92
|
+
return state.runtime;
|
|
93
|
+
}
|
|
94
|
+
//#endregion
|
|
95
|
+
//#region src/composition/create-ai-module.ts
|
|
96
|
+
function createAiModule(options) {
|
|
97
|
+
const moduleId = options.id ?? "ai";
|
|
98
|
+
return defineGameModule({
|
|
99
|
+
id: moduleId,
|
|
100
|
+
install(context) {
|
|
101
|
+
let runtime;
|
|
102
|
+
let handleBound = false;
|
|
103
|
+
try {
|
|
104
|
+
runtime = createAiRuntime({
|
|
105
|
+
...options,
|
|
106
|
+
id: moduleId,
|
|
107
|
+
world: createAiWorldReadModel(context.world),
|
|
108
|
+
eventBus: options.eventBus ?? context.eventBus
|
|
109
|
+
});
|
|
110
|
+
if (options.handle !== void 0) {
|
|
111
|
+
bindAiHandle(options.handle, runtime, moduleId);
|
|
112
|
+
handleBound = true;
|
|
113
|
+
}
|
|
114
|
+
options.onRuntime?.(runtime, context);
|
|
115
|
+
context.systems.register({
|
|
116
|
+
id: `${moduleId}.update`,
|
|
117
|
+
update(systemContext) {
|
|
118
|
+
runtime?.update(systemContext.delta, systemContext.elapsed);
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
} catch (error) {
|
|
122
|
+
if (handleBound && options.handle !== void 0) unbindAiHandle(options.handle, moduleId);
|
|
123
|
+
runtime?.dispose();
|
|
124
|
+
throw error;
|
|
125
|
+
}
|
|
126
|
+
return { dispose() {
|
|
127
|
+
if (options.handle !== void 0) unbindAiHandle(options.handle, moduleId);
|
|
128
|
+
runtime?.dispose();
|
|
129
|
+
runtime = void 0;
|
|
130
|
+
} };
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
//#endregion
|
|
135
|
+
//#region src/persistence/save-contributor.ts
|
|
136
|
+
function createAiSaveContributor(options) {
|
|
137
|
+
const id = options.id ?? "ai";
|
|
138
|
+
const version = options.version ?? "1";
|
|
139
|
+
return {
|
|
140
|
+
id,
|
|
141
|
+
version,
|
|
142
|
+
order: options.order ?? 375,
|
|
143
|
+
scope: "gameplay",
|
|
144
|
+
tags: [
|
|
145
|
+
"gameplay",
|
|
146
|
+
"ai",
|
|
147
|
+
"checkpoint"
|
|
148
|
+
],
|
|
149
|
+
saveByDefault: true,
|
|
150
|
+
required: options.required ?? true,
|
|
151
|
+
capture() {
|
|
152
|
+
return {
|
|
153
|
+
id,
|
|
154
|
+
version,
|
|
155
|
+
data: options.handle.captureCheckpoint()
|
|
156
|
+
};
|
|
157
|
+
},
|
|
158
|
+
restore(context, section) {
|
|
159
|
+
options.handle.restoreCheckpoint(section.data, {
|
|
160
|
+
resolveEntityId(savedEntityId) {
|
|
161
|
+
return context.entityMap.get(savedEntityId) ?? savedEntityId;
|
|
162
|
+
},
|
|
163
|
+
...options.resolveActorId === void 0 ? {} : { resolveActorId(savedActorId) {
|
|
164
|
+
return options.resolveActorId?.(savedActorId, context);
|
|
165
|
+
} },
|
|
166
|
+
...options.resolveTaskState === void 0 ? {} : { resolveTaskState(savedState, binding) {
|
|
167
|
+
return options.resolveTaskState?.(savedState, binding, context);
|
|
168
|
+
} }
|
|
169
|
+
});
|
|
170
|
+
},
|
|
171
|
+
validate(section) {
|
|
172
|
+
return { issues: validateAiSection(section) };
|
|
173
|
+
}
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
function validateAiSection(section) {
|
|
177
|
+
const issues = [];
|
|
178
|
+
if (section.data.version !== 1) issues.push(issue("ai.save_invalid_version", "AI save version must be 1", "data.version"));
|
|
179
|
+
if (!Number.isFinite(section.data.elapsed) || section.data.elapsed < 0) issues.push(issue("ai.save_invalid_elapsed", "AI save elapsed must be a non-negative finite number", "data.elapsed"));
|
|
180
|
+
if (!Array.isArray(section.data.agents)) {
|
|
181
|
+
issues.push(issue("ai.save_invalid_agents", "AI save agents must be an array", "data.agents"));
|
|
182
|
+
return issues;
|
|
183
|
+
}
|
|
184
|
+
const agentIds = /* @__PURE__ */ new Set();
|
|
185
|
+
for (const [index, agent] of section.data.agents.entries()) {
|
|
186
|
+
const path = `data.agents[${index}]`;
|
|
187
|
+
if (typeof agent.binding?.agentId !== "string" || agent.binding.agentId.length === 0 || agentIds.has(agent.binding.agentId)) issues.push(issue("ai.save_invalid_agent_id", "AI save agent ids must be non-empty and unique", `${path}.binding.agentId`));
|
|
188
|
+
if (typeof agent.binding?.definitionId !== "string" || agent.binding.definitionId.length === 0) issues.push(issue("ai.save_invalid_definition_id", "AI save agents require a definition id", `${path}.binding.definitionId`));
|
|
189
|
+
if (!Array.isArray(agent.memory) || !Array.isArray(agent.cooldowns) || !Array.isArray(agent.nextSensorAt)) issues.push(issue("ai.save_invalid_agent_state", "AI save memory and schedules must be arrays", path));
|
|
190
|
+
if (!Number.isFinite(agent.nextDecisionAt) || agent.nextDecisionAt < 0) issues.push(issue("ai.save_invalid_decision_time", "AI save next decision time must be non-negative and finite", `${path}.nextDecisionAt`));
|
|
191
|
+
if (agent.task !== void 0 && (!Number.isFinite(agent.task.startedAt) || !Number.isFinite(agent.task.updatedAt) || agent.task.updatedAt < agent.task.startedAt)) issues.push(issue("ai.save_invalid_task_time", "AI save task timestamps are invalid", `${path}.task.updatedAt`));
|
|
192
|
+
agentIds.add(agent.binding?.agentId ?? "");
|
|
193
|
+
}
|
|
194
|
+
return issues;
|
|
195
|
+
}
|
|
196
|
+
function issue(code, message, path) {
|
|
197
|
+
return {
|
|
198
|
+
code,
|
|
199
|
+
message,
|
|
200
|
+
severity: "error",
|
|
201
|
+
path
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
//#endregion
|
|
205
|
+
export { AI_AGENT_TYPE, AI_GOAL_TYPE, AI_SENSOR_TYPE, AI_TASK_TYPE, AI_TRACE_KINDS, AiError, bindAiHandle, createAiAgentDataType, createAiDataTypes, createAiError, createAiGoalDataType, createAiHandle, createAiModule, createAiNavigationQueries, createAiPhysicsQueries, createAiRuntime, createAiSaveContributor, createAiSensorDataType, createAiSharedFactQueries, createAiTaskDataType, createAiWorldReadModel, evaluateAiUtilityCurve, unbindAiHandle };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { AiBlackboardValue } from "../contracts/blackboard-value";
|
|
2
|
+
export type AiBlackboardValueLimits = {
|
|
3
|
+
maxDepth: number;
|
|
4
|
+
maxNodes: number;
|
|
5
|
+
maxStringLength: number;
|
|
6
|
+
};
|
|
7
|
+
export type AiBlackboard = {
|
|
8
|
+
readonly limit: number;
|
|
9
|
+
readonly size: number;
|
|
10
|
+
set(key: string, value: AiBlackboardValue): void;
|
|
11
|
+
delete(key: string): void;
|
|
12
|
+
read<TValue extends AiBlackboardValue = AiBlackboardValue>(key: string): TValue | undefined;
|
|
13
|
+
keys(): string[];
|
|
14
|
+
capture(): Record<string, AiBlackboardValue>;
|
|
15
|
+
replace(values: Record<string, AiBlackboardValue>): void;
|
|
16
|
+
clear(): void;
|
|
17
|
+
};
|
|
18
|
+
export type CreateAiBlackboardOptions = {
|
|
19
|
+
limit: number;
|
|
20
|
+
valueLimits: AiBlackboardValueLimits;
|
|
21
|
+
};
|
|
22
|
+
export declare function createAiBlackboard(options: CreateAiBlackboardOptions): AiBlackboard;
|
|
23
|
+
export declare function cloneAiBlackboardValue(value: AiBlackboardValue, limits: AiBlackboardValueLimits): AiBlackboardValue;
|
|
24
|
+
//# sourceMappingURL=blackboard.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"blackboard.d.ts","sourceRoot":"","sources":["../../src/memory/blackboard.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AAGvE,MAAM,MAAM,uBAAuB,GAAG;IACpC,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,eAAe,EAAE,MAAM,CAAC;CACzB,CAAC;AAEF,MAAM,MAAM,YAAY,GAAG;IACzB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,iBAAiB,GAAG,IAAI,CAAC;IACjD,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,IAAI,CAAC,MAAM,SAAS,iBAAiB,GAAG,iBAAiB,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC;IAC5F,IAAI,IAAI,MAAM,EAAE,CAAC;IACjB,OAAO,IAAI,MAAM,CAAC,MAAM,EAAE,iBAAiB,CAAC,CAAC;IAC7C,OAAO,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,iBAAiB,CAAC,GAAG,IAAI,CAAC;IACzD,KAAK,IAAI,IAAI,CAAC;CACf,CAAC;AAEF,MAAM,MAAM,yBAAyB,GAAG;IACtC,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,uBAAuB,CAAC;CACtC,CAAC;AAEF,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,yBAAyB,GAAG,YAAY,CAyDnF;AAED,wBAAgB,sBAAsB,CACpC,KAAK,EAAE,iBAAiB,EACxB,MAAM,EAAE,uBAAuB,GAC9B,iBAAiB,CA+EnB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/memory/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,YAAY,EACZ,uBAAuB,EACvB,yBAAyB,EAC1B,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,sBAAsB,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/observability/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,SAAS,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { AiAgentState } from "../controller/agent-state";
|
|
2
|
+
import type { AiAgentSnapshot, AiRuntimeSnapshot } from "./snapshot";
|
|
3
|
+
export declare function projectAiAgentSnapshot(state: AiAgentState): AiAgentSnapshot;
|
|
4
|
+
export declare function projectAiRuntimeSnapshot(options: {
|
|
5
|
+
id: string;
|
|
6
|
+
elapsed: number;
|
|
7
|
+
disposed: boolean;
|
|
8
|
+
compiledDefinitions: number;
|
|
9
|
+
agents: readonly AiAgentState[];
|
|
10
|
+
intentsEmitted: number;
|
|
11
|
+
delayedSensorSamples: number;
|
|
12
|
+
delayedDecisions: number;
|
|
13
|
+
rejectedPathRequests: number;
|
|
14
|
+
droppedTraceEntries: number;
|
|
15
|
+
traceEntries: number;
|
|
16
|
+
}): AiRuntimeSnapshot;
|
|
17
|
+
//# sourceMappingURL=snapshot-projection.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"snapshot-projection.d.ts","sourceRoot":"","sources":["../../src/observability/snapshot-projection.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAE9D,OAAO,KAAK,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAErE,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,YAAY,GAAG,eAAe,CAe3E;AAED,wBAAgB,wBAAwB,CAAC,OAAO,EAAE;IAChD,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,OAAO,CAAC;IAClB,mBAAmB,EAAE,MAAM,CAAC;IAC5B,MAAM,EAAE,SAAS,YAAY,EAAE,CAAC;IAChC,cAAc,EAAE,MAAM,CAAC;IACvB,oBAAoB,EAAE,MAAM,CAAC;IAC7B,gBAAgB,EAAE,MAAM,CAAC;IACzB,oBAAoB,EAAE,MAAM,CAAC;IAC7B,mBAAmB,EAAE,MAAM,CAAC;IAC5B,YAAY,EAAE,MAAM,CAAC;CACtB,GAAG,iBAAiB,CAiBpB"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { AiAgentBinding } from "../contracts/agent-binding";
|
|
2
|
+
import type { AiTaskState } from "../task/task-executor";
|
|
3
|
+
export type AiAgentSnapshot = {
|
|
4
|
+
binding: AiAgentBinding;
|
|
5
|
+
schedulerClassId: string;
|
|
6
|
+
goalId?: string | undefined;
|
|
7
|
+
goalScore?: number | undefined;
|
|
8
|
+
committedUntil?: number | undefined;
|
|
9
|
+
task?: AiTaskState | undefined;
|
|
10
|
+
memorySize: number;
|
|
11
|
+
blackboardSize: number;
|
|
12
|
+
blackboardLimit: number;
|
|
13
|
+
blackboardKeys: string[];
|
|
14
|
+
nextDecisionAt: number;
|
|
15
|
+
delayedDecisions: number;
|
|
16
|
+
};
|
|
17
|
+
export type AiRuntimeSnapshot = {
|
|
18
|
+
id: string;
|
|
19
|
+
elapsed: number;
|
|
20
|
+
disposed: boolean;
|
|
21
|
+
compiledDefinitions: number;
|
|
22
|
+
agents: AiAgentSnapshot[];
|
|
23
|
+
activeTasks: number;
|
|
24
|
+
memoryFacts: number;
|
|
25
|
+
intentsEmitted: number;
|
|
26
|
+
delayedSensorSamples: number;
|
|
27
|
+
delayedDecisions: number;
|
|
28
|
+
rejectedPathRequests: number;
|
|
29
|
+
droppedTraceEntries: number;
|
|
30
|
+
traceEntries: number;
|
|
31
|
+
};
|
|
32
|
+
//# sourceMappingURL=snapshot.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"snapshot.d.ts","sourceRoot":"","sources":["../../src/observability/snapshot.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AACjE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAEzD,MAAM,MAAM,eAAe,GAAG;IAC5B,OAAO,EAAE,cAAc,CAAC;IACxB,gBAAgB,EAAE,MAAM,CAAC;IACzB,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC5B,SAAS,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC/B,cAAc,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACpC,IAAI,CAAC,EAAE,WAAW,GAAG,SAAS,CAAC;IAC/B,UAAU,EAAE,MAAM,CAAC;IACnB,cAAc,EAAE,MAAM,CAAC;IACvB,eAAe,EAAE,MAAM,CAAC;IACxB,cAAc,EAAE,MAAM,EAAE,CAAC;IACzB,cAAc,EAAE,MAAM,CAAC;IACvB,gBAAgB,EAAE,MAAM,CAAC;CAC1B,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG;IAC9B,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,OAAO,CAAC;IAClB,mBAAmB,EAAE,MAAM,CAAC;IAC5B,MAAM,EAAE,eAAe,EAAE,CAAC;IAC1B,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;IACpB,cAAc,EAAE,MAAM,CAAC;IACvB,oBAAoB,EAAE,MAAM,CAAC;IAC7B,gBAAgB,EAAE,MAAM,CAAC;IACzB,oBAAoB,EAAE,MAAM,CAAC;IAC7B,mBAAmB,EAAE,MAAM,CAAC;IAC5B,YAAY,EAAE,MAAM,CAAC;CACtB,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { AiTraceEntry, AiTraceKind } from "./trace";
|
|
2
|
+
import type { AiTraceStore } from "./trace-store";
|
|
3
|
+
export type AiTraceRecorder = {
|
|
4
|
+
beginUpdate(): void;
|
|
5
|
+
push(entry: Omit<AiTraceEntry, "sequence"> & {
|
|
6
|
+
kind: AiTraceKind;
|
|
7
|
+
}): void;
|
|
8
|
+
endUpdate(timestamp: number): void;
|
|
9
|
+
dropped(): number;
|
|
10
|
+
};
|
|
11
|
+
export declare function createAiTraceRecorder(options: {
|
|
12
|
+
store: AiTraceStore;
|
|
13
|
+
enabled: boolean;
|
|
14
|
+
maxEntriesPerUpdate: number;
|
|
15
|
+
emitDropSummary: boolean;
|
|
16
|
+
}): AiTraceRecorder;
|
|
17
|
+
//# sourceMappingURL=trace-recorder.d.ts.map
|