@tini-works/inv-node 0.1.6 → 0.1.7

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.
Files changed (2) hide show
  1. package/dist/cli.js +43 -5
  2. package/package.json +1 -1
package/dist/cli.js CHANGED
@@ -1255,11 +1255,15 @@ class WSHandlers {
1255
1255
  engine;
1256
1256
  store;
1257
1257
  eventBus;
1258
+ sendFn = null;
1258
1259
  constructor(engine, store, eventBus) {
1259
1260
  this.engine = engine;
1260
1261
  this.store = store;
1261
1262
  this.eventBus = eventBus;
1262
1263
  }
1264
+ setSendFn(fn) {
1265
+ this.sendFn = fn;
1266
+ }
1263
1267
  handle(envelope) {
1264
1268
  const { payload } = envelope;
1265
1269
  switch (payload.type) {
@@ -1270,7 +1274,7 @@ class WSHandlers {
1270
1274
  this.handleSweep(payload);
1271
1275
  break;
1272
1276
  case "trace_resolve_request":
1273
- this.handleTraceResolveRequest(payload);
1277
+ this.handleTraceResolveRequest(envelope, payload);
1274
1278
  break;
1275
1279
  case "query_ask":
1276
1280
  this.handleQueryAsk(envelope, payload);
@@ -1294,7 +1298,10 @@ class WSHandlers {
1294
1298
  case "error":
1295
1299
  break;
1296
1300
  }
1297
- this.eventBus.emit(payload.type, payload);
1301
+ this.eventBus.emit(payload.type, {
1302
+ ...payload,
1303
+ fromNode: envelope.fromNode
1304
+ });
1298
1305
  }
1299
1306
  handleSignalChange(payload) {
1300
1307
  try {
@@ -1320,16 +1327,20 @@ class WSHandlers {
1320
1327
  });
1321
1328
  }
1322
1329
  }
1323
- handleTraceResolveRequest(payload) {
1330
+ handleTraceResolveRequest(envelope, payload) {
1324
1331
  try {
1325
1332
  const item = this.engine.getItem(payload.itemId);
1326
- this.eventBus.emit("trace_resolve_response", {
1333
+ const response = {
1327
1334
  type: "trace_resolve_response",
1328
1335
  itemId: item.id,
1329
1336
  title: item.title,
1330
1337
  kind: item.kind,
1331
1338
  state: item.state
1332
- });
1339
+ };
1340
+ this.eventBus.emit("trace_resolve_response", response);
1341
+ if (this.sendFn) {
1342
+ this.sendFn(envelope.fromNode, response);
1343
+ }
1333
1344
  } catch (err) {
1334
1345
  const message = err instanceof Error ? err.message : String(err);
1335
1346
  this.eventBus.emit("error", {
@@ -1346,6 +1357,22 @@ class WSHandlers {
1346
1357
  askerNode: envelope.fromNode,
1347
1358
  question: payload.question
1348
1359
  });
1360
+ if (this.sendFn) {
1361
+ const nodes = this.store.listNodes(envelope.projectId);
1362
+ const allItems = nodes.flatMap((n) => this.store.listItems(n.id));
1363
+ const summary = allItems.map((i) => ({
1364
+ id: i.id,
1365
+ kind: i.kind,
1366
+ title: i.title,
1367
+ state: i.state,
1368
+ externalRef: i.externalRef || undefined
1369
+ }));
1370
+ this.sendFn(envelope.fromNode, {
1371
+ type: "query_respond",
1372
+ answer: JSON.stringify({ items: summary, count: summary.length }),
1373
+ responderId: payload.askerId
1374
+ });
1375
+ }
1349
1376
  } catch (err) {
1350
1377
  const message = err instanceof Error ? err.message : String(err);
1351
1378
  this.eventBus.emit("error", {
@@ -1949,6 +1976,11 @@ async function startChannelServer(configPath) {
1949
1976
  wsClient.onMessage((envelope) => {
1950
1977
  wsHandlers.handle(envelope);
1951
1978
  });
1979
+ wsHandlers.setSendFn((toNode, payload) => {
1980
+ if (wsClient?.connected) {
1981
+ wsClient.sendMessage(toNode, payload);
1982
+ }
1983
+ });
1952
1984
  try {
1953
1985
  await wsClient.connect();
1954
1986
  } catch {
@@ -2002,6 +2034,7 @@ Use the inv_* tools to manage inventory, propose changes, vote, challenge items,
2002
2034
  "checklist_update",
2003
2035
  "error"
2004
2036
  ];
2037
+ const log = new Logger("channel-bridge");
2005
2038
  for (const eventType of channelEvents) {
2006
2039
  eventBus.on(eventType, (data) => {
2007
2040
  mcp.notification({
@@ -2010,6 +2043,11 @@ Use the inv_* tools to manage inventory, propose changes, vote, challenge items,
2010
2043
  content: JSON.stringify(data),
2011
2044
  meta: { source: "inventory", eventType }
2012
2045
  }
2046
+ }).catch((err) => {
2047
+ log.error("Failed to send channel notification", {
2048
+ eventType,
2049
+ error: err instanceof Error ? err.message : String(err)
2050
+ });
2013
2051
  });
2014
2052
  });
2015
2053
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tini-works/inv-node",
3
- "version": "0.1.6",
3
+ "version": "0.1.7",
4
4
  "bin": {
5
5
  "inv-node": "./dist/cli.js"
6
6
  },