@myclaw163/game-agent-runtime 0.1.0 → 0.1.1
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.
|
@@ -7,6 +7,8 @@ export interface EventNotificationContent {
|
|
|
7
7
|
event: Record<string, unknown>;
|
|
8
8
|
monitorText: string;
|
|
9
9
|
desktopEvent?: Record<string, unknown>;
|
|
10
|
+
/** Producer-prepared projections for additional output adapters. */
|
|
11
|
+
views?: Record<string, unknown>;
|
|
10
12
|
}
|
|
11
13
|
export type EventDeliveryClass = 'monitor_and_events' | 'internal_only';
|
|
12
14
|
/** Delivery metadata may be resolved before Ready; factual identity/payload never change. */
|
|
@@ -16,6 +16,7 @@ export type MailboxAdapterDescriptor = {
|
|
|
16
16
|
export interface MailboxDriver {
|
|
17
17
|
/** Optional for internal components; public transport adapters should declare it. */
|
|
18
18
|
readonly adapter?: MailboxAdapterDescriptor;
|
|
19
|
+
afterReady?(ready: RuntimeEpochReady): void;
|
|
19
20
|
observeEvents?(events: readonly CanonicalEvent[]): void;
|
|
20
21
|
flush(): Promise<void>;
|
|
21
22
|
/** Optional finite handoff opportunity before any sibling releases shared delivery state. */
|
|
@@ -26,6 +27,7 @@ export interface MailboxDriver {
|
|
|
26
27
|
export declare class CompositeMailboxDriver implements MailboxDriver {
|
|
27
28
|
private readonly drivers;
|
|
28
29
|
constructor(drivers: readonly MailboxDriver[]);
|
|
30
|
+
afterReady(ready: RuntimeEpochReady): void;
|
|
29
31
|
observeEvents(events: readonly CanonicalEvent[]): void;
|
|
30
32
|
flush(): Promise<void>;
|
|
31
33
|
stop(): Promise<void>;
|
|
@@ -24,6 +24,20 @@ export class CompositeMailboxDriver {
|
|
|
24
24
|
consumers.set(adapter.consumerId, adapter.id);
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
|
+
afterReady(ready) {
|
|
28
|
+
let firstReliableError;
|
|
29
|
+
for (const driver of this.drivers) {
|
|
30
|
+
try {
|
|
31
|
+
driver.afterReady?.(ready);
|
|
32
|
+
}
|
|
33
|
+
catch (error) {
|
|
34
|
+
if (driver.adapter?.acknowledgement !== 'none')
|
|
35
|
+
firstReliableError ??= error;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
if (firstReliableError)
|
|
39
|
+
throw firstReliableError;
|
|
40
|
+
}
|
|
27
41
|
observeEvents(events) {
|
|
28
42
|
let firstReliableError;
|
|
29
43
|
for (const driver of this.drivers) {
|
|
@@ -89,7 +103,10 @@ export class MailboxPlugin {
|
|
|
89
103
|
};
|
|
90
104
|
}
|
|
91
105
|
afterReady(ready) {
|
|
92
|
-
if (
|
|
106
|
+
if (this.stopped)
|
|
107
|
+
return;
|
|
108
|
+
this.driver?.afterReady?.(ready);
|
|
109
|
+
if (ready.events.length)
|
|
93
110
|
this.driver?.observeEvents?.(ready.events);
|
|
94
111
|
}
|
|
95
112
|
async flush(_reason, _context) {
|
|
@@ -81,5 +81,5 @@ export interface PerceptionAdapter {
|
|
|
81
81
|
createRunner(source: PerceptionSource, bindMemory: (input: PerceptionInvocation, active: () => boolean) => StrategyMemory): PerceptionRunner;
|
|
82
82
|
configure(source: PerceptionSource, value: Readonly<Record<string, unknown>>): Readonly<Record<string, unknown>>;
|
|
83
83
|
describe(source: PerceptionSource, locale: string): unknown;
|
|
84
|
-
notification(event: RuntimeEventProposal, boundary: PerceptionBoundary): EventNotificationContent;
|
|
84
|
+
notification(event: RuntimeEventProposal, boundary: PerceptionBoundary, source?: PerceptionSource): EventNotificationContent;
|
|
85
85
|
}
|
|
@@ -210,10 +210,12 @@ export class PerceptionHost {
|
|
|
210
210
|
this.validate(result, source);
|
|
211
211
|
state.value = structuredClone(result.state);
|
|
212
212
|
state.inputState = module.inputState;
|
|
213
|
-
for (const event of result.events ?? [])
|
|
214
|
-
|
|
213
|
+
for (const event of result.events ?? []) {
|
|
214
|
+
const proposal = { type: event.type,
|
|
215
215
|
dedupeKey: JSON.stringify([source.id, event.key]), dedupeScope: 'segment', wakeAgent: event.wakeAgent ?? true,
|
|
216
|
-
payload: { ...event.payload }, occurredAt: new Date(nowMs).toISOString() }
|
|
216
|
+
payload: { ...event.payload }, occurredAt: new Date(nowMs).toISOString() };
|
|
217
|
+
events.push({ ...proposal, notificationContent: this.options.adapter.notification(proposal, prepared, source) });
|
|
218
|
+
}
|
|
217
219
|
const matched = new Map((result.activations ?? []).map(activation => [activation.behavior, activation]));
|
|
218
220
|
for (const [key, binding] of Object.entries(source.module.behaviors ?? {})) {
|
|
219
221
|
const current = state.bindings[key] ??= { armed: true, warningSequence: 0 };
|
|
@@ -306,7 +308,7 @@ export class PerceptionHost {
|
|
|
306
308
|
}
|
|
307
309
|
}
|
|
308
310
|
return { outcome: 'processed', events: events.map(event => ({ ...event,
|
|
309
|
-
notificationContent: this.options.adapter.notification(event, prepared) })), checkpoint: structuredClone(this.checkpoint),
|
|
311
|
+
notificationContent: event.notificationContent ?? this.options.adapter.notification(event, prepared) })), checkpoint: structuredClone(this.checkpoint),
|
|
310
312
|
...(input.pendingEvents.length ? { consumeEventsThroughCommitSeq: input.pendingEvents.at(-1).commitSeq } : {}) };
|
|
311
313
|
}
|
|
312
314
|
validate(result, source) {
|