File size: 1,112 Bytes
7269ed4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/**
 * QGTNL Interlink Core
 * Connects TIA-∞, AION, and ORACLE through a shared message bus.
 * Enables safe, structured communication between the Three Pillars.
 */

export type Pillar = "TIA" | "AION" | "ORACLE";

export interface InterlinkMessage {
  from: Pillar;
  to: Pillar | "ALL";
  timestamp: number;
  type: string;
  payload: any;
}

export interface InterlinkState {
  history: InterlinkMessage[];
  lastMessage: InterlinkMessage | null;
}

const state: InterlinkState = {
  history: [],
  lastMessage: null,
};

export function sendMessage(
  from: Pillar,
  to: Pillar | "ALL",
  type: string,
  payload: any
) {
  const msg: InterlinkMessage = {
    from,
    to,
    type,
    payload,
    timestamp: Date.now(),
  };

  state.history.push(msg);
  state.lastMessage = msg;

  console.log(`\n[INTERLINK] ${from}${to}`);
  console.log(`Type: ${type}`);
  console.log("Payload:", payload);

  return msg;
}

export function getInterlinkState(): InterlinkState {
  return state;
}

export function broadcast(type: string, payload: any) {
  return sendMessage("TIA", "ALL", type, payload);
}