@axiom-lattice/gateway 2.1.88 → 2.1.90

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/index.d.mts CHANGED
@@ -62,19 +62,81 @@ interface MessageContext {
62
62
  }
63
63
  type MessageMiddleware = (ctx: MessageContext, next: () => Promise<void>) => Promise<void>;
64
64
 
65
+ /**
66
+ * Configuration for {@link MessageRouter}.
67
+ *
68
+ * @param middlewares - Ordered middleware chain executed before dispatch
69
+ * @param bindingRegistry - Resolves sender-to-agent bindings
70
+ * @param adapterRegistry - Registry of {@link ChannelAdapter} implementations
71
+ * @param installationStore - Persisted channel installation configs
72
+ */
65
73
  interface MessageRouterConfig {
66
74
  middlewares: MessageMiddleware[];
67
75
  bindingRegistry: BindingRegistry;
68
76
  adapterRegistry: ChannelAdapterRegistry;
69
77
  installationStore: ChannelInstallationStore;
70
78
  }
79
+ /**
80
+ * Core message router for external channel integration.
81
+ *
82
+ * Receives normalized {@link InboundMessage} objects from channel adapters,
83
+ * resolves the target agent via {@link BindingRegistry}, manages thread
84
+ * lifecycle, and sends AI responses back to the channel via
85
+ * `ChannelAdapter.sendReply`.
86
+ *
87
+ * ## Reply flow
88
+ *
89
+ * The router uses a counter-based deduplication scheme on the internal
90
+ * {@link Agent.reply:ready} event:
91
+ *
92
+ * 1. Before `agent.addMessage()`, it subscribes to `reply:ready` on the agent.
93
+ * 2. Multiple concurrent dispatches on the same thread increment a counter;
94
+ * only the first registers the `EventEmitter.once` listener.
95
+ * 3. When `reply:ready` fires, the callback extracts the last AI message from
96
+ * the LangGraph state and sends it via `ChannelAdapter.sendReply`.
97
+ * 4. The counter is decremented; the subscription is only removed when the
98
+ * counter reaches 0.
99
+ * 5. Stale subscriptions are cleaned up after a 1-hour timeout.
100
+ *
101
+ * The `replyTarget` is carried through by injecting `_replyTarget` into
102
+ * `custom_run_config` on {@link Agent.addMessage}, and retrieved from the
103
+ * `reply:ready` event payload.
104
+ *
105
+ * @see {@link ChannelAdapter.sendReply}
106
+ * @see {@link InboundMessage.replyTarget}
107
+ */
71
108
  declare class MessageRouter {
72
109
  private middlewares;
73
110
  private bindingRegistry;
74
111
  private adapterRegistry;
75
112
  private installationStore;
113
+ /**
114
+ * Tracks reply subscriptions per thread+channel to avoid duplicate
115
+ * `subscribeOnce` registrations and ensure proper cleanup.
116
+ *
117
+ * Key format: `{threadId}:{adapterChannel}:reply`
118
+ */
119
+ private _replySubs;
76
120
  constructor(config: MessageRouterConfig);
121
+ /**
122
+ * Register an additional middleware at the end of the chain.
123
+ *
124
+ * @param middleware - A {@link MessageMiddleware} function
125
+ */
77
126
  use(middleware: MessageMiddleware): void;
127
+ /**
128
+ * Dispatch an inbound channel message to the bound agent.
129
+ *
130
+ * Full pipeline: middleware chain → binding resolution → thread lifecycle
131
+ * → agent.addMessage() → (async) reply via {@link ChannelAdapter.sendReply}.
132
+ *
133
+ * If the message has a {@link InboundMessage.replyTarget}, the router subscribes
134
+ * to the agent's `reply:ready` event before enqueuing the message, and sends
135
+ * the AI response back to the channel when it arrives.
136
+ *
137
+ * @param message - Normalized inbound message from a channel adapter
138
+ * @returns {@link DispatchResult} with success status, bindingId, and threadId
139
+ */
78
140
  dispatch(message: InboundMessage): Promise<DispatchResult>;
79
141
  private runMiddlewares;
80
142
  }
