@integrity-labs/xero-broker 0.1.1 → 0.1.3

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/index.js +61 -2
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -20985,6 +20985,57 @@ var StdioServerTransport = class {
20985
20985
  }
20986
20986
  };
20987
20987
 
20988
+ // src/turn-initiator-marker.ts
20989
+ import { readFileSync } from "fs";
20990
+ import { dirname, join } from "path";
20991
+ var TURN_INITIATOR_MAX_AGE_MS = 5 * 60 * 1e3;
20992
+ var TURN_INITIATOR_LEDGER_FILENAME = ".turn-initiator-ledger.json";
20993
+ function readTurnInitiatorFromLedger(file, maxAgeMs) {
20994
+ const ledgerFile = join(dirname(file), TURN_INITIATOR_LEDGER_FILENAME);
20995
+ let entries;
20996
+ try {
20997
+ const parsed = JSON.parse(readFileSync(ledgerFile, "utf8"));
20998
+ if (!parsed || parsed.v !== 1 || !Array.isArray(parsed.entries)) return "no-ledger";
20999
+ entries = parsed.entries;
21000
+ } catch {
21001
+ return "no-ledger";
21002
+ }
21003
+ const now = Date.now();
21004
+ const fresh = entries.filter(
21005
+ (e) => e && typeof e.channel === "string" && e.channel && typeof e.sender_id === "string" && e.sender_id && typeof e.ts === "number" && Number.isFinite(e.ts) && now - e.ts >= 0 && now - e.ts <= maxAgeMs
21006
+ );
21007
+ if (fresh.length === 1) {
21008
+ const e = fresh[0];
21009
+ return { channel: e.channel, sender_id: e.sender_id };
21010
+ }
21011
+ if (fresh.length >= 2) {
21012
+ process.stderr.write(
21013
+ `turn-initiator: ambiguous (${fresh.length} fresh senders), withholding initiator
21014
+ `
21015
+ );
21016
+ return null;
21017
+ }
21018
+ return "no-ledger";
21019
+ }
21020
+ function readTurnInitiator(maxAgeMs = TURN_INITIATOR_MAX_AGE_MS) {
21021
+ const file = process.env["AGT_TURN_INITIATOR_FILE"];
21022
+ if (!file) return null;
21023
+ const fromLedger = readTurnInitiatorFromLedger(file, maxAgeMs);
21024
+ if (fromLedger !== "no-ledger") return fromLedger;
21025
+ try {
21026
+ const raw = readFileSync(file, "utf8");
21027
+ const m = JSON.parse(raw);
21028
+ if (typeof m.channel !== "string" || !m.channel) return null;
21029
+ if (typeof m.sender_id !== "string" || !m.sender_id) return null;
21030
+ if (typeof m.ts !== "number" || !Number.isFinite(m.ts)) return null;
21031
+ const age = Date.now() - m.ts;
21032
+ if (age < 0 || age > maxAgeMs) return null;
21033
+ return { channel: m.channel, sender_id: m.sender_id };
21034
+ } catch {
21035
+ return null;
21036
+ }
21037
+ }
21038
+
20988
21039
  // src/broker-client.ts
20989
21040
  function makeBrokerError(status, message, detail) {
20990
21041
  const err = new Error(message);
@@ -21103,8 +21154,16 @@ var XeroBrokerClient = class {
21103
21154
  if (!runId) {
21104
21155
  throw makeBrokerError(400, "XeroBrokerClient.requestApproval requires runId");
21105
21156
  }
21157
+ const turnInitiator = readTurnInitiator();
21158
+ const { turn_initiator: _ignoredForged, ...safeArgs } = args;
21159
+ void _ignoredForged;
21106
21160
  return this.request("POST", "/xero-broker/requests", {
21107
- body: { ...args, agent_id: agentId, run_id: runId }
21161
+ body: {
21162
+ ...safeArgs,
21163
+ agent_id: agentId,
21164
+ run_id: runId,
21165
+ ...turnInitiator ? { turn_initiator: turnInitiator } : {}
21166
+ }
21108
21167
  });
21109
21168
  }
21110
21169
  pollDecision(args) {
@@ -21179,7 +21238,7 @@ var awaitDecisionSchema = external_exports.object({
21179
21238
  // package.json
21180
21239
  var package_default = {
21181
21240
  name: "@integrity-labs/xero-broker",
21182
- version: "0.1.1",
21241
+ version: "0.1.3",
21183
21242
  description: "Xero Broker \u2014 MCP server that routes money- and ledger-touching Xero writes through approval-core (HITL). Sibling to cloud-broker / channel-broker; the only write path for an agent once the vendor xero-mcp-server's write tools are stripped. ENG-4922.",
21184
21243
  type: "module",
21185
21244
  bin: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@integrity-labs/xero-broker",
3
- "version": "0.1.1",
3
+ "version": "0.1.3",
4
4
  "description": "Xero Broker — MCP server that routes money- and ledger-touching Xero writes through approval-core (HITL). Sibling to cloud-broker / channel-broker; the only write path for an agent once the vendor xero-mcp-server's write tools are stripped. ENG-4922.",
5
5
  "type": "module",
6
6
  "bin": {