@atbash/sdk 0.10.10-dev.0 → 0.10.12-dev.0

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.mjs CHANGED
@@ -3216,6 +3216,10 @@ var callCounter = null;
3216
3216
  var durationHistogram = null;
3217
3217
  var defaultSource = "sdk";
3218
3218
  function isTelemetryOptedOut() {
3219
+ const disabled = process.env.ATBASH_TELEMETRY_DISABLED?.trim().toLowerCase();
3220
+ if (disabled && ["1", "true", "yes", "on"].includes(disabled)) {
3221
+ return true;
3222
+ }
3219
3223
  try {
3220
3224
  const home2 = process.env.HOME || homedir2() || "";
3221
3225
  const filePath = join2(home2, ".config", "atbash", "telemetry.json");
@@ -3236,14 +3240,14 @@ function setupTelemetry(config2) {
3236
3240
  if (!config2.enabled) return;
3237
3241
  if (meterProvider) return;
3238
3242
  if (isTelemetryOptedOut()) return;
3243
+ if (!config2.endpoint || !config2.getAuthHeaders) return;
3244
+ if (/^https?:\/\/(localhost|127\.0\.0\.1|0\.0\.0\.0)(:|\/|$)/i.test(config2.endpoint)) return;
3239
3245
  defaultSource = config2.source ?? "sdk";
3240
- const apiKey = process.env.HONEYCOMB_API_KEY ?? native.HONEYCOMB_KEY;
3241
- if (!apiKey) return;
3246
+ const proxyUrl = `${config2.endpoint.replace(/\/+$/, "")}/api/telemetry`;
3247
+ const getAuthHeaders = config2.getAuthHeaders;
3242
3248
  const exporter = new OTLPMetricExporter({
3243
- url: "https://api.honeycomb.io/v1/metrics",
3244
- headers: {
3245
- "x-honeycomb-team": apiKey
3246
- }
3249
+ url: proxyUrl,
3250
+ headers: async () => getAuthHeaders()
3247
3251
  });
3248
3252
  const reader = new PeriodicExportingMetricReader({
3249
3253
  exporter,
@@ -3418,6 +3422,16 @@ var Atbash = class _Atbash {
3418
3422
  verifying: this.verifyPubKey ? "with response-signature pubkey configured" : "without signature verification"
3419
3423
  });
3420
3424
  }
3425
+ try {
3426
+ setupTelemetry({
3427
+ enabled: true,
3428
+ source: "sdk",
3429
+ endpoint: this.endpoint,
3430
+ getAuthHeaders: () => this.authHeaders()
3431
+ });
3432
+ } catch (err) {
3433
+ this.logger.warn?.("[atbash] telemetry setup failed \u2014 continuing without metrics", { error: String(err) });
3434
+ }
3421
3435
  }
3422
3436
  /**
3423
3437
  * Say which environment this build talks to, once per process.
@@ -3931,19 +3945,25 @@ var Atbash = class _Atbash {
3931
3945
  });
3932
3946
  }
3933
3947
  /* ── risk-engine batched (action-dispatched POST) ──────────────────────── */
3934
- getAgentDetail(agentPubkey) {
3935
- return this.track(
3936
- "getAgentDetail",
3937
- agentPubkey,
3938
- () => this.riskEnginePost({ action: "agent-detail-batch", agent: agentPubkey })
3939
- );
3948
+ async getAgentDetail(agentPubkey, options = {}) {
3949
+ return this.track("getAgentDetail", agentPubkey, async () => {
3950
+ const network = await this.resolveAgentLookupNetwork(options);
3951
+ return this.riskEnginePost(
3952
+ { action: "agent-detail-batch", agent: agentPubkey },
3953
+ network
3954
+ );
3955
+ });
3940
3956
  }
3941
- async getAgentPolicy(agentPubkey) {
3957
+ async getAgentPolicy(agentPubkey, options = {}) {
3942
3958
  return this.track("getAgentPolicy", agentPubkey, async () => {
3943
- const raw2 = await this.riskEnginePost({
3944
- action: "agent-policy-batch",
3945
- agent: agentPubkey
3946
- });
3959
+ const network = await this.resolveAgentLookupNetwork(options);
3960
+ const raw2 = await this.riskEnginePost(
3961
+ {
3962
+ action: "agent-policy-batch",
3963
+ agent: agentPubkey
3964
+ },
3965
+ network
3966
+ );
3947
3967
  return {
3948
3968
  policy: String(raw2.policy ?? ""),
3949
3969
  isJailed: Boolean(raw2.is_jailed),
@@ -4100,6 +4120,20 @@ var Atbash = class _Atbash {
4100
4120
  if (chainOpts?.network === "public") return PUBLIC_CHAIN.blockchainRid;
4101
4121
  return this.blockchainRid;
4102
4122
  }
4123
+ /**
4124
+ * Resolve the dashboard chain used by agent metadata/policy reads.
4125
+ * Explicit per-call network overrides win; otherwise use the supplied org
4126
+ * or the client's configured default org. A custom BRID is intentionally
4127
+ * left untouched because it cannot be represented by the dashboard's
4128
+ * public/private query selector.
4129
+ */
4130
+ async resolveAgentLookupNetwork(options) {
4131
+ if (options.chainOpts?.network) return options.chainOpts.network;
4132
+ if (options.chainOpts?.blockchainRid) return void 0;
4133
+ const orgName = options.orgName ?? this.orgName;
4134
+ if (!orgName) return void 0;
4135
+ return (await this.resolveChainForOrg(orgName)).network;
4136
+ }
4103
4137
  /**
4104
4138
  * Get-or-create a Bearer token for dashboard reads. The token is a
4105
4139
  * signed `log_tool_call` op (locally signed, never submitted) — the
@@ -4142,10 +4176,11 @@ var Atbash = class _Atbash {
4142
4176
  if (resp.status !== 200) throw await this.httpError(resp);
4143
4177
  return this.json(resp);
4144
4178
  }
4145
- async riskEnginePost(body) {
4179
+ async riskEnginePost(body, network) {
4146
4180
  let resp;
4147
4181
  try {
4148
- resp = await this.http.post("/api/risk-engine", body, this.authHeaders());
4182
+ const path7 = network ? `/api/risk-engine?network=${encodeURIComponent(network)}` : "/api/risk-engine";
4183
+ resp = await this.http.post(path7, body, this.authHeaders());
4149
4184
  } catch (err) {
4150
4185
  throw this.transportError(err);
4151
4186
  }
@@ -4416,7 +4451,8 @@ async function scanMemory(entry, auth, opts) {
4416
4451
  const result = await atbash.judgeAction(request.prompt, request.context, {
4417
4452
  toolName: opts?.toolName ?? "memory_write",
4418
4453
  toolArgsJson: opts?.toolArgsJson ?? JSON.stringify({ key: entry.key, source: entry.source }),
4419
- mode: "memory-scan"
4454
+ mode: "memory-scan",
4455
+ orgName: opts?.orgName
4420
4456
  });
4421
4457
  if (result.verdict === "No verdict" && result.status !== "logged") {
4422
4458
  throw new Error(