package/dist/index.d.ts CHANGED
@@ -62,19 +62,81 @@ interface MessageContext {
62
62
  }
63
63
  type MessageMiddleware = (ctx: MessageContext, next: () => Promise<void>) => Promise<void>;
64
64
 
65
+ /**
66
+ * Configuration for {@link MessageRouter}.
67
+ *
68
+ * @param middlewares - Ordered middleware chain executed before dispatch
69
+ * @param bindingRegistry - Resolves sender-to-agent bindings
70
+ * @param adapterRegistry - Registry of {@link ChannelAdapter} implementations
71
+ * @param installationStore - Persisted channel installation configs
72
+ */
65
73
  interface MessageRouterConfig {
66
74
  middlewares: MessageMiddleware[];
67
75
  bindingRegistry: BindingRegistry;
68
76
  adapterRegistry: ChannelAdapterRegistry;
69
77
  installationStore: ChannelInstallationStore;
70
78
  }
79
+ /**
80
+ * Core message router for external channel integration.
81
+ *
82
+ * Receives normalized {@link InboundMessage} objects from channel adapters,
83
+ * resolves the target agent via {@link BindingRegistry}, manages thread
84
+ * lifecycle, and sends AI responses back to the channel via
85
+ * `ChannelAdapter.sendReply`.
86
+ *
87
+ * ## Reply flow
88
+ *
89
+ * The router uses a counter-based deduplication scheme on the internal
90
+ * {@link Agent.reply:ready} event:
91
+ *
92
+ * 1. Before `agent.addMessage()`, it subscribes to `reply:ready` on the agent.
93
+ * 2. Multiple concurrent dispatches on the same thread increment a counter;
94
+ * only the first registers the `EventEmitter.once` listener.
95
+ * 3. When `reply:ready` fires, the callback extracts the last AI message from
96
+ * the LangGraph state and sends it via `ChannelAdapter.sendReply`.
97
+ * 4. The counter is decremented; the subscription is only removed when the
98
+ * counter reaches 0.
99
+ * 5. Stale subscriptions are cleaned up after a 1-hour timeout.
100
+ *
101
+ * The `replyTarget` is carried through by injecting `_replyTarget` into
102
+ * `custom_run_config` on {@link Agent.addMessage}, and retrieved from the
103
+ * `reply:ready` event payload.
104
+ *
105
+ * @see {@link ChannelAdapter.sendReply}
106
+ * @see {@link InboundMessage.replyTarget}
107
+ */
71
108
  declare class MessageRouter {
72
109
  private middlewares;
73
110
  private bindingRegistry;
74
111
  private adapterRegistry;
75
112
  private installationStore;
113
+ /**
114
+ * Tracks reply subscriptions per thread+channel to avoid duplicate
115
+ * `subscribeOnce` registrations and ensure proper cleanup.
116
+ *
117
+ * Key format: `{threadId}:{adapterChannel}:reply`
118
+ */
119
+ private _replySubs;
76
120
  constructor(config: MessageRouterConfig);
121
+ /**
122
+ * Register an additional middleware at the end of the chain.
123
+ *
124
+ * @param middleware - A {@link MessageMiddleware} function
125
+ */
77
126
  use(middleware: MessageMiddleware): void;
127
+ /**
128
+ * Dispatch an inbound channel message to the bound agent.
129
+ *
130
+ * Full pipeline: middleware chain → binding resolution → thread lifecycle
131
+ * → agent.addMessage() → (async) reply via {@link ChannelAdapter.sendReply}.
132
+ *
133
+ * If the message has a {@link InboundMessage.replyTarget}, the router subscribes
134
+ * to the agent's `reply:ready` event before enqueuing the message, and sends
135
+ * the AI response back to the channel when it arrives.
136
+ *
137
+ * @param message - Normalized inbound message from a channel adapter
138
+ * @returns {@link DispatchResult} with success status, bindingId, and threadId
139
+ */
78
140
  dispatch(message: InboundMessage): Promise<DispatchResult>;
79
141
  private runMiddlewares;
80
142
  }